Merge lp:~julien-spautz/slingshot/remove-unused-functions into lp:~elementary-pantheon/slingshot/trunk

Proposed by Julien Spautz
Status: Merged
Approved by: Cody Garver
Approved revision: 442
Merged at revision: 448
Proposed branch: lp:~julien-spautz/slingshot/remove-unused-functions
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 220 lines (+4/-109)
4 files modified
CMakeLists.txt (+0/-1)
src/Backend/AppSystem.vala (+3/-97)
src/Utils.vala (+1/-9)
src/Widgets/AppEntry.vala (+0/-2)
To merge this branch: bzr merge lp:~julien-spautz/slingshot/remove-unused-functions
Reviewer Review Type Date Requested Status
elementary Pantheon team Pending
Review via email: mp+231083@code.launchpad.net

Commit message

Removed some functions rendered useless by the new Synapse backend and minor code cleanup

Description of the change

Removed some functions rendered useless by the new synapse backend.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-06-12 09:36:00 +0000
+++ CMakeLists.txt 2014-08-16 15:16:33 +0000
@@ -127,4 +127,3 @@
127127
128# Translations128# Translations
129add_subdirectory (po)129add_subdirectory (po)
130
131130
=== modified file 'src/Backend/AppSystem.vala'
--- src/Backend/AppSystem.vala 2014-06-12 09:36:00 +0000
+++ src/Backend/AppSystem.vala 2014-08-16 15:16:33 +0000
@@ -32,7 +32,6 @@
32 public signal void changed ();32 public signal void changed ();
3333
34 construct {34 construct {
35
36#if HAVE_ZEITGEIST35#if HAVE_ZEITGEIST
37 rl_service = new RelevancyService ();36 rl_service = new RelevancyService ();
38 rl_service.update_complete.connect (update_popularity);37 rl_service.update_complete.connect (update_popularity);
@@ -45,11 +44,9 @@
45 categories = new Gee.ArrayList<GMenu.TreeDirectory> ();44 categories = new Gee.ArrayList<GMenu.TreeDirectory> ();
4645
47 update_app_system ();46 update_app_system ();
48
49 }47 }
5048
51 private void update_app_system () {49 private void update_app_system () {
52
53 debug ("Updating Applications menu tree...");50 debug ("Updating Applications menu tree...");
54#if HAVE_ZEITGEIST51#if HAVE_ZEITGEIST
55 rl_service.refresh_popularity ();52 rl_service.refresh_popularity ();
@@ -64,11 +61,9 @@
64 update_apps ();61 update_apps ();
6562
66 changed ();63 changed ();
67
68 }64 }
6965
70 private void update_categories_index () {66 private void update_categories_index () {
71
72 categories.clear ();67 categories.clear ();
7368
74 var iter = apps_menu.get_root_directory ().iter ();69 var iter = apps_menu.get_root_directory ().iter ();
@@ -80,12 +75,10 @@
80 categories.add (dir);75 categories.add (dir);
81 }76 }
82 }77 }
83
84 }78 }
8579
86#if HAVE_ZEITGEIST80#if HAVE_ZEITGEIST
87 private void update_popularity () {81 private void update_popularity () {
88
89 foreach (Gee.ArrayList<App> category in apps.values)82 foreach (Gee.ArrayList<App> category in apps.values)
90 foreach (App app in category)83 foreach (App app in category)
91 app.popularity = rl_service.get_app_popularity (app.desktop_id);84 app.popularity = rl_service.get_app_popularity (app.desktop_id);
@@ -93,23 +86,16 @@
93#endif86#endif
9487
95 private void update_apps () {88 private void update_apps () {
96
97 apps.clear ();89 apps.clear ();
9890 foreach (var cat in categories)
99 foreach (var cat in categories) {
100 apps.set (cat.get_name (), get_apps_by_category (cat));91 apps.set (cat.get_name (), get_apps_by_category (cat));
101 }
102
103 }92 }
10493
105 public Gee.ArrayList<GMenu.TreeDirectory> get_categories () {94 public Gee.ArrayList<GMenu.TreeDirectory> get_categories () {
106
107 return categories;95 return categories;
108
109 }96 }
11097
111 public Gee.ArrayList<App> get_apps_by_category (GMenu.TreeDirectory category) {98 public Gee.ArrayList<App> get_apps_by_category (GMenu.TreeDirectory category) {
112
113 var app_list = new Gee.ArrayList<App> ();99 var app_list = new Gee.ArrayList<App> ();
114100
115 var iter = category.iter ();101 var iter = category.iter ();
@@ -130,31 +116,13 @@
130 }116 }
131117
132 return app_list;118 return app_list;
133
134 }119 }
135120
136 public Gee.HashMap<string, Gee.ArrayList<App>> get_apps () {121 public Gee.HashMap<string, Gee.ArrayList<App>> get_apps () {
137
138 return apps;122 return apps;
139
140 }
141
142 public SList<App> get_apps_by_popularity () {
143
144 var sorted_apps = new SList<App> ();
145
146 foreach (Gee.ArrayList<App> category in apps.values) {
147 foreach (App app in category) {
148 sorted_apps.insert_sorted_with_data (app, Utils.sort_apps_by_popularity);
149 }
150 }
151
152 return sorted_apps;
153
154 }123 }
155124
156 public SList<App> get_apps_by_name () {125 public SList<App> get_apps_by_name () {
157
158 var sorted_apps = new SList<App> ();126 var sorted_apps = new SList<App> ();
159 string[] sorted_apps_execs = {};127 string[] sorted_apps_execs = {};
160128
@@ -175,67 +143,5 @@
175 }143 }
176144
177 return sorted_apps;145 return sorted_apps;
178146 }
179 }147}
180
181 public async Gee.ArrayList<App> search_results (string search) {
182
183 Idle.add (search_results.callback, Priority.HIGH);
184 yield;
185
186 var filtered = new Gee.ArrayList<App> ();
187
188 /** It's a bit stupid algorithm, simply check if the char is present
189 * some of the App values, then assign it a double. This is very simple:
190 * if an App name coincide with the search string they have obvious the
191 * same length, then the fraction will be 1.0.
192 * I've added a small multiplier when matching to a exec name, to give
193 * more priority to app.name
194 **/
195 string[] sorted_apps_execs = {};
196
197 foreach (Gee.ArrayList<App> category in apps.values) {
198 foreach (App app in category) {
199 if (!(app.exec in sorted_apps_execs)) {
200 sorted_apps_execs += app.exec;
201 if (app.name != null && search in app.name.down ()) {
202 if (search == app.name.down ()[0:search.length])
203 app.relevancy = 0.5 - app.popularity; // It must be minor than 1.0
204 else
205 app.relevancy = app.name.length / search.length - app.popularity;
206 filtered.add (app);
207 } else if (app.exec != null && search in app.exec.down ()) {
208 app.relevancy = app.exec.length / search.length * 10.0 - app.popularity;
209 filtered.add (app);
210 } else if (app.description != null && search in app.description.down ()) {
211 app.relevancy = app.description.length / search.length - app.popularity;
212 filtered.add (app);
213 } else if (app.generic_name != null && search in app.generic_name.down ()) {
214 app.relevancy = app.generic_name.length / search.length - app.popularity;
215 filtered.add (app);
216 } else if (app.keywords != null) {
217 app.relevancy = 0;
218 foreach (string keyword in app.keywords) {
219 foreach (string search_word in search.split (" ")) {
220 if (search_word in keyword.down ()) {
221 app.relevancy += (keyword.length / search_word.length) * (app.keywords.length / search.split (" ").length) - app.popularity;
222 filtered.add (app);
223 }
224 }
225 }
226 }
227 }
228 }
229 }
230
231 filtered.sort ((a, b) => Utils.sort_apps_by_relevancy ((App) a, (App) b));
232
233 if (filtered.size > 20) {
234 return (Gee.ArrayList<App>) filtered[0:20];
235 } else {
236 return filtered;
237 }
238
239 }
240
241}
242\ No newline at end of file148\ No newline at end of file
243149
=== modified file 'src/Utils.vala'
--- src/Utils.vala 2013-08-15 11:14:46 +0000
+++ src/Utils.vala 2014-08-16 15:16:33 +0000
@@ -29,16 +29,8 @@
29 return widget;29 return widget;
30 }30 }
3131
32 public static int sort_apps_by_popularity (Backend.App a, Backend.App b) {
33 return (int) (b.popularity*1000 - a.popularity*1000);
34 }
35
36 public static int sort_apps_by_name (Backend.App a, Backend.App b) {32 public static int sort_apps_by_name (Backend.App a, Backend.App b) {
37 return a.name.collate (b.name);33 return a.name.collate (b.name);
38 }34 }
39
40 public static int sort_apps_by_relevancy (Backend.App a, Backend.App b) {
41 return (int) (a.relevancy*1000 - b.relevancy*1000);
42 }
43 }35 }
44}36}
45\ No newline at end of file37\ No newline at end of file
4638
=== modified file 'src/Widgets/AppEntry.vala'
--- src/Widgets/AppEntry.vala 2014-05-26 06:11:39 +0000
+++ src/Widgets/AppEntry.vala 2014-08-16 15:16:33 +0000
@@ -92,8 +92,6 @@
92 }92 }
9393
94 protected override bool draw (Cairo.Context cr) {94 protected override bool draw (Cairo.Context cr) {
95
96
97 Gtk.Allocation size;95 Gtk.Allocation size;
98 get_allocation (out size);96 get_allocation (out size);
9997

Subscribers

People subscribed via source and target branches