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

« back to all changes in this revision

Viewing changes to src/LauncherModel.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 "LauncherModel.h"
 
20
#include "LauncherIcon.h"
 
21
#include "Launcher.h"
 
22
 
 
23
typedef struct
 
24
{
 
25
  LauncherIcon *icon;
 
26
  LauncherModel *self;
 
27
} RemoveArg;
 
28
 
 
29
LauncherModel::LauncherModel()
 
30
{
 
31
}
 
32
 
 
33
LauncherModel::~LauncherModel()
 
34
{
 
35
}
 
36
 
 
37
void 
 
38
LauncherModel::AddIcon (LauncherIcon *icon)
 
39
{
 
40
  icon->SinkReference ();
 
41
  
 
42
  _inner.push_front (icon);
 
43
  icon_added.emit (icon);
 
44
  
 
45
  icon->remove.connect (sigc::mem_fun (this, &LauncherModel::OnIconRemove));
 
46
}
 
47
 
 
48
void
 
49
LauncherModel::RemoveIcon (LauncherIcon *icon)
 
50
{
 
51
  size_t size = _inner.size ();
 
52
  _inner.remove (icon);
 
53
  
 
54
  if (size != _inner.size ())
 
55
    icon_removed.emit (icon);
 
56
  
 
57
  icon->UnReference ();
 
58
}
 
59
 
 
60
gboolean
 
61
LauncherModel::RemoveCallback (gpointer data)
 
62
{
 
63
  RemoveArg *arg = (RemoveArg*) data;
 
64
 
 
65
  arg->self->RemoveIcon (arg->icon);
 
66
  g_free (arg);
 
67
  
 
68
  return false;
 
69
}
 
70
 
 
71
void 
 
72
LauncherModel::OnIconRemove (void *icon_pointer)
 
73
{
 
74
  RemoveArg *arg = (RemoveArg*) g_malloc0 (sizeof (RemoveArg));
 
75
  arg->icon = (LauncherIcon*) icon_pointer;
 
76
  arg->self = this;
 
77
  
 
78
  g_timeout_add (1000, &LauncherModel::RemoveCallback, arg);
 
79
}
 
80
 
 
81
void 
 
82
LauncherModel::Sort (SortFunc func)
 
83
{
 
84
  _inner.sort (func);
 
85
}
 
86
 
 
87
int
 
88
LauncherModel::Size ()
 
89
{
 
90
  return _inner.size ();
 
91
}
 
92
    
 
93
LauncherModel::iterator 
 
94
LauncherModel::begin ()
 
95
{
 
96
  return _inner.begin ();
 
97
}
 
98
 
 
99
LauncherModel::iterator 
 
100
LauncherModel::end ()
 
101
{
 
102
  return _inner.end ();
 
103
}
 
104
 
 
105
LauncherModel::reverse_iterator 
 
106
LauncherModel::rbegin ()
 
107
{
 
108
  return _inner.rbegin ();
 
109
}
 
110
 
 
111
LauncherModel::reverse_iterator 
 
112
LauncherModel::rend ()
 
113
{
 
114
  return _inner.rend ();
 
115
}