[gnome-packagekit/glib2: 5/79] moo



commit 6b7412a334efce769ee700839480a60911b4d16b
Author: Richard Hughes <richard hughsie com>
Date:   Wed Sep 9 18:22:22 2009 +0100

    moo

 src/Makefile.am        |   11 ++++-
 src/gpk-application.c  |    2 +-
 src/gpk-check-update.c |    4 +-
 src/gpk-common.c       |  133 ++++++++++++++++++++++++++++-------------------
 src/gpk-common.h       |    7 +--
 src/gpk-log.c          |  116 ++++++++++++++++++++++++------------------
 src/gpk-watch.c        |    2 +-
 7 files changed, 161 insertions(+), 114 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c136ea6..4a3c535 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -250,10 +250,19 @@ gpk_repo_LDADD =					\
 
 gpk_log_SOURCES =					\
 	gpk-log.c					\
+	egg-debug.c					\
+	egg-debug.h					\
+	gpk-enum.h					\
+	gpk-enum.c					\
+	gpk-common.h					\
+	gpk-common.c					\
+	gpk-gnome.h					\
+	gpk-gnome.c					\
+	gpk-animated-icon.c				\
+	gpk-animated-icon.h				\
 	$(NULL)
 
 gpk_log_LDADD =						\
-	libgpkshared.a					\
 	$(shared_LIBS)					\
 	$(NULL)
 
