Fix error creation and warning
[claws.git] / src / plugins / perl / perl_gtk.c
blob0856186ff9a39d60bc81e1fa5b3b5b4873bba2b2
1 /* Perl plugin -- Perl Support for Claws Mail
3 * Copyright (C) 2004-2007 Holger Berndt
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
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.
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, see <http://www.gnu.org/licenses/>.
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #include "claws-features.h"
25 #endif
27 #include <glib.h>
28 #include <glib/gi18n.h>
30 #include <string.h>
32 #include <gtk/gtk.h>
34 #include "common/utils.h"
35 #include "mainwindow.h"
36 #include "prefs_common.h"
37 #include "main.h"
38 #include "menu.h"
40 #include "perl_plugin.h"
41 #include "perl_gtk.h"
43 static void perl_filter_edit(GtkAction *,gpointer);
46 static GtkActionEntry mainwindow_tools_perl_edit[] = {{
47 "Tools/EditPerlRules",
48 NULL, N_("Edit perl filter rules (ext)..."), NULL, NULL, G_CALLBACK(perl_filter_edit)
49 }};
51 static gint main_menu_id = 0;
54 void perl_gtk_init(void)
56 MainWindow *mainwin;
58 mainwin = mainwindow_get_mainwindow();
60 gtk_action_group_add_actions(mainwin->action_group, mainwindow_tools_perl_edit,
61 1, (gpointer)mainwin);
62 MENUITEM_ADDUI_ID_MANAGER(mainwin->ui_manager, "/Menu/Tools", "EditPerlRules",
63 "Tools/EditPerlRules", GTK_UI_MANAGER_MENUITEM,
64 main_menu_id)
67 void perl_gtk_done(void)
69 MainWindow *mainwin;
71 mainwin = mainwindow_get_mainwindow();
73 if(mainwin && !claws_is_exiting()) {
74 MENUITEM_REMUI_MANAGER(mainwin->ui_manager,mainwin->action_group, "Tools/EditPerlRules", main_menu_id);
75 main_menu_id = 0;
79 static void perl_filter_edit(GtkAction *action, gpointer callback_data)
81 gchar *perlfilter;
82 gchar *pp;
83 gchar buf[1024];
84 gchar **cmdline;
86 perlfilter = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, PERLFILTER, NULL);
87 if (prefs_common_get_ext_editor_cmd() &&
88 (pp = strchr(prefs_common_get_ext_editor_cmd(), '%')) &&
89 *(pp + 1) == 's' && !strchr(pp + 2, '%')) {
90 g_snprintf(buf, sizeof(buf), prefs_common_get_ext_editor_cmd(), perlfilter);
92 else {
93 if (prefs_common_get_ext_editor_cmd())
94 g_warning("Perl plugin: external editor command-line is invalid: `%s'",
95 prefs_common_get_ext_editor_cmd());
96 g_snprintf(buf, sizeof(buf), "emacs %s", perlfilter);
98 g_free(perlfilter);
99 cmdline = strsplit_with_quote(buf, " ", 1024);
100 execute_detached(cmdline);
101 g_strfreev(cmdline);