Espionage new feature: activatable services

A new group in the left list show all the services that can be activated on the bus.
Clicking on a name will ask dbus to activate it and wait for the name to become
active, once activation is completed the new name is introspected and showed
on the right list.
This commit is contained in:
Davide Andreoli 2013-11-28 22:35:57 +01:00
parent a0de67e035
commit ca6a035a43
1 changed files with 52 additions and 11 deletions

View File

@ -35,6 +35,7 @@ from efl.elementary.entry import Entry, \
from efl.elementary.flipselector import FlipSelector
from efl.elementary.label import Label
from efl.elementary.panes import Panes
from efl.elementary.progressbar import Progressbar
from efl.elementary.popup import Popup
from efl.elementary.separator import Separator
from efl.elementary.table import Table
@ -275,6 +276,8 @@ class NamesList(Genlist):
self.win = parent
self.sig1 = None
self.waiting_activation = None
self.waiting_popup = None
# create the genlist
Genlist.__init__(self, parent)
@ -282,11 +285,17 @@ class NamesList(Genlist):
self.itc_g = NamesListGroupItemClass()
self.callback_selected_add(self.item_selected_cb)
# add private & public group items
# add public group item
self.public_group = self.item_append(self.itc_g, "Public Services",
flags=ELM_GENLIST_ITEM_GROUP)
self.public_group.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)
# add activatables group item
self.activatable_group = self.item_append(self.itc_g, "Activatable Services",
flags=ELM_GENLIST_ITEM_GROUP)
self.activatable_group.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)
# add private group item
if options.show_private_stuff:
self.private_group = self.item_append(self.itc_g, "Private Services",
flags=ELM_GENLIST_ITEM_GROUP)
@ -296,9 +305,15 @@ class NamesList(Genlist):
self.populate()
def populate(self):
for name in bus.list_names():
active = set(bus.list_names())
activatables = set(bus.list_activatable_names()) - active
for name in active:
self.service_add(name)
for name in activatables:
self.service_activatable_add(name)
# keep the list updated when a name changes
if self.sig1: self.sig1.remove()
self.sig1 = bus.add_signal_receiver(self.name_owner_changed_cb,
@ -313,22 +328,50 @@ class NamesList(Genlist):
def item_selected_cb(self, gl, item):
name = item.data
self.win.detail_list.populate(name)
if item.parent is self.activatable_group:
# activate the service, async with a cool popup
bus.call_async("org.freedesktop.DBus", "/", "org.freedesktop.DBus",
"StartServiceByName", "su", (name, 0), None, None)
spinner = Progressbar(self.win, style="wheel", pulse_mode=True)
spinner.pulse(True)
def stop_waiting_cb(btn):
self.waiting_popup.delete()
self.waiting_activation = None
button = Button(self.win, text="Stop waiting")
button.callback_clicked_add(stop_waiting_cb)
popup = Popup(self.win, content=spinner)
popup.part_text_set('title,text', 'Activating service...')
popup.part_content_set('button1', button)
popup.show()
self.waiting_activation = name
self.waiting_popup = popup
else:
self.win.detail_list.populate(name)
def sort_cb(self, it1, it2):
return 1 if it1.data.lower() < it2.data.lower() else -1
def service_activatable_add(self, name):
self.item_sorted_insert(self.itc, name, self.sort_cb,
self.activatable_group, 0, None)
def service_add(self, name):
# print("service_add('%s')" % name)
if name.startswith(":"):
if options.show_private_stuff:
self.item_sorted_insert(self.itc, name, self.sort_cb,
self.private_group, 0, None)
item = self.item_sorted_insert(self.itc, name, self.sort_cb,
self.private_group, 0, None)
else:
self.item_sorted_insert(self.itc, name, self.sort_cb,
self.public_group, 0, None)
item = self.item_sorted_insert(self.itc, name, self.sort_cb,
self.public_group, 0, None)
if self.waiting_activation is not None and name == self.waiting_activation:
self.waiting_popup.delete()
self.waiting_activation = None
item.selected = True
item.show()
def service_del(self, name):
# print("service_del('%s')" % name)
item = self.first_item
while item:
if item.data == name:
@ -337,8 +380,6 @@ class NamesList(Genlist):
item = item.next
def name_owner_changed_cb(self, name, old_owner, new_owner):
# print("NameOwnerChanged(name='%s', old_owner='%s', new_owner='%s')" %
# (name, old_owner, new_owner))
if old_owner == '':
self.service_add(name)
elif new_owner == '':