diff --git a/src/QuickReports.py b/src/QuickReports.py index d24fa2f51..20ce14dea 100644 --- a/src/QuickReports.py +++ b/src/QuickReports.py @@ -53,11 +53,65 @@ import gtk # GRAMPS modules # #------------------------------------------------------------------------- - +from gui.pluginmanager import GuiPluginManager from gen.plug import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, CATEGORY_QR_MEDIA, CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, CATEGORY_QR_MISC, - CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY, CATEGORY_QR_NOTE) -from gui.pluginmanager import GuiPluginManager + CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY, + CATEGORY_QR_NOTE) + +def flatten(L): + """ + Flattens a possibly nested list. Removes None results, too. + """ + retval = [] + if isinstance(L, (list, tuple)): + for item in L: + fitem = flatten(item) + if fitem is not None: + retval.extend(fitem) + elif L is not None: + retval.append(L) + return retval + +def create_web_connect_menu(dbstate, uistate, nav_group, handle): + """ + This functions querries the registered web connects. It collects + the connects of the requested category, which must be one of + nav_group. + + It constructs the ui string of the menu, and it's actions. The + action callback function is constructed, using the dbstate and the + handle as input method. A tuple is returned, containing the ui + string of the menu, and its associated actions. + """ + actions = [] + ofile = StringIO() + ofile.write('') + actions.append(('WebConnect', None, _("Web Connect"), None, None, None)) + menu = gtk.Menu() + menu.show() + #select the web connects to show + showlst = [] + pmgr = GuiPluginManager.get_instance() + plugins = pmgr.process_plugin_data('WebConnect') + try: + connections = [plug(nav_group) if callable(plug) else plug + for plug in plugins] + except: + import traceback + traceback.print_exc() + connections = [] + connections = flatten(connections) + connections.sort(key=lambda plug: plug.name) + actions = [] + for connect in connections: + ofile.write('' % connect.key) + actions.append((connect.key, None, connect.name, None, None, + connect(dbstate, uistate, nav_group, handle))) + ofile.write('') + retval = [ofile.getvalue()] + retval.extend(actions) + return retval def create_quickreport_menu(category,dbstate,uistate, handle) : """ This functions querries the registered quick reports with diff --git a/src/gui/views/listview.py b/src/gui/views/listview.py index 574d9f731..3318fc4ff 100644 --- a/src/gui/views/listview.py +++ b/src/gui/views/listview.py @@ -744,7 +744,8 @@ class ListView(NavigationView): """ if not self.dbstate.open: return False - from QuickReports import create_quickreport_menu + from QuickReports import (create_quickreport_menu, + create_web_connect_menu) if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: if self.type_list() == LISTFLAT: self.edit(obj) @@ -782,6 +783,23 @@ class ListView(NavigationView): add_menuitem(qr_menu, action[2], None, action[5]) self.uistate.uimanager.get_widget('/Popup/QuickReport').\ set_submenu(qr_menu) + if menu and self.get_active(): + popup = self.uistate.uimanager.get_widget('/Popup/WebConnect') + if popup: + qr_menu = popup.get_submenu() + webconnects = [] + if qr_menu: + popup.remove_submenu() + webconnects = create_web_connect_menu( + self.dbstate, + self.uistate, + self.navigation_type(), + self.first_selected()) + if len(webconnects) > 1 : + qr_menu = gtk.Menu() + for action in webconnects[1:] : + add_menuitem(qr_menu, action[2], None, action[5]) + popup.set_submenu(qr_menu) if menu: menu.popup(None, None, None, event.button, event.time) return True diff --git a/src/plugins/lib/libpersonview.py b/src/plugins/lib/libpersonview.py index cbda32f95..3e532f04e 100644 --- a/src/plugins/lib/libpersonview.py +++ b/src/plugins/lib/libpersonview.py @@ -230,6 +230,9 @@ class BasePersonView(ListView): + + + ''' @@ -326,6 +329,7 @@ class BasePersonView(ListView): ('Edit', gtk.STOCK_EDIT, _("action|_Edit..."), "Return", _("Edit the selected person"), self.edit), ('QuickReport', None, _("Quick View"), None, None, None), + ('WebConnect', None, _("Web Connection"), None, None, None), ('Dummy', None, ' ', None, None, self.dummy_report), ])