From abd499aaeb280ef2ab24f4e392484ecd4d8bb7a2 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 14 Jan 2010 20:27:28 -0600 Subject: Only add the Application if it doesn't already exist in the appstore. --- src/application-service-appstore.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index fa1b9d2..c896beb 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -333,8 +333,6 @@ apply_status (Application * app, ApplicationStatus status) g_signal_emit(G_OBJECT(appstore), signals[APPLICATION_REMOVED], 0, position, TRUE); - - priv->applications = g_list_remove(priv->applications, app); } else { /* Figure out which icon we should be using */ gchar * newicon = app->icon; @@ -511,6 +509,16 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst g_return_if_fail(dbus_object != NULL && dbus_object[0] != '\0'); ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); + GList *l = NULL; + for (l = priv->applications; l != NULL; l = g_list_next (l)) { + Application *tmp_app = (Application *)l->data; + + if (g_strcmp0 (tmp_app->dbus_name, dbus_name) == 0 && + g_strcmp0 (tmp_app->dbus_object, dbus_object) == 0) { + return; + } + } + /* Build the application entry. This will be carried along until we're sure we've got everything. */ Application * app = g_new0(Application, 1); -- cgit v1.2.3 From 7a001c72db8fcbd518c132862ddc215bc215aac4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 23:22:46 -0600 Subject: Fleshing out returning the list of apps already there. --- src/application-service-appstore.c | 47 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index fa1b9d2..282eb51 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -31,7 +31,7 @@ with this program. If not, see . #include "dbus-shared.h" /* DBus Prototypes */ -static gboolean _application_service_server_get_applications (ApplicationServiceAppstore * appstore, GArray ** apps); +static gboolean _application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps); #include "application-service-server.h" @@ -624,8 +624,51 @@ application_service_appstore_application_remove (ApplicationServiceAppstore * ap /* DBus Interface */ static gboolean -_application_service_server_get_applications (ApplicationServiceAppstore * appstore, GArray ** apps) +_application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps) { + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); + + *apps = g_ptr_array_new(); + GList * listpntr; + gint position = 0; + + for (listpntr = priv->applications; listpntr != NULL; listpntr = g_list_next(listpntr)) { + GValueArray * values = g_value_array_new(0); + + GValue value = {0}; + + /* Icon name */ + g_value_init(&value, G_TYPE_STRING); + g_value_set_string(&value, ((Application *)listpntr->data)->icon); + g_value_array_append(values, &value); + g_value_unset(&value); + + /* Position */ + g_value_init(&value, G_TYPE_INT); + g_value_set_int(&value, position++); + g_value_array_append(values, &value); + g_value_unset(&value); + + /* DBus Address */ + g_value_init(&value, G_TYPE_STRING); + g_value_set_string(&value, ((Application *)listpntr->data)->dbus_name); + g_value_array_append(values, &value); + g_value_unset(&value); + + /* DBus Object */ + g_value_init(&value, G_TYPE_STRING); + g_value_set_string(&value, ((Application *)listpntr->data)->dbus_object); + g_value_array_append(values, &value); + g_value_unset(&value); + + /* Icon path */ + g_value_init(&value, G_TYPE_STRING); + g_value_set_string(&value, ((Application *)listpntr->data)->icon_path); + g_value_array_append(values, &value); + g_value_unset(&value); + + g_ptr_array_add(*apps, values); + } return FALSE; } -- cgit v1.2.3 From eddc0d0e435a16acacafe086475ef79cc3f599ae Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Jan 2010 23:30:11 -0600 Subject: Returning truth. --- src/application-service-appstore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 282eb51..d70e2f8 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -670,6 +670,6 @@ _application_service_server_get_applications (ApplicationServiceAppstore * appst g_ptr_array_add(*apps, values); } - return FALSE; + return TRUE; } -- cgit v1.2.3 From 00cad2ec8d5a143b3970dd63825cbd4b6265092a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Jan 2010 00:48:09 -0600 Subject: Better init value and adding error to prototype. --- src/application-service-appstore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index d70e2f8..95f8dde 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -31,7 +31,7 @@ with this program. If not, see . #include "dbus-shared.h" /* DBus Prototypes */ -static gboolean _application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps); +static gboolean _application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps, GError ** error); #include "application-service-server.h" @@ -624,7 +624,7 @@ application_service_appstore_application_remove (ApplicationServiceAppstore * ap /* DBus Interface */ static gboolean -_application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps) +_application_service_server_get_applications (ApplicationServiceAppstore * appstore, GPtrArray ** apps, GError ** error) { ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); @@ -633,7 +633,7 @@ _application_service_server_get_applications (ApplicationServiceAppstore * appst gint position = 0; for (listpntr = priv->applications; listpntr != NULL; listpntr = g_list_next(listpntr)) { - GValueArray * values = g_value_array_new(0); + GValueArray * values = g_value_array_new(5); GValue value = {0}; -- cgit v1.2.3 From 8045abdf6b0390572dbeb1a224431ec4c3e3355e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Jan 2010 01:01:11 -0600 Subject: Setting the proper type for the GValue of an 'o' --- src/application-service-appstore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 95f8dde..df4213a 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -656,8 +656,8 @@ _application_service_server_get_applications (ApplicationServiceAppstore * appst g_value_unset(&value); /* DBus Object */ - g_value_init(&value, G_TYPE_STRING); - g_value_set_string(&value, ((Application *)listpntr->data)->dbus_object); + g_value_init(&value, DBUS_TYPE_G_OBJECT_PATH); + g_value_set_static_boxed(&value, ((Application *)listpntr->data)->dbus_object); g_value_array_append(values, &value); g_value_unset(&value); -- cgit v1.2.3 From 93f32fd90d78997bf9661ddeaa8bfbb2f3020ced Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Jan 2010 10:05:21 -0600 Subject: Using the menu path instead of the item path. --- src/application-service-appstore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index df4213a..bc99855 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -657,7 +657,7 @@ _application_service_server_get_applications (ApplicationServiceAppstore * appst /* DBus Object */ g_value_init(&value, DBUS_TYPE_G_OBJECT_PATH); - g_value_set_static_boxed(&value, ((Application *)listpntr->data)->dbus_object); + g_value_set_static_boxed(&value, ((Application *)listpntr->data)->menu); g_value_array_append(values, &value); g_value_unset(&value); -- cgit v1.2.3 From e9fafdfa046eda4da67357ebfc02f48159403f8d Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 19 Jan 2010 11:28:33 -0600 Subject: Move the check for duplicates. --- src/application-service-appstore.c | 65 +++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 25 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index c896beb..d0b5570 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -311,6 +311,28 @@ application_removed_cb (DBusGProxy * proxy, gpointer userdata) return; } +static gboolean +can_add_application (GList *applications, Application *app) +{ + if (applications) + { + GList *l = NULL; + + for (l = applications; l != NULL; l = g_list_next (l)) + { + Application *tmp_app = (Application *)l->data; + + if (g_strcmp0 (tmp_app->dbus_name, app->dbus_name) == 0 && + g_strcmp0 (tmp_app->dbus_object, app->dbus_object) == 0) + { + return FALSE; + } + } + } + + return TRUE; +} + /* Change the status of the application. If we're going passive it removes it from the panel. If we're coming online, then it add it to the panel. Otherwise it changes the icon. */ @@ -333,6 +355,7 @@ apply_status (Application * app, ApplicationStatus status) g_signal_emit(G_OBJECT(appstore), signals[APPLICATION_REMOVED], 0, position, TRUE); + priv->applications = g_list_remove(priv->applications, app); } else { /* Figure out which icon we should be using */ gchar * newicon = app->icon; @@ -342,21 +365,23 @@ apply_status (Application * app, ApplicationStatus status) /* Determine whether we're already shown or not */ if (app->status == APP_STATUS_PASSIVE) { - /* Put on panel */ - priv->applications = g_list_prepend(priv->applications, app); - - /* TODO: We need to have the position determined better. This - would involve looking at the name and category and sorting - it with the other entries. */ - - g_signal_emit(G_OBJECT(app->appstore), - signals[APPLICATION_ADDED], 0, - newicon, - 0, /* Position */ - app->dbus_name, - app->menu, - app->icon_path, - TRUE); + if (can_add_application (priv->applications, app)) { + /* Put on panel */ + priv->applications = g_list_prepend (priv->applications, app); + + /* TODO: We need to have the position determined better. This + would involve looking at the name and category and sorting + it with the other entries. */ + + g_signal_emit(G_OBJECT(app->appstore), + signals[APPLICATION_ADDED], 0, + newicon, + 0, /* Position */ + app->dbus_name, + app->menu, + app->icon_path, + TRUE); + } } else { /* Icon update */ gint position = get_position(app); @@ -509,16 +534,6 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst g_return_if_fail(dbus_object != NULL && dbus_object[0] != '\0'); ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); - GList *l = NULL; - for (l = priv->applications; l != NULL; l = g_list_next (l)) { - Application *tmp_app = (Application *)l->data; - - if (g_strcmp0 (tmp_app->dbus_name, dbus_name) == 0 && - g_strcmp0 (tmp_app->dbus_object, dbus_object) == 0) { - return; - } - } - /* Build the application entry. This will be carried along until we're sure we've got everything. */ Application * app = g_new0(Application, 1); -- cgit v1.2.3 From 08fef8dc585407e88d27da07a7c6fd726303a0dd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 Jan 2010 17:20:21 -0600 Subject: Adding a _new function for the appstore and using it. It now takes the lru file. --- src/application-service-appstore.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index d0b5570..2121a0d 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -52,6 +52,7 @@ typedef struct _ApplicationServiceAppstorePrivate ApplicationServiceAppstorePriv struct _ApplicationServiceAppstorePrivate { DBusGConnection * bus; GList * applications; + AppLruFile * lrufile; }; #define APP_STATUS_PASSIVE_STR "passive" @@ -148,6 +149,7 @@ application_service_appstore_init (ApplicationServiceAppstore *self) ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(self); priv->applications = NULL; + priv->lrufile = NULL; GError * error = NULL; priv->bus = dbus_g_bus_get(DBUS_BUS_STARTER, &error); @@ -645,6 +647,17 @@ application_service_appstore_application_remove (ApplicationServiceAppstore * ap return; } +/* Creates a basic appstore object and attaches the + LRU file object to it. */ +ApplicationServiceAppstore * +application_service_appstore_new (AppLruFile * lrufile) +{ + ApplicationServiceAppstore * appstore = APPLICATION_SERVICE_APPSTORE(g_object_new(APPLICATION_SERVICE_APPSTORE_TYPE, NULL)); + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); + priv->lrufile = lrufile; + return appstore; +} + /* DBus Interface */ static gboolean _application_service_server_get_applications (ApplicationServiceAppstore * appstore, GArray ** apps) -- cgit v1.2.3 From e8d460427dd2147f2d8e7f4d648f4a49a3afaed3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 Jan 2010 17:21:22 -0600 Subject: Protecting our _new a little bit. --- src/application-service-appstore.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 2121a0d..e734bdd 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -652,6 +652,7 @@ application_service_appstore_application_remove (ApplicationServiceAppstore * ap ApplicationServiceAppstore * application_service_appstore_new (AppLruFile * lrufile) { + g_return_val_if_fail(IS_APP_LRU_FILE(lrufile), NULL); ApplicationServiceAppstore * appstore = APPLICATION_SERVICE_APPSTORE(g_object_new(APPLICATION_SERVICE_APPSTORE_TYPE, NULL)); ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(appstore); priv->lrufile = lrufile; -- cgit v1.2.3 From 570fc9486cb9f0a442ce0989c2bff1bc7942e67f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 Jan 2010 20:44:23 -0600 Subject: Adding in the 'id' and 'category' fields to the application structure. --- src/application-service-appstore.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index e734bdd..7d925d2 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -68,6 +68,8 @@ enum _ApplicationStatus { typedef struct _Application Application; struct _Application { + gchar * id; + gchar * category; gchar * dbus_name; gchar * dbus_object; ApplicationServiceAppstore * appstore; /* not ref'd */ @@ -203,6 +205,8 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err Application * app = (Application *)data; if (g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_MENU) == NULL || + g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ID) == NULL || + g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_CATEGORY) == NULL || g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_STATUS) == NULL || g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ICON_NAME) == NULL) { g_warning("Notification Item on object %s of %s doesn't have enough properties.", app->dbus_object, app->dbus_name); @@ -212,6 +216,11 @@ get_all_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * err app->validated = TRUE; + app->id = g_value_dup_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ID)); + app->category = g_value_dup_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_CATEGORY)); + ApplicationServiceAppstorePrivate * priv = APPLICATION_SERVICE_APPSTORE_GET_PRIVATE(app->appstore); + app_lru_file_touch(priv->lrufile, app->id, app->category); + app->icon = g_value_dup_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_ICON_NAME)); app->menu = g_value_dup_string(g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_MENU)); if (g_hash_table_lookup(properties, NOTIFICATION_ITEM_PROP_AICON_NAME) != NULL) { @@ -275,6 +284,12 @@ application_free (Application * app) g_object_unref(app->prop_proxy); } + if (app->id != NULL) { + g_free(app->id); + } + if (app->category != NULL) { + g_free(app->category); + } if (app->dbus_name != NULL) { g_free(app->dbus_name); } -- cgit v1.2.3 From a634890d9684f87b796670c89383066bb674863d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 Jan 2010 20:57:26 -0600 Subject: Switching to inserting in the application array using a sort function. Looking that up in the LRU file DB. --- src/application-service-appstore.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/application-service-appstore.c') diff --git a/src/application-service-appstore.c b/src/application-service-appstore.c index 7d925d2..4cb2ab6 100644 --- a/src/application-service-appstore.c +++ b/src/application-service-appstore.c @@ -350,6 +350,18 @@ can_add_application (GList *applications, Application *app) return TRUE; } +/* This function takes two Application structure + pointers and uses the lrufile to compare them. */ +static gint +app_sort_func (gconstpointer a, gconstpointer b, gpointer userdata) +{ + Application * appa = (Application *)a; + Application * appb = (Application *)b; + AppLruFile * lrufile = (AppLruFile *)userdata; + + return app_lru_file_sort(lrufile, appa->id, appb->id); +} + /* Change the status of the application. If we're going passive it removes it from the panel. If we're coming online, then it add it to the panel. Otherwise it changes the icon. */ @@ -384,16 +396,12 @@ apply_status (Application * app, ApplicationStatus status) if (app->status == APP_STATUS_PASSIVE) { if (can_add_application (priv->applications, app)) { /* Put on panel */ - priv->applications = g_list_prepend (priv->applications, app); - - /* TODO: We need to have the position determined better. This - would involve looking at the name and category and sorting - it with the other entries. */ + priv->applications = g_list_insert_sorted_with_data (priv->applications, app, app_sort_func, priv->lrufile); g_signal_emit(G_OBJECT(app->appstore), signals[APPLICATION_ADDED], 0, newicon, - 0, /* Position */ + g_list_index(priv->applications, app), /* Position */ app->dbus_name, app->menu, app->icon_path, -- cgit v1.2.3