Merge lp:~mardy/unity-2d/default-apps into lp:unity-2d

Proposed by Alberto Mardegan
Status: Superseded
Proposed branch: lp:~mardy/unity-2d/default-apps
Merge into: lp:unity-2d
Diff against target: 185 lines (+135/-4)
2 files modified
libunity-2d-private/src/giodefaultapplication.cpp (+126/-4)
libunity-2d-private/src/giodefaultapplication.h (+9/-0)
To merge this branch: bzr merge lp:~mardy/unity-2d/default-apps
Reviewer Review Type Date Requested Status
Alberto Mardegan (community) Disapprove
Florian Boucault Pending
Review via email: mp+73003@code.launchpad.net

This proposal has been superseded by a proposal from 2011-09-01.

Description of the change

[places] Hardcode preferred applications priorities

To decide which applications should be launched by the shortcuts in the Dash,
make a list of all applications supporting the desired content type and pick
the first one which is found in a hardcoded list.
This code can all be removed once we have a way to let the user specify his own
default application preferences.

To post a comment you must log in.
lp:~mardy/unity-2d/default-apps updated
673. By Alberto Mardegan

[panel] Workaround QConf incomplete destruction

Ensure that the QConf object stays alive as long as the PanelManager is. This
is to workaround an issue with QConf's destructor, which doesn't disconnect
from the DConf's "notify" signal that can later be emitted while running the
event loop, and would therefore attempt to operate on an already destroyed
object.

674. By Gerry Boland

[dash] Rating Stars now cleared when "All" button pressed. Fixes bug:834640

675. By Alberto Mardegan

[panel] Padding for indicators should be 5 pixels

676. By Gerry Boland

[launcher] Context menu arrow has ugly blue edge. Harder to observe is that all the background graphics have blu-ish edges. This commit cleans up the graphics. Fixes bug:828386

677. By Alberto Mardegan

[dash] Convert UnityCore UTF-8 strings to QStrings

Add a tiny global function to perform the conversion, and use it throughout the project.

678. By Florian Boucault

[dash] Category header label changed from using literal to numeral: "See one more result" changed into "See 1 more result"

679. By Florian Boucault

[dash][launcher] When an application has no icon or the icon fails to load, display a placeholder icon.

680. By Florian Boucault

[dash] Use plural form in category header label 'See x more results'

681. By Florian Boucault

[dash] Fixed drag and drop of results from the dash (in particular applications to the launcher).

682. By Florian Boucault

[dash] Support loading lens' icon from theme in lens navigation bar.

683. By Florian Boucault

[dash] Fallback to using the default renderer if renderer requested by the lens is not found.

684. By Florian Boucault

[dash] Added horizontal renderer used by lenses such as Gwibber.

685. By Florian Boucault

[dash] Home buttons 'Media' and 'Internet' apps now also activate the right filter and open up the 'Filter results' pane.

Revision history for this message
Alberto Mardegan (mardy) wrote :

As I commented on the bug, I don't think this is how we should deal with the problem.

review: Disapprove
lp:~mardy/unity-2d/default-apps updated
686. By Alberto Mardegan

[places] Use shotwell as default photo viewer

