Skip to content

Commit 08d1e4e

Browse files
zhangxianwei8lukefromdc
authored andcommitted
default-applications: Add a widget for a default calculator application
Fix #291 Signed-off-by: Zhang Xianwei <[email protected]>
1 parent a8d6bbb commit 08d1e4e

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

‎capplets/default-applications/mate-da-capplet.c‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum {
4848
DA_TYPE_DOCUMENT,
4949
DA_TYPE_WORD,
5050
DA_TYPE_SPREADSHEET,
51+
DA_TYPE_CALCULATOR,
5152
DA_N_COLUMNS
5253
};
5354

@@ -155,6 +156,10 @@ set_changed(GtkComboBox* combo, MateDACapplet* capplet, GList* list, gint type)
155156
g_settings_set_string (capplet->mobility_settings, MOBILITY_KEY, g_app_info_get_executable (item));
156157
break;
157158

159+
case DA_TYPE_CALCULATOR:
160+
g_settings_set_string (capplet->calculator_settings, CALCULATOR_KEY, g_app_info_get_executable (item));
161+
break;
162+
158163
default:
159164
break;
160165
}
@@ -183,6 +188,7 @@ close_cb(GtkWidget* window, gint response, MateDACapplet* capplet)
183188
set_changed(GTK_COMBO_BOX(capplet->document_combo_box), capplet, capplet->document_viewers, DA_TYPE_DOCUMENT);
184189
set_changed(GTK_COMBO_BOX(capplet->word_combo_box), capplet, capplet->word_editors, DA_TYPE_WORD);
185190
set_changed(GTK_COMBO_BOX(capplet->spreadsheet_combo_box), capplet, capplet->spreadsheet_editors, DA_TYPE_SPREADSHEET);
191+
set_changed(GTK_COMBO_BOX(capplet->calculator_combo_box), capplet, capplet->calculators, DA_TYPE_CALCULATOR);
186192

187193
gtk_widget_destroy(window);
188194
gtk_main_quit();
@@ -268,6 +274,12 @@ spreadsheet_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet)
268274
set_changed(combo, capplet, capplet->spreadsheet_editors, DA_TYPE_SPREADSHEET);
269275
}
270276

277+
static void
278+
calculator_combo_changed_cb(GtkComboBox* combo, MateDACapplet* capplet)
279+
{
280+
set_changed(combo, capplet, capplet->calculators, DA_TYPE_CALCULATOR);
281+
}
282+
271283
static void
272284
refresh_combo_box_icons(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list)
273285
{
@@ -325,6 +337,7 @@ static struct {
325337
{"document_image", "application-pdf"},
326338
{"word_image", "office-document"},
327339
{"spreadsheet_image", "office-spreadsheet"},
340+
{"calculator_image", "accessories-calculator"},
328341
};
329342

330343
/* Callback for icon theme change */
@@ -360,6 +373,7 @@ theme_changed_cb(GtkIconTheme* theme, MateDACapplet* capplet)
360373
refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->document_combo_box), capplet->document_viewers);
361374
refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->word_combo_box), capplet->word_editors);
362375
refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->spreadsheet_combo_box), capplet->spreadsheet_editors);
376+
refresh_combo_box_icons(theme, GTK_COMBO_BOX(capplet->calculator_combo_box), capplet->calculators);
363377
}
364378

