[gnome-software] trivial: Split off some common PackageKit code
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Split off some common PackageKit code
- Date: Fri, 20 Sep 2013 14:57:48 +0000 (UTC)
commit dddccaf9d812ff3d0c839c486b7681c5da3ec637
Author: Richard Hughes <richard hughsie com>
Date: Fri Sep 20 14:57:29 2013 +0100
trivial: Split off some common PackageKit code
src/plugins/Makefile.am | 10 +++-
src/plugins/gs-plugin-packagekit-refine.c | 40 ++---------------
src/plugins/gs-plugin-packagekit.c | 40 ++---------------
src/plugins/packagekit-common.c | 68 +++++++++++++++++++++++++++++
src/plugins/packagekit-common.h | 37 ++++++++++++++++
5 files changed, 121 insertions(+), 74 deletions(-)
---
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 4509ed2..f455c2c 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -100,12 +100,18 @@ libgs_plugin_local_ratings_la_LIBADD = $(GS_PLUGIN_LIBS) $(SQLITE_LIBS)
libgs_plugin_local_ratings_la_LDFLAGS = -module -avoid-version
libgs_plugin_local_ratings_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
-libgs_plugin_packagekit_la_SOURCES = gs-plugin-packagekit.c
+libgs_plugin_packagekit_la_SOURCES = \
+ gs-plugin-packagekit.c \
+ packagekit-common.c \
+ packagekit-common.h
libgs_plugin_packagekit_la_LIBADD = $(GS_PLUGIN_LIBS) $(PACKAGEKIT_LIBS)
libgs_plugin_packagekit_la_LDFLAGS = -module -avoid-version
libgs_plugin_packagekit_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
-libgs_plugin_packagekit_refine_la_SOURCES = gs-plugin-packagekit-refine.c
+libgs_plugin_packagekit_refine_la_SOURCES = \
+ gs-plugin-packagekit-refine.c \
+ packagekit-common.c \
+ packagekit-common.h
libgs_plugin_packagekit_refine_la_LIBADD = $(GS_PLUGIN_LIBS) $(PACKAGEKIT_LIBS)
libgs_plugin_packagekit_refine_la_LDFLAGS = -module -avoid-version
libgs_plugin_packagekit_refine_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 1e7cbe4..2478c1d 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -27,6 +27,8 @@
#include <gs-plugin.h>
#include <glib/gi18n.h>
+#include "packagekit-common.h"
+
struct GsPluginPrivate {
PkClient *client;
};
@@ -80,7 +82,7 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
PkProgressType type,
gpointer user_data)
{
- GsPluginStatus plugin_status = GS_PLUGIN_STATUS_UNKNOWN;
+ GsPluginStatus plugin_status;
PkStatusEnum status;
GsPlugin *plugin = GS_PLUGIN (user_data);
@@ -89,41 +91,7 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
g_object_get (progress,
"status", &status,
NULL);
-
- /* set label */
- switch (status) {
- case PK_STATUS_ENUM_SETUP:
- case PK_STATUS_ENUM_FINISHED:
- case PK_STATUS_ENUM_UNKNOWN:
- break;
- case PK_STATUS_ENUM_WAIT:
- case PK_STATUS_ENUM_WAITING_FOR_LOCK:
- case PK_STATUS_ENUM_WAITING_FOR_AUTH:
- plugin_status = GS_PLUGIN_STATUS_WAITING;
- break;
- case PK_STATUS_ENUM_LOADING_CACHE:
- case PK_STATUS_ENUM_TEST_COMMIT:
- plugin_status = GS_PLUGIN_STATUS_SETUP;
- break;
- case PK_STATUS_ENUM_DOWNLOAD:
- case PK_STATUS_ENUM_DOWNLOAD_REPOSITORY:
- case PK_STATUS_ENUM_DOWNLOAD_PACKAGELIST:
- case PK_STATUS_ENUM_DOWNLOAD_FILELIST:
- case PK_STATUS_ENUM_DOWNLOAD_CHANGELOG:
- case PK_STATUS_ENUM_DOWNLOAD_GROUP:
- case PK_STATUS_ENUM_DOWNLOAD_UPDATEINFO:
- plugin_status = GS_PLUGIN_STATUS_DOWNLOADING;
- break;
- case PK_STATUS_ENUM_QUERY:
- case PK_STATUS_ENUM_INFO:
- case PK_STATUS_ENUM_DEP_RESOLVE:
- plugin_status = GS_PLUGIN_STATUS_QUERYING;
- break;
- default:
- g_warning ("no mapping for %s",
- pk_status_enum_to_string (status));
- break;
- }
+ plugin_status = packagekit_status_enum_to_plugin_status (status);
if (plugin_status != GS_PLUGIN_STATUS_UNKNOWN)
gs_plugin_status_update (plugin, NULL, plugin_status);
}
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 8f36788..0841d9a 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -27,6 +27,8 @@
#include <gs-plugin.h>
+#include "packagekit-common.h"
+
struct GsPluginPrivate {
PkTask *task;
};
@@ -80,7 +82,7 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
PkProgressType type,
gpointer user_data)
{
- GsPluginStatus plugin_status = GS_PLUGIN_STATUS_UNKNOWN;
+ GsPluginStatus plugin_status;
PkStatusEnum status;
GsPlugin *plugin = GS_PLUGIN (user_data);
@@ -89,41 +91,7 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
g_object_get (progress,
"status", &status,
NULL);
-
- /* set label */
- switch (status) {
- case PK_STATUS_ENUM_SETUP:
- case PK_STATUS_ENUM_FINISHED:
- case PK_STATUS_ENUM_UNKNOWN:
- break;
- case PK_STATUS_ENUM_WAIT:
- case PK_STATUS_ENUM_WAITING_FOR_LOCK:
- case PK_STATUS_ENUM_WAITING_FOR_AUTH:
- plugin_status = GS_PLUGIN_STATUS_WAITING;
- break;
- case PK_STATUS_ENUM_LOADING_CACHE:
- case PK_STATUS_ENUM_TEST_COMMIT:
- plugin_status = GS_PLUGIN_STATUS_SETUP;
- break;
- case PK_STATUS_ENUM_DOWNLOAD:
- case PK_STATUS_ENUM_DOWNLOAD_REPOSITORY:
- case PK_STATUS_ENUM_DOWNLOAD_PACKAGELIST:
- case PK_STATUS_ENUM_DOWNLOAD_FILELIST:
- case PK_STATUS_ENUM_DOWNLOAD_CHANGELOG:
- case PK_STATUS_ENUM_DOWNLOAD_GROUP:
- case PK_STATUS_ENUM_DOWNLOAD_UPDATEINFO:
- plugin_status = GS_PLUGIN_STATUS_DOWNLOADING;
- break;
- case PK_STATUS_ENUM_QUERY:
- case PK_STATUS_ENUM_INFO:
- case PK_STATUS_ENUM_DEP_RESOLVE:
- plugin_status = GS_PLUGIN_STATUS_QUERYING;
- break;
- default:
- g_warning ("no mapping for %s",
- pk_status_enum_to_string (status));
- break;
- }
+ plugin_status = packagekit_status_enum_to_plugin_status (status);
if (plugin_status != GS_PLUGIN_STATUS_UNKNOWN)
gs_plugin_status_update (plugin, NULL, plugin_status);
}
diff --git a/src/plugins/packagekit-common.c b/src/plugins/packagekit-common.c
new file mode 100644
index 0000000..57bc143
--- /dev/null
+++ b/src/plugins/packagekit-common.c
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include "packagekit-common.h"
+
+/**
+ * packagekit_status_enum_to_plugin_status:
+ **/
+GsPluginStatus
+packagekit_status_enum_to_plugin_status (PkStatusEnum status)
+{
+ GsPluginStatus plugin_status = GS_PLUGIN_STATUS_UNKNOWN;
+
+ switch (status) {
+ case PK_STATUS_ENUM_SETUP:
+ case PK_STATUS_ENUM_FINISHED:
+ case PK_STATUS_ENUM_UNKNOWN:
+ break;
+ case PK_STATUS_ENUM_WAIT:
+ case PK_STATUS_ENUM_WAITING_FOR_LOCK:
+ case PK_STATUS_ENUM_WAITING_FOR_AUTH:
+ plugin_status = GS_PLUGIN_STATUS_WAITING;
+ break;
+ case PK_STATUS_ENUM_LOADING_CACHE:
+ case PK_STATUS_ENUM_TEST_COMMIT:
+ plugin_status = GS_PLUGIN_STATUS_SETUP;
+ break;
+ case PK_STATUS_ENUM_DOWNLOAD:
+ case PK_STATUS_ENUM_DOWNLOAD_REPOSITORY:
+ case PK_STATUS_ENUM_DOWNLOAD_PACKAGELIST:
+ case PK_STATUS_ENUM_DOWNLOAD_FILELIST:
+ case PK_STATUS_ENUM_DOWNLOAD_CHANGELOG:
+ case PK_STATUS_ENUM_DOWNLOAD_GROUP:
+ case PK_STATUS_ENUM_DOWNLOAD_UPDATEINFO:
+ plugin_status = GS_PLUGIN_STATUS_DOWNLOADING;
+ break;
+ case PK_STATUS_ENUM_QUERY:
+ case PK_STATUS_ENUM_INFO:
+ case PK_STATUS_ENUM_DEP_RESOLVE:
+ plugin_status = GS_PLUGIN_STATUS_QUERYING;
+ break;
+ default:
+ g_warning ("no mapping for %s",
+ pk_status_enum_to_string (status));
+ break;
+ }
+ return plugin_status;
+}
diff --git a/src/plugins/packagekit-common.h b/src/plugins/packagekit-common.h
new file mode 100644
index 0000000..e553ac8
--- /dev/null
+++ b/src/plugins/packagekit-common.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __APPSTREAM_CACHE_H
+#define __APPSTREAM_CACHE_H
+
+#include <glib.h>
+#include <gs-plugin.h>
+
+#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+#include <packagekit-glib2/packagekit.h>
+
+G_BEGIN_DECLS
+
+GsPluginStatus packagekit_status_enum_to_plugin_status (PkStatusEnum status);
+
+G_END_DECLS
+
+#endif /* __APPSTREAM_CACHE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]