Merge lp:~gerboland/qtmir/desktopFileReader into lp:qtmir/rtm-14.09

Proposed by Michał Sawicz
Status: Merged
Approved by: Gerry Boland
Approved revision: 268
Merged at revision: 270
Proposed branch: lp:~gerboland/qtmir/desktopFileReader
Merge into: lp:qtmir/rtm-14.09
Diff against target: 946 lines (+678/-158)
8 files modified
src/modules/Unity/Application/Application.pro (+3/-2)
src/modules/Unity/Application/desktopfilereader.cpp (+169/-115)
src/modules/Unity/Application/desktopfilereader.h (+22/-40)
src/modules/Unity/Application/gscopedpointer.h (+113/-0)
tests/modules/DesktopFileReader/DesktopFileReader.pro (+15/-0)
tests/modules/DesktopFileReader/calculator.desktop (+227/-0)
tests/modules/DesktopFileReader/desktopfilereader_test.cpp (+128/-0)
tests/modules/modules.pro (+1/-1)
To merge this branch: bzr merge lp:~gerboland/qtmir/desktopFileReader
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Review via email: mp+238114@code.launchpad.net

Commit message

Rewrite DesktopFileReader to use GDesktopAppInfo, enables reading localized keys

Description of the change

Rewrite DesktopFileReader to use GDesktopAppInfo, enables reading localized keys

 * Are there any related MPs required for this MP to build/function as expected? Please list.
N
 * Did you perform an exploratory manual test run of your code change and any related functionality?
Y
 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

