claws-mail/src/prefs_summary_column.c

900 lines
24 KiB
C
Raw Normal View History

2001-10-22 10:42:36 +02:00
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (C) 1999-2005 Hiroyuki Yamamoto
2001-10-22 10:42:36 +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
* the Free Software Foundation; either version 2 of the License, or
* (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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "defs.h"
#include <glib.h>
2005-02-10 [paul] 1.0.1cvs3.2 * AUTHORS * Makefile.am * autogen.sh * configure.ac * config/mkinstalldirs * intl/.cvsignore * intl/ChangeLog * intl/VERSION * intl/bindtextdom.c * intl/config.charset * intl/dcgettext.c * intl/dcigettext.c * intl/dcngettext.c * intl/dgettext.c * intl/dngettext.c * intl/eval-plural.h * intl/explodename.c * intl/finddomain.c * intl/gettext.c * intl/gettextP.h * intl/gmo.h * intl/hash-string.h * intl/intl-compat.c * intl/l10nflist.c * intl/libgnuintl.h.in * intl/loadinfo.h * intl/loadmsgcat.c * intl/localcharset.c * intl/localcharset.h * intl/locale.alias * intl/localealias.c * intl/localename.c * intl/log.c * intl/ngettext.c * intl/os2compat.c * intl/os2compat.h * intl/osdep.c * intl/plural-exp.c * intl/plural-exp.h * intl/plural.c * intl/plural.y * intl/ref-add.sin * intl/ref-del.sin * intl/relocatable.c * intl/relocatable.h * intl/textdomain.c * m4/Makefile.am * po/Makefile.in.in * src/Makefile.am * src/account.c * src/action.c * src/addr_compl.c * src/addressadd.c * src/addressbook.c * src/addrgather.c * src/addrindex.c * src/alertpanel.c * src/browseldap.c * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/crash.c * src/editaddress.c * src/editbook.c * src/editgroup.c * src/editjpilot.c * src/editldap.c * src/editldap_basedn.c * src/editvcard.c * src/exphtmldlg.c * src/expldifdlg.c * src/export.c * src/exporthtml.c * src/filtering.c * src/folder.c * src/folder_item_prefs.c * src/foldersel.c * src/folderview.c * src/grouplistdialog.c * src/headerview.c * src/imap.c * src/imap_gtk.c * src/import.c * src/importldif.c * src/importmutt.c * src/importpine.c * src/inc.c * src/ldif.c * src/main.c * src/mainwindow.c * src/matcher.c * src/mbox.c * src/message_search.c * src/messageview.c * src/mh.c * src/mh_gtk.c * src/mimeview.c * src/msgcache.c * src/news.c * src/news_gtk.c * src/noticeview.c * src/partial_download.c * src/pop.c * src/prefs_account.c * src/prefs_actions.c * src/prefs_common.c * src/prefs_customheader.c * src/prefs_display_header.c * src/prefs_ext_prog.c * src/prefs_filtering.c * src/prefs_filtering_action.c * src/prefs_folder_item.c * src/prefs_fonts.c * src/prefs_gtk.c * src/prefs_matcher.c * src/prefs_msg_colors.c * src/prefs_spelling.c * src/prefs_summary_column.c * src/prefs_template.c * src/prefs_themes.c * src/prefs_toolbar.c * src/prefs_wrapping.c * src/privacy.c * src/procheader.c * src/procmime.c * src/procmsg.c * src/quote_fmt.c * src/recv.c * src/send_message.c * src/setup.c * src/sourcewindow.c * src/ssl_manager.c * src/statusbar.c * src/summary_search.c * src/summaryview.c * src/textview.c * src/toolbar.c * src/wizard.c * src/common/nntp.c * src/common/plugin.c * src/common/smtp.c * src/common/ssl.c * src/common/ssl_certificate.c * src/common/string_match.c * src/common/sylpheed.c * src/common/template.c * src/common/utils.c * src/gtk/about.c * src/gtk/colorlabel.c * src/gtk/description_window.c * src/gtk/filesel.c * src/gtk/foldersort.c * src/gtk/gtkaspell.c * src/gtk/gtkutils.c * src/gtk/inputdialog.c * src/gtk/logwindow.c * src/gtk/menu.c * src/gtk/pluginwindow.c * src/gtk/prefswindow.c * src/gtk/progressdialog.c * src/gtk/quicksearch.c * src/gtk/sslcertwindow.c * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/image_viewer/plugin.c * src/plugins/image_viewer/viewer.c * src/plugins/image_viewer/viewerprefs.c * src/plugins/mathml_viewer/mathml_viewer.c * src/plugins/pgpmime/passphrase.c * src/plugins/pgpmime/plugin.c * src/plugins/pgpmime/prefs_gpg.c * src/plugins/pgpmime/select-keys.c * src/plugins/pgpmime/sgpgme.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c sync with main (revision 104)
2005-02-10 13:06:07 +01:00
#include <glib/gi18n.h>
2001-10-22 10:42:36 +02:00
#include <gtk/gtkmain.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkbutton.h>
#include <gdk/gdkkeysyms.h>
#include "prefs_gtk.h"
2001-10-22 10:42:36 +02:00
#include "prefs_common.h"
#include "prefs_summary_column.h"
#include "manage_window.h"
#include "summaryview.h"
#include "mainwindow.h"
#include "inc.h"
#include "gtkutils.h"
#include "utils.h"
enum {
SUMCOL_NAME,
SUMCOL_TYPE,
N_SUMCOL_COLUMNS
};
#define TARGET_INFO_SUMCOL (0xFEEDBABE)
static const GtkTargetEntry row_targets[] = {
{ "PREFS_SUM_COL_MODEL_ROW", GTK_TARGET_SAME_APP, TARGET_INFO_SUMCOL }
};
2001-10-22 10:42:36 +02:00
static struct _SummaryColumnDialog
{
GtkWidget *window;
GtkWidget *stock_list_view;
GtkWidget *shown_list_view;
2001-10-22 10:42:36 +02:00
GtkWidget *add_btn;
GtkWidget *remove_btn;
GtkWidget *up_btn;
GtkWidget *down_btn;
GtkWidget *default_btn;
GtkWidget *ok_btn;
GtkWidget *cancel_btn;
gboolean finished;
} summary_col;
static const gchar *const col_name[N_SUMMARY_COLS] = {
N_("Mark"), /* S_COL_MARK */
2003-01-26 13:56:56 +01:00
N_("Status"), /* S_COL_STATUS */
2001-10-22 10:42:36 +02:00
N_("Attachment"), /* S_COL_MIME */
N_("Subject"), /* S_COL_SUBJECT */
N_("From"), /* S_COL_FROM */
N_("To"), /* S_COL_TO */
2001-10-22 10:42:36 +02:00
N_("Date"), /* S_COL_DATE */
N_("Size"), /* S_COL_SIZE */
N_("Number"), /* S_COL_NUMBER */
N_("Score"), /* S_COL_SCORE */
N_("Locked"), /* S_COL_LOCKED */
2001-10-22 10:42:36 +02:00
};
static SummaryColumnState default_state[N_SUMMARY_COLS] = {
{ S_COL_MARK , TRUE },
2003-01-26 13:56:56 +01:00
{ S_COL_STATUS , TRUE },
2001-10-22 10:42:36 +02:00
{ S_COL_MIME , TRUE },
{ S_COL_SUBJECT, TRUE },
{ S_COL_FROM , TRUE },
{ S_COL_TO , FALSE },
2001-10-22 10:42:36 +02:00
{ S_COL_DATE , TRUE },
{ S_COL_SIZE , TRUE },
{ S_COL_NUMBER , FALSE },
{ S_COL_SCORE , FALSE },
{ S_COL_LOCKED , FALSE },
2001-10-22 10:42:36 +02:00
};
static void prefs_summary_column_create (void);
static void prefs_summary_column_set_dialog (SummaryColumnState *state);
static void prefs_summary_column_set_view (void);
/* callback functions */
static void prefs_summary_column_add (void);
static void prefs_summary_column_remove (void);
static void prefs_summary_column_up (void);
static void prefs_summary_column_down (void);
static void prefs_summary_column_set_to_default (void);
static void prefs_summary_column_ok (void);
static void prefs_summary_column_cancel (void);
static gint prefs_summary_column_delete_event (GtkWidget *widget,
GdkEventAny *event,
gpointer data);
2003-10-05 12:10:30 +02:00
static gboolean prefs_summary_column_key_pressed(GtkWidget *widget,
2001-10-22 10:42:36 +02:00
GdkEventKey *event,
gpointer data);
static GtkListStore *prefs_summary_column_create_store (void);
static void prefs_summary_column_insert_column (GtkListStore *store,
gint row,
const gchar *name,
SummaryColumnType type);
static SummaryColumnType prefs_summary_column_get_column (GtkWidget *list,
gint row);
static GtkWidget *prefs_summary_column_list_view_create (const gchar *name);
static void prefs_filtering_create_list_view_columns (GtkWidget *list_view,
const gchar *name);
static void drag_data_get (GtkTreeView *tree_view,
GdkDragContext *context,
GtkSelectionData *data,
guint info,
guint time,
GtkTreeModel *model);
static void drag_data_received (GtkTreeView *tree_view,
GdkDragContext *context,
gint x, gint y,
GtkSelectionData *data,
guint info,
guint time,
GtkTreeModel *model);
2001-10-22 10:42:36 +02:00
void prefs_summary_column_open(void)
{
inc_lock();
if (!summary_col.window)
prefs_summary_column_create();
manage_window_set_transient(GTK_WINDOW(summary_col.window));
gtk_widget_grab_focus(summary_col.ok_btn);
prefs_summary_column_set_dialog(NULL);
gtk_widget_show(summary_col.window);
summary_col.finished = FALSE;
while (summary_col.finished == FALSE)
gtk_main_iteration();
gtk_widget_hide(summary_col.window);
inc_unlock();
}
static void prefs_summary_column_create(void)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *label_hbox;
GtkWidget *label;
GtkWidget *vbox1;
GtkWidget *hbox1;
GtkWidget *clist_hbox;
GtkWidget *scrolledwin;
GtkWidget *stock_list_view;
GtkWidget *shown_list_view;
2001-10-22 10:42:36 +02:00
GtkWidget *btn_vbox;
GtkWidget *btn_vbox1;
GtkWidget *add_btn;
GtkWidget *remove_btn;
GtkWidget *up_btn;
GtkWidget *down_btn;
GtkWidget *btn_hbox;
GtkWidget *default_btn;
GtkWidget *confirm_area;
GtkWidget *ok_btn;
GtkWidget *cancel_btn;
2002-08-15 09:38:17 +02:00
debug_print("Creating summary column setting window...\n");
2001-10-22 10:42:36 +02:00
2003-10-05 12:10:30 +02:00
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2001-10-22 10:42:36 +02:00
gtk_container_set_border_width(GTK_CONTAINER(window), 8);
2003-10-05 12:10:30 +02:00
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
2001-10-22 10:42:36 +02:00
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
2001-10-22 10:42:36 +02:00
gtk_window_set_title(GTK_WINDOW(window),
2002-11-28 18:23:30 +01:00
_("Displayed items configuration"));
2003-10-05 12:10:30 +02:00
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(prefs_summary_column_delete_event),
NULL);
g_signal_connect(G_OBJECT(window), "key_press_event",
G_CALLBACK(prefs_summary_column_key_pressed),
NULL);
2001-10-22 10:42:36 +02:00
vbox = gtk_vbox_new(FALSE, 6);
gtk_widget_show(vbox);
gtk_container_add(GTK_CONTAINER(window), vbox);
label_hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(label_hbox);
gtk_box_pack_start(GTK_BOX(vbox), label_hbox, FALSE, FALSE, 4);
label = gtk_label_new
2002-11-27 18:41:38 +01:00
(_("Select items to be displayed in the summary view. You can modify\n"
2002-11-28 18:23:30 +01:00
"the order by using the Up / Down buttons or by dragging the items."));
2001-10-22 10:42:36 +02:00
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(label_hbox), label, FALSE, FALSE, 4);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
vbox1 = gtk_vbox_new(FALSE, VSPACING);
gtk_widget_show(vbox1);
gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(vbox1), 2);
hbox1 = gtk_hbox_new(FALSE, 8);
gtk_widget_show(hbox1);
gtk_box_pack_start(GTK_BOX(vbox1), hbox1, FALSE, TRUE, 0);
clist_hbox = gtk_hbox_new(FALSE, 8);
gtk_widget_show(clist_hbox);
gtk_box_pack_start(GTK_BOX(hbox1), clist_hbox, TRUE, TRUE, 0);
scrolledwin = gtk_scrolled_window_new(NULL, NULL);
2003-10-05 12:10:30 +02:00
gtk_widget_set_size_request(scrolledwin, 180, 210);
2001-10-22 10:42:36 +02:00
gtk_widget_show(scrolledwin);
gtk_box_pack_start(GTK_BOX(clist_hbox), scrolledwin, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
stock_list_view = prefs_summary_column_list_view_create
(_("Available items"));
gtk_widget_show(stock_list_view);
gtk_container_add(GTK_CONTAINER(scrolledwin), stock_list_view);
2001-10-22 10:42:36 +02:00
/* add/remove button */
btn_vbox = gtk_vbox_new(FALSE, 0);
gtk_widget_show(btn_vbox);
gtk_box_pack_start(GTK_BOX(hbox1), btn_vbox, FALSE, FALSE, 0);
btn_vbox1 = gtk_vbox_new(FALSE, 8);
gtk_widget_show(btn_vbox1);
gtk_box_pack_start(GTK_BOX(btn_vbox), btn_vbox1, TRUE, FALSE, 0);
add_btn = gtk_button_new_with_label(_(" -> "));
gtk_widget_show(add_btn);
gtk_box_pack_start(GTK_BOX(btn_vbox1), add_btn, FALSE, FALSE, 0);
remove_btn = gtk_button_new_with_label(_(" <- "));
gtk_widget_show(remove_btn);
gtk_box_pack_start(GTK_BOX(btn_vbox1), remove_btn, FALSE, FALSE, 0);
2003-10-05 12:10:30 +02:00
g_signal_connect(G_OBJECT(add_btn), "clicked",
G_CALLBACK(prefs_summary_column_add), NULL);
g_signal_connect(G_OBJECT(remove_btn), "clicked",
G_CALLBACK(prefs_summary_column_remove), NULL);
2001-10-22 10:42:36 +02:00
clist_hbox = gtk_hbox_new(FALSE, 8);
gtk_widget_show(clist_hbox);
gtk_box_pack_start(GTK_BOX(hbox1), clist_hbox, TRUE, TRUE, 0);
scrolledwin = gtk_scrolled_window_new(NULL, NULL);
2003-10-05 12:10:30 +02:00
gtk_widget_set_size_request(scrolledwin, 180, 210);
2001-10-22 10:42:36 +02:00
gtk_widget_show(scrolledwin);
gtk_box_pack_start(GTK_BOX(clist_hbox), scrolledwin, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
shown_list_view = prefs_summary_column_list_view_create
(_("Displayed items"));
gtk_widget_show(shown_list_view);
gtk_container_add(GTK_CONTAINER(scrolledwin), shown_list_view);
2001-10-22 10:42:36 +02:00
/* up/down button */
btn_vbox = gtk_vbox_new(FALSE, 0);
gtk_widget_show(btn_vbox);
gtk_box_pack_start(GTK_BOX(hbox1), btn_vbox, FALSE, FALSE, 0);
btn_vbox1 = gtk_vbox_new(FALSE, 8);
gtk_widget_show(btn_vbox1);
gtk_box_pack_start(GTK_BOX(btn_vbox), btn_vbox1, TRUE, FALSE, 0);
up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
2001-10-22 10:42:36 +02:00
gtk_widget_show(up_btn);
gtk_box_pack_start(GTK_BOX(btn_vbox1), up_btn, FALSE, FALSE, 0);
down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
2001-10-22 10:42:36 +02:00
gtk_widget_show(down_btn);
gtk_box_pack_start(GTK_BOX(btn_vbox1), down_btn, FALSE, FALSE, 0);
2003-10-05 12:10:30 +02:00
g_signal_connect(G_OBJECT(up_btn), "clicked",
G_CALLBACK(prefs_summary_column_up), NULL);
g_signal_connect(G_OBJECT(down_btn), "clicked",
G_CALLBACK(prefs_summary_column_down), NULL);
2001-10-22 10:42:36 +02:00
btn_hbox = gtk_hbox_new(FALSE, 8);
gtk_widget_show(btn_hbox);
gtk_box_pack_end(GTK_BOX(vbox), btn_hbox, FALSE, FALSE, 0);
btn_vbox = gtk_vbox_new(FALSE, 0);
gtk_widget_show(btn_vbox);
gtk_box_pack_start(GTK_BOX(btn_hbox), btn_vbox, FALSE, FALSE, 0);
2002-11-28 18:23:30 +01:00
default_btn = gtk_button_new_with_label(_(" Use default "));
2001-10-22 10:42:36 +02:00
gtk_widget_show(default_btn);
gtk_box_pack_start(GTK_BOX(btn_vbox), default_btn, TRUE, FALSE, 0);
2003-10-05 12:10:30 +02:00
g_signal_connect(G_OBJECT(default_btn), "clicked",
G_CALLBACK(prefs_summary_column_set_to_default),
NULL);
2001-10-22 10:42:36 +02:00
gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK,
&cancel_btn, GTK_STOCK_CANCEL,
NULL, NULL);
2001-10-22 10:42:36 +02:00
gtk_widget_show(confirm_area);
gtk_box_pack_end(GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
gtk_widget_grab_default(ok_btn);
2003-10-05 12:10:30 +02:00
g_signal_connect(G_OBJECT(ok_btn), "clicked",
G_CALLBACK(prefs_summary_column_ok), NULL);
g_signal_connect(G_OBJECT(cancel_btn), "clicked",
G_CALLBACK(prefs_summary_column_cancel), NULL);
2001-10-22 10:42:36 +02:00
2001-10-22 10:42:36 +02:00
summary_col.window = window;
summary_col.add_btn = add_btn;
summary_col.remove_btn = remove_btn;
summary_col.up_btn = up_btn;
summary_col.down_btn = down_btn;
summary_col.ok_btn = ok_btn;
summary_col.cancel_btn = cancel_btn;
summary_col.stock_list_view = stock_list_view;
summary_col.shown_list_view = shown_list_view;
2001-10-22 10:42:36 +02:00
}
SummaryColumnState *prefs_summary_column_get_config(void)
{
static SummaryColumnState state[N_SUMMARY_COLS];
SummaryColumnType type;
gint pos;
for (pos = 0; pos < N_SUMMARY_COLS; pos++)
state[pos].type = -1;
for (type = 0; type < N_SUMMARY_COLS; type++) {
pos = prefs_common.summary_col_pos[type];
if (pos < 0 || pos >= N_SUMMARY_COLS ||
state[pos].type != -1) {
g_warning("Wrong column position\n");
prefs_summary_column_set_config(default_state);
return default_state;
}
state[pos].type = type;
state[pos].visible = prefs_common.summary_col_visible[type];
}
return state;
}
void prefs_summary_column_set_config(SummaryColumnState *state)
{
SummaryColumnType type;
gint pos;
for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
type = state[pos].type;
prefs_common.summary_col_visible[type] = state[pos].visible;
prefs_common.summary_col_pos[type] = pos;
}
}
static void prefs_summary_column_set_dialog(SummaryColumnState *state)
{
GtkListStore *stock_store, *shown_store;
2001-10-22 10:42:36 +02:00
gint pos;
SummaryColumnType type;
gchar *name;
stock_store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(summary_col.stock_list_view)));
shown_store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(summary_col.shown_list_view)));
gtk_list_store_clear(stock_store);
gtk_list_store_clear(shown_store);
2001-10-22 10:42:36 +02:00
if (!state)
state = prefs_summary_column_get_config();
for (pos = 0; pos < N_SUMMARY_COLS; pos++) {
type = state[pos].type;
name = gettext(col_name[type]);
if (state[pos].visible)
prefs_summary_column_insert_column(shown_store,
-1, name,
type);
else
prefs_summary_column_insert_column(stock_store,
-1, name,
type);
2001-10-22 10:42:36 +02:00
}
}
static void prefs_summary_column_set_view(void)
{
gint stock_n_rows, shown_n_rows;
2001-10-22 10:42:36 +02:00
SummaryColumnState state[N_SUMMARY_COLS];
SummaryColumnType type;
gint row, pos = 0;
stock_n_rows = gtk_tree_model_iter_n_children
(gtk_tree_view_get_model(GTK_TREE_VIEW
(summary_col.stock_list_view)), NULL);
shown_n_rows = gtk_tree_model_iter_n_children
(gtk_tree_view_get_model(GTK_TREE_VIEW
(summary_col.shown_list_view)), NULL);
2001-10-22 10:42:36 +02:00
g_return_if_fail
(stock_n_rows + shown_n_rows == N_SUMMARY_COLS);
2001-10-22 10:42:36 +02:00
for (row = 0; row < stock_n_rows; row++) {
type = prefs_summary_column_get_column
(summary_col.stock_list_view, row);
2001-10-22 10:42:36 +02:00
state[row].type = type;
state[row].visible = FALSE;
}
pos = row;
for (row = 0; row < shown_n_rows; row++) {
type = prefs_summary_column_get_column
(summary_col.shown_list_view, row);
2001-10-22 10:42:36 +02:00
state[pos + row].type = type;
state[pos + row].visible = TRUE;
}
prefs_summary_column_set_config(state);
main_window_set_summary_column();
}
static void prefs_summary_column_add(void)
{
GtkListStore *stock_store, *shown_store;
GtkTreeIter stock_sel, shown_sel, shown_add;
gboolean shown_sel_valid;
2001-10-22 10:42:36 +02:00
gchar *name;
SummaryColumnType type;
stock_store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(summary_col.stock_list_view)));
shown_store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(summary_col.shown_list_view)));
if (!gtk_tree_selection_get_selected
(gtk_tree_view_get_selection
(GTK_TREE_VIEW(summary_col.stock_list_view)),
NULL,
&stock_sel))
return;
shown_sel_valid = gtk_tree_selection_get_selected
(gtk_tree_view_get_selection
(GTK_TREE_VIEW(summary_col.shown_list_view)),
NULL,
&shown_sel);
gtk_tree_model_get(GTK_TREE_MODEL(stock_store), &stock_sel,
SUMCOL_TYPE, &type,
-1);
gtk_list_store_remove(stock_store, &stock_sel);
gtk_list_store_insert_after(shown_store, &shown_add,
shown_sel_valid ? &shown_sel : NULL);
name = gettext(col_name[type]);
gtk_list_store_set(shown_store, &shown_add,
SUMCOL_NAME, name,
SUMCOL_TYPE, type,
-1);
gtk_tree_selection_select_iter(gtk_tree_view_get_selection
(GTK_TREE_VIEW(summary_col.shown_list_view)),
&shown_add);
2001-10-22 10:42:36 +02:00
}
static void prefs_summary_column_remove(void)
{
GtkListStore *stock_store, *shown_store;
GtkTreeIter shown_sel, stock_sel, stock_add;
gboolean stock_sel_valid;
2001-10-22 10:42:36 +02:00
gchar *name;
SummaryColumnType type;
stock_store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(summary_col.stock_list_view)));
shown_store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(summary_col.shown_list_view)));
if (!gtk_tree_selection_get_selected
(gtk_tree_view_get_selection
(GTK_TREE_VIEW(summary_col.shown_list_view)),
NULL,
&shown_sel))
return;
stock_sel_valid = gtk_tree_selection_get_selected
(gtk_tree_view_get_selection
(GTK_TREE_VIEW(summary_col.stock_list_view)),
NULL,
&stock_sel);
gtk_tree_model_get(GTK_TREE_MODEL(shown_store), &shown_sel,
SUMCOL_TYPE, &type,
-1);
gtk_list_store_remove(shown_store, &shown_sel);
gtk_list_store_insert_after(stock_store, &stock_add,
stock_sel_valid ? &stock_sel : NULL);
name = gettext(col_name[type]);
gtk_list_store_set(stock_store, &stock_add,
SUMCOL_NAME, name,
SUMCOL_TYPE, type,
-1);
gtk_tree_selection_select_iter(gtk_tree_view_get_selection
(GTK_TREE_VIEW(summary_col.stock_list_view)),
&stock_add);
2001-10-22 10:42:36 +02:00
}
static void prefs_summary_column_up(void)
{
GtkTreePath *prev, *sel;
GtkTreeIter isel;
GtkListStore *shown_store;
GtkTreeIter iprev;
if (!gtk_tree_selection_get_selected
(gtk_tree_view_get_selection
(GTK_TREE_VIEW(summary_col.shown_list_view)),
NULL,
&isel))
return;
shown_store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(summary_col.shown_list_view)));
sel = gtk_tree_model_get_path(GTK_TREE_MODEL(shown_store),
&isel);
if (!sel)
return;
prev = gtk_tree_path_copy(sel);
if (!gtk_tree_path_prev(prev)) {
gtk_tree_path_free(prev);
gtk_tree_path_free(sel);
return;
}
2001-10-22 10:42:36 +02:00
gtk_tree_model_get_iter(GTK_TREE_MODEL(shown_store),
&iprev, prev);
gtk_tree_path_free(sel);
gtk_tree_path_free(prev);
2001-10-22 10:42:36 +02:00
gtk_list_store_swap(shown_store, &iprev, &isel);
2001-10-22 10:42:36 +02:00
}
static void prefs_summary_column_down(void)
{
GtkListStore *shown_store;
GtkTreeIter next, sel;
if (!gtk_tree_selection_get_selected
(gtk_tree_view_get_selection
(GTK_TREE_VIEW(summary_col.shown_list_view)),
NULL,
&sel))
return;
shown_store = GTK_LIST_STORE(gtk_tree_view_get_model
(GTK_TREE_VIEW(summary_col.shown_list_view)));
next = sel;
if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(shown_store), &next))
return;
gtk_list_store_swap(shown_store, &next, &sel);
2001-10-22 10:42:36 +02:00
}
static void prefs_summary_column_set_to_default(void)
{
prefs_summary_column_set_dialog(default_state);
}
static void prefs_summary_column_ok(void)
{
if (!summary_col.finished) {
summary_col.finished = TRUE;
prefs_summary_column_set_view();
}
}
static void prefs_summary_column_cancel(void)
{
summary_col.finished = TRUE;
}
static gint prefs_summary_column_delete_event(GtkWidget *widget,
GdkEventAny *event,
gpointer data)
{
summary_col.finished = TRUE;
return TRUE;
}
2003-10-05 12:10:30 +02:00
static gboolean prefs_summary_column_key_pressed(GtkWidget *widget,
GdkEventKey *event,
gpointer data)
2001-10-22 10:42:36 +02:00
{
if (event && event->keyval == GDK_Escape)
summary_col.finished = TRUE;
2003-10-05 12:10:30 +02:00
return FALSE;
2001-10-22 10:42:36 +02:00
}
static GtkListStore *prefs_summary_column_create_store(void)
{
return gtk_list_store_new(N_SUMCOL_COLUMNS,
G_TYPE_STRING,
G_TYPE_INT,
-1);
}
static void prefs_summary_column_insert_column(GtkListStore *store,
gint row,
const gchar *name,
SummaryColumnType type)
{
GtkTreeIter iter;
if (row >= 0) {
if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store),
&iter, NULL, row))
row = -1;
}
if (row < 0) {
/* add new */
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
SUMCOL_NAME, name,
SUMCOL_TYPE, type,
-1);
return;
} else {
/* change existing */
gtk_list_store_set(store, &iter,
SUMCOL_NAME, name,
SUMCOL_TYPE, type,
-1);
}
}
/*!
*\brief Return the columnn type for a row
*/
static SummaryColumnType prefs_summary_column_get_column(GtkWidget *list, gint row)
{
GtkTreeView *list_view = GTK_TREE_VIEW(list);
GtkTreeModel *model = gtk_tree_view_get_model(list_view);
GtkTreeIter iter;
SummaryColumnType result;
if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
return -1;
gtk_tree_model_get(model, &iter,
SUMCOL_TYPE, &result,
-1);
return result;
}
static GtkWidget *prefs_summary_column_list_view_create(const gchar *name)
{
GtkWidget *list_view;
GtkTreeSelection *selector;
GtkTreeModel *model;
model = GTK_TREE_MODEL(prefs_summary_column_create_store());
list_view = gtk_tree_view_new_with_model(model);
g_object_unref(G_OBJECT(model));
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
prefs_common.enable_rules_hint);
selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
prefs_filtering_create_list_view_columns(GTK_WIDGET(list_view), name);
gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(list_view),
GDK_BUTTON1_MASK,
row_targets,
G_N_ELEMENTS(row_targets),
GDK_ACTION_MOVE);
gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(list_view),
row_targets,
G_N_ELEMENTS(row_targets),
GDK_ACTION_MOVE);
g_signal_connect(G_OBJECT(list_view), "drag_data_get",
G_CALLBACK(drag_data_get),
model);
g_signal_connect(G_OBJECT(list_view), "drag_data_received",
G_CALLBACK(drag_data_received),
model);
return list_view;
}
static void prefs_filtering_create_list_view_columns(GtkWidget *list_view,
const gchar *name)
{
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
(name, renderer, "text", SUMCOL_NAME, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
}
static void drag_data_get(GtkTreeView *tree_view, GdkDragContext *context,
GtkSelectionData *data, guint info,
guint time, GtkTreeModel *model)
{
GtkTreeIter iter;
SummaryColumnType type;
GtkTreeModel *source_model;
if (info != TARGET_INFO_SUMCOL)
return;
if (!gtk_tree_selection_get_selected
(gtk_tree_view_get_selection(tree_view),
&source_model, &iter))
return;
gtk_tree_model_get(source_model, &iter,
SUMCOL_TYPE, &type,
-1);
/* send the type */
gtk_selection_data_set(data, data->target, 8, (gchar *) &type, sizeof type);
}
static void drag_data_received(GtkTreeView *tree_view, GdkDragContext *context,
gint x, gint y, GtkSelectionData *data,
guint info, guint time, GtkTreeModel *model)
{
GtkWidget *source;
GtkTreePath *dst = NULL, *sel = NULL;
GtkTreeIter isel, idst;
GtkTreeViewDropPosition pos;
SummaryColumnType type;
GtkTreeModel *sel_model;
gchar *name;
source = gtk_drag_get_source_widget(context);
if (source == GTK_WIDGET(tree_view)) {
/*
* Same widget: re-order
*/
gtk_tree_selection_get_selected(gtk_tree_view_get_selection(tree_view),
NULL, &isel);
sel = gtk_tree_model_get_path(model, &isel);
gtk_tree_view_get_dest_row_at_pos(tree_view, x, y,
&dst, &pos);
/* NOTE: dst is invalid if selection beyond last row, in that
* case move beyond last one (XXX_move_before(..., NULL)) */
if (dst)
gtk_tree_model_get_iter(model, &idst, dst);
else
gtk_list_store_move_before(GTK_LIST_STORE(model),
&isel,
NULL);
/* we do not drag if no valid dst and sel, and when
* dst and sel are the same (moving after or before
* itself doesn't change order...) */
if ((dst && sel) && gtk_tree_path_compare(sel, dst) != 0) {
if (pos == GTK_TREE_VIEW_DROP_BEFORE
|| pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
gtk_list_store_move_before(GTK_LIST_STORE(model),
&isel,
&idst);
else
gtk_list_store_move_after(GTK_LIST_STORE(model),
&isel,
&idst);
}
gtk_tree_path_free(dst);
gtk_tree_path_free(sel);
gtk_drag_finish(context, TRUE, FALSE, time);
} else if (source == summary_col.stock_list_view
|| source == summary_col.shown_list_view) {
/*
* Other widget: change and update
*/
/* get source information and remove */
gtk_tree_selection_get_selected(gtk_tree_view_get_selection(
GTK_TREE_VIEW(source)),
&sel_model, &isel);
type = *((gint *) data->data);
name = gettext(col_name[type]);
gtk_list_store_remove(GTK_LIST_STORE(sel_model), &isel);
/* get insertion position */
gtk_tree_view_get_dest_row_at_pos(tree_view, x, y, &dst, &pos);
/* NOTE: dst is invalid if insertion point beyond last row,
* just append to list in that case (XXX_store_append()) */
if (dst) {
gtk_tree_model_get_iter(model, &idst, dst);
if (pos == GTK_TREE_VIEW_DROP_BEFORE
|| pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
gtk_list_store_insert_before(GTK_LIST_STORE(model),
&isel,
&idst);
else
gtk_list_store_insert_after(GTK_LIST_STORE(model),
&isel,
&idst);
} else
gtk_list_store_append(GTK_LIST_STORE(model),
&isel);
gtk_list_store_set(GTK_LIST_STORE(model), &isel,
SUMCOL_NAME, name,
SUMCOL_TYPE, type, -1);
gtk_tree_path_free(dst);
gtk_drag_finish(context, TRUE, FALSE, time);
}
/* XXXX: should we call gtk_drag_finish() for other code paths? */
}