Merge lp:~mardy/unity-2d/string-conversion into lp:unity-2d

Proposed by Alberto Mardegan
Status: Merged
Approved by: Florian Boucault
Approved revision: 673
Merged at revision: 677
Proposed branch: lp:~mardy/unity-2d/string-conversion
Merge into: lp:unity-2d
Diff against target: 428 lines (+115/-30)
10 files modified
libunity-2d-private/src/CMakeLists.txt (+1/-0)
libunity-2d-private/src/filter.cpp (+7/-4)
libunity-2d-private/src/filteroption.cpp (+8/-3)
libunity-2d-private/src/global.cpp (+31/-0)
libunity-2d-private/src/global.h (+32/-0)
libunity-2d-private/src/indicatorentrywidget.cpp (+4/-2)
libunity-2d-private/src/indicatorsmanager.cpp (+4/-1)
libunity-2d-private/src/lens.cpp (+21/-18)
panel/applets/appname/menubarwidget.cpp (+4/-1)
panel/applets/indicator/indicatorapplet.cpp (+3/-1)
To merge this branch: bzr merge lp:~mardy/unity-2d/string-conversion
Reviewer Review Type Date Requested Status
Florian Boucault (community) Approve
Review via email: mp+73375@code.launchpad.net

Description of the change

[dash] Convert UnityCore UTF-8 strings to QStrings

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

To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote :

