From 454d2b917ad636ce6020a1a2d133d05cbcb0edc3 Mon Sep 17 00:00:00 2001 From: cpk Date: Sat, 3 Nov 2001 09:07:40 +0000 Subject: [PATCH] * replaced printf()s with D()s. * cleaned up functions in utils in file utils and others, there's a new file.[ch] for the file-related helpers. * Added stat info to E_Icon, watch how directories become grayed when you cannot access them :) SVN revision: 5610 --- src/Makefile.am | 3 +- src/actions.c | 1 - src/background.c | 2 +- src/border.c | 39 +++++---- src/config.c | 15 ++-- src/cursors.c | 6 +- src/desktops.h | 23 +++++ src/e_ferite.c | 10 +-- src/entry.c | 6 +- src/entry.h | 2 +- src/exec.c | 6 +- src/file.c | 218 ++++++++++++++++++++++++++++++++++++++++++++++ src/file.h | 39 +++++++++ src/fs.c | 28 +++--- src/icccm.c | 2 +- src/menu.c | 2 +- src/menubuild.c | 17 ++-- src/object.c | 6 +- src/util.c | 222 +---------------------------------------------- src/util.h | 19 +--- src/view.c | 171 +++++++++++++++++++++++------------- src/view.h | 42 ++++++++- 22 files changed, 513 insertions(+), 366 deletions(-) create mode 100644 src/file.c create mode 100644 src/file.h diff --git a/src/Makefile.am b/src/Makefile.am index 4ed9fea59..d6c2d96aa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,7 +5,7 @@ DISTCLEANFILES = e_ferite_gen_* ## Enable -DDEBUG for debugging messages, -DDEBUG_NEST ## for call tracing. Caution -- this will produce a *lot* ## of output! -DEBUGFLAGS = -g -DDEBUG #-DDEBUG_NEST +DEBUGFLAGS = -W -Wall -g -DDEBUG #-DDEBUG_NEST INCLUDES = \ -I$(top_srcdir)/intl \ @@ -35,6 +35,7 @@ enlightenment_SOURCES = \ embed.c embed.h \ entry.h entry.c \ exec.h exec.c \ + file.h file.c \ fs.h fs.c \ $(ferite_c) \ guides.h guides.c \ diff --git a/src/actions.c b/src/actions.c index f92a825fb..0af1d64f7 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1473,7 +1473,6 @@ e_act_exec_start (E_Object *object, E_Action *a, void *data, int x, int y, int r exe = (char *) a->params; if(!exe) D_RETURN; - /* printf("exe: %s\n",exe); */ e_exec_run(exe); D_RETURN; diff --git a/src/background.c b/src/background.c index 324212375..afccb2a16 100644 --- a/src/background.c +++ b/src/background.c @@ -139,7 +139,7 @@ e_background_realize(E_Background *bg, Evas evas) #if 0 /* dont need this... do we? */ if (evas_get_image_alpha(bg->evas, bl->obj)) { - printf("Adding rectangle to bg!\n"); + D("Adding rectangle to bg!\n"); bg->base_obj = evas_add_rectangle(bg->evas); evas_lower(bg->evas, bg->base_obj); evas_move(bg->evas, bg->base_obj, 0, 0); diff --git a/src/border.c b/src/border.c index a0ff8c44a..f63155faf 100644 --- a/src/border.c +++ b/src/border.c @@ -7,6 +7,7 @@ #include "desktops.h" #include "resist.h" #include "icccm.h" +#include "file.h" #include "util.h" #include "place.h" #include "match.h" @@ -471,14 +472,14 @@ e_focus_in(Ecore_Event * ev) current_ev = ev; e = ev->event; - printf("focus in event\n"); + D("focus in event\n"); { E_Border *b; b = e_border_find_by_window(e->win); if ((b) && (b->win.client == e->win)) { - printf("focus in %s\n", b->client.title); + D("focus in %s\n", b->client.title); e_border_focus_grab_ended(); b->current.selected = 1; b->changed = 1; @@ -496,7 +497,7 @@ e_focus_in(Ecore_Event * ev) /* find a grab that triggered this */ if (b->click_grab == g) { - printf("ungrab %s\n", b->client.title); + D("ungrab %s\n", b->client.title); /* ecore_pointer_ungrab(e->time);*/ ecore_button_ungrab(b->win.main, g->button, g->mods, g->any_mod); /* ecore_window_button_grab_auto_replay_set(b->win.main, 0);*/ @@ -524,7 +525,7 @@ e_focus_out(Ecore_Event * ev) current_ev = ev; e = ev->event; - printf("focus out event\n"); + D("focus out event\n"); { E_Border *b; @@ -535,7 +536,7 @@ e_focus_out(Ecore_Event * ev) E_CFG_INT(cfg_focus_mode, "settings", "/focus/mode", 0); E_CONFIG_INT_GET(cfg_focus_mode, focus_mode); - printf("focus out %s\n", b->client.title); + D("focus out %s\n", b->client.title); b->current.selected = 0; if (e->key_grab) b->current.select_lost_from_grab = 1; /* settings - click to focus would affect grabs */ @@ -550,7 +551,7 @@ e_focus_out(Ecore_Event * ev) g->any_mod = 0; g->remove_after = 1; b->grabs = evas_list_append(b->grabs, g); - printf("grab me baaaybe %8x | %s\n", b->win.client, b->client.title); + D("grab me baaaybe %8x | %s\n", b->win.client, b->client.title); ecore_button_grab(b->win.main, 0, XEV_BUTTON_PRESS | XEV_BUTTON_RELEASE, ECORE_EVENT_KEY_MODIFIER_NONE, 0); ecore_window_button_grab_auto_replay_set(b->win.main, e_border_replay_query); b->click_grab = g; @@ -595,7 +596,7 @@ e_mouse_down(Ecore_Event * ev) D_ENTER; - printf("doooown\n"); + D("doooown\n"); current_ev = ev; e = ev->event; { @@ -607,7 +608,7 @@ e_mouse_down(Ecore_Event * ev) mouse_y = e->ry; mouse_buttons |= (1 << e->button); b = e_border_find_by_window(e->win); - printf("%p (%x)\n", b, e->win); + D("%p (%x)\n", b, e->win); if (b) { int focus_mode; @@ -1125,10 +1126,10 @@ e_cb_border_mouse_down(E_Border *b, Ecore_Event *e) ecore_pointer_grab(b->win.main, CurrentTime); border_mouse_x = mouse_x; border_mouse_y = mouse_y; - printf("%i\n", border_mouse_buttons); + D("%i\n", border_mouse_buttons); /* if (border_mouse_buttons) D_RETURN; */ /* border_mouse_buttons = mouse_buttons; */ - printf("%p\n", current_ev); + D("%p\n", current_ev); if (!current_ev) D_RETURN; x = ((Ecore_Event_Mouse_Down *)(e->event))->x; y = ((Ecore_Event_Mouse_Down *)(e->event))->y; @@ -1151,7 +1152,7 @@ e_cb_border_mouse_down(E_Border *b, Ecore_Event *e) if (b->click_grab == g) b->click_grab = NULL; if (g->remove_after) { - printf("pfft ungrab %s\n", b->client.title); + D("pfft ungrab %s\n", b->client.title); ecore_button_ungrab(b->win.main, g->button, g->mods, g->any_mod); ecore_window_button_grab_auto_replay_set(b->win.main, NULL); ecore_pointer_ungrab(((Ecore_Event_Mouse_Up *)(e->event))->time); @@ -1162,7 +1163,7 @@ e_cb_border_mouse_down(E_Border *b, Ecore_Event *e) } } } - printf("(...e_cb_border_mouse_down...)\n"); + D("(...e_cb_border_mouse_down...)\n"); { E_Action_Type act; Ecore_Event_Key_Modifiers mods; @@ -1801,7 +1802,7 @@ e_border_remove_mouse_grabs(E_Border *b) E_Grab *g; g = l->data; - printf("nooo grabs\n"); + D("nooo grabs\n"); ecore_button_ungrab(b->win.main, g->button, g->mods, g->any_mod); FREE(g); } @@ -1860,7 +1861,7 @@ e_border_attach_mouse_grabs(E_Border *b) g->any_mod = 0; g->remove_after = 1; b->grabs = evas_list_append(b->grabs, g); - printf("attach... grab me baaaybe %8x | %s\n", b->win.client, b->client.title); + D("attach... grab me baaaybe %8x | %s\n", b->win.client, b->client.title); ecore_button_grab(b->win.main, 0, XEV_BUTTON_PRESS | XEV_BUTTON_RELEASE, ECORE_EVENT_KEY_MODIFIER_NONE, 0); ecore_window_button_grab_auto_replay_set(b->win.main, e_border_replay_query); b->click_grab = g; @@ -1955,12 +1956,12 @@ e_border_redo_grabs(void) grabs_db = e_config_get("grabs"); settings_db = e_config_get("settings"); - mod = e_file_modified_time(grabs_db); + mod = e_file_mod_time(grabs_db); if (mod != mod_date_grabs) changed = 1; mod_date_grabs = mod; if (!changed) { - mod = e_file_modified_time(settings_db); + mod = e_file_mod_time(settings_db); if (mod != mod_date_settings) changed = 1; mod_date_settings = mod; } @@ -2713,7 +2714,7 @@ e_border_current_focused(void) E_Border *b; b = l->data; - printf("%s: %i | %i\n", b->client.title, + D("%s: %i | %i\n", b->client.title, b->current.selected, b->current.select_lost_from_grab); } for (l = borders; l; l = l->next) @@ -2823,9 +2824,9 @@ e_border_raise_next(void) current = (E_Border *)next->data; } - printf("current desk coords %d, %d, real dim %d, %d\n", current->desk->x, + D("current desk coords %d, %d, real dim %d, %d\n", current->desk->x, current->desk->y, current->desk->real.w, current->desk->real.h); - printf("current coords %d, %d\n", current->current.x, + D("current coords %d, %d\n", current->current.x, current->current.y); e_border_raise(current); diff --git a/src/config.c b/src/config.c index 38b5cc6d3..7aaf5e211 100644 --- a/src/config.c +++ b/src/config.c @@ -1,5 +1,6 @@ #include "debug.h" #include "config.h" +#include "file.h" #include "util.h" static char cfg_root[] = ""; @@ -154,7 +155,7 @@ e_config_user_dir(void) if (cfg_user_dir[0]) D_RETURN_(cfg_user_dir); if (cfg_root[0]) D_RETURN_(cfg_root); #if 1 /* disabled for now - use system ones only */ - sprintf(cfg_user_dir, "%s/.e/", e_file_home()); + sprintf(cfg_user_dir, "%s/.e/", e_util_get_user_home()); #else sprintf(cfg_user_dir, PACKAGE_DATA_DIR"/data/config/"); #endif @@ -288,8 +289,6 @@ e_config_load(char *file, char *prefix, E_Config_Base_Type *type) break; case E_CFG_TYPE_KEY: { - char *val; - sprintf(buf, "%s/%s", prefix, node->prefix); (*((char **)(&(data[node->offset])))) = strdup(buf); } @@ -346,7 +345,7 @@ void ts(void) /* no data file? */ if (!cfg_data) { - printf("no load!\n"); + D("no load!\n"); } /* got data */ else @@ -357,11 +356,11 @@ void ts(void) { List_Element *cfg_element; - printf("element\n"); + D("element\n"); cfg_element = l->data; - printf("... name %s\n", cfg_element->name); - printf("... size %i\n", cfg_element->size); - printf("... perc %3.3f\n", cfg_element->perc); + D("... name %s\n", cfg_element->name); + D("... size %i\n", cfg_element->size); + D("... perc %3.3f\n", cfg_element->perc); } } exit(0); diff --git a/src/cursors.c b/src/cursors.c index e5f431c04..8828c3cae 100644 --- a/src/cursors.c +++ b/src/cursors.c @@ -2,6 +2,7 @@ #include "cursors.h" #include "config.h" #include "util.h" +#include "file.h" typedef struct _e_cursor E_Cursor; @@ -73,7 +74,7 @@ e_cursors_find(char *type) char buf[PATH_MAX]; sprintf(buf, "%s/%s.db", e_config_get("cursors"), type); - if (e_file_modified_time(buf) > c->mod) + if (e_file_mod_time(buf) > c->mod) { cursors = evas_list_remove(cursors, c); IF_FREE(c->type); @@ -113,7 +114,7 @@ e_cursors_display_in_window(Window win, char *type) e_strdup(c->type, type); sprintf(buf, "%s/%s.db", e_config_get("cursors"), type); - c->mod = e_file_modified_time(buf); + c->mod = e_file_mod_time(buf); E_DB_INT_GET(buf, "/cursor/x", hx, ok); E_DB_INT_GET(buf, "/cursor/y", hy, ok); sprintf(buf, "%s/%s.db:/cursor/image", e_config_get("cursors"), type); @@ -247,7 +248,6 @@ e_cursors_display(char *type) IF_FREE(cur_cursor); e_strdup(cur_cursor, type); - printf("%s\n", type); cursor_change = 1; D_RETURN; diff --git a/src/desktops.h b/src/desktops.h index 62d196086..a67aac087 100644 --- a/src/desktops.h +++ b/src/desktops.h @@ -47,15 +47,38 @@ void e_desktops_init(void); void e_desktops_scroll(E_Desktop *desk, int dx, int dy); void e_desktops_free(E_Desktop *desk); + +/** + * e_desktops_init_file_display - Loads desktop graphics information + * @desk: The desktop for which the graphics are loaded + * + * This function loads the desktop's graphics from the user's desktop + * file definition, which lives in ~/.e/desktop/default/.e_background.bg.db. + */ void e_desktops_init_file_display(E_Desktop *desk); + E_Desktop *e_desktops_new(void); void e_desktops_add_border(E_Desktop *d, E_Border *b); void e_desktops_del_border(E_Desktop *d, E_Border *b); void e_desktops_delete(E_Desktop *d); void e_desktops_show(E_Desktop *d); void e_desktops_hide(E_Desktop *d); + +/** + * e_desktops_get_num - Returns number of desktops. + */ int e_desktops_get_num(void); + +/** + * e_desktops_get - Returns nth desktop + * @d: The number of the desktop to get + * + * The desktops are stored in a linked list. This function + * returns the nth of those desktops, NULL if no desktop + * was found at that index. + */ E_Desktop *e_desktops_get(int d); + int e_desktops_get_current(void); void e_desktops_goto_desk(int d); void e_desktops_goto(int d, int ax, int ay); diff --git a/src/e_ferite.c b/src/e_ferite.c index 0a5875b1b..ec9dfd8f2 100644 --- a/src/e_ferite.c +++ b/src/e_ferite.c @@ -6,7 +6,7 @@ void e_ferite_init(void) { D_ENTER; - printf( "Initialising ferite....\n" ); + D( "Initialising ferite....\n" ); ferite_init( 0, NULL ); D_RETURN; @@ -16,7 +16,7 @@ void e_ferite_deinit(void) { D_ENTER; - printf( "Deinitialising ferite....\n" ); + D( "Deinitialising ferite....\n" ); ferite_deinit(); D_RETURN; @@ -46,14 +46,14 @@ void e_ferite_run( char *txt ) D_ENTER; - printf( "Compiling script `%s'\n", txt ); + D("Ferite: Compiling script `%s'\n", txt); script = __ferite_compile_string( txt ); e_ferite_register( script, script->mainns ); script->error_cb = e_ferite_script_error; script->warning_cb = e_ferite_script_warning; - printf( "Executing script.\n" ); + D("Ferite: executing script.\n"); ferite_script_execute( script ); - printf( "Cleaning up.\n" ); + D("Ferite: Cleaning up.\n"); ferite_script_delete( script ); D_RETURN; diff --git a/src/entry.c b/src/entry.c index 208ef8985..64303981d 100644 --- a/src/entry.c +++ b/src/entry.c @@ -431,7 +431,7 @@ e_entry_new(void) } void -e_entry_handlecore_keypress(E_Entry *entry, Ecore_Event_Key_Down *e) +e_entry_handle_keypress(E_Entry *entry, Ecore_Event_Key_Down *e) { D_ENTER; @@ -506,7 +506,7 @@ e_entry_handlecore_keypress(E_Entry *entry, Ecore_Event_Key_Down *e) type = ecore_keypress_translate_into_typeable(e); if (type) { - printf("%0x\n", type[0]); + D("Keypress: %0x\n", type[0]); if ((strlen(type) == 1) && (type[0] == 0x01)) /* ctrl+a */ { entry->cursor_pos = 0; @@ -970,7 +970,7 @@ e_entry_get_selection(E_Entry *entry) len = entry->select.length; if (entry->select.start + entry->select.length >= (int)strlen(entry->buffer)) len = strlen(entry->buffer) - entry->select.start; - str2 = e_memdup(&(entry->buffer[entry->select.start]), len + 1); + str2 = e_util_memdup(&(entry->buffer[entry->select.start]), len + 1); str2[len] = 0; D_RETURN_(str2); } diff --git a/src/entry.h b/src/entry.h index 82c02aaff..c2f393e45 100644 --- a/src/entry.h +++ b/src/entry.h @@ -49,7 +49,7 @@ void e_entry_init(void); void e_entry_free(E_Entry *entry); E_Entry *e_entry_new(void); -void e_entry_handlecore_keypress(E_Entry *entry, Ecore_Event_Key_Down *e); +void e_entry_handle_keypress(E_Entry *entry, Ecore_Event_Key_Down *e); void e_entry_set_evas(E_Entry *entry, Evas evas); void e_entry_show(E_Entry *entry); void e_entry_hide(E_Entry *entry); diff --git a/src/exec.c b/src/exec.c index 9afef21d0..3f1b06f7b 100644 --- a/src/exec.c +++ b/src/exec.c @@ -25,7 +25,7 @@ e_exec_restart(void) D_ENTER; - printf("e_exec_restart()\n"); + D("e_exec_restart()\n"); /* unset events on root */ ecore_window_set_events(0, XEV_NONE); /* destroy all desktops */ @@ -107,14 +107,14 @@ e_exec_in_dir_with_env(char *exe, char *dir, int *launch_id_ret, char **env, cha { while (*env) { - e_set_env(env[0], env[1]); + e_util_set_env(env[0], env[1]); env += 2; } } /* launch Id hack - if it's an X program the windows popped up should */ /* have this launch Id number set on them - as well as process ID */ /* machine name, and user name */ - if (launch_path) e_set_env("E_HACK_LAUNCH_PATH", launch_path); + if (launch_path) e_util_set_env("E_HACK_LAUNCH_PATH", launch_path); sprintf(preload_paths, "E_HACK_LAUNCH_ID=%i LD_PRELOAD_PATH='%s'", launch_id, PACKAGE_LIB_DIR); sprintf(preload, "LD_PRELOAD='libehack.so libX11.so libdl.so'"); diff --git a/src/file.c b/src/file.c new file mode 100644 index 000000000..1ce3e8063 --- /dev/null +++ b/src/file.c @@ -0,0 +1,218 @@ +#include "debug.h" +#include "file.h" +#include "util.h" + +time_t +e_file_mod_time(char *file) +{ + struct stat st; + + D_ENTER; + + if (stat(file, &st) < 0) D_RETURN_(0); + + D_RETURN_(st.st_mtime); +} + +int +e_file_exists(char *file) +{ + struct stat st; + + D_ENTER; + + if (stat(file, &st) < 0) D_RETURN_(0); + + D_RETURN_(1); +} + +int +e_file_is_dir(char *file) +{ + struct stat st; + + D_ENTER; + + if (stat(file, &st) < 0) D_RETURN_(0); + if (S_ISDIR(st.st_mode)) D_RETURN_(1); + + D_RETURN_(0); +} + +static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + +int +e_file_mkdir(char *dir) +{ + D_ENTER; + + if (mkdir(dir, default_mode) < 0) D_RETURN_(0); + + D_RETURN_(1); +} + +int +e_file_cp(char *src, char *dst) +{ + FILE *f1, *f2; + char buf[16384]; + size_t num; + + D_ENTER; + + f1 = fopen(src, "rb"); + if (!f1) D_RETURN_(0); + f2 = fopen(dst, "wb"); + if (!f2) + { + fclose(f1); + D_RETURN_(0); + } + while ((num = fread(buf, 1, 16384, f1)) > 0) fwrite(buf, 1, num, f2); + fclose(f1); + fclose(f2); + + D_RETURN_(1); +} + +char * +e_file_realpath(char *file) +{ + char buf[PATH_MAX]; + char *f; + + D_ENTER; + + if (!realpath(file, buf)) D_RETURN_(strdup("")); + e_strdup(f, buf); + + D_RETURN_(f); +} + +char * +e_file_get_file(char *path) +{ + char *result = NULL; + + D_ENTER; + + if (!path) + D_RETURN_(NULL); + + if ((result = strrchr(path, '/'))) + result++; + else + result = path; + + D_RETURN_(result); +} + + +char * +e_file_get_dir(char *file) +{ + char *p; + char *f; + char buf[PATH_MAX]; + + D_ENTER; + + strcpy(buf, file); + p = strrchr(buf, '/'); + if (!p) + { + e_strdup(f, file); + D_RETURN_(f); + } + *p = 0; + e_strdup(f, buf); + + D_RETURN_(f); +} + +int +e_file_can_exec(struct stat *st) +{ + static int have_uid = 0; + static uid_t uid = -1; + static gid_t gid = -1; + int ok; + + D_ENTER; + + if (!st) D_RETURN_(0); + ok = 0; + if (!have_uid) uid = getuid(); + if (!have_uid) gid = getgid(); + have_uid = 1; + if (st->st_uid == uid) + { + if (st->st_mode & S_IXUSR) ok = 1; + } + else if (st->st_gid == gid) + { + if (st->st_mode & S_IXGRP) ok = 1; + } + else + { + if (st->st_mode & S_IXOTH) ok = 1; + } + + D_RETURN_(ok); +} + +char * +e_file_readlink(char *link) +{ + char buf[PATH_MAX]; + char *f; + int count; + + D_ENTER; + + if ((count = readlink(link, buf, sizeof(buf))) < 0) D_RETURN_(NULL); + buf[count] = 0; + e_strdup(f, buf); + + D_RETURN_(f); +} + +Evas_List +e_file_ls(char *dir) +{ + DIR *dirp; + struct dirent *dp; + Evas_List list; + + D_ENTER; + + dirp = opendir(dir); + if (!dirp) D_RETURN_(NULL); + list = NULL; + while ((dp = readdir(dirp))) + { + if ((strcmp(dp->d_name, ".")) && + (strcmp(dp->d_name, ".."))) + { + Evas_List l; + char *f; + + /* insertion sort */ + for (l = list; l; l = l->next) + { + if (strcmp(l->data, dp->d_name) > 0) + { + e_strdup(f, dp->d_name); + list = evas_list_prepend_relative(list, f, l->data); + break; + } + } + /* nowhwre to go? just append it */ + e_strdup(f, dp->d_name); + if (!l) list = evas_list_append(list, f); + } + } + closedir(dirp); + + D_RETURN_(list); +} diff --git a/src/file.h b/src/file.h new file mode 100644 index 000000000..0fb3f4886 --- /dev/null +++ b/src/file.h @@ -0,0 +1,39 @@ +#ifndef E_FILE_H +#define E_FILE_H + +#include "e.h" + +time_t e_file_mod_time(char *file); +int e_file_exists(char *file); +int e_file_is_dir(char *file); +int e_file_mkdir(char *dir); +int e_file_cp(char *src, char *dst); +char *e_file_realpath(char *file); + +/** + * e_file_get_file - returns file in a path + * @path: The chanonical path to a file + * + * This functions returns the file name (everything + * after the last "/") of a full path. It returns + * a pointer into the original string, so you don't + * need to free the result. + */ +char *e_file_get_file(char *path); + +/** + * e_file_get_dir - returns directory in a path + * @path: The chanonical path to a file + * + * This functions returns the directory name (everything + * before the last "/") of a full path. It returns + * a freshly allocated string, so you need to free + *the result. + */ +char *e_file_get_dir(char *path); + +int e_file_can_exec(struct stat *st); +char *e_file_readlink(char *link); +Evas_List e_file_ls(char *dir); + +#endif diff --git a/src/fs.c b/src/fs.c index 152dcfe61..d31e06903 100644 --- a/src/fs.c +++ b/src/fs.c @@ -8,8 +8,8 @@ static Evas_List fs_restart_handlers = NULL; static pid_t efsd_pid = 0; static void e_fs_child_handle(Ecore_Event *ev); -static void _e_fs_fd_handle(int fd); -static void _e_fs_restarter(int val, void *data); +static void e_fs_fd_handle(int fd); +static void e_fs_restarter(int val, void *data); static void e_fs_idle(void *data); static void e_fs_flush_timeout(int val, void *data); @@ -50,21 +50,21 @@ e_fs_child_handle(Ecore_Event *ev) D_ENTER; e = ev->event; - printf("pid went splat! (%i)\n", e->pid); + D("pid went splat! (%i)\n", e->pid); if (e->pid == efsd_pid) { - printf("it was efsd!\n"); + D("it was efsd!\n"); if (ec) efsd_close(ec); ec = NULL; efsd_pid = 0; - _e_fs_restarter(1, NULL); + e_fs_restarter(1, NULL); } D_RETURN; } static void -_e_fs_fd_handle(int fd) +e_fs_fd_handle(int fd) { double start, current; @@ -93,17 +93,17 @@ _e_fs_fd_handle(int fd) efsd_close(ec); ecore_del_event_fd(fd); ec = NULL; - _e_fs_restarter(0, NULL); + e_fs_restarter(0, NULL); /* FIXME: need to queue a popup dialog here saying */ /* efsd went wonky */ - printf("EEEEEEEEEEK efsd went wonky. Bye bye efsd.\n"); + D("EEEEEEEEEEK efsd went wonky. Bye bye efsd.\n"); } /* spent more thna 1/20th of a second here.. get out */ current = ecore_get_time(); if ((current - start) > 0.05) { - printf("fs... too much time spent..\n"); + D("fs... too much time spent..\n"); break; } } @@ -112,7 +112,7 @@ _e_fs_fd_handle(int fd) } static void -_e_fs_restarter(int val, void *data) +e_fs_restarter(int val, void *data) { D_ENTER; @@ -125,7 +125,7 @@ _e_fs_restarter(int val, void *data) if (efsd_pid <= 0) { efsd_pid = e_exec_run("efsd -f"); - printf("launch efsd... %i\n", efsd_pid); + D("launch efsd... %i\n", efsd_pid); } if (efsd_pid > 0) ec = efsd_open(); } @@ -133,7 +133,7 @@ _e_fs_restarter(int val, void *data) { Evas_List l; - ecore_add_event_fd(efsd_get_connection_fd(ec), _e_fs_fd_handle); + ecore_add_event_fd(efsd_get_connection_fd(ec), e_fs_fd_handle); for (l = fs_restart_handlers; l; l = l->next) { E_FS_Restarter *rs; @@ -148,7 +148,7 @@ _e_fs_restarter(int val, void *data) gap = (double)val / 10; if (gap > 10.0) gap = 10.0; - ecore_add_event_timer("e_fs_restarter", gap, _e_fs_restarter, val + 1, NULL); + ecore_add_event_timer("e_fs_restarter", gap, e_fs_restarter, val + 1, NULL); } D_RETURN; @@ -214,7 +214,7 @@ e_fs_init(void) writeable, and then calling efsd_flush(). */ ecore_event_filter_idle_handler_add(e_fs_idle, NULL); - _e_fs_restarter(0, NULL); + e_fs_restarter(0, NULL); D_RETURN; } diff --git a/src/icccm.c b/src/icccm.c index 80f720df8..efadaf1d7 100644 --- a/src/icccm.c +++ b/src/icccm.c @@ -180,7 +180,7 @@ e_icccm_get_pos_info(Window win, E_Border *b) { int x, y, w, h; - printf("%li %li\n", hint.flags & USPosition, hint.flags & PPosition); + D("%li %li\n", hint.flags & USPosition, hint.flags & PPosition); b->client.pos.requested = 1; b->client.pos.gravity = NorthWestGravity; if (hint.flags & PWinGravity) diff --git a/src/menu.c b/src/menu.c index dd814e746..43e238c78 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1207,7 +1207,7 @@ e_menu_hide(E_Menu *m) { D_ENTER; - printf("Menu hide!\n"); + D("Menu hide!\n"); if (m->selected) { diff --git a/src/menubuild.c b/src/menubuild.c index 79b1eae33..8574a8d29 100644 --- a/src/menubuild.c +++ b/src/menubuild.c @@ -3,6 +3,7 @@ #include "menubuild.h" #include "exec.h" #include "util.h" +#include "file.h" #ifdef USE_FERITE # include "e_ferite.h" @@ -47,7 +48,7 @@ e_build_menu_cb_script(E_Menu *m, E_Menu_Item *mi, void *data) script = data; e_ferite_run(script); #else - printf( "No cookies for you. You will have to install ferite.\n" ); + D("No cookies for you. You will have to install ferite.\n"); #endif D_RETURN; @@ -106,7 +107,7 @@ e_build_menu_db_poll(int val, void *data) D_ENTER; bm = data; - mod = e_file_modified_time(bm->file); + mod = e_file_mod_time(bm->file); if (mod <= bm->mod_time) { ecore_add_event_timer(bm->file, 1.0, e_build_menu_db_poll, 0, data); @@ -133,7 +134,7 @@ e_build_menu_gnome_apps_poll(int val, void *data) D_ENTER; bm = data; - mod = e_file_modified_time(bm->file); + mod = e_file_mod_time(bm->file); if (mod <= bm->mod_time) { ecore_add_event_timer(bm->file, 1.0, e_build_menu_gnome_apps_poll, 0, data); @@ -278,7 +279,7 @@ e_build_menu_gnome_apps_build_dir(E_Build_Menu *bm, char *dir) fclose(f); } /* read dir listing in alphabetical order and use that to suppliment */ - dirlist = e_file_list_dir(dir); + dirlist = e_file_ls(dir); for (l = dirlist; l; l = l->next) { char *s; @@ -353,8 +354,8 @@ e_build_menu_gnome_apps_build_dir(E_Build_Menu *bm, char *dir) buf[buf_len - 1] = 0; /* look for Name= */ if ((!name) && - (((e_glob_matches(buf, "Name[en]=*")) || - (e_glob_matches(buf, "Name=*"))))) + (((e_util_glob_matches(buf, "Name[en]=*")) || + (e_util_glob_matches(buf, "Name=*"))))) { char *eq; @@ -364,7 +365,7 @@ e_build_menu_gnome_apps_build_dir(E_Build_Menu *bm, char *dir) } /* look for Icon= */ else if ((!icon) && - ((e_glob_matches(buf, "Icon=*")))) + ((e_util_glob_matches(buf, "Icon=*")))) { char *eq; @@ -379,7 +380,7 @@ e_build_menu_gnome_apps_build_dir(E_Build_Menu *bm, char *dir) } /* look for Icon= */ else if ((!exe) && - ((e_glob_matches(buf, "Exec=*")))) + ((e_util_glob_matches(buf, "Exec=*")))) { char *eq; diff --git a/src/object.c b/src/object.c index dd2eaab7e..b658cde87 100644 --- a/src/object.c +++ b/src/object.c @@ -39,7 +39,7 @@ e_object_ref(E_Object *obj) D_RETURN; obj->references++; - printf("++ refcount on %p, now %i\n", obj, obj->references); + D("++ refcount on %p, now %i\n", obj, obj->references); D_RETURN; } @@ -54,11 +54,11 @@ e_object_unref(E_Object *obj) obj->references--; - printf("-- refcount on %p, now %i\n", obj, obj->references); + D("-- refcount on %p, now %i\n", obj, obj->references); if (obj->references == 0 && obj->cleanup_func) { - printf("Refcount is zero, freeing.\n"); + D("Refcount is zero, freeing.\n"); obj->cleanup_func(obj); D_RETURN_(0); } diff --git a/src/util.c b/src/util.c index 4931c2cb2..4513a9521 100644 --- a/src/util.c +++ b/src/util.c @@ -1,20 +1,8 @@ #include "debug.h" #include "util.h" -time_t -e_file_modified_time(char *file) -{ - struct stat st; - - D_ENTER; - - if (stat(file, &st) < 0) D_RETURN_(0); - - D_RETURN_(st.st_mtime); -} - void -e_set_env(char *variable, char *content) +e_util_set_env(char *variable, char *content) { char env[PATH_MAX]; @@ -26,33 +14,8 @@ e_set_env(char *variable, char *content) D_RETURN; } -int -e_file_exists(char *file) -{ - struct stat st; - - D_ENTER; - - if (stat(file, &st) < 0) D_RETURN_(0); - - D_RETURN_(1); -} - -int -e_file_is_dir(char *file) -{ - struct stat st; - - D_ENTER; - - if (stat(file, &st) < 0) D_RETURN_(0); - if (S_ISDIR(st.st_mode)) D_RETURN_(1); - - D_RETURN_(0); -} - char * -e_file_home(void) +e_util_get_user_home(void) { static char *home = NULL; @@ -66,99 +29,8 @@ e_file_home(void) D_RETURN_(home); } -static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - -int -e_file_mkdir(char *dir) -{ - D_ENTER; - - if (mkdir(dir, default_mode) < 0) D_RETURN_(0); - - D_RETURN_(1); -} - -int -e_file_cp(char *src, char *dst) -{ - FILE *f1, *f2; - char buf[16384]; - size_t num; - - D_ENTER; - - f1 = fopen(src, "rb"); - if (!f1) D_RETURN_(0); - f2 = fopen(dst, "wb"); - if (!f2) - { - fclose(f1); - D_RETURN_(0); - } - while ((num = fread(buf, 1, 16384, f1)) > 0) fwrite(buf, 1, num, f2); - fclose(f1); - fclose(f2); - - D_RETURN_(1); -} - -char * -e_file_real(char *file) -{ - char buf[PATH_MAX]; - char *f; - - D_ENTER; - - if (!realpath(file, buf)) D_RETURN_(strdup("")); - e_strdup(f, buf); - - D_RETURN_(f); -} - -char * -e_file_get_file(char *file) -{ - char *p; - char *f; - - D_ENTER; - - p = strrchr(file, '/'); - if (!p) - { - e_strdup(f, file); - D_RETURN_(f); - } - e_strdup(f, &(p[1])); - - D_RETURN_(f); -} - -char * -e_file_get_dir(char *file) -{ - char *p; - char *f; - char buf[PATH_MAX]; - - D_ENTER; - - strcpy(buf, file); - p = strrchr(buf, '/'); - if (!p) - { - e_strdup(f, file); - D_RETURN_(f); - } - *p = 0; - e_strdup(f, buf); - - D_RETURN_(f); -} - void * -e_memdup(void *data, int size) +e_util_memdup(void *data, int size) { void *data_dup; @@ -172,7 +44,7 @@ e_memdup(void *data, int size) } int -e_glob_matches(char *str, char *glob) +e_util_glob_matches(char *str, char *glob) { D_ENTER; @@ -181,89 +53,3 @@ e_glob_matches(char *str, char *glob) D_RETURN_(0); } -int -e_file_can_exec(struct stat *st) -{ - static int have_uid = 0; - static uid_t uid = -1; - static gid_t gid = -1; - int ok; - - D_ENTER; - - if (!st) D_RETURN_(0); - ok = 0; - if (!have_uid) uid = getuid(); - if (!have_uid) gid = getgid(); - have_uid = 1; - if (st->st_uid == uid) - { - if (st->st_mode & S_IXUSR) ok = 1; - } - else if (st->st_gid == gid) - { - if (st->st_mode & S_IXGRP) ok = 1; - } - else - { - if (st->st_mode & S_IXOTH) ok = 1; - } - - D_RETURN_(ok); -} - -char * -e_file_link(char *link) -{ - char buf[PATH_MAX]; - char *f; - int count; - - D_ENTER; - - if ((count = readlink(link, buf, sizeof(buf))) < 0) D_RETURN_(NULL); - buf[count] = 0; - e_strdup(f, buf); - - D_RETURN_(f); -} - -Evas_List -e_file_list_dir(char *dir) -{ - DIR *dirp; - struct dirent *dp; - Evas_List list; - - D_ENTER; - - dirp = opendir(dir); - if (!dirp) D_RETURN_(NULL); - list = NULL; - while ((dp = readdir(dirp))) - { - if ((strcmp(dp->d_name, ".")) && - (strcmp(dp->d_name, ".."))) - { - Evas_List l; - char *f; - - /* insertion sort */ - for (l = list; l; l = l->next) - { - if (strcmp(l->data, dp->d_name) > 0) - { - e_strdup(f, dp->d_name); - list = evas_list_prepend_relative(list, f, l->data); - break; - } - } - /* nowhwre to go? just append it */ - e_strdup(f, dp->d_name); - if (!l) list = evas_list_append(list, f); - } - } - closedir(dirp); - - D_RETURN_(list); -} diff --git a/src/util.h b/src/util.h index 3fa04e402..e00b3dad6 100644 --- a/src/util.h +++ b/src/util.h @@ -3,21 +3,10 @@ #include "e.h" -time_t e_file_modified_time(char *file); -void e_set_env(char *variable, char *content); -int e_file_exists(char *file); -int e_file_is_dir(char *file); -char *e_file_home(void); -int e_file_mkdir(char *dir); -int e_file_cp(char *src, char *dst); -char *e_file_real(char *file); -char *e_file_get_file(char *file); -char *e_file_get_dir(char *file); -void *e_memdup(void *data, int size); -int e_glob_matches(char *str, char *glob); -int e_file_can_exec(struct stat *st); -char *e_file_link(char *link); -Evas_List e_file_list_dir(char *dir); +void e_util_set_env(char *variable, char *content); +char *e_util_get_user_home(void); +void *e_util_memdup(void *data, int size); +int e_util_glob_matches(char *str, char *glob); #define e_strdup(__dest, __var) \ { \ diff --git a/src/view.c b/src/view.c index c13dcd0c4..37e0c037a 100644 --- a/src/view.c +++ b/src/view.c @@ -10,6 +10,7 @@ #include "menu.h" #include "menubuild.h" #include "fs.h" +#include "file.h" #include "util.h" static Evas_List views = NULL; @@ -72,7 +73,7 @@ e_view_write_icon_xy_timeout(int val, void *data) ic->q.write_xy = 0; sprintf(buf, "%s/%s", ic->view->dir, ic->file); - printf("write meta xy for icon for file %s\n", ic->file); + D("write meta xy for icon for file %s\n", ic->file); efsd_set_metadata_int(e_fs_get_connection(), "/pos/x", buf, ic->geom.x); @@ -83,6 +84,7 @@ e_view_write_icon_xy_timeout(int val, void *data) } D_RETURN; + UN(val); } void @@ -489,7 +491,7 @@ e_view_icon_update_state(E_Icon *ic) if (!ic->info.icon) { - printf("EEEEEEEEEEK %s has no icon\n", ic->file); + D("EEEEEEEEEEK %s has no icon\n", ic->file); D_RETURN; } if (ic->state.clicked) @@ -662,7 +664,8 @@ e_view_icon_exec(E_Icon *ic) { D_ENTER; - if (!strcmp(ic->info.mime.base, "dir")) + if (!strcmp(ic->info.mime.base, "dir") && + e_file_can_exec(&ic->stat)) { E_View *v; char buf[PATH_MAX]; @@ -680,7 +683,7 @@ e_view_icon_exec(E_Icon *ic) v->bg = e_background_load(buf); } sprintf(buf, "%s/%s", ic->view->dir, ic->file); - printf("new dir >%s<\n", buf); + D("new dir >%s<\n", buf); v->dir = strdup(buf); e_view_realize(v); ecore_window_set_title(v->win.base, ic->file); @@ -1068,7 +1071,7 @@ e_icon_move_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y) Evas_List ll; v = l->data; - printf("sel count %i\n", v->sel_count); + D("sel count %i\n", v->sel_count); if (v->sel_count > 0) { for (ll = v->icons; ll; ll = ll->next) @@ -1163,7 +1166,7 @@ e_icon_move_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y) icy = iy + v->location.y - wy; if (!ic->info.icon) { - printf("EEEEEEEEEEK %s has no icon\n", ic->file); + D("EEEEEEEEEEK %s has no icon\n", ic->file); D_RETURN; } if (ic->state.clicked) @@ -1196,7 +1199,7 @@ e_icon_move_cb(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y) } else { - printf("eek cant load\n"); + D("eek cant load\n"); } } } @@ -1346,10 +1349,10 @@ e_configure(Ecore_Event * ev) if (e->win == v->win.base) { /* win, root, x, y, w, h, wm_generated */ - printf("configure for view %s\n", v->dir); + D("configure for view %s\n", v->dir); if (e->wm_generated) { - printf("wm generated %i %i, %ix%i\n", e->x, e->y, e->w, e->h); + D("wm generated %i %i, %ix%i\n", e->x, e->y, e->w, e->h); if ((e->x != v->location.x) || (e->y != v->location.y)) { v->location.x = e->x; @@ -1357,11 +1360,11 @@ e_configure(Ecore_Event * ev) e_view_queue_geometry_record(v); } } - printf("size %ix%i\n", e->w, e->h); + D("size %ix%i\n", e->w, e->h); if ((e->w != v->size.w) || (e->h != v->size.h) || (v->size.force)) { v->size.force = 0; - printf("... a new size!\n"); + D("... a new size!\n"); v->size.w = e->w; v->size.h = e->h; if (v->pmap) ecore_pixmap_free(v->pmap); @@ -1380,7 +1383,7 @@ e_configure(Ecore_Event * ev) { e_background_set_size(v->bg, v->size.w, v->size.h); } - printf("evas_set_output_viewpor(%p)\n", v->evas); + D("evas_set_output_viewpor(%p)\n", v->evas); evas_set_output_viewport(v->evas, 0, 0, v->size.w, v->size.h); evas_set_output_size(v->evas, v->size.w, v->size.h); e_view_scroll_to(v, v->scroll.x, v->scroll.y); @@ -1806,7 +1809,7 @@ e_view_handle_fs_restart(void *data) v = data; - printf("e_view_handle_fs_restart\n"); + D("e_view_handle_fs_restart\n"); for (l = v->icons; l; l = l->next) { icons = evas_list_prepend(icons, l->data); @@ -1849,7 +1852,7 @@ e_view_handle_fs_restart(void *data) } v->is_listing = 1; } - printf("restarted monitor id (connection = %p), %i for %s\n", e_fs_get_connection(), v->monitor_id, v->dir); + D("restarted monitor id (connection = %p), %i for %s\n", e_fs_get_connection(), v->monitor_id, v->dir); v->is_listing = 1; D_RETURN; @@ -1922,8 +1925,11 @@ void e_view_icon_show(E_Icon *ic) { D_ENTER; + + D("SHOWING ICON\n"); if (ic->state.visible) D_RETURN; + D("SHOWING ICON REALLY\n"); ic->state.visible = 1; if (!ic->obj.event1) { @@ -2067,6 +2073,27 @@ e_view_icon_apply_xy(E_Icon *ic) D_RETURN; } + +void +e_view_icon_check_permissions(E_Icon *ic) +{ + D_ENTER; + + if (!ic || !ic->info.mime.base || ic->stat.st_ino == 0) + D_RETURN; + + if (!strcmp(ic->info.mime.base, "dir")) + { + if (e_file_can_exec(&ic->stat)) + evas_set_color(ic->view->evas, ic->obj.icon, 255, 255, 255, 255); + else + evas_set_color(ic->view->evas, ic->obj.icon, 128, 128, 128, 128); + } + + D_RETURN; +} + + static int e_view_restart_alphabetical_qsort_cb(const void *data1, const void *data2) { @@ -2093,7 +2120,7 @@ e_view_resort_alphabetical(E_View *v) for (count = 0, l = v->icons; l; l = l->next) count++; array = malloc(sizeof(E_Icon *) * count); for (i = 0, l = v->icons; l; l = l->next) array[i++] = l->data; - printf("qsort %i elements...\n", count); + D("qsort %i elements...\n", count); qsort(array, count, sizeof(E_Icon *), e_view_restart_alphabetical_qsort_cb); for (i = 0; i < count; i++) icons = evas_list_append(icons, array[i]); @@ -2102,7 +2129,7 @@ e_view_resort_alphabetical(E_View *v) evas_list_free(v->icons); v->icons = icons; - printf("done...\n"); + D("done...\n"); D_RETURN; } @@ -2207,10 +2234,12 @@ e_view_icon_initial_show(E_Icon *ic) { D_ENTER; + D("INITIAL SHOWING ICON\n"); /* check if we have enuf info and we havent been shown yet */ if (!ic->info.icon) D_RETURN; if (ic->state.visible) D_RETURN; + D("INITIAL SHOWING ICON REALLY\n"); /* first. lets figure out the size of the icon */ evas_get_image_size(ic->view->evas, ic->obj.icon, &(ic->geom.icon.w), &(ic->geom.icon.h)); @@ -2255,7 +2284,7 @@ e_view_icon_set_mime(E_Icon *ic, char *base, char *mime) ic->info.mime.base = strdup(base); ic->info.mime.type = strdup(mime); - printf("%40s: %s/%s\n", ic->file, base, mime); + D("%40s: %s/%s\n", ic->file, base, mime); /* effect changes here */ if (ic->info.custom_icon) @@ -2340,9 +2369,9 @@ e_view_file_added(int id, char *file) D_ENTER; - /* if we get a path - ignore it - its not a file in the a dir */ + /* if we get a path - ignore it - its not a file in the dir */ if (!file) D_RETURN; -/* printf("FILE ADD: %s\n", file);*/ + /* D("FILE ADD: %s\n", file);*/ if (file[0] == '/') D_RETURN; v = e_view_find_by_monitor_id(id); if (!v) D_RETURN; @@ -2430,7 +2459,7 @@ e_view_file_moved(int id, char *file) /* never gets called ? */ if (!file) D_RETURN; - printf(".!WOW!. e_view_file_moved(%i, %s);\n", id, file); + D(".!WOW!. e_view_file_moved(%i, %s);\n", id, file); if (file[0] == '/') D_RETURN; v = e_view_find_by_monitor_id(id); if (!v) D_RETURN; @@ -2575,7 +2604,7 @@ e_view_set_dir(E_View *v, char *dir) v->monitor_id = 0; } IF_FREE(v->dir); - v->dir = e_file_real(dir); + v->dir = e_file_realpath(dir); /* start monitoring new dir */ v->restarter = e_fs_add_restart_handler(e_view_handle_fs_restart, v); if (e_fs_get_connection()) @@ -2600,7 +2629,7 @@ e_view_set_dir(E_View *v, char *dir) v->monitor_id = efsd_start_monitor(e_fs_get_connection(), v->dir, ops, TRUE); } - printf("monitor id for %s = %i\n", v->dir, v->monitor_id); + D("monitor id for %s = %i\n", v->dir, v->monitor_id); v->is_listing = 1; v->changed = 1; } @@ -2768,35 +2797,35 @@ e_view_handle_fs(EfsdEvent *ev) switch (ev->efsd_filechange_event.changetype) { case EFSD_FILE_CREATED: -/* printf("EFSD_FILE_CREATED: %i %s\n", +/* D("EFSD_FILE_CREATED: %i %s\n", ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); */ e_view_file_added(ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); break; case EFSD_FILE_EXISTS: -/* printf("EFSD_FILE_EXISTS: %i %s\n", + /* D("EFSD_FILE_EXISTS: %i %s\n", ev->efsd_filechange_event.id, - ev->efsd_filechange_event.file); -*/ e_view_file_added(ev->efsd_filechange_event.id, + ev->efsd_filechange_event.file); */ + e_view_file_added(ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); break; case EFSD_FILE_DELETED: -/* printf("EFSD_FILE_DELETED: %i %s\n", +/* D("EFSD_FILE_DELETED: %i %s\n", ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); */ e_view_file_deleted(ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); break; case EFSD_FILE_CHANGED: -/* printf("EFSD_CHANGE_CHANGED: %i %s\n", +/* D("EFSD_CHANGE_CHANGED: %i %s\n", ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); */ e_view_file_changed(ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); break; case EFSD_FILE_MOVED: -/* printf("EFSD_CHANGE_MOVED: %i %s\n", +/* D("EFSD_CHANGE_MOVED: %i %s\n", ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); */ e_view_file_moved(ev->efsd_filechange_event.id, @@ -2806,9 +2835,9 @@ e_view_handle_fs(EfsdEvent *ev) { E_View *v; - v = e_view_find_by_monitor_id(ev->efsd_filechange_event.id); + v = e_view_find_by_monitor_id(efsd_reply_id(ev)); if (v) v->is_listing = 0; -/* printf("EFSD_CHANGE_END_EXISTS: %i %s\n", +/* D("EFSD_CHANGE_END_EXISTS: %i %s\n", ev->efsd_filechange_event.id, ev->efsd_filechange_event.file); */ } @@ -2833,23 +2862,21 @@ e_view_handle_fs(EfsdEvent *ev) case EFSD_CMD_CHMOD: break; case EFSD_CMD_GETFILETYPE: -/* printf("Getmime event %i\n", + D("Getmime event %i\n", ev->efsd_reply_event.command.efsd_file_cmd.id); -*/ if (ev->efsd_reply_event.errorcode == 0) + if (ev->efsd_reply_event.errorcode == 0) { E_Icon *ic; E_View *v; - char *file, *file2; + char *file; file = NULL; - if (ev->efsd_reply_event.command.efsd_file_cmd.files) - file = ev->efsd_reply_event.command.efsd_file_cmd.files[0]; - if (file) + if ( (file = efsd_reply_filename(ev)) ) { - file2 = strrchr(file, '/'); - if (file2) file = file2 + 1; + file = e_file_get_file(file); } - v = e_view_find_by_monitor_id(ev->efsd_reply_event.command.efsd_file_cmd.id); + v = e_view_find_by_monitor_id(efsd_reply_id(ev)); + if ((v) && (file)) { ic = e_view_find_icon_by_file(v, file); @@ -2873,17 +2900,46 @@ e_view_handle_fs(EfsdEvent *ev) strcpy(base, m); strcpy(mime, "unknown"); } -/* printf("MIME: %s\n", m); +/* D("MIME: %s\n", m); */ e_view_icon_set_mime(ic, base, mime); + + /* Try to update the GUI according to the file permissions. + It's just a try because we need to have the file's stat + info as well. + */ + e_view_icon_check_permissions(ic); + D("GOT THERE!"); e_view_icon_initial_show(ic); } } } break; case EFSD_CMD_STAT: -/* printf("Stat event %i\n", - ev->efsd_reply_event.command.efsd_file_cmd.id); -*/ { + D("Stat event %i on %s\n", + efsd_reply_id(ev), efsd_reply_filename(ev)); + + /* When everything went okay and we can find a view and an icon, + set the file stat data for the icon. Then try to check the + permissions and possibly update the gui. It's just a try + because we need to have received the filetype info too. + */ + if (ev->efsd_reply_event.errorcode == 0) + { + E_Icon *ic; + E_View *v; + + v = e_view_find_by_monitor_id(efsd_reply_id(ev)); + + if (v) + { + ic = e_view_find_icon_by_file(v, e_file_get_file(efsd_reply_filename(ev))); + + if (ic) + { + ic->stat = *((struct stat*)efsd_reply_data(ev)); + e_view_icon_check_permissions(ic); + } + } } break; case EFSD_CMD_READLINK: @@ -2892,23 +2948,20 @@ e_view_handle_fs(EfsdEvent *ev) E_Icon *ic; E_View *v; - char *file, *file2; + char *file; file = NULL; - if (ev->efsd_reply_event.command.efsd_file_cmd.files) - file = ev->efsd_reply_event.command.efsd_file_cmd.files[0]; - if (file) + if ( (file = efsd_reply_filename(ev)) ) { - file2 = strrchr(file, '/'); - if (file2) file = file2 + 1; + file = e_file_get_file(file); } - v = e_view_find_by_monitor_id(ev->efsd_reply_event.command.efsd_file_cmd.id); + v = e_view_find_by_monitor_id(efsd_reply_id(ev)); if ((v) && (file)) { ic = e_view_find_icon_by_file(v, file); if ((ic) && (ev->efsd_reply_event.data)) - e_view_icon_set_link(ic, (char*)ev->efsd_reply_event.data); + e_view_icon_set_link(ic, (char*)efsd_reply_data(ev)); e_view_icon_initial_show(ic); } } @@ -2918,13 +2971,13 @@ e_view_handle_fs(EfsdEvent *ev) case EFSD_CMD_SETMETA: break; case EFSD_CMD_GETMETA: - printf("Getmeta event %i\n", - ev->efsd_reply_event.command.efsd_get_metadata_cmd.id); + /* D("Getmeta event %i\n", + efsd_reply_id(ev));*/ { Evas_List l; EfsdCmdId cmd; - cmd = ev->efsd_reply_event.command.efsd_get_metadata_cmd.id; + cmd = efsd_reply_id(ev); for (l = views; l; l = l->next) { E_View *v; @@ -3023,7 +3076,7 @@ e_view_handle_fs(EfsdEvent *ev) struct stat st; if (stat(efsd_metadata_get_str(ev), &st) != -1 ) { - printf("Attempted to set background for: %s\n", v->dir); + D("Attempted to set background for: %s\n", v->dir); v->bg = e_background_load(efsd_metadata_get_str(ev)); e_background_realize(v->bg, v->evas); e_background_set_size(v->bg, v->size.w, v->size.h); @@ -3052,15 +3105,13 @@ e_view_handle_fs(EfsdEvent *ev) } } } - /* - */ break; case EFSD_CMD_STARTMON_DIR: -/* printf("Startmon event %i\n", +/* D("Startmon event %i\n", ev->efsd_reply_event.command.efsd_file_cmd.id); */ break; case EFSD_CMD_STARTMON_FILE: -/* printf("Startmon file event %i\n", +/* D("Startmon file event %i\n", ev->efsd_reply_event.command.efsd_file_cmd.id); */ break; case EFSD_CMD_STOPMON_DIR: diff --git a/src/view.h b/src/view.h index d11565078..719aaaeb7 100644 --- a/src/view.h +++ b/src/view.h @@ -149,7 +149,8 @@ struct _E_Icon { E_Object o; - char *file; + char *file; + struct stat stat; E_View *view; @@ -230,7 +231,16 @@ void e_view_icon_update_state(E_Icon *ic); void e_view_icon_invert_selection(E_Icon *ic); void e_view_icon_select(E_Icon *ic); void e_view_icon_deselect(E_Icon *ic); + +/** + * e_view_icon_exec - handles execution paths when user activates an icon + * @ic: The activated icon + * + * This function takes care of opening views when the user activates a + * directory, launching commands when an executable is activated etc. + */ void e_view_icon_exec(E_Icon *ic); + void e_view_icon_initial_show(E_Icon *ic); void e_view_icon_set_mime(E_Icon *ic, char *base, char *mime); void e_view_icon_set_link(E_Icon *ic, char *link); @@ -239,6 +249,7 @@ E_Icon *e_view_find_icon_by_file(E_View *view, char *file); void e_view_icon_show(E_Icon *ic); void e_view_icon_hide(E_Icon *ic); void e_view_icon_apply_xy(E_Icon *ic); +void e_view_icon_check_permissions(E_Icon *ic); void e_view_resort_alphabetical(E_View *v); void e_view_arrange(E_View *v); void e_view_resort(E_View *v); @@ -250,10 +261,39 @@ void e_view_file_deleted(int id, char *file); void e_view_file_changed(int id, char *file); void e_view_file_moved(int id, char *file); E_View *e_view_find_by_monitor_id(int id); + +/** + * e_view_new - Creates a new view object + * + * This function creates a new view and sets default + * properties on it, such as colors and icon spacings. + */ E_View *e_view_new(void); + void e_view_set_background(E_View *v); + +/** + * e_view_set_dir - Sets view to a given directory + * @v The view for which to set the directory + * @dir The directory to set the view to + * + * This function sets a view to a directory, loading the + * view's metadata (view window coordinates etc) from that + * directory, it also requests monitoring of the files in + * the directory @dir from efsd. + */ void e_view_set_dir(E_View *v, char *dir); + +/** + * e_view_realize - Initializes a view's graphics and content + * @v: The view to initialize + * + * This function initializes a created view by loading + * all the graphics, and sets the view to a given directory + * by calling e_view_set_dir(). + */ void e_view_realize(E_View *v); + void e_view_update(E_View *v); #endif