2 * Claws-Mail-- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 Hiroyuki Yamamoto
4 * This file (C) 2005 Andrej Kacian <andrej@kacian.sk>
6 * - OPML import handling
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <glib/gi18n.h>
31 /* Claws Mail includes */
33 #include <alertpanel.h>
34 #include <common/utils.h>
37 #include "rssyl_feed.h"
38 #include "opml_import.h"
40 gint rssyl_folder_depth(FolderItem *item)
44 for( i = -1; item != NULL; item = folder_item_parent(item), i++ ) {}
48 /* This gets called from the libfeed's OPML parser as a user function for
49 * each <outline ...> from the .opml file.
50 * It creates a folder or subscribes a feed, while keeping track of the
51 * location inside folder hierarchy (using depth and linked list of parent
52 * folders up to the root). */
53 void rssyl_opml_import_func(gchar *title, gchar *url, gint depth, gpointer data)
55 OPMLImportCtx *ctx = (OPMLImportCtx *)data;
58 gboolean nulltitle = FALSE;
61 debug_print("depth %d, ctx->depth %d\n", depth, ctx->depth);
62 while (depth < ctx->depth) {
63 /* We've gone up at least one level, need to find correct parent */
64 ctx->current = g_slist_delete_link(ctx->current, ctx->current);
68 debug_print("OPML_IMPORT: %s %s (%s)\n",
69 (url != NULL ? "feed": "folder"), title, url);
72 debug_print("NULL title received, substituting a placeholder title\n");
73 title = g_strdup(_("Untitled"));
77 /* If URL is not given, then it's a folder */
79 /* Find an unused name for new folder */
80 tmp = g_strdup(title);
81 while (folder_find_child_item_by_name((FolderItem *)ctx->current->data, tmp)) {
82 debug_print("RSSyl: Folder '%s' already exists, trying another name\n",
85 tmp = g_strdup_printf("%s__%d", title, ++i);
88 /* Create the folder */
89 new_item = folder_create_folder((FolderItem *)ctx->current->data, tmp);
91 alertpanel_error(_("Can't create the folder '%s'."), tmp);
100 ctx->current = g_slist_prepend(ctx->current, new_item);
103 /* We have URL, try to add new feed... */
104 new_item = rssyl_feed_subscribe_new((FolderItem *)ctx->current->data,
106 /* ...and rename it if needed */
107 if (new_item != NULL && strcmp(title, new_item->name)) {
108 if (folder_item_rename(new_item, title) < 0) {
109 alertpanel_error(_("Error while subscribing feed\n"
110 "%s\n\nFolder name '%s' is not allowed."),