~om26er/ubuntu/oneiric/unity/sru-778256

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/BamfLauncherIcon.cpp

  • Committer: Didier Roche
  • Date: 2011-07-21 16:17:59 UTC
  • mfrom: (55.813.3 upstream)
  • Revision ID: didier.roche@canonical.com-20110721161759-osmh94x428t2bf2b
* New upstream release.
* debian/control:
  - build-dep on libnotify-dev
  - bump libnux-1.0-dev dep for ABI break

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
struct _ShortcutData
40
40
{
41
 
  BamfLauncherIcon *self;
42
 
  IndicatorDesktopShortcuts *shortcuts;
43
 
  char *nick;
 
41
  BamfLauncherIcon* self;
 
42
  IndicatorDesktopShortcuts* shortcuts;
 
43
  char* nick;
44
44
};
45
45
typedef struct _ShortcutData ShortcutData;
46
 
static void shortcut_data_destroy (ShortcutData *data)
47
 
{
48
 
  g_object_unref (data->shortcuts);
49
 
  g_free (data->nick);
50
 
  g_slice_free (ShortcutData, data);
51
 
}
52
 
 
53
 
static void shortcut_activated (DbusmenuMenuitem* _sender, guint timestamp, gpointer userdata)
54
 
{
55
 
  ShortcutData *data = (ShortcutData *)userdata;
56
 
  indicator_desktop_shortcuts_nick_exec (data->shortcuts, data->nick);
57
 
}
58
 
 
59
 
void BamfLauncherIcon::Activate ()
60
 
{
61
 
  ActivateLauncherIcon ();
62
 
}
63
 
 
64
 
 
65
 
void BamfLauncherIcon::ActivateLauncherIcon ()
66
 