To post a comment you must log in.
Revision history for this message
Gerry Boland (gerboland) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/modules/Unity/Application/Application.pro'
--- src/modules/Unity/Application/Application.pro 2014-09-11 16:18:40 +0000
+++ src/modules/Unity/Application/Application.pro 2014-10-13 09:06:32 +0000
@@ -12,7 +12,7 @@
12QMAKE_CXXFLAGS = -std=c++11 -Werror -Wall12QMAKE_CXXFLAGS = -std=c++11 -Werror -Wall
13QMAKE_LFLAGS = -std=c++11 -Wl,-no-undefined13QMAKE_LFLAGS = -std=c++11 -Wl,-no-undefined
1414
15PKGCONFIG += mirserver glib-2.0 process-cpp ubuntu-app-launch-215PKGCONFIG += mirserver glib-2.0 gio-unix-2.0 process-cpp ubuntu-app-launch-2
1616
17INCLUDEPATH += ../../../platforms/mirserver ../../../common17INCLUDEPATH += ../../../platforms/mirserver ../../../common
18LIBS += -L../../../platforms/mirserver -lqpa-mirserver18LIBS += -L../../../platforms/mirserver -lqpa-mirserver
@@ -65,7 +65,8 @@
65 session.h \65 session.h \
66 session_interface.h \66 session_interface.h \
67 sessionmodel.h \67 sessionmodel.h \
68 upstart/applicationcontroller.h68 upstart/applicationcontroller.h \
69 gscopedpointer.h
6970
70LTTNG_TP_FILES += tracepoints.tp71LTTNG_TP_FILES += tracepoints.tp
7172
7273
=== modified file 'src/modules/Unity/Application/desktopfilereader.cpp'
--- src/modules/Unity/Application/desktopfilereader.cpp 2014-08-07 18:15:45 +0000
+++ src/modules/Unity/Application/desktopfilereader.cpp 2014-10-13 09:06:32 +0000
@@ -16,142 +16,196 @@
1616
17// local17// local
18#include "desktopfilereader.h"18#include "desktopfilereader.h"
19#include "gscopedpointer.h"
19#include "logging.h"20#include "logging.h"
2021
21// Qt22// Qt
22#include <QFile>23#include <QFile>
24#include <QLocale>
25
26// GIO
27#include <gio/gdesktopappinfo.h>
2328
24namespace qtmir29namespace qtmir
25{30{
2631
27DesktopFileReader::Factory::Factory()
28{
29}
30
31DesktopFileReader::Factory::~Factory()
32{
33}
3432
35DesktopFileReader* DesktopFileReader::Factory::createInstance(const QString &appId, const QFileInfo& fi)33DesktopFileReader* DesktopFileReader::Factory::createInstance(const QString &appId, const QFileInfo& fi)
36{34{
37 return new DesktopFileReader(appId, fi);35 return new DesktopFileReader(appId, fi);
38}36}
3937
40// Retrieves the size of an array at compile time.38typedef GObjectScopedPointer<GAppInfo> GAppInfoPointer;
41#define ARRAY_SIZE(a) \39
42 ((sizeof(a) / sizeof(*(a))) / static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))40struct DesktopFileReaderPrivate
41{
42 DesktopFileReaderPrivate(DesktopFileReader *parent):
43 q_ptr( parent )
44 {}
45
46 QString getKey(const char *key) const
47 {
48 if (!loaded()) return QString();
49
50 return QString::fromUtf8(g_desktop_app_info_get_string((GDesktopAppInfo*)appInfo.data(), key));
51 }
52
53 bool loaded() const
54 {
55 return !appInfo.isNull();
56 }
57
58 DesktopFileReader * const q_ptr;
59 Q_DECLARE_PUBLIC(DesktopFileReader)
60
61 QString appId;
62 QString file;
63 GAppInfoPointer appInfo; // GAppInfo is actually implemented by GDesktopAppInfo
64};
65
4366
44DesktopFileReader::DesktopFileReader(const QString &appId, const QFileInfo &desktopFile)67DesktopFileReader::DesktopFileReader(const QString &appId, const QFileInfo &desktopFile)
45 : appId_(appId)68 : d_ptr(new DesktopFileReaderPrivate(this))
46 , entries_(DesktopFileReader::kNumberOfEntries, "")
47{69{
48 qCDebug(QTMIR_APPLICATIONS) << "DesktopFileReader::DesktopFileReader - this=" << this << "appId=" << appId;70 Q_D(DesktopFileReader);
4971
50 file_ = desktopFile.absoluteFilePath();72 d->appId = appId;
51 loaded_ = loadDesktopFile(file_);73 d->file = desktopFile.absoluteFilePath();
74 d->appInfo.reset((GAppInfo*) g_desktop_app_info_new_from_filename(d->file.toUtf8().constData()));
75
76 if (!d->loaded()) {
77 if (!desktopFile.exists()) {
78 qCWarning(QTMIR_APPLICATIONS) << "Desktop file for appId:" << appId << "at:" << d->file
79 << "does not exist";
80 } else {
81 qCWarning(QTMIR_APPLICATIONS) << "Desktop file for appId:" << appId << "at:" << d->file
82 << "is not valid - check its syntax, and that the binary specified"
83 << "by the Exec line is installed!";
84 }
85 }
52}86}
5387
54DesktopFileReader::~DesktopFileReader()88DesktopFileReader::~DesktopFileReader()
55{89{
56 qCDebug(QTMIR_APPLICATIONS) << "DesktopFileReader::~DesktopFileReader";90 delete d_ptr;
57 entries_.clear();91}
58}92
5993QString DesktopFileReader::file() const
60bool DesktopFileReader::loadDesktopFile(QString desktopFile)94{
61{95 Q_D(const DesktopFileReader);
62 qCDebug(QTMIR_APPLICATIONS) << "DesktopFileReader::loadDesktopFile - this=" << this << "desktopFile=" << desktopFile;96 return d->file;
6397}
64 if (this->file().isNull() || this->file().isEmpty()) {98
65 qCritical() << "No desktop file found for appId:" << appId_;99QString DesktopFileReader::appId() const
66 return false;100{
67 }101 Q_D(const DesktopFileReader);
68102 return d->appId;
69 Q_ASSERT(desktopFile != NULL);103}
70 const struct { const char* const name; int size; unsigned int flag; } kEntryNames[] = {104
71 { "Name=", sizeof("Name=") - 1, 1 << DesktopFileReader::kNameIndex },105QString DesktopFileReader::name() const
72 { "Comment=", sizeof("Comment=") - 1, 1 << DesktopFileReader::kCommentIndex },106{
73 { "Icon=", sizeof("Icon=") - 1, 1 << DesktopFileReader::kIconIndex },107 Q_D(const DesktopFileReader);
74 { "Exec=", sizeof("Exec=") - 1, 1 << DesktopFileReader::kExecIndex },108 if (!d->loaded()) return QString();
75 { "Path=", sizeof("Path=") - 1, 1 << DesktopFileReader::kPathIndex },109
76 { "X-Ubuntu-StageHint=", sizeof("X-Ubuntu-StageHint=") - 1, 1 << DesktopFileReader::kStageHintIndex },110 return QString::fromUtf8(g_app_info_get_name(d->appInfo.data()));
77 { "X-Ubuntu-Splash-Title=", sizeof("X-Ubuntu-Splash-Title=") - 1, 1 << DesktopFileReader::kSplashTitleIndex },111}
78 { "X-Ubuntu-Splash-Image=", sizeof("X-Ubuntu-Splash-Image=") - 1, 1 << DesktopFileReader::kSplashImageIndex },112
79 { "X-Ubuntu-Splash-Show-Header=", sizeof("X-Ubuntu-Splash-Show-Header=") - 1, 1 << DesktopFileReader::kSplashShowHeaderIndex },113QString DesktopFileReader::comment() const
80 { "X-Ubuntu-Splash-Color=", sizeof("X-Ubuntu-Splash-Color=") - 1, 1 << DesktopFileReader::kSplashColorIndex },114{
81 { "X-Ubuntu-Splash-Color-Header=", sizeof("X-Ubuntu-Splash-Color-Header=") - 1, 1 << DesktopFileReader::kSplashColorHeaderIndex },115 Q_D(const DesktopFileReader);
82 { "X-Ubuntu-Splash-Color-Footer=", sizeof("X-Ubuntu-Splash-Color-Footer=") - 1, 1 << DesktopFileReader::kSplashColorFooterIndex }116 if (!d->loaded()) return QString();
83 };117
84 const unsigned int kAllEntriesMask =118 return QString::fromUtf8(g_app_info_get_description(d->appInfo.data()));
85 (1 << DesktopFileReader::kNameIndex) | (1 << DesktopFileReader::kCommentIndex)119}
86 | (1 << DesktopFileReader::kIconIndex) | (1 << DesktopFileReader::kExecIndex)120
87 | (1 << DesktopFileReader::kPathIndex) | (1 << DesktopFileReader::kStageHintIndex)121QString DesktopFileReader::icon() const
88 | (1 << DesktopFileReader::kSplashTitleIndex) | (1 << DesktopFileReader::kSplashImageIndex)122{
89 | (1 << DesktopFileReader::kSplashShowHeaderIndex) | (1 << DesktopFileReader::kSplashColorIndex)123 Q_D(const DesktopFileReader);
90 | (1 << DesktopFileReader::kSplashColorHeaderIndex) | (1 << DesktopFileReader::kSplashColorFooterIndex);124 return d->getKey("Icon");
91 const unsigned int kMandatoryEntriesMask =125}
92 (1 << DesktopFileReader::kNameIndex) | (1 << DesktopFileReader::kIconIndex)126
93 | (1 << DesktopFileReader::kExecIndex);127QString DesktopFileReader::exec() const
94 const int kEntriesCount = ARRAY_SIZE(kEntryNames);128{
95 const int kBufferSize = 256;129 Q_D(const DesktopFileReader);
96 static char buffer[kBufferSize];130 if (!d->loaded()) return QString();
97 QFile file(desktopFile);131
98132 return QString::fromUtf8(g_app_info_get_commandline(d->appInfo.data()));
99 // Open file.133}
100 if (!file.open(QFile::ReadOnly | QIODevice::Text)) {134
101 qWarning() << "Can't open file:" << file.errorString();135QString DesktopFileReader::path() const
102 return false;136{
103 }137 Q_D(const DesktopFileReader);
104138 return d->getKey("Path");
105 // Validate "magic key" (standard group header).139}
106 if (file.readLine(buffer, kBufferSize) != -1) {140
107 if (strncmp(buffer, "[Desktop Entry]", sizeof("[Desktop Entry]") - 1)) {141QString DesktopFileReader::stageHint() const
108 qWarning() << "not a desktop file, unable to read it";142{
109 return false;143 Q_D(const DesktopFileReader);
110 }144 return d->getKey("X-Ubuntu-StageHint");
111 }145}
112146
113 int length;147QString DesktopFileReader::splashTitle() const
114 unsigned int entryFlags = 0;148{
115 while ((length = file.readLine(buffer, kBufferSize)) != -1) {149 Q_D(const DesktopFileReader);
116 // Skip empty lines.150 if (!d->loaded()) return QString();
117 if (length > 1) {151
118 // Stop when reaching unsupported next group header.152 /* Sadly GDesktopAppInfo only considers Name, GenericName, Comments and Keywords to be keys
119 if (buffer[0] == '[') {153 * which can have locale-specific entries. So we need to work to make X-Ubuntu-Splash-Title
120 qWarning() << "reached next group header, leaving loop";154 * locale-aware, by generating a locale-correct key name and seeing if that exists. If yes,
121 break;155 * get the value and return it. Else fallback to the non-localized value.
122 }156 */
123 // Lookup entries ignoring duplicates if any.157 GDesktopAppInfo *info = (GDesktopAppInfo*)d->appInfo.data();
124 for (int i = 0; i < kEntriesCount; i++) {158 QLocale defaultLocale;
125 if (!strncmp(buffer, kEntryNames[i].name, kEntryNames[i].size)) {159 QStringList locales = defaultLocale.uiLanguages();
126 if (~entryFlags & kEntryNames[i].flag) {160
127 buffer[length-1] = '\0';161 QString keyTemplate("X-Ubuntu-Splash-Title[%1]");
128 entries_[i] = QString::fromUtf8(&buffer[kEntryNames[i].size]);162 for (QString locale: locales) {
129 entryFlags |= kEntryNames[i].flag;163 // Desktop files use local specifiers with underscore separators but Qt uses hyphens
130 break;164 locale = locale.replace('-', '_');
131 }165 const char* key = keyTemplate.arg(locale).toUtf8().constData();
132 }166 if (g_desktop_app_info_has_key(info, key)) {
133 }167 return d->getKey(key);
134 // Stop when matching the right number of entries.168 }
135 if (entryFlags == kAllEntriesMask) {169 }
136 break;170
137 }171 // Fallback to the non-localized string, if available
138 }172 return d->getKey("X-Ubuntu-Splash-Title");
139 }173}
140174
141 // Check that the mandatory entries are set.175QString DesktopFileReader::splashImage() const
142 if ((entryFlags & kMandatoryEntriesMask) == kMandatoryEntriesMask) {176{
143 qDebug("loaded desktop file with name='%s', comment='%s', icon='%s', exec='%s', path='%s', stagehint='%s'",177 Q_D(const DesktopFileReader);
144 qPrintable(entries_[DesktopFileReader::kNameIndex]),178 return d->getKey("X-Ubuntu-Splash-Image");
145 qPrintable(entries_[DesktopFileReader::kCommentIndex]),179}
146 qPrintable(entries_[DesktopFileReader::kIconIndex]),180
147 qPrintable(entries_[DesktopFileReader::kExecIndex]),181QString DesktopFileReader::splashShowHeader() const
148 qPrintable(entries_[DesktopFileReader::kPathIndex]),182{
149 qPrintable(entries_[DesktopFileReader::kStageHintIndex]));183 Q_D(const DesktopFileReader);
150 return true;184 return d->getKey("X-Ubuntu-Splash-Show-Header");
151 } else {185}
152 qWarning() << "not a valid desktop file, missing mandatory entries in the standard group header";186
153 return false;187QString DesktopFileReader::splashColor() const
154 }188{
189 Q_D(const DesktopFileReader);
190 return d->getKey("X-Ubuntu-Splash-Color");
191}
192
193QString DesktopFileReader::splashColorHeader() const
194{
195 Q_D(const DesktopFileReader);
196 return d->getKey("X-Ubuntu-Splash-Color-Header");
197}
198
199QString DesktopFileReader::splashColorFooter() const
200{
201 Q_D(const DesktopFileReader);
202 return d->getKey("X-Ubuntu-Splash-Color-Footer");
203}
204
205bool DesktopFileReader::loaded() const
206{
207 Q_D(const DesktopFileReader);
208 return d->loaded();
155}209}
156210
157} // namespace qtmir211} // namespace qtmir
158212
=== modified file 'src/modules/Unity/Application/desktopfilereader.h'
--- src/modules/Unity/Application/desktopfilereader.h 2014-08-07 18:15:45 +0000
+++ src/modules/Unity/Application/desktopfilereader.h 2014-10-13 09:06:32 +0000
@@ -18,20 +18,19 @@
18#define DESKTOPFILEREADER_H18#define DESKTOPFILEREADER_H
1919
20#include <QString>20#include <QString>
21#include <QVector>
22#include <QFileInfo>21#include <QFileInfo>
2322
24namespace qtmir23namespace qtmir
25{24{
2625
26class DesktopFileReaderPrivate;
27class DesktopFileReader {27class DesktopFileReader {
28public:28public:
29 class Factory29 class Factory
30 {30 {
31 public:31 public:
32 Factory();32 Factory() = default;
33 Factory(const Factory&) = delete;33 Factory(const Factory&) = delete;
34 virtual ~Factory();
3534
36 Factory& operator=(const Factory&) = delete;35 Factory& operator=(const Factory&) = delete;
3736
@@ -40,48 +39,31 @@
4039
41 virtual ~DesktopFileReader();40 virtual ~DesktopFileReader();
4241
43 virtual QString file() const { return file_; }42 virtual QString file() const;
44 virtual QString appId() const { return appId_; }43 virtual QString appId() const;
45 virtual QString name() const { return entries_[kNameIndex]; }44 virtual QString name() const;
46 virtual QString comment() const { return entries_[kCommentIndex]; }45 virtual QString comment() const;
47 virtual QString icon() const { return entries_[kIconIndex]; }46 virtual QString icon() const;
48 virtual QString exec() const { return entries_[kExecIndex]; }47 virtual QString exec() const;
49 virtual QString path() const { return entries_[kPathIndex]; }48 virtual QString path() const;
50 virtual QString stageHint() const { return entries_[kStageHintIndex]; }49 virtual QString stageHint() const;
51 virtual QString splashTitle() const { return entries_[kSplashTitleIndex]; }50 virtual QString splashTitle() const;
52 virtual QString splashImage() const { return entries_[kSplashImageIndex]; }51 virtual QString splashImage() const;
53 virtual QString splashShowHeader() const { return entries_[kSplashShowHeaderIndex]; }52 virtual QString splashShowHeader() const;
54 virtual QString splashColor() const { return entries_[kSplashColorIndex]; }53 virtual QString splashColor() const;
55 virtual QString splashColorHeader() const { return entries_[kSplashColorHeaderIndex]; }54 virtual QString splashColorHeader() const;
56 virtual QString splashColorFooter() const { return entries_[kSplashColorFooterIndex]; }55 virtual QString splashColorFooter() const;
57 virtual bool loaded() const { return loaded_; }56 virtual bool loaded() const;
5857
59protected:58protected:
59 DesktopFileReader(const QString &appId, const QFileInfo &desktopFile);
60
61 DesktopFileReaderPrivate * const d_ptr;
62
60 friend class DesktopFileReaderFactory;63 friend class DesktopFileReaderFactory;
6164
62 DesktopFileReader(const QString &appId, const QFileInfo &desktopFile);
63
64private:65private:
65 static const int kNameIndex = 0,66 Q_DECLARE_PRIVATE(DesktopFileReader)
66 kCommentIndex = 1,
67 kIconIndex = 2,
68 kExecIndex = 3,
69 kPathIndex = 4,
70 kStageHintIndex = 5,
71 kSplashTitleIndex = 6,
72 kSplashImageIndex = 7,
73 kSplashShowHeaderIndex = 8,
74 kSplashColorIndex = 9,
75 kSplashColorHeaderIndex = 10,
76 kSplashColorFooterIndex = 11,
77 kNumberOfEntries = 12;
78
79 virtual bool loadDesktopFile(QString desktopFile);
80
81 QString appId_;
82 QString file_;
83 QVector<QString> entries_;
84 bool loaded_;
85};67};
8668
87} // namespace qtmir69} // namespace qtmir
8870
=== added file 'src/modules/Unity/Application/gscopedpointer.h'
--- src/modules/Unity/Application/gscopedpointer.h 1970-01-01 00:00:00 +0000
+++ src/modules/Unity/Application/gscopedpointer.h 2014-10-13 09:06:32 +0000
@@ -0,0 +1,113 @@
1/*
2 * Copyright (C) 2011-2014 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
18 */
19
20#ifndef GSCOPEDPOINTER_H
21#define GSCOPEDPOINTER_H
22
23// Local
24
25// Qt
26#include <QScopedPointer>
27
28// GLib
29#include <glib-object.h>
30
31/**
32 * Helper class for GScopedPointer
33 */
34template <class T, void (*cleanup_fcn)(T*)>
35class GScopedPointerDeleter
36{
37public:
38 static void cleanup(T* ptr)
39 {
40 if (ptr) {
41 cleanup_fcn(ptr);
42 }
43 }
44};
45
46/**
47 * A GScopedPointer works like a QScopedPointer, except the cleanup static
48 * method is replaced with a cleanup function, making it useful to handle C
49 * structs whose cleanup function prototype is "void cleanup(T*)"
50 *
51 * Best way to use it is to define a typedef for your C struct, like this:
52 *
53 * typedef GScopedPointer<Foo, foo_free> GFooPointer;
54 */
55template <class T, void (*cleanup)(T*)>
56class GScopedPointer : public QScopedPointer<T, GScopedPointerDeleter<T, cleanup> >
57{
58public:
59 GScopedPointer(T* ptr = 0)
60 : QScopedPointer<T, GScopedPointerDeleter<T, cleanup> >(ptr)
61 {}
62};
63
64
65/**
66 * Helper class for GObjectScopedPointer
67 */
68template <class T, void (*cleanup_fcn)(gpointer)>
69class GObjectScopedPointerDeleter
70{
71public:
72 static void cleanup(T* ptr)
73 {
74 if (ptr) {
75 cleanup_fcn(ptr);
76 }
77 }
78};
79
80/**
81 * A GObjectScopedPointer is similar to a GScopedPointer. The only difference
82 * is its cleanup function signature is "void cleanup(gpointer)" and defaults to
83 * g_object_unref(), making it useful for GObject-based classes.
84 *
85 * You can use it directly like this:
86 *
87 * GObjectScopedPointer<GFoo> foo;
88 *
89 * Or define a typedef for your class:
90 *
91 * typedef GObjectScopedPointer<GFoo> GFooPointer;
92 *
93 * Note: GObjectScopedPointer does *not* call gobject_ref() when assigned a
94 * pointer.
95 */
96template <class T, void (*cleanup)(gpointer) = g_object_unref>
97class GObjectScopedPointer : public QScopedPointer<T, GObjectScopedPointerDeleter<T, cleanup> >
98{
99public:
100 GObjectScopedPointer(T* ptr = 0)
101 : QScopedPointer<T, GObjectScopedPointerDeleter<T, cleanup> >(ptr)
102 {}
103};
104
105// A Generic GObject pointer
106typedef GObjectScopedPointer<GObject> GObjectPointer;
107
108// Take advantage of the cleanup signature of GObjectScopedPointer to define
109// a GCharPointer
110typedef GObjectScopedPointer<gchar, g_free> GCharPointer;
111
112#endif /* GSCOPEDPOINTER_H */
113
0114
=== added directory 'tests/modules/DesktopFileReader'
=== added file 'tests/modules/DesktopFileReader/DesktopFileReader.pro'
--- tests/modules/DesktopFileReader/DesktopFileReader.pro 1970-01-01 00:00:00 +0000
+++ tests/modules/DesktopFileReader/DesktopFileReader.pro 2014-10-13 09:06:32 +0000
@@ -0,0 +1,15 @@
1include(../../test-includes.pri)
2include(../common/common.pri)
3
4TARGET = desktopfilereader_test
5
6SOURCES += \
7 desktopfilereader_test.cpp
8
9OTHER_FILES += \
10 calculator.desktop
11
12# Copy to build directory
13for(FILE, OTHER_FILES){
14 QMAKE_POST_LINK += $$quote(cp $${PWD}/$${FILE} $${OUT_PWD}$$escape_expand(\\n\\t))
15}
016
=== added file 'tests/modules/DesktopFileReader/calculator.desktop'
--- tests/modules/DesktopFileReader/calculator.desktop 1970-01-01 00:00:00 +0000
+++ tests/modules/DesktopFileReader/calculator.desktop 2014-10-13 09:06:32 +0000
@@ -0,0 +1,227 @@
1[Desktop Entry]
2Name=Calculator
3Name[am]=መደመሪያ
4Name[ar]=الآلة الحاسبة
5Name[ast]=Calculadora
6Name[az]=Kalkulyator
7Name[be]=Калькулятар
8Name[bg]=Калкулатор
9Name[br]=Jederez
10Name[bs]=Kalkulator
11Name[ca]=Calculadora
12Name[cs]=Kalkulačka
13Name[cy]=Cyfrifiannell
14Name[da]=Lommeregner
15Name[de]=Taschenrechner
16Name[el]=Αριθμομηχανή
17Name[en_AU]=Calculator
18Name[en_CA]=Calculator
19Name[en_GB]=Calculator
20Name[es]=Calculadora
21Name[eu]=Kalkulagailua
22Name[fa]=ماشین‌حساب
23Name[fi]=Laskin
24Name[fr]=Calculatrice
25Name[gd]=An t-àireamhair
26Name[gl]=Calculadora
27Name[gu]=કેલ્ક્યુલેટર
28Name[he]=מחשבון
29Name[hi]=कैलकुलेटर
30Name[hu]=Számológép
31Name[id]=Kalkulator
32Name[is]=Reiknivél
33Name[it]=Calcolatrice
34Name[ja]=電卓
35Name[km]=ម៉ាស៊ីន​គិត​លេខ
36Name[ko]=계산기
37Name[lv]=Kalkulators
38Name[mr]=गणनयंत्र
39Name[ms]=Kalkulator
40Name[my]=ဂဏန်းတွက်စက်
41Name[nb]=Kalkulator
42Name[ne]=क्याल्कुलेटर
43Name[nl]=Rekenmachine
44Name[pa]=ਕੈਲਕੂਲੇਟਰ
45Name[pl]=Kalkulator
46Name[pt]=Calculadora
47Name[pt_BR]=Calculadora
48Name[ro]=Calculator
49Name[ru]=Калькулятор
50Name[sa]=सङ्कलकम्
51Name[shn]=ၸၢၵ်ႈၼပ့်သွၼ်
52Name[sl]=Računalo
53Name[sr]=Калкулатор
54Name[sv]=Kalkylator
55Name[ta]=கணிப்பான்
56Name[te]=గణన పరికరం
57Name[tr]=Hesap Makinesi
58Name[ug]=ھېسابلىغۇچ
59Name[uk]=Калькулятор
60Name[zh_CN]=计算器
61Name[zh_HK]=計數機
62Name[zh_TW]=計算機
63Comment=A simple calculator for Ubuntu.
64Comment[am]=ለ ኡቡንቱ ቀላል መደመሪያ
65Comment[ar]=آلة حاسبة بسيطة لأوبونتو.
66Comment[ast]=Una calculadora cenciella pa Ubuntu.
67Comment[az]=Ubuntu üçün sadә kalkulyator.
68Comment[br]=Ur jederez eeun evit Ubuntu.
69Comment[ca]=Una calculadora simple per a l'Ubuntu.
70Comment[cy]=Cyfrifiannell hawdd ar gyfer Ubuntu.
71Comment[da]=En simpel lommeregner til Ubuntu.
72Comment[de]=Ein einfach Tachenrechner für Ubuntu.
73Comment[el]=Μια απλή αριθμομηχανή για το Ubuntu
74Comment[en_AU]=A simple calculator for Ubuntu.
75Comment[en_GB]=A simple calculator for Ubuntu.
76Comment[es]=Una calculadora sencilla para Ubuntu.
77Comment[eu]=Ubunturako kalkulagailu sinplea.
78Comment[fa]=یک ماشین حساب ساده برای اوبونتو.
79Comment[fi]=Laskin Ubuntulle.
80Comment[fr]=Une calculatrice simple pour Ubuntu.
81Comment[gd]=Àireamhair simplidh airson Ubuntu.
82Comment[gl]=Calculadora sinxela para Ubuntu.
83Comment[he]=מחשבון פשוט לאובונטו.
84Comment[hu]=Egyszerű számológép Ubuntuhoz.
85Comment[is]=Einföld reiknivél
86Comment[it]=Una semplice calcolatrice per Ubuntu.
87Comment[ja]=Ubuntu用のシンプルな電卓です。
88Comment[km]=ម៉ាស៊ីន​គិត​លេខ​ធម្មតា​សម្រាប់ Ubuntu ។
89Comment[ko]=우분투를 위한 간단한 계산기
90Comment[lv]=Vienkāršs kalkulators priekš Ubuntu
91Comment[nb]=En enkel kalkulator for Ubuntu.
92Comment[ne]=Ubuntu को लागि एक सरल कैलकुलेटर।
93Comment[nl]=Een eenvoudige rekenmachine voor Ubuntu.
94Comment[pa]=ਉਬੰਤੂ ਲਈ ਇੱਕ ਸਧਾਰਨ ਕੈਲਕੂਲੇਟਰ
95Comment[pl]=Prosty kalkulator dla Ubuntu
96Comment[pt]=Uma calculadora simples para o Ubuntu.
97Comment[pt_BR]=Uma simples calculadora para Ubuntu
98Comment[ro]=Un calculator simplu pentru Ubuntu.
99Comment[ru]=Простой калькулятор для Ubuntu
100Comment[sa]=Ubuntu इत्यस्मा एकं सरलं सङ्कलकम्।
101Comment[sl]=Preprost kalkulator za Ubuntu.
102Comment[sr]=Једноставан калкулатор за Убунту
103Comment[sv]=En enkel kalkylator för Ubuntu.
104Comment[tr]=Ubuntu için sade bir hesap makinesi.
105Comment[ug]=ئاددىي ھېسابلىغۇچى
106Comment[uk]=Простий калькулятор для Ubuntu.
107Comment[zh_CN]=Ubuntu 简易计算器
108Comment[zh_TW]=Ubuntu 簡易計算機。
109Keywords=math;addition;subtraction;multiplication;division;
110Keywords[am]=ሂሳብ;መደመሪያ;መቀነሻ;ማባዣ;ማካፈያ;
111Keywords[ar]=رياضة;ياضيات;حساب;حسابات;جمع;طرح;ضرب;قسمة;
112Keywords[ast]=matemática;suma;resta;multiplicación;división;
113Keywords[az]=riyaziyyat;әlavә etmә;çıxma;vurma;bölmә;toplama;
114Keywords[br]=matematikoù;sammadenn;lamadenn;lieskementadenn;rannadenn;
115Keywords[ca]=suma;resta;calculadora;multiplica;divideix
116Keywords[da]=matematik;plus;minus;gange;dividere;beregning;lommeregner;
117Keywords[de]=Mathe;Mathematik;Multiplikation;Subtraktion;Addition;Division;
118Keywords[en_AU]=math;addition;subtraction;multiplication;division;
119Keywords[en_GB]=maths;addition;subtraction;multiplication;division;
120Keywords[es]=matemática;suma;resta;multiplicación;división;
121Keywords[eu]=matematikak;gehitu;kendu;biderkatu;zatitu;
122Keywords[fa]=حساب;جمع;تفریق;ضرب;تقسیم
123Keywords[fi]=math;addition;subtraction;multiplication;division;matematiikka;lisäys;vähennys;kertaus;jakaminen;
124Keywords[fr]=math;addition;soustraction;multiplication;division;
125Keywords[gd]=math;addition;subtraction;multiplication;division;matamataig;roinneadh;toirt air falbh;cur ris;iomadadh
126Keywords[gl]=matemáticas;suma;resta;multiplicación;división;
127Keywords[he]=מתמטיקה;חשבון;חיבור;חיסור;כפל;חילוק;
128Keywords[hu]=számolás;összeadás;kivonás;szorzás;osztás;
129Keywords[is]=reikna;samlagning;frádráttur;margföldun;deiling
130Keywords[it]=matematica;addizioni;sottrazioni;moltiplicazioni;divisioni;
131Keywords[ja]=math;addition;subtraction;multiplication;division;計算;電卓;足し算;引き算;かけ算;わり算;
132Keywords[km]=math;addition;subtraction;multiplication;division;
133Keywords[ko]=수학;덧셈;뺄셈;곱셈;나눗셈;
134Keywords[nb]=matte;addisjon;subtraksjon;multiplikasjon;divisjon;
135Keywords[ne]=गणित; जोड्; घटाउ; गुणन; विभाजन;
136Keywords[nl]=math;addition;subtraction;multiplication;division;optellen;aftrekken;vermenigvuldigen;delen;
137Keywords[pa]=ਹਿਸਾਬ;ਜੋੜ;ਘਟਾਉ;ਗੁਣਾ;ਭਾਗ;
138Keywords[pl]=liczenie;dodawanie;odejmowanie;mnożenie;dzielenie;
139Keywords[pt]=matemática;soma;subtracção;multiplicação;divisão;
140Keywords[pt_BR]=matemática;adição;subtração;multiplicação;divisão
141Keywords[ro]=matematică;adunare;scădere;înmulțire;împărțire
142Keywords[ru]=математика;сложение;умножение;деление;
143Keywords[sa]=गणितम्;योजनम्;वियोजनम्;गुणनम्;विभाजनम्;
144Keywords[sl]=matematika;seštevanje;odštevanje;množenje;deljenje;
145Keywords[sr]=математика;сабирање;одузимање;множење;дељење;рачунање;дигитрон;
146Keywords[sv]=matematik;addition;substraktion;multiplikation;division
147Keywords[tr]=matematik;ekleme;çıkarma;çarpma;bölme;toplama
148Keywords[ug]=ماتېماتىكا;قوشۇش;ئېلىش;كۆپەيتىش;بۆلۈش;
149Keywords[uk]=math;addition;subtraction;multiplication;division;математика;додавання;віднімання;множення;ділення;калькулятор;
150Keywords[zh_CN]=数学;加;减;乘;除;
151Keywords[zh_TW]=math;addition;subtraction;multiplication;division;數學;加;減;乘;除;
152Type=Application
153Terminal=false
154Exec=yes -p com.ubuntu.calculator_calculator_1.3.329 -- qmlscene -qt5 ubuntu-calculator-app.qml
155Icon=/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator/calculator-app@30.png
156X-Ubuntu-Touch=true
157X-Ubuntu-StageHint=SideStage
158X-Ubuntu-Default-Department-ID=accessories
159Path=/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator
160X-Ubuntu-Old-Icon=calculator-app@30.png
161X-Ubuntu-Application-ID=com.ubuntu.calculator_calculator_1.3.329
162X-Ubuntu-Splash-Show-Header=True
163X-Ubuntu-Splash-Color=#aabbcc
164X-Ubuntu-Splash-Color-Header=purple
165X-Ubuntu-Splash-Color-Footer=#deadbeefda
166X-Ubuntu-Splash-Image=/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator/calculator-app@30.png
167X-Ubuntu-Splash-Title=Calculator 2.0
168X-Ubuntu-Splash-Title[am]=መደመሪያ 2.0
169X-Ubuntu-Splash-Title[ar]=الآلة 2.0الحاسبة
170X-Ubuntu-Splash-Title[ast]=Calculadora 2.0
171X-Ubuntu-Splash-Title[az]=Kalkulyator 2.0
172X-Ubuntu-Splash-Title[be]=Калькулятар 2.0
173X-Ubuntu-Splash-Title[bg]=Калкулатор 2.0
174X-Ubuntu-Splash-Title[br]=Jederez 2.0
175X-Ubuntu-Splash-Title[bs]=Kalkulator 2.0
176X-Ubuntu-Splash-Title[ca]=Calculadora 2.0
177X-Ubuntu-Splash-Title[cs]=Kalkulačka 2.0
178X-Ubuntu-Splash-Title[cy]=Cyfrifiannell 2.0
179X-Ubuntu-Splash-Title[da]=Lommeregner 2.0
180X-Ubuntu-Splash-Title[de]=Taschenrechner 2.0
181X-Ubuntu-Splash-Title[el]=Αριθμομηχανή 2.0
182X-Ubuntu-Splash-Title[en_AU]=Calculator 2.0
183X-Ubuntu-Splash-Title[en_CA]=Calculator 2.0
184X-Ubuntu-Splash-Title[en_GB]=Calculator 2.0
185X-Ubuntu-Splash-Title[es]=Calculadora 2.0
186X-Ubuntu-Splash-Title[eu]=Kalkulagailua 2.0
187X-Ubuntu-Splash-Title[fa]= 2.0ماشین‌حساب
188X-Ubuntu-Splash-Title[fi]=Laskin 2.0
189X-Ubuntu-Splash-Title[fr]=Calculatrice 2.0
190X-Ubuntu-Splash-Title[gd]=An t-àireamhair 2.0
191X-Ubuntu-Splash-Title[gl]=Calculadora 2.0
192X-Ubuntu-Splash-Title[gu]=કેલ્ક્યુલેટર 2.0
193X-Ubuntu-Splash-Title[he]= 2.0מחשבון
194X-Ubuntu-Splash-Title[hi]=कैलकुलेटर 2.0
195X-Ubuntu-Splash-Title[hu]=Számológép 2.0
196X-Ubuntu-Splash-Title[id]=Kalkulator 2.0
197X-Ubuntu-Splash-Title[is]=Reiknivél 2.0
198X-Ubuntu-Splash-Title[it]=Calcolatrice 2.0
199X-Ubuntu-Splash-Title[ja]=電卓 2.0
200X-Ubuntu-Splash-Title[km]=ម៉ាស៊ីន​គិត​លេខ 2.0
201X-Ubuntu-Splash-Title[ko]=계산기 2.0
202X-Ubuntu-Splash-Title[lv]=Kalkulators 2.0
203X-Ubuntu-Splash-Title[mr]=गणनयंत्र 2.0
204X-Ubuntu-Splash-Title[ms]=Kalkulator 2.0
205X-Ubuntu-Splash-Title[my]=ဂဏန်းတွက်စက် 2.0
206X-Ubuntu-Splash-Title[nb]=Kalkulator 2.0
207X-Ubuntu-Splash-Title[ne]=क्याल्कुलेटर 2.0
208X-Ubuntu-Splash-Title[nl]=Rekenmachine 2.0
209X-Ubuntu-Splash-Title[pa]=ਕੈਲਕੂਲੇਟਰ 2.0
210X-Ubuntu-Splash-Title[pl]=Kalkulator 2.0
211X-Ubuntu-Splash-Title[pt]=Calculadora 2.0
212X-Ubuntu-Splash-Title[pt_BR]=Calculadora 2.0
213X-Ubuntu-Splash-Title[ro]=Calculator 2.0
214X-Ubuntu-Splash-Title[ru]=Калькулятор 2.0
215X-Ubuntu-Splash-Title[sa]=सङ्कलकम् 2.0
216X-Ubuntu-Splash-Title[shn]=ၸၢၵ်ႈၼပ့်သွၼ် 2.0
217X-Ubuntu-Splash-Title[sl]=Računalo 2.0
218X-Ubuntu-Splash-Title[sr]=Калкулатор 2.0
219X-Ubuntu-Splash-Title[sv]=Kalkylator 2.0
220X-Ubuntu-Splash-Title[ta]=கணிப்பான் 2.0
221X-Ubuntu-Splash-Title[te]=గణన పరికరం 2.0
222X-Ubuntu-Splash-Title[tr]=Hesap Makinesi 2.0
223X-Ubuntu-Splash-Title[ug]= 2.0ھېسابلىغۇچ
224X-Ubuntu-Splash-Title[uk]=Калькулятор 2.0
225X-Ubuntu-Splash-Title[zh_CN]=计算器 2.0
226X-Ubuntu-Splash-Title[zh_HK]=計數機 2.0
227X-Ubuntu-Splash-Title[zh_TW]=計算機 2.0
0228
=== added file 'tests/modules/DesktopFileReader/desktopfilereader_test.cpp'
--- tests/modules/DesktopFileReader/desktopfilereader_test.cpp 1970-01-01 00:00:00 +0000
+++ tests/modules/DesktopFileReader/desktopfilereader_test.cpp 2014-10-13 09:06:32 +0000
@@ -0,0 +1,128 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include <Unity/Application/desktopfilereader.h>
19
20#include <gtest/gtest.h>
21
22#include <QDir>
23#include <QFileInfo>
24#include <QLocale>
25#include <QtGlobal>
26#include <QString>
27
28using namespace qtmir;
29
30namespace {
31 static void setLocale(const char *locale)
32 {
33 qputenv("LANGUAGE", locale);
34 qputenv("LC_ALL", locale); // set these for GIO
35 QLocale::setDefault(QString(locale)); // set for Qt
36 }
37}
38
39TEST(DesktopFileReader, testReadsDesktopFile)
40{
41 using namespace ::testing;
42 setLocale("C");
43
44 QFileInfo fileInfo(QDir::currentPath() + "/calculator.desktop");
45 DesktopFileReader::Factory readerFactory;
46 DesktopFileReader *reader = readerFactory.createInstance("calculator", fileInfo);
47
48 EXPECT_EQ(reader->loaded(), true);
49 EXPECT_EQ(reader->appId(), "calculator");
50 EXPECT_EQ(reader->name(), "Calculator");
51 EXPECT_EQ(reader->exec(), "yes -p com.ubuntu.calculator_calculator_1.3.329 -- qmlscene -qt5 ubuntu-calculator-app.qml");
52 EXPECT_EQ(reader->icon(), "/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator/calculator-app@30.png");
53 EXPECT_EQ(reader->path(), "/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator");
54 EXPECT_EQ(reader->comment(), "A simple calculator for Ubuntu.");
55 EXPECT_EQ(reader->stageHint(), "SideStage");
56 EXPECT_EQ(reader->splashColor(), "#aabbcc");
57 EXPECT_EQ(reader->splashColorFooter(), "#deadbeefda");
58 EXPECT_EQ(reader->splashColorHeader(), "purple");
59 EXPECT_EQ(reader->splashImage(), "/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator/calculator-app@30.png");
60 EXPECT_EQ(reader->splashShowHeader(), "True");
61 EXPECT_EQ(reader->splashTitle(), "Calculator 2.0");
62}
63
64TEST(DesktopFileReader, testReadsLocalizedDesktopFile)
65{
66 using namespace ::testing;
67 setLocale("de");
68
69 QFileInfo fileInfo(QDir::currentPath() + "/calculator.desktop");
70 DesktopFileReader::Factory readerFactory;
71 DesktopFileReader *reader = readerFactory.createInstance("calculator", fileInfo);
72
73 EXPECT_EQ(reader->loaded(), true);
74 EXPECT_EQ(reader->appId(), "calculator");
75 EXPECT_EQ(reader->name(), "Taschenrechner");
76 EXPECT_EQ(reader->exec(), "yes -p com.ubuntu.calculator_calculator_1.3.329 -- qmlscene -qt5 ubuntu-calculator-app.qml");
77 EXPECT_EQ(reader->icon(), "/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator/calculator-app@30.png");
78 EXPECT_EQ(reader->path(), "/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator");
79 EXPECT_EQ(reader->comment(), "Ein einfach Tachenrechner für Ubuntu.");
80 EXPECT_EQ(reader->stageHint(), "SideStage");
81 EXPECT_EQ(reader->splashColor(), "#aabbcc");
82 EXPECT_EQ(reader->splashColorFooter(), "#deadbeefda");
83 EXPECT_EQ(reader->splashColorHeader(), "purple");
84 EXPECT_EQ(reader->splashImage(), "/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.calculator/calculator-app@30.png");
85 EXPECT_EQ(reader->splashShowHeader(), "True");
86 EXPECT_EQ(reader->splashTitle(), "Taschenrechner 2.0");
87}
88
89TEST(DesktopFileReader, testMissingDesktopFile)
90{
91 using namespace ::testing;
92 setLocale("C");
93
94 QFileInfo fileInfo(QDir::currentPath() + "/missing.desktop");
95 DesktopFileReader::Factory readerFactory;
96 DesktopFileReader *reader = readerFactory.createInstance("calculator", fileInfo);
97
98 EXPECT_EQ(reader->loaded(), false);
99 EXPECT_EQ(reader->appId(), "calculator");
100 EXPECT_EQ(reader->name(), "");
101 EXPECT_EQ(reader->exec(), "");
102 EXPECT_EQ(reader->icon(), "");
103 EXPECT_EQ(reader->path(), "");
104 EXPECT_EQ(reader->comment(), "");
105 EXPECT_EQ(reader->stageHint(), "");
106 EXPECT_EQ(reader->splashColor(), "");
107 EXPECT_EQ(reader->splashColorFooter(), "");
108 EXPECT_EQ(reader->splashColorHeader(), "");
109 EXPECT_EQ(reader->splashImage(), "");
110 EXPECT_EQ(reader->splashShowHeader(), "");
111 EXPECT_EQ(reader->splashTitle(), "");
112}
113
114TEST(DesktopFileReader, testUTF8Characters)
115{
116 using namespace ::testing;
117 setLocale("zh_CN");
118
119 QFileInfo fileInfo(QDir::currentPath() + "/calculator.desktop");
120 DesktopFileReader::Factory readerFactory;
121 DesktopFileReader *reader = readerFactory.createInstance("calculator", fileInfo);
122
123 EXPECT_EQ(reader->loaded(), true);
124 EXPECT_EQ(reader->appId(), "calculator");
125 EXPECT_EQ(reader->name(), "计算器");
126 EXPECT_EQ(reader->comment(), "Ubuntu 简易计算器");
127 EXPECT_EQ(reader->splashTitle(), "计算器 2.0");
128}
0129
=== modified file 'tests/modules/modules.pro'
--- tests/modules/modules.pro 2014-09-11 16:18:40 +0000
+++ tests/modules/modules.pro 2014-10-13 09:06:32 +0000
@@ -1,2 +1,2 @@
1TEMPLATE = subdirs1TEMPLATE = subdirs
2SUBDIRS = ApplicationManager General MirSurfaceItem SessionManager TaskController2SUBDIRS = ApplicationManager General MirSurfaceItem SessionManager TaskController DesktopFileReader

Subscribers

People subscribed via source and target branches