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

Richard Hughes hughsient at kemper.freedesktop.org
Tue Oct 2 16:02:13 PDT 2007


 TODO                            |   13 +-
 libpackagekit/Makefile.am       |    7 -
 libpackagekit/pk-client.c       |   37 +-----
 libpackagekit/pk-client.h       |    8 -
 libpackagekit/pk-package-list.c |  244 ++++++++++++++++++++++++++++++++++++++++
 libpackagekit/pk-package-list.h |   69 +++++++++++
 libpackagekit/pk-self-test.c    |    2 
 src/pk-engine.c                 |   17 +-
 src/pk-transaction-list.c       |    4 
 src/pk-transaction-list.h       |    3 
 10 files changed, 347 insertions(+), 57 deletions(-)

New commits:
diff-tree 74032405a96c4763c8f9cc93524f4a23896589dc (from a0d7378b1e8b02f6da5646fe814e26c8f550df8f)
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 3 00:02:03 2007 +0100

    update TODO

diff --git a/TODO b/TODO
index 6073558..517cb00 100644
--- a/TODO
+++ b/TODO
@@ -8,18 +8,22 @@ NOTE: RELEASE BLOCKER
 *** don't output the same package in different repos ***
 Need to store Package() in the server properly, and compare the first chunk
 (not the data) to avoid reporting the same package more than once.
-We can also use this in the client library (perhaps?)
 Also: pk_package_id_compare (gboolean use_data)
-Need to unit test...
+Need to properly unit test...
 NOTE: RELEASE BLOCKER
 
 *** Add new callback for status ***
 TimeRemaining()
  
-*** Get the deps in the UI when removing ***
+*** get the depends and requires in the tabbed UI ***
 We really don't want to remove glibc...
 NOTE: RELEASE BLOCKER
 
+*** the backends will have repo controls ***
+a(s=rid,s=description)=GetRepoList()
+RepoEnable(s=rid,s=value)
+RepoSetData(s=rid,s=data,s=value)
+
 *** pk-application (client) ***
 Use an icons for installed and not-installed rather than tickboxes
 Refresh the query list after an install or remove (means saving the query and re-issuing)
diff-tree a0d7378b1e8b02f6da5646fe814e26c8f550df8f (from d800936b1b3b5acfa2d3e9b2a6b1b0d4c72b0f39)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 2 23:40:46 2007 +0100

    use PkPackageList in PkClient to reduce code duplication

diff --git a/libpackagekit/pk-client.c b/libpackagekit/pk-client.c
index 5a81872..cfe5863 100644
--- a/libpackagekit/pk-client.c
+++ b/libpackagekit/pk-client.c
@@ -35,6 +35,7 @@
 
 #include "pk-client.h"
 #include "pk-connection.h"
+#include "pk-package-list.h"
 #include "pk-debug.h"
 #include "pk-marshal.h"
 #include "pk-polkit-client.h"
@@ -53,7 +54,7 @@ struct PkClientPrivate
 	gboolean	 is_finished;
 	gboolean	 use_buffer;
 	gchar		*tid;
-	GPtrArray	*cache_package;
+	PkPackageList	*package_list;
 	PkConnection	*pconnection;
 	PkPolkitClient	*polkit;
 	PkRestartEnum	 require_restart;
