2
* Copyright (C) 2010 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Jason Smith <jason.smith@canonical.com>
19
#include "FavoriteStore.h"
20
#include "LauncherController.h"
21
#include "LauncherIcon.h"
23
#include "PluginAdapter.h"
27
#include <Nux/BaseWindow.h>
29
LauncherController::LauncherController(Launcher* launcher, CompScreen *screen, nux::BaseWindow* window, NUX_FILE_LINE_DECL)
34
_model = new LauncherModel ();
36
_launcher->SetModel (_model);
37
_favorite_store = FavoriteStore::GetDefault ();
39
g_timeout_add (5000, (GSourceFunc) &LauncherController::BamfTimerCallback, this);
43
LauncherController::~LauncherController()
45
_favorite_store->UnReference ();
49
LauncherController::OnExpoClicked (int button)
51
PluginAdapter::Default ()->InitiateExpo ();
55
LauncherController::InsertExpoAction ()
57
SimpleLauncherIcon *expoIcon;
58
expoIcon = new SimpleLauncherIcon (_launcher);
60
expoIcon->SetTooltipText ("Workspace Switcher");
61
expoIcon->SetIconName ("workspace-switcher");
62
expoIcon->SetVisible (true);
63
expoIcon->SetRunning (false);
64
expoIcon->SetIconType (LAUNCHER_ICON_TYPE_END);
66
expoIcon->MouseClick.connect (sigc::mem_fun (this, &LauncherController::OnExpoClicked));
68
RegisterIcon (expoIcon);
72
LauncherController::CompareIcons (LauncherIcon *first, LauncherIcon *second)
74
if (first->Type () < second->Type ())
76
else if (first->Type () > second->Type ())
79
return first->SortPriority () < second->SortPriority ();
83
LauncherController::RegisterIcon (LauncherIcon *icon)
85
_model->AddIcon (icon);
86
_model->Sort (&LauncherController::CompareIcons);
91
LauncherController::BamfTimerCallback (void *data)
93
LauncherController *self = (LauncherController*) data;
102
LauncherController::OnViewOpened (BamfMatcher *matcher, BamfView *view, gpointer data)
104
LauncherController *self = (LauncherController *) data;
105
BamfApplication *app;
107
if (!BAMF_IS_APPLICATION (view))
110
app = BAMF_APPLICATION (view);
112
BamfLauncherIcon *icon = new BamfLauncherIcon (self->_launcher, app, self->_screen);
113
icon->SetIconType (LAUNCHER_ICON_TYPE_APPLICATION);
115
self->RegisterIcon (icon);
119
LauncherController::CreateFavorite (const char *file_path)
121
BamfApplication *app;
122
BamfLauncherIcon *icon;
124
app = bamf_matcher_get_application_for_desktop_file (_matcher, file_path, true);
126
if (g_object_get_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen")))
128
bamf_view_set_sticky (BAMF_VIEW (app), true);
132
g_object_set_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen"), GINT_TO_POINTER (1));
134
bamf_view_set_sticky (BAMF_VIEW (app), true);
135
icon = new BamfLauncherIcon (_launcher, app, _screen);
136
icon->SetIconType (LAUNCHER_ICON_TYPE_FAVORITE);
143
LauncherController::SetupBamf ()
147
BamfApplication *app;
148
BamfLauncherIcon *icon;
151
_matcher = bamf_matcher_get_default ();
153
favs = FavoriteStore::GetDefault ()->GetFavorites ();
155
for (f = favs; f; f = f->next)
157
LauncherIcon *fav = CreateFavorite ((const char *) f->data);
161
fav->SetSortPriority (priority);
169
apps = bamf_matcher_get_applications (_matcher);
170
g_signal_connect (_matcher, "view-opened", (GCallback) &LauncherController::OnViewOpened, this);
172
for (l = apps; l; l = l->next)
174
app = BAMF_APPLICATION (l->data);
176
if (g_object_get_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen")))
178
g_object_set_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen"), GINT_TO_POINTER (1));
180
icon = new BamfLauncherIcon (_launcher, app, _screen);
181
icon->SetSortPriority (priority);