From d8c77523243b3217d7e76100632a62b0abdc6a29 Mon Sep 17 00:00:00 2001 From: Bradford Hovinen Date: Sat, 26 Jan 2002 16:24:45 +0000 Subject: [PATCH] Implement (find_possible_supported_apps): Implement 2002-01-26 Bradford Hovinen * mime-type-info.c (intersect_lists, reduce_supported_app_list) (mime_category_info_find_apps): Implement (find_possible_supported_apps): Implement * mime-category-edit-dialog.c (mime_category_edit_dialog_init): Use mime_category_edit_widget for the dialog source * model-entry.c (model_entry_remove_from_dirty_list): Accept a ModelEntry structure * mime-category-edit-dialog.c (store_data): Call model_entry_append_to_dirty_list * service-edit-dialog.c (store_data): Call model_entry_append_to_dirty_list --- capplets/file-types/ChangeLog | 67 +++++ capplets/file-types/TODO_NOTES | 8 +- capplets/file-types/file-types-capplet.c | 29 +- .../file-types/file-types-properties.glade | 278 +++++++++++++++++- .../file-types/file-types-properties.glade1 | 261 +++++++++++++++- .../file-types/mime-category-edit-dialog.c | 71 ++--- .../file-types/mime-category-edit-dialog.h | 4 +- capplets/file-types/mime-edit-dialog.c | 56 ++-- capplets/file-types/mime-edit-dialog.h | 2 +- capplets/file-types/mime-type-info.c | 183 ++++++++---- capplets/file-types/mime-type-info.h | 27 +- capplets/file-types/mime-types-model.c | 5 +- capplets/file-types/model-entry.c | 45 +++ capplets/file-types/model-entry.h | 6 + capplets/file-types/service-edit-dialog.c | 167 +++++++++-- capplets/file-types/service-edit-dialog.h | 3 +- capplets/file-types/service-info.c | 59 +--- capplets/file-types/service-info.h | 6 +- 18 files changed, 1029 insertions(+), 248 deletions(-) diff --git a/capplets/file-types/ChangeLog b/capplets/file-types/ChangeLog index df83e4c07..7c8b7ec1e 100644 --- a/capplets/file-types/ChangeLog +++ b/capplets/file-types/ChangeLog @@ -1,5 +1,72 @@ +2002-01-26 Bradford Hovinen + + * mime-type-info.c (intersect_lists, reduce_supported_app_list) + (mime_category_info_find_apps): Implement + (find_possible_supported_apps): Implement + + * mime-category-edit-dialog.c (mime_category_edit_dialog_init): + Use mime_category_edit_widget for the dialog source + + * model-entry.c (model_entry_remove_from_dirty_list): Accept a + ModelEntry structure + + * mime-category-edit-dialog.c (store_data): Call + model_entry_append_to_dirty_list + + * service-edit-dialog.c (store_data): Call + model_entry_append_to_dirty_list + + * service-info.c (service_info_new): Remove changeset + (get_string, get_bool): Remove changeset support + (set_string, set_bool): Ditto + + * file-types-capplet.c: Remove the changeset since it duplicates + functionality already present elsewhere + + * model-entry.c: Move dirty list from mime-type-info.c to here; + extend to support arbitrary model entries + + * mime-type-info.c (mime_type_info_new_category): Rename to + mime_category_info_new; return MimeCategoryInfo + (mime_category_info_new): Set parent to root node if it is NULL + (get_category): Return a MimeCategoryInfo + (mime_type_info_category_find_supported_apps): Rename to + mime_type_info_find_apps + + * mime-type-info.h (struct _MimeCategoryInfo): Create new structure + + * mime-category-edit-dialog.c: Change iter property back to info + (fill_dialog): Desensitize description, mime type entries + + * service-edit-dialog.c: Change iter property back to info + (validate_data): Don't check duplicate directory unless this is an + add dialog + + * mime-edit-dialog.c: Change iter property back to info + 2002-01-25 Bradford Hovinen + * service-edit-dialog.c (store_data): Fetch the protocol name if + this is an add dialog + (validate_data): Implement + (response_cb): Call validate_data + + * service-info.c (service_info_new): Don't strdup the protocol if + it is NULL + + * service-edit-dialog.c (store_data): Use + gtk_tree_model_row_inserted if this is an add dialog; also + construct an iter in that case + (service_edit_dialog_dispose): Free the iter + (service_edit_dialog_finalize): Don't free the iter here + + * file-types-capplet.c (add_service_cb): Implement + (create_dialog): Connect addd_service_button to add_service_cb + + * service-edit-dialog.c: Add property is-add + (service_add_dialog_new): Implement + (setup_add_dialog): Implement + * mime-category-edit-dialog.c (fill_dialog): Desensitize component select (populate_application_list): Desensitize application select if diff --git a/capplets/file-types/TODO_NOTES b/capplets/file-types/TODO_NOTES index e92e471a7..6ed423a3b 100644 --- a/capplets/file-types/TODO_NOTES +++ b/capplets/file-types/TODO_NOTES @@ -5,8 +5,8 @@ - Better sorting on the MIME types tree - Don't consider a mime type when generating category handler list if the mime type overrides the category default - Implement override_category_default flag - - Implement setting of default action for a whole category - - Implement retrieving the current default action for a whole category + - Implement mime_category_info_save, mime_category_info_load_all - Implement remove for Internet services - - Implement add service - - Refactor: Don't pass iter to add/edit dialogs, just pass structure. Generate iter on the fly \ No newline at end of file + - Better checking for duplicate service names, check for duplicate MIME types + - Don't enable Remove button for categories + - Make sure cancel on add is handled properly \ No newline at end of file diff --git a/capplets/file-types/file-types-capplet.c b/capplets/file-types/file-types-capplet.c index f90a68db1..a483e4af7 100644 --- a/capplets/file-types/file-types-capplet.c +++ b/capplets/file-types/file-types-capplet.c @@ -34,7 +34,6 @@ #include #include #include -#include #include "mime-types-model.h" #include "mime-edit-dialog.h" @@ -46,7 +45,6 @@ #define WID(x) (glade_xml_get_widget (dialog, x)) static GList *remove_list = NULL; -static GConfChangeSet *changeset = NULL; static void add_mime_cb (GtkButton *button, GladeXML *dialog) @@ -61,6 +59,19 @@ add_mime_cb (GtkButton *button, GladeXML *dialog) add_dialog = mime_add_dialog_new (model); } +static void +add_service_cb (GtkButton *button, GladeXML *dialog) +{ + GtkTreeView *treeview; + GtkTreeModel *model; + GObject *add_dialog; + + treeview = GTK_TREE_VIEW (WID ("mime_types_tree")); + model = gtk_tree_view_get_model (treeview); + + add_dialog = service_add_dialog_new (model); +} + static GObject * launch_edit_dialog (GtkTreeModel *model, GtkTreeIter *iter) { @@ -70,13 +81,13 @@ launch_edit_dialog (GtkTreeModel *model, GtkTreeIter *iter) switch (entry->type) { case MODEL_ENTRY_MIME_TYPE: - return mime_edit_dialog_new (model, iter); + return mime_edit_dialog_new (model, MIME_TYPE_INFO (entry)); case MODEL_ENTRY_SERVICE: - return service_edit_dialog_new (model, iter); + return service_edit_dialog_new (model, SERVICE_INFO (entry)); case MODEL_ENTRY_CATEGORY: - return mime_category_edit_dialog_new (model, iter); + return mime_category_edit_dialog_new (model, MIME_CATEGORY_INFO (entry)); default: return NULL; @@ -149,7 +160,7 @@ remove_cb (GtkButton *button, GladeXML *dialog) path = gtk_tree_model_get_path (model, &iter); model_entry_remove_child (entry->parent, entry); remove_list = g_list_prepend (remove_list, MIME_TYPE_INFO (entry)->mime_type); - mime_type_remove_from_dirty_list (MIME_TYPE_INFO (entry)->mime_type); + model_entry_remove_from_dirty_list (entry); gtk_tree_model_row_deleted (model, path); gtk_tree_path_free (path); } @@ -208,6 +219,7 @@ create_dialog (void) gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); g_signal_connect (G_OBJECT (WID ("add_mime_button")), "clicked", (GCallback) add_mime_cb, dialog); + g_signal_connect (G_OBJECT (WID ("add_service_button")), "clicked", (GCallback) add_service_cb, dialog); g_signal_connect (G_OBJECT (WID ("edit_button")), "clicked", (GCallback) edit_cb, dialog); g_signal_connect (G_OBJECT (WID ("remove_button")), "clicked", (GCallback) remove_cb, dialog); g_signal_connect (G_OBJECT (selection), "changed", (GCallback) selection_changed_cb, dialog); @@ -220,13 +232,11 @@ create_dialog (void) static void apply_cb (void) { - mime_type_commit_dirty_list (); + model_entry_commit_dirty_list (); g_list_foreach (remove_list, (GFunc) gnome_vfs_mime_registered_mime_type_delete, NULL); g_list_foreach (remove_list, (GFunc) g_free, NULL); g_list_free (remove_list); - - gconf_client_commit_change_set (gconf_client_get_default (), changeset, TRUE, NULL); } int @@ -240,7 +250,6 @@ main (int argc, char **argv) gnome_program_init ("gnome-file-types-properties", VERSION, LIBGNOMEUI_MODULE, argc, argv, NULL); - changeset = gconf_change_set_new (); dialog = create_dialog (); g_signal_connect (G_OBJECT (WID ("main_apply_button")), "clicked", (GCallback) apply_cb, NULL); diff --git a/capplets/file-types/file-types-properties.glade b/capplets/file-types/file-types-properties.glade index 10860ac63..68c825c31 100644 --- a/capplets/file-types/file-types-properties.glade +++ b/capplets/file-types/file-types-properties.glade @@ -257,7 +257,7 @@ - + no 4 yes @@ -304,7 +304,7 @@ - + no 4 yes @@ -351,7 +351,7 @@ - + no 4 yes @@ -1094,4 +1094,276 @@ + + GTK_WINDOW_TOPLEVEL + no + no + no + no + GTK_WIN_POS_NONE + + + + no + 8 + yes + + + + GTK_BUTTONBOX_END + 8 + yes + + + + yes + yes + yes + gtk-ok + yes + yes + + + + + + yes + yes + yes + gtk-apply + yes + yes + + + + + + yes + yes + yes + gtk-cancel + yes + yes + + + + + 0 + no + yes + GTK_PACK_END + + + + + + 4 + no + 4 + yes + + + + no + 4 + yes + + + + Name + GTK_JUSTIFY_CENTER + no + 0.5 + 0.5 + 0 + 0 + yes + + + 0 + no + no + + + + + + yes + yes + + 0 + yes + yes + + + 0 + yes + yes + + + + + 0 + yes + yes + + + + + + Actions + 0 + GTK_SHADOW_ETCHED_IN + yes + + + + 4 + no + 4 + yes + + + + no + 4 + yes + + + + Default action + GTK_JUSTIFY_CENTER + no + 0 + 0.5 + 0 + 0 + yes + + + 0 + no + yes + + + + + + yes + 0 + yes + + + + yes + + + + + 0 + yes + yes + + + + + 0 + no + yes + + + + + + no + 4 + yes + + + + Program to execute + GTK_JUSTIFY_CENTER + no + 0 + 0.5 + 0 + 0 + yes + + + 0 + no + yes + + + + + + no + no + yes + + + + yes + yes + + 0 + yes + yes + + + + + 0 + yes + yes + + + + + 0 + yes + yes + + + + + + yes + Needs terminal + no + yes + yes + + + 0 + no + no + + + + + + + 0 + yes + yes + + + + + 0 + yes + yes + + + + + 4 + yes + yes + + + diff --git a/capplets/file-types/file-types-properties.glade1 b/capplets/file-types/file-types-properties.glade1 index 46b76df1a..3c67e758f 100644 --- a/capplets/file-types/file-types-properties.glade1 +++ b/capplets/file-types/file-types-properties.glade1 @@ -263,7 +263,7 @@ GtkHBox - hbox3 + description_box False 4 @@ -307,7 +307,7 @@ GtkHBox - hbox4 + mime_type_box False 4 @@ -351,7 +351,7 @@ GtkHBox - hbox12 + category_box False 4 @@ -1036,4 +1036,259 @@ + + GnomeDialog + mime_category_edit_dialog + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox5 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area5 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button13 + True + True + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button14 + True + True + GNOME_STOCK_BUTTON_APPLY + + + + GtkButton + button15 + True + True + GNOME_STOCK_BUTTON_CANCEL + + + + + GtkVBox + mime_category_edit_widget + 4 + False + 4 + + 0 + True + True + + + + GtkHBox + name_box + False + 4 + + 0 + True + True + + + + GtkLabel + name_label + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkEntry + name_entry + True + True + True + 0 + + + 0 + True + True + + + + + + GtkFrame + frame4 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkVBox + vbox7 + 4 + False + 4 + + + GtkHBox + default_action_box + False + 4 + + 0 + False + True + + + + GtkLabel + default_action_label + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + False + True + + + + + GtkOptionMenu + default_action_select + True + + 0 + + 0 + True + True + + + + + + GtkHBox + program_entry_box + False + 4 + + 0 + True + True + + + + GtkLabel + program_label + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + False + True + + + + + GnomeFileEntry + program_entry + 10 + False + False + + 0 + True + True + + + + GtkEntry + GnomeEntry:entry + entry2 + True + True + True + 0 + + + + + + + GtkCheckButton + needs_terminal_toggle + True + + False + True + + 0 + False + False + + + + + + + + diff --git a/capplets/file-types/mime-category-edit-dialog.c b/capplets/file-types/mime-category-edit-dialog.c index e3beba55e..1e2999aa3 100644 --- a/capplets/file-types/mime-category-edit-dialog.c +++ b/capplets/file-types/mime-category-edit-dialog.c @@ -38,16 +38,16 @@ enum { PROP_0, PROP_MODEL, - PROP_ITER + PROP_INFO }; struct _MimeCategoryEditDialogPrivate { - GladeXML *dialog_xml; - GtkWidget *dialog_win; - GtkTreeModel *model; - GtkTreeIter *iter; - MimeTypeInfo *info; + GladeXML *dialog_xml; + GtkWidget *dialog_win; + MimeCategoryInfo *info; + + GtkTreeModel *model; }; static GObjectClass *parent_class; @@ -113,28 +113,16 @@ mime_category_edit_dialog_init (MimeCategoryEditDialog *dialog, MimeCategoryEdit dialog->p = g_new0 (MimeCategoryEditDialogPrivate, 1); dialog->p->dialog_xml = glade_xml_new - (GNOMECC_DATA_DIR "/interfaces/file-types-properties.glade", "edit_widget", NULL); + (GNOMECC_DATA_DIR "/interfaces/file-types-properties.glade", "mime_category_edit_widget", NULL); dialog->p->model = NULL; dialog->p->info = NULL; size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_add_widget (size_group, WID ("description_label")); - gtk_size_group_add_widget (size_group, WID ("mime_type_label")); - gtk_size_group_add_widget (size_group, WID ("category_label")); - - size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_add_widget (size_group, WID ("component_label")); gtk_size_group_add_widget (size_group, WID ("default_action_label")); gtk_size_group_add_widget (size_group, WID ("program_label")); - gtk_widget_set_sensitive (WID ("icon_entry"), FALSE); - gtk_widget_set_sensitive (WID ("mime_type_entry"), FALSE); - gtk_widget_set_sensitive (WID ("mime_type_label"), FALSE); - gtk_widget_set_sensitive (WID ("description_entry"), FALSE); - gtk_widget_set_sensitive (WID ("file_extensions_frame"), FALSE); - gtk_widget_set_sensitive (WID ("component_label"), FALSE); - gtk_widget_set_sensitive (WID ("component_select"), FALSE); + gtk_widget_set_sensitive (WID ("name_box"), FALSE); dialog->p->dialog_win = gtk_dialog_new_with_buttons (_("Edit file category"), NULL, -1, @@ -142,7 +130,7 @@ mime_category_edit_dialog_init (MimeCategoryEditDialog *dialog, MimeCategoryEdit GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->p->dialog_win)->vbox), WID ("edit_widget"), TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->p->dialog_win)->vbox), WID ("mime_category_edit_widget"), TRUE, TRUE, 0); g_signal_connect_swapped (G_OBJECT (WID ("default_action_select")), "changed", (GCallback) default_action_changed_cb, dialog); @@ -173,10 +161,10 @@ mime_category_edit_dialog_class_init (MimeCategoryEditDialogClass *class) _("GtkTreeModel that contains the category data"), G_PARAM_READWRITE)); g_object_class_install_property - (object_class, PROP_ITER, - g_param_spec_pointer ("iterator", - _("Iterator"), - _("Iterator"), + (object_class, PROP_INFO, + g_param_spec_pointer ("mime-cat-info", + _("MIME category info"), + _("Structure containing information on the MIME category"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); parent_class = G_OBJECT_CLASS @@ -202,9 +190,8 @@ mime_category_edit_dialog_set_prop (GObject *object, guint prop_id, const GValue break; - case PROP_ITER: - dialog->p->iter = gtk_tree_iter_copy (g_value_get_pointer (value)); - dialog->p->info = MIME_TYPE_INFO (MODEL_ENTRY_FROM_ITER (dialog->p->iter)); + case PROP_INFO: + dialog->p->info = g_value_get_pointer (value); if (dialog->p->model != NULL) fill_dialog (dialog); @@ -232,8 +219,8 @@ mime_category_edit_dialog_get_prop (GObject *object, guint prop_id, GValue *valu g_value_set_pointer (value, dialog->p->model); break; - case PROP_ITER: - g_value_set_pointer (value, dialog->p->iter); + case PROP_INFO: + g_value_set_pointer (value, dialog->p->info); break; default: @@ -275,33 +262,29 @@ mime_category_edit_dialog_finalize (GObject *object) mime_category_edit_dialog = MIME_CATEGORY_EDIT_DIALOG (object); - gtk_tree_iter_free (mime_category_edit_dialog->p->iter); g_free (mime_category_edit_dialog->p); G_OBJECT_CLASS (parent_class)->finalize (object); } GObject * -mime_category_edit_dialog_new (GtkTreeModel *model, GtkTreeIter *iter) +mime_category_edit_dialog_new (GtkTreeModel *model, MimeCategoryInfo *info) { return g_object_new (mime_category_edit_dialog_get_type (), "model", model, - "iterator", iter, + "mime-cat-info", info, NULL); } static void fill_dialog (MimeCategoryEditDialog *dialog) { - gtk_entry_set_text (GTK_ENTRY (WID ("description_entry")), mime_type_info_get_description (dialog->p->info)); + mime_category_info_load_all (dialog->p->info); + + gtk_entry_set_text (GTK_ENTRY (WID ("name_entry")), dialog->p->info->name); populate_application_list (dialog); - if (dialog->p->info->entry.parent->type == MODEL_ENTRY_NONE) - gtk_widget_set_sensitive (WID ("use_category_defaults_toggle"), FALSE); - - gtk_widget_set_sensitive (WID ("component_box"), FALSE); - gtk_widget_show_all (dialog->p->dialog_win); } @@ -319,7 +302,7 @@ populate_application_list (MimeCategoryEditDialog *dialog) menu = GTK_MENU (gtk_menu_new ()); - app_list = mime_type_info_category_find_supported_apps (dialog->p->info); + app_list = mime_category_info_find_apps (dialog->p->info); for (tmp = app_list, i = 0; tmp != NULL; tmp = tmp->next, i++) { app = gnome_vfs_application_registry_get_mime_application (tmp->data); @@ -363,9 +346,13 @@ static void store_data (MimeCategoryEditDialog *dialog) { GtkTreePath *path; + GtkTreeIter iter; - path = gtk_tree_model_get_path (dialog->p->model, dialog->p->iter); - gtk_tree_model_row_changed (dialog->p->model, path, dialog->p->iter); + model_entry_append_to_dirty_list (MODEL_ENTRY (dialog->p->info)); + + mime_types_model_construct_iter (MIME_TYPES_MODEL (dialog->p->model), MODEL_ENTRY (dialog->p->info), &iter); + path = gtk_tree_model_get_path (dialog->p->model, &iter); + gtk_tree_model_row_changed (dialog->p->model, path, &iter); gtk_tree_path_free (path); } diff --git a/capplets/file-types/mime-category-edit-dialog.h b/capplets/file-types/mime-category-edit-dialog.h index 64c78a474..0718525c8 100644 --- a/capplets/file-types/mime-category-edit-dialog.h +++ b/capplets/file-types/mime-category-edit-dialog.h @@ -51,8 +51,8 @@ struct _MimeCategoryEditDialogClass GType mime_category_edit_dialog_get_type (void); -GObject *mime_category_edit_dialog_new (GtkTreeModel *model, - GtkTreeIter *iter); +GObject *mime_category_edit_dialog_new (GtkTreeModel *model, + MimeCategoryInfo *info); G_END_DECLS diff --git a/capplets/file-types/mime-edit-dialog.c b/capplets/file-types/mime-edit-dialog.c index b7915e3a3..e0ec5692d 100644 --- a/capplets/file-types/mime-edit-dialog.c +++ b/capplets/file-types/mime-edit-dialog.c @@ -39,7 +39,7 @@ enum { PROP_0, PROP_MODEL, - PROP_ITER, + PROP_INFO, PROP_IS_ADD }; @@ -53,7 +53,6 @@ struct _MimeEditDialogPrivate gboolean is_add; GtkTreeModel *model; - GtkTreeIter *iter; }; static GObjectClass *parent_class; @@ -188,10 +187,10 @@ mime_edit_dialog_class_init (MimeEditDialogClass *class) G_PARAM_READWRITE)); g_object_class_install_property - (object_class, PROP_ITER, - g_param_spec_pointer ("iterator", - _("Iterator"), - _("Iterator on the model referring to object to edit"), + (object_class, PROP_INFO, + g_param_spec_pointer ("mime-type-info", + _("MIME type information"), + _("Structure with data on the MIME type"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property @@ -221,10 +220,9 @@ mime_edit_dialog_set_prop (GObject *object, guint prop_id, const GValue *value, mime_edit_dialog->p->model = GTK_TREE_MODEL (g_value_get_object (value)); break; - case PROP_ITER: + case PROP_INFO: if (g_value_get_pointer (value) != NULL) { - mime_edit_dialog->p->iter = gtk_tree_iter_copy (g_value_get_pointer (value)); - mime_edit_dialog->p->info = MIME_TYPE_INFO (MODEL_ENTRY_FROM_ITER (mime_edit_dialog->p->iter)); + mime_edit_dialog->p->info = g_value_get_pointer (value); fill_dialog (mime_edit_dialog); gtk_widget_show_all (mime_edit_dialog->p->dialog_win); @@ -264,8 +262,8 @@ mime_edit_dialog_get_prop (GObject *object, guint prop_id, GValue *value, GParam g_value_set_object (value, G_OBJECT (mime_edit_dialog->p->model)); break; - case PROP_ITER: - g_value_set_pointer (value, mime_edit_dialog->p->iter); + case PROP_INFO: + g_value_set_pointer (value, mime_edit_dialog->p->info); break; default: @@ -294,11 +292,6 @@ mime_edit_dialog_dispose (GObject *object) dialog->p->dialog_win = NULL; } - if (dialog->p->iter != NULL) { - gtk_tree_iter_free (dialog->p->iter); - dialog->p->iter = NULL; - } - G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -318,11 +311,11 @@ mime_edit_dialog_finalize (GObject *object) } GObject * -mime_edit_dialog_new (GtkTreeModel *model, GtkTreeIter *iter) +mime_edit_dialog_new (GtkTreeModel *model, MimeTypeInfo *info) { return g_object_new (mime_edit_dialog_get_type (), "model", model, - "iterator", iter, + "mime-type-info", info, NULL); } @@ -537,6 +530,7 @@ store_data (MimeEditDialog *dialog) GnomeVFSMimeApplication *app; + GtkTreeIter iter; GtkTreePath *path; GtkTreePath *old_path = NULL; @@ -576,8 +570,11 @@ store_data (MimeEditDialog *dialog) if (strcmp (tmp, tmp1)) { cat_changed = TRUE; - if (!dialog->p->is_add) - old_path = gtk_tree_model_get_path (dialog->p->model, dialog->p->iter); + if (!dialog->p->is_add) { + mime_types_model_construct_iter (MIME_TYPES_MODEL (dialog->p->model), + MODEL_ENTRY (dialog->p->info), &iter); + old_path = gtk_tree_model_get_path (dialog->p->model, &iter); + } mime_type_info_set_category_name (dialog->p->info, tmp1); } @@ -611,7 +608,10 @@ store_data (MimeEditDialog *dialog) ext_list = collect_filename_extensions (dialog); mime_type_info_set_file_extensions (dialog->p->info, ext_list); - mime_type_append_to_dirty_list (dialog->p->info); + model_entry_append_to_dirty_list (MODEL_ENTRY (dialog->p->info)); + + mime_types_model_construct_iter (MIME_TYPES_MODEL (dialog->p->model), + MODEL_ENTRY (dialog->p->info), &iter); if (cat_changed) { if (old_path != NULL) { @@ -619,18 +619,12 @@ store_data (MimeEditDialog *dialog) gtk_tree_path_free (old_path); } - if (dialog->p->iter == NULL) { - dialog->p->iter = g_new0 (GtkTreeIter, 1); - mime_types_model_construct_iter (MIME_TYPES_MODEL (dialog->p->model), - MODEL_ENTRY (dialog->p->info), dialog->p->iter); - } - - path = gtk_tree_model_get_path (dialog->p->model, dialog->p->iter); - gtk_tree_model_row_inserted (dialog->p->model, path, dialog->p->iter); + path = gtk_tree_model_get_path (dialog->p->model, &iter); + gtk_tree_model_row_inserted (dialog->p->model, path, &iter); gtk_tree_path_free (path); } else { - path = gtk_tree_model_get_path (dialog->p->model, dialog->p->iter); - gtk_tree_model_row_changed (dialog->p->model, path, dialog->p->iter); + path = gtk_tree_model_get_path (dialog->p->model, &iter); + gtk_tree_model_row_changed (dialog->p->model, path, &iter); gtk_tree_path_free (path); } } diff --git a/capplets/file-types/mime-edit-dialog.h b/capplets/file-types/mime-edit-dialog.h index e6a36baf1..2c6cf2c93 100644 --- a/capplets/file-types/mime-edit-dialog.h +++ b/capplets/file-types/mime-edit-dialog.h @@ -53,7 +53,7 @@ struct _MimeEditDialogClass GType mime_edit_dialog_get_type (void); GObject *mime_edit_dialog_new (GtkTreeModel *model, - GtkTreeIter *iter); + MimeTypeInfo *info); GObject *mime_add_dialog_new (GtkTreeModel *model); G_END_DECLS diff --git a/capplets/file-types/mime-type-info.c b/capplets/file-types/mime-type-info.c index b1d7c21a2..f2bce7d2b 100644 --- a/capplets/file-types/mime-type-info.c +++ b/capplets/file-types/mime-type-info.c @@ -38,10 +38,6 @@ #include "mime-type-info.h" #include "mime-types-model.h" -/* List of MimeTypeInfo structures that have data to be committed */ - -static GList *dirty_list = NULL; - static const gchar *get_category_name (const gchar *mime_type); static GSList *get_lang_list (void); static gchar *form_extensions_string (const MimeTypeInfo *info, @@ -51,7 +47,7 @@ static void get_icon_pixbuf (MimeTypeInfo *info, const gchar *icon_path, gboolean want_large); -static MimeTypeInfo *get_category (const gchar *category_name); +static MimeCategoryInfo *get_category (const gchar *category_name); @@ -87,23 +83,6 @@ mime_type_info_new (const gchar *mime_type) return info; } -MimeTypeInfo * -mime_type_info_new_category (MimeTypeInfo *parent, const gchar *category) -{ - MimeTypeInfo *info; - - info = g_new0 (MimeTypeInfo, 1); - MODEL_ENTRY (info)->type = MODEL_ENTRY_CATEGORY; - - info->description = g_strdup (category); - MODEL_ENTRY (info)->parent = MODEL_ENTRY (parent); - - if (parent != NULL) - model_entry_insert_child (MODEL_ENTRY (parent), MODEL_ENTRY (info)); - - return info; -} - /* Fill in the remaining fields in a MimeTypeInfo structure; suitable for * subsequent use in an edit dialog */ @@ -233,7 +212,7 @@ mime_type_info_get_category_name (const MimeTypeInfo *info) tmp = info->entry.parent; for (; tmp != NULL && tmp->type != MODEL_ENTRY_NONE; tmp = tmp->parent) { - g_string_prepend (string, MIME_TYPE_INFO (tmp)->description); + g_string_prepend (string, MIME_CATEGORY_INFO (tmp)->name); g_string_prepend (string, "/"); } @@ -242,12 +221,6 @@ mime_type_info_get_category_name (const MimeTypeInfo *info) return ret; } -GList * -mime_type_info_category_find_supported_apps (MimeTypeInfo *info) -{ - return NULL; -} - void mime_type_info_set_category_name (const MimeTypeInfo *info, const gchar *category_name) { @@ -321,8 +294,6 @@ mime_type_info_save (const MimeTypeInfo *info) void mime_type_info_free (MimeTypeInfo *info) { - dirty_list = g_list_remove (dirty_list, info); - g_free (info->mime_type); g_free (info->description); g_free (info->icon_name); @@ -340,6 +311,120 @@ mime_type_info_free (MimeTypeInfo *info) g_free (info); } +MimeCategoryInfo * +mime_category_info_new (MimeCategoryInfo *parent, const gchar *name) +{ + MimeCategoryInfo *info; + + info = g_new0 (MimeCategoryInfo, 1); + MODEL_ENTRY (info)->type = MODEL_ENTRY_CATEGORY; + + info->name = g_strdup (name); + + if (parent != NULL) + MODEL_ENTRY (info)->parent = MODEL_ENTRY (parent); + else + MODEL_ENTRY (info)->parent = get_model_entries (); + + model_entry_insert_child (MODEL_ENTRY (info)->parent, MODEL_ENTRY (info)); + + return info; +} + +void +mime_category_info_load_all (MimeCategoryInfo *category) +{ +} + +void +mime_category_info_save (MimeCategoryInfo *category) +{ +} + +static GList * +find_possible_supported_apps (ModelEntry *entry) +{ + GList *ret; + ModelEntry *tmp; + + if (entry == NULL) return NULL; + + switch (entry->type) { + case MODEL_ENTRY_CATEGORY: + for (tmp = entry->first_child; tmp != NULL; tmp = tmp->next) { + ret = find_possible_supported_apps (tmp); + + if (ret != NULL) + return ret; + } + + return NULL; + + case MODEL_ENTRY_MIME_TYPE: + return gnome_vfs_application_registry_get_applications (MIME_TYPE_INFO (entry)->mime_type); + + default: + return NULL; + } +} + +static GList * +intersect_lists (GList *list, GList *list1) +{ + GList *tmp, *tmp1, *tmpnext; + + tmp = list; + + while (tmp != NULL) { + tmpnext = tmp->next; + + for (tmp1 = list1; tmp1 != NULL; tmp1 = tmp1->next) + if (!strcmp (tmp->data, tmp1->data)) + break; + + if (tmp1 == NULL) + list = g_list_remove_link (list, tmp); + + tmp = tmpnext; + } + + return list; +} + +static GList * +reduce_supported_app_list (ModelEntry *entry, GList *list) +{ + GList *type_list; + ModelEntry *tmp; + + switch (entry->type) { + case MODEL_ENTRY_CATEGORY: + for (tmp = entry->first_child; tmp != NULL; tmp = tmp->next) + list = reduce_supported_app_list (tmp, list); + break; + + case MODEL_ENTRY_MIME_TYPE: + type_list = gnome_vfs_application_registry_get_applications (MIME_TYPE_INFO (entry)->mime_type); + list = intersect_lists (list, type_list); + g_list_free (type_list); + break; + + default: + break; + } + + return list; +} + +GList * +mime_category_info_find_apps (MimeCategoryInfo *info) +{ + GList *ret; + + ret = find_possible_supported_apps (MODEL_ENTRY (info)); + return reduce_supported_app_list (MODEL_ENTRY (info), ret); +} + char * mime_type_get_pretty_name_for_server (Bonobo_ServerInfo *server) { @@ -376,34 +461,6 @@ mime_type_get_pretty_name_for_server (Bonobo_ServerInfo *server) return g_strdup_printf ("View as %s", view_as_name); } -void -mime_type_append_to_dirty_list (MimeTypeInfo *info) -{ - if (g_list_find (dirty_list, info) == NULL) - dirty_list = g_list_prepend (dirty_list, info); -} - -void -mime_type_remove_from_dirty_list (const gchar *mime_type) -{ - GList *tmp = dirty_list, *tmp1; - - while (tmp != NULL) { - tmp1 = tmp->next; - if (!strcmp (mime_type, ((MimeTypeInfo *) tmp->data)->mime_type)) - dirty_list = g_list_remove_link (dirty_list, tmp); - tmp = tmp1; - } -} - -void -mime_type_commit_dirty_list (void) -{ - gnome_vfs_mime_freeze (); - g_list_foreach (dirty_list, (GFunc) mime_type_info_save, NULL); - gnome_vfs_mime_thaw (); -} - static const gchar * @@ -509,7 +566,7 @@ get_icon_pixbuf (MimeTypeInfo *info, const gchar *icon_path, gboolean want_large } } -static MimeTypeInfo * +static MimeCategoryInfo * get_category (const gchar *category_name) { ModelEntry *current, *child; @@ -528,17 +585,17 @@ get_category (const gchar *category_name) if (child->type != MODEL_ENTRY_CATEGORY) continue; - if (!strcmp (MIME_TYPE_INFO (child)->description, categories[i])) + if (!strcmp (MIME_CATEGORY_INFO (child)->name, categories[i])) break; } if (child == NULL) - child = MODEL_ENTRY (mime_type_info_new_category (MIME_TYPE_INFO (current), categories[i])); + child = MODEL_ENTRY (mime_category_info_new (MIME_CATEGORY_INFO (current), categories[i])); current = child; } g_strfreev (categories); - return MIME_TYPE_INFO (current); + return MIME_CATEGORY_INFO (current); } diff --git a/capplets/file-types/mime-type-info.h b/capplets/file-types/mime-type-info.h index ab39c6974..3c18ff300 100644 --- a/capplets/file-types/mime-type-info.h +++ b/capplets/file-types/mime-type-info.h @@ -35,8 +35,10 @@ G_BEGIN_DECLS #define MIME_TYPE_INFO(obj) ((MimeTypeInfo *) obj) +#define MIME_CATEGORY_INFO(obj) ((MimeCategoryInfo *) obj) typedef struct _MimeTypeInfo MimeTypeInfo; +typedef struct _MimeCategoryInfo MimeCategoryInfo; struct _MimeTypeInfo { @@ -57,11 +59,19 @@ struct _MimeTypeInfo gboolean needs_terminal; }; +struct _MimeCategoryInfo +{ + ModelEntry entry; + + gchar *name; + GnomeVFSMimeApplication *default_action; + gchar *custom_line; + gboolean needs_terminal; +}; + void load_all_mime_types (void); MimeTypeInfo *mime_type_info_new (const gchar *mime_type); -MimeTypeInfo *mime_type_info_new_category (MimeTypeInfo *parent, - const gchar *category); void mime_type_info_load_all (MimeTypeInfo *info); const gchar *mime_type_info_get_description (MimeTypeInfo *info); @@ -76,19 +86,18 @@ gchar *mime_type_info_get_file_extensions_pretty_string (MimeTypeInfo *info); gchar *mime_type_info_get_category_name (const MimeTypeInfo *info); -GList *mime_type_info_category_find_supported_apps - (MimeTypeInfo *info); - void mime_type_info_set_category_name (const MimeTypeInfo *info, const gchar *category_name); void mime_type_info_set_file_extensions (MimeTypeInfo *info, GList *list); -gchar *mime_type_get_pretty_name_for_server (Bonobo_ServerInfo *server); +MimeCategoryInfo *mime_category_info_new (MimeCategoryInfo *parent, + const gchar *name); +void mime_category_info_load_all (MimeCategoryInfo *category); +void mime_category_info_save (MimeCategoryInfo *category); +GList *mime_category_info_find_apps (MimeCategoryInfo *info); -void mime_type_append_to_dirty_list (MimeTypeInfo *info); -void mime_type_remove_from_dirty_list (const gchar *mime_type); -void mime_type_commit_dirty_list (void); +gchar *mime_type_get_pretty_name_for_server (Bonobo_ServerInfo *server); G_END_DECLS diff --git a/capplets/file-types/mime-types-model.c b/capplets/file-types/mime-types-model.c index af44d4987..5c2a09e64 100644 --- a/capplets/file-types/mime-types-model.c +++ b/capplets/file-types/mime-types-model.c @@ -405,10 +405,13 @@ mime_types_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint co switch (entry->type) { case MODEL_ENTRY_MIME_TYPE: - case MODEL_ENTRY_CATEGORY: g_value_set_static_string (value, mime_type_info_get_description (MIME_TYPE_INFO (entry))); break; + case MODEL_ENTRY_CATEGORY: + g_value_set_static_string (value, MIME_CATEGORY_INFO (entry)->name); + break; + case MODEL_ENTRY_SERVICE: g_value_set_static_string (value, service_info_get_description (SERVICE_INFO (entry))); break; diff --git a/capplets/file-types/model-entry.c b/capplets/file-types/model-entry.c index a707e4fb5..eec5298f8 100644 --- a/capplets/file-types/model-entry.c +++ b/capplets/file-types/model-entry.c @@ -30,6 +30,10 @@ #include "mime-type-info.h" #include "service-info.h" +/* List of MimeTypeInfo structures that have data to be committed */ + +static GList *dirty_list = NULL; + ModelEntry * get_model_entries (void) { @@ -125,3 +129,44 @@ model_entry_remove_child (ModelEntry *entry, ModelEntry *child) } } +void +model_entry_save (ModelEntry *entry) +{ + switch (entry->type) { + case MODEL_ENTRY_MIME_TYPE: + mime_type_info_save (MIME_TYPE_INFO (entry)); + break; + + case MODEL_ENTRY_SERVICE: + service_info_save (SERVICE_INFO (entry)); + break; + + case MODEL_ENTRY_CATEGORY: + mime_category_info_save (MIME_CATEGORY_INFO (entry)); + break; + + default: + break; + } +} + +void +model_entry_append_to_dirty_list (ModelEntry *entry) +{ + if (g_list_find (dirty_list, entry) == NULL) + dirty_list = g_list_prepend (dirty_list, entry); +} + +void +model_entry_remove_from_dirty_list (ModelEntry *entry) +{ + dirty_list = g_list_remove (dirty_list, entry); +} + +void +model_entry_commit_dirty_list (void) +{ + gnome_vfs_mime_freeze (); + g_list_foreach (dirty_list, (GFunc) model_entry_save, NULL); + gnome_vfs_mime_thaw (); +} diff --git a/capplets/file-types/model-entry.h b/capplets/file-types/model-entry.h index 0a12ab90a..6c9475103 100644 --- a/capplets/file-types/model-entry.h +++ b/capplets/file-types/model-entry.h @@ -61,6 +61,12 @@ void model_entry_insert_child (ModelEntry *entry, void model_entry_remove_child (ModelEntry *entry, ModelEntry *child); +void model_entry_save (ModelEntry *entry); + +void model_entry_append_to_dirty_list (ModelEntry *entry); +void model_entry_remove_from_dirty_list (ModelEntry *entry); +void model_entry_commit_dirty_list (void); + G_END_DECLS #endif /* __MODEL_ENTRY_H */ diff --git a/capplets/file-types/service-edit-dialog.c b/capplets/file-types/service-edit-dialog.c index 59b07443b..667f081b6 100644 --- a/capplets/file-types/service-edit-dialog.c +++ b/capplets/file-types/service-edit-dialog.c @@ -26,6 +26,8 @@ #endif #include +#include +#include #include "service-edit-dialog.h" #include "mime-types-model.h" @@ -35,7 +37,8 @@ enum { PROP_0, PROP_MODEL, - PROP_ITER + PROP_INFO, + PROP_IS_ADD }; struct _ServiceEditDialogPrivate @@ -43,9 +46,9 @@ struct _ServiceEditDialogPrivate ServiceInfo *info; GladeXML *dialog_xml; GtkWidget *dialog_win; + gboolean is_add; GtkTreeModel *model; - GtkTreeIter *iter; }; static GObjectClass *parent_class; @@ -68,9 +71,12 @@ static void service_edit_dialog_dispose (GObject *object); static void service_edit_dialog_finalize (GObject *object); static void fill_dialog (ServiceEditDialog *dialog); +static void setup_add_dialog (ServiceEditDialog *dialog); + static void populate_app_list (ServiceEditDialog *dialog); static void store_data (ServiceEditDialog *dialog); +static gboolean validate_data (ServiceEditDialog *dialog); static void program_sensitive_cb (ServiceEditDialog *dialog, GtkToggleButton *tb); @@ -161,10 +167,18 @@ service_edit_dialog_class_init (ServiceEditDialogClass *class) G_PARAM_READWRITE)); g_object_class_install_property - (object_class, PROP_ITER, - g_param_spec_pointer ("iterator", - _("Iterator"), - _("Iterator"), + (object_class, PROP_INFO, + g_param_spec_pointer ("service-info", + _("Service info"), + _("Structure containing service information"), + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property + (object_class, PROP_IS_ADD, + g_param_spec_boolean ("is-add", + _("Is add"), + _("TRUE if this is an add service dialog"), + FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); parent_class = G_OBJECT_CLASS @@ -186,10 +200,24 @@ service_edit_dialog_set_prop (GObject *object, guint prop_id, const GValue *valu dialog->p->model = GTK_TREE_MODEL (g_value_get_object (value)); break; - case PROP_ITER: - dialog->p->iter = gtk_tree_iter_copy (g_value_get_pointer (value)); - dialog->p->info = SERVICE_INFO (MODEL_ENTRY_FROM_ITER (dialog->p->iter)); - fill_dialog (dialog); + case PROP_INFO: + if (g_value_get_pointer (value) != NULL) { + dialog->p->info = g_value_get_pointer (value); + fill_dialog (dialog); + gtk_widget_show_all (dialog->p->dialog_win); + } + + break; + + case PROP_IS_ADD: + dialog->p->is_add = g_value_get_boolean (value); + + if (dialog->p->is_add) { + dialog->p->info = service_info_new (NULL); + setup_add_dialog (dialog); + gtk_widget_show_all (dialog->p->dialog_win); + } + break; default: @@ -213,8 +241,12 @@ service_edit_dialog_get_prop (GObject *object, guint prop_id, GValue *value, GPa g_value_set_object (value, G_OBJECT (dialog->p->model)); break; - case PROP_ITER: - g_value_set_pointer (value, dialog->p->iter); + case PROP_INFO: + g_value_set_pointer (value, dialog->p->info); + break; + + case PROP_IS_ADD: + g_value_set_boolean (value, dialog->p->is_add); break; default: @@ -256,18 +288,26 @@ service_edit_dialog_finalize (GObject *object) service_edit_dialog = SERVICE_EDIT_DIALOG (object); - gtk_tree_iter_free (service_edit_dialog->p->iter); g_free (service_edit_dialog->p); G_OBJECT_CLASS (parent_class)->finalize (object); } GObject * -service_edit_dialog_new (GtkTreeModel *model, GtkTreeIter *iter) +service_edit_dialog_new (GtkTreeModel *model, ServiceInfo *info) { return g_object_new (service_edit_dialog_get_type (), "model", model, - "iterator", iter, + "service-info", info, + NULL); +} + +GObject * +service_add_dialog_new (GtkTreeModel *model) +{ + return g_object_new (service_edit_dialog_get_type (), + "model", model, + "is-add", TRUE, NULL); } @@ -295,8 +335,22 @@ fill_dialog (ServiceEditDialog *dialog) gnome_file_entry_set_filename (GNOME_FILE_ENTRY (WID ("custom_program_entry")), dialog->p->info->custom_line); populate_app_list (dialog); +} - gtk_widget_show_all (dialog->p->dialog_win); +static void +setup_add_dialog (ServiceEditDialog *dialog) +{ + GtkWidget *menu, *item; + + item = gtk_menu_item_new_with_label (_("Custom")); + menu = gtk_menu_new (); + gtk_menu_append (GTK_MENU (menu), item); + gtk_option_menu_set_menu (GTK_OPTION_MENU (WID ("program_select")), menu); + + gtk_widget_set_sensitive (WID ("program_select"), FALSE); + + gtk_widget_set_sensitive (WID ("look_at_content_toggle"), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("run_program_toggle")), TRUE); } static void @@ -341,6 +395,10 @@ store_data (ServiceEditDialog *dialog) gint idx; GtkTreePath *path; + GtkTreeIter iter; + + if (dialog->p->is_add) + dialog->p->info->protocol = g_strdup (gtk_entry_get_text (GTK_ENTRY (WID ("protocol_entry")))); g_free (dialog->p->info->description); dialog->p->info->description = g_strdup (gtk_entry_get_text (GTK_ENTRY (WID ("description_entry")))); @@ -361,11 +419,68 @@ store_data (ServiceEditDialog *dialog) dialog->p->info->app = gnome_vfs_mime_application_copy (g_object_get_data (menu_item, "app")); - service_info_save (dialog->p->info); + model_entry_append_to_dirty_list (MODEL_ENTRY (dialog->p->info)); - path = gtk_tree_model_get_path (dialog->p->model, dialog->p->iter); - gtk_tree_model_row_changed (dialog->p->model, path, dialog->p->iter); - gtk_tree_path_free (path); + mime_types_model_construct_iter (MIME_TYPES_MODEL (dialog->p->model), + MODEL_ENTRY (dialog->p->info), &iter); + + if (dialog->p->is_add) { + path = gtk_tree_model_get_path (dialog->p->model, &iter); + gtk_tree_model_row_inserted (dialog->p->model, path, &iter); + gtk_tree_path_free (path); + } else { + path = gtk_tree_model_get_path (dialog->p->model, &iter); + gtk_tree_model_row_changed (dialog->p->model, path, &iter); + gtk_tree_path_free (path); + } +} + +static gboolean +validate_data (ServiceEditDialog *dialog) +{ + const gchar *tmp, *tmp1; + gchar *dir; + GtkWidget *err_dialog; + + tmp = gtk_entry_get_text (GTK_ENTRY (WID ("protocol_entry"))); + + if (tmp == NULL || *tmp == '\0') { + err_dialog = gnome_error_dialog_parented + (_("Please enter a protocol name."), + GTK_WINDOW (dialog->p->dialog_win)); + + gtk_window_set_modal (GTK_WINDOW (err_dialog), TRUE); + + return FALSE; + } else { + for (tmp1 = tmp; *tmp1 != '\0' && isalnum (*tmp1); tmp1++); + + if (*tmp1 != '\0') { + err_dialog = gnome_error_dialog_parented + (_("Invalid protocol name. Please enter a protocol name without any spaces or punctuation."), + GTK_WINDOW (dialog->p->dialog_win)); + + gtk_window_set_modal (GTK_WINDOW (err_dialog), TRUE); + + return FALSE; + } + + if (dialog->p->is_add) { + dir = g_strconcat ("/desktop/gnome/url-handlers/", tmp, NULL); + if (gconf_client_dir_exists (gconf_client_get_default (), dir, NULL)) { + err_dialog = gnome_error_dialog_parented + (_("There is already a protocol by that name."), + GTK_WINDOW (dialog->p->dialog_win)); + + gtk_window_set_modal (GTK_WINDOW (err_dialog), TRUE); + + return FALSE; + } + g_free (dir); + } + } + + return TRUE; } static void @@ -399,8 +514,12 @@ program_changed_cb (ServiceEditDialog *dialog, GtkOptionMenu *option_menu) static void response_cb (ServiceEditDialog *dialog, gint response_id) { - if (response_id == GTK_RESPONSE_OK) - store_data (dialog); - - g_object_unref (G_OBJECT (dialog)); + if (response_id == GTK_RESPONSE_OK) { + if (validate_data (dialog)) { + store_data (dialog); + g_object_unref (G_OBJECT (dialog)); + } + } else { + g_object_unref (G_OBJECT (dialog)); + } } diff --git a/capplets/file-types/service-edit-dialog.h b/capplets/file-types/service-edit-dialog.h index 90bb4c19e..0b39cae60 100644 --- a/capplets/file-types/service-edit-dialog.h +++ b/capplets/file-types/service-edit-dialog.h @@ -53,7 +53,8 @@ struct _ServiceEditDialogClass GType service_edit_dialog_get_type (void); GObject *service_edit_dialog_new (GtkTreeModel *model, - GtkTreeIter *iter); + ServiceInfo *info); +GObject *service_add_dialog_new (GtkTreeModel *model); G_END_DECLS diff --git a/capplets/file-types/service-info.c b/capplets/file-types/service-info.c index 4416a3a4f..b759712e8 100644 --- a/capplets/file-types/service-info.c +++ b/capplets/file-types/service-info.c @@ -83,7 +83,7 @@ load_all_services (void) if (protocol_name == NULL) continue; - service_info_new (protocol_name, NULL); + service_info_new (protocol_name); g_free (tmp->data); } @@ -92,13 +92,14 @@ load_all_services (void) } ServiceInfo * -service_info_new (const gchar *protocol, GConfChangeSet *changeset) +service_info_new (const gchar *protocol) { ServiceInfo *info; info = g_new0 (ServiceInfo, 1); - info->protocol = g_strdup (protocol); - info->changeset = changeset; + + if (protocol != NULL) + info->protocol = g_strdup (protocol); info->entry.type = MODEL_ENTRY_SERVICE; info->entry.parent = MODEL_ENTRY (get_services_category_entry ()); @@ -148,12 +149,6 @@ service_info_get_description (ServiceInfo *info) return info->description; } -void -service_info_set_changeset (ServiceInfo *info, GConfChangeSet *changeset) -{ - info->changeset = changeset; -} - void service_info_save (const ServiceInfo *info) { @@ -240,12 +235,7 @@ set_string (const ServiceInfo *info, gchar *end, gchar *value) return; key = get_key_name (info, end); - - if (info->changeset != NULL) - gconf_change_set_set_string (info->changeset, key, value); - else - gconf_client_set_string (gconf_client_get_default (), key, value, NULL); - + gconf_client_set_string (gconf_client_get_default (), key, value, NULL); g_free (key); } @@ -255,34 +245,17 @@ set_bool (const ServiceInfo *info, gchar *end, gboolean value) gchar *key; key = get_key_name (info, end); - - if (info->changeset != NULL) - gconf_change_set_set_bool (info->changeset, key, value); - else - gconf_client_set_bool (gconf_client_get_default (), key, value, NULL); - + gconf_client_set_bool (gconf_client_get_default (), key, value, NULL); g_free (key); } static gchar * get_string (ServiceInfo *info, const gchar *end) { - gchar *key, *ret; - GConfValue *value; - gboolean found = FALSE; + gchar *key, *ret; key = get_key_name (info, end); - - if (info->changeset != NULL) - found = gconf_change_set_check_value (info->changeset, key, &value); - - if (!found || info->changeset == NULL) { - ret = gconf_client_get_string (gconf_client_get_default (), key, NULL); - } else { - ret = g_strdup (gconf_value_get_string (value)); - gconf_value_free (value); - } - + ret = gconf_client_get_string (gconf_client_get_default (), key, NULL); g_free (key); return ret; @@ -293,21 +266,9 @@ get_bool (const ServiceInfo *info, gchar *end) { gchar *key; gboolean ret; - GConfValue *value; - gboolean found = FALSE; key = get_key_name (info, end); - - if (info->changeset != NULL) - found = gconf_change_set_check_value (info->changeset, key, &value); - - if (!found || info->changeset == NULL) { - ret = gconf_client_get_bool (gconf_client_get_default (), key, NULL); - } else { - ret = gconf_value_get_bool (value); - gconf_value_free (value); - } - + ret = gconf_client_get_bool (gconf_client_get_default (), key, NULL); g_free (key); return ret; diff --git a/capplets/file-types/service-info.h b/capplets/file-types/service-info.h index e76093a8e..3891f2388 100644 --- a/capplets/file-types/service-info.h +++ b/capplets/file-types/service-info.h @@ -28,7 +28,6 @@ #include #include #include -#include #include "model-entry.h" @@ -48,14 +47,11 @@ struct _ServiceInfo { GnomeVFSMimeApplication *app; gchar *custom_line; gboolean need_terminal; - - GConfChangeSet *changeset; }; void load_all_services (void); -ServiceInfo *service_info_new (const gchar *protocol, - GConfChangeSet *changeset); +ServiceInfo *service_info_new (const gchar *protocol); void service_info_load_all (ServiceInfo *info); const gchar *service_info_get_description (ServiceInfo *info); void service_info_save (const ServiceInfo *info);