[packagekit] packagekit: Branch 'master' - 5 commits

Richard Hughes hughsient at kemper.freedesktop.org
Tue Sep 11 14:00:47 PDT 2007


 TODO                               |   23 ----
 backends/BACKENDS                  |   24 ++--
 backends/alpm/pk-backend-alpm.c    |  190 +++++++++++++++++++++++++++++++------
 backends/box/pk-backend-box.c      |    2 
 backends/dummy/pk-backend-dummy.c  |    2 
 backends/yum/helpers/packagekit.py |    5 
 backends/yum/helpers/yumBackend.py |    2 
 client/pk-console.c                |   18 +++
 docs/introduction.xml              |    8 +
 libpackagekit/pk-task-client.c     |    9 -
 libpackagekit/pk-task-monitor.c    |   17 ++-
 src/pk-backend.c                   |   19 +--
 src/pk-backend.h                   |    3 
 src/pk-engine.c                    |   10 -
 src/pk-interface.xml               |    1 
 src/pk-marshal.list                |   19 +--
 16 files changed, 255 insertions(+), 97 deletions(-)

New commits:
diff-tree bee68b3a8b5d4f729a02bc765e38a083a7c04383 (from 9dde69266612566000df9c01c8fc17b7d35462b5)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Sep 11 22:00:29 2007 +0100

    add a licence entry into the description signal so we can do clever things with eulas and that sort of thing. Backend writers, please change 'unknown' into the valid licence if you can find it. Thanks.

diff --git a/backends/alpm/pk-backend-alpm.c b/backends/alpm/pk-backend-alpm.c
index dd280b3..fe199d1 100644
--- a/backends/alpm/pk-backend-alpm.c
+++ b/backends/alpm/pk-backend-alpm.c
@@ -393,7 +393,7 @@ backend_get_description (PkBackend *back
 	    pk_backend_finished (backend, PK_EXIT_ENUM_FAILED);
 	    return;
 	  }
-	//pk_backend_description (backend, package_id, PK_GROUP_ENUM_PROGRAMMING, "sdgd");
+	//pk_backend_description (backend, package_id, "unknown", PK_GROUP_ENUM_PROGRAMMING, "sdgd");
 	pk_backend_finished (backend, PK_EXIT_ENUM_SUCCESS);
 }
 
diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c
index 8567acf..06f371b 100644
--- a/backends/box/pk-backend-box.c
+++ b/backends/box/pk-backend-box.c
@@ -288,7 +288,7 @@ get_description_thread(gpointer data)
 		return NULL;
 	}
 
-	pk_backend_description (d->backend, pi->name, PK_GROUP_ENUM_OTHER, ps->description, "");
+	pk_backend_description (d->backend, pi->name, "unknown", PK_GROUP_ENUM_OTHER, ps->description, "");
 
 	pk_package_id_free (pi);
 	box_db_repos_package_list_free (list);
