/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2009 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <gtk/gtkoptionmenu.h>
#include <gdk/gdkkeysyms.h>
#include <stdio.h>
#include <stdlib.h>
#include "addr_compl.h"
#include "manual.h"
#include "combobox.h"
+#include "menu.h"
#include "matcher_parser.h"
#include "matcher.h"
static void prefs_filtering_set_list (void);
/* callback functions */
-static void prefs_filtering_register_cb (void);
-static void prefs_filtering_substitute_cb (void);
-static void prefs_filtering_delete_cb (void);
-static void prefs_filtering_top (void);
-static void prefs_filtering_up (void);
-static void prefs_filtering_down (void);
-static void prefs_filtering_bottom (void);
+static gboolean prefs_filtering_search_func_cb (GtkTreeModel *model, gint column,
+ const gchar *key, GtkTreeIter *iter,
+ gpointer search_data);
+static void prefs_filtering_register_cb (gpointer action, gpointer data);
+static void prefs_filtering_substitute_cb (gpointer action, gpointer data);
+static void prefs_filtering_delete_cb (gpointer action, gpointer data);
+static void prefs_filtering_delete_all_cb(gpointer action, gpointer data);
+static void prefs_filtering_clear_cb(gpointer action, gpointer data);
+static void prefs_filtering_duplicate_cb(gpointer action, gpointer data);
+static void prefs_filtering_top (gpointer action, gpointer data);
+static void prefs_filtering_page_up (gpointer action, gpointer data);
+static void prefs_filtering_up (gpointer action, gpointer data);
+static void prefs_filtering_down (gpointer action, gpointer data);
+static void prefs_filtering_page_down (gpointer action, gpointer data);
+static void prefs_filtering_bottom (gpointer action, gpointer data);
static gint prefs_filtering_deleted (GtkWidget *widget,
GdkEventAny *event,
gpointer data);
static gboolean prefs_filtering_key_pressed(GtkWidget *widget,
GdkEventKey *event,
gpointer data);
-static void prefs_filtering_cancel (void);
-static void prefs_filtering_ok (void);
+static void prefs_filtering_cancel (gpointer action, gpointer data);
+static void prefs_filtering_ok (gpointer action, gpointer data);
-static void prefs_filtering_condition_define (void);
-static void prefs_filtering_action_define(void);
+static void prefs_filtering_condition_define (gpointer action, gpointer data);
+static void prefs_filtering_action_define (gpointer action, gpointer data);
static gint prefs_filtering_list_view_set_row (gint row, FilteringProp * prop);
static void prefs_filtering_reset_dialog (void);
static GtkWidget *prefs_filtering_list_view_create (void);
static void prefs_filtering_create_list_view_columns (GtkWidget *list_view);
-static gboolean prefs_filtering_selected (GtkTreeSelection *selector,
- GtkTreeModel *model,
- GtkTreePath *path,
- gboolean currently_selected,
- gpointer data);
+static void prefs_filtering_select_row(GtkTreeView *list_view, GtkTreePath *path);
static void prefs_filtering_account_option_menu_populate(void);
}
gtk_widget_show(filtering.window);
+ gtk_window_set_modal(GTK_WINDOW(filtering.window), TRUE);
start_address_completion(NULL);
}
static void prefs_filtering_size_allocate_cb(GtkWidget *widget,
GtkAllocation *allocation)
{
- g_return_if_fail(allocation != NULL);
+ cm_return_if_fail(allocation != NULL);
prefs_common.filteringwin_width = allocation->width;
prefs_common.filteringwin_height = allocation->height;
/* prefs_filtering_close() - just to have one common exit point */
static void prefs_filtering_close(void)
{
+ GtkListStore *store;
+
end_address_completion();
-
+
+ store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
+ (filtering.cond_list_view)));
+ gtk_list_store_clear(store);
gtk_widget_hide(filtering.window);
+ gtk_window_set_modal(GTK_WINDOW(filtering.window), FALSE);
inc_unlock();
}
accounts = account_get_list();
- g_return_if_fail(accounts != NULL);
+ cm_return_if_fail(accounts != NULL);
COMBOBOX_ADD(filtering.account_combobox_list, Q_("Filtering Account Menu|All"), 0);
+ COMBOBOX_ADD(filtering.account_combobox_list, NULL, 0);
for (; accounts != NULL; accounts = accounts->next) {
PrefsAccount *ac = (PrefsAccount *)accounts->data;
GtkWidget *reg_btn;
GtkWidget *subst_btn;
GtkWidget *del_btn;
+ GtkWidget *clear_btn;
GtkWidget *cond_hbox;
GtkWidget *cond_scrolledwin;
GtkWidget *cond_list_view;
GtkWidget *btn_vbox;
- GtkWidget *spc_vbox;
GtkWidget *top_btn;
GtkWidget *up_btn;
GtkWidget *down_btn;
+#ifndef GENERIC_UMPC
+ GtkWidget *page_up_btn;
+ GtkWidget *page_down_btn;
+#endif
GtkWidget *bottom_btn;
GtkWidget *table;
static GdkGeometry geometry;
+ CLAWS_TIP_DECL();
debug_print("Creating filtering configuration window...\n");
window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering");
gtk_container_set_border_width (GTK_CONTAINER (window), 8);
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
- gtk_window_set_modal (GTK_WINDOW (window), TRUE);
gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
vbox = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
g_signal_connect(G_OBJECT (reg_btn), "clicked",
G_CALLBACK(prefs_filtering_register_cb), NULL);
+ CLAWS_SET_TIP(reg_btn,
+ _("Append the new rule above to the list"));
subst_btn = gtkut_get_replace_btn (_("Replace"));
gtk_widget_show (subst_btn);
g_signal_connect(G_OBJECT (subst_btn), "clicked",
G_CALLBACK(prefs_filtering_substitute_cb),
NULL);
+ CLAWS_SET_TIP(subst_btn,
+ _("Replace the selected rule in list with the rule above"));
del_btn = gtk_button_new_from_stock (GTK_STOCK_DELETE);
gtk_widget_show (del_btn);
gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
g_signal_connect(G_OBJECT (del_btn), "clicked",
G_CALLBACK(prefs_filtering_delete_cb), NULL);
+ CLAWS_SET_TIP(del_btn,
+ _("Delete the selected rule from the list"));
+
+ clear_btn = gtk_button_new_from_stock (GTK_STOCK_CLEAR);
+ gtk_widget_show (clear_btn);
+ gtk_box_pack_start (GTK_BOX (btn_hbox), clear_btn, FALSE, TRUE, 0);
+ g_signal_connect(G_OBJECT (clear_btn), "clicked",
+ G_CALLBACK(prefs_filtering_clear_cb), NULL);
+ CLAWS_SET_TIP(clear_btn,
+ _("Clear all the input fields in the dialog"));
cond_hbox = gtk_hbox_new (FALSE, 8);
gtk_widget_show (cond_hbox);
gtk_box_pack_start (GTK_BOX (btn_vbox), top_btn, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT (top_btn), "clicked",
G_CALLBACK(prefs_filtering_top), NULL);
-
- PACK_VSPACER (btn_vbox, spc_vbox, VSPACING_NARROW_2);
+ CLAWS_SET_TIP(top_btn,
+ _("Move the selected rule to the top"));
+
+#ifndef GENERIC_UMPC
+ page_up_btn = gtk_button_new_with_mnemonic (_("Page up"));
+ gtk_button_set_image(GTK_BUTTON(page_up_btn),
+ gtk_image_new_from_stock(GTK_STOCK_GO_UP,GTK_ICON_SIZE_BUTTON));
+ gtk_widget_show (page_up_btn);
+ gtk_box_pack_start (GTK_BOX (btn_vbox), page_up_btn, FALSE, FALSE, 0);
+ g_signal_connect(G_OBJECT (page_up_btn), "clicked",
+ G_CALLBACK(prefs_filtering_page_up), NULL);
+ CLAWS_SET_TIP(page_up_btn,
+ _("Move the selected rule one page up"));
+#endif
up_btn = gtk_button_new_from_stock (GTK_STOCK_GO_UP);
gtk_widget_show (up_btn);
gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT (up_btn), "clicked",
G_CALLBACK(prefs_filtering_up), NULL);
+ CLAWS_SET_TIP(up_btn,
+ _("Move the selected rule up"));
down_btn = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN);
gtk_widget_show (down_btn);
gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT (down_btn), "clicked",
G_CALLBACK(prefs_filtering_down), NULL);
-
- PACK_VSPACER (btn_vbox, spc_vbox, VSPACING_NARROW_2);
+ CLAWS_SET_TIP(down_btn,
+ _("Move the selected rule down"));
+
+#ifndef GENERIC_UMPC
+ page_down_btn = gtk_button_new_with_mnemonic (_("Page down"));
+ gtk_button_set_image(GTK_BUTTON(page_down_btn),
+ gtk_image_new_from_stock(GTK_STOCK_GO_DOWN,GTK_ICON_SIZE_BUTTON));
+ gtk_widget_show (page_down_btn);
+ gtk_box_pack_start (GTK_BOX (btn_vbox), page_down_btn, FALSE, FALSE, 0);
+ g_signal_connect(G_OBJECT (page_down_btn), "clicked",
+ G_CALLBACK(prefs_filtering_page_down), NULL);
+ CLAWS_SET_TIP(page_down_btn,
+ _("Move the selected rule one page down"));
+#endif
bottom_btn = gtk_button_new_from_stock (GTK_STOCK_GOTO_BOTTOM);
gtk_widget_show (bottom_btn);
gtk_box_pack_start (GTK_BOX (btn_vbox), bottom_btn, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT (bottom_btn), "clicked",
G_CALLBACK(prefs_filtering_bottom), NULL);
+ CLAWS_SET_TIP(bottom_btn,
+ _("Move the selected rule to the bottom"));
if (!geometry.min_height) {
geometry.min_width = 500;
- geometry.min_height = 400;
+ geometry.min_height = 460;
}
gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
gint oldpathlen;
GSList * action_cur;
GSList * cur;
-
+ const gchar *separator=G_DIR_SEPARATOR_S;
+ gboolean matched = FALSE;
+#ifdef G_OS_WIN32
+again:
+#endif
oldpathlen = strlen(old_path);
- old_path_with_sep = g_strconcat(old_path,G_DIR_SEPARATOR_S,NULL);
+ old_path_with_sep = g_strconcat(old_path,separator,NULL);
for (cur = filters; cur != NULL; cur = cur->next) {
FilteringProp *filtering = (FilteringProp *)cur->data;
while (*base == G_DIR_SEPARATOR) base++;
if (*base == '\0')
dest_path = g_strconcat(prefix,
- G_DIR_SEPARATOR_S,
+ separator,
new_path, NULL);
else
dest_path = g_strconcat(prefix,
- G_DIR_SEPARATOR_S,
+ separator,
new_path,
- G_DIR_SEPARATOR_S,
+ separator,
base, NULL);
g_free(prefix);
g_free(action->destination);
action->destination = dest_path;
+ matched = TRUE;
} else { /* for non-leaf folders */
/* compare with trailing slash */
if (!strncmp(old_path_with_sep, action->destination, oldpathlen+1)) {
suffix = action->destination + oldpathlen + 1;
dest_path = g_strconcat(new_path,
- G_DIR_SEPARATOR_S,
+ separator,
suffix, NULL);
g_free(action->destination);
action->destination = dest_path;
+ matched = TRUE;
}
}
} else {
dest_path = g_strdup(new_path);
g_free(action->destination);
action->destination = dest_path;
+ matched = TRUE;
}
}
}
}
+
+ g_free(old_path_with_sep);
+#ifdef G_OS_WIN32
+ if (!strcmp(separator, G_DIR_SEPARATOR_S) && !matched) {
+ separator = "/";
+ goto again;
+ }
+#endif
}
static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data)
old_path = paths[0];
new_path = paths[1];
- g_return_val_if_fail(old_path != NULL, FALSE);
- g_return_val_if_fail(new_path != NULL, FALSE);
- g_return_val_if_fail(node != NULL, FALSE);
+ cm_return_val_if_fail(old_path != NULL, FALSE);
+ cm_return_val_if_fail(new_path != NULL, FALSE);
+ cm_return_val_if_fail(node != NULL, FALSE);
item = node->data;
if (!item || !item->prefs)
old_tag = tags[0];
new_tag = tags[1];
- g_return_val_if_fail(old_tag != NULL, FALSE);
- g_return_val_if_fail(new_tag != NULL, FALSE);
- g_return_val_if_fail(node != NULL, FALSE);
+ cm_return_val_if_fail(old_tag != NULL, FALSE);
+ cm_return_val_if_fail(new_tag != NULL, FALSE);
+ cm_return_val_if_fail(node != NULL, FALSE);
item = node->data;
if (!item || !item->prefs)
FolderItem *item;
GSList ** p_filters;
- g_return_val_if_fail(path != NULL, FALSE);
- g_return_val_if_fail(node != NULL, FALSE);
+ cm_return_val_if_fail(path != NULL, FALSE);
+ cm_return_val_if_fail(node != NULL, FALSE);
item = node->data;
if (!item || !item->prefs)
return FALSE;
}
-static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
+static void prefs_filtering_clear_list(GtkListStore *list_store)
{
- GtkTreeView *list_view = GTK_TREE_VIEW(filtering.cond_list_view);
- GSList *cur;
- GSList * prefs_filtering;
- gchar *cond_str;
- GtkListStore *list_store;
-
- list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
gtk_list_store_clear(list_store);
/* add the place holder (New) at row 0 */
_("(New)"),
_("(New)"),
FALSE);
+}
+
+static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
+{
+ GtkTreeView *list_view = GTK_TREE_VIEW(filtering.cond_list_view);
+ GSList *cur;
+ GSList * prefs_filtering;
+ gchar *cond_str;
+ GtkListStore *list_store;
+
+ list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
+ prefs_filtering_clear_list(list_store);
prefs_filtering = *p_processing_list;
gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), "");
}
+static gboolean prefs_filtering_search_func_cb (GtkTreeModel *model, gint column, const gchar *key,
+ GtkTreeIter *iter, gpointer search_data)
+{
+ gchar *store_string;
+ gboolean retval;
+ GtkTreePath *path;
+
+ gtk_tree_model_get (model, iter, column, &store_string, -1);
+
+ if (!store_string || !key) return FALSE;
+
+
+ retval = (strncmp (key, store_string, strlen(key)) != 0);
+
+ g_free(store_string);
+ debug_print("selecting row\n");
+ path = gtk_tree_model_get_path(model, iter);
+ prefs_filtering_select_row(GTK_TREE_VIEW(filtering.cond_list_view), path);
+ gtk_tree_path_free(path);
+
+ return retval;
+}
+
static void prefs_filtering_set_list(void)
{
gint row = 1;
static gint prefs_filtering_list_view_set_row(gint row, FilteringProp * prop)
{
GtkTreeView *list_view = GTK_TREE_VIEW(filtering.cond_list_view);
- gchar *str;
+ gchar *str = NULL;
GtkListStore *list_store;
gchar *name = NULL;
gint account_id = 0;
gchar *account_name = (gchar *)Q_("Filtering Account Menu|All");
gboolean enabled = TRUE;
- str = filteringprop_to_string(prop);
+ if (prop)
+ str = filteringprop_to_string(prop);
if (str == NULL)
return -1;
}
}
-static void prefs_filtering_condition_define(void)
+static void prefs_filtering_condition_define(gpointer action, gpointer data)
{
gchar * cond_str;
MatcherList * matchers = NULL;
}
}
-static void prefs_filtering_action_define(void)
+static void prefs_filtering_action_define(gpointer action, gpointer data)
{
gchar * action_str;
GSList * action_list = NULL;
return prop;
}
-static void prefs_filtering_register_cb(void)
+static void prefs_filtering_register_cb(gpointer action, gpointer data)
{
- FilteringProp * prop;
+ FilteringProp *prop;
prop = prefs_filtering_dialog_to_filtering(TRUE);
if (prop == NULL)
modified = TRUE;
}
-static void prefs_filtering_substitute_cb(void)
+static void prefs_filtering_substitute_cb(gpointer action, gpointer data)
{
gint selected_row = gtkut_list_view_get_selected_row
(filtering.cond_list_view);
modified = TRUE;
}
-static void prefs_filtering_delete_cb(void)
+static void prefs_filtering_delete_cb(gpointer action, gpointer data)
{
GtkTreeView *list_view = GTK_TREE_VIEW(filtering.cond_list_view);
GtkTreeModel *model;
GtkTreeIter iter;
- gint row;
+ gint selected_row;
- row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
- if (row <= 0)
+ selected_row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
+ if (selected_row <= 0)
return;
if (alertpanel(_("Delete rule"),
return;
model = gtk_tree_view_get_model(list_view);
- if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
+ if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, selected_row))
return;
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
modified = TRUE;
}
-static void prefs_filtering_top(void)
+static void prefs_filtering_delete_all_cb(gpointer action, gpointer data)
+{
+ GtkListStore *list_store;
+
+ if (alertpanel(_("Delete all rules"),
+ _("Do you really want to delete all the rules?"),
+ GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL) == G_ALERTDEFAULT)
+ return;
+
+ list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view)));
+ prefs_filtering_clear_list(list_store);
+
+ prefs_filtering_reset_dialog();
+ modified = TRUE;
+}
+
+static void prefs_filtering_clear_cb(gpointer action, gpointer data)
+{
+ prefs_filtering_reset_dialog();
+}
+
+static void prefs_filtering_duplicate_cb(gpointer action, gpointer data)
+{
+ gint selected_row = gtkut_list_view_get_selected_row
+ (filtering.cond_list_view);
+ FilteringProp *prop;
+ gboolean enabled;
+ gchar *name;
+ gint account_id;
+
+ if (selected_row <= 0)
+ return;
+
+ prop = prefs_filtering_dialog_to_filtering(TRUE);
+ if (prop == NULL)
+ return;
+
+ /* prop->emabled is always TRUE here, re-use the value from the selected row
+ as we don't substitute this value from dialog */
+ prefs_filtering_list_view_get_rule_info(
+ filtering.cond_list_view, selected_row,
+ &enabled, &name, &account_id);
+ prop->enabled = enabled;
+
+ prefs_filtering_list_view_set_row(-selected_row-2, prop);
+
+ filteringprop_free(prop);
+
+ prefs_filtering_reset_dialog();
+ modified = TRUE;
+}
+
+static void prefs_filtering_top(gpointer action, gpointer data)
{
gint row;
GtkTreeIter top, sel;
modified = TRUE;
}
-static void prefs_filtering_up(void)
+static void prefs_filtering_page_up(gpointer action, gpointer data)
+{
+ gint row, target_row, n_rows;
+ GtkTreeIter selected, target;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GdkRectangle cell_rect, view_rect;
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
+ n_rows = gtk_tree_model_iter_n_children(model, NULL);
+ row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
+ if (row <= 1)
+ return;
+
+ if (!gtk_tree_model_iter_nth_child(model, &selected, NULL, row))
+ return;
+
+ /* compute number of rows per page (approximation) */
+ path = gtk_tree_model_get_path(model, &selected);
+ gtk_tree_view_get_cell_area(GTK_TREE_VIEW(filtering.cond_list_view), path, NULL, &cell_rect);
+ gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(filtering.cond_list_view), &view_rect);
+ gtk_tree_path_free(path);
+ target_row = row - (view_rect.height/cell_rect.height);
+ if (target_row < 1)
+ target_row = 1;
+
+ if (!gtk_tree_model_iter_nth_child(model, &target, NULL, target_row))
+ return;
+ gtk_list_store_move_before(GTK_LIST_STORE(model), &selected, &target);
+ gtkut_list_view_select_row(filtering.cond_list_view, target_row);
+ modified = TRUE;
+}
+static void prefs_filtering_up(gpointer action, gpointer data)
{
gint row;
GtkTreeIter top, sel;
modified = TRUE;
}
-static void prefs_filtering_down(void)
+static void prefs_filtering_down(gpointer action, gpointer data)
{
gint row, n_rows;
GtkTreeIter top, sel;
modified = TRUE;
}
-static void prefs_filtering_bottom(void)
+static void prefs_filtering_page_down(gpointer action, gpointer data)
+{
+ gint row, target_row, n_rows;
+ GtkTreeIter selected, target;
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GdkRectangle cell_rect, view_rect;
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(filtering.cond_list_view));
+ n_rows = gtk_tree_model_iter_n_children(model, NULL);
+ row = gtkut_list_view_get_selected_row(filtering.cond_list_view);
+ if (row < 1 || row >= n_rows -1)
+ return;
+
+ if (!gtk_tree_model_iter_nth_child(model, &selected, NULL, row))
+ return;
+
+ /* compute number of rows per page (approximation) */
+ path = gtk_tree_model_get_path(model, &selected);
+ gtk_tree_view_get_cell_area(GTK_TREE_VIEW(filtering.cond_list_view), path, NULL, &cell_rect);
+ gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(filtering.cond_list_view), &view_rect);
+ gtk_tree_path_free(path);
+ target_row = row + (view_rect.height/cell_rect.height);
+ if (target_row > n_rows-1)
+ target_row = n_rows-1;
+
+ if (!gtk_tree_model_iter_nth_child(model, &target, NULL, target_row))
+ return;
+ gtk_list_store_move_after(GTK_LIST_STORE(model), &selected, &target);
+ gtkut_list_view_select_row(filtering.cond_list_view, target_row);
+ modified = TRUE;
+}
+
+static void prefs_filtering_bottom(gpointer action, gpointer data)
{
gint row, n_rows;
GtkTreeIter top, sel;
static gint prefs_filtering_deleted(GtkWidget *widget, GdkEventAny *event,
gpointer data)
{
- prefs_filtering_cancel();
+ prefs_filtering_cancel(NULL, NULL);
return TRUE;
}
gpointer data)
{
if (event && event->keyval == GDK_Escape) {
- prefs_filtering_cancel();
+ prefs_filtering_cancel(NULL, NULL);
return TRUE;
}
return FALSE;
return FALSE;
}
-static void prefs_filtering_ok(void)
+static void prefs_filtering_ok(gpointer action, gpointer data)
{
if (prefs_filtering_check_mod(FALSE))
return;
prefs_filtering_close();
}
-static void prefs_filtering_cancel(void)
+static void prefs_filtering_cancel(gpointer action, gpointer data)
{
if (prefs_filtering_check_mod(TRUE))
return;
* at least it made GTK 2 porting easier.
*
*\param list_store Store to operate on
- *\param row -1 to add a new rule to store, else change an existing
- * row
+ *\param row -1 to add a new rule to store,
+ row >=0 to change an existing row
+ row <-1 insert a new row after (-row-2)
*\param enabled TRUE if rule is enabled
*\param name The Name of rule
*\param account_id The account ID
gboolean prop)
{
GtkTreeIter iter;
+ GtkTreeIter sibling;
/* check if valid row at all */
if (row >= 0) {
if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store),
&iter, NULL, row))
+ row = -1;
+ } else if (row < -1) {
+ if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(list_store),
+ &sibling, NULL, -row-2))
row = -1;
}
- if (row < 0) {
+ if (row == -1 ) {
/* append new */
gtk_list_store_append(list_store, &iter);
gtk_list_store_set(list_store, &iter,
-1);
return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store),
NULL) - 1;
+ } else if (row < -1) {
+ /* duplicate */
+ gtk_list_store_insert_after(list_store, &iter, &sibling);
+ gtk_list_store_set(list_store, &iter,
+ PREFS_FILTERING_ENABLED, enabled,
+ PREFS_FILTERING_NAME, name,
+ PREFS_FILTERING_ACCOUNT_ID, account_id,
+ PREFS_FILTERING_ACCOUNT_NAME, account_name,
+ PREFS_FILTERING_RULE, rule,
+ PREFS_FILTERING_PROP, prop,
+ -1);
+ return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store),
+ NULL) - 1;
} else {
/* change existing */
gtk_list_store_set(list_store, &iter,
}
}
+static GtkActionGroup *prefs_filtering_popup_action = NULL;
+static GtkWidget *prefs_filtering_popup_menu = NULL;
+
+static GtkActionEntry prefs_filtering_popup_entries[] =
+{
+ {"PrefsFilteringPopup", NULL, "PrefsFilteringPopup" },
+ {"PrefsFilteringPopup/Delete", NULL, N_("_Delete"), NULL, NULL, G_CALLBACK(prefs_filtering_delete_cb) },
+ {"PrefsFilteringPopup/DeleteAll", NULL, N_("Delete _all"), NULL, NULL, G_CALLBACK(prefs_filtering_delete_all_cb) },
+ {"PrefsFilteringPopup/Duplicate", NULL, N_("D_uplicate"), NULL, NULL, G_CALLBACK(prefs_filtering_duplicate_cb) },
+#ifdef GENERIC_UMPC
+ {"PrefsFilteringPopup/---", NULL, "---", NULL, NULL, NULL },
+ {"PrefsFilteringPopup/PageUp", NULL, N_("Move one page up"), NULL, NULL, G_CALLBACK(prefs_filtering_page_up) },
+ {"PrefsFilteringPopup/PageDown", NULL, N_("Move one page down"), NULL, NULL, G_CALLBACK(prefs_filtering_page_down) },
+#endif
+};
+
+static gint prefs_filtering_list_btn_pressed(GtkWidget *widget, GdkEventButton *event,
+ GtkTreeView *list_view)
+{
+ if (event) {
+ /* left- or right-button click */
+ if (event->button == 1 || event->button == 3) {
+ GtkTreePath *path = NULL;
+
+ if (gtk_tree_view_get_path_at_pos( list_view, event->x, event->y,
+ &path, NULL, NULL, NULL)) {
+ prefs_filtering_select_row(list_view, path);
+ }
+ if (path)
+ gtk_tree_path_free(path);
+ }
+
+ /* right-button click */
+ if (event->button == 3) {
+ GtkTreeModel *model = gtk_tree_view_get_model(list_view);
+ GtkTreeIter iter;
+ gboolean non_empty;
+ gint row;
+
+ if (!prefs_filtering_popup_menu) {
+ prefs_filtering_popup_action = cm_menu_create_action_group("PrefsFilteringPopup", prefs_filtering_popup_entries,
+ G_N_ELEMENTS(prefs_filtering_popup_entries), (gpointer)list_view);
+ MENUITEM_ADDUI("/Menus", "PrefsFilteringPopup", "PrefsFilteringPopup", GTK_UI_MANAGER_MENU)
+ MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "Delete", "PrefsFilteringPopup/Delete", GTK_UI_MANAGER_MENUITEM)
+ MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "DeleteAll", "PrefsFilteringPopup/DeleteAll", GTK_UI_MANAGER_MENUITEM)
+ MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "Duplicate", "PrefsFilteringPopup/Duplicate", GTK_UI_MANAGER_MENUITEM)
+#ifdef GENERIC_UMPC
+ MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "Separator1", "PrefsFilteringPopup/---", GTK_UI_MANAGER_SEPARATOR)
+ MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "PageUp", "PrefsFilteringPopup/PageUp", GTK_UI_MANAGER_MENUITEM)
+ MENUITEM_ADDUI("/Menus/PrefsFilteringPopup", "PageDown", "PrefsFilteringPopup/PageDown", GTK_UI_MANAGER_MENUITEM)
+#endif
+ prefs_filtering_popup_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
+ gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/PrefsFilteringPopup")) );
+ }
+
+ /* grey out some popup menu items if there is no selected row */
+ row = gtkut_list_view_get_selected_row(GTK_WIDGET(list_view));
+ cm_menu_set_sensitive("PrefsFilteringPopup/Delete", (row > 0));
+ cm_menu_set_sensitive("PrefsFilteringPopup/Duplicate", (row > 0));
+
+ /* grey out seom popup menu items if there is no row
+ (not counting the (New) one at row 0) */
+ non_empty = gtk_tree_model_get_iter_first(model, &iter);
+ if (non_empty)
+ non_empty = gtk_tree_model_iter_next(model, &iter);
+ cm_menu_set_sensitive("PrefsFilteringPopup/DeleteAll", non_empty);
+
+ gtk_menu_popup(GTK_MENU(prefs_filtering_popup_menu),
+ NULL, NULL, NULL, NULL,
+ event->button, event->time);
+ }
+ }
+ return FALSE;
+}
+
+static gboolean prefs_filtering_list_popup_menu(GtkWidget *widget, gpointer data)
+{
+ GtkTreeView *list_view = (GtkTreeView *)data;
+ GdkEventButton event;
+
+ event.button = 3;
+ event.time = gtk_get_current_event_time();
+
+ prefs_filtering_list_btn_pressed(NULL, &event, list_view);
+
+ return TRUE;
+}
+
/*!
*\brief Create list view for filtering
*/
list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL
(prefs_filtering_create_data_store())));
+#ifdef GENERIC_UMPC
+ g_object_set(list_view, "allow-checkbox-mode", FALSE, NULL);
+#endif
+
+#ifndef MAEMO
+ g_signal_connect(G_OBJECT(list_view), "popup-menu",
+ G_CALLBACK(prefs_filtering_list_popup_menu), list_view);
+#else
+ gtk_widget_tap_and_hold_setup(GTK_WIDGET(list_view), NULL, NULL,
+ GTK_TAP_AND_HOLD_NONE | GTK_TAP_AND_HOLD_NO_INTERNALS);
+ g_signal_connect(G_OBJECT(list_view), "tap-and-hold",
+ G_CALLBACK(prefs_filtering_list_popup_menu), list_view);
+#endif
+ g_signal_connect(G_OBJECT(list_view), "button-press-event",
+ G_CALLBACK(prefs_filtering_list_btn_pressed), list_view);
gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
gtk_tree_view_set_reorderable(list_view, TRUE);
selector = gtk_tree_view_get_selection(list_view);
gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
- gtk_tree_selection_set_select_function(selector, prefs_filtering_selected,
- NULL, NULL);
/* create the columns */
prefs_filtering_create_list_view_columns(GTK_WIDGET(list_view));
renderer,
"text", PREFS_FILTERING_RULE,
NULL);
+
+ gtk_tree_view_set_search_column(GTK_TREE_VIEW(list_view), PREFS_FILTERING_NAME);
+ gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(list_view), prefs_filtering_search_func_cb , NULL, NULL);
+
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
}
/*!
- *\brief Triggered when a row is selected
+ *\brief Triggered when a row has to be selected
*/
-static gboolean prefs_filtering_selected(GtkTreeSelection *selector,
- GtkTreeModel *model,
- GtkTreePath *path,
- gboolean currently_selected,
- gpointer data)
+static void prefs_filtering_select_row(GtkTreeView *list_view, GtkTreePath *path)
{
- if (currently_selected)
- return TRUE;
- else {
- gboolean has_prop = FALSE;
+ GtkTreeModel *model = gtk_tree_view_get_model(list_view);
+
+ if (path && model) {
+ GtkTreeSelection *selection;
+ gboolean has_prop = FALSE;
GtkTreeIter iter;
+ /* select row */
+ selection = gtk_tree_view_get_selection(list_view);
+ gtk_tree_selection_select_path(selection, path);
+
+ /* update dialog from selection */
gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_model_get(model, &iter,
PREFS_FILTERING_PROP, &has_prop,
g_free(filtering_str);
} else
prefs_filtering_reset_dialog();
- }
-
- return TRUE;
+ }
}
-