Merge lp:~agateau/unity-2d/unity-core into lp:unity-2d/3.0

Proposed by Aurélien Gâteau on 2011-07-05
Status: Superseded
Proposed branch: lp:~agateau/unity-2d/unity-core
Merge into: lp:unity-2d/3.0
Diff against target: 4445 lines (+1465/-2159)
57 files modified
CMakeLists.txt (+5/-0)
debian/control (+5/-4)
debian/unity-2d-panel.install (+0/-2)
launcher/app/CMakeLists.txt (+0/-2)
launcher/app/launcher.cpp (+5/-21)
libunity-2d-private/Unity2d/CMakeLists.txt (+1/-7)
libunity-2d-private/Unity2d/launcherapplication.cpp (+3/-5)
libunity-2d-private/Unity2d/plugin.cpp (+0/-4)
libunity-2d-private/Unity2d/screeninfo.cpp (+1/-3)
libunity-2d-private/Unity2d/windowinfo.cpp (+1/-3)
libunity-2d-private/Unity2d/workspacesinfo.cpp (+1/-3)
libunity-2d-private/src/CMakeLists.txt (+1/-4)
libunity-2d-private/src/debug.cpp (+23/-0)
libunity-2d-private/src/debug_p.h (+6/-0)
libunity-2d-private/src/unity2dapplication.cpp (+48/-0)
libunity-2d-private/src/unity2dapplication.h (+7/-0)
libunity-2d-private/tests/keyboardmodifiersmonitortest.cpp (+1/-0)
libunity-2d-private/tests/mouseareademo.cpp (+1/-0)
panel/CMakeLists.txt (+3/-5)
panel/app/CMakeLists.txt (+3/-1)
panel/app/main.cpp (+5/-17)
panel/app/panelmanager.cpp (+32/-46)
panel/app/panelmanager.h (+4/-0)
panel/app/unity2dstyle.cpp (+0/-98)
panel/app/unity2dstyle.h (+0/-44)
panel/applets/CMakeLists.txt (+10/-30)
panel/applets/appname/appnameapplet.cpp (+5/-10)
panel/applets/appname/appnameapplet.h (+3/-1)
panel/applets/appname/com.canonical.AppMenu.Registrar.xml (+0/-82)
panel/applets/appname/menubarwidget.cpp (+79/-279)
panel/applets/appname/menubarwidget.h (+24/-66)
panel/applets/appname/registrar.cpp (+0/-138)
panel/applets/appname/registrar.h (+0/-85)
panel/applets/common/fakecairo.h (+125/-0)
panel/applets/common/indicatorentrywidget.cpp (+388/-0)
panel/applets/common/indicatorentrywidget.h (+81/-0)
panel/applets/common/indicatorsmanager.cpp (+179/-0)
panel/applets/common/indicatorsmanager.h (+70/-0)
panel/applets/common/indicatorwidget.cpp (+53/-0)
panel/applets/common/indicatorwidget.h (+51/-0)
panel/applets/common/panelstyle.cpp (+176/-0)
panel/applets/common/panelstyle.h (+59/-0)
panel/applets/indicator-config.h.in (+0/-7)
panel/applets/indicator/abstractindicator.cpp (+0/-43)
panel/applets/indicator/abstractindicator.h (+0/-53)
panel/applets/indicator/datetimeindicator.cpp (+0/-94)
panel/applets/indicator/datetimeindicator.h (+0/-53)
panel/applets/indicator/indicator.c (+0/-510)
panel/applets/indicator/indicator.h (+0/-45)
panel/applets/indicator/indicatorapplet.cpp (+0/-114)
panel/applets/indicator/indicatorapplet.h (+0/-60)
panel/applets/indicator/indicatorservicemanager.cpp (+0/-120)
panel/applets/indicator/indicatorservicemanager.h (+0/-54)
places/app/CMakeLists.txt (+0/-2)
places/app/places.cpp (+3/-19)
spread/app/CMakeLists.txt (+0/-4)
spread/app/spread.cpp (+3/-21)
To merge this branch: bzr merge lp:~agateau/unity-2d/unity-core
Reviewer Review Type Date Requested Status
Tim Penhey (community) Needs Information on 2011-07-12
Florian Boucault 2011-07-05 Pending
Review via email: mp+66960@code.launchpad.net

This proposal has been superseded by a proposal from 2011-07-25.

Commit message

[panel] Refactor to make use of indicator-panel-service, like Unity 3D does.

Description of the change

This branch is an heavy refactor of unity-2d-panel to use the new indicator-panel-service provided by Unity 3D. It has been developed on Oneiric and most likely will not build and work properly on Natty as it depends on GTK3[1] and UnityCore, a new library provided by Unity 3D.

[1] This branch is based on the gtk3 branch I created but which I did not propose for merge because support for indicators is disabled on it (at the time I did the work on this branch, indicators were gtk2-only).

To post a comment you must log in.
Tim Penhey (thumper) wrote :

Hi Aurélien,

I notice you have a GConnector class. It covers a very similar area to Neil's
latest work -
https://code.launchpad.net/~njpatel/unity/nicer-glib-signals/+merge/67439

I also notice you aren't using namespaces for your top level classes - like
the GConnector. Have you considered using one?

A slight niggle, <string> is in the C++ standard library, not the STL (they
don't say we work for pedantical for nothing).

Redeclaring nux::Color is a dangerous thing. Slightly convoluted due to the
actual nux Color being nux::color::Color, which is then used in the nux
namespace. That is probably the only reason you are not getting linker errors
with this.

review: Needs Information
Aurélien Gâteau (agateau) wrote :

> Hi Aurélien,
>
> I notice you have a GConnector class. It covers a very similar area to Neil's
> latest work -
> https://code.launchpad.net/~njpatel/unity/nicer-glib-signals/+merge/67439

Yes, I discussed it briefly with Neil during Platform Rally, but from what I
understand it imposes the use of sigc++ signals. We already deal with GObject
and Qt signals so I prefer not adding another signal system to our stack
(granted, the code in this branch uses sigc++ signals when we deal with
UnityCore so this may be a moot point)

> I also notice you aren't using namespaces for your top level classes - like
> the GConnector. Have you considered using one?

Not really. GConnector is in libunity-2d-private, which is not supposed to be
reused outside of unity-2d. Therefore I don't see an advantage in using
namespaces here.

> A slight niggle, <string> is in the C++ standard library, not the STL (they
> don't say we work for pedantical for nothing).

Will fix :)

> Redeclaring nux::Color is a dangerous thing. Slightly convoluted due to the
> actual nux Color being nux::color::Color, which is then used in the nux
> namespace. That is probably the only reason you are not getting linker errors
> with this.

Granted, this code is hackish. It cannot cause link errors though:
nux::Color is in Nux and we only link to NuxCore, not to Nux. I would have
used nux::Color directly instead of reimplementing it otherwise.

This code is part of a fake Cairo API used to draw the border behind the active
menubar item:

I expected the corresponding code in unity-3d to continue to evolve based on
adjustments from Design and more drawing code to be added later on. It would
have been a pain to catch up with it if I had rewritten the whole drawing code
using Qt painting API. Instead I opted to fake the Cairo API, this way I
expected to be able to catch up by simply copying the drawing code from
unity-3d.

It turned out to be a not-so-smart move in the end because by the time I was
done with my fake Cairo API, Cimi started redoing the panel drawing code using
GTK3 style API :/. I plan on investigating whether it is possible for us to
directly call the GTK3 style API to paint on QWidgets so that we can keep
rendering synchronized. At this point this whole fake Cairo code should be
scrapped.

Tim Penhey (thumper) wrote :

On Tue, 12 Jul 2011 21:12:39 you wrote:
> > I also notice you aren't using namespaces for your top level classes -
> > like the GConnector. Have you considered using one?
>
> Not really. GConnector is in libunity-2d-private, which is not supposed to
> be reused outside of unity-2d. Therefore I don't see an advantage in using
> namespaces here.

You could say the same about unity, but I'm pushing for "namespace unity" (and
implementing).

> > Redeclaring nux::Color is a dangerous thing. Slightly convoluted due to
> > the actual nux Color being nux::color::Color, which is then used in the
> > nux namespace. That is probably the only reason you are not getting
> > linker errors with this.
>
> Granted, this code is hackish. It cannot cause link errors though:
> nux::Color is in Nux and we only link to NuxCore, not to Nux. I would have
> used nux::Color directly instead of reimplementing it otherwise.

No. nux::Color is in NuxCore, not Nux.

> This code is part of a fake Cairo API used to draw the border behind the
> active menubar item:
>
> I expected the corresponding code in unity-3d to continue to evolve based
> on adjustments from Design and more drawing code to be added later on. It
> would have been a pain to catch up with it if I had rewritten the whole
> drawing code using Qt painting API. Instead I opted to fake the Cairo API,
> this way I expected to be able to catch up by simply copying the drawing
> code from unity-3d.
>
> It turned out to be a not-so-smart move in the end because by the time I
> was done with my fake Cairo API, Cimi started redoing the panel drawing
> code using GTK3 style API :/. I plan on investigating whether it is
> possible for us to directly call the GTK3 style API to paint on QWidgets
> so that we can keep rendering synchronized. At this point this whole fake
> Cairo code should be scrapped.

Sure.

Aurélien Gâteau (agateau) wrote :

> On Tue, 12 Jul 2011 21:12:39 you wrote:
> > > I also notice you aren't using namespaces for your top level classes -
> > > like the GConnector. Have you considered using one?
> >
> > Not really. GConnector is in libunity-2d-private, which is not supposed to
> > be reused outside of unity-2d. Therefore I don't see an advantage in using
> > namespaces here.
>
> You could say the same about unity, but I'm pushing for "namespace unity" (and
> implementing).

Not exactly, at least libunity-core is used by both unity-2d and unity-3d.

> > > Redeclaring nux::Color is a dangerous thing. Slightly convoluted due to
> > > the actual nux Color being nux::color::Color, which is then used in the
> > > nux namespace. That is probably the only reason you are not getting
> > > linker errors with this.
> >
> > Granted, this code is hackish. It cannot cause link errors though:
> > nux::Color is in Nux and we only link to NuxCore, not to Nux. I would have
> > used nux::Color directly instead of reimplementing it otherwise.
>
> No. nux::Color is in NuxCore, not Nux.

Oh. Will fix.

Aurélien

lp:~agateau/unity-2d/unity-core updated on 2011-07-27
671. By Aurélien Gâteau on 2011-07-12

Sync with trunk

672. By Aurélien Gâteau on 2011-07-12

[panel] Use the real nux::color::Color class instead of faking it.

673. By Aurélien Gâteau on 2011-07-12

[panel] Use the float versions of rgba accessors...

674. By Aurélien Gâteau on 2011-07-12

[panel] debug--

675. By Aurélien Gâteau on 2011-07-13

Merge gtk3 branch

676. By Aurélien Gâteau on 2011-07-13

Merge gtk3 branch

677. By Aurélien Gâteau on 2011-07-13

[packaging] Add missing build-dep, do not try to install removed pngs

678. By Aurélien Gâteau on 2011-07-18

Merged gtk3 branch

679. By Aurélien Gâteau on 2011-07-19

Cleanup

680. By Aurélien Gâteau on 2011-07-25

Synced with gtk3 branch

681. By Aurélien Gâteau on 2011-07-26

[build] Fix build with libunity-core 4.4

UnityCore.h has been removed

682. By Aurélien Gâteau on 2011-07-27

Remove forgotten FIXME comment

683. By Aurélien Gâteau on 2011-07-27

Sync with gtk3

684. By Aurélien Gâteau on 2011-07-27

Merge unity-2d/4.0 in

685. By Aurélien Gâteau on 2011-07-27

[panel] Empty commit to close bugs

686. By Aurélien Gâteau on 2011-07-27

Sync with unity-2d/4.0

687. By Aurélien Gâteau on 2011-07-27

[panel] Make sure indicators are present on hotplugged monitor

IndicatorsManager should not be shared among panels, otherwise when a new
monitor is plugged after unity-2d-panel startup, we don't get any indicators as
no on_object_added() signal is emitted.

Unmerged revisions

687. By Aurélien Gâteau on 2011-07-27

[panel] Make sure indicators are present on hotplugged monitor

IndicatorsManager should not be shared among panels, otherwise when a new
monitor is plugged after unity-2d-panel startup, we don't get any indicators as
no on_object_added() signal is emitted.

686. By Aurélien Gâteau on 2011-07-27

Sync with unity-2d/4.0

685. By Aurélien Gâteau on 2011-07-27

[panel] Empty commit to close bugs

684. By Aurélien Gâteau on 2011-07-27

Merge unity-2d/4.0 in

683. By Aurélien Gâteau on 2011-07-27

Sync with gtk3

682. By Aurélien Gâteau on 2011-07-27

Remove forgotten FIXME comment

681. By Aurélien Gâteau on 2011-07-26

[build] Fix build with libunity-core 4.4

UnityCore.h has been removed

680. By Aurélien Gâteau on 2011-07-25

Synced with gtk3 branch

679. By Aurélien Gâteau on 2011-07-19

Cleanup

678. By Aurélien Gâteau on 2011-07-18

