root / src / prefs_search_folder.c @ 879
History | View | Annotate | Download (9.1 kB)
| 1 | /*
|
|---|---|
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | * Copyright (C) 1999-2005 Hiroyuki Yamamoto |
| 4 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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. |
| 18 | */ |
| 19 | |
| 20 | #ifdef HAVE_CONFIG_H
|
| 21 | # include "config.h" |
| 22 | #endif
|
| 23 | |
| 24 | #include "defs.h" |
| 25 | |
| 26 | #include <glib.h> |
| 27 | #include <glib/gi18n.h> |
| 28 | #include <gdk/gdkkeysyms.h> |
| 29 | #include <gtk/gtkwidget.h> |
| 30 | #include <gtk/gtkwindow.h> |
| 31 | #include <gtk/gtkvbox.h> |
| 32 | #include <gtk/gtkoptionmenu.h> |
| 33 | #include <gtk/gtkmenuitem.h> |
| 34 | #include <gtk/gtklabel.h> |
| 35 | #include <gtk/gtkentry.h> |
| 36 | #include <gtk/gtkhbox.h> |
| 37 | #include <gtk/gtkcheckbutton.h> |
| 38 | #include <gtk/gtkhbbox.h> |
| 39 | #include <gtk/gtkbutton.h> |
| 40 | #include <gtk/gtkstock.h> |
| 41 | #include <stdio.h> |
| 42 | #include <stdlib.h> |
| 43 | #include <string.h> |
| 44 | |
| 45 | #include "prefs_search_folder.h" |
| 46 | #include "prefs_ui.h" |
| 47 | #include "mainwindow.h" |
| 48 | #include "manage_window.h" |
| 49 | #include "alertpanel.h" |
| 50 | #include "foldersel.h" |
| 51 | #include "folder.h" |
| 52 | #include "filter.h" |
| 53 | #include "prefs_filter.h" |
| 54 | #include "prefs_filter_edit.h" |
| 55 | #include "menu.h" |
| 56 | #include "utils.h" |
| 57 | #include "gtkutils.h" |
| 58 | |
| 59 | typedef struct _PrefsSearchFolderDialog PrefsSearchFolderDialog; |
| 60 | |
| 61 | struct _PrefsSearchFolderDialog
|
| 62 | {
|
| 63 | PrefsDialog *dialog; |
| 64 | FolderItem *item; |
| 65 | |
| 66 | GtkWidget *bool_optmenu; |
| 67 | |
| 68 | FilterCondEdit *cond_edit; |
| 69 | |
| 70 | GtkWidget *folder_entry; |
| 71 | GtkWidget *folder_btn; |
| 72 | |
| 73 | GtkWidget *subfolder_checkbtn; |
| 74 | GtkWidget *case_checkbtn; |
| 75 | }; |
| 76 | |
| 77 | static PrefsSearchFolderDialog *prefs_search_folder_create(FolderItem *item);
|
| 78 | static void prefs_search_folder_set_dialog(PrefsSearchFolderDialog *dialog); |
| 79 | |
| 80 | static gint prefs_search_folder_delete_cb(GtkWidget *widget,
|
| 81 | GdkEventAny *event, |
| 82 | PrefsSearchFolderDialog *dialog); |
| 83 | static gint prefs_search_folder_key_press_cb
|
| 84 | (GtkWidget *widget, |
| 85 | GdkEventKey *event, |
| 86 | PrefsSearchFolderDialog *dialog); |
| 87 | |
| 88 | static void prefs_search_folder_ok_cb (GtkWidget *widget, |
| 89 | PrefsSearchFolderDialog *dialog); |
| 90 | static void prefs_search_folder_apply_cb (GtkWidget *widget, |
| 91 | PrefsSearchFolderDialog *dialog); |
| 92 | static void prefs_search_folder_cancel_cb(GtkWidget *widget, |
| 93 | PrefsSearchFolderDialog *dialog); |
| 94 | |
| 95 | |
| 96 | void prefs_search_folder_open(FolderItem *item)
|
| 97 | {
|
| 98 | PrefsSearchFolderDialog *dialog; |
| 99 | |
| 100 | g_return_if_fail(item != NULL);
|
| 101 | |
| 102 | dialog = prefs_search_folder_create(item); |
| 103 | manage_window_set_transient(GTK_WINDOW(dialog->dialog->window)); |
| 104 | prefs_search_folder_set_dialog(dialog); |
| 105 | gtk_widget_show(dialog->dialog->window); |
| 106 | } |
| 107 | |
| 108 | static PrefsSearchFolderDialog *prefs_search_folder_create(FolderItem *item)
|
| 109 | {
|
| 110 | PrefsSearchFolderDialog *new_dialog; |
| 111 | PrefsDialog *dialog; |
| 112 | GtkWidget *vbox; |
| 113 | GtkWidget *bool_hbox; |
| 114 | GtkWidget *bool_optmenu; |
| 115 | GtkWidget *bool_menu; |
| 116 | GtkWidget *menuitem; |
| 117 | |
| 118 | GtkWidget *scrolledwin; |
| 119 | FilterCondEdit *cond_edit; |
| 120 | |
| 121 | GtkWidget *folder_hbox; |
| 122 | GtkWidget *folder_label; |
| 123 | GtkWidget *folder_entry; |
| 124 | GtkWidget *folder_btn; |
| 125 | |
| 126 | GtkWidget *checkbtn_hbox; |
| 127 | GtkWidget *subfolder_checkbtn; |
| 128 | GtkWidget *case_checkbtn; |
| 129 | |
| 130 | new_dialog = g_new0(PrefsSearchFolderDialog, 1);
|
| 131 | |
| 132 | dialog = g_new0(PrefsDialog, 1);
|
| 133 | prefs_dialog_create(dialog); |
| 134 | |
| 135 | gtk_widget_set_size_request(dialog->window, 600, -1); |
| 136 | gtk_window_set_title(GTK_WINDOW(dialog->window), |
| 137 | _("Search folder properties"));
|
| 138 | gtk_notebook_set_show_border(GTK_NOTEBOOK(dialog->notebook), FALSE); |
| 139 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(dialog->notebook), FALSE); |
| 140 | |
| 141 | g_signal_connect(G_OBJECT(dialog->window), "delete_event",
|
| 142 | G_CALLBACK(prefs_search_folder_delete_cb), new_dialog); |
| 143 | g_signal_connect(G_OBJECT(dialog->window), "key_press_event",
|
| 144 | G_CALLBACK(prefs_search_folder_key_press_cb), |
| 145 | new_dialog); |
| 146 | |
| 147 | MANAGE_WINDOW_SIGNALS_CONNECT(dialog->window); |
| 148 | |
| 149 | vbox = gtk_vbox_new(FALSE, 6);
|
| 150 | gtk_widget_show(vbox); |
| 151 | gtk_container_add(GTK_CONTAINER(dialog->notebook), vbox); |
| 152 | //gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
|
| 153 | |
| 154 | bool_hbox = gtk_hbox_new(FALSE, 12);
|
| 155 | gtk_widget_show(bool_hbox); |
| 156 | gtk_box_pack_start(GTK_BOX(vbox), bool_hbox, FALSE, FALSE, 0);
|
| 157 | |
| 158 | bool_optmenu = gtk_option_menu_new(); |
| 159 | gtk_widget_show(bool_optmenu); |
| 160 | gtk_box_pack_start(GTK_BOX(bool_hbox), bool_optmenu, FALSE, FALSE, 0);
|
| 161 | |
| 162 | bool_menu = gtk_menu_new(); |
| 163 | MENUITEM_ADD(bool_menu, menuitem, _("Match any of the following"),
|
| 164 | FLT_OR); |
| 165 | MENUITEM_ADD(bool_menu, menuitem, _("Match all of the following"),
|
| 166 | FLT_AND); |
| 167 | gtk_option_menu_set_menu(GTK_OPTION_MENU(bool_optmenu), bool_menu); |
| 168 | |
| 169 | scrolledwin = gtk_scrolled_window_new(NULL, NULL); |
| 170 | gtk_widget_show(scrolledwin); |
| 171 | gtk_widget_set_size_request(scrolledwin, -1, 150); |
| 172 | gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
|
| 173 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), |
| 174 | GTK_POLICY_AUTOMATIC, |
| 175 | GTK_POLICY_AUTOMATIC); |
| 176 | |
| 177 | cond_edit = prefs_filter_edit_cond_edit_create(); |
| 178 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwin), |
| 179 | cond_edit->cond_vbox); |
| 180 | |
| 181 | folder_hbox = gtk_hbox_new (FALSE, 8);
|
| 182 | gtk_widget_show(folder_hbox); |
| 183 | gtk_box_pack_start(GTK_BOX(vbox), folder_hbox, FALSE, FALSE, 0);
|
| 184 | |
| 185 | folder_label = gtk_label_new(_("Folder:"));
|
| 186 | gtk_widget_show(folder_label); |
| 187 | gtk_box_pack_start(GTK_BOX(folder_hbox), folder_label, FALSE, FALSE, 0);
|
| 188 | |
| 189 | folder_entry = gtk_entry_new(); |
| 190 | gtk_widget_show(folder_entry); |
| 191 | gtk_box_pack_start(GTK_BOX(folder_hbox), folder_entry, TRUE, TRUE, 0);
|
| 192 | |
| 193 | folder_btn = gtk_button_new_with_label("...");
|
| 194 | gtk_widget_show(folder_btn); |
| 195 | gtk_box_pack_start(GTK_BOX(folder_hbox), folder_btn, FALSE, FALSE, 0);
|
| 196 | |
| 197 | checkbtn_hbox = gtk_hbox_new(FALSE, 12);
|
| 198 | gtk_widget_show(checkbtn_hbox); |
| 199 | gtk_box_pack_start(GTK_BOX(vbox), checkbtn_hbox, FALSE, FALSE, 0);
|
| 200 | |
| 201 | subfolder_checkbtn = |
| 202 | gtk_check_button_new_with_label(_("Search subfolders"));
|
| 203 | gtk_widget_show(subfolder_checkbtn); |
| 204 | gtk_box_pack_start(GTK_BOX(checkbtn_hbox), subfolder_checkbtn, |
| 205 | FALSE, FALSE, 0);
|
| 206 | |
| 207 | case_checkbtn = gtk_check_button_new_with_label(_("Case sensitive"));
|
| 208 | gtk_widget_show(case_checkbtn); |
| 209 | gtk_box_pack_start(GTK_BOX(checkbtn_hbox), case_checkbtn, |
| 210 | FALSE, FALSE, 0);
|
| 211 | |
| 212 | g_signal_connect(G_OBJECT(dialog->ok_btn), "clicked",
|
| 213 | G_CALLBACK(prefs_search_folder_ok_cb), new_dialog); |
| 214 | g_signal_connect(G_OBJECT(dialog->apply_btn), "clicked",
|
| 215 | G_CALLBACK(prefs_search_folder_apply_cb), new_dialog); |
| 216 | g_signal_connect(G_OBJECT(dialog->cancel_btn), "clicked",
|
| 217 | G_CALLBACK(prefs_search_folder_cancel_cb), new_dialog); |
| 218 | |
| 219 | new_dialog->dialog = dialog; |
| 220 | new_dialog->item = item; |
| 221 | new_dialog->bool_optmenu = bool_optmenu; |
| 222 | new_dialog->cond_edit = cond_edit; |
| 223 | |
| 224 | new_dialog->folder_entry = folder_entry; |
| 225 | new_dialog->folder_btn = folder_btn; |
| 226 | new_dialog->subfolder_checkbtn = subfolder_checkbtn; |
| 227 | new_dialog->case_checkbtn = case_checkbtn; |
| 228 | |
| 229 | return new_dialog;
|
| 230 | } |
| 231 | |
| 232 | static void prefs_search_folder_set_dialog(PrefsSearchFolderDialog *dialog) |
| 233 | {
|
| 234 | GSList *flist; |
| 235 | FilterRule *rule; |
| 236 | gchar *path; |
| 237 | gchar *rule_file; |
| 238 | FolderItem *target; |
| 239 | gint index; |
| 240 | |
| 241 | path = folder_item_get_path(dialog->item); |
| 242 | rule_file = g_strconcat(path, G_DIR_SEPARATOR_S, "filter.xml", NULL); |
| 243 | flist = filter_read_file(rule_file); |
| 244 | g_free(rule_file); |
| 245 | g_free(path); |
| 246 | |
| 247 | if (!flist) {
|
| 248 | g_warning("filter rule not found\n");
|
| 249 | return;
|
| 250 | } |
| 251 | |
| 252 | rule = (FilterRule *)flist->data; |
| 253 | target = folder_find_item_from_identifier(rule->target_folder); |
| 254 | |
| 255 | index = menu_find_option_menu_index |
| 256 | (GTK_OPTION_MENU(dialog->bool_optmenu), |
| 257 | GINT_TO_POINTER(rule->bool_op), NULL);
|
| 258 | if (index < 0) |
| 259 | index = 0;
|
| 260 | gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->bool_optmenu), |
| 261 | index); |
| 262 | |
| 263 | prefs_filter_set_header_list(NULL);
|
| 264 | prefs_filter_edit_set_header_list(dialog->cond_edit, rule); |
| 265 | prefs_filter_edit_add_rule_cond(dialog->cond_edit, rule); |
| 266 | |
| 267 | filter_rule_list_free(flist); |
| 268 | } |
| 269 | |
| 270 | static void prefs_search_folder_destroy(PrefsSearchFolderDialog *dialog) |
| 271 | {
|
| 272 | prefs_dialog_destroy(dialog->dialog); |
| 273 | g_free(dialog->dialog); |
| 274 | g_free(dialog); |
| 275 | |
| 276 | main_window_popup(main_window_get()); |
| 277 | } |
| 278 | |
| 279 | static gint prefs_search_folder_delete_cb(GtkWidget *widget, GdkEventAny *event,
|
| 280 | PrefsSearchFolderDialog *dialog) |
| 281 | {
|
| 282 | prefs_search_folder_destroy(dialog); |
| 283 | return TRUE;
|
| 284 | } |
| 285 | |
| 286 | static gint prefs_search_folder_key_press_cb(GtkWidget *widget,
|
| 287 | GdkEventKey *event, |
| 288 | PrefsSearchFolderDialog *dialog) |
| 289 | {
|
| 290 | if (event && event->keyval == GDK_Escape) {
|
| 291 | prefs_search_folder_cancel_cb(widget, dialog); |
| 292 | return TRUE;
|
| 293 | } |
| 294 | return FALSE;
|
| 295 | } |
| 296 | |
| 297 | static void prefs_search_folder_ok_cb(GtkWidget *widget, |
| 298 | PrefsSearchFolderDialog *dialog) |
| 299 | {
|
| 300 | prefs_search_folder_apply_cb(widget, dialog); |
| 301 | prefs_search_folder_destroy(dialog); |
| 302 | } |
| 303 | |
| 304 | static void prefs_search_folder_apply_cb(GtkWidget *widget, |
| 305 | PrefsSearchFolderDialog *dialog) |
| 306 | {
|
| 307 | // create filter rule
|
| 308 | // delete search cache
|
| 309 | } |
| 310 | |
| 311 | static void prefs_search_folder_cancel_cb(GtkWidget *widget, |
| 312 | PrefsSearchFolderDialog *dialog) |
| 313 | {
|
| 314 | prefs_search_folder_destroy(dialog); |
| 315 | } |