r7036 - dumbhippo/trunk/client/common/ddm
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7036 - dumbhippo/trunk/client/common/ddm
- Date: Wed, 12 Dec 2007 09:49:24 -0600 (CST)
Author: otaylor
Date: 2007-12-12 09:49:24 -0600 (Wed, 12 Dec 2007)
New Revision: 7036
Modified:
dumbhippo/trunk/client/common/ddm/ddm-feed.c
dumbhippo/trunk/client/common/ddm/ddm-feed.h
dumbhippo/trunk/client/common/ddm/test-feed-object.c
Log:
Add a boolean 'changed' return value to ddm_feed_add_item()/remove_item()
Modified: dumbhippo/trunk/client/common/ddm/ddm-feed.c
===================================================================
--- dumbhippo/trunk/client/common/ddm/ddm-feed.c 2007-12-12 00:55:44 UTC (rev 7035)
+++ dumbhippo/trunk/client/common/ddm/ddm-feed.c 2007-12-12 15:49:24 UTC (rev 7036)
@@ -131,7 +131,7 @@
}
}
-void
+gboolean
ddm_feed_add_item (DDMFeed *feed,
DDMDataResource *resource,
gint64 timestamp)
@@ -139,14 +139,14 @@
GList *node;
DDMFeedItem *item;
- g_return_if_fail(DDM_IS_FEED(feed));
+ g_return_val_if_fail(DDM_IS_FEED(feed), FALSE);
node = g_hash_table_lookup(feed->nodes_by_resource, resource);
if (node != NULL) {
item = node->data;
if (item->timestamp == timestamp)
- return;
+ return FALSE;
item->timestamp = timestamp;
@@ -166,22 +166,22 @@
feed_insert_sorted(feed, node, timestamp);
g_signal_emit(feed, signals[ITEM_ADDED], 0, resource, timestamp);
}
+
+ return TRUE;
}
-void
+gboolean
ddm_feed_remove_item (DDMFeed *feed,
DDMDataResource *resource)
{
GList *node;
DDMFeedItem *item;
- g_return_if_fail(DDM_IS_FEED(feed));
+ g_return_val_if_fail(DDM_IS_FEED(feed), FALSE);
node = g_hash_table_lookup(feed->nodes_by_resource, resource);
if (node == NULL) {
- g_warning("ddm_feed_remove_item(): resource %s not in feed",
- ddm_data_resource_get_resource_id(resource));
- return;
+ return FALSE;
}
item = node->data;
@@ -192,6 +192,8 @@
g_signal_emit(feed, signals[ITEM_REMOVED], 0, item->resource);
ddm_data_resource_unref(item->resource);
g_slice_free(DDMFeedItem, item);
+
+ return TRUE;
}
static void
@@ -227,6 +229,14 @@
ddm_feed_clear_internal(feed, TRUE);
}
+gboolean
+ddm_feed_is_empty (DDMFeed *feed)
+{
+ g_return_val_if_fail(DDM_IS_FEED(feed), TRUE);
+
+ return feed->items == NULL;
+}
+
void
ddm_feed_iter_init (DDMFeedIter *iter,
DDMFeed *feed)
Modified: dumbhippo/trunk/client/common/ddm/ddm-feed.h
===================================================================
--- dumbhippo/trunk/client/common/ddm/ddm-feed.h 2007-12-12 00:55:44 UTC (rev 7035)
+++ dumbhippo/trunk/client/common/ddm/ddm-feed.h 2007-12-12 15:49:24 UTC (rev 7036)
@@ -48,13 +48,16 @@
DDMFeed *ddm_feed_new (void);
/* If an item for this resource is already in the feed, will update the
- * item's timestamp and reorder it as necessary */
-void ddm_feed_add_item (DDMFeed *feed,
- DDMDataResource *resource,
- gint64 timestamp);
-void ddm_feed_remove_item (DDMFeed *feed,
- DDMDataResource *resource);
-void ddm_feed_clear (DDMFeed *feed);
+ * item's timestamp and reorder it as necessary; return value is whether
+ * anything changed at all */
+gboolean ddm_feed_add_item (DDMFeed *feed,
+ DDMDataResource *resource,
+ gint64 timestamp);
+/* return value is whether the item was found and removed */
+gboolean ddm_feed_remove_item (DDMFeed *feed,
+ DDMDataResource *resource);
+void ddm_feed_clear (DDMFeed *feed);
+gboolean ddm_feed_is_empty (DDMFeed *feed);
void ddm_feed_iter_init (DDMFeedIter *iter,
DDMFeed *feed);
Modified: dumbhippo/trunk/client/common/ddm/test-feed-object.c
===================================================================
--- dumbhippo/trunk/client/common/ddm/test-feed-object.c 2007-12-12 00:55:44 UTC (rev 7035)
+++ dumbhippo/trunk/client/common/ddm/test-feed-object.c 2007-12-12 15:49:24 UTC (rev 7036)
@@ -100,19 +100,22 @@
/* Add two items to it */
- ddm_feed_add_item(feed, user1, TS1);
+ g_assert(ddm_feed_add_item(feed, user1, TS1));
g_assert(last_op == ITEM_ADDED);
g_assert(last_resource == user1);
g_assert(last_timestamp == TS1);
- ddm_feed_add_item(feed, user2, TS2);
+ g_assert(ddm_feed_add_item(feed, user2, TS2));
g_assert(last_op == ITEM_ADDED);
g_assert(last_resource == user2);
g_assert(last_timestamp == TS2);
+ /* Adding an item again with the same timestamp should return FALSE */
+ g_assert(!ddm_feed_add_item(feed, user2, TS2));
+
/* Restack the older one to the top */
- ddm_feed_add_item(feed, user1, TS3);
+ g_assert(ddm_feed_add_item(feed, user1, TS3));
g_assert(last_op == ITEM_CHANGED);
g_assert(last_resource == user1);
g_assert(last_timestamp == TS3);
@@ -133,7 +136,7 @@
/* Remove an item */
- ddm_feed_remove_item(feed, user2);
+ g_assert(ddm_feed_remove_item(feed, user2));
g_assert(last_op == ITEM_REMOVED);
g_assert(last_resource == user2);
@@ -145,6 +148,9 @@
g_assert(!ddm_feed_iter_next(&iter, &resource, ×tamp));
+ /* Removing the same item again should return FALSE */
+ g_assert(!ddm_feed_remove_item(feed, user2));
+
/* Remove all items */
ddm_feed_clear(feed);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]