Merge lp:~njpatel/unity/nicer-glib-signals into lp:unity

Proposed by Neil J. Patel
Status: Merged
Merged at revision: 1291
Proposed branch: lp:~njpatel/unity/nicer-glib-signals
Merge into: lp:unity
Diff against target: 1961 lines (+1361/-170)
34 files modified
CMakeLists.txt (+3/-3)
UnityCore/CMakeLists.txt (+3/-1)
UnityCore/DBusIndicators.cpp (+79/-83)
UnityCore/GLibSignal-inl.h (+299/-0)
UnityCore/GLibSignal.cpp (+87/-0)
UnityCore/GLibSignal.h (+307/-0)
UnityCore/UnityCore.h (+0/-32)
plugins/unityshell/src/FavoriteStoreGSettings.h (+1/-1)
plugins/unityshell/src/IconTexture.cpp (+8/-7)
plugins/unityshell/src/Launcher.cpp (+1/-1)
plugins/unityshell/src/LauncherIcon.cpp (+1/-1)
plugins/unityshell/src/PanelHomeButton.cpp (+1/-1)
plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp (+2/-1)
plugins/unityshell/src/PanelIndicatorObjectEntryView.h (+1/-1)
plugins/unityshell/src/PanelIndicatorObjectView.h (+1/-1)
plugins/unityshell/src/PanelMenuView.cpp (+1/-1)
plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp (+1/-1)
plugins/unityshell/src/PanelTray.h (+0/-2)
plugins/unityshell/src/PanelView.cpp (+1/-1)
plugins/unityshell/src/PanelView.h (+1/-1)
plugins/unityshell/src/PlacesHomeView.cpp (+1/-1)
plugins/unityshell/src/PlacesSearchBar.cpp (+1/-1)
plugins/unityshell/src/PlacesSimpleTile.cpp (+1/-1)
plugins/unityshell/src/PlacesView.cpp (+1/-1)
plugins/unityshell/src/QuicklistMenuItem.cpp (+1/-1)
plugins/unityshell/src/WindowButtons.cpp (+10/-20)
po/unity.pot (+1/-1)
tests/CMakeLists.txt (+16/-4)
tests/test_glib_signals.cpp (+366/-0)
tests/test_glib_signals_utils.cpp (+102/-0)
tests/test_glib_signals_utils.h (+46/-0)
tests/test_glib_signals_utils_marshal.list (+6/-0)
tests/test_indicator_entry.cpp (+1/-1)
tests/test_main.cpp (+10/-0)
To merge this branch: bzr merge lp:~njpatel/unity/nicer-glib-signals
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Unity Team Pending
Review via email: mp+67439@code.launchpad.net

Description of the change

This branch adds support for a cleaner way to connect to signals on GObjects inside Unity.

The idea behind the branch is that, with the current way, we need to take care of a few very annoying things:
- Connect the signal to a static member in our class and access members/variables from the callback via "self->"
- We need to remember to disconnect the signals (g_signal_handler_disconnect) when our class destructs. This means we need to keep around the signal id returned from g_signal_connect, as well as remember to disconnect in our destructor.

Both of these things have led to clumsy/cluttered code, or bugs where we've accidentally looked over something (like disconnecting).

The idea behind this branch is to:
- Allow the calling class to connect to signals on a GObject using sigc::slots (either sigc::ptr_fun or, more likely, sigc::mem_fun).
- Automatically handle disconnection of the signal on destruction of a Signal instance.
- Add a SignalManager class to manage multiple connections to different GObjects for an object. It will automatically disconnect the signals when it destructs.

Both these things mean that it's possible to ditch the multiple "static void Foo", "guint my_signal_id_", and "g_signal_handler_disconnect", from a class and replace with a simple "SignalManager signal_manger_" variable.

= API/Code =

I've tried to make it as clean as possible to use API-wise. My only real regret is having to use "new Signal<..." with a smartpointer to pass Signal instances to the SignalManager class. As explained in the code, this was mostly to strike a balance between a clean API and also to reduce the likelihood of bugs being introduced if the Signal class was passed in by reference and it's details "stolen" from it by the instance in the Vector (only one Signal class should manage a unique connection at any time).

Apart from that, I heard you like templates, so I put templates in your templates, so you can derive when you derive.

Oh, there're tests.

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Yo Dawg,

I went a little deeper into this code and found that in tests/ you've added what looks like generated marshallers for glib callbacks. It might be better to autogenerate that a build time instead of shipping it in the source distribution since the *.list could change whenever we need a new marshaller. For example

add_executable (test-signals ... ${CMAKE_CURRENT_BINARY_DIR}/generated/test_glib_signals_utils_marshal.cpp
...)

file (MAKE_DIRECTORY ${CMAKE_CURRENT_BUILD_DIR}/generated)
add_custom_command (TARGET test-signals PRE_BUILD
COMMAND glib-genmarshals ${CMAKE_CURRENT_SOURCE_DIR}/test_glib_signals_utils_marshal.list
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)

That way we can create and perceive the marshallers at the same time, without the person doing the compiling ever knowing that!

(I can't comment on the nature of the code itself, knowing little about glib, however I do intend to run the tests and try it out)

Revision history for this message
Neil J. Patel (njpatel) wrote :

Thanks for reminding me, totally forgot to commit and push the generation before proposing the merge.

We already do this in services/CMakeFiles.txt, however the difference was that with all the funky new g++ flags we use, the code glib produces no longer compiles with g++, so had to add a small workaround for that for now. Going to see if I can just patch glib-genmarshal when I get some time.

Revision history for this message
Tim Penhey (thumper) wrote :

OK Neil,

Well your description makes me keen to look at the code :-)

First question, since we are looking to use more glib stuff inside nux itself,
do you think perhaps the GLibSignal headers should go into nux itself?

Looking at a line like this:

  signal_manager_.Add (new glib::Signal<void, GDBusProxy*, char*, char*, GVariant*>
    (proxy_, "g-signal", sigc::mem_fun(this, &Impl::OnProxySignalReceived)));

It makes me wonder if we could simplify it. Given that the compiler has
enough type inference based on the sigc::mem_fun, we could perhaps get the
compiler to work out what glib::Signal we need, so we don't need to specify
it. I'm not entirely clear on the magic needed, but I'm 99% sure that it
could be done, allowing something like:

  signal_manager_.Add(proxy_, "g-signal",
                      sigc::mem_fun(this, &Impl::OnProxySignalReceived));

Perhaps for later...

Authored by in UnityCore/GLibSignal-inl.h, do you want to capitalise patel?

Please don't use capital O, or lowercase L for any single character variables
or type markers. It becomes non-obvious as zero is a valid template arg
(if the template is expecting an int tempate param).

Also, aligning the params in a multiline arguement clause actually hinders
readability (for me) - see the "O object"

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Function_Names
recommends that the accessors look like:

  GObject* object() const;
  std::string const& name() const;

The Signal template class constructor should take the std::string as a const&.

You should make the SignalManager non-copyable, and it doesn't need to define
a destructor, and certainly not a virtual destructor. The add method should
take SignalBase::Ptr const& as the param, not SignalBase*.

UnityCore/UnityCore.h makes me sad. Can we delete it?

I'm not clear on why you want the GObject type defined in the Signal template
parameteres. It seems to me that they could be removed completely and just
use a GObject*. Oh... I see now. It is the first param to the callback.
This was a little confusing as you have the first param given a special name.

Comments in tests are OK :-) I'd like to know what
TestGLibSignals.TestCleanDestruction is testing exactly.

Also, why do you sometimes pass in the address of a gboolean to
g_signal_emit_by_name?

I don't undestand the gobject test signal class and marshallers, but I'll
trust you on that.

On the whole, a bit +1 from me, but ask if you want to fix the Add method to
not need new signal ...

review: Needs Information
Revision history for this message
Tim Penhey (thumper) wrote :

r1294 fails to compile for me locally... I'm looking into it.

Revision history for this message
Tim Penhey (thumper) wrote :

CMakeFiles/test-gtest.dir/test_glib_signals.cpp.o: In function `(anonymous namespace)::TestGLibSignals_TestConstructions_Test::TestBody()':
test_glib_signals.cpp:(.text+0x4f5): undefined reference to `unity::glib::SignalBase::SignalBase()'
test_glib_signals.cpp:(.text+0x69f): undefined reference to `unity::glib::SignalBase::~SignalBase()'
test_glib_signals.cpp:(.text+0x7bc): undefined reference to `unity::glib::SignalBase::~SignalBase()'

and many more. It seems that the test is trying to link against the installed unity-core library rather than the one it has just compiled. Ideas?

Revision history for this message
Neil J. Patel (njpatel) wrote :
Download full text (3.5 KiB)

> OK Neil,
>
> Well your description makes me keen to look at the code :-)
>
> First question, since we are looking to use more glib stuff inside nux itself,
> do you think perhaps the GLibSignal headers should go into nux itself?

Sure, though let's get through a review here and then I can move over to Nux.

> Looking at a line like this:
>
> signal_manager_.Add (new glib::Signal<void, GDBusProxy*, char*, char*,
> GVariant*>
> (proxy_, "g-signal", sigc::mem_fun(this, &Impl::OnProxySignalReceived)));
>
> It makes me wonder if we could simplify it. Given that the compiler has
> enough type inference based on the sigc::mem_fun, we could perhaps get the
> compiler to work out what glib::Signal we need, so we don't need to specify
> it. I'm not entirely clear on the magic needed, but I'm 99% sure that it
> could be done, allowing something like:
>
> signal_manager_.Add(proxy_, "g-signal",
> sigc::mem_fun(this, &Impl::OnProxySignalReceived));

> Perhaps for later...

So, I implemented what we spoke about, however the compiler refuses to let it happen. It expects sigc::slot to be declared with the template types rather than being able to infer them from passes in sigc::bound_mem_functorN

Changing the arguments to take a sigc::bound_mem_functorN (where N is number of args), worked, but this is not a low-level class you can pass around, you'd need to create overrides for all the different types of functor's to make it work.

I'm not against that, but I'm hoping I messed something up that another pair of eyes can take a look at. I've moved everything to sigc::nil, could you try your idea out and let me know if you've more luck with it?

> Authored by in UnityCore/GLibSignal-inl.h, do you want to capitalise patel?
>
> Please don't use capital O, or lowercase L for any single character variables
> or type markers. It becomes non-obvious as zero is a valid template arg
> (if the template is expecting an int tempate param).

Both fixed.

> Also, aligning the params in a multiline arguement clause actually hinders
> readability (for me) - see the "O object"

I like it the way it is but not enough to care, can make that change before committing.

> http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Function_Names
> recommends that the accessors look like:
>
> GObject* object() const;
> std::string const& name() const;
>
> The Signal template class constructor should take the std::string as a const&.
>
> You should make the SignalManager non-copyable, and it doesn't need to define
> a destructor, and certainly not a virtual destructor.

All fixed.

> The add method should
> take SignalBase::Ptr const& as the param, not SignalBase*.