365379
static void
@@ -437,6 +451,21 @@ fill_combo_box(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list, gch
437451
g_free (default_mobility);
438452
g_object_unref (mobility_settings);
439453
}
454+
else if (g_strcmp0(mime, "calculator") == 0)
455+
{
456+
GSettings *calculator_settings = g_settings_new (CALCULATOR_SCHEMA);
457+
gchar *default_calculator = g_settings_get_string (calculator_settings, CALCULATOR_KEY);
458+
for (entry = app_list; entry != NULL; entry = g_list_next(entry))
459+
{
460+
GAppInfo* item = (GAppInfo*) entry->data;
461+
if (g_strcmp0 (g_app_info_get_executable (item), default_calculator) == 0)
462+
{
463+
default_app = item;
464+
}
465+
}
466+
g_free (default_calculator);
467+
g_object_unref (calculator_settings);
468+
}
440469
else
441470
{
442471
default_app = g_app_info_get_default_for_type (mime, FALSE);
@@ -568,6 +597,7 @@ show_dialog(MateDACapplet* capplet, const gchar* start_page)
568597
capplet->document_combo_box = get_widget("document_combobox");
569598
capplet->word_combo_box = get_widget("word_combobox");
570599
capplet->spreadsheet_combo_box = get_widget("spreadsheet_combobox");
600+
capplet->calculator_combo_box = get_widget("calculator_combobox");
571601

572602
capplet->visual_startup_checkbutton = get_widget("visual_start_checkbutton");
573603
capplet->mobility_startup_checkbutton = get_widget("mobility_start_checkbutton");
@@ -614,6 +644,21 @@ show_dialog(MateDACapplet* capplet, const gchar* start_page)
614644
}
615645
capplet->terminals = g_list_reverse (capplet->terminals);
616646

647+
/* Calculator havent mime types, so check in .desktop files for
648+
Categories=Calculator */
649+
capplet->calculators = NULL;
650+
all_apps = g_app_info_get_all();
651+
for (entry = all_apps; entry != NULL; entry = g_list_next(entry))
652+
{
653+
GDesktopAppInfo* item = (GDesktopAppInfo*) entry->data;
654+
if (g_desktop_app_info_get_categories (item) != NULL &&
655+
g_strrstr (g_desktop_app_info_get_categories (item), "Calculator"))
656+
{
657+
capplet->calculators = g_list_prepend (capplet->calculators, item);
658+
}
659+
}
660+
capplet->calculators = g_list_reverse (capplet->calculators);
661+
617662
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->web_combo_box), capplet->web_browsers, "x-scheme-handler/http");
618663
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->mail_combo_box), capplet->mail_readers, "x-scheme-handler/mailto");
619664
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)
627672
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->document_combo_box), capplet->document_viewers, "application/pdf");
628673
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->word_combo_box), capplet->word_editors, "application/vnd.oasis.opendocument.text");
629674
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->spreadsheet_combo_box), capplet->spreadsheet_editors, "application/vnd.oasis.opendocument.spreadsheet");
675+
fill_combo_box(capplet->icon_theme, GTK_COMBO_BOX(capplet->calculator_combo_box), capplet->calculators, "calculator");
630676

631677
g_signal_connect(capplet->web_combo_box, "changed", G_CALLBACK(web_combo_changed_cb), capplet);
632678
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)
641687
g_signal_connect(capplet->document_combo_box, "changed", G_CALLBACK(document_combo_changed_cb), capplet);
642688
g_signal_connect(capplet->word_combo_box, "changed", G_CALLBACK(word_combo_changed_cb), capplet);
643689
g_signal_connect(capplet->spreadsheet_combo_box, "changed", G_CALLBACK(spreadsheet_combo_changed_cb), capplet);
690+
g_signal_connect(capplet->calculator_combo_box, "changed", G_CALLBACK(calculator_combo_changed_cb), capplet);
644691

645692
g_settings_bind (capplet->mobility_settings, MOBILITY_STARTUP_KEY, capplet->mobility_startup_checkbutton, "active", G_SETTINGS_BIND_DEFAULT);
646693
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)
707754
capplet->terminal_settings = g_settings_new (TERMINAL_SCHEMA);
708755
capplet->mobility_settings = g_settings_new (MOBILITY_SCHEMA);
709756
capplet->visual_settings = g_settings_new (VISUAL_SCHEMA);
757+
capplet->calculator_settings = g_settings_new (CALCULATOR_SCHEMA);
710758

711759
show_dialog(capplet, start_page);
712760
g_free(start_page);
@@ -716,6 +764,7 @@ main(int argc, char** argv)
716764
g_object_unref (capplet->terminal_settings);
717765
g_object_unref (capplet->mobility_settings);
718766
g_object_unref (capplet->visual_settings);
767+
g_object_unref (capplet->calculator_settings);
719768