Merged gtk3 branch

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2011-06-27 13:40:51 +0000
3+++ CMakeLists.txt 2011-07-18 14:37:40 +0000
4@@ -23,6 +23,11 @@
5 find_package(Qt4 REQUIRED)
6 find_package(X11 REQUIRED)
7 find_package(Gettext REQUIRED)
8+pkg_check_modules(GLIB REQUIRED glib-2.0)
9+pkg_check_modules(GDK REQUIRED gdk-3.0)
10+pkg_check_modules(GTK REQUIRED gtk+-3.0)
11+pkg_check_modules(GIO REQUIRED gio-2.0)
12+pkg_check_modules(WNCK REQUIRED libwnck-3.0)
13
14 include_directories(
15 ${CMAKE_BINARY_DIR}
16
17=== modified file 'debian/control'
18--- debian/control 2011-06-22 21:17:49 +0000
19+++ debian/control 2011-07-18 14:37:40 +0000
20@@ -10,16 +10,17 @@
21 libqt4-dev,
22 libqt4-opengl-dev,
23 libglib2.0-dev,
24- libwnck-dev,
25+ libwnck-3-dev,
26 libqtgconf-dev,
27 libqtbamf-dev,
28 libqtdee-dev,
29 libdbusmenu-qt-dev,
30 libx11-dev,
31- libindicator-dev,
32- libgtk2.0-dev,
33+ libindicator3-dev,
34+ libgtk-3-dev,
35 libutouch-geis-dev,
36- libstartup-notification0-dev
37+ libstartup-notification0-dev,
38+ libunity-core-4.0-dev
39 Standards-Version: 3.9.1
40 Vcs-Bzr: http://bazaar.launchpad.net/~unity-2d-team/unity-2d/trunk
41
42
43=== modified file 'debian/unity-2d-panel.install'
44--- debian/unity-2d-panel.install 2011-01-14 21:41:39 +0000
45+++ debian/unity-2d-panel.install 2011-07-18 14:37:40 +0000
46@@ -1,4 +1,2 @@
47 usr/bin/unity-2d-panel
48 usr/share/applications/unity-2d-panel.desktop
49-usr/share/unity-2d/panel/artwork/background.png
50-usr/share/unity-2d/panel/artwork/divider.png
51
52=== modified file 'launcher/app/CMakeLists.txt'
53--- launcher/app/CMakeLists.txt 2011-06-11 11:33:52 +0000
54+++ launcher/app/CMakeLists.txt 2011-07-18 14:37:40 +0000
55@@ -1,6 +1,4 @@
56 # Dependencies
57-pkg_check_modules(GTK REQUIRED gtk+-2.0)
58-pkg_check_modules(X11 REQUIRED x11)
59 pkg_check_modules(GEIS REQUIRED libutouch-geis)
60 pkg_check_modules(QTGCONF REQUIRED libqtgconf)
61
62
63=== modified file 'launcher/app/launcher.cpp'
64--- launcher/app/launcher.cpp 2011-06-22 08:33:52 +0000
65+++ launcher/app/launcher.cpp 2011-07-18 14:37:40 +0000
66@@ -17,8 +17,6 @@
67 * along with this program. If not, see <http://www.gnu.org/licenses/>.
68 */
69
70-#include <gtk/gtk.h>
71-
72 // unity-2d
73 #include <gnomesessionclient.h>
74 #include <launcherclient.h>
75@@ -44,6 +42,9 @@
76 #include "unity2dpanel.h"
77 #include "gesturehandler.h"
78
79+// libc
80+#include <stdlib.h>
81+
82 #if defined(QMLJSDEBUGGER)
83 #include <qt_private/qdeclarativedebughelper_p.h>
84 #endif
85@@ -73,24 +74,7 @@
86
87 int main(int argc, char *argv[])
88 {
89- /* Unity2d plugin uses GTK APIs to retrieve theme icons
90- (gtk_icon_theme_get_default) and requires a call to gtk_init */
91- gtk_init(&argc, &argv);
92-
93- Unity2dDebug::installHandlers();
94-
95- /* When the environment variable QT_GRAPHICSSYSTEM is not set,
96- force graphics system to 'raster' instead of the default 'native'
97- which on X11 is 'XRender'.
98- 'XRender' defaults to using a TrueColor visual. We do _not_ mimick that
99- behaviour with 'raster' by calling QApplication::setColorSpec because
100- of a bug where black rectangular artifacts were appearing randomly:
101-
102- https://bugs.launchpad.net/unity-2d/+bug/734143
103- */
104- if(getenv("QT_GRAPHICSSYSTEM") == 0) {
105- QApplication::setGraphicsSystem("raster");
106- }
107+ Unity2dApplication::earlySetup(argc, argv);
108 Unity2dApplication application(argc, argv);
109 QSet<QString> arguments = QSet<QString>::fromList(QCoreApplication::arguments());
110
111@@ -149,7 +133,7 @@
112 the launcher itself was autostarted (which is the common case when
113 running installed).
114 For a discussion, see https://bugs.launchpad.net/upicek/+bug/684160. */
115- g_unsetenv("DESKTOP_AUTOSTART_ID");
116+ unsetenv("DESKTOP_AUTOSTART_ID");
117
118 /* Gesture handler instance in charge of listening to gesture events and
119 trigger appropriate actions in response. */
120
121=== modified file 'libunity-2d-private/Unity2d/CMakeLists.txt'
122--- libunity-2d-private/Unity2d/CMakeLists.txt 2011-06-22 08:54:52 +0000
123+++ libunity-2d-private/Unity2d/CMakeLists.txt 2011-07-18 14:37:40 +0000
124@@ -1,16 +1,10 @@
125 # Dependencies
126-pkg_check_modules(WNCK REQUIRED libwnck-1.0)
127 pkg_check_modules(QTBAMF REQUIRED libqtbamf)
128 pkg_check_modules(QTGCONF REQUIRED libqtgconf)
129 pkg_check_modules(QTDEE REQUIRED libqtdee)
130 pkg_check_modules(DBUSMENUQT REQUIRED dbusmenu-qt)
131-pkg_check_modules(GLIB REQUIRED glib-2.0)
132-pkg_check_modules(GDK REQUIRED gdk-2.0)
133-pkg_check_modules(GIO REQUIRED gio-2.0)
134 pkg_check_modules(STARTUPNOTIFICATION REQUIRED libstartup-notification-1.0)
135-pkg_check_modules(INDICATOR REQUIRED indicator)
136-
137-find_package(X11 REQUIRED)
138+pkg_check_modules(INDICATOR REQUIRED indicator3-0.4)
139
140 # Sources
141 set(unity-2d-private-qml_SRCS
142
143=== modified file 'libunity-2d-private/Unity2d/launcherapplication.cpp'
144--- libunity-2d-private/Unity2d/launcherapplication.cpp 2011-07-13 17:42:29 +0000
145+++ libunity-2d-private/Unity2d/launcherapplication.cpp 2011-07-18 14:37:40 +0000
146@@ -14,10 +14,6 @@
147 * along with this program. If not, see <http://www.gnu.org/licenses/>.
148 */
149
150-/* Those have to be included before any QObject-style header to avoid
151- compilation errors. */
152-#include <gdk/gdk.h>
153-
154 /* Note regarding the use of wnck: it is critically important that the client
155 type be set to pager because wnck will pass that type over to the window
156 manager through XEvents.
157@@ -59,6 +55,7 @@
158 #include <QX11Info>
159
160 extern "C" {
161+#include <gdk/gdk.h>
162 #include <libsn/sn.h>
163 }
164
165@@ -649,7 +646,8 @@
166 GTimeVal timeval;
167
168 g_get_current_time (&timeval);
169- GObjectScopedPointer<GdkAppLaunchContext> context(gdk_app_launch_context_new());
170+ GdkDisplay* display = gdk_display_get_default();
171+ GObjectScopedPointer<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));
172 /* Using GDK_CURRENT_TIME doesn’t seem to work, launched windows
173 sometimes don’t get focus (see https://launchpad.net/bugs/643616). */
174 gdk_app_launch_context_set_timestamp(context.data(), timeval.tv_sec);
175
176=== modified file 'libunity-2d-private/Unity2d/plugin.cpp'
177--- libunity-2d-private/Unity2d/plugin.cpp 2011-07-14 11:17:30 +0000
178+++ libunity-2d-private/Unity2d/plugin.cpp 2011-07-18 14:37:40 +0000
179@@ -20,10 +20,6 @@
180 /* Required otherwise using wnck_set_client_type breaks linking with error:
181 undefined reference to `wnck_set_client_type(WnckClientType)'
182 */
183-extern "C" {
184-#include <libwnck/util.h>
185-}
186-
187 #include "plugin.h"
188
189 #include "launcherapplication.h"
190
191=== modified file 'libunity-2d-private/Unity2d/screeninfo.cpp'
192--- libunity-2d-private/Unity2d/screeninfo.cpp 2011-06-27 13:43:05 +0000
193+++ libunity-2d-private/Unity2d/screeninfo.cpp 2011-07-18 14:37:40 +0000
194@@ -1,7 +1,5 @@
195 extern "C" {
196-#include <libwnck/screen.h>
197-#include <libwnck/window.h>
198-#include <libwnck/workspace.h>
199+#include <libwnck/libwnck.h>
200 }
201
202 #include "bamf-matcher.h"
203
204=== modified file 'libunity-2d-private/Unity2d/windowinfo.cpp'
205--- libunity-2d-private/Unity2d/windowinfo.cpp 2011-02-08 11:48:16 +0000
206+++ libunity-2d-private/Unity2d/windowinfo.cpp 2011-07-18 14:37:40 +0000
207@@ -14,9 +14,7 @@
208 * along with this program. If not, see <http://www.gnu.org/licenses/>.
209 */
210
211-#include <libwnck/screen.h>
212-#include <libwnck/window.h>
213-#include <libwnck/workspace.h>
214+#include <libwnck/libwnck.h>
215
216 #include <glib-2.0/glib.h>
217
218
219=== modified file 'libunity-2d-private/Unity2d/workspacesinfo.cpp'
220--- libunity-2d-private/Unity2d/workspacesinfo.cpp 2011-06-27 13:43:05 +0000
221+++ libunity-2d-private/Unity2d/workspacesinfo.cpp 2011-07-18 14:37:40 +0000
222@@ -4,9 +4,7 @@
223 #include <debug_p.h>
224
225 extern "C" {
226-#include <libwnck/screen.h>
227-#include <libwnck/window.h>
228-#include <libwnck/workspace.h>
229+#include <libwnck/libwnck.h>
230 }
231
232 #include "gconfitem-qml-wrapper.h"
233
234=== modified file 'libunity-2d-private/src/CMakeLists.txt'
235--- libunity-2d-private/src/CMakeLists.txt 2011-07-12 10:30:50 +0000
236+++ libunity-2d-private/src/CMakeLists.txt 2011-07-18 14:37:40 +0000
237@@ -1,9 +1,6 @@
238-# Dependencies
239-pkg_check_modules(GLIB REQUIRED glib-2.0)
240-pkg_check_modules(WNCK REQUIRED libwnck-1.0)
241-
242 # Sources
243 set(libunity-2d-private_SRCS
244+ debug.cpp
245 gconnector.cpp
246 gnomesessionclient.cpp
247 keyboardmodifiersmonitor.cpp
248
249=== added file 'libunity-2d-private/src/debug.cpp'
250--- libunity-2d-private/src/debug.cpp 1970-01-01 00:00:00 +0000
251+++ libunity-2d-private/src/debug.cpp 2011-07-18 14:37:40 +0000
252@@ -0,0 +1,23 @@
253+/* This file is part of unity-2d
254+ Copyright 2011 Canonical
255+ Author: Aurelien Gateau <aurelien.gateau@canonical.com>
256+
257+ This program is free software; you can redistribute it and/or modify
258+ it under the terms of the GNU General Public License as published
259+ by the Free Software Foundation; version 3.
260+
261+ This program is distributed in the hope that it will be useful,
262+ but WITHOUT ANY WARRANTY; without even the implied warranty of
263+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
264+ GNU General Public License for more details.
265+
266+ You should have received a copy of the GNU General Public License
267+ along with this program. If not, see <http://www.gnu.org/licenses/>.
268+ */
269+// Self
270+#include <debug_p.h>
271+
272+QDebug operator<<(QDebug& dbg, const std::string& str)
273+{
274+ return dbg << QString::fromUtf8(str.c_str());
275+}
276
277=== modified file 'libunity-2d-private/src/debug_p.h'
278--- libunity-2d-private/src/debug_p.h 2011-03-28 14:06:14 +0000
279+++ libunity-2d-private/src/debug_p.h 2011-07-18 14:37:40 +0000
280@@ -17,8 +17,12 @@
281 #ifndef DEBUG_P_H
282 #define DEBUG_P_H
283
284+// Qt
285 #include <QDebug>
286
287+// STL
288+#include <string>
289+
290 #define _UQ_TRACE(level) (level().nospace() << __PRETTY_FUNCTION__ << ":").space()
291
292 // Simple macros to get KDebug like support
293@@ -62,5 +66,7 @@
294
295 #define UQ_DEBUG_BLOCK Unity2dDebugBlock __unity2dDebugBlock__(__PRETTY_FUNCTION__)
296
297+// Support for outputing std::string with qDebug
298+QDebug operator<<(QDebug& dbg, const std::string& str);
299
300 #endif /* DEBUG_P_H */
301
302=== modified file 'libunity-2d-private/src/unity2dapplication.cpp'
303--- libunity-2d-private/src/unity2dapplication.cpp 2011-06-11 10:50:03 +0000
304+++ libunity-2d-private/src/unity2dapplication.cpp 2011-07-18 14:37:40 +0000
305@@ -22,7 +22,15 @@
306 // Self
307 #include "unity2dapplication.h"
308
309+// libunity-2d
310+#include <debug_p.h>
311+#include <unity2ddebug.h>
312+
313 // Qt
314+#include <QWindowsStyle>
315+
316+// GTK
317+#include <gtk/gtk.h>
318
319 AbstractX11EventFilter::~AbstractX11EventFilter()
320 {
321@@ -32,6 +40,46 @@
322 }
323 }
324
325+static bool arrayContains(char** begin, char** end, const char* string)
326+{
327+ for (char** ptr = begin; ptr != end; ++ptr) {
328+ if (strcmp(*ptr, string) == 0) {
329+ return true;
330+ }
331+ }
332+ return false;
333+}
334+
335+void Unity2dApplication::earlySetup(int& argc, char** argv)
336+{
337+ // Parts of unity-2d uses GTK so it needs to be initialized
338+ gtk_init(&argc, &argv);
339+
340+ Unity2dDebug::installHandlers();
341+
342+ /* When the environment variable QT_GRAPHICSSYSTEM is not set, force
343+ * graphics system to 'raster' instead of the default 'native' which on X11
344+ * is 'XRender'. 'XRender' defaults to using a TrueColor visual. We do
345+ * _not_ mimick that behaviour with 'raster' by calling
346+ * QApplication::setColorSpec because of bugs where some pixmaps become
347+ * blueish or black rectangular artifacts were appearing randomly:
348+ *
349+ * https://bugs.launchpad.net/unity-2d/+bug/689877
350+ * https://bugs.launchpad.net/unity-2d/+bug/734143
351+ */
352+ if(getenv("QT_GRAPHICSSYSTEM") == 0) {
353+ QApplication::setGraphicsSystem("raster");
354+ }
355+
356+ /* Unless style has been specified in args, set default Qt style to
357+ * QWindowStyle to avoid loading QGtkStyle. We don't want to load QGtkStyle
358+ * because it uses libgtk2, which causes conflicts with our gtk3 code.
359+ */
360+ if (!arrayContains(argv, argv + argc, "-style")) {
361+ QApplication::setStyle(new QWindowsStyle);
362+ }
363+}
364+
365 Unity2dApplication::Unity2dApplication(int& argc, char** argv)
366 : QApplication(argc, argv)
367 {
368
369=== modified file 'libunity-2d-private/src/unity2dapplication.h'
370--- libunity-2d-private/src/unity2dapplication.h 2011-02-28 17:14:19 +0000
371+++ libunity-2d-private/src/unity2dapplication.h 2011-07-18 14:37:40 +0000
372@@ -49,6 +49,13 @@
373 void removeX11EventFilter(AbstractX11EventFilter*);
374
375 /**
376+ * This method must be called *before* instantiating a Unity2dApplication.
377+ * It inits gtk and adjusts settings like the graphics system and the Qt
378+ * style.
379+ */
380+ static void earlySetup(int& argc, char** argv);
381+
382+ /**
383 * Note: This function will return a null pointer if you did not use a Unity2dApplication in your application!
384 */
385 static Unity2dApplication* instance();
386
387=== modified file 'libunity-2d-private/tests/keyboardmodifiersmonitortest.cpp'
388--- libunity-2d-private/tests/keyboardmodifiersmonitortest.cpp 2011-01-26 15:50:26 +0000
389+++ libunity-2d-private/tests/keyboardmodifiersmonitortest.cpp 2011-07-18 14:37:40 +0000
390@@ -39,6 +39,7 @@
391 #define UQ_TEST_MAIN(TestObject) \
392 int main(int argc, char *argv[]) \
393 { \
394+ Unity2dApplication::earlySetup(argc, argv); \
395 Unity2dApplication app(argc, argv); \
396 QTEST_DISABLE_KEYPAD_NAVIGATION \
397 TestObject tc; \
398
399=== modified file 'libunity-2d-private/tests/mouseareademo.cpp'
400--- libunity-2d-private/tests/mouseareademo.cpp 2011-02-15 18:18:13 +0000
401+++ libunity-2d-private/tests/mouseareademo.cpp 2011-07-18 14:37:40 +0000
402@@ -29,6 +29,7 @@
403
404 int main(int argc, char** argv)
405 {
406+ Unity2dApplication::earlySetup(argc, argv);
407 Unity2dApplication app(argc, argv);
408 QWidget window;
409 QLabel* enteredLabel = new QLabel("Entered");
410
411=== modified file 'panel/CMakeLists.txt'
412--- panel/CMakeLists.txt 2011-06-27 13:40:51 +0000
413+++ panel/CMakeLists.txt 2011-07-18 14:37:40 +0000
414@@ -1,5 +1,8 @@
415 project(unity-2d-panel)
416
417+# Dependencies
418+pkg_check_modules(UNITYCORE REQUIRED unity-core-4.0)
419+
420 # Source
421 include_directories(
422 ${libunity-2d-private_SOURCE_DIR}/src
423@@ -8,8 +11,3 @@
424 add_subdirectory(applets)
425 add_subdirectory(app)
426 add_subdirectory(tests)
427-
428-# Install
429-install(DIRECTORY artwork
430- DESTINATION ${UNITY_2D_DIR}/panel
431- )
432
433=== modified file 'panel/app/CMakeLists.txt'
434--- panel/app/CMakeLists.txt 2011-04-04 16:41:15 +0000
435+++ panel/app/CMakeLists.txt 2011-07-18 14:37:40 +0000
436@@ -1,7 +1,6 @@
437 set(panel_SRCS
438 main.cpp
439 panelmanager.cpp
440- unity2dstyle.cpp
441 )
442
443 qt4_automoc(${panel_SRCS})
444@@ -10,14 +9,17 @@
445 include_directories(
446 ${CMAKE_CURRENT_BINARY_DIR}
447 ${CMAKE_CURRENT_SOURCE_DIR}
448+ ${GTK_INCLUDE_DIRS}
449 ${uqapplets_SOURCE_DIR}
450 ${uqapplets_SOURCE_DIR}/common
451+ ${UNITYCORE_INCLUDE_DIRS}
452 ${libunity-2d-private_SOURCE_DIR}/src
453 )
454
455 target_link_libraries(unity-2d-panel
456 ${QT_QTGUI_LIBRARIES}
457 ${QT_QTCORE_LIBRARIES}
458+ ${GTK_LDFLAGS}
459 uqapplets
460 unity-2d-private
461 )
462
463=== modified file 'panel/app/main.cpp'
464--- panel/app/main.cpp 2011-06-06 09:23:48 +0000
465+++ panel/app/main.cpp 2011-07-18 14:37:40 +0000
466@@ -22,12 +22,12 @@
467 // Local
468 #include <config.h>
469 #include <panelmanager.h>
470+#include <panelstyle.h>
471
472 // Unity
473 #include <gnomesessionclient.h>
474 #include <unity2ddebug.h>
475 #include <unity2dapplication.h>
476-#include <unity2dstyle.h>
477 #include <unity2dtr.h>
478
479 // Qt
480@@ -52,23 +52,11 @@
481 int main(int argc, char** argv)
482 {
483 ThemeEngineHandler handler;
484-
485- Unity2dDebug::installHandlers();
486-
487- /* When the environment variable QT_GRAPHICSSYSTEM is not set,
488- force graphics system to 'raster' instead of the default 'native'
489- which on X11 is 'XRender'.
490- 'XRender' defaults to using a TrueColor visual. We do _not_ mimick that
491- behaviour with 'raster' by calling QApplication::setColorSpec because
492- of a bug where black rectangular artifacts were appearing randomly:
493-
494- https://bugs.launchpad.net/unity-2d/+bug/734143
495- */
496- if(getenv("QT_GRAPHICSSYSTEM") == 0) {
497- QApplication::setGraphicsSystem("raster");
498- }
499+ Unity2dApplication::earlySetup(argc, argv);
500 Unity2dApplication app(argc, argv);
501- QApplication::setStyle(new Unity2dStyle);
502+
503+ // Instantiate a PanelStyle so that it configures QApplication
504+ PanelStyle::instance();
505
506 GnomeSessionClient client(INSTALL_PREFIX "/share/applications/unity-2d-panel.desktop");
507 client.connectToSessionManager();
508
509=== modified file 'panel/app/panelmanager.cpp'
510--- panel/app/panelmanager.cpp 2011-06-12 23:01:35 +0000
511+++ panel/app/panelmanager.cpp 2011-07-18 14:37:40 +0000
512@@ -24,6 +24,8 @@
513
514 // Local
515 #include <config.h>
516+#include <panelstyle.h>
517+#include <indicatorsmanager.h>
518
519 // Applets
520 #include <appindicator/appindicatorapplet.h>
521@@ -42,35 +44,37 @@
522
523 using namespace Unity2d;
524
525-static QPalette getPalette()
526-{
527- QPalette palette;
528-
529- /* Should use the panel's background provided by Unity but it turns
530- out not to be good. It would look like:
531-
532- QBrush bg(QPixmap("theme:/panel_background.png"));
533- */
534- QBrush bg(QPixmap(unity2dDirectory() + "/panel/artwork/background.png"));
535- palette.setBrush(QPalette::Window, bg);
536- palette.setBrush(QPalette::Button, bg);
537- return palette;
538-}
539-
540-static QLabel* createSeparator()
541-{
542- QLabel* label = new QLabel;
543- QPixmap pix(unity2dDirectory() + "/panel/artwork/divider.png");
544- label->setPixmap(pix);
545- label->setFixedSize(pix.size());
546- return label;
547-}
548-
549-static Unity2dPanel* instantiatePanel(int screen)
550+static QWidget* createSeparator()
551+{
552+ // Just a quick-hack: homebutton is going away anyway
553+ QWidget* widget = new QWidget;
554+ widget->setFixedWidth(6);
555+ return widget;
556+}
557+
558+PanelManager::PanelManager(QObject* parent)
559+: QObject(parent)
560+, m_indicatorsManager(new IndicatorsManager(this))
561+{
562+ QDesktopWidget* desktop = QApplication::desktop();
563+ for(int i = 0; i < desktop->screenCount(); ++i) {
564+ Unity2dPanel* panel = instantiatePanel(i);
565+ m_panels.append(panel);
566+ panel->show();
567+ panel->move(desktop->screenGeometry(i).topLeft());
568+ }
569+ connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));
570+}
571+
572+PanelManager::~PanelManager()
573+{
574+ qDeleteAll(m_panels);
575+}
576+
577+Unity2dPanel* PanelManager::instantiatePanel(int screen)
578 {
579 Unity2dPanel* panel = new Unity2dPanel;
580 panel->setEdge(Unity2dPanel::TopEdge);
581- panel->setPalette(getPalette());
582 panel->setFixedHeight(24);
583
584 int leftmost = QApplication::desktop()->screenNumber(QPoint());
585@@ -78,34 +82,16 @@
586 panel->addWidget(new HomeButtonApplet);
587 panel->addWidget(createSeparator());
588 }
589- panel->addWidget(new AppNameApplet);
590+ panel->addWidget(new AppNameApplet(m_indicatorsManager));
591 if (screen == leftmost) {
592 /* It doesn’t make sense to have more than one instance of the systray,
593 XEmbed’ed windows can be displayed only once anyway. */
594 panel->addWidget(new LegacyTrayApplet);
595 }
596- panel->addWidget(new IndicatorApplet);
597+ panel->addWidget(new IndicatorApplet(m_indicatorsManager));
598 return panel;
599 }
600
601-PanelManager::PanelManager(QObject* parent)
602- : QObject(parent)
603-{
604- QDesktopWidget* desktop = QApplication::desktop();
605- for(int i = 0; i < desktop->screenCount(); ++i) {
606- Unity2dPanel* panel = instantiatePanel(i);
607- m_panels.append(panel);
608- panel->show();
609- panel->move(desktop->screenGeometry(i).topLeft());
610- }
611- connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));
612-}
613-
614-PanelManager::~PanelManager()
615-{
616- qDeleteAll(m_panels);
617-}
618-
619 void
620 PanelManager::onScreenCountChanged(int newCount)
621 {
622
623=== modified file 'panel/app/panelmanager.h'
624--- panel/app/panelmanager.h 2011-04-04 16:41:15 +0000
625+++ panel/app/panelmanager.h 2011-07-18 14:37:40 +0000
626@@ -26,6 +26,7 @@
627 #include <QObject>
628 #include <QList>
629
630+class IndicatorsManager;
631 class Unity2dPanel;
632
633 class PanelManager : public QObject
634@@ -38,8 +39,11 @@
635
636 private:
637 Q_DISABLE_COPY(PanelManager)
638+ IndicatorsManager* m_indicatorsManager;
639 QList<Unity2dPanel*> m_panels;
640
641+ Unity2dPanel* instantiatePanel(int screen);
642+
643 private Q_SLOTS:
644 void onScreenCountChanged(int newCount);
645 };
646
647=== removed file 'panel/app/unity2dstyle.cpp'
648--- panel/app/unity2dstyle.cpp 2011-03-28 12:16:02 +0000
649+++ panel/app/unity2dstyle.cpp 1970-01-01 00:00:00 +0000
650@@ -1,98 +0,0 @@
651-/*
652- * Plasma applet to display DBus global menu
653- *
654- * Copyright 2009 Canonical Ltd.
655- *
656- * Authors:
657- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
658- *
659- * This program is free software; you can redistribute it and/or modify
660- * it under the terms of the GNU General Public License as published by
661- * the Free Software Foundation; version 3.
662- *
663- * This program is distributed in the hope that it will be useful,
664- * but WITHOUT ANY WARRANTY; without even the implied warranty of
665- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
666- * GNU General Public License for more details.
667- *
668- * You should have received a copy of the GNU General Public License
669- * along with this program. If not, see <http://www.gnu.org/licenses/>
670- */
671-
672-// Self
673-#include "unity2dstyle.h"
674-
675-// Local
676-
677-// libunity-2d-private
678-#include <debug_p.h>
679-#include <keyboardmodifiersmonitor.h>
680-
681-// Qt
682-#include <QGtkStyle>
683-#include <QMenu>
684-#include <QPainter>
685-#include <QStyleOptionFrame>
686-#include <QWidget>
687-
688-Unity2dStyle::Unity2dStyle()
689-: QProxyStyle(new QGtkStyle)
690-{
691-}
692-
693-void Unity2dStyle::drawControl(QStyle::ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
694-{
695- if (element == QStyle::CE_MenuBarItem && widget) {
696- QStyleOptionMenuItem opt = *qstyleoption_cast<const QStyleOptionMenuItem*>(option);
697- if (!(opt.state & QStyle::State_Enabled) && (opt.state & QStyle::State_Sunken)) {
698- // Reset State_Sunken flag to avoid drawing a frame on a disabled menu item
699- // See https://bugs.launchpad.net/unity-2d/+bug/717744
700- opt.state ^= QStyle::State_Sunken;
701- }
702- // Skip "widget" parameter to avoid solid gray background behind the menubar items
703- QProxyStyle::drawControl(element, &opt, painter, 0);
704- } else if (element == QStyle::CE_MenuBarEmptyArea) {
705- // Avoid gray borders around the menubar items
706- } else {
707- QProxyStyle::drawControl(element, option, painter, widget);
708- }
709-}
710-
711-int Unity2dStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption* option, const QWidget* widget) const
712-{
713- if (metric == QStyle::PM_MenuBarVMargin) {
714- // Avoid one-pixel gap above menuitem
715- return 0;
716- } else {
717- return QProxyStyle::pixelMetric(metric, option, widget);
718- }
719-}
720-
721-QSize Unity2dStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget) const
722-{
723- QSize size = QProxyStyle::sizeFromContents(type, option, contentsSize, widget);
724- if (type == QStyle::CT_MenuBarItem && widget) {
725- // Avoid three-pixel gap below menuitem
726- size.setHeight(widget->height());
727- }
728- return size;
729-}
730-
731-int Unity2dStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
732-{
733- if (hint == QStyle::SH_UnderlineShortcut) {
734- // The shortcut of an opened menu can be triggered without holding Alt
735- // down, so we always show the underline. For all other widgets we only
736- // show the underlines if alt is down.
737- // Note that this is a bit hackish: it only works reliably if the
738- // widget repaints itself when alt is pressed or released. For now only
739- // the MenuBarWidget from the AppNameApplets does this.
740- if (qobject_cast<const QMenu*>(widget)) {
741- return true;
742- } else {
743- return KeyboardModifiersMonitor::instance()->keyboardModifiers() == Qt::AltModifier;
744- }
745- } else {
746- return QProxyStyle::styleHint(hint, option, widget, returnData);
747- }
748-}
749
750=== removed file 'panel/app/unity2dstyle.h'
751--- panel/app/unity2dstyle.h 2011-01-26 15:50:26 +0000
752+++ panel/app/unity2dstyle.h 1970-01-01 00:00:00 +0000
753@@ -1,44 +0,0 @@
754-/*
755- * This file is part of unity-2d
756- *
757- * Copyright 2010 Canonical Ltd.
758- *
759- * Authors:
760- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
761- *
762- * This program is free software; you can redistribute it and/or modify
763- * it under the terms of the GNU General Public License as published by
764- * the Free Software Foundation; version 3.
765- *
766- * This program is distributed in the hope that it will be useful,
767- * but WITHOUT ANY WARRANTY; without even the implied warranty of
768- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
769- * GNU General Public License for more details.
770- *
771- * You should have received a copy of the GNU General Public License
772- * along with this program. If not, see <http://www.gnu.org/licenses/>
773- */
774-
775-#ifndef UNITY2DSTYLE_H
776-#define UNITY2DSTYLE_H
777-
778-// Local
779-
780-// Qt
781-#include <QProxyStyle>
782-
783-class Unity2dStyle : public QProxyStyle
784-{
785-public:
786- Unity2dStyle();
787-
788- virtual void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0) const;
789-
790- virtual int pixelMetric(PixelMetric metric, const QStyleOption* option = 0, const QWidget* widget = 0) const;
791-
792- virtual QSize sizeFromContents(ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget = 0) const;
793-
794- virtual int styleHint(StyleHint hint, const QStyleOption* option = 0, const QWidget* widget = 0, QStyleHintReturn* returnData = 0) const;
795-};
796-
797-#endif /* UNITY2DSTYLE_H */
798
799=== modified file 'panel/applets/CMakeLists.txt'
800--- panel/applets/CMakeLists.txt 2011-06-22 08:22:14 +0000
801+++ panel/applets/CMakeLists.txt 2011-07-18 14:37:40 +0000
802@@ -1,29 +1,11 @@
803 project(uqapplets)
804
805-macro(read_pkg_variable cmake_var pkg pkg_var)
806- execute_process(
807- COMMAND pkg-config --variable=${pkg_var} ${pkg}
808- OUTPUT_VARIABLE tmp
809- )
810- # Remove trailing newline from ${tmp}
811- string(STRIP "${tmp}" ${cmake_var})
812-endmacro(read_pkg_variable)
813-
814 # Dependencies
815 include(FindPkgConfig)
816
817 pkg_check_modules(QTBAMF REQUIRED libqtbamf)
818 pkg_check_modules(DBUSMENUQT REQUIRED dbusmenu-qt)
819-pkg_check_modules(GTK REQUIRED gtk+-2.0)
820-pkg_check_modules(INDICATOR REQUIRED indicator)
821-pkg_check_modules(WNCK REQUIRED libwnck-1.0)
822-
823-find_package(X11 REQUIRED)
824-
825-# Get indicator dirs from pkgconfig
826-read_pkg_variable(INDICATOR_DIR indicator indicatordir)
827-read_pkg_variable(INDICATOR_ICONS_DIR indicator iconsdir)
828-configure_file(indicator-config.h.in indicator-config.h)
829+pkg_check_modules(PANGO REQUIRED pango)
830
831 # Sources
832 set(uqapplets_SRCS
833@@ -31,16 +13,15 @@
834 appindicator/sniitem.cpp
835 appname/appnameapplet.cpp
836 appname/menubarwidget.cpp
837- appname/registrar.cpp
838 appname/windowhelper.cpp
839 common/applet.cpp
840+ common/indicatorentrywidget.cpp
841+ common/indicatorsmanager.cpp
842+ common/indicatorwidget.cpp
843+ common/panelstyle.cpp
844 homebutton/homebuttonapplet.cpp
845 homebutton/homebutton.cpp
846- indicator/abstractindicator.cpp
847- indicator/datetimeindicator.cpp
848 indicator/indicatorapplet.cpp
849- indicator/indicatorservicemanager.cpp
850- indicator/indicator.c
851 legacytray/legacytrayapplet.cpp
852 legacytray/fdoselectionmanager.cpp
853 legacytray/fdotask.cpp
854@@ -49,10 +30,6 @@
855 legacytray/x11embedpainter.cpp
856 )
857
858-qt4_add_dbus_adaptor(uqapplets_SRCS appname/com.canonical.AppMenu.Registrar.xml
859- registrar.h Registrar
860- )
861-
862 qt4_automoc(${uqapplets_SRCS})
863
864 # Build
865@@ -62,13 +39,15 @@
866 ${CMAKE_CURRENT_SOURCE_DIR}/common
867 ${CMAKE_CURRENT_SOURCE_DIR}/homebutton
868 ${CMAKE_CURRENT_SOURCE_DIR}/indicator
869+ ${CMAKE_CURRENT_SOURCE_DIR}/unitycore
870 ${QTBAMF_INCLUDE_DIRS}
871 ${DBUSMENUQT_INCLUDE_DIRS}
872 ${GTK_INCLUDE_DIRS}
873- ${INDICATOR_INCLUDE_DIRS}
874 ${WNCK_INCLUDE_DIRS}
875 ${CMAKE_CURRENT_BINARY_DIR}
876 ${X11_INCLUDE_DIR}
877+ ${UNITYCORE_INCLUDE_DIRS}
878+ ${PANGO_INCLUDE_DIRS}
879 ${libunity-2d-private_SOURCE_DIR}/src
880 )
881
882@@ -80,12 +59,13 @@
883 ${DBUSMENUQT_LDFLAGS}
884 ${QTBAMF_LDFLAGS}
885 ${GTK_LDFLAGS}
886- ${INDICATOR_LDFLAGS}
887 ${WNCK_LDFLAGS}
888 ${X11_LIBRARIES}
889 ${X11_Xrender_LIB}
890 ${X11_Xcomposite_LIB}
891 ${X11_Xdamage_LIB}
892 ${X11_Xfixes_LIB}
893+ ${UNITYCORE_LDFLAGS}
894+ ${PANGO_LDFLAGS}
895 unity-2d-private
896 )
897
898=== modified file 'panel/applets/appname/appnameapplet.cpp'
899--- panel/applets/appname/appnameapplet.cpp 2011-06-21 16:03:12 +0000
900+++ panel/applets/appname/appnameapplet.cpp 2011-07-18 14:37:40 +0000
901@@ -200,10 +200,10 @@
902 q, SLOT(updateWidgets()));
903 }
904
905- void setupMenuBarWidget()
906+ void setupMenuBarWidget(IndicatorsManager* manager)
907 {
908- m_menuBarWidget = new MenuBarWidget(0 /* Window menu */);
909- QObject::connect(m_menuBarWidget, SIGNAL(menuBarClosed()),
910+ m_menuBarWidget = new MenuBarWidget(manager);
911+ QObject::connect(m_menuBarWidget, SIGNAL(isOpenedChanged()),
912 q, SLOT(updateWidgets()));
913 QObject::connect(m_menuBarWidget, SIGNAL(isEmptyChanged()),
914 q, SLOT(updateWidgets()));
915@@ -216,21 +216,16 @@
916 }
917 };
918
919-AppNameApplet::AppNameApplet()
920+AppNameApplet::AppNameApplet(IndicatorsManager* indicatorsManager)
921 : d(new AppNameAppletPrivate)
922 {
923 d->q = this;
924 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);
925
926- QPalette palette;
927- palette.setColor(QPalette::WindowText, Qt::white);
928- palette.setColor(QPalette::ButtonText, Qt::white);
929- setPalette(palette);
930-
931 d->setupWindowHelper();
932 d->setupLabel();
933 d->setupWindowButtonWidget();
934- d->setupMenuBarWidget();
935+ d->setupMenuBarWidget(indicatorsManager);
936 d->setupKeyboardModifiersMonitor();
937
938 QHBoxLayout* layout = new QHBoxLayout(this);
939
940=== modified file 'panel/applets/appname/appnameapplet.h'
941--- panel/applets/appname/appnameapplet.h 2011-06-06 09:06:55 +0000
942+++ panel/applets/appname/appnameapplet.h 2011-07-18 14:37:40 +0000
943@@ -29,6 +29,8 @@
944
945 class QEvent;
946
947+class IndicatorsManager;
948+
949 namespace Unity2d
950 {
951
952@@ -37,7 +39,7 @@
953 {
954 Q_OBJECT
955 public:
956- AppNameApplet();
957+ AppNameApplet(IndicatorsManager*);
958 ~AppNameApplet();
959
960 protected:
961
962=== removed file 'panel/applets/appname/com.canonical.AppMenu.Registrar.xml'
963--- panel/applets/appname/com.canonical.AppMenu.Registrar.xml 2011-02-10 01:10:19 +0000
964+++ panel/applets/appname/com.canonical.AppMenu.Registrar.xml 1970-01-01 00:00:00 +0000
965@@ -1,82 +0,0 @@
966-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
967-<node xmlns:dox="http://www.ayatana.org/dbus/dox.dtd">
968- <dox:d><![CDATA[
969- @mainpage
970-  
971- An interface to register menus that are associated with a window in an application.  The
972- main interface is docuemented here: @ref com::canonical::AppMenu::Registrar.
973-     
974- The actual menus are transported using the dbusmenu protocol which is available
975- here: @ref com::canonical::dbusmenu.
976- ]]></dox:d>
977- <interface name="com.canonical.AppMenu.Registrar" xmlns:dox="http://www.ayatana.org/dbus/dox.dtd">
978- <dox:d>
979- An interface to register a menu from an application's window to be displayed in another
980- window.  This manages that association between XWindow Window IDs and the dbus
981- address and object that provides the menu using the dbusmenu dbus interface.
982- </dox:d>
983- <method name="RegisterWindow">
984- <dox:d><![CDATA[
985- Associates a dbusmenu with a window
986-      
987- /note this method assumes that the connection from the caller is the DBus connection
988- to use for the object.  Applications that use multiple DBus connections will need to
989- ensure this method is called with the same connection that implmenets the object.
990- ]]></dox:d>
991- <arg name="windowId" type="u" direction="in">
992- <dox:d>The XWindow ID of the window</dox:d>
993- </arg>
994- <arg name="menuObjectPath" type="o" direction="in">
995- <dox:d>The object on the dbus interface implementing the dbusmenu interface</dox:d>
996- </arg>
997- </method>
998- <method name="UnregisterWindow">
999- <dox:d>
1000- A method to allow removing a window from the database. Windows will also be removed
1001- when the client drops off DBus so this is not required. It is polite though. And
1002- important for testing.
1003- </dox:d>
1004- <arg name="windowId" type="u" direction="in">
1005- <dox:d>The XWindow ID of the window</dox:d>
1006- </arg>
1007- </method>
1008- <method name="GetMenuForWindow">
1009- <dox:d>Gets the registered menu for a given window ID.</dox:d>
1010- <arg name="windowId" type="u" direction="in">
1011- <dox:d>The XWindow ID of the window to get</dox:d>
1012- </arg>
1013- <arg name="service" type="s" direction="out">
1014- <dox:d>The address of the connection on DBus (e.g. :1.23 or org.example.service)</dox:d>
1015- </arg>
1016- <arg name="menuObjectPath" type="o" direction="out">
1017- <dox:d>The path to the object which implements the com.canonical.dbusmenu interface.</dox:d>
1018- </arg>
1019- </method>
1020- <method name="GetMenus">
1021- <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MenuInfoList"/>
1022- <dox:d>Gets the information on all menus that the registrar knows about. This
1023- is useful for debugging or bringing up a new renderer.</dox:d>
1024- <arg name="menus" type="a(uso)" direction="out">
1025- <dox:d>An array of structures containing the same parameters as @GetMenuForWindow. Window ID, Service and ObjectPath.</dox:d>
1026- </arg>
1027- </method>
1028- <signal name="WindowRegistered">
1029- <dox:d>Signals when the registrar gets a new menu registered</dox:d>
1030- <arg name="windowId" type="u" direction="out">
1031- <dox:d>The XWindow ID of the window</dox:d>
1032- </arg>
1033- <arg name="service" type="s" direction="out">
1034- <dox:d>The address of the connection on DBus (e.g. :1.23 or org.example.service)</dox:d>
1035- </arg>
1036- <arg name="menuObjectPath" type="o" direction="out">
1037- <dox:d>The path to the object which implements the com.canonical.dbusmenu interface.</dox:d>
1038- </arg>
1039- </signal>
1040- <signal name="WindowUnregistered">
1041- <dox:d>Signals when the registrar removes a menu registration</dox:d>
1042- <arg name="windowId" type="u" direction="out">
1043- <dox:d>The XWindow ID of the window</dox:d>
1044- </arg>
1045- </signal>
1046- </interface>
1047-</node>
1048
1049=== modified file 'panel/applets/appname/menubarwidget.cpp'
1050--- panel/applets/appname/menubarwidget.cpp 2011-07-13 09:00:33 +0000
1051+++ panel/applets/appname/menubarwidget.cpp 2011-07-18 14:37:40 +0000
1052@@ -20,299 +20,99 @@
1053 */
1054
1055 // Self
1056-#include "menubarwidget.h"
1057+#include <menubarwidget.h>
1058
1059 // Local
1060-#include "config.h"
1061-#include "debug_p.h"
1062-#include "keyboardmodifiersmonitor.h"
1063-#include "registrar.h"
1064-
1065-// dbusmenu-qt
1066-#include <dbusmenuimporter.h>
1067-
1068-// bamf
1069-#include <bamf-matcher.h>
1070-#include <bamf-window.h>
1071+#include <debug_p.h>
1072+#include <indicatorentrywidget.h>
1073+#include <indicatorsmanager.h>
1074
1075 // Qt
1076-#include <QActionEvent>
1077 #include <QHBoxLayout>
1078-#include <QLabel>
1079-#include <QMenuBar>
1080-#include <QTimer>
1081-
1082-class MyDBusMenuImporter : public DBusMenuImporter
1083-{
1084-public:
1085- MyDBusMenuImporter(const QString &service, const QString &path, QObject *parent)
1086- : DBusMenuImporter(service, path, parent)
1087- , m_service(service)
1088- , m_path(path)
1089- {}
1090-
1091- QString service() const { return m_service; }
1092- QString path() const { return m_path; }
1093-
1094-private:
1095- QString m_service;
1096- QString m_path;
1097-};
1098-
1099-MenuBarWidget::MenuBarWidget(QMenu* windowMenu, QWidget* parent)
1100+
1101+static const int MENU_ITEM_PADDING = 6;
1102+
1103+MenuBarWidget::MenuBarWidget(IndicatorsManager* indicatorsManager, QWidget* parent)
1104 : QWidget(parent)
1105-, m_windowMenu(windowMenu)
1106-{
1107- m_activeWinId = 0;
1108- setupRegistrar();
1109- setupMenuBar();
1110-
1111- connect(&BamfMatcher::get_default(), SIGNAL(ActiveWindowChanged(BamfWindow*, BamfWindow*)),
1112- SLOT(slotActiveWindowChanged(BamfWindow*, BamfWindow*)));
1113- /* Work around a bug in BAMF: the ActiveWindowChanged signal is not emitted
1114- for some windows that open maximized. This is for example the case of the
1115- LibreOffice startcenter. */
1116- connect(&BamfMatcher::get_default(), SIGNAL(ViewOpened(BamfView*)),
1117- SLOT(slotViewOpened()));
1118- updateActiveWinId(BamfMatcher::get_default().active_window());
1119-}
1120-
1121-void MenuBarWidget::setupRegistrar()
1122-{
1123- m_registrar = Registrar::instance();
1124- if (!m_registrar->connectToBus()) {
1125- UQ_WARNING << "could not connect registrar to DBus";
1126- }
1127-
1128- connect(m_registrar, SIGNAL(WindowRegistered(WId, const QString&, const QDBusObjectPath&)),
1129- SLOT(slotWindowRegistered(WId, const QString&, const QDBusObjectPath&)));
1130- connect(m_registrar, SIGNAL(WindowUnregistered(WId)),
1131- SLOT(slotWindowUnregistered(WId)));
1132-}
1133-
1134-void MenuBarWidget::setupMenuBar()
1135-{
1136- m_menuBar = new QMenuBar;
1137- new MenuBarClosedHelper(this);
1138-
1139- QHBoxLayout* layout = new QHBoxLayout(this);
1140- layout->setMargin(0);
1141- layout->setSpacing(0);
1142- layout->addWidget(m_menuBar);
1143- m_menuBar->setNativeMenuBar(false);
1144-
1145- m_updateMenuBarTimer = new QTimer(this);
1146- m_updateMenuBarTimer->setSingleShot(true);
1147- m_updateMenuBarTimer->setInterval(0);
1148- connect(m_updateMenuBarTimer, SIGNAL(timeout()),
1149- SLOT(updateMenuBar()));
1150-
1151- // Repaint the menubar when modifiers change so that the shortcut underline
1152- // is drawn or not
1153- connect(KeyboardModifiersMonitor::instance(), SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)),
1154- m_menuBar, SLOT(update()));
1155-}
1156-
1157-void MenuBarWidget::slotActiveWindowChanged(BamfWindow* /*former*/, BamfWindow* current)
1158-{
1159- if (current) {
1160- updateActiveWinId(current);
1161- }
1162-}
1163-
1164-void MenuBarWidget::slotViewOpened()
1165-{
1166- BamfWindow* active = BamfMatcher::get_default().active_window();
1167- if (active != NULL) {
1168- if (active->xid() != m_activeWinId) {
1169- /* This shouldn’t be needed as BAMF should have emitted the
1170- ActiveWindowChanged signal, but it sometimes doesn’t (e.g. when
1171- LibreOffice startcenter starts automatically maximized). */
1172- updateActiveWinId(active);
1173- }
1174- }
1175-}
1176-
1177-void MenuBarWidget::slotWindowRegistered(WId wid, const QString& service, const QDBusObjectPath& menuObjectPath)
1178-{
1179- MyDBusMenuImporter* importer = new MyDBusMenuImporter(service, menuObjectPath.path(), this);
1180- delete m_importers.take(wid);
1181- m_importers.insert(wid, importer);
1182- connect(importer, SIGNAL(menuUpdated()), SLOT(slotMenuUpdated()));
1183- connect(importer, SIGNAL(actionActivationRequested(QAction*)), SLOT(slotActionActivationRequested(QAction*)));
1184- QMetaObject::invokeMethod(importer, "updateMenu", Qt::QueuedConnection);
1185-}
1186-
1187-void MenuBarWidget::slotWindowUnregistered(WId wid)
1188-{
1189- MyDBusMenuImporter* importer = m_importers.take(wid);
1190- if (importer) {
1191- importer->deleteLater();
1192- }
1193- if (wid == m_activeWinId) {
1194- m_activeWinId = 0;
1195- updateMenuBar();
1196- }
1197-}
1198-
1199-void MenuBarWidget::slotMenuUpdated()
1200-{
1201- DBusMenuImporter* importer = static_cast<DBusMenuImporter*>(sender());
1202-
1203- if (m_importers.value(m_activeWinId) == importer) {
1204- updateMenuBar();
1205- }
1206-}
1207-
1208-void MenuBarWidget::slotActionActivationRequested(QAction* action)
1209-{
1210- DBusMenuImporter* importer = static_cast<DBusMenuImporter*>(sender());
1211-
1212- if (m_importers.value(m_activeWinId) == importer) {
1213- m_menuBar->setActiveAction(action);
1214- }
1215-}
1216-
1217-QMenu* MenuBarWidget::menuForWinId(WId wid) const
1218-{
1219- MyDBusMenuImporter* importer = m_importers.value(wid);
1220- return importer ? importer->menu() : 0;
1221-}
1222-
1223-void MenuBarWidget::updateActiveWinId(BamfWindow* bamfWindow)
1224-{
1225- WId id = bamfWindow ? bamfWindow->xid() : 0;
1226- if (id == m_activeWinId) {
1227- return;
1228- }
1229- if (id == window()->winId()) {
1230- // Do not update id if the active window is the one hosting this applet
1231- return;
1232- }
1233- m_activeWinId = id;
1234- updateMenuBar();
1235-}
1236-
1237-void MenuBarWidget::updateMenuBar()
1238-{
1239- WId winId = m_activeWinId;
1240- QMenu* menu = menuForWinId(winId);
1241-
1242- if (!menu) {
1243- if (winId) {
1244- menu = m_windowMenu;
1245- } else {
1246- // No active window, show a desktop menubar
1247- // FIXME: Empty menu
1248- /*
1249- menu = mEmptyMenu;
1250- */
1251- }
1252- }
1253-
1254- m_menuBar->clear();
1255- // FIXME: Empty menu
1256- if (!menu) {
1257- return;
1258- }
1259- menu->installEventFilter(this);
1260- Q_FOREACH(QAction* action, menu->actions()) {
1261- if (action->isSeparator()) {
1262- continue;
1263- }
1264- m_menuBar->addAction(action);
1265- }
1266-}
1267-
1268-bool MenuBarWidget::eventFilter(QObject* object, QEvent* event)
1269-{
1270- switch (event->type()) {
1271- case QEvent::ActionAdded:
1272- case QEvent::ActionRemoved:
1273- case QEvent::ActionChanged:
1274- m_updateMenuBarTimer->start();
1275- break;
1276- default:
1277- break;
1278- }
1279- return false;
1280+, m_indicatorsManager(indicatorsManager)
1281+, m_layout(new QHBoxLayout(this))
1282+, m_isEmpty(true)
1283+, m_isOpened(false)
1284+{
1285+ m_layout->setMargin(0);
1286+ m_layout->setSpacing(0);
1287+ indicatorsManager->indicators()->on_object_added.connect(
1288+ sigc::mem_fun(this, &MenuBarWidget::onObjectAdded)
1289+ );
1290+ indicatorsManager->indicators()->on_entry_activated.connect(
1291+ sigc::mem_fun(this, &MenuBarWidget::onEntryActivated)
1292+ );
1293+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
1294+ m_layout->addStretch();
1295 }
1296
1297 bool MenuBarWidget::isEmpty() const
1298 {
1299- return m_menuBar->actions().isEmpty();
1300+ return m_isEmpty;
1301 }
1302
1303 bool MenuBarWidget::isOpened() const
1304 {
1305- return m_menuBar->activeAction();
1306-}
1307-
1308-// MenuBarClosedHelper ----------------------------------------
1309-MenuBarClosedHelper::MenuBarClosedHelper(MenuBarWidget* widget)
1310-: QObject(widget)
1311-, m_widget(widget)
1312-{
1313- widget->m_menuBar->installEventFilter(this);
1314-}
1315-
1316-bool MenuBarClosedHelper::eventFilter(QObject* object, QEvent* event)
1317-{
1318- if (object == m_widget->m_menuBar) {
1319- switch (event->type()) {
1320- case QEvent::ActionAdded:
1321- case QEvent::ActionRemoved:
1322- case QEvent::ActionChanged:
1323- menuBarActionEvent(static_cast<QActionEvent*>(event));
1324- break;
1325- default:
1326- break;
1327- }
1328- } else {
1329- // Top-level menus
1330- if (event->type() == QEvent::Hide) {
1331- // menu hide themselves when the menubar is closed but also when
1332- // one goes from one menu to another. The way to know this is to
1333- // check the value of QMenuBar::activeAction(), but at this point
1334- // it has not been updated yet, so we check in a delayed method.
1335- QMetaObject::invokeMethod(this, "emitMenuBarClosed", Qt::QueuedConnection);
1336- }
1337- }
1338- return false;
1339-}
1340-
1341-void MenuBarClosedHelper::emitMenuBarClosed()
1342-{
1343- if (!m_widget->m_menuBar->activeAction()) {
1344- QMetaObject::invokeMethod(m_widget, "menuBarClosed");
1345- }
1346-}
1347-
1348-void MenuBarClosedHelper::menuBarActionEvent(QActionEvent* event)
1349-{
1350- QMenu* menu = event->action()->menu();
1351- if (menu) {
1352- // Install/remove event filters on top level menus so that know when
1353- // they hide themselves and can emit menuBarClosed()
1354- switch (event->type()) {
1355- case QEvent::ActionAdded:
1356- case QEvent::ActionChanged:
1357- menu->installEventFilter(this);
1358- break;
1359- case QEvent::ActionRemoved:
1360- menu->removeEventFilter(this);
1361- break;
1362- default:
1363- break;
1364- }
1365- }
1366-
1367- // Emit isEmptyChanged() if necessary
1368- QList<QAction*> actions = m_widget->m_menuBar->actions();
1369- if (event->type() == QEvent::ActionAdded && actions.count() == 1) {
1370- QMetaObject::invokeMethod(m_widget, "isEmptyChanged");
1371- } else if (event->type() == QEvent::ActionRemoved && actions.isEmpty()) {
1372- QMetaObject::invokeMethod(m_widget, "isEmptyChanged");
1373+ // FIXME
1374+ return m_isOpened;
1375+}
1376+
1377+void MenuBarWidget::onObjectAdded(const unity::indicator::Indicator::Ptr& indicator)
1378+{
1379+ QString name = QString::fromStdString(indicator->name());
1380+ if (name == "libappmenu.so") {
1381+ indicator->on_entry_added.connect(sigc::mem_fun(this, &MenuBarWidget::onEntryAdded));
1382+ }
1383+}
1384+
1385+void MenuBarWidget::onEntryAdded(const unity::indicator::Entry::Ptr& entry)
1386+{
1387+ IndicatorEntryWidget* widget = new IndicatorEntryWidget(entry);
1388+ widget->setPadding(MENU_ITEM_PADDING);
1389+ connect(widget, SIGNAL(isEmptyChanged()), SLOT(updateIsEmpty()));
1390+
1391+ m_widgetList.append(widget);
1392+ m_indicatorsManager->addIndicatorEntryWidget(widget);
1393+
1394+ // Insert *before* stretch
1395+ m_layout->insertWidget(m_layout->count() - 1, widget);
1396+}
1397+
1398+void MenuBarWidget::updateIsEmpty()
1399+{
1400+ bool empty = true;
1401+ Q_FOREACH(IndicatorEntryWidget* widget, m_widgetList) {
1402+ if (!widget->isEmpty()) {
1403+ empty = false;
1404+ break;
1405+ }
1406+ }
1407+ if (m_isEmpty != empty) {
1408+ m_isEmpty = empty;
1409+ isEmptyChanged();
1410+ }
1411+}
1412+
1413+void MenuBarWidget::onEntryActivated(const std::string& id)
1414+{
1415+ bool isOpened = false;
1416+ if (!id.empty()) {
1417+ // We only cares about menubar entries
1418+ Q_FOREACH(IndicatorEntryWidget* widget, m_widgetList) {
1419+ if (widget->entry()->id() == id) {
1420+ isOpened = true;
1421+ break;
1422+ }
1423+ }
1424+ }
1425+ if (m_isOpened != isOpened) {
1426+ m_isOpened = isOpened;
1427+ isOpenedChanged();
1428 }
1429 }
1430
1431
1432=== modified file 'panel/applets/appname/menubarwidget.h'
1433--- panel/applets/appname/menubarwidget.h 2011-04-13 21:17:38 +0000
1434+++ panel/applets/appname/menubarwidget.h 2011-07-18 14:37:40 +0000
1435@@ -23,86 +23,44 @@
1436 #define MENUBARWIDGET_H
1437
1438 // Qt
1439-#include <QHash>
1440 #include <QWidget>
1441
1442-class BamfWindow;
1443-
1444-class QActionEvent;
1445-class QDBusObjectPath;
1446-class QMenu;
1447-class QMenuBar;
1448-class QTimer;
1449-
1450-class MyDBusMenuImporter;
1451-class Registrar;
1452-
1453-typedef QHash<WId, MyDBusMenuImporter*> ImporterForWId;
1454-
1455-class MenuBarWidget;
1456-
1457-/**
1458- * An helper class which monitors the menubar and emits MenuBarWidget::menuBarClosed()
1459- * when necessary
1460- */
1461-class MenuBarClosedHelper : public QObject
1462-{
1463-Q_OBJECT
1464-public:
1465- MenuBarClosedHelper(MenuBarWidget*);
1466-
1467-protected:
1468- bool eventFilter(QObject*, QEvent*); //reimp
1469-
1470-private Q_SLOTS:
1471- void emitMenuBarClosed();
1472-
1473-private:
1474- MenuBarWidget* m_widget;
1475- void menuBarActionEvent(QActionEvent*);
1476-};
1477-
1478-class MenuBarWidget : public QWidget
1479-{
1480-Q_OBJECT
1481-public:
1482- MenuBarWidget(QMenu* windowMenu, QWidget* parent = 0);
1483+// libunity-core
1484+#include <UnityCore/UnityCore.h>
1485+
1486+class QHBoxLayout;
1487+
1488+class IndicatorEntryWidget;
1489+class IndicatorsManager;
1490+
1491+class MenuBarWidget : public QWidget, public sigc::trackable
1492+{
1493+Q_OBJECT
1494+public:
1495+ MenuBarWidget(IndicatorsManager*, QWidget* parent = 0);
1496
1497 bool isEmpty() const;
1498 bool isOpened() const;
1499
1500 Q_SIGNALS:
1501- void menuBarClosed();
1502+ void isOpenedChanged();
1503 void isEmptyChanged();
1504
1505-protected:
1506- bool eventFilter(QObject*, QEvent*); // reimp
1507-
1508 private Q_SLOTS:
1509- void slotActiveWindowChanged(BamfWindow*, BamfWindow*);
1510- void slotViewOpened();
1511- void slotWindowRegistered(WId, const QString& service, const QDBusObjectPath& menuObjectPath);
1512- void slotWindowUnregistered(WId);
1513- void slotMenuUpdated();
1514- void slotActionActivationRequested(QAction* action);
1515- void updateMenuBar();
1516+ void updateIsEmpty();
1517
1518 private:
1519 Q_DISABLE_COPY(MenuBarWidget)
1520
1521- QMenuBar* m_menuBar;
1522- Registrar* m_registrar;
1523- ImporterForWId m_importers;
1524- WId m_activeWinId;
1525- QMenu* m_windowMenu;
1526- QTimer* m_updateMenuBarTimer;
1527-
1528- void setupRegistrar();
1529- void setupMenuBar();
1530- QMenu* menuForWinId(WId) const;
1531- void updateActiveWinId(BamfWindow*);
1532-
1533- friend class MenuBarClosedHelper;
1534+ IndicatorsManager* m_indicatorsManager;
1535+ QHBoxLayout* m_layout;
1536+ bool m_isEmpty;
1537+ bool m_isOpened;
1538+ QList<IndicatorEntryWidget*> m_widgetList;
1539+
1540+ void onObjectAdded(const unity::indicator::Indicator::Ptr&);
1541+ void onEntryAdded(const unity::indicator::Entry::Ptr&);
1542+ void onEntryActivated(const std::string&);
1543 };
1544
1545 #endif /* MENUBARWIDGET_H */
1546
1547=== removed file 'panel/applets/appname/registrar.cpp'
1548--- panel/applets/appname/registrar.cpp 2011-04-04 16:46:14 +0000
1549+++ panel/applets/appname/registrar.cpp 1970-01-01 00:00:00 +0000
1550@@ -1,138 +0,0 @@
1551-/*
1552- * Plasma applet to display application window menus
1553- *
1554- * Copyright 2010 Canonical Ltd.
1555- *
1556- * Authors:
1557- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
1558- *
1559- * This program is free software; you can redistribute it and/or modify
1560- * it under the terms of the GNU General Public License as published by
1561- * the Free Software Foundation; version 3.
1562- *
1563- * This program is distributed in the hope that it will be useful,
1564- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1565- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1566- * GNU General Public License for more details.
1567- *
1568- * You should have received a copy of the GNU General Public License
1569- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1570- */
1571-
1572-// Self
1573-#include "registrar.h"
1574-
1575-// Qt
1576-#include <QApplication>
1577-#include <QDBusMessage>
1578-#include <QDBusObjectPath>
1579-#include <QDBusServiceWatcher>
1580-
1581-// Local
1582-#include "registraradaptor.h"
1583-
1584-static const char* DBUS_SERVICE = "com.canonical.AppMenu.Registrar";
1585-static const char* DBUS_OBJECT_PATH = "/com/canonical/AppMenu/Registrar";
1586-
1587-// Marshalling code for MenuInfo
1588-QDBusArgument& operator<<(QDBusArgument& argument, const MenuInfo& info)
1589-{
1590- argument.beginStructure();
1591- argument << info.winId << info.service << info.path;
1592- argument.endStructure();
1593- return argument;
1594-}
1595-
1596-const QDBusArgument& operator>>(const QDBusArgument& argument, MenuInfo& info)
1597-{
1598- argument.beginStructure();
1599- argument >> info.winId >> info.service >> info.path;
1600- argument.endStructure();
1601- return argument;
1602-}
1603-
1604-Registrar::Registrar()
1605-: QObject()
1606-, mServiceWatcher(new QDBusServiceWatcher(this))
1607-{
1608- qDBusRegisterMetaType<MenuInfo>();
1609- qDBusRegisterMetaType<MenuInfoList>();
1610- mServiceWatcher->setConnection(QDBusConnection::sessionBus());
1611- mServiceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
1612- connect(mServiceWatcher, SIGNAL(serviceUnregistered(const QString&)), SLOT(slotServiceUnregistered(const QString&)));
1613-}
1614-
1615-Registrar::~Registrar()
1616-{
1617- QDBusConnection::sessionBus().unregisterService(mService);
1618-}
1619-
1620-Registrar* Registrar::instance()
1621-{
1622- static Registrar singleton;
1623- return &singleton;
1624-}
1625-
1626-bool Registrar::connectToBus(const QString& _service, const QString& _path)
1627-{
1628- mService = _service.isEmpty() ? DBUS_SERVICE : _service;
1629- QString path = _path.isEmpty() ? DBUS_OBJECT_PATH : _path;
1630-
1631- bool ok = QDBusConnection::sessionBus().registerService(mService);
1632- if (!ok) {
1633- return false;
1634- }
1635- new RegistrarAdaptor(this);
1636- QDBusConnection::sessionBus().registerObject(path, this);
1637-
1638- return true;
1639-}
1640-
1641-void Registrar::RegisterWindow(WId wid, const QDBusObjectPath& menuObjectPath)
1642-{
1643- MenuInfo info;
1644- info.winId = wid;
1645- info.service = message().service();
1646- info.path = menuObjectPath;
1647- mDb.insert(wid, info);
1648- mServiceWatcher->addWatchedService(info.service);
1649- WindowRegistered(wid, info.service, info.path);
1650-}
1651-
1652-void Registrar::UnregisterWindow(WId wid)
1653-{
1654- mDb.remove(wid);
1655- WindowUnregistered(wid);
1656-}
1657-
1658-QString Registrar::GetMenuForWindow(WId winId, QDBusObjectPath& menuObjectPath)
1659-{
1660- MenuInfo info = mDb.value(winId);
1661- QString service = info.service;
1662- menuObjectPath = info.path;
1663- return service;
1664-}
1665-
1666-MenuInfoList Registrar::GetMenus()
1667-{
1668- return mDb.values();
1669-}
1670-
1671-void Registrar::slotServiceUnregistered(const QString& service)
1672-{
1673- MenuInfoDb::Iterator
1674- it = mDb.begin(),
1675- end = mDb.end();
1676- for (;it != end;) {
1677- if (it.value().service == service) {
1678- WId id = it.key();
1679- it = mDb.erase(it);
1680- WindowUnregistered(id);
1681- } else {
1682- ++it;
1683- }
1684- }
1685- mServiceWatcher->removeWatchedService(service);
1686-}
1687-
1688-#include "registrar.moc"
1689
1690=== removed file 'panel/applets/appname/registrar.h'
1691--- panel/applets/appname/registrar.h 2011-04-04 16:47:28 +0000
1692+++ panel/applets/appname/registrar.h 1970-01-01 00:00:00 +0000
1693@@ -1,85 +0,0 @@
1694-/*
1695- * Plasma applet to display application window menus
1696- *
1697- * Copyright 2010 Canonical Ltd.
1698- *
1699- * Authors:
1700- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
1701- *
1702- * This program is free software; you can redistribute it and/or modify
1703- * it under the terms of the GNU General Public License as published by
1704- * the Free Software Foundation; version 3.
1705- *
1706- * This program is distributed in the hope that it will be useful,
1707- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1708- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1709- * GNU General Public License for more details.
1710- *
1711- * You should have received a copy of the GNU General Public License
1712- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1713- */
1714-
1715-#ifndef REGISTRAR_H
1716-#define REGISTRAR_H
1717-
1718-// Qt
1719-#include <QDBusContext>
1720-#include <QDBusObjectPath>
1721-#include <QObject>
1722-#include <QWidget> // For WId
1723-
1724-class QDBusObjectPath;
1725-class QDBusServiceWatcher;
1726-class QMenu;
1727-
1728-struct MenuInfo
1729-{
1730- MenuInfo()
1731- : winId(0)
1732- , path("/")
1733- {}
1734-
1735- uint winId;
1736- QString service;
1737- QDBusObjectPath path;
1738-};
1739-Q_DECLARE_METATYPE(MenuInfo)
1740-
1741-typedef QList<MenuInfo> MenuInfoList;
1742-Q_DECLARE_METATYPE(MenuInfoList)
1743-
1744-class Registrar : public QObject, protected QDBusContext
1745-{
1746- Q_OBJECT
1747-
1748-public:
1749- /* The registrar is a singleton shared between all instances of MenuBarWidget. */
1750- static Registrar* instance();
1751-
1752- bool connectToBus(const QString& service = QString(), const QString& objectPath = QString());
1753-
1754-Q_SIGNALS:
1755- void WindowRegistered(WId wid, const QString& service, const QDBusObjectPath&);
1756- void WindowUnregistered(WId wid);
1757-
1758-public Q_SLOTS:
1759- Q_NOREPLY void RegisterWindow(WId wid, const QDBusObjectPath& menuObjectPath);
1760- Q_NOREPLY void UnregisterWindow(WId wid);
1761- QString GetMenuForWindow(WId wid, QDBusObjectPath& menuObjectPath);
1762- MenuInfoList GetMenus();
1763-
1764-private Q_SLOTS:
1765- void slotServiceUnregistered(const QString& service);
1766-
1767-private:
1768- Registrar();
1769- Q_DISABLE_COPY(Registrar)
1770- ~Registrar();
1771-
1772- QDBusServiceWatcher* mServiceWatcher;
1773- typedef QHash<WId, MenuInfo> MenuInfoDb;
1774- MenuInfoDb mDb;
1775- QString mService;
1776-};
1777-
1778-#endif /* REGISTRAR_H */
1779
1780=== added file 'panel/applets/common/fakecairo.h'
1781--- panel/applets/common/fakecairo.h 1970-01-01 00:00:00 +0000
1782+++ panel/applets/common/fakecairo.h 2011-07-18 14:37:40 +0000
1783@@ -0,0 +1,125 @@
1784+/*
1785+ * This file is part of unity-2d
1786+ *
1787+ * Copyright 2011 Canonical Ltd.
1788+ *
1789+ * Authors:
1790+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
1791+ *
1792+ * This program is free software; you can redistribute it and/or modify
1793+ * it under the terms of the GNU General Public License as published by
1794+ * the Free Software Foundation; version 3.
1795+ *
1796+ * This program is distributed in the hope that it will be useful,
1797+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1798+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1799+ * GNU General Public License for more details.
1800+ *
1801+ * You should have received a copy of the GNU General Public License
1802+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1803+ */
1804+#ifndef FAKECAIRO_H
1805+#define FAKECAIRO_H
1806+
1807+// NuxCore
1808+#include <NuxCore/Color.h>
1809+
1810+// Qt
1811+#include <QPainter>
1812+#include <QPainterPath>
1813+
1814+/*
1815+ * This module attempts to fake Cairo calls using QPainter, making it easier to
1816+ * port Cairo paint operations to Qt
1817+ */
1818+struct fcairo_t
1819+{
1820+ fcairo_t(QPainter* _painter)
1821+ : painter(_painter)
1822+ {
1823+ painter->save();
1824+ }
1825+
1826+ ~fcairo_t()
1827+ {
1828+ painter->restore();
1829+ }
1830+
1831+ QPainter* painter;
1832+ QPainterPath path;
1833+};
1834+
1835+inline void fcairo_arc(fcairo_t& cr, qreal xc, qreal yc, qreal radius, qreal angle1, qreal angle2)
1836+{
1837+ QRectF rect(xc - radius, yc - radius, radius * 2, radius * 2);
1838+
1839+ while (angle2 < angle1) {
1840+ angle2 += 2 * M_PI;
1841+ }
1842+
1843+ qreal start = (2. - angle1 / M_PI) * 180;
1844+ qreal stop = (2. - angle2 / M_PI) * 180;
1845+ cr.path.arcTo(rect, start, stop - start);
1846+}
1847+
1848+inline void fcairo_move_to(fcairo_t& cr, qreal x, qreal y)
1849+{
1850+ cr.path.moveTo(x, y);
1851+}
1852+
1853+inline void fcairo_line_to(fcairo_t& cr, qreal x, qreal y)
1854+{
1855+ cr.path.lineTo(x, y);
1856+}
1857+
1858+inline void fcairo_fill_preserve(fcairo_t& cr)
1859+{
1860+ cr.painter->fillPath(cr.path, cr.painter->brush());
1861+}
1862+
1863+inline void fcairo_stroke(fcairo_t& cr)
1864+{
1865+ QPen pen(cr.painter->brush().color(), 1);
1866+ cr.painter->strokePath(cr.path, pen);
1867+ cr.path = QPainterPath();
1868+}
1869+
1870+typedef QGradient fcairo_pattern_t;
1871+
1872+inline fcairo_pattern_t* fcairo_pattern_create_linear (qreal x1, qreal y1, qreal x2, qreal y2)
1873+{
1874+ return new QLinearGradient(x1, y1, x2, y2);
1875+}
1876+
1877+inline void fcairo_pattern_destroy(fcairo_pattern_t* pattern)
1878+{
1879+ delete pattern;
1880+}
1881+
1882+inline void fcairo_pattern_add_color_stop_rgba(fcairo_pattern_t* pattern, qreal offset, qreal r, qreal g, qreal b, qreal a)
1883+{
1884+ pattern->setColorAt(offset, QColor::fromRgbF(r, g, b, a));
1885+}
1886+
1887+inline void fcairo_set_source(fcairo_t& cr, fcairo_pattern_t* pattern)
1888+{
1889+ cr.painter->setPen(Qt::NoPen);
1890+ cr.painter->setBrush(*pattern);
1891+}
1892+
1893+inline void fcairo_set_source_rgb(fcairo_t& cr, qreal r, qreal g, qreal b)
1894+{
1895+ cr.painter->setBrush(QColor::fromRgbF(r, g, b));
1896+}
1897+
1898+inline nux::color::Color nuxColorFromQColor(const QColor& qColor)
1899+{
1900+ nux::color::Color color;
1901+ color.red = qColor.redF();
1902+ color.green = qColor.greenF();
1903+ color.blue = qColor.blueF();
1904+ color.alpha = qColor.alphaF();
1905+ return color;
1906+}
1907+
1908+#endif /* FAKECAIRO_H */
1909
1910=== added file 'panel/applets/common/indicatorentrywidget.cpp'
1911--- panel/applets/common/indicatorentrywidget.cpp 1970-01-01 00:00:00 +0000
1912+++ panel/applets/common/indicatorentrywidget.cpp 2011-07-18 14:37:40 +0000
1913@@ -0,0 +1,388 @@
1914+/*
1915+ * This file is part of unity-2d
1916+ *
1917+ * Copyright 2011 Canonical Ltd.
1918+ *
1919+ * Authors:
1920+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
1921+ *
1922+ * This program is free software; you can redistribute it and/or modify
1923+ * it under the terms of the GNU General Public License as published by
1924+ * the Free Software Foundation; version 3.
1925+ *
1926+ * This program is distributed in the hope that it will be useful,
1927+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1928+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1929+ * GNU General Public License for more details.
1930+ *
1931+ * You should have received a copy of the GNU General Public License
1932+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1933+ */
1934+// Self
1935+#include "indicatorentrywidget.h"
1936+
1937+// Local
1938+#include <debug_p.h>
1939+#include <fakecairo.h>
1940+#include <panelstyle.h>
1941+
1942+// Qt
1943+#include <QIcon>
1944+#include <QPainter>
1945+#include <QWheelEvent>
1946+
1947+// GTK
1948+#include <gtk/gtk.h>
1949+
1950+// libc
1951+#include <time.h>
1952+
1953+static const int SPACING = 3;
1954+static const int PADDING = 3;
1955+
1956+using namespace unity::indicator;
1957+
1958+// Copied from libdbusmenu-qt
1959+static QString swapMnemonicChar(const QString &in, const char src, const char dst)
1960+{
1961+ QString out;
1962+ bool mnemonicFound = false;
1963+
1964+ for (int pos = 0; pos < in.length(); ) {
1965+ QChar ch = in[pos];
1966+ if (ch == src) {
1967+ if (pos == in.length() - 1) {
1968+ // 'src' at the end of string, skip it
1969+ ++pos;
1970+ } else {
1971+ if (in[pos + 1] == src) {
1972+ // A real 'src'
1973+ out += src;
1974+ pos += 2;
1975+ } else if (!mnemonicFound) {
1976+ // We found the mnemonic
1977+ mnemonicFound = true;
1978+ out += dst;
1979+ ++pos;
1980+ } else {
1981+ // We already have a mnemonic, just skip the char
1982+ ++pos;
1983+ }
1984+ }
1985+ } else if (ch == dst) {
1986+ // Escape 'dst'
1987+ out += dst;
1988+ out += dst;
1989+ ++pos;
1990+ } else {
1991+ out += ch;
1992+ ++pos;
1993+ }
1994+ }
1995+
1996+ return out;
1997+}
1998+
1999+IndicatorEntryWidget::IndicatorEntryWidget(const Entry::Ptr& entry)
2000+: m_entry(entry)
2001+, m_padding(PADDING)
2002+, m_hasIcon(false)
2003+, m_hasLabel(false)
2004+{
2005+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
2006+ m_entry->updated.connect(sigc::mem_fun(this, &IndicatorEntryWidget::updatePix));
2007+ updatePix();
2008+}
2009+
2010+QSize IndicatorEntryWidget::minimumSizeHint() const
2011+{
2012+ return sizeHint();
2013+}
2014+
2015+QSize IndicatorEntryWidget::sizeHint() const
2016+{
2017+ return m_pix.size();
2018+}
2019+
2020+void IndicatorEntryWidget::paintEvent(QPaintEvent*)
2021+{
2022+ if (!m_pix.isNull()) {
2023+ QPainter painter(this);
2024+ if (m_entry->active()) {
2025+ paintActiveBackground(&painter);
2026+ }
2027+ painter.drawPixmap(0, 0, m_pix);
2028+ }
2029+}
2030+
2031+
2032+void IndicatorEntryWidget::paintActiveBackground(QPainter* painter)
2033+{
2034+ // This code should be kept in sync with the draw_menu_bg() function from
2035+ // plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp
2036+ int radius = 4;
2037+ double x = 0;
2038+ double y = 0;
2039+ double xos = 0.5;
2040+ double yos = 0.5;
2041+ /* FIXME */
2042+ double mpi = 3.14159265358979323846;
2043+
2044+ PanelStyle* style = PanelStyle::instance();
2045+ nux::color::Color bgtop = nuxColorFromQColor(style->backgroundTopColor());
2046+ nux::color::Color bgbot = nuxColorFromQColor(style->backgroundBottomColor());
2047+ nux::color::Color line = nuxColorFromQColor(style->lineColor());
2048+
2049+ painter->setRenderHint(QPainter::Antialiasing);
2050+
2051+ fcairo_t cr(painter);
2052+
2053+ fcairo_move_to (cr, x+xos+radius, y+yos);
2054+ fcairo_arc (cr, x+xos+width()-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
2055+ fcairo_line_to (cr, x+xos+width()-xos*2, y+yos+height()-yos*2+2);
2056+ fcairo_line_to (cr, x+xos, y+yos+height()-yos*2+2);
2057+ fcairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
2058+
2059+ fcairo_pattern_t * pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+2);
2060+ fcairo_pattern_add_color_stop_rgba (pat, 0.0,
2061+ bgtop.red,
2062+ bgtop.green,
2063+ bgtop.blue,
2064+ 1.0f - bgbot.red);
2065+ fcairo_pattern_add_color_stop_rgba (pat, 1.0,
2066+ bgbot.red,
2067+ bgbot.green,
2068+ bgbot.blue,
2069+ 1.0f - bgtop.red);
2070+ fcairo_set_source (cr, pat);
2071+ fcairo_fill_preserve (cr);
2072+ fcairo_pattern_destroy (pat);
2073+
2074+ /*
2075+ pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+2);
2076+ fcairo_pattern_add_color_stop_rgba (pat, 0.0,
2077+ line.red,
2078+ line.green,
2079+ line.blue,
2080+ 1.0f);
2081+ fcairo_pattern_add_color_stop_rgba (pat, 1.0,
2082+ line.red,
2083+ line.green,
2084+ line.blue,
2085+ 1.0f);
2086+ fcairo_set_source (cr, pat);
2087+ */
2088+ fcairo_set_source_rgb (cr, line.red, line.green, line.blue);
2089+ fcairo_stroke (cr);
2090+ //fcairo_pattern_destroy (pat);
2091+
2092+ xos++;
2093+ yos++;
2094+
2095+ /* enlarging the area to not draw the lightborder at bottom, ugly trick :P */
2096+ fcairo_move_to (cr, x+radius+xos, y+yos);
2097+ fcairo_arc (cr, x+xos+width()-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
2098+ fcairo_line_to (cr, x+xos+width()-xos*2, y+yos+height()-yos*2+3);
2099+ fcairo_line_to (cr, x+xos, y+yos+height()-yos*2+3);
2100+ fcairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
2101+
2102+ /*
2103+ pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+3);
2104+ fcairo_pattern_add_color_stop_rgba (pat, 0.0,
2105+ bgbot.red,
2106+ bgbot.green,
2107+ bgbot.blue,
2108+ 1.0f);
2109+ fcairo_pattern_add_color_stop_rgba (pat, 1.0,
2110+ bgbot.red,
2111+ bgbot.green,
2112+ bgbot.blue,
2113+ 1.0f);
2114+ fcairo_set_source (cr, pat);
2115+ */
2116+ fcairo_set_source_rgb (cr, bgbot.red, bgbot.green, bgbot.blue);
2117+ fcairo_stroke (cr);
2118+ //fcairo_pattern_destroy (pat);
2119+}
2120+
2121+void IndicatorEntryWidget::updatePix()
2122+{
2123+ bool oldIsEmpty = isEmpty();
2124+
2125+ int width = m_padding;
2126+ int iconX = m_padding;
2127+ int labelX = 0;
2128+
2129+ // Compute width, labelX and update m_has{Icon,Label}
2130+ QPixmap iconPix;
2131+ if (m_entry->image_visible()) {
2132+ iconPix = decodeIcon();
2133+ m_hasIcon = !iconPix.isNull();
2134+ } else {
2135+ m_hasIcon = false;
2136+ }
2137+ if (m_hasIcon) {
2138+ width += iconPix.width();
2139+ }
2140+
2141+ QString label = QString::fromUtf8(m_entry->label().c_str());
2142+ label = swapMnemonicChar(label, '_', '&');
2143+ m_hasLabel = !label.isEmpty() && m_entry->label_visible();
2144+ if (m_hasLabel) {
2145+ if (m_hasIcon) {
2146+ width += SPACING;
2147+ }
2148+ labelX = width;
2149+ QString visibleLabel = label;
2150+ visibleLabel.remove('&');
2151+ width += fontMetrics().width(visibleLabel);
2152+ }
2153+
2154+ width += m_padding;
2155+
2156+ // Paint
2157+ QPixmap oldPix = m_pix;
2158+ if (!m_hasIcon && !m_hasLabel) {
2159+ m_pix = QPixmap();
2160+ } else {
2161+ m_pix = QPixmap(width, 24);
2162+ m_pix.fill(Qt::transparent);
2163+ QPainter painter(&m_pix);
2164+ painter.initFrom(this);
2165+ if (m_hasIcon) {
2166+ bool disabled = !m_entry->image_sensitive();
2167+ if (disabled) {
2168+ painter.setOpacity(0.5);
2169+ }
2170+ painter.drawPixmap(iconX, 0, iconPix);
2171+ if (disabled) {
2172+ painter.setOpacity(1);
2173+ }
2174+ }
2175+ if (m_hasLabel) {
2176+ PanelStyle* style = PanelStyle::instance();
2177+
2178+ int flags = Qt::AlignLeft | Qt::AlignVCenter;
2179+ flags |= m_entry->show_now() ? Qt::TextShowMnemonic : Qt::TextHideMnemonic;
2180+
2181+ // Shadow
2182+ QColor color = style->textShadowColor();
2183+ color.setAlphaF(1. - color.redF());
2184+ painter.setPen(color);
2185+ painter.drawText(labelX, 1, width - labelX, m_pix.height(), flags, label);
2186+
2187+ // Text
2188+ color = style->textColor();
2189+ color.setAlphaF(m_entry->label_sensitive() ? 1. : .5);
2190+ painter.setPen(color);
2191+ painter.drawText(labelX, 0, width - labelX, m_pix.height(), flags, label);
2192+ }
2193+ }
2194+
2195+ // Notify others we changed, but only trigger a layout update if necessary
2196+ if (m_pix.size() == oldPix.size()) {
2197+ update();
2198+ } else {
2199+ updateGeometry();
2200+ }
2201+ bool newIsEmpty = isEmpty();
2202+ if (newIsEmpty != oldIsEmpty) {
2203+ // If we emit isEmptyChanged() directly it won't reach any connected
2204+ // slot. I assume this is because this method is called as a response
2205+ // to a sigc++ signal.
2206+ QMetaObject::invokeMethod(this, "isEmptyChanged", Qt::QueuedConnection);
2207+ }
2208+}
2209+
2210+QPixmap IndicatorEntryWidget::decodeIcon()
2211+{
2212+ QPixmap pix;
2213+
2214+ int type = m_entry->image_type();
2215+
2216+ if (type == 0) {
2217+ // No icon
2218+ } else if (type == GTK_IMAGE_PIXBUF) {
2219+ QByteArray data = QByteArray::fromBase64(m_entry->image_data().c_str());
2220+ QImage image;
2221+ bool ok = image.loadFromData(data);
2222+ if (ok) {
2223+ pix = QPixmap::fromImage(image);
2224+ } else {
2225+ UQ_WARNING << "Failed to decode image";
2226+ }
2227+ } else if (type == GTK_IMAGE_ICON_NAME) {
2228+ QString name = QString::fromStdString(m_entry->image_data());
2229+ QIcon icon = QIcon::fromTheme(name);
2230+ pix = icon.pixmap(24, 24);
2231+ } else if (type == GTK_IMAGE_GICON) {
2232+ UQ_WARNING << "FIXME: Implement support for GTK_IMAGE_GICON image type";
2233+ } else {
2234+ UQ_WARNING << "Unknown image type" << m_entry->image_type();
2235+ }
2236+ return pix;
2237+}
2238+
2239+void IndicatorEntryWidget::mousePressEvent(QMouseEvent*)
2240+{
2241+ UQ_RETURN_IF_FAIL(m_hasIcon || m_hasLabel);
2242+ showMenu(Qt::LeftButton);
2243+}
2244+
2245+void IndicatorEntryWidget::mouseReleaseEvent(QMouseEvent*)
2246+{
2247+ UQ_VAR(this);
2248+ update();
2249+}
2250+
2251+void IndicatorEntryWidget::wheelEvent(QWheelEvent* event)
2252+{
2253+ m_entry->Scroll(event->delta());
2254+}
2255+
2256+void IndicatorEntryWidget::showMenu(Qt::MouseButton qtButton)
2257+{
2258+ if (m_entry->active()) {
2259+ return;
2260+ }
2261+ int nuxButton = qtButton == Qt::NoButton ? 0 : 1;
2262+ QPoint pos = mapToGlobal(rect().bottomLeft());
2263+ m_entry->ShowMenu(pos.x(), pos.y(),
2264+ time(NULL),
2265+ nuxButton
2266+ );
2267+}
2268+
2269+void IndicatorEntryWidget::setPadding(int padding)
2270+{
2271+ if (m_padding != padding) {
2272+ m_padding = padding;
2273+ updatePix();
2274+ }
2275+}
2276+
2277+bool IndicatorEntryWidget::event(QEvent* ev)
2278+{
2279+ bool ret = QWidget::event(ev);
2280+ switch (ev->type()) {
2281+ case QEvent::FontChange:
2282+ case QEvent::PaletteChange:
2283+ updatePix();
2284+ break;
2285+ default:
2286+ break;
2287+ }
2288+ return ret;
2289+}
2290+
2291+bool IndicatorEntryWidget::isEmpty() const
2292+{
2293+ return !m_hasIcon && !m_hasLabel;
2294+}
2295+
2296+unity::indicator::Entry::Ptr IndicatorEntryWidget::entry() const
2297+{
2298+ return m_entry;
2299+}
2300+
2301+#include "indicatorentrywidget.moc"
2302
2303=== added file 'panel/applets/common/indicatorentrywidget.h'
2304--- panel/applets/common/indicatorentrywidget.h 1970-01-01 00:00:00 +0000
2305+++ panel/applets/common/indicatorentrywidget.h 2011-07-18 14:37:40 +0000
2306@@ -0,0 +1,81 @@
2307+/*
2308+ * This file is part of unity-2d
2309+ *
2310+ * Copyright 2011 Canonical Ltd.
2311+ *
2312+ * Authors:
2313+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
2314+ *
2315+ * This program is free software; you can redistribute it and/or modify
2316+ * it under the terms of the GNU General Public License as published by
2317+ * the Free Software Foundation; version 3.
2318+ *
2319+ * This program is distributed in the hope that it will be useful,
2320+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2321+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2322+ * GNU General Public License for more details.
2323+ *
2324+ * You should have received a copy of the GNU General Public License
2325+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2326+ */
2327+#ifndef INDICATORENTRYWIDGET_H
2328+#define INDICATORENTRYWIDGET_H
2329+
2330+// Local
2331+
2332+// libunity-core
2333+#include <UnityCore/UnityCore.h>
2334+
2335+// Qt
2336+#include <QWidget>
2337+
2338+class QPainter;
2339+
2340+class IndicatorEntryWidget : public QWidget, public sigc::trackable
2341+{
2342+Q_OBJECT
2343+public:
2344+ IndicatorEntryWidget(const unity::indicator::Entry::Ptr& entry);
2345+
2346+ QSize minimumSizeHint() const;
2347+ QSize sizeHint() const;
2348+
2349+ void setPadding(int);
2350+
2351+ bool isEmpty() const;
2352+
2353+ unity::indicator::Entry::Ptr entry() const;
2354+
2355+ /**
2356+ * Shows the menu.
2357+ *
2358+ * When this method is called because of a click, button
2359+ * must be set to Qt::LeftButton.
2360+ *
2361+ * When it is called because user previously clicked an indicator and moved the
2362+ * mouse to another indicator, button must be set to Qt::NoButton.
2363+ */
2364+ void showMenu(Qt::MouseButton button);
2365+
2366+Q_SIGNALS:
2367+ void isEmptyChanged();
2368+
2369+protected:
2370+ void paintEvent(QPaintEvent*);
2371+ void mousePressEvent(QMouseEvent*);
2372+ void mouseReleaseEvent(QMouseEvent*);
2373+ void wheelEvent(QWheelEvent*);
2374+ bool event(QEvent*);
2375+
2376+private:
2377+ unity::indicator::Entry::Ptr m_entry;
2378+ QPixmap m_pix;
2379+ int m_padding;
2380+ bool m_hasIcon;
2381+ bool m_hasLabel;
2382+ void updatePix();
2383+ QPixmap decodeIcon();
2384+ void paintActiveBackground(QPainter*);
2385+};
2386+
2387+#endif /* INDICATORENTRYWIDGET_H */
2388
2389=== added file 'panel/applets/common/indicatorsmanager.cpp'
2390--- panel/applets/common/indicatorsmanager.cpp 1970-01-01 00:00:00 +0000
2391+++ panel/applets/common/indicatorsmanager.cpp 2011-07-18 14:37:40 +0000
2392@@ -0,0 +1,179 @@
2393+/*
2394+ * This file is part of unity-2d
2395+ *
2396+ * Copyright 2011 Canonical Ltd.
2397+ *
2398+ * Authors:
2399+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
2400+ *
2401+ * This program is free software; you can redistribute it and/or modify
2402+ * it under the terms of the GNU General Public License as published by
2403+ * the Free Software Foundation; version 3.
2404+ *
2405+ * This program is distributed in the hope that it will be useful,
2406+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2407+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2408+ * GNU General Public License for more details.
2409+ *
2410+ * You should have received a copy of the GNU General Public License
2411+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2412+ */
2413+// Self
2414+#include "indicatorsmanager.h"
2415+
2416+// Local
2417+#include <debug_p.h>
2418+#include <indicatorentrywidget.h>
2419+
2420+// Qt
2421+#include <QApplication>
2422+#include <QTimer>
2423+#include <QX11Info>
2424+
2425+// UnityCore
2426+#include <UnityCore/UnityCore.h>
2427+
2428+// X11
2429+#include <X11/Xlib.h>
2430+
2431+using namespace unity::indicator;
2432+
2433+IndicatorsManager::IndicatorsManager(QObject* parent)
2434+: QObject(parent)
2435+, m_indicators(new DBusIndicators)
2436+, m_geometrySyncTimer(new QTimer(this))
2437+{
2438+ m_geometrySyncTimer->setInterval(0);
2439+ m_geometrySyncTimer->setSingleShot(true);
2440+ connect(m_geometrySyncTimer, SIGNAL(timeout()), SLOT(syncGeometries()));
2441+
2442+ m_indicators->on_entry_show_menu.connect(
2443+ sigc::mem_fun(this, &IndicatorsManager::onEntryShowMenu)
2444+ );
2445+
2446+ m_indicators->on_menu_pointer_moved.connect(
2447+ sigc::mem_fun(this, &IndicatorsManager::onMenuPointerMoved)
2448+ );
2449+
2450+ m_indicators->on_entry_activate_request.connect(
2451+ sigc::mem_fun(this, &IndicatorsManager::onEntryActivateRequest)
2452+ );
2453+
2454+ m_indicators->on_synced.connect(
2455+ sigc::mem_fun(this, &IndicatorsManager::onSynced)
2456+ );
2457+}
2458+
2459+unity::indicator::DBusIndicators::Ptr IndicatorsManager::indicators() const
2460+{
2461+ return m_indicators;
2462+}
2463+
2464+void IndicatorsManager::onEntryShowMenu(const std::string& /*entryId*/, int posX, int posY, int /*timestamp*/, int /*button*/)
2465+{
2466+ // Copied from plugins/unityshell/src/PanelView.cpp, in OnEntryShowMenu()
2467+ // Without this code, menus cannot be shown from mousePressEvent() (but can
2468+ // be shown from mouseReleaseEvent())
2469+ /*
2470+ Neil explanation:
2471+ On button down, X automatically gives Qt a passive grab on the mouse this
2472+ means that, if the panel service tries to grab the pointer to show the menu
2473+ (gtk does this automatically), it fails and the menu can't show.
2474+ We connect to the on_entry_show_menu signal, which is emitted before
2475+ DBusIndicators does anything else, and just break the grab.
2476+ */
2477+ Display* display = QX11Info::display();
2478+ XUngrabPointer(display, CurrentTime);
2479+ XFlush(display);
2480+
2481+ XButtonEvent event = {
2482+ ButtonRelease,
2483+ 0,
2484+ False,
2485+ display,
2486+ 0,
2487+ 0,
2488+ 0,
2489+ CurrentTime,
2490+ posX, posY,
2491+ posX, posY,
2492+ 0,
2493+ Button1,
2494+ True
2495+ };
2496+ qApp->x11ProcessEvent(reinterpret_cast<XEvent*>(&event));
2497+}
2498+
2499+void IndicatorsManager::onMenuPointerMoved(int posX, int posY)
2500+{
2501+ QWidget* widget = QApplication::widgetAt(posX, posY);
2502+ IndicatorEntryWidget* entryWidget = qobject_cast<IndicatorEntryWidget*>(widget);
2503+ if (!entryWidget) {
2504+ return;
2505+ }
2506+ entryWidget->showMenu(Qt::NoButton);
2507+}
2508+
2509+void IndicatorsManager::onEntryActivateRequest(const std::string& entryId)
2510+{
2511+ if (entryId.empty()) {
2512+ return;
2513+ }
2514+ IndicatorEntryWidget* widget = 0;
2515+ Q_FOREACH(widget, m_widgetList) {
2516+ if (widget->entry()->id() == entryId) {
2517+ break;
2518+ }
2519+ }
2520+ if (!widget) {
2521+ UQ_WARNING << "Could not find a widget for IndicatorEntry with id" << QString::fromStdString(entryId);
2522+ return;
2523+ }
2524+ widget->showMenu(Qt::NoButton);
2525+}
2526+
2527+void IndicatorsManager::onSynced()
2528+{
2529+ QMetaObject::invokeMethod(m_geometrySyncTimer, "start", Qt::QueuedConnection);
2530+}
2531+
2532+void IndicatorsManager::addIndicatorEntryWidget(IndicatorEntryWidget* widget)
2533+{
2534+ m_widgetList.append(widget);
2535+ widget->installEventFilter(this);
2536+}
2537+
2538+bool IndicatorsManager::eventFilter(QObject*, QEvent* event)
2539+{
2540+ switch (event->type()) {
2541+ case QEvent::Show:
2542+ case QEvent::Hide:
2543+ case QEvent::Move:
2544+ case QEvent::Resize:
2545+ m_geometrySyncTimer->start();
2546+ break;
2547+ default:
2548+ break;
2549+ }
2550+ return false;
2551+}
2552+
2553+void IndicatorsManager::syncGeometries()
2554+{
2555+ EntryLocationMap locations;
2556+ Q_FOREACH(IndicatorEntryWidget* widget, m_widgetList) {
2557+ if (!widget->isVisible()) {
2558+ continue;
2559+ }
2560+ Entry::Ptr entry = widget->entry();
2561+ if (entry->IsUnused()) {
2562+ continue;
2563+ }
2564+ QPoint topLeft = widget->mapToGlobal(QPoint(0, 0));
2565+ nux::Rect rect(topLeft.x(), topLeft.y(), widget->width(), widget->height());
2566+ locations[widget->entry()->id()] = rect;
2567+ }
2568+ m_indicators->SyncGeometries("Panel", locations);
2569+}
2570+
2571+#include "indicatorsmanager.moc"
2572
2573=== added file 'panel/applets/common/indicatorsmanager.h'
2574--- panel/applets/common/indicatorsmanager.h 1970-01-01 00:00:00 +0000
2575+++ panel/applets/common/indicatorsmanager.h 2011-07-18 14:37:40 +0000
2576@@ -0,0 +1,70 @@
2577+/*
2578+ * This file is part of unity-2d
2579+ *
2580+ * Copyright 2011 Canonical Ltd.
2581+ *
2582+ * Authors:
2583+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
2584+ *
2585+ * This program is free software; you can redistribute it and/or modify
2586+ * it under the terms of the GNU General Public License as published by
2587+ * the Free Software Foundation; version 3.
2588+ *
2589+ * This program is distributed in the hope that it will be useful,
2590+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2591+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2592+ * GNU General Public License for more details.
2593+ *
2594+ * You should have received a copy of the GNU General Public License
2595+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2596+ */
2597+#ifndef INDICATORSMANAGER_H
2598+#define INDICATORSMANAGER_H
2599+
2600+// Local
2601+
2602+// Qt
2603+#include <QMap>
2604+#include <QObject>
2605+
2606+// libunity-core
2607+#include <UnityCore/UnityCore.h>
2608+
2609+class QTimer;
2610+
2611+class IndicatorEntryWidget;
2612+
2613+/**
2614+ * Instantiates DBusIndicators and implement common behavior
2615+ */
2616+class IndicatorsManager : public QObject, public sigc::trackable
2617+{
2618+ Q_OBJECT
2619+public:
2620+ IndicatorsManager(QObject* parent);
2621+
2622+ unity::indicator::DBusIndicators::Ptr indicators() const;
2623+
2624+ void addIndicatorEntryWidget(IndicatorEntryWidget* widget);
2625+
2626+protected:
2627+ bool eventFilter(QObject*, QEvent*);
2628+
2629+private Q_SLOTS:
2630+ void syncGeometries();
2631+
2632+private:
2633+ Q_DISABLE_COPY(IndicatorsManager)
2634+ unity::indicator::DBusIndicators::Ptr m_indicators;
2635+ QTimer* m_geometrySyncTimer;
2636+
2637+ typedef QList<IndicatorEntryWidget*> IndicatorEntryWidgetList;
2638+ IndicatorEntryWidgetList m_widgetList;
2639+
2640+ void onSynced();
2641+ void onEntryShowMenu(const std::string&, int x, int y, int timestamp, int button);
2642+ void onMenuPointerMoved(int x, int y);
2643+ void onEntryActivateRequest(const std::string& entryId);
2644+};
2645+
2646+#endif /* INDICATORSMANAGER_H */
2647
2648=== added file 'panel/applets/common/indicatorwidget.cpp'
2649--- panel/applets/common/indicatorwidget.cpp 1970-01-01 00:00:00 +0000
2650+++ panel/applets/common/indicatorwidget.cpp 2011-07-18 14:37:40 +0000
2651@@ -0,0 +1,53 @@
2652+/*
2653+ * This file is part of unity-2d
2654+ *
2655+ * Copyright 2011 Canonical Ltd.
2656+ *
2657+ * Authors:
2658+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
2659+ *
2660+ * This program is free software; you can redistribute it and/or modify
2661+ * it under the terms of the GNU General Public License as published by
2662+ * the Free Software Foundation; version 3.
2663+ *
2664+ * This program is distributed in the hope that it will be useful,
2665+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2666+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2667+ * GNU General Public License for more details.
2668+ *
2669+ * You should have received a copy of the GNU General Public License
2670+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2671+ */
2672+// Self
2673+#include "indicatorwidget.h"
2674+
2675+// Local
2676+#include <debug_p.h>
2677+#include <indicatorentrywidget.h>
2678+#include <indicatorsmanager.h>
2679+
2680+// Qt
2681+#include <QHBoxLayout>
2682+
2683+using namespace unity::indicator;
2684+
2685+IndicatorWidget::IndicatorWidget(const Indicator::Ptr& indicator, IndicatorsManager* manager)
2686+: m_layout(new QHBoxLayout(this))
2687+, m_indicatorsManager(manager)
2688+, m_indicator(indicator)
2689+{
2690+ m_layout->setMargin(0);
2691+ m_layout->setSpacing(0);
2692+
2693+ m_indicator->on_entry_added.connect(sigc::mem_fun(this, &IndicatorWidget::onEntryAdded));
2694+}
2695+
2696+void IndicatorWidget::onEntryAdded(const Entry::Ptr& entry)
2697+{
2698+ IndicatorEntryWidget* widget = new IndicatorEntryWidget(entry);
2699+ m_indicatorsManager->addIndicatorEntryWidget(widget);
2700+ m_layout->addWidget(widget);
2701+}
2702+
2703+
2704+#include "indicatorwidget.moc"
2705
2706=== added file 'panel/applets/common/indicatorwidget.h'
2707--- panel/applets/common/indicatorwidget.h 1970-01-01 00:00:00 +0000
2708+++ panel/applets/common/indicatorwidget.h 2011-07-18 14:37:40 +0000
2709@@ -0,0 +1,51 @@
2710+/*
2711+ * This file is part of unity-2d
2712+ *
2713+ * Copyright 2011 Canonical Ltd.
2714+ *
2715+ * Authors:
2716+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
2717+ *
2718+ * This program is free software; you can redistribute it and/or modify
2719+ * it under the terms of the GNU General Public License as published by
2720+ * the Free Software Foundation; version 3.
2721+ *
2722+ * This program is distributed in the hope that it will be useful,
2723+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2724+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2725+ * GNU General Public License for more details.
2726+ *
2727+ * You should have received a copy of the GNU General Public License
2728+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2729+ */
2730+#ifndef INDICATORWIDGET_H
2731+#define INDICATORWIDGET_H
2732+
2733+// Local
2734+
2735+// libunity-core
2736+#include <UnityCore/UnityCore.h>
2737+
2738+// Qt
2739+#include <QWidget>
2740+
2741+class QHBoxLayout;
2742+
2743+class IndicatorEntryWidget;
2744+class IndicatorsManager;
2745+
2746+class IndicatorWidget : public QWidget, public sigc::trackable
2747+{
2748+Q_OBJECT
2749+public:
2750+ IndicatorWidget(const unity::indicator::Indicator::Ptr& indicator, IndicatorsManager* manager);
2751+
2752+private:
2753+ QHBoxLayout* m_layout;
2754+ IndicatorsManager* m_indicatorsManager;
2755+ unity::indicator::Indicator::Ptr m_indicator;
2756+
2757+ void onEntryAdded(const unity::indicator::Entry::Ptr& entry);
2758+};
2759+
2760+#endif /* INDICATORWIDGET_H */
2761
2762=== added file 'panel/applets/common/panelstyle.cpp'
2763--- panel/applets/common/panelstyle.cpp 1970-01-01 00:00:00 +0000
2764+++ panel/applets/common/panelstyle.cpp 2011-07-18 14:37:40 +0000
2765@@ -0,0 +1,176 @@
2766+/*
2767+ * This file is part of unity-2d
2768+ *
2769+ * Copyright 2011 Canonical Ltd.
2770+ *
2771+ * Authors:
2772+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
2773+ *
2774+ * This program is free software; you can redistribute it and/or modify
2775+ * it under the terms of the GNU General Public License as published by
2776+ * the Free Software Foundation; version 3.
2777+ *
2778+ * This program is distributed in the hope that it will be useful,
2779+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2780+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2781+ * GNU General Public License for more details.
2782+ *
2783+ * You should have received a copy of the GNU General Public License
2784+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2785+ */
2786+// Self
2787+#include "panelstyle.h"
2788+
2789+// libunity-2d
2790+#include <debug_p.h>
2791+#include <gconnector.h>
2792+#include <gscopedpointer.h>
2793+
2794+// Qt
2795+#include <QApplication>
2796+#include <QColor>
2797+#include <QFont>
2798+#include <QPalette>
2799+
2800+// GTK
2801+#include <gtk/gtk.h>
2802+#include <pango/pango.h>
2803+
2804+typedef void (*ColorGetter)(GtkStyleContext*, GtkStateFlags, GdkRGBA*);
2805+
2806+inline QColor colorFromContext(ColorGetter getter, GtkStyleContext* context, GtkStateFlags state)
2807+{
2808+ GdkRGBA color;
2809+ getter(context, state, &color);
2810+ return QColor::fromRgbF(color.red, color.green, color.blue, color.alpha);
2811+}
2812+
2813+class PanelStylePrivate
2814+{
2815+public:
2816+ PanelStyle* q;
2817+ GtkWidget* m_offScreenWindow;
2818+ GConnector m_gConnector;
2819+ QList<gulong> m_connections;
2820+
2821+ QColor m_textColor;
2822+ QColor m_backgroundTopColor;
2823+ QColor m_backgroundBottomColor;
2824+ QColor m_textShadowColor;
2825+ QColor m_lineColor;
2826+ QFont m_font;
2827+
2828+ static void onThemeChanged(GObject*, GParamSpec*, gpointer data)
2829+ {
2830+ PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);
2831+ priv->updatePalette();
2832+ }
2833+
2834+ static void onFontChanged(GObject*, GParamSpec*, gpointer data)
2835+ {
2836+ PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);
2837+ priv->updateFont();
2838+ }
2839+
2840+ void updatePalette()
2841+ {
2842+ GtkStyleContext* context = gtk_widget_get_style_context(m_offScreenWindow);
2843+ UQ_RETURN_IF_FAIL(context);
2844+
2845+ m_textColor = colorFromContext(gtk_style_context_get_color, context, GTK_STATE_FLAG_NORMAL);
2846+ m_textShadowColor = colorFromContext(gtk_style_context_get_color, context, GTK_STATE_FLAG_SELECTED);
2847+ m_lineColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_NORMAL).darker(130);
2848+ m_backgroundTopColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_ACTIVE);
2849+ m_backgroundBottomColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_NORMAL);
2850+
2851+ QPalette pal;
2852+ pal.setColor(QPalette::Window, m_backgroundTopColor);
2853+ pal.setColor(QPalette::Button, m_backgroundTopColor);
2854+ pal.setColor(QPalette::Text, m_textColor);
2855+ pal.setColor(QPalette::WindowText, m_textColor);
2856+ pal.setColor(QPalette::ButtonText, m_textColor);
2857+ QApplication::setPalette(pal);
2858+ }
2859+
2860+ void updateFont()
2861+ {
2862+ gchar* fontName = 0;
2863+ g_object_get(gtk_settings_get_default(), "gtk-font-name", &fontName, NULL);
2864+ GScopedPointer<PangoFontDescription, pango_font_description_free> fontDescription(
2865+ pango_font_description_from_string(fontName)
2866+ );
2867+ g_free(fontName);
2868+
2869+ int size = pango_font_description_get_size(fontDescription.data());
2870+
2871+ m_font = QFont(
2872+ pango_font_description_get_family(fontDescription.data()),
2873+ size / PANGO_SCALE
2874+ );
2875+
2876+ QApplication::setFont(m_font);
2877+ }
2878+};
2879+
2880+PanelStyle::PanelStyle(QObject* parent)
2881+: d(new PanelStylePrivate)
2882+{
2883+ d->q = this;
2884+ d->m_offScreenWindow = gtk_offscreen_window_new();
2885+ gtk_widget_set_name(d->m_offScreenWindow, "UnityPanelWidget");
2886+ gtk_widget_set_size_request(d->m_offScreenWindow, 100, 24);
2887+ gtk_style_context_add_class(gtk_widget_get_style_context(d->m_offScreenWindow), "menubar");
2888+ gtk_widget_show_all(d->m_offScreenWindow);
2889+
2890+ d->m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-theme-name",
2891+ G_CALLBACK(PanelStylePrivate::onThemeChanged), d);
2892+ d->m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-font-name",
2893+ G_CALLBACK(PanelStylePrivate::onFontChanged), d);
2894+
2895+ d->updatePalette();
2896+ d->updateFont();
2897+}
2898+
2899+PanelStyle::~PanelStyle()
2900+{
2901+ gtk_widget_destroy(d->m_offScreenWindow);
2902+ delete d;
2903+}
2904+
2905+PanelStyle* PanelStyle::instance()
2906+{
2907+ static PanelStyle style;
2908+ return &style;
2909+}
2910+
2911+QColor PanelStyle::textColor() const
2912+{
2913+ return d->m_textColor;
2914+}
2915+
2916+QColor PanelStyle::backgroundTopColor() const
2917+{
2918+ return d->m_backgroundTopColor;
2919+}
2920+
2921+QColor PanelStyle::backgroundBottomColor() const
2922+{
2923+ return d->m_backgroundBottomColor;
2924+}
2925+
2926+QColor PanelStyle::textShadowColor() const
2927+{
2928+ return d->m_textShadowColor;
2929+}
2930+
2931+QColor PanelStyle::lineColor() const
2932+{
2933+ return d->m_lineColor;
2934+}
2935+
2936+QFont PanelStyle::font() const
2937+{
2938+ return d->m_font;
2939+}
2940+
2941+#include "panelstyle.moc"
2942
2943=== added file 'panel/applets/common/panelstyle.h'
2944--- panel/applets/common/panelstyle.h 1970-01-01 00:00:00 +0000
2945+++ panel/applets/common/panelstyle.h 2011-07-18 14:37:40 +0000
2946@@ -0,0 +1,59 @@
2947+/*
2948+ * This file is part of unity-2d
2949+ *
2950+ * Copyright 2011 Canonical Ltd.
2951+ *
2952+ * Authors:
2953+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
2954+ *
2955+ * This program is free software; you can redistribute it and/or modify
2956+ * it under the terms of the GNU General Public License as published by
2957+ * the Free Software Foundation; version 3.
2958+ *
2959+ * This program is distributed in the hope that it will be useful,
2960+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2961+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2962+ * GNU General Public License for more details.
2963+ *
2964+ * You should have received a copy of the GNU General Public License
2965+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2966+ */
2967+#ifndef PANELSTYLE_H
2968+#define PANELSTYLE_H
2969+
2970+// Local
2971+
2972+// Qt
2973+#include <QObject>
2974+
2975+class QColor;
2976+class QFont;
2977+
2978+class PanelStylePrivate;
2979+/**
2980+ * Provides easy access to panel colors
2981+ */
2982+class PanelStyle : public QObject
2983+{
2984+ Q_OBJECT
2985+public:
2986+ PanelStyle(QObject* parent = 0);
2987+ ~PanelStyle();
2988+
2989+ static PanelStyle* instance();
2990+
2991+ QColor textColor() const;
2992+ QColor backgroundTopColor() const;
2993+ QColor backgroundBottomColor() const;
2994+ QColor textShadowColor() const;
2995+ QColor lineColor() const;
2996+
2997+ QFont font() const;
2998+
2999+private:
3000+ friend class PanelStylePrivate;
3001+ // Use a pimpl to avoid the need for gtk includes here
3002+ PanelStylePrivate* const d;
3003+};
3004+
3005+#endif /* PANELSTYLE_H */
3006
3007=== added directory 'panel/applets/indicator'
3008=== removed directory 'panel/applets/indicator'
3009=== removed file 'panel/applets/indicator-config.h.in'
3010--- panel/applets/indicator-config.h.in 2011-03-01 09:04:13 +0000
3011+++ panel/applets/indicator-config.h.in 1970-01-01 00:00:00 +0000
3012@@ -1,7 +0,0 @@
3013-#ifndef INDICATOR_CONFIG_H
3014-#define INDICATOR_CONFIG_H
3015-
3016-#define INDICATOR_ICONS_DIR "${INDICATOR_ICONS_DIR}"
3017-#define INDICATOR_DIR "${INDICATOR_DIR}"
3018-
3019-#endif /* INDICATOR_CONFIG_H */
3020
3021=== removed file 'panel/applets/indicator/abstractindicator.cpp'
3022--- panel/applets/indicator/abstractindicator.cpp 2011-01-15 01:41:03 +0000
3023+++ panel/applets/indicator/abstractindicator.cpp 1970-01-01 00:00:00 +0000
3024@@ -1,43 +0,0 @@
3025-/*
3026- * This file is part of unity-2d
3027- *
3028- * Copyright 2010 Canonical Ltd.
3029- *
3030- * Authors:
3031- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
3032- *
3033- * This program is free software; you can redistribute it and/or modify
3034- * it under the terms of the GNU General Public License as published by
3035- * the Free Software Foundation; version 3.
3036- *
3037- * This program is distributed in the hope that it will be useful,
3038- * but WITHOUT ANY WARRANTY; without even the implied warranty of
3039- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3040- * GNU General Public License for more details.
3041- *
3042- * You should have received a copy of the GNU General Public License
3043- * along with this program. If not, see <http://www.gnu.org/licenses/>.
3044- */
3045-
3046-// Self
3047-#include "abstractindicator.h"
3048-
3049-// Local
3050-
3051-// Qt
3052-#include <QAction>
3053-
3054-AbstractIndicator::AbstractIndicator(QObject* parent)
3055-: QObject(parent)
3056-{
3057-}
3058-
3059-AbstractIndicator::~AbstractIndicator()
3060-{
3061-}
3062-
3063-void AbstractIndicator::init()
3064-{
3065-}
3066-
3067-#include "abstractindicator.moc"
3068
3069=== removed file 'panel/applets/indicator/abstractindicator.h'
3070--- panel/applets/indicator/abstractindicator.h 2011-01-15 01:41:03 +0000
3071+++ panel/applets/indicator/abstractindicator.h 1970-01-01 00:00:00 +0000
3072@@ -1,53 +0,0 @@
3073-/*
3074- * This file is part of unity-2d
3075- *
3076- * Copyright 2010 Canonical Ltd.
3077- *
3078- * Authors:
3079- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
3080- *
3081- * This program is free software; you can redistribute it and/or modify
3082- * it under the terms of the GNU General Public License as published by
3083- * the Free Software Foundation; version 3.
3084- *
3085- * This program is distributed in the hope that it will be useful,
3086- * but WITHOUT ANY WARRANTY; without even the implied warranty of
3087- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3088- * GNU General Public License for more details.
3089- *
3090- * You should have received a copy of the GNU General Public License
3091- * along with this program. If not, see <http://www.gnu.org/licenses/>.
3092- */
3093-
3094-#ifndef ABSTRACTINDICATOR_H
3095-#define ABSTRACTINDICATOR_H
3096-
3097-// Local
3098-
3099-// Qt
3100-#include <QObject>
3101-
3102-class QAction;
3103-
3104-class AbstractIndicator : public QObject
3105-{
3106- Q_OBJECT
3107-public:
3108- AbstractIndicator(QObject* parent=0);
3109- ~AbstractIndicator();
3110-
3111- /**
3112- * Called when the indicator has been constructed and its owner is connected to signals.
3113- * It's the right place to emit actionAdded()
3114- */
3115- virtual void init();
3116-
3117-Q_SIGNALS:
3118- void actionAdded(QAction*);
3119- void actionRemoved(QAction*);
3120-
3121-private:
3122- Q_DISABLE_COPY(AbstractIndicator)
3123-};
3124-
3125-#endif /* ABSTRACTINDICATOR_H */
3126
3127=== removed file 'panel/applets/indicator/datetimeindicator.cpp'
3128--- panel/applets/indicator/datetimeindicator.cpp 2011-02-10 01:10:19 +0000
3129+++ panel/applets/indicator/datetimeindicator.cpp 1970-01-01 00:00:00 +0000
3130@@ -1,94 +0,0 @@
3131-/*
3132- * This file is part of unity-2d
3133- *
3134- * Copyright 2010 Canonical Ltd.
3135- *
3136- * Authors:
3137- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
3138- *
3139- * This program is free software; you can redistribute it and/or modify
3140- * it under the terms of the GNU General Public License as published by
3141- * the Free Software Foundation; version 3.
3142- *
3143- * This program is distributed in the hope that it will be useful,
3144- * but WITHOUT ANY WARRANTY; without even the implied warranty of
3145- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3146- * GNU General Public License for more details.
3147- *
3148- * You should have received a copy of the GNU General Public License
3149- * along with this program. If not, see <http://www.gnu.org/licenses/>.
3150- */
3151-
3152-// Self
3153-#include "datetimeindicator.h"
3154-
3155-// Local
3156-#include "indicatorservicemanager.h"
3157-
3158-// dbusmenu-qt
3159-#include "dbusmenuimporter.h"
3160-
3161-// Qt
3162-#include <QAction>
3163-#include <QDateTime>
3164-
3165-// From dbus-shared.h
3166-#define SERVICE_NAME "com.canonical.indicator.datetime"
3167-#define SERVICE_IFACE "com.canonical.indicator.datetime.service"
3168-#define SERVICE_OBJ "/com.canonical/indicator/datetime/service"
3169-#define SERVICE_VERSION 1
3170-
3171-#define MENU_OBJ "/com.canonical/indicator/datetime/menu"
3172-
3173-#define DBUSMENU_CALENDAR_MENUITEM_TYPE "x-canonical-calendar-item"
3174-////
3175-
3176-DateTimeIndicator::DateTimeIndicator(QObject* parent)
3177-: AbstractIndicator(parent)
3178-, m_action(new QAction(this))
3179-, m_timer(new QTimer(this))
3180-{
3181- new IndicatorServiceManager(SERVICE_NAME, SERVICE_VERSION, this);
3182-
3183- readConfig();
3184- setupMenu();
3185- setupTimer();
3186- updateText();
3187-}
3188-
3189-void DateTimeIndicator::init()
3190-{
3191- actionAdded(m_action);
3192-}
3193-
3194-void DateTimeIndicator::setupMenu()
3195-{
3196- DBusMenuImporter* importer = new DBusMenuImporter(SERVICE_NAME, MENU_OBJ, this);
3197- m_action->setMenu(importer->menu());
3198-}
3199-
3200-void DateTimeIndicator::setupTimer()
3201-{
3202- m_timer->setSingleShot(false);
3203- connect(m_timer, SIGNAL(timeout()), SLOT(updateText()));
3204- updateTimer();
3205- m_timer->start();
3206-}
3207-
3208-void DateTimeIndicator::updateTimer()
3209-{
3210- m_timer->setInterval(1000);
3211-}
3212-
3213-void DateTimeIndicator::updateText()
3214-{
3215- QString text = QDateTime::currentDateTime().toString(m_format);
3216- m_action->setText(text);
3217-}
3218-
3219-void DateTimeIndicator::readConfig()
3220-{
3221- m_format = "hh:mm:ss";
3222-}
3223-
3224-#include "datetimeindicator.moc"
3225
3226=== removed file 'panel/applets/indicator/datetimeindicator.h'
3227--- panel/applets/indicator/datetimeindicator.h 2011-01-15 01:41:03 +0000
3228+++ panel/applets/indicator/datetimeindicator.h 1970-01-01 00:00:00 +0000
3229@@ -1,53 +0,0 @@
3230-/*
3231- * This file is part of unity-2d
3232- *
3233- * Copyright 2010 Canonical Ltd.
3234- *
3235- * Authors:
3236- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
3237- *
3238- * This program is free software; you can redistribute it and/or modify
3239- * it under the terms of the GNU General Public License as published by
3240- * the Free Software Foundation; version 3.
3241- *
3242- * This program is distributed in the hope that it will be useful,
3243- * but WITHOUT ANY WARRANTY; without even the implied warranty of
3244- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3245- * GNU General Public License for more details.
3246- *
3247- * You should have received a copy of the GNU General Public License
3248- * along with this program. If not, see <http://www.gnu.org/licenses/>.
3249- */
3250-
3251-#ifndef DATETIMEINDICATOR_H
3252-#define DATETIMEINDICATOR_H
3253-
3254-// Local
3255-#include "abstractindicator.h"
3256-
3257-// Qt
3258-#include <QTimer>
3259-
3260-class DateTimeIndicator : public AbstractIndicator
3261-{
3262- Q_OBJECT
3263-public:
3264- DateTimeIndicator(QObject* parent=0);
3265-
3266- virtual void init();
3267-
3268-private Q_SLOTS:
3269- void updateText();
3270-private:
3271- Q_DISABLE_COPY(DateTimeIndicator)
3272- QAction* m_action;
3273- QTimer* m_timer;
3274- QString m_format;
3275-
3276- void setupTimer();
3277- void setupMenu();
3278- void readConfig();
3279- void updateTimer();
3280-};
3281-
3282-#endif /* DATETIMEINDICATOR_H */
3283
3284=== removed file 'panel/applets/indicator/indicator.c'
3285--- panel/applets/indicator/indicator.c 2011-03-30 14:50:35 +0000
3286+++ panel/applets/indicator/indicator.c 1970-01-01 00:00:00 +0000
3287@@ -1,510 +0,0 @@
3288-/* Copyright (c) 2009 Mark Trompell <mark@foresightlinux.org>
3289- *
3290- * This program is free software; you can redistribute it and/or modify
3291- * it under the terms of the GNU General Public License as published by
3292- * the Free Software Foundation; either version 2 of the License, or
3293- * (at your option) any later version.
3294- *
3295- * This program is distributed in the hope that it will be useful,
3296- * but WITHOUT ANY WARRANTY; without even the implied warranty of
3297- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3298- * GNU Library General Public License for more details.
3299- *
3300- * You should have received a copy of the GNU General Public License
3301- * along with this program; if not, write to the Free Software
3302- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3303- */
3304-
3305-#include <string.h>
3306-
3307-#include <gtk/gtk.h>
3308-#include <libindicator/indicator-object.h>
3309-
3310-#include "indicator.h"
3311-
3312-#include "indicator-config.h"
3313-
3314-/* default settings */
3315-#define DEFAULT_SETTING1 NULL
3316-#define DEFAULT_SETTING2 1
3317-#define DEFAULT_SETTING3 FALSE
3318-
3319-typedef enum {
3320- PANEL_APPLET_ORIENT_LEFT,
3321- PANEL_APPLET_ORIENT_RIGHT,
3322- PANEL_APPLET_ORIENT_TOP,
3323- PANEL_APPLET_ORIENT_BOTTOM
3324-} PanelAppletOrient;
3325-
3326-// <indicator-applet-copy>
3327-static gchar * indicator_order[] = {
3328- "libappmenu.so",
3329- "libapplication.so",
3330- "libsoundmenu.so",
3331- "libnetworkmenu.so",
3332- "libmessaging.so",
3333- "libdatetime.so",
3334- "libme.so",
3335- "libsession.so",
3336- NULL
3337-};
3338-
3339-static GtkPackDirection packdirection;
3340-static PanelAppletOrient orient;
3341-
3342-#define MENU_DATA_INDICATOR_OBJECT "indicator-object"
3343-#define MENU_DATA_INDICATOR_ENTRY "indicator-entry"
3344-
3345-#define IO_DATA_ORDER_NUMBER "indicator-order-number"
3346-
3347-static gint
3348-name2order (const gchar * name) {
3349- int i;
3350-
3351- for (i = 0; indicator_order[i] != NULL; i++) {
3352- if (g_strcmp0(name, indicator_order[i]) == 0) {
3353- return i;
3354- }
3355- }
3356-
3357- return -1;
3358-}
3359-
3360-typedef struct _incoming_position_t incoming_position_t;
3361-struct _incoming_position_t {
3362- gint objposition;
3363- gint entryposition;
3364- gint menupos;
3365- gboolean found;
3366-};
3367-
3368-/* This function helps by determining where in the menu list
3369- this new entry should be placed. It compares the objects
3370- that they're on, and then the individual entries. Each
3371- is progressively more expensive. */
3372-static void
3373-place_in_menu (GtkWidget * widget, gpointer user_data)
3374-{
3375- incoming_position_t * position = (incoming_position_t *)user_data;
3376- if (position->found) {
3377- /* We've already been placed, just finish the foreach */
3378- return;
3379- }
3380-
3381- IndicatorObject * io = INDICATOR_OBJECT(g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_OBJECT));
3382- g_assert(io != NULL);
3383-
3384- gint objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
3385- /* We've already passed it, well, then this is where
3386- we should be be. Stop! */
3387- if (objposition > position->objposition) {
3388- position->found = TRUE;
3389- return;
3390- }
3391-
3392- /* The objects don't match yet, keep looking */
3393- if (objposition < position->objposition) {
3394- position->menupos++;
3395- return;
3396- }
3397-
3398- /* The objects are the same, let's start looking at entries. */
3399- IndicatorObjectEntry * entry = (IndicatorObjectEntry *)g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
3400- gint entryposition = indicator_object_get_location(io, entry);
3401-
3402- if (entryposition > position->entryposition) {
3403- position->found = TRUE;
3404- return;
3405- }
3406-
3407- if (entryposition < position->entryposition) {
3408- position->menupos++;
3409- return;
3410- }
3411-
3412- /* We've got the same object and the same entry. Well,
3413- let's just put it right here then. */
3414- position->found = TRUE;
3415- return;
3416-}
3417-
3418-static void
3419-something_shown (GtkWidget * widget, gpointer user_data)
3420-{
3421- GtkWidget * menuitem = GTK_WIDGET(user_data);
3422- gtk_widget_show(menuitem);
3423-}
3424-
3425-static void
3426-something_hidden (GtkWidget * widget, gpointer user_data)
3427-{
3428- GtkWidget * menuitem = GTK_WIDGET(user_data);
3429- gtk_widget_hide(menuitem);
3430-}
3431-
3432-static void
3433-sensitive_cb (GObject * obj, GParamSpec * pspec, gpointer user_data)
3434-{
3435- g_return_if_fail(GTK_IS_WIDGET(obj));
3436- g_return_if_fail(GTK_IS_WIDGET(user_data));
3437-
3438- gtk_widget_set_sensitive(GTK_WIDGET(user_data), gtk_widget_get_sensitive(GTK_WIDGET(obj)));
3439- return;
3440-}
3441-
3442-static void
3443-entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, GtkWidget * menubar)
3444-{
3445- g_debug("Signal: Entry Added");
3446- gboolean something_visible = FALSE;
3447- gboolean something_sensitive = FALSE;
3448-
3449- GtkWidget * menuitem = gtk_menu_item_new();
3450- GtkWidget * box = (packdirection == GTK_PACK_DIRECTION_LTR) ?
3451- gtk_hbox_new(FALSE, 3) : gtk_vbox_new(FALSE, 3);
3452-
3453- g_object_set_data (G_OBJECT (menuitem), "indicator", io);
3454- g_object_set_data (G_OBJECT (menuitem), "box", box);
3455-
3456- if (entry->image != NULL) {
3457- gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(entry->image), FALSE, FALSE, 0);
3458- if (gtk_widget_get_visible(GTK_WIDGET(entry->image))) {
3459- something_visible = TRUE;
3460- }
3461-
3462- if (gtk_widget_get_sensitive(GTK_WIDGET(entry->image))) {
3463- something_sensitive = TRUE;
3464- }
3465-
3466- g_signal_connect(G_OBJECT(entry->image), "show", G_CALLBACK(something_shown), menuitem);
3467- g_signal_connect(G_OBJECT(entry->image), "hide", G_CALLBACK(something_hidden), menuitem);
3468-
3469- g_signal_connect(G_OBJECT(entry->image), "notify::sensitive", G_CALLBACK(sensitive_cb), menuitem);
3470- }
3471- if (entry->label != NULL) {
3472- switch(packdirection) {
3473- case GTK_PACK_DIRECTION_LTR:
3474- gtk_label_set_angle(GTK_LABEL(entry->label), 0.0);
3475- break;
3476- case GTK_PACK_DIRECTION_TTB:
3477- gtk_label_set_angle(GTK_LABEL(entry->label),
3478- (orient == PANEL_APPLET_ORIENT_LEFT) ?
3479- 270.0 : 90.0);
3480- break;
3481- default:
3482- break;
3483- }
3484- gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(entry->label), FALSE, FALSE, 0);
3485-
3486- if (gtk_widget_get_visible(GTK_WIDGET(entry->label))) {
3487- something_visible = TRUE;
3488- }
3489-
3490- if (gtk_widget_get_sensitive(GTK_WIDGET(entry->label))) {
3491- something_sensitive = TRUE;
3492- }
3493-
3494- g_signal_connect(G_OBJECT(entry->label), "show", G_CALLBACK(something_shown), menuitem);
3495- g_signal_connect(G_OBJECT(entry->label), "hide", G_CALLBACK(something_hidden), menuitem);
3496-
3497- g_signal_connect(G_OBJECT(entry->label), "notify::sensitive", G_CALLBACK(sensitive_cb), menuitem);
3498- }
3499- gtk_container_add(GTK_CONTAINER(menuitem), box);
3500- gtk_widget_show(box);
3501-
3502- if (entry->menu != NULL) {
3503- gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
3504- }
3505-
3506- incoming_position_t position;
3507- position.objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
3508- position.entryposition = indicator_object_get_location(io, entry);
3509- position.menupos = 0;
3510- position.found = FALSE;
3511-
3512- gtk_container_foreach(GTK_CONTAINER(menubar), place_in_menu, &position);
3513-
3514- gtk_menu_shell_insert(GTK_MENU_SHELL(menubar), menuitem, position.menupos);
3515-
3516- if (something_visible) {
3517- gtk_widget_show(menuitem);
3518- }
3519- gtk_widget_set_sensitive(menuitem, something_sensitive);
3520-
3521- g_object_set_data(G_OBJECT(menuitem), MENU_DATA_INDICATOR_ENTRY, entry);
3522- g_object_set_data(G_OBJECT(menuitem), MENU_DATA_INDICATOR_OBJECT, io);
3523-
3524- return;
3525-}
3526-
3527-static void
3528-entry_removed_cb (GtkWidget * widget, gpointer userdata)
3529-{
3530- gpointer data = g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
3531-
3532- if (data != userdata) {
3533- return;
3534- }
3535-
3536- IndicatorObjectEntry * entry = (IndicatorObjectEntry *)data;
3537- if (entry->label != NULL) {
3538- g_signal_handlers_disconnect_by_func(G_OBJECT(entry->label), G_CALLBACK(something_shown), widget);
3539- g_signal_handlers_disconnect_by_func(G_OBJECT(entry->label), G_CALLBACK(something_hidden), widget);
3540- g_signal_handlers_disconnect_by_func(G_OBJECT(entry->label), G_CALLBACK(sensitive_cb), widget);
3541- }
3542- if (entry->image != NULL) {
3543- g_signal_handlers_disconnect_by_func(G_OBJECT(entry->image), G_CALLBACK(something_shown), widget);
3544- g_signal_handlers_disconnect_by_func(G_OBJECT(entry->image), G_CALLBACK(something_hidden), widget);
3545- g_signal_handlers_disconnect_by_func(G_OBJECT(entry->image), G_CALLBACK(sensitive_cb), widget);
3546- }
3547-
3548- gtk_widget_destroy(widget);
3549- return;
3550-}
3551-
3552-static void
3553-entry_removed (IndicatorObject * io G_GNUC_UNUSED, IndicatorObjectEntry * entry,
3554- gpointer user_data)
3555-{
3556- g_debug("Signal: Entry Removed");
3557-
3558- gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);
3559-
3560- return;
3561-}
3562-
3563-static void
3564-entry_moved_find_cb (GtkWidget * widget, gpointer userdata)
3565-{
3566- gpointer * array = (gpointer *)userdata;
3567- if (array[1] != NULL) {
3568- return;
3569- }
3570-
3571- gpointer data = g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
3572-
3573- if (data != array[0]) {
3574- return;
3575- }
3576-
3577- array[1] = widget;
3578- return;
3579-}
3580-
3581-/* Gets called when an entry for an object was moved. */
3582-static void
3583-entry_moved (IndicatorObject * io, IndicatorObjectEntry * entry,
3584- gint old G_GNUC_UNUSED, gint new G_GNUC_UNUSED, gpointer user_data)
3585-{
3586- GtkWidget * menubar = GTK_WIDGET(user_data);
3587-
3588- gpointer array[2];
3589- array[0] = entry;
3590- array[1] = NULL;
3591-
3592- gtk_container_foreach(GTK_CONTAINER(menubar), entry_moved_find_cb, array);
3593- if (array[1] == NULL) {
3594- g_warning("Moving an entry that isn't in our menus.");
3595- return;
3596- }
3597-
3598- GtkWidget * mi = GTK_WIDGET(array[1]);
3599- g_object_ref(G_OBJECT(mi));
3600- gtk_container_remove(GTK_CONTAINER(menubar), mi);
3601-
3602- incoming_position_t position;
3603- position.objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
3604- position.entryposition = indicator_object_get_location(io, entry);
3605- position.menupos = 0;
3606- position.found = FALSE;
3607-
3608- gtk_container_foreach(GTK_CONTAINER(menubar), place_in_menu, &position);
3609-
3610- gtk_menu_shell_insert(GTK_MENU_SHELL(menubar), mi, position.menupos);
3611-
3612- g_object_unref(G_OBJECT(mi));
3613-
3614- return;
3615-}
3616-
3617-static gboolean
3618-load_module (const gchar * name, GtkWidget * menubar)
3619-{
3620- g_debug("Looking at Module: %s", name);
3621- g_return_val_if_fail(name != NULL, FALSE);
3622-
3623- if (!g_str_has_suffix(name, G_MODULE_SUFFIX)) {
3624- return FALSE;
3625- }
3626-
3627- g_debug("Loading Module: %s", name);
3628-
3629- /* Build the object for the module */
3630- gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
3631- IndicatorObject * io = indicator_object_new_from_file(fullpath);
3632- g_free(fullpath);
3633- g_return_val_if_fail(io != NULL, FALSE);
3634-
3635- /* Attach the 'name' to the object */
3636- g_object_set_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER, GINT_TO_POINTER(name2order(name)));
3637-
3638- /* Connect to its signals */
3639- g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menubar);
3640- g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menubar);
3641- g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED, G_CALLBACK(entry_moved), menubar);
3642-
3643- /* Work on the entries */
3644- GList * entries = indicator_object_get_entries(io);
3645- GList * entry = NULL;
3646-
3647- for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
3648- IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
3649- entry_added(io, entrydata, menubar);
3650- }
3651-
3652- g_list_free(entries);
3653-
3654- return TRUE;
3655-}
3656-// </indicator-applet-copy>
3657-
3658-
3659-/* prototypes */
3660-static gboolean
3661-on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator);
3662-
3663-IndicatorPlugin *
3664-indicator_new ()
3665-{
3666- IndicatorPlugin *indicator;
3667- GtkOrientation orientation;
3668- gint indicators_loaded = 0;
3669-
3670- /* Hack! prevent the appmenu indicator from swallowing our own menubar */
3671- setenv("APPMENU_DISPLAY_BOTH", "1");
3672-
3673- /* allocate memory for the plugin structure */
3674- indicator = g_new (IndicatorPlugin, 1);
3675-
3676- indicator->container = gtk_plug_new(0);
3677-
3678- /* Init some theme/icon stuff */
3679- g_object_set (gtk_settings_get_default(), "gtk-theme-name", "Ambiance", NULL);
3680- g_object_set (gtk_settings_get_default(), "gtk-icon-theme-name", "ubuntu-mono-dark", NULL);
3681- gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
3682- INDICATOR_ICONS_DIR);
3683- gtk_rc_parse_string (
3684- "widget \"indicator-applet*\" style \"panel\"\n"
3685- "style \"indicator-applet-style\"\n"
3686- "{\n"
3687- " GtkMenuBar::shadow-type = none\n"
3688- " GtkMenuBar::internal-padding = 0\n"
3689- " GtkWidget::focus-line-width = 0\n"
3690- " GtkWidget::focus-padding = 0\n"
3691- "}\n"
3692- "style \"indicator-applet-menubar-style\"\n"
3693- "{\n"
3694- " GtkMenuBar::shadow-type = none\n"
3695- " GtkMenuBar::internal-padding = 0\n"
3696- " GtkWidget::focus-line-width = 0\n"
3697- " GtkWidget::focus-padding = 0\n"
3698- " GtkMenuItem::horizontal-padding = 0\n"
3699- "}\n"
3700- "style \"indicator-applet-menuitem-style\"\n"
3701- "{\n"
3702- " GtkWidget::focus-line-width = 0\n"
3703- " GtkWidget::focus-padding = 0\n"
3704- " GtkMenuItem::horizontal-padding = 0\n"
3705- "}\n"
3706- "widget \"*.indicator-applet\" style \"indicator-applet-style\""
3707- "widget \"*.indicator-applet-menuitem\" style \"indicator-applet-menuitem-style\""
3708- "widget \"*.indicator-applet-menubar\" style \"indicator-applet-menubar-style\"");
3709- gtk_widget_set_name(GTK_WIDGET (indicator->container), "indicator-applet");
3710- /* create some panel widgets */
3711-
3712- /* Build menu */
3713- indicator->menu = gtk_menu_bar_new();
3714- GTK_WIDGET_SET_FLAGS (indicator->menu, GTK_WIDGET_FLAGS(indicator->menu) | GTK_CAN_FOCUS);
3715- gtk_widget_set_name(GTK_WIDGET (indicator->menu), "indicator-applet-menubar");
3716- g_signal_connect(indicator->menu, "button-press-event", G_CALLBACK(on_menu_press), NULL);
3717- //g_signal_connect_after(indicator->menu, "expose-event", G_CALLBACK(menu_on_expose), menu);
3718- gtk_container_set_border_width(GTK_CONTAINER(indicator->menu), 0);
3719-
3720- /* load 'em */
3721- if (!g_file_test(INDICATOR_DIR, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
3722- g_warning ("%s does not exist, cannot read any indicators", INDICATOR_DIR);
3723- } else {
3724- GDir *dir;
3725- const gchar *name;
3726-
3727- dir = g_dir_open(INDICATOR_DIR, 0, NULL);
3728- while ((name = g_dir_read_name (dir)) != NULL) {
3729- if (g_strcmp0(name, "libappmenu.so") == 0) {
3730- continue;
3731- }
3732-
3733- if (load_module(name, indicator->menu)) {
3734- indicators_loaded++;
3735- } else {
3736- g_warning("Failed to load module %s", name);
3737- }
3738- }
3739- g_dir_close(dir);
3740- }
3741-
3742- if (indicators_loaded == 0) {
3743- /* A label to allow for click through */
3744- indicator->item = gtk_button_new();
3745- gtk_button_set_label(GTK_BUTTON(indicator->item), "No Indicators");
3746- gtk_widget_show(indicator->item);
3747- gtk_container_add (GTK_CONTAINER (indicator->container), indicator->item);
3748- } else {
3749- gtk_widget_show(indicator->menu);
3750- gtk_container_add (GTK_CONTAINER (indicator->container), indicator->menu);
3751- }
3752- return indicator;
3753-}
3754-
3755-
3756-
3757-void
3758-indicator_free (IndicatorPlugin *indicator)
3759-{
3760- g_free(indicator);
3761-}
3762-
3763-
3764-#if 0
3765-static gboolean
3766-indicator_size_changed (XfcePanelPlugin *plugin,
3767- gint size,
3768- IndicatorPlugin *indicator)
3769-{
3770- GtkOrientation orientation;
3771-
3772- /* get the orientation of the plugin */
3773- orientation = xfce_panel_plugin_get_orientation (plugin);
3774-
3775- /* set the widget size */
3776- if (orientation == GTK_ORIENTATION_HORIZONTAL)
3777- gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
3778- else
3779- gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
3780-
3781- /* we handled the orientation */
3782- return TRUE;
3783-}
3784-#endif
3785-
3786-
3787-static gboolean
3788-on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
3789-{
3790- if (indicator != NULL && event->button == 1) /* left click only */
3791- {
3792- /* gtk_menu_popup (GTK_MENU(indicator->menu), NULL, NULL, NULL, NULL, 0,
3793- event->time);*/
3794- return TRUE;
3795- }
3796- return FALSE ;
3797-}
3798
3799=== removed file 'panel/applets/indicator/indicator.h'
3800--- panel/applets/indicator/indicator.h 2011-06-22 14:49:34 +0000
3801+++ panel/applets/indicator/indicator.h 1970-01-01 00:00:00 +0000
3802@@ -1,45 +0,0 @@
3803-/* Copyright (c) 2009 Mark Trompell <mark@foresightlinux.org>
3804- *
3805- * This program is free software; you can redistribute it and/or modify
3806- * it under the terms of the GNU General Public License as published by
3807- * the Free Software Foundation; either version 2 of the License, or
3808- * (at your option) any later version.
3809- *
3810- * This program is distributed in the hope that it will be useful,
3811- * but WITHOUT ANY WARRANTY; without even the implied warranty of
3812- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3813- * GNU Library General Public License for more details.
3814- *
3815- * You should have received a copy of the GNU General Public License
3816- * along with this program; if not, write to the Free Software
3817- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3818- */
3819-
3820-#ifndef __INDICATOR_H__
3821-#define __INDICATOR_H__
3822-
3823-#include <gtk/gtk.h>
3824-
3825-G_BEGIN_DECLS
3826-
3827-/* plugin structure */
3828-typedef struct _IndicatorPlugin
3829-{
3830- GtkWidget *container;
3831- /* panel widgets */
3832- GtkWidget *menu;
3833- GtkWidget *item;
3834-
3835- /* indicator settings */
3836-}
3837-IndicatorPlugin;
3838-
3839-IndicatorPlugin *
3840-indicator_new ();
3841-
3842-void
3843-indicator_free(IndicatorPlugin*);
3844-
3845-G_END_DECLS
3846-
3847-#endif /* !__INDICATOR_H__ */
3848
3849=== added file 'panel/applets/indicator/indicatorapplet.cpp'
3850--- panel/applets/indicator/indicatorapplet.cpp 1970-01-01 00:00:00 +0000
3851+++ panel/applets/indicator/indicatorapplet.cpp 2011-07-18 14:37:40 +0000
3852@@ -0,0 +1,58 @@
3853+/*
3854+ * This file is part of unity-2d
3855+ *
3856+ * Copyright 2011 Canonical Ltd.
3857+ *
3858+ * Authors:
3859+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
3860+ *
3861+ * This program is free software; you can redistribute it and/or modify
3862+ * it under the terms of the GNU General Public License as published by
3863+ * the Free Software Foundation; version 3.
3864+ *
3865+ * This program is distributed in the hope that it will be useful,
3866+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3867+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3868+ * GNU General Public License for more details.
3869+ *
3870+ * You should have received a copy of the GNU General Public License
3871+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
3872+ */
3873+// Self
3874+#include "indicatorapplet.h"
3875+
3876+// Local
3877+#include <debug_p.h>
3878+#include <indicatorsmanager.h>
3879+#include <indicatorwidget.h>
3880+
3881+// Qt
3882+#include <QHBoxLayout>
3883+
3884+using namespace unity::indicator;
3885+
3886+IndicatorApplet::IndicatorApplet(IndicatorsManager* manager)
3887+: m_indicatorsManager(manager)
3888+{
3889+ QHBoxLayout* layout = new QHBoxLayout(this);
3890+ layout->setMargin(0);
3891+ layout->setSpacing(0);
3892+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
3893+
3894+ m_indicatorsManager->indicators()->on_object_added.connect(
3895+ sigc::mem_fun(this, &IndicatorApplet::onObjectAdded)
3896+ );
3897+}
3898+
3899+void IndicatorApplet::onObjectAdded(Indicator::Ptr const& indicator)
3900+{
3901+ QString name = QString::fromStdString(indicator->name());
3902+ if (name == "libappmenu.so") {
3903+ // appmenu indicator is handled by AppNameApplet
3904+ return;
3905+ }
3906+ IndicatorWidget* widget = new IndicatorWidget(indicator, m_indicatorsManager);
3907+ layout()->addWidget(widget);
3908+}
3909+
3910+#include "indicatorapplet.moc"
3911
3912=== removed file 'panel/applets/indicator/indicatorapplet.cpp'
3913--- panel/applets/indicator/indicatorapplet.cpp 2011-06-22 14:49:34 +0000
3914+++ panel/applets/indicator/indicatorapplet.cpp 1970-01-01 00:00:00 +0000
3915@@ -1,114 +0,0 @@
3916-/*
3917- * This file is part of unity-2d
3918- *
3919- * Copyright 2010 Canonical Ltd.
3920- *
3921- * Authors:
3922- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
3923- *
3924- * This program is free software; you can redistribute it and/or modify
3925- * it under the terms of the GNU General Public License as published by
3926- * the Free Software Foundation; version 3.
3927- *
3928- * This program is distributed in the hope that it will be useful,
3929- * but WITHOUT ANY WARRANTY; without even the implied warranty of
3930- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3931- * GNU General Public License for more details.
3932- *
3933- * You should have received a copy of the GNU General Public License
3934- * along with this program. If not, see <http://www.gnu.org/licenses/>.
3935- */
3936-
3937-// Self
3938-#include "indicatorapplet.h"
3939-
3940-// Local
3941-#include "abstractindicator.h"
3942-#include "datetimeindicator.h"
3943-#include "debug_p.h"
3944-#include "indicator.h"
3945-
3946-// Qt
3947-#include <QAction>
3948-#include <QDBusConnection>
3949-#include <QHBoxLayout>
3950-#include <QMenu>
3951-#include <QX11EmbedContainer>
3952-
3953-// Gtk
3954-#include <gdk/gdk.h>
3955-#include <gtk/gtk.h>
3956-
3957-IndicatorApplet::IndicatorApplet()
3958-{
3959- setupUi();
3960- loadIndicators();
3961-}
3962-
3963-void IndicatorApplet::setupUi()
3964-{
3965- m_menuBar = new QMenuBar;
3966- m_menuBar->setNativeMenuBar(false);
3967- QHBoxLayout* layout = new QHBoxLayout(this);
3968- layout->setMargin(0);
3969- layout->addWidget(m_menuBar);
3970-
3971- QMetaObject::invokeMethod(this, "createGtkIndicator", Qt::QueuedConnection);
3972-}
3973-
3974-void IndicatorApplet::createGtkIndicator()
3975-{
3976- int* argc = 0;
3977- char*** argv = 0;
3978- gtk_init(argc, argv);
3979-
3980- m_container = new QX11EmbedContainer;
3981- layout()->addWidget(m_container);
3982-
3983- m_gtkIndicator = indicator_new();
3984- m_container->embedClient(gtk_plug_get_id(GTK_PLUG(m_gtkIndicator->container)));
3985- gtk_widget_show(m_gtkIndicator->container);
3986-
3987- QTimer* timer = new QTimer(this);
3988- timer->setInterval(1000);
3989- timer->setSingleShot(false);
3990- connect(timer, SIGNAL(timeout()), SLOT(adjustGtkIndicatorSize()));
3991- timer->start();
3992-}
3993-
3994-void IndicatorApplet::adjustGtkIndicatorSize()
3995-{
3996- GtkRequisition requisition;
3997- gtk_widget_size_request(m_gtkIndicator->menu, &requisition);
3998- m_container->setFixedWidth(requisition.width);
3999-}
4000-
4001-void IndicatorApplet::loadIndicators()
4002-{
4003-#if 0
4004- // FIXME: Using Qt plugins
4005- QList<AbstractIndicator*> indicators = QList<AbstractIndicator*>()
4006- << new DateTimeIndicator(this)
4007- ;
4008-
4009- Q_FOREACH(AbstractIndicator* indicator, indicators) {
4010- connect(indicator, SIGNAL(actionAdded(QAction*)), SLOT(slotActionAdded(QAction*)));
4011- connect(indicator, SIGNAL(actionRemoved(QAction*)), SLOT(slotActionRemoved(QAction*)));
4012- indicator->init();
4013- }
4014-#endif
4015-}
4016-
4017-void IndicatorApplet::slotActionAdded(QAction* action)
4018-{
4019- UQ_VAR(action->text());
4020- m_menuBar->addAction(action);
4021-}
4022-
4023-void IndicatorApplet::slotActionRemoved(QAction* action)
4024-{
4025- m_menuBar->removeAction(action);
4026-}
4027-
4028-
4029-#include "indicatorapplet.moc"
4030
4031=== added file 'panel/applets/indicator/indicatorapplet.h'
4032--- panel/applets/indicator/indicatorapplet.h 1970-01-01 00:00:00 +0000
4033+++ panel/applets/indicator/indicatorapplet.h 2011-07-18 14:37:40 +0000
4034@@ -0,0 +1,45 @@
4035+/*
4036+ * This file is part of unity-2d
4037+ *
4038+ * Copyright 2011 Canonical Ltd.
4039+ *
4040+ * Authors:
4041+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
4042+ *
4043+ * This program is free software; you can redistribute it and/or modify
4044+ * it under the terms of the GNU General Public License as published by
4045+ * the Free Software Foundation; version 3.
4046+ *
4047+ * This program is distributed in the hope that it will be useful,
4048+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4049+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4050+ * GNU General Public License for more details.
4051+ *
4052+ * You should have received a copy of the GNU General Public License
4053+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
4054+ */
4055+
4056+#ifndef INDICATORAPPLET_H
4057+#define INDICATORAPPLET_H
4058+
4059+// Local
4060+#include <applet.h>
4061+
4062+// libunity-core
4063+#include <UnityCore/UnityCore.h>
4064+
4065+class IndicatorsManager;
4066+
4067+class IndicatorApplet : public Unity2d::Applet, public sigc::trackable
4068+{
4069+Q_OBJECT
4070+public:
4071+ IndicatorApplet(IndicatorsManager* manager);
4072+
4073+private:
4074+ Q_DISABLE_COPY(IndicatorApplet)
4075+ IndicatorsManager* m_indicatorsManager;
4076+ void onObjectAdded(unity::indicator::Indicator::Ptr const&);
4077+};
4078+
4079+#endif /* INDICATORAPPLET_H */
4080
4081=== removed file 'panel/applets/indicator/indicatorapplet.h'
4082--- panel/applets/indicator/indicatorapplet.h 2011-01-15 01:41:03 +0000
4083+++ panel/applets/indicator/indicatorapplet.h 1970-01-01 00:00:00 +0000
4084@@ -1,60 +0,0 @@
4085-/*
4086- * This file is part of unity-2d
4087- *
4088- * Copyright 2010 Canonical Ltd.
4089- *
4090- * Authors:
4091- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
4092- *
4093- * This program is free software; you can redistribute it and/or modify
4094- * it under the terms of the GNU General Public License as published by
4095- * the Free Software Foundation; version 3.
4096- *
4097- * This program is distributed in the hope that it will be useful,
4098- * but WITHOUT ANY WARRANTY; without even the implied warranty of
4099- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4100- * GNU General Public License for more details.
4101- *
4102- * You should have received a copy of the GNU General Public License
4103- * along with this program. If not, see <http://www.gnu.org/licenses/>.
4104- */
4105-
4106-#ifndef INDICATORAPPLET_H
4107-#define INDICATORAPPLET_H
4108-
4109-// Local
4110-#include <applet.h>
4111-
4112-// Qt
4113-#include <QDBusInterface>
4114-#include <QMenuBar>
4115-
4116-class QX11EmbedContainer;
4117-
4118-struct _IndicatorPlugin;
4119-
4120-class IndicatorApplet : public Unity2d::Applet
4121-{
4122-Q_OBJECT
4123-public:
4124- IndicatorApplet();
4125-
4126-private Q_SLOTS:
4127- void loadIndicators();
4128- void slotActionAdded(QAction*);
4129- void slotActionRemoved(QAction*);
4130- void createGtkIndicator();
4131- void adjustGtkIndicatorSize();
4132-
4133-private:
4134- Q_DISABLE_COPY(IndicatorApplet)
4135-
4136- QDBusInterface* m_watcher;
4137- QMenuBar* m_menuBar;
4138- QX11EmbedContainer* m_container;
4139- struct _IndicatorPlugin* m_gtkIndicator;
4140-
4141- void setupUi();
4142-};
4143-
4144-#endif /* INDICATORAPPLET_H */
4145
4146=== removed file 'panel/applets/indicator/indicatorservicemanager.cpp'
4147--- panel/applets/indicator/indicatorservicemanager.cpp 2011-02-10 01:10:19 +0000
4148+++ panel/applets/indicator/indicatorservicemanager.cpp 1970-01-01 00:00:00 +0000
4149@@ -1,120 +0,0 @@
4150-/*
4151- * This file is part of unity-2d
4152- *
4153- * Copyright 2010 Canonical Ltd.
4154- *
4155- * Authors:
4156- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
4157- *
4158- * This program is free software; you can redistribute it and/or modify
4159- * it under the terms of the GNU General Public License as published by
4160- * the Free Software Foundation; version 3.
4161- *
4162- * This program is distributed in the hope that it will be useful,
4163- * but WITHOUT ANY WARRANTY; without even the implied warranty of
4164- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4165- * GNU General Public License for more details.
4166- *
4167- * You should have received a copy of the GNU General Public License
4168- * along with this program. If not, see <http://www.gnu.org/licenses/>.
4169- */
4170-
4171-// Self
4172-#include "indicatorservicemanager.h"
4173-
4174-// Local
4175-#include "debug_p.h"
4176-
4177-// Qt
4178-#include <QAction>
4179-#include <QDBusConnection>
4180-#include <QDBusConnectionInterface>
4181-#include <QDBusMessage>
4182-#include <QDBusServiceWatcher>
4183-#include <QDBusReply>
4184-#include <QDBusInterface>
4185-
4186-static const char* INDICATOR_SERVICE_INTERFACE = "com.canonical.indicator.service";
4187-static const char* INDICATOR_SERVICE_OBJECT = "/com.canonical/indicator/service";
4188-static const uint INDICATOR_SERVICE_VERSION = 1;
4189-
4190-IndicatorServiceManager::IndicatorServiceManager(const char* name, uint version, QObject* parent)
4191-: QObject(parent)
4192-, m_serviceName(name)
4193-, m_serviceVersion(version)
4194-{
4195- QDBusServiceWatcher* serviceWatcher = new QDBusServiceWatcher(this);
4196- serviceWatcher->setConnection(QDBusConnection::sessionBus());
4197- serviceWatcher->addWatchedService(m_serviceName);
4198- connect(serviceWatcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
4199- SLOT(slotServiceOwnerChanged(QString, QString, QString)));
4200- connectToService();
4201-}
4202-
4203-IndicatorServiceManager::~IndicatorServiceManager()
4204-{
4205- unwatchService();
4206-}
4207-
4208-void IndicatorServiceManager::connectToService()
4209-{
4210- QDBusConnectionInterface* iface = QDBusConnection::sessionBus().interface();
4211- QDBusReply<bool> reply = iface->isServiceRegistered(m_serviceName);
4212- UQ_RETURN_IF_FAIL(reply.isValid());
4213-
4214- if (reply.value()) {
4215- watchService();
4216- } else {
4217- QDBusReply<void> reply = iface->startService(m_serviceName);
4218- if (!reply.isValid()) {
4219- UQ_WARNING << reply.error().message();
4220- }
4221- }
4222-}
4223-
4224-void IndicatorServiceManager::watchService()
4225-{
4226- QDBusInterface iface(m_serviceName, INDICATOR_SERVICE_OBJECT, INDICATOR_SERVICE_INTERFACE);
4227- QDBusPendingCall pending = iface.asyncCall("Watch");
4228- QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(pending, this);
4229- connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(slotWatchFinished(QDBusPendingCallWatcher*)));
4230-}
4231-
4232-void IndicatorServiceManager::slotWatchFinished(QDBusPendingCallWatcher* watcher)
4233-{
4234- QDBusMessage message = watcher->reply();
4235- delete watcher;
4236- UQ_RETURN_IF_FAIL(message.type() == QDBusMessage::ReplyMessage);
4237- QVariantList args = message.arguments();
4238- UQ_RETURN_IF_FAIL(args.count() == 2);
4239-
4240- uint apiVersion = args.at(0).toUInt();
4241- uint serviceVersion = args.at(1).toUInt();
4242-
4243- if (apiVersion != INDICATOR_SERVICE_VERSION) {
4244- UQ_WARNING << "Expected api version=" << INDICATOR_SERVICE_VERSION << "got" << apiVersion << "instead";
4245- unwatchService();
4246- return;
4247- }
4248- if (serviceVersion != m_serviceVersion) {
4249- UQ_WARNING << "Expected service version=" << m_serviceVersion << "got" << serviceVersion << "instead";
4250- unwatchService();
4251- }
4252-}
4253-
4254-void IndicatorServiceManager::unwatchService()
4255-{
4256- QDBusInterface iface(m_serviceName, INDICATOR_SERVICE_OBJECT, INDICATOR_SERVICE_INTERFACE);
4257- iface.asyncCall("Unwatch");
4258-}
4259-
4260-void IndicatorServiceManager::slotServiceOwnerChanged(const QString& /*name*/, const QString& /*oldOwner*/, const QString& newOwner)
4261-{
4262- if (newOwner.isNull()) {
4263- // FIXME: Respawn
4264- } else {
4265- watchService();
4266- }
4267-}
4268-
4269-#include "indicatorservicemanager.moc"
4270
4271=== removed file 'panel/applets/indicator/indicatorservicemanager.h'
4272--- panel/applets/indicator/indicatorservicemanager.h 2011-01-15 01:41:03 +0000
4273+++ panel/applets/indicator/indicatorservicemanager.h 1970-01-01 00:00:00 +0000
4274@@ -1,54 +0,0 @@
4275-/*
4276- * This file is part of unity-2d
4277- *
4278- * Copyright 2010 Canonical Ltd.
4279- *
4280- * Authors:
4281- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
4282- *
4283- * This program is free software; you can redistribute it and/or modify
4284- * it under the terms of the GNU General Public License as published by
4285- * the Free Software Foundation; version 3.
4286- *
4287- * This program is distributed in the hope that it will be useful,
4288- * but WITHOUT ANY WARRANTY; without even the implied warranty of
4289- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4290- * GNU General Public License for more details.
4291- *
4292- * You should have received a copy of the GNU General Public License
4293- * along with this program. If not, see <http://www.gnu.org/licenses/>.
4294- */
4295-
4296-#ifndef INDICATORSERVICEMANAGER_H
4297-#define INDICATORSERVICEMANAGER_H
4298-
4299-// Local
4300-
4301-// Qt
4302-#include <QObject>
4303-
4304-class QAction;
4305-class QDBusPendingCallWatcher;
4306-
4307-class IndicatorServiceManager : public QObject
4308-{
4309- Q_OBJECT
4310-public:
4311- IndicatorServiceManager(const char* name, uint version, QObject* parent=0);
4312- ~IndicatorServiceManager();
4313-
4314-private Q_SLOTS:
4315- void slotServiceOwnerChanged(const QString& name, const QString& oldOwner, const QString& newOwner);
4316- void slotWatchFinished(QDBusPendingCallWatcher*);
4317-
4318-private:
4319- Q_DISABLE_COPY(IndicatorServiceManager)
4320- QString m_serviceName;
4321- uint m_serviceVersion;
4322-
4323- void connectToService();
4324- void watchService();
4325- void unwatchService();
4326-};
4327-
4328-#endif /* INDICATORSERVICEMANAGER_H */
4329
4330=== removed directory 'panel/artwork'
4331=== removed file 'panel/artwork/background.png'
4332Binary files panel/artwork/background.png 2010-11-23 16:13:46 +0000 and panel/artwork/background.png 1970-01-01 00:00:00 +0000 differ
4333=== removed file 'panel/artwork/divider.png'
4334Binary files panel/artwork/divider.png 2010-11-23 16:13:46 +0000 and panel/artwork/divider.png 1970-01-01 00:00:00 +0000 differ
4335=== modified file 'places/app/CMakeLists.txt'
4336--- places/app/CMakeLists.txt 2011-03-08 09:20:02 +0000
4337+++ places/app/CMakeLists.txt 2011-07-18 14:37:40 +0000
4338@@ -1,7 +1,5 @@
4339 # Dependencies
4340-find_package(X11 REQUIRED)
4341 pkg_check_modules(QTGCONF REQUIRED libqtgconf)
4342-pkg_check_modules(GTK REQUIRED gtk+-2.0)
4343
4344 # Sources
4345 set(places_SRCS
4346
4347=== modified file 'places/app/places.cpp'
4348--- places/app/places.cpp 2011-06-27 13:43:05 +0000
4349+++ places/app/places.cpp 2011-07-18 14:37:40 +0000
4350@@ -31,9 +31,8 @@
4351
4352 #include <X11/Xlib.h>
4353
4354-#include <gtk/gtk.h>
4355-
4356 // unity-2d
4357+#include <unity2dapplication.h>
4358 #include <unity2ddebug.h>
4359
4360 #include "dashdeclarativeview.h"
4361@@ -41,23 +40,8 @@
4362
4363 int main(int argc, char *argv[])
4364 {
4365- /* gtk needs to be inited, otherwise we get an assert failure in gdk */
4366- gtk_init(&argc, &argv);
4367- Unity2dDebug::installHandlers();
4368-
4369- /* When the environment variable QT_GRAPHICSSYSTEM is not set,
4370- force graphics system to 'raster' instead of the default 'native'
4371- which on X11 is 'XRender'.
4372- 'XRender' defaults to using a TrueColor visual. We do _not_ mimick that
4373- behaviour with 'raster' by calling QApplication::setColorSpec because
4374- of a bug where some pixmaps become blueish:
4375-
4376- https://bugs.launchpad.net/unity-2d/+bug/689877
4377- */
4378- if(getenv("QT_GRAPHICSSYSTEM") == 0) {
4379- QApplication::setGraphicsSystem("raster");
4380- }
4381- QApplication application(argc, argv);
4382+ Unity2dApplication::earlySetup(argc, argv);
4383+ Unity2dApplication application(argc, argv);
4384 QSet<QString> arguments = QSet<QString>::fromList(QCoreApplication::arguments());
4385
4386 qmlRegisterType<DashDeclarativeView>("Unity2d", 1, 0, "DashDeclarativeView");
4387
4388=== modified file 'spread/app/CMakeLists.txt'
4389--- spread/app/CMakeLists.txt 2011-03-07 14:52:11 +0000
4390+++ spread/app/CMakeLists.txt 2011-07-18 14:37:40 +0000
4391@@ -1,7 +1,3 @@
4392-# Dependencies
4393-pkg_check_modules(GTK REQUIRED gtk+-2.0)
4394-find_package(X11 REQUIRED)
4395-
4396 # Sources
4397 set(spread_SRCS
4398 spread.cpp
4399
4400=== modified file 'spread/app/spread.cpp'
4401--- spread/app/spread.cpp 2011-06-22 08:33:52 +0000
4402+++ spread/app/spread.cpp 2011-07-18 14:37:40 +0000
4403@@ -18,7 +18,6 @@
4404 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4405 */
4406
4407-#include <gtk/gtk.h>
4408 #include <QApplication>
4409 #include <QDesktopWidget>
4410 #include <QDeclarativeEngine>
4411@@ -28,31 +27,14 @@
4412 #include "spreadcontrol.h"
4413 #include "launcherclient.h"
4414
4415-#include <unity2ddebug.h>
4416+#include <unity2dapplication.h>
4417
4418 #include "config.h"
4419
4420 int main(int argc, char *argv[])
4421 {
4422- /* Unity2d plugin uses GTK APIs to retrieve theme icons
4423- (gtk_icon_theme_get_default) and requires a call to gtk_init */
4424- gtk_init(&argc, &argv);
4425-
4426- Unity2dDebug::installHandlers();
4427-
4428- /* When the environment variable QT_GRAPHICSSYSTEM is not set,
4429- force graphics system to 'raster' instead of the default 'native'
4430- which on X11 is 'XRender'.
4431- 'XRender' defaults to using a TrueColor visual. We do _not_ mimick that
4432- behaviour with 'raster' by calling QApplication::setColorSpec because
4433- of a bug where some pixmaps become blueish:
4434-
4435- https://bugs.launchpad.net/unity-2d/+bug/689877
4436- */
4437- if(getenv("QT_GRAPHICSSYSTEM") == 0) {
4438- QApplication::setGraphicsSystem("raster");
4439- }
4440- QApplication application(argc, argv);
4441+ Unity2dApplication::earlySetup(argc, argv);
4442+ Unity2dApplication application(argc, argv);
4443 QSet<QString> arguments = QSet<QString>::fromList(QCoreApplication::arguments());
4444
4445 SpreadView view;

Subscribers

People subscribed via source and target branches