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
=== modified file 'libunity-2d-private/Unity2d/plugin.cpp'
--- libunity-2d-private/Unity2d/plugin.cpp 2011-08-23 09:42:44 +0000
+++ libunity-2d-private/Unity2d/plugin.cpp 2011-08-24 11:24:23 +0000
@@ -54,6 +54,7 @@
54#include "dragitemwithurl.h"54#include "dragitemwithurl.h"
55#include "dropitem.h"55#include "dropitem.h"
56#include "launcherdropitem.h"56#include "launcherdropitem.h"
57#include "util.h"
5758
58#include "config.h"59#include "config.h"
5960
@@ -149,6 +150,7 @@
149 not creatable directly in QML */150 not creatable directly in QML */
150 engine->rootContext()->setContextProperty("screen", ScreenInfo::instance());151 engine->rootContext()->setContextProperty("screen", ScreenInfo::instance());
151 engine->rootContext()->setContextProperty("iconUtilities", new IconUtilities(engine));152 engine->rootContext()->setContextProperty("iconUtilities", new IconUtilities(engine));
153 engine->rootContext()->setContextProperty("util", Util::instance());
152154
153 /* Critically important to set the client type to pager because wnck155 /* Critically important to set the client type to pager because wnck
154 will pass that type over to the window manager through XEvents.156 will pass that type over to the window manager through XEvents.
155157
=== modified file 'libunity-2d-private/src/CMakeLists.txt'
--- libunity-2d-private/src/CMakeLists.txt 2011-08-16 10:40:14 +0000
+++ libunity-2d-private/src/CMakeLists.txt 2011-08-24 11:24:23 +0000
@@ -54,6 +54,7 @@
54 launcherdropitem.cpp54 launcherdropitem.cpp
55 iconutilities.cpp55 iconutilities.cpp
56 panelapplet.cpp56 panelapplet.cpp
57 util.cpp
57 )58 )
5859
59# Build60# Build
6061
=== modified file 'libunity-2d-private/src/screeninfo.cpp'
--- libunity-2d-private/src/screeninfo.cpp 2011-07-29 13:49:34 +0000
+++ libunity-2d-private/src/screeninfo.cpp 2011-08-24 11:24:23 +0000
@@ -61,14 +61,6 @@
61 }61 }
62}62}
6363
64/* FIXME: This should be removed when we find a cleaner way to bypass the
65 QML Image cache. See SpreadWindow.qml and WindowImageProvider::requestImage
66 for details. */
67QString ScreenInfo::currentTime()
68{
69 return QString::number(time(NULL));
70}
71
72QRect ScreenInfo::availableGeometry() const64QRect ScreenInfo::availableGeometry() const
73{65{
74 return QApplication::desktop()->availableGeometry(QX11Info::appScreen());66 return QApplication::desktop()->availableGeometry(QX11Info::appScreen());
7567
=== modified file 'libunity-2d-private/src/screeninfo.h'
--- libunity-2d-private/src/screeninfo.h 2011-07-29 13:49:34 +0000
+++ libunity-2d-private/src/screeninfo.h 2011-08-24 11:24:23 +0000
@@ -27,11 +27,6 @@
27public:27public:
28 static ScreenInfo* instance();28 static ScreenInfo* instance();
2929
30 /* The following method doesn't strictly belong to a "screen" class
31 logically. It would be perhaps more appropriate to make an
32 "utility" class for it, but this will do for now. */
33 Q_INVOKABLE QString currentTime();
34
35 /* Getters */30 /* Getters */
36 WorkspacesInfo *workspaces() { return &m_workspacesInfo; }31 WorkspacesInfo *workspaces() { return &m_workspacesInfo; }
37 unsigned int activeWindow() const { return m_activeWindow; }32 unsigned int activeWindow() const { return m_activeWindow; }
3833
=== added file 'libunity-2d-private/src/util.cpp'
--- libunity-2d-private/src/util.cpp 1970-01-01 00:00:00 +0000
+++ libunity-2d-private/src/util.cpp 2011-08-24 11:24:23 +0000
@@ -0,0 +1,27 @@
1#include "util.h"
2#include <QDateTime>
3
4Util::Util(QObject *parent) :
5 QObject(parent)
6{
7}
8
9Util* Util::instance()
10{
11 static Util* singleton = new Util();
12 return singleton;
13}
14
15QSize Util::scaleSize(QSize original, QSize scaleTo)
16{
17 original.scale(scaleTo, Qt::KeepAspectRatio);
18 return original;
19}
20
21/* FIXME: This exists only to bypass the QML Image cache.
22 See WindowImageProvider::requestImage for details. */
23QString Util::currentTime() {
24 return QString::number(QDateTime::currentMSecsSinceEpoch());
25}
26
27#include "util.moc"
028
=== added file 'libunity-2d-private/src/util.h'
--- libunity-2d-private/src/util.h 1970-01-01 00:00:00 +0000
+++ libunity-2d-private/src/util.h 2011-08-24 11:24:23 +0000
@@ -0,0 +1,22 @@
1#ifndef UTIL_H
2#define UTIL_H
3
4#include <QObject>
5#include <QSize>
6
7class Util : public QObject
8{
9 Q_OBJECT
10
11private:
12 explicit Util(QObject *parent = 0);
13
14public:
15 static Util* instance();
16
17 Q_INVOKABLE QSize scaleSize(QSize original, QSize scaleTo);
18 Q_INVOKABLE QString currentTime();
19
20};
21
22#endif // UTIL_H
023
=== modified file 'places/dash.qml'
--- places/dash.qml 2011-08-23 17:02:22 +0000
+++ places/dash.qml 2011-08-24 11:24:23 +0000
@@ -130,7 +130,7 @@
130 property variant timeAtActivation130 property variant timeAtActivation
131 Connections {131 Connections {
132 target: declarativeView132 target: declarativeView
133 onActiveChanged: blurredBackground.timeAtActivation = screen.currentTime()133 onActiveChanged: blurredBackground.timeAtActivation = util.currentTime()
134 }134 }
135135
136 /* Use an image of the root window which essentially is a136 /* Use an image of the root window which essentially is a
137137
=== modified file 'spread/Window.qml'
--- spread/Window.qml 2011-06-23 17:08:53 +0000
+++ spread/Window.qml 2011-08-24 11:24:23 +0000
@@ -77,7 +77,7 @@
77 */77 */
78 source: "image://window/" + windowInfo.decoratedXid + "|"78 source: "image://window/" + windowInfo.decoratedXid + "|"
79 + windowInfo.contentXid + "@"79 + windowInfo.contentXid + "@"
80 + screen.currentTime()80 + util.currentTime()
8181
82 /* Disabled during animations for performance reasons */82 /* Disabled during animations for performance reasons */
83 smooth: !animating83 smooth: !animating

Subscribers

People subscribed via source and target branches

to all changes: