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
=== modified file 'libunity-2d-private/src/giodefaultapplication.cpp'
--- libunity-2d-private/src/giodefaultapplication.cpp 2011-07-05 15:27:03 +0000
+++ libunity-2d-private/src/giodefaultapplication.cpp 2011-08-26 08:37:26 +0000
@@ -28,11 +28,58 @@
28#include <QTimer>28#include <QTimer>
2929
30// gio30// gio
31#include <gio/gio.h>
32#include <gio/gdesktopappinfo.h>31#include <gio/gdesktopappinfo.h>
3332
34static const QString MIMEAPPS_FILE = QDir::homePath() + QString("/.local/share/applications/mimeapps.list");33static const QString MIMEAPPS_FILE = QDir::homePath() + QString("/.local/share/applications/mimeapps.list");
3534
35static const gchar desktopSuffix[] = ".desktop";
36
37struct PreferredAppsMap {
38 const gchar* contentType;
39 const gchar* const* applications;
40};
41
42static const gchar* preferredBrowsers[] = {
43 "firefox",
44 "chromium-browser",
45 "epiphany-browser",
46 "midori",
47 NULL
48};
49
50static const gchar* preferredPhotoApps[] = {
51 "shotwell-viewer",
52 "f-spot",
53 "gthumb",
54 "gwenview",
55 "eog",
56 NULL
57};
58
59static const gchar* preferredMailApps[] = {
60 "evolution",
61 "thunderbird",
62 "claws-mail",
63 "kmail",
64 NULL
65};
66
67static const gchar* preferredMusicApps[] = {
68 "banshee",
69 "rhythmbox",
70 "totem",
71 "vlc",
72 NULL
73};
74
75static const PreferredAppsMap preferredAppsMap[] = {
76 { "x-scheme-handler/http", preferredBrowsers },
77 { "image/jpeg", preferredPhotoApps },
78 { "x-scheme-handler/mailto", preferredMailApps },
79 { "audio/x-vorbis+ogg", preferredMusicApps },
80 { NULL, NULL }
81};
82
36GioDefaultApplication::GioDefaultApplication(QObject* parent)83GioDefaultApplication::GioDefaultApplication(QObject* parent)
37 : QObject(parent),84 : QObject(parent),
38 m_contentType(""),85 m_contentType(""),
@@ -88,13 +135,88 @@
88 updateDesktopFile();135 updateDesktopFile();
89}136}
90137
138const gchar* const* GioDefaultApplication::preferredAppsForType(
139 const gchar* contentType)
140{
141 for (int i = 0; preferredAppsMap[i].contentType != NULL; i++) {
142 if (strcmp(contentType, preferredAppsMap[i].contentType) == 0) {
143 return preferredAppsMap[i].applications;
144 }
145 }
146 return NULL;
147}
148
149GAppInfo* GioDefaultApplication::findApplication(const gchar* application,
150 GList* list)
151{
152 while (list != NULL) {
153 GAppInfo* appInfo = (GAppInfo*) list->data;
154 gchar* appId = g_strdup(g_app_info_get_id(appInfo));
155
156 // the returned Id has the .desktop suffix: strip it
157 if (g_str_has_suffix(appId, desktopSuffix)) {
158 appId[strlen(appId) - sizeof(desktopSuffix) + 1] = '\0';
159 }
160
161 gboolean found = (g_strcmp0(appId, application) == 0);
162 g_free(appId);
163
164 if (found) {
165 return appInfo;
166 }
167
168 list = list->next;
169 }
170 return NULL;
171}
172
173GAppInfo* GioDefaultApplication::appInfo() const
174{
175 GAppInfo* appInfo = NULL;
176 QByteArray byteArray = m_contentType.toUtf8();
177 gchar* contentType = byteArray.data();
178
179 /* We could just call g_app_info_get_default_for_type(), but
180 * unfortunately there is no UI to set the default application yet.
181 * This causes obvious problems, such as
182 * https://bugs.launchpad.net/unity-2d/+bug/822605
183 *
184 * So, for those content types which we care about, get the list of all
185 * possible handlers and pick the one which scores best according to a
186 * hardcoded priority.
187 */
188 const gchar* const* preferredApps = preferredAppsForType(contentType);
189 if (preferredApps != NULL) {
190 GList* allApps = g_app_info_get_all_for_type(contentType);
191
192 for (int i = 0; preferredApps[i] != NULL; i++) {
193 /* if the preferred app is in the list of available apps, return
194 * that one */
195 appInfo = findApplication(preferredApps[i], allApps);
196 if (appInfo != NULL) {
197 /* This is the application we want to use; add a reference to
198 * the GAppInfo object, to avoid it getting destroyed when we
199 * free the whole list.
200 */
201 g_object_ref(appInfo);
202 break;
203 }
204 }
205 g_list_free_full(allApps, g_object_unref);
206 }
207
208 if (appInfo == NULL) {
209 appInfo = g_app_info_get_default_for_type(contentType, false);
210 }
211
212 return appInfo;
213}
214
91void GioDefaultApplication::updateDesktopFile()215void GioDefaultApplication::updateDesktopFile()
92{216{
93 GObjectScopedPointer<GAppInfo> app_info;217 GObjectScopedPointer<GAppInfo> app_info;
94 QByteArray byte_array = m_contentType.toUtf8();218 app_info.reset(appInfo());
95 gchar *content_type = byte_array.data();
96219
97 app_info.reset(g_app_info_get_default_for_type(content_type, false));
98 if (!app_info.isNull()) {220 if (!app_info.isNull()) {
99 m_desktopFile = QString::fromUtf8(g_desktop_app_info_get_filename((GDesktopAppInfo*)app_info.data()));221 m_desktopFile = QString::fromUtf8(g_desktop_app_info_get_filename((GDesktopAppInfo*)app_info.data()));
100 } else {222 } else {
101223
=== modified file 'libunity-2d-private/src/giodefaultapplication.h'
--- libunity-2d-private/src/giodefaultapplication.h 2011-07-26 16:06:48 +0000
+++ libunity-2d-private/src/giodefaultapplication.h 2011-08-26 08:37:26 +0000
@@ -20,9 +20,13 @@
20#ifndef GIODEFAULTAPPLICATION_H20#ifndef GIODEFAULTAPPLICATION_H
21#define GIODEFAULTAPPLICATION_H21#define GIODEFAULTAPPLICATION_H
2222
23// Qt
23#include <QObject>24#include <QObject>
24#include <QString>25#include <QString>
2526
27// gio
28#include <gio/gio.h>
29
26class QFileSystemWatcher;30class QFileSystemWatcher;
2731
28/* Wrapper around GIO's g_app_info_get_default_for_type.32/* Wrapper around GIO's g_app_info_get_default_for_type.
@@ -54,6 +58,11 @@
54 Q_SLOT void updateDesktopFile();58 Q_SLOT void updateDesktopFile();
55 Q_SLOT void onMimeappsFileChanged();59 Q_SLOT void onMimeappsFileChanged();
5660
61 static GAppInfo* findApplication(const gchar* application,
62 GList* list);
63 static const gchar* const* preferredAppsForType(const gchar* contentType);
64 GAppInfo* appInfo() const;
65
57 QString m_contentType;66 QString m_contentType;
58 QString m_desktopFile;67 QString m_desktopFile;
59 QFileSystemWatcher* m_mimeappsWatcher;68 QFileSystemWatcher* m_mimeappsWatcher;

Subscribers

People subscribed via source and target branches