Merge lp:~fboucault/unity-2d/dash_encoding_global_fix into lp:unity-2d

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

Description of the change

[dash] Fix encoding and decoding of strings coming from and passed to the backend so that searches containing non-ascii characters work.

Reverted revision 677. It was introducing QStringFromUtf8StdString that has
the same result as QString::fromStdString with the codec for C-strings set to UTF-8.

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

To ease review, I suggest to look individually at the 2 commits of the submitted branch.

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

Oh! I don't understand why my patch introduced problems with decoding, but anyway your solution is way more clean and less invasive. :-)

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

Subscribers

People subscribed via source and target branches