Extend GioDefaultApplication with a defaultDesktopFile property which can be
used to override the default application registered for the content-type.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/giodefaultapplication.cpp'
2--- libunity-2d-private/src/giodefaultapplication.cpp 2011-07-05 15:27:03 +0000
3+++ libunity-2d-private/src/giodefaultapplication.cpp 2011-08-26 08:37:26 +0000
4@@ -28,11 +28,58 @@
5 #include <QTimer>
6
7 // gio
8-#include <gio/gio.h>
9 #include <gio/gdesktopappinfo.h>
10
11 static const QString MIMEAPPS_FILE = QDir::homePath() + QString("/.local/share/applications/mimeapps.list");
12
13+static const gchar desktopSuffix[] = ".desktop";
14+
15+struct PreferredAppsMap {
16+ const gchar* contentType;
17+ const gchar* const* applications;
18+};
19+
20+static const gchar* preferredBrowsers[] = {
21+ "firefox",
22+ "chromium-browser",
23+ "epiphany-browser",
24+ "midori",
25+ NULL
26+};
27+
28+static const gchar* preferredPhotoApps[] = {
29+ "shotwell-viewer",
30+ "f-spot",
31+ "gthumb",
32+ "gwenview",
33+ "eog",
34+ NULL
35+};
36+
37+static const gchar* preferredMailApps[] = {
38+ "evolution",
39+ "thunderbird",
40+ "claws-mail",
41+ "kmail",
42+ NULL
43+};
44+
45+static const gchar* preferredMusicApps[] = {
46+ "banshee",
47+ "rhythmbox",
48+ "totem",
49+ "vlc",
50+ NULL
51+};
52+
53+static const PreferredAppsMap preferredAppsMap[] = {
54+ { "x-scheme-handler/http", preferredBrowsers },
55+ { "image/jpeg", preferredPhotoApps },
56+ { "x-scheme-handler/mailto", preferredMailApps },
57+ { "audio/x-vorbis+ogg", preferredMusicApps },
58+ { NULL, NULL }
59+};
60+
61 GioDefaultApplication::GioDefaultApplication(QObject* parent)
62 : QObject(parent),
63 m_contentType(""),
64@@ -88,13 +135,88 @@
65 updateDesktopFile();
66 }
67
68+const gchar* const* GioDefaultApplication::preferredAppsForType(
69+ const gchar* contentType)
70+{
71+ for (int i = 0; preferredAppsMap[i].contentType != NULL; i++) {
72+ if (strcmp(contentType, preferredAppsMap[i].contentType) == 0) {
73+ return preferredAppsMap[i].applications;
74+ }
75+ }
76+ return NULL;
77+}
78+
79+GAppInfo* GioDefaultApplication::findApplication(const gchar* application,
80+ GList* list)
81+{
82+ while (list != NULL) {
83+ GAppInfo* appInfo = (GAppInfo*) list->data;
84+ gchar* appId = g_strdup(g_app_info_get_id(appInfo));
85+
86+ // the returned Id has the .desktop suffix: strip it
87+ if (g_str_has_suffix(appId, desktopSuffix)) {
88+ appId[strlen(appId) - sizeof(desktopSuffix) + 1] = '\0';
89+ }
90+
91+ gboolean found = (g_strcmp0(appId, application) == 0);
92+ g_free(appId);
93+
94+ if (found) {
95+ return appInfo;
96+ }
97+
98+ list = list->next;
99+ }
100+ return NULL;
101+}
102+
103+GAppInfo* GioDefaultApplication::appInfo() const
104+{
105+ GAppInfo* appInfo = NULL;
106+ QByteArray byteArray = m_contentType.toUtf8();
107+ gchar* contentType = byteArray.data();
108+
109+ /* We could just call g_app_info_get_default_for_type(), but
110+ * unfortunately there is no UI to set the default application yet.
111+ * This causes obvious problems, such as
112+ * https://bugs.launchpad.net/unity-2d/+bug/822605
113+ *
114+ * So, for those content types which we care about, get the list of all
115+ * possible handlers and pick the one which scores best according to a
116+ * hardcoded priority.
117+ */
118+ const gchar* const* preferredApps = preferredAppsForType(contentType);
119+ if (preferredApps != NULL) {
120+ GList* allApps = g_app_info_get_all_for_type(contentType);
121+
122+ for (int i = 0; preferredApps[i] != NULL; i++) {
123+ /* if the preferred app is in the list of available apps, return
124+ * that one */
125+ appInfo = findApplication(preferredApps[i], allApps);
126+ if (appInfo != NULL) {
127+ /* This is the application we want to use; add a reference to
128+ * the GAppInfo object, to avoid it getting destroyed when we
129+ * free the whole list.
130+ */
131+ g_object_ref(appInfo);
132+ break;
133+ }
134+ }
135+ g_list_free_full(allApps, g_object_unref);
136+ }
137+
138+ if (appInfo == NULL) {
139+ appInfo = g_app_info_get_default_for_type(contentType, false);
140+ }
141+
142+ return appInfo;
143+}
144+
145 void GioDefaultApplication::updateDesktopFile()
146 {
147 GObjectScopedPointer<GAppInfo> app_info;
148- QByteArray byte_array = m_contentType.toUtf8();
149- gchar *content_type = byte_array.data();
150+ app_info.reset(appInfo());
151
152- app_info.reset(g_app_info_get_default_for_type(content_type, false));
153 if (!app_info.isNull()) {
154 m_desktopFile = QString::fromUtf8(g_desktop_app_info_get_filename((GDesktopAppInfo*)app_info.data()));
155 } else {
156
157=== modified file 'libunity-2d-private/src/giodefaultapplication.h'
158--- libunity-2d-private/src/giodefaultapplication.h 2011-07-26 16:06:48 +0000
159+++ libunity-2d-private/src/giodefaultapplication.h 2011-08-26 08:37:26 +0000
160@@ -20,9 +20,13 @@
161 #ifndef GIODEFAULTAPPLICATION_H
162 #define GIODEFAULTAPPLICATION_H
163
164+// Qt
165 #include <QObject>
166 #include <QString>
167
168+// gio
169+#include <gio/gio.h>
170+
171 class QFileSystemWatcher;
172
173 /* Wrapper around GIO's g_app_info_get_default_for_type.
174@@ -54,6 +58,11 @@
175 Q_SLOT void updateDesktopFile();
176 Q_SLOT void onMimeappsFileChanged();
177
178+ static GAppInfo* findApplication(const gchar* application,
179+ GList* list);
180+ static const gchar* const* preferredAppsForType(const gchar* contentType);
181+ GAppInfo* appInfo() const;
182+
183 QString m_contentType;
184 QString m_desktopFile;
185 QFileSystemWatcher* m_mimeappsWatcher;

Subscribers

People subscribed via source and target branches