{
67
 
  bool scaleWasActive = PluginAdapter::Default ()->IsScaleActive ();
 
46
static void shortcut_data_destroy(ShortcutData* data)
 
47
{
 
48
  g_object_unref(data->shortcuts);
 
49
  g_free(data->nick);
 
50
  g_slice_free(ShortcutData, data);
 
51
}
 
52
 
 
53
static void shortcut_activated(DbusmenuMenuitem* _sender, guint timestamp, gpointer userdata)
 
54
{
 
55
  ShortcutData* data = (ShortcutData*)userdata;
 
56
  indicator_desktop_shortcuts_nick_exec(data->shortcuts, data->nick);
 
57
}
 
58
 
 
59
void BamfLauncherIcon::Activate(ActionArg arg)
 
60
{
 
61
  ActivateLauncherIcon(arg);
 
62
}
 
63
 
 
64
 
 
65
void BamfLauncherIcon::ActivateLauncherIcon(ActionArg arg)
 
66
{
 
67
  bool scaleWasActive = PluginAdapter::Default()->IsScaleActive();
68
68
 
69
69
  bool active, running;
70
 
  active = bamf_view_is_active (BAMF_VIEW (m_App));
71
 
  running = bamf_view_is_running (BAMF_VIEW (m_App));
 
70
  active = bamf_view_is_active(BAMF_VIEW(m_App));
 
71
  running = bamf_view_is_running(BAMF_VIEW(m_App));
72
72
 
73
73
  /* Behaviour:
74
74
   * 1) Nothing running -> launch application
80
80
 
81
81
  if (!running) // #1 above
82
82
  {
83
 
    if (GetQuirk (QUIRK_STARTING))
 
83
    if (GetQuirk(QUIRK_STARTING))
84
84
      return;
85
85
 
86
86
    if (scaleWasActive)
87
87
    {
88
 
      PluginAdapter::Default ()->TerminateScale ();
 
88
      PluginAdapter::Default()->TerminateScale();
89
89
    }
90
90
 
91
 
    SetQuirk (QUIRK_STARTING, true);
92
 
    OpenInstanceLauncherIcon ();
 
91
    SetQuirk(QUIRK_STARTING, true);
 
92
    OpenInstanceLauncherIcon();
93
93
  }
94
94
  else // app is running
95
95
  {
97
97
    {
98
98
      if (scaleWasActive) // #5 above
99
99
      {
100
 
        PluginAdapter::Default ()->TerminateScale ();
101
 
        Focus ();
 
100
        PluginAdapter::Default()->TerminateScale();
 
101
        Focus();
102
102
      }
103
103
      else // #2 above
104
104
      {
105
 
        Spread (0, false);
 
105
        if (arg.source != ActionArg::SWITCHER)
 
106
          Spread(0, false);
106
107
      }
107
108
    }
108
109
    else
109
110
    {
110
111
      if (scaleWasActive) // #4 above
111
112
      {
112
 
        PluginAdapter::Default ()->TerminateScale ();
113
 
        Focus ();
114
 
        Spread (0, false);
 
113
        PluginAdapter::Default()->TerminateScale();
 
114
        Focus();
 
115
        if (arg.source != ActionArg::SWITCHER)
 
116
          Spread(0, false);
115
117
      }
116
118
      else // #3 above
117
119
      {
118
 
        Focus ();
 
120
        Focus();
119
121
      }
120
122
    }
121
123
  }
122
124
 
123
 
  ubus_server_send_message (ubus_server_get_default (), UBUS_LAUNCHER_ACTION_DONE, NULL);
 
125
  ubus_server_send_message(ubus_server_get_default(), UBUS_LAUNCHER_ACTION_DONE, NULL);
124
126
}
125
127
 
126
 
BamfLauncherIcon::BamfLauncherIcon (Launcher* IconManager, BamfApplication *app, CompScreen *screen)
127
 
:   SimpleLauncherIcon(IconManager)
 
128
BamfLauncherIcon::BamfLauncherIcon(Launcher* IconManager, BamfApplication* app, CompScreen* screen)
 
129
  :   SimpleLauncherIcon(IconManager)
128
130
{
129
131
  _cached_desktop_file = NULL;
130
132
  _cached_name = NULL;
135
137
  _dnd_hovered = false;
136
138
  _launcher = IconManager;
137
139
  _menu_desktop_shortcuts = NULL;
138
 
  char *icon_name = bamf_view_get_icon (BAMF_VIEW (m_App));
139
 
 
140
 
  SetTooltipText (BamfName ());
141
 
  SetIconName (icon_name);
142
 
  SetIconType (TYPE_APPLICATION);
143
 
 
144
 
  if (bamf_view_is_sticky (BAMF_VIEW (m_App)))
145
 
    SetQuirk (QUIRK_VISIBLE, true);
 
140
  char* icon_name = bamf_view_get_icon(BAMF_VIEW(m_App));
 
141
 
 
142
  tooltip_text = BamfName();
 
143
  SetIconName(icon_name);
 
144
  SetIconType(TYPE_APPLICATION);
 
145
 
 
146
  if (bamf_view_is_sticky(BAMF_VIEW(m_App)))
 
147
    SetQuirk(QUIRK_VISIBLE, true);
146
148
  else
147
 
    SetQuirk (QUIRK_VISIBLE, bamf_view_user_visible (BAMF_VIEW (m_App)));
148
 
 
149
 
  SetQuirk (QUIRK_ACTIVE, bamf_view_is_active (BAMF_VIEW (m_App)));
150
 
  SetQuirk (QUIRK_RUNNING, bamf_view_is_running (BAMF_VIEW (m_App)));
151
 
 
152
 
  g_free (icon_name);
153
 
 
154
 
  g_signal_connect (app, "child-removed", (GCallback) &BamfLauncherIcon::OnChildRemoved, this);
155
 
  g_signal_connect (app, "child-added", (GCallback) &BamfLauncherIcon::OnChildAdded, this);
156
 
  g_signal_connect (app, "urgent-changed", (GCallback) &BamfLauncherIcon::OnUrgentChanged, this);
157
 
  g_signal_connect (app, "running-changed", (GCallback) &BamfLauncherIcon::OnRunningChanged, this);
158
 
  g_signal_connect (app, "active-changed", (GCallback) &BamfLauncherIcon::OnActiveChanged, this);
159
 
  g_signal_connect (app, "user-visible-changed", (GCallback) &BamfLauncherIcon::OnUserVisibleChanged, this);
160
 
  g_signal_connect (app, "closed", (GCallback) &BamfLauncherIcon::OnClosed, this);
161
 
 
162
 
  g_object_ref (m_App);
163
 
 
164
 
  EnsureWindowState ();
165
 
  UpdateMenus ();
 
149
    SetQuirk(QUIRK_VISIBLE, bamf_view_user_visible(BAMF_VIEW(m_App)));
 
150
 
 
151
  SetQuirk(QUIRK_ACTIVE, bamf_view_is_active(BAMF_VIEW(m_App)));
 
152
  SetQuirk(QUIRK_RUNNING, bamf_view_is_running(BAMF_VIEW(m_App)));
 
153
 
 
154
  g_free(icon_name);
 
155
 
 
156
  g_signal_connect(app, "child-removed", (GCallback) &BamfLauncherIcon::OnChildRemoved, this);
 
157
  g_signal_connect(app, "child-added", (GCallback) &BamfLauncherIcon::OnChildAdded, this);
 
158
  g_signal_connect(app, "urgent-changed", (GCallback) &BamfLauncherIcon::OnUrgentChanged, this);
 
159
  g_signal_connect(app, "running-changed", (GCallback) &BamfLauncherIcon::OnRunningChanged, this);
 
160
  g_signal_connect(app, "active-changed", (GCallback) &BamfLauncherIcon::OnActiveChanged, this);
 
161
  g_signal_connect(app, "user-visible-changed", (GCallback) &BamfLauncherIcon::OnUserVisibleChanged, this);
 
162
  g_signal_connect(app, "closed", (GCallback) &BamfLauncherIcon::OnClosed, this);
 
163
 
 
164
  g_object_ref(m_App);
 
165
 
 
166
  EnsureWindowState();
 
167
  UpdateMenus();
166
168
 
167
169
  // add a file watch to the desktop file so that if/when the app is removed we can remove ourself from the launcher.
168
 
  GFile *_desktop_file = g_file_new_for_path (DesktopFile ());
169
 
  _desktop_file_monitor = g_file_monitor_file (_desktop_file,
170
 
                                               G_FILE_MONITOR_NONE,
171
 
                                               NULL,
172
 
                                               NULL);
173
 
 
174
 
  _on_desktop_file_changed_handler_id = g_signal_connect (_desktop_file_monitor,
175
 
                                                          "changed",
176
 
                                                          G_CALLBACK (&BamfLauncherIcon::OnDesktopFileChanged),
177
 
                                                          this);
178
 
 
179
 
  _on_window_minimized_connection = (sigc::connection) PluginAdapter::Default ()->window_minimized.connect (sigc::mem_fun (this, &BamfLauncherIcon::OnWindowMinimized));
180
 
  _hidden_changed_connection = (sigc::connection) IconManager->hidden_changed.connect (sigc::mem_fun (this, &BamfLauncherIcon::OnLauncherHiddenChanged));
 
170
  GFile* _desktop_file = g_file_new_for_path(DesktopFile());
 
171
  _desktop_file_monitor = g_file_monitor_file(_desktop_file,
 
172
                                              G_FILE_MONITOR_NONE,
 
173
                                              NULL,
 
174
                                              NULL);
 
175
 
 
176
  _on_desktop_file_changed_handler_id = g_signal_connect(_desktop_file_monitor,
 
177
                                                         "changed",
 
178
                                                         G_CALLBACK(&BamfLauncherIcon::OnDesktopFileChanged),
 
179
                                                         this);
 
180
 
 
181
  PluginAdapter::Default()->window_minimized.connect(sigc::mem_fun(this, &BamfLauncherIcon::OnWindowMinimized));
 
182
  IconManager->hidden_changed.connect(sigc::mem_fun(this, &BamfLauncherIcon::OnLauncherHiddenChanged));
181
183
 
182
184
  /* hack */
183
 
  SetProgress (0.0f);
184
 
  
 
185
  SetProgress(0.0f);
 
186
 
185
187
}
186
188
 
187
189
BamfLauncherIcon::~BamfLauncherIcon()
188
190
{
189
 
  g_object_set_qdata (G_OBJECT (m_App), g_quark_from_static_string ("unity-seen"), GINT_TO_POINTER (0));
 
191
  g_object_set_qdata(G_OBJECT(m_App), g_quark_from_static_string("unity-seen"), GINT_TO_POINTER(0));
190
192
 
191
193
  // We might not have created the menu items yet
192
 
  if (_menu_items.find ("Pin") != _menu_items.end ()) {
193
 
    g_signal_handler_disconnect ((gpointer) _menu_items["Pin"],
194
 
                                 _menu_callbacks["Pin"]);
 
194
  if (_menu_items.find("Pin") != _menu_items.end())
 
195
  {
 
196
    g_signal_handler_disconnect((gpointer) _menu_items["Pin"],
 
197
                                _menu_callbacks["Pin"]);
195
198
  }
196
199
 
197
 
  if (_menu_items.find ("Quit") != _menu_items.end ()) {
198
 
    g_signal_handler_disconnect ((gpointer) _menu_items["Quit"],
199
 
                                 _menu_callbacks["Quit"]);
 
200
  if (_menu_items.find("Quit") != _menu_items.end())
 
201
  {
 
202
    g_signal_handler_disconnect((gpointer) _menu_items["Quit"],
 
203
                                _menu_callbacks["Quit"]);
200
204
  }
201
205
 
202
206
  if (_on_desktop_file_changed_handler_id != 0)
203
 
    g_signal_handler_disconnect ((gpointer) _desktop_file_monitor,
204
 
                                 _on_desktop_file_changed_handler_id);
205
 
 
206
 
  if (_on_window_minimized_connection.connected ())
207
 
    _on_window_minimized_connection.disconnect ();
208
 
  
209
 
  if (_hidden_changed_connection.connected ())
210
 
    _hidden_changed_connection.disconnect ();
211
 
 
212
 
  g_signal_handlers_disconnect_by_func (m_App, (void *) &BamfLauncherIcon::OnChildRemoved,       this);
213
 
  g_signal_handlers_disconnect_by_func (m_App, (void *) &BamfLauncherIcon::OnChildAdded,         this);
214
 
  g_signal_handlers_disconnect_by_func (m_App, (void *) &BamfLauncherIcon::OnUrgentChanged,      this);
215
 
  g_signal_handlers_disconnect_by_func (m_App, (void *) &BamfLauncherIcon::OnRunningChanged,     this);
216
 
  g_signal_handlers_disconnect_by_func (m_App, (void *) &BamfLauncherIcon::OnActiveChanged,      this);
217
 
  g_signal_handlers_disconnect_by_func (m_App, (void *) &BamfLauncherIcon::OnUserVisibleChanged, this);
218
 
  g_signal_handlers_disconnect_by_func (m_App, (void *) &BamfLauncherIcon::OnClosed,             this);
219
 
 
220
 
  g_object_unref (m_App);
221
 
  g_object_unref (_desktop_file_monitor);
222
 
 
223
 
  g_free (_cached_desktop_file);
224
 
  g_free (_cached_name);
225
 
}
226
 
 
227
 
void BamfLauncherIcon::OnLauncherHiddenChanged ()
228
 
{
229
 
  UpdateIconGeometries (GetCenter ());
230
 
}
231
 
 
232
 
void BamfLauncherIcon::OnWindowMinimized (guint32 xid)
233
 
{
234
 
  if (!OwnsWindow (xid))
 
207
    g_signal_handler_disconnect((gpointer) _desktop_file_monitor,
 
208
                                _on_desktop_file_changed_handler_id);
 
209
 
 
210
  g_signal_handlers_disconnect_by_func(m_App, (void*) &BamfLauncherIcon::OnChildRemoved,       this);
 
211
  g_signal_handlers_disconnect_by_func(m_App, (void*) &BamfLauncherIcon::OnChildAdded,         this);
 
212
  g_signal_handlers_disconnect_by_func(m_App, (void*) &BamfLauncherIcon::OnUrgentChanged,      this);
 
213
  g_signal_handlers_disconnect_by_func(m_App, (void*) &BamfLauncherIcon::OnRunningChanged,     this);
 
214
  g_signal_handlers_disconnect_by_func(m_App, (void*) &BamfLauncherIcon::OnActiveChanged,      this);
 
215
  g_signal_handlers_disconnect_by_func(m_App, (void*) &BamfLauncherIcon::OnUserVisibleChanged, this);
 
216
  g_signal_handlers_disconnect_by_func(m_App, (void*) &BamfLauncherIcon::OnClosed,             this);
 
217
 
 
218
  g_object_unref(m_App);
 
219
  g_object_unref(_desktop_file_monitor);
 
220
 
 
221
  g_free(_cached_desktop_file);
 
222
  g_free(_cached_name);
 
223
}
 
224
 
 
225
void BamfLauncherIcon::OnLauncherHiddenChanged()
 
226
{
 
227
  UpdateIconGeometries(GetCenter());
 
228
}
 
229
 
 
230
void BamfLauncherIcon::OnWindowMinimized(guint32 xid)
 
231
{
 
232
  if (!OwnsWindow(xid))
235
233
    return;
236
234
 
237
 
  Present (0.5f, 600);
238
 
  UpdateQuirkTimeDelayed (300, QUIRK_SHIMMER);
239
 
}
240
 
 
241
 
bool BamfLauncherIcon::IsSticky ()
242
 
{
243
 
  return bamf_view_is_sticky (BAMF_VIEW (m_App));
244
 
}
245
 
 
246
 
const char* BamfLauncherIcon::DesktopFile ()
247
 
{
248
 
  char *filename = NULL;
249
 
  filename = (char*) bamf_application_get_desktop_file (m_App);
 
235
  Present(0.5f, 600);
 
236
  UpdateQuirkTimeDelayed(300, QUIRK_SHIMMER);
 
237
}
 
238
 
 
239
bool BamfLauncherIcon::IsSticky()
 
240
{
 
241
  return bamf_view_is_sticky(BAMF_VIEW(m_App));
 
242
}
 
243
 
 
244
const char* BamfLauncherIcon::DesktopFile()
 
245
{
 
246
  char* filename = NULL;
 
247
  filename = (char*) bamf_application_get_desktop_file(m_App);
250
248
 
251
249
  if (filename != NULL)
252
250
  {
253
251
    if (_cached_desktop_file != NULL)
254
 
      g_free (_cached_desktop_file);
255
 
    
256
 
    _cached_desktop_file = g_strdup (filename);
 
252
      g_free(_cached_desktop_file);
 
253
 
 
254
    _cached_desktop_file = g_strdup(filename);
257
255
  }
258
 
  
 
256
 
259
257
  return _cached_desktop_file;
260
258
}
261
259
 
262
 
const char* BamfLauncherIcon::BamfName ()
 
260
const char* BamfLauncherIcon::BamfName()
263
261
{
264
 
  char *name = NULL;
265
 
  name = (char *)bamf_view_get_name (BAMF_VIEW (m_App));
266
 
 
267
 
  if (name != NULL)
268
 
  {
269
 
    if (_cached_name != NULL)
270
 
      g_free (_cached_name);
271
 
 
272
 
    _cached_name = g_strdup (name);
273
 
  }
 
262
  const char* name = NULL;
 
263
  name = bamf_view_get_name(BAMF_VIEW(m_App));
 
264
 
 
265
  if (name == NULL)
 
266
    name = "";
 
267
 
 
268
  if (_cached_name != NULL)
 
269
    g_free(_cached_name);
 
270
 
 
271
  _cached_name = g_strdup(name);
274
272
 
275
273
  return _cached_name;
276
274
}
277
275
 
278
 
void BamfLauncherIcon::AddProperties (GVariantBuilder *builder)
 
276
void BamfLauncherIcon::AddProperties(GVariantBuilder* builder)
279
277
{
280
 
  LauncherIcon::AddProperties (builder);
281
 
 
282
 
  g_variant_builder_add (builder, "{sv}", "desktop-file", g_variant_new_string (bamf_application_get_desktop_file (m_App)));
283
 
 
284
 
  GList *children, *l;
285
 
  BamfView *view;
286
 
 
287
 
  children = bamf_view_get_children (BAMF_VIEW (m_App));
288
 
  GVariant* xids[(int) g_list_length (children)];
 
278
  LauncherIcon::AddProperties(builder);
 
279
 
 
280
  g_variant_builder_add(builder, "{sv}", "desktop-file", g_variant_new_string(bamf_application_get_desktop_file(m_App)));
 
281
 
 
282
  GList* children, *l;
 
283
  BamfView* view;
 
284
 
 
285
  children = bamf_view_get_children(BAMF_VIEW(m_App));
 
286
  GVariant* xids[(int) g_list_length(children)];
289
287
 
290
288
  int i = 0;
291
289
  for (l = children; l; l = l->next)
292
290
  {
293
 
    view = (BamfView *) l->data;
 
291
    view = (BamfView*) l->data;
294
292
 
295
 
    if (BAMF_IS_WINDOW (view))
 
293
    if (BAMF_IS_WINDOW(view))
296
294
    {
297
 
      xids[i++] = g_variant_new_uint32 (bamf_window_get_xid (BAMF_WINDOW (view)));
 
295
      xids[i++] = g_variant_new_uint32(bamf_window_get_xid(BAMF_WINDOW(view)));
298
296
    }
299
297
  }
300
 
  g_list_free (children);
301
 
  g_variant_builder_add (builder, "{sv}", "xids", g_variant_new_array (G_VARIANT_TYPE_UINT32, xids, i));
 
298
  g_list_free(children);
 
299
  g_variant_builder_add(builder, "{sv}", "xids", g_variant_new_array(G_VARIANT_TYPE_UINT32, xids, i));
302
300
}
303
301
 
304
 
bool BamfLauncherIcon::OwnsWindow (Window w)
 
302
bool BamfLauncherIcon::OwnsWindow(Window w)
305
303
{
306
 
  GList *children, *l;
307
 
  BamfView *view;
 
304
  GList* children, *l;
 
305
  BamfView* view;
308
306
  bool owns = false;
309
307
 
310
 
  children = bamf_view_get_children (BAMF_VIEW (m_App));
 
308
  children = bamf_view_get_children(BAMF_VIEW(m_App));
311
309
 
312
310
  for (l = children; l; l = l->next)
313
311
  {
314
 
    view = (BamfView *) l->data;
 
312
    view = (BamfView*) l->data;
315
313
 
316
 
    if (BAMF_IS_WINDOW (view))
 
314
    if (BAMF_IS_WINDOW(view))
317
315
    {
318
 
      guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
 
316
      guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
319
317
 
320
318
      if (xid == w)
321
319
      {
325
323
    }
326
324
  }
327
325
 
328
 
  g_list_free (children);
 
326
  g_list_free(children);
329
327
  return owns;
330
328
}
331
329
 
332
 
void BamfLauncherIcon::OpenInstanceWithUris (std::list<char *> uris)
 
330
void BamfLauncherIcon::OpenInstanceWithUris(std::list<char*> uris)
333
331
{
334
 
  GDesktopAppInfo *appInfo;
335
 
  GError *error = NULL;
336
 
  std::list<char *>::iterator it;
337
 
 
338
 
  appInfo = g_desktop_app_info_new_from_filename (bamf_application_get_desktop_file (BAMF_APPLICATION (m_App)));
339
 
  
340
 
  if (g_app_info_supports_uris (G_APP_INFO (appInfo)))
 
332
  GDesktopAppInfo* appInfo;
 
333
  GError* error = NULL;
 
334
  std::list<char*>::iterator it;
 
335
 
 
336
  appInfo = g_desktop_app_info_new_from_filename(bamf_application_get_desktop_file(BAMF_APPLICATION(m_App)));
 
337
 
 
338
  if (g_app_info_supports_uris(G_APP_INFO(appInfo)))
341
339
  {
342
 
    GList *list = NULL;
343
 
    
344
 
    for (it = uris.begin (); it != uris.end (); it++)
345
 
      list = g_list_prepend (list, *it);
346
 
    
347
 
    g_app_info_launch_uris (G_APP_INFO (appInfo), list, NULL, &error);
348
 
    g_list_free (list);
 
340
    GList* list = NULL;
 
341
 
 
342
    for (it = uris.begin(); it != uris.end(); it++)
 
343
      list = g_list_prepend(list, *it);
 
344
 
 
345
    g_app_info_launch_uris(G_APP_INFO(appInfo), list, NULL, &error);
 
346
    g_list_free(list);
349
347
  }
350
 
  else if (g_app_info_supports_files (G_APP_INFO (appInfo)))
 
348
  else if (g_app_info_supports_files(G_APP_INFO(appInfo)))
351
349
  {
352
 
    GList *list = NULL, *l;
353
 
    for (it = uris.begin (); it != uris.end (); it++)
 
350
    GList* list = NULL, *l;
 
351
    for (it = uris.begin(); it != uris.end(); it++)
354
352
    {
355
 
      GFile *file = g_file_new_for_uri (*it);
356
 
      list = g_list_prepend (list, file);
 
353
      GFile* file = g_file_new_for_uri(*it);
 
354
      list = g_list_prepend(list, file);
357
355
    }
358
 
    g_app_info_launch (G_APP_INFO (appInfo), list, NULL, &error);
359
 
    
 
356
    g_app_info_launch(G_APP_INFO(appInfo), list, NULL, &error);
 
357
 
360
358
    for (l = list; l; l = l->next)
361
 
      g_object_unref (G_FILE (list->data));
362
 
      
363
 
    g_list_free (list);
 
359
      g_object_unref(G_FILE(list->data));
 
360
 
 
361
    g_list_free(list);
364
362
  }
365
363
  else
366
364
  {
367
 
    g_app_info_launch (G_APP_INFO (appInfo), NULL, NULL, &error);
 
365
    g_app_info_launch(G_APP_INFO(appInfo), NULL, NULL, &error);
368
366
  }
369
367
 
370
 
  g_object_unref (appInfo);
 
368
  g_object_unref(appInfo);
371
369
 
372
370
  if (error)
373
371
  {
374
 
    g_warning ("%s\n", error->message);
375
 
    g_error_free (error);
 
372
    g_warning("%s\n", error->message);
 
373
    g_error_free(error);
376
374
  }
377
375
 
378
 
  UpdateQuirkTime (QUIRK_STARTING);
379
 
}
380
 
 
381
 
void BamfLauncherIcon::OpenInstanceLauncherIcon ()
382
 
{
383
 
  std::list<char *> empty;
384
 
  OpenInstanceWithUris (empty);
385
 
  ubus_server_send_message (ubus_server_get_default (), UBUS_LAUNCHER_ACTION_DONE, NULL);
386
 
}
387
 
 
388
 
void BamfLauncherIcon::Focus ()
389
 
{
390
 
  GList *children, *l;
391
 
  BamfView *view;
 
376
  UpdateQuirkTime(QUIRK_STARTING);
 
377
}
 
378
 
 
379
void BamfLauncherIcon::OpenInstanceLauncherIcon()
 
380
{
 
381
  std::list<char*> empty;
 
382
  OpenInstanceWithUris(empty);
 
383
  ubus_server_send_message(ubus_server_get_default(), UBUS_LAUNCHER_ACTION_DONE, NULL);
 
384
}
 
385
 
 
386
void BamfLauncherIcon::Focus()
 
387
{
 
388
  GList* children, *l;
 
389
  BamfView* view;
392
390
  bool any_urgent = false;
393
391
  bool any_on_current = false;
394
392
 
395
 
  children = bamf_view_get_children (BAMF_VIEW (m_App));
 
393
  children = bamf_view_get_children(BAMF_VIEW(m_App));
396
394
 
397
395
  CompWindowList windows;
398
396
 
399
397
  /* get the list of windows */
400
398
  for (l = children; l; l = l->next)
401
399
  {
402
 
    view = (BamfView *) l->data;
 
400
    view = (BamfView*) l->data;
403
401
 
404
 
    if (BAMF_IS_WINDOW (view))
 
402
    if (BAMF_IS_WINDOW(view))
405
403
    {
406
 
      guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
 
404
      guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
407
405
 
408
 
      CompWindow *window = m_Screen->findWindow ((Window) xid);
 
406
      CompWindow* window = m_Screen->findWindow((Window) xid);
409
407
 
410
408
      if (window)
411
409
      {
412
 
        if (bamf_view_is_urgent (view))
 
410
        if (bamf_view_is_urgent(view))
413
411
          any_urgent = true;
414
 
        windows.push_back (window);
 
412
        windows.push_back(window);
415
413
      }
416
414
    }
417
415
  }
418
416
 
419
417
  // not a good sign
420
 
  if (windows.empty ())
 
418
  if (windows.empty())
421
419
  {
422
 
    g_list_free (children);
 
420
    g_list_free(children);
423
421
    return;
424
422
  }
425
423
 
426
424
  /* sort the list */
427
425
  CompWindowList tmp;
428
426
  CompWindowList::iterator it;
429
 
  for (it = m_Screen->windows ().begin (); it != m_Screen->windows ().end (); it++)
 
427
  for (it = m_Screen->windows().begin(); it != m_Screen->windows().end(); it++)
430
428
  {
431
 
    if (std::find (windows.begin (), windows.end (), *it) != windows.end ())
432
 
      tmp.push_back (*it);
 
429
    if (std::find(windows.begin(), windows.end(), *it) != windows.end())
 
430
      tmp.push_back(*it);
433
431
  }
434
432
  windows = tmp;
435
433
 
436
434
  /* filter based on workspace */
437
 
  for (it = windows.begin (); it != windows.end (); it++)
 
435
  for (it = windows.begin(); it != windows.end(); it++)
438
436
  {
439
 
    if ((*it)->defaultViewport () == m_Screen->vp ())
 
437
    if ((*it)->defaultViewport() == m_Screen->vp())
440
438
    {
441
439
      any_on_current = true;
442
440
      break;
456
454
    }*/
457
455
    for (l = children; l; l = l->next)
458
456
    {
459
 
      view = (BamfView *) l->data;
 
457
      view = (BamfView*) l->data;
460
458
 
461
 
      if (BAMF_IS_WINDOW (view))
 
459
      if (BAMF_IS_WINDOW(view))
462
460
      {
463
 
        guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
464
 
 
465
 
        CompWindow *window = m_Screen->findWindow ((Window) xid);
466
 
 
467
 
        if (window && bamf_view_is_urgent (view))
 
461
        guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
 
462
 
 
463
        CompWindow* window = m_Screen->findWindow((Window) xid);
 
464
 
 
465
        if (window && bamf_view_is_urgent(view))
468
466
        {
469
 
          window->activate ();
 
467
          window->activate();
470
468
          break;
471
469
        }
472
470
      }
474
472
  }
475
473
  else if (any_on_current)
476
474
  {
477
 
    for (it = windows.begin (); it != windows.end (); it++)
 
475
    for (it = windows.begin(); it != windows.end(); it++)
478
476
    {
479
 
      if ((*it)->defaultViewport () == m_Screen->vp ())
 
477
      if ((*it)->defaultViewport() == m_Screen->vp())
480
478
      {
481
 
        (*it)->activate ();
 
479
        (*it)->activate();
482
480
      }
483
481
    }
484
482
  }
485
483
  else
486
484
  {
487
 
    (*(windows.rbegin ()))->activate ();
 
485
    (*(windows.rbegin()))->activate();
488
486
  }
489
487
 
490
 
  g_list_free (children);
 
488
  g_list_free(children);
491
489
}
492
490
 
493
 
bool BamfLauncherIcon::Spread (int state, bool force)
 
491
bool BamfLauncherIcon::Spread(int state, bool force)
494
492
{
495
 
  BamfView *view;
496
 
  GList *children, *l;
497
 
  children = bamf_view_get_children (BAMF_VIEW (m_App));
 
493
  BamfView* view;
 
494
  GList* children, *l;
 
495
  children = bamf_view_get_children(BAMF_VIEW(m_App));
498
496
 
499
497
  std::list<Window> windowList;
500
498
  for (l = children; l; l = l->next)
501
499
  {
502
 
    view = (BamfView *) l->data;
 
500
    view = (BamfView*) l->data;
503
501
 
504
 
    if (BAMF_IS_WINDOW (view))
 
502
    if (BAMF_IS_WINDOW(view))
505
503
    {
506
 
      guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
507
 
      CompWindow *window = m_Screen->findWindow ((Window) xid);
 
504
      guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
 
505
      CompWindow* window = m_Screen->findWindow((Window) xid);
508
506
 
509
507
      // filter by workspace
510
 
      if (window && window->defaultViewport () == m_Screen->vp ())
 
508
      if (window && window->defaultViewport() == m_Screen->vp())
511
509
      {
512
 
        windowList.push_back ((Window) xid);
 
510
        windowList.push_back((Window) xid);
513
511
      }
514
512
    }
515
513
  }
516
514
 
517
 
  if (windowList.size () > 1 || (windowList.size () > 0 && force))
 
515
  if (windowList.size() > 1 || (windowList.size() > 0 && force))
518
516
  {
519
 
    std::string match = PluginAdapter::Default ()->MatchStringForXids (&windowList);
520
 
    PluginAdapter::Default ()->InitiateScale (match, state);
521
 
    g_list_free (children);
 
517
    std::string match = PluginAdapter::Default()->MatchStringForXids(&windowList);
 
518
    PluginAdapter::Default()->InitiateScale(match, state);
 
519
    g_list_free(children);
522
520
    return true;
523
521
  }
524
522
 
525
 
  g_list_free (children);
526
 
 
527
 
  return false;  
528
 
}
529
 
 
530
 
void BamfLauncherIcon::OnClosed (BamfView *view, gpointer data)
531
 
{
532
 
  BamfLauncherIcon *self = (BamfLauncherIcon *) data;
533
 
 
534
 
  if (!bamf_view_is_sticky (BAMF_VIEW (self->m_App)))
535
 
    self->Remove ();
536
 
}
537
 
 
538
 
void BamfLauncherIcon::OnUserVisibleChanged (BamfView *view, gboolean visible, 
539
 
                                             gpointer data)
540
 
{
541
 
  BamfLauncherIcon *self = (BamfLauncherIcon *) data;
542
 
 
543
 
  if (!bamf_view_is_sticky (BAMF_VIEW (self->m_App)))
544
 
    self->SetQuirk (QUIRK_VISIBLE, visible);
545
 
}
546
 
 
547
 
void BamfLauncherIcon::OnRunningChanged (BamfView *view, gboolean running, 
548
 
                                         gpointer data)
549
 
{
550
 
  BamfLauncherIcon *self = (BamfLauncherIcon *) data;
551
 
  self->SetQuirk (QUIRK_RUNNING, running);
 
523
  g_list_free(children);
 
524
 
 
525
  return false;
 
526
}
 
527
 
 
528
void BamfLauncherIcon::OnClosed(BamfView* view, gpointer data)
 
529
{
 
530
  BamfLauncherIcon* self = (BamfLauncherIcon*) data;
 
531
 
 
532
  if (!bamf_view_is_sticky(BAMF_VIEW(self->m_App)))
 
533
    self->Remove();
 
534
}
 
535
 
 
536
void BamfLauncherIcon::OnUserVisibleChanged(BamfView* view, gboolean visible,
 
537
                                            gpointer data)
 
538
{
 
539
  BamfLauncherIcon* self = (BamfLauncherIcon*) data;
 
540
 
 
541
  if (!bamf_view_is_sticky(BAMF_VIEW(self->m_App)))
 
542
    self->SetQuirk(QUIRK_VISIBLE, visible);
 
543
}
 
544
 
 
545
void BamfLauncherIcon::OnRunningChanged(BamfView* view, gboolean running,
 
546
                                        gpointer data)
 
547
{
 
548
  BamfLauncherIcon* self = (BamfLauncherIcon*) data;
 
549
  self->SetQuirk(QUIRK_RUNNING, running);
552
550
 
553
551
  if (running)
554
552
  {
555
 
    self->EnsureWindowState ();
556
 
    self->UpdateIconGeometries (self->GetCenter ());
 
553
    self->EnsureWindowState();
 
554
    self->UpdateIconGeometries(self->GetCenter());
557
555
  }
558
556
}
559
557
 
560
 
void BamfLauncherIcon::OnActiveChanged (BamfView *view, gboolean active, gpointer data)
561
 
{
562
 
  BamfLauncherIcon *self = (BamfLauncherIcon *) data;
563
 
  self->SetQuirk (QUIRK_ACTIVE, active);
564
 
}
565
 
 
566
 
void BamfLauncherIcon::OnUrgentChanged (BamfView *view, gboolean urgent, gpointer data)
567
 
{
568
 
  BamfLauncherIcon *self = (BamfLauncherIcon *) data;
569
 
  self->SetQuirk (QUIRK_URGENT, urgent);
570
 
}
571
 
 
572
 
void BamfLauncherIcon::EnsureWindowState ()
573
 
{
574
 
  GList *children, *l;
 
558
void BamfLauncherIcon::OnActiveChanged(BamfView* view, gboolean active, gpointer data)
 
559
{
 
560
  BamfLauncherIcon* self = (BamfLauncherIcon*) data;
 
561
  self->SetQuirk(QUIRK_ACTIVE, active);
 
562
}
 
563
 
 
564
void BamfLauncherIcon::OnUrgentChanged(BamfView* view, gboolean urgent, gpointer data)
 
565
{
 
566
  BamfLauncherIcon* self = (BamfLauncherIcon*) data;
 
567
  self->SetQuirk(QUIRK_URGENT, urgent);
 
568
}
 
569
 
 
570
void BamfLauncherIcon::EnsureWindowState()
 
571
{
 
572
  GList* children, *l;
575
573
  int count = 0;
576
574
 
577
575
  bool has_visible = false;
578
 
  
579
 
  children = bamf_view_get_children (BAMF_VIEW (m_App));
 
576
 
 
577
  children = bamf_view_get_children(BAMF_VIEW(m_App));
580
578
  for (l = children; l; l = l->next)
581
579
  {
582
 
    if (!BAMF_IS_WINDOW (l->data))
 
580
    if (!BAMF_IS_WINDOW(l->data))
583
581
      continue;
584
 
      
 
582
 
585
583
    count++;
586
 
    
587
 
    guint32 xid = bamf_window_get_xid (BAMF_WINDOW (l->data));
588
 
    CompWindow *window = m_Screen->findWindow ((Window) xid);
589
 
    
590
 
    if (window && window->defaultViewport () == m_Screen->vp ())
 
584
 
 
585
    guint32 xid = bamf_window_get_xid(BAMF_WINDOW(l->data));
 
586
    CompWindow* window = m_Screen->findWindow((Window) xid);
 
587
 
 
588
    if (window && window->defaultViewport() == m_Screen->vp())
591
589
      has_visible = true;
592
590
  }
593
591
 
594
 
  SetRelatedWindows (count);
595
 
  SetHasVisibleWindow (has_visible);
596
 
 
597
 
  g_list_free (children);
598
 
}
599
 
 
600
 
void BamfLauncherIcon::OnChildAdded (BamfView *view, BamfView *child, gpointer data)
601
 
{
602
 
  BamfLauncherIcon *self = (BamfLauncherIcon*) data;
603
 
  self->EnsureWindowState ();
604
 
  self->UpdateMenus ();
605
 
  self->UpdateIconGeometries (self->GetCenter ());
606
 
}
607
 
 
608
 
void BamfLauncherIcon::OnChildRemoved (BamfView *view, BamfView *child, gpointer data)
609
 
{
610
 
  BamfLauncherIcon *self = (BamfLauncherIcon*) data;
611
 
  self->EnsureWindowState ();
612
 
}
613
 
 
614
 
void BamfLauncherIcon::UpdateMenus ()
615
 
{
616
 
  GList *children, *l;
617
 
  IndicatorDesktopShortcuts *desktop_shortcuts;
618
 
 
619
 
  children = bamf_view_get_children (BAMF_VIEW (m_App));
 
592
  SetRelatedWindows(count);
 
593
  SetHasWindowOnViewport(has_visible);
 
594
 
 
595
  g_list_free(children);
 
596
}
 
597
 
 
598
void BamfLauncherIcon::OnChildAdded(BamfView* view, BamfView* child, gpointer data)
 
599
{
 
600
  BamfLauncherIcon* self = (BamfLauncherIcon*) data;
 
601
  self->EnsureWindowState();
 
602
  self->UpdateMenus();
 
603
  self->UpdateIconGeometries(self->GetCenter());
 
604
}
 
605
 
 
606
void BamfLauncherIcon::OnChildRemoved(BamfView* view, BamfView* child, gpointer data)
 
607
{
 
608
  BamfLauncherIcon* self = (BamfLauncherIcon*) data;
 
609
  self->EnsureWindowState();
 
610
}
 
611
 
 
612
void BamfLauncherIcon::UpdateMenus()
 
613
{
 
614
  GList* children, *l;
 
615
  IndicatorDesktopShortcuts* desktop_shortcuts;
 
616
 
 
617
  children = bamf_view_get_children(BAMF_VIEW(m_App));
620
618
  for (l = children; l; l = l->next)
621
619
  {
622
 
    if (!BAMF_IS_INDICATOR (l->data))
 
620
    if (!BAMF_IS_INDICATOR(l->data))
623
621
      continue;
624
622
 
625
 
    BamfIndicator *indicator = BAMF_INDICATOR (l->data);
626
 
    std::string path = bamf_indicator_get_dbus_menu_path (indicator);
 
623
    BamfIndicator* indicator = BAMF_INDICATOR(l->data);
 
624
    std::string path = bamf_indicator_get_dbus_menu_path(indicator);
627
625
 
628
626
    // we already have this
629
 
    if (_menu_clients.find (path) != _menu_clients.end ())
 
627
    if (_menu_clients.find(path) != _menu_clients.end())
630
628
      continue;
631
629
 
632
 
    DbusmenuClient *client = dbusmenu_client_new (bamf_indicator_get_remote_address (indicator), path.c_str ());
 
630
    DbusmenuClient* client = dbusmenu_client_new(bamf_indicator_get_remote_address(indicator), path.c_str());
633
631
    _menu_clients[path] = client;
634
632
  }
635
633
 
636
 
  g_list_free (children);
637
 
  
 
634
  g_list_free(children);
 
635
 
638
636
  // add dynamic quicklist
639
637
  if (_menuclient_dynamic_quicklist != NULL)
640
638
    _menu_clients["dynamicquicklist"] = _menuclient_dynamic_quicklist;
641
639
 
642
640
  // make a client for desktop file actions
643
 
  if (!DBUSMENU_IS_MENUITEM (_menu_desktop_shortcuts) &&
644
 
      g_strcmp0 (DesktopFile (), """"))
 
641
  if (!DBUSMENU_IS_MENUITEM(_menu_desktop_shortcuts) &&
 
642
      g_strcmp0(DesktopFile(), """"))
645
643
  {
646
 
    GKeyFile *keyfile;
647
 
    GError *error = NULL;
 
644
    GKeyFile* keyfile;
 
645
    GError* error = NULL;
648
646
 
649
647
    // check that we have the X-Ayatana-Desktop-Shortcuts flag
650
648
    // not sure if we should do this or if libindicator should shut up
651
649
    // and not report errors when it can't find the key.
652
650
    // so FIXME when ted is around
653
 
    keyfile = g_key_file_new ();
654
 
    g_key_file_load_from_file (keyfile, DesktopFile (), G_KEY_FILE_NONE, &error);
 
651
    keyfile = g_key_file_new();
 
652
    g_key_file_load_from_file(keyfile, DesktopFile(), G_KEY_FILE_NONE, &error);
655
653
 
656
654
    if (error != NULL)
657
655
    {
658
 
      g_warning ("Could not load desktop file for: %s" , DesktopFile ());
659
 
      g_error_free (error);
 
656
      g_warning("Could not load desktop file for: %s" , DesktopFile());
 
657
      g_error_free(error);
660
658
      return;
661
659
    }
662
660
 
663
 
    if (g_key_file_has_key (keyfile, G_KEY_FILE_DESKTOP_GROUP,
664
 
                            "X-Ayatana-Desktop-Shortcuts", NULL))
 
661
    if (g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP,
 
662
                           "X-Ayatana-Desktop-Shortcuts", NULL))
665
663
    {
666
 
      DbusmenuMenuitem *root = dbusmenu_menuitem_new ();
667
 
      dbusmenu_menuitem_set_root (root, TRUE);
668
 
      desktop_shortcuts = indicator_desktop_shortcuts_new (bamf_application_get_desktop_file (m_App),
669
 
                                                           "Unity");
670
 
      const gchar **nicks = indicator_desktop_shortcuts_get_nicks (desktop_shortcuts);
 
664
      DbusmenuMenuitem* root = dbusmenu_menuitem_new();
 
665
      dbusmenu_menuitem_set_root(root, TRUE);
 
666
      desktop_shortcuts = indicator_desktop_shortcuts_new(bamf_application_get_desktop_file(m_App),
 
667
                                                          "Unity");
 
668
      const gchar** nicks = indicator_desktop_shortcuts_get_nicks(desktop_shortcuts);
671
669
 
672
670
      int index = 0;
673
671
      if (nicks)
674
672
      {
675
673
        while (((gpointer*) nicks)[index])
676
674
        {
677
 
          const char* name;
678
 
          DbusmenuMenuitem *item;
679
 
          name = g_strdup (indicator_desktop_shortcuts_nick_get_name (desktop_shortcuts,
680
 
                                                                      nicks[index]));
681
 
          ShortcutData *data = g_slice_new0 (ShortcutData);
 
675
          gchar* name;
 
676
          DbusmenuMenuitem* item;
 
677
          name = indicator_desktop_shortcuts_nick_get_name(desktop_shortcuts,
 
678
                                                           nicks[index]);
 
679
          ShortcutData* data = g_slice_new0(ShortcutData);
682
680
          data->self = this;
683
 
          data->shortcuts = INDICATOR_DESKTOP_SHORTCUTS (g_object_ref (desktop_shortcuts));
684
 
          data->nick = g_strdup (nicks[index]);
 
681
          data->shortcuts = INDICATOR_DESKTOP_SHORTCUTS(g_object_ref(desktop_shortcuts));
 
682
          data->nick = g_strdup(nicks[index]);
685
683
 
686
 
          item = dbusmenu_menuitem_new ();
687
 
          dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_LABEL, name);
688
 
          dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
689
 
          dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
690
 
          g_signal_connect_data (item, "item-activated",
 
684
          item = dbusmenu_menuitem_new();
 
685
          dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, name);
 
686
          dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
 
687
          dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
 
688
          g_signal_connect_data(item, "item-activated",
691
689
                                (GCallback) shortcut_activated, (gpointer) data,
692
690
                                (GClosureNotify) shortcut_data_destroy, (GConnectFlags)0);
693
691
 
694
 
          dbusmenu_menuitem_child_append (root, item);
 
692
          dbusmenu_menuitem_child_append(root, item);
695
693
 
696
694
          index++;
697
695
 
698
 
          g_free ((void *)name);
 
696
          g_free(name);
699
697
        }
700
698
      }
701
699
 
702
700
      _menu_desktop_shortcuts = root;
703
 
      g_key_file_free (keyfile);
 
701
      g_key_file_free(keyfile);
704
702
 
705
703
    }
706
704
  }
707
705
 
708
706
}
709
707
 
710
 
void BamfLauncherIcon::OnQuit (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self)
 
708
void BamfLauncherIcon::OnQuit(DbusmenuMenuitem* item, int time, BamfLauncherIcon* self)
711
709
{
712
 
  GList *children, *l;
713
 
  BamfView *view;
 
710
  GList* children, *l;
 
711
  BamfView* view;
714
712
 
715
 
  children = bamf_view_get_children (BAMF_VIEW (self->m_App));
 
713
  children = bamf_view_get_children(BAMF_VIEW(self->m_App));
716
714
 
717
715
  for (l = children; l; l = l->next)
718
716
  {
719
 
    view = (BamfView *) l->data;
 
717
    view = (BamfView*) l->data;
720
718
 
721
 
    if (BAMF_IS_WINDOW (view))
 
719
    if (BAMF_IS_WINDOW(view))
722
720
    {
723
 
      guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
724
 
      CompWindow *window = self->m_Screen->findWindow ((Window) xid);
 
721
      guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
 
722
      CompWindow* window = self->m_Screen->findWindow((Window) xid);
725
723
 
726
724
      if (window)
727
 
        window->close (self->m_Screen->getCurrentTime ());
 
725
        window->close(self->m_Screen->getCurrentTime());
728
726
    }
729
727
  }
730
728
 
731
 
  g_list_free (children);
 
729
  g_list_free(children);
732
730
}
733
731
 
734
 
void BamfLauncherIcon::UnStick (void)
 
732
void BamfLauncherIcon::UnStick(void)
735
733
{
736
 
  BamfView *view = BAMF_VIEW (this->m_App);
737
 
  
738
 
  if (!bamf_view_is_sticky (view))
 
734
  BamfView* view = BAMF_VIEW(this->m_App);
 
735
 
 
736
  if (!bamf_view_is_sticky(view))
739
737
    return;
740
738
 
741
 
  const gchar *desktop_file = bamf_application_get_desktop_file (this->m_App);
742
 
  bamf_view_set_sticky (view, false);
743
 
  if (bamf_view_is_closed (view))
744
 
    this->Remove ();
 
739
  const gchar* desktop_file = bamf_application_get_desktop_file(this->m_App);
 
740
  bamf_view_set_sticky(view, false);
 
741
  if (bamf_view_is_closed(view))
 
742
    this->Remove();
745
743
 
746
 
  if (desktop_file && strlen (desktop_file) > 0)
 
744
  if (desktop_file && strlen(desktop_file) > 0)
747
745
    FavoriteStore::GetDefault().RemoveFavorite(desktop_file);
748
746
}
749
747
 
750
 
void BamfLauncherIcon::OnTogglePin (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self)
 
748
void BamfLauncherIcon::OnTogglePin(DbusmenuMenuitem* item, int time, BamfLauncherIcon* self)
751
749
{
752
 
  BamfView *view = BAMF_VIEW (self->m_App);
753
 
  bool sticky = bamf_view_is_sticky (view);
754
 
  const gchar *desktop_file = bamf_application_get_desktop_file (self->m_App);
 
750
  BamfView* view = BAMF_VIEW(self->m_App);
 
751
  bool sticky = bamf_view_is_sticky(view);
 
752
  const gchar* desktop_file = bamf_application_get_desktop_file(self->m_App);
755
753
 
756
754
  if (sticky)
757
755
  {
758
 
    self->UnStick ();
 
756
    self->UnStick();
759
757
  }
760
758
  else
761
759
  {
762
 
    bamf_view_set_sticky (view, true);
 
760
    bamf_view_set_sticky(view, true);
763
761
 
764
 
    if (desktop_file && strlen (desktop_file) > 0)
 
762
    if (desktop_file && strlen(desktop_file) > 0)
765
763
      FavoriteStore::GetDefault().AddFavorite(desktop_file, -1);
766
764
  }
767
765
}
768
766
 
769
 
void BamfLauncherIcon::EnsureMenuItemsReady ()
 
767
void BamfLauncherIcon::EnsureMenuItemsReady()
770
768
{
771
 
  DbusmenuMenuitem *menu_item;
 
769
  DbusmenuMenuitem* menu_item;
772
770
 
773
771
  /* Pin */
774
 
  if (_menu_items.find ("Pin") == _menu_items.end ())
 
772
  if (_menu_items.find("Pin") == _menu_items.end())
775
773
  {
776
 
    menu_item = dbusmenu_menuitem_new ();
777
 
    g_object_ref (menu_item);
778
 
 
779
 
    dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK);
780
 
    dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Keep in launcher"));
781
 
    dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
782
 
    dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
783
 
 
784
 
    _menu_callbacks["Pin"] = g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnTogglePin, this);
 
774
    menu_item = dbusmenu_menuitem_new();
 
775
    g_object_ref(menu_item);
 
776
 
 
777
    dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK);
 
778
    dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Keep in launcher"));
 
779
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
 
780
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
 
781
 
 
782
    _menu_callbacks["Pin"] = g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnTogglePin, this);
785
783
 
786
784
    _menu_items["Pin"] = menu_item;
787
785
  }
788
 
  int checked = !bamf_view_is_sticky (BAMF_VIEW (m_App)) ?
789
 
                 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED;
 
786
  int checked = !bamf_view_is_sticky(BAMF_VIEW(m_App)) ?
 
787
                DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED;
790
788
 
791
 
  dbusmenu_menuitem_property_set_int (_menu_items["Pin"],
792
 
                                      DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
793
 
                                      checked);
 
789
  dbusmenu_menuitem_property_set_int(_menu_items["Pin"],
 
790
                                     DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
 
791
                                     checked);
794
792
 
795
793
 
796
794
  /* Quit */
797
 
  if (_menu_items.find ("Quit") == _menu_items.end ())
 
795
  if (_menu_items.find("Quit") == _menu_items.end())
798
796
  {
799
 
    menu_item = dbusmenu_menuitem_new ();
800
 
    g_object_ref (menu_item);
801
 
 
802
 
    dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Quit"));
803
 
    dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
804
 
    dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
805
 
 
806
 
    _menu_callbacks["Quit"] = g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnQuit, this);
 
797
    menu_item = dbusmenu_menuitem_new();
 
798
    g_object_ref(menu_item);
 
799
 
 
800
    dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Quit"));
 
801
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
 
802
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
 
803
 
 
804
    _menu_callbacks["Quit"] = g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnQuit, this);
807
805
 
808
806
    _menu_items["Quit"] = menu_item;
809
807
  }
810
808
}
811
809
 
