Merge lp:~jeremy-munsch/synapse-project/virtualbox-plugin into lp:synapse-project
- virtualbox-plugin
- Merge into trunk
Status: | Needs review | ||||||||
---|---|---|---|---|---|---|---|---|---|
Proposed branch: | lp:~jeremy-munsch/synapse-project/virtualbox-plugin | ||||||||
Merge into: | lp:synapse-project | ||||||||
Diff against target: |
499 lines (+443/-1) 5 files modified
configure.ac (+3/-1) debian/control (+1/-0) src/plugins/Makefile.am (+1/-0) src/plugins/virtualbox-plugin.vala (+437/-0) src/ui/synapse-main.vala (+1/-0) |
||||||||
To merge this branch: | bzr merge lp:~jeremy-munsch/synapse-project/virtualbox-plugin | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rico Tzschichholz | Pending | ||
Review via email: mp+278244@code.launchpad.net |
Commit message
Description of the change
Search for virtual machines and provides actions for it
using libxmlbird since librest xml is buggy/harassing to work with.
- 634. By Rico Tzschichholz
-
ui/controller: Some optimization accessing model.query[] in search*()
- 635. By Rico Tzschichholz
-
core/query: Cache and reuse Regex.escape_string (query)
- 636. By Rico Tzschichholz
-
debian: Bump build-deps accordingly
- 637. By Rico Tzschichholz
-
plugins: Add suport for MATE Screensaver
- 638. By Rico Tzschichholz
-
po: Update translations
- 639. By Rico Tzschichholz
-
desktop-
file-plugin: correct ApplicationsMatch to DesktopFileMatch - 640. By Rico Tzschichholz
-
src: Drop "using Gee;"
- 641. By Rico Tzschichholz
-
src: Drop "using Json;"
- 642. By Rico Tzschichholz
-
src: Drop "using Zeitgeist;"
- 643. By Rico Tzschichholz
-
src: Drop "using Gtk;"
- 644. By Rico Tzschichholz
-
src: Drop "using Cairo;"
- 645. By Rico Tzschichholz
-
src: Drop last usages of "using *;"
- 646. By Rico Tzschichholz
-
ui: Show release-name in about-dialog only
- 647. By Rico Tzschichholz
-
ui: Bump to 2016
- 648. By Rico Tzschichholz
-
Release 0.2.99.2
- 649. By Rico Tzschichholz
-
ui: Set and update client-window of Gtk.IMMulticontext
- 650. By Rico Tzschichholz
-
main: Properly construct OptionEntry
Stop using an empty string where is getting treated as translateable.
- 651. By Michael Aquilina
-
Add pass plugin
- 652. By Rico Tzschichholz
-
Fix non-matching generic types
- 653. By Rico Tzschichholz
-
Fix non-matching generic types of interface implementations
- 654. By Jeremy Munsch
-
add virtualbox plugin
add libxmlbird dependency
Unmerged revisions
- 654. By Jeremy Munsch
-
add virtualbox plugin
add libxmlbird dependency
Preview Diff
1 | === modified file 'configure.ac' | |||
2 | --- configure.ac 2016-02-28 12:40:08 +0000 | |||
3 | +++ configure.ac 2016-12-16 21:07:04 +0000 | |||
4 | @@ -62,7 +62,8 @@ | |||
5 | 62 | gee-0.8 >= $MIN_GEE_VERSION \ | 62 | gee-0.8 >= $MIN_GEE_VERSION \ |
6 | 63 | json-glib-1.0 >= $MIN_JSON_VERSION \ | 63 | json-glib-1.0 >= $MIN_JSON_VERSION \ |
7 | 64 | keybinder-3.0 \ | 64 | keybinder-3.0 \ |
9 | 65 | libnotify | 65 | libnotify \ |
10 | 66 | xmlbird | ||
11 | 66 | ) | 67 | ) |
12 | 67 | SYNAPSE_MODULES_VALAFLAGS=" --pkg gdk-x11-3.0 \ | 68 | SYNAPSE_MODULES_VALAFLAGS=" --pkg gdk-x11-3.0 \ |
13 | 68 | --pkg gtk+-3.0 \ | 69 | --pkg gtk+-3.0 \ |
14 | @@ -71,6 +72,7 @@ | |||
15 | 71 | --pkg gee-0.8 \ | 72 | --pkg gee-0.8 \ |
16 | 72 | --pkg json-glib-1.0 \ | 73 | --pkg json-glib-1.0 \ |
17 | 73 | --pkg keybinder-3.0 \ | 74 | --pkg keybinder-3.0 \ |
18 | 75 | --pkg xmlbird \ | ||
19 | 74 | --pkg libnotify" | 76 | --pkg libnotify" |
20 | 75 | AC_SUBST(SYNAPSE_MODULES_VALAFLAGS) | 77 | AC_SUBST(SYNAPSE_MODULES_VALAFLAGS) |
21 | 76 | 78 | ||
22 | 77 | 79 | ||
23 | === modified file 'debian/control' | |||
24 | --- debian/control 2015-11-30 14:47:10 +0000 | |||
25 | +++ debian/control 2016-12-16 21:07:04 +0000 | |||
26 | @@ -15,6 +15,7 @@ | |||
27 | 15 | libkeybinder-3.0-dev, | 15 | libkeybinder-3.0-dev, |
28 | 16 | libnotify-dev, | 16 | libnotify-dev, |
29 | 17 | librest-dev, | 17 | librest-dev, |
30 | 18 | libxmlbird-dev, | ||
31 | 18 | libappindicator3-dev (>= 0.0.7) | 19 | libappindicator3-dev (>= 0.0.7) |
32 | 19 | Vcs-Bzr: http://bazaar.launchpad.net/~synapse-core/synapse-project/trunk/ | 20 | Vcs-Bzr: http://bazaar.launchpad.net/~synapse-core/synapse-project/trunk/ |
33 | 20 | Vcs-Browser: http://bazaar.launchpad.net/~synapse-core/synapse-project/trunk/files | 21 | Vcs-Browser: http://bazaar.launchpad.net/~synapse-core/synapse-project/trunk/files |
34 | 21 | 22 | ||
35 | === modified file 'src/plugins/Makefile.am' | |||
36 | --- src/plugins/Makefile.am 2016-04-01 05:58:51 +0000 | |||
37 | +++ src/plugins/Makefile.am 2016-12-16 21:07:04 +0000 | |||
38 | @@ -53,6 +53,7 @@ | |||
39 | 53 | test-slow-plugin.vala \ | 53 | test-slow-plugin.vala \ |
40 | 54 | xnoise-media-player-plugin.vala \ | 54 | xnoise-media-player-plugin.vala \ |
41 | 55 | system-management.vala \ | 55 | system-management.vala \ |
42 | 56 | virtualbox-plugin.vala \ | ||
43 | 56 | zeal-plugin.vala \ | 57 | zeal-plugin.vala \ |
44 | 57 | $(NULL) | 58 | $(NULL) |
45 | 58 | 59 | ||
46 | 59 | 60 | ||
47 | === added file 'src/plugins/virtualbox-plugin.vala' | |||
48 | --- src/plugins/virtualbox-plugin.vala 1970-01-01 00:00:00 +0000 | |||
49 | +++ src/plugins/virtualbox-plugin.vala 2016-12-16 21:07:04 +0000 | |||
50 | @@ -0,0 +1,437 @@ | |||
51 | 1 | /* | ||
52 | 2 | * Copyright (C) 2015 Jérémy Munsch <jeremy.munsch@gmail.com> | ||
53 | 3 | * | ||
54 | 4 | * This program is free software; you can redistribute it and/or modify | ||
55 | 5 | * it under the terms of the GNU General Public License as published by | ||
56 | 6 | * the Free Software Foundation; either version 2 of the License, or | ||
57 | 7 | * (at your option) any later version. | ||
58 | 8 | * | ||
59 | 9 | * This program is distributed in the hope that it will be useful, | ||
60 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
61 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
62 | 12 | * GNU General Public License for more details. | ||
63 | 13 | * | ||
64 | 14 | * You should have received a copy of the GNU General Public License | ||
65 | 15 | * along with this program; if not, write to the Free Software | ||
66 | 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
67 | 17 | * | ||
68 | 18 | * Note : | ||
69 | 19 | * Using libxmlbird since librest is buggy/pain to use | ||
70 | 20 | * | ||
71 | 21 | * What is does : | ||
72 | 22 | * Search hosts virtual machines and provides | ||
73 | 23 | * some actions took from virtualbox --help | ||
74 | 24 | */ | ||
75 | 25 | |||
76 | 26 | using B; | ||
77 | 27 | |||
78 | 28 | namespace Synapse | ||
79 | 29 | { | ||
80 | 30 | private errordomain VMParseError { ERROR } | ||
81 | 31 | |||
82 | 32 | public class VirtualBoxPlugin : Object, Activatable, ItemProvider, ActionProvider | ||
83 | 33 | { | ||
84 | 34 | public bool enabled { get; set; default = true; } | ||
85 | 35 | |||
86 | 36 | public static string virtualbox_config_dir { get; private set; default = "VirtualBox"; } | ||
87 | 37 | public static string virtualbox_vm_dir { get; private set; } | ||
88 | 38 | |||
89 | 39 | private Gee.List<VirtualBoxMachineMatch> machines; | ||
90 | 40 | private Gee.List<VirtualBoxAction> actions; | ||
91 | 41 | |||
92 | 42 | public void activate () | ||
93 | 43 | { | ||
94 | 44 | parse_vm_config.begin (); | ||
95 | 45 | } | ||
96 | 46 | |||
97 | 47 | public void deactivate () | ||
98 | 48 | { | ||
99 | 49 | } | ||
100 | 50 | |||
101 | 51 | static void register_plugin () | ||
102 | 52 | { | ||
103 | 53 | PluginRegistry.get_default ().register_plugin ( | ||
104 | 54 | typeof (VirtualBoxPlugin), | ||
105 | 55 | _("VirtualBox"), | ||
106 | 56 | _("Control you virtual machines"), | ||
107 | 57 | "virtualbox", | ||
108 | 58 | register_plugin, | ||
109 | 59 | Environment.find_program_in_path ("virtualbox") != null, | ||
110 | 60 | _("Unable to find \"virtualbox\" program") | ||
111 | 61 | ); | ||
112 | 62 | } | ||
113 | 63 | |||
114 | 64 | static construct | ||
115 | 65 | { | ||
116 | 66 | register_plugin (); | ||
117 | 67 | virtualbox_config_dir = Path.build_filename (Environment.get_user_config_dir (), virtualbox_config_dir); | ||
118 | 68 | } | ||
119 | 69 | |||
120 | 70 | construct | ||
121 | 71 | { | ||
122 | 72 | machines = new Gee.ArrayList<VirtualBoxMachineMatch> (); | ||
123 | 73 | actions = new Gee.ArrayList<VirtualBoxAction> (); | ||
124 | 74 | actions.add (new StartVirtualMachine ()); | ||
125 | 75 | actions.add (new StartFullscreenVirtualMachine ()); | ||
126 | 76 | actions.add (new StartSeemlessVirtualMachine ()); | ||
127 | 77 | actions.add (new StartScaleVirtualMachine ()); | ||
128 | 78 | actions.add (new RestoreVirtualMachine ()); | ||
129 | 79 | actions.add (new StartPausedVirtualMachine ()); | ||
130 | 80 | actions.add (new StartSeparateVirtualMachine ()); | ||
131 | 81 | } | ||
132 | 82 | |||
133 | 83 | public bool handles_query (Query query) | ||
134 | 84 | { | ||
135 | 85 | return (QueryFlags.APPLICATIONS in query.query_type); | ||
136 | 86 | } | ||
137 | 87 | |||
138 | 88 | public async ResultSet? search (Query q) throws SearchError | ||
139 | 89 | { | ||
140 | 90 | var results = new ResultSet (); | ||
141 | 91 | |||
142 | 92 | var matchers = Query.get_matchers_for_query (q.query_string, MatcherFlags.NO_FUZZY, RegexCompileFlags.OPTIMIZE | RegexCompileFlags.CASELESS); | ||
143 | 93 | foreach (var matcher in matchers) | ||
144 | 94 | { | ||
145 | 95 | foreach (var machine in machines) | ||
146 | 96 | { | ||
147 | 97 | q.check_cancellable (); | ||
148 | 98 | if (matcher.key.match (machine.title)) | ||
149 | 99 | { | ||
150 | 100 | results.add (machine, matcher.value); | ||
151 | 101 | } | ||
152 | 102 | } | ||
153 | 103 | } | ||
154 | 104 | return results; | ||
155 | 105 | } | ||
156 | 106 | |||
157 | 107 | public ResultSet? find_for_match (ref Query q, Match match) | ||
158 | 108 | { | ||
159 | 109 | if (!actions[0].valid_for_match (match)) return null; | ||
160 | 110 | |||
161 | 111 | var matchers = Query.get_matchers_for_query (q.query_string, 0, RegexCompileFlags.OPTIMIZE | RegexCompileFlags.CASELESS); | ||
162 | 112 | |||
163 | 113 | var results = new ResultSet (); | ||
164 | 114 | foreach (var matcher in matchers) | ||
165 | 115 | { | ||
166 | 116 | foreach (var action in actions) | ||
167 | 117 | { | ||
168 | 118 | if (matcher.key.match (action.title)) | ||
169 | 119 | { | ||
170 | 120 | int relevancy = (match is StartVirtualMachine) ? | ||
171 | 121 | action.default_relevancy : | ||
172 | 122 | action.default_relevancy - MatchScore.INCREMENT_MINOR; | ||
173 | 123 | results.add (action, relevancy); | ||
174 | 124 | } | ||
175 | 125 | } | ||
176 | 126 | } | ||
177 | 127 | return results; | ||
178 | 128 | } | ||
179 | 129 | |||
180 | 130 | |||
181 | 131 | /** | ||
182 | 132 | * Actions | ||
183 | 133 | */ | ||
184 | 134 | |||
185 | 135 | private abstract class VirtualBoxAction : Action | ||
186 | 136 | { | ||
187 | 137 | public abstract string command { get; set; } | ||
188 | 138 | public new virtual int default_relevancy { get; set; default = MatchScore.AVERAGE; } | ||
189 | 139 | |||
190 | 140 | public override bool valid_for_match (Match match) | ||
191 | 141 | { | ||
192 | 142 | return (match is VirtualBoxMachineMatch); | ||
193 | 143 | } | ||
194 | 144 | |||
195 | 145 | public override void do_execute (Match match, Match? target = null) | ||
196 | 146 | { | ||
197 | 147 | string cmd = command.printf (((VirtualBoxMachineMatch)match).uuid); | ||
198 | 148 | try | ||
199 | 149 | { | ||
200 | 150 | AppInfo ai = AppInfo.create_from_commandline (cmd, "virtualbox", 0); | ||
201 | 151 | if (!ai.launch (null, null)) | ||
202 | 152 | warning ("Could not launch VirtualBox %s".printf (cmd)); | ||
203 | 153 | } | ||
204 | 154 | catch (Error err) | ||
205 | 155 | { | ||
206 | 156 | warning ("Could not launch %s %s", cmd, err.message); | ||
207 | 157 | } | ||
208 | 158 | } | ||
209 | 159 | } | ||
210 | 160 | |||
211 | 161 | private class StartVirtualMachine : VirtualBoxAction | ||
212 | 162 | { | ||
213 | 163 | public override string command { get; set; default = "virtualbox --startvm %s"; } | ||
214 | 164 | public StartVirtualMachine () | ||
215 | 165 | { | ||
216 | 166 | Object (title: _("Turn on"), | ||
217 | 167 | description: _("Start the virtual machine"), | ||
218 | 168 | icon_name: "virtualbox", | ||
219 | 169 | has_thumbnail: false); | ||
220 | 170 | default_relevancy = MatchScore.HIGHEST; | ||
221 | 171 | } | ||
222 | 172 | } | ||
223 | 173 | |||
224 | 174 | private class StartFullscreenVirtualMachine : VirtualBoxAction | ||
225 | 175 | { | ||
226 | 176 | public override string command { get; set; default = "virtualbox --startvm %s --fullscreen"; } | ||
227 | 177 | public StartFullscreenVirtualMachine () | ||
228 | 178 | { | ||
229 | 179 | Object (title: _("Fullscreen"), | ||
230 | 180 | description: _("Start the virtual machine in fullscreen mode"), | ||
231 | 181 | icon_name: "virtualbox", | ||
232 | 182 | has_thumbnail: true); | ||
233 | 183 | } | ||
234 | 184 | } | ||
235 | 185 | |||
236 | 186 | private class StartSeemlessVirtualMachine : VirtualBoxAction | ||
237 | 187 | { | ||
238 | 188 | public override string command { get; set; default = "virtualbox --startvm %s --seamless"; } | ||
239 | 189 | public StartSeemlessVirtualMachine () | ||
240 | 190 | { | ||
241 | 191 | Object (title: _("Seamless"), | ||
242 | 192 | description: _("Start the virtual machine in seamless mode"), | ||
243 | 193 | icon_name: "virtualbox", | ||
244 | 194 | has_thumbnail: false); | ||
245 | 195 | } | ||
246 | 196 | } | ||
247 | 197 | |||
248 | 198 | private class StartScaleVirtualMachine : VirtualBoxAction | ||
249 | 199 | { | ||
250 | 200 | public override string command { get; set; default = "virtualbox --startvm %s --scale"; } | ||
251 | 201 | public StartScaleVirtualMachine () | ||
252 | 202 | { | ||
253 | 203 | Object (title: _("Scale"), | ||
254 | 204 | description: _("Start the virtual machine in scale mode"), | ||
255 | 205 | icon_name: "virtualbox", | ||
256 | 206 | has_thumbnail: false); | ||
257 | 207 | } | ||
258 | 208 | } | ||
259 | 209 | |||
260 | 210 | private class RestoreVirtualMachine : VirtualBoxAction | ||
261 | 211 | { | ||
262 | 212 | public override string command { get; set; default = "virtualbox --startvm %s --restore"; } | ||
263 | 213 | public RestoreVirtualMachine () | ||
264 | 214 | { | ||
265 | 215 | Object (title: _("Restore"), | ||
266 | 216 | description: _("Restore the last vitual machine state"), | ||
267 | 217 | icon_name: "virtualbox", | ||
268 | 218 | has_thumbnail: false); | ||
269 | 219 | } | ||
270 | 220 | } | ||
271 | 221 | |||
272 | 222 | private class StartPausedVirtualMachine : VirtualBoxAction | ||
273 | 223 | { | ||
274 | 224 | public override string command { get; set; default = "virtualbox --startvm %s --start-paused"; } | ||
275 | 225 | public StartPausedVirtualMachine () | ||
276 | 226 | { | ||
277 | 227 | Object (title: _("Start Paused"), | ||
278 | 228 | description: _("Start the virtual machine in paused state"), | ||
279 | 229 | icon_name: "virtualbox", | ||
280 | 230 | has_thumbnail: false); | ||
281 | 231 | } | ||
282 | 232 | } | ||
283 | 233 | |||
284 | 234 | private class StartSeparateVirtualMachine : VirtualBoxAction | ||
285 | 235 | { | ||
286 | 236 | public override string command { get; set; default = "virtualbox --startvm %s --separate"; } | ||
287 | 237 | public StartSeparateVirtualMachine () | ||
288 | 238 | { | ||
289 | 239 | Object (title: _("Start Separated"), | ||
290 | 240 | description: _("Start the virtual machine in a separate process"), | ||
291 | 241 | icon_name: "virtualbox", | ||
292 | 242 | has_thumbnail: false); | ||
293 | 243 | } | ||
294 | 244 | } | ||
295 | 245 | |||
296 | 246 | |||
297 | 247 | /** | ||
298 | 248 | * Match | ||
299 | 249 | */ | ||
300 | 250 | |||
301 | 251 | private class VirtualBoxMachineMatch : Match | ||
302 | 252 | { | ||
303 | 253 | public string name { get; set; } | ||
304 | 254 | public string uuid { get; set; } | ||
305 | 255 | public string src { get; set; } | ||
306 | 256 | public string os_type { get; set; } | ||
307 | 257 | |||
308 | 258 | public VirtualBoxMachineMatch (string name, string uuid, string src, string os_type) | ||
309 | 259 | { | ||
310 | 260 | Object (title: "VM %s %s".printf (name, os_type), | ||
311 | 261 | description : "", | ||
312 | 262 | icon_name: "virtualbox", | ||
313 | 263 | has_thumbnail: false); | ||
314 | 264 | this.uuid = uuid; | ||
315 | 265 | this.src = src; | ||
316 | 266 | this.os_type = os_type; | ||
317 | 267 | } | ||
318 | 268 | } | ||
319 | 269 | |||
320 | 270 | |||
321 | 271 | /** | ||
322 | 272 | * private methods | ||
323 | 273 | */ | ||
324 | 274 | |||
325 | 275 | private async void parse_vm_config () | ||
326 | 276 | { | ||
327 | 277 | try | ||
328 | 278 | { | ||
329 | 279 | Gee.List<Tag> results = new Gee.ArrayList<Tag> (); | ||
330 | 280 | string vm_config_file = Path.build_filename (virtualbox_config_dir, "VirtualBox.xml"); | ||
331 | 281 | |||
332 | 282 | Tag root = parse_xml_file (vm_config_file); | ||
333 | 283 | |||
334 | 284 | if (null == root) | ||
335 | 285 | throw new VMParseError.ERROR ("Failed to parse VirtualBox config file %s".printf (vm_config_file)); | ||
336 | 286 | |||
337 | 287 | find_all_tags ("MachineEntry", root, ref results); | ||
338 | 288 | |||
339 | 289 | foreach (var machine_entry in results) | ||
340 | 290 | { | ||
341 | 291 | string uuid = get_attribute ("uuid", machine_entry) ?? null; | ||
342 | 292 | string src = get_attribute ("src", machine_entry) ?? null; | ||
343 | 293 | |||
344 | 294 | if (null == uuid || null == src) | ||
345 | 295 | throw new VMParseError.ERROR ("Could not get uuid %s or src %s from MachineEntry %s".printf (uuid, src, vm_config_file)); | ||
346 | 296 | |||
347 | 297 | Idle.add_full (Priority.DEFAULT_IDLE, parse_vm_config.callback); | ||
348 | 298 | yield; | ||
349 | 299 | |||
350 | 300 | Tag machine_tag = parse_xml_file (src); | ||
351 | 301 | |||
352 | 302 | if (null == machine_tag) | ||
353 | 303 | { | ||
354 | 304 | message ("Failed to parse VirtualBox config file %s".printf (src)); | ||
355 | 305 | continue; | ||
356 | 306 | } | ||
357 | 307 | |||
358 | 308 | machine_tag = find_first_tag ("Machine", machine_tag); | ||
359 | 309 | |||
360 | 310 | if (null == machine_tag) | ||
361 | 311 | { | ||
362 | 312 | message ("Could not get Machine from %s".printf (src)); | ||
363 | 313 | continue; | ||
364 | 314 | } | ||
365 | 315 | |||
366 | 316 | string name = get_attribute ("name", machine_tag) ?? null; | ||
367 | 317 | string os_type = get_attribute ("OSType", machine_tag) ?? null; | ||
368 | 318 | |||
369 | 319 | if (null == name || null == os_type) | ||
370 | 320 | { | ||
371 | 321 | message ("Could not get name %s or ostype %s from MachineEntry %s".printf (name, os_type, src)); | ||
372 | 322 | continue; | ||
373 | 323 | } | ||
374 | 324 | |||
375 | 325 | machines.add (new VirtualBoxMachineMatch (name, uuid, src, parse_os (os_type))); | ||
376 | 326 | } | ||
377 | 327 | } | ||
378 | 328 | catch (Error e) | ||
379 | 329 | { | ||
380 | 330 | warning ("%s".printf (e.message)); | ||
381 | 331 | } | ||
382 | 332 | } | ||
383 | 333 | |||
384 | 334 | private string parse_os (string os_info) | ||
385 | 335 | { | ||
386 | 336 | int _pos = os_info.index_of_char ('_'); | ||
387 | 337 | // 0: arch, 1: os, 2: version | ||
388 | 338 | string os[3] = { -1 != _pos ? os_info.slice (_pos, os_info.length).replace ("_", "x") : "", | ||
389 | 339 | -1 != _pos ? os_info.slice (0, _pos).replace ("_", "x") : os_info, | ||
390 | 340 | "" }; | ||
391 | 341 | try | ||
392 | 342 | { | ||
393 | 343 | os[2] = (new Regex ("[a-zA-Z]")).replace (os[1], os[1].length, 0, ""); | ||
394 | 344 | os[1] = os[1].replace (os[2], ""); | ||
395 | 345 | switch (os[1]) | ||
396 | 346 | { | ||
397 | 347 | case "Linux": | ||
398 | 348 | if (os[2].length > 1) // eg: 22 -> 2.2 | ||
399 | 349 | os[2] = os[2].substring (0, 1) + "." + os[2].substring (1); | ||
400 | 350 | break; | ||
401 | 351 | case "MacOS": | ||
402 | 352 | if (os[2].length > 2) // eg: 106 -> 10.6 | ||
403 | 353 | os[2] = os[2].substring (0, 2) + "." + os[2].substring (2); | ||
404 | 354 | break; | ||
405 | 355 | case "Windows": | ||
406 | 356 | if ("81" == os[2]) | ||
407 | 357 | os[2] = "8.1"; | ||
408 | 358 | break; | ||
409 | 359 | case "L": | ||
410 | 360 | os[1] = "L4"; | ||
411 | 361 | os[2] = ""; | ||
412 | 362 | break; | ||
413 | 363 | case "OSx": // IBM | ||
414 | 364 | os[1] = "OS/x"; | ||
415 | 365 | os[2] = "21"; | ||
416 | 366 | break; | ||
417 | 367 | case "OS2Warp45": // IBM | ||
418 | 368 | os[1] = "OS/2 Warp"; | ||
419 | 369 | os[2] = "45"; | ||
420 | 370 | break; | ||
421 | 371 | case "OS2Warp4": // IBM | ||
422 | 372 | os[1] = "OS/2 Warp"; | ||
423 | 373 | os[2] = "4"; | ||
424 | 374 | break; | ||
425 | 375 | case "OSeCS": // IBM | ||
426 | 376 | os[1] = "OS/2 eCS"; | ||
427 | 377 | os[2] = ""; | ||
428 | 378 | break; | ||
429 | 379 | } | ||
430 | 380 | } | ||
431 | 381 | catch (Error e) | ||
432 | 382 | { | ||
433 | 383 | warning ("%s".printf (e.message)); | ||
434 | 384 | } | ||
435 | 385 | return "%s %s %s%s".printf (os[1], os[2], string.nfill (3-os[0].length, ' '), os[0]); | ||
436 | 386 | } | ||
437 | 387 | |||
438 | 388 | /** | ||
439 | 389 | * Xml methods | ||
440 | 390 | */ | ||
441 | 391 | |||
442 | 392 | private void find_all_tags (string tag_name, Tag root, ref Gee.List<Tag> results) | ||
443 | 393 | { | ||
444 | 394 | foreach (Tag tag in root) { | ||
445 | 395 | if (tag_name == tag.get_name ()) | ||
446 | 396 | results.add (tag); | ||
447 | 397 | else | ||
448 | 398 | find_all_tags (tag_name, tag, ref results); | ||
449 | 399 | } | ||
450 | 400 | } | ||
451 | 401 | |||
452 | 402 | private Tag? find_first_tag (string tag_name, Tag root) | ||
453 | 403 | { | ||
454 | 404 | foreach (Tag tag in root) { | ||
455 | 405 | if (tag_name == tag.get_name ()) | ||
456 | 406 | return tag; | ||
457 | 407 | else | ||
458 | 408 | find_first_tag (tag_name, tag); | ||
459 | 409 | } | ||
460 | 410 | return null; | ||
461 | 411 | } | ||
462 | 412 | |||
463 | 413 | private string? get_attribute (string attribute_name, Tag tag) { | ||
464 | 414 | foreach (Attribute attribute in tag.get_attributes ()) { | ||
465 | 415 | if (attribute_name == attribute.get_name ()) | ||
466 | 416 | return attribute.get_content (); | ||
467 | 417 | } | ||
468 | 418 | return null; | ||
469 | 419 | } | ||
470 | 420 | |||
471 | 421 | private Tag parse_xml_file (string file) throws FileError, VMParseError | ||
472 | 422 | { | ||
473 | 423 | size_t length; | ||
474 | 424 | string read; | ||
475 | 425 | FileUtils.get_contents (file, out read, out length); | ||
476 | 426 | |||
477 | 427 | XmlParser parser = new XmlParser (read); | ||
478 | 428 | |||
479 | 429 | if (!parser.validate ()) | ||
480 | 430 | { | ||
481 | 431 | throw new VMParseError.ERROR ("Invalid XML %s".printf (file)); | ||
482 | 432 | } | ||
483 | 433 | |||
484 | 434 | return parser.get_root_tag (); | ||
485 | 435 | } | ||
486 | 436 | } | ||
487 | 437 | } | ||
488 | 0 | 438 | ||
489 | === modified file 'src/ui/synapse-main.vala' | |||
490 | --- src/ui/synapse-main.vala 2016-04-01 05:58:51 +0000 | |||
491 | +++ src/ui/synapse-main.vala 2016-12-16 21:07:04 +0000 | |||
492 | @@ -183,6 +183,7 @@ | |||
493 | 183 | #endif | 183 | #endif |
494 | 184 | #if HAVE_LIBREST | 184 | #if HAVE_LIBREST |
495 | 185 | typeof (ImgUrPlugin), | 185 | typeof (ImgUrPlugin), |
496 | 186 | typeof (VirtualBoxPlugin), | ||
497 | 186 | #endif | 187 | #endif |
498 | 187 | // action-only plugins | 188 | // action-only plugins |
499 | 188 | typeof (DevhelpPlugin), | 189 | typeof (DevhelpPlugin), |