1
1
// AppletControl.cc --- Applet info Control
3
// Copyright (C) 2006, 2007, 2008, 2009 Rob Caelers & Raymond Penners
3
// Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012 Rob Caelers & Raymond Penners
4
4
// All rights reserved.
6
6
// This program is free software: you can redistribute it and/or modify
44
39
#include "W32AppletWindow.hh"
47
// #ifdef PLATFORM_OS_OSX
48
// #include "OSXAppletWindow.hh"
43
#include "GenericDBusApplet.hh"
46
#ifdef PLATFORM_OS_OSX
47
#include "OSXAppletWindow.hh"
52
#include "MainWindow.hh"
53
51
#include "TimerBoxControl.hh"
52
#include "Menus.hh" // REFACTOR
55
54
#include "CoreFactory.hh"
56
55
#include "IConfigurator.hh"
91
91
AppletControl::init()
94
applets[APPLET_KDE] = new KdeAppletWindow(this);
97
#ifdef HAVE_GNOMEAPPLET
98
applets[APPLET_GNOME] = new GnomeAppletWindow(this);
93
#if defined(HAVE_PANELAPPLET2) || defined(HAVE_PANELAPPLET4)
94
applets[APPLET_GNOME] = new GnomeAppletWindow();
98
applets[APPLET_GENERIC_DBUS] = new GenericDBusApplet();
101
101
#ifdef PLATFORM_OS_UNIX
102
applets[APPLET_TRAY] = new X11SystrayAppletWindow(this);
102
applets[APPLET_TRAY] = new X11SystrayAppletWindow();
105
105
#ifdef PLATFORM_OS_WIN32
106
106
applets[APPLET_W32] = new W32AppletWindow();
109
// #ifdef PLATFORM_OS_OSX
110
// applets[APPLET_OSX] = new OSXAppletWindow();
109
#ifdef PLATFORM_OS_OSX
110
applets[APPLET_OSX] = new OSXAppletWindow();
113
for (int i = 0; i < APPLET_SIZE; i++)
115
if (applets[i] != NULL)
117
applets[i]->init_applet();
118
applets[i]->signal_state_changed().connect(sigc::bind<0>(sigc::mem_fun(*this, &AppletControl::on_applet_state_changed), (AppletType)i));
119
applets[i]->signal_request_activate().connect(sigc::bind<0>(sigc::mem_fun(*this, &AppletControl::on_applet_request_activate), (AppletType)i));
113
123
// Read configuration and start monitoring it.
114
124
IConfigurator *config = CoreFactory::get_configurator();
115
125
config->add_listener(TimerBoxControl::CFG_KEY_TIMERBOX + "applet", this);
123
133
AppletControl::show()
125
135
TRACE_ENTER("AppletControl::show");
127
137
bool specific = false;
140
rc = activate_applet(APPLET_GENERIC_DBUS);
141
TRACE_MSG("Generic" << rc);
130
143
rc = activate_applet(APPLET_GNOME);
131
144
TRACE_MSG("Gnome " << rc);
132
145
if (rc != AppletWindow::APPLET_STATE_DISABLED)
139
rc = activate_applet(APPLET_KDE);
140
TRACE_MSG("kde " << rc);
141
if (rc != AppletWindow::APPLET_STATE_DISABLED)
146
152
rc = activate_applet(APPLET_W32);
147
153
TRACE_MSG("Win32 " << rc);
148
154
if (rc != AppletWindow::APPLET_STATE_DISABLED)
153
// rc = activate_applet(APPLET_OSX);
154
// TRACE_MSG("OSX " << rc);
155
// if (rc != AppletWindow::APPLET_STATE_DISABLED)
159
rc = activate_applet(APPLET_OSX);
160
TRACE_MSG("OSX " << rc);
161
if (rc != AppletWindow::APPLET_STATE_DISABLED)
160
166
#ifdef PLATFORM_OS_UNIX
223
//! Hide a specific applet.
225
AppletControl::hide(AppletType type)
227
deactivate_applet(type);
231
229
//! The specified applet is not active.
233
AppletControl::set_applet_state(AppletType type, AppletWindow::AppletState state)
231
AppletControl::on_applet_state_changed(AppletType type, AppletWindow::AppletState state)
235
233
TRACE_ENTER_MSG("AppletControl::set_applet_state", type << " " << state);
238
case AppletWindow::APPLET_STATE_DISABLED:
239
visible[type] = false;
242
case AppletWindow::APPLET_STATE_VISIBLE:
243
visible[type] = true;
246
case AppletWindow::APPLET_STATE_PENDING:
247
visible[type] = false;
234
applet_state[type] = state;
251
236
#ifdef PLATFORM_OS_UNIX
253
(type == APPLET_KDE || type == APPLET_GNOME))
237
if (is_visible(type) && (type == APPLET_GNOME || type == APPLET_GENERIC_DBUS))
239
TRACE_MSG("Deactivate tray");
255
240
deactivate_applet(APPLET_TRAY);
259
244
if (enabled && !is_visible())
246
TRACE_MSG("none visible, show in 5s");
261
247
delayed_show = 5;
251
if (state == AppletWindow::APPLET_STATE_VISIBLE)
253
IGUI *gui = GUI::get_instance();
254
Menus *menus = gui->get_menus();
264
AppletControl::on_applet_request_activate(AppletType type)
269
269
//! Is at least a single applet visible.
271
271
AppletControl::is_visible(AppletType type)
273
return visible[type];
273
return applet_state[type] == AppletWindow::APPLET_STATE_VISIBLE;
313
for (int i = 0; i < APPLET_SIZE; i++)
313
for (int i = APPLET_FIRST; i < APPLET_SIZE; i++)
315
if (applets[i] != NULL && visible[i])
315
if (applets[i] != NULL && is_visible((AppletType)i))
317
317
applets[i]->update_applet();
324
324
//! Sets the tooltip of all visible applets.
326
AppletControl::set_timers_tooltip(std::string& tip)
326
AppletControl::set_tooltip(std::string& tip)
328
for (int i = 0; i < APPLET_SIZE; i++)
328
for (int i = APPLET_FIRST; i < APPLET_SIZE; i++)
330
if (applets[i] != NULL && visible[i])
330
if (applets[i] != NULL && is_visible((AppletType)i))
332
applets[i]->set_timers_tooltip(tip);
332
applets[i]->set_applet_tooltip(tip);
376
376
TRACE_ENTER("AppletControl::check_visible");
379
for (int i = 0; i < APPLET_SIZE; i++)
379
for (int i = APPLET_FIRST; i < APPLET_SIZE; i++)
381
if (is_visible((AppletType)i))
383
TRACE_MSG(i << " is visible");
387
// #ifdef PLATFORM_OS_OSX
391
GUI *gui = GUI::get_instance();
392
MainWindow *main = gui->get_main_window();
388
#ifdef PLATFORM_OS_OSX
392
bool new_visible = count > 0;
393
if (new_visible != visible)
395
main->set_applet_active( count > 0 );
395
visible = new_visible;
396
visibility_changed_signal.emit();
401
402
AppletWindow::AppletState
402
403
AppletControl::activate_applet(AppletType type)
404
AppletState r = AppletWindow::APPLET_STATE_DISABLED;
405
AppletState state = AppletWindow::APPLET_STATE_DISABLED;
406
407
if (applets[type] != NULL)
408
r = applets[type]->activate_applet();
409
if (r == AppletWindow::APPLET_STATE_VISIBLE)
411
visible[type] = true;
409
state = applets[type]->activate_applet();
410
applet_state[type] = state;
421
419
if (applets[type] != NULL)
423
421
applets[type]->deactivate_applet();
424
visible[type] = false;
422
applet_state[type] = AppletWindow::APPLET_STATE_DISABLED;
427
AppletControl::signal_visibility_changed()
429
return visibility_changed_signal;