}
static void
-feed_panel_add_item_cb (KatzeArray* feed,
+feed_panel_add_item_cb (KatzeArray* parent,
KatzeItem* child,
FeedPanel* panel)
{
KatzeItem* item;
gint i;
- g_return_if_fail (KATZE_IS_ARRAY (feed));
+ g_return_if_fail (KATZE_IS_ARRAY (parent));
g_return_if_fail (KATZE_IS_ITEM (child));
model = gtk_tree_view_get_model (GTK_TREE_VIEW (panel->treeview));
- if (KATZE_IS_ARRAY (child))
- {
- gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), &child_iter,
- NULL, G_MAXINT, 0, child, -1);
- }
- else
+ if (katze_item_get_parent (KATZE_ITEM (parent)))
{
-
- i = 0;
- while (gtk_tree_model_iter_nth_child (model, &iter, NULL, i++))
+ if (KATZE_IS_ARRAY (child))
{
- gtk_tree_model_get (model, &iter, 0, &item, -1);
- if (item == KATZE_ITEM (feed))
+ gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), &child_iter,
+ NULL, G_MAXINT, 0, child, -1);
+ }
+ else
+ {
+
+ i = 0;
+ while (gtk_tree_model_iter_nth_child (model, &iter, NULL, i++))
{
- gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), &child_iter,
- &iter, 0, 0, child, -1);
+ gtk_tree_model_get (model, &iter, 0, &item, -1);
+ if (item == KATZE_ITEM (parent))
+ {
+ gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), &child_iter,
+ &iter, 0, 0, child, -1);
- g_object_unref (child);
+ g_object_unref (child);
+ g_object_unref (item);
+ break;
+ }
g_object_unref (item);
- break;
}
- g_object_unref (item);
}
}
feed_panel_insert_item (panel, GTK_TREE_STORE (model), &child_iter, child);
}
static void
-feed_panel_remove_item_cb (KatzeArray* feed,
+feed_panel_remove_item_cb (KatzeArray* item,
KatzeItem* child,
FeedPanel* panel)
{
GtkTreeModel* model;
+ KatzeItem* pitem;
- g_assert (KATZE_IS_ARRAY (feed));
+ g_assert (KATZE_IS_ARRAY (item));
g_assert (KATZE_IS_ITEM (child));
if (KATZE_IS_ARRAY (child))
feed_panel_disconnect_feed (panel, KATZE_ARRAY (child));
+ if (!katze_item_get_parent (KATZE_ITEM (item)))
+ {
+ gint n;
+
+ n = katze_array_get_length (KATZE_ARRAY (child));
+ g_assert (n == 1);
+ pitem = katze_array_get_nth_item (KATZE_ARRAY (child), 0);
+ }
+ else
+ pitem = child;
+
model = gtk_tree_view_get_model (GTK_TREE_VIEW (panel->treeview));
- feed_panel_remove_iter (model, child);
- g_object_unref (child);
+ feed_panel_remove_iter (model, pitem);
+ g_object_unref (pitem);
}
static void
if (date)
{
SoupDate* sdate;
- const gchar* suri;
+ const gchar* puri;
+ KatzeItem* parent;
sdate = soup_date_new_from_time_t ((time_t) date);
- suri = (const gchar*)g_object_get_data (G_OBJECT (item), "feeduri");
+
+ parent = katze_item_get_parent (item);
+ g_assert (KATZE_IS_ARRAY (parent));
+ puri = katze_item_get_uri (parent);
text = g_strdup_printf (
"<html><head><title>feed</title></head>"
"<body><h3>%s</h3><p />Last updated %s.</body></html>",
- suri, soup_date_to_string (sdate, SOUP_DATE_HTTP));
+ puri, soup_date_to_string (sdate, SOUP_DATE_HTTP));
soup_date_free (sdate);
}
}
enum
{
- FEED_NEW,
FEED_READ,
FEED_REMOVE
};
if (uri)
{
- feed = katze_array_new (KATZE_TYPE_ITEM);
- g_object_set_data_full (G_OBJECT (feed), "feeduri",
- (gpointer) g_strdup ((uri)), g_free);
- katze_array_add_item (feeds, feed);
+ if (katze_array_find_token (feeds, uri))
+ {
+ GtkWidget* dialog;
+
+ dialog = gtk_message_dialog_new (
+ NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ _("Error"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("Feed %s already exists"), uri);
+ gtk_window_set_title (GTK_WINDOW (dialog), EXTENSION_NAME);
+ gtk_widget_show (dialog);
+ g_signal_connect_swapped (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), dialog);
+
+ }
+ else
+ {
+ KatzeArray* child;
+
+ feed = katze_array_new (KATZE_TYPE_ARRAY);
+ child = katze_array_new (KATZE_TYPE_ITEM);
+ katze_item_set_uri (KATZE_ITEM (feed), uri);
+ katze_item_set_token (KATZE_ITEM (feed), uri);
+ katze_item_set_uri (KATZE_ITEM (child), uri);
+ katze_array_add_item (feeds, feed);
+ katze_array_add_item (feed, child);
+ }
}
return feed;
}
for (i = 0; i < n; i++)
{
item = katze_array_get_nth_item (feed, i);
- sfeeds[i] = (gchar*) g_object_get_data (G_OBJECT (item), "feeduri");
+ sfeeds[i] = (gchar*) katze_item_get_uri (KATZE_ITEM (item));
}
sfeeds[n] = NULL;
feed_handle_net_error (FeedNetPrivate* netpriv,
const gchar* msg)
{
+ KatzeItem* child;
const gchar* uri;
+ gint n;
+
+ n = katze_array_get_length (netpriv->feed);
+ g_assert (n == 1);
+ child = katze_array_get_nth_item (netpriv->feed, 0);
+ g_assert (KATZE_IS_ARRAY (child));
- uri = (gchar*) g_object_get_data (G_OBJECT (netpriv->feed), "feeduri");
- katze_item_set_name (KATZE_ITEM (netpriv->feed), uri);
- katze_item_set_text (KATZE_ITEM (netpriv->feed), msg);
- katze_item_set_uri (KATZE_ITEM (netpriv->feed), NULL);
+ uri = katze_item_get_uri (KATZE_ITEM (netpriv->feed));
+ katze_item_set_name (child, uri);
+ katze_item_set_text (child, msg);
+ katze_item_set_uri (child, NULL);
feed_remove_flags (netpriv->feed, FEED_READ);
}
if (request->data)
{
+ KatzeArray* item;
+ const gchar* uri;
+ gint n;
+
+ n = katze_array_get_length (netpriv->feed);
+ g_assert (n == 1);
+ item = katze_array_get_nth_item (netpriv->feed, 0);
+ g_assert (KATZE_IS_ARRAY (item));
+ uri = katze_item_get_uri (KATZE_ITEM (netpriv->feed));
+ katze_item_set_uri (KATZE_ITEM (item), uri);
+
if (!parse_feed (request->data, request->length,
- netpriv->parsers, netpriv->feed, &error))
+ netpriv->parsers, item, &error))
{
feed_handle_net_error (netpriv, error->message);
g_error_free (error);
if (!(feed_has_flags (feed, FEED_READ)))
{
FeedNetPrivate* netpriv;
- gchar* uri;
- uri = (gchar*) g_object_get_data (G_OBJECT (feed), "feeduri");
feed_add_flags (feed, FEED_READ);
- katze_item_set_uri (KATZE_ITEM (feed), uri);
netpriv = g_new0 (FeedNetPrivate, 1);
netpriv->parsers = priv->parsers;
netpriv->extension = priv->extension;
KatzeArray* feed;
feed = feed_add_item (priv->feeds, uri);
- feed_save_items (priv->extension, priv->feeds);
- feed_add_flags (feed, FEED_NEW);
- update_feed (priv, KATZE_ITEM (feed));
+ if (feed)
+ {
+ feed_save_items (priv->extension, priv->feeds);
+ update_feed (priv, KATZE_ITEM (feed));
+ }
}
}
KatzeArray* feed;
feed = feed_add_item (priv->feeds, uri);
- feed_save_items (priv->extension, priv->feeds);
- feed_add_flags (feed, FEED_NEW);
- update_feed (priv, KATZE_ITEM (feed));
+ if (feed)
+ {
+ feed_save_items (priv->extension, priv->feeds);
+ update_feed (priv, KATZE_ITEM (feed));
+ }
}
}
gtk_widget_destroy (dialog);
static void
panel_remove_feed_cb (FeedPanel* panel,
- KatzeArray* feed,
+ KatzeItem* item,
FeedPrivate* priv)
{
+ KatzeArray* feed;
+
+ feed = katze_item_get_parent (item);
+
g_assert (KATZE_IS_ARRAY (priv->feeds));
+ g_assert (KATZE_IS_ARRAY (feed));
if (feed_has_flags (feed, FEED_READ))
feed_add_flags (feed, FEED_REMOVE);
if (sfeeds[i])
{
feed = feed_add_item (feeds, sfeeds[i]);
- update_feed (priv, KATZE_ITEM (feed));
+ if (feed)
+ update_feed (priv, KATZE_ITEM (feed));
}
}
g_strdupv (sfeeds);