720769
return 0;
721770
}

‎capplets/default-applications/mate-da-capplet.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#define MOBILITY_KEY "exec"
3636
#define MOBILITY_STARTUP_KEY "startup"
3737

38+
#define CALCULATOR_SCHEMA "org.mate.applications-calculator"
39+
#define CALCULATOR_KEY "exec"
40+
3841
typedef struct _MateDACapplet {
3942
GtkBuilder* builder;
4043

@@ -55,6 +58,7 @@ typedef struct _MateDACapplet {
5558
GtkWidget* document_combo_box;
5659
GtkWidget* word_combo_box;
5760
GtkWidget* spreadsheet_combo_box;
61+
GtkWidget* calculator_combo_box;
5862

5963
/* Visual Accessibility */
6064
GtkWidget* visual_startup_checkbutton;
@@ -76,11 +80,13 @@ typedef struct _MateDACapplet {
7680
GList* document_viewers;
7781
GList* word_editors;
7882
GList* spreadsheet_editors;
83+
GList* calculators;
7984

8085
/* Settings objects */
8186
GSettings* terminal_settings;
8287
GSettings* visual_settings;
8388
GSettings* mobility_settings;
89+
GSettings* calculator_settings;
8490
} MateDACapplet;
8591

8692
#endif

‎capplets/default-applications/mate-default-applications-properties.ui‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,83 @@
863863
<property name="position">2</property>
864864
</packing>
865865
</child>
866+
<child>
867+
<object class="GtkBox" id="calculator_vbox">
868+
<property name="visible">True</property>
869+
<property name="can_focus">False</property>
870+
<property name="orientation">vertical</property>
871+
<property name="spacing">6</property>
872+
<child>
873+
<object class="GtkLabel" id="calculator_label">
874+
<property name="visible">True</property>
875+
<property name="can_focus">False</property>
876+
<property name="halign">start</property>
877+
<property name="label" translatable="yes">Calculator</property>
878+
<attributes>
879+
<attribute name="weight" value="bold"/>
880+
</attributes>
881+
</object>
882+
<packing>
883+
<property name="expand">False</property>
884+
<property name="fill">False</property>
885+
<property name="position">0</property>
886+
</packing>
887+
</child>
888+
<child>
889+
<object class="GtkBox" id="calculator_hbox">
890+
<property name="visible">True</property>
891+
<property name="can_focus">False</property>
892+
<property name="spacing">12</property>
893+
<child>
894+
<object class="GtkImage" id="calculator_image">
895+
<property name="visible">True</property>
896+
<property name="can_focus">False</property>
897+
<property name="valign">start</property>
898+
</object>
899+
<packing>
900+
<property name="expand">False</property>
901+
<property name="fill">False</property>
902+
<property name="position">0</property>
903+
</packing>
904+
</child>
905+
<child>
906+
<object class="GtkBox" id="calculator_options_vbox">
907+
<property name="visible">True</property>
908+
<property name="can_focus">False</property>
909+
<property name="orientation">vertical</property>
910+
<property name="spacing">6</property>
911+
<child>
912+
<object class="GtkComboBox" id="calculator_combobox">
913+
<property name="visible">True</property>
914+
<property name="can_focus">False</property>
915+
</object>
916+
<packing>
917+
<property name="expand">False</property>
918+
<property name="fill">True</property>
919+
<property name="position">0</property>
920+
</packing>
921+
</child>
922+
</object>
923+
<packing>
924+
<property name="expand">True</property>
925+
<property name="fill">True</property>
926+
<property name="position">1</property>
927+
</packing>
928+
</child>
929+
</object>
930+
<packing>
931+
<property name="expand">False</property>
932+
<property name="fill">True</property>
933+
<property name="position">1</property>
934+
</packing>
935+
</child>
936+
</object>
937+
<packing>
938+
<property name="expand">False</property>
939+
<property name="fill">True</property>
940+
<property name="position">3</property>
941+
</packing>
942+
</child>
866943
</object>
867944
<packing>
868945
<property name="position">2</property>

0 commit comments

Comments
 (0)