2001-04-19 14:21:46 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2007-01-03 06:42:43 +01:00
|
|
|
* Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
|
2001-04-19 14:21:46 +02:00
|
|
|
*
|
|
|
|
* 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
|
2007-07-11 18:38:12 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-04-19 14:21:46 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-11 18:38:12 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2001-04-19 14:21:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gtk/gtkmain.h>
|
|
|
|
#include <gtk/gtkwidget.h>
|
2005-03-31 08:35:45 +02:00
|
|
|
#include <gtk/gtktreestore.h>
|
|
|
|
#include <gtk/gtktreeview.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
#include <gtk/gtkwindow.h>
|
|
|
|
#include <gtk/gtkvbox.h>
|
|
|
|
#include <gtk/gtkscrolledwindow.h>
|
|
|
|
#include <gtk/gtkentry.h>
|
|
|
|
#include <gtk/gtkhbbox.h>
|
|
|
|
#include <gtk/gtksignal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "gtkutils.h"
|
2001-12-22 01:30:32 +01:00
|
|
|
#include "stock_pixmap.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#include "foldersel.h"
|
|
|
|
#include "alertpanel.h"
|
|
|
|
#include "manage_window.h"
|
2005-03-31 08:35:45 +02:00
|
|
|
#include "folderview.h"
|
|
|
|
#include "inputdialog.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#include "folder.h"
|
2005-05-31 09:04:59 +02:00
|
|
|
#include "prefs_common.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-12-30 10:15:35 +01:00
|
|
|
enum {
|
|
|
|
FOLDERSEL_FOLDERNAME,
|
|
|
|
FOLDERSEL_FOLDERITEM,
|
2005-03-31 08:35:45 +02:00
|
|
|
FOLDERSEL_PIXBUF,
|
|
|
|
FOLDERSEL_PIXBUF_OPEN,
|
2005-07-14 12:17:54 +02:00
|
|
|
FOLDERSEL_FOREGROUND,
|
|
|
|
FOLDERSEL_BOLD,
|
2004-12-30 10:15:35 +01:00
|
|
|
N_FOLDERSEL_COLUMNS
|
|
|
|
};
|
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
typedef struct _FolderItemSearch FolderItemSearch;
|
|
|
|
|
|
|
|
struct _FolderItemSearch
|
|
|
|
{
|
|
|
|
FolderItem *item;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
};
|
|
|
|
|
2004-12-30 10:15:35 +01:00
|
|
|
static GdkPixbuf *folder_pixbuf;
|
|
|
|
static GdkPixbuf *folderopen_pixbuf;
|
2005-03-31 08:35:45 +02:00
|
|
|
static GdkPixbuf *foldernoselect_pixbuf;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
static GtkWidget *window;
|
2005-03-31 08:35:45 +02:00
|
|
|
static GtkWidget *treeview;
|
2001-04-19 14:21:46 +02:00
|
|
|
static GtkWidget *entry;
|
|
|
|
static GtkWidget *ok_button;
|
|
|
|
static GtkWidget *cancel_button;
|
2005-03-31 08:35:45 +02:00
|
|
|
static GtkWidget *new_button;
|
2008-02-12 11:44:26 +01:00
|
|
|
static gboolean root_selectable;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
static FolderItem *folder_item;
|
2004-05-10 12:22:28 +02:00
|
|
|
static FolderItem *selected_item;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-12-30 10:15:35 +01:00
|
|
|
static GtkTreeStore *tree_store;
|
2002-02-07 11:14:25 +01:00
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
static gboolean cancelled;
|
|
|
|
static gboolean finished;
|
2004-12-30 10:15:35 +01:00
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
static void foldersel_create (void);
|
|
|
|
static void foldersel_init (void);
|
|
|
|
|
|
|
|
static void foldersel_append_item (GtkTreeStore *store,
|
|
|
|
FolderItem *item,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent);
|
|
|
|
|
|
|
|
static void foldersel_set_tree (Folder *cur_folder,
|
|
|
|
FolderSelectionType type);
|
|
|
|
|
|
|
|
static gboolean foldersel_selected (GtkTreeSelection *selection,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gboolean currently_selected,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void foldersel_ok (GtkButton *button,
|
|
|
|
gpointer data);
|
|
|
|
static void foldersel_cancel (GtkButton *button,
|
|
|
|
gpointer data);
|
|
|
|
static void foldersel_new_folder (GtkButton *button,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void foldersel_entry_activated (GtkEntry *entry,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void foldersel_tree_activated (GtkTreeView *treeview,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static gint delete_event (GtkWidget *widget,
|
|
|
|
GdkEventAny *event,
|
|
|
|
gpointer data);
|
|
|
|
static gboolean key_pressed (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static gint foldersel_folder_name_compare (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *a,
|
|
|
|
GtkTreeIter *b,
|
|
|
|
gpointer context);
|
|
|
|
|
|
|
|
static gboolean tree_view_folder_item_func (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
FolderItemSearch *data);
|
2004-12-30 10:15:35 +01:00
|
|
|
|
|
|
|
FolderItem *foldersel_folder_sel(Folder *cur_folder, FolderSelectionType type,
|
2008-02-12 11:44:26 +01:00
|
|
|
const gchar *default_folder, gboolean can_sel_mailbox)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2004-05-10 12:22:28 +02:00
|
|
|
selected_item = NULL;
|
2008-02-12 11:44:26 +01:00
|
|
|
root_selectable = can_sel_mailbox;
|
2004-05-10 12:22:28 +02:00
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
if (!window) {
|
2001-04-19 14:21:46 +02:00
|
|
|
foldersel_create();
|
2005-03-31 08:35:45 +02:00
|
|
|
foldersel_init();
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
foldersel_set_tree(cur_folder, type);
|
2004-12-30 10:15:35 +01:00
|
|
|
|
|
|
|
/* select current */
|
2001-04-19 14:21:46 +02:00
|
|
|
if (folder_item) {
|
2004-12-30 10:15:35 +01:00
|
|
|
FolderItemSearch fis;
|
|
|
|
|
|
|
|
fis.item = folder_item;
|
|
|
|
fis.path = NULL;
|
|
|
|
|
|
|
|
/* find matching model entry */
|
|
|
|
gtk_tree_model_foreach
|
2005-03-31 08:35:45 +02:00
|
|
|
(GTK_TREE_MODEL(tree_store),
|
2004-12-30 10:15:35 +01:00
|
|
|
(GtkTreeModelForeachFunc)tree_view_folder_item_func,
|
2005-03-31 08:35:45 +02:00
|
|
|
&fis);
|
|
|
|
|
2004-12-30 10:15:35 +01:00
|
|
|
if (fis.path) {
|
2005-03-31 08:35:45 +02:00
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection
|
|
|
|
(GTK_TREE_VIEW(treeview));
|
|
|
|
gtk_tree_selection_select_iter(selection, &fis.iter);
|
|
|
|
gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview),
|
|
|
|
fis.path, NULL, FALSE);
|
|
|
|
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview),
|
|
|
|
fis.path,
|
|
|
|
NULL, TRUE, 0.5, 0.0);
|
|
|
|
gtk_tree_path_free(fis.path);
|
|
|
|
} else
|
|
|
|
gtk_tree_view_scroll_to_point
|
|
|
|
(GTK_TREE_VIEW(treeview), 0, 0);
|
|
|
|
} else
|
|
|
|
gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(treeview), 0, 0);
|
|
|
|
|
|
|
|
gtk_widget_grab_focus(ok_button);
|
|
|
|
gtk_widget_grab_focus(treeview);
|
|
|
|
|
|
|
|
gtk_widget_show(window);
|
|
|
|
manage_window_set_transient(GTK_WINDOW(window));
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-06-06 10:12:43 +02:00
|
|
|
cancelled = finished = FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-06-06 10:12:43 +02:00
|
|
|
while (finished == FALSE)
|
|
|
|
gtk_main_iteration();
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
gtk_widget_hide(window);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), "");
|
2005-03-31 08:35:45 +02:00
|
|
|
gtk_tree_store_clear(tree_store);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
if (!cancelled &&
|
2008-02-12 11:44:26 +01:00
|
|
|
selected_item && (selected_item->path || root_selectable)) {
|
2004-05-10 12:22:28 +02:00
|
|
|
folder_item = selected_item;
|
2001-04-19 14:21:46 +02:00
|
|
|
return folder_item;
|
2004-05-10 12:22:28 +02:00
|
|
|
} else
|
2001-04-19 14:21:46 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-09 11:36:18 +01:00
|
|
|
static void foldersel_size_allocate_cb(GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
g_return_if_fail(allocation != NULL);
|
|
|
|
|
|
|
|
prefs_common.folderselwin_width = allocation->width;
|
|
|
|
prefs_common.folderselwin_height = allocation->height;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static void foldersel_create(void)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *scrolledwin;
|
|
|
|
GtkWidget *confirm_area;
|
2004-12-30 10:15:35 +01:00
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkCellRenderer *renderer;
|
2005-03-31 08:35:45 +02:00
|
|
|
GtkTreeSelection *selection;
|
2006-03-09 11:36:18 +01:00
|
|
|
static GdkGeometry geometry;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2007-02-04 12:51:29 +01:00
|
|
|
window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "foldersel");
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_window_set_title(GTK_WINDOW(window), _("Select folder"));
|
2004-05-10 12:22:28 +02:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(window), 4);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
|
|
|
|
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
|
2006-08-29 08:16:20 +02:00
|
|
|
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
|
2007-02-04 12:51:29 +01:00
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
gtk_widget_realize(window);
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(window), "delete_event",
|
|
|
|
G_CALLBACK(delete_event), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(window), "key_press_event",
|
|
|
|
G_CALLBACK(key_pressed), NULL);
|
2006-03-09 11:36:18 +01:00
|
|
|
g_signal_connect(G_OBJECT(window), "size_allocate",
|
|
|
|
G_CALLBACK(foldersel_size_allocate_cb), NULL);
|
2002-02-23 11:52:54 +01:00
|
|
|
MANAGE_WINDOW_SIGNALS_CONNECT(window);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
vbox = gtk_vbox_new(FALSE, 4);
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), vbox);
|
|
|
|
|
|
|
|
scrolledwin = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
|
2005-03-31 08:35:45 +02:00
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
|
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
|
|
|
|
GTK_SHADOW_IN);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
|
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
tree_store = gtk_tree_store_new(N_FOLDERSEL_COLUMNS,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_POINTER,
|
|
|
|
GDK_TYPE_PIXBUF,
|
|
|
|
GDK_TYPE_PIXBUF,
|
2005-07-14 12:17:54 +02:00
|
|
|
GDK_TYPE_COLOR,
|
2006-05-26 13:24:19 +02:00
|
|
|
G_TYPE_INT);
|
2005-03-31 08:35:45 +02:00
|
|
|
gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(tree_store),
|
|
|
|
FOLDERSEL_FOLDERNAME,
|
|
|
|
foldersel_folder_name_compare,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
|
|
|
|
g_object_unref(G_OBJECT(tree_store));
|
|
|
|
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
|
2005-05-31 09:04:59 +02:00
|
|
|
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview),
|
2006-09-06 11:14:40 +02:00
|
|
|
prefs_common.use_stripes_everywhere);
|
2008-06-13 08:08:31 +02:00
|
|
|
gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(treeview),
|
|
|
|
prefs_common.enable_dotted_lines);
|
2005-03-31 08:35:45 +02:00
|
|
|
gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview),
|
|
|
|
FOLDERSEL_FOLDERNAME);
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
|
|
|
|
gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
|
|
|
|
gtk_tree_selection_set_select_function(selection, foldersel_selected,
|
2004-12-30 10:15:35 +01:00
|
|
|
NULL, NULL);
|
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
g_signal_connect(G_OBJECT(treeview), "row-activated",
|
|
|
|
G_CALLBACK(foldersel_tree_activated), NULL);
|
|
|
|
gtk_container_add(GTK_CONTAINER(scrolledwin), treeview);
|
2004-12-30 10:15:35 +01:00
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
column = gtk_tree_view_column_new();
|
|
|
|
gtk_tree_view_column_set_spacing(column, 2);
|
2004-12-30 10:15:35 +01:00
|
|
|
renderer = gtk_cell_renderer_pixbuf_new();
|
|
|
|
gtk_tree_view_column_pack_start(column, renderer, FALSE);
|
2005-03-31 08:35:45 +02:00
|
|
|
gtk_tree_view_column_set_attributes
|
|
|
|
(column, renderer,
|
|
|
|
"pixbuf", FOLDERSEL_PIXBUF,
|
|
|
|
"pixbuf-expander-open", FOLDERSEL_PIXBUF_OPEN,
|
|
|
|
"pixbuf-expander-closed", FOLDERSEL_PIXBUF,
|
|
|
|
NULL);
|
2004-12-30 10:15:35 +01:00
|
|
|
|
|
|
|
/* create text renderer */
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
gtk_tree_view_column_pack_start(column, renderer, TRUE);
|
2005-07-14 12:17:54 +02:00
|
|
|
gtk_tree_view_column_set_attributes
|
|
|
|
(column, renderer,
|
|
|
|
"text", FOLDERSEL_FOLDERNAME,
|
|
|
|
"foreground-gdk", FOLDERSEL_FOREGROUND,
|
2006-05-26 13:24:19 +02:00
|
|
|
"weight", FOLDERSEL_BOLD,
|
2005-07-14 12:17:54 +02:00
|
|
|
NULL);
|
|
|
|
g_object_set(G_OBJECT(renderer), "weight", PANGO_WEIGHT_BOLD, NULL);
|
2005-04-06 10:46:10 +02:00
|
|
|
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
2005-03-31 08:35:45 +02:00
|
|
|
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
entry = gtk_entry_new();
|
2004-05-10 12:22:28 +02:00
|
|
|
gtk_entry_set_editable(GTK_ENTRY(entry), FALSE);
|
2001-04-19 14:21:46 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(entry), "activate",
|
2005-03-31 08:35:45 +02:00
|
|
|
G_CALLBACK(foldersel_entry_activated), NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-01-29 17:53:23 +01:00
|
|
|
gtkut_stock_button_set_create(&confirm_area,
|
2005-12-12 11:07:30 +01:00
|
|
|
&new_button, GTK_STOCK_NEW,
|
2006-01-14 13:18:38 +01:00
|
|
|
&cancel_button, GTK_STOCK_CANCEL,
|
|
|
|
&ok_button, GTK_STOCK_OK);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_grab_default(ok_button);
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
g_signal_connect(G_OBJECT(ok_button), "clicked",
|
|
|
|
G_CALLBACK(foldersel_ok), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(cancel_button), "clicked",
|
|
|
|
G_CALLBACK(foldersel_cancel), NULL);
|
2005-03-31 08:35:45 +02:00
|
|
|
g_signal_connect(G_OBJECT(new_button), "clicked",
|
|
|
|
G_CALLBACK(foldersel_new_folder), NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2006-03-09 11:36:18 +01:00
|
|
|
if (!geometry.min_height) {
|
|
|
|
geometry.min_width = 300;
|
|
|
|
geometry.min_height = 360;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
|
|
|
|
GDK_HINT_MIN_SIZE);
|
|
|
|
gtk_widget_set_size_request(window, prefs_common.folderselwin_width,
|
|
|
|
prefs_common.folderselwin_height);
|
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
gtk_widget_show_all(vbox);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
static void foldersel_init(void)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2005-03-31 08:35:45 +02:00
|
|
|
stock_pixbuf_gdk(treeview, STOCK_PIXMAP_DIR_CLOSE,
|
2005-01-05 22:41:32 +01:00
|
|
|
&folder_pixbuf);
|
2005-03-31 08:35:45 +02:00
|
|
|
stock_pixbuf_gdk(treeview, STOCK_PIXMAP_DIR_OPEN,
|
2005-01-05 22:41:32 +01:00
|
|
|
&folderopen_pixbuf);
|
2005-03-31 08:35:45 +02:00
|
|
|
stock_pixbuf_gdk(treeview, STOCK_PIXMAP_DIR_NOSELECT,
|
|
|
|
&foldernoselect_pixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foldersel_append_item(GtkTreeStore *store, FolderItem *item,
|
|
|
|
GtkTreeIter *iter, GtkTreeIter *parent)
|
|
|
|
{
|
|
|
|
gchar *name, *tmpname;
|
|
|
|
GdkPixbuf *pixbuf, *pixbuf_open;
|
2006-05-26 13:24:19 +02:00
|
|
|
gboolean use_color;
|
|
|
|
PangoWeight weight = PANGO_WEIGHT_NORMAL;
|
2005-07-14 12:17:54 +02:00
|
|
|
GdkColor *foreground = NULL;
|
|
|
|
static GdkColor color_noselect = {0, COLOR_DIM, COLOR_DIM, COLOR_DIM};
|
|
|
|
static GdkColor color_new;
|
|
|
|
|
|
|
|
gtkut_convert_int_to_gdk_color(prefs_common.color_new, &color_new);
|
2005-03-31 08:35:45 +02:00
|
|
|
|
|
|
|
name = tmpname = folder_item_get_name(item);
|
|
|
|
|
|
|
|
if (item->stype != F_NORMAL && FOLDER_IS_LOCAL(item->folder)) {
|
|
|
|
switch (item->stype) {
|
|
|
|
case F_INBOX:
|
|
|
|
if (!strcmp2(item->name, INBOX_DIR))
|
|
|
|
name = _("Inbox");
|
|
|
|
break;
|
|
|
|
case F_OUTBOX:
|
|
|
|
if (!strcmp2(item->name, OUTBOX_DIR))
|
|
|
|
name = _("Sent");
|
|
|
|
break;
|
|
|
|
case F_QUEUE:
|
|
|
|
if (!strcmp2(item->name, QUEUE_DIR))
|
|
|
|
name = _("Queue");
|
|
|
|
break;
|
|
|
|
case F_TRASH:
|
|
|
|
if (!strcmp2(item->name, TRASH_DIR))
|
|
|
|
name = _("Trash");
|
|
|
|
break;
|
|
|
|
case F_DRAFT:
|
|
|
|
if (!strcmp2(item->name, DRAFT_DIR))
|
|
|
|
name = _("Drafts");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-07 15:39:27 +02:00
|
|
|
if (folder_has_parent_of_type(item, F_QUEUE) && item->total_msgs > 0) {
|
2005-07-14 12:17:54 +02:00
|
|
|
name = g_strdup_printf("%s (%d)", name, item->total_msgs);
|
|
|
|
} else if (item->unread_msgs > 0) {
|
|
|
|
name = g_strdup_printf("%s (%d)", name, item->unread_msgs);
|
|
|
|
} else
|
|
|
|
name = g_strdup(name);
|
2005-03-31 08:35:45 +02:00
|
|
|
|
2005-07-14 12:17:54 +02:00
|
|
|
pixbuf = item->no_select ? foldernoselect_pixbuf : folder_pixbuf;
|
2005-03-31 08:35:45 +02:00
|
|
|
pixbuf_open =
|
2005-07-14 12:17:54 +02:00
|
|
|
item->no_select ? foldernoselect_pixbuf : folderopen_pixbuf;
|
|
|
|
|
2005-08-07 15:39:27 +02:00
|
|
|
if (folder_has_parent_of_type(item, F_DRAFT) ||
|
|
|
|
folder_has_parent_of_type(item, F_OUTBOX) ||
|
|
|
|
folder_has_parent_of_type(item, F_TRASH)) {
|
2006-05-26 13:24:19 +02:00
|
|
|
use_color = FALSE;
|
2005-08-07 15:39:27 +02:00
|
|
|
} else if (folder_has_parent_of_type(item, F_QUEUE)) {
|
2006-05-26 13:24:19 +02:00
|
|
|
use_color = (item->total_msgs > 0);
|
|
|
|
if (item->total_msgs > 0)
|
|
|
|
weight = PANGO_WEIGHT_BOLD;
|
2005-07-14 12:17:54 +02:00
|
|
|
} else {
|
2006-05-26 13:24:19 +02:00
|
|
|
if (item->unread_msgs > 0)
|
|
|
|
weight = PANGO_WEIGHT_BOLD;
|
2005-07-14 12:17:54 +02:00
|
|
|
use_color = (item->new_msgs > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->no_select)
|
|
|
|
foreground = &color_noselect;
|
|
|
|
else if (use_color)
|
|
|
|
foreground = &color_new;
|
2005-03-31 08:35:45 +02:00
|
|
|
|
|
|
|
/* insert this node */
|
2005-07-14 12:17:54 +02:00
|
|
|
gtk_tree_store_append(store, iter, parent);
|
2005-03-31 08:35:45 +02:00
|
|
|
gtk_tree_store_set(store, iter,
|
|
|
|
FOLDERSEL_FOLDERNAME, name,
|
|
|
|
FOLDERSEL_FOLDERITEM, item,
|
|
|
|
FOLDERSEL_PIXBUF, pixbuf,
|
|
|
|
FOLDERSEL_PIXBUF_OPEN, pixbuf_open,
|
2005-07-14 12:17:54 +02:00
|
|
|
FOLDERSEL_FOREGROUND, foreground,
|
2006-05-26 13:24:19 +02:00
|
|
|
FOLDERSEL_BOLD, weight,
|
2005-03-31 08:35:45 +02:00
|
|
|
-1);
|
|
|
|
|
|
|
|
g_free(tmpname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foldersel_insert_gnode_in_store(GtkTreeStore *store, GNode *node,
|
|
|
|
GtkTreeIter *parent)
|
|
|
|
{
|
|
|
|
FolderItem *item;
|
|
|
|
GtkTreeIter child;
|
|
|
|
GNode *iter;
|
|
|
|
|
|
|
|
g_return_if_fail(node != NULL);
|
|
|
|
g_return_if_fail(node->data != NULL);
|
|
|
|
g_return_if_fail(store != NULL);
|
|
|
|
|
|
|
|
item = FOLDER_ITEM(node->data);
|
|
|
|
foldersel_append_item(store, item, &child, parent);
|
|
|
|
|
|
|
|
/* insert its children (this node as parent) */
|
|
|
|
for (iter = node->children; iter != NULL; iter = iter->next)
|
|
|
|
foldersel_insert_gnode_in_store(store, iter, &child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foldersel_set_tree(Folder *cur_folder, FolderSelectionType type)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = folder_get_list(); list != NULL; list = list->next) {
|
|
|
|
folder = FOLDER(list->data);
|
|
|
|
g_return_if_fail(folder != NULL);
|
|
|
|
|
|
|
|
if (type != FOLDER_SEL_ALL) {
|
|
|
|
if (FOLDER_TYPE(folder) == F_NEWS)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foldersel_insert_gnode_in_store(tree_store, folder->node, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(tree_store),
|
|
|
|
FOLDERSEL_FOLDERNAME,
|
|
|
|
GTK_SORT_ASCENDING);
|
|
|
|
|
|
|
|
gtk_tree_view_expand_all(GTK_TREE_VIEW(treeview));
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2008-02-12 11:44:26 +01:00
|
|
|
#include "localfolder.h"
|
2005-03-31 08:35:45 +02:00
|
|
|
static gboolean foldersel_selected(GtkTreeSelection *selection,
|
|
|
|
GtkTreeModel *model, GtkTreePath *path,
|
|
|
|
gboolean currently_selected, gpointer data)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2004-12-30 10:15:35 +01:00
|
|
|
GtkTreeIter iter;
|
|
|
|
FolderItem *item = NULL;
|
|
|
|
|
|
|
|
if (currently_selected)
|
|
|
|
return TRUE;
|
2005-03-31 08:35:45 +02:00
|
|
|
|
2004-12-30 10:15:35 +01:00
|
|
|
if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
|
|
|
|
return TRUE;
|
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
gtk_tree_model_get(GTK_TREE_MODEL(tree_store), &iter,
|
|
|
|
FOLDERSEL_FOLDERITEM, &item, -1);
|
|
|
|
|
2004-12-30 10:15:35 +01:00
|
|
|
selected_item = item;
|
2007-08-19 12:15:21 +02:00
|
|
|
if (selected_item && selected_item->path) {
|
2004-05-10 12:22:28 +02:00
|
|
|
gchar *id;
|
|
|
|
id = folder_item_get_identifier(selected_item);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), id);
|
|
|
|
g_free(id);
|
2008-02-12 11:44:26 +01:00
|
|
|
} else
|
|
|
|
if (root_selectable && selected_item && selected_item->folder &&
|
|
|
|
(FOLDER_TYPE(selected_item->folder) == F_MH ||
|
|
|
|
FOLDER_TYPE(selected_item->folder) == F_MBOX ||
|
|
|
|
FOLDER_TYPE(selected_item->folder) == F_IMAP)) {
|
|
|
|
gchar *id = folder_get_identifier(selected_item->folder);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), id);
|
|
|
|
g_free(id);
|
2004-05-10 12:22:28 +02:00
|
|
|
} else
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), "");
|
2005-03-31 08:35:45 +02:00
|
|
|
|
2004-12-30 10:15:35 +01:00
|
|
|
return TRUE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void foldersel_ok(GtkButton *button, gpointer data)
|
|
|
|
{
|
2003-06-06 10:12:43 +02:00
|
|
|
finished = TRUE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void foldersel_cancel(GtkButton *button, gpointer data)
|
|
|
|
{
|
|
|
|
cancelled = TRUE;
|
2003-06-06 10:12:43 +02:00
|
|
|
finished = TRUE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2005-03-31 08:35:45 +02:00
|
|
|
static void foldersel_new_folder(GtkButton *button, gpointer data)
|
|
|
|
{
|
|
|
|
FolderItem *new_item;
|
|
|
|
gchar *new_folder;
|
|
|
|
gchar *disp_name;
|
|
|
|
gchar *p;
|
|
|
|
GtkTreeIter selected, new_child;
|
|
|
|
GtkTreePath *selected_p, *new_child_p;
|
|
|
|
GtkTreeStore *store;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
if (!selected_item || FOLDER_TYPE(selected_item->folder) == F_NEWS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
|
|
|
|
if (!gtk_tree_selection_get_selected(selection, &model, &selected))
|
|
|
|
return;
|
|
|
|
store = GTK_TREE_STORE(model);
|
|
|
|
|
|
|
|
new_folder = input_dialog(_("New folder"),
|
|
|
|
_("Input the name of new folder:"),
|
|
|
|
_("NewFolder"));
|
|
|
|
if (!new_folder) return;
|
|
|
|
AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
|
|
|
|
|
|
|
|
p = strchr(new_folder, G_DIR_SEPARATOR);
|
|
|
|
if ((p && FOLDER_TYPE(selected_item->folder) != F_IMAP) ||
|
|
|
|
(p && FOLDER_TYPE(selected_item->folder) == F_IMAP &&
|
|
|
|
*(p + 1) != '\0')) {
|
2005-07-17 09:30:07 +02:00
|
|
|
alertpanel_error(_("'%c' can't be included in folder name."),
|
2005-03-31 08:35:45 +02:00
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
disp_name = trim_string(new_folder, 32);
|
|
|
|
AUTORELEASE_STR(disp_name, {g_free(disp_name); return;});
|
|
|
|
|
|
|
|
/* find whether the directory already exists */
|
|
|
|
if (folder_find_child_item_by_name(selected_item, new_folder)) {
|
2005-07-17 09:30:07 +02:00
|
|
|
alertpanel_error(_("The folder '%s' already exists."),
|
2005-03-31 08:35:45 +02:00
|
|
|
disp_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_item = folder_create_folder(selected_item, new_folder);
|
|
|
|
if (!new_item) {
|
2005-07-17 09:30:07 +02:00
|
|
|
alertpanel_error(_("Can't create the folder '%s'."), disp_name);
|
2005-03-31 08:35:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add new child */
|
|
|
|
foldersel_append_item(store, new_item, &new_child, &selected);
|
|
|
|
|
|
|
|
selected_p = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &selected);
|
|
|
|
new_child_p = gtk_tree_model_get_path(GTK_TREE_MODEL(store),
|
|
|
|
&new_child);
|
|
|
|
|
|
|
|
gtk_tree_view_expand_row(GTK_TREE_VIEW(treeview), selected_p, FALSE);
|
|
|
|
gtk_tree_selection_select_iter(selection, &new_child);
|
|
|
|
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), new_child_p,
|
|
|
|
NULL, TRUE, 0.5, 0.0);
|
|
|
|
gtk_tree_path_free(new_child_p);
|
|
|
|
gtk_tree_path_free(selected_p);
|
|
|
|
|
|
|
|
folder_write_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foldersel_entry_activated(GtkEntry *entry, gpointer data)
|
|
|
|
{
|
|
|
|
gtk_button_clicked(GTK_BUTTON(ok_button));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foldersel_tree_activated(GtkTreeView *treeview, GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column, gpointer data)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
gtk_button_clicked(GTK_BUTTON(ok_button));
|
|
|
|
}
|
|
|
|
|
2001-05-08 00:13:03 +02:00
|
|
|
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
|
|
|
|
{
|
|
|
|
foldersel_cancel(NULL, NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2005-03-31 08:35:45 +02:00
|
|
|
if (event && event->keyval == GDK_Escape)
|
|
|
|
foldersel_cancel(NULL, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint foldersel_folder_name_compare(GtkTreeModel *model, GtkTreeIter *a,
|
|
|
|
GtkTreeIter *b, gpointer context)
|
|
|
|
{
|
|
|
|
gchar *str_a = NULL, *str_b = NULL;
|
|
|
|
gint val = 0;
|
|
|
|
FolderItem *item_a = NULL, *item_b = NULL;
|
|
|
|
GtkTreeIter parent;
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, a, FOLDERSEL_FOLDERITEM, &item_a, -1);
|
|
|
|
gtk_tree_model_get(model, b, FOLDERSEL_FOLDERITEM, &item_b, -1);
|
|
|
|
|
|
|
|
/* no sort for root folder */
|
|
|
|
if (!gtk_tree_model_iter_parent(GTK_TREE_MODEL(model), &parent, a))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* if both a and b are special folders, sort them according to
|
|
|
|
* their types (which is in-order). Note that this assumes that
|
|
|
|
* there are no multiple folders of a special type. */
|
|
|
|
if (item_a->stype != F_NORMAL && item_b->stype != F_NORMAL)
|
|
|
|
return item_a->stype - item_b->stype;
|
|
|
|
|
|
|
|
/* if b is normal folder, and a is not, b is smaller (ends up
|
|
|
|
* lower in the list) */
|
|
|
|
if (item_a->stype != F_NORMAL && item_b->stype == F_NORMAL)
|
|
|
|
return item_b->stype - item_a->stype;
|
|
|
|
|
|
|
|
/* if b is special folder, and a is not, b is larger (ends up
|
|
|
|
* higher in the list) */
|
|
|
|
if (item_a->stype == F_NORMAL && item_b->stype != F_NORMAL)
|
|
|
|
return item_b->stype - item_a->stype;
|
|
|
|
|
|
|
|
/* XXX g_utf8_collate_key() comparisons may speed things
|
|
|
|
* up when having large lists of folders */
|
|
|
|
gtk_tree_model_get(model, a, FOLDERSEL_FOLDERNAME, &str_a, -1);
|
|
|
|
gtk_tree_model_get(model, b, FOLDERSEL_FOLDERNAME, &str_b, -1);
|
|
|
|
|
|
|
|
/* otherwise just compare the folder names */
|
|
|
|
val = g_utf8_collate(str_a, str_b);
|
|
|
|
|
|
|
|
g_free(str_a);
|
|
|
|
g_free(str_b);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean tree_view_folder_item_func(GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
FolderItemSearch *data)
|
|
|
|
{
|
|
|
|
FolderItem *item = NULL;
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, iter, FOLDERSEL_FOLDERITEM, &item, -1);
|
|
|
|
|
|
|
|
if (data->item == item) {
|
|
|
|
data->path = gtk_tree_path_copy(path);
|
|
|
|
data->iter = *iter;
|
|
|
|
return TRUE;
|
2005-03-18 09:04:18 +01:00
|
|
|
}
|
|
|
|
|
2003-10-05 12:10:30 +02:00
|
|
|
return FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|