1 /*
2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2015 the Claws Mail Team
4 * Copyright (C) 2014-2015 Charles Lehner
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 3 of the License, or
9 * (at your option) 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, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <glib.h>
22 #include <glib/gi18n.h>
23
24 #include "version.h"
25 #include "claws.h"
26 #include "plugin.h"
27 #include "utils.h"
28 #include "hooks.h"
29 #include "menu.h"
30 #include "mainwindow.h"
31 #include "log.h"
32 #include "sieve_prefs.h"
33 #include "sieve_manager.h"
34 #include "sieve_editor.h"
35
36 #define PLUGIN_NAME (_("ManageSieve"))
37
38 static gint main_menu_id = 0;
39
manage_cb(GtkAction * action,gpointer data)40 static void manage_cb(GtkAction *action, gpointer data) {
41 sieve_manager_show();
42 }
43
44 static GtkActionEntry sieve_main_menu[] = {{
45 "Tools/ManageSieveFilters",
46 NULL, N_("Manage Sieve Filters..."), NULL, NULL, G_CALLBACK(manage_cb)
47 }};
48
49 /**
50 * Initialize plugin.
51 *
52 * @param error For storing the returned error message.
53 *
54 * @return 0 if initialization succeeds, -1 on failure.
55 */
plugin_init(gchar ** error)56 gint plugin_init(gchar **error)
57 {
58 MainWindow *mainwin = mainwindow_get_mainwindow();
59
60 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
61 VERSION_NUMERIC, PLUGIN_NAME, error))
62 return -1;
63
64 gtk_action_group_add_actions(mainwin->action_group, sieve_main_menu, 1,
65 (gpointer)mainwin);
66 MENUITEM_ADDUI_ID_MANAGER(mainwin->ui_manager,
67 "/Menu/Tools", "ManageSieveFilters", "Tools/ManageSieveFilters",
68 GTK_UI_MANAGER_MENUITEM, main_menu_id)
69
70 sieve_prefs_init();
71
72 debug_print("ManageSieve plugin loaded\n");
73
74 return 0;
75 }
76
77 /**
78 * Destructor for the plugin.
79 * Unregister callback functions and free stuff.
80 *
81 * @return Always TRUE.
82 */
plugin_done(void)83 gboolean plugin_done(void)
84 {
85 MainWindow *mainwin = mainwindow_get_mainwindow();
86
87 sieve_prefs_done();
88 sieve_managers_done();
89 sieve_editors_close();
90 sieve_sessions_close();
91
92 if (mainwin)
93 MENUITEM_REMUI_MANAGER(mainwin->ui_manager,
94 mainwin->action_group,
95 "Tools/ManageSieveFilters", main_menu_id);
96
97 debug_print("ManageSieve plugin unloaded\n");
98
99 return TRUE;
100 }
101
plugin_name(void)102 const gchar *plugin_name(void)
103 {
104 return PLUGIN_NAME;
105 }
106
107 /**
108 * Get the description of the plugin.
109 *
110 * @return The plugin's description, maybe translated.
111 */
plugin_desc(void)112 const gchar *plugin_desc(void)
113 {
114 return _("Manage sieve filters on a server using the ManageSieve protocol.");
115 }
116
117 /**
118 * Get the kind of plugin.
119 *
120 * @return The "GTK2" constant.
121 */
plugin_type(void)122 const gchar *plugin_type(void)
123 {
124 return "GTK2";
125 }
126 /**
127 * Get the license acronym the plugin is released under.
128 *
129 * @return The "GPL3+" constant.
130 */
plugin_licence(void)131 const gchar *plugin_licence(void)
132 {
133 return "GPL3+";
134 }
135
136 /**
137 * Get the version of the plugin.
138 *
139 * @return The current version string.
140 */
plugin_version(void)141 const gchar *plugin_version(void)
142 {
143 return VERSION;
144 }
145
146 /**
147 * Get the features implemented by the plugin.
148 *
149 * @return A constant PluginFeature structure with the features.
150 */
plugin_provides(void)151 struct PluginFeature *plugin_provides(void)
152 {
153 static struct PluginFeature features[] =
154 { {PLUGIN_UTILITY, N_("ManageSieve")},
155 {PLUGIN_NOTHING, NULL}};
156
157 return features;
158 }
159