~canonical-dx-team/unity/unity.fix-ql-losing-focus

« back to all changes in this revision

Viewing changes to src/LauncherController.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-11-11 18:51:08 UTC
  • mfrom: (572.1.58 unity-3.0)
  • Revision ID: neil.patel@canonical.com-20101111185108-71923a90txzvxbit
[merge] Unity 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Canonical Ltd
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Jason Smith <jason.smith@canonical.com>
 
17
 */
 
18
 
 
19
#include "FavoriteStore.h"
 
20
#include "LauncherController.h"
 
21
#include "LauncherIcon.h"
 
22
#include "Launcher.h"
 
23
#include "PluginAdapter.h"
 
24
 
 
25
 
 
26
#include <Nux/Nux.h>
 
27
#include <Nux/BaseWindow.h>
 
28
 
 
29
LauncherController::LauncherController(Launcher* launcher, CompScreen *screen, nux::BaseWindow* window, NUX_FILE_LINE_DECL)
 
30
{
 
31
    _launcher = launcher;
 
32
    _window = window;
 
33
    _screen = screen;
 
34
    _model = new LauncherModel ();
 
35
    
 
36
    _launcher->SetModel (_model);
 
37
    _favorite_store = FavoriteStore::GetDefault ();
 
38
  
 
39
    g_timeout_add (5000, (GSourceFunc) &LauncherController::BamfTimerCallback, this);
 
40
    InsertExpoAction ();
 
41
}
 
42
 
 
43
LauncherController::~LauncherController()
 
44
{
 
45
  _favorite_store->UnReference ();
 
46
}
 
47
 
 
48
void
 
49
LauncherController::OnExpoClicked (int button)
 
50
{
 
51
    PluginAdapter::Default ()->InitiateExpo ();
 
52
}
 
53
 
 
54
void
 
55
LauncherController::InsertExpoAction ()
 
56
{
 
57
    SimpleLauncherIcon *expoIcon;
 
58
    expoIcon = new SimpleLauncherIcon (_launcher);
 
59
    
 
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);
 
65
    
 
66
    expoIcon->MouseClick.connect (sigc::mem_fun (this, &LauncherController::OnExpoClicked));
 
67
    
 
68
    RegisterIcon (expoIcon);
 
69
}
 
70
 
 
71
bool
 
72
LauncherController::CompareIcons (LauncherIcon *first, LauncherIcon *second)
 
73
{
 
74
    if (first->Type () < second->Type ())
 
75
        return true;
 
76
    else if (first->Type () > second->Type ())
 
77
        return false;
 
78
    
 
79
    return first->SortPriority () < second->SortPriority ();
 
80
}
 
81
 
 
82
void
 
83
LauncherController::RegisterIcon (LauncherIcon *icon)
 
84
{
 
85
    _model->AddIcon (icon);
 
86
    _model->Sort (&LauncherController::CompareIcons);
 
87
}
 
88
 
 
89
/* static private */
 
90
bool 
 
91
LauncherController::BamfTimerCallback (void *data)
 
92
{
 
93
    LauncherController *self = (LauncherController*) data;
 
94
  
 
95
    self->SetupBamf ();
 
96
    
 
97
    return false;
 
98
}
 
99
 
 
100
/* static private */
 
101
void
 
102
LauncherController::OnViewOpened (BamfMatcher *matcher, BamfView *view, gpointer data)
 
103
{
 
104
    LauncherController *self = (LauncherController *) data;
 
105
    BamfApplication *app;
 
106
    
 
107
    if (!BAMF_IS_APPLICATION (view))
 
108
      return;
 
109
    
 
110
    app = BAMF_APPLICATION (view);
 
111
    
 
112
    BamfLauncherIcon *icon = new BamfLauncherIcon (self->_launcher, app, self->_screen);
 
113
    icon->SetIconType (LAUNCHER_ICON_TYPE_APPLICATION);
 
114
 
 
115
    self->RegisterIcon (icon);
 
116
}
 
117
 
 
118
LauncherIcon *
 
119
LauncherController::CreateFavorite (const char *file_path)
 
120
{
 
121
    BamfApplication *app;
 
122
    BamfLauncherIcon *icon;
 
123
 
 
124
    app = bamf_matcher_get_application_for_desktop_file (_matcher, file_path, true);
 
125
    
 
126
    if (g_object_get_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen")))
 
127
    {
 
128
        bamf_view_set_sticky (BAMF_VIEW (app), true);
 
129
        return 0;
 
130
    }
 
131
    
 
132
    g_object_set_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen"), GINT_TO_POINTER (1));
 
133
    
 
134
    bamf_view_set_sticky (BAMF_VIEW (app), true);
 
135
    icon = new BamfLauncherIcon (_launcher, app, _screen);
 
136
    icon->SetIconType (LAUNCHER_ICON_TYPE_FAVORITE);
 
137
    
 
138
    return icon;
 
139
}
 
140
 
 
141
/* private */
 
142
void
 
143
LauncherController::SetupBamf ()
 
144
{
 
145
    GList *apps, *l;
 
146
    GSList *favs, *f;
 
147
    BamfApplication *app;
 
148
    BamfLauncherIcon *icon;
 
149
    int priority = 0;
 
150
    
 
151
    _matcher = bamf_matcher_get_default ();
 
152
    
 
153
    favs = FavoriteStore::GetDefault ()->GetFavorites ();
 
154
    
 
155
    for (f = favs; f; f = f->next)
 
156
    {
 
157
        LauncherIcon *fav = CreateFavorite ((const char *) f->data);
 
158
        
 
159
        if (fav)
 
160
        {
 
161
            fav->SetSortPriority (priority);
 
162
            RegisterIcon (fav);
 
163
            priority++;
 
164
        }
 
165
    }
 
166
    
 
167
    priority = 0;
 
168
    
 
169
    apps = bamf_matcher_get_applications (_matcher);
 
170
    g_signal_connect (_matcher, "view-opened", (GCallback) &LauncherController::OnViewOpened, this);
 
171
    
 
172
    for (l = apps; l; l = l->next)
 
173
    {
 
174
        app = BAMF_APPLICATION (l->data);
 
175
        
 
176
        if (g_object_get_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen")))
 
177
          continue;
 
178
        g_object_set_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen"), GINT_TO_POINTER (1));
 
179
        
 
180
        icon = new BamfLauncherIcon (_launcher, app, _screen);
 
181
        icon->SetSortPriority (priority);
 
182
        RegisterIcon (icon);
 
183
        
 
184
        priority++;
 
185
    }
 
186
}
 
187