@@ -163,23 +164,7 @@ pk_client_get_package_buffer (PkClient *
 	if (client->priv->use_buffer == FALSE) {
 		return NULL;
 	}
-	return client->priv->cache_package;
-}
-
-/**
- * pk_client_remove_cache_package:
- **/
-static void
-pk_client_remove_cache_package (PkClient *client)
-{
-	PkClientPackageItem *item;
-	while (client->priv->cache_package->len > 0) {
-		item = g_ptr_array_index (client->priv->cache_package, 0);
-		g_free (item->package_id);
-		g_free (item->summary);
-		g_free (item);
-		g_ptr_array_remove_index_fast (client->priv->cache_package, 0);
-	}
+	return pk_package_list_get_buffer (client->priv->package_list);
 }
 
 /**
@@ -200,7 +185,7 @@ pk_client_reset (PkClient *client)
 	client->priv->tid = NULL;
 	client->priv->last_status = PK_STATUS_ENUM_UNKNOWN;
 	client->priv->is_finished = FALSE;
-	pk_client_remove_cache_package (client);
+	pk_package_list_remove_buffer (client->priv->package_list);
 	return TRUE;
 }
 
@@ -333,7 +318,6 @@ pk_client_package_cb (DBusGProxy   *prox
 		      const gchar  *summary,
 		      PkClient     *client)
 {
-	PkClientPackageItem *item;
 	PkInfoEnum info;
 	g_return_if_fail (client != NULL);
 	g_return_if_fail (PK_IS_CLIENT (client));
@@ -346,11 +330,7 @@ pk_client_package_cb (DBusGProxy   *prox
 		/* cache */
 		if (client->priv->use_buffer == TRUE) {
 			pk_debug ("adding to cache array package %i, %s, %s", info, package_id, summary);
-			item = g_new0 (PkClientPackageItem, 1);
-			item->info = info;
-			item->package_id = g_strdup (package_id);
-			item->summary = g_strdup (summary);
-			g_ptr_array_add (client->priv->cache_package, item);
+			pk_package_list_add (client->priv->package_list, info, package_id, summary);
 		}
 	}
 }
@@ -1775,7 +1755,7 @@ pk_client_init (PkClient *client)
 	client->priv->last_status = PK_STATUS_ENUM_UNKNOWN;
 	client->priv->require_restart = PK_RESTART_ENUM_NONE;
 	client->priv->is_finished = FALSE;
-	client->priv->cache_package = g_ptr_array_new ();
+	client->priv->package_list = pk_package_list_new ();
 
 	/* check dbus connections, exit if not valid */
 	client->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
@@ -1943,10 +1923,7 @@ pk_client_finalize (GObject *object)
 	g_object_unref (G_OBJECT (client->priv->proxy));
 	g_object_unref (client->priv->pconnection);
 	g_object_unref (client->priv->polkit);
-
-	/* removed any cached packages */
-	pk_client_remove_cache_package (client);
-	g_ptr_array_free (client->priv->cache_package, TRUE);
+	g_object_unref (client->priv->package_list);
 
 	G_OBJECT_CLASS (pk_client_parent_class)->finalize (object);
 }
diff --git a/libpackagekit/pk-client.h b/libpackagekit/pk-client.h
index 6b6d7fb..838baa0 100644
--- a/libpackagekit/pk-client.h
+++ b/libpackagekit/pk-client.h
@@ -48,14 +48,6 @@ typedef struct
 	GObjectClass	parent_class;
 } PkClientClass;
 
-/* used if we are collecting packages sync */
-typedef struct
-{
-	PkInfoEnum		 info;
-	gchar			*package_id;
-	gchar			*summary;
-} PkClientPackageItem;
-
 GType		 pk_client_get_type			(void);
 PkClient	*pk_client_new				(void);
 
