Clean ups, abstract the widgets a bit, and don't segfault when not finding an unsuitable write mode.

This commit is contained in:
Jaime Thomas 2008-12-18 22:16:55 +00:00
parent 6a512c1163
commit 8815f3c6f6
11 changed files with 358 additions and 112 deletions

View File

@ -215,7 +215,7 @@ group {
}
part {
name: "label";
name: "ecdb.label";
type: TEXT;
mouse_events: 1;
@ -226,16 +226,16 @@ group {
fixed: 1 1;
rel1 {
to: "icon";
to: "ecdb.swallow.icon";
offset: 40 0;
}
rel2 {
to: "icon";
to: "ecdb.swallow.icon";
}
text {
text: "Burn Audio CD";
text: "";
font: "ecdb/default";
min: 1 1;
size: 11;
@ -245,7 +245,7 @@ group {
}
part {
name: "icon";
name: "ecdb.swallow.icon";
type: SWALLOW;
mouse_events: 1;

View File

@ -151,7 +151,7 @@ group {
}
part {
name: "label";
name: "ecdb.label";
type: TEXT;
description {
@ -171,7 +171,7 @@ group {
}
text {
text: "Change Burn Speed";
text: "";
font: "ecdb/default";
min: 1 1;
size: 11;
@ -254,5 +254,31 @@ group {
set_state(PART:"check", "default", 0.0);
}
}
program {
name: "check_off";
signal: "ecdb,check,off";
source: "ecdb";
script {
set_int(s, 0);
}
action: STATE_SET "default" 0.0;
target: "check";
}
program {
name: "check_on";
signal: "ecdb,check,on";
source: "ecdb";
script {
set_int(s, 1);
}
action: STATE_SET "active" 0.0;
target: "check";
}
}
}

View File

@ -60,13 +60,14 @@ group {
}
part {
name: "label";
name: "ecdb.text";
type: TEXTBLOCK;
mouse_events: 1;
entry_mode: EDITABLE;
multiline: 0;
source2: "entry/selection/default";
source3: "entry/cursor/default";
//source3: "entry/cursor/default";
source3: "entry/selection/default";
description {
state: "default" 0.0;
@ -92,7 +93,7 @@ group {
program {
name: "focus_set";
action: FOCUS_SET;
target: "label";
target: "ecdb.text";
}
program {
@ -142,6 +143,7 @@ group {
}
}
/*
group {
name: "entry/cursor/default";
@ -169,6 +171,7 @@ group {
}
}
}
*/
group {
name: "entry/selection/default";

View File

@ -11,6 +11,7 @@ ecdb_SOURCES = \
ecdb_audio.c ecdb_audio.h \
ecdb_gui.c ecdb_gui.h \
ecdb_erase.c ecdb_erase.h \
ecdb_widgets.c ecdb_widgets.h \
ecdb_common.h
ecdb_CFLAGS = @ECDB_CFLAGS@

View File

@ -54,6 +54,7 @@ extern int ECDB_DRIVE_ACTION_UPDATE;
#include "ecdb_misc.h"
#include "ecdb_audio.h"
#include "ecdb_gui.h"
#include "ecdb_widgets.h"
#endif

View File

@ -151,7 +151,7 @@ ecdb_burn_project(Ecdb_Burn_Project *proj)
burn_write_opts_free(opts);
ecdb_sources_list_free(data->sources);
ecdb_tracks_list_free(data->tracks);
FREE(proj);
FREE(data);
return ECDB_ERROR_WRITE_MODE;
}

View File

@ -506,41 +506,29 @@ ecdb_cb_burn_image_page_buttons_clicked(void *data, Evas_Object *o,
Ecdb_Burn_Project *proj;
Evas_Object *entry;
Ecdb_Source *iso_file;
const char *file;
char *sanitized_file;
char *file;
char buf[1024];
Ecdb_Burn_Result burn_result;
entry = evas_object_name_find(ecore_evas_get(em->main_win_ee),
"ecdb/burn_image/file");
file = edje_object_part_text_get(entry, "label");
//Textblock returns a <br> at the end, so chop that off
if (!strcmp(&file[strlen(file) - 4], "<br>"))
{
sanitized_file = alloca(sizeof(char) * (strlen(file) - 3));
sanitized_file[0] = '\0';
ecore_strlcpy(sanitized_file, file, strlen(file) - 3);
printf("Sanitized_file: %s\n", sanitized_file);
}
else
{
// We aren't altering sanitized_file after this
sanitized_file = (char *)file;
}
file = ecdb_entry_text_get(entry);
printf("file: '%s'\n", file);
// Make sure that file actually exists
if (!ecore_file_exists(sanitized_file))
if (!ecore_file_exists(file))
{
edje_object_part_text_set(swallow, "progress_text", "File doesn't "
"exists!");
FREE(file);
return;
}
proj = ecdb_burn_project_new();
ecdb_project_type_set(ECDB_PROJECT(proj), ECDB_IMAGE_PROJECT);
iso_file = ecdb_source_new();
ecdb_source_data_set(iso_file, sanitized_file);
ecdb_source_data_set(iso_file, file);
FREE(file);
ecdb_source_child_append(proj->files, iso_file);
snprintf(buf, sizeof(buf), "Commencing...");
@ -610,6 +598,8 @@ ecdb_welcome_page_show(void)
if (!swallow)
{
Evas_Object *b;
Evas_Coord x, y, w, h;
swallow = edje_object_add(ecore_evas_get(em->main_win_ee));
@ -627,7 +617,6 @@ ecdb_welcome_page_show(void)
ecdb_cb_page_hide_finished, NULL);
evas_object_show(swallow);
Evas_Object *b;
int i;
char *labels[] = {"Burn Data CD", "Burn Audio CD", "Burn Image",
"Erase Re-writable Disc"};
@ -635,18 +624,10 @@ ecdb_welcome_page_show(void)
"ecdb/erase"};
for (i = 0; i < 4; i++)
{
b = edje_object_add(ecore_evas_get(em->main_win_ee));
evas_object_name_set(b, ids[i]);
edje_object_file_set(b, em->theme_path, "ecdb/button");
edje_object_part_geometry_get(swallow, ids[i], &x, &y, &w, &h);
edje_object_part_text_set(b, "label", labels[i]);
evas_object_move(b, x, y);
evas_object_resize(b, w, h);
edje_object_part_swallow(swallow, ids[i], b);
b = ecdb_button_add(swallow, ids[i]);
ecdb_button_label_set(b, labels[i]);
evas_object_show(b);
/* Place this after */
ecdb_button_icon_swallow(ecore_evas_get(em->main_win_ee), b, ids[i]);
ecdb_button_icon_set(b, ids[i]);
}
}
@ -752,6 +733,7 @@ ecdb_erase_page_show(void)
if (!swallow)
{
Evas_Object *b;
Evas_Coord x, y, w, h;
swallow = edje_object_add(ecore_evas_get(em->main_win_ee));
@ -772,32 +754,19 @@ ecdb_erase_page_show(void)
ecdb_cb_page_hide_finished, NULL);
evas_object_show(swallow);
int i;
char *labels[] = {"Return to Main Page", "Start Erase",
"Quick Erase"};
char *ids[] = {"ecdb/erase/return", "ecdb/erase/begin",
"ecdb/erase/speed"};
char *wtype[] = {"ecdb/button", "ecdb/button", "ecdb/check"};
b = ecdb_button_add(swallow, "ecdb/erase/return");
ecdb_button_label_set(b, "Return to Main Page");
evas_object_show(b);
ecdb_button_icon_set(b, "ecdb/erase/return");
for (i = 0; i < 3; i++)
{
Evas_Object *b;
b = edje_object_add(ecore_evas_get(em->main_win_ee));
evas_object_name_set(b, ids[i]);
edje_object_file_set(b, em->theme_path, wtype[i]);
edje_object_part_geometry_get(swallow, ids[i], &x, &y, &w, &h);
evas_object_move(b, x, y);
evas_object_resize(b, w, h);
edje_object_part_text_set(b, "label", labels[i]);
edje_object_part_swallow(swallow, ids[i], b);
evas_object_show(b);
b = ecdb_button_add(swallow, "ecdb/erase/begin");
ecdb_button_label_set(b, "Start Erase");
evas_object_show(b);
ecdb_button_icon_set(b, "ecdb/erase/begin");
if (!strcmp("ecdb/button", wtype[i]))
{
ecdb_button_icon_swallow(ecore_evas_get(em->main_win_ee), b,
ids[i]);
}
}
b = ecdb_check_add(swallow, "ecdb/erase/speed");
ecdb_check_label_set(b, "Quick Erase");
evas_object_show(b);
}
else if (edje_object_part_swallow_get(gui, "action_area") != swallow)
@ -821,6 +790,7 @@ ecdb_burn_image_page_show(void)
if (!swallow)
{
Evas_Object *b;
Evas_Coord x, y, w, h;
swallow = edje_object_add(ecore_evas_get(em->main_win_ee));
@ -843,36 +813,19 @@ ecdb_burn_image_page_show(void)
ecdb_cb_page_hide_finished, NULL);
evas_object_show(swallow);
int i;
char *labels[] = {"Return to Main Page", "Start Burn", "Burn File"};
char *ids[] = {"ecdb/burn_image/return", "ecdb/burn_image/begin",
"ecdb/burn_image/file"};
char *wtype[] = {"ecdb/button", "ecdb/button", "ecdb/entry"};
b = ecdb_button_add(swallow, "ecdb/burn_image/return");
ecdb_button_label_set(b, "Return to Main Page");
evas_object_show(b);
ecdb_button_icon_set(b, "ecdb/burn_image/return");
for (i = 0; i < 3; i++)
{
Evas_Object *b;
b = edje_object_add(ecore_evas_get(em->main_win_ee));
evas_object_name_set(b, ids[i]);
edje_object_file_set(b, em->theme_path, wtype[i]);
edje_object_part_geometry_get(swallow, ids[i], &x, &y, &w, &h);
evas_object_move(b, x, y);
evas_object_resize(b, w, h);
edje_object_part_text_set(b, "label", labels[i]);
edje_object_part_swallow(swallow, ids[i], b);
evas_object_show(b);
b = ecdb_button_add(swallow, "ecdb/burn_image/begin");
ecdb_button_label_set(b, "Start Burn");
evas_object_show(b);
ecdb_button_icon_set(b, "ecdb/burn_image/begin");
if (!strcmp("ecdb/button", wtype[i]))
{
ecdb_button_icon_swallow(ecore_evas_get(em->main_win_ee), b,
ids[i]);
}
else if (!strcmp("ecdb/entry", wtype[i]))
{
em->dnd_candidates = eina_list_append(em->dnd_candidates, b);
evas_object_data_set(b, "dnd_call_func", ecdb_dnd_entry_dnd_set);
}
}
b = ecdb_entry_add(swallow, "ecdb/burn_image/file");
ecdb_entry_text_set(b, "Burn File");
evas_object_show(b);
}
else if (edje_object_part_swallow_get(gui, "action_area") != swallow)

View File

@ -163,21 +163,6 @@ ecdb_strip_next_argument(const char *strip)
return NULL;
}
void
ecdb_button_icon_swallow(Evas *e, Evas_Object *b, const char *iname)
{
Evas_Object *icon;
Evas_Coord x, y, w, h;
icon = edje_object_add(e);
edje_object_file_set(icon, em->theme_path, iname);
edje_object_part_geometry_get(b, "icon", &x, &y, &w, &h);
evas_object_move(icon, x, y);
evas_object_resize(icon, w, h);
edje_object_part_swallow(b, "icon", icon);
evas_object_show(icon);
}
int
ecdb_dnd_position(void *data, int type, void *event)
{
@ -274,6 +259,6 @@ ecdb_dnd_entry_dnd_set(Evas_Object *o, Ecore_X_Selection_Data_Files *files)
Efreet_Uri *uri;
uri = efreet_uri_decode(files->files[0]);
edje_object_part_text_set(o, "label", uri->path);
ecdb_entry_text_set(o, uri->path);
efreet_uri_free(uri);
}

View File

@ -17,8 +17,6 @@ int ecdb_image_init(void);
int ecdb_match_keyword(const char *chk, const char *key, int len);
char *ecdb_strip_next_argument(const char *strip);
char *ecdb_strip_string(const char *strip);
void ecdb_button_icon_swallow(Evas *e, Evas_Object *b,
const char *iname);
// Also consider moving dnd stuff into its own file
int ecdb_dnd_position(void *data, int type, void *event);

View File

@ -0,0 +1,260 @@
/* vim: set sw=3 ts=3 sts=3 expandtab: */
#include "ecdb.h"
static char *ecdb_entry_markup_to_text(const char *mkup);
static char *_str_append(char *str, const char *txt, int *len, int *alloc);
Evas_Object *
ecdb_widget_add(Evas_Object *parent, const char *name)
{
Evas_Object *o;
int x, y, w, h;
o = edje_object_add(evas_object_evas_get(parent));
evas_object_name_set(o, name);
edje_object_part_geometry_get(parent, name, &x, &y, &w, &h);
evas_object_move(o, x, y);
evas_object_resize(o, w, h);
edje_object_part_swallow(parent, name, o);
return o;
}
Evas_Object *
ecdb_button_add(Evas_Object *parent, const char *name)
{
Evas_Object *b;
b = ecdb_widget_add(parent, name);
edje_object_file_set(b, em->theme_path, "ecdb/button");
return b;
}
void
ecdb_button_label_set(Evas_Object *b, const char *label)
{
edje_object_part_text_set(b, "ecdb.label", label);
}
void
ecdb_button_icon_set(Evas_Object *b, const char *group)
{
Evas_Object *icon;
icon = ecdb_widget_add(b, "ecdb.swallow.icon");
edje_object_file_set(icon, em->theme_path, group);
evas_object_show(icon);
}
Evas_Object *
ecdb_check_add(Evas_Object *parent, const char *name)
{
Evas_Object *c;
c = ecdb_widget_add(parent, name);
edje_object_file_set(c, em->theme_path, "ecdb/check");
return c;
}
void
ecdb_check_label_set(Evas_Object *c, const char *label)
{
edje_object_part_text_set(c, "ecdb.label", label);
}
void
ecdb_check_states_set(Evas_Object *c, const char *ystate, const char *nstate)
{
edje_object_part_text_set(c, "ecdb.ystate", ystate);
edje_object_part_text_set(c, "ecdb.nstate", nstate);
}
void
ecdb_check_state_set(Evas_Object *c, int state)
{
if (state)
{
edje_object_signal_emit(c, "ecdb,check,on", "ecdb");
}
else
{
edje_object_signal_emit(c, "ecdb,check,off", "ecdb");
}
}
Evas_Object *
ecdb_entry_add(Evas_Object *parent, const char *name)
{
Evas_Object *e;
e = ecdb_widget_add(parent, name);
edje_object_file_set(e, em->theme_path, "ecdb/entry");
em->dnd_candidates = eina_list_append(em->dnd_candidates, e);
evas_object_data_set(e, "dnd_call_func", ecdb_dnd_entry_dnd_set);
return e;
}
void
ecdb_entry_text_set(Evas_Object *e, const char *text)
{
edje_object_part_text_set(e, "ecdb.text", text);
}
char *
ecdb_entry_text_get(Evas_Object *e)
{
return ecdb_entry_markup_to_text(edje_object_part_text_get(e, "ecdb.text"));
}
/* Shamelessly stolen from Elementary... */
static char *
ecdb_entry_markup_to_text(const char *mkup)
{
char *str = NULL;
int str_len = 0, str_alloc = 0;
// FIXME: markup -> text
char *s, *p;
char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
tag_start = tag_end = esc_start = esc_end = NULL;
p = (char *)mkup;
s = p;
for (;;)
{
if ((*p == 0) ||
(tag_end) || (esc_end) ||
(tag_start) || (esc_start))
{
if (tag_end)
{
char *ttag;
ttag = malloc(tag_end - tag_start);
if (ttag)
{
strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
ttag[tag_end - tag_start - 1] = 0;
/*
if (!strcmp(ttag, "br"))
str = _str_append(str, "\n", &str_len, &str_alloc);
*/
if (!strcmp(ttag, "\n"))
str = _str_append(str, "\n", &str_len, &str_alloc);
else if (!strcmp(ttag, "\\n"))
str = _str_append(str, "\n", &str_len, &str_alloc);
else if (!strcmp(ttag, "\t"))
str = _str_append(str, "\t", &str_len, &str_alloc);
else if (!strcmp(ttag, "\\t"))
str = _str_append(str, "\t", &str_len, &str_alloc);
free(ttag);
}
tag_start = tag_end = NULL;
}
else if (esc_end)
{
ts = malloc(esc_end - esc_start + 1);
if (ts)
{
const char *esc;
strncpy(ts, esc_start, esc_end - esc_start);
ts[esc_end - esc_start] = 0;
esc = evas_textblock_escape_string_get(ts);
if (esc)
str = _str_append(str, esc, &str_len, &str_alloc);
free(ts);
}
esc_start = esc_end = NULL;
}
else if (*p == 0)
{
ts = malloc(p - s + 1);
if (ts)
{
strncpy(ts, s, p - s);
ts[p - s] = 0;
str = _str_append(str, ts, &str_len, &str_alloc);
free(ts);
}
s = NULL;
}
if (*p == 0)
break;
}
if (*p == '<')
{
if (!esc_start)
{
tag_start = p;
tag_end = NULL;
ts = malloc(p - s + 1);
if (ts)
{
strncpy(ts, s, p - s);
ts[p - s] = 0;
str = _str_append(str, ts, &str_len, &str_alloc);
free(ts);
}
s = NULL;
}
}
else if (*p == '>')
{
if (tag_start)
{
tag_end = p;
s = p + 1;
}
}
else if (*p == '&')
{
if (!tag_start)
{
esc_start = p;
esc_end = NULL;
ts = malloc(p - s + 1);
if (ts)
{
strncpy(ts, s, p - s);
ts[p - s] = 0;
str = _str_append(str, ts, &str_len, &str_alloc);
free(ts);
}
s = NULL;
}
}
else if (*p == ';')
{
if (esc_start)
{
esc_end = p;
s = p + 1;
}
}
p++;
}
return str;
}
static char *
_str_append(char *str, const char *txt, int *len, int *alloc)
{
int txt_len = strlen(txt);
if (txt_len <= 0) return str;
if ((*len + txt_len) >= *alloc)
{
char *str2;
int alloc2;
alloc2 = *alloc + txt_len + 128;
str2 = realloc(str, alloc2);
if (!str2) return str;
*alloc = alloc2;
str = str2;
}
strcpy(str + *len, txt);
*len += txt_len;
return str;
}

View File

@ -0,0 +1,19 @@
/* vim: set sw=3 ts=3 sts=3 expandtab: */
#ifndef ECDB_WIDGETS_H
#define ECDB_WIDGETS_H
Evas_Object *ecdb_button_add(Evas_Object *parent, const char *name);
void ecdb_button_label_set(Evas_Object *b, const char *label);
void ecdb_button_icon_set(Evas_Object *b, const char *group);
Evas_Object *ecdb_check_add(Evas_Object *parent, const char *name);
void ecdb_check_label_set(Evas_Object *c, const char *label);
void ecdb_check_states_set(Evas_Object *c, const char *ystate,
const char *nstate);
void ecdb_check_state_set(Evas_Object *c, int state);
Evas_Object *ecdb_entry_add(Evas_Object *parent, const char *name);
void ecdb_entry_text_set(Evas_Object *e, const char *text);
char *ecdb_entry_text_get(Evas_Object *e);
#endif