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

Proposed by Aurélien Gâteau
Status: Merged
Approved by: Florian Boucault
Approved revision: 687
Merged at revision: 609
Proposed branch: lp:~agateau/unity-2d/unity-core
Merge into: lp:unity-2d
Diff against target: 4163 lines (+1408/-2079)
48 files modified
CMakeLists.txt (+3/-3)
debian/control (+5/-4)
debian/unity-2d-panel.install (+0/-2)
libunity-2d-private/Unity2d/CMakeLists.txt (+1/-1)
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/-0)
libunity-2d-private/src/debug.cpp (+23/-0)
libunity-2d-private/src/debug_p.h (+6/-0)
libunity-2d-private/src/unity2dapplication.cpp (+18/-0)
panel/CMakeLists.txt (+3/-5)
panel/app/CMakeLists.txt (+3/-1)
panel/app/main.cpp (+4/-2)
panel/app/panelmanager.cpp (+33/-46)
panel/app/panelmanager.h (+2/-0)
panel/app/unity2dstyle.cpp (+0/-98)
panel/app/unity2dstyle.h (+0/-44)
panel/applets/CMakeLists.txt (+10/-26)
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 (+78/-279)
panel/applets/appname/menubarwidget.h (+25/-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 (+176/-0)
panel/applets/common/indicatorsmanager.h (+70/-0)
panel/applets/common/indicatorwidget.cpp (+53/-0)
panel/applets/common/indicatorwidget.h (+52/-0)
panel/applets/common/panelstyle.cpp (+175/-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/-525)
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)
To merge this branch: bzr merge lp:~agateau/unity-2d/unity-core
Reviewer Review Type Date Requested Status
Tim Penhey Pending
Florian Boucault Pending
Review via email: mp+69451@code.launchpad.net

This proposal supersedes a proposal from 2011-07-25.

Commit message

[panel] Refactor panel to use the unity-panel-service shared with Unity 3D.

Description of the change

This branch is an heavy refactor of unity-2d-panel to use the new unity-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 and UnityCore, a new library provided by Unity 3D.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

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
Revision history for this message
Aurélien Gâteau (agateau) wrote : Posted in a previous version of this proposal

> 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.

Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

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.

Revision history for this message
Aurélien Gâteau (agateau) wrote : Posted in a previous version of this proposal

> 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

Revision history for this message
Florian Boucault (fboucault) wrote : Posted in a previous version of this proposal

lp:unity-2d/4.0 saw quite a few updates which caused a couple of conflicts. Do you mind fixing them while I do the code review?

Revision history for this message
Florian Boucault (fboucault) wrote : Posted in a previous version of this proposal

It seems like quite a few panel bugs got fixed by this piece, nice!

I don't see any background gradient in the panel anymore, is that expected?
Also the datetime indicator is there but tiny (easy to spot by navigating with the keyboard in the panel).

Revision history for this message
Florian Boucault (fboucault) wrote : Posted in a previous version of this proposal

> Also the datetime indicator is there but tiny (easy to spot by navigating with
> the keyboard in the panel).

This is fixed now for some reason.

Revision history for this message
Florian Boucault (fboucault) wrote : Posted in a previous version of this proposal

* Height of 24 pixels is hardcoded in various places. It would be nice to define it only once.

* Texts in panel do not have a shadow (sunken) like in Unity 3D.
* In the indicator with the username displayed in it (is it called 'me menu'?), the icon is not vertically centered like in Unity 3D.

* In panel/applets/appname/menubarwidget.cpp:

bool MenuBarWidget::isOpened() const
{
    // FIXME
[...]

What is the FIXME about?

* Do you know why does the shared panel backend need to know about the geometry of the indicators?

Have you tested the new panel with multiple monitors? I don't have the means to do it at the moment unfortunately.

review: Needs Fixing
Revision history for this message
Aurélien Gâteau (agateau) wrote : Posted in a previous version of this proposal

> lp:unity-2d/4.0 saw quite a few updates which caused a couple of conflicts. Do
> you mind fixing them while I do the code review?

I have a whole stack of branches right now but they are targeting trunk, not 4.0. Should I change this so they all target 4.0?

Revision history for this message
Aurélien Gâteau (agateau) wrote : Posted in a previous version of this proposal

> It seems like quite a few panel bugs got fixed by this piece, nice!
>
> I don't see any background gradient in the panel anymore, is that expected?

This is fixed in the next branch (use-gtk-rendering)

Revision history for this message
Aurélien Gâteau (agateau) wrote : Posted in a previous version of this proposal

> * Height of 24 pixels is hardcoded in various places. It would be nice to
> define it only once.

Yes, I got rid of a few of them in the use-gtk-rendering branch, but there are a few remainings.

> * Texts in panel do not have a shadow (sunken) like in Unity 3D.
> * In the indicator with the username displayed in it (is it called 'me
> menu'?), the icon is not vertically centered like in Unity 3D.

Both fixed in use-gtk-rendering.

> * In panel/applets/appname/menubarwidget.cpp:
>
> bool MenuBarWidget::isOpened() const
> {
> // FIXME
> [...]
>
> What is the FIXME about?

I just forgot to remove the comment. Fixed.

>
> * Do you know why does the shared panel backend need to know about the
> geometry of the indicators?

This is for accessibility support.

> Have you tested the new panel with multiple monitors? I don't have the means
> to do it at the moment unfortunately.

No I haven't. Will do.

Revision history for this message
Florian Boucault (fboucault) wrote : Posted in a previous version of this proposal

> > lp:unity-2d/4.0 saw quite a few updates which caused a couple of conflicts.
> Do
> > you mind fixing them while I do the code review?
>
> I have a whole stack of branches right now but they are targeting trunk, not
> 4.0. Should I change this so they all target 4.0?

Please do. 4.0 is basically the branch targetting oneiric.
For this MR you can drop the prerequisite lp:~agateau/unity-2d/gtk3 as this branch cannot be merged on its own: it basically breaks the indicators more than anything else and I reviewed its code changes as part of this MR.

Revision history for this message
Florian Boucault (fboucault) wrote : Posted in a previous version of this proposal

Once you resubmitted this one and we are sure it works as before on multi monitors setup, it's good to merge (it will need a commit message).
I am onto https://code.launchpad.net/~agateau/unity-2d/use-gtk-rendering/+merge/69113 now.

lp:~agateau/unity-2d/unity-core updated
686. By Aurélien Gâteau

Sync with unity-2d/4.0

687. By Aurélien Gâteau

[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.

Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

On Wed, 27 Jul 2011 23:39:33 you wrote:
> Please do. 4.0 is basically the branch targetting oneiric.
> For this MR you can drop the prerequisite lp:~agateau/unity-2d/gtk3 as this
> branch cannot be merged on its own: it basically breaks the indicators
> more than anything else and I reviewed its code changes as part of this
> MR.

Florian,

I regularly have dependent branches that can't be landed by themselves. It is
useful for review purposes. Showing particular changes in their own branch
can make reviews much easier. Merge proposals don't have to be landable by
themselves.

Launchpad knows when branches are merged, and when the subsequent merge
proposal is landed, the dependent merge proposal is marked as merged as well.

Tim

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

Subscribers

People subscribed via source and target branches