~didrocks/unity/launcher-bug-fix-fest

« back to all changes in this revision

Viewing changes to src/LauncherController.cpp

Import the work done so far with Compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "FavoriteStore.h"
 
3
#include "LauncherController.h"
 
4
#include "LauncherIcon.h"
 
5
#include "Launcher.h"
 
6
#include "PluginAdapter.h"
 
7
 
 
8
 
 
9
#include <Nux/Nux.h>
 
10
#include <Nux/BaseWindow.h>
 
11
 
 
12
LauncherController::LauncherController(Launcher* launcher, CompScreen *screen, nux::BaseWindow* window, NUX_FILE_LINE_DECL)
 
13
{
 
14
    m_Launcher = launcher;
 
15
    m_Window = window;
 
16
    m_Screen = screen;
 
17
    _model = new LauncherModel ();
 
18
    
 
19
    m_Launcher->SetModel (_model);
 
20
    m_FavoriteStore = FavoriteStore::GetDefault ();
 
21
  
 
22
    g_timeout_add (5000, (GSourceFunc) &LauncherController::BamfTimerCallback, this);
 
23
    InsertExpoAction ();
 
24
}
 
25
 
 
26
LauncherController::~LauncherController()
 
27
{
 
28
  m_FavoriteStore->UnReference ();
 
29
}
 
30
 
 
31
void
 
32
LauncherController::OnExpoClicked ()
 
33
{
 
34
    PluginAdapter::Default ()->InitiateExpo ();
 
35
}
 
36
 
 
37
void
 
38
LauncherController::InsertExpoAction ()
 
39
{
 
40
    SimpleLauncherIcon *expoIcon;
 
41
    expoIcon = new SimpleLauncherIcon (m_Launcher);
 
42
    
 
43
    expoIcon->SetTooltipText ("Workspace Switcher");
 
44
    expoIcon->SetIconName ("workspace-switcher");
 
45
    expoIcon->SetVisible (true);
 
46
    
 
47
    expoIcon->MouseClick.connect (sigc::mem_fun (this, &LauncherController::OnExpoClicked));
 
48
    
 
49
    RegisterIcon (expoIcon);
 
50
}
 
51
 
 
52
void
 
53
LauncherController::OnIconShow (void *sender)
 
54
{
 
55
    LauncherIcon *icon = (LauncherIcon *) sender;
 
56
    _model->AddIcon (icon);
 
57
}
 
58
 
 
59
void
 
60
LauncherController::OnIconHide (void *sender)
 
61
{
 
62
    LauncherIcon *icon = (LauncherIcon *) sender;
 
63
    _model->RemoveIcon (icon);
 
64
}
 
65
 
 
66
void
 
67
LauncherController::OnIconRemove (void *sender)
 
68
{
 
69
    LauncherIcon *icon = (LauncherIcon *) sender;
 
70
    _model->RemoveIcon (icon);
 
71
    
 
72
    m_Icons.remove (icon);
 
73
    delete icon;
 
74
}
 
75
 
 
76
void
 
77
LauncherController::RegisterIcon (LauncherIcon *icon)
 
78
{
 
79
    icon->show.connect   (sigc::mem_fun (this, &LauncherController::OnIconShow));
 
80
    icon->hide.connect   (sigc::mem_fun (this, &LauncherController::OnIconHide));
 
81
    icon->remove.connect (sigc::mem_fun (this, &LauncherController::OnIconRemove));
 
82
    
 
83
    m_Icons.push_back (icon);
 
84
    
 
85
    if (icon->Visible ())
 
86
        _model->AddIcon (icon);
 
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->m_Launcher, app, self->m_Screen);
 
113
    self->RegisterIcon (icon);
 
114
}
 
115
 
 
116
void
 
117
LauncherController::CreateFavorite (const char *file_path)
 
118
{
 
119
    BamfApplication *app;
 
120
    BamfLauncherIcon *icon;
 
121
 
 
122
    app = bamf_matcher_get_application_for_desktop_file (m_Matcher, file_path, true);
 
123
    
 
124
    if (g_object_get_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen")))
 
125
      {
 
126
        bamf_view_set_sticky (BAMF_VIEW (app), true);
 
127
        return;
 
128
      }
 
129
    
 
130
    g_object_set_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen"), GINT_TO_POINTER (1));
 
131
    
 
132
    bamf_view_set_sticky (BAMF_VIEW (app), true);
 
133
    icon = new BamfLauncherIcon (m_Launcher, app, m_Screen);
 
134
    RegisterIcon (icon);
 
135
}
 
136
 
 
137
/* private */
 
138
void
 
139
LauncherController::SetupBamf ()
 
140
{
 
141
    GList *apps, *l;
 
142
    GSList *favs, *f;
 
143
    BamfApplication *app;
 
144
    BamfLauncherIcon *icon;
 
145
    
 
146
    m_Matcher = bamf_matcher_get_default ();
 
147
    
 
148
    favs = FavoriteStore::GetDefault ()->GetFavorites ();
 
149
    
 
150
    for (f = favs; f; f = f->next)
 
151
      CreateFavorite ((const char *) f->data);
 
152
    
 
153
    apps = bamf_matcher_get_applications (m_Matcher);
 
154
    g_signal_connect (m_Matcher, "view-opened", (GCallback) &LauncherController::OnViewOpened, this);
 
155
    
 
156
    for (l = apps; l; l = l->next)
 
157
    {
 
158
        app = BAMF_APPLICATION (l->data);
 
159
        
 
160
        if (g_object_get_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen")))
 
161
          continue;
 
162
        g_object_set_qdata (G_OBJECT (app), g_quark_from_static_string ("unity-seen"), GINT_TO_POINTER (1));
 
163
        
 
164
        icon = new BamfLauncherIcon (m_Launcher, app, m_Screen);
 
165
        RegisterIcon (icon);
 
166
    }
 
167
}
 
168