Enigma2-meta: rework plugin meta files and prepare for inclusion into enigma2 transla...
[enigma2.git] / lib / python / Plugins / SystemPlugins / SoftwareManager / plugin.py
index f61ea53c638987cedff432f918669a0f0c93c68b..286636ccf1ef86e472e281a96896d6a8b0cc4533 100755 (executable)
@@ -137,8 +137,8 @@ class UpdatePluginMenu(Screen):
                        self.list.append(("advancedrestore", _("Advanced restore"), _("\nRestore your backups by date." ) + self.oktext, None))
                        self.list.append(("backuplocation", _("Choose backup location"),  _("\nSelect your backup device.\nCurrent device: " ) + config.plugins.configurationbackup.backuplocation.value + self.oktext, None))
                        self.list.append(("backupfiles", _("Choose backup files"),  _("Select files for backup. Currently selected:\n" ) + self.backupdirs + self.oktext, None))
-                       #if config.usage.setup_level.index >= 2: # expert+
-                       #       self.list.append(("ipkg-manager", _("Packet management"),  _("\nView, install and remove available or installed packages." ) + self.oktext, None))
+                       if config.usage.setup_level.index >= 2: # expert+
+                               self.list.append(("ipkg-manager", _("Packet management"),  _("\nView, install and remove available or installed packages." ) + self.oktext, None))
                        self.list.append(("ipkg-source",_("Choose upgrade source"), _("\nEdit the upgrade source address." ) + self.oktext, None))
                        for p in plugins.getPlugins(PluginDescriptor.WHERE_SOFTWAREMANAGER):
                                if p.__call__.has_key("AdvancedSoftwareSupported"):
