From 06d81df2871a25a93cdf7cffaf87f5cd4f15fe84 Mon Sep 17 00:00:00 2001 From: Perberos Date: Tue, 6 Dec 2011 08:07:40 -0300 Subject: adding support for select text editor and file manager --- capplets/default-applications/mate-da-capplet.c | 304 +++++++++++++++++---- capplets/default-applications/mate-da-capplet.h | 40 ++- capplets/default-applications/mate-da-item.c | 42 +++ capplets/default-applications/mate-da-item.h | 16 ++ capplets/default-applications/mate-da-xml.c | 226 +++++++++------ .../mate-default-applications-properties.ui | 2 +- .../mate-default-applications.xml.in | 56 +++- 7 files changed, 535 insertions(+), 151 deletions(-) (limited to 'capplets') diff --git a/capplets/default-applications/mate-da-capplet.c b/capplets/default-applications/mate-da-capplet.c index 8810caec..6fff57ad 100644 --- a/capplets/default-applications/mate-da-capplet.c +++ b/capplets/default-applications/mate-da-capplet.c @@ -44,23 +44,12 @@ static void close_cb(GtkWidget* window, gint response, gpointer user_data) { if (response == GTK_RESPONSE_HELP) { - capplet_help (GTK_WINDOW (window), "prefs-preferredapps"); + capplet_help(GTK_WINDOW (window), "prefs-preferredapps"); } else { - gtk_widget_destroy (window); - gtk_main_quit (); - } -} - -static void set_icon(GtkImage* image, GtkIconTheme* theme, const char* name) -{ - GdkPixbuf* pixbuf = gtk_icon_theme_load_icon(theme, name, 48, 0, NULL); - - if (pixbuf) - { - gtk_image_set_from_pixbuf(image, pixbuf); - g_object_unref(pixbuf); + gtk_widget_destroy(window); + gtk_main_quit(); } } @@ -164,6 +153,9 @@ static void web_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet) is_custom_active = TRUE; } + /* Si, aun falta para poder crear personalizables... */ + has_net_remote = FALSE; + is_custom_active = FALSE; gtk_widget_set_sensitive(capplet->default_radiobutton, has_net_remote); gtk_widget_set_sensitive(capplet->new_win_radiobutton, has_net_remote); gtk_widget_set_sensitive(capplet->new_tab_radiobutton, has_net_remote); @@ -230,11 +222,103 @@ static void mail_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet) } } + /* Si, aun falta para poder crear personalizables... */ + is_custom_active = FALSE; gtk_widget_set_sensitive(capplet->mail_reader_command_entry, is_custom_active); gtk_widget_set_sensitive(capplet->mail_reader_command_label, is_custom_active); gtk_widget_set_sensitive(capplet->mail_reader_terminal_checkbutton, is_custom_active); } +static void file_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet) +{ + guint current_index; + gboolean is_custom_active; + + current_index = gtk_combo_box_get_active(combo); + is_custom_active = (current_index >= g_list_length(capplet->file_managers)); + + if (current_index != -1) + { + MateDAItem* item = (MateDAItem*) g_list_nth_data(capplet->file_managers, current_index); + + if (item != NULL) + { + /* Para obtener la lista de elementos, y si está en la lista, agregar ese + * item. + * De lo contrario, se crea un elemento especial. */ + GList* recommended = g_app_info_get_recommended_for_type("inode/directory"); + + if (recommended!= NULL) + { + GList* app; + + for (app = recommended; app != NULL; app = app->next) + { + /* nice hack bro */ + if (strcmp(item->executable, g_app_info_get_executable((GAppInfo*) app->data)) == 0) + { + /* falta agregar más mime-types */ + g_app_info_set_as_default_for_type((GAppInfo*) app->data, "inode/directory", NULL); + } + } + + g_list_free_full(recommended, g_object_unref); + } + } + } + + /* Si, aun falta para poder crear personalizables... */ + is_custom_active = FALSE; + gtk_widget_set_sensitive(capplet->file_manager_command_entry, is_custom_active); + gtk_widget_set_sensitive(capplet->file_manager_command_label, is_custom_active); + gtk_widget_set_sensitive(capplet->file_manager_terminal_checkbutton, is_custom_active); +} + +static void text_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet) +{ + guint current_index; + gboolean is_custom_active; + + current_index = gtk_combo_box_get_active(combo); + is_custom_active = (current_index >= g_list_length(capplet->text_editors)); + + if (current_index != -1) + { + MateDAItem* item = (MateDAItem*) g_list_nth_data(capplet->text_editors, current_index); + + if (item != NULL) + { + /* Para obtener la lista de elementos, y si está en la lista, agregar ese + * item. + * De lo contrario, se crea un elemento especial. */ + GList* recommended = g_app_info_get_recommended_for_type("text/plain"); + + if (recommended!= NULL) + { + GList* app; + + for (app = recommended; app != NULL; app = app->next) + { + /* nice hack bro */ + if (strcmp(item->executable, g_app_info_get_executable((GAppInfo*) app->data)) == 0) + { + /* falta agregar más mime-types */ + g_app_info_set_as_default_for_type((GAppInfo*) app->data, "text/plain", NULL); + } + } + + g_list_free_full(recommended, g_object_unref); + } + } + } + + /* Si, aun falta para poder crear personalizables... */ + is_custom_active = FALSE; + gtk_widget_set_sensitive(capplet->text_editor_command_entry, is_custom_active); + gtk_widget_set_sensitive(capplet->text_editor_command_label, is_custom_active); + gtk_widget_set_sensitive(capplet->text_editor_terminal_checkbutton, is_custom_active); +} + static void media_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet) { guint current_index; @@ -243,6 +327,41 @@ static void media_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet) current_index = gtk_combo_box_get_active (combo); is_custom_active = (current_index >= g_list_length (capplet->media_players)); + if (current_index != -1) + { + MateDAItem* item = (MateDAItem*) g_list_nth_data(capplet->media_players, current_index); + + if (item != NULL) + { + /* Para obtener la lista de elementos, y si está en la lista, agregar ese + * item. + * De lo contrario, se crea un elemento especial. */ + GList* recommended = g_app_info_get_recommended_for_type("audio/x-vorbis+ogg"); + + if (recommended!= NULL) + { + GList* app; + + for (app = recommended; app != NULL; app = app->next) + { + /* nice hack bro */ + if (strcmp(item->executable, g_app_info_get_executable((GAppInfo*) app->data)) == 0) + { + /* por alguna extraña razon, solo se usa mailto, en vez de mail. */ + g_app_info_set_as_default_for_type((GAppInfo*) app->data, "audio/x-scpls", NULL); + g_app_info_set_as_default_for_type((GAppInfo*) app->data, "audio/mpeg", NULL); + g_app_info_set_as_default_for_type((GAppInfo*) app->data, "audio/x-wav", NULL); + g_app_info_set_as_default_for_type((GAppInfo*) app->data, "audio/x-mpegurl", NULL); + } + } + + g_list_free_full(recommended, g_object_unref); + } + } + } + + /* Si, aun falta para poder crear personalizables... */ + is_custom_active = FALSE; gtk_widget_set_sensitive(capplet->media_player_command_entry, is_custom_active); gtk_widget_set_sensitive(capplet->media_player_command_label, is_custom_active); gtk_widget_set_sensitive(capplet->media_player_terminal_checkbutton, is_custom_active); @@ -286,7 +405,6 @@ static void mobility_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet gtk_widget_set_sensitive (capplet->mobility_command_label, is_custom_active); } - static void image_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet) { guint current_index; @@ -334,7 +452,6 @@ static void image_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet) gtk_widget_set_sensitive(capplet->image_viewer_terminal_checkbutton, is_custom_active); } - static void refresh_combo_box_icons(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list) { GList *entry; @@ -386,7 +503,14 @@ static void theme_changed_cb(GtkIconTheme* theme, MateDACapplet* capplet) for (i = 0; i < G_N_ELEMENTS(icons); i++) { icon = gtk_builder_get_object(capplet->builder, icons[i].name); - set_icon (GTK_IMAGE (icon), theme, icons[i].icon); + + GdkPixbuf* pixbuf = gtk_icon_theme_load_icon(theme, icons[i].icon, 48, 0, NULL); + + if (pixbuf) + { + gtk_image_set_from_pixbuf(GTK_IMAGE(icon), pixbuf); + g_object_unref(pixbuf); + } } refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->web_combo_box), capplet->web_browsers); @@ -395,6 +519,8 @@ static void theme_changed_cb(GtkIconTheme* theme, MateDACapplet* capplet) refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->term_combo_box), capplet->terminals); refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->visual_combo_box), capplet->visual_ats); refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->mobility_combo_box), capplet->mobility_ats); + refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->file_combo_box), capplet->file_managers); + refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->text_combo_box), capplet->text_editors); } static void screen_changed_cb(GtkWidget* widget, GdkScreen* screen, MateDACapplet* capplet) @@ -414,29 +540,36 @@ static void screen_changed_cb(GtkWidget* widget, GdkScreen* screen, MateDACapple capplet->icon_theme = theme; } -static gint generic_item_comp(gconstpointer list_item, gconstpointer command) +static gint generic_item_comp(const void* list_item, const void* command) { - return (strcmp (((MateDAItem *) list_item)->command, (gchar *) command)); + return (strcmp(((MateDAItem*) list_item)->command, (char*) command)); } -static gint web_item_comp(gconstpointer item, gconstpointer command) +static int web_item_comp(const void* item, const void* command) { - MateDAWebItem *web_list_item; + MateDAWebItem* web_list_item; - web_list_item = (MateDAWebItem *) item; + web_list_item = (MateDAWebItem*) item; - if (strcmp (web_list_item->generic.command, (gchar *) command) == 0) - return 0; + if (strcmp (web_list_item->generic.command, (char*) command) == 0) + { + return 0; + } - if (web_list_item->netscape_remote) { - if (strcmp (web_list_item->tab_command, (gchar *) command) == 0) - return 0; + if (web_list_item->netscape_remote) + { + if (strcmp (web_list_item->tab_command, (char*) command) == 0) + { + return 0; + } - if (strcmp (web_list_item->win_command, (gchar *) command) == 0) - return 0; + if (strcmp (web_list_item->win_command, (char*) command) == 0) + { + return 0; + } } - return (strcmp (web_list_item->generic.command, (gchar *) command)); + return (strcmp(web_list_item->generic.command, (char*) command)); } static void web_mateconf_changed_cb(MateConfPropertyEditor* peditor, gchar* key, MateConfValue* value, MateDACapplet* capplet) @@ -558,37 +691,42 @@ static void web_browser_update_radio_buttons(MateDACapplet* capplet, const gchar static MateConfValue* web_combo_conv_to_widget (MateConfPropertyEditor *peditor, const MateConfValue *value) { - MateConfValue *ret; - GList *entry, *handlers; - const gchar *command; - gint index; - MateDACapplet *capplet; + MateConfValue *ret; + GList *entry, *handlers; + const gchar *command; + gint index; + MateDACapplet *capplet; - g_object_get (G_OBJECT (peditor), "data", &capplet, NULL); + g_object_get (G_OBJECT (peditor), "data", &capplet, NULL); - command = mateconf_value_get_string (value); - handlers = capplet->web_browsers; + command = mateconf_value_get_string (value); + handlers = capplet->web_browsers; - if (handlers) - { - entry = g_list_find_custom (handlers, command, (GCompareFunc) web_item_comp); - if (entry) - index = g_list_position (handlers, entry); - else - index = g_list_length (handlers) + 1; - } - else - { - /* if the item has no handlers lsit then select the Custom item */ - index = 1; - } + if (handlers) + { + entry = g_list_find_custom (handlers, command, (GCompareFunc) web_item_comp); + + if (entry) + { + index = g_list_position (handlers, entry); + } + else + { + index = g_list_length (handlers) + 1; + } + } + else + { + /* if the item has no handlers lsit then select the Custom item */ + index = 1; + } - web_browser_update_radio_buttons (capplet, command); + web_browser_update_radio_buttons (capplet, command); - ret = mateconf_value_new (MATECONF_VALUE_INT); - mateconf_value_set_int (ret, index); + ret = mateconf_value_new (MATECONF_VALUE_INT); + mateconf_value_set_int (ret, index); - return ret; + return ret; } static MateConfValue* web_combo_conv_from_widget (MateConfPropertyEditor *peditor, const MateConfValue *value) @@ -876,6 +1014,14 @@ static void show_dialog(MateDACapplet* capplet, const gchar* start_page) capplet->image_viewer_command_label = get_widget("image_command_label"); capplet->image_viewer_terminal_checkbutton = get_widget("image_terminal_checkbox"); + capplet->text_editor_command_entry = get_widget("text_command_entry"); + capplet->text_editor_command_label = get_widget("text_command_label"); + capplet->text_editor_terminal_checkbutton = get_widget("text_terminal_checkbox"); + + capplet->file_manager_command_entry = get_widget("filemanager_command_entry"); + capplet->file_manager_command_label = get_widget("filemanager_command_label"); + capplet->file_manager_terminal_checkbutton = get_widget("filemanager_terminal_checkbox"); + capplet->mobility_command_entry = get_widget("mobility_command_entry"); capplet->mobility_command_label = get_widget("mobility_command_label"); capplet->mobility_startup_checkbutton = get_widget("mobility_start_checkbutton"); @@ -888,7 +1034,7 @@ static void show_dialog(MateDACapplet* capplet, const gchar* start_page) capplet->mobility_combo_box = get_widget("mobility_combobox"); capplet->text_combo_box = get_widget("text_combobox"); - capplet->file_combo_box = get_widget("file_combobox"); + capplet->file_combo_box = get_widget("filemanager_combobox"); capplet->image_combo_box = get_widget("image_combobox"); @@ -902,6 +1048,8 @@ static void show_dialog(MateDACapplet* capplet, const gchar* start_page) fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->visual_combo_box), capplet->visual_ats); fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->mobility_combo_box), capplet->mobility_ats); fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->image_combo_box), capplet->image_viewers); + fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->text_combo_box), capplet->text_editors); + fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->file_combo_box), capplet->file_managers); g_signal_connect(capplet->web_combo_box, "changed", G_CALLBACK(web_combo_changed_cb), capplet); g_signal_connect(capplet->mail_combo_box, "changed", G_CALLBACK(mail_combo_changed_cb), capplet); @@ -910,6 +1058,8 @@ static void show_dialog(MateDACapplet* capplet, const gchar* start_page) g_signal_connect(capplet->visual_combo_box, "changed", G_CALLBACK(visual_combo_changed_cb), capplet); g_signal_connect(capplet->mobility_combo_box, "changed", G_CALLBACK(mobility_combo_changed_cb), capplet); g_signal_connect(capplet->image_combo_box, "changed", G_CALLBACK(image_combo_changed_cb), capplet); + g_signal_connect(capplet->text_combo_box, "changed", G_CALLBACK(text_combo_changed_cb), capplet); + g_signal_connect(capplet->file_combo_box, "changed", G_CALLBACK(file_combo_changed_cb), capplet); g_signal_connect(capplet->default_radiobutton, "toggled", G_CALLBACK(web_radiobutton_toggled_cb), capplet); @@ -996,6 +1146,46 @@ static void show_dialog(MateDACapplet* capplet, const gchar* start_page) capplet->image_viewer_terminal_checkbutton, NULL); + /* File manager */ + mateconf_peditor_new_combo_box(NULL, + DEFAULT_APPS_KEY_FILE_EXEC, + capplet->file_combo_box, + "conv-from-widget-cb", combo_conv_from_widget, + "conv-to-widget-cb", combo_conv_to_widget, + "data", capplet->file_managers, + NULL); + + mateconf_peditor_new_string (NULL, + DEFAULT_APPS_KEY_FILE_EXEC, + capplet->file_manager_command_entry, + NULL); + + mateconf_peditor_new_boolean (NULL, + DEFAULT_APPS_KEY_FILE_NEEDS_TERM, + capplet->file_manager_terminal_checkbutton, + NULL); + + + /* Text editors */ + mateconf_peditor_new_combo_box(NULL, + DEFAULT_APPS_KEY_TEXT_EXEC, + capplet->text_combo_box, + "conv-from-widget-cb", combo_conv_from_widget, + "conv-to-widget-cb", combo_conv_to_widget, + "data", capplet->text_editors, + NULL); + + mateconf_peditor_new_string (NULL, + DEFAULT_APPS_KEY_TEXT_EXEC, + capplet->text_editor_command_entry, + NULL); + + mateconf_peditor_new_boolean (NULL, + DEFAULT_APPS_KEY_TEXT_NEEDS_TERM, + capplet->text_editor_terminal_checkbutton, + NULL); + + /* Terminal */ mateconf_peditor_new_combo_box (NULL, DEFAULT_APPS_KEY_TERMINAL_EXEC, @@ -1062,7 +1252,7 @@ static void show_dialog(MateDACapplet* capplet, const gchar* start_page) capplet->mobility_startup_checkbutton, NULL); - gtk_window_set_icon_name (GTK_WINDOW (capplet->window), "preferences-desktop-default-applications"); + gtk_window_set_icon_name(GTK_WINDOW (capplet->window), "preferences-desktop-default-applications"); if (start_page != NULL) { diff --git a/capplets/default-applications/mate-da-capplet.h b/capplets/default-applications/mate-da-capplet.h index e149e39b..3b9d328f 100644 --- a/capplets/default-applications/mate-da-capplet.h +++ b/capplets/default-applications/mate-da-capplet.h @@ -66,6 +66,14 @@ #define DEFAULT_APPS_KEY_IMAGE_EXEC DEFAULT_APPS_KEY_IMAGE_PATH"/exec" #define DEFAULT_APPS_KEY_IMAGE_NEEDS_TERM DEFAULT_APPS_KEY_IMAGE_PATH"/needs_term" +#define DEFAULT_APPS_KEY_TEXT_PATH "/desktop/mate/applications/text" +#define DEFAULT_APPS_KEY_TEXT_EXEC DEFAULT_APPS_KEY_TEXT_PATH"/exec" +#define DEFAULT_APPS_KEY_TEXT_NEEDS_TERM DEFAULT_APPS_KEY_TEXT_PATH"/needs_term" + +#define DEFAULT_APPS_KEY_FILE_PATH "/desktop/mate/applications/file" +#define DEFAULT_APPS_KEY_FILE_EXEC DEFAULT_APPS_KEY_FILE_PATH"/exec" +#define DEFAULT_APPS_KEY_FILE_NEEDS_TERM DEFAULT_APPS_KEY_FILE_PATH"/needs_term" + #define DEFAULT_APPS_KEY_VISUAL_PATH "/desktop/mate/applications/at/visual" #define DEFAULT_APPS_KEY_VISUAL_EXEC DEFAULT_APPS_KEY_VISUAL_PATH"/exec" #define DEFAULT_APPS_KEY_VISUAL_STARTUP DEFAULT_APPS_KEY_VISUAL_PATH"/startup" @@ -74,9 +82,7 @@ #define DEFAULT_APPS_KEY_MOBILITY_EXEC DEFAULT_APPS_KEY_MOBILITY_PATH"/exec" #define DEFAULT_APPS_KEY_MOBILITY_STARTUP DEFAULT_APPS_KEY_MOBILITY_PATH"/startup" -typedef struct _MateDACapplet MateDACapplet; - -struct _MateDACapplet { +typedef struct _MateDACapplet { GtkBuilder* builder; GtkIconTheme* icon_theme; @@ -94,7 +100,8 @@ struct _MateDACapplet { GtkWidget* text_combo_box; GtkWidget* image_combo_box; - + /* navegador web + * por el momento default,new_win,new_tab no se utilizan */ GtkWidget* web_browser_command_entry; GtkWidget* web_browser_command_label; GtkWidget* web_browser_terminal_checkbutton; @@ -106,37 +113,44 @@ struct _MateDACapplet { GtkWidget* file_manager_command_entry; GtkWidget* file_manager_command_label; GtkWidget* file_manager_terminal_checkbutton; - GtkWidget* file_manager_default_radiobutton; - GtkWidget* file_manager_new_win_radiobutton; - GtkWidget* file_manager_new_tab_radiobutton; + /* editor de texto */ + GtkWidget* text_editor_command_entry; + GtkWidget* text_editor_command_label; + GtkWidget* text_editor_terminal_checkbutton; + /* cliente de correo */ GtkWidget* mail_reader_command_entry; GtkWidget* mail_reader_command_label; GtkWidget* mail_reader_terminal_checkbutton; + /* terminal */ GtkWidget* terminal_command_entry; GtkWidget* terminal_command_label; GtkWidget* terminal_exec_flag_entry; GtkWidget* terminal_exec_flag_label; + /* visor de imagenes */ + GtkWidget* image_viewer_command_entry; + GtkWidget* image_viewer_command_label; + GtkWidget* image_viewer_terminal_checkbutton; + + /* reproductor de musica */ GtkWidget* media_player_command_entry; GtkWidget* media_player_command_label; GtkWidget* media_player_terminal_checkbutton; + /* accesibilidad visual */ GtkWidget* visual_command_entry; GtkWidget* visual_command_label; GtkWidget* visual_startup_checkbutton; + /* accesibilidad motriz */ GtkWidget* mobility_command_entry; GtkWidget* mobility_command_label; GtkWidget* mobility_startup_checkbutton; - GtkWidget* image_viewer_command_entry; - GtkWidget* image_viewer_command_label; - GtkWidget* image_viewer_terminal_checkbutton; - MateConfClient* mateconf; GList* web_browsers; @@ -145,9 +159,9 @@ struct _MateDACapplet { GList* media_players; GList* visual_ats; GList* mobility_ats; - /* Para el File Manager */ GList* file_managers; + GList* text_editors; GList* image_viewers; -}; +} MateDACapplet; #endif diff --git a/capplets/default-applications/mate-da-item.c b/capplets/default-applications/mate-da-item.c index 7cdfa768..ab3803de 100644 --- a/capplets/default-applications/mate-da-item.c +++ b/capplets/default-applications/mate-da-item.c @@ -56,6 +56,20 @@ MateDAImageItem* mate_da_image_item_new(void) return item; } +MateDATextItem* mate_da_text_item_new(void) +{ + MateDATextItem* item = g_new0(MateDATextItem, 1); + + return item; +} + +MateDAFileItem* mate_da_file_item_new(void) +{ + MateDAFileItem* item = g_new0(MateDAFileItem, 1); + + return item; +} + MateDAMobilityItem* mate_da_mobility_item_new(void) { MateDAMobilityItem* item = g_new0(MateDAMobilityItem, 1); @@ -108,6 +122,34 @@ void mate_da_image_item_free(MateDAImageItem* item) } } +void mate_da_text_item_free(MateDATextItem* item) +{ + if (item != NULL) + { + g_free(item->generic.name); + g_free(item->generic.executable); + g_free(item->generic.command); + g_free(item->generic.icon_name); + g_free(item->generic.icon_path); + + g_free(item); + } +} + +void mate_da_file_item_free(MateDAFileItem* item) +{ + if (item != NULL) + { + g_free(item->generic.name); + g_free(item->generic.executable); + g_free(item->generic.command); + g_free(item->generic.icon_name); + g_free(item->generic.icon_path); + + g_free(item); + } +} + void mate_da_term_item_free(MateDATermItem* item) { if (item != NULL) diff --git a/capplets/default-applications/mate-da-item.h b/capplets/default-applications/mate-da-item.h index 3462840c..b6a3b573 100644 --- a/capplets/default-applications/mate-da-item.h +++ b/capplets/default-applications/mate-da-item.h @@ -49,6 +49,16 @@ typedef struct _MateDAImageItem { gboolean run_in_terminal; } MateDAImageItem; +typedef struct _MateDATextItem { + MateDAItem generic; + gboolean run_in_terminal; +} MateDATextItem; + +typedef struct _MateDAFileItem { + MateDAItem generic; + gboolean run_in_terminal; +} MateDAFileItem; + typedef struct _MateDATermItem { MateDAItem generic; gchar* exec_flag; @@ -79,6 +89,12 @@ void mate_da_visual_item_free(MateDAVisualItem* item); MateDAImageItem* mate_da_image_item_new(void); void mate_da_image_item_free(MateDAImageItem* item); +MateDATextItem* mate_da_text_item_new(void); +void mate_da_text_item_free(MateDATextItem* item); + +MateDAFileItem* mate_da_file_item_new(void); +void mate_da_file_item_free(MateDAFileItem* item); + MateDAMobilityItem* mate_da_mobility_item_new(void); void mate_da_mobility_item_free(MateDAMobilityItem* item); diff --git a/capplets/default-applications/mate-da-xml.c b/capplets/default-applications/mate-da-xml.c index ba41aa1f..eba290db 100644 --- a/capplets/default-applications/mate-da-xml.c +++ b/capplets/default-applications/mate-da-xml.c @@ -31,80 +31,92 @@ static gboolean mate_da_xml_get_bool(const xmlNode* parent, const gchar* val_name) { - xmlNode *element; + xmlNode* element; gboolean ret_val = FALSE; - xmlChar *xml_val_name; + xmlChar* xml_val_name; gint len; - g_return_val_if_fail (parent != NULL, FALSE); - g_return_val_if_fail (parent->children != NULL, ret_val); - g_return_val_if_fail (val_name != NULL, FALSE); + if (parent != NULL && parent->children != NULL && val_name == NULL) + { + xml_val_name = xmlCharStrdup(val_name); + len = xmlStrlen(xml_val_name); - xml_val_name = xmlCharStrdup (val_name); - len = xmlStrlen (xml_val_name); + for (element = parent->children; element != NULL; element = element->next) + { + if (!xmlStrncmp(element->name, xml_val_name, len)) + { + xmlChar* cont = xmlNodeGetContent(element); - for (element = parent->children; element != NULL; element = element->next) { - if (!xmlStrncmp (element->name, xml_val_name, len)) { - xmlChar *cont = xmlNodeGetContent (element); + if (!xmlStrcasecmp(cont, (const xmlChar*) "true") || !xmlStrcasecmp(cont, (const xmlChar*) "1")) + { + ret_val = TRUE; + } + else + { + ret_val = FALSE; + } - if (!xmlStrcasecmp(cont, (const xmlChar*) "true") || !xmlStrcasecmp(cont, (const xmlChar*) "1")) - ret_val = TRUE; - else - ret_val = FALSE; + xmlFree(cont); + } + } - xmlFree (cont); + xmlFree(xml_val_name); } - } - xmlFree (xml_val_name); return ret_val; } static gchar* mate_da_xml_get_string(const xmlNode* parent, const gchar* val_name) { - const gchar * const *sys_langs; - xmlChar *node_lang; - xmlNode *element; - gchar *ret_val = NULL; - xmlChar *xml_val_name; - gint len; - gint i; - - g_return_val_if_fail (parent != NULL, ret_val); - g_return_val_if_fail (parent->children != NULL, ret_val); - g_return_val_if_fail (val_name != NULL, ret_val); - -#if GLIB_CHECK_VERSION (2, 6, 0) - sys_langs = g_get_language_names (); -#endif - - xml_val_name = xmlCharStrdup (val_name); - len = xmlStrlen (xml_val_name); - - for (element = parent->children; element != NULL; element = element->next) { - if (!xmlStrncmp (element->name, xml_val_name, len)) { - node_lang = xmlNodeGetLang (element); - - if (node_lang == NULL) { - ret_val = (gchar *) xmlNodeGetContent (element); - } - else { - for (i = 0; sys_langs[i] != NULL; i++) { - if (!strcmp(sys_langs[i], (char*) node_lang)) { - ret_val = (gchar *) xmlNodeGetContent (element); - /* since sys_langs is sorted from most desirable to - * least desirable, exit at first match - */ - break; - } + const gchar* const* sys_langs; + xmlChar* node_lang; + xmlNode* element; + gchar* ret_val = NULL; + xmlChar* xml_val_name; + gint len; + gint i; + + if (parent != NULL && parent->children != NULL && val_name != NULL) + { + #if GLIB_CHECK_VERSION (2, 6, 0) + sys_langs = g_get_language_names(); + #endif + + xml_val_name = xmlCharStrdup(val_name); + len = xmlStrlen(xml_val_name); + + for (element = parent->children; element != NULL; element = element->next) + { + if (!xmlStrncmp(element->name, xml_val_name, len)) + { + node_lang = xmlNodeGetLang(element); + + if (node_lang == NULL) + { + ret_val = (gchar *) xmlNodeGetContent(element); + } + else + { + for (i = 0; sys_langs[i] != NULL; i++) + { + if (!strcmp(sys_langs[i], (char*) node_lang)) + { + ret_val = (gchar*) xmlNodeGetContent(element); + /* since sys_langs is sorted from most desirable to + * least desirable, exit at first match */ + break; + } + } + } + + xmlFree(node_lang); + } } - } - xmlFree (node_lang); + + xmlFree(xml_val_name); } - } - xmlFree (xml_val_name); - return ret_val; + return ret_val; } static gboolean is_executable_valid(gchar* executable) @@ -134,6 +146,8 @@ static void mate_da_xml_load_xml(MateDACapplet* capplet, const gchar* filename) MateDAVisualItem* visual_item; MateDAMobilityItem* mobility_item; MateDAImageItem* image_item; + MateDATextItem* text_item; + MateDAFileItem* file_item; xml_doc = xmlParseFile(filename); @@ -292,6 +306,62 @@ static void mate_da_xml_load_xml(MateDACapplet* capplet, const gchar* filename) } } } + else if (!xmlStrncmp(section->name, (const xmlChar*) "text-editors", strlen("text-editors"))) + { + for (element = section->children; element != NULL; element = element->next) + { + if (!xmlStrncmp(element->name, (const xmlChar*) "text-editor", strlen("text-editor"))) + { + executable = mate_da_xml_get_string(element, "executable"); + + if (is_executable_valid(executable)) + { + text_item = mate_da_text_item_new(); + + text_item->generic.name = mate_da_xml_get_string(element, "name"); + text_item->generic.executable = executable; + text_item->generic.command = mate_da_xml_get_string(element, "command"); + text_item->generic.icon_name = mate_da_xml_get_string(element, "icon-name"); + + text_item->run_in_terminal = mate_da_xml_get_bool(element, "run-in-terminal"); + + capplet->text_editors = g_list_append(capplet->text_editors, text_item); + } + else + { + g_free(executable); + } + } + } + } + else if (!xmlStrncmp(section->name, (const xmlChar*) "file-managers", strlen("file-managers"))) + { + for (element = section->children; element != NULL; element = element->next) + { + if (!xmlStrncmp(element->name, (const xmlChar*) "file-manager", strlen("file-manager"))) + { + executable = mate_da_xml_get_string(element, "executable"); + + if (is_executable_valid(executable)) + { + file_item = mate_da_file_item_new(); + + file_item->generic.name = mate_da_xml_get_string(element, "name"); + file_item->generic.executable = executable; + file_item->generic.command = mate_da_xml_get_string(element, "command"); + file_item->generic.icon_name = mate_da_xml_get_string(element, "icon-name"); + + file_item->run_in_terminal = mate_da_xml_get_bool(element, "run-in-terminal"); + + capplet->file_managers = g_list_append(capplet->file_managers, file_item); + } + else + { + g_free(executable); + } + } + } + } else if (!xmlStrncmp(section->name, (const xmlChar*) "a11y-visual", strlen("a11y-visual"))) { for (element = section->children; element != NULL; element = element->next) @@ -380,24 +450,26 @@ void mate_da_xml_load_list(MateDACapplet* capplet) void mate_da_xml_free(MateDACapplet* capplet) { - g_list_foreach(capplet->web_browsers, (GFunc) mate_da_web_item_free, NULL); - g_list_foreach(capplet->mail_readers, (GFunc) mate_da_simple_item_free, NULL); - g_list_foreach(capplet->terminals, (GFunc) mate_da_term_item_free, NULL); - g_list_foreach(capplet->media_players, (GFunc) mate_da_simple_item_free, NULL); - g_list_foreach(capplet->visual_ats, (GFunc) mate_da_visual_item_free, NULL); - g_list_foreach(capplet->mobility_ats, (GFunc) mate_da_mobility_item_free, NULL); - //g_list_foreach(capplet->filemanagers, (GFunc) mate_da_filemanager_item_free, NULL); - g_list_foreach(capplet->image_viewers, (GFunc) mate_da_image_item_free, NULL); - - g_list_free(capplet->web_browsers); - g_list_free(capplet->mail_readers); - g_list_free(capplet->terminals); - g_list_free(capplet->media_players); - g_list_free(capplet->visual_ats); - g_list_free(capplet->mobility_ats); - g_list_free(capplet->image_viewers); - //g_list_free(capplet->filemanagers); - - g_object_unref(capplet->builder); - g_free(capplet); + g_list_foreach(capplet->web_browsers, (GFunc) mate_da_web_item_free, NULL); + g_list_foreach(capplet->mail_readers, (GFunc) mate_da_simple_item_free, NULL); + g_list_foreach(capplet->terminals, (GFunc) mate_da_term_item_free, NULL); + g_list_foreach(capplet->media_players, (GFunc) mate_da_simple_item_free, NULL); + g_list_foreach(capplet->visual_ats, (GFunc) mate_da_visual_item_free, NULL); + g_list_foreach(capplet->mobility_ats, (GFunc) mate_da_mobility_item_free, NULL); + g_list_foreach(capplet->image_viewers, (GFunc) mate_da_image_item_free, NULL); + g_list_foreach(capplet->text_editors, (GFunc) mate_da_text_item_free, NULL); + g_list_foreach(capplet->file_managers, (GFunc) mate_da_file_item_free, NULL); + + g_list_free(capplet->web_browsers); + g_list_free(capplet->mail_readers); + g_list_free(capplet->terminals); + g_list_free(capplet->media_players); + g_list_free(capplet->visual_ats); + g_list_free(capplet->mobility_ats); + g_list_free(capplet->image_viewers); + g_list_free(capplet->text_editors); + g_list_free(capplet->file_managers); + + g_object_unref(capplet->builder); + g_free(capplet); } diff --git a/capplets/default-applications/mate-default-applications-properties.ui b/capplets/default-applications/mate-default-applications-properties.ui index bf1073c1..0da56bc6 100644 --- a/capplets/default-applications/mate-default-applications-properties.ui +++ b/capplets/default-applications/mate-default-applications-properties.ui @@ -321,7 +321,7 @@ - True + 6 diff --git a/capplets/default-applications/mate-default-applications.xml.in b/capplets/default-applications/mate-default-applications.xml.in index b4c1c6d7..204e562a 100644 --- a/capplets/default-applications/mate-default-applications.xml.in +++ b/capplets/default-applications/mate-default-applications.xml.in @@ -286,7 +286,7 @@ - <_name>MATE File Manager + <_name>MATE file manager caja false caja %s @@ -303,10 +303,10 @@ <_name>Thunar - thunar + Thunar false thunar %s - thunar + Thunar @@ -552,7 +552,57 @@ + + + <_name>Gedit + gedit + gedit %s + accessories-text-editor + false + + + + <_name>MATE text editor + pluma + pluma %s + accessories-text-editor + false + + + + + + <_name>leafpad + leafpad + leafpad %s + leafpad + false + + + + + + + -- cgit v1.2.1