34
33
LauncherModel::~LauncherModel()
36
for (iterator it = _inner_shelf.begin (); it != _inner_shelf.end (); ++it)
37
reinterpret_cast<LauncherIcon*> (*it)->UnReference ();
38
_inner_shelf.clear ();
40
for (iterator it = _inner_main.begin (); it != _inner_main.end (); ++it)
41
reinterpret_cast<LauncherIcon*> (*it)->UnReference ();
47
bool LauncherModel::IconShouldShelf (LauncherIcon *icon)
49
return icon->Type () == LauncherIcon::TYPE_TRASH;
52
bool LauncherModel::CompareIcons (LauncherIcon *first, LauncherIcon *second)
54
if (first->Type () < second->Type ())
35
for (iterator it = _inner_shelf.begin(); it != _inner_shelf.end(); ++it)
36
reinterpret_cast<LauncherIcon*>(*it)->UnReference();
39
for (iterator it = _inner_main.begin(); it != _inner_main.end(); ++it)
40
reinterpret_cast<LauncherIcon*>(*it)->UnReference();
46
bool LauncherModel::IconShouldShelf(LauncherIcon* icon)
48
return icon->Type() == LauncherIcon::TYPE_TRASH;
51
bool LauncherModel::CompareIcons(LauncherIcon* first, LauncherIcon* second)
53
if (first->Type() < second->Type())
56
else if (first->Type () > second->Type ())
55
else if (first->Type() > second->Type())
59
return first->SortPriority () < second->SortPriority ();
58
return first->SortPriority() < second->SortPriority();
63
LauncherModel::Populate ()
62
LauncherModel::Populate()
65
64
Base copy = _inner;
72
for (it = main_begin (); it != main_end (); it++)
74
_inner.push_back (*it);
75
(*it)->SetSortPriority (i++);
78
for (it = shelf_begin (); it != shelf_end (); it++)
80
_inner.push_back (*it);
81
(*it)->SetSortPriority (i++);
84
return !std::equal (begin (), end (), copy.begin ());
71
for (it = main_begin(); it != main_end(); it++)
73
_inner.push_back(*it);
74
(*it)->SetSortPriority(i++);
77
for (it = shelf_begin(); it != shelf_end(); it++)
79
_inner.push_back(*it);
80
(*it)->SetSortPriority(i++);
83
return !std::equal(begin(), end(), copy.begin());
88
LauncherModel::AddIcon (LauncherIcon *icon)
87
LauncherModel::AddIcon(LauncherIcon* icon)
90
icon->SinkReference ();
92
if (IconShouldShelf (icon))
93
_inner_shelf.push_front (icon);
89
icon->SinkReference();
91
if (IconShouldShelf(icon))
92
_inner_shelf.push_front(icon);
95
_inner_main.push_front (icon);
99
icon_added.emit (icon);
101
if (icon->on_icon_removed_connection.connected ())
102
icon->on_icon_removed_connection.disconnect ();
103
icon->on_icon_removed_connection = (sigc::connection) icon->remove.connect (sigc::mem_fun (this, &LauncherModel::OnIconRemove));
94
_inner_main.push_front(icon);
98
icon_added.emit(icon);
100
if (icon->on_icon_removed_connection.connected())
101
icon->on_icon_removed_connection.disconnect();
102
icon->on_icon_removed_connection = icon->remove.connect(sigc::mem_fun(this, &LauncherModel::OnIconRemove));
107
LauncherModel::RemoveIcon (LauncherIcon *icon)
106
LauncherModel::RemoveIcon(LauncherIcon* icon)
111
_inner_shelf.remove (icon);
112
_inner_main.remove (icon);
114
size = _inner.size ();
115
_inner.remove (icon);
117
if (size != _inner.size ())
110
_inner_shelf.remove(icon);
111
_inner_main.remove(icon);
113
size = _inner.size();
116
if (size != _inner.size())
119
icon_removed.emit (icon);
120
icon->UnReference ();
118
icon_removed.emit(icon);
125
LauncherModel::RemoveCallback (gpointer data)
124
LauncherModel::RemoveCallback(gpointer data)
127
RemoveArg *arg = (RemoveArg*) data;
129
arg->self->RemoveIcon (arg->icon);
126
RemoveArg* arg = (RemoveArg*) data;
128
arg->self->RemoveIcon(arg->icon);
136
LauncherModel::OnIconRemove (LauncherIcon *icon)
135
LauncherModel::OnIconRemove(LauncherIcon* icon)
138
RemoveArg *arg = (RemoveArg*) g_malloc0 (sizeof (RemoveArg));
137
RemoveArg* arg = (RemoveArg*) g_malloc0(sizeof(RemoveArg));
139
138
arg->icon = icon;
140
139
arg->self = this;
142
g_timeout_add (1000, &LauncherModel::RemoveCallback, arg);
141
g_timeout_add(1000, &LauncherModel::RemoveCallback, arg);
146
LauncherModel::Sort ()
145
LauncherModel::Sort()
148
_inner_shelf.sort (&LauncherModel::CompareIcons);
149
_inner_main.sort (&LauncherModel::CompareIcons);
152
order_changed.emit ();
147
_inner_shelf.sort(&LauncherModel::CompareIcons);
148
_inner_main.sort(&LauncherModel::CompareIcons);
151
order_changed.emit();
156
LauncherModel::IconHasSister (LauncherIcon *icon)
155
LauncherModel::IconHasSister(LauncherIcon* icon)
158
iterator (LauncherModel::*begin_it)(void);
159
iterator (LauncherModel::*end_it)(void);
157
iterator(LauncherModel::*begin_it)(void);
158
iterator(LauncherModel::*end_it)(void);
162
if (IconShouldShelf (icon))
161
if (IconShouldShelf(icon))
164
163
begin_it = &LauncherModel::shelf_begin;
165
164
end_it = &LauncherModel::shelf_end;
169
168
begin_it = &LauncherModel::main_begin;
170
169
end_it = &LauncherModel::main_end;
173
for (it = (this->*begin_it) (); it != (this->*end_it) (); it++)
172
for (it = (this->*begin_it)(); it != (this->*end_it)(); it++)
175
174
if ((*it != icon)
176
&& (*it)->Type () == icon->Type ())
175
&& (*it)->Type() == icon->Type())
184
LauncherModel::ReorderBefore (LauncherIcon *icon, LauncherIcon *other, bool save)
183
LauncherModel::ReorderBefore(LauncherIcon* icon, LauncherIcon* other, bool save)
186
185
if (icon == other)
189
188
LauncherModel::iterator it;
193
for (it = begin (); it != end (); it++)
192
for (it = begin(); it != end(); it++)
195
194
if ((*it) == icon)
201
200
if ((*it) == other)
203
icon->SetSortPriority (i);
204
if (i != j && save) (*it)->SaveCenter ();
202
icon->SetSortPriority(i);
207
(*it)->SetSortPriority (i);
208
if (i != j && save) (*it)->SaveCenter ();
207
(*it)->SetSortPriority(i);
213
(*it)->SetSortPriority (i);
214
if (i != j && save) (*it)->SaveCenter ();
214
(*it)->SetSortPriority(i);
224
LauncherModel::ReorderSmart (LauncherIcon *icon, LauncherIcon *other, bool save)
226
LauncherModel::ReorderSmart(LauncherIcon* icon, LauncherIcon* other, bool save)
226
228
if (icon == other)
229
231
LauncherModel::iterator it;
233
235
bool skipped = false;
234
for (it = begin (); it != end (); it++)
236
for (it = begin(); it != end(); it++)
236
238
if ((*it) == icon)
243
245
if ((*it) == other)
247
icon->SetSortPriority (i);
248
if (i != j && save) (*it)->SaveCenter ();
249
icon->SetSortPriority(i);
252
(*it)->SetSortPriority (i);
253
if (i != j && save) (*it)->SaveCenter ();
255
(*it)->SetSortPriority(i);
258
icon->SetSortPriority (i);
259
if (i != j && save) (*it)->SaveCenter ();
262
icon->SetSortPriority(i);
265
(*it)->SetSortPriority (i);
266
if (i != j && save) (*it)->SaveCenter ();
270
(*it)->SetSortPriority(i);
276
LauncherModel::Size ()
282
LauncherModel::Size()
278
return _inner.size ();
284
return _inner.size();
283
LauncherModel::iterator
284
LauncherModel::begin ()
286
return _inner.begin ();
289
LauncherModel::iterator
290
LauncherModel::end ()
292
return _inner.end ();
295
LauncherModel::iterator
296
LauncherModel::at (int index)
289
LauncherModel::iterator
290
LauncherModel::begin()
292
return _inner.begin();
295
LauncherModel::iterator
301
LauncherModel::iterator
302
LauncherModel::at(int index)
298
304
LauncherModel::iterator it;
301
307
// start currently selected icon
302
for (it = _inner.begin (), i = 0; it != _inner.end (); it++, i++)
308
for (it = _inner.begin(), i = 0; it != _inner.end(); it++, i++)
308
314
return (LauncherModel::iterator)NULL;
311
LauncherModel::reverse_iterator
312
LauncherModel::rbegin ()
314
return _inner.rbegin ();
317
LauncherModel::reverse_iterator
318
LauncherModel::rend ()
320
return _inner.rend ();
323
LauncherModel::iterator
324
LauncherModel::main_begin ()
326
return _inner_main.begin ();
329
LauncherModel::iterator
330
LauncherModel::main_end ()
332
return _inner_main.end ();
335
LauncherModel::reverse_iterator
336
LauncherModel::main_rbegin ()
338
return _inner_main.rbegin ();
341
LauncherModel::reverse_iterator
342
LauncherModel::main_rend ()
344
return _inner_main.rend ();
347
LauncherModel::iterator
348
LauncherModel::shelf_begin ()
350
return _inner_shelf.begin ();
353
LauncherModel::iterator
354
LauncherModel::shelf_end ()
356
return _inner_shelf.end ();
359
LauncherModel::reverse_iterator
360
LauncherModel::shelf_rbegin ()
362
return _inner_shelf.rbegin ();
365
LauncherModel::reverse_iterator
366
LauncherModel::shelf_rend ()
368
return _inner_shelf.rend ();
317
LauncherModel::reverse_iterator
318
LauncherModel::rbegin()
320
return _inner.rbegin();
323
LauncherModel::reverse_iterator
324
LauncherModel::rend()
326
return _inner.rend();
329
LauncherModel::iterator
330
LauncherModel::main_begin()
332
return _inner_main.begin();
335
LauncherModel::iterator
336
LauncherModel::main_end()
338
return _inner_main.end();
341
LauncherModel::reverse_iterator
342
LauncherModel::main_rbegin()
344
return _inner_main.rbegin();
347
LauncherModel::reverse_iterator
348
LauncherModel::main_rend()
350
return _inner_main.rend();
353
LauncherModel::iterator
354
LauncherModel::shelf_begin()
356
return _inner_shelf.begin();
359
LauncherModel::iterator
360
LauncherModel::shelf_end()
362
return _inner_shelf.end();
365
LauncherModel::reverse_iterator
366
LauncherModel::shelf_rbegin()
368
return _inner_shelf.rbegin();
371
LauncherModel::reverse_iterator
372
LauncherModel::shelf_rend()
374
return _inner_shelf.rend();