812
 
static void OnAppLabelActivated (DbusmenuMenuitem* sender,
813
 
                                 guint             timestamp,
814
 
                                 gpointer data)
 
810
static void OnAppLabelActivated(DbusmenuMenuitem* sender,
 
811
                                guint             timestamp,
 
812
                                gpointer data)
815
813
{
816
814
  BamfLauncherIcon* self = NULL;
817
815
 
818
816
  if (!data)
819
817
    return;
820
 
    
 
818
 
821
819
  self = (BamfLauncherIcon*) data;
822
 
  self->ActivateLauncherIcon ();
 
820
  self->ActivateLauncherIcon(ActionArg(ActionArg::OTHER, 0));
823
821
}
824
822
 
825
 
std::list<DbusmenuMenuitem *> BamfLauncherIcon::GetMenus ()
 
823
std::list<DbusmenuMenuitem*> BamfLauncherIcon::GetMenus()
826
824
{
827
 
  std::map<std::string, DbusmenuClient *>::iterator it;
828
 
  std::list<DbusmenuMenuitem *> result;
 
825
  std::map<std::string, DbusmenuClient*>::iterator it;
 
826
  std::list<DbusmenuMenuitem*> result;
829
827
  bool first_separator_needed = false;
830
828
  DbusmenuMenuitem* item = NULL;
831
 
  
 
829
 
832
830
  // FIXME for O: hack around the wrong abstraction
833
 
  UpdateMenus ();
834
 
  
835
 
  for (it = _menu_clients.begin (); it != _menu_clients.end (); it++)
 
831
  UpdateMenus();
 
832
 
 
833
  for (it = _menu_clients.begin(); it != _menu_clients.end(); it++)
836
834
  {
837
 
    GList * child = NULL;
838
 
    DbusmenuClient *client = (*it).second;
839
 
    DbusmenuMenuitem *root = dbusmenu_client_get_root (client);
 
835
    GList* child = NULL;
 
836
    DbusmenuClient* client = (*it).second;
 
837
    DbusmenuMenuitem* root = dbusmenu_client_get_root(client);
840
838
 
841
839
    for (child = dbusmenu_menuitem_get_children(root); child != NULL; child = g_list_next(child))
842
840
    {
843
 
      DbusmenuMenuitem *item = (DbusmenuMenuitem *) child->data;
 
841
      DbusmenuMenuitem* item = (DbusmenuMenuitem*) child->data;
844
842
 
845
843
      if (!item)
846
844
        continue;
847
845
 
848
846
      first_separator_needed = true;
849
847
 
850
 
      result.push_back (item);
 
848
      result.push_back(item);
851
849
    }
852
850
  }
853
851
 
854
852
  // FIXME: this should totally be added as a _menu_client
855
 
  if (DBUSMENU_IS_MENUITEM (_menu_desktop_shortcuts))
 
853
  if (DBUSMENU_IS_MENUITEM(_menu_desktop_shortcuts))
856
854
  {
857
 
    GList * child = NULL;
858
 
    DbusmenuMenuitem *root = _menu_desktop_shortcuts;
 
855
    GList* child = NULL;
 
856
    DbusmenuMenuitem* root = _menu_desktop_shortcuts;
859
857
 
860
858
    for (child = dbusmenu_menuitem_get_children(root); child != NULL; child = g_list_next(child))
861
859
    {
862
 
      DbusmenuMenuitem *item = (DbusmenuMenuitem *) child->data;
 
860
      DbusmenuMenuitem* item = (DbusmenuMenuitem*) child->data;
863
861
 
864
862
      if (!item)
865
863
        continue;
866
864
 
867
865
      first_separator_needed = true;
868
866
 
869
 
      result.push_back (item);
 
867
      result.push_back(item);
870
868
    }
871
869
  }
872
870
 
873
871
  if (first_separator_needed)
874
872
  {
875
 
    item = dbusmenu_menuitem_new ();
876
 
    dbusmenu_menuitem_property_set (item,
877
 
                                    DBUSMENU_MENUITEM_PROP_TYPE,
878
 
                                    DBUSMENU_CLIENT_TYPES_SEPARATOR);
879
 
    result.push_back (item);
 
873
    item = dbusmenu_menuitem_new();
 
874
    dbusmenu_menuitem_property_set(item,
 
875
                                   DBUSMENU_MENUITEM_PROP_TYPE,
 
876
                                   DBUSMENU_CLIENT_TYPES_SEPARATOR);
 
877
    result.push_back(item);
880
878
  }
881
879
 
882
 
  gchar *app_name;
883
 
  app_name = g_markup_escape_text (BamfName (), -1);
884
 
 
885
 
  item = dbusmenu_menuitem_new ();
886
 
  dbusmenu_menuitem_property_set (item,
887
 
                                  DBUSMENU_MENUITEM_PROP_LABEL,
888
 
                                  app_name);
889
 
  dbusmenu_menuitem_property_set_bool (item,
890
 
                                       DBUSMENU_MENUITEM_PROP_ENABLED,
891
 
                                       true);
892
 
  g_signal_connect (item, "item-activated", (GCallback) OnAppLabelActivated, this);
893
 
  result.push_back (item);
894
 
  g_free (app_name);
895
 
 
896
 
  item = dbusmenu_menuitem_new ();
897
 
  dbusmenu_menuitem_property_set (item,
898
 
                                  DBUSMENU_MENUITEM_PROP_TYPE,
899
 
                                  DBUSMENU_CLIENT_TYPES_SEPARATOR);
900
 
  result.push_back (item);
901
 
 
902
 
  EnsureMenuItemsReady ();
903
 
 
904
 
  std::map<std::string, DbusmenuMenuitem *>::iterator it_m;
905
 
  std::list<DbusmenuMenuitem *>::iterator it_l;
 
880
  gchar* app_name;
 
881
  app_name = g_markup_escape_text(BamfName(), -1);
 
882
 
 
883
  item = dbusmenu_menuitem_new();
 
884
  dbusmenu_menuitem_property_set(item,
 
885
                                 DBUSMENU_MENUITEM_PROP_LABEL,
 
886
                                 app_name);
 
887
  dbusmenu_menuitem_property_set_bool(item,
 
888
                                      DBUSMENU_MENUITEM_PROP_ENABLED,
 
889
                                      true);
 
890
  g_signal_connect(item, "item-activated", (GCallback) OnAppLabelActivated, this);
 
891
  result.push_back(item);
 
892
  g_free(app_name);
 
893
 
 
894
  item = dbusmenu_menuitem_new();
 
895
  dbusmenu_menuitem_property_set(item,
 
896
                                 DBUSMENU_MENUITEM_PROP_TYPE,
 
897
                                 DBUSMENU_CLIENT_TYPES_SEPARATOR);
 
898
  result.push_back(item);
 
899
 
 
900
  EnsureMenuItemsReady();
 
901
 
 
902
  std::map<std::string, DbusmenuMenuitem*>::iterator it_m;
 
903
  std::list<DbusmenuMenuitem*>::iterator it_l;
906
904
  bool exists;
907
 
  for (it_m = _menu_items.begin (); it_m != _menu_items.end (); it_m++)
 
905
  for (it_m = _menu_items.begin(); it_m != _menu_items.end(); it_m++)
908
906
  {
909
907
    const char* key = ((*it_m).first).c_str();
910
 
    if (g_strcmp0 (key , "Quit") == 0 && !bamf_view_is_running (BAMF_VIEW (m_App)))
 
908
    if (g_strcmp0(key , "Quit") == 0 && !bamf_view_is_running(BAMF_VIEW(m_App)))
911
909
      continue;
912
910
 
913
911
    exists = false;
914
 
    std::string label_default = dbusmenu_menuitem_property_get ((*it_m).second, DBUSMENU_MENUITEM_PROP_LABEL);
915
 
    for(it_l = result.begin(); it_l != result.end(); it_l++)
 
912
    std::string label_default = dbusmenu_menuitem_property_get((*it_m).second, DBUSMENU_MENUITEM_PROP_LABEL);
 
913
    for (it_l = result.begin(); it_l != result.end(); it_l++)
916
914
    {
917
 
      const gchar* type = dbusmenu_menuitem_property_get (*it_l, DBUSMENU_MENUITEM_PROP_TYPE);
 
915
      const gchar* type = dbusmenu_menuitem_property_get(*it_l, DBUSMENU_MENUITEM_PROP_TYPE);
918
916
      if (type == NULL)//(g_strcmp0 (type, DBUSMENU_MENUITEM_PROP_LABEL) == 0)
919
917
      {
920
 
        std::string label_menu = dbusmenu_menuitem_property_get (*it_l, DBUSMENU_MENUITEM_PROP_LABEL);
 
918
        std::string label_menu = dbusmenu_menuitem_property_get(*it_l, DBUSMENU_MENUITEM_PROP_LABEL);
921
919
        if (label_menu.compare(label_default) == 0)
922
920
        {
923
921
          exists = true;
934
932
}
935
933
 
936
934
 
937
 
void BamfLauncherIcon::UpdateIconGeometries (nux::Point3 center)
 
935
void BamfLauncherIcon::UpdateIconGeometries(nux::Point3 center)
938
936
{
939
 
  GList *children, *l;
940
 
  BamfView *view;
 
937
  GList* children, *l;
 
938
  BamfView* view;
941
939
  long data[4];
942
940
 
943
 
  if (_launcher->Hidden () && !_launcher->ShowOnEdge ())
 
941
  if (_launcher->Hidden() && !_launcher->ShowOnEdge())
944
942
  {
945
943
    data[0] = 0;
946
944
    data[1] = 0;
953
951
  data[2] = 48;
954
952
  data[3] = 48;
955
953
 
956
 
  children = bamf_view_get_children (BAMF_VIEW (m_App));
 
954
  children = bamf_view_get_children(BAMF_VIEW(m_App));
957
955
 
958
956
  for (l = children; l; l = l->next)
959
957
  {
960
 
    view = (BamfView *) l->data;
 
958
    view = (BamfView*) l->data;
961
959
 
962
 
    if (BAMF_IS_WINDOW (view))
 
960
    if (BAMF_IS_WINDOW(view))
963
961
    {
964
 
      guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
 
962
      guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
965
963
 
966
 
      XChangeProperty (m_Screen->dpy (), xid, Atoms::wmIconGeometry,
967
 
                       XA_CARDINAL, 32, PropModeReplace,
968
 
                       (unsigned char *) data, 4);
 
964
      XChangeProperty(m_Screen->dpy(), xid, Atoms::wmIconGeometry,
 
965
                      XA_CARDINAL, 32, PropModeReplace,
 
966
                      (unsigned char*) data, 4);
969
967
    }
970
968
  }
971
969
 
972
 
  g_list_free (children);
 
970
  g_list_free(children);
973
971
}
974
972
 
975
 
void BamfLauncherIcon::OnCenterStabilized (nux::Point3 center)
 
973
void BamfLauncherIcon::OnCenterStabilized(nux::Point3 center)
976
974
{
977
 
  UpdateIconGeometries (center);
 
975
  UpdateIconGeometries(center);
978
976
}
979
977
 
980
 
const gchar* BamfLauncherIcon::GetRemoteUri ()
 
978
const gchar* BamfLauncherIcon::GetRemoteUri()
981
979
{
982
980
  if (!_remote_uri)
983
981
  {
984
 
    const gchar * desktop_file = bamf_application_get_desktop_file (BAMF_APPLICATION (m_App));
985
 
    _remote_uri = g_strdup_printf ("application://%s", g_path_get_basename (desktop_file));
 
982
    const gchar* desktop_file = bamf_application_get_desktop_file(BAMF_APPLICATION(m_App));
 
983
    gchar* basename =  g_path_get_basename(desktop_file);
 
984
 
 
985
    _remote_uri = g_strdup_printf("application://%s", basename);
 
986
 
 
987
    g_free(basename);
986
988
  }
987
 
  
 
989
 
988
990
  return _remote_uri;
989
991
}
990
992
 
991
 
std::list<char *> BamfLauncherIcon::ValidateUrisForLaunch (std::list<char *> uris)
 
993
std::list<char*> BamfLauncherIcon::ValidateUrisForLaunch(std::list<char*> uris)
992
994
{
993
 
  GKeyFile *key_file;
994
 
  const char *desktop_file;
995
 
  GError *error = NULL;
996
 
  std::list<char *> results;
997
 
  
998
 
  desktop_file = DesktopFile ();
999
 
  
1000
 
  if (!desktop_file || strlen (desktop_file) <= 1)
 
995
  GKeyFile* key_file;
 
996
  const char* desktop_file;
 
997
  GError* error = NULL;
 
998
  std::list<char*> results;
 
999
 
 
1000
  desktop_file = DesktopFile();
 
1001
 
 
1002
  if (!desktop_file || strlen(desktop_file) <= 1)
1001
1003
    return results;
1002
 
  
1003
 
  key_file = g_key_file_new ();
1004
 
  g_key_file_load_from_file (key_file, desktop_file, (GKeyFileFlags) 0, &error);
1005
 
  
 
1004
 
 
1005
  key_file = g_key_file_new();
 
1006
  g_key_file_load_from_file(key_file, desktop_file, (GKeyFileFlags) 0, &error);
 
1007
 
1006
1008
  if (error)
1007
1009
  {
1008
 
    g_error_free (error);
1009
 
    g_key_file_free (key_file);
 
1010
    g_error_free(error);
 
1011
    g_key_file_free(key_file);
1010
1012
    return results;
1011
1013
  }
1012
1014
 
1013
 
  char **mimes = g_key_file_get_string_list (key_file, "Desktop Entry", "MimeType", NULL, NULL);
 
1015
  char** mimes = g_key_file_get_string_list(key_file, "Desktop Entry", "MimeType", NULL, NULL);
1014
1016
  if (!mimes)
1015
1017
  {
1016
 
    g_key_file_free (key_file);
 
1018
    g_key_file_free(key_file);
1017
1019
    return results;
1018
1020
  }
1019
 
  
1020
 
  std::list<char *>::iterator it;
1021
 
  for (it = uris.begin (); it != uris.end (); it++)
 
1021
 
 
1022
  std::list<char*>::iterator it;
 
1023
  for (it = uris.begin(); it != uris.end(); it++)
1022
1024
  {
1023
 
    GFile *file = g_file_new_for_uri (*it);
1024
 
    GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
1025
 
    const char *content_type = g_file_info_get_content_type (info);
 
1025
    GFile* file = g_file_new_for_uri(*it);
 
1026
    GFileInfo* info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
 
1027
    const char* content_type = g_file_info_get_content_type(info);
1026
1028
 
1027
1029
    int i = 0;
1028
1030
    for (; mimes[i]; i++)
1029
1031
    {
1030
 
      char *super_type = g_content_type_from_mime_type (mimes[i]);
1031
 
      if (g_content_type_is_a (content_type, super_type))
 
1032
      char* super_type = g_content_type_from_mime_type(mimes[i]);
 
1033
      if (g_content_type_is_a(content_type, super_type))
1032
1034
      {
1033
 
        results.push_back (*it);
 
1035
        results.push_back(*it);
1034
1036
        break;
1035
1037
      }
1036
 
      g_free (super_type);
 
1038
      g_free(super_type);
1037
1039
    }
1038
 
    
1039
 
    
1040
 
    g_object_unref (file);
1041
 
    g_object_unref (info);
 
1040
 
 
1041
 
 
1042
    g_object_unref(file);
 
1043
    g_object_unref(info);
1042
1044
  }
1043
 
  
1044
 
  g_strfreev (mimes);
1045
 
  g_key_file_free (key_file);
 
1045
 
 
1046
  g_strfreev(mimes);
 
1047
  g_key_file_free(key_file);
1046
1048
  return results;
1047
1049
}
1048
1050
 
1049
 
gboolean BamfLauncherIcon::OnDndHoveredTimeout (gpointer data)
 
1051
gboolean BamfLauncherIcon::OnDndHoveredTimeout(gpointer data)
1050
1052
{
1051
 
  BamfLauncherIcon *self = (BamfLauncherIcon*) data;
1052
 
  if (self->_dnd_hovered && bamf_view_is_running (BAMF_VIEW (self->m_App)))
1053
 
    self->Spread (CompAction::StateInitEdgeDnd, true);
1054
 
  
 
1053
  BamfLauncherIcon* self = (BamfLauncherIcon*) data;
 
1054
  if (self->_dnd_hovered && bamf_view_is_running(BAMF_VIEW(self->m_App)))
 
1055
    self->Spread(CompAction::StateInitEdgeDnd, true);
 
1056
 
1055
1057
  self->_dnd_hover_timer = 0;
1056
1058
  return false;
1057
1059
}
1058
1060
 
1059
 
void BamfLauncherIcon::OnDndEnter ()
 
1061
void BamfLauncherIcon::OnDndEnter()
1060
1062
{
1061
1063
  _dnd_hovered = true;
1062
 
  _dnd_hover_timer = g_timeout_add (1000, &BamfLauncherIcon::OnDndHoveredTimeout, this);
 
1064
  _dnd_hover_timer = g_timeout_add(1000, &BamfLauncherIcon::OnDndHoveredTimeout, this);
1063
1065
}
1064
1066
 
1065
 
void BamfLauncherIcon::OnDndLeave ()
 
1067
void BamfLauncherIcon::OnDndLeave()
1066
1068
{
1067
1069
  _dnd_hovered = false;
1068
 
  
 
1070
 
1069
1071
  if (_dnd_hover_timer)
1070
 
    g_source_remove (_dnd_hover_timer);
 
1072
    g_source_remove(_dnd_hover_timer);
1071
1073
  _dnd_hover_timer = 0;
1072
1074
}
1073
1075
 
1074
 
nux::DndAction BamfLauncherIcon::OnQueryAcceptDrop (std::list<char *> uris)
1075
 
{
1076
 
  return ValidateUrisForLaunch (uris).empty () ? nux::DNDACTION_NONE : nux::DNDACTION_COPY;
1077
 
}
1078
 
 
1079
 
void  BamfLauncherIcon::OnAcceptDrop (std::list<char *> uris)
1080
 
{
1081
 
  OpenInstanceWithUris (ValidateUrisForLaunch (uris));
1082
 
}
1083
 
 
1084
 
void BamfLauncherIcon::OnDesktopFileChanged (GFileMonitor        *monitor,
1085
 
                                             GFile               *file,
1086
 
                                             GFile               *other_file,
1087
 
                                             GFileMonitorEvent    event_type,
1088
 
                                             gpointer             data)
1089
 
{
1090
 
  BamfLauncherIcon *self = static_cast<BamfLauncherIcon*> (data);
1091
 
  switch (event_type) {
1092
 
  case G_FILE_MONITOR_EVENT_DELETED:
1093
 
    self->UnStick ();
1094
 
    break;
1095
 
  default:
1096
 
    break;
1097
 
  }
 
1076
nux::DndAction BamfLauncherIcon::OnQueryAcceptDrop(std::list<char*> uris)
 
1077
{
 
1078
  return ValidateUrisForLaunch(uris).empty() ? nux::DNDACTION_NONE : nux::DNDACTION_COPY;
 
1079
}
 
1080
 
 
1081
void  BamfLauncherIcon::OnAcceptDrop(std::list<char*> uris)
 
1082
{
 
1083
  OpenInstanceWithUris(ValidateUrisForLaunch(uris));
 
1084
}
 
1085
 
 
1086
void BamfLauncherIcon::OnDesktopFileChanged(GFileMonitor*        monitor,
 
1087
                                            GFile*               file,
 
1088
                                            GFile*               other_file,
 
1089
                                            GFileMonitorEvent    event_type,
 
1090
                                            gpointer             data)
 
1091
{
 
1092
  BamfLauncherIcon* self = static_cast<BamfLauncherIcon*>(data);
 
1093
  switch (event_type)
 
1094
  {
 
1095
    case G_FILE_MONITOR_EVENT_DELETED:
 
1096
      self->UnStick();
 
1097
      break;
 
1098
    default:
 
1099
      break;
 
1100
  }
 
1101
}
 
1102
 
 
1103
bool
 
1104
BamfLauncherIcon::ShowInSwitcher()
 
1105
{
 
1106
  return GetQuirk(QUIRK_RUNNING) && GetQuirk(QUIRK_VISIBLE);
 
1107
}
 
1108
 
 
1109
unsigned int
 
1110
BamfLauncherIcon::SwitcherPriority()
 
1111
{
 
1112
  GList* children, *l;
 
1113
  BamfView* view;
 
1114
  unsigned int result = 0;
 
1115
 
 
1116
  children = bamf_view_get_children(BAMF_VIEW(m_App));
 
1117
 
 
1118
  /* get the list of windows */
 
1119
  for (l = children; l; l = l->next)
 
1120
  {
 
1121
    view = (BamfView*) l->data;
 
1122
 
 
1123
    if (BAMF_IS_WINDOW(view))
 
1124
    {
 
1125
      guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
 
1126
      CompWindow* window = m_Screen->findWindow((Window) xid);
 
1127
 
 
1128
      if (window)
 
1129
        result = std::max(result, window->activeNum());
 
1130
    }
 
1131
  }
 
1132
 
 
1133
  g_list_free(children);
 
1134
  return result;
1098
1135
}