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 * - GUI handling functions
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 <mainwindow.h>
34 #include <inputdialog.h>
35 #include <folderview.h>
36 #include <alertpanel.h>
38 #include <summaryview.h>
42 #include "rssyl_prefs.h"
43 #include "rssyl_gtk.h"
44 #include "rssyl_cb_menu.h"
46 static char *rssyl_popup_menu_labels[] =
49 N_("Feed pr_operties"),
51 N_("R_efresh recursively"),
52 N_("Subscribe _new feed..."),
53 N_("Create new _folder..."),
54 N_("Import feed list..."),
55 N_("_Delete folder..."),
60 static GtkActionEntry rssyl_popup_entries[] =
62 {"FolderViewPopup/RefreshFeed", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_refresh_feed_cb) },
63 {"FolderViewPopup/FeedProperties", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_prop_cb) },
64 {"FolderViewPopup/RenameFolder", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_rename_cb) },
65 {"FolderViewPopup/RefreshAllFeeds", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_update_all_cb) },
66 {"FolderViewPopup/NewFeed", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_new_feed_cb) },
67 {"FolderViewPopup/NewFolder", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_new_folder_cb) },
68 {"FolderViewPopup/ImportFeedList", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_import_feed_list_cb) },
69 {"FolderViewPopup/RemoveFolder", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_remove_folder_cb) },
70 {"FolderViewPopup/RemoveMailbox", NULL, NULL, NULL, NULL, G_CALLBACK(rssyl_remove_mailbox_cb) }
73 static void rssyl_add_menuitems(GtkUIManager *ui_manager, FolderItem *item)
75 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "RefreshFeed", "FolderViewPopup/RefreshFeed", GTK_UI_MANAGER_MENUITEM)
76 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "FeedProperties", "FolderViewPopup/FeedProperties", GTK_UI_MANAGER_MENUITEM)
77 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "RenameFolder", "FolderViewPopup/RenameFolder", GTK_UI_MANAGER_MENUITEM)
78 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "SeparatorRSS1", "FolderViewPopup/---", GTK_UI_MANAGER_SEPARATOR)
79 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "RefreshAllFeeds", "FolderViewPopup/RefreshAllFeeds", GTK_UI_MANAGER_MENUITEM)
80 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "SeparatorRSS2", "FolderViewPopup/---", GTK_UI_MANAGER_SEPARATOR)
81 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "NewFeed", "FolderViewPopup/NewFeed", GTK_UI_MANAGER_MENUITEM)
82 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "NewFolder", "FolderViewPopup/NewFolder", GTK_UI_MANAGER_MENUITEM)
83 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "ImportFeedList", "FolderViewPopup/ImportFeedList", GTK_UI_MANAGER_MENUITEM)
84 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "SeparatorRSS3", "FolderViewPopup/---", GTK_UI_MANAGER_SEPARATOR)
85 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "RemoveFolder", "FolderViewPopup/RemoveFolder", GTK_UI_MANAGER_MENUITEM)
86 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "SeparatorRSS4", "FolderView/Popup/---", GTK_UI_MANAGER_SEPARATOR)
87 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "RemoveMailbox", "FolderViewPopup/RemoveMailbox", GTK_UI_MANAGER_MENUITEM)
88 MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "SeparatorRSS5", "FolderView/Popup/---", GTK_UI_MANAGER_SEPARATOR)
91 static void rssyl_set_sensitivity(GtkUIManager *ui_manager, FolderItem *item)
93 #define SET_SENS(name, sens) \
94 cm_menu_set_sensitive_full(ui_manager, "Popup/"name, sens)
95 RFolderItem *ritem = (RFolderItem *)item;
96 SET_SENS("FolderViewPopup/RefreshFeed", folder_item_parent(item) != NULL && ritem->url );
97 SET_SENS("FolderViewPopup/FeedProperties", folder_item_parent(item) != NULL && ritem->url );
98 SET_SENS("FolderViewPopup/RenameFolder", folder_item_parent(item) != NULL );
99 SET_SENS("FolderViewPopup/RefreshAllFeeds", TRUE );
100 SET_SENS("FolderViewPopup/NewFeed", TRUE);
101 SET_SENS("FolderViewPopup/NewFolder", TRUE );
102 SET_SENS("FolderViewPopup/RemoveFolder", folder_item_parent(item) != NULL);
103 SET_SENS("FolderViewPopup/RemoveMailbox", folder_item_parent(item) == NULL);
108 static FolderViewPopup rssyl_popup =
113 G_N_ELEMENTS(rssyl_popup_entries),
117 rssyl_set_sensitivity
120 static void rssyl_add_mailbox(GtkAction *action, gpointer callback_data)
122 MainWindow *mainwin = (MainWindow *) callback_data;
123 gchar *path = NULL, *tmp = NULL;
126 path = input_dialog(_("Add RSS folder tree"),
127 _("Enter name for a new RSS folder tree."),
128 RSSYL_DEFAULT_MAILBOX);
131 if( folder_find_from_path(path) ) {
132 alertpanel_error(_("The mailbox '%s' already exists."), path);
137 tmp = g_path_get_basename(path);
138 folder = folder_new(folder_get_class_from_string("rssyl"), tmp, path);
142 if( folder->klass->create_tree(folder) < 0 ) {
143 alertpanel_error(_("Creation of folder tree failed.\n"
144 "Maybe some files already exist, or you don't have the permission "
146 folder_destroy(folder);
151 folder_scan_tree(folder, TRUE);
153 folderview_set(mainwin->folderview);
157 static GtkActionEntry mainwindow_add_mailbox[] = {{
158 "File/AddMailbox/RSSyl",
159 NULL, "RSSyl...", NULL, NULL, G_CALLBACK(rssyl_add_mailbox)
162 static void rssyl_fill_popup_menu_labels(void) {
165 for (i = 0; rssyl_popup_menu_labels[i] != NULL; i++) {
166 (rssyl_popup_entries[i].label = _(rssyl_popup_menu_labels[i]));
170 static guint main_menu_id = 0;
172 void rssyl_gtk_init(void)
174 MainWindow *mainwin = mainwindow_get_mainwindow();
175 gtk_action_group_add_actions(mainwin->action_group, mainwindow_add_mailbox,
176 1, (gpointer)mainwin);
177 MENUITEM_ADDUI_ID_MANAGER(mainwin->ui_manager, "/Menu/File/AddMailbox", PLUGIN_NAME,
178 "File/AddMailbox/"PLUGIN_NAME, GTK_UI_MANAGER_MENUITEM,
180 rssyl_fill_popup_menu_labels();
181 folderview_register_popup(&rssyl_popup);
184 void rssyl_gtk_done(void)
186 MainWindow *mainwin = mainwindow_get_mainwindow();
187 FolderView *folderview = NULL;
188 FolderItem *fitem = NULL;
190 if (mainwin == NULL || claws_is_exiting())
193 folderview = mainwin->folderview;
194 fitem = folderview->summaryview->folder_item;
196 if( fitem && IS_RSSYL_FOLDER_ITEM(fitem) ) {
197 folderview_unselect(folderview);
198 summary_clear_all(folderview->summaryview);
201 folderview_unregister_popup(&rssyl_popup);
203 MENUITEM_REMUI_MANAGER(mainwin->ui_manager,mainwin->action_group, "File/AddMailbox/RSSyl", main_menu_id);