1 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
2 /* Balsa E-Mail Client
3  * Copyright (C) 1997-2013 Stuart Parmenter and others,
4  *                         See the file AUTHORS for a list.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21 
22 /*
23  * Author : Emmanuel ALLAUD
24  */
25 
26 /*
27  * FIXME : should have a combo box for mailbox name when selecting a move or copy action
28  */
29 
30 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
31 # include "config.h"
32 #endif                          /* HAVE_CONFIG_H */
33 #include "filter-export.h"
34 
35 #include "balsa-app.h"
36 
37 #include <glib/gi18n.h>	/* Must come after balsa-app.h. */
38 
39 /* To prevent user from silmultaneously edit/export filters */
40 
41 extern gboolean fe_already_open;
42 extern GList * fr_dialogs_opened;
43 
44 gboolean fex_already_open=FALSE;
45 
46 GtkWidget * fex_window;
47 
48 /*
49  * filters_export_dialog()
50  *
51  * Returns immediately, but fires off the filter export dialog.
52  */
53 void
filters_export_dialog(void)54 filters_export_dialog(void)
55 {
56     GtkTreeView *list;
57     GtkTreeModel *model;
58     GtkTreeIter iter;
59     GtkWidget *sw;
60     LibBalsaFilter *fil;
61     GSList *filter_list;
62 
63     if (fr_dialogs_opened) {
64 	balsa_information(LIBBALSA_INFORMATION_ERROR,
65                           _("There are opened filter run dialogs, "
66                             "close them before you can modify filters."));
67 	return;
68     }
69     if (fex_already_open) {
70 	gtk_window_present(GTK_WINDOW(fex_window));
71 	return;
72     }
73 
74     fex_already_open = TRUE;
75 
76     fex_window =
77         gtk_dialog_new_with_buttons(_("Balsa Filters Export"),
78                                     NULL, 0, /* FIXME */
79                                     GTK_STOCK_OK,     GTK_RESPONSE_OK,
80                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
81                                     GTK_STOCK_HELP,   GTK_RESPONSE_HELP,
82                                     NULL);
83     gtk_window_set_wmclass(GTK_WINDOW(fex_window), "filter-export",
84                            "Balsa");
85 
86     sw = gtk_scrolled_window_new(NULL, NULL);
87     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
88 				   GTK_POLICY_AUTOMATIC,
89 				   GTK_POLICY_AUTOMATIC);
90 
91     list =
92         libbalsa_filter_list_new(TRUE, _("Name"), GTK_SELECTION_MULTIPLE,
93                                  NULL, TRUE);
94 
95     gtk_container_add(GTK_CONTAINER(sw), GTK_WIDGET(list));
96     gtk_box_pack_start(GTK_BOX
97                        (gtk_dialog_get_content_area(GTK_DIALOG(fex_window))),
98                        sw, TRUE, TRUE, 2);
99 
100     /* Populate the list of filters */
101 
102     model = gtk_tree_view_get_model(list);
103     for (filter_list = balsa_app.filters; filter_list;
104          filter_list = g_slist_next(filter_list)) {
105         fil = (LibBalsaFilter *) filter_list->data;
106         gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
107         gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, fil->name, 1,
108                            fil, -1);
109     }
110     if (gtk_tree_model_get_iter_first(model, &iter)) {
111         GtkTreeSelection *selection =
112             gtk_tree_view_get_selection(list);
113         gtk_tree_selection_select_iter(selection, &iter);
114     }
115 
116     g_signal_connect(G_OBJECT(fex_window), "response",
117                      G_CALLBACK(fex_dialog_response), list);
118     g_signal_connect(G_OBJECT(fex_window), "destroy",
119 		     G_CALLBACK(fex_destroy_window_cb), NULL);
120 
121     gtk_widget_show_all(GTK_WIDGET(fex_window));
122 }
123