summaryrefslogtreecommitdiff
path: root/capplets/default-applications/mate-da-capplet.c
diff options
context:
space:
mode:
authorZhang Xianwei <[email protected]>2018-12-06 16:34:30 +0800
committerlukefromdc <[email protected]>2018-12-07 20:37:53 +0000
commit08d1e4e1e600d3957f7dc2771960cc5401111456 (patch)
treea327bc732352954b6c1b2f790e0604cdbfc4157e /capplets/default-applications/mate-da-capplet.c
parenta8d6bbbcd905b2a598ede612e15ccc8febd24341 (diff)
downloadmate-control-center-08d1e4e1e600d3957f7dc2771960cc5401111456.tar.bz2
mate-control-center-08d1e4e1e600d3957f7dc2771960cc5401111456.tar.xz
default-applications: Add a widget for a default calculator application
Fix https://github.com/mate-desktop/mate-control-center/issues/291 Signed-off-by: Zhang Xianwei <[email protected]>
Diffstat (limited to 'capplets/default-applications/mate-da-capplet.c')
-rw-r--r--capplets/default-applications/mate-da-capplet.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/capplets/default-applications/mate-da-capplet.c b/capplets/default-applications/mate-da-capplet.c
index 450f1e9f..c42aca02 100644
--- a/capplets/default-applications/mate-da-capplet.c
+++ b/capplets/default-applications/mate-da-capplet.c
@@ -48,6 +48,7 @@ enum {
DA_TYPE_DOCUMENT,
DA_TYPE_WORD,
DA_TYPE_SPREADSHEET,
+ DA_TYPE_CALCULATOR,
DA_N_COLUMNS
};
@@ -155,6 +156,10 @@ set_changed(GtkComboBox* combo, MateDACapplet* capplet, GList* list, gint type)
g_settings_set_string (capplet->mobility_settings, MOBILITY_KEY, g_app_info_get_executable (item));
break;
+ case DA_TYPE_CALCULATOR:
+ g_settings_set_string (capplet->calculator_settings, CALCULATOR_KEY, g_app_info_get_executable (item));
+ break;
+
default:
break;
}
@@ -183,6 +188,7 @@ close_cb(GtkWidget* window, gint response, MateDACapplet* capplet)
set_changed(GTK_COMBO_BOX(capplet->document_combo_box), capplet, capplet->document_viewers, DA_TYPE_DOCUMENT);
set_changed(GTK_COMBO_BOX(capplet->word_combo_box), capplet, capplet->word_editors, DA_TYPE_WORD);
set_changed(GTK_COMBO_BOX(capplet->spreadsheet_combo_box), capplet, capplet->spreadsheet_editors, DA_TYPE_SPREADSHEET);
+ set_changed(GTK_COMBO_BOX(capplet->calculator_combo_box), capplet, capplet->calculators, DA_TYPE_CALCULATOR);
gtk_widget_destroy(window);
gtk_main_quit();
@@ -269,6 +275,12 @@ spreadsheet_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet)
}
static void
+calculator_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet)
+{
+ set_changed(combo, capplet, capplet->calculators, DA_TYPE_CALCULATOR);
+}
+
+static void
refresh_combo_box_icons(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list)
{
GtkTreeIter iter;
@@ -325,6 +337,7 @@ static struct {
{"document_image", "application-pdf"},
{"word_image", "office-document"},
{"spreadsheet_image", "office-spreadsheet"},
+ {"calculator_image", "accessories-calculator"},
};
/* Callback for icon theme change */
@@ -360,6 +373,7 @@ theme_changed_cb(GtkIconTheme* theme, MateDACapplet* capplet)
refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->document_combo_box), capplet->document_viewers);
refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->word_combo_box), capplet->word_editors);
refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->spreadsheet_combo_box), capplet->spreadsheet_editors);
+ refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->calculator_combo_box), capplet->calculators);
}
static void
@@ -437,6 +451,21 @@ fill_combo_box(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list, gch
g_free (default_mobility);
g_object_unref (mobility_settings);
}
+ else if (g_strcmp0(mime, "calculator") == 0)
+ {
+ GSettings *calculator_settings = g_settings_new (CALCULATOR_SCHEMA);
+ gchar *default_calculator = g_settings_get_string (calculator_settings, CALCULATOR_KEY);
+ for (entry = app_list; entry != NULL; entry = g_list_next(entry))
+ {
+ GAppInfo* item = (GAppInfo*) entry->data;
+ if (g_strcmp0 (g_app_info_get_executable (item), default_calculator) == 0)
+ {
+ default_app = item;
+ }
+ }
+ g_free (default_calculator);
+ g_object_unref (calculator_settings);
+ }
else
{
default_app = g_app_info_get_default_for_type (mime, FALSE);
@@ -568,6 +597,7 @@ show_dialog(MateDACapplet* capplet, const gchar* start_page)
capplet->document_combo_box = get_widget("document_combobox");
capplet->word_combo_box = get_widget("word_combobox");
capplet->spreadsheet_combo_box = get_widget("spreadsheet_combobox");
+ capplet->calculator_combo_box = get_widget("calculator_combobox");
capplet->visual_startup_checkbutton = get_widget("visual_start_checkbutton");
capplet->mobility_startup_checkbutton = get_widget("mobility_start_checkbutton");
@@ -614,6 +644,21 @@ show_dialog(MateDACapplet* capplet, const gchar* start_page)
}
capplet->terminals = g_list_reverse (capplet->terminals);
+ /* Calculator havent mime types, so check in .desktop files for
+ Categories=Calculator */
+ capplet->calculators = NULL;
+ all_apps = g_app_info_get_all();
+ for (entry = all_apps; entry != NULL; entry = g_list_next(entry))
+ {
+ GDesktopAppInfo* item = (GDesktopAppInfo*) entry->data;
+ if (g_desktop_app_info_get_categories (item) != NULL &&
+ g_strrstr (g_desktop_app_info_get_categories (item), "Calculator"))
+ {
+ capplet->calculators = g_list_prepend (capplet->calculators, item);
+ }
+ }
+ capplet->calculators = g_list_reverse (capplet->calculators);
+
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->web_combo_box), capplet->web_browsers, "x-scheme-handler/http");
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->mail_combo_box), capplet->mail_readers, "x-scheme-handler/mailto");
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->term_combo_box), capplet->terminals, "terminal");
@@ -627,6 +672,7 @@ show_dialog(MateDACapplet* capplet, const gchar* start_page)
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->document_combo_box), capplet->document_viewers, "application/pdf");
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->word_combo_box), capplet->word_editors, "application/vnd.oasis.opendocument.text");
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->spreadsheet_combo_box), capplet->spreadsheet_editors, "application/vnd.oasis.opendocument.spreadsheet");
+ fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->calculator_combo_box), capplet->calculators, "calculator");
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);
@@ -641,6 +687,7 @@ show_dialog(MateDACapplet* capplet, const gchar* start_page)
g_signal_connect(capplet->document_combo_box, "changed", G_CALLBACK(document_combo_changed_cb), capplet);
g_signal_connect(capplet->word_combo_box, "changed", G_CALLBACK(word_combo_changed_cb), capplet);
g_signal_connect(capplet->spreadsheet_combo_box, "changed", G_CALLBACK(spreadsheet_combo_changed_cb), capplet);
+ g_signal_connect(capplet->calculator_combo_box, "changed", G_CALLBACK(calculator_combo_changed_cb), capplet);
g_settings_bind (capplet->mobility_settings, MOBILITY_STARTUP_KEY, capplet->mobility_startup_checkbutton, "active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (capplet->visual_settings, VISUAL_STARTUP_KEY, capplet->visual_startup_checkbutton, "active", G_SETTINGS_BIND_DEFAULT);
@@ -707,6 +754,7 @@ main(int argc, char** argv)
capplet->terminal_settings = g_settings_new (TERMINAL_SCHEMA);
capplet->mobility_settings = g_settings_new (MOBILITY_SCHEMA);
capplet->visual_settings = g_settings_new (VISUAL_SCHEMA);
+ capplet->calculator_settings = g_settings_new (CALCULATOR_SCHEMA);
show_dialog(capplet, start_page);
g_free(start_page);
@@ -716,6 +764,7 @@ main(int argc, char** argv)
g_object_unref (capplet->terminal_settings);
g_object_unref (capplet->mobility_settings);
g_object_unref (capplet->visual_settings);
+ g_object_unref (capplet->calculator_settings);
return 0;
}