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));
140
SetTooltipText (BamfName ());
141
SetIconName (icon_name);
142
SetIconType (TYPE_APPLICATION);
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));
142
tooltip_text = BamfName();
143
SetIconName(icon_name);
144
SetIconType(TYPE_APPLICATION);
146
if (bamf_view_is_sticky(BAMF_VIEW(m_App)))
147
SetQuirk(QUIRK_VISIBLE, true);
147
SetQuirk (QUIRK_VISIBLE, bamf_view_user_visible (BAMF_VIEW (m_App)));
149
SetQuirk (QUIRK_ACTIVE, bamf_view_is_active (BAMF_VIEW (m_App)));
150
SetQuirk (QUIRK_RUNNING, bamf_view_is_running (BAMF_VIEW (m_App)));
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);
162
g_object_ref (m_App);
164
EnsureWindowState ();
149
SetQuirk(QUIRK_VISIBLE, bamf_view_user_visible(BAMF_VIEW(m_App)));
151
SetQuirk(QUIRK_ACTIVE, bamf_view_is_active(BAMF_VIEW(m_App)));
152
SetQuirk(QUIRK_RUNNING, bamf_view_is_running(BAMF_VIEW(m_App)));
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);
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,
174
_on_desktop_file_changed_handler_id = g_signal_connect (_desktop_file_monitor,
176
G_CALLBACK (&BamfLauncherIcon::OnDesktopFileChanged),
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,
176
_on_desktop_file_changed_handler_id = g_signal_connect(_desktop_file_monitor,
178
G_CALLBACK(&BamfLauncherIcon::OnDesktopFileChanged),
181
PluginAdapter::Default()->window_minimized.connect(sigc::mem_fun(this, &BamfLauncherIcon::OnWindowMinimized));
182
IconManager->hidden_changed.connect(sigc::mem_fun(this, &BamfLauncherIcon::OnLauncherHiddenChanged));
187
189
BamfLauncherIcon::~BamfLauncherIcon()
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));
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())
196
g_signal_handler_disconnect((gpointer) _menu_items["Pin"],
197
_menu_callbacks["Pin"]);
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())
202
g_signal_handler_disconnect((gpointer) _menu_items["Quit"],
203
_menu_callbacks["Quit"]);
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);
206
if (_on_window_minimized_connection.connected ())
207
_on_window_minimized_connection.disconnect ();
209
if (_hidden_changed_connection.connected ())
210
_hidden_changed_connection.disconnect ();
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);
220
g_object_unref (m_App);
221
g_object_unref (_desktop_file_monitor);
223
g_free (_cached_desktop_file);
224
g_free (_cached_name);
227
void BamfLauncherIcon::OnLauncherHiddenChanged ()
229
UpdateIconGeometries (GetCenter ());
232
void BamfLauncherIcon::OnWindowMinimized (guint32 xid)
234
if (!OwnsWindow (xid))
207
g_signal_handler_disconnect((gpointer) _desktop_file_monitor,
208
_on_desktop_file_changed_handler_id);
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);
218
g_object_unref(m_App);
219
g_object_unref(_desktop_file_monitor);
221
g_free(_cached_desktop_file);
222
g_free(_cached_name);
225
void BamfLauncherIcon::OnLauncherHiddenChanged()
227
UpdateIconGeometries(GetCenter());
230
void BamfLauncherIcon::OnWindowMinimized(guint32 xid)
232
if (!OwnsWindow(xid))
238
UpdateQuirkTimeDelayed (300, QUIRK_SHIMMER);
241
bool BamfLauncherIcon::IsSticky ()
243
return bamf_view_is_sticky (BAMF_VIEW (m_App));
246
const char* BamfLauncherIcon::DesktopFile ()
248
char *filename = NULL;
249
filename = (char*) bamf_application_get_desktop_file (m_App);
236
UpdateQuirkTimeDelayed(300, QUIRK_SHIMMER);
239
bool BamfLauncherIcon::IsSticky()
241
return bamf_view_is_sticky(BAMF_VIEW(m_App));
244
const char* BamfLauncherIcon::DesktopFile()
246
char* filename = NULL;
247
filename = (char*) bamf_application_get_desktop_file(m_App);
251
249
if (filename != NULL)
253
251
if (_cached_desktop_file != NULL)
254
g_free (_cached_desktop_file);
256
_cached_desktop_file = g_strdup (filename);
252
g_free(_cached_desktop_file);
254
_cached_desktop_file = g_strdup(filename);
259
257
return _cached_desktop_file;
262
const char* BamfLauncherIcon::BamfName ()
260
const char* BamfLauncherIcon::BamfName()
265
name = (char *)bamf_view_get_name (BAMF_VIEW (m_App));
269
if (_cached_name != NULL)
270
g_free (_cached_name);
272
_cached_name = g_strdup (name);
262
const char* name = NULL;
263
name = bamf_view_get_name(BAMF_VIEW(m_App));
268
if (_cached_name != NULL)
269
g_free(_cached_name);
271
_cached_name = g_strdup(name);
275
273
return _cached_name;
278
void BamfLauncherIcon::AddProperties (GVariantBuilder *builder)
276
void BamfLauncherIcon::AddProperties(GVariantBuilder* builder)
280
LauncherIcon::AddProperties (builder);
282
g_variant_builder_add (builder, "{sv}", "desktop-file", g_variant_new_string (bamf_application_get_desktop_file (m_App)));
287
children = bamf_view_get_children (BAMF_VIEW (m_App));
288
GVariant* xids[(int) g_list_length (children)];
278
LauncherIcon::AddProperties(builder);
280
g_variant_builder_add(builder, "{sv}", "desktop-file", g_variant_new_string(bamf_application_get_desktop_file(m_App)));
285
children = bamf_view_get_children(BAMF_VIEW(m_App));
286
GVariant* xids[(int) g_list_length(children)];
291
289
for (l = children; l; l = l->next)
293
view = (BamfView *) l->data;
291
view = (BamfView*) l->data;
295
if (BAMF_IS_WINDOW (view))
293
if (BAMF_IS_WINDOW(view))
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)));
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));
304
bool BamfLauncherIcon::OwnsWindow (Window w)
302
bool BamfLauncherIcon::OwnsWindow(Window w)
308
306
bool owns = false;
310
children = bamf_view_get_children (BAMF_VIEW (m_App));
308
children = bamf_view_get_children(BAMF_VIEW(m_App));
312
310
for (l = children; l; l = l->next)
314
view = (BamfView *) l->data;
312
view = (BamfView*) l->data;
316
if (BAMF_IS_WINDOW (view))
314
if (BAMF_IS_WINDOW(view))
318
guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
316
guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
328
g_list_free (children);
326
g_list_free(children);
332
void BamfLauncherIcon::OpenInstanceWithUris (std::list<char *> uris)
330
void BamfLauncherIcon::OpenInstanceWithUris(std::list<char*> uris)
334
GDesktopAppInfo *appInfo;
335
GError *error = NULL;
336
std::list<char *>::iterator it;
338
appInfo = g_desktop_app_info_new_from_filename (bamf_application_get_desktop_file (BAMF_APPLICATION (m_App)));
340
if (g_app_info_supports_uris (G_APP_INFO (appInfo)))
332
GDesktopAppInfo* appInfo;
333
GError* error = NULL;
334
std::list<char*>::iterator it;
336
appInfo = g_desktop_app_info_new_from_filename(bamf_application_get_desktop_file(BAMF_APPLICATION(m_App)));
338
if (g_app_info_supports_uris(G_APP_INFO(appInfo)))
344
for (it = uris.begin (); it != uris.end (); it++)
345
list = g_list_prepend (list, *it);
347
g_app_info_launch_uris (G_APP_INFO (appInfo), list, NULL, &error);
342
for (it = uris.begin(); it != uris.end(); it++)
343
list = g_list_prepend(list, *it);
345
g_app_info_launch_uris(G_APP_INFO(appInfo), list, NULL, &error);
350
else if (g_app_info_supports_files (G_APP_INFO (appInfo)))
348
else if (g_app_info_supports_files(G_APP_INFO(appInfo)))
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++)
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);
358
g_app_info_launch (G_APP_INFO (appInfo), list, NULL, &error);
356
g_app_info_launch(G_APP_INFO(appInfo), list, NULL, &error);
360
358
for (l = list; l; l = l->next)
361
g_object_unref (G_FILE (list->data));
359
g_object_unref(G_FILE(list->data));
367
g_app_info_launch (G_APP_INFO (appInfo), NULL, NULL, &error);
365
g_app_info_launch(G_APP_INFO(appInfo), NULL, NULL, &error);
370
g_object_unref (appInfo);
368
g_object_unref(appInfo);
374
g_warning ("%s\n", error->message);
375
g_error_free (error);
372
g_warning("%s\n", error->message);
378
UpdateQuirkTime (QUIRK_STARTING);
381
void BamfLauncherIcon::OpenInstanceLauncherIcon ()
383
std::list<char *> empty;
384
OpenInstanceWithUris (empty);
385
ubus_server_send_message (ubus_server_get_default (), UBUS_LAUNCHER_ACTION_DONE, NULL);
388
void BamfLauncherIcon::Focus ()
376
UpdateQuirkTime(QUIRK_STARTING);
379
void BamfLauncherIcon::OpenInstanceLauncherIcon()
381
std::list<char*> empty;
382
OpenInstanceWithUris(empty);
383
ubus_server_send_message(ubus_server_get_default(), UBUS_LAUNCHER_ACTION_DONE, NULL);
386
void BamfLauncherIcon::Focus()
392
390
bool any_urgent = false;
393
391
bool any_on_current = false;
395
children = bamf_view_get_children (BAMF_VIEW (m_App));
393
children = bamf_view_get_children(BAMF_VIEW(m_App));
397
395
CompWindowList windows;
399
397
/* get the list of windows */
400
398
for (l = children; l; l = l->next)
402
view = (BamfView *) l->data;
400
view = (BamfView*) l->data;
404
if (BAMF_IS_WINDOW (view))
402
if (BAMF_IS_WINDOW(view))
406
guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
404
guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
408
CompWindow *window = m_Screen->findWindow ((Window) xid);
406
CompWindow* window = m_Screen->findWindow((Window) xid);
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);
419
417
// not a good sign
420
if (windows.empty ())
422
g_list_free (children);
420
g_list_free(children);
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++)
431
if (std::find (windows.begin (), windows.end (), *it) != windows.end ())
429
if (std::find(windows.begin(), windows.end(), *it) != windows.end())
436
434
/* filter based on workspace */
437
for (it = windows.begin (); it != windows.end (); it++)
435
for (it = windows.begin(); it != windows.end(); it++)
439
if ((*it)->defaultViewport () == m_Screen->vp ())
437
if ((*it)->defaultViewport() == m_Screen->vp())
441
439
any_on_current = true;
475
473
else if (any_on_current)
477
for (it = windows.begin (); it != windows.end (); it++)
475
for (it = windows.begin(); it != windows.end(); it++)
479
if ((*it)->defaultViewport () == m_Screen->vp ())
477
if ((*it)->defaultViewport() == m_Screen->vp())
487
(*(windows.rbegin ()))->activate ();
485
(*(windows.rbegin()))->activate();
490
g_list_free (children);
488
g_list_free(children);
493
bool BamfLauncherIcon::Spread (int state, bool force)
491
bool BamfLauncherIcon::Spread(int state, bool force)
497
children = bamf_view_get_children (BAMF_VIEW (m_App));
495
children = bamf_view_get_children(BAMF_VIEW(m_App));
499
497
std::list<Window> windowList;
500
498
for (l = children; l; l = l->next)
502
view = (BamfView *) l->data;
500
view = (BamfView*) l->data;
504
if (BAMF_IS_WINDOW (view))
502
if (BAMF_IS_WINDOW(view))
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);
509
507
// filter by workspace
510
if (window && window->defaultViewport () == m_Screen->vp ())
508
if (window && window->defaultViewport() == m_Screen->vp())
512
windowList.push_back ((Window) xid);
510
windowList.push_back((Window) xid);
517
if (windowList.size () > 1 || (windowList.size () > 0 && force))
515
if (windowList.size() > 1 || (windowList.size() > 0 && force))
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);
525
g_list_free (children);
530
void BamfLauncherIcon::OnClosed (BamfView *view, gpointer data)
532
BamfLauncherIcon *self = (BamfLauncherIcon *) data;
534
if (!bamf_view_is_sticky (BAMF_VIEW (self->m_App)))
538
void BamfLauncherIcon::OnUserVisibleChanged (BamfView *view, gboolean visible,
541
BamfLauncherIcon *self = (BamfLauncherIcon *) data;
543
if (!bamf_view_is_sticky (BAMF_VIEW (self->m_App)))
544
self->SetQuirk (QUIRK_VISIBLE, visible);
547
void BamfLauncherIcon::OnRunningChanged (BamfView *view, gboolean running,
550
BamfLauncherIcon *self = (BamfLauncherIcon *) data;
551
self->SetQuirk (QUIRK_RUNNING, running);
523
g_list_free(children);
528
void BamfLauncherIcon::OnClosed(BamfView* view, gpointer data)
530
BamfLauncherIcon* self = (BamfLauncherIcon*) data;
532
if (!bamf_view_is_sticky(BAMF_VIEW(self->m_App)))
536
void BamfLauncherIcon::OnUserVisibleChanged(BamfView* view, gboolean visible,
539
BamfLauncherIcon* self = (BamfLauncherIcon*) data;
541
if (!bamf_view_is_sticky(BAMF_VIEW(self->m_App)))
542
self->SetQuirk(QUIRK_VISIBLE, visible);
545
void BamfLauncherIcon::OnRunningChanged(BamfView* view, gboolean running,
548
BamfLauncherIcon* self = (BamfLauncherIcon*) data;
549
self->SetQuirk(QUIRK_RUNNING, running);
555
self->EnsureWindowState ();
556
self->UpdateIconGeometries (self->GetCenter ());
553
self->EnsureWindowState();
554
self->UpdateIconGeometries(self->GetCenter());
560
void BamfLauncherIcon::OnActiveChanged (BamfView *view, gboolean active, gpointer data)
562
BamfLauncherIcon *self = (BamfLauncherIcon *) data;
563
self->SetQuirk (QUIRK_ACTIVE, active);
566
void BamfLauncherIcon::OnUrgentChanged (BamfView *view, gboolean urgent, gpointer data)
568
BamfLauncherIcon *self = (BamfLauncherIcon *) data;
569
self->SetQuirk (QUIRK_URGENT, urgent);
572
void BamfLauncherIcon::EnsureWindowState ()
558
void BamfLauncherIcon::OnActiveChanged(BamfView* view, gboolean active, gpointer data)
560
BamfLauncherIcon* self = (BamfLauncherIcon*) data;
561
self->SetQuirk(QUIRK_ACTIVE, active);
564
void BamfLauncherIcon::OnUrgentChanged(BamfView* view, gboolean urgent, gpointer data)
566
BamfLauncherIcon* self = (BamfLauncherIcon*) data;
567
self->SetQuirk(QUIRK_URGENT, urgent);
570
void BamfLauncherIcon::EnsureWindowState()
577
575
bool has_visible = false;
579
children = bamf_view_get_children (BAMF_VIEW (m_App));
577
children = bamf_view_get_children(BAMF_VIEW(m_App));
580
578
for (l = children; l; l = l->next)
582
if (!BAMF_IS_WINDOW (l->data))
580
if (!BAMF_IS_WINDOW(l->data))
587
guint32 xid = bamf_window_get_xid (BAMF_WINDOW (l->data));
588
CompWindow *window = m_Screen->findWindow ((Window) xid);
590
if (window && window->defaultViewport () == m_Screen->vp ())
585
guint32 xid = bamf_window_get_xid(BAMF_WINDOW(l->data));
586
CompWindow* window = m_Screen->findWindow((Window) xid);
588
if (window && window->defaultViewport() == m_Screen->vp())
591
589
has_visible = true;
594
SetRelatedWindows (count);
595
SetHasVisibleWindow (has_visible);
597
g_list_free (children);
600
void BamfLauncherIcon::OnChildAdded (BamfView *view, BamfView *child, gpointer data)
602
BamfLauncherIcon *self = (BamfLauncherIcon*) data;
603
self->EnsureWindowState ();
604
self->UpdateMenus ();
605
self->UpdateIconGeometries (self->GetCenter ());
608
void BamfLauncherIcon::OnChildRemoved (BamfView *view, BamfView *child, gpointer data)
610
BamfLauncherIcon *self = (BamfLauncherIcon*) data;
611
self->EnsureWindowState ();
614
void BamfLauncherIcon::UpdateMenus ()
617
IndicatorDesktopShortcuts *desktop_shortcuts;
619
children = bamf_view_get_children (BAMF_VIEW (m_App));
592
SetRelatedWindows(count);
593
SetHasWindowOnViewport(has_visible);
595
g_list_free(children);
598
void BamfLauncherIcon::OnChildAdded(BamfView* view, BamfView* child, gpointer data)
600
BamfLauncherIcon* self = (BamfLauncherIcon*) data;
601
self->EnsureWindowState();
603
self->UpdateIconGeometries(self->GetCenter());
606
void BamfLauncherIcon::OnChildRemoved(BamfView* view, BamfView* child, gpointer data)
608
BamfLauncherIcon* self = (BamfLauncherIcon*) data;
609
self->EnsureWindowState();
612
void BamfLauncherIcon::UpdateMenus()
615
IndicatorDesktopShortcuts* desktop_shortcuts;
617
children = bamf_view_get_children(BAMF_VIEW(m_App));
620
618
for (l = children; l; l = l->next)
622
if (!BAMF_IS_INDICATOR (l->data))
620
if (!BAMF_IS_INDICATOR(l->data))
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);
628
626
// we already have this
629
if (_menu_clients.find (path) != _menu_clients.end ())
627
if (_menu_clients.find(path) != _menu_clients.end())
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;
636
g_list_free (children);
634
g_list_free(children);
638
636
// add dynamic quicklist
639
637
if (_menuclient_dynamic_quicklist != NULL)
640
638
_menu_clients["dynamicquicklist"] = _menuclient_dynamic_quicklist;
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(), """"))
647
GError *error = NULL;
645
GError* error = NULL;
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);
656
654
if (error != NULL)
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());
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))
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),
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),
668
const gchar** nicks = indicator_desktop_shortcuts_get_nicks(desktop_shortcuts);
675
673
while (((gpointer*) nicks)[index])
678
DbusmenuMenuitem *item;
679
name = g_strdup (indicator_desktop_shortcuts_nick_get_name (desktop_shortcuts,
681
ShortcutData *data = g_slice_new0 (ShortcutData);
676
DbusmenuMenuitem* item;
677
name = indicator_desktop_shortcuts_nick_get_name(desktop_shortcuts,
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]);
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);
694
dbusmenu_menuitem_child_append (root, item);
692
dbusmenu_menuitem_child_append(root, item);
698
g_free ((void *)name);
702
700
_menu_desktop_shortcuts = root;
703
g_key_file_free (keyfile);
701
g_key_file_free(keyfile);
710
void BamfLauncherIcon::OnQuit (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self)
708
void BamfLauncherIcon::OnQuit(DbusmenuMenuitem* item, int time, BamfLauncherIcon* self)
715
children = bamf_view_get_children (BAMF_VIEW (self->m_App));
713
children = bamf_view_get_children(BAMF_VIEW(self->m_App));
717
715
for (l = children; l; l = l->next)
719
view = (BamfView *) l->data;
717
view = (BamfView*) l->data;
721
if (BAMF_IS_WINDOW (view))
719
if (BAMF_IS_WINDOW(view))
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);
727
window->close (self->m_Screen->getCurrentTime ());
725
window->close(self->m_Screen->getCurrentTime());
731
g_list_free (children);
729
g_list_free(children);
734
void BamfLauncherIcon::UnStick (void)
732
void BamfLauncherIcon::UnStick(void)
736
BamfView *view = BAMF_VIEW (this->m_App);
738
if (!bamf_view_is_sticky (view))
734
BamfView* view = BAMF_VIEW(this->m_App);
736
if (!bamf_view_is_sticky(view))
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))
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))
746
if (desktop_file && strlen (desktop_file) > 0)
744
if (desktop_file && strlen(desktop_file) > 0)
747
745
FavoriteStore::GetDefault().RemoveFavorite(desktop_file);
750
void BamfLauncherIcon::OnTogglePin (DbusmenuMenuitem *item, int time, BamfLauncherIcon *self)
748
void BamfLauncherIcon::OnTogglePin(DbusmenuMenuitem* item, int time, BamfLauncherIcon* self)
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);
762
bamf_view_set_sticky (view, true);
760
bamf_view_set_sticky(view, true);
764
if (desktop_file && strlen (desktop_file) > 0)
762
if (desktop_file && strlen(desktop_file) > 0)
765
763
FavoriteStore::GetDefault().AddFavorite(desktop_file, -1);
769
void BamfLauncherIcon::EnsureMenuItemsReady ()
767
void BamfLauncherIcon::EnsureMenuItemsReady()
771
DbusmenuMenuitem *menu_item;
769
DbusmenuMenuitem* menu_item;
774
if (_menu_items.find ("Pin") == _menu_items.end ())
772
if (_menu_items.find("Pin") == _menu_items.end())
776
menu_item = dbusmenu_menuitem_new ();
777
g_object_ref (menu_item);
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);
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);
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);
782
_menu_callbacks["Pin"] = g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnTogglePin, this);
786
784
_menu_items["Pin"] = menu_item;
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;
791
dbusmenu_menuitem_property_set_int (_menu_items["Pin"],
792
DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
789
dbusmenu_menuitem_property_set_int(_menu_items["Pin"],
790
DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
797
if (_menu_items.find ("Quit") == _menu_items.end ())
795
if (_menu_items.find("Quit") == _menu_items.end())
799
menu_item = dbusmenu_menuitem_new ();
800
g_object_ref (menu_item);
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);
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);
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);
804
_menu_callbacks["Quit"] = g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, (GCallback) &BamfLauncherIcon::OnQuit, this);
808
806
_menu_items["Quit"] = menu_item;
812
static void OnAppLabelActivated (DbusmenuMenuitem* sender,
810
static void OnAppLabelActivated(DbusmenuMenuitem* sender,
816
814
BamfLauncherIcon* self = NULL;
821
819
self = (BamfLauncherIcon*) data;
822
self->ActivateLauncherIcon ();
820
self->ActivateLauncherIcon(ActionArg(ActionArg::OTHER, 0));
825
std::list<DbusmenuMenuitem *> BamfLauncherIcon::GetMenus ()
823
std::list<DbusmenuMenuitem*> BamfLauncherIcon::GetMenus()
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;
832
830
// FIXME for O: hack around the wrong abstraction
835
for (it = _menu_clients.begin (); it != _menu_clients.end (); it++)
833
for (it = _menu_clients.begin(); it != _menu_clients.end(); it++)
837
GList * child = NULL;
838
DbusmenuClient *client = (*it).second;
839
DbusmenuMenuitem *root = dbusmenu_client_get_root (client);
836
DbusmenuClient* client = (*it).second;
837
DbusmenuMenuitem* root = dbusmenu_client_get_root(client);
841
839
for (child = dbusmenu_menuitem_get_children(root); child != NULL; child = g_list_next(child))
843
DbusmenuMenuitem *item = (DbusmenuMenuitem *) child->data;
841
DbusmenuMenuitem* item = (DbusmenuMenuitem*) child->data;
848
846
first_separator_needed = true;
850
result.push_back (item);
848
result.push_back(item);
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))
857
GList * child = NULL;
858
DbusmenuMenuitem *root = _menu_desktop_shortcuts;
856
DbusmenuMenuitem* root = _menu_desktop_shortcuts;
860
858
for (child = dbusmenu_menuitem_get_children(root); child != NULL; child = g_list_next(child))
862
DbusmenuMenuitem *item = (DbusmenuMenuitem *) child->data;
860
DbusmenuMenuitem* item = (DbusmenuMenuitem*) child->data;
867
865
first_separator_needed = true;
869
result.push_back (item);
867
result.push_back(item);
873
871
if (first_separator_needed)
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);
883
app_name = g_markup_escape_text (BamfName (), -1);
885
item = dbusmenu_menuitem_new ();
886
dbusmenu_menuitem_property_set (item,
887
DBUSMENU_MENUITEM_PROP_LABEL,
889
dbusmenu_menuitem_property_set_bool (item,
890
DBUSMENU_MENUITEM_PROP_ENABLED,
892
g_signal_connect (item, "item-activated", (GCallback) OnAppLabelActivated, this);
893
result.push_back (item);
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);
902
EnsureMenuItemsReady ();
904
std::map<std::string, DbusmenuMenuitem *>::iterator it_m;
905
std::list<DbusmenuMenuitem *>::iterator it_l;
881
app_name = g_markup_escape_text(BamfName(), -1);
883
item = dbusmenu_menuitem_new();
884
dbusmenu_menuitem_property_set(item,
885
DBUSMENU_MENUITEM_PROP_LABEL,
887
dbusmenu_menuitem_property_set_bool(item,
888
DBUSMENU_MENUITEM_PROP_ENABLED,
890
g_signal_connect(item, "item-activated", (GCallback) OnAppLabelActivated, this);
891
result.push_back(item);
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);
900
EnsureMenuItemsReady();
902
std::map<std::string, DbusmenuMenuitem*>::iterator it_m;
903
std::list<DbusmenuMenuitem*>::iterator it_l;
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++)
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)))
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++)
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)
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)
956
children = bamf_view_get_children (BAMF_VIEW (m_App));
954
children = bamf_view_get_children(BAMF_VIEW(m_App));
958
956
for (l = children; l; l = l->next)
960
view = (BamfView *) l->data;
958
view = (BamfView*) l->data;
962
if (BAMF_IS_WINDOW (view))
960
if (BAMF_IS_WINDOW(view))
964
guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
962
guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
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);
972
g_list_free (children);
970
g_list_free(children);
975
void BamfLauncherIcon::OnCenterStabilized (nux::Point3 center)
973
void BamfLauncherIcon::OnCenterStabilized(nux::Point3 center)
977
UpdateIconGeometries (center);
975
UpdateIconGeometries(center);
980
const gchar* BamfLauncherIcon::GetRemoteUri ()
978
const gchar* BamfLauncherIcon::GetRemoteUri()
982
980
if (!_remote_uri)
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);
985
_remote_uri = g_strdup_printf("application://%s", basename);
988
990
return _remote_uri;
991
std::list<char *> BamfLauncherIcon::ValidateUrisForLaunch (std::list<char *> uris)
993
std::list<char*> BamfLauncherIcon::ValidateUrisForLaunch(std::list<char*> uris)
994
const char *desktop_file;
995
GError *error = NULL;
996
std::list<char *> results;
998
desktop_file = DesktopFile ();
1000
if (!desktop_file || strlen (desktop_file) <= 1)
996
const char* desktop_file;
997
GError* error = NULL;
998
std::list<char*> results;
1000
desktop_file = DesktopFile();
1002
if (!desktop_file || strlen(desktop_file) <= 1)
1001
1003
return results;
1003
key_file = g_key_file_new ();
1004
g_key_file_load_from_file (key_file, desktop_file, (GKeyFileFlags) 0, &error);
1005
key_file = g_key_file_new();
1006
g_key_file_load_from_file(key_file, desktop_file, (GKeyFileFlags) 0, &error);
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;
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);
1016
g_key_file_free (key_file);
1018
g_key_file_free(key_file);
1017
1019
return results;
1020
std::list<char *>::iterator it;
1021
for (it = uris.begin (); it != uris.end (); it++)
1022
std::list<char*>::iterator it;
1023
for (it = uris.begin(); it != uris.end(); it++)
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);
1028
1030
for (; mimes[i]; i++)
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))
1033
results.push_back (*it);
1035
results.push_back(*it);
1036
g_free (super_type);
1040
g_object_unref (file);
1041
g_object_unref (info);
1042
g_object_unref(file);
1043
g_object_unref(info);
1045
g_key_file_free (key_file);
1047
g_key_file_free(key_file);
1046
1048
return results;
1049
gboolean BamfLauncherIcon::OnDndHoveredTimeout (gpointer data)
1051
gboolean BamfLauncherIcon::OnDndHoveredTimeout(gpointer data)
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);
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);
1055
1057
self->_dnd_hover_timer = 0;
1059
void BamfLauncherIcon::OnDndEnter ()
1061
void BamfLauncherIcon::OnDndEnter()
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);
1065
void BamfLauncherIcon::OnDndLeave ()
1067
void BamfLauncherIcon::OnDndLeave()
1067
1069
_dnd_hovered = false;
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;
1074
nux::DndAction BamfLauncherIcon::OnQueryAcceptDrop (std::list<char *> uris)
1076
return ValidateUrisForLaunch (uris).empty () ? nux::DNDACTION_NONE : nux::DNDACTION_COPY;
1079
void BamfLauncherIcon::OnAcceptDrop (std::list<char *> uris)
1081
OpenInstanceWithUris (ValidateUrisForLaunch (uris));
1084
void BamfLauncherIcon::OnDesktopFileChanged (GFileMonitor *monitor,
1087
GFileMonitorEvent event_type,
1090
BamfLauncherIcon *self = static_cast<BamfLauncherIcon*> (data);
1091
switch (event_type) {
1092
case G_FILE_MONITOR_EVENT_DELETED:
1076
nux::DndAction BamfLauncherIcon::OnQueryAcceptDrop(std::list<char*> uris)
1078
return ValidateUrisForLaunch(uris).empty() ? nux::DNDACTION_NONE : nux::DNDACTION_COPY;
1081
void BamfLauncherIcon::OnAcceptDrop(std::list<char*> uris)
1083
OpenInstanceWithUris(ValidateUrisForLaunch(uris));
1086
void BamfLauncherIcon::OnDesktopFileChanged(GFileMonitor* monitor,
1089
GFileMonitorEvent event_type,
1092
BamfLauncherIcon* self = static_cast<BamfLauncherIcon*>(data);
1095
case G_FILE_MONITOR_EVENT_DELETED:
1104
BamfLauncherIcon::ShowInSwitcher()
1106
return GetQuirk(QUIRK_RUNNING) && GetQuirk(QUIRK_VISIBLE);
1110
BamfLauncherIcon::SwitcherPriority()
1112
GList* children, *l;
1114
unsigned int result = 0;
1116
children = bamf_view_get_children(BAMF_VIEW(m_App));
1118
/* get the list of windows */
1119
for (l = children; l; l = l->next)
1121
view = (BamfView*) l->data;
1123
if (BAMF_IS_WINDOW(view))
1125
guint32 xid = bamf_window_get_xid(BAMF_WINDOW(view));
1126
CompWindow* window = m_Screen->findWindow((Window) xid);
1129
result = std::max(result, window->activeNum());
1133
g_list_free(children);