@@ -307,8 +307,8 @@ class PluginManager(Screen, DreamInfoHandler):
                                <convert type="TemplatedMultiContent">
                                {"templates":
                                        {"default": (51,[
-                                                       MultiContentEntryText(pos = (30, 1), size = (470, 24), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
-                                                       MultiContentEntryText(pos = (30, 25), size = (470, 24), font=1, flags = RT_HALIGN_LEFT, text = 2), # index 2 is the description
+                                                       MultiContentEntryText(pos = (0, 1), size = (470, 24), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
+                                                       MultiContentEntryText(pos = (0, 25), size = (470, 24), font=1, flags = RT_HALIGN_LEFT, text = 2), # index 2 is the description
                                                        MultiContentEntryPixmapAlphaTest(pos = (475, 0), size = (48, 48), png = 5), # index 5 is the status pixmap
                                                        MultiContentEntryPixmapAlphaTest(pos = (0, 49), size = (550, 2), png = 6), # index 6 is the div pixmap
                                                ]),
@@ -326,10 +326,12 @@ class PluginManager(Screen, DreamInfoHandler):
                        <widget source="status" render="Label" position="5,410" zPosition="10" size="540,30" halign="center" valign="center" font="Regular;22" transparent="1" shadowColor="black" shadowOffset="-1,-1" />
                </screen>"""
 
-       def __init__(self, session, plugin_path, args = None):
+       def __init__(self, session, plugin_path = None, args = None):
                Screen.__init__(self, session)
                self.session = session
                self.skin_path = plugin_path
+               if self.skin_path == None:
+                       self.skin_path = resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager")
 
                self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions", "InfobarEPGActions", "HelpActions" ],
                {
@@ -403,22 +405,19 @@ class PluginManager(Screen, DreamInfoHandler):
                        if status == 'update':
                                statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/upgrade.png"))
                                self.statuslist.append(( _("Updating software catalog"), '', _("Searching for available updates. Please wait..." ),'', '', statuspng, divpng, None, '' ))
-                               self["list"].style = "default"
-                               self['list'].setList(self.statuslist)
                        elif status == 'sync':
                                statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/upgrade.png"))
                                self.statuslist.append(( _("Package list update"), '', _("Searching for new installed or removed packages. Please wait..." ),'', '', statuspng, divpng, None, '' ))
-                               self["list"].style = "default"
-                               self['list'].setList(self.statuslist)
                        elif status == 'error':
                                statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/remove.png"))
                                self.statuslist.append(( _("Error"), '', _("There was an error downloading the packetlist. Please try again." ),'', '', statuspng, divpng, None, '' ))
-                               self["list"].style = "default"
-                               self['list'].setList(self.statuslist)
+                       self["list"].style = "default"
+                       self['list'].setList(self.statuslist)
+
 
        def getUpdateInfos(self):
                self.setState('update')
-               iSoftwareTools.getUpdates(self.getUpdateInfosCB)
+               iSoftwareTools.startSoftwareTools(self.getUpdateInfosCB)
 
        def getUpdateInfosCB(self, retval = None):
                if retval is not None:
@@ -427,9 +426,13 @@ class PluginManager(Screen, DreamInfoHandler):
                                        self["status"].setText(_("There are at least ") + str(iSoftwareTools.available_updates) + _(" updates available."))
                                else:
                                        self["status"].setText(_("There are no updates available."))
+                               self.rebuildList()
                        elif retval is False:
-                               self["status"].setText(_("No network connection available."))
-                       self.rebuildList()
+                               self.setState('error')
+                               if iSoftwareTools.NetworkConnectionAvailable:
+                                       self["status"].setText(_("Updatefeed not available."))
+                               else:
+                                       self["status"].setText(_("No network connection available."))
 
        def rebuildList(self, retval = None):
                if self.currentSelectedTag is None:
@@ -586,13 +589,13 @@ class PluginManager(Screen, DreamInfoHandler):
                                                status = "remove"
                                        else:
                                                status = "installed"
-                                       self.list.append(self.buildEntryComponent(name, details, description, packagename, status, selected = selectState))
+                                       self.list.append(self.buildEntryComponent(name, _(details), _(description), packagename, status, selected = selectState))
                                else:
                                        if selectState == True:
                                                status = "install"
                                        else:
                                                status = "installable"
-                                       self.list.append(self.buildEntryComponent(name, details, description, packagename, status, selected = selectState))
+                                       self.list.append(self.buildEntryComponent(name, _(details), _(description), packagename, status, selected = selectState))
                        if len(self.list):
                                self.list.sort(key=lambda x: x[0])
                        self["list"].style = "default"
@@ -634,7 +637,7 @@ class PluginManager(Screen, DreamInfoHandler):
                        elif tag == 'Default':
                                return(( _("Default Settings"), _("View list of available default settings" ), tag, divpng ))
                        elif tag == 'SAT':
-                               return(( _("Satteliteequipment"), _("View list of available Satteliteequipment extensions." ), tag, divpng ))
+                               return(( _("Satellite equipment"), _("View list of available Satellite equipment extensions." ), tag, divpng ))
                        elif tag == 'Software':
                                return(( _("Software"), _("View list of available software extensions" ), tag, divpng ))
                        elif tag == 'Multimedia':
@@ -818,7 +821,7 @@ class PluginManagerHelp(Screen):
                        <widget source="list" render="Listbox" position="5,50" size="550,350" scrollbarMode="showOnDemand" selectionDisabled="1">
                                <convert type="TemplatedMultiContent">
                                        {"template": [
-                                                       MultiContentEntryText(pos = (50, 0), size = (150, 26), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
+                                                       MultiContentEntryText(pos = (50, 0), size = (540, 26), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
                                                        MultiContentEntryText(pos = (50, 27), size = (540, 23), font=1, flags = RT_HALIGN_LEFT, text = 1), # index 1 is the state
                                                        MultiContentEntryPixmapAlphaTest(pos = (0, 1), size = (48, 48), png = 2), # index 2 is the status pixmap
                                                        MultiContentEntryPixmapAlphaTest(pos = (0, 48), size = (550, 2), png = 3), # index 3 is the div pixmap
@@ -901,8 +904,7 @@ class PluginDetails(Screen, DreamInfoHandler):
                self.skin_path = plugin_path
                self.language = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
                self.attributes = None
-               self.translatedAttributes = None
-               DreamInfoHandler.__init__(self, self.statusCallback, blocking = False, language = self.language)
+               DreamInfoHandler.__init__(self, self.statusCallback, blocking = False)
                self.directory = resolveFilename(SCOPE_METADIR)
                if packagedata:
                        self.pluginname = packagedata[0]
@@ -940,8 +942,6 @@ class PluginDetails(Screen, DreamInfoHandler):
                self.package = self.packageDetails[0]
                if self.package[0].has_key("attributes"):
                        self.attributes = self.package[0]["attributes"]
-               if self.package[0].has_key("translation"):
-                       self.translatedAttributes = self.package[0]["translation"]
 
                self.cmdList = []
                self.oktext = _("\nAfter pressing OK, please wait!")
@@ -951,7 +951,7 @@ class PluginDetails(Screen, DreamInfoHandler):
                self.onLayoutFinish.append(self.setInfos)
 
        def setWindowTitle(self):
-               self.setTitle(_("Details for extension: " + self.pluginname))
+               self.setTitle(_("Details for plugin: ") + self.pluginname )
 
        def exit(self):
                self.close(False)
@@ -966,34 +966,26 @@ class PluginDetails(Screen, DreamInfoHandler):
                pass
 
        def setInfos(self):
-               if self.translatedAttributes.has_key("name"):
-                       self.pluginname = self.translatedAttributes["name"]
-               elif self.attributes.has_key("name"):
+               if self.attributes.has_key("screenshot"):
+                       self.loadThumbnail(self.attributes)
+
+               if self.attributes.has_key("name"):
                        self.pluginname = self.attributes["name"]
                else:
                        self.pluginname = _("unknown")
 
-               if self.translatedAttributes.has_key("author"):
-                       self.author = self.translatedAttributes["author"]
-               elif self.attributes.has_key("author"):
+               if self.attributes.has_key("author"):
                        self.author = self.attributes["author"]
                else:
                        self.author = _("unknown")
 
-               if self.translatedAttributes.has_key("description"):
-                       self.description = self.translatedAttributes["description"]
-               elif self.attributes.has_key("description"):
-                       self.description = self.attributes["description"]
+               if self.attributes.has_key("description"):
+                       self.description = _(self.attributes["description"].replace("\\n", "\n"))
                else:
                        self.description = _("No description available.")
 
-               if self.translatedAttributes.has_key("screenshot"):
-                       self.loadThumbnail(self.translatedAttributes)
-               else:
-                       self.loadThumbnail(self.attributes)
-
                self["author"].setText(_("Author: ") + self.author)
-               self["detailtext"].setText(self.description.strip())
+               self["detailtext"].setText(_(self.description))
                if self.pluginstate in ('installable', 'install'):
                        self["key_green"].setText(_("Install"))
                else:
@@ -1003,6 +995,10 @@ class PluginDetails(Screen, DreamInfoHandler):
                thumbnailUrl = None
                if entry.has_key("screenshot"):
                        thumbnailUrl = entry["screenshot"]
+                       if self.language == "de":
+                               if thumbnailUrl[-7:] == "_en.jpg":
+                                       thumbnailUrl = thumbnailUrl[:-7] + "_de.jpg"
+
                if thumbnailUrl is not None:
                        self.thumbnail = "/tmp/" + thumbnailUrl.split('/')[-1]
                        print "[PluginDetails] downloading screenshot " + thumbnailUrl + " to " + self.thumbnail
@@ -1556,24 +1552,31 @@ class PacketManager(Screen):
                pass
 
        def IpkgList_Finished(self, result, retval, extra_args = None):
-               if len(result):
+               if result:
                        self.packetlist = []
                        for x in result.splitlines():
-                               split = x.split(' - ')   #self.blacklisted_packages
-                               if not any(split[0].strip().endswith(x) for x in self.unwanted_extensions):
-                                       self.packetlist.append([split[0].strip(), split[1].strip(),split[2].strip()])
+                               tokens = x.split(' - ')   #self.blacklisted_packages
+                               name = tokens[0].strip()
+                               if not any(name.endswith(x) for x in self.unwanted_extensions):
+                                       l = len(tokens)
+                                       version = l > 1 and tokens[1].strip() or ""
+                                       descr = l > 2 and tokens[2].strip() or ""
+                                       self.packetlist.append([name, version, descr])
                if not self.Console:
                        self.Console = Console()
                cmd = "ipkg list_installed"
                self.Console.ePopen(cmd, self.IpkgListInstalled_Finished)
 
        def IpkgListInstalled_Finished(self, result, retval, extra_args = None):
-               if len(result):
+               if result:
                        self.installed_packetlist = {}
                        for x in result.splitlines():
-                               split = x.split(' - ')
-                               if not any(split[0].strip().endswith(x) for x in self.unwanted_extensions):
-                                       self.installed_packetlist[split[0].strip()] = split[1].strip()
+                               tokens = x.split(' - ')   #self.blacklisted_packages
+                               name = tokens[0].strip()
+                               if not any(name.endswith(x) for x in self.unwanted_extensions):
+                                       l = len(tokens)
+                                       version = l > 1 and tokens[1].strip() or ""
+                                       self.installed_packetlist[name] = version
                self.buildPacketList()
 
        def buildEntryComponent(self, name, version, description, state):
@@ -1692,16 +1695,12 @@ def startSetup(menuid):
                return [ ]
        return [(_("Software management"), UpgradeMain, "software_manager", 50)]
 
-def autostart(reason, **kwargs):
-       if reason is True:
-               iSoftwareTools.startSoftwareTools()
 
 def Plugins(path, **kwargs):
        global plugin_path
        plugin_path = path
        list = [
-               PluginDescriptor(where = [PluginDescriptor.WHERE_NETWORKCONFIG_READ], fnc = autostart),
-               PluginDescriptor(name=_("Software management"), description=_("Manage your receiver's software"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup), 
+               PluginDescriptor(name=_("Software management"), description=_("Manage your receiver's software"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup),
                PluginDescriptor(name=_("Ipkg"), where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan)
        ]
        if config.usage.setup_level.index >= 2: # expert+