Hmm, doing this means that manager->Add becomes Add(SignalBase::Ptr(new Signal<void, GObject*, Bar*> (..... I don't like this. Am I missing something on how this would work? If the idea above works this is moot anyway.

> UnityCore/UnityCore.h makes me sad. Can we delete it?

Why?

> Comments in tests are OK :-) I'd like to know what
> TestGLibSignals.TestCleanDestruction is testing exactly.

If the object is no longer around, we shouldn't do anything stu...

Read more...

Revision history for this message
Tim Penhey (thumper) wrote :

Hi Neil,

After several hours of fluffing around trying to get a nicer Add method, I've
given up as well. It seems that the sigc wrappers don't give us access to the
type information for the function call arguments. We could perhaps submit a
patch to the sigc guys, but not with this branch.

I forgot that the shared_ptr has an explicit constructor, so passing through
the shared pointer would be a bit cumbersome as you mention. So lets not
worry about that here.

By having UnityCore/UnityCore.h we are pulling in headers that we don't care
about, and creating an artificial dependency between our code and other
headers that have no impact on the code in the source file. This increases
coupling between the files and increases compilation time.

review: Approve
Revision history for this message
Tim Penhey (thumper) wrote :

Actually, can you just change the using namespace sigc in the header to "using sigc::nul" ?

You should never have a using namespace * in a header.

Revision history for this message
Neil J. Patel (njpatel) wrote :

Okay, so last few commits should hopefully make this good for merge. Getting rid of UnityCore.h must have inflated the diff a bit but couldn't help that.

Revision history for this message
Neil J. Patel (njpatel) wrote :

Ah, forgot to answer the gboolean comment on this and Jason's merge proposal properly: bool and gboolean can be different sizes because "typedef int gboolean" (on my system sizeof(bool) = 1 and sizeof(gboolean)=4). As timeouts, signal-accumulators etc are often used by sending in a return location for the result (maybe from higher up in the callstack), sending a bool where glib expects to accumulate a gboolean causes all sorts of fun errors (timeouts sometimes return false but that is evaluated to TRUE, ask Sam :) and for things like GVariant we can easily cause memory errors.

So, since tackling a lot of this at the end of the last cycle (we managed to fix some of the worst crashes by auditing the bool/gboolean code), I've tried to make absolutely sure that we don't mix them up at all, even if it might be okay in some cases, I'd rather be more strict about it.

Ideally we'd reach a point where the few areas where we hit gboolean/guint32/etc/etc are handled by a wrapper that does the conversion back into standard C++ types internally and safely.

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Yep, that's static_cast <gboolean> ((bool) false) == TRUE :)

Revision history for this message
Tim Penhey (thumper) wrote :

On Mon, 18 Jul 2011 02:56:22 you wrote:
> Yep, that's static_cast <gboolean> ((bool) false) == TRUE :)

Casting can the be the source of many many problems. This is just one of the
reasons I don't like them.

They are a useful tool, but just because you have a hammer doesn't mean you
need to hit everything with it.

Revision history for this message
Neil J. Patel (njpatel) wrote :

Honestly I just do bool foo = my_gboolean == TRUE;

Seems the safest to me :)

Sent from my iPhone

On 17 Jul 2011, at 15:56, Sam Spilsbury <email address hidden> wrote:

> Yep, that's static_cast <gboolean> ((bool) false) == TRUE :)
>
> --
> https://code.launchpad.net/~njpatel/unity/nicer-glib-signals/+merge/67439
> You are the owner of lp:~njpatel/unity/nicer-glib-signals.

Revision history for this message
Tim Penhey (thumper) wrote :

On Mon, 18 Jul 2011 09:42:36 you wrote:
> Honestly I just do bool foo = my_gboolean == TRUE;
>
> Seems the safest to me :)

bool foo = my_gboolean is fine.

it is the casting of a bool to gboolean that is the issue.

The big issue here is exactly the above:

gboolean foo = 42; // entirely valid

foo -> true
bool(foo) -> true
foo != FALSE -> true
foo == TRUE -> false !!!!

We should not be doing == TRUE anywhere.

TRUE is defined to be !FALSE.
FALSE is defined to be 0.

The C (and C++) standard say that 0 is false, and anything else is considered
to be true. If we are checking for equality to TRUE on an integral type, we
may well have situations where the variable is neither TRUE nor FALSE. We
should only ever check for FALSE, or != FALSE. Checking for TRUE is a world
of pain for integral types.

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-10 14:16:30 +0000
+++ CMakeLists.txt 2011-07-15 10:26:29 +0000
@@ -16,9 +16,9 @@
16set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}")16set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}")
17set (UNITY_API_VERSION "4.0")17set (UNITY_API_VERSION "4.0")
1818
19set (CMAKE_CXX_FLAGS "-fno-permissive")19set (CMAKE_CXX_FLAGS "-std=c++0x -fno-permissive")
20set (CMAKE_CXX_FLAGS_DEBUG "-fno-permissive")20set (CMAKE_CXX_FLAGS_DEBUG "-std=c++0x -fno-permissive")
21set (CMAKE_CXX_FLAGS_RELEASE "-fno-permissive")21set (CMAKE_CXX_FLAGS_RELEASE "-std=c++0x -fno-permissive")
2222
23#23#
24# Niceties24# Niceties
2525
=== modified file 'UnityCore/CMakeLists.txt'
--- UnityCore/CMakeLists.txt 2011-06-22 14:08:16 +0000
+++ UnityCore/CMakeLists.txt 2011-07-15 10:26:29 +0000
@@ -6,17 +6,19 @@
6#6#
7set (CORE_HEADERS7set (CORE_HEADERS
8 DBusIndicators.h8 DBusIndicators.h
9 GLibSignal.h
10 GLibSignal-inl.h
9 GLibWrapper.h11 GLibWrapper.h
10 GLibWrapper-inl.h12 GLibWrapper-inl.h
11 IndicatorEntry.h13 IndicatorEntry.h
12 Indicator.h14 Indicator.h
13 Indicators.h15 Indicators.h
14 UnityCore.h
15 Variant.h16 Variant.h
16 )17 )
1718
18set (CORE_SOURCES19set (CORE_SOURCES
19 DBusIndicators.cpp20 DBusIndicators.cpp
21 GLibSignal.cpp
20 GLibWrapper.cpp22 GLibWrapper.cpp
21 Indicator.cpp23 Indicator.cpp
22 IndicatorEntry.cpp24 IndicatorEntry.cpp
2325
=== modified file 'UnityCore/DBusIndicators.cpp'
--- UnityCore/DBusIndicators.cpp 2011-06-29 15:40:49 +0000
+++ UnityCore/DBusIndicators.cpp 2011-07-15 10:26:29 +0000
@@ -27,6 +27,7 @@
27#include <X11/Xlib.h>27#include <X11/Xlib.h>
2828
29#include "config.h"29#include "config.h"
30#include "GLibSignal.h"
30#include "GLibWrapper.h"31#include "GLibWrapper.h"
31#include "Variant.h"32#include "Variant.h"
3233
@@ -83,12 +84,6 @@
83bool run_local_panel_service();84bool run_local_panel_service();
84gboolean reconnect_to_service(gpointer data);85gboolean reconnect_to_service(gpointer data);
85void on_proxy_ready_cb(GObject* source, GAsyncResult* res, gpointer data);86void on_proxy_ready_cb(GObject* source, GAsyncResult* res, gpointer data);
86void on_proxy_name_owner_changed(GDBusProxy* proxy, GParamSpec* pspec,
87 DBusIndicators::Impl* remote);
88void on_proxy_signal_received(GDBusProxy* proxy,
89 char* sender_name, char* signal_name,
90 GVariant* parameters,
91 DBusIndicators::Impl* remote);
92void request_sync(GDBusProxy* proxy, const char* method, GVariant* name,87void request_sync(GDBusProxy* proxy, const char* method, GVariant* name,
93 SyncData* data);88 SyncData* data);
94void on_sync_ready_cb(GObject* source, GAsyncResult* res, gpointer data);89void on_sync_ready_cb(GObject* source, GAsyncResult* res, gpointer data);
@@ -113,6 +108,11 @@
113 void Sync(GVariant* args, SyncData* data);108 void Sync(GVariant* args, SyncData* data);
114 void SyncGeometries(std::string const& name,109 void SyncGeometries(std::string const& name,
115 EntryLocationMap const& locations);110 EntryLocationMap const& locations);
111 void OnProxyNameOwnerChanged(GDBusProxy*proxy, GParamSpec *pspec);
112 void OnProxySignalReceived(GDBusProxy* proxy,
113 char* sender_name,
114 char* signal_name_,
115 GVariant* parameters);
116116
117 virtual void OnEntryScroll(std::string const& entry_id, int delta);117 virtual void OnEntryScroll(std::string const& entry_id, int delta);
118 virtual void OnEntryShowMenu(std::string const& entry_id,118 virtual void OnEntryShowMenu(std::string const& entry_id,
@@ -124,10 +124,10 @@
124124
125 DBusIndicators* owner_;125 DBusIndicators* owner_;
126 GDBusProxy* proxy_;126 GDBusProxy* proxy_;
127 guint32 proxy_signal_id_;
128 guint32 proxy_name_id_;
129 typedef std::vector<SyncDataPtr> PendingSyncs;127 typedef std::vector<SyncDataPtr> PendingSyncs;
130 PendingSyncs pending_syncs_;128 PendingSyncs pending_syncs_;
129
130 glib::SignalManager signal_manager_;
131};131};
132132
133133
@@ -143,8 +143,6 @@
143{143{
144 if (G_IS_OBJECT (proxy_))144 if (G_IS_OBJECT (proxy_))
145 {145 {
146 g_signal_handler_disconnect(proxy_, proxy_signal_id_);
147 g_signal_handler_disconnect(proxy_, proxy_name_id_);
148 g_object_unref(proxy_);146 g_object_unref(proxy_);
149 }147 }
150}148}
@@ -178,12 +176,11 @@
178 {176 {
179 proxy_ = proxy;177 proxy_ = proxy;
180 // Connect to interesting signals178 // Connect to interesting signals
181 proxy_signal_id_ = g_signal_connect(proxy_, "g-signal",179 signal_manager_.Add (new glib::Signal<void, GDBusProxy*, char*, char*, GVariant*>
182 G_CALLBACK(on_proxy_signal_received),180 (proxy_, "g-signal", sigc::mem_fun(this, &Impl::OnProxySignalReceived)));
183 this);181
184 proxy_name_id_ = g_signal_connect(proxy_, "notify::g-name-owner",182 signal_manager_.Add(new glib::Signal<void, GDBusProxy*,GParamSpec*>
185 G_CALLBACK(on_proxy_name_owner_changed),183 (proxy_, "notify::g-name-owner", sigc::mem_fun(this, &Impl::OnProxyNameOwnerChanged)));
186 this);
187 }184 }
188 RequestSyncAll();185 RequestSyncAll();
189}186}
@@ -373,6 +370,72 @@
373 return g_getenv("PANEL_USE_LOCAL_SERVICE") != NULL;370 return g_getenv("PANEL_USE_LOCAL_SERVICE") != NULL;
374}371}
375372
373void DBusIndicators::Impl::OnProxyNameOwnerChanged(GDBusProxy* proxy,
374 GParamSpec* pspec)
375{
376 char* name_owner = g_dbus_proxy_get_name_owner(proxy);
377
378 if (name_owner == NULL)
379 {
380 // The panel service has stopped for some reason. Restart it if not in
381 // dev mode
382 if (!g_getenv("UNITY_DEV_MODE"))
383 Reconnect();
384 }
385
386 g_free (name_owner);
387}
388
389void DBusIndicators::Impl::OnProxySignalReceived(GDBusProxy* proxy,
390 char* sender_name,
391 char* signal_name_,
392 GVariant* parameters)
393{
394 std::string signal_name(signal_name_);
395 if (signal_name == "EntryActivated")
396 {
397 const char* entry_name = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
398 if (entry_name) {
399 owner_->ActivateEntry(entry_name);
400 }
401 }
402 else if (signal_name == "EntryActivateRequest")
403 {
404 const char* entry_name = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
405 if (entry_name) {
406 owner_->on_entry_activate_request.emit(entry_name);
407 }
408 }
409 else if (signal_name == "ReSync")
410 {
411 const char* id = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
412 bool sync_one = !g_strcmp0 (id, "") == 0;
413
414 if (sync_one) {
415 RequestSyncIndicator(id);
416 }
417 else {
418 RequestSyncAll();
419 }
420 }
421 else if (signal_name == "ActiveMenuPointerMotion")
422 {
423 int x = 0;
424 int y = 0;
425 g_variant_get (parameters, "(ii)", &x, &y);
426 owner_->on_menu_pointer_moved.emit(x, y);
427 }
428 else if (signal_name == "EntryShowNowChanged")
429 {
430 gchar *id = NULL;
431 gboolean show_now;
432
433 g_variant_get (parameters, "(sb)", &id, &show_now);
434 owner_->SetEntryShowNow(id, show_now);
435
436 g_free (id);
437 }
438}
376439
377DBusIndicators::DBusIndicators()440DBusIndicators::DBusIndicators()
378 : pimpl(new Impl(this))441 : pimpl(new Impl(this))
@@ -495,73 +558,6 @@
495 return true;558 return true;
496}559}
497560
498void on_proxy_signal_received(GDBusProxy* proxy,
499 char* sender_name, char* signal_name_,
500 GVariant* parameters,
501 DBusIndicators::Impl* remote)
502{
503 std::string signal_name(signal_name_);
504 if (signal_name == "EntryActivated")
505 {
506 const char* entry_name = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
507 if (entry_name) {
508 remote->owner_->ActivateEntry(entry_name);
509 }
510 }
511 else if (signal_name == "EntryActivateRequest")
512 {
513 const char* entry_name = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
514 if (entry_name) {
515 remote->owner_->on_entry_activate_request.emit(entry_name);
516 }
517 }
518 else if (signal_name == "ReSync")
519 {
520 const char* id = g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL);
521 bool sync_one = !g_strcmp0 (id, "") == 0;
522
523 if (sync_one) {
524 remote->RequestSyncIndicator(id);
525 }
526 else {
527 remote->RequestSyncAll();
528 }
529 }
530 else if (signal_name == "ActiveMenuPointerMotion")
531 {
532 int x = 0;
533 int y = 0;
534 g_variant_get (parameters, "(ii)", &x, &y);
535 remote->owner_->on_menu_pointer_moved.emit(x, y);
536 }
537 else if (signal_name == "EntryShowNowChanged")
538 {
539 gchar *id = NULL;
540 gboolean show_now;
541
542 g_variant_get (parameters, "(sb)", &id, &show_now);
543 remote->owner_->SetEntryShowNow(id, show_now);
544
545 g_free (id);
546 }
547}
548
549void on_proxy_name_owner_changed(GDBusProxy* proxy, GParamSpec* pspec,
550 DBusIndicators::Impl* remote)
551{
552 char* name_owner = g_dbus_proxy_get_name_owner(proxy);
553
554 if (name_owner == NULL)
555 {
556 // The panel service has stopped for some reason. Restart it if not in
557 // dev mode
558 if (!g_getenv("UNITY_DEV_MODE"))
559 remote->Reconnect();
560 }
561
562 g_free (name_owner);
563}
564
565void request_sync(GDBusProxy* proxy, const char* method, GVariant* name, SyncData* data)561void request_sync(GDBusProxy* proxy, const char* method, GVariant* name, SyncData* data)
566{562{
567 g_dbus_proxy_call(proxy, method, name, G_DBUS_CALL_FLAGS_NONE,563 g_dbus_proxy_call(proxy, method, name, G_DBUS_CALL_FLAGS_NONE,
568564
=== added file 'UnityCore/GLibSignal-inl.h'
--- UnityCore/GLibSignal-inl.h 1970-01-01 00:00:00 +0000
+++ UnityCore/GLibSignal-inl.h 2011-07-15 10:26:29 +0000
@@ -0,0 +1,299 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2011 Canonical Ltd
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 version 3 as
7* published by the Free Software Foundation.
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* Authored by: Neil Jagdish patel <neil.patel@canonical.com>
18*/
19
20#ifndef UNITY_GLIB_SIGNAL_INL_H
21#define UNITY_GLIB_SIGNAL_INL_H
22
23namespace unity {
24namespace glib {
25
26template <typename R, typename G>
27Signal0<R, G>::Signal0()
28{}
29
30template <typename R, typename G>
31void Signal0<R, G>::Connect(G object,
32 std::string const& signal_name,
33 SignalCallback callback)
34{
35 object_ = reinterpret_cast<GObject*>(object);
36 name_ = signal_name;
37 callback_ = callback;
38 connection_id_ = g_signal_connect(object, signal_name.c_str (),
39 G_CALLBACK(Callback), this);
40}
41
42template <typename R, typename G>
43R Signal0<R, G>::Callback(G object, Signal0* self)
44{
45 return self->callback_(object);
46}
47
48template <typename R, typename G, typename T>
49Signal1<R, G, T>::Signal1()
50{}
51
52template <typename R, typename G, typename T>
53void Signal1<R, G, T>::Connect(G object,
54 std::string const& signal_name,
55 SignalCallback callback)
56{
57 object_ = reinterpret_cast<GObject*>(object);
58 name_ = signal_name;
59 callback_ = callback;
60 connection_id_ = g_signal_connect(object, signal_name.c_str (),
61 G_CALLBACK(Callback), this);
62}
63
64template <typename R, typename G, typename T>
65R Signal1<R, G, T>::Callback(G object, T data1, Signal1* self)
66{
67 return self->callback_(object, data1);
68}
69
70template <typename R, typename G, typename T1, typename T2>
71Signal2<R, G, T1, T2>::Signal2()
72{}
73
74template <typename R, typename G, typename T1, typename T2>
75void Signal2<R, G, T1, T2>::Connect(G object,
76 std::string const& signal_name,
77 SignalCallback callback)
78{
79 object_ = reinterpret_cast<GObject*>(object);
80 name_ = signal_name;
81 callback_ = callback;
82 connection_id_ = g_signal_connect(object, signal_name.c_str (),
83 G_CALLBACK (Callback), this);
84}
85
86template <typename R, typename G, typename T1, typename T2>
87R Signal2<R, G, T1, T2>::Callback(G object,
88 T1 data1,
89 T2 data2,
90 Signal2* self)
91{
92 return self->callback_(object, data1, data2);
93}
94
95template <typename R, typename G, typename T1, typename T2, typename T3>
96Signal3<R, G, T1, T2, T3>::Signal3()
97{}
98
99template <typename R, typename G, typename T1, typename T2, typename T3>
100void Signal3<R, G, T1, T2, T3>::Connect(G object,
101 std::string const& signal_name,
102 SignalCallback callback)
103{
104 object_ = reinterpret_cast<GObject*>(object);
105 name_ = signal_name;
106 callback_ = callback;
107 connection_id_ = g_signal_connect(object, signal_name.c_str (),
108 G_CALLBACK (Callback), this);
109}
110
111template <typename R, typename G, typename T1, typename T2, typename T3>
112R Signal3<R, G, T1, T2, T3>::Callback(G object,
113 T1 data1,
114 T2 data2,
115 T3 data3,
116 Signal3* self)
117{
118 return self->callback_(object, data1, data2, data3);
119}
120
121template <typename R, typename G, typename T1, typename T2, typename T3, typename T4>
122Signal4<R, G, T1, T2, T3, T4>::Signal4()
123{}
124
125template <typename R, typename G, typename T1, typename T2, typename T3, typename T4>
126void Signal4<R, G, T1, T2, T3, T4>::Connect(G object,
127 std::string const& signal_name,
128 SignalCallback callback)
129{
130 object_ = reinterpret_cast<GObject*>(object);
131 name_ = signal_name;
132 callback_ = callback;
133 connection_id_ = g_signal_connect(object, signal_name.c_str (),
134 G_CALLBACK (Callback), this);
135}
136
137template <typename R, typename G, typename T1, typename T2, typename T3, typename T4>
138R Signal4<R, G, T1, T2, T3, T4>::Callback(G object,
139 T1 data1,
140 T2 data2,
141 T3 data3,
142 T4 data4,
143 Signal4* self)
144{
145 return self->callback_(object, data1, data2, data3, data4);
146}
147
148
149template <typename R, typename G, typename T1, typename T2,
150 typename T3, typename T4, typename T5>
151Signal5<R, G, T1, T2, T3, T4, T5>::Signal5()
152{}
153
154template <typename R, typename G, typename T1, typename T2,
155 typename T3, typename T4, typename T5 >
156void Signal5<R, G, T1, T2, T3, T4, T5>::Connect(G object,
157 std::string const& signal_name,
158 SignalCallback callback)
159{
160 object_ = reinterpret_cast<GObject*>(object);
161 name_ = signal_name;
162 callback_ = callback;
163 connection_id_ = g_signal_connect(object, signal_name.c_str (),
164 G_CALLBACK (Callback), this);
165}
166
167template <typename R, typename G, typename T1, typename T2,
168 typename T3, typename T4, typename T5>
169R Signal5<R, G, T1, T2, T3, T4, T5>::Callback(G object,
170 T1 data1,
171 T2 data2,
172 T3 data3,
173 T4 data4,
174 T5 data5,
175 Signal5* self)
176{
177 return self->callback_(object, data1, data2, data3, data4, data5);
178}
179
180template <typename R, typename G, typename T1, typename T2,
181 typename T3, typename T4, typename T5 , typename T6>
182Signal6<R, G, T1, T2, T3, T4, T5, T6>::Signal6()
183{}
184
185template <typename R, typename G, typename T1, typename T2,
186 typename T3, typename T4, typename T5 , typename T6>
187void Signal6<R, G, T1, T2, T3, T4, T5, T6>::Connect(G object,
188 std::string const& signal_name,
189 SignalCallback callback)
190{
191 object_ = reinterpret_cast<GObject*>(object);
192 name_ = signal_name;
193 callback_ = callback;
194 connection_id_ = g_signal_connect(object, signal_name.c_str (),
195 G_CALLBACK (Callback), this);
196}
197
198template <typename R, typename G, typename T1, typename T2,
199 typename T3, typename T4, typename T5, typename T6>
200R Signal6<R, G, T1, T2, T3, T4, T5, T6>::Callback(G object,
201 T1 data1,
202 T2 data2,
203 T3 data3,
204 T4 data4,
205 T5 data5,
206 T6 data6,
207 Signal6* self)
208{
209 return self->callback_(object, data1, data2, data3, data4, data5, data6);
210}
211
212template<typename R, typename G>
213Signal<R, G>::Signal()
214{}
215
216template<typename R, typename G>
217Signal<R, G>::Signal(G object, std::string const& signal_name, SignalCallback callback)
218{
219 Connect(object, signal_name, callback);
220}
221
222template<typename R, typename G, typename T1>
223Signal<R, G, T1>::Signal()
224{}
225
226template<typename R, typename G, typename T1>
227Signal<R, G, T1>::Signal(G object, std::string const& signal_name, SignalCallback callback)
228{
229 Connect(object, signal_name, callback);
230}
231
232template<typename R, typename G, typename T1, typename T2>
233Signal<R, G, T1, T2>::Signal()
234{}
235
236template<typename R, typename G, typename T1, typename T2>
237Signal<R, G, T1, T2>::Signal(G object,
238 std::string const& signal_name,
239 SignalCallback callback)
240{
241 Connect(object, signal_name, callback);
242}
243
244template<typename R, typename G, typename T1, typename T2, typename T3>
245Signal<R, G, T1, T2, T3>::Signal()
246{}
247
248template<typename R, typename G, typename T1, typename T2, typename T3>
249Signal<R, G, T1, T2, T3>::Signal(G object,
250 std::string const& signal_name,
251 SignalCallback callback)
252{
253 Connect(object, signal_name, callback);
254}
255
256template<typename R, typename G, typename T1, typename T2, typename T3, typename T4>
257Signal<R, G, T1, T2, T3, T4>::Signal()
258{}
259
260template<typename R, typename G, typename T1, typename T2, typename T3, typename T4>
261Signal<R, G, T1, T2, T3, T4>::Signal(G object,
262 std::string const& signal_name,
263 SignalCallback callback)
264{
265 Connect(object, signal_name, callback);
266}
267
268template<typename R, typename G, typename T1, typename T2, typename T3, typename T4,
269 typename T5>
270Signal<R, G, T1, T2, T3, T4, T5>::Signal()
271{}
272
273template<typename R, typename G, typename T1, typename T2, typename T3, typename T4,
274 typename T5>
275Signal<R, G, T1, T2, T3, T4, T5>::Signal(G object,
276 std::string const& signal_name,
277 SignalCallback callback)
278{
279 Connect(object, signal_name, callback);
280}
281
282template<typename R, typename G, typename T1, typename T2, typename T3, typename T4,
283 typename T5, typename T6>
284Signal<R, G, T1, T2, T3, T4, T5, T6>::Signal()
285{}
286
287template<typename R, typename G, typename T1, typename T2, typename T3, typename T4,
288 typename T5, typename T6>
289Signal<R, G, T1, T2, T3, T4, T5, T6>::Signal(G object,
290 std::string const& signal_name,
291 SignalCallback callback)
292{
293 Connect(object, signal_name, callback);
294}
295
296}
297}
298
299#endif
0300
=== added file 'UnityCore/GLibSignal.cpp'
--- UnityCore/GLibSignal.cpp 1970-01-01 00:00:00 +0000
+++ UnityCore/GLibSignal.cpp 2011-07-15 10:26:29 +0000
@@ -0,0 +1,87 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2011 Canonical Ltd
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 version 3 as
7* published by the Free Software Foundation.
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* Authored by: Neil Jagdish patel <neil.patel@canonical.com>
18*/
19
20#include "GLibSignal.h"
21
22namespace unity {
23namespace glib {
24
25SignalBase::SignalBase()
26 : object_(0),
27 connection_id_(0)
28{}
29
30SignalBase::~SignalBase()
31{
32 Disconnect();
33}
34
35void SignalBase::Disconnect()
36{
37 if (G_IS_OBJECT(object_) && connection_id_)
38 g_signal_handler_disconnect(object_, connection_id_);
39
40 object_ = 0;
41 connection_id_ = 0;
42}
43
44GObject* SignalBase::object() const
45{
46 return object_;
47}
48
49std::string const& SignalBase::name() const
50{
51 return name_;
52}
53
54SignalManager::SignalManager()
55{}
56
57// Ideally this would be SignalBase& but there is a specific requirment to allow
58// only one instance of Signal to control a connection. With the templating, it
59// was too messy to try and write a copy constructor/operator that would steal
60// from "other" and make the new one the owner. Not only did it create
61// opportunity for random bugs, it also made the API bad.
62void SignalManager::Add(SignalBase* signal)
63{
64 SignalBase::Ptr s(signal);
65 connections_.push_back(s);
66}
67
68// This uses void* to keep in line with the g_signal* functions
69// (it allows you to pass in a GObject without casting up).
70void SignalManager::Disconnect(void* object, std::string const& signal_name)
71{
72 for (ConnectionVector::iterator it = connections_.begin();
73 it != connections_.end();
74 ++it)
75 {
76 if ((*it)->object() == object
77 && (*it)->name() == signal_name)
78 {
79 (*it)->Disconnect();
80 connections_.erase(it, it);
81 }
82 }
83}
84
85}
86}
87
088
=== added file 'UnityCore/GLibSignal.h'
--- UnityCore/GLibSignal.h 1970-01-01 00:00:00 +0000
+++ UnityCore/GLibSignal.h 2011-07-15 10:26:29 +0000
@@ -0,0 +1,307 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2011 Canonical Ltd
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 version 3 as
7* published by the Free Software Foundation.
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* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18*/
19
20#ifndef UNITY_GLIB_SIGNAL_H
21#define UNITY_GLIB_SIGNAL_H
22
23#include <string>
24#include <vector>
25#include <boost/noncopyable.hpp>
26#include <boost/shared_ptr.hpp>
27#include <glib-object.h>
28#include <sigc++/sigc++.h>
29
30namespace unity {
31namespace glib {
32
33using sigc::nil;
34
35class SignalBase
36{
37public:
38 typedef boost::shared_ptr<SignalBase> Ptr;
39
40 SignalBase();
41 virtual ~SignalBase();
42
43 void Disconnect();
44
45 GObject* object() const;
46 std::string const& name() const;
47
48protected:
49 GObject* object_;
50 guint32 connection_id_;
51 std::string name_;
52};
53
54template <typename R, typename G>
55class Signal0 : public SignalBase
56{
57public:
58 typedef sigc::slot<R, G> SignalCallback;
59
60 Signal0();
61
62 void Connect(G Object,
63 std::string const& signal_name,
64 SignalCallback cb);
65private:
66 static R Callback(G object, Signal0* self);
67private:
68 SignalCallback callback_;
69};
70
71template <typename R, typename G, typename T>
72class Signal1 : public SignalBase
73{
74public:
75 typedef sigc::slot<R, G, T> SignalCallback;
76
77 Signal1();
78
79 void Connect(G Object,
80 std::string const& signal_name,
81 SignalCallback callback);
82private:
83 static R Callback(G object, T data1, Signal1* self);
84private:
85 SignalCallback callback_;
86};
87
88template <typename R, typename G, typename T1, typename T2>
89class Signal2 : public SignalBase
90{
91public:
92 typedef sigc::slot<R, G, T1, T2> SignalCallback;
93
94 Signal2();
95
96 void Connect(G Object,
97 std::string const& signal_name,
98 SignalCallback callback);
99private:
100 static R Callback(G Object,
101 T1 data1,
102 T2 data2,
103 Signal2* self);
104private:
105 SignalCallback callback_;
106};
107
108template <typename R, typename G, typename T1, typename T2, typename T3>
109class Signal3 : public SignalBase
110{
111public:
112 typedef sigc::slot<R, G, T1, T2, T3> SignalCallback;
113
114 Signal3();
115
116 void Connect(G Object,
117 std::string const& signal_name,
118 SignalCallback callback);
119private:
120 static R Callback(G Object,
121 T1 data1,
122 T2 data2,
123 T3 data3,
124 Signal3* self);
125private:
126 SignalCallback callback_;
127};
128
129template <typename R, typename G, typename T1, typename T2, typename T3, typename T4>
130class Signal4 : public SignalBase
131{
132public:
133 typedef sigc::slot<R, G, T1, T2, T3, T4> SignalCallback;
134
135 Signal4();
136
137 void Connect(G Object,
138 std::string const& signal_name,
139 SignalCallback callback);
140private:
141 static R Callback(G Object,
142 T1 data1,
143 T2 data2,
144 T3 data3,
145 T4 data4,
146 Signal4* self);
147private:
148 SignalCallback callback_;
149};
150
151template <typename R, typename G, typename T1, typename T2,
152 typename T3, typename T4, typename T5>
153class Signal5 : public SignalBase
154{
155public:
156 typedef sigc::slot<R, G, T1, T2, T3, T4, T5> SignalCallback;
157
158 Signal5();
159
160 void Connect(G Object,
161 std::string const& signal_name,
162 SignalCallback callback);
163private:
164 static R Callback(G Object,
165 T1 data1,
166 T2 data2,
167 T3 data3,
168 T4 data4,
169 T5 data5,
170 Signal5* self);
171private:
172 SignalCallback callback_;
173};
174
175template <typename R, typename G, typename T1, typename T2,
176 typename T3, typename T4, typename T5, typename T6>
177class Signal6 : public SignalBase
178{
179public:
180 typedef sigc::slot<R, G, T1, T2, T3, T4, T5, T6> SignalCallback;
181
182 Signal6();
183
184 void Connect(G Object,
185 std::string const& signal_name,
186 SignalCallback callback);
187private:
188 static R Callback(G Object,
189 T1 data1,
190 T2 data2,
191 T3 data3,
192 T4 data4,
193 T5 data5,
194 T6 data6,
195 Signal6* self);
196private:
197 SignalCallback callback_;
198};
199
200template <typename R, typename G,
201 typename T1 = nil, typename T2 = nil,
202 typename T3 = nil, typename T4 = nil,
203 typename T5 = nil, typename T6 = nil>
204class Signal : public Signal6<R, G, T1, T2, T3, T4, T5, T6>
205{
206public:
207 typedef sigc::slot<R, G, T1, T2, T3, T4, T5, T6> SignalCallback;
208
209 inline Signal();
210 inline Signal(G Object,
211 std::string const& signal_name,
212 SignalCallback callback);
213};
214
215template <typename R, typename G>
216class Signal<R, G, nil, nil, nil, nil, nil, nil> : public Signal0<R, G>
217{
218public:
219 typedef sigc::slot<R, G> SignalCallback;
220
221 inline Signal();
222 inline Signal(G Object,
223 std::string const& signal_name,
224 SignalCallback callback);
225};
226
227template <typename R, typename G, typename T1>
228class Signal<R, G, T1, nil, nil, nil, nil, nil> : public Signal1<R, G, T1>
229{
230public:
231 typedef sigc::slot<R, G, T1> SignalCallback;
232
233 inline Signal();
234 inline Signal(G Object,
235 std::string const& signal_name,
236 SignalCallback callback);
237};
238
239template <typename R, typename G, typename T1, typename T2>
240class Signal<R, G, T1, T2, nil, nil, nil, nil> : public Signal2<R, G, T1, T2>
241{
242public:
243 typedef sigc::slot<R, G, T1, T2> SignalCallback;
244
245 inline Signal();
246 inline Signal(G Object,
247 std::string const& signal_name,
248 SignalCallback callback);
249};
250
251template <typename R, typename G, typename T1, typename T2, typename T3>
252class Signal<R, G, T1, T2, T3, nil, nil, nil> : public Signal3<R, G, T1, T2 ,T3>
253{
254public:
255 typedef sigc::slot<R, G, T1, T2, T3> SignalCallback;
256
257 inline Signal();
258 inline Signal(G Object,
259 std::string const& signal_name,
260 SignalCallback callback);
261};
262
263template <typename R, typename G, typename T1, typename T2, typename T3, typename T4>
264class Signal<R, G, T1, T2, T3, T4, nil, nil>
265 : public Signal4<R, G, T1, T2 ,T3, T4>
266{
267public:
268 typedef sigc::slot<R, G, T1, T2, T3, T4> SignalCallback;
269
270 inline Signal();
271 inline Signal(G Object,
272 std::string const& signal_name,
273 SignalCallback callback);
274};
275
276template <typename R, typename G, typename T1, typename T2, typename T3, typename T4, typename T5>
277class Signal<R, G, T1, T2, T3, T4, T5, nil>
278 : public Signal5<R, G, T1, T2 ,T3, T4, T5>
279{
280public:
281 typedef sigc::slot<R, G, T1, T2, T3, T4, T5> SignalCallback;
282
283 inline Signal();
284 inline Signal(G Object,
285 std::string const& signal_name,
286 SignalCallback callback);
287};
288
289class SignalManager : public boost::noncopyable
290{
291public:
292 typedef std::vector<SignalBase::Ptr> ConnectionVector;
293
294 SignalManager();
295 void Add(SignalBase* signal);
296 void Disconnect(void* object, std::string const& signal_name);
297
298private:
299 ConnectionVector connections_;
300};
301
302}
303}
304
305#include "GLibSignal-inl.h"
306
307#endif
0308
=== removed file 'UnityCore/UnityCore.h'
--- UnityCore/UnityCore.h 2011-06-21 12:10:09 +0000
+++ UnityCore/UnityCore.h 1970-01-01 00:00:00 +0000
@@ -1,32 +0,0 @@
1/*
2 * Copyright (C) 2011 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
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 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, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
17 */
18
19#ifndef _UNITY_CORE_H_
20#define _UNITY_CORE_H_
21
22// Single include for headers
23
24#include <UnityCore/DBusIndicators.h>
25#include <UnityCore/GLibWrapper.h>
26#include <UnityCore/GLibWrapper-inl.h>
27#include <UnityCore/Indicator.h>
28#include <UnityCore/IndicatorEntry.h>
29#include <UnityCore/Indicators.h>
30#include <UnityCore/Variant.h>
31
32#endif // _UNITY_CORE_H_
330
=== modified file 'plugins/unityshell/src/FavoriteStoreGSettings.h'
--- plugins/unityshell/src/FavoriteStoreGSettings.h 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/FavoriteStoreGSettings.h 2011-07-15 10:26:29 +0000
@@ -23,7 +23,7 @@
23#include <gio/gio.h>23#include <gio/gio.h>
2424
25#include "FavoriteStore.h"25#include "FavoriteStore.h"
26#include <UnityCore/UnityCore.h>26#include <UnityCore/GLibWrapper.h>
2727
28// An abstract object that facilitates getting and modifying the list of favorites28// An abstract object that facilitates getting and modifying the list of favorites
29// Use GetDefault () to get the correct store for the session29// Use GetDefault () to get the correct store for the session
3030
=== modified file 'plugins/unityshell/src/IconTexture.cpp'
--- plugins/unityshell/src/IconTexture.cpp 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/IconTexture.cpp 2011-07-15 10:26:29 +0000
@@ -19,16 +19,17 @@
1919
20#include "config.h"20#include "config.h"
2121
22#include "Nux/Nux.h"22#include <glib.h>
23#include "NuxGraphics/GLThread.h"23#include <gtk/gtk.h>
24#include <pango/pangocairo.h>
25
26#include <Nux/Nux.h>
27#include <NuxGraphics/GLThread.h>
28#include <UnityCore/Variant.h>
29
24#include "IconLoader.h"30#include "IconLoader.h"
25#include "IconTexture.h"31#include "IconTexture.h"
26#include "TextureCache.h"32#include "TextureCache.h"
27#include <UnityCore/UnityCore.h>
28
29#include <glib.h>
30#include <pango/pangocairo.h>
31#include <gtk/gtk.h>
3233
33#define DEFAULT_ICON "text-x-preview"34#define DEFAULT_ICON "text-x-preview"
3435
3536
=== modified file 'plugins/unityshell/src/Launcher.cpp'
--- plugins/unityshell/src/Launcher.cpp 2011-07-14 14:15:37 +0000
+++ plugins/unityshell/src/Launcher.cpp 2011-07-15 10:26:29 +0000
@@ -48,7 +48,7 @@
48#include "ubus-server.h"48#include "ubus-server.h"
49#include "UBusMessages.h"49#include "UBusMessages.h"
5050
51#include <UnityCore/UnityCore.h>51#include <UnityCore/Variant.h>
5252
53using namespace unity::ui;53using namespace unity::ui;
5454
5555
=== modified file 'plugins/unityshell/src/LauncherIcon.cpp'
--- plugins/unityshell/src/LauncherIcon.cpp 2011-07-14 14:37:26 +0000
+++ plugins/unityshell/src/LauncherIcon.cpp 2011-07-15 10:26:29 +0000
@@ -42,7 +42,7 @@
4242
43#include "ubus-server.h"43#include "ubus-server.h"
44#include "UBusMessages.h"44#include "UBusMessages.h"
45#include <UnityCore/UnityCore.h>45#include <UnityCore/Variant.h>
4646
47#define DEFAULT_ICON "application-default-icon"47#define DEFAULT_ICON "application-default-icon"
48#define MONO_TEST_ICON "gnome-home"48#define MONO_TEST_ICON "gnome-home"
4949
=== modified file 'plugins/unityshell/src/PanelHomeButton.cpp'
--- plugins/unityshell/src/PanelHomeButton.cpp 2011-07-01 14:58:41 +0000
+++ plugins/unityshell/src/PanelHomeButton.cpp 2011-07-15 10:26:29 +0000
@@ -33,7 +33,7 @@
33#include <gtk/gtk.h>33#include <gtk/gtk.h>
3434
35#include "PanelStyle.h"35#include "PanelStyle.h"
36#include <UnityCore/UnityCore.h>36#include <UnityCore/Variant.h>
3737
38#define PANEL_HEIGHT 2438#define PANEL_HEIGHT 24
3939
4040
=== modified file 'plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp'
--- plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp 2011-07-07 10:22:47 +0000
+++ plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp 2011-07-15 10:26:29 +0000
@@ -37,7 +37,8 @@
37#include "PanelIndicatorObjectEntryView.h"37#include "PanelIndicatorObjectEntryView.h"
3838
39#include "PanelStyle.h"39#include "PanelStyle.h"
40#include <UnityCore/UnityCore.h>40#include <UnityCore/GLibWrapper.h>
41#include <UnityCore/Variant.h>
4142
4243
43namespace unity {44namespace unity {
4445
=== modified file 'plugins/unityshell/src/PanelIndicatorObjectEntryView.h'
--- plugins/unityshell/src/PanelIndicatorObjectEntryView.h 2011-07-11 08:49:45 +0000
+++ plugins/unityshell/src/PanelIndicatorObjectEntryView.h 2011-07-15 10:26:29 +0000
@@ -25,7 +25,7 @@
25#include <NuxImage/CairoGraphics.h>25#include <NuxImage/CairoGraphics.h>
26#include <NuxGraphics/GraphicsEngine.h>26#include <NuxGraphics/GraphicsEngine.h>
2727
28#include <UnityCore/UnityCore.h>28#include <UnityCore/IndicatorEntry.h>
2929
30#include "Introspectable.h"30#include "Introspectable.h"
3131
3232
=== modified file 'plugins/unityshell/src/PanelIndicatorObjectView.h'
--- plugins/unityshell/src/PanelIndicatorObjectView.h 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/PanelIndicatorObjectView.h 2011-07-15 10:26:29 +0000
@@ -22,7 +22,7 @@
2222
23#include <Nux/View.h>23#include <Nux/View.h>
2424
25#include <UnityCore/UnityCore.h>25#include <UnityCore/Indicator.h>
26#include "PanelIndicatorObjectEntryView.h"26#include "PanelIndicatorObjectEntryView.h"
2727
28#include "Introspectable.h"28#include "Introspectable.h"
2929
=== modified file 'plugins/unityshell/src/PanelMenuView.cpp'
--- plugins/unityshell/src/PanelMenuView.cpp 2011-07-10 18:14:49 +0000
+++ plugins/unityshell/src/PanelMenuView.cpp 2011-07-15 10:26:29 +0000
@@ -31,7 +31,7 @@
3131
32#include "PanelMenuView.h"32#include "PanelMenuView.h"
33#include "PanelStyle.h"33#include "PanelStyle.h"
34#include <UnityCore/UnityCore.h>34#include <UnityCore/Variant.h>
3535
36#include "WindowManager.h"36#include "WindowManager.h"
3737
3838
=== modified file 'plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp'
--- plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp 2011-07-15 10:26:29 +0000
@@ -28,7 +28,7 @@
28#include "Nux/WindowCompositor.h"28#include "Nux/WindowCompositor.h"
2929
30#include "PanelTitlebarGrabAreaView.h"30#include "PanelTitlebarGrabAreaView.h"
31#include <UnityCore/UnityCore.h>31#include <UnityCore/Variant.h>
3232
33#include <glib.h>33#include <glib.h>
3434
3535
=== modified file 'plugins/unityshell/src/PanelTray.h'
--- plugins/unityshell/src/PanelTray.h 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/PanelTray.h 2011-07-15 10:26:29 +0000
@@ -24,8 +24,6 @@
2424
25#include <gdk/gdkx.h>25#include <gdk/gdkx.h>
2626
27#include <UnityCore/UnityCore.h>
28
29#include "Introspectable.h"27#include "Introspectable.h"
30#include "PanelIndicatorObjectView.h"28#include "PanelIndicatorObjectView.h"
3129
3230
=== modified file 'plugins/unityshell/src/PanelView.cpp'
--- plugins/unityshell/src/PanelView.cpp 2011-07-01 14:58:41 +0000
+++ plugins/unityshell/src/PanelView.cpp 2011-07-15 10:26:29 +0000
@@ -34,7 +34,7 @@
3434
35#include "PanelStyle.h"35#include "PanelStyle.h"
36#include "PanelIndicatorObjectView.h"36#include "PanelIndicatorObjectView.h"
37#include <UnityCore/UnityCore.h>37#include <UnityCore/Variant.h>
3838
39namespace unity {39namespace unity {
4040
4141
=== modified file 'plugins/unityshell/src/PanelView.h'
--- plugins/unityshell/src/PanelView.h 2011-06-22 14:39:34 +0000
+++ plugins/unityshell/src/PanelView.h 2011-07-15 10:26:29 +0000
@@ -28,7 +28,7 @@
2828
29#include <gdk/gdkx.h>29#include <gdk/gdkx.h>
3030
31#include <UnityCore/UnityCore.h>31#include <UnityCore/DBusIndicators.h>
3232
33#include "Introspectable.h"33#include "Introspectable.h"
34#include "PanelHomeButton.h"34#include "PanelHomeButton.h"
3535
=== modified file 'plugins/unityshell/src/PlacesHomeView.cpp'
--- plugins/unityshell/src/PlacesHomeView.cpp 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/PlacesHomeView.cpp 2011-07-15 10:26:29 +0000
@@ -42,7 +42,7 @@
42#include "PlacesSettings.h"42#include "PlacesSettings.h"
43#include "PlacesSimpleTile.h"43#include "PlacesSimpleTile.h"
44#include "PlacesStyle.h"44#include "PlacesStyle.h"
45#include <UnityCore/UnityCore.h>45#include <UnityCore/Variant.h>
4646
47#include <string>47#include <string>
48#include <vector>48#include <vector>
4949
=== modified file 'plugins/unityshell/src/PlacesSearchBar.cpp'
--- plugins/unityshell/src/PlacesSearchBar.cpp 2011-06-28 11:17:23 +0000
+++ plugins/unityshell/src/PlacesSearchBar.cpp 2011-07-15 10:26:29 +0000
@@ -40,7 +40,7 @@
40#include "UBusMessages.h"40#include "UBusMessages.h"
4141
42#include "PlacesSearchBar.h"42#include "PlacesSearchBar.h"
43#include <UnityCore/UnityCore.h>43#include <UnityCore/Variant.h>
4444
45#include "PlacesStyle.h"45#include "PlacesStyle.h"
4646
4747
=== modified file 'plugins/unityshell/src/PlacesSimpleTile.cpp'
--- plugins/unityshell/src/PlacesSimpleTile.cpp 2011-07-07 11:52:58 +0000
+++ plugins/unityshell/src/PlacesSimpleTile.cpp 2011-07-15 10:26:29 +0000
@@ -30,7 +30,7 @@
30#include <gtk/gtk.h>30#include <gtk/gtk.h>
31#include <gdk/gdk.h>31#include <gdk/gdk.h>
3232
33#include <UnityCore/UnityCore.h>33#include <UnityCore/Variant.h>
3434
35PlacesSimpleTile::PlacesSimpleTile (const char *icon_name,35PlacesSimpleTile::PlacesSimpleTile (const char *icon_name,
36 const char *label,36 const char *label,
3737
=== modified file 'plugins/unityshell/src/PlacesView.cpp'
--- plugins/unityshell/src/PlacesView.cpp 2011-06-28 12:19:37 +0000
+++ plugins/unityshell/src/PlacesView.cpp 2011-07-15 10:26:29 +0000
@@ -34,7 +34,7 @@
34#include "PlacesStyle.h"34#include "PlacesStyle.h"
35#include "PlacesSettings.h"35#include "PlacesSettings.h"
36#include "PlacesView.h"36#include "PlacesView.h"
37#include <UnityCore/UnityCore.h>37#include <UnityCore/Variant.h>
3838
39static void place_entry_activate_request (GVariant *payload, PlacesView *self);39static void place_entry_activate_request (GVariant *payload, PlacesView *self);
4040
4141
=== modified file 'plugins/unityshell/src/QuicklistMenuItem.cpp'
--- plugins/unityshell/src/QuicklistMenuItem.cpp 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/QuicklistMenuItem.cpp 2011-07-15 10:26:29 +0000
@@ -23,7 +23,7 @@
2323
24#include "Nux/Nux.h"24#include "Nux/Nux.h"
25#include "QuicklistMenuItem.h"25#include "QuicklistMenuItem.h"
26#include <UnityCore/UnityCore.h>26#include <UnityCore/Variant.h>
2727
28#include <X11/Xlib.h>28#include <X11/Xlib.h>
2929
3030
=== modified file 'plugins/unityshell/src/WindowButtons.cpp'
--- plugins/unityshell/src/WindowButtons.cpp 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/WindowButtons.cpp 2011-07-15 10:26:29 +0000
@@ -25,7 +25,7 @@
25#include "Nux/BaseWindow.h"25#include "Nux/BaseWindow.h"
26#include "Nux/WindowCompositor.h"26#include "Nux/WindowCompositor.h"
2727
28#include <UnityCore/UnityCore.h>28#include <UnityCore/Variant.h>
29#include "WindowButtons.h"29#include "WindowButtons.h"
3030
31#include <glib.h>31#include <glib.h>
@@ -58,7 +58,7 @@
58 nux::Geometry geo = GetGeometry ();58 nux::Geometry geo = GetGeometry ();
59 nux::BaseTexture *tex;59 nux::BaseTexture *tex;
60 nux::TexCoordXForm texxform;60 nux::TexCoordXForm texxform;
61 61
62 GfxContext.PushClippingRectangle (geo);62 GfxContext.PushClippingRectangle (geo);
6363
64 if (HasMouseFocus ())64 if (HasMouseFocus ())
@@ -123,23 +123,25 @@
123{123{
124 WindowButton *but;124 WindowButton *but;
125125
126 auto lambda_statechanged = [&](int x, int y, unsigned long button_flags, unsigned long key_flags) { redraw_signal.emit (); };
127
126 but = new WindowButton (PanelStyle::WINDOW_BUTTON_CLOSE);128 but = new WindowButton (PanelStyle::WINDOW_BUTTON_CLOSE);
127 AddView (but, 0, nux::eCenter, nux::eFix);129 AddView (but, 0, nux::eCenter, nux::eFix);
128 but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnCloseClicked));130 but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnCloseClicked));
129 but->OnMouseEnter.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseEnter));131 but->OnMouseEnter.connect (lambda_statechanged);
130 but->OnMouseLeave.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseLeave));132 but->OnMouseLeave.connect (lambda_statechanged);
131133
132 but = new WindowButton (PanelStyle::WINDOW_BUTTON_MINIMIZE);134 but = new WindowButton (PanelStyle::WINDOW_BUTTON_MINIMIZE);
133 AddView (but, 0, nux::eCenter, nux::eFix);135 AddView (but, 0, nux::eCenter, nux::eFix);
134 but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnMinimizeClicked));136 but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnMinimizeClicked));
135 but->OnMouseEnter.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseEnter));137 but->OnMouseEnter.connect (lambda_statechanged);
136 but->OnMouseLeave.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseLeave));138 but->OnMouseLeave.connect (lambda_statechanged);
137139
138 but = new WindowButton (PanelStyle::WINDOW_BUTTON_UNMAXIMIZE);140 but = new WindowButton (PanelStyle::WINDOW_BUTTON_UNMAXIMIZE);
139 AddView (but, 0, nux::eCenter, nux::eFix);141 AddView (but, 0, nux::eCenter, nux::eFix);
140 but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnRestoreClicked));142 but->sigClick.connect (sigc::mem_fun (this, &WindowButtons::OnRestoreClicked));
141 but->OnMouseEnter.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseEnter));143 but->OnMouseEnter.connect (lambda_statechanged);
142 but->OnMouseLeave.connect (sigc::mem_fun (this, &WindowButtons::RecvMouseLeave));144 but->OnMouseLeave.connect (lambda_statechanged);
143145
144 SetContentDistribution (nux::eStackLeft);146 SetContentDistribution (nux::eStackLeft);
145}147}
@@ -184,15 +186,3 @@
184{186{
185 unity::variant::BuilderWrapper(builder).add(GetGeometry());187 unity::variant::BuilderWrapper(builder).add(GetGeometry());
186}188}
187
188void WindowButtons::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
189{
190 redraw_signal.emit ();
191}
192
193void WindowButtons::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
194{
195 redraw_signal.emit ();
196}
197
198
199189
=== modified file 'po/unity.pot'
--- po/unity.pot 2011-07-13 13:54:57 +0000
+++ po/unity.pot 2011-07-15 10:26:29 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: PACKAGE VERSION\n"9"Project-Id-Version: PACKAGE VERSION\n"
10"Report-Msgid-Bugs-To: ayatana-dev@lists.launchpad.net\n"10"Report-Msgid-Bugs-To: ayatana-dev@lists.launchpad.net\n"
11"POT-Creation-Date: 2011-07-13 01:33-0400\n"11"POT-Creation-Date: 2011-07-09 23:12+0100\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"
1515
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2011-07-13 14:20:07 +0000
+++ tests/CMakeLists.txt 2011-07-15 10:26:29 +0000
@@ -20,6 +20,7 @@
20 "-DGETTEXT_PACKAGE=\"unity\""20 "-DGETTEXT_PACKAGE=\"unity\""
21 "-DINDICATORDIR=\"${CMAKE_BINARY_DIR}/tests\""21 "-DINDICATORDIR=\"${CMAKE_BINARY_DIR}/tests\""
22 "-DINDICATORICONDIR=\"${CMAKE_BINARY_DIR}/tests\""22 "-DINDICATORICONDIR=\"${CMAKE_BINARY_DIR}/tests\""
23 "-I${CMAKE_CURRENT_BINARY_DIR}"
23 )24 )
24add_definitions (${CFLAGS})25add_definitions (${CFLAGS})
2526
@@ -27,7 +28,7 @@
27link_libraries (${LIBS})28link_libraries (${LIBS})
2829
29set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})30set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})
30link_directories (${LIB_PATHS} ${CMAKE_BINARY_DIR}/UnityCore)31link_directories (${CMAKE_BINARY_DIR}/UnityCore ${LIB_PATHS})
3132
32include_directories (. .. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_DIR})33include_directories (. .. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_DIR})
3334
@@ -285,16 +286,27 @@
285#286#
286# GTest tests287# GTest tests
287#288#
289find_program(GLIB_GENMARSHAL glib-genmarshal)
290add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_glib_signals_utils_marshal.cpp
291 COMMAND ${GLIB_GENMARSHAL} ARGS test_glib_signals_utils_marshal.list --body --prefix=test_signals > ${CMAKE_CURRENT_BINARY_DIR}/test_glib_signals_utils_marshal.cpp
292 COMMAND ${GLIB_GENMARSHAL} ARGS test_glib_signals_utils_marshal.list --header --prefix=test_signals > ${CMAKE_CURRENT_BINARY_DIR}/test_glib_signals_utils_marshal.h
293 COMMAND sed ARGS -i "s/glib-object/test_glib_signals_utils_marshal/" ${CMAKE_CURRENT_BINARY_DIR}/test_glib_signals_utils_marshal.cpp
294 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
295 DEPENDS test_glib_signals_utils_marshal.list
296 COMMENT "Generating marshallers")
288297
289enable_testing()298enable_testing()
290find_package(GTest)299find_package(GTest)
291
292if (${GTEST_FOUND} STREQUAL TRUE)300if (${GTEST_FOUND} STREQUAL TRUE)
293
294 include_directories(${GTEST_INCLUDE_DIRS})301 include_directories(${GTEST_INCLUDE_DIRS})
295 add_executable(test-gtest302 add_executable(test-gtest
303 test_glib_signals.cpp
304 test_glib_signals_utils.cpp
305 test_glib_signals_utils.h
306 ${CMAKE_CURRENT_BINARY_DIR}/test_glib_signals_utils_marshal.cpp
307 test_indicator_entry.cpp
308 test_main.cpp
296 test_timer.cpp309 test_timer.cpp
297 test_indicator_entry.cpp
298 ${UNITY_SRC}/Timer.h310 ${UNITY_SRC}/Timer.h
299 ${UNITY_SRC}/Timer.cpp311 ${UNITY_SRC}/Timer.cpp
300 )312 )
301313
=== added file 'tests/test_glib_signals.cpp'
--- tests/test_glib_signals.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_glib_signals.cpp 2011-07-15 10:26:29 +0000
@@ -0,0 +1,366 @@
1#include <UnityCore/GLibSignal.h>
2#include <gtest/gtest.h>
3
4#include "test_glib_signals_utils.h"
5
6using namespace std;
7using namespace unity;
8using namespace unity::glib;
9
10namespace {
11
12class TestGLibSignals : public testing::Test
13{
14public:
15 TestGLibSignals()
16 : signal0_received_(false)
17 , signal1_received_(false)
18 , signal2_received_(false)
19 , signal3_received_(false)
20 , signal4_received_(false)
21 , signal5_received_(false)
22 , signal6_received_(false)
23 , arg1_("")
24 , arg2_(-1)
25 , arg3_(0.0f)
26 , arg4_(0.00)
27 , arg5_(false)
28 , arg6_(0)
29 {
30 test_signals_ = static_cast<TestSignals*>(g_object_new(TEST_TYPE_SIGNALS, NULL));
31 }
32
33 virtual ~TestGLibSignals()
34 {
35 if (G_IS_OBJECT(test_signals_))
36 g_object_unref(test_signals_);
37 }
38
39 void Signal0Callback(TestSignals* signals)
40 {
41 signal0_received_ = true;
42 }
43
44 void Signal1Callback(TestSignals* signals, const char *str)
45 {
46 arg1_ = str;
47 signal1_received_ = true;
48 }
49
50 void Signal2Callback(TestSignals* signals, const char* str, int i)
51 {
52 arg1_ = str;
53 arg2_ = i;
54 signal2_received_ = true;
55 }
56
57 void Signal3Callback(TestSignals* signals, const char* str, int i, float f)
58 {
59 arg1_ = str;
60 arg2_ = i;
61 arg3_ = f;
62 signal3_received_ = true;
63 }
64
65 void Signal4Callback(TestSignals* signals, const char* str, int i, float f, double d) // heh
66 {
67 arg1_ = str;
68 arg2_ = i;
69 arg3_ = f;
70 arg4_ = d;
71 signal4_received_ = true;
72 }
73
74 void Signal5Callback(TestSignals* signals, const char* str, int i, float f,
75 double d, gboolean b)
76 {
77 arg1_ = str;
78 arg2_ = i;
79 arg3_ = f;
80 arg4_ = d;
81 arg5_ = b ? true : false;
82 signal5_received_ = true;
83 }
84
85 gboolean Signal6Callback(TestSignals* signals, const char* str, int i, float f,
86 double d, gboolean b, char c)
87 {
88 arg1_ = str;
89 arg2_ = i;
90 arg3_ = f;
91 arg4_ = d;
92 arg5_ = b ? true : false;
93 arg6_ = c;
94 signal6_received_ = true;
95 return TRUE;
96 }
97
98protected:
99 TestSignals* test_signals_;
100
101 bool signal0_received_;
102 bool signal1_received_;
103 bool signal2_received_;
104 bool signal3_received_;
105 bool signal4_received_;
106 bool signal5_received_;
107 bool signal6_received_;
108
109 string arg1_;
110 int arg2_;
111 float arg3_;
112 double arg4_;
113 bool arg5_;
114 char arg6_;
115};
116
117
118TEST_F(TestGLibSignals, TestConstructions)
119{
120 SignalBase base;
121
122 Signal0<void, TestSignals*> signal0;
123 Signal1<void, TestSignals*, string> signal1;
124 Signal2<void, TestSignals*, string, int> signal2;
125 Signal3<void, TestSignals*, string, int, float> signal3;
126 Signal4<void, TestSignals*, string, int, float, double> signal4;
127 Signal5<void, TestSignals*, string, int, float, double, gboolean> signal5;
128 Signal6<gboolean, TestSignals*, string, int, float, double, gboolean, char> signal6;
129
130 Signal<void, TestSignals*> signal00;
131 Signal<void, TestSignals*, string> signal01;
132 Signal<void, TestSignals*, string, int> signal02;
133 Signal<void, TestSignals*, string, int, float> signal03;
134 Signal<void, TestSignals*, string, int, float, double> signal04;
135 Signal<void, TestSignals*, string, int, float, double, gboolean> signal05;
136 Signal<gboolean, TestSignals*, string, int, float, double, gboolean, char> signal06;
137}
138
139TEST_F(TestGLibSignals, TestSignal0)
140{
141 Signal<void, TestSignals*> signal;
142 signal.Connect(test_signals_, "signal0",
143 sigc::mem_fun(this, &TestGLibSignals::Signal0Callback));
144
145 g_signal_emit_by_name(test_signals_, "signal0");
146
147 EXPECT_TRUE(signal0_received_);
148 EXPECT_EQ(arg1_, "");
149}
150
151TEST_F(TestGLibSignals, TestSignal1)
152{
153 Signal<void, TestSignals*, const char*> signal;
154 signal.Connect(test_signals_, "signal1",
155 sigc::mem_fun(this, &TestGLibSignals::Signal1Callback));
156
157 g_signal_emit_by_name(test_signals_, "signal1", "test");
158
159 EXPECT_TRUE(signal1_received_);
160 EXPECT_EQ(arg1_, "test");
161 EXPECT_EQ(arg2_, -1);
162}
163
164TEST_F(TestGLibSignals, TestSignal2)
165{
166 Signal<void, TestSignals*, const char*, int> signal;
167 signal.Connect(test_signals_, "signal2",
168 sigc::mem_fun(this, &TestGLibSignals::Signal2Callback));
169
170 g_signal_emit_by_name(test_signals_, "signal2", "test", 100);
171
172 EXPECT_TRUE(signal2_received_);
173 EXPECT_EQ(arg1_, "test");
174 EXPECT_EQ(arg2_, 100);
175 EXPECT_EQ(arg3_, 0.0f);
176}
177
178TEST_F(TestGLibSignals, TestSignal3)
179{
180 Signal<void, TestSignals*, const char*, int, float> signal;
181 signal.Connect(test_signals_, "signal3",
182 sigc::mem_fun(this, &TestGLibSignals::Signal3Callback));
183
184 g_signal_emit_by_name(test_signals_, "signal3", "test", 100, 200.0f);
185
186 EXPECT_TRUE(signal3_received_);
187 EXPECT_EQ(arg1_, "test");
188 EXPECT_EQ(arg2_, 100);
189 EXPECT_EQ(arg3_, 200.0f);
190 EXPECT_EQ(arg4_, 0.00);
191}
192
193
194TEST_F(TestGLibSignals, TestSignal4)
195{
196 Signal<void, TestSignals*, const char*, int, float, double> signal;
197 signal.Connect(test_signals_, "signal4",
198 sigc::mem_fun(this, &TestGLibSignals::Signal4Callback));
199
200 g_signal_emit_by_name(test_signals_, "signal4", "test", 100, 200.0f, 300.00);
201
202 EXPECT_TRUE(signal4_received_);
203 EXPECT_EQ(arg1_, "test");
204 EXPECT_EQ(arg2_, 100);
205 EXPECT_EQ(arg3_, 200.0f);
206 EXPECT_EQ(arg4_, 300.00);
207 EXPECT_EQ(arg5_, false);
208}
209
210TEST_F(TestGLibSignals, TestSignal5)
211{
212 Signal<void, TestSignals*, const char*, int, float, double, gboolean> signal;
213 signal.Connect(test_signals_, "signal5",
214 sigc::mem_fun(this, &TestGLibSignals::Signal5Callback));
215
216 g_signal_emit_by_name(test_signals_, "signal5", "test", 100, 200.0f, 300.00,
217 TRUE);
218
219 EXPECT_TRUE(signal5_received_);
220 EXPECT_EQ(arg1_, "test");
221 EXPECT_EQ(arg2_, 100);
222 EXPECT_EQ(arg3_, 200.0f);
223 EXPECT_EQ(arg4_, 300.00);
224 EXPECT_EQ(arg5_, true);
225 EXPECT_EQ(arg6_, 0);
226}
227
228// This tests accumulation as well
229TEST_F(TestGLibSignals, TestSignal6)
230{
231 Signal<gboolean, TestSignals*, const char*, int, float, double, gboolean, char> signal;
232 signal.Connect(test_signals_, "signal6",
233 sigc::mem_fun(this, &TestGLibSignals::Signal6Callback));
234
235 gboolean ret = FALSE;
236 g_signal_emit_by_name(test_signals_, "signal6", "test", 100, 200.0f, 300.00,
237 TRUE, 'x', &ret);
238
239 EXPECT_TRUE(signal6_received_);
240 EXPECT_EQ(arg1_, "test");
241 EXPECT_EQ(arg2_, 100);
242 EXPECT_EQ(arg3_, 200.0f);
243 EXPECT_EQ(arg4_, 300.00);
244 EXPECT_EQ(arg5_, true);
245 EXPECT_EQ(arg6_, 'x');
246 EXPECT_EQ(ret, TRUE);
247}
248
249TEST_F(TestGLibSignals, TestDisconnection)
250{
251 Signal<void, TestSignals*> signal;
252 signal.Connect(test_signals_, "signal0",
253 sigc::mem_fun(this, &TestGLibSignals::Signal0Callback));
254 signal.Disconnect();
255
256 g_signal_emit_by_name(test_signals_, "signal0");
257
258 EXPECT_FALSE(signal0_received_);
259}
260
261TEST_F(TestGLibSignals, TestAutoDisconnection)
262{
263 {
264 Signal<void, TestSignals*> signal;
265 signal.Connect(test_signals_, "signal0",
266 sigc::mem_fun(this, &TestGLibSignals::Signal0Callback));
267 }
268
269 g_signal_emit_by_name(test_signals_, "signal0");
270
271 EXPECT_FALSE(signal0_received_);
272}
273
274TEST_F(TestGLibSignals, TestCleanDestruction)
275{
276 Signal<void, TestSignals*> signal;
277 signal.Connect(test_signals_, "signal0",
278 sigc::mem_fun(this, &TestGLibSignals::Signal0Callback));
279 g_object_unref (test_signals_);
280}
281
282TEST_F(TestGLibSignals, TestManagerConstruction)
283{
284 SignalManager manager;
285}
286
287TEST_F(TestGLibSignals, TestManagerAddition)
288{
289 SignalManager manager;
290
291 manager.Add(new Signal<void, TestSignals*>(test_signals_,
292 "signal0",
293 sigc::mem_fun(this, &TestGLibSignals::Signal0Callback)));
294 manager.Add(new Signal<void, TestSignals*, const char *>(test_signals_,
295 "signal1",
296 sigc::mem_fun(this, &TestGLibSignals::Signal1Callback)));
297 manager.Add(new Signal<void, TestSignals*, const char *, int>(test_signals_,
298 "signal2",
299 sigc::mem_fun(this, &TestGLibSignals::Signal2Callback)));
300 manager.Add(new Signal<void, TestSignals*, const char *, int, float>(test_signals_,
301 "signal3",
302 sigc::mem_fun(this, &TestGLibSignals::Signal3Callback)));
303 manager.Add(new Signal<void, TestSignals*, const char *, int, float, double>(test_signals_,
304 "signal4",
305 sigc::mem_fun(this, &TestGLibSignals::Signal4Callback)));
306 manager.Add(new Signal<void, TestSignals*, const char *, int, float, double, gboolean>(test_signals_,
307 "signal5",
308 sigc::mem_fun(this, &TestGLibSignals::Signal5Callback)));
309 manager.Add(new Signal<gboolean, TestSignals*, const char *, int, float, double, gboolean, char>(test_signals_,
310 "signal6",
311 sigc::mem_fun(this, &TestGLibSignals::Signal6Callback)));
312}
313
314TEST_F(TestGLibSignals, TestManagerConnection)
315{
316 SignalManager manager;
317
318 manager.Add(new Signal<void, TestSignals*>(test_signals_,
319 "signal0",
320 sigc::mem_fun(this, &TestGLibSignals::Signal0Callback)));
321
322 g_signal_emit_by_name(test_signals_, "signal0");
323 EXPECT_TRUE(signal0_received_);
324
325 manager.Add(new Signal<void, TestSignals*, const char *>(test_signals_,
326 "signal1",
327 sigc::mem_fun(this, &TestGLibSignals::Signal1Callback)));
328 g_signal_emit_by_name(test_signals_, "signal1", "test");
329 EXPECT_TRUE(signal1_received_);
330
331 gboolean ret = FALSE;
332 manager.Add(new Signal<gboolean, TestSignals*, const char *, int, float, double, gboolean, char>(test_signals_,
333 "signal6",
334 sigc::mem_fun(this, &TestGLibSignals::Signal6Callback)));
335 g_signal_emit_by_name(test_signals_, "signal6", "test", 100, 1.0f, 100.00, FALSE, 'x', &ret);
336 EXPECT_TRUE(signal6_received_);
337 EXPECT_TRUE(ret);
338}
339
340TEST_F(TestGLibSignals, TestManagerAutoDisconnect)
341{
342 {
343 SignalManager manager;
344 manager.Add(new Signal<void, TestSignals*>(test_signals_,
345 "signal0",
346 sigc::mem_fun(this, &TestGLibSignals::Signal0Callback)));
347 }
348
349 g_signal_emit_by_name(test_signals_, "signal0");
350 EXPECT_FALSE(signal0_received_);
351}
352
353TEST_F(TestGLibSignals, TestManagerDisconnection)
354{
355 SignalManager manager;
356
357 manager.Add(new Signal<void, TestSignals*>(test_signals_,
358 "signal0",
359 sigc::mem_fun(this, &TestGLibSignals::Signal0Callback)));
360 manager.Disconnect(test_signals_, "signal0");
361
362 g_signal_emit_by_name(test_signals_, "signal0");
363 EXPECT_FALSE(signal0_received_);
364}
365
366}
0367
=== added file 'tests/test_glib_signals_utils.cpp'
--- tests/test_glib_signals_utils.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_glib_signals_utils.cpp 2011-07-15 10:26:29 +0000
@@ -0,0 +1,102 @@
1#include "test_glib_signals_utils.h"
2#include "test_glib_signals_utils_marshal.h"
3
4enum
5{
6 SIGNAL_0,
7 SIGNAL_1,
8 SIGNAL_2,
9 SIGNAL_3,
10 SIGNAL_4,
11 SIGNAL_5,
12 SIGNAL_6,
13
14 LAST_SIGNAL
15};
16
17
18static guint32 _service_signals[LAST_SIGNAL] = { 0 };
19
20G_DEFINE_TYPE (TestSignals, test_signals, G_TYPE_OBJECT);
21
22static void
23test_signals_class_init (TestSignalsClass *klass)
24{
25 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
26
27 /* Signals */
28 _service_signals[SIGNAL_0] =
29 g_signal_new ("signal0",
30 G_OBJECT_CLASS_TYPE (obj_class),
31 G_SIGNAL_RUN_LAST,
32 0,
33 NULL, NULL,
34 g_cclosure_marshal_VOID__VOID,
35 G_TYPE_NONE, 0);
36
37 _service_signals[SIGNAL_1] =
38 g_signal_new ("signal1",
39 G_OBJECT_CLASS_TYPE (obj_class),
40 G_SIGNAL_RUN_LAST,
41 0,
42 NULL, NULL,
43 g_cclosure_marshal_VOID__STRING,
44 G_TYPE_NONE, 1, G_TYPE_STRING);
45
46 _service_signals[SIGNAL_2] =
47 g_signal_new ("signal2",
48 G_OBJECT_CLASS_TYPE (obj_class),
49 G_SIGNAL_RUN_LAST,
50 0,
51 NULL, NULL,
52 test_signals_VOID__STRING_INT,
53 G_TYPE_NONE, 2,
54 G_TYPE_STRING, G_TYPE_INT);
55
56 _service_signals[SIGNAL_3] =
57 g_signal_new ("signal3",
58 G_OBJECT_CLASS_TYPE (obj_class),
59 G_SIGNAL_RUN_LAST,
60 0,
61 NULL, NULL,
62 test_signals_VOID__STRING_INT_FLOAT,
63 G_TYPE_NONE, 3,
64 G_TYPE_STRING, G_TYPE_INT, G_TYPE_FLOAT);
65
66 _service_signals[SIGNAL_4] =
67 g_signal_new ("signal4",
68 G_OBJECT_CLASS_TYPE (obj_class),
69 G_SIGNAL_RUN_LAST,
70 0,
71 NULL, NULL,
72 test_signals_VOID__STRING_INT_FLOAT_DOUBLE,
73 G_TYPE_NONE, 4,
74 G_TYPE_STRING, G_TYPE_INT, G_TYPE_FLOAT, G_TYPE_DOUBLE);
75
76 _service_signals[SIGNAL_5] =
77 g_signal_new ("signal5",
78 G_OBJECT_CLASS_TYPE (obj_class),
79 G_SIGNAL_RUN_LAST,
80 0,
81 NULL, NULL,
82 test_signals_VOID__STRING_INT_FLOAT_DOUBLE_BOOLEAN,
83 G_TYPE_NONE, 5,
84 G_TYPE_STRING, G_TYPE_INT, G_TYPE_FLOAT,
85 G_TYPE_DOUBLE, G_TYPE_BOOLEAN);
86
87 _service_signals[SIGNAL_6] =
88 g_signal_new ("signal6",
89 G_OBJECT_CLASS_TYPE (obj_class),
90 G_SIGNAL_RUN_LAST,
91 0,
92 NULL, NULL,
93 test_signals_BOOLEAN__STRING_INT_FLOAT_DOUBLE_BOOLEAN_CHAR,
94 G_TYPE_BOOLEAN, 6,
95 G_TYPE_STRING, G_TYPE_INT, G_TYPE_FLOAT,
96 G_TYPE_DOUBLE, G_TYPE_BOOLEAN, G_TYPE_CHAR);
97}
98
99static void
100test_signals_init (TestSignals *self)
101{
102}
0103
=== added file 'tests/test_glib_signals_utils.h'
--- tests/test_glib_signals_utils.h 1970-01-01 00:00:00 +0000
+++ tests/test_glib_signals_utils.h 2011-07-15 10:26:29 +0000
@@ -0,0 +1,46 @@
1/*
2 * GObject Class to allow for extensive testing of our Signal wrapper
3 */
4
5#ifndef _TEST_SIGNALS_H_
6#define _TEST_SIGNALS_H_
7
8#include <glib-object.h>
9
10G_BEGIN_DECLS
11
12#define TEST_TYPE_SIGNALS (test_signals_get_type ())
13
14#define TestSignals(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
15 TEST_TYPE_SIGNALS, TestSignals))
16
17#define TestSignals_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
18 TEST_TYPE_SIGNALS, TestSignalsClass))
19
20#define TEST_IS_SIGNALS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
21 TEST_TYPE_SIGNALS))
22
23#define TEST_IS_SIGNALS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
24 TEST_TYPE_SIGNALS))
25
26#define TestSignals_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
27 TEST_TYPE_SIGNALS, TestSignalsClass))
28
29typedef struct _TEST_SIGNALS TestSignals;
30typedef struct _TEST_SIGNALSClass TestSignalsClass;
31
32struct _TEST_SIGNALS
33{
34 GObject parent;
35};
36
37struct _TEST_SIGNALSClass
38{
39 GObjectClass parent_class;
40};
41
42GType test_signals_get_type(void) G_GNUC_CONST;
43
44G_END_DECLS
45
46#endif /* _TEST_SIGNALS_H_ */
047
=== added file 'tests/test_glib_signals_utils_marshal.list'
--- tests/test_glib_signals_utils_marshal.list 1970-01-01 00:00:00 +0000
+++ tests/test_glib_signals_utils_marshal.list 2011-07-15 10:26:29 +0000
@@ -0,0 +1,6 @@
1VOID:STRING,INT
2VOID:STRING,INT,FLOAT
3VOID:STRING,INT,FLOAT,DOUBLE
4VOID:STRING,INT,FLOAT,DOUBLE,BOOL
5BOOL:STRING,INT,FLOAT,DOUBLE,BOOL,CHAR
6BOOL:STRING,INT,FLOAT,DOUBLE,BOOL,CHAR,UINT
07
=== modified file 'tests/test_indicator_entry.cpp'
--- tests/test_indicator_entry.cpp 2011-06-21 12:10:09 +0000
+++ tests/test_indicator_entry.cpp 2011-07-15 10:26:29 +0000
@@ -1,4 +1,4 @@
1#include <UnityCore/UnityCore.h>1#include <UnityCore/IndicatorEntry.h>
22
3#include <gtest/gtest.h>3#include <gtest/gtest.h>
44
55
=== added file 'tests/test_main.cpp'
--- tests/test_main.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_main.cpp 2011-07-15 10:26:29 +0000
@@ -0,0 +1,10 @@
1#include <gtest/gtest.h>
2#include <glib-object.h>
3
4int main(int argc, char **argv)
5{
6 ::testing::InitGoogleTest(&argc, argv);
7 g_type_init();
8
9 return RUN_ALL_TESTS();
10}