2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto & The Sylpheed Claws Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
35 #include "prefs_gtk.h"
39 #include "manage_window.h"
40 #include "mainwindow.h"
41 #include "prefs_common.h"
42 #include "alertpanel.h"
43 #include "prefs_actions.h"
45 #include "description_window.h"
48 PREFS_ACTIONS_STRING, /*!< string pointer managed by list store,
49 * and never touched or retrieved by
51 PREFS_ACTIONS_DATA, /*!< pointer to string that is not managed by
52 * the list store, and which is retrieved
53 * and touched by us */
54 PREFS_ACTIONS_VALID, /*!< contains a valid action, otherwise "(New)" */
55 N_PREFS_ACTIONS_COLUMNS
64 GtkWidget *name_entry;
67 GtkWidget *actions_list_view;
70 /* widget creating functions */
71 static void prefs_actions_create (MainWindow *mainwin);
72 static void prefs_actions_set_dialog (void);
73 static gint prefs_actions_clist_set_row (GtkTreeIter *row);
75 /* callback functions */
76 static void prefs_actions_help_cb (GtkWidget *w,
78 static void prefs_actions_register_cb (GtkWidget *w,
80 static void prefs_actions_substitute_cb (GtkWidget *w,
82 static void prefs_actions_delete_cb (GtkWidget *w,
84 static void prefs_actions_up (GtkWidget *w,
86 static void prefs_actions_down (GtkWidget *w,
88 static gint prefs_actions_deleted (GtkWidget *widget,
91 static gboolean prefs_actions_key_pressed(GtkWidget *widget,
94 static void prefs_actions_cancel (GtkWidget *w,
96 static void prefs_actions_ok (GtkWidget *w,
100 static GtkListStore* prefs_actions_create_data_store (void);
102 static void prefs_actions_list_view_insert_action (GtkWidget *list_view,
103 GtkTreeIter *row_iter,
106 static GtkWidget *prefs_actions_list_view_create (void);
107 static void prefs_actions_create_list_view_columns (GtkWidget *list_view);
108 static gboolean prefs_actions_selected (GtkTreeSelection *selector,
111 gboolean currently_selected,
114 void prefs_actions_open(MainWindow *mainwin)
119 prefs_actions_create(mainwin);
121 manage_window_set_transient(GTK_WINDOW(actions.window));
122 gtk_widget_grab_focus(actions.ok_btn);
124 prefs_actions_set_dialog();
126 gtk_widget_show(actions.window);
129 static void prefs_actions_create(MainWindow *mainwin)
134 GtkWidget *cancel_btn;
135 GtkWidget *confirm_area;
139 GtkWidget *entry_vbox;
141 GtkWidget *name_label;
142 GtkWidget *name_entry;
143 GtkWidget *cmd_label;
144 GtkWidget *cmd_entry;
150 GtkWidget *subst_btn;
153 GtkWidget *cond_hbox;
154 GtkWidget *cond_scrolledwin;
155 GtkWidget *cond_list_view;
157 GtkWidget *help_button;
163 debug_print("Creating actions configuration window...\n");
165 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
167 gtk_container_set_border_width(GTK_CONTAINER (window), 8);
168 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
169 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
170 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
171 gtk_window_set_default_size(GTK_WINDOW(window), 400, -1);
173 vbox = gtk_vbox_new(FALSE, 6);
174 gtk_widget_show(vbox);
175 gtk_container_add(GTK_CONTAINER(window), vbox);
177 gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK,
178 &cancel_btn, GTK_STOCK_CANCEL,
180 gtk_widget_show(confirm_area);
181 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
182 gtk_widget_grab_default(ok_btn);
184 gtk_window_set_title(GTK_WINDOW(window), _("Actions configuration"));
185 g_signal_connect(G_OBJECT(window), "delete_event",
186 G_CALLBACK(prefs_actions_deleted), NULL);
187 g_signal_connect(G_OBJECT(window), "key_press_event",
188 G_CALLBACK(prefs_actions_key_pressed), NULL);
189 MANAGE_WINDOW_SIGNALS_CONNECT(window);
190 g_signal_connect(G_OBJECT(ok_btn), "clicked",
191 G_CALLBACK(prefs_actions_ok), mainwin);
192 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
193 G_CALLBACK(prefs_actions_cancel), NULL);
195 vbox1 = gtk_vbox_new(FALSE, 8);
196 gtk_widget_show(vbox1);
197 gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
198 gtk_container_set_border_width(GTK_CONTAINER(vbox1), 2);
200 entry_vbox = gtk_vbox_new(FALSE, 4);
201 gtk_box_pack_start(GTK_BOX(vbox1), entry_vbox, FALSE, FALSE, 0);
203 hbox = gtk_hbox_new(FALSE, 8);
204 gtk_box_pack_start(GTK_BOX(entry_vbox), hbox, FALSE, FALSE, 0);
206 name_label = gtk_label_new(_("Menu name:"));
207 gtk_box_pack_start(GTK_BOX(hbox), name_label, FALSE, FALSE, 0);
209 name_entry = gtk_entry_new();
210 gtk_box_pack_start(GTK_BOX(hbox), name_entry, TRUE, TRUE, 0);
212 hbox = gtk_hbox_new(FALSE, 8);
213 gtk_box_pack_start(GTK_BOX(entry_vbox), hbox, TRUE, TRUE, 0);
215 cmd_label = gtk_label_new(_("Command line:"));
216 gtk_box_pack_start(GTK_BOX(hbox), cmd_label, FALSE, FALSE, 0);
218 cmd_entry = gtk_entry_new();
219 gtk_box_pack_start(GTK_BOX(hbox), cmd_entry, TRUE, TRUE, 0);
221 gtk_widget_show_all(entry_vbox);
223 /* register / substitute / delete */
225 reg_hbox = gtk_hbox_new(FALSE, 4);
226 gtk_widget_show(reg_hbox);
227 gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
229 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
230 gtk_widget_show(arrow);
231 gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
232 gtk_widget_set_size_request(arrow, -1, 16);
234 btn_hbox = gtk_hbox_new(TRUE, 4);
235 gtk_widget_show(btn_hbox);
236 gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
238 reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
239 gtk_widget_show(reg_btn);
240 gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
241 g_signal_connect(G_OBJECT(reg_btn), "clicked",
242 G_CALLBACK(prefs_actions_register_cb), NULL);
244 subst_btn = gtk_button_new_with_label(_(" Replace "));
245 gtk_widget_show(subst_btn);
246 gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
247 g_signal_connect(G_OBJECT(subst_btn), "clicked",
248 G_CALLBACK(prefs_actions_substitute_cb),
251 del_btn = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
252 gtk_widget_show(del_btn);
253 gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
254 g_signal_connect(G_OBJECT(del_btn), "clicked",
255 G_CALLBACK(prefs_actions_delete_cb), NULL);
257 help_button = gtk_button_new_with_label(_(" Syntax help "));
258 gtk_widget_show(help_button);
259 gtk_box_pack_end(GTK_BOX(reg_hbox), help_button, FALSE, FALSE, 0);
260 g_signal_connect(G_OBJECT(help_button), "clicked",
261 G_CALLBACK(prefs_actions_help_cb), NULL);
263 cond_hbox = gtk_hbox_new(FALSE, 8);
264 gtk_widget_show(cond_hbox);
265 gtk_box_pack_start(GTK_BOX(vbox1), cond_hbox, TRUE, TRUE, 0);
267 cond_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
268 gtk_widget_show(cond_scrolledwin);
269 gtk_widget_set_size_request(cond_scrolledwin, -1, 150);
270 gtk_box_pack_start(GTK_BOX(cond_hbox), cond_scrolledwin,
272 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (cond_scrolledwin),
273 GTK_POLICY_AUTOMATIC,
274 GTK_POLICY_AUTOMATIC);
276 cond_list_view = prefs_actions_list_view_create();
277 gtk_widget_show(cond_list_view);
278 gtk_container_add(GTK_CONTAINER (cond_scrolledwin), cond_list_view);
280 btn_vbox = gtk_vbox_new(FALSE, 8);
281 gtk_widget_show(btn_vbox);
282 gtk_box_pack_start(GTK_BOX(cond_hbox), btn_vbox, FALSE, FALSE, 0);
284 up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
285 gtk_widget_show(up_btn);
286 gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
287 g_signal_connect(G_OBJECT(up_btn), "clicked",
288 G_CALLBACK(prefs_actions_up), NULL);
290 down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
291 gtk_widget_show(down_btn);
292 gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
293 g_signal_connect(G_OBJECT(down_btn), "clicked",
294 G_CALLBACK(prefs_actions_down), NULL);
296 gtk_widget_show(window);
298 actions.window = window;
299 actions.ok_btn = ok_btn;
301 actions.name_entry = name_entry;
302 actions.cmd_entry = cmd_entry;
304 actions.actions_list_view = cond_list_view;
308 void prefs_actions_read_config(void)
312 gchar buf[PREFSBUFSIZE];
315 debug_print("Reading actions configurations...\n");
317 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
318 if ((fp = fopen(rcpath, "rb")) == NULL) {
319 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
325 while (prefs_common.actions_list != NULL) {
326 act = (gchar *)prefs_common.actions_list->data;
327 prefs_common.actions_list =
328 g_slist_remove(prefs_common.actions_list, act);
332 while (fgets(buf, sizeof(buf), fp) != NULL) {
333 const gchar *src_codeset = conv_get_locale_charset_str();
334 const gchar *dest_codeset = CS_UTF_8;
337 tmp = conv_codeset_strdup(buf, src_codeset, dest_codeset);
339 g_warning("Faild to convert character set of action configuration\n");
344 act = strstr(tmp, ": ");
346 action_get_type(&act[2]) != ACTION_ERROR)
347 prefs_common.actions_list =
348 g_slist_append(prefs_common.actions_list,
356 void prefs_actions_write_config(void)
362 debug_print("Writing actions configuration...\n");
364 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
365 if ((pfile= prefs_write_open(rcpath)) == NULL) {
366 g_warning("failed to write configuration to file\n");
371 for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
372 gchar *tmp = (gchar *)cur->data;
373 const gchar *src_codeset = CS_UTF_8;
374 const gchar *dest_codeset = conv_get_locale_charset_str();
377 act = conv_codeset_strdup(tmp, src_codeset, dest_codeset);
379 g_warning("Faild to convert character set of action configuration\n");
383 if (fputs(act, pfile->fp) == EOF ||
384 fputc('\n', pfile->fp) == EOF) {
385 FILE_OP_ERROR(rcpath, "fputs || fputc");
386 prefs_file_close_revert(pfile);
395 if (prefs_file_close(pfile) < 0) {
396 g_warning("failed to write configuration to file\n");
401 static void prefs_actions_set_dialog(void)
405 GtkTreeSelection *selection;
408 store = GTK_LIST_STORE(gtk_tree_view_get_model
409 (GTK_TREE_VIEW(actions.actions_list_view)));
410 gtk_list_store_clear(store);
412 prefs_actions_list_view_insert_action(actions.actions_list_view,
413 NULL, _("New"), FALSE);
415 for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
416 gchar *action = (gchar *) cur->data;
418 prefs_actions_list_view_insert_action(actions.actions_list_view,
422 /* select first entry */
423 selection = gtk_tree_view_get_selection
424 (GTK_TREE_VIEW(actions.actions_list_view));
425 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store),
427 gtk_tree_selection_select_iter(selection, &iter);
430 static void prefs_actions_set_list(void)
436 g_slist_free(prefs_common.actions_list);
437 prefs_common.actions_list = NULL;
439 store = GTK_LIST_STORE(gtk_tree_view_get_model
440 (GTK_TREE_VIEW(actions.actions_list_view)));
442 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) {
447 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
448 PREFS_ACTIONS_DATA, &action,
449 PREFS_ACTIONS_VALID, &is_valid,
453 prefs_common.actions_list =
454 g_slist_append(prefs_common.actions_list,
457 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store),
462 #define GET_ENTRY(entry) \
463 entry_text = gtk_entry_get_text(GTK_ENTRY(entry))
465 static gint prefs_actions_clist_set_row(GtkTreeIter *row)
467 const gchar *entry_text;
469 gchar action[PREFSBUFSIZE];
473 store = GTK_LIST_STORE(gtk_tree_view_get_model
474 (GTK_TREE_VIEW(actions.actions_list_view)));
477 GET_ENTRY(actions.name_entry);
478 if (entry_text[0] == '\0') {
479 alertpanel_error(_("Menu name is not set."));
483 if (strchr(entry_text, ':')) {
484 alertpanel_error(_("Colon ':' is not allowed in the menu name."));
488 strncpy(action, entry_text, PREFSBUFSIZE - 1);
491 /* Keep space for the ': ' delimiter */
492 len = strlen(action) + 2;
493 if (len >= PREFSBUFSIZE - 1) {
494 alertpanel_error(_("Menu name is too long."));
498 strcat(action, ": ");
500 GET_ENTRY(actions.cmd_entry);
502 if (entry_text[0] == '\0') {
503 alertpanel_error(_("Command line not set."));
507 if (len + strlen(entry_text) >= PREFSBUFSIZE - 1) {
508 alertpanel_error(_("Menu name and command are too long."));
512 if (action_get_type(entry_text) == ACTION_ERROR) {
513 alertpanel_error(_("The command\n%s\nhas a syntax error."),
518 strcat(action, entry_text);
520 new_action = g_strdup(action);
521 prefs_actions_list_view_insert_action(actions.actions_list_view,
522 row, new_action, TRUE);
524 prefs_actions_set_list();
529 /* callback functions */
531 static void prefs_actions_register_cb(GtkWidget *w, gpointer data)
533 prefs_actions_clist_set_row(NULL);
536 static void prefs_actions_substitute_cb(GtkWidget *w, gpointer data)
538 GtkTreeIter isel, inew;
539 GtkTreePath *path_sel, *path_new;
540 GtkTreeSelection *selection = gtk_tree_view_get_selection
541 (GTK_TREE_VIEW(actions.actions_list_view));
544 if (!gtk_tree_selection_get_selected(selection, &model, &isel))
546 if (!gtk_tree_model_get_iter_first(model, &inew))
549 path_sel = gtk_tree_model_get_path(model, &isel);
550 path_new = gtk_tree_model_get_path(model, &inew);
552 if (path_sel && path_new
553 && gtk_tree_path_compare(path_sel, path_new) != 0)
554 prefs_actions_clist_set_row(&isel);
556 gtk_tree_path_free(path_sel);
557 gtk_tree_path_free(path_new);
560 static void prefs_actions_delete_cb(GtkWidget *w, gpointer data)
566 if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection
567 (GTK_TREE_VIEW(actions.actions_list_view)),
571 if (alertpanel(_("Delete action"),
572 _("Do you really want to delete this action?"),
573 GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
576 /* XXX: Here's the reason why we need to store the original
577 * pointer: we search the slist for it. */
578 gtk_tree_model_get(model, &sel,
579 PREFS_ACTIONS_DATA, &action,
581 gtk_list_store_remove(GTK_LIST_STORE(model), &sel);
583 prefs_common.actions_list = g_slist_remove(prefs_common.actions_list,
587 static void prefs_actions_up(GtkWidget *w, gpointer data)
589 GtkTreePath *prev, *sel, *try;
594 if (!gtk_tree_selection_get_selected
595 (gtk_tree_view_get_selection
596 (GTK_TREE_VIEW(actions.actions_list_view)),
597 (GtkTreeModel **) &store,
601 sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
605 /* no move if we're at row 0 or 1, looks phony, but other
606 * solutions are more convoluted... */
607 try = gtk_tree_path_copy(sel);
608 if (!gtk_tree_path_prev(try) || !gtk_tree_path_prev(try)) {
609 gtk_tree_path_free(try);
610 gtk_tree_path_free(sel);
613 gtk_tree_path_free(try);
615 prev = gtk_tree_path_copy(sel);
616 if (!gtk_tree_path_prev(prev)) {
617 gtk_tree_path_free(prev);
618 gtk_tree_path_free(sel);
622 gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
624 gtk_tree_path_free(sel);
625 gtk_tree_path_free(prev);
627 gtk_list_store_swap(store, &iprev, &isel);
628 prefs_actions_set_list();
631 static void prefs_actions_down(GtkWidget *w, gpointer data)
634 GtkTreeIter next, sel;
637 if (!gtk_tree_selection_get_selected
638 (gtk_tree_view_get_selection
639 (GTK_TREE_VIEW(actions.actions_list_view)),
640 (GtkTreeModel **) &store,
644 try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
648 /* no move when we're at row 0 */
649 if (!gtk_tree_path_prev(try)) {
650 gtk_tree_path_free(try);
653 gtk_tree_path_free(try);
656 if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
659 gtk_list_store_swap(store, &next, &sel);
660 prefs_actions_set_list();
663 static gint prefs_actions_deleted(GtkWidget *widget, GdkEventAny *event,
666 prefs_actions_cancel(widget, data);
670 static gboolean prefs_actions_key_pressed(GtkWidget *widget, GdkEventKey *event,
673 if (event && event->keyval == GDK_Escape)
674 prefs_actions_cancel(widget, data);
678 static void prefs_actions_cancel(GtkWidget *w, gpointer data)
680 prefs_actions_read_config();
681 gtk_widget_hide(actions.window);
685 static void prefs_actions_ok(GtkWidget *widget, gpointer data)
687 MainWindow *mainwin = (MainWindow *) data;
690 MessageView *msgview;
693 prefs_actions_write_config();
695 /* Update mainwindow actions menu */
696 main_window_update_actions_menu(mainwin);
698 /* Update separated message view actions menu */
699 list = messageview_get_msgview_list();
700 for (iter = list; iter; iter = iter->next) {
701 msgview = (MessageView *) iter->data;
702 messageview_update_actions_menu(msgview);
705 /* Update compose windows actions menu */
706 list = compose_get_compose_list();
707 for (iter = list; iter; iter = iter->next) {
708 compose = (Compose *) iter->data;
709 compose_update_actions_menu(compose);
712 gtk_widget_hide(actions.window);
717 * Strings describing action format strings
719 * When adding new lines, remember to put one string for each line
721 static gchar *actions_desc_strings[] = {
722 N_("MENU NAME:"), NULL,
723 " ", N_("Use / in menu name to make submenus."),
725 N_("COMMAND LINE:"), NULL,
726 N_("Begin with:"), NULL,
727 " |", N_("to send message body or selection to command's standard input"),
728 " >", N_("to send user provided text to command's standard input"),
729 " *", N_("to send user provided hidden text to command's standard input"),
730 N_("End with:"), NULL,
731 " |", N_("to replace message body or selection with command's standard output"),
732 " >", N_("to insert command's standard output without replacing old text"),
733 " &", N_("to run command asynchronously"),
735 " %f", N_("for the file of the selected message in RFC822/2822 format "),
736 " %F", N_("for the list of the files of the selected messages in RFC822/2822 format"),
737 " %p", N_("for the file of the selected decoded message MIME part"),
738 " %u", N_("for a user provided argument"),
739 " %h", N_("for a user provided hidden argument (e.g. password)"),
740 " %s", N_("for the text selection"),
741 " %as{}", N_("apply filtering actions between {} to selected messages"),
746 static DescriptionWindow actions_desc_win = {
749 N_("Description of symbols"),
754 static void prefs_actions_help_cb(GtkWidget *w, gpointer data)
756 description_window_create(&actions_desc_win);
759 static GtkListStore* prefs_actions_create_data_store(void)
761 return gtk_list_store_new(N_PREFS_ACTIONS_COLUMNS,
768 static void prefs_actions_list_view_insert_action(GtkWidget *list_view,
769 GtkTreeIter *row_iter,
774 GtkListStore *list_store = GTK_LIST_STORE(gtk_tree_view_get_model
775 (GTK_TREE_VIEW(list_view)));
777 if (row_iter == NULL) {
779 gtk_list_store_append(list_store, &iter);
780 gtk_list_store_set(list_store, &iter,
781 PREFS_ACTIONS_STRING, action,
782 PREFS_ACTIONS_DATA, action,
783 PREFS_ACTIONS_VALID, is_valid,
786 /* change existing */
789 gtk_tree_model_get(GTK_TREE_MODEL(list_store), row_iter,
790 PREFS_ACTIONS_DATA, &old_action,
794 gtk_list_store_set(list_store, row_iter,
795 PREFS_ACTIONS_STRING, action,
796 PREFS_ACTIONS_DATA, action,
801 static GtkWidget *prefs_actions_list_view_create(void)
803 GtkTreeView *list_view;
804 GtkTreeSelection *selector;
807 model = GTK_TREE_MODEL(prefs_actions_create_data_store());
808 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
809 g_object_unref(model);
811 gtk_tree_view_set_rules_hint(list_view, TRUE);
813 selector = gtk_tree_view_get_selection(list_view);
814 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
815 gtk_tree_selection_set_select_function(selector, prefs_actions_selected,
818 /* create the columns */
819 prefs_actions_create_list_view_columns(GTK_WIDGET(list_view));
821 return GTK_WIDGET(list_view);
824 static void prefs_actions_create_list_view_columns(GtkWidget *list_view)
826 GtkTreeViewColumn *column;
827 GtkCellRenderer *renderer;
829 renderer = gtk_cell_renderer_text_new();
830 column = gtk_tree_view_column_new_with_attributes
831 (_("Current actions"),
833 "text", PREFS_ACTIONS_STRING,
835 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
838 #define ENTRY_SET_TEXT(entry, str) \
839 gtk_entry_set_text(GTK_ENTRY(entry), str ? str : "")
841 static gboolean prefs_actions_selected(GtkTreeSelection *selector,
844 gboolean currently_selected,
849 gchar buf[PREFSBUFSIZE];
853 if (currently_selected)
856 if (!gtk_tree_model_get_iter(model, &iter, path))
859 gtk_tree_model_get(model, &iter,
860 PREFS_ACTIONS_VALID, &is_valid,
861 PREFS_ACTIONS_DATA, &action,
864 ENTRY_SET_TEXT(actions.name_entry, "");
865 ENTRY_SET_TEXT(actions.cmd_entry, "");
869 strncpy(buf, action, PREFSBUFSIZE - 1);
870 buf[PREFSBUFSIZE - 1] = 0x00;
871 cmd = strstr(buf, ": ");
874 ENTRY_SET_TEXT(actions.cmd_entry, &cmd[2]);
879 ENTRY_SET_TEXT(actions.name_entry, buf);