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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2011-07-27 09:42:32 +0000
+++ CMakeLists.txt 2011-07-27 15:26:24 +0000
@@ -25,10 +25,10 @@
25find_package(X11 REQUIRED)25find_package(X11 REQUIRED)
26find_package(Gettext REQUIRED)26find_package(Gettext REQUIRED)
27pkg_check_modules(GLIB REQUIRED glib-2.0)27pkg_check_modules(GLIB REQUIRED glib-2.0)
28pkg_check_modules(GDK REQUIRED gdk-2.0)28pkg_check_modules(GDK REQUIRED gdk-3.0)
29pkg_check_modules(GTK REQUIRED gtk+-2.0)29pkg_check_modules(GTK REQUIRED gtk+-3.0)
30pkg_check_modules(GIO REQUIRED gio-2.0)30pkg_check_modules(GIO REQUIRED gio-2.0)
31pkg_check_modules(WNCK REQUIRED libwnck-1.0)31pkg_check_modules(WNCK REQUIRED libwnck-3.0)
3232
3333
34# GSettings schemas34# GSettings schemas
3535
=== modified file 'debian/control'
--- debian/control 2011-07-26 16:16:52 +0000
+++ debian/control 2011-07-27 15:26:24 +0000
@@ -10,17 +10,18 @@
10 libqt4-dev,10 libqt4-dev,
11 libqt4-opengl-dev,11 libqt4-opengl-dev,
12 libglib2.0-dev,12 libglib2.0-dev,
13 libwnck-dev,13 libwnck-3-dev,
14 libqtgconf-dev,14 libqtgconf-dev,
15 libdconf-qt-dev,15 libdconf-qt-dev,
16 libqtbamf-dev,16 libqtbamf-dev,
17 libqtdee-dev,17 libqtdee-dev,
18 libdbusmenu-qt-dev,18 libdbusmenu-qt-dev,
19 libx11-dev,19 libx11-dev,
20 libindicator-dev (>= 0.3.90),20 libindicator3-dev,
21 libgtk2.0-dev,21 libgtk-3-dev,
22 libutouch-geis-dev,22 libutouch-geis-dev,
23 libstartup-notification0-dev23 libstartup-notification0-dev,
24 libunity-core-4.0-dev,
24Standards-Version: 3.9.225Standards-Version: 3.9.2
25Vcs-Bzr: http://bazaar.launchpad.net/~unity-2d-team/unity-2d/oneiric26Vcs-Bzr: http://bazaar.launchpad.net/~unity-2d-team/unity-2d/oneiric
2627
2728
=== modified file 'debian/unity-2d-panel.install'
--- debian/unity-2d-panel.install 2011-01-14 21:41:39 +0000
+++ debian/unity-2d-panel.install 2011-07-27 15:26:24 +0000
@@ -1,4 +1,2 @@
1usr/bin/unity-2d-panel1usr/bin/unity-2d-panel
2usr/share/applications/unity-2d-panel.desktop2usr/share/applications/unity-2d-panel.desktop
3usr/share/unity-2d/panel/artwork/background.png
4usr/share/unity-2d/panel/artwork/divider.png
53
=== modified file 'libunity-2d-private/Unity2d/CMakeLists.txt'
--- libunity-2d-private/Unity2d/CMakeLists.txt 2011-07-27 12:33:59 +0000
+++ libunity-2d-private/Unity2d/CMakeLists.txt 2011-07-27 15:26:24 +0000
@@ -4,7 +4,7 @@
4pkg_check_modules(QTDEE REQUIRED libqtdee)4pkg_check_modules(QTDEE REQUIRED libqtdee)
5pkg_check_modules(DBUSMENUQT REQUIRED dbusmenu-qt)5pkg_check_modules(DBUSMENUQT REQUIRED dbusmenu-qt)
6pkg_check_modules(STARTUPNOTIFICATION REQUIRED libstartup-notification-1.0)6pkg_check_modules(STARTUPNOTIFICATION REQUIRED libstartup-notification-1.0)
7pkg_check_modules(INDICATOR REQUIRED indicator-0.4)7pkg_check_modules(INDICATOR REQUIRED indicator3-0.4)
8pkg_check_modules(DCONFQT REQUIRED dconf-qt)8pkg_check_modules(DCONFQT REQUIRED dconf-qt)
99
10# Sources10# Sources
1111
=== modified file 'libunity-2d-private/Unity2d/launcherapplication.cpp'
--- libunity-2d-private/Unity2d/launcherapplication.cpp 2011-07-13 17:42:29 +0000
+++ libunity-2d-private/Unity2d/launcherapplication.cpp 2011-07-27 15:26:24 +0000
@@ -14,10 +14,6 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */15 */
1616
17/* Those have to be included before any QObject-style header to avoid
18 compilation errors. */
19#include <gdk/gdk.h>
20
21/* Note regarding the use of wnck: it is critically important that the client17/* Note regarding the use of wnck: it is critically important that the client
22 type be set to pager because wnck will pass that type over to the window18 type be set to pager because wnck will pass that type over to the window
23 manager through XEvents.19 manager through XEvents.
@@ -59,6 +55,7 @@
59#include <QX11Info>55#include <QX11Info>
6056
61extern "C" {57extern "C" {
58#include <gdk/gdk.h>
62#include <libsn/sn.h>59#include <libsn/sn.h>
63}60}
6461
@@ -649,7 +646,8 @@
649 GTimeVal timeval;646 GTimeVal timeval;
650647
651 g_get_current_time (&timeval);648 g_get_current_time (&timeval);
652 GObjectScopedPointer<GdkAppLaunchContext> context(gdk_app_launch_context_new());649 GdkDisplay* display = gdk_display_get_default();
650 GObjectScopedPointer<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));
653 /* Using GDK_CURRENT_TIME doesn’t seem to work, launched windows651 /* Using GDK_CURRENT_TIME doesn’t seem to work, launched windows
654 sometimes don’t get focus (see https://launchpad.net/bugs/643616). */652 sometimes don’t get focus (see https://launchpad.net/bugs/643616). */
655 gdk_app_launch_context_set_timestamp(context.data(), timeval.tv_sec);653 gdk_app_launch_context_set_timestamp(context.data(), timeval.tv_sec);
656654
=== modified file 'libunity-2d-private/Unity2d/plugin.cpp'
--- libunity-2d-private/Unity2d/plugin.cpp 2011-07-26 16:05:51 +0000
+++ libunity-2d-private/Unity2d/plugin.cpp 2011-07-27 15:26:24 +0000
@@ -20,10 +20,6 @@
20/* Required otherwise using wnck_set_client_type breaks linking with error:20/* Required otherwise using wnck_set_client_type breaks linking with error:
21 undefined reference to `wnck_set_client_type(WnckClientType)'21 undefined reference to `wnck_set_client_type(WnckClientType)'
22*/22*/
23extern "C" {
24#include <libwnck/util.h>
25}
26
27#include "plugin.h"23#include "plugin.h"
2824
29#include "launcherapplication.h"25#include "launcherapplication.h"
3026
=== modified file 'libunity-2d-private/Unity2d/screeninfo.cpp'
--- libunity-2d-private/Unity2d/screeninfo.cpp 2011-06-27 13:43:05 +0000
+++ libunity-2d-private/Unity2d/screeninfo.cpp 2011-07-27 15:26:24 +0000
@@ -1,7 +1,5 @@
1extern "C" {1extern "C" {
2#include <libwnck/screen.h>2#include <libwnck/libwnck.h>
3#include <libwnck/window.h>
4#include <libwnck/workspace.h>
5}3}
64
7#include "bamf-matcher.h"5#include "bamf-matcher.h"
86
=== modified file 'libunity-2d-private/Unity2d/windowinfo.cpp'
--- libunity-2d-private/Unity2d/windowinfo.cpp 2011-02-08 11:48:16 +0000
+++ libunity-2d-private/Unity2d/windowinfo.cpp 2011-07-27 15:26:24 +0000
@@ -14,9 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */15 */
1616
17#include <libwnck/screen.h>17#include <libwnck/libwnck.h>
18#include <libwnck/window.h>
19#include <libwnck/workspace.h>
2018
21#include <glib-2.0/glib.h>19#include <glib-2.0/glib.h>
2220
2321
=== modified file 'libunity-2d-private/Unity2d/workspacesinfo.cpp'
--- libunity-2d-private/Unity2d/workspacesinfo.cpp 2011-07-23 12:46:30 +0000
+++ libunity-2d-private/Unity2d/workspacesinfo.cpp 2011-07-27 15:26:24 +0000
@@ -4,9 +4,7 @@
4#include <debug_p.h>4#include <debug_p.h>
55
6extern "C" {6extern "C" {
7#include <libwnck/screen.h>7#include <libwnck/libwnck.h>
8#include <libwnck/window.h>
9#include <libwnck/workspace.h>
10}8}
119
12#include <QAbstractEventDispatcher>10#include <QAbstractEventDispatcher>
1311
=== modified file 'libunity-2d-private/src/CMakeLists.txt'
--- libunity-2d-private/src/CMakeLists.txt 2011-07-27 09:42:32 +0000
+++ libunity-2d-private/src/CMakeLists.txt 2011-07-27 15:26:24 +0000
@@ -1,5 +1,6 @@
1# Sources1# Sources
2set(libunity-2d-private_SRCS2set(libunity-2d-private_SRCS
3 debug.cpp
3 gconnector.cpp4 gconnector.cpp
4 gnomesessionclient.cpp5 gnomesessionclient.cpp
5 keyboardmodifiersmonitor.cpp6 keyboardmodifiersmonitor.cpp
67
=== added file 'libunity-2d-private/src/debug.cpp'
--- libunity-2d-private/src/debug.cpp 1970-01-01 00:00:00 +0000
+++ libunity-2d-private/src/debug.cpp 2011-07-27 15:26:24 +0000
@@ -0,0 +1,23 @@
1/* This file is part of unity-2d
2 Copyright 2011 Canonical
3 Author: Aurelien Gateau <aurelien.gateau@canonical.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 3.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17// Self
18#include <debug_p.h>
19
20QDebug operator<<(QDebug& dbg, const std::string& str)
21{
22 return dbg << QString::fromUtf8(str.c_str());
23}
024
=== modified file 'libunity-2d-private/src/debug_p.h'
--- libunity-2d-private/src/debug_p.h 2011-03-28 14:06:14 +0000
+++ libunity-2d-private/src/debug_p.h 2011-07-27 15:26:24 +0000
@@ -17,8 +17,12 @@
17#ifndef DEBUG_P_H17#ifndef DEBUG_P_H
18#define DEBUG_P_H18#define DEBUG_P_H
1919
20// Qt
20#include <QDebug>21#include <QDebug>
2122
23// STL
24#include <string>
25
22#define _UQ_TRACE(level) (level().nospace() << __PRETTY_FUNCTION__ << ":").space()26#define _UQ_TRACE(level) (level().nospace() << __PRETTY_FUNCTION__ << ":").space()
2327
24// Simple macros to get KDebug like support28// Simple macros to get KDebug like support
@@ -62,5 +66,7 @@
6266
63#define UQ_DEBUG_BLOCK Unity2dDebugBlock __unity2dDebugBlock__(__PRETTY_FUNCTION__)67#define UQ_DEBUG_BLOCK Unity2dDebugBlock __unity2dDebugBlock__(__PRETTY_FUNCTION__)
6468
69// Support for outputing std::string with qDebug
70QDebug operator<<(QDebug& dbg, const std::string& str);
6571
66#endif /* DEBUG_P_H */72#endif /* DEBUG_P_H */
6773
=== modified file 'libunity-2d-private/src/unity2dapplication.cpp'
--- libunity-2d-private/src/unity2dapplication.cpp 2011-07-27 11:42:46 +0000
+++ libunity-2d-private/src/unity2dapplication.cpp 2011-07-27 15:26:24 +0000
@@ -41,6 +41,16 @@
41 }41 }
42}42}
4343
44static bool arrayContains(char** begin, char** end, const char* string)
45{
46 for (char** ptr = begin; ptr != end; ++ptr) {
47 if (strcmp(*ptr, string) == 0) {
48 return true;
49 }
50 }
51 return false;
52}
53
44void Unity2dApplication::earlySetup(int& argc, char** argv)54void Unity2dApplication::earlySetup(int& argc, char** argv)
45{55{
46 // Parts of unity-2d uses GTK so it needs to be initialized56 // Parts of unity-2d uses GTK so it needs to be initialized
@@ -61,6 +71,14 @@
61 if(getenv("QT_GRAPHICSSYSTEM") == 0) {71 if(getenv("QT_GRAPHICSSYSTEM") == 0) {
62 QApplication::setGraphicsSystem("raster");72 QApplication::setGraphicsSystem("raster");
63 }73 }
74
75 /* Unless style has been specified in args, set default Qt style to
76 * QWindowStyle to avoid loading QGtkStyle. We don't want to load QGtkStyle
77 * because it uses libgtk2, which causes conflicts with our gtk3 code.
78 */
79 if (!arrayContains(argv, argv + argc, "-style")) {
80 QApplication::setStyle(new QWindowsStyle);
81 }
64}82}
6583
66Unity2dApplication::Unity2dApplication(int& argc, char** argv)84Unity2dApplication::Unity2dApplication(int& argc, char** argv)
6785
=== modified file 'panel/CMakeLists.txt'
--- panel/CMakeLists.txt 2011-06-27 13:40:51 +0000
+++ panel/CMakeLists.txt 2011-07-27 15:26:24 +0000
@@ -1,5 +1,8 @@
1project(unity-2d-panel)1project(unity-2d-panel)
22
3# Dependencies
4pkg_check_modules(UNITYCORE REQUIRED unity-core-4.0)
5
3# Source6# Source
4include_directories(7include_directories(
5 ${libunity-2d-private_SOURCE_DIR}/src8 ${libunity-2d-private_SOURCE_DIR}/src
@@ -8,8 +11,3 @@
8add_subdirectory(applets)11add_subdirectory(applets)
9add_subdirectory(app)12add_subdirectory(app)
10add_subdirectory(tests)13add_subdirectory(tests)
11
12# Install
13install(DIRECTORY artwork
14 DESTINATION ${UNITY_2D_DIR}/panel
15 )
1614
=== modified file 'panel/app/CMakeLists.txt'
--- panel/app/CMakeLists.txt 2011-04-04 16:41:15 +0000
+++ panel/app/CMakeLists.txt 2011-07-27 15:26:24 +0000
@@ -1,7 +1,6 @@
1set(panel_SRCS1set(panel_SRCS
2 main.cpp2 main.cpp
3 panelmanager.cpp3 panelmanager.cpp
4 unity2dstyle.cpp
5 )4 )
65
7qt4_automoc(${panel_SRCS})6qt4_automoc(${panel_SRCS})
@@ -10,14 +9,17 @@
10include_directories(9include_directories(
11 ${CMAKE_CURRENT_BINARY_DIR}10 ${CMAKE_CURRENT_BINARY_DIR}
12 ${CMAKE_CURRENT_SOURCE_DIR}11 ${CMAKE_CURRENT_SOURCE_DIR}
12 ${GTK_INCLUDE_DIRS}
13 ${uqapplets_SOURCE_DIR}13 ${uqapplets_SOURCE_DIR}
14 ${uqapplets_SOURCE_DIR}/common14 ${uqapplets_SOURCE_DIR}/common
15 ${UNITYCORE_INCLUDE_DIRS}
15 ${libunity-2d-private_SOURCE_DIR}/src16 ${libunity-2d-private_SOURCE_DIR}/src
16 )17 )
1718
18target_link_libraries(unity-2d-panel19target_link_libraries(unity-2d-panel
19 ${QT_QTGUI_LIBRARIES}20 ${QT_QTGUI_LIBRARIES}
20 ${QT_QTCORE_LIBRARIES}21 ${QT_QTCORE_LIBRARIES}
22 ${GTK_LDFLAGS}
21 uqapplets23 uqapplets
22 unity-2d-private24 unity-2d-private
23 )25 )
2426
=== modified file 'panel/app/main.cpp'
--- panel/app/main.cpp 2011-07-18 13:47:29 +0000
+++ panel/app/main.cpp 2011-07-27 15:26:24 +0000
@@ -22,12 +22,12 @@
22// Local22// Local
23#include <config.h>23#include <config.h>
24#include <panelmanager.h>24#include <panelmanager.h>
25#include <panelstyle.h>
2526
26// Unity27// Unity
27#include <gnomesessionclient.h>28#include <gnomesessionclient.h>
28#include <unity2ddebug.h>29#include <unity2ddebug.h>
29#include <unity2dapplication.h>30#include <unity2dapplication.h>
30#include <unity2dstyle.h>
31#include <unity2dtr.h>31#include <unity2dtr.h>
3232
33// Qt33// Qt
@@ -54,7 +54,9 @@
54 ThemeEngineHandler handler;54 ThemeEngineHandler handler;
55 Unity2dApplication::earlySetup(argc, argv);55 Unity2dApplication::earlySetup(argc, argv);
56 Unity2dApplication app(argc, argv);56 Unity2dApplication app(argc, argv);
57 QApplication::setStyle(new Unity2dStyle);57
58 // Instantiate a PanelStyle so that it configures QApplication
59 PanelStyle::instance();
5860
59 GnomeSessionClient client(INSTALL_PREFIX "/share/applications/unity-2d-panel.desktop");61 GnomeSessionClient client(INSTALL_PREFIX "/share/applications/unity-2d-panel.desktop");
60 client.connectToSessionManager();62 client.connectToSessionManager();
6163
=== modified file 'panel/app/panelmanager.cpp'
--- panel/app/panelmanager.cpp 2011-06-12 23:01:35 +0000
+++ panel/app/panelmanager.cpp 2011-07-27 15:26:24 +0000
@@ -24,6 +24,8 @@
2424
25// Local25// Local
26#include <config.h>26#include <config.h>
27#include <panelstyle.h>
28#include <indicatorsmanager.h>
2729
28// Applets30// Applets
29#include <appindicator/appindicatorapplet.h>31#include <appindicator/appindicatorapplet.h>
@@ -42,70 +44,55 @@
4244
43using namespace Unity2d;45using namespace Unity2d;
4446
45static QPalette getPalette()47static QWidget* createSeparator()
46{48{
47 QPalette palette;49 // Just a quick-hack: homebutton is going away anyway
4850 QWidget* widget = new QWidget;
49 /* Should use the panel's background provided by Unity but it turns51 widget->setFixedWidth(6);
50 out not to be good. It would look like:52 return widget;
5153}
52 QBrush bg(QPixmap("theme:/panel_background.png"));54
53 */55PanelManager::PanelManager(QObject* parent)
54 QBrush bg(QPixmap(unity2dDirectory() + "/panel/artwork/background.png"));56: QObject(parent)
55 palette.setBrush(QPalette::Window, bg);57{
56 palette.setBrush(QPalette::Button, bg);58 QDesktopWidget* desktop = QApplication::desktop();
57 return palette;59 for(int i = 0; i < desktop->screenCount(); ++i) {
58}60 Unity2dPanel* panel = instantiatePanel(i);
5961 m_panels.append(panel);
60static QLabel* createSeparator()62 panel->show();
61{63 panel->move(desktop->screenGeometry(i).topLeft());
62 QLabel* label = new QLabel;64 }
63 QPixmap pix(unity2dDirectory() + "/panel/artwork/divider.png");65 connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));
64 label->setPixmap(pix);66}
65 label->setFixedSize(pix.size());67
66 return label;68PanelManager::~PanelManager()
67}69{
6870 qDeleteAll(m_panels);
69static Unity2dPanel* instantiatePanel(int screen)71}
72
73Unity2dPanel* PanelManager::instantiatePanel(int screen)
70{74{
71 Unity2dPanel* panel = new Unity2dPanel;75 Unity2dPanel* panel = new Unity2dPanel;
72 panel->setEdge(Unity2dPanel::TopEdge);76 panel->setEdge(Unity2dPanel::TopEdge);
73 panel->setPalette(getPalette());
74 panel->setFixedHeight(24);77 panel->setFixedHeight(24);
7578
79 IndicatorsManager* indicatorsManager = new IndicatorsManager(panel);
80
76 int leftmost = QApplication::desktop()->screenNumber(QPoint());81 int leftmost = QApplication::desktop()->screenNumber(QPoint());
77 if (screen == leftmost) {82 if (screen == leftmost) {
78 panel->addWidget(new HomeButtonApplet);83 panel->addWidget(new HomeButtonApplet);
79 panel->addWidget(createSeparator());84 panel->addWidget(createSeparator());
80 }85 }
81 panel->addWidget(new AppNameApplet);86 panel->addWidget(new AppNameApplet(indicatorsManager));
82 if (screen == leftmost) {87 if (screen == leftmost) {
83 /* It doesn’t make sense to have more than one instance of the systray,88 /* It doesn’t make sense to have more than one instance of the systray,
84 XEmbed’ed windows can be displayed only once anyway. */89 XEmbed’ed windows can be displayed only once anyway. */
85 panel->addWidget(new LegacyTrayApplet);90 panel->addWidget(new LegacyTrayApplet);
86 }91 }
87 panel->addWidget(new IndicatorApplet);92 panel->addWidget(new IndicatorApplet(indicatorsManager));
88 return panel;93 return panel;
89}94}
9095
91PanelManager::PanelManager(QObject* parent)
92 : QObject(parent)
93{
94 QDesktopWidget* desktop = QApplication::desktop();
95 for(int i = 0; i < desktop->screenCount(); ++i) {
96 Unity2dPanel* panel = instantiatePanel(i);
97 m_panels.append(panel);
98 panel->show();
99 panel->move(desktop->screenGeometry(i).topLeft());
100 }
101 connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));
102}
103
104PanelManager::~PanelManager()
105{
106 qDeleteAll(m_panels);
107}
108
109void96void
110PanelManager::onScreenCountChanged(int newCount)97PanelManager::onScreenCountChanged(int newCount)
111{98{
11299
=== modified file 'panel/app/panelmanager.h'
--- panel/app/panelmanager.h 2011-04-04 16:41:15 +0000
+++ panel/app/panelmanager.h 2011-07-27 15:26:24 +0000
@@ -40,6 +40,8 @@
40 Q_DISABLE_COPY(PanelManager)40 Q_DISABLE_COPY(PanelManager)
41 QList<Unity2dPanel*> m_panels;41 QList<Unity2dPanel*> m_panels;
4242
43 Unity2dPanel* instantiatePanel(int screen);
44
43private Q_SLOTS:45private Q_SLOTS:
44 void onScreenCountChanged(int newCount);46 void onScreenCountChanged(int newCount);
45};47};
4648
=== removed file 'panel/app/unity2dstyle.cpp'
--- panel/app/unity2dstyle.cpp 2011-03-28 12:16:02 +0000
+++ panel/app/unity2dstyle.cpp 1970-01-01 00:00:00 +0000
@@ -1,98 +0,0 @@
1/*
2 * Plasma applet to display DBus global menu
3 *
4 * Copyright 2009 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
20 */
21
22// Self
23#include "unity2dstyle.h"
24
25// Local
26
27// libunity-2d-private
28#include <debug_p.h>
29#include <keyboardmodifiersmonitor.h>
30
31// Qt
32#include <QGtkStyle>
33#include <QMenu>
34#include <QPainter>
35#include <QStyleOptionFrame>
36#include <QWidget>
37
38Unity2dStyle::Unity2dStyle()
39: QProxyStyle(new QGtkStyle)
40{
41}
42
43void Unity2dStyle::drawControl(QStyle::ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
44{
45 if (element == QStyle::CE_MenuBarItem && widget) {
46 QStyleOptionMenuItem opt = *qstyleoption_cast<const QStyleOptionMenuItem*>(option);
47 if (!(opt.state & QStyle::State_Enabled) && (opt.state & QStyle::State_Sunken)) {
48 // Reset State_Sunken flag to avoid drawing a frame on a disabled menu item
49 // See https://bugs.launchpad.net/unity-2d/+bug/717744
50 opt.state ^= QStyle::State_Sunken;
51 }
52 // Skip "widget" parameter to avoid solid gray background behind the menubar items
53 QProxyStyle::drawControl(element, &opt, painter, 0);
54 } else if (element == QStyle::CE_MenuBarEmptyArea) {
55 // Avoid gray borders around the menubar items
56 } else {
57 QProxyStyle::drawControl(element, option, painter, widget);
58 }
59}
60
61int Unity2dStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption* option, const QWidget* widget) const
62{
63 if (metric == QStyle::PM_MenuBarVMargin) {
64 // Avoid one-pixel gap above menuitem
65 return 0;
66 } else {
67 return QProxyStyle::pixelMetric(metric, option, widget);
68 }
69}
70
71QSize Unity2dStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget) const
72{
73 QSize size = QProxyStyle::sizeFromContents(type, option, contentsSize, widget);
74 if (type == QStyle::CT_MenuBarItem && widget) {
75 // Avoid three-pixel gap below menuitem
76 size.setHeight(widget->height());
77 }
78 return size;
79}
80
81int Unity2dStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
82{
83 if (hint == QStyle::SH_UnderlineShortcut) {
84 // The shortcut of an opened menu can be triggered without holding Alt
85 // down, so we always show the underline. For all other widgets we only
86 // show the underlines if alt is down.
87 // Note that this is a bit hackish: it only works reliably if the
88 // widget repaints itself when alt is pressed or released. For now only
89 // the MenuBarWidget from the AppNameApplets does this.
90 if (qobject_cast<const QMenu*>(widget)) {
91 return true;
92 } else {
93 return KeyboardModifiersMonitor::instance()->keyboardModifiers() == Qt::AltModifier;
94 }
95 } else {
96 return QProxyStyle::styleHint(hint, option, widget, returnData);
97 }
98}
990
=== removed file 'panel/app/unity2dstyle.h'
--- panel/app/unity2dstyle.h 2011-01-26 15:50:26 +0000
+++ panel/app/unity2dstyle.h 1970-01-01 00:00:00 +0000
@@ -1,44 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
20 */
21
22#ifndef UNITY2DSTYLE_H
23#define UNITY2DSTYLE_H
24
25// Local
26
27// Qt
28#include <QProxyStyle>
29
30class Unity2dStyle : public QProxyStyle
31{
32public:
33 Unity2dStyle();
34
35 virtual void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0) const;
36
37 virtual int pixelMetric(PixelMetric metric, const QStyleOption* option = 0, const QWidget* widget = 0) const;
38
39 virtual QSize sizeFromContents(ContentsType type, const QStyleOption* option, const QSize& contentsSize, const QWidget* widget = 0) const;
40
41 virtual int styleHint(StyleHint hint, const QStyleOption* option = 0, const QWidget* widget = 0, QStyleHintReturn* returnData = 0) const;
42};
43
44#endif /* UNITY2DSTYLE_H */
450
=== modified file 'panel/applets/CMakeLists.txt'
--- panel/applets/CMakeLists.txt 2011-07-27 12:33:59 +0000
+++ panel/applets/CMakeLists.txt 2011-07-27 15:26:24 +0000
@@ -1,25 +1,11 @@
1project(uqapplets)1project(uqapplets)
22
3macro(read_pkg_variable cmake_var pkg pkg_var)
4 execute_process(
5 COMMAND pkg-config --variable=${pkg_var} ${pkg}
6 OUTPUT_VARIABLE tmp
7 )
8 # Remove trailing newline from ${tmp}
9 string(STRIP "${tmp}" ${cmake_var})
10endmacro(read_pkg_variable)
11
12# Dependencies3# Dependencies
13include(FindPkgConfig)4include(FindPkgConfig)
145
15pkg_check_modules(QTBAMF REQUIRED libqtbamf)6pkg_check_modules(QTBAMF REQUIRED libqtbamf)
16pkg_check_modules(DBUSMENUQT REQUIRED dbusmenu-qt)7pkg_check_modules(DBUSMENUQT REQUIRED dbusmenu-qt)
17pkg_check_modules(INDICATOR REQUIRED indicator-0.4)8pkg_check_modules(PANGO REQUIRED pango)
18
19# Get indicator dirs from pkgconfig
20read_pkg_variable(INDICATOR_DIR indicator-0.4 indicatordir)
21read_pkg_variable(INDICATOR_ICONS_DIR indicator-0.4 iconsdir)
22configure_file(indicator-config.h.in indicator-config.h)
239
24# Sources10# Sources
25set(uqapplets_SRCS11set(uqapplets_SRCS
@@ -27,16 +13,15 @@
27 appindicator/sniitem.cpp13 appindicator/sniitem.cpp
28 appname/appnameapplet.cpp14 appname/appnameapplet.cpp
29 appname/menubarwidget.cpp15 appname/menubarwidget.cpp
30 appname/registrar.cpp
31 appname/windowhelper.cpp16 appname/windowhelper.cpp
32 common/applet.cpp17 common/applet.cpp
18 common/indicatorentrywidget.cpp
19 common/indicatorsmanager.cpp
20 common/indicatorwidget.cpp
21 common/panelstyle.cpp
33 homebutton/homebuttonapplet.cpp22 homebutton/homebuttonapplet.cpp
34 homebutton/homebutton.cpp23 homebutton/homebutton.cpp
35 indicator/abstractindicator.cpp
36 indicator/datetimeindicator.cpp
37 indicator/indicatorapplet.cpp24 indicator/indicatorapplet.cpp
38 indicator/indicatorservicemanager.cpp
39 indicator/indicator.c
40 legacytray/legacytrayapplet.cpp25 legacytray/legacytrayapplet.cpp
41 legacytray/fdoselectionmanager.cpp26 legacytray/fdoselectionmanager.cpp
42 legacytray/fdotask.cpp27 legacytray/fdotask.cpp
@@ -45,10 +30,6 @@
45 legacytray/x11embedpainter.cpp30 legacytray/x11embedpainter.cpp
46 )31 )
4732
48qt4_add_dbus_adaptor(uqapplets_SRCS appname/com.canonical.AppMenu.Registrar.xml
49 registrar.h Registrar
50 )
51
52qt4_automoc(${uqapplets_SRCS})33qt4_automoc(${uqapplets_SRCS})
5334
54# Build35# Build
@@ -58,13 +39,15 @@
58 ${CMAKE_CURRENT_SOURCE_DIR}/common39 ${CMAKE_CURRENT_SOURCE_DIR}/common
59 ${CMAKE_CURRENT_SOURCE_DIR}/homebutton40 ${CMAKE_CURRENT_SOURCE_DIR}/homebutton
60 ${CMAKE_CURRENT_SOURCE_DIR}/indicator41 ${CMAKE_CURRENT_SOURCE_DIR}/indicator
42 ${CMAKE_CURRENT_SOURCE_DIR}/unitycore
61 ${QTBAMF_INCLUDE_DIRS}43 ${QTBAMF_INCLUDE_DIRS}
62 ${DBUSMENUQT_INCLUDE_DIRS}44 ${DBUSMENUQT_INCLUDE_DIRS}
63 ${GTK_INCLUDE_DIRS}45 ${GTK_INCLUDE_DIRS}
64 ${INDICATOR_INCLUDE_DIRS}
65 ${WNCK_INCLUDE_DIRS}46 ${WNCK_INCLUDE_DIRS}
66 ${CMAKE_CURRENT_BINARY_DIR}47 ${CMAKE_CURRENT_BINARY_DIR}
67 ${X11_INCLUDE_DIR}48 ${X11_INCLUDE_DIR}
49 ${UNITYCORE_INCLUDE_DIRS}
50 ${PANGO_INCLUDE_DIRS}
68 ${libunity-2d-private_SOURCE_DIR}/src51 ${libunity-2d-private_SOURCE_DIR}/src
69 )52 )
7053
@@ -76,12 +59,13 @@
76 ${DBUSMENUQT_LDFLAGS}59 ${DBUSMENUQT_LDFLAGS}
77 ${QTBAMF_LDFLAGS}60 ${QTBAMF_LDFLAGS}
78 ${GTK_LDFLAGS}61 ${GTK_LDFLAGS}
79 ${INDICATOR_LDFLAGS}
80 ${WNCK_LDFLAGS}62 ${WNCK_LDFLAGS}
81 ${X11_LIBRARIES}63 ${X11_LIBRARIES}
82 ${X11_Xrender_LIB}64 ${X11_Xrender_LIB}
83 ${X11_Xcomposite_LIB}65 ${X11_Xcomposite_LIB}
84 ${X11_Xdamage_LIB}66 ${X11_Xdamage_LIB}
85 ${X11_Xfixes_LIB}67 ${X11_Xfixes_LIB}
68 ${UNITYCORE_LDFLAGS}
69 ${PANGO_LDFLAGS}
86 unity-2d-private70 unity-2d-private
87 )71 )
8872
=== modified file 'panel/applets/appname/appnameapplet.cpp'
--- panel/applets/appname/appnameapplet.cpp 2011-07-26 09:36:41 +0000
+++ panel/applets/appname/appnameapplet.cpp 2011-07-27 15:26:24 +0000
@@ -200,10 +200,10 @@
200 q, SLOT(updateWidgets()));200 q, SLOT(updateWidgets()));
201 }201 }
202202
203 void setupMenuBarWidget()203 void setupMenuBarWidget(IndicatorsManager* manager)
204 {204 {
205 m_menuBarWidget = new MenuBarWidget(0 /* Window menu */);205 m_menuBarWidget = new MenuBarWidget(manager);
206 QObject::connect(m_menuBarWidget, SIGNAL(menuBarClosed()),206 QObject::connect(m_menuBarWidget, SIGNAL(isOpenedChanged()),
207 q, SLOT(updateWidgets()));207 q, SLOT(updateWidgets()));
208 QObject::connect(m_menuBarWidget, SIGNAL(isEmptyChanged()),208 QObject::connect(m_menuBarWidget, SIGNAL(isEmptyChanged()),
209 q, SLOT(updateWidgets()));209 q, SLOT(updateWidgets()));
@@ -216,21 +216,16 @@
216 }216 }
217};217};
218218
219AppNameApplet::AppNameApplet()219AppNameApplet::AppNameApplet(IndicatorsManager* indicatorsManager)
220: d(new AppNameAppletPrivate)220: d(new AppNameAppletPrivate)
221{221{
222 d->q = this;222 d->q = this;
223 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);223 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);
224224
225 QPalette palette;
226 palette.setColor(QPalette::WindowText, Qt::white);
227 palette.setColor(QPalette::ButtonText, Qt::white);
228 setPalette(palette);
229
230 d->setupWindowHelper();225 d->setupWindowHelper();
231 d->setupLabel();226 d->setupLabel();
232 d->setupWindowButtonWidget();227 d->setupWindowButtonWidget();
233 d->setupMenuBarWidget();228 d->setupMenuBarWidget(indicatorsManager);
234 d->setupKeyboardModifiersMonitor();229 d->setupKeyboardModifiersMonitor();
235230
236 QHBoxLayout* layout = new QHBoxLayout(this);231 QHBoxLayout* layout = new QHBoxLayout(this);
237232
=== modified file 'panel/applets/appname/appnameapplet.h'
--- panel/applets/appname/appnameapplet.h 2011-06-06 09:06:55 +0000
+++ panel/applets/appname/appnameapplet.h 2011-07-27 15:26:24 +0000
@@ -29,6 +29,8 @@
2929
30class QEvent;30class QEvent;
3131
32class IndicatorsManager;
33
32namespace Unity2d34namespace Unity2d
33{35{
3436
@@ -37,7 +39,7 @@
37{39{
38Q_OBJECT40Q_OBJECT
39public:41public:
40 AppNameApplet();42 AppNameApplet(IndicatorsManager*);
41 ~AppNameApplet();43 ~AppNameApplet();
4244
43protected:45protected:
4446
=== removed file 'panel/applets/appname/com.canonical.AppMenu.Registrar.xml'
--- panel/applets/appname/com.canonical.AppMenu.Registrar.xml 2011-02-10 01:10:19 +0000
+++ panel/applets/appname/com.canonical.AppMenu.Registrar.xml 1970-01-01 00:00:00 +0000
@@ -1,82 +0,0 @@
1<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
2<node xmlns:dox="http://www.ayatana.org/dbus/dox.dtd">
3 <dox:d><![CDATA[
4 @mainpage
5  
6 An interface to register menus that are associated with a window in an application.  The
7 main interface is docuemented here: @ref com::canonical::AppMenu::Registrar.
8     
9 The actual menus are transported using the dbusmenu protocol which is available
10 here: @ref com::canonical::dbusmenu.
11 ]]></dox:d>
12 <interface name="com.canonical.AppMenu.Registrar" xmlns:dox="http://www.ayatana.org/dbus/dox.dtd">
13 <dox:d>
14 An interface to register a menu from an application's window to be displayed in another
15 window.  This manages that association between XWindow Window IDs and the dbus
16 address and object that provides the menu using the dbusmenu dbus interface.
17 </dox:d>
18 <method name="RegisterWindow">
19 <dox:d><![CDATA[
20 Associates a dbusmenu with a window
21      
22 /note this method assumes that the connection from the caller is the DBus connection
23 to use for the object.  Applications that use multiple DBus connections will need to
24 ensure this method is called with the same connection that implmenets the object.
25 ]]></dox:d>
26 <arg name="windowId" type="u" direction="in">
27 <dox:d>The XWindow ID of the window</dox:d>
28 </arg>
29 <arg name="menuObjectPath" type="o" direction="in">
30 <dox:d>The object on the dbus interface implementing the dbusmenu interface</dox:d>
31 </arg>
32 </method>
33 <method name="UnregisterWindow">
34 <dox:d>
35 A method to allow removing a window from the database. Windows will also be removed
36 when the client drops off DBus so this is not required. It is polite though. And
37 important for testing.
38 </dox:d>
39 <arg name="windowId" type="u" direction="in">
40 <dox:d>The XWindow ID of the window</dox:d>
41 </arg>
42 </method>
43 <method name="GetMenuForWindow">
44 <dox:d>Gets the registered menu for a given window ID.</dox:d>
45 <arg name="windowId" type="u" direction="in">
46 <dox:d>The XWindow ID of the window to get</dox:d>
47 </arg>
48 <arg name="service" type="s" direction="out">
49 <dox:d>The address of the connection on DBus (e.g. :1.23 or org.example.service)</dox:d>
50 </arg>
51 <arg name="menuObjectPath" type="o" direction="out">
52 <dox:d>The path to the object which implements the com.canonical.dbusmenu interface.</dox:d>
53 </arg>
54 </method>
55 <method name="GetMenus">
56 <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MenuInfoList"/>
57 <dox:d>Gets the information on all menus that the registrar knows about. This
58 is useful for debugging or bringing up a new renderer.</dox:d>
59 <arg name="menus" type="a(uso)" direction="out">
60 <dox:d>An array of structures containing the same parameters as @GetMenuForWindow. Window ID, Service and ObjectPath.</dox:d>
61 </arg>
62 </method>
63 <signal name="WindowRegistered">
64 <dox:d>Signals when the registrar gets a new menu registered</dox:d>
65 <arg name="windowId" type="u" direction="out">
66 <dox:d>The XWindow ID of the window</dox:d>
67 </arg>
68 <arg name="service" type="s" direction="out">
69 <dox:d>The address of the connection on DBus (e.g. :1.23 or org.example.service)</dox:d>
70 </arg>
71 <arg name="menuObjectPath" type="o" direction="out">
72 <dox:d>The path to the object which implements the com.canonical.dbusmenu interface.</dox:d>
73 </arg>
74 </signal>
75 <signal name="WindowUnregistered">
76 <dox:d>Signals when the registrar removes a menu registration</dox:d>
77 <arg name="windowId" type="u" direction="out">
78 <dox:d>The XWindow ID of the window</dox:d>
79 </arg>
80 </signal>
81 </interface>
82</node>
830
=== modified file 'panel/applets/appname/menubarwidget.cpp'
--- panel/applets/appname/menubarwidget.cpp 2011-07-26 09:36:41 +0000
+++ panel/applets/appname/menubarwidget.cpp 2011-07-27 15:26:24 +0000
@@ -20,299 +20,98 @@
20 */20 */
2121
22// Self22// Self
23#include "menubarwidget.h"23#include <menubarwidget.h>
2424
25// Local25// Local
26#include "config.h"26#include <debug_p.h>
27#include "debug_p.h"27#include <indicatorentrywidget.h>
28#include "keyboardmodifiersmonitor.h"28#include <indicatorsmanager.h>
29#include "registrar.h"
30
31// dbusmenu-qt
32#include <dbusmenuimporter.h>
33
34// bamf
35#include <bamf-matcher.h>
36#include <bamf-window.h>
3729
38// Qt30// Qt
39#include <QActionEvent>
40#include <QHBoxLayout>31#include <QHBoxLayout>
41#include <QLabel>32
42#include <QMenuBar>33static const int MENU_ITEM_PADDING = 6;
43#include <QTimer>34
4435MenuBarWidget::MenuBarWidget(IndicatorsManager* indicatorsManager, QWidget* parent)
45class MyDBusMenuImporter : public DBusMenuImporter
46{
47public:
48 MyDBusMenuImporter(const QString &service, const QString &path, QObject *parent)
49 : DBusMenuImporter(service, path, parent)
50 , m_service(service)
51 , m_path(path)
52 {}
53
54 QString service() const { return m_service; }
55 QString path() const { return m_path; }
56
57private:
58 QString m_service;
59 QString m_path;
60};
61
62MenuBarWidget::MenuBarWidget(QMenu* windowMenu, QWidget* parent)
63: QWidget(parent)36: QWidget(parent)
64, m_windowMenu(windowMenu)37, m_indicatorsManager(indicatorsManager)
65{38, m_layout(new QHBoxLayout(this))
66 m_activeWinId = 0;39, m_isEmpty(true)
67 setupRegistrar();40, m_isOpened(false)
68 setupMenuBar();41{
6942 m_layout->setMargin(0);
70 connect(&BamfMatcher::get_default(), SIGNAL(ActiveWindowChanged(BamfWindow*, BamfWindow*)),43 m_layout->setSpacing(0);
71 SLOT(slotActiveWindowChanged(BamfWindow*, BamfWindow*)));44 indicatorsManager->indicators()->on_object_added.connect(
72 /* Work around a bug in BAMF: the ActiveWindowChanged signal is not emitted45 sigc::mem_fun(this, &MenuBarWidget::onObjectAdded)
73 for some windows that open maximized. This is for example the case of the46 );
74 LibreOffice startcenter. */47 indicatorsManager->indicators()->on_entry_activated.connect(
75 connect(&BamfMatcher::get_default(), SIGNAL(ViewOpened(BamfView*)),48 sigc::mem_fun(this, &MenuBarWidget::onEntryActivated)
76 SLOT(slotViewOpened()));49 );
77 updateActiveWinId(BamfMatcher::get_default().active_window());50 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
78}51 m_layout->addStretch();
79
80void MenuBarWidget::setupRegistrar()
81{
82 m_registrar = Registrar::instance();
83 if (!m_registrar->connectToBus()) {
84 UQ_WARNING << "could not connect registrar to DBus";
85 }
86
87 connect(m_registrar, SIGNAL(WindowRegistered(WId, const QString&, const QDBusObjectPath&)),
88 SLOT(slotWindowRegistered(WId, const QString&, const QDBusObjectPath&)));
89 connect(m_registrar, SIGNAL(WindowUnregistered(WId)),
90 SLOT(slotWindowUnregistered(WId)));
91}
92
93void MenuBarWidget::setupMenuBar()
94{
95 m_menuBar = new QMenuBar;
96 new MenuBarClosedHelper(this);
97
98 QHBoxLayout* layout = new QHBoxLayout(this);
99 layout->setMargin(0);
100 layout->setSpacing(0);
101 layout->addWidget(m_menuBar);
102 m_menuBar->setNativeMenuBar(false);
103
104 m_updateMenuBarTimer = new QTimer(this);
105 m_updateMenuBarTimer->setSingleShot(true);
106 m_updateMenuBarTimer->setInterval(0);
107 connect(m_updateMenuBarTimer, SIGNAL(timeout()),
108 SLOT(updateMenuBar()));
109
110 // Repaint the menubar when modifiers change so that the shortcut underline
111 // is drawn or not
112 connect(KeyboardModifiersMonitor::instance(), SIGNAL(keyboardModifiersChanged(Qt::KeyboardModifiers)),
113 m_menuBar, SLOT(update()));
114}
115
116void MenuBarWidget::slotActiveWindowChanged(BamfWindow* /*former*/, BamfWindow* current)
117{
118 if (current) {
119 updateActiveWinId(current);
120 }
121}
122
123void MenuBarWidget::slotViewOpened()
124{
125 BamfWindow* active = BamfMatcher::get_default().active_window();
126 if (active != NULL) {
127 if (active->xid() != m_activeWinId) {
128 /* This shouldn’t be needed as BAMF should have emitted the
129 ActiveWindowChanged signal, but it sometimes doesn’t (e.g. when
130 LibreOffice startcenter starts automatically maximized). */
131 updateActiveWinId(active);
132 }
133 }
134}
135
136void MenuBarWidget::slotWindowRegistered(WId wid, const QString& service, const QDBusObjectPath& menuObjectPath)
137{
138 MyDBusMenuImporter* importer = new MyDBusMenuImporter(service, menuObjectPath.path(), this);
139 delete m_importers.take(wid);
140 m_importers.insert(wid, importer);
141 connect(importer, SIGNAL(menuUpdated()), SLOT(slotMenuUpdated()));
142 connect(importer, SIGNAL(actionActivationRequested(QAction*)), SLOT(slotActionActivationRequested(QAction*)));
143 QMetaObject::invokeMethod(importer, "updateMenu", Qt::QueuedConnection);
144}
145
146void MenuBarWidget::slotWindowUnregistered(WId wid)
147{
148 MyDBusMenuImporter* importer = m_importers.take(wid);
149 if (importer) {
150 importer->deleteLater();
151 }
152 if (wid == m_activeWinId) {
153 m_activeWinId = 0;
154 updateMenuBar();
155 }
156}
157
158void MenuBarWidget::slotMenuUpdated()
159{
160 DBusMenuImporter* importer = static_cast<DBusMenuImporter*>(sender());
161
162 if (m_importers.value(m_activeWinId) == importer) {
163 updateMenuBar();
164 }
165}
166
167void MenuBarWidget::slotActionActivationRequested(QAction* action)
168{
169 DBusMenuImporter* importer = static_cast<DBusMenuImporter*>(sender());
170
171 if (m_importers.value(m_activeWinId) == importer) {
172 m_menuBar->setActiveAction(action);
173 }
174}
175
176QMenu* MenuBarWidget::menuForWinId(WId wid) const
177{
178 MyDBusMenuImporter* importer = m_importers.value(wid);
179 return importer ? importer->menu() : 0;
180}
181
182void MenuBarWidget::updateActiveWinId(BamfWindow* bamfWindow)
183{
184 WId id = bamfWindow ? bamfWindow->xid() : 0;
185 if (id == m_activeWinId) {
186 return;
187 }
188 if (id == window()->winId()) {
189 // Do not update id if the active window is the one hosting this applet
190 return;
191 }
192 m_activeWinId = id;
193 updateMenuBar();
194}
195
196void MenuBarWidget::updateMenuBar()
197{
198 WId winId = m_activeWinId;
199 QMenu* menu = menuForWinId(winId);
200
201 if (!menu) {
202 if (winId) {
203 menu = m_windowMenu;
204 } else {
205 // No active window, show a desktop menubar
206 // FIXME: Empty menu
207 /*
208 menu = mEmptyMenu;
209 */
210 }
211 }
212
213 m_menuBar->clear();
214 // FIXME: Empty menu
215 if (!menu) {
216 return;
217 }
218 menu->installEventFilter(this);
219 Q_FOREACH(QAction* action, menu->actions()) {
220 if (action->isSeparator()) {
221 continue;
222 }
223 m_menuBar->addAction(action);
224 }
225}
226
227bool MenuBarWidget::eventFilter(QObject* object, QEvent* event)
228{
229 switch (event->type()) {
230 case QEvent::ActionAdded:
231 case QEvent::ActionRemoved:
232 case QEvent::ActionChanged:
233 m_updateMenuBarTimer->start();
234 break;
235 default:
236 break;
237 }
238 return false;
239}52}
24053
241bool MenuBarWidget::isEmpty() const54bool MenuBarWidget::isEmpty() const
242{55{
243 return m_menuBar->actions().isEmpty();56 return m_isEmpty;
244}57}
24558
246bool MenuBarWidget::isOpened() const59bool MenuBarWidget::isOpened() const
247{60{
248 return m_menuBar->activeAction();61 return m_isOpened;
249}62}
25063
251// MenuBarClosedHelper ----------------------------------------64void MenuBarWidget::onObjectAdded(const unity::indicator::Indicator::Ptr& indicator)
252MenuBarClosedHelper::MenuBarClosedHelper(MenuBarWidget* widget)65{
253: QObject(widget)66 QString name = QString::fromStdString(indicator->name());
254, m_widget(widget)67 if (name == "libappmenu.so") {
255{68 indicator->on_entry_added.connect(sigc::mem_fun(this, &MenuBarWidget::onEntryAdded));
256 widget->m_menuBar->installEventFilter(this);69 }
257}70}
25871
259bool MenuBarClosedHelper::eventFilter(QObject* object, QEvent* event)72void MenuBarWidget::onEntryAdded(const unity::indicator::Entry::Ptr& entry)
260{73{
261 if (object == m_widget->m_menuBar) {74 IndicatorEntryWidget* widget = new IndicatorEntryWidget(entry);
262 switch (event->type()) {75 widget->setPadding(MENU_ITEM_PADDING);
263 case QEvent::ActionAdded:76 connect(widget, SIGNAL(isEmptyChanged()), SLOT(updateIsEmpty()));
264 case QEvent::ActionRemoved:77
265 case QEvent::ActionChanged:78 m_widgetList.append(widget);
266 menuBarActionEvent(static_cast<QActionEvent*>(event));79 m_indicatorsManager->addIndicatorEntryWidget(widget);
267 break;80
268 default:81 // Insert *before* stretch
269 break;82 m_layout->insertWidget(m_layout->count() - 1, widget);
270 }83}
271 } else {84
272 // Top-level menus85void MenuBarWidget::updateIsEmpty()
273 if (event->type() == QEvent::Hide) {86{
274 // menu hide themselves when the menubar is closed but also when87 bool empty = true;
275 // one goes from one menu to another. The way to know this is to88 Q_FOREACH(IndicatorEntryWidget* widget, m_widgetList) {
276 // check the value of QMenuBar::activeAction(), but at this point89 if (!widget->isEmpty()) {
277 // it has not been updated yet, so we check in a delayed method.90 empty = false;
278 QMetaObject::invokeMethod(this, "emitMenuBarClosed", Qt::QueuedConnection);91 break;
279 }92 }
280 }93 }
281 return false;94 if (m_isEmpty != empty) {
282}95 m_isEmpty = empty;
28396 isEmptyChanged();
284void MenuBarClosedHelper::emitMenuBarClosed()97 }
285{98}
286 if (!m_widget->m_menuBar->activeAction()) {99
287 QMetaObject::invokeMethod(m_widget, "menuBarClosed");100void MenuBarWidget::onEntryActivated(const std::string& id)
288 }101{
289}102 bool isOpened = false;
290103 if (!id.empty()) {
291void MenuBarClosedHelper::menuBarActionEvent(QActionEvent* event)104 // We only cares about menubar entries
292{105 Q_FOREACH(IndicatorEntryWidget* widget, m_widgetList) {
293 QMenu* menu = event->action()->menu();106 if (widget->entry()->id() == id) {
294 if (menu) {107 isOpened = true;
295 // Install/remove event filters on top level menus so that know when108 break;
296 // they hide themselves and can emit menuBarClosed()109 }
297 switch (event->type()) {110 }
298 case QEvent::ActionAdded:111 }
299 case QEvent::ActionChanged:112 if (m_isOpened != isOpened) {
300 menu->installEventFilter(this);113 m_isOpened = isOpened;
301 break;114 isOpenedChanged();
302 case QEvent::ActionRemoved:
303 menu->removeEventFilter(this);
304 break;
305 default:
306 break;
307 }
308 }
309
310 // Emit isEmptyChanged() if necessary
311 QList<QAction*> actions = m_widget->m_menuBar->actions();
312 if (event->type() == QEvent::ActionAdded && actions.count() == 1) {
313 QMetaObject::invokeMethod(m_widget, "isEmptyChanged");
314 } else if (event->type() == QEvent::ActionRemoved && actions.isEmpty()) {
315 QMetaObject::invokeMethod(m_widget, "isEmptyChanged");
316 }115 }
317}116}
318117
319118
=== modified file 'panel/applets/appname/menubarwidget.h'
--- panel/applets/appname/menubarwidget.h 2011-07-26 09:36:41 +0000
+++ panel/applets/appname/menubarwidget.h 2011-07-27 15:26:24 +0000
@@ -23,86 +23,45 @@
23#define MENUBARWIDGET_H23#define MENUBARWIDGET_H
2424
25// Qt25// Qt
26#include <QHash>
27#include <QWidget>26#include <QWidget>
2827
29class BamfWindow;28// libunity-core
3029#include <UnityCore/Indicator.h>
31class QActionEvent;30#include <UnityCore/IndicatorEntry.h>
32class QDBusObjectPath;31
33class QMenu;32class QHBoxLayout;
34class QMenuBar;33
35class QTimer;34class IndicatorEntryWidget;
3635class IndicatorsManager;
37class MyDBusMenuImporter;36
38class Registrar;37class MenuBarWidget : public QWidget, public sigc::trackable
3938{
40typedef QHash<WId, MyDBusMenuImporter*> ImporterForWId;39Q_OBJECT
4140public:
42class MenuBarWidget;41 MenuBarWidget(IndicatorsManager*, QWidget* parent = 0);
43
44/**
45 * An helper class which monitors the menubar and emits MenuBarWidget::menuBarClosed()
46 * when necessary
47 */
48class MenuBarClosedHelper : public QObject
49{
50Q_OBJECT
51public:
52 MenuBarClosedHelper(MenuBarWidget*);
53
54protected:
55 bool eventFilter(QObject*, QEvent*); //reimp
56
57private Q_SLOTS:
58 void emitMenuBarClosed();
59
60private:
61 MenuBarWidget* m_widget;
62 void menuBarActionEvent(QActionEvent*);
63};
64
65class MenuBarWidget : public QWidget
66{
67Q_OBJECT
68public:
69 MenuBarWidget(QMenu* windowMenu, QWidget* parent = 0);
7042
71 bool isEmpty() const;43 bool isEmpty() const;
72 bool isOpened() const;44 bool isOpened() const;
7345
74Q_SIGNALS:46Q_SIGNALS:
75 void menuBarClosed();47 void isOpenedChanged();
76 void isEmptyChanged();48 void isEmptyChanged();
7749
78protected:
79 bool eventFilter(QObject*, QEvent*); // reimp
80
81private Q_SLOTS:50private Q_SLOTS:
82 void slotActiveWindowChanged(BamfWindow*, BamfWindow*);51 void updateIsEmpty();
83 void slotViewOpened();
84 void slotWindowRegistered(WId, const QString& service, const QDBusObjectPath& menuObjectPath);
85 void slotWindowUnregistered(WId);
86 void slotMenuUpdated();
87 void slotActionActivationRequested(QAction* action);
88 void updateMenuBar();
8952
90private:53private:
91 Q_DISABLE_COPY(MenuBarWidget)54 Q_DISABLE_COPY(MenuBarWidget)
9255
93 QMenuBar* m_menuBar;56 IndicatorsManager* m_indicatorsManager;
94 Registrar* m_registrar;57 QHBoxLayout* m_layout;
95 ImporterForWId m_importers;58 bool m_isEmpty;
96 WId m_activeWinId;59 bool m_isOpened;
97 QMenu* m_windowMenu;60 QList<IndicatorEntryWidget*> m_widgetList;
98 QTimer* m_updateMenuBarTimer;61
9962 void onObjectAdded(const unity::indicator::Indicator::Ptr&);
100 void setupRegistrar();63 void onEntryAdded(const unity::indicator::Entry::Ptr&);
101 void setupMenuBar();64 void onEntryActivated(const std::string&);
102 QMenu* menuForWinId(WId) const;
103 void updateActiveWinId(BamfWindow*);
104
105 friend class MenuBarClosedHelper;
106};65};
10766
108#endif /* MENUBARWIDGET_H */67#endif /* MENUBARWIDGET_H */
10968
=== removed file 'panel/applets/appname/registrar.cpp'
--- panel/applets/appname/registrar.cpp 2011-04-04 16:46:14 +0000
+++ panel/applets/appname/registrar.cpp 1970-01-01 00:00:00 +0000
@@ -1,138 +0,0 @@
1/*
2 * Plasma applet to display application window menus
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22// Self
23#include "registrar.h"
24
25// Qt
26#include <QApplication>
27#include <QDBusMessage>
28#include <QDBusObjectPath>
29#include <QDBusServiceWatcher>
30
31// Local
32#include "registraradaptor.h"
33
34static const char* DBUS_SERVICE = "com.canonical.AppMenu.Registrar";
35static const char* DBUS_OBJECT_PATH = "/com/canonical/AppMenu/Registrar";
36
37// Marshalling code for MenuInfo
38QDBusArgument& operator<<(QDBusArgument& argument, const MenuInfo& info)
39{
40 argument.beginStructure();
41 argument << info.winId << info.service << info.path;
42 argument.endStructure();
43 return argument;
44}
45
46const QDBusArgument& operator>>(const QDBusArgument& argument, MenuInfo& info)
47{
48 argument.beginStructure();
49 argument >> info.winId >> info.service >> info.path;
50 argument.endStructure();
51 return argument;
52}
53
54Registrar::Registrar()
55: QObject()
56, mServiceWatcher(new QDBusServiceWatcher(this))
57{
58 qDBusRegisterMetaType<MenuInfo>();
59 qDBusRegisterMetaType<MenuInfoList>();
60 mServiceWatcher->setConnection(QDBusConnection::sessionBus());
61 mServiceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
62 connect(mServiceWatcher, SIGNAL(serviceUnregistered(const QString&)), SLOT(slotServiceUnregistered(const QString&)));
63}
64
65Registrar::~Registrar()
66{
67 QDBusConnection::sessionBus().unregisterService(mService);
68}
69
70Registrar* Registrar::instance()
71{
72 static Registrar singleton;
73 return &singleton;
74}
75
76bool Registrar::connectToBus(const QString& _service, const QString& _path)
77{
78 mService = _service.isEmpty() ? DBUS_SERVICE : _service;
79 QString path = _path.isEmpty() ? DBUS_OBJECT_PATH : _path;
80
81 bool ok = QDBusConnection::sessionBus().registerService(mService);
82 if (!ok) {
83 return false;
84 }
85 new RegistrarAdaptor(this);
86 QDBusConnection::sessionBus().registerObject(path, this);
87
88 return true;
89}
90
91void Registrar::RegisterWindow(WId wid, const QDBusObjectPath& menuObjectPath)
92{
93 MenuInfo info;
94 info.winId = wid;
95 info.service = message().service();
96 info.path = menuObjectPath;
97 mDb.insert(wid, info);
98 mServiceWatcher->addWatchedService(info.service);
99 WindowRegistered(wid, info.service, info.path);
100}
101
102void Registrar::UnregisterWindow(WId wid)
103{
104 mDb.remove(wid);
105 WindowUnregistered(wid);
106}
107
108QString Registrar::GetMenuForWindow(WId winId, QDBusObjectPath& menuObjectPath)
109{
110 MenuInfo info = mDb.value(winId);
111 QString service = info.service;
112 menuObjectPath = info.path;
113 return service;
114}
115
116MenuInfoList Registrar::GetMenus()
117{
118 return mDb.values();
119}
120
121void Registrar::slotServiceUnregistered(const QString& service)
122{
123 MenuInfoDb::Iterator
124 it = mDb.begin(),
125 end = mDb.end();
126 for (;it != end;) {
127 if (it.value().service == service) {
128 WId id = it.key();
129 it = mDb.erase(it);
130 WindowUnregistered(id);
131 } else {
132 ++it;
133 }
134 }
135 mServiceWatcher->removeWatchedService(service);
136}
137
138#include "registrar.moc"
1390
=== removed file 'panel/applets/appname/registrar.h'
--- panel/applets/appname/registrar.h 2011-04-04 16:47:28 +0000
+++ panel/applets/appname/registrar.h 1970-01-01 00:00:00 +0000
@@ -1,85 +0,0 @@
1/*
2 * Plasma applet to display application window menus
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef REGISTRAR_H
23#define REGISTRAR_H
24
25// Qt
26#include <QDBusContext>
27#include <QDBusObjectPath>
28#include <QObject>
29#include <QWidget> // For WId
30
31class QDBusObjectPath;
32class QDBusServiceWatcher;
33class QMenu;
34
35struct MenuInfo
36{
37 MenuInfo()
38 : winId(0)
39 , path("/")
40 {}
41
42 uint winId;
43 QString service;
44 QDBusObjectPath path;
45};
46Q_DECLARE_METATYPE(MenuInfo)
47
48typedef QList<MenuInfo> MenuInfoList;
49Q_DECLARE_METATYPE(MenuInfoList)
50
51class Registrar : public QObject, protected QDBusContext
52{
53 Q_OBJECT
54
55public:
56 /* The registrar is a singleton shared between all instances of MenuBarWidget. */
57 static Registrar* instance();
58
59 bool connectToBus(const QString& service = QString(), const QString& objectPath = QString());
60
61Q_SIGNALS:
62 void WindowRegistered(WId wid, const QString& service, const QDBusObjectPath&);
63 void WindowUnregistered(WId wid);
64
65public Q_SLOTS:
66 Q_NOREPLY void RegisterWindow(WId wid, const QDBusObjectPath& menuObjectPath);
67 Q_NOREPLY void UnregisterWindow(WId wid);
68 QString GetMenuForWindow(WId wid, QDBusObjectPath& menuObjectPath);
69 MenuInfoList GetMenus();
70
71private Q_SLOTS:
72 void slotServiceUnregistered(const QString& service);
73
74private:
75 Registrar();
76 Q_DISABLE_COPY(Registrar)
77 ~Registrar();
78
79 QDBusServiceWatcher* mServiceWatcher;
80 typedef QHash<WId, MenuInfo> MenuInfoDb;
81 MenuInfoDb mDb;
82 QString mService;
83};
84
85#endif /* REGISTRAR_H */
860
=== added file 'panel/applets/common/fakecairo.h'
--- panel/applets/common/fakecairo.h 1970-01-01 00:00:00 +0000
+++ panel/applets/common/fakecairo.h 2011-07-27 15:26:24 +0000
@@ -0,0 +1,125 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21#ifndef FAKECAIRO_H
22#define FAKECAIRO_H
23
24// NuxCore
25#include <NuxCore/Color.h>
26
27// Qt
28#include <QPainter>
29#include <QPainterPath>
30
31/*
32 * This module attempts to fake Cairo calls using QPainter, making it easier to
33 * port Cairo paint operations to Qt
34 */
35struct fcairo_t
36{
37 fcairo_t(QPainter* _painter)
38 : painter(_painter)
39 {
40 painter->save();
41 }
42
43 ~fcairo_t()
44 {
45 painter->restore();
46 }
47
48 QPainter* painter;
49 QPainterPath path;
50};
51
52inline void fcairo_arc(fcairo_t& cr, qreal xc, qreal yc, qreal radius, qreal angle1, qreal angle2)
53{
54 QRectF rect(xc - radius, yc - radius, radius * 2, radius * 2);
55
56 while (angle2 < angle1) {
57 angle2 += 2 * M_PI;
58 }
59
60 qreal start = (2. - angle1 / M_PI) * 180;
61 qreal stop = (2. - angle2 / M_PI) * 180;
62 cr.path.arcTo(rect, start, stop - start);
63}
64
65inline void fcairo_move_to(fcairo_t& cr, qreal x, qreal y)
66{
67 cr.path.moveTo(x, y);
68}
69
70inline void fcairo_line_to(fcairo_t& cr, qreal x, qreal y)
71{
72 cr.path.lineTo(x, y);
73}
74
75inline void fcairo_fill_preserve(fcairo_t& cr)
76{
77 cr.painter->fillPath(cr.path, cr.painter->brush());
78}
79
80inline void fcairo_stroke(fcairo_t& cr)
81{
82 QPen pen(cr.painter->brush().color(), 1);
83 cr.painter->strokePath(cr.path, pen);
84 cr.path = QPainterPath();
85}
86
87typedef QGradient fcairo_pattern_t;
88
89inline fcairo_pattern_t* fcairo_pattern_create_linear (qreal x1, qreal y1, qreal x2, qreal y2)
90{
91 return new QLinearGradient(x1, y1, x2, y2);
92}
93
94inline void fcairo_pattern_destroy(fcairo_pattern_t* pattern)
95{
96 delete pattern;
97}
98
99inline void fcairo_pattern_add_color_stop_rgba(fcairo_pattern_t* pattern, qreal offset, qreal r, qreal g, qreal b, qreal a)
100{
101 pattern->setColorAt(offset, QColor::fromRgbF(r, g, b, a));
102}
103
104inline void fcairo_set_source(fcairo_t& cr, fcairo_pattern_t* pattern)
105{
106 cr.painter->setPen(Qt::NoPen);
107 cr.painter->setBrush(*pattern);
108}
109
110inline void fcairo_set_source_rgb(fcairo_t& cr, qreal r, qreal g, qreal b)
111{
112 cr.painter->setBrush(QColor::fromRgbF(r, g, b));
113}
114
115inline nux::color::Color nuxColorFromQColor(const QColor& qColor)
116{
117 nux::color::Color color;
118 color.red = qColor.redF();
119 color.green = qColor.greenF();
120 color.blue = qColor.blueF();
121 color.alpha = qColor.alphaF();
122 return color;
123}
124
125#endif /* FAKECAIRO_H */
0126
=== added file 'panel/applets/common/indicatorentrywidget.cpp'
--- panel/applets/common/indicatorentrywidget.cpp 1970-01-01 00:00:00 +0000
+++ panel/applets/common/indicatorentrywidget.cpp 2011-07-27 15:26:24 +0000
@@ -0,0 +1,388 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21// Self
22#include "indicatorentrywidget.h"
23
24// Local
25#include <debug_p.h>
26#include <fakecairo.h>
27#include <panelstyle.h>
28
29// Qt
30#include <QIcon>
31#include <QPainter>
32#include <QWheelEvent>
33
34// GTK
35#include <gtk/gtk.h>
36
37// libc
38#include <time.h>
39
40static const int SPACING = 3;
41static const int PADDING = 3;
42
43using namespace unity::indicator;
44
45// Copied from libdbusmenu-qt
46static QString swapMnemonicChar(const QString &in, const char src, const char dst)
47{
48 QString out;
49 bool mnemonicFound = false;
50
51 for (int pos = 0; pos < in.length(); ) {
52 QChar ch = in[pos];
53 if (ch == src) {
54 if (pos == in.length() - 1) {
55 // 'src' at the end of string, skip it
56 ++pos;
57 } else {
58 if (in[pos + 1] == src) {
59 // A real 'src'
60 out += src;
61 pos += 2;
62 } else if (!mnemonicFound) {
63 // We found the mnemonic
64 mnemonicFound = true;
65 out += dst;
66 ++pos;
67 } else {
68 // We already have a mnemonic, just skip the char
69 ++pos;
70 }
71 }
72 } else if (ch == dst) {
73 // Escape 'dst'
74 out += dst;
75 out += dst;
76 ++pos;
77 } else {
78 out += ch;
79 ++pos;
80 }
81 }
82
83 return out;
84}
85
86IndicatorEntryWidget::IndicatorEntryWidget(const Entry::Ptr& entry)
87: m_entry(entry)
88, m_padding(PADDING)
89, m_hasIcon(false)
90, m_hasLabel(false)
91{
92 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
93 m_entry->updated.connect(sigc::mem_fun(this, &IndicatorEntryWidget::updatePix));
94 updatePix();
95}
96
97QSize IndicatorEntryWidget::minimumSizeHint() const
98{
99 return sizeHint();
100}
101
102QSize IndicatorEntryWidget::sizeHint() const
103{
104 return m_pix.size();
105}
106
107void IndicatorEntryWidget::paintEvent(QPaintEvent*)
108{
109 if (!m_pix.isNull()) {
110 QPainter painter(this);
111 if (m_entry->active()) {
112 paintActiveBackground(&painter);
113 }
114 painter.drawPixmap(0, 0, m_pix);
115 }
116}
117
118
119void IndicatorEntryWidget::paintActiveBackground(QPainter* painter)
120{
121 // This code should be kept in sync with the draw_menu_bg() function from
122 // plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp
123 int radius = 4;
124 double x = 0;
125 double y = 0;
126 double xos = 0.5;
127 double yos = 0.5;
128 /* FIXME */
129 double mpi = 3.14159265358979323846;
130
131 PanelStyle* style = PanelStyle::instance();
132 nux::color::Color bgtop = nuxColorFromQColor(style->backgroundTopColor());
133 nux::color::Color bgbot = nuxColorFromQColor(style->backgroundBottomColor());
134 nux::color::Color line = nuxColorFromQColor(style->lineColor());
135
136 painter->setRenderHint(QPainter::Antialiasing);
137
138 fcairo_t cr(painter);
139
140 fcairo_move_to (cr, x+xos+radius, y+yos);
141 fcairo_arc (cr, x+xos+width()-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
142 fcairo_line_to (cr, x+xos+width()-xos*2, y+yos+height()-yos*2+2);
143 fcairo_line_to (cr, x+xos, y+yos+height()-yos*2+2);
144 fcairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
145
146 fcairo_pattern_t * pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+2);
147 fcairo_pattern_add_color_stop_rgba (pat, 0.0,
148 bgtop.red,
149 bgtop.green,
150 bgtop.blue,
151 1.0f - bgbot.red);
152 fcairo_pattern_add_color_stop_rgba (pat, 1.0,
153 bgbot.red,
154 bgbot.green,
155 bgbot.blue,
156 1.0f - bgtop.red);
157 fcairo_set_source (cr, pat);
158 fcairo_fill_preserve (cr);
159 fcairo_pattern_destroy (pat);
160
161 /*
162 pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+2);
163 fcairo_pattern_add_color_stop_rgba (pat, 0.0,
164 line.red,
165 line.green,
166 line.blue,
167 1.0f);
168 fcairo_pattern_add_color_stop_rgba (pat, 1.0,
169 line.red,
170 line.green,
171 line.blue,
172 1.0f);
173 fcairo_set_source (cr, pat);
174 */
175 fcairo_set_source_rgb (cr, line.red, line.green, line.blue);
176 fcairo_stroke (cr);
177 //fcairo_pattern_destroy (pat);
178
179 xos++;
180 yos++;
181
182 /* enlarging the area to not draw the lightborder at bottom, ugly trick :P */
183 fcairo_move_to (cr, x+radius+xos, y+yos);
184 fcairo_arc (cr, x+xos+width()-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
185 fcairo_line_to (cr, x+xos+width()-xos*2, y+yos+height()-yos*2+3);
186 fcairo_line_to (cr, x+xos, y+yos+height()-yos*2+3);
187 fcairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
188
189 /*
190 pat = fcairo_pattern_create_linear (x+xos, y, x+xos, y+height()-yos*2+3);
191 fcairo_pattern_add_color_stop_rgba (pat, 0.0,
192 bgbot.red,
193 bgbot.green,
194 bgbot.blue,
195 1.0f);
196 fcairo_pattern_add_color_stop_rgba (pat, 1.0,
197 bgbot.red,
198 bgbot.green,
199 bgbot.blue,
200 1.0f);
201 fcairo_set_source (cr, pat);
202 */
203 fcairo_set_source_rgb (cr, bgbot.red, bgbot.green, bgbot.blue);
204 fcairo_stroke (cr);
205 //fcairo_pattern_destroy (pat);
206}
207
208void IndicatorEntryWidget::updatePix()
209{
210 bool oldIsEmpty = isEmpty();
211
212 int width = m_padding;
213 int iconX = m_padding;
214 int labelX = 0;
215
216 // Compute width, labelX and update m_has{Icon,Label}
217 QPixmap iconPix;
218 if (m_entry->image_visible()) {
219 iconPix = decodeIcon();
220 m_hasIcon = !iconPix.isNull();
221 } else {
222 m_hasIcon = false;
223 }
224 if (m_hasIcon) {
225 width += iconPix.width();
226 }
227
228 QString label = QString::fromUtf8(m_entry->label().c_str());
229 label = swapMnemonicChar(label, '_', '&');
230 m_hasLabel = !label.isEmpty() && m_entry->label_visible();
231 if (m_hasLabel) {
232 if (m_hasIcon) {
233 width += SPACING;
234 }
235 labelX = width;
236 QString visibleLabel = label;
237 visibleLabel.remove('&');
238 width += fontMetrics().width(visibleLabel);
239 }
240
241 width += m_padding;
242
243 // Paint
244 QPixmap oldPix = m_pix;
245 if (!m_hasIcon && !m_hasLabel) {
246 m_pix = QPixmap();
247 } else {
248 m_pix = QPixmap(width, 24);
249 m_pix.fill(Qt::transparent);
250 QPainter painter(&m_pix);
251 painter.initFrom(this);
252 if (m_hasIcon) {
253 bool disabled = !m_entry->image_sensitive();
254 if (disabled) {
255 painter.setOpacity(0.5);
256 }
257 painter.drawPixmap(iconX, 0, iconPix);
258 if (disabled) {
259 painter.setOpacity(1);
260 }
261 }
262 if (m_hasLabel) {
263 PanelStyle* style = PanelStyle::instance();
264
265 int flags = Qt::AlignLeft | Qt::AlignVCenter;
266 flags |= m_entry->show_now() ? Qt::TextShowMnemonic : Qt::TextHideMnemonic;
267
268 // Shadow
269 QColor color = style->textShadowColor();
270 color.setAlphaF(1. - color.redF());
271 painter.setPen(color);
272 painter.drawText(labelX, 1, width - labelX, m_pix.height(), flags, label);
273
274 // Text
275 color = style->textColor();
276 color.setAlphaF(m_entry->label_sensitive() ? 1. : .5);
277 painter.setPen(color);
278 painter.drawText(labelX, 0, width - labelX, m_pix.height(), flags, label);
279 }
280 }
281
282 // Notify others we changed, but only trigger a layout update if necessary
283 if (m_pix.size() == oldPix.size()) {
284 update();
285 } else {
286 updateGeometry();
287 }
288 bool newIsEmpty = isEmpty();
289 if (newIsEmpty != oldIsEmpty) {
290 // If we emit isEmptyChanged() directly it won't reach any connected
291 // slot. I assume this is because this method is called as a response
292 // to a sigc++ signal.
293 QMetaObject::invokeMethod(this, "isEmptyChanged", Qt::QueuedConnection);
294 }
295}
296
297QPixmap IndicatorEntryWidget::decodeIcon()
298{
299 QPixmap pix;
300
301 int type = m_entry->image_type();
302
303 if (type == 0) {
304 // No icon
305 } else if (type == GTK_IMAGE_PIXBUF) {
306 QByteArray data = QByteArray::fromBase64(m_entry->image_data().c_str());
307 QImage image;
308 bool ok = image.loadFromData(data);
309 if (ok) {
310 pix = QPixmap::fromImage(image);
311 } else {
312 UQ_WARNING << "Failed to decode image";
313 }
314 } else if (type == GTK_IMAGE_ICON_NAME) {
315 QString name = QString::fromStdString(m_entry->image_data());
316 QIcon icon = QIcon::fromTheme(name);
317 pix = icon.pixmap(24, 24);
318 } else if (type == GTK_IMAGE_GICON) {
319 UQ_WARNING << "FIXME: Implement support for GTK_IMAGE_GICON image type";
320 } else {
321 UQ_WARNING << "Unknown image type" << m_entry->image_type();
322 }
323 return pix;
324}
325
326void IndicatorEntryWidget::mousePressEvent(QMouseEvent*)
327{
328 UQ_RETURN_IF_FAIL(m_hasIcon || m_hasLabel);
329 showMenu(Qt::LeftButton);
330}
331
332void IndicatorEntryWidget::mouseReleaseEvent(QMouseEvent*)
333{
334 UQ_VAR(this);
335 update();
336}
337
338void IndicatorEntryWidget::wheelEvent(QWheelEvent* event)
339{
340 m_entry->Scroll(event->delta());
341}
342
343void IndicatorEntryWidget::showMenu(Qt::MouseButton qtButton)
344{
345 if (m_entry->active()) {
346 return;
347 }
348 int nuxButton = qtButton == Qt::NoButton ? 0 : 1;
349 QPoint pos = mapToGlobal(rect().bottomLeft());
350 m_entry->ShowMenu(pos.x(), pos.y(),
351 time(NULL),
352 nuxButton
353 );
354}
355
356void IndicatorEntryWidget::setPadding(int padding)
357{
358 if (m_padding != padding) {
359 m_padding = padding;
360 updatePix();
361 }
362}
363
364bool IndicatorEntryWidget::event(QEvent* ev)
365{
366 bool ret = QWidget::event(ev);
367 switch (ev->type()) {
368 case QEvent::FontChange:
369 case QEvent::PaletteChange:
370 updatePix();
371 break;
372 default:
373 break;
374 }
375 return ret;
376}
377
378bool IndicatorEntryWidget::isEmpty() const
379{
380 return !m_hasIcon && !m_hasLabel;
381}
382
383unity::indicator::Entry::Ptr IndicatorEntryWidget::entry() const
384{
385 return m_entry;
386}
387
388#include "indicatorentrywidget.moc"
0389
=== added file 'panel/applets/common/indicatorentrywidget.h'
--- panel/applets/common/indicatorentrywidget.h 1970-01-01 00:00:00 +0000
+++ panel/applets/common/indicatorentrywidget.h 2011-07-27 15:26:24 +0000
@@ -0,0 +1,81 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21#ifndef INDICATORENTRYWIDGET_H
22#define INDICATORENTRYWIDGET_H
23
24// Local
25
26// libunity-core
27#include <UnityCore/IndicatorEntry.h>
28
29// Qt
30#include <QWidget>
31
32class QPainter;
33
34class IndicatorEntryWidget : public QWidget, public sigc::trackable
35{
36Q_OBJECT
37public:
38 IndicatorEntryWidget(const unity::indicator::Entry::Ptr& entry);
39
40 QSize minimumSizeHint() const;
41 QSize sizeHint() const;
42
43 void setPadding(int);
44
45 bool isEmpty() const;
46
47 unity::indicator::Entry::Ptr entry() const;
48
49 /**
50 * Shows the menu.
51 *
52 * When this method is called because of a click, button
53 * must be set to Qt::LeftButton.
54 *
55 * When it is called because user previously clicked an indicator and moved the
56 * mouse to another indicator, button must be set to Qt::NoButton.
57 */
58 void showMenu(Qt::MouseButton button);
59
60Q_SIGNALS:
61 void isEmptyChanged();
62
63protected:
64 void paintEvent(QPaintEvent*);
65 void mousePressEvent(QMouseEvent*);
66 void mouseReleaseEvent(QMouseEvent*);
67 void wheelEvent(QWheelEvent*);
68 bool event(QEvent*);
69
70private:
71 unity::indicator::Entry::Ptr m_entry;
72 QPixmap m_pix;
73 int m_padding;
74 bool m_hasIcon;
75 bool m_hasLabel;
76 void updatePix();
77 QPixmap decodeIcon();
78 void paintActiveBackground(QPainter*);
79};
80
81#endif /* INDICATORENTRYWIDGET_H */
082
=== added file 'panel/applets/common/indicatorsmanager.cpp'
--- panel/applets/common/indicatorsmanager.cpp 1970-01-01 00:00:00 +0000
+++ panel/applets/common/indicatorsmanager.cpp 2011-07-27 15:26:24 +0000
@@ -0,0 +1,176 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21// Self
22#include "indicatorsmanager.h"
23
24// Local
25#include <debug_p.h>
26#include <indicatorentrywidget.h>
27
28// Qt
29#include <QApplication>
30#include <QTimer>
31#include <QX11Info>
32
33// X11
34#include <X11/Xlib.h>
35
36using namespace unity::indicator;
37
38IndicatorsManager::IndicatorsManager(QObject* parent)
39: QObject(parent)
40, m_indicators(new DBusIndicators)
41, m_geometrySyncTimer(new QTimer(this))
42{
43 m_geometrySyncTimer->setInterval(0);
44 m_geometrySyncTimer->setSingleShot(true);
45 connect(m_geometrySyncTimer, SIGNAL(timeout()), SLOT(syncGeometries()));
46
47 m_indicators->on_entry_show_menu.connect(
48 sigc::mem_fun(this, &IndicatorsManager::onEntryShowMenu)
49 );
50
51 m_indicators->on_menu_pointer_moved.connect(
52 sigc::mem_fun(this, &IndicatorsManager::onMenuPointerMoved)
53 );
54
55 m_indicators->on_entry_activate_request.connect(
56 sigc::mem_fun(this, &IndicatorsManager::onEntryActivateRequest)
57 );
58
59 m_indicators->on_synced.connect(
60 sigc::mem_fun(this, &IndicatorsManager::onSynced)
61 );
62}
63
64unity::indicator::DBusIndicators::Ptr IndicatorsManager::indicators() const
65{
66 return m_indicators;
67}
68
69void IndicatorsManager::onEntryShowMenu(const std::string& /*entryId*/, int posX, int posY, int /*timestamp*/, int /*button*/)
70{
71 // Copied from plugins/unityshell/src/PanelView.cpp, in OnEntryShowMenu()
72 // Without this code, menus cannot be shown from mousePressEvent() (but can
73 // be shown from mouseReleaseEvent())
74 /*
75 Neil explanation:
76 On button down, X automatically gives Qt a passive grab on the mouse this
77 means that, if the panel service tries to grab the pointer to show the menu
78 (gtk does this automatically), it fails and the menu can't show.
79 We connect to the on_entry_show_menu signal, which is emitted before
80 DBusIndicators does anything else, and just break the grab.
81 */
82 Display* display = QX11Info::display();
83 XUngrabPointer(display, CurrentTime);
84 XFlush(display);
85
86 XButtonEvent event = {
87 ButtonRelease,
88 0,
89 False,
90 display,
91 0,
92 0,
93 0,
94 CurrentTime,
95 posX, posY,
96 posX, posY,
97 0,
98 Button1,
99 True
100 };
101 qApp->x11ProcessEvent(reinterpret_cast<XEvent*>(&event));
102}
103
104void IndicatorsManager::onMenuPointerMoved(int posX, int posY)
105{
106 QWidget* widget = QApplication::widgetAt(posX, posY);
107 IndicatorEntryWidget* entryWidget = qobject_cast<IndicatorEntryWidget*>(widget);
108 if (!entryWidget) {
109 return;
110 }
111 entryWidget->showMenu(Qt::NoButton);
112}
113
114void IndicatorsManager::onEntryActivateRequest(const std::string& entryId)
115{
116 if (entryId.empty()) {
117 return;
118 }
119 IndicatorEntryWidget* widget = 0;
120 Q_FOREACH(widget, m_widgetList) {
121 if (widget->entry()->id() == entryId) {
122 break;
123 }
124 }
125 if (!widget) {
126 UQ_WARNING << "Could not find a widget for IndicatorEntry with id" << QString::fromStdString(entryId);
127 return;
128 }
129 widget->showMenu(Qt::NoButton);
130}
131
132void IndicatorsManager::onSynced()
133{
134 QMetaObject::invokeMethod(m_geometrySyncTimer, "start", Qt::QueuedConnection);
135}
136
137void IndicatorsManager::addIndicatorEntryWidget(IndicatorEntryWidget* widget)
138{
139 m_widgetList.append(widget);
140 widget->installEventFilter(this);
141}
142
143bool IndicatorsManager::eventFilter(QObject*, QEvent* event)
144{
145 switch (event->type()) {
146 case QEvent::Show:
147 case QEvent::Hide:
148 case QEvent::Move:
149 case QEvent::Resize:
150 m_geometrySyncTimer->start();
151 break;
152 default:
153 break;
154 }
155 return false;
156}
157
158void IndicatorsManager::syncGeometries()
159{
160 EntryLocationMap locations;
161 Q_FOREACH(IndicatorEntryWidget* widget, m_widgetList) {
162 if (!widget->isVisible()) {
163 continue;
164 }
165 Entry::Ptr entry = widget->entry();
166 if (entry->IsUnused()) {
167 continue;
168 }
169 QPoint topLeft = widget->mapToGlobal(QPoint(0, 0));
170 nux::Rect rect(topLeft.x(), topLeft.y(), widget->width(), widget->height());
171 locations[widget->entry()->id()] = rect;
172 }
173 m_indicators->SyncGeometries("Panel", locations);
174}
175
176#include "indicatorsmanager.moc"
0177
=== added file 'panel/applets/common/indicatorsmanager.h'
--- panel/applets/common/indicatorsmanager.h 1970-01-01 00:00:00 +0000
+++ panel/applets/common/indicatorsmanager.h 2011-07-27 15:26:24 +0000
@@ -0,0 +1,70 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21#ifndef INDICATORSMANAGER_H
22#define INDICATORSMANAGER_H
23
24// Local
25
26// Qt
27#include <QMap>
28#include <QObject>
29
30// libunity-core
31#include <UnityCore/DBusIndicators.h>
32
33class QTimer;
34
35class IndicatorEntryWidget;
36
37/**
38 * Instantiates DBusIndicators and implement common behavior
39 */
40class IndicatorsManager : public QObject, public sigc::trackable
41{
42 Q_OBJECT
43public:
44 IndicatorsManager(QObject* parent);
45
46 unity::indicator::DBusIndicators::Ptr indicators() const;
47
48 void addIndicatorEntryWidget(IndicatorEntryWidget* widget);
49
50protected:
51 bool eventFilter(QObject*, QEvent*);
52
53private Q_SLOTS:
54 void syncGeometries();
55
56private:
57 Q_DISABLE_COPY(IndicatorsManager)
58 unity::indicator::DBusIndicators::Ptr m_indicators;
59 QTimer* m_geometrySyncTimer;
60
61 typedef QList<IndicatorEntryWidget*> IndicatorEntryWidgetList;
62 IndicatorEntryWidgetList m_widgetList;
63
64 void onSynced();
65 void onEntryShowMenu(const std::string&, int x, int y, int timestamp, int button);
66 void onMenuPointerMoved(int x, int y);
67 void onEntryActivateRequest(const std::string& entryId);
68};
69
70#endif /* INDICATORSMANAGER_H */
071
=== added file 'panel/applets/common/indicatorwidget.cpp'
--- panel/applets/common/indicatorwidget.cpp 1970-01-01 00:00:00 +0000
+++ panel/applets/common/indicatorwidget.cpp 2011-07-27 15:26:24 +0000
@@ -0,0 +1,53 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21// Self
22#include "indicatorwidget.h"
23
24// Local
25#include <debug_p.h>
26#include <indicatorentrywidget.h>
27#include <indicatorsmanager.h>
28
29// Qt
30#include <QHBoxLayout>
31
32using namespace unity::indicator;
33
34IndicatorWidget::IndicatorWidget(const Indicator::Ptr& indicator, IndicatorsManager* manager)
35: m_layout(new QHBoxLayout(this))
36, m_indicatorsManager(manager)
37, m_indicator(indicator)
38{
39 m_layout->setMargin(0);
40 m_layout->setSpacing(0);
41
42 m_indicator->on_entry_added.connect(sigc::mem_fun(this, &IndicatorWidget::onEntryAdded));
43}
44
45void IndicatorWidget::onEntryAdded(const Entry::Ptr& entry)
46{
47 IndicatorEntryWidget* widget = new IndicatorEntryWidget(entry);
48 m_indicatorsManager->addIndicatorEntryWidget(widget);
49 m_layout->addWidget(widget);
50}
51
52
53#include "indicatorwidget.moc"
054
=== added file 'panel/applets/common/indicatorwidget.h'
--- panel/applets/common/indicatorwidget.h 1970-01-01 00:00:00 +0000
+++ panel/applets/common/indicatorwidget.h 2011-07-27 15:26:24 +0000
@@ -0,0 +1,52 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21#ifndef INDICATORWIDGET_H
22#define INDICATORWIDGET_H
23
24// Local
25
26// libunity-core
27#include <UnityCore/Indicator.h>
28#include <UnityCore/IndicatorEntry.h>
29
30// Qt
31#include <QWidget>
32
33class QHBoxLayout;
34
35class IndicatorEntryWidget;
36class IndicatorsManager;
37
38class IndicatorWidget : public QWidget, public sigc::trackable
39{
40Q_OBJECT
41public:
42 IndicatorWidget(const unity::indicator::Indicator::Ptr& indicator, IndicatorsManager* manager);
43
44private:
45 QHBoxLayout* m_layout;
46 IndicatorsManager* m_indicatorsManager;
47 unity::indicator::Indicator::Ptr m_indicator;
48
49 void onEntryAdded(const unity::indicator::Entry::Ptr& entry);
50};
51
52#endif /* INDICATORWIDGET_H */
053
=== added file 'panel/applets/common/panelstyle.cpp'
--- panel/applets/common/panelstyle.cpp 1970-01-01 00:00:00 +0000
+++ panel/applets/common/panelstyle.cpp 2011-07-27 15:26:24 +0000
@@ -0,0 +1,175 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21// Self
22#include "panelstyle.h"
23
24// libunity-2d
25#include <debug_p.h>
26#include <gconnector.h>
27#include <gscopedpointer.h>
28
29// Qt
30#include <QApplication>
31#include <QColor>
32#include <QFont>
33#include <QPalette>
34
35// GTK
36#include <gtk/gtk.h>
37#include <pango/pango.h>
38
39typedef void (*ColorGetter)(GtkStyleContext*, GtkStateFlags, GdkRGBA*);
40
41inline QColor colorFromContext(ColorGetter getter, GtkStyleContext* context, GtkStateFlags state)
42{
43 GdkRGBA color;
44 getter(context, state, &color);
45 return QColor::fromRgbF(color.red, color.green, color.blue, color.alpha);
46}
47
48class PanelStylePrivate
49{
50public:
51 PanelStyle* q;
52 GtkWidget* m_offScreenWindow;
53 GConnector m_gConnector;
54
55 QColor m_textColor;
56 QColor m_backgroundTopColor;
57 QColor m_backgroundBottomColor;
58 QColor m_textShadowColor;
59 QColor m_lineColor;
60 QFont m_font;
61
62 static void onThemeChanged(GObject*, GParamSpec*, gpointer data)
63 {
64 PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);
65 priv->updatePalette();
66 }
67
68 static void onFontChanged(GObject*, GParamSpec*, gpointer data)
69 {
70 PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);
71 priv->updateFont();
72 }
73
74 void updatePalette()
75 {
76 GtkStyleContext* context = gtk_widget_get_style_context(m_offScreenWindow);
77 UQ_RETURN_IF_FAIL(context);
78
79 m_textColor = colorFromContext(gtk_style_context_get_color, context, GTK_STATE_FLAG_NORMAL);
80 m_textShadowColor = colorFromContext(gtk_style_context_get_color, context, GTK_STATE_FLAG_SELECTED);
81 m_lineColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_NORMAL).darker(130);
82 m_backgroundTopColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_ACTIVE);
83 m_backgroundBottomColor = colorFromContext(gtk_style_context_get_background_color, context, GTK_STATE_FLAG_NORMAL);
84
85 QPalette pal;
86 pal.setColor(QPalette::Window, m_backgroundTopColor);
87 pal.setColor(QPalette::Button, m_backgroundTopColor);
88 pal.setColor(QPalette::Text, m_textColor);
89 pal.setColor(QPalette::WindowText, m_textColor);
90 pal.setColor(QPalette::ButtonText, m_textColor);
91 QApplication::setPalette(pal);
92 }
93
94 void updateFont()
95 {
96 gchar* fontName = 0;
97 g_object_get(gtk_settings_get_default(), "gtk-font-name", &fontName, NULL);
98 GScopedPointer<PangoFontDescription, pango_font_description_free> fontDescription(
99 pango_font_description_from_string(fontName)
100 );
101 g_free(fontName);
102
103 int size = pango_font_description_get_size(fontDescription.data());
104
105 m_font = QFont(
106 pango_font_description_get_family(fontDescription.data()),
107 size / PANGO_SCALE
108 );
109
110 QApplication::setFont(m_font);
111 }
112};
113
114PanelStyle::PanelStyle(QObject* parent)
115: d(new PanelStylePrivate)
116{
117 d->q = this;
118 d->m_offScreenWindow = gtk_offscreen_window_new();
119 gtk_widget_set_name(d->m_offScreenWindow, "UnityPanelWidget");
120 gtk_widget_set_size_request(d->m_offScreenWindow, 100, 24);
121 gtk_style_context_add_class(gtk_widget_get_style_context(d->m_offScreenWindow), "menubar");
122 gtk_widget_show_all(d->m_offScreenWindow);
123
124 d->m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-theme-name",
125 G_CALLBACK(PanelStylePrivate::onThemeChanged), d);
126 d->m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-font-name",
127 G_CALLBACK(PanelStylePrivate::onFontChanged), d);
128
129 d->updatePalette();
130 d->updateFont();
131}
132
133PanelStyle::~PanelStyle()
134{
135 gtk_widget_destroy(d->m_offScreenWindow);
136 delete d;
137}
138
139PanelStyle* PanelStyle::instance()
140{
141 static PanelStyle style;
142 return &style;
143}
144
145QColor PanelStyle::textColor() const
146{
147 return d->m_textColor;
148}
149
150QColor PanelStyle::backgroundTopColor() const
151{
152 return d->m_backgroundTopColor;
153}
154
155QColor PanelStyle::backgroundBottomColor() const
156{
157 return d->m_backgroundBottomColor;
158}
159
160QColor PanelStyle::textShadowColor() const
161{
162 return d->m_textShadowColor;
163}
164
165QColor PanelStyle::lineColor() const
166{
167 return d->m_lineColor;
168}
169
170QFont PanelStyle::font() const
171{
172 return d->m_font;
173}
174
175#include "panelstyle.moc"
0176
=== added file 'panel/applets/common/panelstyle.h'
--- panel/applets/common/panelstyle.h 1970-01-01 00:00:00 +0000
+++ panel/applets/common/panelstyle.h 2011-07-27 15:26:24 +0000
@@ -0,0 +1,59 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21#ifndef PANELSTYLE_H
22#define PANELSTYLE_H
23
24// Local
25
26// Qt
27#include <QObject>
28
29class QColor;
30class QFont;
31
32class PanelStylePrivate;
33/**
34 * Provides easy access to panel colors
35 */
36class PanelStyle : public QObject
37{
38 Q_OBJECT
39public:
40 PanelStyle(QObject* parent = 0);
41 ~PanelStyle();
42
43 static PanelStyle* instance();
44
45 QColor textColor() const;
46 QColor backgroundTopColor() const;
47 QColor backgroundBottomColor() const;
48 QColor textShadowColor() const;
49 QColor lineColor() const;
50
51 QFont font() const;
52
53private:
54 friend class PanelStylePrivate;
55 // Use a pimpl to avoid the need for gtk includes here
56 PanelStylePrivate* const d;
57};
58
59#endif /* PANELSTYLE_H */
060
=== added directory 'panel/applets/indicator'
=== removed directory 'panel/applets/indicator'
=== removed file 'panel/applets/indicator-config.h.in'
--- panel/applets/indicator-config.h.in 2011-03-01 09:04:13 +0000
+++ panel/applets/indicator-config.h.in 1970-01-01 00:00:00 +0000
@@ -1,7 +0,0 @@
1#ifndef INDICATOR_CONFIG_H
2#define INDICATOR_CONFIG_H
3
4#define INDICATOR_ICONS_DIR "${INDICATOR_ICONS_DIR}"
5#define INDICATOR_DIR "${INDICATOR_DIR}"
6
7#endif /* INDICATOR_CONFIG_H */
80
=== removed file 'panel/applets/indicator/abstractindicator.cpp'
--- panel/applets/indicator/abstractindicator.cpp 2011-01-15 01:41:03 +0000
+++ panel/applets/indicator/abstractindicator.cpp 1970-01-01 00:00:00 +0000
@@ -1,43 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22// Self
23#include "abstractindicator.h"
24
25// Local
26
27// Qt
28#include <QAction>
29
30AbstractIndicator::AbstractIndicator(QObject* parent)
31: QObject(parent)
32{
33}
34
35AbstractIndicator::~AbstractIndicator()
36{
37}
38
39void AbstractIndicator::init()
40{
41}
42
43#include "abstractindicator.moc"
440
=== removed file 'panel/applets/indicator/abstractindicator.h'
--- panel/applets/indicator/abstractindicator.h 2011-01-15 01:41:03 +0000
+++ panel/applets/indicator/abstractindicator.h 1970-01-01 00:00:00 +0000
@@ -1,53 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef ABSTRACTINDICATOR_H
23#define ABSTRACTINDICATOR_H
24
25// Local
26
27// Qt
28#include <QObject>
29
30class QAction;
31
32class AbstractIndicator : public QObject
33{
34 Q_OBJECT
35public:
36 AbstractIndicator(QObject* parent=0);
37 ~AbstractIndicator();
38
39 /**
40 * Called when the indicator has been constructed and its owner is connected to signals.
41 * It's the right place to emit actionAdded()
42 */
43 virtual void init();
44
45Q_SIGNALS:
46 void actionAdded(QAction*);
47 void actionRemoved(QAction*);
48
49private:
50 Q_DISABLE_COPY(AbstractIndicator)
51};
52
53#endif /* ABSTRACTINDICATOR_H */
540
=== removed file 'panel/applets/indicator/datetimeindicator.cpp'
--- panel/applets/indicator/datetimeindicator.cpp 2011-02-10 01:10:19 +0000
+++ panel/applets/indicator/datetimeindicator.cpp 1970-01-01 00:00:00 +0000
@@ -1,94 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22// Self
23#include "datetimeindicator.h"
24
25// Local
26#include "indicatorservicemanager.h"
27
28// dbusmenu-qt
29#include "dbusmenuimporter.h"
30
31// Qt
32#include <QAction>
33#include <QDateTime>
34
35// From dbus-shared.h
36#define SERVICE_NAME "com.canonical.indicator.datetime"
37#define SERVICE_IFACE "com.canonical.indicator.datetime.service"
38#define SERVICE_OBJ "/com.canonical/indicator/datetime/service"
39#define SERVICE_VERSION 1
40
41#define MENU_OBJ "/com.canonical/indicator/datetime/menu"
42
43#define DBUSMENU_CALENDAR_MENUITEM_TYPE "x-canonical-calendar-item"
44////
45
46DateTimeIndicator::DateTimeIndicator(QObject* parent)
47: AbstractIndicator(parent)
48, m_action(new QAction(this))
49, m_timer(new QTimer(this))
50{
51 new IndicatorServiceManager(SERVICE_NAME, SERVICE_VERSION, this);
52
53 readConfig();
54 setupMenu();
55 setupTimer();
56 updateText();
57}
58
59void DateTimeIndicator::init()
60{
61 actionAdded(m_action);
62}
63
64void DateTimeIndicator::setupMenu()
65{
66 DBusMenuImporter* importer = new DBusMenuImporter(SERVICE_NAME, MENU_OBJ, this);
67 m_action->setMenu(importer->menu());
68}
69
70void DateTimeIndicator::setupTimer()
71{
72 m_timer->setSingleShot(false);
73 connect(m_timer, SIGNAL(timeout()), SLOT(updateText()));
74 updateTimer();
75 m_timer->start();
76}
77
78void DateTimeIndicator::updateTimer()
79{
80 m_timer->setInterval(1000);
81}
82
83void DateTimeIndicator::updateText()
84{
85 QString text = QDateTime::currentDateTime().toString(m_format);
86 m_action->setText(text);
87}
88
89void DateTimeIndicator::readConfig()
90{
91 m_format = "hh:mm:ss";
92}
93
94#include "datetimeindicator.moc"
950
=== removed file 'panel/applets/indicator/datetimeindicator.h'
--- panel/applets/indicator/datetimeindicator.h 2011-01-15 01:41:03 +0000
+++ panel/applets/indicator/datetimeindicator.h 1970-01-01 00:00:00 +0000
@@ -1,53 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef DATETIMEINDICATOR_H
23#define DATETIMEINDICATOR_H
24
25// Local
26#include "abstractindicator.h"
27
28// Qt
29#include <QTimer>
30
31class DateTimeIndicator : public AbstractIndicator
32{
33 Q_OBJECT
34public:
35 DateTimeIndicator(QObject* parent=0);
36
37 virtual void init();
38
39private Q_SLOTS:
40 void updateText();
41private:
42 Q_DISABLE_COPY(DateTimeIndicator)
43 QAction* m_action;
44 QTimer* m_timer;
45 QString m_format;
46
47 void setupTimer();
48 void setupMenu();
49 void readConfig();
50 void updateTimer();
51};
52
53#endif /* DATETIMEINDICATOR_H */
540
=== removed file 'panel/applets/indicator/indicator.c'
--- panel/applets/indicator/indicator.c 2011-07-01 03:58:28 +0000
+++ panel/applets/indicator/indicator.c 1970-01-01 00:00:00 +0000
@@ -1,525 +0,0 @@
1/* Copyright (c) 2009 Mark Trompell <mark@foresightlinux.org>
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#include <string.h>
19
20#include <gtk/gtk.h>
21#include <libindicator/indicator-object.h>
22
23#include "indicator.h"
24
25#include "indicator-config.h"
26
27/* default settings */
28#define DEFAULT_SETTING1 NULL
29#define DEFAULT_SETTING2 1
30#define DEFAULT_SETTING3 FALSE
31
32typedef enum {
33 PANEL_APPLET_ORIENT_LEFT,
34 PANEL_APPLET_ORIENT_RIGHT,
35 PANEL_APPLET_ORIENT_TOP,
36 PANEL_APPLET_ORIENT_BOTTOM
37} PanelAppletOrient;
38
39// <indicator-applet-copy>
40static gchar * indicator_order[] = {
41 "libappmenu.so",
42 "libapplication.so",
43 "libsoundmenu.so",
44 "libnetworkmenu.so",
45 "libmessaging.so",
46 "libdatetime.so",
47 "libme.so",
48 "libsession.so",
49 NULL
50};
51
52static GtkPackDirection packdirection;
53static PanelAppletOrient orient;
54
55#define MENU_DATA_INDICATOR_OBJECT "indicator-object"
56#define MENU_DATA_INDICATOR_ENTRY "indicator-entry"
57
58#define IO_DATA_ORDER_NUMBER "indicator-order-number"
59
60static gint
61name2order (const gchar * name) {
62 int i;
63
64 for (i = 0; indicator_order[i] != NULL; i++) {
65 if (g_strcmp0(name, indicator_order[i]) == 0) {
66 return i;
67 }
68 }
69
70 return -1;
71}
72
73typedef struct _incoming_position_t incoming_position_t;
74struct _incoming_position_t {
75 gint objposition;
76 gint entryposition;
77 gint menupos;
78 gboolean found;
79};
80
81/* This function helps by determining where in the menu list
82 this new entry should be placed. It compares the objects
83 that they're on, and then the individual entries. Each
84 is progressively more expensive. */
85static void
86place_in_menu (GtkWidget * widget, gpointer user_data)
87{
88 incoming_position_t * position = (incoming_position_t *)user_data;
89 if (position->found) {
90 /* We've already been placed, just finish the foreach */
91 return;
92 }
93
94 IndicatorObject * io = INDICATOR_OBJECT(g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_OBJECT));
95 g_assert(io != NULL);
96
97 gint objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
98 /* We've already passed it, well, then this is where
99 we should be be. Stop! */
100 if (objposition > position->objposition) {
101 position->found = TRUE;
102 return;
103 }
104
105 /* The objects don't match yet, keep looking */
106 if (objposition < position->objposition) {
107 position->menupos++;
108 return;
109 }
110
111 /* The objects are the same, let's start looking at entries. */
112 IndicatorObjectEntry * entry = (IndicatorObjectEntry *)g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
113 gint entryposition = indicator_object_get_location(io, entry);
114
115 if (entryposition > position->entryposition) {
116 position->found = TRUE;
117 return;
118 }
119
120 if (entryposition < position->entryposition) {
121 position->menupos++;
122 return;
123 }
124
125 /* We've got the same object and the same entry. Well,
126 let's just put it right here then. */
127 position->found = TRUE;
128 return;
129}
130
131static void
132something_shown (GtkWidget * widget, gpointer user_data)
133{
134 GtkWidget * menuitem = GTK_WIDGET(user_data);
135 gtk_widget_show(menuitem);
136}
137
138static void
139something_hidden (GtkWidget * widget, gpointer user_data)
140{
141 GtkWidget * menuitem = GTK_WIDGET(user_data);
142 gtk_widget_hide(menuitem);
143}
144
145static void
146sensitive_cb (GObject * obj, GParamSpec * pspec, gpointer user_data)
147{
148 g_return_if_fail(GTK_IS_WIDGET(obj));
149 g_return_if_fail(GTK_IS_WIDGET(user_data));
150
151 gtk_widget_set_sensitive(GTK_WIDGET(user_data), gtk_widget_get_sensitive(GTK_WIDGET(obj)));
152 return;
153}
154
155static gboolean
156entry_scrolled (GtkWidget *menuitem, GdkEventScroll *event, gpointer data)
157{
158 IndicatorObject *io = g_object_get_data (G_OBJECT (menuitem), MENU_DATA_INDICATOR_OBJECT);
159 IndicatorObjectEntry *entry = g_object_get_data (G_OBJECT (menuitem), MENU_DATA_INDICATOR_ENTRY);
160
161 g_return_val_if_fail(INDICATOR_IS_OBJECT(io), FALSE);
162
163 g_signal_emit_by_name (io, "scroll", 1, event->direction);
164 g_signal_emit_by_name (io, "scroll-entry", entry, 1, event->direction);
165
166 return FALSE;
167}
168
169static void
170entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, GtkWidget * menubar)
171{
172 g_debug("Signal: Entry Added");
173 gboolean something_visible = FALSE;
174 gboolean something_sensitive = FALSE;
175
176 GtkWidget * menuitem = gtk_menu_item_new();
177 GtkWidget * box = (packdirection == GTK_PACK_DIRECTION_LTR) ?
178 gtk_hbox_new(FALSE, 3) : gtk_vbox_new(FALSE, 3);
179
180 g_object_set_data (G_OBJECT (menuitem), "indicator", io);
181 g_object_set_data (G_OBJECT (menuitem), "box", box);
182
183 if (entry->image != NULL) {
184 gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(entry->image), FALSE, FALSE, 0);
185 if (gtk_widget_get_visible(GTK_WIDGET(entry->image))) {
186 something_visible = TRUE;
187 }
188
189 if (gtk_widget_get_sensitive(GTK_WIDGET(entry->image))) {
190 something_sensitive = TRUE;
191 }
192
193 g_signal_connect(G_OBJECT(entry->image), "show", G_CALLBACK(something_shown), menuitem);
194 g_signal_connect(G_OBJECT(entry->image), "hide", G_CALLBACK(something_hidden), menuitem);
195
196 g_signal_connect(G_OBJECT(entry->image), "notify::sensitive", G_CALLBACK(sensitive_cb), menuitem);
197 }
198 if (entry->label != NULL) {
199 switch(packdirection) {
200 case GTK_PACK_DIRECTION_LTR:
201 gtk_label_set_angle(GTK_LABEL(entry->label), 0.0);
202 break;
203 case GTK_PACK_DIRECTION_TTB:
204 gtk_label_set_angle(GTK_LABEL(entry->label),
205 (orient == PANEL_APPLET_ORIENT_LEFT) ?
206 270.0 : 90.0);
207 break;
208 default:
209 break;
210 }
211 gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(entry->label), FALSE, FALSE, 0);
212
213 if (gtk_widget_get_visible(GTK_WIDGET(entry->label))) {
214 something_visible = TRUE;
215 }
216
217 if (gtk_widget_get_sensitive(GTK_WIDGET(entry->label))) {
218 something_sensitive = TRUE;
219 }
220
221 g_signal_connect(G_OBJECT(entry->label), "show", G_CALLBACK(something_shown), menuitem);
222 g_signal_connect(G_OBJECT(entry->label), "hide", G_CALLBACK(something_hidden), menuitem);
223
224 g_signal_connect(G_OBJECT(entry->label), "notify::sensitive", G_CALLBACK(sensitive_cb), menuitem);
225 }
226 gtk_container_add(GTK_CONTAINER(menuitem), box);
227 gtk_widget_show(box);
228
229 if (entry->menu != NULL) {
230 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
231 }
232
233 incoming_position_t position;
234 position.objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
235 position.entryposition = indicator_object_get_location(io, entry);
236 position.menupos = 0;
237 position.found = FALSE;
238
239 gtk_container_foreach(GTK_CONTAINER(menubar), place_in_menu, &position);
240
241 gtk_menu_shell_insert(GTK_MENU_SHELL(menubar), menuitem, position.menupos);
242
243 if (something_visible) {
244 gtk_widget_show(menuitem);
245 }
246 gtk_widget_set_sensitive(menuitem, something_sensitive);
247
248 g_object_set_data(G_OBJECT(menuitem), MENU_DATA_INDICATOR_ENTRY, entry);
249 g_object_set_data(G_OBJECT(menuitem), MENU_DATA_INDICATOR_OBJECT, io);
250 g_signal_connect(G_OBJECT (menuitem), "scroll-event", G_CALLBACK(entry_scrolled), NULL);
251
252 return;
253}
254
255static void
256entry_removed_cb (GtkWidget * widget, gpointer userdata)
257{
258 gpointer data = g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
259
260 if (data != userdata) {
261 return;
262 }
263
264 IndicatorObjectEntry * entry = (IndicatorObjectEntry *)data;
265 if (entry->label != NULL) {
266 g_signal_handlers_disconnect_by_func(G_OBJECT(entry->label), G_CALLBACK(something_shown), widget);
267 g_signal_handlers_disconnect_by_func(G_OBJECT(entry->label), G_CALLBACK(something_hidden), widget);
268 g_signal_handlers_disconnect_by_func(G_OBJECT(entry->label), G_CALLBACK(sensitive_cb), widget);
269 }
270 if (entry->image != NULL) {
271 g_signal_handlers_disconnect_by_func(G_OBJECT(entry->image), G_CALLBACK(something_shown), widget);
272 g_signal_handlers_disconnect_by_func(G_OBJECT(entry->image), G_CALLBACK(something_hidden), widget);
273 g_signal_handlers_disconnect_by_func(G_OBJECT(entry->image), G_CALLBACK(sensitive_cb), widget);
274 }
275
276 gtk_widget_destroy(widget);
277 return;
278}
279
280static void
281entry_removed (IndicatorObject * io G_GNUC_UNUSED, IndicatorObjectEntry * entry,
282 gpointer user_data)
283{
284 g_debug("Signal: Entry Removed");
285
286 gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);
287
288 return;
289}
290
291static void
292entry_moved_find_cb (GtkWidget * widget, gpointer userdata)
293{
294 gpointer * array = (gpointer *)userdata;
295 if (array[1] != NULL) {
296 return;
297 }
298
299 gpointer data = g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
300
301 if (data != array[0]) {
302 return;
303 }
304
305 array[1] = widget;
306 return;
307}
308
309/* Gets called when an entry for an object was moved. */
310static void
311entry_moved (IndicatorObject * io, IndicatorObjectEntry * entry,
312 gint old G_GNUC_UNUSED, gint new G_GNUC_UNUSED, gpointer user_data)
313{
314 GtkWidget * menubar = GTK_WIDGET(user_data);
315
316 gpointer array[2];
317 array[0] = entry;
318 array[1] = NULL;
319
320 gtk_container_foreach(GTK_CONTAINER(menubar), entry_moved_find_cb, array);
321 if (array[1] == NULL) {
322 g_warning("Moving an entry that isn't in our menus.");
323 return;
324 }
325
326 GtkWidget * mi = GTK_WIDGET(array[1]);
327 g_object_ref(G_OBJECT(mi));
328 gtk_container_remove(GTK_CONTAINER(menubar), mi);
329
330 incoming_position_t position;
331 position.objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
332 position.entryposition = indicator_object_get_location(io, entry);
333 position.menupos = 0;
334 position.found = FALSE;
335
336 gtk_container_foreach(GTK_CONTAINER(menubar), place_in_menu, &position);
337
338 gtk_menu_shell_insert(GTK_MENU_SHELL(menubar), mi, position.menupos);
339
340 g_object_unref(G_OBJECT(mi));
341
342 return;
343}
344
345static gboolean
346load_module (const gchar * name, GtkWidget * menubar)
347{
348 g_debug("Looking at Module: %s", name);
349 g_return_val_if_fail(name != NULL, FALSE);
350
351 if (!g_str_has_suffix(name, G_MODULE_SUFFIX)) {
352 return FALSE;
353 }
354
355 g_debug("Loading Module: %s", name);
356
357 /* Build the object for the module */
358 gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
359 IndicatorObject * io = indicator_object_new_from_file(fullpath);
360 g_free(fullpath);
361 g_return_val_if_fail(io != NULL, FALSE);
362
363 /* Attach the 'name' to the object */
364 g_object_set_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER, GINT_TO_POINTER(name2order(name)));
365
366 /* Connect to its signals */
367 g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menubar);
368 g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menubar);
369 g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED, G_CALLBACK(entry_moved), menubar);
370
371 /* Work on the entries */
372 GList * entries = indicator_object_get_entries(io);
373 GList * entry = NULL;
374
375 for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
376 IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
377 entry_added(io, entrydata, menubar);
378 }
379
380 g_list_free(entries);
381
382 return TRUE;
383}
384// </indicator-applet-copy>
385
386
387/* prototypes */
388static gboolean
389on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator);
390
391IndicatorPlugin *
392indicator_new ()
393{
394 IndicatorPlugin *indicator;
395 GtkOrientation orientation;
396 gint indicators_loaded = 0;
397
398 /* Hack! prevent the appmenu indicator from swallowing our own menubar */
399 setenv("APPMENU_DISPLAY_BOTH", "1");
400
401 /* allocate memory for the plugin structure */
402 indicator = g_new (IndicatorPlugin, 1);
403
404 indicator->container = gtk_plug_new(0);
405
406 /* Init some theme/icon stuff */
407 g_object_set (gtk_settings_get_default(), "gtk-theme-name", "Ambiance", NULL);
408 g_object_set (gtk_settings_get_default(), "gtk-icon-theme-name", "ubuntu-mono-dark", NULL);
409 gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
410 INDICATOR_ICONS_DIR);
411 gtk_rc_parse_string (
412 "widget \"indicator-applet*\" style \"panel\"\n"
413 "style \"indicator-applet-style\"\n"
414 "{\n"
415 " GtkMenuBar::shadow-type = none\n"
416 " GtkMenuBar::internal-padding = 0\n"
417 " GtkWidget::focus-line-width = 0\n"
418 " GtkWidget::focus-padding = 0\n"
419 "}\n"
420 "style \"indicator-applet-menubar-style\"\n"
421 "{\n"
422 " GtkMenuBar::shadow-type = none\n"
423 " GtkMenuBar::internal-padding = 0\n"
424 " GtkWidget::focus-line-width = 0\n"
425 " GtkWidget::focus-padding = 0\n"
426 " GtkMenuItem::horizontal-padding = 0\n"
427 "}\n"
428 "style \"indicator-applet-menuitem-style\"\n"
429 "{\n"
430 " GtkWidget::focus-line-width = 0\n"
431 " GtkWidget::focus-padding = 0\n"
432 " GtkMenuItem::horizontal-padding = 0\n"
433 "}\n"
434 "widget \"*.indicator-applet\" style \"indicator-applet-style\""
435 "widget \"*.indicator-applet-menuitem\" style \"indicator-applet-menuitem-style\""
436 "widget \"*.indicator-applet-menubar\" style \"indicator-applet-menubar-style\"");
437 gtk_widget_set_name(GTK_WIDGET (indicator->container), "indicator-applet");
438 /* create some panel widgets */
439
440 /* Build menu */
441 indicator->menu = gtk_menu_bar_new();
442 GTK_WIDGET_SET_FLAGS (indicator->menu, GTK_WIDGET_FLAGS(indicator->menu) | GTK_CAN_FOCUS);
443 gtk_widget_set_name(GTK_WIDGET (indicator->menu), "indicator-applet-menubar");
444 g_signal_connect(indicator->menu, "button-press-event", G_CALLBACK(on_menu_press), NULL);
445 //g_signal_connect_after(indicator->menu, "expose-event", G_CALLBACK(menu_on_expose), menu);
446 gtk_container_set_border_width(GTK_CONTAINER(indicator->menu), 0);
447
448 /* load 'em */
449 if (!g_file_test(INDICATOR_DIR, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
450 g_warning ("%s does not exist, cannot read any indicators", INDICATOR_DIR);
451 } else {
452 GDir *dir;
453 const gchar *name;
454
455 dir = g_dir_open(INDICATOR_DIR, 0, NULL);
456 while ((name = g_dir_read_name (dir)) != NULL) {
457 if (g_strcmp0(name, "libappmenu.so") == 0) {
458 continue;
459 }
460
461 if (load_module(name, indicator->menu)) {
462 indicators_loaded++;
463 } else {
464 g_warning("Failed to load module %s", name);
465 }
466 }
467 g_dir_close(dir);
468 }
469
470 if (indicators_loaded == 0) {
471 /* A label to allow for click through */
472 indicator->item = gtk_button_new();
473 gtk_button_set_label(GTK_BUTTON(indicator->item), "No Indicators");
474 gtk_widget_show(indicator->item);
475 gtk_container_add (GTK_CONTAINER (indicator->container), indicator->item);
476 } else {
477 gtk_widget_show(indicator->menu);
478 gtk_container_add (GTK_CONTAINER (indicator->container), indicator->menu);
479 }
480 return indicator;
481}
482
483
484
485void
486indicator_free (IndicatorPlugin *indicator)
487{
488 g_free(indicator);
489}
490
491
492#if 0
493static gboolean
494indicator_size_changed (XfcePanelPlugin *plugin,
495 gint size,
496 IndicatorPlugin *indicator)
497{
498 GtkOrientation orientation;
499
500 /* get the orientation of the plugin */
501 orientation = xfce_panel_plugin_get_orientation (plugin);
502
503 /* set the widget size */
504 if (orientation == GTK_ORIENTATION_HORIZONTAL)
505 gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
506 else
507 gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
508
509 /* we handled the orientation */
510 return TRUE;
511}
512#endif
513
514
515static gboolean
516on_menu_press (GtkWidget *widget, GdkEventButton *event, IndicatorPlugin *indicator)
517{
518 if (indicator != NULL && event->button == 1) /* left click only */
519 {
520 /* gtk_menu_popup (GTK_MENU(indicator->menu), NULL, NULL, NULL, NULL, 0,
521 event->time);*/
522 return TRUE;
523 }
524 return FALSE ;
525}
5260
=== removed file 'panel/applets/indicator/indicator.h'
--- panel/applets/indicator/indicator.h 2011-06-22 14:49:34 +0000
+++ panel/applets/indicator/indicator.h 1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
1/* Copyright (c) 2009 Mark Trompell <mark@foresightlinux.org>
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#ifndef __INDICATOR_H__
19#define __INDICATOR_H__
20
21#include <gtk/gtk.h>
22
23G_BEGIN_DECLS
24
25/* plugin structure */
26typedef struct _IndicatorPlugin
27{
28 GtkWidget *container;
29 /* panel widgets */
30 GtkWidget *menu;
31 GtkWidget *item;
32
33 /* indicator settings */
34}
35IndicatorPlugin;
36
37IndicatorPlugin *
38indicator_new ();
39
40void
41indicator_free(IndicatorPlugin*);
42
43G_END_DECLS
44
45#endif /* !__INDICATOR_H__ */
460
=== added file 'panel/applets/indicator/indicatorapplet.cpp'
--- panel/applets/indicator/indicatorapplet.cpp 1970-01-01 00:00:00 +0000
+++ panel/applets/indicator/indicatorapplet.cpp 2011-07-27 15:26:24 +0000
@@ -0,0 +1,58 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21// Self
22#include "indicatorapplet.h"
23
24// Local
25#include <debug_p.h>
26#include <indicatorsmanager.h>
27#include <indicatorwidget.h>
28
29// Qt
30#include <QHBoxLayout>
31
32using namespace unity::indicator;
33
34IndicatorApplet::IndicatorApplet(IndicatorsManager* manager)
35: m_indicatorsManager(manager)
36{
37 QHBoxLayout* layout = new QHBoxLayout(this);
38 layout->setMargin(0);
39 layout->setSpacing(0);
40 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
41
42 m_indicatorsManager->indicators()->on_object_added.connect(
43 sigc::mem_fun(this, &IndicatorApplet::onObjectAdded)
44 );
45}
46
47void IndicatorApplet::onObjectAdded(Indicator::Ptr const& indicator)
48{
49 QString name = QString::fromStdString(indicator->name());
50 if (name == "libappmenu.so") {
51 // appmenu indicator is handled by AppNameApplet
52 return;
53 }
54 IndicatorWidget* widget = new IndicatorWidget(indicator, m_indicatorsManager);
55 layout()->addWidget(widget);
56}
57
58#include "indicatorapplet.moc"
059
=== removed file 'panel/applets/indicator/indicatorapplet.cpp'
--- panel/applets/indicator/indicatorapplet.cpp 2011-06-22 14:49:34 +0000
+++ panel/applets/indicator/indicatorapplet.cpp 1970-01-01 00:00:00 +0000
@@ -1,114 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22// Self
23#include "indicatorapplet.h"
24
25// Local
26#include "abstractindicator.h"
27#include "datetimeindicator.h"
28#include "debug_p.h"
29#include "indicator.h"
30
31// Qt
32#include <QAction>
33#include <QDBusConnection>
34#include <QHBoxLayout>
35#include <QMenu>
36#include <QX11EmbedContainer>
37
38// Gtk
39#include <gdk/gdk.h>
40#include <gtk/gtk.h>
41
42IndicatorApplet::IndicatorApplet()
43{
44 setupUi();
45 loadIndicators();
46}
47
48void IndicatorApplet::setupUi()
49{
50 m_menuBar = new QMenuBar;
51 m_menuBar->setNativeMenuBar(false);
52 QHBoxLayout* layout = new QHBoxLayout(this);
53 layout->setMargin(0);
54 layout->addWidget(m_menuBar);
55
56 QMetaObject::invokeMethod(this, "createGtkIndicator", Qt::QueuedConnection);
57}
58
59void IndicatorApplet::createGtkIndicator()
60{
61 int* argc = 0;
62 char*** argv = 0;
63 gtk_init(argc, argv);
64
65 m_container = new QX11EmbedContainer;
66 layout()->addWidget(m_container);
67
68 m_gtkIndicator = indicator_new();
69 m_container->embedClient(gtk_plug_get_id(GTK_PLUG(m_gtkIndicator->container)));
70 gtk_widget_show(m_gtkIndicator->container);
71
72 QTimer* timer = new QTimer(this);
73 timer->setInterval(1000);
74 timer->setSingleShot(false);
75 connect(timer, SIGNAL(timeout()), SLOT(adjustGtkIndicatorSize()));
76 timer->start();
77}
78
79void IndicatorApplet::adjustGtkIndicatorSize()
80{
81 GtkRequisition requisition;
82 gtk_widget_size_request(m_gtkIndicator->menu, &requisition);
83 m_container->setFixedWidth(requisition.width);
84}
85
86void IndicatorApplet::loadIndicators()
87{
88#if 0
89 // FIXME: Using Qt plugins
90 QList<AbstractIndicator*> indicators = QList<AbstractIndicator*>()
91 << new DateTimeIndicator(this)
92 ;
93
94 Q_FOREACH(AbstractIndicator* indicator, indicators) {
95 connect(indicator, SIGNAL(actionAdded(QAction*)), SLOT(slotActionAdded(QAction*)));
96 connect(indicator, SIGNAL(actionRemoved(QAction*)), SLOT(slotActionRemoved(QAction*)));
97 indicator->init();
98 }
99#endif
100}
101
102void IndicatorApplet::slotActionAdded(QAction* action)
103{
104 UQ_VAR(action->text());
105 m_menuBar->addAction(action);
106}
107
108void IndicatorApplet::slotActionRemoved(QAction* action)
109{
110 m_menuBar->removeAction(action);
111}
112
113
114#include "indicatorapplet.moc"
1150
=== added file 'panel/applets/indicator/indicatorapplet.h'
--- panel/applets/indicator/indicatorapplet.h 1970-01-01 00:00:00 +0000
+++ panel/applets/indicator/indicatorapplet.h 2011-07-27 15:26:24 +0000
@@ -0,0 +1,45 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef INDICATORAPPLET_H
23#define INDICATORAPPLET_H
24
25// Local
26#include <applet.h>
27
28// libunity-core
29#include <UnityCore/Indicator.h>
30
31class IndicatorsManager;
32
33class IndicatorApplet : public Unity2d::Applet, public sigc::trackable
34{
35Q_OBJECT
36public:
37 IndicatorApplet(IndicatorsManager* manager);
38
39private:
40 Q_DISABLE_COPY(IndicatorApplet)
41 IndicatorsManager* m_indicatorsManager;
42 void onObjectAdded(unity::indicator::Indicator::Ptr const&);
43};
44
45#endif /* INDICATORAPPLET_H */
046
=== removed file 'panel/applets/indicator/indicatorapplet.h'
--- panel/applets/indicator/indicatorapplet.h 2011-01-15 01:41:03 +0000
+++ panel/applets/indicator/indicatorapplet.h 1970-01-01 00:00:00 +0000
@@ -1,60 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef INDICATORAPPLET_H
23#define INDICATORAPPLET_H
24
25// Local
26#include <applet.h>
27
28// Qt
29#include <QDBusInterface>
30#include <QMenuBar>
31
32class QX11EmbedContainer;
33
34struct _IndicatorPlugin;
35
36class IndicatorApplet : public Unity2d::Applet
37{
38Q_OBJECT
39public:
40 IndicatorApplet();
41
42private Q_SLOTS:
43 void loadIndicators();
44 void slotActionAdded(QAction*);
45 void slotActionRemoved(QAction*);
46 void createGtkIndicator();
47 void adjustGtkIndicatorSize();
48
49private:
50 Q_DISABLE_COPY(IndicatorApplet)
51
52 QDBusInterface* m_watcher;
53 QMenuBar* m_menuBar;
54 QX11EmbedContainer* m_container;
55 struct _IndicatorPlugin* m_gtkIndicator;
56
57 void setupUi();
58};
59
60#endif /* INDICATORAPPLET_H */
610
=== removed file 'panel/applets/indicator/indicatorservicemanager.cpp'
--- panel/applets/indicator/indicatorservicemanager.cpp 2011-02-10 01:10:19 +0000
+++ panel/applets/indicator/indicatorservicemanager.cpp 1970-01-01 00:00:00 +0000
@@ -1,120 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22// Self
23#include "indicatorservicemanager.h"
24
25// Local
26#include "debug_p.h"
27
28// Qt
29#include <QAction>
30#include <QDBusConnection>
31#include <QDBusConnectionInterface>
32#include <QDBusMessage>
33#include <QDBusServiceWatcher>
34#include <QDBusReply>
35#include <QDBusInterface>
36
37static const char* INDICATOR_SERVICE_INTERFACE = "com.canonical.indicator.service";
38static const char* INDICATOR_SERVICE_OBJECT = "/com.canonical/indicator/service";
39static const uint INDICATOR_SERVICE_VERSION = 1;
40
41IndicatorServiceManager::IndicatorServiceManager(const char* name, uint version, QObject* parent)
42: QObject(parent)
43, m_serviceName(name)
44, m_serviceVersion(version)
45{
46 QDBusServiceWatcher* serviceWatcher = new QDBusServiceWatcher(this);
47 serviceWatcher->setConnection(QDBusConnection::sessionBus());
48 serviceWatcher->addWatchedService(m_serviceName);
49 connect(serviceWatcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
50 SLOT(slotServiceOwnerChanged(QString, QString, QString)));
51 connectToService();
52}
53
54IndicatorServiceManager::~IndicatorServiceManager()
55{
56 unwatchService();
57}
58
59void IndicatorServiceManager::connectToService()
60{
61 QDBusConnectionInterface* iface = QDBusConnection::sessionBus().interface();
62 QDBusReply<bool> reply = iface->isServiceRegistered(m_serviceName);
63 UQ_RETURN_IF_FAIL(reply.isValid());
64
65 if (reply.value()) {
66 watchService();
67 } else {
68 QDBusReply<void> reply = iface->startService(m_serviceName);
69 if (!reply.isValid()) {
70 UQ_WARNING << reply.error().message();
71 }
72 }
73}
74
75void IndicatorServiceManager::watchService()
76{
77 QDBusInterface iface(m_serviceName, INDICATOR_SERVICE_OBJECT, INDICATOR_SERVICE_INTERFACE);
78 QDBusPendingCall pending = iface.asyncCall("Watch");
79 QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(pending, this);
80 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(slotWatchFinished(QDBusPendingCallWatcher*)));
81}
82
83void IndicatorServiceManager::slotWatchFinished(QDBusPendingCallWatcher* watcher)
84{
85 QDBusMessage message = watcher->reply();
86 delete watcher;
87 UQ_RETURN_IF_FAIL(message.type() == QDBusMessage::ReplyMessage);
88 QVariantList args = message.arguments();
89 UQ_RETURN_IF_FAIL(args.count() == 2);
90
91 uint apiVersion = args.at(0).toUInt();
92 uint serviceVersion = args.at(1).toUInt();
93
94 if (apiVersion != INDICATOR_SERVICE_VERSION) {
95 UQ_WARNING << "Expected api version=" << INDICATOR_SERVICE_VERSION << "got" << apiVersion << "instead";
96 unwatchService();
97 return;
98 }
99 if (serviceVersion != m_serviceVersion) {
100 UQ_WARNING << "Expected service version=" << m_serviceVersion << "got" << serviceVersion << "instead";
101 unwatchService();
102 }
103}
104
105void IndicatorServiceManager::unwatchService()
106{
107 QDBusInterface iface(m_serviceName, INDICATOR_SERVICE_OBJECT, INDICATOR_SERVICE_INTERFACE);
108 iface.asyncCall("Unwatch");
109}
110
111void IndicatorServiceManager::slotServiceOwnerChanged(const QString& /*name*/, const QString& /*oldOwner*/, const QString& newOwner)
112{
113 if (newOwner.isNull()) {
114 // FIXME: Respawn
115 } else {
116 watchService();
117 }
118}
119
120#include "indicatorservicemanager.moc"
1210
=== removed file 'panel/applets/indicator/indicatorservicemanager.h'
--- panel/applets/indicator/indicatorservicemanager.h 2011-01-15 01:41:03 +0000
+++ panel/applets/indicator/indicatorservicemanager.h 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
1/*
2 * This file is part of unity-2d
3 *
4 * Copyright 2010 Canonical Ltd.
5 *
6 * Authors:
7 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef INDICATORSERVICEMANAGER_H
23#define INDICATORSERVICEMANAGER_H
24
25// Local
26
27// Qt
28#include <QObject>
29
30class QAction;
31class QDBusPendingCallWatcher;
32
33class IndicatorServiceManager : public QObject
34{
35 Q_OBJECT
36public:
37 IndicatorServiceManager(const char* name, uint version, QObject* parent=0);
38 ~IndicatorServiceManager();
39
40private Q_SLOTS:
41 void slotServiceOwnerChanged(const QString& name, const QString& oldOwner, const QString& newOwner);
42 void slotWatchFinished(QDBusPendingCallWatcher*);
43
44private:
45 Q_DISABLE_COPY(IndicatorServiceManager)
46 QString m_serviceName;
47 uint m_serviceVersion;
48
49 void connectToService();
50 void watchService();
51 void unwatchService();
52};
53
54#endif /* INDICATORSERVICEMANAGER_H */
550
=== removed directory 'panel/artwork'
=== removed file 'panel/artwork/background.png'
56Binary files panel/artwork/background.png 2010-11-23 16:13:46 +0000 and panel/artwork/background.png 1970-01-01 00:00:00 +0000 differ1Binary 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
=== removed file 'panel/artwork/divider.png'
57Binary files panel/artwork/divider.png 2010-11-23 16:13:46 +0000 and panel/artwork/divider.png 1970-01-01 00:00:00 +0000 differ2Binary 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