diff --git a/backends/dummy/pk-backend-dummy.c b/backends/dummy/pk-backend-dummy.c
index 37a3307..98f3bd0 100644
--- a/backends/dummy/pk-backend-dummy.c
+++ b/backends/dummy/pk-backend-dummy.c
@@ -103,7 +103,7 @@ static void
 backend_get_description (PkBackend *backend, const gchar *package_id)
 {
 	g_return_if_fail (backend != NULL);
-	pk_backend_description (backend, "gnome-power-manager;2.6.19;i386;fedora", PK_GROUP_ENUM_PROGRAMMING,
+	pk_backend_description (backend, "gnome-power-manager;2.6.19;i386;fedora", "GPL2", PK_GROUP_ENUM_PROGRAMMING,
 "Scribus is an desktop open source page layout program with "
 "the aim of producing commercial grade output in PDF and "
 "Postscript, primarily, though not exclusively for Linux.\n"
diff --git a/backends/yum/helpers/packagekit.py b/backends/yum/helpers/packagekit.py
index 7d3f89a..4bf0d34 100644
--- a/backends/yum/helpers/packagekit.py
+++ b/backends/yum/helpers/packagekit.py
@@ -104,15 +104,16 @@ class PackageKitBaseBackend:
         '''
         print >> sys.stderr,"data\t%s" % (data)
 
-    def description(self,id,group,desc,url):
+    def description(self,id,licence,group,desc,url):
         '''
         Send 'description' signal
         @param id: The package ID name, e.g. openoffice-clipart;2.6.22;ppc64;fedora
+        @param licence: The licence of the package
         @param group: The enumerated group
         @param desc: The multi line package description
         @param url: The upstream project homepage
         '''
-        print >> sys.stdout,"description\t%s\t%s\t%s\t%s" % (id,group,desc,url)
+        print >> sys.stdout,"description\t%s\t%s\t%s\t%s\t%s" % (id,licence,group,desc,url)
 
     def require_restart(self,restart_type,details):
         '''
diff --git a/backends/yum/helpers/yumBackend.py b/backends/yum/helpers/yumBackend.py
index ea670fa..34ad246 100644
--- a/backends/yum/helpers/yumBackend.py
+++ b/backends/yum/helpers/yumBackend.py
@@ -363,7 +363,7 @@ class PackageKitYumBackend(PackageKitBas
             desc = desc.replace('\n\n',';')
             desc = desc.replace('\n',' ')            
             self.description(id, "%s-%s" % (pkg.version, pkg.release),
-                                 desc, pkg.url)
+                                 "unknown", desc, pkg.url)
         else:
             self.error(ERROR_INTERNAL_ERROR,'Package was not found')
     
diff --git a/client/pk-console.c b/client/pk-console.c
index 9ca725e..c7866be 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -376,6 +376,22 @@ pk_console_error_code_cb (PkTaskClient *
 }
 
 /**
+ * pk_console_description_cb:
+ **/
+static void
+pk_console_description_cb (PkTaskClient *tclient, const gchar *package_id,
+			   const gchar *licence, PkGroupEnum group,
+			   const gchar *description, const gchar *url, gpointer data)
+{
+	g_print ("description\n");
+	g_print ("  package:     '%s'\n", package_id);
+	g_print ("  licence:     '%s'\n", licence);
+	g_print ("  group:       '%s'\n", pk_group_enum_to_text (group));
+	g_print ("  description: '%s'\n", description);
+	g_print ("  url:         '%s'\n", url);
+}
+
+/**
  * main:
  **/
 int
@@ -413,6 +429,8 @@ main (int argc, char *argv[])
 	tclient = pk_task_client_new ();
 	g_signal_connect (tclient, "package",
 			  G_CALLBACK (pk_console_package_cb), NULL);
+	g_signal_connect (tclient, "description",
+			  G_CALLBACK (pk_console_description_cb), NULL);
 	g_signal_connect (tclient, "update-detail",
 			  G_CALLBACK (pk_console_update_detail_cb), NULL);
 	g_signal_connect (tclient, "percentage-changed",
diff --git a/docs/introduction.xml b/docs/introduction.xml
index fc4b04c..7b721aa 100644
--- a/docs/introduction.xml
+++ b/docs/introduction.xml
@@ -1136,6 +1136,14 @@
               <entry>The package ID</entry>
             </row>
             <row>
+              <entry><literal>licence</literal></entry>
+              <entry>
+                The licence, e.g. "GPL2" or "proprietary".
+                If you need to add a EULA then do it like this:
+                "proprietary;By installing this software\nyou may kill a kitten."
+              </entry>
+            </row>
+            <row>
               <entry><literal>group</literal></entry>
               <entry>The enumerated package group description</entry>
             </row>
diff --git a/libpackagekit/pk-task-client.c b/libpackagekit/pk-task-client.c
index 2bcb9cc..3b97db7 100644
--- a/libpackagekit/pk-task-client.c
+++ b/libpackagekit/pk-task-client.c
@@ -1152,6 +1152,7 @@ pk_task_client_update_detail_cb (PkTaskM
 static void
 pk_task_client_description_cb (PkTaskMonitor *tmonitor,
 			   const gchar   *package_id,
+			   const gchar   *licence,
 			   PkGroupEnum    group,
 			   const gchar   *detail,
 			   const gchar   *url,
@@ -1160,8 +1161,8 @@ pk_task_client_description_cb (PkTaskMon
 	g_return_if_fail (tclient != NULL);
 	g_return_if_fail (PK_IS_TASK_CLIENT (tclient));
 
-	pk_debug ("emit description %s, %i, %s, %s", package_id, group, detail, url);
-	g_signal_emit (tclient , signals [PK_TASK_CLIENT_DESCRIPTION], 0, package_id, group, detail, url);
+	pk_debug ("emit description %s, %s, %i, %s, %s", package_id, licence, group, detail, url);
+	g_signal_emit (tclient , signals [PK_TASK_CLIENT_DESCRIPTION], 0, package_id, licence, group, detail, url);
 }
 
 /**
@@ -1243,8 +1244,8 @@ pk_task_client_class_init (PkTaskClientC
 	signals [PK_TASK_CLIENT_DESCRIPTION] =
 		g_signal_new ("description",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, pk_marshal_VOID__STRING_UINT_STRING_STRING,
-			      G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
+			      0, NULL, NULL, pk_marshal_VOID__STRING_STRING_UINT_STRING_STRING,
+			      G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
 	signals [PK_TASK_CLIENT_ERROR_CODE] =
 		g_signal_new ("error-code",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
diff --git a/libpackagekit/pk-task-monitor.c b/libpackagekit/pk-task-monitor.c
index ef92f71..a46f53f 100644
--- a/libpackagekit/pk-task-monitor.c
+++ b/libpackagekit/pk-task-monitor.c
@@ -405,6 +405,7 @@ static void
 pk_task_monitor_description_cb (DBusGProxy    *proxy,
 				guint	       job,
 				const gchar   *package_id,
+				const gchar   *licence,
 				const gchar   *group_text,
 				const gchar   *description,
 				const gchar   *url,
@@ -416,8 +417,8 @@ pk_task_monitor_description_cb (DBusGPro
 
 	if (job == tmonitor->priv->job) {
 		group = pk_group_enum_from_text (group_text);
-		pk_debug ("emit description %s, %i, %s, %s", package_id, group, description, url);
-		g_signal_emit (tmonitor , signals [PK_TASK_MONITOR_DESCRIPTION], 0, package_id, group, description, url);
+		pk_debug ("emit description %s, %s, %i, %s, %s", package_id, licence, group, description, url);
+		g_signal_emit (tmonitor , signals [PK_TASK_MONITOR_DESCRIPTION], 0, package_id, licence, group, description, url);
 	}
 }
 
@@ -507,8 +508,8 @@ pk_task_monitor_class_init (PkTaskMonito
 	signals [PK_TASK_MONITOR_DESCRIPTION] =
 		g_signal_new ("description",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, pk_marshal_VOID__STRING_UINT_STRING_STRING,
-			      G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
+			      0, NULL, NULL, pk_marshal_VOID__STRING_STRING_UINT_STRING_STRING,
+			      G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
 	signals [PK_TASK_MONITOR_ERROR_CODE] =
 		g_signal_new ("error-code",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
@@ -591,6 +592,11 @@ pk_task_monitor_init (PkTaskMonitor *tmo
 					   G_TYPE_NONE, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID);
 	dbus_g_object_register_marshaller (pk_marshal_VOID__UINT_STRING_STRING,
 					   G_TYPE_NONE, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_object_register_marshaller (pk_marshal_VOID__UINT_STRING_STRING_STRING_STRING_STRING,
+					   G_TYPE_NONE, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, 
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_object_register_marshaller (pk_marshal_VOID__UINT_STRING_STRING_STRING,
+					   G_TYPE_NONE, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
 	dbus_g_object_register_marshaller (pk_marshal_VOID__UINT_STRING_STRING_STRING_STRING,
 					   G_TYPE_NONE, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING,
 					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
@@ -635,7 +641,8 @@ pk_task_monitor_init (PkTaskMonitor *tmo
 	dbus_g_proxy_connect_signal (proxy, "UpdateDetail",
 				     G_CALLBACK (pk_task_monitor_update_detail_cb), tmonitor, NULL);
 	dbus_g_proxy_add_signal (proxy, "Description",
-				 G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+				 G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING,
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
 	dbus_g_proxy_connect_signal (proxy, "Description",
 				     G_CALLBACK (pk_task_monitor_description_cb), tmonitor, NULL);
 	dbus_g_proxy_add_signal (proxy, "ErrorCode",
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 3b419f8..03e18ab 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -207,13 +207,13 @@ pk_backend_parse_common_output (PkBacken
 			pk_warning ("invalid package_id");
 		}
 	} else if (strcmp (command, "description") == 0) {
-		if (size != 5) {
+		if (size != 6) {
 			g_error ("invalid command '%s'", command);
 			ret = FALSE;
 			goto out;
 		}
-		group = pk_group_enum_from_text (sections[2]);
-		pk_backend_description (backend, sections[1], group, sections[3], sections[4]);
+		group = pk_group_enum_from_text (sections[3]);
+		pk_backend_description (backend, sections[1], sections[2], group, sections[4], sections[5]);
 	} else {
 		pk_warning ("invalid command '%s'", command);
 	}
@@ -605,14 +605,15 @@ pk_backend_require_restart (PkBackend *b
  * pk_backend_description:
  **/
 gboolean
-pk_backend_description (PkBackend *backend, const gchar *package, PkGroupEnum group,
-		     const gchar *description, const gchar *url)
+pk_backend_description (PkBackend *backend, const gchar *package_id,
+			const gchar *licence, PkGroupEnum group,
+			const gchar *description, const gchar *url)
 {
 	g_return_val_if_fail (backend != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
 
-	pk_debug ("emit description %s, %i, %s, %s", package, group, description, url);
-	g_signal_emit (backend, signals [PK_TASK_DESCRIPTION], 0, package, group, description, url);
+	pk_debug ("emit description %s, %s, %i, %s, %s", package_id, licence, group, description, url);
+	g_signal_emit (backend, signals [PK_TASK_DESCRIPTION], 0, package_id, licence, group, description, url);
 
 	return TRUE;
 }
@@ -1182,8 +1183,8 @@ pk_backend_class_init (PkBackendClass *k
 	signals [PK_TASK_DESCRIPTION] =
 		g_signal_new ("description",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, pk_marshal_VOID__STRING_UINT_STRING_STRING,
-			      G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
+			      0, NULL, NULL, pk_marshal_VOID__STRING_STRING_UINT_STRING_STRING,
+			      G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
 	signals [PK_TASK_ERROR_CODE] =
 		g_signal_new ("error-code",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
diff --git a/src/pk-backend.h b/src/pk-backend.h
index ce78af5..da82bc1 100644
--- a/src/pk-backend.h
+++ b/src/pk-backend.h
@@ -57,7 +57,8 @@ gboolean	 pk_backend_require_restart		(P
 							 PkRestartEnum	 restart,
 							 const gchar	*details);
 gboolean	 pk_backend_description			(PkBackend	*backend,
-							 const gchar	*package,
+							 const gchar	*package_id,
+							 const gchar	*licence,
 							 PkGroupEnum	 group,
 							 const gchar	*description,
 							 const gchar	*url);
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 9850254..85fffc0 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -349,7 +349,7 @@ pk_engine_require_restart_cb (PkTask *ta
  * pk_engine_description_cb:
  **/
 static void
-pk_engine_description_cb (PkTask *task, const gchar *package_id, PkGroupEnum group,
+pk_engine_description_cb (PkTask *task, const gchar *package_id, const gchar *licence, PkGroupEnum group,
 			  const gchar *detail, const gchar *url, PkEngine *engine)
 {
 	PkJobListItem *item;
@@ -365,8 +365,8 @@ pk_engine_description_cb (PkTask *task, 
 	}
 	group_text = pk_group_enum_to_text (group);
 
-	pk_debug ("emitting description job:%i, %s, %s, %s, %s", item->job, package_id, group_text, detail, url);
-	g_signal_emit (engine, signals [PK_ENGINE_DESCRIPTION], 0, item->job, package_id, group_text, detail, url);
+	pk_debug ("emitting description job:%i, %s, %s, %s, %s, %s", item->job, package_id, licence, group_text, detail, url);
+	g_signal_emit (engine, signals [PK_ENGINE_DESCRIPTION], 0, item->job, package_id, licence, group_text, detail, url);
 }
 
 /**
@@ -1527,8 +1527,8 @@ pk_engine_class_init (PkEngineClass *kla
 	signals [PK_ENGINE_DESCRIPTION] =
 		g_signal_new ("description",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, pk_marshal_VOID__UINT_STRING_STRING_STRING_STRING,
-			      G_TYPE_NONE, 5, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+			      0, NULL, NULL, pk_marshal_VOID__UINT_STRING_STRING_STRING_STRING_STRING,
+			      G_TYPE_NONE, 6, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 	signals [PK_ENGINE_FINISHED] =
 		g_signal_new ("finished",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
diff --git a/src/pk-interface.xml b/src/pk-interface.xml
index c012668..6091215 100644
--- a/src/pk-interface.xml
+++ b/src/pk-interface.xml
@@ -92,6 +92,7 @@
     <signal name="Description">
       <arg type="u" name="job" direction="out"/>
       <arg type="s" name="package_id" direction="out"/>
+      <arg type="s" name="licence" direction="out"/>
       <arg type="s" name="group" direction="out"/>
       <arg type="s" name="detail" direction="out"/>
       <arg type="s" name="url" direction="out"/>
diff --git a/src/pk-marshal.list b/src/pk-marshal.list
index 78ea747..ca70f2b 100644
--- a/src/pk-marshal.list
+++ b/src/pk-marshal.list
@@ -1,15 +1,16 @@
-VOID:STRING,STRING
-VOID:UINT,STRING,STRING
-VOID:STRING,STRING,STRING,STRING
-VOID:STRING,UINT,STRING,STRING
-VOID:UINT,STRING,STRING,STRING,STRING
-VOID:UINT,UINT,STRING,STRING
-VOID:UINT,STRING,STRING
+VOID:UINT,BOOL
 VOID:UINT,UINT
-VOID:UINT,STRING
 VOID:UINT,STRING,UINT
+VOID:UINT,UINT,STRING,STRING
+VOID:UINT,STRING
 VOID:UINT,STRING,STRING
-VOID:UINT,BOOL
+VOID:UINT,STRING,STRING,STRING
+VOID:UINT,STRING,STRING,STRING,STRING
+VOID:UINT,STRING,STRING,STRING,STRING,STRING
 VOID:UINT,STRING,STRING,STRING,STRING,STRING,STRING
+VOID:STRING,STRING
+VOID:STRING,STRING,STRING,STRING
 VOID:STRING,STRING,STRING,STRING,STRING,STRING
+VOID:STRING,STRING,UINT,STRING,STRING
+VOID:STRING,UINT,STRING,STRING
 
diff-tree 9dde69266612566000df9c01c8fc17b7d35462b5 (from 10550cfba8580adcedf7c0966599d94743d5ce1d)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Sep 11 19:18:46 2007 +0100

    update TODO

diff --git a/TODO b/TODO
index d5179b5..8353e1e 100644
--- a/TODO
+++ b/TODO
@@ -6,6 +6,10 @@ but write jobs are done in serial. Maybe
 paused state?
 NOTE: RELEASE BLOCKER
 
+*** Have to have an UpdatesChanged signal ***
+For the icon to update after we've done a system upgrade
+NOTE: RELEASE BLOCKER
+
 *** Add a way to import GPG keys ***
 In fedora, if you add a signed repo you have to agree to the GPG key.
 
@@ -31,25 +35,8 @@ Depends on transaction_id and sqlite int
 
 *** Add "when installed" and "installed by" data into UI ***
 Is this useful?
-We would need to store package_id,installed_by,when_installed in a sqlite database
-
-*** Add GetUpdateDetail
-update_detail
-GetUpdateDetail(s=package_id)
-UpdateDetail(
-string package_id
-string updates
-string obsoletes
-string url
-string restart_enum
-string update_text
-}
-NOTE: RELEASE BLOCKER
-
-*** Have to have an UpdatesChanged signal ***
-For the icon to update after we've done a system upgrade
-NOTE: RELEASE BLOCKER
 
+We would need to store package_id,installed_by,when_installed in a sqlite database
 *** Dummy backend should use subpercent and install deps ***
 It's not a great test case right now...
 
diff-tree 10550cfba8580adcedf7c0966599d94743d5ce1d (from parents)
Merge: 45fdcf6952c14c2f47e30bd1f21a7619238e9b7d 6a1e775714ac7cf306fba465f7bd78d0402a5249
Author: Andreas Obergrusberger <tradiaz at yahoo.de>
Date:   Tue Sep 11 19:28:21 2007 +0200

    Merge branch 'master' of ssh://tradiaz@hughsient.no-ip.org/srv/git/PackageKit

diff-tree 45fdcf6952c14c2f47e30bd1f21a7619238e9b7d (from fbea625ff8e6f0d99070746baee5968dc450cc68)
Author: Andreas Obergrusberger <tradiaz at yahoo.de>
Date:   Tue Sep 11 19:27:49 2007 +0200

    alpm update

diff --git a/backends/alpm/pk-backend-alpm.c b/backends/alpm/pk-backend-alpm.c
index 044db56..d4afbc9 100644
--- a/backends/alpm/pk-backend-alpm.c
+++ b/backends/alpm/pk-backend-alpm.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ * Copyright (C) 2007 Andreas Obergrusberger <tradiaz at yahoo.de>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -20,6 +20,7 @@
  */
 
 #define ALPM_CONFIG_PATH "/etc/pacman.conf"
+#define PROGRESS_UPDATE_INTERVAL 400
 
 #include <gmodule.h>
 #include <glib.h>
@@ -31,6 +32,7 @@
 #include <alpm_list.h>
 
 static int progress_percentage;
+static int subprogress_percentage;
 
 typedef struct _PackageSource 
 {
@@ -39,18 +41,61 @@ typedef struct _PackageSource 
   guint installed;
 } PackageSource;
 
-
-static void
+void
 package_source_free (PackageSource *source)
 {
   alpm_pkg_free (source->pkg);
 }
 
+void
+trans_event_cb (pmtransevt_t event, void *data1, void *data2)
+{
+}
+
+void 
+trans_conv_cb (pmtransconv_t conv, 
+	       void *data1, void *data2, void *data3, 
+	       int *response)
+{
+}
+
+void 
+trans_prog_cb (pmtransprog_t prog, const char *pkgname, int percent,
+                       int n, int remain)
+{
+  subprogress_percentage = percent;
+}
+
+gboolean
+update_subprogress (void *data)
+{
+  if (subprogress_percentage == -1)
+    return FALSE;
+
+  pk_debug ("alpm: subprogress is %i", subprogress_percentage);  
+
+  pk_backend_change_percentage ((PkBackend *)data, subprogress_percentage);
+  return TRUE;
+}
+
+gboolean
+update_progress (void *data)
+{
+  if (progress_percentage == -1)
+    return FALSE;
+
+  pk_backend_change_percentage ((PkBackend *)data, progress_percentage);
+  return TRUE;
+}
+
 alpm_list_t *
 my_list_mmerge (alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn)
 {
   alpm_list_t *newlist, *lp;
 
+  if (left == NULL && right == NULL)
+    return NULL;
+
   if (left == NULL) 
     return right;
   if (right == NULL)
@@ -134,9 +179,13 @@ static void
 add_package (PkBackend *backend, PackageSource *package)
 { 
   gchar *pkg_string;
+  gchar *arch = (gchar *)alpm_pkg_get_arch (package->pkg);
+
+  if (arch == NULL) arch = "lala";
+
   pkg_string = pk_package_id_build(alpm_pkg_get_name (package->pkg), 
 				     alpm_pkg_get_version (package->pkg), 
-				     alpm_pkg_get_arch (package->pkg), 
+				     arch, 
 				     package->repo);
 
   pk_backend_package (backend, package->installed, pkg_string, alpm_pkg_get_desc (package->pkg));
@@ -170,12 +219,12 @@ find_packages ( const gchar *name, pmdb_
   needle = alpm_list_add (needle, (gchar *)name);
   dbname = alpm_db_get_name (db);
   result = alpm_db_search (db, needle);
+  localdb = alpm_option_get_localdb ();
 
   alpm_list_t *i = NULL;
 
   if (db != localdb)
     {
-      localdb = alpm_option_get_localdb ();
       if (localdb != NULL)
 	localresult = alpm_db_search (localdb, needle);
     }
@@ -201,9 +250,37 @@ find_packages ( const gchar *name, pmdb_
       i->data = source;
     }
 
+  alpm_list_free (needle);
+  if (localresult != NULL)
+    alpm_list_free_inner (localresult, (alpm_list_fn_free)alpm_pkg_free);
   return result;
 }
 
+gboolean
+pkg_is_installed (const gchar *name, const gchar *version)
+{
+  pmdb_t *localdb = NULL;
+  alpm_list_t *result = NULL;
+
+  if (name == NULL) return FALSE;
+  localdb = alpm_option_get_localdb ();
+  if (localdb == NULL) return FALSE;
+
+  result = find_packages (name, localdb);
+  if (result == NULL) return FALSE;
+  if (!alpm_list_count (result)) return FALSE; 
+
+  if (version == NULL)
+    return TRUE;
+
+  alpm_list_t *icmp = NULL;
+  for (icmp = result; icmp; icmp = alpm_list_next (icmp))
+    if (strcmp (alpm_pkg_get_version ((pmpkg_t *)icmp->data), version) == 0)
+      return TRUE;
+
+  return FALSE;
+}
+
 static void
 filter_packages_installed (alpm_list_t *packages, gboolean filter)
 {
@@ -222,6 +299,11 @@ filter_packages_installed (alpm_list_t *
     }
 }
 
+/*static void
+filter_packages_multiavail (alpm_list_t *packages, gboolean)
+{*/
+
+
 /**
  * backend_destroy:
  */
@@ -378,6 +460,49 @@ static void
 backend_refresh_cache (PkBackend *backend, gboolean force)
 {
 	g_return_if_fail (backend != NULL);
+	alpm_list_t *dbs = alpm_option_get_syncdbs ();
+	//alpm_list_t *problems = NULL;
+
+	if (alpm_trans_init (PM_TRANS_TYPE_SYNC, 0,
+		        trans_event_cb, trans_conv_cb, 
+			trans_prog_cb) != 0)
+	   {
+	    pk_backend_error_code (backend,
+				   PK_ERROR_ENUM_TRANSACTION_ERROR,
+				   alpm_strerror (pm_errno));
+	    pk_backend_finished (backend, PK_EXIT_ENUM_FAILED);
+	    return;
+	  }
+
+	pk_debug ("alpm: %s", "transaction initialized");
+
+/*	if (alpm_trans_prepare (&problems) != 0)
+	  {
+	    pk_backend_error_code (backend,
+				   PK_ERROR_ENUM_TRANSACTION_ERROR,
+				   alpm_strerror (pm_errno));
+	    pk_backend_finished (backend, PK_EXIT_ENUM_FAILED);
+	    return;
+	  }*/
+
+	alpm_list_t *i = NULL;
+	pk_backend_change_job_status (backend, PK_STATUS_ENUM_REFRESH_CACHE); 
+	g_timeout_add (PROGRESS_UPDATE_INTERVAL, update_subprogress, backend);
+	for (i = dbs; i; i = alpm_list_next (i))	
+	  {
+	    if (alpm_db_update (force, (pmdb_t *)i->data))
+	      {
+		pk_backend_error_code (backend, 
+				       PK_ERROR_ENUM_TRANSACTION_ERROR,  
+				       alpm_strerror (pm_errno));
+		alpm_list_free (dbs);
+		pk_backend_finished (backend, PK_EXIT_ENUM_FAILED);
+		subprogress_percentage = -1;
+		return;
+	      }
+	    subprogress_percentage = -1;
+	  }
+
 	pk_backend_finished (backend, PK_EXIT_ENUM_SUCCESS);
 }
 
@@ -429,25 +554,6 @@ backend_search_group (PkBackend *backend
 }
 
 /**
- * backend_search_name_timeout:
- **/
-gboolean
-backend_search_name_timeout (gpointer data)
-{
-	PkBackend *backend = (PkBackend *) data;
-	pk_backend_package (backend, 1, "evince;0.9.3-5.fc8;i386;installed",
-			 "PDF Document viewer");
-	pk_backend_package (backend, 1, "tetex;3.0-41.fc8;i386;fedora",
-			 "TeTeX is an implementation of TeX for Linux or UNIX systems.");
-	pk_backend_package (backend, 0, "scribus;1.3.4-1.fc8;i386;fedora",
-			 "Scribus is an desktop open source page layout program");
-	pk_backend_package (backend, 0, "vips-doc;7.12.4-2.fc8;noarch;linva",
-			 "The vips documentation package.");
-	pk_backend_finished (backend, PK_EXIT_ENUM_SUCCESS);
-	return FALSE;
-}
-
-/**
  * backend_search_name:
  */
 static void
@@ -455,6 +561,7 @@ backend_search_name (PkBackend *backend,
 {
 	g_return_if_fail (backend != NULL);
 	alpm_list_t *result = NULL;
+	alpm_list_t *localresult = NULL;
 	alpm_list_t *dbs = NULL;
 	gchar **sections = NULL;
 	gboolean installed = TRUE, ninstalled = TRUE;
@@ -476,19 +583,44 @@ backend_search_name (PkBackend *backend,
 	}
 	g_strfreev (sections);
 
-	pk_debug ("alpm: searching for \"%s\" - searchin in installed: %i, ~installed: %i",
+	pk_debug ("alpm: searching for \"%s\" - searching in installed: %i, ~installed: %i",
 		  search, installed, ninstalled);
 
-	if (installed) dbs = alpm_list_add (dbs, alpm_option_get_localdb ());
+	if (installed && !ninstalled) dbs = alpm_list_add (dbs, alpm_option_get_localdb ());
 	if (ninstalled) dbs = my_list_mmerge (dbs, alpm_option_get_syncdbs (), list_cmp_fn);
 
 	for (; dbs; dbs = alpm_list_next (dbs))
-	  result = my_list_mmerge (result, find_packages (search, (pmdb_t *)dbs->data), list_cmp_fn);
+	  result  = my_list_mmerge (result, find_packages (search, (pmdb_t *)dbs->data), list_cmp_fn);
+
+	if (ninstalled && installed)
+	  {
+	   pmdb_t *localdb = alpm_option_get_localdb ();
+	   if (localdb != NULL)
+	     {
+	       localresult = find_packages (search, localdb);
+	       alpm_list_t *i = NULL;
+	       for (i = alpm_list_first (result); i; i = alpm_list_next (i))
+		 {
+		   alpm_list_t *icmp = NULL;
+		   for (icmp = localresult; icmp; )
+		     if (pkg_equal ((pmpkg_t *)icmp->data, (pmpkg_t *)i->data))
+		       {
+			 alpm_list_t *tmp = icmp;
+			 icmp = alpm_list_next (icmp);
+			 my_list_remove_node (tmp);
+		       }
+		     else icmp = alpm_list_next (icmp);
+		 }
+	     }
+	   else  pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR,
+					"Could not find local db");
+	   result = my_list_mmerge (result, localresult, list_cmp_fn);
+	  }
 
 	if (!installed) filter_packages_installed (result, TRUE);
 	if (!ninstalled) filter_packages_installed (result, FALSE);	
 	
-	add_packages_from_list (backend, result);
+	add_packages_from_list (backend, alpm_list_first (result));
 	pk_backend_finished  (backend, PK_EXIT_ENUM_SUCCESS); 
 }
 
diff-tree fbea625ff8e6f0d99070746baee5968dc450cc68 (from ca3f2f7b0636a9bff3557f5d1c39611dc951f3ae)
Author: Andreas Obergrusberger <tradiaz at yahoo.de>
Date:   Tue Sep 11 15:15:13 2007 +0200

    alpm is listed in BACKENDS now

diff --git a/backends/BACKENDS b/backends/BACKENDS
index ce6f38c..82ba119 100644
--- a/backends/BACKENDS
+++ b/backends/BACKENDS
@@ -1,14 +1,14 @@
 Current status of the backends
 
-                |   conary  |   yum |   apt |   box |
------------------------------------------------------
-refresh-cache   |     X     |   X   |   X   |   X   |
-search-name     |     X     |   X   |   X   |   X   |
-search-details  |           |   X   |   X   |       |
-get-updates     |     X     |   X   |       |   X   |
-update-system   |           |   X   |       |       |
-install         |           |   X   |       |       |
-remove          |           |   X   |       |       |
-get-deps        |           |   X   |       |       |
-get-description |     X     |       |   X   |   X   |
-search-file     |           |       |       |   X   |
+                |   conary  |   yum |   apt |   box |   alpm|
+-------------------------------------------------------------
+refresh-cache   |     X     |   X   |   X   |   X   |       |
+search-name     |     X     |   X   |   X   |   X   |   X   |
+search-details  |           |   X   |   X   |       |       |
+get-updates     |     X     |   X   |       |   X   |       |
+update-system   |           |   X   |       |       |       |
+install         |           |   X   |       |       |       |
+remove          |           |   X   |       |       |       |
+get-deps        |           |   X   |       |       |       |
+get-description |     X     |       |   X   |   X   |       |
+search-file     |           |       |       |   X   |       |



More information about the PackageKit mailing list