1 /* Perl plugin -- Perl Support for Claws Mail
2  *
3  * Copyright (C) 2004-2007 Holger Berndt
4  *
5  * Sylpheed and Claws Mail are GTK+ based, lightweight, and fast e-mail clients
6  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail Team
7  *
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 3 of the License, or
11  * (at your option) any later version.
12  *
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.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #include "claws-features.h"
25 #endif
26 
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 
30 #include <string.h>
31 
32 #include <glib.h>
33 #include <glib/gi18n.h>
34 #include <gtk/gtk.h>
35 
36 #include "common/utils.h"
37 #include "mainwindow.h"
38 #include "prefs_common.h"
39 #include "main.h"
40 #include "menu.h"
41 
42 #include "perl_plugin.h"
43 #include "perl_gtk.h"
44 
45 static void perl_filter_edit(GtkAction *,gpointer);
46 
47 
48 static GtkActionEntry mainwindow_tools_perl_edit[] = {{
49 	"Tools/EditPerlRules",
50 	NULL, N_("Edit perl filter rules (ext)..."), NULL, NULL, G_CALLBACK(perl_filter_edit)
51 }};
52 
53 static gint main_menu_id = 0;
54 
55 
perl_gtk_init(void)56 void perl_gtk_init(void)
57 {
58   MainWindow *mainwin;
59 
60   mainwin =  mainwindow_get_mainwindow();
61 
62   gtk_action_group_add_actions(mainwin->action_group, mainwindow_tools_perl_edit,
63 		  1, (gpointer)mainwin);
64   MENUITEM_ADDUI_ID_MANAGER(mainwin->ui_manager, "/Menu/Tools", "EditPerlRules",
65 		    "Tools/EditPerlRules", GTK_UI_MANAGER_MENUITEM,
66 		    main_menu_id)
67 }
68 
perl_gtk_done(void)69 void perl_gtk_done(void)
70 {
71   MainWindow *mainwin;
72 
73   mainwin = mainwindow_get_mainwindow();
74 
75   if(mainwin && !claws_is_exiting()) {
76     MENUITEM_REMUI_MANAGER(mainwin->ui_manager,mainwin->action_group, "Tools/EditPerlRules", main_menu_id);
77     main_menu_id = 0;
78   }
79 }
80 
perl_filter_edit(GtkAction * action,gpointer callback_data)81 static void perl_filter_edit(GtkAction *action, gpointer callback_data)
82 {
83   gchar *perlfilter;
84   gchar *pp;
85   gchar buf[1024];
86   gchar **cmdline;
87 
88   perlfilter = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, PERLFILTER, NULL);
89   if (prefs_common_get_ext_editor_cmd() &&
90       (pp = strchr(prefs_common_get_ext_editor_cmd(), '%')) &&
91       *(pp + 1) == 's' && !strchr(pp + 2, '%')) {
92     g_snprintf(buf, sizeof(buf), prefs_common_get_ext_editor_cmd(), perlfilter);
93   }
94   else {
95     if (prefs_common_get_ext_editor_cmd())
96       g_warning("Perl Plugin: External editor command-line is invalid: `%s'",
97 		prefs_common_get_ext_editor_cmd());
98     g_snprintf(buf, sizeof(buf), "emacs %s", perlfilter);
99   }
100   g_free(perlfilter);
101   cmdline = strsplit_with_quote(buf, " ", 1024);
102   execute_detached(cmdline);
103   g_strfreev(cmdline);
104 }
105