Merge lp:~uriboni/unity-2d/unity-2d-libunity2dprivate-util into lp:unity-2d/3.0

Proposed by Ugo Riboni
Status: Rejected
Rejected by: Ugo Riboni
Proposed branch: lp:~uriboni/unity-2d/unity-2d-libunity2dprivate-util
Merge into: lp:unity-2d/3.0
Diff against target: 151 lines (+54/-15)
8 files modified
libunity-2d-private/Unity2d/plugin.cpp (+2/-0)
libunity-2d-private/src/CMakeLists.txt (+1/-0)
libunity-2d-private/src/screeninfo.cpp (+0/-8)
libunity-2d-private/src/screeninfo.h (+0/-5)
libunity-2d-private/src/util.cpp (+27/-0)
libunity-2d-private/src/util.h (+22/-0)
places/dash.qml (+1/-1)
spread/Window.qml (+1/-1)
To merge this branch: bzr merge lp:~uriboni/unity-2d/unity-2d-libunity2dprivate-util
Reviewer Review Type Date Requested Status
Alberto Mardegan (community) Needs Fixing
Florian Boucault Pending
Review via email: mp+72700@code.launchpad.net

Commit message

[libunity2dprivate] Add a small singleton Util class where to add all otherwise unrelated utility functions. Replace ScreenInfo::currentTime with Util::currentTime.

Description of the change

Add to libunity2dprivate a small singleton class where to add all otherwise unrelated utility functions.
One of these is currentTime, which was previously living in ScreenInfo but clearly didn't belong there.
Therefore I removed it from ScreenInfo and fixed all the places where it was used to use the one from Util.

To post a comment you must log in.
Revision history for this message
Alberto Mardegan (mardy) wrote :

Hi Ugo!
  There's some unused code in there: the scaleSize() method.
But I think we can do without this class at all, and just use Javascript's Date() class:
http://www.w3schools.com/jsref/jsref_gettime.asp

review: Needs Fixing
Revision history for this message
Ugo Riboni (uriboni) wrote :

The unused method is something I use in another project and Florian said he was ok having available in case unity-2d wanted to use it to simplify some calculations.

However considering your good tip about the JS functions, and the fact I can probably export that scale function in some other way, I think this MR is not worth it anymore and I'll cancel it.

I'll submit later the MR about using the JS funtions for currentTime.

Unmerged revisions

687. By Ugo Riboni

Remove currentTime from ScreenInfo and use the new currentTime from Util instead

686. By Ugo Riboni

