Merge lp:~chrisccoulson/indicator-messages/dont-hardcode-evolution into lp:indicator-messages/0.5

Proposed by Chris Coulson
Status: Merged
Approved by: Ted Gould
Approved revision: 220
Merged at revision: 221
Proposed branch: lp:~chrisccoulson/indicator-messages/dont-hardcode-evolution
Merge into: lp:indicator-messages/0.5
Diff against target: 76 lines (+36/-8)
1 file modified
src/default-applications.c (+36/-8)
To merge this branch: bzr merge lp:~chrisccoulson/indicator-messages/dont-hardcode-evolution
Reviewer Review Type Date Requested Status
Ted Gould Pending
Review via email: mp+68741@code.launchpad.net

Description of the change

Don't hardcode the "Mail" entry to point to Evolution

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

I fixed a couple of little things including putting found as a condition for the for loop and using the G_N_ELEMENTS() macro. Then merged.

Also, do you think we could do this for the other items in the menu at the distro level. Define types for them so people could set default IM and broadcast message apps?

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Thanks, I thought that something like G_N_ELEMENTS() existed but I couldn't remember what it was called, so I implemented it myself ;)

I guess it would be nice to make the Broadcast and IM entries dynamic too, but I left them as they are for now because there isn't really anywhere on the system to define a default IM or broadcast client. It's easy for mail because the default client is defined in the mimetype system. IM and broadcast clients aren't associated with a filetype or URI scheme, so we'd need to invent a new setting for those if we wanted to make it dynamic.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/default-applications.c'
2--- src/default-applications.c 2010-03-12 14:49:32 +0000
3+++ src/default-applications.c 2011-07-21 20:05:35 +0000
4@@ -21,20 +21,22 @@
5
6 #include <glib.h>
7 #include <glib/gi18n.h>
8+#include <gio/gio.h>
9+#include <gio/gdesktopappinfo.h>
10 #include "default-applications.h"
11
12 struct default_db_t {
13 const gchar * desktop_file;
14+ const gchar * uri_scheme;
15 const gchar * name;
16 const gchar * setupname;
17 const gchar * icon;
18 };
19
20 struct default_db_t default_db[] = {
21- {"evolution.desktop", N_("Mail"), N_("Set Up Mail..."), "applications-email-panel"},
22- {"empathy.desktop", N_("Chat"), N_("Set Up Chat..."), "applications-chat-panel"},
23- {"gwibber.desktop", N_("Broadcast"), N_("Set Up Broadcast Account..."), "applications-microblogging-panel"},
24- {NULL, NULL}
25+ {NULL, "mailto", N_("Mail"), N_("Set Up Mail..."), "applications-email-panel"},
26+ {"empathy.desktop", NULL, N_("Chat"), N_("Set Up Chat..."), "applications-chat-panel"},
27+ {"gwibber.desktop", NULL, N_("Broadcast"), N_("Set Up Broadcast Account..."), "applications-microblogging-panel"},
28 };
29
30 static struct default_db_t *
31@@ -44,16 +46,42 @@
32 gchar * basename = g_path_get_basename(desktop_path);
33 g_return_val_if_fail(basename != NULL, NULL);
34
35+ gboolean found = FALSE;
36 gint i;
37- for (i = 0; default_db[i].desktop_file != NULL; i++) {
38- if (g_strcmp0(default_db[i].desktop_file, basename) == 0) {
39- break;
40+ gint length = sizeof(default_db)/sizeof(default_db[0]);
41+ for (i = 0; i < length; i++) {
42+ if (default_db[i].desktop_file) {
43+ if (g_strcmp0(default_db[i].desktop_file, basename) == 0) {
44+ found = TRUE;
45+ break;
46+ }
47+ } else if (default_db[i].uri_scheme) {
48+ GAppInfo *info = g_app_info_get_default_for_uri_scheme(default_db[i].uri_scheme);
49+ if (!info) {
50+ continue;
51+ }
52+
53+ const gchar * filename = g_desktop_app_info_get_filename(G_DESKTOP_APP_INFO(info));
54+ if (!filename) {
55+ g_object_unref(info);
56+ continue;
57+ }
58+
59+ gchar * default_basename = g_path_get_basename(filename);
60+ g_object_unref(info);
61+ if (g_strcmp0(default_basename, basename) == 0) {
62+ found = TRUE;
63+ g_free(default_basename);
64+ break;
65+ }
66+
67+ g_free(default_basename);
68 }
69 }
70
71 g_free(basename);
72
73- if (default_db[i].desktop_file != NULL) {
74+ if (found) {
75 return &default_db[i];
76 }
77

Subscribers

People subscribed via source and target branches