From a55cd9d21192676802cf6f34719e7d8a78b95b1e Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 21 Aug 1999 16:03:08 +0000 Subject: [PATCH] r70: Removed some old code. Dragging now quotes the correct MIME type for files. Unused menu entries now give a message. --- ROX-Filer/src/dnd.c | 37 +++++++++++------------- ROX-Filer/src/filer.c | 23 ++++----------- ROX-Filer/src/filer.h | 2 +- ROX-Filer/src/main.c | 20 ++++--------- ROX-Filer/src/menu.c | 78 +++++++++++++++++++++++++++------------------------ ROX-Filer/src/type.c | 15 ++++++++++ ROX-Filer/src/type.h | 1 + 7 files changed, 85 insertions(+), 91 deletions(-) diff --git a/ROX-Filer/src/dnd.c b/ROX-Filer/src/dnd.c index bc0ad831..214fc166 100644 --- a/ROX-Filer/src/dnd.c +++ b/ROX-Filer/src/dnd.c @@ -348,7 +348,7 @@ static void create_uri_list(GString *string, * start a drag. * * We always provide text/uri-list. If we are dragging a single, regular file - * then we also offer application/octet-stream. + * then we also offer application/octet-stream and the type of the file. */ void drag_selection(Collection *collection, GdkEventMotion *event, @@ -364,6 +364,7 @@ void drag_selection(Collection *collection, { {"text/uri-list", 0, TARGET_URI_LIST}, {"application/octet-stream", 0, TARGET_RAW}, + {"", 0, TARGET_RAW}, }; FileItem *item; @@ -374,8 +375,17 @@ void drag_selection(Collection *collection, widget = GTK_WIDGET(collection); - target_list = gtk_target_list_new(target_table, - item && item->base_type == TYPE_FILE ? 2 : 1); + if (item && item->mime_type) + { + MIME_type *t = item->mime_type; + + target_table[2].target = g_strconcat(t->media_type, "/", + t->subtype, NULL); + target_list = gtk_target_list_new(target_table, 3); + g_free(target_table[2].target); + } + else + target_list = gtk_target_list_new(target_table, 1); context = gtk_drag_begin(widget, target_list, @@ -423,7 +433,10 @@ void drag_data_get(GtkWidget *widget, &to_send, &to_send_length)) { delete_once_sent = TRUE; - type = application_octet_stream; /* XXX */ + if (item->mime_type) + type = type_to_atom(item->mime_type); + else + type = application_octet_stream; break; } return; @@ -908,7 +921,6 @@ static void got_uri_list(GtkWidget *widget, FilerWindow *filer_window; GSList *uri_list; char *error = NULL; - char **argv = NULL; /* Command to exec, or NULL */ GSList *next_uri; gboolean send_reply = TRUE; char *dest_path; @@ -1000,22 +1012,7 @@ static void got_uri_list(GtkWidget *widget, delayed_error("Error getting file list", error); } else if (send_reply) - { gtk_drag_finish(context, TRUE, FALSE, time); /* Success! */ - if (argv) - { - int child; /* Child process ID */ - - child = spawn(argv); - if (child) - g_hash_table_insert(child_to_filer, - (gpointer) child, filer_window); - else - delayed_error("ROX-Filer", - "Failed to fork() child process"); - g_free(argv); - } - } next_uri = uri_list; while (next_uri) diff --git a/ROX-Filer/src/filer.c b/ROX-Filer/src/filer.c index e87a49d0..f5bdef07 100644 --- a/ROX-Filer/src/filer.c +++ b/ROX-Filer/src/filer.c @@ -36,11 +36,6 @@ FilerWindow *window_with_focus = NULL; -/* When a child process that changes a directory dies we need to know - * which filer window to update. Use this table. - */ -GHashTable *child_to_filer = NULL; - /* Link paths to GLists of filer windows */ GHashTable *path_to_window_list = NULL; @@ -84,7 +79,6 @@ void filer_init() { xa_string = gdk_atom_intern("STRING", FALSE); - child_to_filer = g_hash_table_new(NULL, NULL); path_to_window_list = g_hash_table_new(g_str_hash, g_str_equal); } @@ -122,14 +116,6 @@ static void remove_view(FilerWindow *filer_window) newlist); } -/* When a filer window is destroyed we call this for each entry in the - * child_to_filer hash table to remove old entries. - */ -static gboolean child_eq(gpointer key, gpointer data, gpointer filer_window) -{ - return data == filer_window; -} - /* Go though all the FileItems in a collection, freeing all the temp * icons. * TODO: Maybe we should cache icons? @@ -167,7 +153,6 @@ static void filer_window_destroyed(GtkWidget *widget, } remove_view(filer_window); - g_hash_table_foreach_remove(child_to_filer, child_eq, filer_window); free_temp_icons(filer_window); if (filer_window->dir) @@ -292,8 +277,7 @@ static void add_item(FilerWindow *filer_window, char *leafname) } item->base_type = base_type; - - item->mime_type = type_from_path(path->str); + item->mime_type = NULL; if (base_type == TYPE_DIRECTORY) { @@ -330,6 +314,7 @@ static void add_item(FilerWindow *filer_window, char *leafname) } else if (base_type == TYPE_FILE) { + item->mime_type = type_from_path(path->str); item->image = type_to_icon(filer_window->window, item->mime_type); } @@ -724,7 +709,9 @@ void open_item(Collection *collection, GString *message; MIME_type *type = item->mime_type; - if (type && type_open(full_path, type)) + g_return_if_fail(type != NULL); + + if (type_open(full_path, type)) { if (adjust && !filer_window->panel) gtk_widget_destroy(widget); diff --git a/ROX-Filer/src/filer.h b/ROX-Filer/src/filer.h index b530e449..631b0443 100644 --- a/ROX-Filer/src/filer.h +++ b/ROX-Filer/src/filer.h @@ -58,7 +58,7 @@ struct _FileItem char *leafname; int base_type; /* (regular file, dir, pipe, etc) */ - MIME_type *mime_type; /* only valid for files */ + MIME_type *mime_type; /* NULL, except for non-exec files */ ItemFlags flags; int text_width; diff --git a/ROX-Filer/src/main.c b/ROX-Filer/src/main.c index 5ec11124..e763f9ea 100644 --- a/ROX-Filer/src/main.c +++ b/ROX-Filer/src/main.c @@ -29,31 +29,20 @@ int number_of_windows = 0; /* Quit when this reaches 0 again... */ -/* XXX: Maybe we shouldn't do so much work in a signal handler? */ static void child_died(int signum) { int status; int child; - FilerWindow *filer_window; - /* Find out which children exited. This also has the effect of - * allowing the children to die. - */ + /* Find out which children exited and allow them to die */ do { - child = waitpid(-1, &status, WNOHANG | WUNTRACED); + child = waitpid(-1, &status, WNOHANG); if (child == 0 || child == -1) return; - filer_window = g_hash_table_lookup(child_to_filer, - (gpointer) child); - if (filer_window) - scan_dir(filer_window); - - if (!WIFSTOPPED(status)) - g_hash_table_remove(child_to_filer, - (gpointer) child); + /* fprintf(stderr, "Child %d exited\n", child); */ } while (1); } @@ -105,9 +94,10 @@ int main(int argc, char **argv) options_load(); + /* Let child processes die */ act.sa_handler = child_died; sigemptyset(&act.sa_mask); - act.sa_flags = 0; + act.sa_flags = SA_NOCLDSTOP; sigaction(SIGCHLD, &act, NULL); if (geteuid() == 0) diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index c31118da..bd2c6601 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -47,6 +47,8 @@ static void menu_closed(GtkWidget *widget); static void items_sensitive(GtkWidget *menu, int from, int n, gboolean state); static char *load_xterm_here(char *data); +static void not_yet(gpointer data, guint action, GtkWidget *widget); + static void hidden(gpointer data, guint action, GtkWidget *widget); static void refresh(gpointer data, guint action, GtkWidget *widget); @@ -90,17 +92,19 @@ static GtkWidget *panel_menu; /* The popup panel menu */ static GtkWidget *panel_file_item; /* The File '' label */ static GtkWidget *panel_file_menu; /* The File '' menu */ +static gint screen_width, screen_height; + static GtkItemFactoryEntry filer_menu_def[] = { {"/Display", NULL, NULL, 0, ""}, -{"/Display/Large Icons", NULL, NULL, 0, ""}, -{"/Display/Small Icons", NULL, NULL, 0, "/Display/Large Icons"}, -{"/Display/Full Info", NULL, NULL, 0, "/Display/Large Icons"}, -{"/Display/Separator", NULL, NULL, 0, ""}, -{"/Display/Sort by Name", NULL, NULL, 0, ""}, -{"/Display/Sort by Type", NULL, NULL, 0, "/Display/Sort by Name"}, -{"/Display/Sort by Date", NULL, NULL, 0, "/Display/Sort by Name"}, -{"/Display/Sort by Size", NULL, NULL, 0, "/Display/Sort by Name"}, -{"/Display/Sort by Owner", NULL, NULL, 0, "/Display/Sort by Name"}, +{"/Display/Large Icons", NULL, not_yet, 0, ""}, +{"/Display/Small Icons", NULL, not_yet, 0, "/Display/Large Icons"}, +{"/Display/Full Info", NULL, not_yet, 0, "/Display/Large Icons"}, +{"/Display/Separator", NULL, not_yet, 0, ""}, +{"/Display/Sort by Name", NULL, not_yet, 0, ""}, +{"/Display/Sort by Type", NULL, not_yet, 0, "/Display/Sort by Name"}, +{"/Display/Sort by Date", NULL, not_yet, 0, "/Display/Sort by Name"}, +{"/Display/Sort by Size", NULL, not_yet, 0, "/Display/Sort by Name"}, +{"/Display/Sort by Owner", NULL, not_yet, 0, "/Display/Sort by Name"}, {"/Display/Separator", NULL, NULL, 0, ""}, {"/Display/Show Hidden", C_"H", hidden, 0, ""}, {"/Display/Refresh", C_"L", refresh, 0, NULL}, @@ -113,10 +117,10 @@ static GtkItemFactoryEntry filer_menu_def[] = { {"/File/Separator", NULL, NULL, 0, ""}, {"/File/Mount", C_"M", mount, 0, NULL}, {"/File/Delete", C_"X", delete, 0, NULL}, -{"/File/Disk Usage", C_"U", NULL, 0, NULL}, -{"/File/Permissions", NULL, NULL, 0, NULL}, -{"/File/Touch", NULL, NULL, 0, NULL}, -{"/File/Find", NULL, NULL, 0, NULL}, +{"/File/Disk Usage", C_"U", not_yet, 0, NULL}, +{"/File/Permissions", NULL, not_yet, 0, NULL}, +{"/File/Touch", NULL, not_yet, 0, NULL}, +{"/File/Find", NULL, not_yet, 0, NULL}, {"/Select All", C_"A", select_all, 0, NULL}, {"/Clear Selection", C_"Z", clear_selection, 0, NULL}, {"/Options...", NULL, show_options, 0, NULL}, @@ -127,15 +131,15 @@ static GtkItemFactoryEntry filer_menu_def[] = { static GtkItemFactoryEntry panel_menu_def[] = { {"/Display", NULL, NULL, 0, ""}, -{"/Display/Large Icons", NULL, NULL, 0, ""}, -{"/Display/Small Icons", NULL, NULL, 0, "/Display/Large Icons"}, -{"/Display/Full Info", NULL, NULL, 0, "/Display/Large Icons"}, +{"/Display/Large Icons", NULL, not_yet, 0, ""}, +{"/Display/Small Icons", NULL, not_yet, 0, "/Display/Large Icons"}, +{"/Display/Full Info", NULL, not_yet, 0, "/Display/Large Icons"}, {"/Display/Separator", NULL, NULL, 0, ""}, -{"/Display/Sort by Name", NULL, NULL, 0, ""}, -{"/Display/Sort by Type", NULL, NULL, 0, "/Display/Sort by Name"}, -{"/Display/Sort by Date", NULL, NULL, 0, "/Display/Sort by Name"}, -{"/Display/Sort by Size", NULL, NULL, 0, "/Display/Sort by Name"}, -{"/Display/Sort by Owner", NULL, NULL, 0, "/Display/Sort by Name"}, +{"/Display/Sort by Name", NULL, not_yet, 0, ""}, +{"/Display/Sort by Type", NULL, not_yet, 0, "/Display/Sort by Name"}, +{"/Display/Sort by Date", NULL, not_yet, 0, "/Display/Sort by Name"}, +{"/Display/Sort by Size", NULL, not_yet, 0, "/Display/Sort by Name"}, +{"/Display/Sort by Owner", NULL, not_yet, 0, "/Display/Sort by Name"}, {"/Display/Separator", NULL, NULL, 0, ""}, {"/Display/Show Hidden", NULL, hidden, 0, ""}, {"/Display/Refresh", NULL, refresh, 0, NULL}, @@ -153,6 +157,11 @@ void menu_init() char *menurc; GList *items; + /* This call starts returning strange values after a while, so get + * the result here during init. + */ + gdk_window_get_size(GDK_ROOT_PARENT(), &screen_width, &screen_height); + filer_keys = gtk_accel_group_new(); item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "", @@ -278,36 +287,26 @@ static void items_sensitive(GtkWidget *menu, int from, int n, gboolean state) static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data) { int *pos = (int *) data; - int swidth, sheight; GtkRequisition requisition; - gdk_window_get_size(GDK_ROOT_PARENT(), &swidth, &sheight); - /* XXX: GDK sometimes seems to get the height wrong... */ - if (sheight < 2) - { - g_print("ROX-Filer: Root window height reported as %d\n", - sheight); - sheight = 768; - } - gtk_widget_size_request(GTK_WIDGET(menu), &requisition); if (pos[0] == -1) - *x = swidth - MENU_MARGIN - requisition.width; + *x = screen_width - MENU_MARGIN - requisition.width; else if (pos[0] == -2) *x = MENU_MARGIN; else *x = pos[0] - (requisition.width >> 2); if (pos[1] == -1) - *y = sheight - MENU_MARGIN - requisition.height; + *y = screen_height - MENU_MARGIN - requisition.height; else if (pos[1] == -2) *y = MENU_MARGIN; else *y = pos[1] - (requisition.height >> 2); - *x = CLAMP(*x, 0, swidth - requisition.width); - *y = CLAMP(*y, 0, sheight - requisition.height); + *x = CLAMP(*x, 0, screen_width - requisition.width); + *y = CLAMP(*y, 0, screen_height - requisition.height); } void show_filer_menu(FilerWindow *filer_window, GdkEventButton *event, @@ -407,6 +406,12 @@ static void menu_closed(GtkWidget *widget) /* Actions */ +/* Fake action to warn when a menu item does nothing */ +static void not_yet(gpointer data, guint action, GtkWidget *widget) +{ + delayed_error("ROX-Filer", "Sorry, that feature isn't implemented yet"); +} + static void hidden(gpointer data, guint action, GtkWidget *widget) { g_return_if_fail(window_with_focus != NULL); @@ -614,8 +619,7 @@ static void show_file_info(gpointer data, guint action, GtkWidget *widget) label = gtk_label_new("MIME type:"); gtk_misc_set_alignment(GTK_MISC(label), 1, .5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); - if (file->base_type == TYPE_FILE && - !(file->flags & ITEM_FLAG_EXEC_FILE)) + if (file->mime_type) { string = g_strconcat(file->mime_type->media_type, "/", file->mime_type->subtype, NULL); diff --git a/ROX-Filer/src/type.c b/ROX-Filer/src/type.c index 16560ae8..113918ee 100644 --- a/ROX-Filer/src/type.c +++ b/ROX-Filer/src/type.c @@ -253,3 +253,18 @@ MaskedPixmap *type_to_icon(GtkWidget *window, MIME_type *type) return i; } + +GdkAtom type_to_atom(MIME_type *type) +{ + char *str; + GdkAtom retval; + + g_return_val_if_fail(type != NULL, GDK_NONE); + + str = g_strconcat(type->media_type, "/", type->subtype, NULL); + retval = gdk_atom_intern(str, FALSE); + g_free(str); + + return retval; +} + diff --git a/ROX-Filer/src/type.h b/ROX-Filer/src/type.h index 4c4967b3..db12dbd2 100644 --- a/ROX-Filer/src/type.h +++ b/ROX-Filer/src/type.h @@ -27,5 +27,6 @@ char *basetype_name(FileItem *item); MIME_type *type_from_path(char *path); gboolean type_open(char *path, MIME_type *type); MaskedPixmap *type_to_icon(GtkWidget *window, MIME_type *type); +GdkAtom type_to_atom(MIME_type *type); #endif /* _TYPE_H */ -- 2.11.4.GIT