Add a new singleton class where to collect miscellaneous utility methods.

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 09:42:44 +0000
3+++ libunity-2d-private/Unity2d/plugin.cpp 2011-08-24 11:24:23 +0000
4@@ -54,6 +54,7 @@
5 #include "dragitemwithurl.h"
6 #include "dropitem.h"
7 #include "launcherdropitem.h"
8+#include "util.h"
9
10 #include "config.h"
11
12@@ -149,6 +150,7 @@
13 not creatable directly in QML */
14 engine->rootContext()->setContextProperty("screen", ScreenInfo::instance());
15 engine->rootContext()->setContextProperty("iconUtilities", new IconUtilities(engine));
16+ engine->rootContext()->setContextProperty("util", Util::instance());
17
18 /* Critically important to set the client type to pager because wnck
19 will pass that type over to the window manager through XEvents.
20
21=== modified file 'libunity-2d-private/src/CMakeLists.txt'
22--- libunity-2d-private/src/CMakeLists.txt 2011-08-16 10:40:14 +0000
23+++ libunity-2d-private/src/CMakeLists.txt 2011-08-24 11:24:23 +0000
24@@ -54,6 +54,7 @@
25 launcherdropitem.cpp
26 iconutilities.cpp
27 panelapplet.cpp
28+ util.cpp
29 )
30
31 # Build
32
33=== modified file 'libunity-2d-private/src/screeninfo.cpp'
34--- libunity-2d-private/src/screeninfo.cpp 2011-07-29 13:49:34 +0000
35+++ libunity-2d-private/src/screeninfo.cpp 2011-08-24 11:24:23 +0000
36@@ -61,14 +61,6 @@
37 }
38 }
39
40-/* FIXME: This should be removed when we find a cleaner way to bypass the
41- QML Image cache. See SpreadWindow.qml and WindowImageProvider::requestImage
42- for details. */
43-QString ScreenInfo::currentTime()
44-{
45- return QString::number(time(NULL));
46-}
47-
48 QRect ScreenInfo::availableGeometry() const
49 {
50 return QApplication::desktop()->availableGeometry(QX11Info::appScreen());
51
52=== modified file 'libunity-2d-private/src/screeninfo.h'
53--- libunity-2d-private/src/screeninfo.h 2011-07-29 13:49:34 +0000
54+++ libunity-2d-private/src/screeninfo.h 2011-08-24 11:24:23 +0000
55@@ -27,11 +27,6 @@
56 public:
57 static ScreenInfo* instance();
58
59- /* The following method doesn't strictly belong to a "screen" class
60- logically. It would be perhaps more appropriate to make an
61- "utility" class for it, but this will do for now. */
62- Q_INVOKABLE QString currentTime();
63-
64 /* Getters */
65 WorkspacesInfo *workspaces() { return &m_workspacesInfo; }
66 unsigned int activeWindow() const { return m_activeWindow; }
67
68=== added file 'libunity-2d-private/src/util.cpp'
69--- libunity-2d-private/src/util.cpp 1970-01-01 00:00:00 +0000
70+++ libunity-2d-private/src/util.cpp 2011-08-24 11:24:23 +0000
71@@ -0,0 +1,27 @@
72+#include "util.h"
73+#include <QDateTime>
74+
75+Util::Util(QObject *parent) :
76+ QObject(parent)
77+{
78+}
79+
80+Util* Util::instance()
81+{
82+ static Util* singleton = new Util();
83+ return singleton;
84+}
85+
86+QSize Util::scaleSize(QSize original, QSize scaleTo)
87+{
88+ original.scale(scaleTo, Qt::KeepAspectRatio);
89+ return original;
90+}
91+
92+/* FIXME: This exists only to bypass the QML Image cache.
93+ See WindowImageProvider::requestImage for details. */
94+QString Util::currentTime() {
95+ return QString::number(QDateTime::currentMSecsSinceEpoch());
96+}
97+
98+#include "util.moc"
99
100=== added file 'libunity-2d-private/src/util.h'
101--- libunity-2d-private/src/util.h 1970-01-01 00:00:00 +0000
102+++ libunity-2d-private/src/util.h 2011-08-24 11:24:23 +0000
103@@ -0,0 +1,22 @@
104+#ifndef UTIL_H
105+#define UTIL_H
106+
107+#include <QObject>
108+#include <QSize>
109+
110+class Util : public QObject
111+{
112+ Q_OBJECT
113+
114+private:
115+ explicit Util(QObject *parent = 0);
116+
117+public:
118+ static Util* instance();
119+
120+ Q_INVOKABLE QSize scaleSize(QSize original, QSize scaleTo);
121+ Q_INVOKABLE QString currentTime();
122+
123+};
124+
125+#endif // UTIL_H
126
127=== modified file 'places/dash.qml'
128--- places/dash.qml 2011-08-23 17:02:22 +0000
129+++ places/dash.qml 2011-08-24 11:24:23 +0000
130@@ -130,7 +130,7 @@
131 property variant timeAtActivation
132 Connections {
133 target: declarativeView
134- onActiveChanged: blurredBackground.timeAtActivation = screen.currentTime()
135+ onActiveChanged: blurredBackground.timeAtActivation = util.currentTime()
136 }
137
138 /* Use an image of the root window which essentially is a
139
140=== modified file 'spread/Window.qml'
141--- spread/Window.qml 2011-06-23 17:08:53 +0000
142+++ spread/Window.qml 2011-08-24 11:24:23 +0000
143@@ -77,7 +77,7 @@
144 */
145 source: "image://window/" + windowInfo.decoratedXid + "|"
146 + windowInfo.contentXid + "@"
147- + screen.currentTime()
148+ + util.currentTime()
149
150 /* Disabled during animations for performance reasons */
151 smooth: !animating

Subscribers

People subscribed via source and target branches

to all changes: