Merge lp:~3v1n0/unity/keep-priority-launcher-model into lp:unity
- keep-priority-launcher-model
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Timo Jyrinki |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2660 |
Proposed branch: | lp:~3v1n0/unity/keep-priority-launcher-model |
Merge into: | lp:unity |
Diff against target: |
1314 lines (+513/-454) 7 files modified
launcher/Launcher.cpp (+2/-1) launcher/LauncherController.cpp (+1/-6) launcher/LauncherModel.cpp (+191/-202) launcher/LauncherModel.h (+19/-20) launcher/MockLauncherIcon.h (+9/-9) tests/test_launcher.cpp (+0/-4) tests/test_launcher_model.cpp (+291/-212) |
To merge this branch: | bzr merge lp:~3v1n0/unity/keep-priority-launcher-model |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andrea Azzarone (community) | Approve | ||
jenkins | continuous-integration | Pending | |
Review via email: mp+122699@code.launchpad.net |
Commit message
LauncherModel: rewrite the Reordering functions to keep the icon priority deltas
The priority of the icons added to the model was reset every time the model
was reordered; we should otherwise keep the priority deltas between icons
so that we can safely set them without be worried that a reorder would completely
reset them.
Also add IconIndex method to get the positio of a given icon.
Description of the change
The unity LauncherModel used the IconPriority value to sort icons, however it was resetting this value every time the model was reordered, and was not possible to keep the priority deltas between the icons.
I've rewritten the model functions to make them change the priority to a relative value, instead of absolute ones.
This work is preliminary to the work needed for bug #761155
Unit tests added and updated.
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
Preview Diff
1 | === modified file 'launcher/Launcher.cpp' | |||
2 | --- launcher/Launcher.cpp 2012-09-03 08:47:49 +0000 | |||
3 | +++ launcher/Launcher.cpp 2012-09-04 16:43:33 +0000 | |||
4 | @@ -1981,7 +1981,8 @@ | |||
5 | 1981 | 1981 | ||
6 | 1982 | // FIXME: nux doesn't give nux::GetEventButton (button_flags) there, relying | 1982 | // FIXME: nux doesn't give nux::GetEventButton (button_flags) there, relying |
7 | 1983 | // on an internal Launcher property then | 1983 | // on an internal Launcher property then |
9 | 1984 | if (drag_icon && _last_button_press == 1 && _model->IconHasSister(drag_icon)) | 1984 | bool can_drag = (_model->IconHasSister(drag_icon) || drag_icon->GetIconType() == AbstractLauncherIcon::IconType::DEVICE); |
10 | 1985 | if (drag_icon && _last_button_press == 1 && can_drag) | ||
11 | 1985 | { | 1986 | { |
12 | 1986 | SetActionState(ACTION_DRAG_ICON); | 1987 | SetActionState(ACTION_DRAG_ICON); |
13 | 1987 | StartIconDrag(drag_icon); | 1988 | StartIconDrag(drag_icon); |
14 | 1988 | 1989 | ||
15 | === modified file 'launcher/LauncherController.cpp' | |||
16 | --- launcher/LauncherController.cpp 2012-08-30 21:09:02 +0000 | |||
17 | +++ launcher/LauncherController.cpp 2012-09-04 16:43:33 +0000 | |||
18 | @@ -688,10 +688,6 @@ | |||
19 | 688 | GList* apps, *l; | 688 | GList* apps, *l; |
20 | 689 | BamfApplication* app; | 689 | BamfApplication* app; |
21 | 690 | 690 | ||
22 | 691 | // Sufficiently large number such that we ensure proper sorting | ||
23 | 692 | // (avoids case where first item gets tacked onto end rather than start) | ||
24 | 693 | int priority = 100; | ||
25 | 694 | |||
26 | 695 | FavoriteList const& favs = FavoriteStore::Instance().GetFavorites(); | 691 | FavoriteList const& favs = FavoriteStore::Instance().GetFavorites(); |
27 | 696 | 692 | ||
28 | 697 | for (FavoriteList::const_iterator i = favs.begin(), end = favs.end(); | 693 | for (FavoriteList::const_iterator i = favs.begin(), end = favs.end(); |
29 | @@ -701,9 +697,8 @@ | |||
30 | 701 | 697 | ||
31 | 702 | if (fav) | 698 | if (fav) |
32 | 703 | { | 699 | { |
34 | 704 | fav->SetSortPriority(priority); | 700 | fav->SetSortPriority(sort_priority_++); |
35 | 705 | RegisterIcon(fav); | 701 | RegisterIcon(fav); |
36 | 706 | priority++; | ||
37 | 707 | } | 702 | } |
38 | 708 | } | 703 | } |
39 | 709 | 704 | ||
40 | 710 | 705 | ||
41 | === modified file 'launcher/LauncherModel.cpp' | |||
42 | --- launcher/LauncherModel.cpp 2012-08-31 19:35:46 +0000 | |||
43 | +++ launcher/LauncherModel.cpp 2012-09-04 16:43:33 +0000 | |||
44 | @@ -1,6 +1,6 @@ | |||
45 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
46 | 2 | /* | 2 | /* |
48 | 3 | * Copyright (C) 2010 Canonical Ltd | 3 | * Copyright (C) 2010-2012 Canonical Ltd |
49 | 4 | * | 4 | * |
50 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
51 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
52 | @@ -15,6 +15,7 @@ | |||
53 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
54 | 16 | * | 16 | * |
55 | 17 | * Authored by: Jason Smith <jason.smith@canonical.com> | 17 | * Authored by: Jason Smith <jason.smith@canonical.com> |
56 | 18 | * Marco Trevisan <marco.trevisan@canonical.com> | ||
57 | 18 | */ | 19 | */ |
58 | 19 | 20 | ||
59 | 20 | #include "LauncherModel.h" | 21 | #include "LauncherModel.h" |
60 | @@ -30,8 +31,7 @@ | |||
61 | 30 | 31 | ||
62 | 31 | LauncherModel::LauncherModel() | 32 | LauncherModel::LauncherModel() |
63 | 32 | : selection_(0) | 33 | : selection_(0) |
66 | 33 | { | 34 | {} |
65 | 34 | } | ||
67 | 35 | 35 | ||
68 | 36 | std::string LauncherModel::GetName() const | 36 | std::string LauncherModel::GetName() const |
69 | 37 | { | 37 | { |
70 | @@ -54,12 +54,12 @@ | |||
71 | 54 | return introspection_results_; | 54 | return introspection_results_; |
72 | 55 | } | 55 | } |
73 | 56 | 56 | ||
75 | 57 | bool LauncherModel::IconShouldShelf(AbstractLauncherIcon::Ptr icon) const | 57 | bool LauncherModel::IconShouldShelf(AbstractLauncherIcon::Ptr const& icon) const |
76 | 58 | { | 58 | { |
77 | 59 | return icon->GetIconType() == AbstractLauncherIcon::IconType::TRASH; | 59 | return icon->GetIconType() == AbstractLauncherIcon::IconType::TRASH; |
78 | 60 | } | 60 | } |
79 | 61 | 61 | ||
81 | 62 | bool LauncherModel::CompareIcons(AbstractLauncherIcon::Ptr first, AbstractLauncherIcon::Ptr second) | 62 | bool LauncherModel::CompareIcons(AbstractLauncherIcon::Ptr const& first, AbstractLauncherIcon::Ptr const& second) |
82 | 63 | { | 63 | { |
83 | 64 | if (first->GetIconType() < second->GetIconType()) | 64 | if (first->GetIconType() < second->GetIconType()) |
84 | 65 | return true; | 65 | return true; |
85 | @@ -69,36 +69,43 @@ | |||
86 | 69 | return first->SortPriority() < second->SortPriority(); | 69 | return first->SortPriority() < second->SortPriority(); |
87 | 70 | } | 70 | } |
88 | 71 | 71 | ||
91 | 72 | bool | 72 | void LauncherModel::PopulatePart(iterator begin, iterator end) |
92 | 73 | LauncherModel::Populate() | 73 | { |
93 | 74 | AbstractLauncherIcon::Ptr prev_icon; | ||
94 | 75 | for (auto it = begin; it != end; ++it) | ||
95 | 76 | { | ||
96 | 77 | auto const& icon = *it; | ||
97 | 78 | _inner.push_back(icon); | ||
98 | 79 | |||
99 | 80 | if (prev_icon) | ||
100 | 81 | { | ||
101 | 82 | // Ensuring that the current icon has higher priority than previous one | ||
102 | 83 | if (icon->SortPriority() < prev_icon->SortPriority()) | ||
103 | 84 | { | ||
104 | 85 | int new_priority = prev_icon->SortPriority() + 1; | ||
105 | 86 | icon->SetSortPriority(new_priority); | ||
106 | 87 | } | ||
107 | 88 | } | ||
108 | 89 | |||
109 | 90 | prev_icon = icon; | ||
110 | 91 | } | ||
111 | 92 | } | ||
112 | 93 | |||
113 | 94 | bool LauncherModel::Populate() | ||
114 | 74 | { | 95 | { |
115 | 75 | Base copy = _inner; | 96 | Base copy = _inner; |
116 | 76 | |||
117 | 77 | _inner.clear(); | 97 | _inner.clear(); |
135 | 78 | 98 | PopulatePart(main_begin(), main_end()); | |
136 | 79 | iterator it, it2; | 99 | PopulatePart(shelf_begin(), shelf_end()); |
120 | 80 | |||
121 | 81 | int i = 0; | ||
122 | 82 | for (it = main_begin(); it != main_end(); ++it) | ||
123 | 83 | { | ||
124 | 84 | _inner.push_back(*it); | ||
125 | 85 | (*it)->SetSortPriority(i); | ||
126 | 86 | ++i; | ||
127 | 87 | } | ||
128 | 88 | |||
129 | 89 | for (it = shelf_begin(); it != shelf_end(); ++it) | ||
130 | 90 | { | ||
131 | 91 | _inner.push_back(*it); | ||
132 | 92 | (*it)->SetSortPriority(i); | ||
133 | 93 | ++i; | ||
134 | 94 | } | ||
137 | 95 | 100 | ||
138 | 96 | return copy.size() == _inner.size() && !std::equal(begin(), end(), copy.begin()); | 101 | return copy.size() == _inner.size() && !std::equal(begin(), end(), copy.begin()); |
139 | 97 | } | 102 | } |
140 | 98 | 103 | ||
143 | 99 | void | 104 | void LauncherModel::AddIcon(AbstractLauncherIcon::Ptr const& icon) |
142 | 100 | LauncherModel::AddIcon(AbstractLauncherIcon::Ptr icon) | ||
144 | 101 | { | 105 | { |
145 | 106 | if (!icon || std::find(begin(), end(), icon) != end()) | ||
146 | 107 | return; | ||
147 | 108 | |||
148 | 102 | if (IconShouldShelf(icon)) | 109 | if (IconShouldShelf(icon)) |
149 | 103 | _inner_shelf.push_back(icon); | 110 | _inner_shelf.push_back(icon); |
150 | 104 | else | 111 | else |
151 | @@ -113,8 +120,7 @@ | |||
152 | 113 | icon->on_icon_removed_connection = icon->remove.connect(sigc::mem_fun(this, &LauncherModel::OnIconRemove)); | 120 | icon->on_icon_removed_connection = icon->remove.connect(sigc::mem_fun(this, &LauncherModel::OnIconRemove)); |
153 | 114 | } | 121 | } |
154 | 115 | 122 | ||
157 | 116 | void | 123 | void LauncherModel::RemoveIcon(AbstractLauncherIcon::Ptr const& icon) |
156 | 117 | LauncherModel::RemoveIcon(AbstractLauncherIcon::Ptr icon) | ||
158 | 118 | { | 124 | { |
159 | 119 | size_t size; | 125 | size_t size; |
160 | 120 | 126 | ||
161 | @@ -130,23 +136,20 @@ | |||
162 | 130 | } | 136 | } |
163 | 131 | } | 137 | } |
164 | 132 | 138 | ||
167 | 133 | void | 139 | void LauncherModel::OnIconRemove(AbstractLauncherIcon::Ptr const& icon) |
166 | 134 | LauncherModel::OnIconRemove(AbstractLauncherIcon::Ptr icon) | ||
168 | 135 | { | 140 | { |
170 | 136 | timeouts_.AddTimeout(1000, [&, icon] { | 141 | timeouts_.AddTimeout(1000, [this, icon] { |
171 | 137 | RemoveIcon(icon); | 142 | RemoveIcon(icon); |
172 | 138 | return false; | 143 | return false; |
173 | 139 | }); | 144 | }); |
174 | 140 | } | 145 | } |
175 | 141 | 146 | ||
178 | 142 | void | 147 | void LauncherModel::Save() |
177 | 143 | LauncherModel::Save() | ||
179 | 144 | { | 148 | { |
180 | 145 | saved.emit(); | 149 | saved.emit(); |
181 | 146 | } | 150 | } |
182 | 147 | 151 | ||
185 | 148 | void | 152 | void LauncherModel::Sort() |
184 | 149 | LauncherModel::Sort() | ||
186 | 150 | { | 153 | { |
187 | 151 | std::stable_sort(_inner_shelf.begin(), _inner_shelf.end(), &LauncherModel::CompareIcons); | 154 | std::stable_sort(_inner_shelf.begin(), _inner_shelf.end(), &LauncherModel::CompareIcons); |
188 | 152 | std::stable_sort(_inner_main.begin(), _inner_main.end(), &LauncherModel::CompareIcons); | 155 | std::stable_sort(_inner_main.begin(), _inner_main.end(), &LauncherModel::CompareIcons); |
189 | @@ -155,15 +158,14 @@ | |||
190 | 155 | order_changed.emit(); | 158 | order_changed.emit(); |
191 | 156 | } | 159 | } |
192 | 157 | 160 | ||
195 | 158 | bool | 161 | bool LauncherModel::IconHasSister(AbstractLauncherIcon::Ptr const& icon) const |
194 | 159 | LauncherModel::IconHasSister(AbstractLauncherIcon::Ptr icon) const | ||
196 | 160 | { | 162 | { |
197 | 163 | if (!icon) | ||
198 | 164 | return false; | ||
199 | 165 | |||
200 | 161 | const_iterator it; | 166 | const_iterator it; |
201 | 162 | const_iterator end; | 167 | const_iterator end; |
202 | 163 | 168 | ||
203 | 164 | if (icon && icon->GetIconType() == AbstractLauncherIcon::IconType::DEVICE) | ||
204 | 165 | return true; | ||
205 | 166 | |||
206 | 167 | if (IconShouldShelf(icon)) | 169 | if (IconShouldShelf(icon)) |
207 | 168 | { | 170 | { |
208 | 169 | it = _inner_shelf.begin(); | 171 | it = _inner_shelf.begin(); |
209 | @@ -177,144 +179,125 @@ | |||
210 | 177 | 179 | ||
211 | 178 | for (; it != end; ++it) | 180 | for (; it != end; ++it) |
212 | 179 | { | 181 | { |
216 | 180 | AbstractLauncherIcon::Ptr iter_icon = *it; | 182 | AbstractLauncherIcon::Ptr const& iter_icon = *it; |
217 | 181 | if ((iter_icon != icon) | 183 | |
218 | 182 | && iter_icon->GetIconType() == icon->GetIconType()) | 184 | if (iter_icon != icon && iter_icon->GetIconType() == icon->GetIconType()) |
219 | 183 | return true; | 185 | return true; |
220 | 184 | } | 186 | } |
221 | 185 | 187 | ||
222 | 186 | return false; | 188 | return false; |
223 | 187 | } | 189 | } |
224 | 188 | 190 | ||
354 | 189 | void | 191 | void LauncherModel::ReorderAfter(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other) |
355 | 190 | LauncherModel::ReorderAfter(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other) | 192 | { |
356 | 191 | { | 193 | if (icon == other || icon.IsNull() || other.IsNull()) |
357 | 192 | if (icon == other || icon.IsNull() || other.IsNull()) | 194 | return; |
358 | 193 | return; | 195 | |
359 | 194 | 196 | if (icon->GetIconType() != other->GetIconType()) | |
360 | 195 | if (icon->GetIconType() != other->GetIconType()) | 197 | return; |
361 | 196 | return; | 198 | |
362 | 197 | 199 | icon->SetSortPriority(other->SortPriority() + 1); | |
363 | 198 | int i = 0; | 200 | |
364 | 199 | for (LauncherModel::iterator it = begin(); it != end(); ++it) | 201 | for (auto it = std::next(std::find(begin(), end(), other)); it != end(); ++it) |
365 | 200 | { | 202 | { |
366 | 201 | if ((*it) == icon) | 203 | // Increasing the priority of the icons next to the other one |
367 | 202 | continue; | 204 | auto const& icon_it = *it; |
368 | 203 | 205 | int new_priority = icon_it->SortPriority() + 1; | |
369 | 204 | if ((*it) == other) | 206 | icon_it->SetSortPriority(new_priority); |
370 | 205 | { | 207 | } |
371 | 206 | (*it)->SetSortPriority(i); | 208 | |
372 | 207 | ++i; | 209 | Sort(); |
373 | 208 | 210 | } | |
374 | 209 | icon->SetSortPriority(i); | 211 | |
375 | 210 | ++i; | 212 | void LauncherModel::ReorderBefore(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other, bool animate) |
376 | 211 | } | 213 | { |
377 | 212 | else | 214 | if (icon == other || icon.IsNull() || other.IsNull()) |
378 | 213 | { | 215 | return; |
379 | 214 | (*it)->SetSortPriority(i); | 216 | |
380 | 215 | ++i; | 217 | if (icon->GetIconType() != other->GetIconType()) |
381 | 216 | } | 218 | return; |
382 | 217 | } | 219 | |
383 | 218 | 220 | bool found_target = false; | |
384 | 219 | Sort(); | 221 | bool center = false; |
385 | 220 | } | 222 | |
386 | 221 | 223 | for (auto const& icon_it : _inner) | |
387 | 222 | void | 224 | { |
388 | 223 | LauncherModel::ReorderBefore(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save) | 225 | if (icon_it == icon) |
389 | 224 | { | 226 | { |
390 | 225 | if (icon == other || icon.IsNull() || other.IsNull()) | 227 | center = !center; |
391 | 226 | return; | 228 | continue; |
392 | 227 | 229 | } | |
393 | 228 | if (icon->GetIconType() != other->GetIconType()) | 230 | |
394 | 229 | return; | 231 | int new_priority = icon_it->SortPriority() + (found_target ? 1 : -1); |
395 | 230 | 232 | icon_it->SetSortPriority(new_priority); | |
396 | 231 | int i = 0; | 233 | |
397 | 232 | int j = 0; | 234 | if (icon_it == other) |
398 | 233 | for (auto icon_it : _inner) | 235 | { |
399 | 234 | { | 236 | if (animate && center) |
400 | 235 | if (icon_it == icon) | 237 | icon_it->SaveCenter(); |
401 | 236 | { | 238 | |
402 | 237 | j++; | 239 | center = !center; |
403 | 238 | continue; | 240 | new_priority = new_priority - 1; |
404 | 239 | } | 241 | icon->SetSortPriority(new_priority); |
405 | 240 | 242 | ||
406 | 241 | if (icon_it == other) | 243 | if (animate && center) |
407 | 242 | { | 244 | icon_it->SaveCenter(); |
408 | 243 | icon->SetSortPriority(i); | 245 | |
409 | 244 | if (i != j && save) | 246 | found_target = true; |
410 | 245 | icon_it->SaveCenter(); | 247 | } |
411 | 246 | i++; | 248 | else |
412 | 247 | 249 | { | |
413 | 248 | icon_it->SetSortPriority(i); | 250 | if (animate && center) |
414 | 249 | if (i != j && save) | 251 | icon_it->SaveCenter(); |
415 | 250 | icon_it->SaveCenter(); | 252 | } |
416 | 251 | i++; | 253 | } |
417 | 252 | } | 254 | |
418 | 253 | else | 255 | Sort(); |
419 | 254 | { | 256 | } |
420 | 255 | icon_it->SetSortPriority(i); | 257 | |
421 | 256 | if (i != j && save) | 258 | void LauncherModel::ReorderSmart(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other, bool animate) |
422 | 257 | icon_it->SaveCenter(); | 259 | { |
423 | 258 | i++; | 260 | if (icon == other || icon.IsNull() || other.IsNull()) |
424 | 259 | } | 261 | return; |
425 | 260 | j++; | 262 | |
426 | 261 | } | 263 | if (icon->GetIconType() != other->GetIconType()) |
427 | 262 | 264 | return; | |
428 | 263 | Sort(); | 265 | |
429 | 264 | } | 266 | bool found_icon = false; |
430 | 265 | 267 | bool found_target = false; | |
431 | 266 | void | 268 | bool center = false; |
432 | 267 | LauncherModel::ReorderSmart(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save) | 269 | |
433 | 268 | { | 270 | for (auto const& icon_it : _inner) |
434 | 269 | if (icon == other || icon.IsNull() || other.IsNull()) | 271 | { |
435 | 270 | return; | 272 | if (icon_it == icon) |
436 | 271 | 273 | { | |
437 | 272 | if (icon->GetIconType() != other->GetIconType()) | 274 | found_icon = true; |
438 | 273 | return; | 275 | center = !center; |
439 | 274 | 276 | continue; | |
440 | 275 | int i = 0; | 277 | } |
441 | 276 | int j = 0; | 278 | |
442 | 277 | bool skipped = false; | 279 | int new_priority = icon_it->SortPriority() + (found_target ? 1 : -1); |
443 | 278 | for (auto icon_it : _inner) | 280 | icon_it->SetSortPriority(new_priority); |
444 | 279 | { | 281 | |
445 | 280 | if (icon_it == icon) | 282 | if (icon_it == other) |
446 | 281 | { | 283 | { |
447 | 282 | skipped = true; | 284 | if (animate && center) |
448 | 283 | j++; | 285 | icon_it->SaveCenter(); |
449 | 284 | continue; | 286 | |
450 | 285 | } | 287 | center = !center; |
451 | 286 | 288 | new_priority = new_priority + (found_icon ? 1 : -1); | |
452 | 287 | if (icon_it == other) | 289 | icon->SetSortPriority(new_priority); |
453 | 288 | { | 290 | |
454 | 289 | if (!skipped) | 291 | if (animate && center) |
455 | 290 | { | 292 | icon_it->SaveCenter(); |
456 | 291 | icon->SetSortPriority(i); | 293 | |
457 | 292 | if (i != j && save) | 294 | found_target = true; |
458 | 293 | icon_it->SaveCenter(); | 295 | } |
459 | 294 | i++; | 296 | else |
460 | 295 | } | 297 | { |
461 | 296 | 298 | if (animate && center) | |
462 | 297 | icon_it->SetSortPriority(i); | 299 | icon_it->SaveCenter(); |
463 | 298 | if (i != j && save) | 300 | } |
335 | 299 | icon_it->SaveCenter(); | ||
336 | 300 | i++; | ||
337 | 301 | |||
338 | 302 | if (skipped) | ||
339 | 303 | { | ||
340 | 304 | icon->SetSortPriority(i); | ||
341 | 305 | if (i != j && save) | ||
342 | 306 | icon_it->SaveCenter(); | ||
343 | 307 | i++; | ||
344 | 308 | } | ||
345 | 309 | } | ||
346 | 310 | else | ||
347 | 311 | { | ||
348 | 312 | icon_it->SetSortPriority(i); | ||
349 | 313 | if (i != j && save) | ||
350 | 314 | icon_it->SaveCenter(); | ||
351 | 315 | i++; | ||
352 | 316 | } | ||
353 | 317 | j++; | ||
464 | 318 | } | 301 | } |
465 | 319 | 302 | ||
466 | 320 | Sort(); | 303 | Sort(); |
467 | @@ -357,7 +340,7 @@ | |||
468 | 357 | if (temp >= Size()) | 340 | if (temp >= Size()) |
469 | 358 | temp = 0; | 341 | temp = 0; |
470 | 359 | 342 | ||
472 | 360 | if (_inner[temp]->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE)) | 343 | if (_inner[temp]->IsVisible()) |
473 | 361 | { | 344 | { |
474 | 362 | selection_ = temp; | 345 | selection_ = temp; |
475 | 363 | selection_changed.emit(Selection()); | 346 | selection_changed.emit(Selection()); |
476 | @@ -377,7 +360,7 @@ | |||
477 | 377 | if (temp < 0) | 360 | if (temp < 0) |
478 | 378 | temp = Size() - 1; | 361 | temp = Size() - 1; |
479 | 379 | 362 | ||
481 | 380 | if (_inner[temp]->GetQuirk(AbstractLauncherIcon::Quirk::VISIBLE)) | 363 | if (_inner[temp]->IsVisible()) |
482 | 381 | { | 364 | { |
483 | 382 | selection_ = temp; | 365 | selection_ = temp; |
484 | 383 | selection_changed.emit(Selection()); | 366 | selection_changed.emit(Selection()); |
485 | @@ -387,7 +370,7 @@ | |||
486 | 387 | } | 370 | } |
487 | 388 | } | 371 | } |
488 | 389 | 372 | ||
490 | 390 | AbstractLauncherIcon::Ptr LauncherModel::GetClosestIcon(AbstractLauncherIcon::Ptr icon, bool& is_before) const | 373 | AbstractLauncherIcon::Ptr LauncherModel::GetClosestIcon(AbstractLauncherIcon::Ptr const& icon, bool& is_before) const |
491 | 391 | { | 374 | { |
492 | 392 | AbstractLauncherIcon::Ptr prev, next; | 375 | AbstractLauncherIcon::Ptr prev, next; |
493 | 393 | bool found_target = false; | 376 | bool found_target = false; |
494 | @@ -423,22 +406,38 @@ | |||
495 | 423 | return is_before ? prev : next; | 406 | return is_before ? prev : next; |
496 | 424 | } | 407 | } |
497 | 425 | 408 | ||
498 | 409 | int LauncherModel::IconIndex(AbstractLauncherIcon::Ptr const& target) const | ||
499 | 410 | { | ||
500 | 411 | int pos = 0; | ||
501 | 412 | bool found = false; | ||
502 | 413 | |||
503 | 414 | for (auto const& icon : _inner) | ||
504 | 415 | { | ||
505 | 416 | if (icon == target) | ||
506 | 417 | { | ||
507 | 418 | found = true; | ||
508 | 419 | break; | ||
509 | 420 | } | ||
510 | 421 | |||
511 | 422 | ++pos; | ||
512 | 423 | } | ||
513 | 424 | |||
514 | 425 | return found ? pos : -1; | ||
515 | 426 | } | ||
516 | 427 | |||
517 | 426 | /* iterators */ | 428 | /* iterators */ |
518 | 427 | 429 | ||
521 | 428 | LauncherModel::iterator | 430 | LauncherModel::iterator LauncherModel::begin() |
520 | 429 | LauncherModel::begin() | ||
522 | 430 | { | 431 | { |
523 | 431 | return _inner.begin(); | 432 | return _inner.begin(); |
524 | 432 | } | 433 | } |
525 | 433 | 434 | ||
528 | 434 | LauncherModel::iterator | 435 | LauncherModel::iterator LauncherModel::end() |
527 | 435 | LauncherModel::end() | ||
529 | 436 | { | 436 | { |
530 | 437 | return _inner.end(); | 437 | return _inner.end(); |
531 | 438 | } | 438 | } |
532 | 439 | 439 | ||
535 | 440 | LauncherModel::iterator | 440 | LauncherModel::iterator LauncherModel::at(int index) |
534 | 441 | LauncherModel::at(int index) | ||
536 | 442 | { | 441 | { |
537 | 443 | LauncherModel::iterator it; | 442 | LauncherModel::iterator it; |
538 | 444 | int i; | 443 | int i; |
539 | @@ -453,62 +452,52 @@ | |||
540 | 453 | return (LauncherModel::iterator)NULL; | 452 | return (LauncherModel::iterator)NULL; |
541 | 454 | } | 453 | } |
542 | 455 | 454 | ||
545 | 456 | LauncherModel::reverse_iterator | 455 | LauncherModel::reverse_iterator LauncherModel::rbegin() |
544 | 457 | LauncherModel::rbegin() | ||
546 | 458 | { | 456 | { |
547 | 459 | return _inner.rbegin(); | 457 | return _inner.rbegin(); |
548 | 460 | } | 458 | } |
549 | 461 | 459 | ||
552 | 462 | LauncherModel::reverse_iterator | 460 | LauncherModel::reverse_iterator LauncherModel::rend() |
551 | 463 | LauncherModel::rend() | ||
553 | 464 | { | 461 | { |
554 | 465 | return _inner.rend(); | 462 | return _inner.rend(); |
555 | 466 | } | 463 | } |
556 | 467 | 464 | ||
559 | 468 | LauncherModel::iterator | 465 | LauncherModel::iterator LauncherModel::main_begin() |
558 | 469 | LauncherModel::main_begin() | ||
560 | 470 | { | 466 | { |
561 | 471 | return _inner_main.begin(); | 467 | return _inner_main.begin(); |
562 | 472 | } | 468 | } |
563 | 473 | 469 | ||
566 | 474 | LauncherModel::iterator | 470 | LauncherModel::iterator LauncherModel::main_end() |
565 | 475 | LauncherModel::main_end() | ||
567 | 476 | { | 471 | { |
568 | 477 | return _inner_main.end(); | 472 | return _inner_main.end(); |
569 | 478 | } | 473 | } |
570 | 479 | 474 | ||
573 | 480 | LauncherModel::reverse_iterator | 475 | LauncherModel::reverse_iterator LauncherModel::main_rbegin() |
572 | 481 | LauncherModel::main_rbegin() | ||
574 | 482 | { | 476 | { |
575 | 483 | return _inner_main.rbegin(); | 477 | return _inner_main.rbegin(); |
576 | 484 | } | 478 | } |
577 | 485 | 479 | ||
580 | 486 | LauncherModel::reverse_iterator | 480 | LauncherModel::reverse_iterator LauncherModel::main_rend() |
579 | 487 | LauncherModel::main_rend() | ||
581 | 488 | { | 481 | { |
582 | 489 | return _inner_main.rend(); | 482 | return _inner_main.rend(); |
583 | 490 | } | 483 | } |
584 | 491 | 484 | ||
587 | 492 | LauncherModel::iterator | 485 | LauncherModel::iterator LauncherModel::shelf_begin() |
586 | 493 | LauncherModel::shelf_begin() | ||
588 | 494 | { | 486 | { |
589 | 495 | return _inner_shelf.begin(); | 487 | return _inner_shelf.begin(); |
590 | 496 | } | 488 | } |
591 | 497 | 489 | ||
594 | 498 | LauncherModel::iterator | 490 | LauncherModel::iterator LauncherModel::shelf_end() |
593 | 499 | LauncherModel::shelf_end() | ||
595 | 500 | { | 491 | { |
596 | 501 | return _inner_shelf.end(); | 492 | return _inner_shelf.end(); |
597 | 502 | } | 493 | } |
598 | 503 | 494 | ||
601 | 504 | LauncherModel::reverse_iterator | 495 | LauncherModel::reverse_iterator LauncherModel::shelf_rbegin() |
600 | 505 | LauncherModel::shelf_rbegin() | ||
602 | 506 | { | 496 | { |
603 | 507 | return _inner_shelf.rbegin(); | 497 | return _inner_shelf.rbegin(); |
604 | 508 | } | 498 | } |
605 | 509 | 499 | ||
608 | 510 | LauncherModel::reverse_iterator | 500 | LauncherModel::reverse_iterator LauncherModel::shelf_rend() |
607 | 511 | LauncherModel::shelf_rend() | ||
609 | 512 | { | 501 | { |
610 | 513 | return _inner_shelf.rend(); | 502 | return _inner_shelf.rend(); |
611 | 514 | } | 503 | } |
612 | 515 | 504 | ||
613 | === modified file 'launcher/LauncherModel.h' | |||
614 | --- launcher/LauncherModel.h 2012-08-31 19:35:46 +0000 | |||
615 | +++ launcher/LauncherModel.h 2012-09-04 16:43:33 +0000 | |||
616 | @@ -1,6 +1,6 @@ | |||
617 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
618 | 2 | /* | 2 | /* |
620 | 3 | * Copyright (C) 2010 Canonical Ltd | 3 | * Copyright (C) 2010-2012 Canonical Ltd |
621 | 4 | * | 4 | * |
622 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
623 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
624 | @@ -15,6 +15,7 @@ | |||
625 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
626 | 16 | * | 16 | * |
627 | 17 | * Authored by: Jason Smith <jason.smith@canonical.com> | 17 | * Authored by: Jason Smith <jason.smith@canonical.com> |
628 | 18 | * Marco Trevisan <marco.trevisan@canonical.com> | ||
629 | 18 | */ | 19 | */ |
630 | 19 | 20 | ||
631 | 20 | #ifndef LAUNCHERMODEL_H | 21 | #ifndef LAUNCHERMODEL_H |
632 | @@ -41,20 +42,18 @@ | |||
633 | 41 | 42 | ||
634 | 42 | LauncherModel(); | 43 | LauncherModel(); |
635 | 43 | 44 | ||
638 | 44 | void AddIcon(AbstractLauncherIcon::Ptr icon); | 45 | void AddIcon(AbstractLauncherIcon::Ptr const& icon); |
639 | 45 | void RemoveIcon(AbstractLauncherIcon::Ptr icon); | 46 | void RemoveIcon(AbstractLauncherIcon::Ptr const& icon); |
640 | 46 | void Save(); | 47 | void Save(); |
641 | 47 | void Sort(); | 48 | void Sort(); |
642 | 48 | int Size() const; | 49 | int Size() const; |
643 | 49 | 50 | ||
652 | 50 | void OnIconRemove(AbstractLauncherIcon::Ptr icon); | 51 | bool IconHasSister(AbstractLauncherIcon::Ptr const& icon) const; |
653 | 51 | 52 | int IconIndex(AbstractLauncherIcon::Ptr const& icon) const; | |
654 | 52 | bool IconHasSister(AbstractLauncherIcon::Ptr icon) const; | 53 | |
655 | 53 | 54 | void ReorderAfter(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other); | |
656 | 54 | void ReorderAfter(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other); | 55 | void ReorderBefore(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other, bool animate); |
657 | 55 | void ReorderBefore(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save); | 56 | void ReorderSmart(AbstractLauncherIcon::Ptr const& icon, AbstractLauncherIcon::Ptr const& other, bool animate); |
650 | 56 | |||
651 | 57 | void ReorderSmart(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save); | ||
658 | 58 | 57 | ||
659 | 59 | AbstractLauncherIcon::Ptr Selection() const; | 58 | AbstractLauncherIcon::Ptr Selection() const; |
660 | 60 | int SelectionIndex() const; | 59 | int SelectionIndex() const; |
661 | @@ -62,7 +61,7 @@ | |||
662 | 62 | void SelectNext(); | 61 | void SelectNext(); |
663 | 63 | void SelectPrevious(); | 62 | void SelectPrevious(); |
664 | 64 | 63 | ||
666 | 65 | AbstractLauncherIcon::Ptr GetClosestIcon(AbstractLauncherIcon::Ptr icon, bool& is_before) const; | 64 | AbstractLauncherIcon::Ptr GetClosestIcon(AbstractLauncherIcon::Ptr const& icon, bool& is_before) const; |
667 | 66 | 65 | ||
668 | 67 | iterator begin(); | 66 | iterator begin(); |
669 | 68 | iterator end(); | 67 | iterator end(); |
670 | @@ -80,17 +79,17 @@ | |||
671 | 80 | reverse_iterator shelf_rbegin(); | 79 | reverse_iterator shelf_rbegin(); |
672 | 81 | reverse_iterator shelf_rend(); | 80 | reverse_iterator shelf_rend(); |
673 | 82 | 81 | ||
676 | 83 | sigc::signal<void, AbstractLauncherIcon::Ptr> icon_added; | 82 | sigc::signal<void, AbstractLauncherIcon::Ptr const&> icon_added; |
677 | 84 | sigc::signal<void, AbstractLauncherIcon::Ptr> icon_removed; | 83 | sigc::signal<void, AbstractLauncherIcon::Ptr const&> icon_removed; |
678 | 84 | sigc::signal<void, AbstractLauncherIcon::Ptr const&> selection_changed; | ||
679 | 85 | sigc::signal<void> order_changed; | 85 | sigc::signal<void> order_changed; |
680 | 86 | sigc::signal<void> saved; | 86 | sigc::signal<void> saved; |
681 | 87 | sigc::signal<void, AbstractLauncherIcon::Ptr> selection_changed; | ||
682 | 88 | 87 | ||
683 | 89 | IntrospectableList GetIntrospectableChildren(); | ||
684 | 90 | protected: | 88 | protected: |
685 | 91 | // Introspectable methods | 89 | // Introspectable methods |
686 | 92 | std::string GetName() const; | 90 | std::string GetName() const; |
687 | 93 | void AddProperties(GVariantBuilder* builder); | 91 | void AddProperties(GVariantBuilder* builder); |
688 | 92 | IntrospectableList GetIntrospectableChildren(); | ||
689 | 94 | 93 | ||
690 | 95 | private: | 94 | private: |
691 | 96 | Base _inner; | 95 | Base _inner; |
692 | @@ -101,10 +100,10 @@ | |||
693 | 101 | glib::SourceManager timeouts_; | 100 | glib::SourceManager timeouts_; |
694 | 102 | 101 | ||
695 | 103 | bool Populate(); | 102 | bool Populate(); |
700 | 104 | 103 | void PopulatePart(iterator begin, iterator end); | |
701 | 105 | bool IconShouldShelf(AbstractLauncherIcon::Ptr icon) const; | 104 | void OnIconRemove(AbstractLauncherIcon::Ptr const& icon); |
702 | 106 | 105 | bool IconShouldShelf(AbstractLauncherIcon::Ptr const& icon) const; | |
703 | 107 | static bool CompareIcons(AbstractLauncherIcon::Ptr first, AbstractLauncherIcon::Ptr second); | 106 | static bool CompareIcons(AbstractLauncherIcon::Ptr const& first, AbstractLauncherIcon::Ptr const& second); |
704 | 108 | 107 | ||
705 | 109 | /* Template Methods */ | 108 | /* Template Methods */ |
706 | 110 | public: | 109 | public: |
707 | 111 | 110 | ||
708 | === modified file 'launcher/MockLauncherIcon.h' | |||
709 | --- launcher/MockLauncherIcon.h 2012-08-31 18:00:29 +0000 | |||
710 | +++ launcher/MockLauncherIcon.h 2012-09-04 16:43:33 +0000 | |||
711 | @@ -44,12 +44,12 @@ | |||
712 | 44 | { | 44 | { |
713 | 45 | NUX_DECLARE_OBJECT_TYPE(MockLauncherIcon, AbstractLauncherIcon); | 45 | NUX_DECLARE_OBJECT_TYPE(MockLauncherIcon, AbstractLauncherIcon); |
714 | 46 | public: | 46 | public: |
717 | 47 | MockLauncherIcon() | 47 | MockLauncherIcon(IconType type = IconType::APPLICATION) |
718 | 48 | : icon_(0) | 48 | : type_(type) |
719 | 49 | , sort_priority_(0) | ||
720 | 50 | , icon_(0) | ||
721 | 49 | { | 51 | { |
722 | 50 | tooltip_text = "Mock Icon"; | 52 | tooltip_text = "Mock Icon"; |
723 | 51 | sort_priority_ = 0; | ||
724 | 52 | type_ = IconType::APPLICATION; | ||
725 | 53 | 53 | ||
726 | 54 | for (unsigned i = 0; i < unsigned(Quirk::LAST); ++i) | 54 | for (unsigned i = 0; i < unsigned(Quirk::LAST); ++i) |
727 | 55 | { | 55 | { |
728 | @@ -58,7 +58,7 @@ | |||
729 | 58 | } | 58 | } |
730 | 59 | 59 | ||
731 | 60 | std::string GetName() const { return "MockLauncherIcon"; } | 60 | std::string GetName() const { return "MockLauncherIcon"; } |
733 | 61 | 61 | ||
734 | 62 | void AddProperties(GVariantBuilder* builder) {} | 62 | void AddProperties(GVariantBuilder* builder) {} |
735 | 63 | 63 | ||
736 | 64 | void HideTooltip() {} | 64 | void HideTooltip() {} |
737 | @@ -293,9 +293,9 @@ | |||
738 | 293 | bool IsVisible() const { return false; } | 293 | bool IsVisible() const { return false; } |
739 | 294 | 294 | ||
740 | 295 | void AboutToRemove() {} | 295 | void AboutToRemove() {} |
742 | 296 | 296 | ||
743 | 297 | void Stick(bool save = true) {} | 297 | void Stick(bool save = true) {} |
745 | 298 | 298 | ||
746 | 299 | void UnStick() {} | 299 | void UnStick() {} |
747 | 300 | 300 | ||
748 | 301 | private: | 301 | private: |
749 | @@ -346,9 +346,9 @@ | |||
750 | 346 | return result; | 346 | return result; |
751 | 347 | } | 347 | } |
752 | 348 | 348 | ||
753 | 349 | IconType type_; | ||
754 | 350 | int sort_priority_; | ||
755 | 349 | nux::BaseTexture* icon_; | 351 | nux::BaseTexture* icon_; |
756 | 350 | int sort_priority_; | ||
757 | 351 | IconType type_; | ||
758 | 352 | bool quirks_[unsigned(Quirk::LAST)]; | 352 | bool quirks_[unsigned(Quirk::LAST)]; |
759 | 353 | timespec quirk_times_[unsigned(Quirk::LAST)]; | 353 | timespec quirk_times_[unsigned(Quirk::LAST)]; |
760 | 354 | std::map<int, nux::Point3> center_; | 354 | std::map<int, nux::Point3> center_; |
761 | 355 | 355 | ||
762 | === modified file 'tests/test_launcher.cpp' | |||
763 | --- tests/test_launcher.cpp 2012-09-01 14:09:20 +0000 | |||
764 | +++ tests/test_launcher.cpp 2012-09-04 16:43:33 +0000 | |||
765 | @@ -210,10 +210,6 @@ | |||
766 | 210 | MockMockLauncherIcon::Ptr icon2(new MockMockLauncherIcon); | 210 | MockMockLauncherIcon::Ptr icon2(new MockMockLauncherIcon); |
767 | 211 | MockMockLauncherIcon::Ptr icon3(new MockMockLauncherIcon); | 211 | MockMockLauncherIcon::Ptr icon3(new MockMockLauncherIcon); |
768 | 212 | 212 | ||
769 | 213 | icon1->SetSortPriority(0); | ||
770 | 214 | icon2->SetSortPriority(1); | ||
771 | 215 | icon3->SetSortPriority(2); | ||
772 | 216 | |||
773 | 217 | model_->AddIcon(icon1); | 213 | model_->AddIcon(icon1); |
774 | 218 | model_->AddIcon(icon2); | 214 | model_->AddIcon(icon2); |
775 | 219 | model_->AddIcon(icon3); | 215 | model_->AddIcon(icon3); |
776 | 220 | 216 | ||
777 | === modified file 'tests/test_launcher_model.cpp' | |||
778 | --- tests/test_launcher_model.cpp 2012-08-31 19:35:46 +0000 | |||
779 | +++ tests/test_launcher_model.cpp 2012-09-04 16:43:33 +0000 | |||
780 | @@ -1,5 +1,5 @@ | |||
781 | 1 | /* | 1 | /* |
783 | 2 | * Copyright 2011 Canonical Ltd. | 2 | * Copyright 2011-2012 Canonical Ltd. |
784 | 3 | * | 3 | * |
785 | 4 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
786 | 5 | * under the terms of the GNU General Public License version 3, as published | 5 | * under the terms of the GNU General Public License version 3, as published |
787 | @@ -15,7 +15,7 @@ | |||
788 | 15 | * <http://www.gnu.org/licenses/> | 15 | * <http://www.gnu.org/licenses/> |
789 | 16 | * | 16 | * |
790 | 17 | * Authored by: Jason Smith <jason.smith@canonical.com> | 17 | * Authored by: Jason Smith <jason.smith@canonical.com> |
792 | 18 | * | 18 | * Marco Trevisan <marco.trevisan@canonical.com> |
793 | 19 | */ | 19 | */ |
794 | 20 | 20 | ||
795 | 21 | #include <gtest/gtest.h> | 21 | #include <gtest/gtest.h> |
796 | @@ -32,229 +32,308 @@ | |||
797 | 32 | namespace | 32 | namespace |
798 | 33 | { | 33 | { |
799 | 34 | 34 | ||
801 | 35 | class EventListener | 35 | class TestLauncherModel : public testing::Test |
802 | 36 | { | 36 | { |
822 | 37 | public: | 37 | public: |
823 | 38 | EventListener() | 38 | TestLauncherModel() |
824 | 39 | { | 39 | : icon1(new MockLauncherIcon()) |
825 | 40 | icon_added = false; | 40 | , icon2(new MockLauncherIcon()) |
826 | 41 | icon_removed = false; | 41 | , icon3(new MockLauncherIcon()) |
827 | 42 | } | 42 | , icon4(new MockLauncherIcon()) |
828 | 43 | 43 | {} | |
829 | 44 | void OnIconAdded (AbstractLauncherIcon::Ptr icon) | 44 | |
830 | 45 | { | 45 | AbstractLauncherIcon::Ptr icon1; |
831 | 46 | icon_added = true; | 46 | AbstractLauncherIcon::Ptr icon2; |
832 | 47 | } | 47 | AbstractLauncherIcon::Ptr icon3; |
833 | 48 | 48 | AbstractLauncherIcon::Ptr icon4; | |
834 | 49 | void OnIconRemoved (AbstractLauncherIcon::Ptr icon) | 49 | |
835 | 50 | { | 50 | LauncherModel model; |
817 | 51 | icon_removed = true; | ||
818 | 52 | } | ||
819 | 53 | |||
820 | 54 | bool icon_added; | ||
821 | 55 | bool icon_removed; | ||
836 | 56 | }; | 51 | }; |
1013 | 57 | //bool seen_result; | 52 | |
1014 | 58 | 53 | TEST_F(TestLauncherModel, Constructor) | |
1015 | 59 | TEST(TestLauncherModel, TestConstructor) | 54 | { |
1016 | 60 | { | 55 | EXPECT_EQ(model.Size(), 0); |
1017 | 61 | LauncherModel::Ptr model(new LauncherModel()); | 56 | } |
1018 | 62 | EXPECT_EQ(model->Size(), 0); | 57 | |
1019 | 63 | } | 58 | TEST_F(TestLauncherModel, Add) |
1020 | 64 | 59 | { | |
1021 | 65 | TEST(TestLauncherModel, TestAdd) | 60 | model.AddIcon(icon1); |
1022 | 66 | { | 61 | EXPECT_EQ(model.Size(), 1); |
1023 | 67 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | 62 | |
1024 | 68 | LauncherModel::Ptr model(new LauncherModel()); | 63 | model.AddIcon(icon1); |
1025 | 69 | 64 | EXPECT_EQ(model.Size(), 1); | |
1026 | 70 | EXPECT_EQ(model->Size(), 0); | 65 | |
1027 | 71 | model->AddIcon(first); | 66 | model.AddIcon(AbstractLauncherIcon::Ptr()); |
1028 | 72 | EXPECT_EQ(model->Size(), 1); | 67 | EXPECT_EQ(model.Size(), 1); |
1029 | 73 | } | 68 | } |
1030 | 74 | 69 | ||
1031 | 75 | TEST(TestLauncherModel, TestRemove) | 70 | TEST_F(TestLauncherModel, Remove) |
1032 | 76 | { | 71 | { |
1033 | 77 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | 72 | model.AddIcon(icon1); |
1034 | 78 | LauncherModel::Ptr model(new LauncherModel()); | 73 | EXPECT_EQ(model.Size(), 1); |
1035 | 79 | 74 | ||
1036 | 80 | EXPECT_EQ(model->Size(), 0); | 75 | model.RemoveIcon(icon1); |
1037 | 81 | model->AddIcon(first); | 76 | EXPECT_EQ(model.Size(), 0); |
1038 | 82 | EXPECT_EQ(model->Size(), 1); | 77 | } |
1039 | 83 | model->RemoveIcon(first); | 78 | |
1040 | 84 | EXPECT_EQ(model->Size(), 0); | 79 | TEST_F(TestLauncherModel, AddSignal) |
1041 | 85 | } | 80 | { |
1042 | 86 | 81 | bool icon_added = false; | |
1043 | 87 | TEST(TestLauncherModel, TestAddSignal) | 82 | model.icon_added.connect([&icon_added] (AbstractLauncherIcon::Ptr) { icon_added = true; }); |
1044 | 88 | { | 83 | |
1045 | 89 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | 84 | model.AddIcon(icon1); |
1046 | 90 | LauncherModel::Ptr model(new LauncherModel()); | 85 | EXPECT_TRUE(icon_added); |
1047 | 91 | 86 | ||
1048 | 92 | EventListener *listener = new EventListener(); | 87 | icon_added = false; |
1049 | 93 | 88 | model.AddIcon(icon1); | |
1050 | 94 | model->icon_added.connect(sigc::mem_fun(listener, &EventListener::OnIconAdded)); | 89 | EXPECT_FALSE(icon_added); |
1051 | 95 | model->AddIcon(first); | 90 | |
1052 | 96 | EXPECT_EQ(listener->icon_added, true); | 91 | icon_added = false; |
1053 | 97 | 92 | model.AddIcon(AbstractLauncherIcon::Ptr()); | |
1054 | 98 | delete listener; | 93 | EXPECT_FALSE(icon_added); |
1055 | 99 | } | 94 | } |
1056 | 100 | 95 | ||
1057 | 101 | TEST(TestLauncherModel, TestRemoveSignal) | 96 | TEST_F(TestLauncherModel, RemoveSignal) |
1058 | 102 | { | 97 | { |
1059 | 103 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | 98 | bool icon_removed = false; |
1060 | 104 | LauncherModel::Ptr model(new LauncherModel()); | 99 | model.icon_removed.connect([&icon_removed] (AbstractLauncherIcon::Ptr) { icon_removed = true; }); |
1061 | 105 | 100 | ||
1062 | 106 | EventListener *listener = new EventListener(); | 101 | model.AddIcon(icon1); |
1063 | 107 | 102 | EXPECT_FALSE(icon_removed); | |
1064 | 108 | model->icon_removed.connect(sigc::mem_fun(listener, &EventListener::OnIconRemoved)); | 103 | model.RemoveIcon(icon1); |
1065 | 109 | model->AddIcon(first); | 104 | EXPECT_TRUE(icon_removed); |
1066 | 110 | EXPECT_EQ(listener->icon_removed, false); | 105 | } |
1067 | 111 | model->RemoveIcon(first); | 106 | |
1068 | 112 | EXPECT_EQ(listener->icon_removed, true); | 107 | TEST_F(TestLauncherModel, Sort) |
1069 | 113 | 108 | { | |
1070 | 114 | delete listener; | 109 | icon2->SetSortPriority(0); |
1071 | 115 | } | 110 | model.AddIcon(icon2); |
1072 | 116 | 111 | ||
1073 | 117 | TEST(TestLauncherModel, TestSort) | 112 | icon1->SetSortPriority(-1); |
1074 | 118 | { | 113 | model.AddIcon(icon1); |
1075 | 119 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | 114 | |
1076 | 120 | AbstractLauncherIcon::Ptr second(new MockLauncherIcon()); | 115 | icon4->SetSortPriority(2); |
1077 | 121 | AbstractLauncherIcon::Ptr third(new MockLauncherIcon()); | 116 | model.AddIcon(icon4); |
1078 | 122 | AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon()); | 117 | |
1079 | 123 | 118 | icon3->SetSortPriority(0); | |
1080 | 124 | LauncherModel::Ptr model(new LauncherModel()); | 119 | model.AddIcon(icon3); |
1081 | 125 | 120 | ||
1082 | 126 | third->SetSortPriority(0); | 121 | LauncherModel::iterator it; |
1083 | 127 | model->AddIcon(third); | 122 | it = model.begin(); |
1084 | 128 | 123 | ||
1085 | 129 | first->SetSortPriority(-1); | 124 | EXPECT_EQ(icon1, *it); |
1086 | 130 | model->AddIcon(first); | 125 | it++; |
1087 | 131 | 126 | EXPECT_EQ(icon2, *it); | |
1088 | 132 | fourth->SetSortPriority(2); | 127 | it++; |
1089 | 133 | model->AddIcon(fourth); | 128 | EXPECT_EQ(icon3, *it); |
1090 | 134 | 129 | it++; | |
1091 | 135 | second->SetSortPriority(0); | 130 | EXPECT_EQ(icon4, *it); |
1092 | 136 | model->AddIcon(second); | 131 | } |
1093 | 137 | 132 | ||
1094 | 138 | LauncherModel::iterator it; | 133 | TEST_F(TestLauncherModel, ModelKeepsPriorityDeltas) |
1095 | 139 | it = model->begin(); | 134 | { |
1096 | 140 | 135 | icon2->SetSortPriority(0); | |
1097 | 141 | EXPECT_EQ(first, *it); | 136 | icon1->SetSortPriority(-1); |
1098 | 142 | it++; | 137 | icon4->SetSortPriority(2); |
1099 | 143 | EXPECT_EQ(second, *it); | 138 | icon3->SetSortPriority(0); |
1100 | 144 | it++; | 139 | |
1101 | 145 | EXPECT_EQ(third, *it); | 140 | model.AddIcon(icon2); |
1102 | 146 | it++; | 141 | model.AddIcon(icon1); |
1103 | 147 | EXPECT_EQ(fourth, *it); | 142 | model.AddIcon(icon4); |
1104 | 148 | } | 143 | model.AddIcon(icon3); |
1105 | 149 | 144 | ||
1106 | 150 | TEST(TestLauncherModel, TestReorderBefore) | 145 | auto it = model.begin(); |
1107 | 151 | { | 146 | EXPECT_EQ(icon1, *it); |
1108 | 152 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | 147 | it++; |
1109 | 153 | AbstractLauncherIcon::Ptr second(new MockLauncherIcon()); | 148 | EXPECT_EQ(icon2, *it); |
1110 | 154 | AbstractLauncherIcon::Ptr third(new MockLauncherIcon()); | 149 | it++; |
1111 | 155 | AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon()); | 150 | EXPECT_EQ(icon3, *it); |
1112 | 156 | 151 | it++; | |
1113 | 157 | LauncherModel::Ptr model(new LauncherModel()); | 152 | EXPECT_EQ(icon4, *it); |
1114 | 158 | 153 | ||
1115 | 159 | first->SetSortPriority(0); | 154 | EXPECT_GT(icon2->SortPriority(), icon1->SortPriority()); |
1116 | 160 | second->SetSortPriority(1); | 155 | EXPECT_EQ(icon2->SortPriority(), icon3->SortPriority()); |
1117 | 161 | third->SetSortPriority(2); | 156 | EXPECT_LT(icon3->SortPriority(), icon4->SortPriority()); |
1118 | 162 | fourth->SetSortPriority(3); | 157 | } |
1119 | 163 | 158 | ||
1120 | 164 | model->AddIcon(first); | 159 | TEST_F(TestLauncherModel, ReorderBefore) |
1121 | 165 | model->AddIcon(second); | 160 | { |
1122 | 166 | model->AddIcon(third); | 161 | icon1->SetSortPriority(0); |
1123 | 167 | model->AddIcon(fourth); | 162 | icon2->SetSortPriority(1); |
1124 | 168 | 163 | icon3->SetSortPriority(2); | |
1125 | 169 | model->ReorderBefore(third, second, false); | 164 | icon4->SetSortPriority(3); |
1126 | 170 | 165 | ||
1127 | 171 | LauncherModel::iterator it; | 166 | model.AddIcon(icon1); |
1128 | 172 | it = model->begin(); | 167 | model.AddIcon(icon2); |
1129 | 173 | 168 | model.AddIcon(icon3); | |
1130 | 174 | EXPECT_EQ(first, *it); | 169 | model.AddIcon(icon4); |
1131 | 175 | it++; | 170 | |
1132 | 176 | EXPECT_EQ(third, *it); | 171 | model.ReorderBefore(icon3, icon2, false); |
1133 | 177 | it++; | 172 | |
1134 | 178 | EXPECT_EQ(second, *it); | 173 | LauncherModel::iterator it; |
1135 | 179 | it++; | 174 | it = model.begin(); |
1136 | 180 | EXPECT_EQ(fourth, *it); | 175 | |
1137 | 181 | } | 176 | EXPECT_EQ(icon1, *it); |
1138 | 182 | 177 | it++; | |
1139 | 183 | TEST(TestLauncherModel, TestReorderSmart) | 178 | EXPECT_EQ(icon3, *it); |
1140 | 184 | { | 179 | it++; |
1141 | 185 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | 180 | EXPECT_EQ(icon2, *it); |
1142 | 186 | AbstractLauncherIcon::Ptr second(new MockLauncherIcon()); | 181 | it++; |
1143 | 187 | AbstractLauncherIcon::Ptr third(new MockLauncherIcon()); | 182 | EXPECT_EQ(icon4, *it); |
1144 | 188 | AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon()); | 183 | } |
1145 | 189 | 184 | ||
1146 | 190 | LauncherModel::Ptr model(new LauncherModel()); | 185 | TEST_F(TestLauncherModel, ReorderAfter) |
1147 | 191 | 186 | { | |
1148 | 192 | first->SetSortPriority(0); | 187 | model.AddIcon(icon1); |
1149 | 193 | second->SetSortPriority(1); | 188 | model.AddIcon(icon3); |
1150 | 194 | third->SetSortPriority(2); | 189 | model.AddIcon(icon2); |
1151 | 195 | fourth->SetSortPriority(3); | 190 | model.AddIcon(icon4); |
1152 | 196 | 191 | ||
1153 | 197 | model->AddIcon(first); | 192 | model.ReorderAfter(icon3, icon2); |
1154 | 198 | model->AddIcon(second); | 193 | |
1155 | 199 | model->AddIcon(third); | 194 | LauncherModel::iterator it; |
1156 | 200 | model->AddIcon(fourth); | 195 | it = model.begin(); |
1157 | 201 | 196 | ||
1158 | 202 | model->ReorderSmart(third, second, false); | 197 | EXPECT_EQ(icon1, *it); |
1159 | 203 | 198 | it++; | |
1160 | 204 | LauncherModel::iterator it; | 199 | EXPECT_EQ(icon2, *it); |
1161 | 205 | it = model->begin(); | 200 | it++; |
1162 | 206 | 201 | EXPECT_EQ(icon3, *it); | |
1163 | 207 | EXPECT_EQ(first, *it); | 202 | it++; |
1164 | 208 | it++; | 203 | EXPECT_EQ(icon4, *it); |
1165 | 209 | EXPECT_EQ(third, *it); | 204 | } |
1166 | 210 | it++; | 205 | |
1167 | 211 | EXPECT_EQ(second, *it); | 206 | TEST_F(TestLauncherModel, ReorderSmart) |
1168 | 212 | it++; | 207 | { |
1169 | 213 | EXPECT_EQ(fourth, *it); | 208 | icon1->SetSortPriority(0); |
1170 | 214 | } | 209 | icon2->SetSortPriority(1); |
1171 | 215 | 210 | icon3->SetSortPriority(2); | |
1172 | 216 | TEST(TestLauncherModel, TestGetClosestIcon) | 211 | icon4->SetSortPriority(3); |
1173 | 217 | { | 212 | |
1174 | 218 | LauncherModel::Ptr model(new LauncherModel()); | 213 | model.AddIcon(icon1); |
1175 | 219 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | 214 | model.AddIcon(icon2); |
1176 | 220 | AbstractLauncherIcon::Ptr second(new MockLauncherIcon()); | 215 | model.AddIcon(icon3); |
1177 | 221 | AbstractLauncherIcon::Ptr third(new MockLauncherIcon()); | 216 | model.AddIcon(icon4); |
1178 | 222 | AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon()); | 217 | |
1179 | 223 | 218 | model.ReorderSmart(icon3, icon2, false); | |
1180 | 224 | first->SetSortPriority(0); | 219 | |
1181 | 225 | second->SetSortPriority(1); | 220 | LauncherModel::iterator it; |
1182 | 226 | third->SetSortPriority(2); | 221 | it = model.begin(); |
1183 | 227 | fourth->SetSortPriority(3); | 222 | |
1184 | 228 | 223 | EXPECT_EQ(icon1, *it); | |
1185 | 229 | model->AddIcon(first); | 224 | it++; |
1186 | 230 | model->AddIcon(second); | 225 | EXPECT_EQ(icon3, *it); |
1187 | 231 | model->AddIcon(third); | 226 | it++; |
1188 | 232 | model->AddIcon(fourth); | 227 | EXPECT_EQ(icon2, *it); |
1189 | 228 | it++; | ||
1190 | 229 | EXPECT_EQ(icon4, *it); | ||
1191 | 230 | } | ||
1192 | 231 | |||
1193 | 232 | TEST_F(TestLauncherModel, OrderByType) | ||
1194 | 233 | { | ||
1195 | 234 | AbstractLauncherIcon::Ptr icon1(new MockLauncherIcon(AbstractLauncherIcon::IconType::HOME)); | ||
1196 | 235 | AbstractLauncherIcon::Ptr icon2(new MockLauncherIcon(AbstractLauncherIcon::IconType::APPLICATION)); | ||
1197 | 236 | AbstractLauncherIcon::Ptr icon3(new MockLauncherIcon(AbstractLauncherIcon::IconType::EXPO)); | ||
1198 | 237 | AbstractLauncherIcon::Ptr icon4(new MockLauncherIcon(AbstractLauncherIcon::IconType::DEVICE)); | ||
1199 | 238 | AbstractLauncherIcon::Ptr icon5(new MockLauncherIcon(AbstractLauncherIcon::IconType::TRASH)); | ||
1200 | 239 | |||
1201 | 240 | model.AddIcon(icon3); | ||
1202 | 241 | model.AddIcon(icon4); | ||
1203 | 242 | model.AddIcon(icon2); | ||
1204 | 243 | model.AddIcon(icon1); | ||
1205 | 244 | model.AddIcon(icon5); | ||
1206 | 245 | |||
1207 | 246 | auto it = model.begin(); | ||
1208 | 247 | EXPECT_EQ(icon1, *it); | ||
1209 | 248 | it++; | ||
1210 | 249 | EXPECT_EQ(icon2, *it); | ||
1211 | 250 | it++; | ||
1212 | 251 | EXPECT_EQ(icon3, *it); | ||
1213 | 252 | it++; | ||
1214 | 253 | EXPECT_EQ(icon4, *it); | ||
1215 | 254 | it++; | ||
1216 | 255 | EXPECT_EQ(icon5, *it); | ||
1217 | 256 | it++; | ||
1218 | 257 | EXPECT_EQ(it, model.end()); | ||
1219 | 258 | |||
1220 | 259 | auto it_main = model.main_begin(); | ||
1221 | 260 | EXPECT_EQ(icon1, *it_main); | ||
1222 | 261 | it_main++; | ||
1223 | 262 | EXPECT_EQ(icon2, *it_main); | ||
1224 | 263 | it_main++; | ||
1225 | 264 | EXPECT_EQ(icon3, *it_main); | ||
1226 | 265 | it_main++; | ||
1227 | 266 | EXPECT_EQ(icon4, *it_main); | ||
1228 | 267 | it_main++; | ||
1229 | 268 | EXPECT_EQ(it_main, model.main_end()); | ||
1230 | 269 | |||
1231 | 270 | auto it_shelf = model.shelf_begin(); | ||
1232 | 271 | EXPECT_EQ(icon5, *it_shelf); | ||
1233 | 272 | it_shelf++; | ||
1234 | 273 | EXPECT_EQ(it_shelf, model.shelf_end()); | ||
1235 | 274 | } | ||
1236 | 275 | |||
1237 | 276 | TEST_F(TestLauncherModel, GetClosestIcon) | ||
1238 | 277 | { | ||
1239 | 278 | model.AddIcon(icon1); | ||
1240 | 279 | model.AddIcon(icon2); | ||
1241 | 280 | model.AddIcon(icon3); | ||
1242 | 281 | model.AddIcon(icon4); | ||
1243 | 233 | 282 | ||
1244 | 234 | bool before; | 283 | bool before; |
1246 | 235 | EXPECT_EQ(model->GetClosestIcon(first, before), second); | 284 | EXPECT_EQ(model.GetClosestIcon(icon1, before), icon2); |
1247 | 236 | EXPECT_FALSE(before); | 285 | EXPECT_FALSE(before); |
1248 | 237 | 286 | ||
1256 | 238 | EXPECT_EQ(model->GetClosestIcon(second, before), first); | 287 | EXPECT_EQ(model.GetClosestIcon(icon2, before), icon1); |
1257 | 239 | EXPECT_TRUE(before); | 288 | EXPECT_TRUE(before); |
1258 | 240 | 289 | ||
1259 | 241 | EXPECT_EQ(model->GetClosestIcon(third, before), second); | 290 | EXPECT_EQ(model.GetClosestIcon(icon3, before), icon2); |
1260 | 242 | EXPECT_TRUE(before); | 291 | EXPECT_TRUE(before); |
1261 | 243 | 292 | ||
1262 | 244 | EXPECT_EQ(model->GetClosestIcon(fourth, before), third); | 293 | EXPECT_EQ(model.GetClosestIcon(icon4, before), icon3); |
1263 | 245 | EXPECT_TRUE(before); | 294 | EXPECT_TRUE(before); |
1264 | 246 | } | 295 | } |
1265 | 247 | 296 | ||
1267 | 248 | TEST(TestLauncherModel, TestGetClosestIconWithOneIcon) | 297 | TEST_F(TestLauncherModel, GetClosestIconWithOneIcon) |
1268 | 249 | { | 298 | { |
1273 | 250 | LauncherModel::Ptr model(new LauncherModel()); | 299 | model.AddIcon(icon1); |
1270 | 251 | AbstractLauncherIcon::Ptr first(new MockLauncherIcon()); | ||
1271 | 252 | |||
1272 | 253 | model->AddIcon(first); | ||
1274 | 254 | 300 | ||
1275 | 255 | bool before; | 301 | bool before; |
1277 | 256 | EXPECT_EQ(model->GetClosestIcon(first, before), nullptr); | 302 | EXPECT_EQ(model.GetClosestIcon(icon1, before), nullptr); |
1278 | 257 | EXPECT_TRUE(before); | 303 | EXPECT_TRUE(before); |
1279 | 258 | } | 304 | } |
1280 | 259 | 305 | ||
1281 | 306 | TEST_F(TestLauncherModel, IconIndex) | ||
1282 | 307 | { | ||
1283 | 308 | model.AddIcon(icon1); | ||
1284 | 309 | model.AddIcon(icon2); | ||
1285 | 310 | model.AddIcon(icon3); | ||
1286 | 311 | model.AddIcon(icon4); | ||
1287 | 312 | |||
1288 | 313 | EXPECT_EQ(model.IconIndex(icon1), 0); | ||
1289 | 314 | EXPECT_EQ(model.IconIndex(icon2), 1); | ||
1290 | 315 | EXPECT_EQ(model.IconIndex(icon3), 2); | ||
1291 | 316 | EXPECT_EQ(model.IconIndex(icon4), 3); | ||
1292 | 317 | |||
1293 | 318 | AbstractLauncherIcon::Ptr icon5(new MockLauncherIcon()); | ||
1294 | 319 | EXPECT_EQ(model.IconIndex(icon5), -1); | ||
1295 | 320 | } | ||
1296 | 321 | |||
1297 | 322 | TEST_F(TestLauncherModel, IconHasSister) | ||
1298 | 323 | { | ||
1299 | 324 | model.AddIcon(icon1); | ||
1300 | 325 | EXPECT_FALSE(model.IconHasSister(icon1)); | ||
1301 | 326 | |||
1302 | 327 | model.AddIcon(icon2); | ||
1303 | 328 | model.AddIcon(icon3); | ||
1304 | 329 | model.AddIcon(icon4); | ||
1305 | 330 | |||
1306 | 331 | EXPECT_TRUE(model.IconHasSister(icon1)); | ||
1307 | 332 | EXPECT_TRUE(model.IconHasSister(icon2)); | ||
1308 | 333 | EXPECT_TRUE(model.IconHasSister(icon3)); | ||
1309 | 334 | EXPECT_TRUE(model.IconHasSister(icon4)); | ||
1310 | 335 | |||
1311 | 336 | EXPECT_FALSE(AbstractLauncherIcon::Ptr()); | ||
1312 | 337 | } | ||
1313 | 338 | |||
1314 | 260 | } | 339 | } |
LGTM... Discussed and reviewed on IRC.