~ubuntu-branches/ubuntu/raring/workrave/raring

« back to all changes in this revision

Viewing changes to frontend/gtkmm/src/AppletControl.cc

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Jordi Mallach
  • Date: 2012-05-28 11:29:40 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20120528112940-bbbsjkk30fom9s8x
Tags: 1.9.909+abc941eb70-1
[ Francois Marier ]
* New upstream snapshot
  - Drop leak-fix patch (applied upstream)
  - Document how the tarball is built in README.source
* Build GNOME applets and use gsettings
* Massive update of Build-Depends as per configure.ac

* Update README.source with snapshot instructions
* Switch to machine-readable copyright file
* Update alioth git repo links
* Bump debhelper version to 9
* Bump Standards-Version to 3.9.3

[ Jordi Mallach ]
* Avoid references to GNU/Linux in manpage.
* Drop build dependency on libgnet-dev, it's obsolete and unneeded.
* Add myself to Uploaders.
* Rewrite d/rules into dh style.
  - Move all install tweaks to .install files.
  - Install manpages using dh_installman.
* As a side effect, the package installs arch-dependant data in the
  arch triplet directory; add the required Pre-Depends for m-a-support.
* Bring back GNOME Panel applet (for GNOME 3 fallback mode) and ship the
  new GNOME Shell extension (closes: #642514, #666100).
* Add private_dirs.patch: move libworkrave-private and GObject
  Introspection files to a private dir, so they are really out of the
  way, but disable it for now as it breaks the Shell extension.
* Move typelib out of the triplet dir as gobject-introspection is not
  M-A ready yet.
* Enable dh_autoreconf for the above patches.
* Add lintian overrides.
* Add necessary Breaks/Replaces as the xpm icon has moved to workrave-data.
* Prefix all debhelper files with package name.
* Suggest gnome-shell and gnome-panel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// AppletControl.cc --- Applet info Control
2
2
//
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.
5
5
//
6
6
// This program is free software: you can redistribute it and/or modify
23
23
#include "config.h"
24
24
#endif
25
25
 
26
 
#include "nls.h"
27
26
#include "debug.hh"
28
27
 
29
28
#include "AppletControl.hh"
30
29
 
31
 
#ifdef HAVE_KDE
32
 
#include "KdeAppletWindow.hh"
33
 
#endif
34
 
 
35
 
#ifdef HAVE_GNOMEAPPLET
 
30
#if defined(HAVE_PANELAPPLET2) || defined(HAVE_PANELAPPLET4)
36
31
#include "GnomeAppletWindow.hh"
37
32
#endif
38
33
 
44
39
#include "W32AppletWindow.hh"
45
40
#endif
46
41
 
47
 
// #ifdef PLATFORM_OS_OSX
48
 
// #include "OSXAppletWindow.hh"
49
 
// #endif
 
42
#ifdef HAVE_DBUS_GIO
 
43
#include "GenericDBusApplet.hh"
 
44
#endif
 
45
 
 
46
#ifdef PLATFORM_OS_OSX
 
47
#include "OSXAppletWindow.hh"
 
48
#endif
50
49
 
51
50
#include "GUI.hh"
52
 
#include "MainWindow.hh"
53
51
#include "TimerBoxControl.hh"
 
52
#include "Menus.hh" // REFACTOR
54
53
 
55
54
#include "CoreFactory.hh"
56
55
#include "IConfigurator.hh"
60
59
 
61
60
//! Constructor.
62
61
AppletControl::AppletControl()
63
 
  : enabled(false),
 
62
  : visible(false),
 
63
    enabled(false),
64
64
    delayed_show(-1)
65
65
{
66
66
  for (int i = 0; i < APPLET_SIZE; i++)
67
67
    {
68
68
      applets[i] = NULL;
69
 
      visible[i] = false;
 
69
      applet_state[i] = AppletWindow::APPLET_STATE_DISABLED;
70
70
    }
71
71
}
72
72
 
90
90
void
91
91
AppletControl::init()
92
92
{
93
 
#ifdef HAVE_KDE
94
 
  applets[APPLET_KDE] = new KdeAppletWindow(this);
95
 
#endif
96
 
 
97
 
#ifdef HAVE_GNOMEAPPLET
98
 
  applets[APPLET_GNOME] = new GnomeAppletWindow(this);
99
 
#endif
100
 
 
 
93
#if defined(HAVE_PANELAPPLET2) || defined(HAVE_PANELAPPLET4)
 
94
  applets[APPLET_GNOME] = new GnomeAppletWindow();
 
95
#endif
 
96
 
 
97
#ifdef HAVE_DBUS_GIO
 
98
  applets[APPLET_GENERIC_DBUS] = new GenericDBusApplet();
 
99
#endif
 
100
  
101
101
#ifdef PLATFORM_OS_UNIX
102
 
  applets[APPLET_TRAY] = new X11SystrayAppletWindow(this);
 
102
  applets[APPLET_TRAY] = new X11SystrayAppletWindow();
103
103
#endif
104
104
 
105
105
#ifdef PLATFORM_OS_WIN32
106
106
  applets[APPLET_W32] = new W32AppletWindow();
107
107
#endif
108
108
 
109
 
// #ifdef PLATFORM_OS_OSX
110
 
//   applets[APPLET_OSX] = new OSXAppletWindow();
111
 
// #endif
112
 
 
 
109
#ifdef PLATFORM_OS_OSX
 
110
  applets[APPLET_OSX] = new OSXAppletWindow();
 
111
#endif
 
112
  
 
113
  for (int i = 0; i < APPLET_SIZE; i++)
 
114
    {
 
115
      if (applets[i] != NULL)
 
116
        {
 
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));
 
120
        }
 
121
    }
 
122
  
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()
124
134
{
125
135
  TRACE_ENTER("AppletControl::show");
126
 
  
 
136
 
127
137
  bool specific = false;
128
138
  AppletState rc;
129
139
 
 
140
  rc = activate_applet(APPLET_GENERIC_DBUS);
 
141
  TRACE_MSG("Generic" << rc);
 
142
 
130
143
  rc = activate_applet(APPLET_GNOME);
131
144
  TRACE_MSG("Gnome " << rc);
132
145
  if (rc != AppletWindow::APPLET_STATE_DISABLED)
136
149
      specific = true;
137
150
    }
138
151
 
139
 
  rc = activate_applet(APPLET_KDE);
140
 
  TRACE_MSG("kde " << rc);
141
 
  if (rc != AppletWindow::APPLET_STATE_DISABLED)
142
 
    {
143
 
      specific = true;
144
 
    }
145
 
 
146
152
  rc = activate_applet(APPLET_W32);
147
153
  TRACE_MSG("Win32 " << rc);
148
154
  if (rc != AppletWindow::APPLET_STATE_DISABLED)
150
156
      specific = true;
151
157
    }
152
158
 
153
 
//   rc = activate_applet(APPLET_OSX);
154
 
//   TRACE_MSG("OSX " << rc);
155
 
//   if (rc != AppletWindow::APPLET_STATE_DISABLED)
156
 
//     {
157
 
//       specific = true;
158
 
//     }
 
159
  rc = activate_applet(APPLET_OSX);
 
160
  TRACE_MSG("OSX " << rc);
 
161
  if (rc != AppletWindow::APPLET_STATE_DISABLED)
 
162
    {
 
163
      specific = true;
 
164
    }
159
165
 
160
166
#ifdef PLATFORM_OS_UNIX
161
167
  if (specific)
170
176
    }
171
177
#endif
172
178
  check_visible();
173
 
  
 
179
 
174
180
  TRACE_EXIT();
175
181
}
176
182
 
192
198
#ifdef PLATFORM_OS_UNIX
193
199
  if (applets[APPLET_TRAY] != NULL)
194
200
    {
195
 
      if ((type == APPLET_KDE || type == APPLET_GNOME)
196
 
          && specific)
197
 
 
 
201
      if (type == APPLET_GNOME && specific)
198
202
        {
199
203
          deactivate_applet(APPLET_TRAY);
200
204
        }
203
207
          activate_applet(APPLET_TRAY);
204
208
        }
205
209
    }
 
210
#else
 
211
  (void) specific;
206
212
#endif
207
213
 
208
214
  check_visible();
220
226
}
221
227
 
222
228
 
223
 
//! Hide a specific applet.
224
 
void
225
 
AppletControl::hide(AppletType type)
226
 
{
227
 
  deactivate_applet(type);
228
 
}
229
 
 
230
 
 
231
229
//! The specified applet is not active.
232
230
void
233
 
AppletControl::set_applet_state(AppletType type, AppletWindow::AppletState state)
 
231
AppletControl::on_applet_state_changed(AppletType type, AppletWindow::AppletState state)
234
232
{
235
233
  TRACE_ENTER_MSG("AppletControl::set_applet_state", type << " " << state);
236
 
  switch (state)
237
 
    {
238
 
    case AppletWindow::APPLET_STATE_DISABLED:
239
 
      visible[type] = false;
240
 
      break;
241
 
 
242
 
    case AppletWindow::APPLET_STATE_VISIBLE:
243
 
      visible[type] = true;
244
 
      break;
245
 
 
246
 
    case AppletWindow::APPLET_STATE_PENDING:
247
 
      visible[type] = false;
248
 
      break;
249
 
    }
 
234
  applet_state[type] = state;
250
235
 
251
236
#ifdef PLATFORM_OS_UNIX
252
 
  if (visible[type] &&
253
 
      (type == APPLET_KDE || type == APPLET_GNOME))
 
237
  if (is_visible(type) && (type == APPLET_GNOME || type == APPLET_GENERIC_DBUS))
254
238
    {
 
239
      TRACE_MSG("Deactivate tray");
255
240
      deactivate_applet(APPLET_TRAY);
256
241
    }
257
242
#endif
258
243
 
259
244
  if (enabled && !is_visible())
260
245
    {
 
246
      TRACE_MSG("none visible, show in 5s");
261
247
      delayed_show = 5;
262
248
    }
263
249
 
 
250
  // REFACTOR
 
251
  if (state == AppletWindow::APPLET_STATE_VISIBLE)
 
252
    {
 
253
      IGUI *gui = GUI::get_instance();
 
254
      Menus *menus = gui->get_menus();
 
255
      menus->resync();
 
256
    }
 
257
 
264
258
  check_visible();
265
259
  TRACE_EXIT();
266
260
}
267
261
 
268
262
 
 
263
void
 
264
AppletControl::on_applet_request_activate(AppletType type)
 
265
{
 
266
  show(type);
 
267
}
 
268
 
269
269
//! Is at least a single applet visible.
270
270
bool
271
271
AppletControl::is_visible(AppletType type)
272
272
{
273
 
  return visible[type];
 
273
  return applet_state[type] == AppletWindow::APPLET_STATE_VISIBLE;
274
274
}
275
275
 
276
276
 
280
280
{
281
281
  bool ret = false;
282
282
 
283
 
    for (int i = 0; i < APPLET_SIZE; i++)
 
283
  for (int i = APPLET_FIRST; i < APPLET_SIZE; i++)
284
284
    {
285
 
      if (visible[i])
 
285
      if (is_visible((AppletType)i))
286
286
        {
287
287
          ret = true;
288
288
        }
298
298
  TRACE_ENTER("AppletControl::heartbeat");
299
299
  if (delayed_show < 0 && enabled && !is_visible())
300
300
    {
301
 
      delayed_show = 60;
 
301
      delayed_show = 30;
302
302
    }
303
303
  else if (delayed_show > 0)
304
304
    {
310
310
      show();
311
311
    }
312
312
 
313
 
  for (int i = 0; i < APPLET_SIZE; i++)
 
313
  for (int i = APPLET_FIRST; i < APPLET_SIZE; i++)
314
314
    {
315
 
      if (applets[i] != NULL && visible[i])
 
315
      if (applets[i] != NULL && is_visible((AppletType)i))
316
316
        {
317
317
          applets[i]->update_applet();
318
318
        }
323
323
 
324
324
//! Sets the tooltip of all visible applets.
325
325
void
326
 
AppletControl::set_timers_tooltip(std::string& tip)
 
326
AppletControl::set_tooltip(std::string& tip)
327
327
{
328
 
  for (int i = 0; i < APPLET_SIZE; i++)
 
328
  for (int i = APPLET_FIRST; i < APPLET_SIZE; i++)
329
329
    {
330
 
      if (applets[i] != NULL && visible[i])
 
330
      if (applets[i] != NULL && is_visible((AppletType)i))
331
331
        {
332
 
          applets[i]->set_timers_tooltip(tip);
 
332
          applets[i]->set_applet_tooltip(tip);
333
333
        }
334
334
    }
335
335
}
346
346
    {
347
347
      delayed_show = -1;
348
348
    }
349
 
  
 
349
 
350
350
  if (!previous_enabled && enabled)
351
351
    {
352
352
      show();
376
376
  TRACE_ENTER("AppletControl::check_visible");
377
377
  int count = 0;
378
378
 
379
 
  for (int i = 0; i < APPLET_SIZE; i++)
 
379
  for (int i = APPLET_FIRST; i < APPLET_SIZE; i++)
380
380
    {
381
 
      if (visible[i])
 
381
      if (is_visible((AppletType)i))
382
382
        {
 
383
          TRACE_MSG(i << " is visible"); 
383
384
          count++;
384
385
        }
385
386
    }
386
387
 
387
 
// #ifdef PLATFORM_OS_OSX
388
 
//   count++;
389
 
// #endif
390
 
    
391
 
  GUI *gui = GUI::get_instance();
392
 
  MainWindow *main = gui->get_main_window();
393
 
  if (main != NULL)
 
388
#ifdef PLATFORM_OS_OSX
 
389
  count++;
 
390
#endif
 
391
 
 
392
  bool new_visible = count > 0;
 
393
  if (new_visible != visible)
394
394
    {
395
 
      main->set_applet_active( count > 0 );
 
395
      visible = new_visible;
 
396
      visibility_changed_signal.emit();
396
397
    }
397
 
 
 
398
  
398
399
  TRACE_EXIT();
399
400
}
400
401
 
401
402
AppletWindow::AppletState
402
403
AppletControl::activate_applet(AppletType type)
403
404
{
404
 
  AppletState r = AppletWindow::APPLET_STATE_DISABLED;
 
405
  AppletState state = AppletWindow::APPLET_STATE_DISABLED;
405
406
 
406
407
  if (applets[type] != NULL)
407
408
    {
408
 
      r = applets[type]->activate_applet();
409
 
      if (r == AppletWindow::APPLET_STATE_VISIBLE)
410
 
        {
411
 
          visible[type] = true;
412
 
        }
 
409
      state = applets[type]->activate_applet();
 
410
      applet_state[type] = state;
413
411
    }
414
412
 
415
 
  return r;
 
413
  return state;
416
414
}
417
415
 
418
416
void
421
419
 if (applets[type] != NULL)
422
420
    {
423
421
      applets[type]->deactivate_applet();
424
 
      visible[type] = false;
 
422
      applet_state[type] = AppletWindow::APPLET_STATE_DISABLED;
425
423
    }
426
424
}
 
425
 
 
426
sigc::signal<void> &
 
427
AppletControl::signal_visibility_changed()
 
428
{
 
429
  return visibility_changed_signal;
 
430
}