diff --git a/src/gpk-application.c b/src/gpk-application.c
index 80d0941..5539d0e 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -3307,7 +3307,7 @@ gpk_application_create_group_list_enum (GpkApplication *application)
 static void
 gpk_application_categories_finished (GpkApplication *application)
 {
-	PkObjList *list;
+	GPtrArray *list;
 	const PkCategoryObj *obj;
 	const PkCategoryObj *obj2;
 	GtkTreeIter iter;
diff --git a/src/gpk-check-update.c b/src/gpk-check-update.c
index e14aeb2..8698174 100644
--- a/src/gpk-check-update.c
+++ b/src/gpk-check-update.c
@@ -1093,7 +1093,7 @@ out:
  * gpk_check_update_process_distro_upgrades:
  **/
 static void
-gpk_check_update_process_distro_upgrades (GpkCheckUpdate *cupdate, PkObjList *array)
+gpk_check_update_process_distro_upgrades (GpkCheckUpdate *cupdate, GPtrArray *array)
 {
 	gboolean ret;
 	GError *error = NULL;
@@ -1389,7 +1389,7 @@ gpk_check_update_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runt
 {
 	PkRoleEnum role;
 	GPtrArray *list;
-	PkObjList *array;
+	GPtrArray *array;
 
 	pk_client_get_role (client, &role, NULL, NULL);
 	egg_debug ("role: %s, exit: %s", pk_role_enum_to_text (role), pk_exit_enum_to_text (exit_enum));
diff --git a/src/gpk-common.c b/src/gpk-common.c
index 0302530..c943b9a 100644
--- a/src/gpk-common.c
+++ b/src/gpk-common.c
@@ -200,15 +200,6 @@ gtk_text_buffer_insert_markup (GtkTextBuffer *buffer, GtkTextIter *iter, const g
 }
 
 /**
- * gpk_window_get_small_form_factor_mode:
- **/
-gboolean
-gpk_window_get_small_form_factor_mode (void)
-{
-	return small_form_factor_mode;
-}
-
-/**
  * gpk_window_set_size_request:
  **/
 gboolean
@@ -276,31 +267,34 @@ gpk_window_set_parent_xid (GtkWindow *window, guint32 xid)
  * Return value: "<b>GTK Toolkit</b>\ngtk2-2.12.2 (i386)"
  **/
 gchar *
-gpk_package_id_format_twoline (const gchar *id, const gchar *summary)
+gpk_package_id_format_twoline (const gchar *package_id, const gchar *summary)
 {
 	gchar *summary_safe;
 	gchar *text;
 	GString *string;
+	gchar **split;
 
-	g_return_val_if_fail (id != NULL, NULL);
+	g_return_val_if_fail (package_id != NULL, NULL);
 
 	/* optional */
-	if (egg_strzero (summary)) {
-		string = g_string_new (id->name);
+	split = pk_package_id_split (package_id);
+	if (summary == NULL || summary[0] == '\0') {
+		string = g_string_new (split[0]);
 	} else {
 		string = g_string_new ("");
 		summary_safe = g_markup_escape_text (summary, -1);
-		g_string_append_printf (string, "<b>%s</b>\n%s", summary_safe, id->name);
+		g_string_append_printf (string, "<b>%s</b>\n%s", summary_safe, split[0]);
 		g_free (summary_safe);
 	}
 
 	/* some backends don't provide this */
-	if (id->version != NULL)
-		g_string_append_printf (string, "-%s", id->version);
-	if (id->arch != NULL)
-		g_string_append_printf (string, " (%s)", id->arch);
+	if (split[1][0] != '\0')
+		g_string_append_printf (string, "-%s", split[2]);
+	if (split[2][0] != '\0')
+		g_string_append_printf (string, " (%s)", split[3]);
 
 	text = g_string_free (string, FALSE);
+	g_strfreev (split);
 	return text;
 }
 
@@ -310,39 +304,24 @@ gpk_package_id_format_twoline (const gchar *id, const gchar *summary)
  * Return value: "<b>GTK Toolkit</b> (gtk2)"
  **/
 gchar *
-gpk_package_id_format_oneline (const gchar *id, const gchar *summary)
+gpk_package_id_format_oneline (const gchar *package_id, const gchar *summary)
 {
 	gchar *summary_safe;
 	gchar *text;
+	gchar **split;
 
-	if (egg_strzero (summary)) {
+	g_return_val_if_fail (package_id != NULL, NULL);
+
+	split = pk_package_id_split (package_id);
+	if (summary == NULL || summary[0] == '\0') {
 		/* just have name */
-		text = g_strdup (id->name);
+		text = g_strdup (split[0]);
 	} else {
 		summary_safe = g_markup_escape_text (summary, -1);
-		text = g_strdup_printf ("<b>%s</b> (%s)", summary_safe, id->name);
+		text = g_strdup_printf ("<b>%s</b> (%s)", summary_safe, split[0]);
 		g_free (summary_safe);
 	}
-	return text;
-}
-
-/**
- * gpk_package_id_name_version:
- **/
-gchar *
-gpk_package_id_name_version (const gchar *id)
-{
-	gchar *text;
-	GString *string;
-
-	if (id == NULL)
-		return g_strdup("");
-
-	string = g_string_new (id->name);
-	if (id->version != NULL)
-		g_string_append_printf (string, "-%s", id->version);
-	text = g_string_free (string, FALSE);
-
+	g_strfreev (split);
 	return text;
 }
 
@@ -592,6 +571,50 @@ gpk_strv_join_locale (gchar **array)
 }
 
 /**
+ * gpk_package_entry_completion_get_names_from_file:
+ *
+ * Creates a tree model containing completions from the system package list
+ **/
+static GPtrArray *
+gpk_package_entry_completion_get_names_from_file (const gchar *filename)
+{
+	GPtrArray *array = NULL;
+	gboolean ret;
+	GError *error = NULL;
+	gchar *data = NULL;
+	gchar **lines = NULL;
+	guint i;
+	gchar **split;
+	PkItemPackage *item;
+
+	/* get data */
+	ret = g_file_get_contents (filename, &data, NULL, &error);
+	if (!ret) {
+		egg_warning ("failed to open package list: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* create array of PkItemPackage's */
+	array = g_ptr_array_new_with_free_func ((GDestroyNotify) pk_item_package_unref);
+
+	/* split */
+	lines = g_strsplit (data, "\n", -1);
+	for (i=0; lines[i] != NULL; i++) {
+		split = g_strsplit (lines[i], "\t", 3);
+		if (g_strv_length (split) != 3)
+			continue;
+		item = pk_item_package_new (pk_info_enum_from_text (split[0]), split[1], split[2]);
+		g_ptr_array_add (array, item);
+		g_strfreev (split);
+	}
+out:
+	g_free (data);
+	g_strfreev (lines);
+	return array;
+}
+
+/**
  * gpk_package_entry_completion_model_new:
  *
  * Creates a tree model containing completions from the system package list
@@ -601,39 +624,41 @@ gpk_package_entry_completion_model_new (void)
 {
 	GPtrArray *list;
 	guint i;
-	gboolean ret;
-	const PkItemPackage *obj;
+	const PkItemPackage *item;
 	GHashTable *hash;
 	gpointer data;
 	GtkListStore *store;
 	GtkTreeIter iter;
+	gchar **split;
 
 	store = gtk_list_store_new (1, G_TYPE_STRING);
 	hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-	list = g_ptr_array_new_with_free_func_xxx ();
-	ret = pk_obj_list_from_file (PK_OBJ_LIST(list), PK_SYSTEM_PACKAGE_LIST_FILENAME);
-	if (!ret) {
+	list = gpk_package_entry_completion_get_names_from_file (PK_SYSTEM_PACKAGE_LIST_FILENAME);
+	if (list == NULL) {
 		egg_warning ("no package list, try refreshing");
 		return NULL;
 	}
 
 	egg_debug ("loading %i autocomplete items", list->len);
 	for (i=0; i<list->len; i++) {
-		obj = g_ptr_array_index (list, i);
-		if (obj == NULL || obj->package_id == NULL || obj->package_id->namexxxneedtosplitxxx == NULL) {
-			egg_warning ("obj invalid!");
+		item = g_ptr_array_index (list, i);
+		if (item == NULL || item->package_id == NULL) {
+			egg_warning ("item invalid!");
 			break;
 		}
-		data = g_hash_table_lookup (hash, (gpointer) obj->package_id->namexxxneedtosplitxxx);
+
+		split = pk_package_id_split (item->package_id);
+		data = g_hash_table_lookup (hash, (gpointer) split[0]);
 		if (data == NULL) {
 			/* append just the name */
-			g_hash_table_insert (hash, g_strdup (obj->package_id->namexxxneedtosplitxxx), GINT_TO_POINTER (1));
+			g_hash_table_insert (hash, g_strdup (split[0]), GINT_TO_POINTER (1));
 			gtk_list_store_append (store, &iter);
-			gtk_list_store_set (store, &iter, 0, obj->package_id->namexxxneedtosplitxxx, -1);
+			gtk_list_store_set (store, &iter, 0, split[0], -1);
 		}
+		g_strfreev (split);
 	}
 	g_hash_table_unref (hash);
-	g_object_unref (list);
+	g_ptr_array_unref (list);
 
 	return GTK_TREE_MODEL (store);
 }
diff --git a/src/gpk-common.h b/src/gpk-common.h
index af98791..4a867e2 100644
--- a/src/gpk-common.h
+++ b/src/gpk-common.h
@@ -93,12 +93,10 @@ void		 gpk_common_test			(gpointer	 data);
 void		 gtk_text_buffer_insert_markup		(GtkTextBuffer	*buffer,
 							 GtkTextIter	*iter,
 							 const gchar	*markup);
-gchar		*gpk_package_id_format_twoline		(const gchar *id,
+gchar		*gpk_package_id_format_twoline		(const gchar 	*package_id,
 							 const gchar	*summary);
-gchar		*gpk_package_id_format_oneline		(const gchar *id,
+gchar		*gpk_package_id_format_oneline		(const gchar 	*package_id,
 							 const gchar	*summary);
-gchar		*gpk_package_id_name_version		(const gchar *id);
-
 gchar		*gpk_time_to_localised_string		(guint		 time_secs);
 gchar		*gpk_time_to_imprecise_string		(guint		 time_secs);
 gboolean	 gpk_check_privileged_user		(const gchar	*application_name,
@@ -112,7 +110,6 @@ gboolean	 gpk_window_set_size_request		(GtkWindow	*window,
 							 guint		 width,
 							 guint		 height);
 gboolean	 gpk_ignore_session_error		(GError		*error);
-gboolean	 gpk_window_get_small_form_factor_mode 	(void);
 gboolean	 gpk_window_set_parent_xid		(GtkWindow	*window,
 							 guint32	 xid);
 #if (!PK_CHECK_VERSION(0,5,0))
diff --git a/src/gpk-log.c b/src/gpk-log.c
index e155187..4bc2df8 100644
--- a/src/gpk-log.c
+++ b/src/gpk-log.c
@@ -25,9 +25,9 @@
 #include <glib/gi18n.h>
 
 #include <gtk/gtk.h>
-#include <math.h>
-#include <string.h>
-#include <dbus/dbus-glib.h>
+//#include <math.h>
+//#include <string.h>
+//#include <dbus/dbus-glib.h>
 #include <locale.h>
 #include <sys/types.h>
 #include <pwd.h>
@@ -37,18 +37,18 @@
 #include <unique/unique.h>
 
 #include "egg-debug.h"
-#include "egg-string.h"
+//#include "egg-string.h"
 
 #include "gpk-common.h"
 #include "gpk-gnome.h"
-#include "gpk-enum.h"
+//#include "gpk-enum.h"
 
 static GtkBuilder *builder = NULL;
 static GtkListStore *list_store = NULL;
 static PkClient *client = NULL;
 static gchar *transaction_id = NULL;
 static gchar *filter = NULL;
-static PkObjList *transactions = NULL;
+static GPtrArray *transactions = NULL;
 static GtkTreePath *path_global = NULL;
 
 enum
@@ -384,7 +384,7 @@ gpk_log_message_received_cb (UniqueApp *app, UniqueCommand command, UniqueMessag
  * gpk_log_filter:
  **/
 static gboolean
-gpk_log_filter (const PkTransactionObj *obj)
+gpk_log_filter (const PkItemTransaction *item)
 {
 	gboolean ret = FALSE;
 	guint i;
@@ -394,8 +394,8 @@ gpk_log_filter (const PkTransactionObj *obj)
 	gchar **split;
 
 	/* only show transactions that succeeded */
-	if (!obj->succeeded) {
-		egg_debug ("tid %s did not succeed, so not adding", obj->tid);
+	if (!item->succeeded) {
+		egg_debug ("tid %s did not succeed, so not adding", item->tid);
 		return FALSE;
 	}
 
@@ -403,11 +403,11 @@ gpk_log_filter (const PkTransactionObj *obj)
 		return TRUE;
 
 	/* matches cmdline */
-	if (obj->cmdline != NULL && g_strrstr (obj->cmdline, filter) != NULL)
+	if (item->cmdline != NULL && g_strrstr (item->cmdline, filter) != NULL)
 		ret = TRUE;
 
 	/* look in all the data for the filter string */
-	packages = g_strsplit (obj->data, "\n", 0);
+	packages = g_strsplit (item->data, "\n", 0);
 	length = g_strv_length (packages);
 	for (i=0; i<length; i++) {
 		sections = g_strsplit (packages[i], "\t", 0);
@@ -439,10 +439,10 @@ gpk_log_filter (const PkTransactionObj *obj)
 }
 
 /**
- * gpk_log_add_obj
+ * gpk_log_add_item
  **/
 static void
-gpk_log_add_obj (const PkTransactionObj *obj)
+gpk_log_add_item (const PkItemTransaction *item)
 {
 	GtkTreeIter iter;
 	gchar *details;
@@ -458,15 +458,15 @@ gpk_log_add_obj (const PkTransactionObj *obj)
 	GtkTreeModel *model = gtk_tree_view_get_model (treeview);
 
 	/* put formatted text into treeview */
-	details = gpk_log_get_details_localised (obj->timespec, obj->data);
-	date = gpk_log_get_localised_date (obj->timespec);
+	details = gpk_log_get_details_localised (item->timespec, item->data);
+	date = gpk_log_get_localised_date (item->timespec);
 	date_part = g_strsplit (date, ", ", 2);
 
-	icon_name = gpk_role_enum_to_icon_name (obj->role);
-	role_text = gpk_role_enum_to_localised_past (obj->role);
+	icon_name = gpk_role_enum_to_icon_name (item->role);
+	role_text = gpk_role_enum_to_localised_past (item->role);
 
 	/* query real name */
-	pw = getpwuid(obj->uid);
+	pw = getpwuid(item->uid);
 	if (pw != NULL) {
 		if (pw->pw_gecos != NULL)
 			username = pw->pw_gecos;
@@ -475,29 +475,29 @@ gpk_log_add_obj (const PkTransactionObj *obj)
 	}
 
 	/* get nice name for tool name */
-	if (g_strcmp0 (obj->cmdline, "pkcon") == 0)
+	if (g_strcmp0 (item->cmdline, "pkcon") == 0)
 		/* TRANSLATORS: short name for pkcon */
 		tool = _("Command line client");
-	else if (g_strcmp0 (obj->cmdline, "gpk-application") == 0)
+	else if (g_strcmp0 (item->cmdline, "gpk-application") == 0)
 		/* TRANSLATORS: short name for gpk-update-viewer */
 		tool = _("Add/Remove Software");
-	else if (g_strcmp0 (obj->cmdline, "gpk-update-viewer") == 0)
+	else if (g_strcmp0 (item->cmdline, "gpk-update-viewer") == 0)
 		/* TRANSLATORS: short name for gpk-update-viewer */
 		tool = _("Update System");
-	else if (g_strcmp0 (obj->cmdline, "gpk-update-icon") == 0)
+	else if (g_strcmp0 (item->cmdline, "gpk-update-icon") == 0)
 		/* TRANSLATORS: short name for gpk-update-icon */
 		tool = _("Update Icon");
 	else
-		tool = obj->cmdline;
+		tool = item->cmdline;
 
-	gpk_log_model_get_iter (model, &iter, obj->tid);
+	gpk_log_model_get_iter (model, &iter, item->tid);
 	gtk_list_store_set (list_store, &iter,
 			    GPK_LOG_COLUMN_ICON, icon_name,
-			    GPK_LOG_COLUMN_TIMESPEC, obj->timespec,
+			    GPK_LOG_COLUMN_TIMESPEC, item->timespec,
 			    GPK_LOG_COLUMN_DATE, date_part[1],
 			    GPK_LOG_COLUMN_ROLE, role_text,
 			    GPK_LOG_COLUMN_DETAILS, details,
-			    GPK_LOG_COLUMN_ID, obj->tid,
+			    GPK_LOG_COLUMN_ID, item->tid,
 			    GPK_LOG_COLUMN_USER, username,
 			    GPK_LOG_COLUMN_TOOL, tool,
 			    GPK_LOG_COLUMN_ACTIVE, TRUE, -1);
@@ -520,7 +520,7 @@ gpk_log_refilter (void)
 {
 	guint i;
 	gboolean ret;
-	const PkTransactionObj *obj;
+	const PkItemTransaction *item;
 	GtkWidget *widget;
 	const gchar *package;
 	GtkTreeView *treeview;
@@ -530,7 +530,7 @@ gpk_log_refilter (void)
 	g_free (filter);
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_package"));
 	package = gtk_entry_get_text (GTK_ENTRY(widget));
-	if (!egg_strzero (package))
+	if (package != NULL && package[0] != '\0')
 		filter = g_strdup (package);
 	else
 		filter = NULL;
@@ -544,10 +544,10 @@ gpk_log_refilter (void)
 
 	/* go through the list, adding and removing the items as required */
 	for (i=0; i<transactions->len; i++) {
-		obj = g_ptr_array_index (transactions, i);
-		ret = gpk_log_filter (obj);
+		item = g_ptr_array_index (transactions, i);
+		ret = gpk_log_filter (item);
 		if (ret)
-			gpk_log_add_obj (obj);
+			gpk_log_add_item (item);
 	}
 
 	/* remove the items that are not used */
@@ -555,32 +555,49 @@ gpk_log_refilter (void)
 }
 
 /**
- * gpk_log_refresh
+ * gpk_log_get_old_transactions_cb
  **/
-static gboolean
-gpk_log_refresh (void)
+static void
+gpk_log_get_old_transactions_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 {
-	gboolean ret;
+//	PkClient *client = PK_CLIENT (object);
 	GError *error = NULL;
+	PkResults *results = NULL;
+	PkExitEnum exit_enum;
 
-	ret = pk_client_get_old_transactions (client, 0, &error);
-	if (!ret) {
-		egg_warning ("failed to get list: %s", error->message);
+	/* get the results */
+	results = pk_client_generic_finish (client, res, &error);
+	if (results == NULL) {
+		egg_warning ("failed to get old transactions: %s", error->message);
 		g_error_free (error);
 		goto out;
 	}
 
+	/* get results */
+	exit_enum = pk_results_get_exit_code (results);
+	if (exit_enum != PK_EXIT_ENUM_SUCCESS)
+		egg_warning ("failed to get old transactions: %s", pk_exit_enum_to_text (exit_enum));
+
 	/* get the list */
 	if (transactions != NULL)
-		g_object_unref (transactions);
-#if PK_CHECK_VERSION(0,5,0)
-	transactions = pk_client_get_transaction_list (client);
-#else
-	transactions = pk_client_get_cached_objects (client); /* removed in 0.5.x */
-#endif
+		g_ptr_array_unref (transactions);
+	transactions = pk_results_get_transaction_array (results);
 	gpk_log_refilter ();
 out:
-	return ret;
+	if (results != NULL)
+		g_object_unref (results);
+}
+
+
+/**
+ * gpk_log_refresh
+ **/
+static void
+gpk_log_refresh (void)
+{
+	/* get the list async */
+	pk_client_get_old_transactions_async (client, 0, NULL, NULL, NULL,
+					      (GAsyncReadyCallback) gpk_log_get_old_transactions_cb, NULL);
 }
 
 /**
@@ -650,7 +667,6 @@ main (int argc, char *argv[])
 
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
-	dbus_g_thread_init ();
 	g_type_init ();
 
 	context = g_option_context_new (NULL);
@@ -757,9 +773,6 @@ main (int argc, char *argv[])
 	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store),
 					      GPK_LOG_COLUMN_TIMESPEC, GTK_SORT_DESCENDING);
 
-	/* get the update list */
-	gpk_log_refresh ();
-
 	/* show */
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_simple"));
 	gtk_widget_show (widget);
@@ -770,6 +783,9 @@ main (int argc, char *argv[])
 		gpk_window_set_parent_xid (GTK_WINDOW (widget), xid);
 	}
 
+	/* get the update list */
+	gpk_log_refresh ();
+
 	gtk_main ();
 
 out_build:
@@ -779,7 +795,7 @@ out_build:
 	g_free (transaction_id);
 	g_free (filter);
 	if (transactions != NULL)
-		g_object_unref (transactions);
+		g_ptr_array_unref (transactions);
 unique_out:
 	g_object_unref (unique_app);
 	return 0;
diff --git a/src/gpk-watch.c b/src/gpk-watch.c
index 1b23fdc..4e5cf13 100644
--- a/src/gpk-watch.c
+++ b/src/gpk-watch.c
@@ -441,7 +441,7 @@ gpk_watch_task_list_finished_cb (PkTaskList *tlist, PkClient *client, PkExitEnum
 	guint j;
 	const PkRequireRestartObj *obj;
 	const PkRequireRestartObj *obj_tmp;
-	PkObjList *array;
+	GPtrArray *array;
 #else
 	gchar *id;
 	const GPtrArray *array;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]