diff --git a/backends/alpm/pk-backend-alpm.c b/backends/alpm/pk-backend-alpm.c index 25fbda6..d63b178 100644 --- a/backends/alpm/pk-backend-alpm.c +++ b/backends/alpm/pk-backend-alpm.c @@ -1465,6 +1465,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/apt.deprecated/pk-backend-apt.c b/backends/apt.deprecated/pk-backend-apt.c index e3499e3..70dec9e 100644 --- a/backends/apt.deprecated/pk-backend-apt.c +++ b/backends/apt.deprecated/pk-backend-apt.c @@ -245,6 +245,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ NULL, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c index 901c59c..5e1126c 100644 --- a/backends/apt/pk-backend-apt.c +++ b/backends/apt/pk-backend-apt.c @@ -343,6 +343,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ backend_download_packages, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ #ifdef HAVE_PYTHON_META_RELEASE diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c index 952f235..d7941eb 100644 --- a/backends/box/pk-backend-box.c +++ b/backends/box/pk-backend-box.c @@ -669,6 +669,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ NULL, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/conary/pk-backend-conary.c b/backends/conary/pk-backend-conary.c index b893e62..fea37b6 100644 --- a/backends/conary/pk-backend-conary.c +++ b/backends/conary/pk-backend-conary.c @@ -280,6 +280,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ NULL, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/dummy/pk-backend-dummy.c b/backends/dummy/pk-backend-dummy.c index 0632770..42fcd96 100644 --- a/backends/dummy/pk-backend-dummy.c +++ b/backends/dummy/pk-backend-dummy.c @@ -931,6 +931,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ backend_download_packages, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ backend_get_distro_upgrades, /* get_distro_upgrades */ diff --git a/backends/opkg/pk-backend-opkg.c b/backends/opkg/pk-backend-opkg.c index ff184f2..f39feba 100644 --- a/backends/opkg/pk-backend-opkg.c +++ b/backends/opkg/pk-backend-opkg.c @@ -723,6 +723,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ NULL, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ NULL, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/pisi/pk-backend-pisi.c b/backends/pisi/pk-backend-pisi.c index 14db961..f6454b7 100644 --- a/backends/pisi/pk-backend-pisi.c +++ b/backends/pisi/pk-backend-pisi.c @@ -368,6 +368,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/poldek/pk-backend-poldek.c b/backends/poldek/pk-backend-poldek.c index eebf6bb..d7a1172 100644 --- a/backends/poldek/pk-backend-poldek.c +++ b/backends/poldek/pk-backend-poldek.c @@ -2849,6 +2849,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_get_cancel, /* cancel */ backend_download_packages, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/razor/pk-backend-razor.c b/backends/razor/pk-backend-razor.c index ac2d3ca..4e390b2 100644 --- a/backends/razor/pk-backend-razor.c +++ b/backends/razor/pk-backend-razor.c @@ -403,6 +403,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ NULL, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ NULL, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/smart/pk-backend-smart.c b/backends/smart/pk-backend-smart.c index 72c916b..68a4350 100644 --- a/backends/smart/pk-backend-smart.c +++ b/backends/smart/pk-backend-smart.c @@ -455,6 +455,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ backend_download_packages, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/test/pk-backend-test-dbus.c b/backends/test/pk-backend-test-dbus.c index 5d3ee53..d62cea6 100644 --- a/backends/test/pk-backend-test-dbus.c +++ b/backends/test/pk-backend-test-dbus.c @@ -82,6 +82,8 @@ PK_BACKEND_OPTIONS ( NULL, /* get_filters */ backend_cancel, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ NULL, /* get_depends */ NULL, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/test/pk-backend-test-fail.c b/backends/test/pk-backend-test-fail.c index 3003f9a..b134133 100644 --- a/backends/test/pk-backend-test-fail.c +++ b/backends/test/pk-backend-test-fail.c @@ -256,6 +256,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/test/pk-backend-test-nop.c b/backends/test/pk-backend-test-nop.c index 89a6408..5d82b51 100644 --- a/backends/test/pk-backend-test-nop.c +++ b/backends/test/pk-backend-test-nop.c @@ -32,6 +32,8 @@ PK_BACKEND_OPTIONS ( NULL, /* get_filters */ NULL, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ NULL, /* get_depends */ NULL, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/test/pk-backend-test-spawn.c b/backends/test/pk-backend-test-spawn.c index a49a773..afda14a 100644 --- a/backends/test/pk-backend-test-spawn.c +++ b/backends/test/pk-backend-test-spawn.c @@ -73,6 +73,8 @@ PK_BACKEND_OPTIONS ( NULL, /* get_filters */ NULL, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ NULL, /* get_depends */ NULL, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/test/pk-backend-test-succeed.c b/backends/test/pk-backend-test-succeed.c index 833ef57..42f19c6 100644 --- a/backends/test/pk-backend-test-succeed.c +++ b/backends/test/pk-backend-test-succeed.c @@ -325,6 +325,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/test/pk-backend-test-thread.c b/backends/test/pk-backend-test-thread.c index 9a4bfde..fd27574 100644 --- a/backends/test/pk-backend-test-thread.c +++ b/backends/test/pk-backend-test-thread.c @@ -145,6 +145,8 @@ PK_BACKEND_OPTIONS ( NULL, /* get_filters */ backend_cancel, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ NULL, /* get_depends */ NULL, /* get_details */ NULL, /* get_distro_upgrades */ diff --git a/backends/urpmi/pk-backend-urpmi.c b/backends/urpmi/pk-backend-urpmi.c index 5362cb9..12bd08f 100644 --- a/backends/urpmi/pk-backend-urpmi.c +++ b/backends/urpmi/pk-backend-urpmi.c @@ -366,6 +366,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ NULL, /* cancel */ NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ backend_get_distro_upgrades, /* get_distro_upgrades */ diff --git a/backends/yum/pk-backend-yum.c b/backends/yum/pk-backend-yum.c index be6f420..9725fc0 100644 --- a/backends/yum/pk-backend-yum.c +++ b/backends/yum/pk-backend-yum.c @@ -449,6 +449,24 @@ backend_what_provides (PkBackend *backend, PkBitfield filters, PkProvidesEnum pr g_free (filters_text); } +/** + * pk_backend_get_categories: + */ +static void +backend_get_categories (PkBackend *backend) +{ + pk_backend_spawn_helper (spawn, "yumBackend.py", "get-categories", NULL); +} + +/** + * pk_backend__get_groups: + */ +static void +backend_get_collections (PkBackend *backend) +{ + pk_backend_spawn_helper (spawn, "yumBackend.py", "get-collections", NULL); +} + PK_BACKEND_OPTIONS ( "YUM", /* description */ "Tim Lauridsen , Richard Hughes ", /* author */ @@ -458,6 +476,8 @@ PK_BACKEND_OPTIONS ( backend_get_filters, /* get_filters */ backend_cancel, /* cancel */ backend_download_packages, /* download_packages */ + backend_get_categories, /* get_categories */ + backend_get_collections, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ backend_get_distro_upgrades, /* get_distro_upgrades */ diff --git a/backends/yum/yumBackend.py b/backends/yum/yumBackend.py index 7976aa1..35750a7 100755 --- a/backends/yum/yumBackend.py +++ b/backends/yum/yumBackend.py @@ -140,6 +140,31 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage): summary = self._to_unicode(summary) PackageKitBaseBackend.package(self, package_id, status, summary) + def category(self, cat_id, name, summary, icon): + ''' + Send 'category' signal + cat_id : a unique category id like 'apps','devel' + name : a verbose category name in current locale. + summery : a summary of the category in current locale. + icon : path to an icon or a enum to a existing pk defined icon + ''' + name = self._to_unicode(name) + summary = self._to_unicode(summary) + PackageKitBaseBackend.category(self,cat_id, name, summary, icon) + + def collection(self, grp_id, cat_id, name, summary, icon): + ''' + Send 'group' signal + grp_id : a unique group id like 'kde-desktop' + cat_id : a unique category id like 'desktop' + name : a verbose category name in current locale. + summery : a summary of the category in current locale. + icon : path to an icon or a enum to a existing pk defined icon + ''' + summary = self._to_unicode(summary) + name = self._to_unicode(name) + PackageKitBaseBackend.collection(self, grp_id, cat_id, name, summary, icon) + def _to_unicode(self, txt, encoding='utf-8'): if isinstance(txt, basestring): if not isinstance(txt, unicode): @@ -321,8 +346,15 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage): self._handle_collections(fltlist) return - # get the packagelist for this group - all_packages = self.comps.get_package_list(group_key) + # handle dynamic groups (yum comps group) + if group_key[0] == '@': + id = group_key[1:] + print id + # get the packagelist for this group + all_packages = self.comps.get_meta_package_list(id) + else: # this is an group_enum + # get the packagelist for this group enum + all_packages = self.comps.get_package_list(group_key) # group don't exits, just bail out if not all_packages: @@ -433,6 +465,53 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage): self._show_package_list(package_list) @handle_repo_error + def get_categories(self): + ''' + Implement the {backend}-get-categories functionality + ''' + self.status(STATUS_QUERY) + self.allow_cancel(True) + for cat in self.yumbase.comps.categories: + id = cat.categoryid + # yum >= 3.2.10 + # name = cat.nameByLang(self._lang) + # summary = cat.descriptionByLang(self._lang) + name = cat.name + summary = cat.description + fn = "/usr/share/pixmaps/comps/%s.png" % id + if os.access(fn, os.R_OK): + icon = fn + else: + icon = "" + self.category(id,name,summary,icon) + + @handle_repo_error + def get_collections(self): + ''' + Implement the {backend}-get-collections functionality + ''' + self.status(STATUS_QUERY) + self.allow_cancel(True) + grps = self.comps.get_groups() + for (grp_id, cat_id) in grps: + grp = self.yumbase.comps.return_group(grp_id) + if grp: + id = "@%s" % grp_id + name = grp.nameByLang(self._lang) + summary = grp.descriptionByLang(self._lang) + icon = "" + fn = "/usr/share/pixmaps/comps/%s.png" % grp_id + if os.access(fn, os.R_OK): + icon = fn + else: + fn = "/usr/share/pixmaps/comps/%s.png" % cat_id + if os.access(fn, os.R_OK): + icon = fn + self.collection(id, cat_id, name, summary, icon) + + + + @handle_repo_error def download_packages(self, directory, package_ids): ''' Implement the {backend}-download-packages functionality @@ -510,10 +589,15 @@ class PackageKitYumBackend(PackageKitBaseBackend, PackagekitPackage): if len(package_id.split(';')) > 1: # Split up the id (name, idver, a, repo) = self.get_package_from_id(package_id) + isGroup = False if repo == 'meta': grp = self.yumbase.comps.return_group(name) - if not grp: - self.error(ERROR_PACKAGE_NOT_FOUND, "The Group %s dont exist" % name) + isGroup = True + elif name[0] == '@': + grp = self.yumbase.comps.return_group(name[1:]) + isGroup = True + if isGroup and not grp: + self.error(ERROR_PACKAGE_NOT_FOUND, "The Group %s dont exist" % name) return grp def _findPackage(self, package_id): diff --git a/backends/yum/yumComps.py b/backends/yum/yumComps.py index 53e41f9..789702f 100755 --- a/backends/yum/yumComps.py +++ b/backends/yum/yumComps.py @@ -297,6 +297,13 @@ class yumComps: break return category + def get_groups(self): + grps = set() + self.cursor.execute('SELECT groupid,category FROM groups') + for row in self.cursor: + grps.add((row[0],row[1])) + return list(grps) + if __name__ == "__main__": import yum import os diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp index 7a089be..b3c57a3 100644 --- a/backends/zypp/pk-backend-zypp.cpp +++ b/backends/zypp/pk-backend-zypp.cpp @@ -1841,8 +1841,10 @@ extern "C" PK_BACKEND_OPTIONS ( backend_destroy, /* destroy */ backend_get_groups, /* get_groups */ backend_get_filters, /* get_filters */ - NULL, /* cancel */ - NULL, /* download_packages */ + NULL, /* cancel */ + NULL, /* download_packages */ + NULL, /* get_categories */ + NULL, /* get_collections */ backend_get_depends, /* get_depends */ backend_get_details, /* get_details */ backend_get_distro_upgrades, /* get_distro_upgrades */ diff --git a/contrib/pk-completion.bash b/contrib/pk-completion.bash index 784a882..95357ba 100755 --- a/contrib/pk-completion.bash +++ b/contrib/pk-completion.bash @@ -32,6 +32,8 @@ __pkcon_commandlist=" get-transactions get-update-detail get-updates + get-collections + get-categories install refresh remove diff --git a/libpackagekit/pk-client.c b/libpackagekit/pk-client.c index 0a6c438..2332e92 100644 --- a/libpackagekit/pk-client.c +++ b/libpackagekit/pk-client.c @@ -125,6 +125,8 @@ typedef enum { PK_CLIENT_CALLER_ACTIVE_CHANGED, PK_CLIENT_REPO_DETAIL, PK_CLIENT_ALLOW_CANCEL, + PK_CLIENT_CATEGORY, + PK_CLIENT_COLLECTION, PK_CLIENT_LAST_SIGNAL } PkSignals; diff --git a/libpackagekit/pk-enum.c b/libpackagekit/pk-enum.c index ba427ed..f92bd8a 100644 --- a/libpackagekit/pk-enum.c +++ b/libpackagekit/pk-enum.c @@ -117,6 +117,8 @@ static const PkEnumMatch enum_role[] = { {PK_ROLE_ENUM_ACCEPT_EULA, "accept-eula"}, {PK_ROLE_ENUM_DOWNLOAD_PACKAGES, "download-packages"}, {PK_ROLE_ENUM_GET_DISTRO_UPGRADES, "get-distro-upgrades"}, + {PK_ROLE_ENUM_GET_CATEGORIES, "get-categories"}, + {PK_ROLE_ENUM_GET_COLLECTIONS, "get-collections"}, {0, NULL} }; diff --git a/libpackagekit/pk-enum.h b/libpackagekit/pk-enum.h index 4ad8570..34dadde 100644 --- a/libpackagekit/pk-enum.h +++ b/libpackagekit/pk-enum.h @@ -75,6 +75,8 @@ typedef enum { PK_ROLE_ENUM_ACCEPT_EULA, PK_ROLE_ENUM_DOWNLOAD_PACKAGES, PK_ROLE_ENUM_GET_DISTRO_UPGRADES, + PK_ROLE_ENUM_GET_CATEGORIES, + PK_ROLE_ENUM_GET_COLLECTIONS, PK_ROLE_ENUM_UNKNOWN } PkRoleEnum; diff --git a/python/packagekit/backend.py b/python/packagekit/backend.py index ff410d4..8dd1e68 100644 --- a/python/packagekit/backend.py +++ b/python/packagekit/backend.py @@ -157,6 +157,29 @@ class PackageKitBaseBackend: print >> sys.stdout, "files\t%s\t%s" % (package_id, file_list) sys.stdout.flush() + def collection(self, grp_id, cat_id, name, summary, icon): + ''' + Send 'group' signal + grp_id : a unique group id like 'kde-desktop' + cat_id : a unique category id like 'desktop' + name : a verbose category name in current locale. + summery : a summary of the category in current locale. + icon : path to an icon or a enum to a existing pk defined icon + ''' + print >> sys.stdout,"collection\t%s\t%s\t%s\t%s\t%s" % (grp_id, cat_id, name, summary, icon) + sys.stdout.flush() + + def category(self, cat_id, name, summary, icon): + ''' + Send 'category' signal + cat_id : a unique category id like 'apps','devel' + name : a verbose category name in current locale. + summery : a summary of the category in current locale. + icon : path to an icon or a enum to a existing pk defined icon + ''' + print >> sys.stdout,"category\t%s\t%s\t%s\t%s" % (cat_id, name, summary, icon) + sys.stdout.flush() + def finished(self): ''' Send 'finished' signal @@ -423,6 +446,20 @@ class PackageKitBaseBackend: ''' self.error(ERROR_NOT_SUPPORTED, "This function is not implemented in this backend") + def get_categories(self): + ''' + Implement the {backend}-get-categories functionality + Needed to be implemented in a sub class + ''' + self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend") + + def get_collections(self): + ''' + Implement the {backend}-get-collections functionality + Needed to be implemented in a sub class + ''' + self.error(ERROR_NOT_SUPPORTED,"This function is not implemented in this backend") + def customTracebackHandler(self, tb): ''' Custom Traceback Handler @@ -568,6 +605,12 @@ class PackageKitBaseBackend: code = args[0] self.set_locale(code) self.finished() + elif cmd == 'get-categories': + self.get_categories() + self.finished() + elif cmd == 'get-collections': + self.get_collections() + self.finished() else: errmsg = "command '%s' is not known" % cmd self.error(ERROR_INTERNAL_ERROR, errmsg, exit=False) @@ -577,8 +620,8 @@ class PackageKitBaseBackend: if len(args) > 0: self.dispatch_command(args[0], args[1:]) while True: - line = raw_input('') - if line == 'exit': + line = sys.stdin.readline().strip('\n') + if not line or line == 'exit': break args = line.split('\t') self.dispatch_command(args[0], args[1:]) diff --git a/python/packagekit/client.py b/python/packagekit/client.py index 9866bc6..8e08c25 100644 --- a/python/packagekit/client.py +++ b/python/packagekit/client.py @@ -122,6 +122,32 @@ class PackageKitClient: self._wrapCall(pk_xn, method, {'Details' : details_cb}) return result + def _wrapCategoryCall(self, pk_xn, method): + ''' + Wraps a call which emits Finished, ErrorCode on completion and + Details for information returns a list of dicts with 'id', + 'license', 'group', 'description', 'upstream_url', 'size'.keys + ''' + result = [] + details_cb = lambda cat_id, name, summary, icon: result.append( + PackageKitCategory( cat_id, name, summary, icon)) + + self._wrapCall(pk_xn, method, {'Category' : details_cb}) + return result + + def _wrapCollectionCall(self, pk_xn, method): + ''' + Wraps a call which emits Finished, ErrorCode on completion and + Details for information returns a list of dicts with 'id', + 'license', 'group', 'description', 'upstream_url', 'size'.keys + ''' + result = [] + details_cb = lambda grp_id, cat_id, name, summary, icon: result.append( + PackageKitCollection(grp_id, cat_id, name, summary, icon)) + + self._wrapCall(pk_xn, method, {'Collection' : details_cb}) + return result + def _wrapUpdateDetailsCall(self, pk_xn, method): ''' Wraps a call which emits Finished, ErrorCode on completion and @@ -313,6 +339,20 @@ class PackageKitClient: xn = self._get_xn() return self._wrapPackageCall(xn, lambda : xn.GetUpdates(filters)) + def GetCategories(self): + ''' + This method should return a list of Categories + ''' + xn = self._get_xn() + return self._wrapCategoryCall(xn, lambda : xn.GetCategories()) + + def GetCollections(self): + ''' + This method should return a list of Collections (groups) + ''' + xn = self._get_xn() + return self._wrapCollectionCall(xn, lambda : xn.GetCollections()) + def GetPackages(self, filters=FILTER_NONE): ''' This method should return a total list of packages, limited by the diff --git a/python/packagekit/misc.py b/python/packagekit/misc.py index e6d113f..d585f1e 100644 --- a/python/packagekit/misc.py +++ b/python/packagekit/misc.py @@ -20,12 +20,12 @@ # Tim Lauridsen # Misc classes and funtions +def _to_unicode( txt, encoding='utf-8'): + if isinstance(txt, basestring): + if not isinstance(txt, unicode): + txt = unicode(txt, encoding, errors='replace') + return txt -def _to_utf8( obj, errors='replace'): - '''convert 'unicode' to an encoded utf-8 byte string ''' - if isinstance(obj, unicode): - obj = obj.encode('utf-8', errors) - return obj class PackageKitPackage: ''' @@ -34,16 +34,12 @@ class PackageKitPackage: def __init__(self, installed, package_id, summary): self.installed = (installed == 'installed') self.id = str(package_id) - self.summary = _to_utf8(summary) + self.summary = _to_unicode(summary) def __str__(self): (name, ver, arch, repo) = tuple(self.id.split(";")) p = "%s-%s.%s" % (name, ver, arch) - if self.installed: - inst = "installed" - else: - inst = "available" - return "%-40s : %s : %s" % (p, inst, self.summary) + return p class PackageKitDistroUpgrade: ''' @@ -51,8 +47,8 @@ class PackageKitDistroUpgrade: ''' def __init__(self, upgrade_type, name, summary): self.upgrade_type = upgrade_type - self.name = name - self.summary = _to_utf8(summary) + self.name = str(name) + self.summary = unicode(summary) def __str__(self): return " type : %s, name : %s, summary : %s " % ( @@ -64,11 +60,11 @@ class PackageKitDetails: ''' def __init__(self, package_id, package_license, group, detail, url, size): self.id = str(package_id) - self.license = package_license - self.group = group - self.detail = _to_utf8(detail) - self.url = url - self.size = size + self.license = str(package_license) + self.group = str(group) + self.detail = _to_unicode(detail) + self.url = str(url) + self.size = int(size) class PackageKitUpdateDetails: ''' @@ -78,26 +74,26 @@ class PackageKitUpdateDetails: cve_url, restart, update_text, changelog, state, \ issued, updated): self.id = str(package_id) - self.updates = updates - self.obsoletes = obsoletes - self.vendor_url = vendor_url - self.bugzilla_url = bugzilla_url - self.cve_url = cve_url - self.restart = restart - self.update_text = update_text - self.changelog = changelog - self.state = state - self.issued = issued - self.updated = updated + self.updates = str(updates) + self.obsoletes = str(obsoletes) + self.vendor_url = str(vendor_url) + self.bugzilla_url = str(bugzilla_url) + self.cve_url = str(cve_url) + self.restart = (restart == 'yes') + self.update_text = _to_unicode(update_text) + self.changelog = _to_unicode(changelog) + self.state = str(state) + self.issued = str(issued) + self.updated = str(updated) class PackageKitRepos: ''' container class from values from the Repos signal ''' - def __init__(self, package_id, description, enabled): - self.id = str(package_id) - self.description = description - self.enabled = enabled + def __init__(self, repo_id, description, enabled): + self.id = str(repo_id) + self.description = _to_unicode(description) + self.enabled = (enabled == 'yes') class PackageKitFiles: ''' @@ -105,5 +101,30 @@ class PackageKitFiles: ''' def __init__(self, package_id, files): self.id = str(package_id) - self.files = files - + self.files = str(files) + +class PackageKitCategory: + ''' + container class from values from the Category signal + ''' + def __init__(self, cat_id, name, summary, icon): + self.cat_id = str(cat_id) + self.name = _to_unicode(name) + self.summary = _to_unicode(summary) + self.icon = str(icon) + + + +class PackageKitCollection: + ''' + container class from values from the Collection signal + ''' + def __init__(self, grp_id, cat_id, name, summary, icon): + self.grp_id = str(grp_id) + self.cat_id = str(cat_id) + self.name = _to_unicode(name) + self.summary = _to_unicode(summary) + self.icon = str(icon) + + + diff --git a/python/wrapper-test.py b/python/wrapper-test.py index 8265949..2f8920a 100755 --- a/python/wrapper-test.py +++ b/python/wrapper-test.py @@ -19,6 +19,7 @@ # Tim Lauridsen import sys + from packagekit.client import PackageKitClient from packagekit.enums import * @@ -39,7 +40,8 @@ def show_package(pkg): if pkg: if isinstance(pkg, list): pkg = pkg[0] - print str(pkg) + print pkg + print pkg.summary else: print "no package found" @@ -128,5 +130,28 @@ if __name__ == '__main__': print "Installing : %s " % pkg[0].id print pk.DownloadPackages(pkg[0].id) + if "get-categories" in cmd: + print '---- GetCategories() -----' + cats = pk.GetCategories() + for cat in cats: + print cat.name + + if "get-collections" in cmd: + print '---- GetCollections() -----' + cats = pk.GetCategories() + cols = pk.GetCollections() + tree = {} + for col in cols: + if col.cat_id in tree: + tree[col.cat_id].append(col) + else: + tree[col.cat_id] = [col] + for cat in cats: + if cat.cat_id in tree.keys(): + cols = tree[cat.cat_id] + print cat.name + for col in cols: + print " %-25s : %s " % (col.grp_id,col.name) + pk.SuggestDaemonQuit() diff --git a/src/pk-backend-dbus.c b/src/pk-backend-dbus.c index c68a413..04313c0 100644 --- a/src/pk-backend-dbus.c +++ b/src/pk-backend-dbus.c @@ -164,6 +164,40 @@ pk_backend_dbus_distro_upgrade_cb (DBusGProxy *proxy, } /** + * pk_backend_dbus_category_cb: + **/ +static void +pk_backend_dbus_category_cb (DBusGProxy *proxy, + const gchar *cat_id, + const gchar *name, + const gchar *summary, + const gchar *icon, + PkBackendDbus *backend_dbus) +{ + egg_debug ("got signal"); + pk_backend_category (backend_dbus->priv->backend, + cat_id, name, summary, icon); +} + +/** + * pk_backend_dbus_collection_cb: + **/ +static void +pk_backend_dbus_collection_cb (DBusGProxy *proxy, + const gchar *grp_id, + const gchar *cat_id, + const gchar *name, + const gchar *summary, + const gchar *icon, + PkBackendDbus *backend_dbus) +{ + egg_debug ("got signal"); + pk_backend_collection (backend_dbus->priv->backend, + grp_id, cat_id, name, summary, icon); +} + + +/** * pk_backend_dbus_files_cb: **/ static void @@ -358,6 +392,10 @@ pk_backend_dbus_remove_callbacks (PkBackendDbus *backend_dbus) G_CALLBACK (pk_backend_dbus_repo_signature_required_cb), backend_dbus); dbus_g_proxy_disconnect_signal (proxy, "EulaRequired", G_CALLBACK (pk_backend_dbus_eula_required_cb), backend_dbus); + dbus_g_proxy_disconnect_signal (proxy, "Category", + G_CALLBACK (pk_backend_dbus_category_cb), backend_dbus); + dbus_g_proxy_disconnect_signal (proxy, "Collection", + G_CALLBACK (pk_backend_dbus_collection_cb), backend_dbus); dbus_g_proxy_disconnect_signal (proxy, "DistroUpgrade", G_CALLBACK (pk_backend_dbus_distro_upgrade_cb), backend_dbus); return TRUE; @@ -497,6 +535,12 @@ pk_backend_dbus_set_name (PkBackendDbus *backend_dbus, const gchar *service) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID); dbus_g_proxy_add_signal (proxy, "Files", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_add_signal (proxy, "Collection", + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_add_signal (proxy, "Category", + G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal (proxy, "UpdateDetail", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, @@ -538,6 +582,10 @@ pk_backend_dbus_set_name (PkBackendDbus *backend_dbus, const gchar *service) G_CALLBACK (pk_backend_dbus_details_cb), backend_dbus, NULL); dbus_g_proxy_connect_signal (proxy, "Files", G_CALLBACK (pk_backend_dbus_files_cb), backend_dbus, NULL); + dbus_g_proxy_connect_signal (proxy, "Category", + G_CALLBACK (pk_backend_dbus_category_cb), backend_dbus, NULL); + dbus_g_proxy_connect_signal (proxy, "Collection", + G_CALLBACK (pk_backend_dbus_collection_cb), backend_dbus, NULL); dbus_g_proxy_connect_signal (proxy, "UpdateDetail", G_CALLBACK (pk_backend_dbus_update_detail_cb), backend_dbus, NULL); dbus_g_proxy_connect_signal (proxy, "Finished", @@ -771,6 +819,60 @@ pk_backend_dbus_update_system (PkBackendDbus *backend_dbus) } /** + * pk_backend_dbus_get_categories: + **/ +gboolean +pk_backend_dbus_get_categories (PkBackendDbus *backend_dbus) +{ + gboolean ret; + GError *error = NULL; + + g_return_val_if_fail (PK_IS_BACKEND_DBUS (backend_dbus), FALSE); + g_return_val_if_fail (backend_dbus->priv->proxy != NULL, FALSE); + + /* new sync method call */ + pk_backend_dbus_time_reset (backend_dbus); + ret = dbus_g_proxy_call (backend_dbus->priv->proxy, "GetCategories", &error, + G_TYPE_INVALID, G_TYPE_INVALID); + if (error != NULL) { + egg_warning ("%s", error->message); + pk_backend_error_code (backend_dbus->priv->backend, PK_ERROR_ENUM_INTERNAL_ERROR, error->message); + pk_backend_finished (backend_dbus->priv->backend); + g_error_free (error); + } + if (ret) + pk_backend_dbus_time_check (backend_dbus); + return ret; +} + +/** + * pk_backend_dbus_get_collections: + **/ +gboolean +pk_backend_dbus_get_collections (PkBackendDbus *backend_dbus) +{ + gboolean ret; + GError *error = NULL; + + g_return_val_if_fail (PK_IS_BACKEND_DBUS (backend_dbus), FALSE); + g_return_val_if_fail (backend_dbus->priv->proxy != NULL, FALSE); + + /* new sync method call */ + pk_backend_dbus_time_reset (backend_dbus); + ret = dbus_g_proxy_call (backend_dbus->priv->proxy, "GetCollections", &error, + G_TYPE_INVALID, G_TYPE_INVALID); + if (error != NULL) { + egg_warning ("%s", error->message); + pk_backend_error_code (backend_dbus->priv->backend, PK_ERROR_ENUM_INTERNAL_ERROR, error->message); + pk_backend_finished (backend_dbus->priv->backend); + g_error_free (error); + } + if (ret) + pk_backend_dbus_time_check (backend_dbus); + return ret; +} + +/** * pk_backend_dbus_repo_enable: **/ gboolean @@ -1538,6 +1640,14 @@ pk_backend_dbus_init (PkBackendDbus *backend_dbus) dbus_g_object_register_marshaller (pk_marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + /* Category */ + dbus_g_object_register_marshaller (pk_marshal_VOID__STRING_STRING, + G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + /* Collection */ + dbus_g_object_register_marshaller (pk_marshal_VOID__STRING_STRING, + G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); /* Repo Signature Required */ dbus_g_object_register_marshaller (pk_marshal_VOID__STRING_STRING_STRING_STRING_STRING_STRING_STRING_UINT, diff --git a/src/pk-backend-dbus.h b/src/pk-backend-dbus.h index eb53962..9f9f19f 100644 --- a/src/pk-backend-dbus.h +++ b/src/pk-backend-dbus.h @@ -66,6 +66,8 @@ PkBackendDbus *pk_backend_dbus_new (void); gboolean pk_backend_dbus_refresh_cache (PkBackendDbus *backend_dbus, gboolean force); gboolean pk_backend_dbus_update_system (PkBackendDbus *backend_dbus); +gboolean pk_backend_dbus_get_categories (PkBackendDbus *backend_dbus); +gboolean pk_backend_dbus_get_collections (PkBackendDbus *backend_dbus); gboolean pk_backend_dbus_resolve (PkBackendDbus *backend_dbus, PkBitfield filters, gchar **packages); diff --git a/src/pk-backend-spawn.c b/src/pk-backend-spawn.c index 9878340..400ee02 100644 --- a/src/pk-backend-spawn.c +++ b/src/pk-backend-spawn.c @@ -384,6 +384,24 @@ pk_backend_spawn_parse_stdout (PkBackendSpawn *backend_spawn, const gchar *line) ret = pk_backend_distro_upgrade (backend_spawn->priv->backend, distro_upgrade_enum, sections[2], sections[3]); goto out; + } else if (egg_strequal (command, "category")) { + + if (size != 5) { + egg_warning ("invalid command '%s'", command); + ret = FALSE; + goto out; + } + ret = pk_backend_category (backend_spawn->priv->backend, sections[1], sections[2], sections[3], sections[4]); + goto out; + } else if (egg_strequal (command, "collection")) { + + if (size != 6) { + egg_warning ("invalid command '%s'", command); + ret = FALSE; + goto out; + } + ret = pk_backend_collection (backend_spawn->priv->backend, sections[1], sections[2], sections[3], sections[4], sections[5]); + goto out; } else { egg_warning ("invalid command '%s'", command); } diff --git a/src/pk-backend.c b/src/pk-backend.c index 71c92c1..22aeace 100644 --- a/src/pk-backend.c +++ b/src/pk-backend.c @@ -131,6 +131,8 @@ enum { PK_BACKEND_FINISHED, PK_BACKEND_ALLOW_CANCEL, PK_BACKEND_REPO_DETAIL, + PK_BACKEND_CATEGORY, + PK_BACKEND_COLLECTION, PK_BACKEND_LAST_SIGNAL }; @@ -232,6 +234,10 @@ pk_backend_get_actions (PkBackend *backend) pk_bitfield_add (roles, PK_ROLE_ENUM_REPO_SET_DATA); if (desc->get_distro_upgrades != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_DISTRO_UPGRADES); + if (desc->get_categories != NULL) + pk_bitfield_add (roles, PK_ROLE_ENUM_GET_CATEGORIES); + if (desc->get_collections != NULL) + pk_bitfield_add (roles, PK_ROLE_ENUM_GET_COLLECTIONS); return roles; } @@ -1198,6 +1204,66 @@ pk_backend_repo_detail (PkBackend *backend, const gchar *repo_id, } /** + * pk_backend_category: + **/ +gboolean +pk_backend_category (PkBackend *backend, const gchar *cat_id, const gchar *name, + const gchar *summary, const gchar *icon) +{ + gchar *summary_safe; + + g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE); + g_return_val_if_fail (cat_id != NULL, FALSE); + g_return_val_if_fail (backend->priv->locked != FALSE, FALSE); + + /* have we already set an error? */ + if (backend->priv->set_error) { + egg_warning ("already set error, cannot process: category %s", cat_id); + return FALSE; + } + + /* replace unsafe chars */ + summary_safe = pk_strsafe (summary); + + egg_debug ("emit category %s, %s, %s, %s", cat_id, name, summary_safe, icon); + g_signal_emit (backend, signals [PK_BACKEND_CATEGORY], 0, cat_id, name, summary, icon); + g_free (summary_safe); + return TRUE; + +} + +/** + * pk_backend_collection: + **/ +gboolean +pk_backend_collection (PkBackend *backend, const gchar *grp_id, const gchar *cat_id, + const gchar *name, const gchar *summary, const gchar *icon) +{ + gchar *summary_safe; + + g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE); + g_return_val_if_fail (grp_id != NULL, FALSE); + g_return_val_if_fail (cat_id != NULL, FALSE); + g_return_val_if_fail (backend->priv->locked != FALSE, FALSE); + + /* have we already set an error? */ + if (backend->priv->set_error) { + egg_warning ("already set error, cannot process: collection %s", grp_id); + return FALSE; + } + + /* replace unsafe chars */ + summary_safe = pk_strsafe (summary); + + egg_debug ("emit collection %s, %s, %s, %s, %s", grp_id, cat_id, name, summary_safe, icon); + g_signal_emit (backend, signals [PK_BACKEND_COLLECTION], 0, grp_id, cat_id, name, summary, icon); + g_free (summary_safe); + return TRUE; + + +} + +/** * pk_backend_error_timeout_delay_cb: * * We have to call Finished() within PK_BACKEND_FINISHED_ERROR_TIMEOUT of ErrorCode(), enforce this. @@ -1762,6 +1828,16 @@ pk_backend_class_init (PkBackendClass *klass) G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, pk_marshal_VOID__STRING_STRING_BOOL, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); + signals [PK_BACKEND_CATEGORY] = + g_signal_new ("category", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + 0, NULL, NULL, pk_marshal_VOID__STRING_STRING_STRING_STRING, + G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + signals [PK_BACKEND_COLLECTION] = + g_signal_new ("collection", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + 0, NULL, NULL, pk_marshal_VOID__STRING_STRING_STRING_STRING_STRING, + G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); g_type_class_add_private (klass, sizeof (PkBackendPrivate)); } diff --git a/src/pk-backend.h b/src/pk-backend.h index bc026d7..b80eef1 100644 --- a/src/pk-backend.h +++ b/src/pk-backend.h @@ -141,6 +141,17 @@ gboolean pk_backend_eula_required (PkBackend *backend, const gchar *package_id, const gchar *vendor_name, const gchar *license_agreement); +gboolean pk_backend_category (PkBackend *backend, + const gchar *cat_id, + const gchar *name, + const gchar *summary, + const gchar *icon); +gboolean pk_backend_collection (PkBackend *backend, + const gchar *grp_id, + const gchar *cat_id, + const gchar *name, + const gchar *summary, + const gchar *icon); /* set backend instance data */ gboolean pk_backend_set_array (PkBackend *backend, @@ -206,6 +217,8 @@ typedef struct { void (*download_packages) (PkBackend *backend, gchar **package_ids, const gchar *directory); + void (*get_categories) (PkBackend *backend); + void (*get_collections) (PkBackend *backend); void (*get_depends) (PkBackend *backend, PkBitfield filters, gchar **package_ids, @@ -280,6 +293,7 @@ typedef struct { } PkBackendDesc; #define PK_BACKEND_OPTIONS(description, author, initialize, destroy, get_filters, get_groups, cancel, download_packages, \ + get_categories, get_collections, \ get_depends, get_details, get_distro_upgrades, get_files, get_packages, get_repo_list, get_requires, \ get_update_detail, get_updates, install_files, install_packages, \ install_signature, refresh_cache, remove_packages, repo_enable, \ @@ -294,6 +308,8 @@ typedef struct { get_groups, \ cancel, \ download_packages, \ + get_categories, \ + get_collections, \ get_depends, \ get_details, \ get_distro_upgrades, \ diff --git a/src/pk-interface-transaction.xml b/src/pk-interface-transaction.xml index 09e5e70..04d2795 100644 --- a/src/pk-interface-transaction.xml +++ b/src/pk-interface-transaction.xml @@ -110,6 +110,41 @@ + + + + + + This method return the collection categories + + + + This method typically emits + Categories, + Error and + + + + + + + + + + + This method return all collections + + + + This method typically emits + Collection, + Error and + + + + + + @@ -1311,6 +1346,109 @@ + + + + + This signal send information about a collection category + + + + + + + + The category ID (ex. 'apps') + + + + + + + + + The verbose name of the category + + + + + + + + + The category summary + + + + + + + + + the full path to the category icon file + + + + + + + + + + + + This signal send information about a collection + + + + + + + + The collection ID (ex. 'kde-desktop') + + + + + + + + + The category ID of the collection(ex. 'apps') + + + + + + + + + The verbose name of the collection + + + + + + + + + The collection summary + + + + + + + + + the full path to the collection icon file + + + + + + + diff --git a/src/pk-transaction.c b/src/pk-transaction.c index 73f86dc..ce2fa02 100644 --- a/src/pk-transaction.c +++ b/src/pk-transaction.c @@ -146,6 +146,8 @@ struct PkTransactionPrivate guint signal_require_restart; guint signal_status_changed; guint signal_update_detail; + guint signal_category; + guint signal_collection; }; enum { @@ -166,6 +168,8 @@ enum { PK_TRANSACTION_STATUS_CHANGED, PK_TRANSACTION_TRANSACTION, PK_TRANSACTION_UPDATE_DETAIL, + PK_TRANSACTION_CATEGORY, + PK_TRANSACTION_COLLECTION, PK_TRANSACTION_LAST_SIGNAL }; @@ -452,6 +456,36 @@ pk_transaction_files_cb (PkBackend *backend, const gchar *package_id, } /** + * pk_transaction_category_cb: + **/ +static void +pk_transaction_category_cb (PkBackend *backend, const gchar *cat_id, + const gchar *name, const gchar *summary, const gchar *icon, + PkTransaction *transaction) +{ + g_return_if_fail (PK_IS_TRANSACTION (transaction)); + g_return_if_fail (transaction->priv->tid != NULL); + + egg_debug ("emitting category %s, %s, %s, %s ", cat_id, name, summary, icon); + g_signal_emit (transaction, signals [PK_TRANSACTION_CATEGORY], 0, cat_id, name, summary, icon); +} + +/** + * pk_transaction_collection_cb: + **/ +static void +pk_transaction_collection_cb (PkBackend *backend, const gchar *grp_id, const gchar *cat_id, + const gchar *name, const gchar *summary, const gchar *icon, + PkTransaction *transaction) +{ + g_return_if_fail (PK_IS_TRANSACTION (transaction)); + g_return_if_fail (transaction->priv->tid != NULL); + + egg_debug ("emitting collection %s, %s, %s, %s, %s ", grp_id, cat_id, name, summary, icon); + g_signal_emit (transaction, signals [PK_TRANSACTION_COLLECTION], 0, grp_id, cat_id, name, summary, icon); +} + +/** * pk_transaction_distro_upgrade_cb: **/ static void @@ -504,6 +538,8 @@ pk_transaction_finished_cb (PkBackend *backend, PkExitEnum exit, PkTransaction * g_signal_handler_disconnect (transaction->priv->backend, transaction->priv->signal_require_restart); g_signal_handler_disconnect (transaction->priv->backend, transaction->priv->signal_status_changed); g_signal_handler_disconnect (transaction->priv->backend, transaction->priv->signal_update_detail); + g_signal_handler_disconnect (transaction->priv->backend, transaction->priv->signal_category); + g_signal_handler_disconnect (transaction->priv->backend, transaction->priv->signal_collection); /* do some optional extra actions when we've finished refreshing the cache */ if (transaction->priv->role == PK_ROLE_ENUM_REFRESH_CACHE) { @@ -921,6 +957,12 @@ pk_transaction_set_running (PkTransaction *transaction) transaction->priv->signal_update_detail = g_signal_connect (transaction->priv->backend, "update-detail", G_CALLBACK (pk_transaction_update_detail_cb), transaction); + transaction->priv->signal_category = + g_signal_connect (transaction->priv->backend, "category", + G_CALLBACK (pk_transaction_category_cb), transaction); + transaction->priv->signal_collection = + g_signal_connect (transaction->priv->backend, "collection", + G_CALLBACK (pk_transaction_collection_cb), transaction); /* mark running */ transaction->priv->running = TRUE; @@ -999,6 +1041,10 @@ pk_transaction_set_running (PkTransaction *transaction) desc->update_packages (priv->backend, priv->cached_package_ids); else if (priv->role == PK_ROLE_ENUM_UPDATE_SYSTEM) desc->update_system (priv->backend); + else if (priv->role == PK_ROLE_ENUM_GET_CATEGORIES) + desc->get_categories (priv->backend); + else if (priv->role == PK_ROLE_ENUM_GET_COLLECTIONS) + desc->get_collections (priv->backend); else if (priv->role == PK_ROLE_ENUM_GET_REPO_LIST) desc->get_repo_list (priv->backend, priv->cached_filters); else if (priv->role == PK_ROLE_ENUM_REPO_ENABLE) @@ -3529,6 +3575,119 @@ pk_transaction_update_system (PkTransaction *transaction, DBusGMethodInvocation } /** + * pk_transaction_get_categories: + **/ +void +pk_transaction_get_categories (PkTransaction *transaction, DBusGMethodInvocation *context) +{ + gboolean ret; + GError *error; + gchar *sender; + + g_return_if_fail (PK_IS_TRANSACTION (transaction)); + g_return_if_fail (transaction->priv->tid != NULL); + + egg_debug ("GetCategories method called"); + + /* not implemented yet */ + if (transaction->priv->backend->desc->get_categories == NULL) { + error = g_error_new (PK_TRANSACTION_ERROR, PK_TRANSACTION_ERROR_NOT_SUPPORTED, + "Operation not yet supported by backend"); + pk_transaction_list_remove (transaction->priv->transaction_list, + transaction->priv->tid); + dbus_g_method_return_error (context, error); + return; + } + + /* set the dbus name, so we can get the disconnect */ + if (context != NULL) { + /* not set inside the test suite */ + sender = dbus_g_method_get_sender (context); + pk_transaction_set_dbus_name (transaction, sender); + g_free (sender); + } + + /* are we already performing an update? */ + if (pk_transaction_list_role_present (transaction->priv->transaction_list, PK_ROLE_ENUM_GET_CATEGORIES)) { + error = g_error_new (PK_TRANSACTION_ERROR, PK_TRANSACTION_ERROR_TRANSACTION_EXISTS_WITH_ROLE, + "Already performing get categories"); + dbus_g_method_return_error (context, error); + return; + } + + transaction->priv->status = PK_STATUS_ENUM_WAIT; + pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_CATEGORIES); + + /* try to commit this */ + ret = pk_transaction_commit (transaction); + if (!ret) { + error = g_error_new (PK_TRANSACTION_ERROR, PK_TRANSACTION_ERROR_COMMIT_FAILED, + "Could not commit to a transaction object"); + dbus_g_method_return_error (context, error); + return; + } + + dbus_g_method_return (context); +} + +/** + * pk_transaction_get_collections: + **/ +void +pk_transaction_get_collections (PkTransaction *transaction, DBusGMethodInvocation *context) +{ + gboolean ret; + GError *error; + gchar *sender; + + g_return_if_fail (PK_IS_TRANSACTION (transaction)); + g_return_if_fail (transaction->priv->tid != NULL); + + egg_debug ("GetCollections method called"); + + /* not implemented yet */ + if (transaction->priv->backend->desc->get_collections == NULL) { + error = g_error_new (PK_TRANSACTION_ERROR, PK_TRANSACTION_ERROR_NOT_SUPPORTED, + "Operation not yet supported by backend"); + pk_transaction_list_remove (transaction->priv->transaction_list, + transaction->priv->tid); + dbus_g_method_return_error (context, error); + return; + } + + /* set the dbus name, so we can get the disconnect */ + if (context != NULL) { + /* not set inside the test suite */ + sender = dbus_g_method_get_sender (context); + pk_transaction_set_dbus_name (transaction, sender); + g_free (sender); + } + + /* are we already performing an get-collection? */ + if (pk_transaction_list_role_present (transaction->priv->transaction_list, PK_ROLE_ENUM_GET_COLLECTIONS)) { + error = g_error_new (PK_TRANSACTION_ERROR, PK_TRANSACTION_ERROR_TRANSACTION_EXISTS_WITH_ROLE, + "Already performing get collections"); + dbus_g_method_return_error (context, error); + return; + } + + transaction->priv->status = PK_STATUS_ENUM_WAIT; + pk_transaction_set_role (transaction, PK_ROLE_ENUM_GET_COLLECTIONS); + + /* try to commit this */ + ret = pk_transaction_commit (transaction); + if (!ret) { + error = g_error_new (PK_TRANSACTION_ERROR, PK_TRANSACTION_ERROR_COMMIT_FAILED, + "Could not commit to a transaction object"); + dbus_g_method_return_error (context, error); + return; + } + + dbus_g_method_return (context); +} + + +/** * pk_transaction_what_provides: **/ void @@ -3641,6 +3800,16 @@ pk_transaction_class_init (PkTransactionClass *klass) G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, pk_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); + signals [PK_TRANSACTION_CATEGORY] = + g_signal_new ("category", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + 0, NULL, NULL, pk_marshal_VOID__STRING_STRING_STRING_STRING, + G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + signals [PK_TRANSACTION_COLLECTION] = + g_signal_new ("collection", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + 0, NULL, NULL, pk_marshal_VOID__STRING_STRING_STRING_STRING_STRING, + G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); signals [PK_TRANSACTION_DISTRO_UPGRADE] = g_signal_new ("distro-upgrade", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, diff --git a/src/pk-transaction.h b/src/pk-transaction.h index 0c7814d..7767ded 100644 --- a/src/pk-transaction.h +++ b/src/pk-transaction.h @@ -219,6 +219,10 @@ void pk_transaction_update_packages (PkTransaction *transaction, DBusGMethodInvocation *context); void pk_transaction_update_system (PkTransaction *transaction, DBusGMethodInvocation *context); +void pk_transaction_get_categories (PkTransaction *transaction, + DBusGMethodInvocation *context); +void pk_transaction_get_collections (PkTransaction *transaction, + DBusGMethodInvocation *context); void pk_transaction_what_provides (PkTransaction *transaction, const gchar *filter, const gchar *type,