diff --git a/libpackagekit/pk-package-list.c b/libpackagekit/pk-package-list.c
index 01114fb..73475dc 100644
--- a/libpackagekit/pk-package-list.c
+++ b/libpackagekit/pk-package-list.c
@@ -107,7 +107,7 @@ pk_package_list_get_string (PkPackageLis
  * pk_plist_get_package_buffer:
  **/
 GPtrArray *
-pk_package_list_get_package_buffer (PkPackageList *plist)
+pk_package_list_get_buffer (PkPackageList *plist)
 {
 	g_return_val_if_fail (plist != NULL, NULL);
 	g_return_val_if_fail (PK_IS_PACKAGE_LIST (plist), NULL);
@@ -115,15 +115,15 @@ pk_package_list_get_package_buffer (PkPa
 }
 
 /**
- * pk_plist_remove_array:
+ * pk_package_list_remove_buffer:
  **/
-static void
-pk_plist_remove_array (PkPackageList *plist)
+gboolean
+pk_package_list_remove_buffer (PkPackageList *plist)
 {
 	PkPackageListItem *item;
 
-	g_return_if_fail (plist != NULL);
-	g_return_if_fail (PK_IS_PACKAGE_LIST (plist));
+	g_return_val_if_fail (plist != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_PACKAGE_LIST (plist), FALSE);
 
 	while (plist->priv->array->len > 0) {
 		item = g_ptr_array_index (plist->priv->array, 0);
@@ -132,6 +132,7 @@ pk_plist_remove_array (PkPackageList *pl
 		g_free (item);
 		g_ptr_array_remove_index_fast (plist->priv->array, 0);
 	}
+	return TRUE;
 }
 
 /**
@@ -173,7 +174,7 @@ pk_package_list_finalize (GObject *objec
 	g_return_if_fail (plist->priv != NULL);
 
 	/* removed any cached packages */
-	pk_plist_remove_array (plist);
+	pk_package_list_remove_buffer (plist);
 	g_ptr_array_free (plist->priv->array, TRUE);
 
 	G_OBJECT_CLASS (pk_package_list_parent_class)->finalize (object);
diff --git a/libpackagekit/pk-package-list.h b/libpackagekit/pk-package-list.h
index 76fbc28..5685827 100644
--- a/libpackagekit/pk-package-list.h
+++ b/libpackagekit/pk-package-list.h
@@ -61,7 +61,8 @@ gboolean	 pk_package_list_add			(PkPacka
 							 const gchar		*package_id,
 							 const gchar		*summary);
 gchar		*pk_package_list_get_string		(PkPackageList		*plist);
-GPtrArray	*pk_package_list_get_package_buffer	(PkPackageList		*plist);
+GPtrArray	*pk_package_list_get_buffer		(PkPackageList		*plist);
+gboolean	 pk_package_list_remove_buffer		(PkPackageList		*plist);
 
 G_END_DECLS
 
diff-tree d800936b1b3b5acfa2d3e9b2a6b1b0d4c72b0f39 (from 2509a191fa55a76c430945e2b9d21a39f970dde8)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 2 23:26:30 2007 +0100

    use pk-package-list in the daemon

diff --git a/TODO b/TODO
index 4528da3..6073558 100644
--- a/TODO
+++ b/TODO
@@ -8,7 +8,6 @@ NOTE: RELEASE BLOCKER
 *** don't output the same package in different repos ***
 Need to store Package() in the server properly, and compare the first chunk
 (not the data) to avoid reporting the same package more than once.
-Instead of Gstring have PkPackageCache instance.
 We can also use this in the client library (perhaps?)
 Also: pk_package_id_compare (gboolean use_data)
 Need to unit test...
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 8f2bde3..fa5b91c 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -39,6 +39,7 @@
 #include <polkit/polkit.h>
 #include <polkit-dbus/polkit-dbus.h>
 #include <pk-package-id.h>
+#include <pk-package-list.h>
 
 #include <pk-debug.h>
 #include <pk-task-common.h>
@@ -267,7 +268,6 @@ pk_engine_package_cb (PkBackend *backend
 {
 	PkTransactionItem *item;
 	const gchar *info_text;
-	gchar *cache;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
@@ -277,14 +277,11 @@ pk_engine_package_cb (PkBackend *backend
 		pk_warning ("could not find backend");
 		return;
 	}
-	info_text = pk_info_enum_to_text (info);
 
 	/* add to package cache */
-	cache = g_strdup_printf ("%s\t%s\t%s\n", info_text, package_id, summary);
-	pk_debug ("cache='%s'", cache);
-	g_string_append (item->package_cache, cache);
-	g_free (cache);
+	pk_package_list_add (item->package_list, info, package_id, summary);
 
+	info_text = pk_info_enum_to_text (info);
 	pk_debug ("emitting package tid:%s info=%s %s, %s", item->tid, info_text, package_id, summary);
 	g_signal_emit (engine, signals [PK_ENGINE_PACKAGE], 0, item->tid, info_text, package_id, summary);
 	pk_engine_reset_timer (engine);
@@ -419,6 +416,7 @@ pk_engine_finished_cb (PkBackend *backen
 	PkRoleEnum role;
 	const gchar *exit_text;
 	gdouble time;
+	gchar *packages;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
@@ -434,10 +432,11 @@ pk_engine_finished_cb (PkBackend *backen
 	time = pk_backend_get_runtime (backend);
 
 	/* add to the database */
-	if (item->package_cache->len != 0) {
-		g_string_set_size (item->package_cache, item->package_cache->len-1);
-		pk_transaction_db_set_data (engine->priv->transaction_db, item->tid, item->package_cache->str);
+	packages = pk_package_list_get_string (item->package_list);
+	if (strlen (packages) > 0) {
+		pk_transaction_db_set_data (engine->priv->transaction_db, item->tid, packages);
 	}
+	g_free (packages);
 
 	pk_debug ("backend was running for %f seconds", time);
 	pk_transaction_db_set_finished (engine->priv->transaction_db, item->tid, TRUE, time);
diff --git a/src/pk-transaction-list.c b/src/pk-transaction-list.c
index 44b86e8..0d18bb1 100644
--- a/src/pk-transaction-list.c
+++ b/src/pk-transaction-list.c
@@ -104,7 +104,7 @@ pk_transaction_list_create (PkTransactio
 	item->committed = FALSE;
 	item->running = FALSE;
 	item->backend = NULL;
-	item->package_cache = g_string_new ("");
+	item->package_list = pk_package_list_new ();
 	item->tid = pk_transaction_id_generate ();
 	g_ptr_array_add (tlist->priv->array, item);
 	return item;
@@ -121,8 +121,8 @@ pk_transaction_list_remove (PkTransactio
 
 	/* valid item */
 	g_ptr_array_remove (tlist->priv->array, item);
+	g_object_unref (item->package_list);
 	g_free (item->tid);
-	g_string_free (item->package_cache, TRUE);
 	g_free (item);
 
 	/* we have changed what is running */
diff --git a/src/pk-transaction-list.h b/src/pk-transaction-list.h
index 818f815..2add6d6 100644
--- a/src/pk-transaction-list.h
+++ b/src/pk-transaction-list.h
@@ -24,6 +24,7 @@
 
 #include <glib-object.h>
 #include "pk-backend-internal.h"
+#include "pk-package-list.h"
 
 G_BEGIN_DECLS
 
@@ -54,7 +55,7 @@ typedef struct {
 	gboolean		 running;
 	PkBackend		*backend;
 	gchar			*tid;
-	GString			*package_cache;
+	PkPackageList		*package_list;
 } PkTransactionItem;
 
 GType		 pk_transaction_list_get_type	  	(void);
diff-tree 2509a191fa55a76c430945e2b9d21a39f970dde8 (from d62660cdb4d39b7a92f7392c5dd3b59d59ebcc31)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 2 23:14:43 2007 +0100

    add get_string to package_list

diff --git a/libpackagekit/pk-package-list.c b/libpackagekit/pk-package-list.c
index 9a88db5..01114fb 100644
--- a/libpackagekit/pk-package-list.c
+++ b/libpackagekit/pk-package-list.c
@@ -78,10 +78,29 @@ pk_package_list_add (PkPackageList *plis
 gchar *
 pk_package_list_get_string (PkPackageList *plist)
 {
+	PkPackageListItem *item;
+	guint i;
+	guint length;
+	const gchar *info_text;
+	GString *package_cache;
+
 	g_return_val_if_fail (plist != NULL, NULL);
 	g_return_val_if_fail (PK_IS_PACKAGE_LIST (plist), NULL);
 
-	return NULL;
+	package_cache = g_string_new ("");
+	length = plist->priv->array->len;
+	for (i=0; i<length; i++) {
+		item = g_ptr_array_index (plist->priv->array, i);
+		info_text = pk_info_enum_to_text (item->info);
+		g_string_append_printf (package_cache, "%s\t%s\t%s\n", info_text, item->package_id, item->summary);
+	}
+
+	/* remove trailing newline */
+	if (package_cache->len != 0) {
+		g_string_set_size (package_cache, package_cache->len-1);
+	}
+
+	return g_string_free (package_cache, FALSE);
 }
 
 /**
@@ -183,6 +202,7 @@ void
 libst_package_list (LibSelfTest *test)
 {
 	PkPackageList *plist;
+	gchar *text;
 	gboolean ret;
 
 	if (libst_start (test, "PkPackageList", CLASS_AUTO) == FALSE) {
@@ -207,6 +227,16 @@ libst_package_list (LibSelfTest *test)
 		libst_failed (test, NULL);
 	}
 
+	/************************************************************/
+	libst_title (test, "add entry");
+	text = pk_package_list_get_string (plist);
+	if (text != NULL && strcmp (text, "installed\tgnome;1.23;i386;data\tGNOME!") == 0) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "get string incorrect '%s'", text);
+	}
+	g_free (text);
+
 	libst_end (test);
 }
 #endif
diff-tree d62660cdb4d39b7a92f7392c5dd3b59d59ebcc31 (from f28a3317b1115b21088eba68e20e01cef8cf956a)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 2 22:59:53 2007 +0100

    add the package list code to be used in the daemon and client

diff --git a/TODO b/TODO
index d6eec31..4528da3 100644
--- a/TODO
+++ b/TODO
@@ -8,9 +8,7 @@ NOTE: RELEASE BLOCKER
 *** don't output the same package in different repos ***
 Need to store Package() in the server properly, and compare the first chunk
 (not the data) to avoid reporting the same package more than once.
-Have pk-package-cache.c object which is created in pk-backend for each instance
 Instead of Gstring have PkPackageCache instance.
-pk_package_cache_add (i=role, s=package_id, s=summary) s=pk_package_cache_get_string()
 We can also use this in the client library (perhaps?)
 Also: pk_package_id_compare (gboolean use_data)
 Need to unit test...
diff --git a/libpackagekit/Makefile.am b/libpackagekit/Makefile.am
index 4d60534..77bcfee 100644
--- a/libpackagekit/Makefile.am
+++ b/libpackagekit/Makefile.am
@@ -28,6 +28,7 @@ libpackagekit_include_HEADERS =					\
 	pk-debug.h						\
 	pk-connection.h						\
 	pk-package-id.h						\
+	pk-package-list.h					\
 	pk-enum-list.h						\
 	pk-enum.h						\
 	pk-task-common.h					\
@@ -44,8 +45,10 @@ libpackagekit_la_SOURCES =					\
 	pk-marshal.h						\
 	pk-connection.c						\
 	pk-connection.h						\
-	pk-package-id.h						\
 	pk-package-id.c						\
+	pk-package-id.h						\
+	pk-package-list.c					\
+	pk-package-list.h					\
 	pk-enum-list.c						\
 	pk-enum-list.h						\
 	pk-enum.h						\
@@ -84,6 +87,8 @@ pk_self_test_SOURCES =						\
 	pk-enum-list.c						\
 	pk-package-id.h						\
 	pk-package-id.c						\
+	pk-package-list.h					\
+	pk-package-list.c					\
 	pk-self-test.c						\
 	$(NULL)
 
diff --git a/libpackagekit/pk-package-list.c b/libpackagekit/pk-package-list.c
new file mode 100644
index 0000000..9a88db5
--- /dev/null
+++ b/libpackagekit/pk-package-list.c
@@ -0,0 +1,213 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <errno.h>
+
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#include <glib/gi18n.h>
+
+#include "pk-debug.h"
+#include "pk-package-list.h"
+
+static void     pk_package_list_class_init	(PkPackageListClass *klass);
+static void     pk_package_list_init		(PkPackageList      *plist);
+static void     pk_package_list_finalize	(GObject            *object);
+
+#define PK_PACKAGE_LIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_PACKAGE_LIST, PkPackageListPrivate))
+
+struct PkPackageListPrivate
+{
+	GPtrArray	*array;
+};
+
+G_DEFINE_TYPE (PkPackageList, pk_package_list, G_TYPE_OBJECT)
+
+/**
+ * pk_package_list_add:
+ **/
+gboolean
+pk_package_list_add (PkPackageList *plist, PkInfoEnum info, const gchar *package_id, const gchar *summary)
+{
+	PkPackageListItem *item;
+
+	g_return_val_if_fail (plist != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_PACKAGE_LIST (plist), FALSE);
+
+	pk_debug ("adding to cache array package %i, %s, %s", info, package_id, summary);
+	item = g_new0 (PkPackageListItem, 1);
+	item->info = info;
+	item->package_id = g_strdup (package_id);
+	item->summary = g_strdup (summary);
+	g_ptr_array_add (plist->priv->array, item);
+
+	return TRUE;
+}
+
+/**
+ * pk_package_list_get_string:
+ **/
+gchar *
+pk_package_list_get_string (PkPackageList *plist)
+{
+	g_return_val_if_fail (plist != NULL, NULL);
+	g_return_val_if_fail (PK_IS_PACKAGE_LIST (plist), NULL);
+
+	return NULL;
+}
+
+/**
+ * pk_plist_get_package_buffer:
+ **/
+GPtrArray *
+pk_package_list_get_package_buffer (PkPackageList *plist)
+{
+	g_return_val_if_fail (plist != NULL, NULL);
+	g_return_val_if_fail (PK_IS_PACKAGE_LIST (plist), NULL);
+	return plist->priv->array;
+}
+
+/**
+ * pk_plist_remove_array:
+ **/
+static void
+pk_plist_remove_array (PkPackageList *plist)
+{
+	PkPackageListItem *item;
+
+	g_return_if_fail (plist != NULL);
+	g_return_if_fail (PK_IS_PACKAGE_LIST (plist));
+
+	while (plist->priv->array->len > 0) {
+		item = g_ptr_array_index (plist->priv->array, 0);
+		g_free (item->package_id);
+		g_free (item->summary);
+		g_free (item);
+		g_ptr_array_remove_index_fast (plist->priv->array, 0);
+	}
+}
+
+/**
+ * pk_package_list_class_init:
+ * @klass: The PkPackageListClass
+ **/
+static void
+pk_package_list_class_init (PkPackageListClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = pk_package_list_finalize;
+	g_type_class_add_private (klass, sizeof (PkPackageListPrivate));
+}
+
+/**
+ * pk_package_list_init:
+ **/
+static void
+pk_package_list_init (PkPackageList *plist)
+{
+	g_return_if_fail (plist != NULL);
+	g_return_if_fail (PK_IS_PACKAGE_LIST (plist));
+
+	plist->priv = PK_PACKAGE_LIST_GET_PRIVATE (plist);
+	plist->priv->array = g_ptr_array_new ();
+}
+
+/**
+ * pk_package_list_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_package_list_finalize (GObject *object)
+{
+	PkPackageList *plist;
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (PK_IS_PACKAGE_LIST (object));
+	plist = PK_PACKAGE_LIST (object);
+	g_return_if_fail (plist->priv != NULL);
+
+	/* removed any cached packages */
+	pk_plist_remove_array (plist);
+	g_ptr_array_free (plist->priv->array, TRUE);
+
+	G_OBJECT_CLASS (pk_package_list_parent_class)->finalize (object);
+}
+
+/**
+ * pk_package_list_new:
+ *
+ * Return value: a new PkPackageList object.
+ **/
+PkPackageList *
+pk_package_list_new (void)
+{
+	PkPackageList *plist;
+	plist = g_object_new (PK_TYPE_PACKAGE_LIST, NULL);
+	return PK_PACKAGE_LIST (plist);
+}
+
+/***************************************************************************
+ ***                          MAKE CHECK TESTS                           ***
+ ***************************************************************************/
+#ifdef PK_BUILD_TESTS
+#include <libselftest.h>
+
+void
+libst_package_list (LibSelfTest *test)
+{
+	PkPackageList *plist;
+	gboolean ret;
+
+	if (libst_start (test, "PkPackageList", CLASS_AUTO) == FALSE) {
+		return;
+	}
+
+	/************************************************************/
+	libst_title (test, "create");
+	plist = pk_package_list_new ();
+	if (plist != NULL) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/************************************************************/
+	libst_title (test, "add entry");
+	ret = pk_package_list_add (plist, PK_INFO_ENUM_INSTALLED, "gnome;1.23;i386;data", "GNOME!");
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	libst_end (test);
+}
+#endif
+
diff --git a/libpackagekit/pk-package-list.h b/libpackagekit/pk-package-list.h
new file mode 100644
index 0000000..76fbc28
--- /dev/null
+++ b/libpackagekit/pk-package-list.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PK_PACKAGE_LIST_H
+#define __PK_PACKAGE_LIST_H
+
+#include <glib-object.h>
+#include <pk-enum.h>
+
+G_BEGIN_DECLS
+
+#define PK_TYPE_PACKAGE_LIST		(pk_package_list_get_type ())
+#define PK_PACKAGE_LIST(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_PACKAGE_LIST, PkPackageList))
+#define PK_PACKAGE_LIST_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_PACKAGE_LIST, PkPackageListClass))
+#define PK_IS_PACKAGE_LIST(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_PACKAGE_LIST))
+#define PK_IS_PACKAGE_LIST_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_PACKAGE_LIST))
+#define PK_PACKAGE_LIST_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_PACKAGE_LIST, PkPackageListClass))
+
+typedef struct PkPackageListPrivate PkPackageListPrivate;
+
+typedef struct
+{
+	 GObject		 parent;
+	 PkPackageListPrivate	*priv;
+} PkPackageList;
+
+typedef struct
+{
+	GObjectClass	parent_class;
+} PkPackageListClass;
+
+typedef struct
+{
+	PkInfoEnum		 info;
+	gchar			*package_id;
+	gchar			*summary;
+} PkPackageListItem;
+
+GType		 pk_package_list_get_type		(void);
+PkPackageList	*pk_package_list_new			(void);
+gboolean	 pk_package_list_add			(PkPackageList		*plist,
+							 PkInfoEnum		 info,
+							 const gchar		*package_id,
+							 const gchar		*summary);
+gchar		*pk_package_list_get_string		(PkPackageList		*plist);
+GPtrArray	*pk_package_list_get_package_buffer	(PkPackageList		*plist);
+
+G_END_DECLS
+
+#endif /* __PK_PACKAGE_LIST_H */
diff --git a/libpackagekit/pk-self-test.c b/libpackagekit/pk-self-test.c
index ae490b1..d53bcf9 100644
--- a/libpackagekit/pk-self-test.c
+++ b/libpackagekit/pk-self-test.c
@@ -25,6 +25,7 @@
 
 /* prototypes */
 void libst_package_id (LibSelfTest *test);
+void libst_package_list (LibSelfTest *test);
 void libst_enum (LibSelfTest *test);
 void libst_enum_list (LibSelfTest *test);
 
@@ -38,6 +39,7 @@ main (int argc, char **argv)
 
 	/* tests go here */
 	libst_package_id (&test);
+	libst_package_list (&test);
 	libst_enum (&test);
 	libst_enum_list (&test);
 



More information about the PackageKit mailing list