Fixes the issue and code looks great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/CMakeLists.txt'
2--- libunity-2d-private/src/CMakeLists.txt 2011-08-23 09:47:12 +0000
3+++ libunity-2d-private/src/CMakeLists.txt 2011-08-30 13:45:31 +0000
4@@ -7,6 +7,7 @@
5 debug.cpp
6 gconnector.cpp
7 gimageutils.cpp
8+ global.cpp
9 gnomesessionclient.cpp
10 keyboardmodifiersmonitor.cpp
11 hotkeymonitor.cpp
12
13=== modified file 'libunity-2d-private/src/filter.cpp'
14--- libunity-2d-private/src/filter.cpp 2011-08-19 17:12:24 +0000
15+++ libunity-2d-private/src/filter.cpp 2011-08-30 13:45:31 +0000
16@@ -21,6 +21,7 @@
17 #include "filter.h"
18
19 // local
20+#include "global.h"
21 #include "ratingsfilter.h"
22 #include "radiooptionfilter.h"
23 #include "checkoptionfilter.h"
24@@ -36,6 +37,8 @@
25 // Qt
26 #include <QDebug>
27
28+using namespace Unity2d;
29+
30 Filter::Filter(QObject *parent) :
31 QObject(parent)
32 {
33@@ -44,22 +47,22 @@
34
35 QString Filter::id() const
36 {
37- return QString::fromStdString(m_unityFilter->id());
38+ return QStringFromUtf8StdString(m_unityFilter->id());
39 }
40
41 QString Filter::name() const
42 {
43- return QString::fromStdString(m_unityFilter->name());
44+ return QStringFromUtf8StdString(m_unityFilter->name());
45 }
46
47 QString Filter::iconHint() const
48 {
49- return QString::fromStdString(m_unityFilter->icon_hint());
50+ return QStringFromUtf8StdString(m_unityFilter->icon_hint());
51 }
52
53 QString Filter::rendererName() const
54 {
55- return QString::fromStdString(m_unityFilter->renderer_name());
56+ return QStringFromUtf8StdString(m_unityFilter->renderer_name());
57 }
58
59 bool Filter::visible() const
60
61=== modified file 'libunity-2d-private/src/filteroption.cpp'
62--- libunity-2d-private/src/filteroption.cpp 2011-08-19 17:12:24 +0000
63+++ libunity-2d-private/src/filteroption.cpp 2011-08-30 13:45:31 +0000
64@@ -20,9 +20,14 @@
65 // Self
66 #include "filteroption.h"
67
68+// libunity-2d-private
69+#include "global.h"
70+
71 // libunity-core
72 #include <UnityCore/Filter.h>
73
74+using namespace Unity2d;
75+
76 FilterOption::FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent) :
77 QObject(parent), m_unityFilterOption(NULL)
78 {
79@@ -31,17 +36,17 @@
80
81 QString FilterOption::id() const
82 {
83- return QString::fromStdString(m_unityFilterOption->id());
84+ return QStringFromUtf8StdString(m_unityFilterOption->id());
85 }
86
87 QString FilterOption::name() const
88 {
89- return QString::fromStdString(m_unityFilterOption->name());
90+ return QStringFromUtf8StdString(m_unityFilterOption->name());
91 }
92
93 QString FilterOption::iconHint() const
94 {
95- return QString::fromStdString(m_unityFilterOption->icon_hint());
96+ return QStringFromUtf8StdString(m_unityFilterOption->icon_hint());
97 }
98
99 bool FilterOption::active() const
100
101=== added file 'libunity-2d-private/src/global.cpp'
102--- libunity-2d-private/src/global.cpp 1970-01-01 00:00:00 +0000
103+++ libunity-2d-private/src/global.cpp 2011-08-30 13:45:31 +0000
104@@ -0,0 +1,31 @@
105+/*
106+ * Copyright (C) 2011 Canonical, Ltd.
107+ *
108+ * Authors:
109+ * Alberto Mardegan <alberto.mardegan@canonical.com>
110+ *
111+ * This program is free software; you can redistribute it and/or modify
112+ * it under the terms of the GNU General Public License as published by
113+ * the Free Software Foundation; version 3.
114+ *
115+ * This program is distributed in the hope that it will be useful,
116+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
117+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118+ * GNU General Public License for more details.
119+ *
120+ * You should have received a copy of the GNU General Public License
121+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
122+ */
123+
124+// local
125+#include "global.h"
126+
127+namespace Unity2d {
128+
129+QString QStringFromUtf8StdString(std::string s)
130+{
131+ return QString::fromUtf8(s.c_str());
132+}
133+
134+};
135+
136
137=== added file 'libunity-2d-private/src/global.h'
138--- libunity-2d-private/src/global.h 1970-01-01 00:00:00 +0000
139+++ libunity-2d-private/src/global.h 2011-08-30 13:45:31 +0000
140@@ -0,0 +1,32 @@
141+/*
142+ * Copyright (C) 2011 Canonical, Ltd.
143+ *
144+ * Authors:
145+ * Alberto Mardegan <alberto.mardegan@canonical.com>
146+ *
147+ * This program is free software; you can redistribute it and/or modify
148+ * it under the terms of the GNU General Public License as published by
149+ * the Free Software Foundation; version 3.
150+ *
151+ * This program is distributed in the hope that it will be useful,
152+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
153+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
154+ * GNU General Public License for more details.
155+ *
156+ * You should have received a copy of the GNU General Public License
157+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
158+ */
159+
160+#ifndef GLOBAL_H
161+#define GLOBAL_H
162+
163+// Qt
164+#include <QString>
165+
166+namespace Unity2d {
167+
168+QString QStringFromUtf8StdString(std::string s);
169+
170+}
171+
172+#endif // GLOBAL_H
173
174=== modified file 'libunity-2d-private/src/indicatorentrywidget.cpp'
175--- libunity-2d-private/src/indicatorentrywidget.cpp 2011-08-22 09:17:03 +0000
176+++ libunity-2d-private/src/indicatorentrywidget.cpp 2011-08-30 13:45:31 +0000
177@@ -24,6 +24,7 @@
178 // Local
179 #include <cairoutils.h>
180 #include <debug_p.h>
181+#include <global.h>
182 #include <gscopedpointer.h>
183 #include <gimageutils.h>
184 #include <panelstyle.h>
185@@ -44,6 +45,7 @@
186 static const int ICON_SIZE = 22;
187
188 using namespace unity::indicator;
189+using namespace Unity2d;
190
191 IndicatorEntryWidget::IndicatorEntryWidget(const Entry::Ptr& entry)
192 : m_entry(entry)
193@@ -292,11 +294,11 @@
194 UQ_WARNING << "Failed to decode image";
195 }
196 } else if (type == GTK_IMAGE_ICON_NAME) {
197- QString name = QString::fromStdString(m_entry->image_data());
198+ QString name = QStringFromUtf8StdString(m_entry->image_data());
199 QIcon icon = QIcon::fromTheme(name);
200 pix = icon.pixmap(ICON_SIZE, ICON_SIZE);
201 } else if (type == GTK_IMAGE_GICON) {
202- QString name = QString::fromStdString(m_entry->image_data());
203+ QString name = QStringFromUtf8StdString(m_entry->image_data());
204 QImage image = GImageUtils::imageForIconString(name, ICON_SIZE);
205 if (image.isNull()) {
206 UQ_WARNING << "Failed to load icon from" << name;
207
208=== modified file 'libunity-2d-private/src/indicatorsmanager.cpp'
209--- libunity-2d-private/src/indicatorsmanager.cpp 2011-08-23 13:30:12 +0000
210+++ libunity-2d-private/src/indicatorsmanager.cpp 2011-08-30 13:45:31 +0000
211@@ -23,6 +23,7 @@
212
213 // Local
214 #include <debug_p.h>
215+#include <global.h>
216 #include <indicatorentrywidget.h>
217
218 // Qt
219@@ -34,6 +35,7 @@
220 #include <X11/Xlib.h>
221
222 using namespace unity::indicator;
223+using namespace Unity2d;
224
225 IndicatorsManager::IndicatorsManager(QObject* parent)
226 : QObject(parent)
227@@ -167,7 +169,8 @@
228 }
229 }
230 if (!widget) {
231- UQ_WARNING << "Could not find a widget for IndicatorEntry with id" << QString::fromStdString(entryId);
232+ UQ_WARNING << "Could not find a widget for IndicatorEntry with id" <<
233+ QStringFromUtf8StdString(entryId);
234 return;
235 }
236 widget->showMenu(Qt::NoButton);
237
238=== modified file 'libunity-2d-private/src/lens.cpp'
239--- libunity-2d-private/src/lens.cpp 2011-08-19 17:12:24 +0000
240+++ libunity-2d-private/src/lens.cpp 2011-08-30 13:45:31 +0000
241@@ -24,11 +24,14 @@
242 #include <debug_p.h>
243 #include "launcherapplication.h"
244 #include "filters.h"
245+#include "global.h"
246
247 // Qt
248 #include <QUrl>
249 #include <QDesktopServices>
250
251+using namespace Unity2d;
252+
253 Lens::Lens(QObject *parent) :
254 QObject(parent)
255 {
256@@ -39,37 +42,37 @@
257
258 QString Lens::id() const
259 {
260- return QString::fromStdString(m_unityLens->id());
261+ return QStringFromUtf8StdString(m_unityLens->id());
262 }
263
264 QString Lens::dbusName() const
265 {
266- return QString::fromStdString(m_unityLens->dbus_name());
267+ return QStringFromUtf8StdString(m_unityLens->dbus_name());
268 }
269
270 QString Lens::dbusPath() const
271 {
272- return QString::fromStdString(m_unityLens->dbus_path());
273+ return QStringFromUtf8StdString(m_unityLens->dbus_path());
274 }
275
276 QString Lens::name() const
277 {
278- return QString::fromStdString(m_unityLens->name());
279+ return QStringFromUtf8StdString(m_unityLens->name());
280 }
281
282 QString Lens::iconHint() const
283 {
284- return QString::fromStdString(m_unityLens->icon_hint());
285+ return QStringFromUtf8StdString(m_unityLens->icon_hint());
286 }
287
288 QString Lens::description() const
289 {
290- return QString::fromStdString(m_unityLens->description());
291+ return QStringFromUtf8StdString(m_unityLens->description());
292 }
293
294 QString Lens::searchHint() const
295 {
296- return QString::fromStdString(m_unityLens->search_hint());
297+ return QStringFromUtf8StdString(m_unityLens->search_hint());
298 }
299
300 bool Lens::visible() const
301@@ -84,7 +87,7 @@
302
303 QString Lens::shortcut() const
304 {
305- return QString::fromStdString(m_unityLens->shortcut());
306+ return QStringFromUtf8StdString(m_unityLens->shortcut());
307 }
308
309 bool Lens::connected() const
310@@ -158,7 +161,7 @@
311 void Lens::onActivated(std::string const& uri, unity::dash::HandledType type, unity::dash::Lens::Hints const&)
312 {
313 if (type == unity::dash::NOT_HANDLED) {
314- fallbackActivate(QString::fromStdString(uri));
315+ fallbackActivate(QStringFromUtf8StdString(uri));
316 }
317 }
318
319@@ -216,9 +219,9 @@
320
321 m_filters = new Filters(m_unityLens->filters, this);
322
323- m_results->setName(QString::fromStdString(m_unityLens->results()->swarm_name));
324- m_globalResults->setName(QString::fromStdString(m_unityLens->global_results()->swarm_name));
325- m_categories->setName(QString::fromStdString(m_unityLens->categories()->swarm_name));
326+ m_results->setName(QStringFromUtf8StdString(m_unityLens->results()->swarm_name));
327+ m_globalResults->setName(QStringFromUtf8StdString(m_unityLens->global_results()->swarm_name));
328+ m_categories->setName(QStringFromUtf8StdString(m_unityLens->categories()->swarm_name));
329
330 /* Property change signals */
331 m_unityLens->id.changed.connect(sigc::mem_fun(this, &Lens::idChanged));
332@@ -250,32 +253,32 @@
333
334 void Lens::onResultsSwarmNameChanged(std::string swarm_name)
335 {
336- m_results->setName(QString::fromStdString(m_unityLens->results()->swarm_name));
337+ m_results->setName(QStringFromUtf8StdString(m_unityLens->results()->swarm_name));
338 }
339
340 void Lens::onResultsChanged(unity::dash::Results::Ptr results)
341 {
342- m_results->setName(QString::fromStdString(m_unityLens->results()->swarm_name));
343+ m_results->setName(QStringFromUtf8StdString(m_unityLens->results()->swarm_name));
344 }
345
346 void Lens::onGlobalResultsSwarmNameChanged(std::string swarm_name)
347 {
348- m_globalResults->setName(QString::fromStdString(m_unityLens->global_results()->swarm_name));
349+ m_globalResults->setName(QStringFromUtf8StdString(m_unityLens->global_results()->swarm_name));
350 }
351
352 void Lens::onGlobalResultsChanged(unity::dash::Results::Ptr global_results)
353 {
354- m_globalResults->setName(QString::fromStdString(m_unityLens->global_results()->swarm_name));
355+ m_globalResults->setName(QStringFromUtf8StdString(m_unityLens->global_results()->swarm_name));
356 }
357
358 void Lens::onCategoriesSwarmNameChanged(std::string swarm_name)
359 {
360- m_categories->setName(QString::fromStdString(m_unityLens->categories()->swarm_name));
361+ m_categories->setName(QStringFromUtf8StdString(m_unityLens->categories()->swarm_name));
362 }
363
364 void Lens::onCategoriesChanged(unity::dash::Categories::Ptr categories)
365 {
366- m_categories->setName(QString::fromStdString(m_unityLens->categories()->swarm_name));
367+ m_categories->setName(QStringFromUtf8StdString(m_unityLens->categories()->swarm_name));
368 }
369
370 #include "lens.moc"
371
372=== modified file 'panel/applets/appname/menubarwidget.cpp'
373--- panel/applets/appname/menubarwidget.cpp 2011-07-27 11:59:05 +0000
374+++ panel/applets/appname/menubarwidget.cpp 2011-08-30 13:45:31 +0000
375@@ -24,12 +24,15 @@
376
377 // Local
378 #include <debug_p.h>
379+#include <global.h>
380 #include <indicatorentrywidget.h>
381 #include <indicatorsmanager.h>
382
383 // Qt
384 #include <QHBoxLayout>
385
386+using namespace Unity2d;
387+
388 static const int MENU_ITEM_PADDING = 6;
389
390 MenuBarWidget::MenuBarWidget(IndicatorsManager* indicatorsManager, QWidget* parent)
391@@ -63,7 +66,7 @@
392
393 void MenuBarWidget::onObjectAdded(const unity::indicator::Indicator::Ptr& indicator)
394 {
395- QString name = QString::fromStdString(indicator->name());
396+ QString name = QStringFromUtf8StdString(indicator->name());
397 if (name == "libappmenu.so") {
398 indicator->on_entry_added.connect(sigc::mem_fun(this, &MenuBarWidget::onEntryAdded));
399 }
400
401=== modified file 'panel/applets/indicator/indicatorapplet.cpp'
402--- panel/applets/indicator/indicatorapplet.cpp 2011-08-22 09:39:50 +0000
403+++ panel/applets/indicator/indicatorapplet.cpp 2011-08-30 13:45:31 +0000
404@@ -23,6 +23,7 @@
405
406 // Local
407 #include <debug_p.h>
408+#include <global.h>
409 #include <indicatorsmanager.h>
410 #include <indicatorwidget.h>
411 #include <unity2dpanel.h>
412@@ -31,6 +32,7 @@
413 #include <QHBoxLayout>
414
415 using namespace unity::indicator;
416+using namespace Unity2d;
417
418 IndicatorApplet::IndicatorApplet(Unity2dPanel* panel)
419 : Unity2d::PanelApplet(panel)
420@@ -49,7 +51,7 @@
421
422 void IndicatorApplet::onObjectAdded(Indicator::Ptr const& indicator)
423 {
424- QString name = QString::fromStdString(indicator->name());
425+ QString name = QStringFromUtf8StdString(indicator->name());
426 if (name == "libappmenu.so") {
427 // appmenu indicator is handled by AppNameApplet
428 return;

Subscribers

People subscribed via source and target branches