Merge lp:~submarine/unity-scope-virtualbox/previews into lp:unity-scope-virtualbox

Proposed by David Callé
Status: Merged
Approved by: Michal Hruby
Approved revision: 23
Merged at revision: 21
Proposed branch: lp:~submarine/unity-scope-virtualbox/previews
Merge into: lp:unity-scope-virtualbox
Diff against target: 131 lines (+71/-18)
2 files modified
data/virtualbox.scope.in (+1/-1)
src/unity_virtualbox_daemon.py (+70/-17)
To merge this branch: bzr merge lp:~submarine/unity-scope-virtualbox/previews
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+160328@code.launchpad.net

Commit message

Add previews, displaying the same info as virtualbox details

Description of the change

Add previews, displaying the same info as virtualbox details

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/virtualbox.scope.in'
2--- data/virtualbox.scope.in 2013-03-20 16:43:39 +0000
3+++ data/virtualbox.scope.in 2013-04-23 10:45:34 +0000
4@@ -1,5 +1,5 @@
5 [Scope]
6-DBusName=com.canonical.Unity.Scope.Boxes.VirtualBox
7+DBusName=com.canonical.Unity.Scope.Boxes.Virtualbox
8 DBusPath=/com/canonical/unity/scope/boxes/virtualbox
9 Icon=
10 QueryBinary=virtualbox
11
12=== modified file 'src/unity_virtualbox_daemon.py'
13--- src/unity_virtualbox_daemon.py 2013-03-19 22:30:15 +0000
14+++ src/unity_virtualbox_daemon.py 2013-04-23 10:45:34 +0000
15@@ -21,6 +21,7 @@
16 import re
17 import shlex
18 import gettext
19+import datetime
20
21 APP_NAME = 'unity-scope-virtualbox'
22 LOCAL_PATH = '/usr/share/locale/'
23@@ -72,10 +73,15 @@
24 else:
25 vboxlist = EXTRA_DATA
26 for vbox in vboxlist.splitlines():
27- vbox = re.sub('\{.*\}', '', vbox.decode('utf-8'))
28- if search.lower() in vbox.lower():
29- results.append({'uri':shlex.split(vbox)[0],
30- 'title':shlex.split(vbox)[0]})
31+ vbox_name = re.sub('\{.*\}', '', vbox.decode('utf-8'))
32+ uuid = re.match(r'.*\{(.*)\}', vbox.decode('utf-8'))
33+ if uuid:
34+ uuid = uuid.group(1)
35+ else:
36+ uuid = shlex.split(vbox_name)[0]
37+ if search.lower() in vbox_name.lower():
38+ results.append({'uri':uuid,
39+ 'title':shlex.split(vbox_name)[0]})
40 except Exception as error:
41 print (error)
42 return results
43@@ -114,22 +120,59 @@
44 i['comment'] = ''
45 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
46 i['dnd_uri'] = i['uri']
47- i['metadata'] = {}
48- if EXTRA_METADATA:
49- for e in i:
50- for m in EXTRA_METADATA:
51- if m['id'] == e:
52- i['metadata'][e] = i[e]
53- i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
54- result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
55- i['category'], i['result_type'],
56- str(i['mimetype']), str(i['title']),
57- str(i['comment']), str(i['dnd_uri']),
58- i['metadata'])
59- result_set.add_result(result)
60+ i['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
61+ result_set.add_result(**i)
62 except Exception as error:
63 print (error)
64
65+class Preview (Unity.ResultPreviewer):
66+
67+ def do_run(self):
68+ preview = Unity.GenericPreview.new(self.result.title, self.result.comment, None)
69+ preview.props.image_source_uri = self.result.icon_hint
70+ vboxinfo = subprocess.check_output(['vboxmanage', 'showvminfo', self.result.uri])
71+ description_line = False
72+ for line in vboxinfo.splitlines():
73+ line = line.decode('utf-8')
74+ if line.startswith('Guest OS:'):
75+ os = re.match(r'.*:\s+([^\s].*)',line)
76+ if os:
77+ os_text = os.group(1)
78+ preview.add_info(Unity.InfoHint.new("os", _("Operating System"), None, os_text))
79+ if line.startswith('Memory size:'):
80+ memsize = re.match(r'.*:\s+([^\s].*)',line)
81+ if memsize:
82+ memsize_text = memsize.group(1)
83+ preview.add_info(Unity.InfoHint.new("memsize", _("Base Memory"), None, memsize_text))
84+ if line.startswith('VRAM size:'):
85+ vramsize = re.match(r'.*:\s+([^\s].*)',line)
86+ if vramsize:
87+ vramsize_text = vramsize.group(1)
88+ preview.add_info(Unity.InfoHint.new("vramsize", _("Video Memory"), None, vramsize_text))
89+ if line.startswith('Number of CPUs:'):
90+ numcpu = re.match(r'.*:\s+([^\s].*)',line)
91+ if numcpu:
92+ numcpu_text = numcpu.group(1)
93+ preview.add_info(Unity.InfoHint.new("numcpu", _("Processors"), None, numcpu_text))
94+ if line.startswith('State:'):
95+ state = re.match(r'.*:\s+([^\s].*)\(since\s(.*)\)',line)
96+ if state:
97+ state_text = state.group(1)
98+ date = state.group(2)
99+ translated_date = datetime.datetime.strptime(date[:-3], '%Y-%m-%dT%H:%M:%S.%f')
100+ preview.props.subtitle = state_text.title() + "(%s)" % translated_date.strftime('%c')
101+ if line.startswith('Description:'):
102+ description_line = True
103+ continue
104+ if description_line:
105+ preview.props.description_markup = line
106+ description_line = False
107+
108+ icon = Gio.FileIcon.new (Gio.file_new_for_path(PROVIDER_ICON))
109+ view_action = Unity.PreviewAction.new("launch", _("Launch"), icon)
110+ preview.add_action(view_action)
111+ return preview
112+
113 class Scope (Unity.AbstractScope):
114 def __init__(self):
115 Unity.AbstractScope.__init__(self)
116@@ -181,5 +224,15 @@
117 se = MySearch (search_context)
118 return se
119
120+ def do_create_previewer(self, result, metadata):
121+ rp = Preview()
122+ rp.set_scope_result(result)
123+ rp.set_search_metadata(metadata)
124+ return rp
125+
126+ def do_activate(self, result, metadata, id):
127+ GLib.spawn_async(["/usr/bin/vboxmanage", "startvm", result.uri])
128+ return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri=None)
129+
130 def load_scope():
131 return Scope()

Subscribers

People subscribed via source and target branches

to all changes: