[balsa/wip/gtk4: 334/351] balsa-index: Add convenience functions
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/wip/gtk4: 334/351] balsa-index: Add convenience functions
- Date: Wed, 23 May 2018 21:45:03 +0000 (UTC)
commit 2372b5869eed0e20342fbf092f4db1884ab71c2f
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sun May 6 10:15:55 2018 -0400
balsa-index: Add convenience functions
for accessing BalsaIndex::mailbox_node. Also use them in main-window and
mblist.
src/balsa-index.c | 1436 ++++++++++++++++++++++++++++++----------------------
src/balsa-index.h | 28 +-
src/balsa-mblist.c | 4 +-
src/main-window.c | 9 +-
4 files changed, 852 insertions(+), 625 deletions(-)
---
diff --git a/src/balsa-index.c b/src/balsa-index.c
index d648d1d..88b536f 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -26,10 +26,10 @@
The alternative is to create a hidden column containing the sorting
key and replace the key on every change of the sort method.
-*/
+ */
#if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif /* HAVE_CONFIG_H */
#include "balsa-index.h"
@@ -51,7 +51,7 @@
#include <glib/gi18n.h>
#if HAVE_MACOSX_DESKTOP
-# include "macosx-helpers.h"
+# include "macosx-helpers.h"
#endif
/* TREE_VIEW_FIXED_HEIGHT enables hight-performance mode of GtkTreeView
@@ -60,72 +60,77 @@
/* gtk widget */
-static void bndx_destroy(GObject * obj);
-static gboolean bndx_popup_menu(GtkWidget * widget);
+static void bndx_destroy(GObject *obj);
+static gboolean bndx_popup_menu(GtkWidget *widget);
/* statics */
/* Manage the tree view */
-static gboolean bndx_row_is_viewable(BalsaIndex * index,
- GtkTreePath * path);
-static void bndx_expand_to_row_and_select(BalsaIndex * index,
- GtkTreeIter * iter);
-static void bndx_changed_find_row(BalsaIndex * index);
+static gboolean bndx_row_is_viewable(BalsaIndex *index,
+ GtkTreePath *path);
+static void bndx_expand_to_row_and_select(BalsaIndex *index,
+ GtkTreeIter *iter);
+static void bndx_changed_find_row(BalsaIndex *index);
/* mailbox callbacks */
-static void bndx_mailbox_changed_cb(LibBalsaMailbox * mailbox,
- BalsaIndex * bindex);
+static void bndx_mailbox_changed_cb(LibBalsaMailbox *mailbox,
+ BalsaIndex *bindex);
/* GtkTree* callbacks */
-static void bndx_selection_changed(GtkTreeSelection * selection,
- BalsaIndex * index);
+static void bndx_selection_changed(GtkTreeSelection *selection,
+ BalsaIndex *index);
static void bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
gint n_press,
gdouble x,
gdouble y,
gpointer user_data);
-static void bndx_row_activated(GtkTreeView * tree_view, GtkTreePath * path,
- GtkTreeViewColumn * column,
- gpointer user_data);
-static void bndx_column_resize(GtkWidget * widget,
- GtkAllocation * allocation,
- gint baseline,
- gpointer user_data);
-static void bndx_tree_expand_cb(GtkTreeView * tree_view,
- GtkTreeIter * iter, GtkTreePath * path,
- gpointer user_data);
-static gboolean bndx_test_collapse_row_cb(GtkTreeView * tree_view,
- GtkTreeIter * iter,
- GtkTreePath * path,
- gpointer user_data);
-static void bndx_tree_collapse_cb(GtkTreeView * tree_view,
- GtkTreeIter * iter, GtkTreePath * path,
- gpointer user_data);
+static void bndx_row_activated(GtkTreeView *tree_view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer user_data);
+static void bndx_column_resize(GtkWidget *widget,
+ GtkAllocation *allocation,
+ gint baseline,
+ gpointer user_data);
+static void bndx_tree_expand_cb(GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer user_data);
+static gboolean bndx_test_collapse_row_cb(GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer user_data);
+static void bndx_tree_collapse_cb(GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer user_data);
/* formerly balsa-index-page stuff */
enum {
TARGET_MESSAGES
};
-static const gchar * index_drag_types[] = {
+static const gchar *index_drag_types[] = {
"x-application/x-message-list"
};
-static void bndx_drag_cb(GtkWidget* widget,
- GdkDragContext* drag_context,
- GtkSelectionData* data,
- guint time,
- gpointer user_data);
+static void bndx_drag_cb(GtkWidget *widget,
+ GdkDragContext *drag_context,
+ GtkSelectionData *data,
+ guint time,
+ gpointer user_data);
/* Popup menu */
-static GtkWidget* bndx_popup_menu_create(BalsaIndex * index);
-static void bndx_do_popup(BalsaIndex * index,
- const GdkEvent * event);
-static GtkWidget *create_stock_menu_item(GtkWidget * menu,
- const gchar * label,
- GCallback cb, gpointer data);
+static GtkWidget *bndx_popup_menu_create(BalsaIndex *index);
+static void bndx_do_popup(BalsaIndex *index,
+ const GdkEvent *event);
+static GtkWidget *create_stock_menu_item(GtkWidget *menu,
+ const gchar *label,
+ GCallback cb,
+ gpointer data);
-static void sendmsg_window_destroy_cb(GtkWidget * widget, gpointer data);
+static void sendmsg_window_destroy_cb(GtkWidget *widget,
+ gpointer data);
/* signals */
enum {
@@ -138,8 +143,10 @@ static gint balsa_index_signals[LAST_SIGNAL] = {
};
/* General helpers. */
-static void bndx_expand_to_row(BalsaIndex * index, GtkTreePath * path);
-static void bndx_select_row(BalsaIndex * index, GtkTreePath * path);
+static void bndx_expand_to_row(BalsaIndex *index,
+ GtkTreePath *path);
+static void bndx_select_row(BalsaIndex *index,
+ GtkTreePath *path);
/* Other callbacks. */
static void bndx_store_address(gpointer data);
@@ -151,7 +158,7 @@ G_DEFINE_TYPE(BalsaIndex, balsa_index, GTK_TYPE_TREE_VIEW)
/* BalsaIndex class init method. */
static void
-balsa_index_class_init(BalsaIndexClass * klass)
+balsa_index_class_init(BalsaIndexClass *klass)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
@@ -162,25 +169,28 @@ balsa_index_class_init(BalsaIndexClass * klass)
balsa_index_signals[INDEX_CHANGED] =
g_signal_new("index-changed",
G_TYPE_FROM_CLASS(object_class),
- G_SIGNAL_RUN_FIRST,
+ G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
- object_class->dispose = bndx_destroy;
+ object_class->dispose = bndx_destroy;
widget_class->popup_menu = bndx_popup_menu;
}
+
/* Object class destroy method. */
static void
-bndx_mbnode_weak_notify(gpointer data, GObject *where_the_object_was)
+bndx_mbnode_weak_notify(gpointer data,
+ GObject *where_the_object_was)
{
BalsaIndex *bindex = data;
bindex->mailbox_node = NULL;
gtk_widget_destroy(GTK_WIDGET(bindex));
}
+
static void
-bndx_destroy(GObject * obj)
+bndx_destroy(GObject *obj)
{
BalsaIndex *index;
@@ -188,18 +198,18 @@ bndx_destroy(GObject * obj)
index = BALSA_INDEX(obj);
if (index->mailbox_node) {
- LibBalsaMailbox* mailbox;
-
- mailbox = balsa_index_get_mailbox(index);
- if (mailbox != NULL) {
- g_signal_handlers_disconnect_matched(mailbox,
- G_SIGNAL_MATCH_DATA,
- 0, 0, NULL, NULL, index);
- gtk_tree_view_set_model(GTK_TREE_VIEW(index), NULL);
- libbalsa_mailbox_close(mailbox, balsa_app.expunge_on_close);
- }
-
- if (index->mailbox_node) {
+ LibBalsaMailbox *mailbox;
+
+ mailbox = balsa_index_get_mailbox(index);
+ if (mailbox != NULL) {
+ g_signal_handlers_disconnect_matched(mailbox,
+ G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, index);
+ gtk_tree_view_set_model(GTK_TREE_VIEW(index), NULL);
+ libbalsa_mailbox_close(mailbox, balsa_app.expunge_on_close);
+ }
+
+ if (index->mailbox_node) {
g_object_weak_unref(G_OBJECT(index->mailbox_node),
(GWeakNotify) bndx_mbnode_weak_notify,
index);
@@ -215,19 +225,22 @@ bndx_destroy(GObject * obj)
G_OBJECT_CLASS(balsa_index_parent_class)->dispose(obj);
}
+
/* Widget class popup menu method. */
static gboolean
-bndx_popup_menu(GtkWidget * widget)
+bndx_popup_menu(GtkWidget *widget)
{
bndx_do_popup(BALSA_INDEX(widget), NULL);
return TRUE;
}
+
static void
bi_apply_other_column_settings(GtkTreeViewColumn *column,
- gboolean sortable, gint typeid)
+ gboolean sortable,
+ gint typeid)
{
- if(sortable)
+ if (sortable)
gtk_tree_view_column_set_sort_column_id(column, typeid);
gtk_tree_view_column_set_alignment(column, 0.5);
@@ -237,9 +250,10 @@ bi_apply_other_column_settings(GtkTreeViewColumn *column,
#endif
}
+
/* Width of a string in pixels for the default font. */
static gint
-bndx_string_width(const gchar * text)
+bndx_string_width(const gchar *text)
{
GtkWidget *label;
gint natural_width;
@@ -254,13 +268,14 @@ bndx_string_width(const gchar * text)
return natural_width;
}
+
/* BalsaIndex instance init method; no tree store is set on the tree
* view--that's handled later, when the view is populated. */
static void
-balsa_index_init(BalsaIndex * index)
+balsa_index_init(BalsaIndex *index)
{
- GtkWidget *widget = GTK_WIDGET(index);
- GtkTreeView *tree_view = GTK_TREE_VIEW(index);
+ GtkWidget *widget = GTK_WIDGET(index);
+ GtkTreeView *tree_view = GTK_TREE_VIEW(index);
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
@@ -274,68 +289,68 @@ balsa_index_init(BalsaIndex * index)
/* Index column */
renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes
- ("#", renderer,
- "text", LB_MBOX_MSGNO_COL,
- "foreground", LB_MBOX_FOREGROUND_COL,
- "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
- "background", LB_MBOX_BACKGROUND_COL,
- "background-set", LB_MBOX_BACKGROUND_SET_COL,
- NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ ("#", renderer,
+ "text", LB_MBOX_MSGNO_COL,
+ "foreground", LB_MBOX_FOREGROUND_COL,
+ "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
+ "background", LB_MBOX_BACKGROUND_COL,
+ "background-set", LB_MBOX_BACKGROUND_SET_COL,
+ NULL);
g_object_set(renderer, "xalign", 1.0, NULL);
bi_apply_other_column_settings(column, TRUE, LB_MBOX_MSGNO_COL);
gtk_tree_view_append_column(tree_view, column);
/* Status icon column */
renderer = gtk_cell_renderer_pixbuf_new();
- column = gtk_tree_view_column_new_with_attributes
- ("S", renderer,
- "pixbuf", LB_MBOX_MARKED_COL,
- "cell-background", LB_MBOX_BACKGROUND_COL,
- "cell-background-set", LB_MBOX_BACKGROUND_SET_COL,
- NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ ("S", renderer,
+ "pixbuf", LB_MBOX_MARKED_COL,
+ "cell-background", LB_MBOX_BACKGROUND_COL,
+ "cell-background-set", LB_MBOX_BACKGROUND_SET_COL,
+ NULL);
bi_apply_other_column_settings(column, FALSE, 0);
gtk_tree_view_append_column(tree_view, column);
/* Attachment icon column */
renderer = gtk_cell_renderer_pixbuf_new();
- column = gtk_tree_view_column_new_with_attributes
- ("A", renderer,
- "pixbuf", LB_MBOX_ATTACH_COL,
- "cell-background", LB_MBOX_BACKGROUND_COL,
- "cell-background-set", LB_MBOX_BACKGROUND_SET_COL,
- NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ ("A", renderer,
+ "pixbuf", LB_MBOX_ATTACH_COL,
+ "cell-background", LB_MBOX_BACKGROUND_COL,
+ "cell-background-set", LB_MBOX_BACKGROUND_SET_COL,
+ NULL);
bi_apply_other_column_settings(column, FALSE, 0);
gtk_tree_view_append_column(tree_view, column);
/* From/To column */
renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes
- (_("From"), renderer,
- "text", LB_MBOX_FROM_COL,
- "weight", LB_MBOX_WEIGHT_COL,
- "style", LB_MBOX_STYLE_COL,
- "foreground", LB_MBOX_FOREGROUND_COL,
- "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
- "background", LB_MBOX_BACKGROUND_COL,
- "background-set", LB_MBOX_BACKGROUND_SET_COL,
- NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ (_("From"), renderer,
+ "text", LB_MBOX_FROM_COL,
+ "weight", LB_MBOX_WEIGHT_COL,
+ "style", LB_MBOX_STYLE_COL,
+ "foreground", LB_MBOX_FOREGROUND_COL,
+ "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
+ "background", LB_MBOX_BACKGROUND_COL,
+ "background-set", LB_MBOX_BACKGROUND_SET_COL,
+ NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
bi_apply_other_column_settings(column, TRUE, LB_MBOX_FROM_COL);
gtk_tree_view_append_column(tree_view, column);
/* Subject column--contains tree expanders */
renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes
- (_("Subject"), renderer,
- "text", LB_MBOX_SUBJECT_COL,
- "weight", LB_MBOX_WEIGHT_COL,
- "style", LB_MBOX_STYLE_COL,
- "foreground", LB_MBOX_FOREGROUND_COL,
- "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
- "background", LB_MBOX_BACKGROUND_COL,
- "background-set", LB_MBOX_BACKGROUND_SET_COL,
- NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Subject"), renderer,
+ "text", LB_MBOX_SUBJECT_COL,
+ "weight", LB_MBOX_WEIGHT_COL,
+ "style", LB_MBOX_STYLE_COL,
+ "foreground", LB_MBOX_FOREGROUND_COL,
+ "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
+ "background", LB_MBOX_BACKGROUND_COL,
+ "background-set", LB_MBOX_BACKGROUND_SET_COL,
+ NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
bi_apply_other_column_settings(column, TRUE, LB_MBOX_SUBJECT_COL);
gtk_tree_view_append_column(tree_view, column);
@@ -343,16 +358,16 @@ balsa_index_init(BalsaIndex * index)
/* Date column */
renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes
- (_("Date"), renderer,
- "text", LB_MBOX_DATE_COL,
- "weight", LB_MBOX_WEIGHT_COL,
- "style", LB_MBOX_STYLE_COL,
- "foreground", LB_MBOX_FOREGROUND_COL,
- "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
- "background", LB_MBOX_BACKGROUND_COL,
- "background-set", LB_MBOX_BACKGROUND_SET_COL,
- NULL);
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Date"), renderer,
+ "text", LB_MBOX_DATE_COL,
+ "weight", LB_MBOX_WEIGHT_COL,
+ "style", LB_MBOX_STYLE_COL,
+ "foreground", LB_MBOX_FOREGROUND_COL,
+ "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
+ "background", LB_MBOX_BACKGROUND_COL,
+ "background-set", LB_MBOX_BACKGROUND_SET_COL,
+ NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
bi_apply_other_column_settings(column, TRUE, LB_MBOX_DATE_COL);
gtk_tree_view_append_column(tree_view, column);
@@ -369,20 +384,20 @@ balsa_index_init(BalsaIndex * index)
gtk_tree_view_column_pack_start(column, renderer, FALSE);
gtk_tree_view_column_set_attributes
(column, renderer,
- "text", LB_MBOX_SIZE_COL,
- "weight", LB_MBOX_WEIGHT_COL,
- "style", LB_MBOX_STYLE_COL,
- "foreground", LB_MBOX_FOREGROUND_COL,
- "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
- "background", LB_MBOX_BACKGROUND_COL,
- "background-set", LB_MBOX_BACKGROUND_SET_COL,
- NULL);
+ "text", LB_MBOX_SIZE_COL,
+ "weight", LB_MBOX_WEIGHT_COL,
+ "style", LB_MBOX_STYLE_COL,
+ "foreground", LB_MBOX_FOREGROUND_COL,
+ "foreground-set", LB_MBOX_FOREGROUND_SET_COL,
+ "background", LB_MBOX_BACKGROUND_COL,
+ "background-set", LB_MBOX_BACKGROUND_SET_COL,
+ NULL);
bi_apply_other_column_settings(column, TRUE, LB_MBOX_SIZE_COL);
gtk_tree_view_append_column(tree_view, column);
/* Initialize some other members */
index->mailbox_node = NULL;
- index->popup_menu = bndx_popup_menu_create(index);
+ index->popup_menu = bndx_popup_menu_create(index);
g_object_ref_sink(index->popup_menu);
gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
@@ -398,7 +413,7 @@ balsa_index_init(BalsaIndex * index)
gesture = gtk_gesture_multi_press_new();
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
g_signal_connect(gesture, "pressed",
- G_CALLBACK(bndx_gesture_pressed_cb), NULL);
+ G_CALLBACK(bndx_gesture_pressed_cb), NULL);
/* We need to claim the event sequence before GtkTreeView gets it,
* so we jump in at the capture phase: */
controller = GTK_EVENT_CONTROLLER(gesture);
@@ -406,7 +421,7 @@ balsa_index_init(BalsaIndex * index)
gtk_widget_add_controller(widget, controller);
g_signal_connect(tree_view, "row-activated",
- G_CALLBACK(bndx_row_activated), NULL);
+ G_CALLBACK(bndx_row_activated), NULL);
/* catch thread expand events */
index->row_expanded_id =
@@ -439,6 +454,7 @@ balsa_index_init(BalsaIndex * index)
gtk_widget_show(widget);
}
+
/*
* Remove a GObject reference; if it was the last reference (and the
* GObject has now been finalized), clear the location and return TRUE.
@@ -457,6 +473,7 @@ bndx_clear_if_last_ref(gpointer data)
return TRUE;
}
+
/* Callbacks used by bndx_instance_init. */
/*
@@ -470,7 +487,7 @@ bndx_clear_if_last_ref(gpointer data)
/* idle callback: */
static gboolean
-bndx_selection_changed_idle(BalsaIndex * index)
+bndx_selection_changed_idle(BalsaIndex *index)
{
LibBalsaMailbox *mailbox;
guint msgno;
@@ -478,11 +495,13 @@ bndx_selection_changed_idle(BalsaIndex * index)
if (bndx_clear_if_last_ref(&index))
return FALSE;
+
index->has_selection_changed_idle = FALSE;
if (!index->mailbox_node)
return FALSE;
- mailbox = balsa_index_get_mailbox(index);
+
+ mailbox = balsa_index_get_mailbox(index);
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(index));
/* Save next_msgno, because changing flags may zero it. */
@@ -499,9 +518,9 @@ bndx_selection_changed_idle(BalsaIndex * index)
if (msgno) {
GtkTreePath *path;
- if (!libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL))
+ if (!libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL)) {
msgno = 0;
- else {
+ } else {
if (!gtk_tree_selection_path_is_selected(selection, path)) {
bndx_expand_to_row(index, path);
bndx_select_row(index, path);
@@ -524,18 +543,23 @@ bndx_selection_changed_idle(BalsaIndex * index)
return FALSE;
}
+
/* GtkTreeSelectionForeachFunc: */
static void
-bndx_selection_changed_func(GtkTreeModel * model, GtkTreePath * path,
- GtkTreeIter * iter, guint * msgno)
+bndx_selection_changed_func(GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ guint *msgno)
{
if (!*msgno)
gtk_tree_model_get(model, iter, LB_MBOX_MSGNO_COL, msgno, -1);
}
+
/* the signal handler: */
static void
-bndx_selection_changed(GtkTreeSelection * selection, BalsaIndex * index)
+bndx_selection_changed(GtkTreeSelection *selection,
+ BalsaIndex *index)
{
index->next_msgno = 0;
gtk_tree_selection_selected_foreach(selection,
@@ -582,6 +606,7 @@ bndx_selection_changed(GtkTreeSelection * selection, BalsaIndex * index)
}
}
+
static void
bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
gint n_press,
@@ -598,16 +623,16 @@ bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
gint by;
GtkTreePath *path;
- gesture = GTK_GESTURE(multi_press);
+ gesture = GTK_GESTURE(multi_press);
sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(multi_press));
- event = gtk_gesture_get_last_event(gesture, sequence);
+ event = gtk_gesture_get_last_event(gesture, sequence);
g_return_if_fail(event != NULL);
if (!gdk_event_triggers_context_menu(event))
return;
gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
- index = BALSA_INDEX(gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)));
+ index = BALSA_INDEX(gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)));
tree_view = GTK_TREE_VIEW(index);
gtk_tree_view_convert_widget_to_bin_window_coords(tree_view, (gint) x, (gint) y,
&bx, &by);
@@ -629,9 +654,12 @@ bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
bndx_do_popup(index, event);
}
+
static void
-bndx_row_activated(GtkTreeView * tree_view, GtkTreePath * path,
- GtkTreeViewColumn * column, gpointer user_data)
+bndx_row_activated(GtkTreeView *tree_view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer user_data)
{
GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
GtkTreeIter iter;
@@ -657,13 +685,16 @@ bndx_row_activated(GtkTreeView * tree_view, GtkTreePath * path,
if (sm != NULL)
g_signal_connect(sendmsg_window_get_window(sm), "destroy",
G_CALLBACK(sendmsg_window_destroy_cb), NULL);
- } else
+ } else {
message_window_new(mailbox, msgno);
+ }
}
+
static gboolean
-bndx_find_current_msgno(BalsaIndex * bindex,
- GtkTreePath ** path, GtkTreeIter * iter)
+bndx_find_current_msgno(BalsaIndex *bindex,
+ GtkTreePath **path,
+ GtkTreeIter *iter)
{
gboolean retval = FALSE;
@@ -680,15 +711,18 @@ bndx_find_current_msgno(BalsaIndex * bindex,
return retval;
}
+
/* bndx_tree_expand_cb:
* callback on expand events
* set/reset unread style, as appropriate
*/
static void
-bndx_tree_expand_cb(GtkTreeView * tree_view, GtkTreeIter * iter,
- GtkTreePath * path, gpointer user_data)
+bndx_tree_expand_cb(GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer user_data)
{
- BalsaIndex *index = BALSA_INDEX(tree_view);
+ BalsaIndex *index = BALSA_INDEX(tree_view);
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
GtkTreePath *current_path;
@@ -706,73 +740,83 @@ bndx_tree_expand_cb(GtkTreeView * tree_view, GtkTreeIter * iter,
bndx_changed_find_row(index);
}
+
/* bndx_test_collapse_row_cb:
* callback on "test-collapse-row" events
* just set collapsing, and return FALSE to allow the row (thread) to be
* collapsed. */
static gboolean
-bndx_test_collapse_row_cb(GtkTreeView * tree_view, GtkTreeIter * iter,
- GtkTreePath * path, gpointer user_data)
+bndx_test_collapse_row_cb(GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer user_data)
{
BalsaIndex *index = BALSA_INDEX(tree_view);
index->collapsing = TRUE;
return FALSE;
}
+
/* callback on collapse events;
* clear collapsing;
* the next message may have become invisible, so we must check whether
* a next message still exists. */
static void
-bndx_tree_collapse_cb(GtkTreeView * tree_view, GtkTreeIter * iter,
- GtkTreePath * path, gpointer user_data)
+bndx_tree_collapse_cb(GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer user_data)
{
BalsaIndex *index = BALSA_INDEX(tree_view);
index->collapsing = FALSE;
bndx_changed_find_row(index);
}
+
/* When a column is resized, store the new size for later use */
static void
-bndx_column_resize(GtkWidget * widget, GtkAllocation * allocation,
- gint baseline, gpointer user_data)
+bndx_column_resize(GtkWidget *widget,
+ GtkAllocation *allocation,
+ gint baseline,
+ gpointer user_data)
{
GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
balsa_app.index_num_width =
gtk_tree_view_column_get_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_MSGNO_COL));
+ (tree_view, LB_MBOX_MSGNO_COL));
balsa_app.index_status_width =
gtk_tree_view_column_get_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_MARKED_COL));
+ (tree_view, LB_MBOX_MARKED_COL));
balsa_app.index_attachment_width =
gtk_tree_view_column_get_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_ATTACH_COL));
+ (tree_view, LB_MBOX_ATTACH_COL));
balsa_app.index_from_width =
gtk_tree_view_column_get_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_FROM_COL));
+ (tree_view, LB_MBOX_FROM_COL));
balsa_app.index_subject_width =
gtk_tree_view_column_get_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_SUBJECT_COL));
+ (tree_view, LB_MBOX_SUBJECT_COL));
balsa_app.index_date_width =
gtk_tree_view_column_get_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_DATE_COL));
+ (tree_view, LB_MBOX_DATE_COL));
balsa_app.index_size_width =
gtk_tree_view_column_get_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_SIZE_COL));
+ (tree_view, LB_MBOX_SIZE_COL));
}
+
/* bndx_drag_cb
*
* This is the drag_data_get callback for the index widgets.
* Currently supports DND only within the application.
*/
static void
-bndx_drag_cb(GtkWidget * widget,
- GdkDragContext * drag_context,
- GtkSelectionData * data,
- guint time,
- gpointer user_data)
+bndx_drag_cb(GtkWidget *widget,
+ GdkDragContext *drag_context,
+ GtkSelectionData *data,
+ guint time,
+ gpointer user_data)
{
BalsaIndex *index;
@@ -781,21 +825,24 @@ bndx_drag_cb(GtkWidget * widget,
index = BALSA_INDEX(widget);
if (gtk_tree_selection_count_selected_rows
- (gtk_tree_view_get_selection(GTK_TREE_VIEW(index))) > 0)
+ (gtk_tree_view_get_selection(GTK_TREE_VIEW(index))) > 0) {
gtk_selection_data_set(data, gtk_selection_data_get_target(data),
8, (const guchar *) &index,
sizeof(BalsaIndex *));
+ }
}
+
/* Public methods */
GtkWidget *
balsa_index_new(void)
{
- BalsaIndex* index = g_object_new(BALSA_TYPE_INDEX, NULL);
+ BalsaIndex *index = g_object_new(BALSA_TYPE_INDEX, NULL);
return GTK_WIDGET(index);
}
+
/**
* balsa_index_scroll_on_open() moves to the first unread message in
* the index, or the last message if none is unread, and selects
@@ -820,8 +867,8 @@ bndx_scroll_on_open_idle(BalsaIndex *index)
balsa_index_update_tree(index, balsa_app.expand_tree);
mailbox = balsa_index_get_mailbox(index);
if ((msgno = libbalsa_mailbox_get_first_unread(mailbox))) {
- libbalsa_mailbox_set_first_unread(mailbox, 0);
- if(!libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL))
+ libbalsa_mailbox_set_first_unread(mailbox, 0);
+ if (!libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL))
return FALSE; /* Oops! */
} else {
/* we want to scroll to the last one in current order. The
@@ -829,9 +876,10 @@ bndx_scroll_on_open_idle(BalsaIndex *index)
delivered does not feel natural when other sorting order is
used */
int total = gtk_tree_model_iter_n_children
- (GTK_TREE_MODEL(mailbox), NULL);
- if(total == 0)
+ (GTK_TREE_MODEL(mailbox), NULL);
+ if (total == 0)
return FALSE;
+
path = gtk_tree_path_new_from_indices(total - 1, -1);
}
@@ -844,9 +892,9 @@ bndx_scroll_on_open_idle(BalsaIndex *index)
if (gtk_tree_view_get_model(tree_view)) {
if ((view_on_open && GPOINTER_TO_INT(view_on_open))
- || balsa_app.view_message_on_open)
+ || balsa_app.view_message_on_open) {
bndx_select_row(index, path);
- else {
+ } else {
GtkTreeSelection *selection;
gulong changed_id = index->selection_changed_id;
@@ -862,8 +910,9 @@ bndx_scroll_on_open_idle(BalsaIndex *index)
return FALSE;
}
+
void
-balsa_index_scroll_on_open(BalsaIndex * bindex)
+balsa_index_scroll_on_open(BalsaIndex *bindex)
{
/* Scroll in an idle handler, because the mailbox is perhaps being
* opened in its own idle handler. */
@@ -871,14 +920,15 @@ balsa_index_scroll_on_open(BalsaIndex * bindex)
g_object_ref(bindex));
}
+
static LibBalsaCondition *cond_undeleted;
/* Callback for the mailbox's "row-inserted" signal; queue an idle
* handler to expand the thread. */
struct bndx_mailbox_row_inserted_info {
LibBalsaMailbox *mailbox;
- guint msgno;
- BalsaIndex *index;
+ guint msgno;
+ BalsaIndex *index;
};
static gboolean
@@ -896,9 +946,12 @@ bndx_mailbox_row_inserted_idle(struct bndx_mailbox_row_inserted_info *info)
return FALSE;
}
+
static void
-bndx_mailbox_row_inserted_cb(LibBalsaMailbox * mailbox, GtkTreePath * path,
- GtkTreeIter * iter, BalsaIndex * index)
+bndx_mailbox_row_inserted_cb(LibBalsaMailbox *mailbox,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ BalsaIndex *index)
{
guint msgno;
@@ -915,24 +968,25 @@ bndx_mailbox_row_inserted_cb(LibBalsaMailbox * mailbox, GtkTreePath * path,
LIBBALSA_MESSAGE_FLAG_UNREAD,
0))
#endif /* BALSA_EXPAND_TO_NEW_UNREAD_MESSAGE */
- )
- {
- struct bndx_mailbox_row_inserted_info *info =
- g_new(struct bndx_mailbox_row_inserted_info, 1);
- info->mailbox = mailbox;
- g_object_ref(mailbox);
- info->index = index;
- g_object_ref(index);
- info->msgno = msgno;
- g_idle_add_full(G_PRIORITY_LOW, /* to run after threading */
- (GSourceFunc) bndx_mailbox_row_inserted_idle,
- info, NULL);
+ ) {
+ struct bndx_mailbox_row_inserted_info *info =
+ g_new(struct bndx_mailbox_row_inserted_info, 1);
+ info->mailbox = mailbox;
+ g_object_ref(mailbox);
+ info->index = index;
+ g_object_ref(index);
+ info->msgno = msgno;
+ g_idle_add_full(G_PRIORITY_LOW, /* to run after threading */
+ (GSourceFunc) bndx_mailbox_row_inserted_idle,
+ info, NULL);
}
}
+
static void
-bndx_mailbox_message_expunged_cb(LibBalsaMailbox * mailbox, guint msgno,
- BalsaIndex * bindex)
+bndx_mailbox_message_expunged_cb(LibBalsaMailbox *mailbox,
+ guint msgno,
+ BalsaIndex *bindex)
{
if (bindex->current_msgno == msgno)
bindex->current_msgno = 0;
@@ -945,14 +999,15 @@ bndx_mailbox_message_expunged_cb(LibBalsaMailbox * mailbox, guint msgno,
--bindex->next_msgno;
}
+
/* balsa_index_load_mailbox_node:
*
* mbnode->mailbox is already open
*/
gboolean
-balsa_index_load_mailbox_node(BalsaIndex * index,
- BalsaMailboxNode* mbnode)
+balsa_index_load_mailbox_node(BalsaIndex *index,
+ BalsaMailboxNode *mbnode)
{
GtkTreeView *tree_view;
LibBalsaMailbox *mailbox;
@@ -975,7 +1030,7 @@ balsa_index_load_mailbox_node(BalsaIndex * index,
tree_view = GTK_TREE_VIEW(index);
if (libbalsa_mailbox_get_show(mailbox) == LB_MAILBOX_SHOW_TO) {
GtkTreeViewColumn *column =
- gtk_tree_view_get_column(tree_view, LB_MBOX_FROM_COL);
+ gtk_tree_view_get_column(tree_view, LB_MBOX_FROM_COL);
index->filter_no = 1; /* FIXME: this is hack! */
gtk_tree_view_column_set_title(column, _("To"));
}
@@ -994,19 +1049,21 @@ balsa_index_load_mailbox_node(BalsaIndex * index,
gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(mailbox));
/* Create a search-iter for SEARCH UNDELETED. */
- if (!cond_undeleted)
+ if (!cond_undeleted) {
cond_undeleted =
libbalsa_condition_new_flag_enum(TRUE,
LIBBALSA_MESSAGE_FLAG_DELETED);
+ }
index->search_iter = libbalsa_mailbox_search_iter_new(cond_undeleted);
/* Note when this mailbox was opened, for use in auto-closing. */
- balsa_mailbox_node_set_last_use(index->mailbox_node);
+ balsa_index_set_last_use(index);
return FALSE;
}
+
void
-balsa_index_set_width_preference(BalsaIndex *bindex,
+balsa_index_set_width_preference(BalsaIndex *bindex,
BalsaIndexWidthPreference pref)
{
GtkTreeView *tree_view;
@@ -1017,9 +1074,12 @@ balsa_index_set_width_preference(BalsaIndex *bindex,
bindex->width_preference = pref;
switch (pref) {
- case BALSA_INDEX_NARROW: visible = FALSE; break;
+ case BALSA_INDEX_NARROW: visible = FALSE;
+ break;
+
default:
- case BALSA_INDEX_WIDE: visible = TRUE; break;
+ case BALSA_INDEX_WIDE: visible = TRUE;
+ break;
}
tree_view = GTK_TREE_VIEW(bindex);
@@ -1031,6 +1091,7 @@ balsa_index_set_width_preference(BalsaIndex *bindex,
(gtk_tree_view_get_column(tree_view, LB_MBOX_SIZE_COL), visible);
}
+
/*
* select message interfaces
*
@@ -1089,24 +1150,27 @@ typedef enum {
} BndxSearchWrap;
static gboolean
-bndx_find_root(BalsaIndex * index, GtkTreeIter * iter)
+bndx_find_root(BalsaIndex *index,
+ GtkTreeIter *iter)
{
GtkTreeView *tree_view = GTK_TREE_VIEW(index);
- GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
+ GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
if (!model || !gtk_tree_model_get_iter_first(model, iter))
- return FALSE;
+ return FALSE;
iter->user_data = NULL;
return TRUE;
}
+
static gboolean
-bndx_search_iter(BalsaIndex * index,
- LibBalsaMailboxSearchIter * search_iter,
- GtkTreeIter * iter,
- BndxSearchDirection direction,
- BndxSearchViewable viewable, guint stop_msgno)
+bndx_search_iter(BalsaIndex *index,
+ LibBalsaMailboxSearchIter *search_iter,
+ GtkTreeIter *iter,
+ BndxSearchDirection direction,
+ BndxSearchViewable viewable,
+ guint stop_msgno)
{
LibBalsaMailbox *mailbox;
gboolean found;
@@ -1126,7 +1190,7 @@ bndx_search_iter(BalsaIndex * index,
if (viewable == BNDX_SEARCH_VIEWABLE_ANY)
break;
- path = gtk_tree_model_get_path(GTK_TREE_MODEL(mailbox), iter);
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL(mailbox), iter);
found = bndx_row_is_viewable(index, path);
gtk_tree_path_free(path);
} while (!found);
@@ -1134,13 +1198,14 @@ bndx_search_iter(BalsaIndex * index,
return found;
}
+
static gboolean
-bndx_search_iter_and_select(BalsaIndex * index,
- LibBalsaMailboxSearchIter * search_iter,
- BndxSearchDirection direction,
- BndxSearchViewable viewable,
- BndxSearchStart start,
- BndxSearchWrap wrap)
+bndx_search_iter_and_select(BalsaIndex *index,
+ LibBalsaMailboxSearchIter *search_iter,
+ BndxSearchDirection direction,
+ BndxSearchViewable viewable,
+ BndxSearchStart start,
+ BndxSearchWrap wrap)
{
LibBalsaMailbox *mailbox;
GtkTreeIter iter;
@@ -1148,15 +1213,15 @@ bndx_search_iter_and_select(BalsaIndex * index,
mailbox = balsa_index_get_mailbox(index);
- if (!((index->next_msgno > 0
+ if (!(((index->next_msgno > 0)
&& libbalsa_mailbox_msgno_find(mailbox, index->next_msgno,
NULL, &iter))
- || (start == BNDX_SEARCH_START_ANY
+ || ((start == BNDX_SEARCH_START_ANY)
&& bndx_find_root(index, &iter))))
return FALSE;
stop_msgno = 0;
- if (wrap == BNDX_SEARCH_WRAP_YES && index->next_msgno)
+ if ((wrap == BNDX_SEARCH_WRAP_YES) && index->next_msgno)
stop_msgno = index->next_msgno;
if (!bndx_search_iter(index, search_iter, &iter, direction, viewable,
stop_msgno))
@@ -1166,20 +1231,22 @@ bndx_search_iter_and_select(BalsaIndex * index,
return TRUE;
}
+
void
-balsa_index_select_next(BalsaIndex * index)
+balsa_index_select_next(BalsaIndex *index)
{
g_return_if_fail(BALSA_IS_INDEX(index));
bndx_search_iter_and_select(index, index->search_iter,
- BNDX_SEARCH_DIRECTION_NEXT,
- BNDX_SEARCH_VIEWABLE_ONLY,
- BNDX_SEARCH_START_CURRENT,
- BNDX_SEARCH_WRAP_NO);
+ BNDX_SEARCH_DIRECTION_NEXT,
+ BNDX_SEARCH_VIEWABLE_ONLY,
+ BNDX_SEARCH_START_CURRENT,
+ BNDX_SEARCH_WRAP_NO);
}
+
static void
-bndx_select_next_threaded(BalsaIndex * index)
+bndx_select_next_threaded(BalsaIndex *index)
{
/* Make sure we start at the current message: */
index->next_msgno = index->current_msgno;
@@ -1193,45 +1260,51 @@ bndx_select_next_threaded(BalsaIndex * index)
BNDX_SEARCH_DIRECTION_PREV,
BNDX_SEARCH_VIEWABLE_ONLY,
BNDX_SEARCH_START_CURRENT,
- BNDX_SEARCH_WRAP_NO))
- /* Nowhere to go--unselect current, so it can be filtered out of
- * the view. */
+ BNDX_SEARCH_WRAP_NO)) {
+ /* Nowhere to go--unselect current, so it can be filtered out of
+ * the view. */
gtk_tree_selection_unselect_all(gtk_tree_view_get_selection
- (GTK_TREE_VIEW(index)));
+ (GTK_TREE_VIEW(index)));
+ }
}
+
void
-balsa_index_select_previous(BalsaIndex * index)
+balsa_index_select_previous(BalsaIndex *index)
{
g_return_if_fail(BALSA_IS_INDEX(index));
bndx_search_iter_and_select(index, index->search_iter,
- BNDX_SEARCH_DIRECTION_PREV,
- BNDX_SEARCH_VIEWABLE_ONLY,
- BNDX_SEARCH_START_CURRENT,
- BNDX_SEARCH_WRAP_NO);
+ BNDX_SEARCH_DIRECTION_PREV,
+ BNDX_SEARCH_VIEWABLE_ONLY,
+ BNDX_SEARCH_START_CURRENT,
+ BNDX_SEARCH_WRAP_NO);
}
+
void
-balsa_index_find(BalsaIndex * index,
- LibBalsaMailboxSearchIter * search_iter,
- gboolean previous, gboolean wrap)
+balsa_index_find(BalsaIndex *index,
+ LibBalsaMailboxSearchIter *search_iter,
+ gboolean previous,
+ gboolean wrap)
{
g_return_if_fail(BALSA_IS_INDEX(index));
bndx_search_iter_and_select(index, search_iter,
- (previous ?
- BNDX_SEARCH_DIRECTION_PREV :
- BNDX_SEARCH_DIRECTION_NEXT),
- BNDX_SEARCH_VIEWABLE_ANY,
- BNDX_SEARCH_START_ANY,
- (wrap ?
- BNDX_SEARCH_WRAP_YES :
- BNDX_SEARCH_WRAP_NO));
+ (previous ?
+ BNDX_SEARCH_DIRECTION_PREV :
+ BNDX_SEARCH_DIRECTION_NEXT),
+ BNDX_SEARCH_VIEWABLE_ANY,
+ BNDX_SEARCH_START_ANY,
+ (wrap ?
+ BNDX_SEARCH_WRAP_YES :
+ BNDX_SEARCH_WRAP_NO));
}
+
static gboolean
-bndx_select_next_with_flag(BalsaIndex * index, LibBalsaMessageFlag flag)
+bndx_select_next_with_flag(BalsaIndex *index,
+ LibBalsaMessageFlag flag)
{
LibBalsaCondition *cond_flag, *cond_and;
LibBalsaMailboxSearchIter *search_iter;
@@ -1240,7 +1313,7 @@ bndx_select_next_with_flag(BalsaIndex * index, LibBalsaMessageFlag flag)
g_assert(BALSA_IS_INDEX(index));
cond_flag = libbalsa_condition_new_flag_enum(FALSE, flag);
- cond_and =
+ cond_and =
libbalsa_condition_new_bool_ptr(FALSE, CONDITION_AND, cond_flag,
cond_undeleted);
libbalsa_condition_unref(cond_flag);
@@ -1259,34 +1332,40 @@ bndx_select_next_with_flag(BalsaIndex * index, LibBalsaMessageFlag flag)
return retval;
}
+
gboolean
-balsa_index_select_next_unread(BalsaIndex * index)
+balsa_index_select_next_unread(BalsaIndex *index)
{
g_return_val_if_fail(BALSA_IS_INDEX(index), FALSE);
return bndx_select_next_with_flag(index, LIBBALSA_MESSAGE_FLAG_NEW);
}
+
void
-balsa_index_select_next_flagged(BalsaIndex * index)
+balsa_index_select_next_flagged(BalsaIndex *index)
{
g_return_if_fail(BALSA_IS_INDEX(index));
bndx_select_next_with_flag(index, LIBBALSA_MESSAGE_FLAG_FLAGGED);
}
+
void
-balsa_index_set_next_msgno(BalsaIndex * bindex, guint msgno)
+balsa_index_set_next_msgno(BalsaIndex *bindex,
+ guint msgno)
{
bindex->next_msgno = msgno;
}
+
guint
-balsa_index_get_next_msgno(BalsaIndex * bindex)
+balsa_index_get_next_msgno(BalsaIndex *bindex)
{
return bindex->next_msgno;
}
+
/* bndx_expand_to_row_and_select:
* make sure it's viewable, then pass it to bndx_select_row
* no-op if it's NULL
@@ -1294,7 +1373,8 @@ balsa_index_get_next_msgno(BalsaIndex * bindex)
* Note: iter must be valid; it isn't checked here.
*/
static void
-bndx_expand_to_row_and_select(BalsaIndex * index, GtkTreeIter * iter)
+bndx_expand_to_row_and_select(BalsaIndex *index,
+ GtkTreeIter *iter)
{
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(index));
GtkTreePath *path;
@@ -1305,49 +1385,51 @@ bndx_expand_to_row_and_select(BalsaIndex * index, GtkTreeIter * iter)
gtk_tree_path_free(path);
}
+
/* End of select message interfaces. */
void
-balsa_index_set_column_widths(BalsaIndex * index)
+balsa_index_set_column_widths(BalsaIndex *index)
{
GtkTreeView *tree_view = GTK_TREE_VIEW(index);
- gint icon_w = 16;
+ gint icon_w = 16;
#if defined(TREE_VIEW_FIXED_HEIGHT)
/* so that fixed width works properly */
gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_MSGNO_COL),
+ (tree_view, LB_MBOX_MSGNO_COL),
bndx_string_width("00000"));
#endif
/* I have no idea why we must add 5 pixels to the icon width - otherwise,
the icon will be clipped... */
gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_MARKED_COL),
+ (tree_view, LB_MBOX_MARKED_COL),
icon_w + 5);
gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_ATTACH_COL),
+ (tree_view, LB_MBOX_ATTACH_COL),
icon_w + 5);
gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_FROM_COL),
+ (tree_view, LB_MBOX_FROM_COL),
balsa_app.index_from_width);
gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_SUBJECT_COL),
+ (tree_view, LB_MBOX_SUBJECT_COL),
balsa_app.index_subject_width);
gtk_tree_view_column_set_fixed_width(gtk_tree_view_get_column
- (tree_view, LB_MBOX_DATE_COL),
+ (tree_view, LB_MBOX_DATE_COL),
balsa_app.index_date_width);
}
+
/* Mailbox Callbacks... */
/* bndx_mailbox_changed_cb : callback for sync with backend; the signal
is emitted by the mailbox when new messages has been retrieved (either
after opening the mailbox, or after "check new messages").
-*/
+ */
/* bndx_mailbox_changed_cb:
may be called from a thread. Use idle callback to update the view.
-*/
+ */
static gboolean
bndx_queue_draw_idle_cb(gpointer bindex)
@@ -1358,8 +1440,9 @@ bndx_queue_draw_idle_cb(gpointer bindex)
return FALSE;
}
+
static gboolean
-bndx_mailbox_changed_idle(BalsaIndex * bindex)
+bndx_mailbox_changed_idle(BalsaIndex *bindex)
{
LibBalsaMailbox *mailbox;
guint msgno;
@@ -1371,7 +1454,7 @@ bndx_mailbox_changed_idle(BalsaIndex * bindex)
bindex->has_mailbox_changed_idle = FALSE;
mailbox = balsa_index_get_mailbox(bindex);
- if ((msgno = libbalsa_mailbox_get_first_unread(mailbox)) > 0
+ if (((msgno = libbalsa_mailbox_get_first_unread(mailbox)) > 0)
&& libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL)) {
bndx_expand_to_row(bindex, path);
gtk_tree_path_free(path);
@@ -1393,8 +1476,10 @@ bndx_mailbox_changed_idle(BalsaIndex * bindex)
return FALSE;
}
+
static void
-bndx_mailbox_changed_cb(LibBalsaMailbox * mailbox, BalsaIndex * bindex)
+bndx_mailbox_changed_cb(LibBalsaMailbox *mailbox,
+ BalsaIndex *bindex)
{
if (!gtk_widget_get_realized(GTK_WIDGET(bindex)))
return;
@@ -1418,9 +1503,12 @@ bndx_mailbox_changed_cb(LibBalsaMailbox * mailbox, BalsaIndex * bindex)
g_object_ref(bindex));
}
+
static void
-bndx_selected_msgnos_func(GtkTreeModel * model, GtkTreePath * path,
- GtkTreeIter * iter, GArray * msgnos)
+bndx_selected_msgnos_func(GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ GArray *msgnos)
{
guint msgno;
@@ -1428,11 +1516,12 @@ bndx_selected_msgnos_func(GtkTreeModel * model, GtkTreePath * path,
g_array_append_val(msgnos, msgno);
}
+
GArray *
-balsa_index_selected_msgnos_new(BalsaIndex * index)
+balsa_index_selected_msgnos_new(BalsaIndex *index)
{
- GArray *msgnos = g_array_new(FALSE, FALSE, sizeof(guint));
- GtkTreeView *tree_view = GTK_TREE_VIEW(index);
+ GArray *msgnos = g_array_new(FALSE, FALSE, sizeof(guint));
+ GtkTreeView *tree_view = GTK_TREE_VIEW(index);
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
LibBalsaMailbox *mailbox;
@@ -1446,8 +1535,10 @@ balsa_index_selected_msgnos_new(BalsaIndex * index)
return msgnos;
}
+
void
-balsa_index_selected_msgnos_free(BalsaIndex * index, GArray * msgnos)
+balsa_index_selected_msgnos_free(BalsaIndex *index,
+ GArray *msgnos)
{
LibBalsaMailbox *mailbox;
@@ -1456,6 +1547,7 @@ balsa_index_selected_msgnos_free(BalsaIndex * index, GArray * msgnos)
g_array_free(msgnos, TRUE);
}
+
static void
bndx_view_source(gpointer data)
{
@@ -1465,18 +1557,18 @@ bndx_view_source(gpointer data)
GArray *selected;
selected = balsa_index_selected_msgnos_new(index);
- mailbox = balsa_index_get_mailbox(index);
+ mailbox = balsa_index_get_mailbox(index);
for (i = 0; i < selected->len; i++) {
- guint msgno = g_array_index(selected, guint, i);
+ guint msgno = g_array_index(selected, guint, i);
LibBalsaMessage *message =
libbalsa_mailbox_get_message(mailbox, msgno);
if (!message)
continue;
- libbalsa_show_message_source(balsa_app.application,
+ libbalsa_show_message_source(balsa_app.application,
message, balsa_app.message_font,
- &balsa_app.source_escape_specials,
+ &balsa_app.source_escape_specials,
&balsa_app.source_width,
&balsa_app.source_height);
g_object_unref(message);
@@ -1484,6 +1576,7 @@ bndx_view_source(gpointer data)
balsa_index_selected_msgnos_free(index, selected);
}
+
static void
bndx_store_address(gpointer data)
{
@@ -1493,9 +1586,12 @@ bndx_store_address(gpointer data)
g_list_free_full(messages, g_object_unref);
}
+
static void
-balsa_index_selected_list_func(GtkTreeModel * model, GtkTreePath * path,
- GtkTreeIter * iter, gpointer data)
+balsa_index_selected_list_func(GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
{
GList **list = data;
guint msgno;
@@ -1505,16 +1601,18 @@ balsa_index_selected_list_func(GtkTreeModel * model, GtkTreePath * path,
message = libbalsa_mailbox_get_message(LIBBALSA_MAILBOX(model), msgno);
if (!message)
return;
+
*list = g_list_prepend(*list, message);
}
+
/*
* balsa_index_selected_list: create a GList of selected messages
*
* Free with g_list_foreach(l,g_object_unref)/g_list_free.
*/
GList *
-balsa_index_selected_list(BalsaIndex * index)
+balsa_index_selected_list(BalsaIndex *index)
{
GtkTreeSelection *selection =
gtk_tree_view_get_selection(GTK_TREE_VIEW(index));
@@ -1527,32 +1625,36 @@ balsa_index_selected_list(BalsaIndex * index)
return list;
}
+
/*
* bndx_compose_foreach: create a compose window for each selected
* message
*/
static void
-bndx_compose_foreach(BalsaIndex * index, SendType send_type)
+bndx_compose_foreach(BalsaIndex *index,
+ SendType send_type)
{
GArray *selected;
LibBalsaMailbox *mailbox;
guint i;
selected = balsa_index_selected_msgnos_new(index);
- mailbox = balsa_index_get_mailbox(index);
+ mailbox = balsa_index_get_mailbox(index);
for (i = 0; i < selected->len; i++) {
guint msgno = g_array_index(selected, guint, i);
BalsaSendmsg *sm;
- switch(send_type) {
+ switch (send_type) {
case SEND_REPLY:
case SEND_REPLY_ALL:
case SEND_REPLY_GROUP:
sm = sendmsg_window_reply(mailbox, msgno, send_type);
break;
+
case SEND_CONTINUE:
sm = sendmsg_window_continue(mailbox, msgno);
break;
+
default:
g_assert_not_reached();
sm = NULL; /** silence invalid warnings */
@@ -1564,6 +1666,7 @@ bndx_compose_foreach(BalsaIndex * index, SendType send_type)
balsa_index_selected_msgnos_free(index, selected);
}
+
/*
* Public `reply' methods
*/
@@ -1573,37 +1676,42 @@ balsa_message_reply(gpointer user_data)
bndx_compose_foreach(BALSA_INDEX (user_data), SEND_REPLY);
}
+
void
balsa_message_replytoall(gpointer user_data)
{
bndx_compose_foreach(BALSA_INDEX (user_data), SEND_REPLY_ALL);
}
+
void
balsa_message_replytogroup(gpointer user_data)
{
bndx_compose_foreach(BALSA_INDEX (user_data), SEND_REPLY_GROUP);
}
+
void
balsa_message_continue(gpointer user_data)
{
bndx_compose_foreach(BALSA_INDEX (user_data), SEND_CONTINUE);
}
+
/*
* bndx_compose_from_list: create a single compose window for the
* selected messages
*/
static void
-bndx_compose_from_list(BalsaIndex * index, SendType send_type)
+bndx_compose_from_list(BalsaIndex *index,
+ SendType send_type)
{
GArray *selected;
LibBalsaMailbox *mailbox;
BalsaSendmsg *sm;
selected = balsa_index_selected_msgnos_new(index);
- mailbox = balsa_index_get_mailbox(index);
+ mailbox = balsa_index_get_mailbox(index);
sm = sendmsg_window_new_from_list(mailbox, selected, send_type);
@@ -1612,6 +1720,7 @@ bndx_compose_from_list(BalsaIndex * index, SendType send_type)
G_CALLBACK(sendmsg_window_destroy_cb), NULL);
}
+
/*
* Public forwarding methods
*/
@@ -1621,12 +1730,14 @@ balsa_message_forward_attached(gpointer user_data)
bndx_compose_from_list(BALSA_INDEX(user_data), SEND_FORWARD_ATTACH);
}
+
void
balsa_message_forward_inline(gpointer user_data)
{
bndx_compose_from_list(BALSA_INDEX(user_data), SEND_FORWARD_INLINE);
}
+
void
balsa_message_forward_default(gpointer user_data)
{
@@ -1635,11 +1746,13 @@ balsa_message_forward_default(gpointer user_data)
SEND_FORWARD_ATTACH : SEND_FORWARD_INLINE);
}
+
/*
* bndx_do_delete: helper for message delete methods
*/
static void
-bndx_do_delete(BalsaIndex* index, gboolean move_to_trash)
+bndx_do_delete(BalsaIndex *index,
+ gboolean move_to_trash)
{
BalsaIndex *trash;
GArray *selected;
@@ -1647,42 +1760,43 @@ bndx_do_delete(BalsaIndex* index, gboolean move_to_trash)
LibBalsaMailbox *mailbox;
guint i;
- trash = balsa_find_index_by_mailbox(balsa_app.trash);
+ trash = balsa_find_index_by_mailbox(balsa_app.trash);
selected = balsa_index_selected_msgnos_new(index);
- mailbox = balsa_index_get_mailbox(index);
+ mailbox = balsa_index_get_mailbox(index);
messages = g_array_new(FALSE, FALSE, sizeof(guint));
for (i = 0; i < selected->len; i++) {
guint msgno = g_array_index(selected, guint, i);
- if (libbalsa_mailbox_msgno_has_flags(mailbox, msgno, 0,
+ if (libbalsa_mailbox_msgno_has_flags(mailbox, msgno, 0,
LIBBALSA_MESSAGE_FLAG_DELETED))
g_array_append_val(messages, msgno);
}
if (messages->len) {
- if (move_to_trash && (index != trash)) {
+ if (move_to_trash && (index != trash)) {
GError *err = NULL;
- if(!libbalsa_mailbox_messages_move(mailbox, messages,
- balsa_app.trash, &err)) {
+ if (!libbalsa_mailbox_messages_move(mailbox, messages,
+ balsa_app.trash, &err)) {
balsa_information_parented(GTK_WINDOW(balsa_app.main_window),
LIBBALSA_INFORMATION_ERROR,
_("Move to Trash failed: %s"),
err ? err->message : "?");
g_clear_error(&err);
}
- enable_empty_trash(balsa_app.main_window, TRASH_FULL);
- } else {
+ enable_empty_trash(balsa_app.main_window, TRASH_FULL);
+ } else {
libbalsa_mailbox_messages_change_flags
- (mailbox, messages, LIBBALSA_MESSAGE_FLAG_DELETED,
- (LibBalsaMessageFlag) 0);
- if (index == trash)
- enable_empty_trash(balsa_app.main_window, TRASH_CHECK);
- }
+ (mailbox, messages, LIBBALSA_MESSAGE_FLAG_DELETED,
+ (LibBalsaMessageFlag) 0);
+ if (index == trash)
+ enable_empty_trash(balsa_app.main_window, TRASH_CHECK);
+ }
}
g_array_free(messages, TRUE);
balsa_index_selected_msgnos_free(index, selected);
}
+
/*
* Public message delete methods
*/
@@ -1696,11 +1810,12 @@ balsa_message_move_to_trash(gpointer user_data)
bndx_do_delete(index, TRUE);
/* Note when message was flagged as deleted, for use in
* auto-expunge. */
- balsa_mailbox_node_set_last_use(index->mailbox_node);
+ balsa_index_set_last_use(index);
}
+
gint
-balsa_find_notebook_page_num(LibBalsaMailbox * mailbox)
+balsa_find_notebook_page_num(LibBalsaMailbox *mailbox)
{
GtkWidget *page;
gint i;
@@ -1710,12 +1825,12 @@ balsa_find_notebook_page_num(LibBalsaMailbox * mailbox)
for (i = 0;
(page =
- gtk_notebook_get_nth_page(GTK_NOTEBOOK(balsa_app.notebook), i));
+ gtk_notebook_get_nth_page(GTK_NOTEBOOK(balsa_app.notebook), i));
i++) {
GtkWidget *index = gtk_bin_get_child(GTK_BIN(page));
- if (index != NULL &&
- balsa_index_get_mailbox(BALSA_INDEX(index)) == mailbox)
+ if ((index != NULL) &&
+ (balsa_index_get_mailbox(BALSA_INDEX(index)) == mailbox))
return i;
}
@@ -1723,11 +1838,13 @@ balsa_find_notebook_page_num(LibBalsaMailbox * mailbox)
return -1;
}
+
/* This function toggles the given attribute of a list of messages,
using given callback.
*/
void
-balsa_index_toggle_flag(BalsaIndex* index, LibBalsaMessageFlag flag)
+balsa_index_toggle_flag(BalsaIndex *index,
+ LibBalsaMessageFlag flag)
{
LibBalsaMailbox *mailbox;
int is_all_flagged = TRUE;
@@ -1735,15 +1852,15 @@ balsa_index_toggle_flag(BalsaIndex* index, LibBalsaMessageFlag flag)
guint i;
selected = balsa_index_selected_msgnos_new(index);
- mailbox = balsa_index_get_mailbox(index);
+ mailbox = balsa_index_get_mailbox(index);
/* First see if we should set given flag or unset */
for (i = 0; i < selected->len; i++) {
guint msgno = g_array_index(selected, guint, i);
if (libbalsa_mailbox_msgno_has_flags(mailbox, msgno, 0, flag)) {
- is_all_flagged = FALSE;
- break;
- }
+ is_all_flagged = FALSE;
+ break;
+ }
}
libbalsa_mailbox_messages_change_flags(mailbox, selected,
@@ -1752,13 +1869,15 @@ balsa_index_toggle_flag(BalsaIndex* index, LibBalsaMessageFlag flag)
balsa_index_selected_msgnos_free(index, selected);
if (flag == LIBBALSA_MESSAGE_FLAG_DELETED)
- /* Note when deleted flag was changed, for use in
- * auto-expunge. */
- balsa_mailbox_node_set_last_use(index->mailbox_node);
+ /* Note when deleted flag was changed, for use in
+ * auto-expunge. */
+ balsa_index_set_last_use(index);
}
+
static void
-bi_toggle_deleted_cb(gpointer user_data, GtkWidget * widget)
+bi_toggle_deleted_cb(gpointer user_data,
+ GtkWidget *widget)
{
BalsaIndex *index;
GArray *selected;
@@ -1769,20 +1888,21 @@ bi_toggle_deleted_cb(gpointer user_data, GtkWidget * widget)
balsa_index_toggle_flag(index, LIBBALSA_MESSAGE_FLAG_DELETED);
selected = balsa_index_selected_msgnos_new(index);
- if (widget == index->undelete_item && selected->len > 0) {
- LibBalsaMailbox *mailbox;
+ if ((widget == index->undelete_item) && (selected->len > 0)) {
+ LibBalsaMailbox *mailbox;
guint msgno = g_array_index(selected, guint, 0);
- mailbox = balsa_index_get_mailbox(index);
+ mailbox = balsa_index_get_mailbox(index);
if (libbalsa_mailbox_msgno_has_flags(mailbox, msgno,
LIBBALSA_MESSAGE_FLAG_DELETED,
- 0))
- /* Oops! */
- balsa_index_toggle_flag(index, LIBBALSA_MESSAGE_FLAG_DELETED);
+ 0))
+ /* Oops! */
+ balsa_index_toggle_flag(index, LIBBALSA_MESSAGE_FLAG_DELETED);
}
balsa_index_selected_msgnos_free(index, selected);
}
+
/* This function toggles the FLAGGED attribute of a list of messages
*/
static void
@@ -1794,6 +1914,7 @@ bi_toggle_flagged_cb(gpointer user_data)
LIBBALSA_MESSAGE_FLAG_FLAGGED);
}
+
static void
bi_toggle_new_cb(gpointer user_data)
{
@@ -1805,7 +1926,8 @@ bi_toggle_new_cb(gpointer user_data)
static void
-mru_menu_cb(const gchar * url, BalsaIndex * index)
+mru_menu_cb(const gchar *url,
+ BalsaIndex *index)
{
LibBalsaMailbox *mailbox = balsa_find_mailbox_by_url(url);
@@ -1818,39 +1940,49 @@ mru_menu_cb(const gchar * url, BalsaIndex * index)
}
}
+
/*
* bndx_popup_menu_create: create the popup menu at init time
*/
static GtkWidget *
-bndx_popup_menu_create(BalsaIndex * index)
+bndx_popup_menu_create(BalsaIndex *index)
{
- static const struct { /* this is a invariable part of */
- const char *icon, *label; /* the context message menu. */
- GCallback func;
+ static const struct { /* this is a invariable part of */
+ const char *icon, *label; /* the context message menu. */
+ GCallback func;
} entries[] = {
{
- BALSA_PIXMAP_REPLY, N_("_Reply…"),
- G_CALLBACK(balsa_message_reply)}, {
- BALSA_PIXMAP_REPLY_ALL, N_("Reply To _All…"),
- G_CALLBACK(balsa_message_replytoall)}, {
- BALSA_PIXMAP_REPLY_GROUP, N_("Reply To _Group…"),
- G_CALLBACK(balsa_message_replytogroup)}, {
- BALSA_PIXMAP_FORWARD, N_("_Forward Attached…"),
- G_CALLBACK(balsa_message_forward_attached)}, {
- BALSA_PIXMAP_FORWARD, N_("Forward _Inline…"),
- G_CALLBACK(balsa_message_forward_inline)}, {
- NULL, N_("_Pipe through…"),
- G_CALLBACK(balsa_index_pipe)}, {
- BALSA_PIXMAP_BOOK_RED, N_("_Store Address…"),
- G_CALLBACK(bndx_store_address)}};
+ BALSA_PIXMAP_REPLY, N_("_Reply…"),
+ G_CALLBACK(balsa_message_reply)
+ },{
+ BALSA_PIXMAP_REPLY_ALL, N_("Reply To _All…"),
+ G_CALLBACK(balsa_message_replytoall)
+ },{
+ BALSA_PIXMAP_REPLY_GROUP, N_("Reply To _Group…"),
+ G_CALLBACK(balsa_message_replytogroup)
+ },{
+ BALSA_PIXMAP_FORWARD, N_("_Forward Attached…"),
+ G_CALLBACK(balsa_message_forward_attached)
+ },{
+ BALSA_PIXMAP_FORWARD, N_("Forward _Inline…"),
+ G_CALLBACK(balsa_message_forward_inline)
+ },{
+ NULL, N_("_Pipe through…"),
+ G_CALLBACK(balsa_index_pipe)
+ },{
+ BALSA_PIXMAP_BOOK_RED, N_("_Store Address…"),
+ G_CALLBACK(bndx_store_address)
+ }
+ };
GtkWidget *menu, *menuitem, *submenu;
unsigned i;
menu = gtk_menu_new();
- for (i = 0; i < G_N_ELEMENTS(entries); i++)
+ for (i = 0; i < G_N_ELEMENTS(entries); i++) {
create_stock_menu_item(menu, _(entries[i].label),
entries[i].func, index);
+ }
gtk_menu_shell_append(GTK_MENU_SHELL(menu),
gtk_separator_menu_item_new());
@@ -1865,11 +1997,11 @@ bndx_popup_menu_create(BalsaIndex * index)
index->move_to_trash_item =
create_stock_menu_item(menu, _("Move To _Trash"),
G_CALLBACK
- (balsa_message_move_to_trash), index);
+ (balsa_message_move_to_trash), index);
- menuitem = gtk_menu_item_new_with_mnemonic(_("T_oggle"));
+ menuitem = gtk_menu_item_new_with_mnemonic(_("T_oggle"));
index->toggle_item = menuitem;
- submenu = gtk_menu_new();
+ submenu = gtk_menu_new();
create_stock_menu_item(submenu, _("_Flagged"),
G_CALLBACK(bi_toggle_flagged_cb),
index);
@@ -1881,7 +2013,7 @@ bndx_popup_menu_create(BalsaIndex * index)
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
- menuitem = gtk_menu_item_new_with_mnemonic(_("_Move to"));
+ menuitem = gtk_menu_item_new_with_mnemonic(_("_Move to"));
index->move_to_item = menuitem;
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
@@ -1895,6 +2027,7 @@ bndx_popup_menu_create(BalsaIndex * index)
return menu;
}
+
/* bndx_do_popup: common code for the popup menu;
* set sensitivity of menuitems on the popup
* menu, and populate the mru submenu
@@ -1905,34 +2038,37 @@ bndx_popup_menu_create(BalsaIndex * index)
*/
static void
-bndx_set_sensitive_func(GtkWidget * item, gpointer sensitive)
+bndx_set_sensitive_func(GtkWidget *item,
+ gpointer sensitive)
{
gtk_widget_set_sensitive(item, GPOINTER_TO_INT(sensitive));
}
+
static void
-bndx_do_popup(BalsaIndex * index, const GdkEvent * event)
+bndx_do_popup(BalsaIndex *index,
+ const GdkEvent *event)
{
GtkWidget *menu = index->popup_menu;
GtkWidget *submenu;
GArray *selected;
- LibBalsaMailbox* mailbox;
+ LibBalsaMailbox *mailbox;
gboolean any;
gboolean readonly;
- gboolean any_deleted = FALSE;
+ gboolean any_deleted = FALSE;
gboolean any_not_deleted = FALSE;
guint i;
BALSA_DEBUG();
selected = balsa_index_selected_msgnos_new(index);
- mailbox = balsa_index_get_mailbox(index);
+ mailbox = balsa_index_get_mailbox(index);
for (i = 0; i < selected->len; i++) {
guint msgno = g_array_index(selected, guint, i);
if (libbalsa_mailbox_msgno_has_flags(mailbox, msgno,
LIBBALSA_MESSAGE_FLAG_DELETED,
- 0))
+ 0))
any_deleted = TRUE;
else
any_not_deleted = TRUE;
@@ -1958,7 +2094,7 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent * event)
submenu =
balsa_mblist_mru_menu(GTK_WINDOW
- (gtk_widget_get_toplevel(GTK_WIDGET(index))),
+ (gtk_widget_get_toplevel(GTK_WIDGET(index))),
&balsa_app.folder_mru,
G_CALLBACK(mru_menu_cb), index);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(index->move_to_item),
@@ -1973,9 +2109,12 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent * event)
}
}
+
static GtkWidget *
-create_stock_menu_item(GtkWidget * menu, const gchar * label, GCallback cb,
- gpointer data)
+create_stock_menu_item(GtkWidget *menu,
+ const gchar *label,
+ GCallback cb,
+ gpointer data)
{
GtkWidget *menuitem = gtk_menu_item_new_with_mnemonic(label);
@@ -1987,17 +2126,21 @@ create_stock_menu_item(GtkWidget * menu, const gchar * label, GCallback cb,
return menuitem;
}
+
static void
-sendmsg_window_destroy_cb(GtkWidget * widget, gpointer data)
+sendmsg_window_destroy_cb(GtkWidget *widget,
+ gpointer data)
{
balsa_window_enable_continue(balsa_app.main_window);
}
+
void
-balsa_index_update_tree(BalsaIndex * index, gboolean expand)
+balsa_index_update_tree(BalsaIndex *index,
+ gboolean expand)
/* Remarks: In the "collapse" case, we still expand current thread to the
- extent where viewed message is visible. An alternative
- approach would be to change preview, e.g. to top of thread. */
+ extent where viewed message is visible. An alternative
+ approach would be to change preview, e.g. to top of thread. */
{
GtkTreeView *tree_view = GTK_TREE_VIEW(index);
GtkTreeIter iter;
@@ -2025,9 +2168,11 @@ balsa_index_update_tree(BalsaIndex * index, gboolean expand)
bndx_changed_find_row(index);
}
+
/* balsa_index_set_threading_type: public method. */
void
-balsa_index_set_threading_type(BalsaIndex * index, int thtype)
+balsa_index_set_threading_type(BalsaIndex *index,
+ int thtype)
{
LibBalsaMailbox *mailbox;
@@ -2035,19 +2180,22 @@ balsa_index_set_threading_type(BalsaIndex * index, int thtype)
mailbox = balsa_index_get_mailbox(index);
g_return_if_fail(mailbox != NULL);
- if (thtype != LB_MAILBOX_THREADING_FLAT
+ if ((thtype != LB_MAILBOX_THREADING_FLAT)
&& !libbalsa_mailbox_prepare_threading(mailbox, 0))
return;
+
libbalsa_mailbox_set_threading_type(mailbox, thtype);
libbalsa_mailbox_set_threading(mailbox, thtype);
balsa_index_update_tree(index, balsa_app.expand_tree);
}
+
void
-balsa_index_set_view_filter(BalsaIndex * bindex, int filter_no,
- const gchar * filter_string,
- LibBalsaCondition * filter)
+balsa_index_set_view_filter(BalsaIndex *bindex,
+ int filter_no,
+ const gchar *filter_string,
+ LibBalsaCondition *filter)
{
LibBalsaMailbox *mailbox;
@@ -2055,29 +2203,33 @@ balsa_index_set_view_filter(BalsaIndex * bindex, int filter_no,
mailbox = balsa_index_get_mailbox(bindex);
g_free(bindex->filter_string);
- bindex->filter_no = filter_no;
+ bindex->filter_no = filter_no;
bindex->filter_string = g_strdup(filter_string);
if (libbalsa_mailbox_set_view_filter(mailbox, filter, TRUE))
balsa_index_ensure_visible(bindex);
}
+
/* Public method. */
void
-balsa_index_refresh_size(BalsaIndex * index)
+balsa_index_refresh_size(BalsaIndex *index)
{
}
/* Public method. */
void
-balsa_index_refresh_date(BalsaIndex * index)
+balsa_index_refresh_date(BalsaIndex *index)
{
}
+
/* Transfer messages. */
void
-balsa_index_transfer(BalsaIndex *index, GArray * msgnos,
- LibBalsaMailbox * to_mailbox, gboolean copy)
+balsa_index_transfer(BalsaIndex *index,
+ GArray *msgnos,
+ LibBalsaMailbox *to_mailbox,
+ gboolean copy)
{
gboolean success;
LibBalsaMailbox *from_mailbox;
@@ -2088,22 +2240,22 @@ balsa_index_transfer(BalsaIndex *index, GArray * msgnos,
return;
from_mailbox = balsa_index_get_mailbox(index);
- success = copy ?
+ success = copy ?
libbalsa_mailbox_messages_copy(from_mailbox, msgnos, to_mailbox, &e) :
libbalsa_mailbox_messages_move(from_mailbox, msgnos, to_mailbox, &e);
to_mailbox_name = libbalsa_mailbox_get_name(to_mailbox);
if (!success) {
- balsa_information
+ balsa_information
(LIBBALSA_INFORMATION_WARNING,
- ngettext("Failed to copy %d message to mailbox “%s”: %s",
- "Failed to copy %d messages to mailbox “%s”: %s",
- msgnos->len),
- msgnos->len, to_mailbox_name, e ? e->message : "?");
- return;
+ ngettext("Failed to copy %d message to mailbox “%s”: %s",
+ "Failed to copy %d messages to mailbox “%s”: %s",
+ msgnos->len),
+ msgnos->len, to_mailbox_name, e ? e->message : "?");
+ return;
}
- if (from_mailbox == balsa_app.trash && !copy)
+ if ((from_mailbox == balsa_app.trash) && !copy)
enable_empty_trash(balsa_app.main_window, TRASH_CHECK);
else if (to_mailbox == balsa_app.trash)
enable_empty_trash(balsa_app.main_window, TRASH_FULL);
@@ -2111,14 +2263,16 @@ balsa_index_transfer(BalsaIndex *index, GArray * msgnos,
copy ? _("Copied to “%s”.")
: _("Moved to “%s”."), to_mailbox_name);
if (!copy)
- /* Note when message was flagged as deleted, for use in
- * auto-expunge. */
- balsa_mailbox_node_set_last_use(index->mailbox_node);
+ /* Note when message was flagged as deleted, for use in
+ * auto-expunge. */
+ balsa_index_set_last_use(index);
}
+
/* General helpers. */
static void
-bndx_expand_to_row(BalsaIndex * index, GtkTreePath * path)
+bndx_expand_to_row(BalsaIndex *index,
+ GtkTreePath *path)
{
GtkTreePath *tmp;
gint i, j;
@@ -2128,23 +2282,25 @@ bndx_expand_to_row(BalsaIndex * index, GtkTreePath * path)
tmp = gtk_tree_path_copy(path);
while (gtk_tree_path_up(tmp) && gtk_tree_path_get_depth(tmp) > 0
- && !gtk_tree_view_row_expanded(GTK_TREE_VIEW(index), tmp));
+ && !gtk_tree_view_row_expanded(GTK_TREE_VIEW(index), tmp)) {
+ }
/* Now we go from the deepest unexpanded ancestor up to full path */
if ((i = gtk_tree_path_get_depth(tmp))
- < (j = gtk_tree_path_get_depth(path) - 1)) {
- gint *indices = gtk_tree_path_get_indices(path);
+ < (j = gtk_tree_path_get_depth(path) - 1)) {
+ gint *indices = gtk_tree_path_get_indices(path);
- do {
- gtk_tree_path_append_index(tmp, indices[i]);
- gtk_tree_view_expand_row(GTK_TREE_VIEW(index), tmp, FALSE);
- } while (++i < j);
+ do {
+ gtk_tree_path_append_index(tmp, indices[i]);
+ gtk_tree_view_expand_row(GTK_TREE_VIEW(index), tmp, FALSE);
+ } while (++i < j);
}
gtk_tree_path_free(tmp);
}
+
static void
-bndx_changed_find_row(BalsaIndex * index)
+bndx_changed_find_row(BalsaIndex *index)
{
GtkTreeIter iter;
@@ -2154,7 +2310,7 @@ bndx_changed_find_row(BalsaIndex * index)
bndx_search_iter(index, index->search_iter, &iter,
BNDX_SEARCH_DIRECTION_NEXT,
BNDX_SEARCH_VIEWABLE_ONLY, 0);
- iter.user_data = tmp;
+ iter.user_data = tmp;
index->prev_message =
bndx_search_iter(index, index->search_iter, &iter,
BNDX_SEARCH_DIRECTION_PREV,
@@ -2167,11 +2323,13 @@ bndx_changed_find_row(BalsaIndex * index)
g_signal_emit(G_OBJECT(index), balsa_index_signals[INDEX_CHANGED], 0);
}
+
/* Make the actual selection,
* making sure the selected row is within bounds and made visible.
*/
static void
-bndx_select_row(BalsaIndex * index, GtkTreePath * path)
+bndx_select_row(BalsaIndex *index,
+ GtkTreePath *path)
{
GtkTreeView *tree_view = GTK_TREE_VIEW(index);
@@ -2179,25 +2337,29 @@ bndx_select_row(BalsaIndex * index, GtkTreePath * path)
gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
}
+
/* Check that all parents are expanded. */
static gboolean
-bndx_row_is_viewable(BalsaIndex * index, GtkTreePath * path)
+bndx_row_is_viewable(BalsaIndex *index,
+ GtkTreePath *path)
{
GtkTreePath *tmp_path = gtk_tree_path_copy(path);
- gboolean ret_val = TRUE;
+ gboolean ret_val = TRUE;
while (ret_val && gtk_tree_path_up(tmp_path)
- && gtk_tree_path_get_depth(tmp_path) > 0)
+ && gtk_tree_path_get_depth(tmp_path) > 0) {
ret_val =
gtk_tree_view_row_expanded(GTK_TREE_VIEW(index), tmp_path);
+ }
gtk_tree_path_free(tmp_path);
return ret_val;
}
+
/* Expunge deleted messages. */
void
-balsa_index_expunge(BalsaIndex * index)
+balsa_index_expunge(BalsaIndex *index)
{
LibBalsaMailbox *mailbox;
gboolean rc;
@@ -2206,20 +2368,23 @@ balsa_index_expunge(BalsaIndex * index)
mailbox = balsa_index_get_mailbox(index);
if (libbalsa_mailbox_get_readonly(mailbox))
- return;
+ return;
rc = libbalsa_mailbox_sync_storage(mailbox, TRUE);
- if (!rc)
- balsa_information(LIBBALSA_INFORMATION_WARNING,
- _("Committing mailbox %s failed."),
- libbalsa_mailbox_get_name(mailbox));
+ if (!rc) {
+ balsa_information(LIBBALSA_INFORMATION_WARNING,
+ _("Committing mailbox %s failed."),
+ libbalsa_mailbox_get_name(mailbox));
+ }
}
+
/* Message window */
static guint
-bndx_next_msgno(BalsaIndex * index, guint current_msgno,
- LibBalsaMailboxSearchIter * search_iter,
- BndxSearchDirection direction)
+bndx_next_msgno(BalsaIndex *index,
+ guint current_msgno,
+ LibBalsaMailboxSearchIter *search_iter,
+ BndxSearchDirection direction)
{
LibBalsaMailbox *mailbox;
GtkTreeIter iter;
@@ -2243,170 +2408,188 @@ bndx_next_msgno(BalsaIndex * index, guint current_msgno,
return msgno;
}
+
guint
-balsa_index_next_msgno(BalsaIndex * index, guint current_msgno)
+balsa_index_next_msgno(BalsaIndex *index,
+ guint current_msgno)
{
return bndx_next_msgno(index, current_msgno, index->search_iter,
BNDX_SEARCH_DIRECTION_NEXT);
}
+
guint
-balsa_index_previous_msgno(BalsaIndex * index, guint current_msgno)
+balsa_index_previous_msgno(BalsaIndex *index,
+ guint current_msgno)
{
return bndx_next_msgno(index, current_msgno, index->search_iter,
BNDX_SEARCH_DIRECTION_PREV);
}
+
/* Functions and data structures for asynchronous message piping via
external commands. */
/** PipeData stores the context of a message currently sent via a pipe
to an external command. */
struct PipeData {
GDestroyNotify destroy_notify;
- gpointer notify_arg;
- gchar *message;
- ssize_t message_length;
- ssize_t chars_written;
- GIOChannel *in_channel;
- GIOChannel *out_channel;
- GIOChannel *err_channel;
- guint in_source;
- guint out_source;
- guint err_source;
- int out_closed:1;
- int err_closed:1;
+ gpointer notify_arg;
+ gchar *message;
+ ssize_t message_length;
+ ssize_t chars_written;
+ GIOChannel *in_channel;
+ GIOChannel *out_channel;
+ GIOChannel *err_channel;
+ guint in_source;
+ guint out_source;
+ guint err_source;
+ int out_closed : 1;
+ int err_closed : 1;
};
static void
-pipe_data_destroy(struct PipeData* pipe)
+pipe_data_destroy(struct PipeData *pipe)
{
- if(pipe->destroy_notify)
- pipe->destroy_notify(pipe->notify_arg);
+ if (pipe->destroy_notify)
+ pipe->destroy_notify(pipe->notify_arg);
g_free(pipe->message);
- if(pipe->in_channel)
- g_io_channel_unref(pipe->in_channel);
+ if (pipe->in_channel)
+ g_io_channel_unref(pipe->in_channel);
g_io_channel_unref(pipe->out_channel);
g_io_channel_unref(pipe->err_channel);
- if(pipe->in_source)
- g_source_remove(pipe->in_source);
+ if (pipe->in_source)
+ g_source_remove(pipe->in_source);
g_source_remove(pipe->out_source);
g_source_remove(pipe->err_source);
g_free(pipe);
}
+
static gboolean
-pipe_in_watch(GIOChannel *channel, GIOCondition condition, gpointer data)
+pipe_in_watch(GIOChannel *channel,
+ GIOCondition condition,
+ gpointer data)
{
- struct PipeData *pipe = (struct PipeData*)data;
+ struct PipeData *pipe = (struct PipeData *)data;
GIOStatus status;
GError *error = NULL;
gsize chars_written;
gboolean rc;
if ((condition & (G_IO_HUP | G_IO_ERR)) != 0) {
- if ((condition & G_IO_HUP) != 0) {
+ if ((condition & G_IO_HUP) != 0)
fprintf(stderr, "pipe_in_watch: broken pipe. Aborts writing.\n");
- }
- if ((condition & G_IO_ERR) != 0) {
+ if ((condition & G_IO_ERR) != 0)
fprintf(stderr, "pipe_in_watch encountered error. Aborts writing.\n");
- }
- pipe_data_destroy(pipe);
+ pipe_data_destroy(pipe);
return FALSE;
}
- if( (condition & G_IO_OUT) == G_IO_OUT) {
- status =
- g_io_channel_write_chars(channel,
- pipe->message + pipe->chars_written,
- pipe->message_length-pipe->chars_written,
- &chars_written,
- &error);
-
- switch(status) {
- case G_IO_STATUS_ERROR:
- libbalsa_information(LIBBALSA_INFORMATION_ERROR,
- _("Cannot process the message: %s"),
- error->message);
- g_clear_error(&error);
- pipe_data_destroy(pipe);
- return FALSE;
- case G_IO_STATUS_NORMAL:
- pipe->chars_written += chars_written;
- break;
- case G_IO_STATUS_EOF:
- printf("pipe_in::write_chars receieved premature EOF %s\n",
- error ? error->message : "unknown");
- pipe_data_destroy(pipe);
- return FALSE;
- case G_IO_STATUS_AGAIN:
- printf("pipe_in::write_chars again?\n");
- break;
- }
+ if ((condition & G_IO_OUT) == G_IO_OUT) {
+ status =
+ g_io_channel_write_chars(channel,
+ pipe->message + pipe->chars_written,
+ pipe->message_length - pipe->chars_written,
+ &chars_written,
+ &error);
+
+ switch (status) {
+ case G_IO_STATUS_ERROR:
+ libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+ _("Cannot process the message: %s"),
+ error->message);
+ g_clear_error(&error);
+ pipe_data_destroy(pipe);
+ return FALSE;
+
+ case G_IO_STATUS_NORMAL:
+ pipe->chars_written += chars_written;
+ break;
+
+ case G_IO_STATUS_EOF:
+ printf("pipe_in::write_chars receieved premature EOF %s\n",
+ error ? error->message : "unknown");
+ pipe_data_destroy(pipe);
+ return FALSE;
+
+ case G_IO_STATUS_AGAIN:
+ printf("pipe_in::write_chars again?\n");
+ break;
+ }
}
rc = pipe->message_length > pipe->chars_written;
- if(!rc) {
- g_io_channel_unref(pipe->in_channel); pipe->in_channel = NULL;
- g_source_remove(pipe->in_source); pipe->in_source = 0;
+ if (!rc) {
+ g_io_channel_unref(pipe->in_channel);
+ pipe->in_channel = NULL;
+ g_source_remove(pipe->in_source);
+ pipe->in_source = 0;
}
return rc;
}
+
static gboolean
-pipe_out_watch(GIOChannel *channel, GIOCondition condition, gpointer data)
+pipe_out_watch(GIOChannel *channel,
+ GIOCondition condition,
+ gpointer data)
{
- struct PipeData *pipe = (struct PipeData*)data;
+ struct PipeData *pipe = (struct PipeData *)data;
gsize bytes_read;
GIOStatus status;
GError *error = NULL;
gchar *s;
- if ( (condition & G_IO_IN) == G_IO_IN) {
+ if ((condition & G_IO_IN) == G_IO_IN) {
char buf[2048];
- status =
- g_io_channel_read_chars(channel, buf, sizeof(buf), &bytes_read,
- &error);
- switch(status) {
- case G_IO_STATUS_ERROR:
- pipe_data_destroy(pipe);
- fprintf(stderr, "Reading characters from pipe failed: %s\n",
- error ? error->message : "unknown");
- g_clear_error(&error);
- return FALSE;
- case G_IO_STATUS_NORMAL:
- s = g_strndup(buf, bytes_read > 128 ? 128 : bytes_read);
- libbalsa_information(LIBBALSA_INFORMATION_MESSAGE, "%s", s);
- g_free(s);
- /* if(fwrite(buf, 1, bytes_read, stdout) != bytes_read); */
- break;
- case G_IO_STATUS_EOF:
- printf("pipe_out got EOF\n");
- pipe_data_destroy(pipe);
- g_clear_error(&error);
- return FALSE;
- case G_IO_STATUS_AGAIN: break;
- }
+ status =
+ g_io_channel_read_chars(channel, buf, sizeof(buf), &bytes_read,
+ &error);
+ switch (status) {
+ case G_IO_STATUS_ERROR:
+ pipe_data_destroy(pipe);
+ fprintf(stderr, "Reading characters from pipe failed: %s\n",
+ error ? error->message : "unknown");
+ g_clear_error(&error);
+ return FALSE;
+
+ case G_IO_STATUS_NORMAL:
+ s = g_strndup(buf, bytes_read > 128 ? 128 : bytes_read);
+ libbalsa_information(LIBBALSA_INFORMATION_MESSAGE, "%s", s);
+ g_free(s);
+ /* if(fwrite(buf, 1, bytes_read, stdout) != bytes_read); */
+ break;
+
+ case G_IO_STATUS_EOF:
+ printf("pipe_out got EOF\n");
+ pipe_data_destroy(pipe);
+ g_clear_error(&error);
+ return FALSE;
+
+ case G_IO_STATUS_AGAIN: break;
+ }
}
if ( condition == G_IO_HUP) {
- if(channel == pipe->out_channel)
- pipe->out_closed = 1;
- else
- pipe->err_closed = 1;
- if(pipe->out_closed && pipe->err_closed)
- pipe_data_destroy((struct PipeData*)data);
+ if (channel == pipe->out_channel)
+ pipe->out_closed = 1;
+ else
+ pipe->err_closed = 1;
+ if (pipe->out_closed && pipe->err_closed)
+ pipe_data_destroy((struct PipeData *)data);
}
- if ( (condition & G_IO_ERR) == G_IO_ERR) {
- fprintf(stderr,
- "pipe_out_watch encountered error…\n");
- pipe_data_destroy(pipe);
- return FALSE;
+ if ((condition & G_IO_ERR) == G_IO_ERR) {
+ fprintf(stderr,
+ "pipe_out_watch encountered error…\n");
+ pipe_data_destroy(pipe);
+ return FALSE;
}
return TRUE;
}
+
/** BndxPipeQueue represents the context of message pipe
processing. Several messages from specified mailbox can be sent
via the pipe. For each message, a separate context as stored in
@@ -2414,8 +2597,8 @@ pipe_out_watch(GIOChannel *channel, GIOCondition condition, gpointer data)
struct BndxPipeQueue {
LibBalsaMailbox *mailbox;
- GArray *msgnos;
- gchar *pipe_cmd;
+ GArray *msgnos;
+ gchar *pipe_cmd;
};
static void
@@ -2432,122 +2615,125 @@ bndx_pipe_queue_last(struct BndxPipeQueue *queue)
int std_error;
guint msgno = 0;
- while(queue->msgnos->len>0){
- msgno = g_array_index(queue->msgnos, guint, queue->msgnos->len-1);
- stream =
- libbalsa_mailbox_get_message_stream(queue->mailbox, msgno, TRUE);
- g_array_remove_index(queue->msgnos, queue->msgnos->len-1);
- if(stream)
- break;
- if(!stream) {
- libbalsa_information(LIBBALSA_INFORMATION_ERROR,
- _("Cannot access message %u to pass to %s"),
- msgno, queue->pipe_cmd);
- }
+ while (queue->msgnos->len > 0) {
+ msgno = g_array_index(queue->msgnos, guint, queue->msgnos->len - 1);
+ stream =
+ libbalsa_mailbox_get_message_stream(queue->mailbox, msgno, TRUE);
+ g_array_remove_index(queue->msgnos, queue->msgnos->len - 1);
+ if (stream)
+ break;
+ if (!stream) {
+ libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+ _("Cannot access message %u to pass to %s"),
+ msgno, queue->pipe_cmd);
+ }
}
- if(queue->msgnos->len == 0 && !stream) {
- printf("Piping finished. Destroying the context.\n");
- libbalsa_mailbox_unregister_msgnos(queue->mailbox, queue->msgnos);
- libbalsa_mailbox_close(queue->mailbox, FALSE);
- g_array_free(queue->msgnos, TRUE);
- g_free(queue->pipe_cmd);
- g_free(queue);
- return;
+ if ((queue->msgnos->len == 0) && !stream) {
+ printf("Piping finished. Destroying the context.\n");
+ libbalsa_mailbox_unregister_msgnos(queue->mailbox, queue->msgnos);
+ libbalsa_mailbox_close(queue->mailbox, FALSE);
+ g_array_free(queue->msgnos, TRUE);
+ g_free(queue->pipe_cmd);
+ g_free(queue);
+ return;
}
- pipe = g_new0(struct PipeData, 1);
+ pipe = g_new0(struct PipeData, 1);
pipe->destroy_notify = (GDestroyNotify)bndx_pipe_queue_last;
- pipe->notify_arg = queue;
+ pipe->notify_arg = queue;
pipe->message_length = g_mime_stream_length(stream);
- pipe->message = g_malloc(pipe->message_length);
+ pipe->message = g_malloc(pipe->message_length);
libbalsa_mailbox_lock_store(queue->mailbox);
chars_read = g_mime_stream_read(stream, pipe->message,
- pipe->message_length);
+ pipe->message_length);
libbalsa_mailbox_unlock_store(queue->mailbox);
- if(chars_read != pipe->message_length) {
- libbalsa_information(LIBBALSA_INFORMATION_ERROR,
- _("Cannot read message %u to pass to %s"),
- msgno, queue->pipe_cmd);
- bndx_pipe_queue_last(queue);
- g_free(pipe);
- return;
+ if (chars_read != pipe->message_length) {
+ libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+ _("Cannot read message %u to pass to %s"),
+ msgno, queue->pipe_cmd);
+ bndx_pipe_queue_last(queue);
+ g_free(pipe);
+ return;
}
- argv = g_new(gchar *, 4);
+ argv = g_new(gchar *, 4);
argv[0] = g_strdup("/bin/sh");
argv[1] = g_strdup("-c");
argv[2] = g_strdup(queue->pipe_cmd);
argv[3] = NULL;
spawned =
- g_spawn_async_with_pipes(NULL, argv, NULL,
- 0, NULL, NULL,
- NULL,
- &std_input, &std_output,
- &std_error,
- &error);
+ g_spawn_async_with_pipes(NULL, argv, NULL,
+ 0, NULL, NULL,
+ NULL,
+ &std_input, &std_output,
+ &std_error,
+ &error);
g_strfreev(argv);
- if(spawned) {
- pipe->in_channel = g_io_channel_unix_new(std_input);
- g_io_channel_set_flags(pipe->in_channel, G_IO_FLAG_NONBLOCK, NULL);
- pipe->in_source = g_io_add_watch(pipe->in_channel, G_IO_OUT | G_IO_HUP,
- pipe_in_watch, pipe);
- pipe->out_channel = g_io_channel_unix_new(std_output);
- g_io_channel_set_flags(pipe->out_channel, G_IO_FLAG_NONBLOCK, NULL);
- pipe->out_source = g_io_add_watch(pipe->out_channel, G_IO_IN|G_IO_HUP,
- pipe_out_watch, pipe);
- pipe->err_channel = g_io_channel_unix_new(std_error);
- g_io_channel_set_flags(pipe->err_channel, G_IO_FLAG_NONBLOCK, NULL);
- pipe->err_source = g_io_add_watch(pipe->err_channel, G_IO_IN | G_IO_HUP,
- pipe_out_watch, pipe);
-
- g_io_channel_set_encoding(pipe->in_channel, NULL, NULL);
- g_io_channel_set_encoding(pipe->out_channel, NULL, NULL);
- g_io_channel_set_encoding(pipe->err_channel, NULL, NULL);
- g_io_channel_set_close_on_unref(pipe->in_channel, TRUE);
- g_io_channel_set_close_on_unref(pipe->out_channel, TRUE);
- g_io_channel_set_close_on_unref(pipe->err_channel, TRUE);
+ if (spawned) {
+ pipe->in_channel = g_io_channel_unix_new(std_input);
+ g_io_channel_set_flags(pipe->in_channel, G_IO_FLAG_NONBLOCK, NULL);
+ pipe->in_source = g_io_add_watch(pipe->in_channel, G_IO_OUT | G_IO_HUP,
+ pipe_in_watch, pipe);
+ pipe->out_channel = g_io_channel_unix_new(std_output);
+ g_io_channel_set_flags(pipe->out_channel, G_IO_FLAG_NONBLOCK, NULL);
+ pipe->out_source = g_io_add_watch(pipe->out_channel, G_IO_IN | G_IO_HUP,
+ pipe_out_watch, pipe);
+ pipe->err_channel = g_io_channel_unix_new(std_error);
+ g_io_channel_set_flags(pipe->err_channel, G_IO_FLAG_NONBLOCK, NULL);
+ pipe->err_source = g_io_add_watch(pipe->err_channel, G_IO_IN | G_IO_HUP,
+ pipe_out_watch, pipe);
+
+ g_io_channel_set_encoding(pipe->in_channel, NULL, NULL);
+ g_io_channel_set_encoding(pipe->out_channel, NULL, NULL);
+ g_io_channel_set_encoding(pipe->err_channel, NULL, NULL);
+ g_io_channel_set_close_on_unref(pipe->in_channel, TRUE);
+ g_io_channel_set_close_on_unref(pipe->out_channel, TRUE);
+ g_io_channel_set_close_on_unref(pipe->err_channel, TRUE);
} else {
- printf("Could not spawn pipe %s : %s\n", queue->pipe_cmd,
- error ? error->message : "unknown");
- g_clear_error(&error);
- g_free(pipe);
+ printf("Could not spawn pipe %s : %s\n", queue->pipe_cmd,
+ error ? error->message : "unknown");
+ g_clear_error(&error);
+ g_free(pipe);
}
}
+
/** Initiates the asynchronous process of sending specified messages
from given mailbox via the provided command. */
static gboolean
bndx_start_pipe_messages_array(LibBalsaMailbox *mailbox,
- GArray *msgnos,
- const char *pipe_cmd)
+ GArray *msgnos,
+ const char *pipe_cmd)
{
guint i;
struct BndxPipeQueue *queue;
- if(!libbalsa_mailbox_open(mailbox, NULL))
- return FALSE;
+ if (!libbalsa_mailbox_open(mailbox, NULL))
+ return FALSE;
- queue = g_new(struct BndxPipeQueue, 1);
- queue->mailbox = mailbox;
- queue->msgnos = g_array_sized_new(FALSE, FALSE, sizeof(guint), msgnos->len);
+ queue = g_new(struct BndxPipeQueue, 1);
+ queue->mailbox = mailbox;
+ queue->msgnos = g_array_sized_new(FALSE, FALSE, sizeof(guint), msgnos->len);
queue->pipe_cmd = g_strdup(pipe_cmd);
- for(i=0; i<msgnos->len; i++)
- g_array_append_val(queue->msgnos,
- g_array_index(msgnos, guint, msgnos->len-i-1));
+ for (i = 0; i < msgnos->len; i++) {
+ g_array_append_val(queue->msgnos,
+ g_array_index(msgnos, guint, msgnos->len - i - 1));
+ }
libbalsa_mailbox_register_msgnos(mailbox, queue->msgnos);
bndx_pipe_queue_last(queue);
return TRUE;
}
+
struct bndx_mailbox_info {
- GtkWidget *dialog;
- GtkWidget *entry;
+ GtkWidget *dialog;
+ GtkWidget *entry;
LibBalsaMailbox *mailbox;
- BalsaIndex *bindex;
- GArray *msgnos;
+ BalsaIndex *bindex;
+ GArray *msgnos;
};
static void
@@ -2560,10 +2746,12 @@ bndx_mailbox_notify(gpointer data)
g_free(info);
}
+
#define BALSA_INDEX_PIPE_INFO "balsa-index-pipe-info"
static void
-bndx_pipe_response(GtkWidget * dialog, gint response,
+bndx_pipe_response(GtkWidget *dialog,
+ gint response,
struct bndx_mailbox_info *info)
{
LibBalsaMailbox *mailbox = info->mailbox;
@@ -2576,36 +2764,38 @@ bndx_pipe_response(GtkWidget * dialog, gint response,
pipe_cmd =
gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT
- (info->entry));
+ (info->entry));
active_cmd =
g_list_find_custom(balsa_app.pipe_cmds, pipe_cmd,
(GCompareFunc) strcmp);
- if (!active_cmd)
+ if (!active_cmd) {
balsa_app.pipe_cmds =
g_list_prepend(balsa_app.pipe_cmds, g_strdup(pipe_cmd));
- else if (active_cmd != balsa_app.pipe_cmds) {
+ } else if (active_cmd != balsa_app.pipe_cmds) {
balsa_app.pipe_cmds =
g_list_remove_link(balsa_app.pipe_cmds, active_cmd);
balsa_app.pipe_cmds =
g_list_concat(active_cmd, balsa_app.pipe_cmds);
}
- bndx_start_pipe_messages_array(mailbox, info->msgnos, pipe_cmd);
+ bndx_start_pipe_messages_array(mailbox, info->msgnos, pipe_cmd);
g_free(pipe_cmd);
}
if (!mailbox)
return;
+
g_object_remove_weak_pointer(G_OBJECT(mailbox), (gpointer) & mailbox);
libbalsa_mailbox_close(mailbox, balsa_app.expunge_on_close);
g_object_set_data(G_OBJECT(mailbox), BALSA_INDEX_PIPE_INFO, NULL);
}
+
#define HIG_PADDING 12
void
-balsa_index_pipe(BalsaIndex * index)
+balsa_index_pipe(BalsaIndex *index)
{
LibBalsaMailbox *mailbox;
struct bndx_mailbox_info *info;
@@ -2624,10 +2814,11 @@ balsa_index_pipe(BalsaIndex * index)
return;
}
- if(!libbalsa_mailbox_open(mailbox, NULL))
- return;
- info = g_new(struct bndx_mailbox_info, 1);
- info->bindex = index;
+ if (!libbalsa_mailbox_open(mailbox, NULL))
+ return;
+
+ info = g_new(struct bndx_mailbox_info, 1);
+ info->bindex = index;
info->mailbox = mailbox;
g_object_set_data_full(G_OBJECT(info->mailbox), BALSA_INDEX_PIPE_INFO,
info, bndx_mailbox_notify);
@@ -2635,13 +2826,13 @@ balsa_index_pipe(BalsaIndex * index)
info->msgnos = balsa_index_selected_msgnos_new(index);
info->dialog = dialog =
- gtk_dialog_new_with_buttons(_("Pipe message through a program"),
- GTK_WINDOW(balsa_app.main_window),
- GTK_DIALOG_DESTROY_WITH_PARENT |
- libbalsa_dialog_flags(),
- _("_Run"), GTK_RESPONSE_OK,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- NULL);
+ gtk_dialog_new_with_buttons(_("Pipe message through a program"),
+ GTK_WINDOW(balsa_app.main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ libbalsa_dialog_flags(),
+ _("_Run"), GTK_RESPONSE_OK,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ NULL);
#if HAVE_MACOSX_DESKTOP
libbalsa_macosx_menu_for_parent(dialog, GTK_WINDOW(balsa_app.main_window));
#endif
@@ -2655,9 +2846,10 @@ balsa_index_pipe(BalsaIndex * index)
gtk_box_pack_start(GTK_BOX(vbox), label);
info->entry = entry = gtk_combo_box_text_new_with_entry();
- for (list = balsa_app.pipe_cmds; list; list = list->next)
+ for (list = balsa_app.pipe_cmds; list; list = list->next) {
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(entry),
list->data);
+ }
gtk_combo_box_set_active(GTK_COMBO_BOX(entry), 0);
gtk_box_pack_start(GTK_BOX(vbox), entry);
@@ -2669,12 +2861,13 @@ balsa_index_pipe(BalsaIndex * index)
gtk_widget_show(dialog);
}
+
/** GtkTreeView can leave no messages showing after changing the view
* filter, even though the view does contain messages. We prefer to
* scroll to either the current message. If this one is unavailable -
* to the last message in the view, if any. */
void
-balsa_index_ensure_visible(BalsaIndex * index)
+balsa_index_ensure_visible(BalsaIndex *index)
{
GtkTreeView *tree_view = GTK_TREE_VIEW(index);
GdkRectangle rect;
@@ -2701,7 +2894,7 @@ balsa_index_ensure_visible(BalsaIndex * index)
GtkTreeModel *model;
gint n_children;
- model = gtk_tree_view_get_model(tree_view);
+ model = gtk_tree_view_get_model(tree_view);
n_children = gtk_tree_model_iter_n_children(model, NULL);
if (n_children > 0) {
@@ -2719,10 +2912,11 @@ balsa_index_ensure_visible(BalsaIndex * index)
}
}
+
void
-balsa_index_select_all(BalsaIndex * bindex)
+balsa_index_select_all(BalsaIndex *bindex)
{
- GtkTreeView *tree_view = GTK_TREE_VIEW(bindex);
+ GtkTreeView *tree_view = GTK_TREE_VIEW(bindex);
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
gtk_tree_view_expand_all(tree_view);
@@ -2732,19 +2926,21 @@ balsa_index_select_all(BalsaIndex * bindex)
g_signal_emit(bindex, balsa_index_signals[INDEX_CHANGED], 0);
}
+
gint
-balsa_index_count_selected_messages(BalsaIndex * bindex)
+balsa_index_count_selected_messages(BalsaIndex *bindex)
{
g_return_val_if_fail(BALSA_IS_INDEX(bindex), -1);
return
gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection
- (GTK_TREE_VIEW(bindex)));
+ (GTK_TREE_VIEW(bindex)));
}
+
/* Select all messages in current thread */
void
-balsa_index_select_thread(BalsaIndex * bindex)
+balsa_index_select_thread(BalsaIndex *bindex)
{
LibBalsaMailbox *mailbox;
GtkTreeModel *model;
@@ -2760,12 +2956,13 @@ balsa_index_select_thread(BalsaIndex * bindex)
mailbox = balsa_index_get_mailbox(bindex);
if (!libbalsa_mailbox_msgno_find(mailbox, bindex->current_msgno,
- NULL, &iter))
+ NULL, &iter))
return;
model = GTK_TREE_MODEL(mailbox);
- while (gtk_tree_model_iter_parent(model, &next_iter, &iter))
+ while (gtk_tree_model_iter_parent(model, &next_iter, &iter)) {
iter = next_iter;
+ }
path = gtk_tree_model_get_path(model, &iter);
gtk_tree_view_expand_row(GTK_TREE_VIEW(bindex), path, TRUE);
@@ -2775,9 +2972,9 @@ balsa_index_select_thread(BalsaIndex * bindex)
gtk_tree_selection_select_iter(selection, &iter);
valid = gtk_tree_model_iter_children(model, &next_iter, &iter);
- if (valid)
+ if (valid) {
iter = next_iter;
- else {
+ } else {
do {
GtkTreeIter save_iter = iter;
@@ -2792,12 +2989,13 @@ balsa_index_select_thread(BalsaIndex * bindex)
&& gtk_tree_model_iter_parent(model, &next_iter, &iter));
}
+
/*
- * Helper
+ * Convenience functions
*/
LibBalsaMailbox *
-balsa_index_get_mailbox(BalsaIndex * bindex)
+balsa_index_get_mailbox(BalsaIndex *bindex)
{
BalsaMailboxNode *mailbox_node;
@@ -2806,5 +3004,33 @@ balsa_index_get_mailbox(BalsaIndex * bindex)
mailbox_node = bindex->mailbox_node;
return mailbox_node != NULL ?
- balsa_mailbox_node_get_mailbox(mailbox_node) : NULL;
+ balsa_mailbox_node_get_mailbox(mailbox_node) : NULL;
+}
+
+
+time_t
+balsa_index_get_last_use(BalsaIndex *bindex)
+{
+ BalsaMailboxNode *mailbox_node;
+
+ g_return_val_if_fail(BALSA_IS_INDEX(bindex), (time_t) -1);
+
+ mailbox_node = bindex->mailbox_node;
+
+ return mailbox_node != NULL ?
+ balsa_mailbox_node_get_last_use(mailbox_node) : (time_t) -1;
+}
+
+
+void
+balsa_index_set_last_use(BalsaIndex *bindex)
+{
+ BalsaMailboxNode *mailbox_node;
+
+ g_return_if_fail(BALSA_IS_INDEX(bindex));
+
+ mailbox_node = bindex->mailbox_node;
+
+ if (mailbox_node != NULL)
+ balsa_mailbox_node_set_last_use(mailbox_node);
}
diff --git a/src/balsa-index.h b/src/balsa-index.h
index a59139c..59478d7 100644
--- a/src/balsa-index.h
+++ b/src/balsa-index.h
@@ -52,16 +52,16 @@ struct _BalsaIndex {
GtkWidget *move_to_item;
BalsaMailboxNode *mailbox_node;
- guint current_msgno;
- guint next_msgno;
- gboolean current_message_is_deleted : 1;
- gboolean prev_message : 1;
- gboolean next_message : 1;
- gboolean has_selection_changed_idle : 1;
- gboolean has_mailbox_changed_idle : 1;
- gboolean collapsing : 1;
- int filter_no;
- gchar *filter_string; /* Quick view filter string, if any */
+ guint current_msgno;
+ guint next_msgno;
+ gboolean current_message_is_deleted : 1;
+ gboolean prev_message : 1;
+ gboolean next_message : 1;
+ gboolean has_selection_changed_idle : 1;
+ gboolean has_mailbox_changed_idle : 1;
+ gboolean collapsing : 1;
+ int filter_no;
+ gchar *filter_string; /* Quick view filter string, if any */
/* signal handler ids */
gulong row_expanded_id;
@@ -69,7 +69,7 @@ struct _BalsaIndex {
gulong selection_changed_id;
LibBalsaMailboxSearchIter *search_iter;
- BalsaIndexWidthPreference width_preference;
+ BalsaIndexWidthPreference width_preference;
};
/* tree model columns */
@@ -184,9 +184,11 @@ void balsa_index_select_thread(BalsaIndex *bindex);
gint balsa_index_count_selected_messages(BalsaIndex *bindex);
/*
- * Helper
+ * Convenience functions
*/
-LibBalsaMailbox * balsa_index_get_mailbox(BalsaIndex * bindex);
+LibBalsaMailbox *balsa_index_get_mailbox(BalsaIndex *bindex);
+time_t balsa_index_get_last_use(BalsaIndex *bindex);
+void balsa_index_set_last_use(BalsaIndex *bindex);
#define BALSA_INDEX_VIEW_ON_OPEN "balsa-index-view-on-open"
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index ea2bc6b..a8cdf47 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -1030,7 +1030,7 @@ bmbl_open_mailbox(LibBalsaMailbox * mailbox, gboolean set_current)
/* If we currently have a page open, update the time last visited */
if (index != NULL)
- balsa_mailbox_node_set_last_use(BALSA_INDEX(index)->mailbox_node);
+ balsa_index_set_last_use(BALSA_INDEX(index));
i = balsa_find_notebook_page_num(mailbox);
if (i != -1) {
@@ -1038,7 +1038,7 @@ bmbl_open_mailbox(LibBalsaMailbox * mailbox, gboolean set_current)
gtk_notebook_set_current_page(GTK_NOTEBOOK(balsa_app.notebook),
i);
index = balsa_window_find_current_index(balsa_app.main_window);
- balsa_mailbox_node_set_last_use(BALSA_INDEX(index)->mailbox_node);
+ balsa_index_set_last_use(BALSA_INDEX(index));
balsa_index_set_column_widths(BALSA_INDEX(index));
}
} else { /* page with mailbox not found, open it */
diff --git a/src/main-window.c b/src/main-window.c
index b5b55b7..db95d3b 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -3161,9 +3161,8 @@ bw_close_mailbox_on_timer(BalsaWindow * window)
continue;
if (balsa_app.close_mailbox_auto &&
- (delta_time = current_time -
- balsa_mailbox_node_get_last_use(index->mailbox_node)) >
- balsa_app.close_mailbox_timeout) {
+ (delta_time = current_time - balsa_index_get_last_use(index))
+ > balsa_app.close_mailbox_timeout) {
if (balsa_app.debug)
fprintf(stderr, "Closing Page %d unused for %d s\n",
i, delta_time);
@@ -4285,7 +4284,7 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
g_object_remove_weak_pointer(G_OBJECT(priv->current_index),
(gpointer) &priv->current_index);
/* Note when this mailbox was hidden, for use in auto-closing. */
- balsa_mailbox_node_set_last_use(BALSA_INDEX(priv->current_index)->mailbox_node);
+ balsa_index_set_last_use(BALSA_INDEX(priv->current_index));
priv->current_index = NULL;
}
@@ -4300,7 +4299,7 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
g_object_add_weak_pointer(G_OBJECT(index),
(gpointer) &priv->current_index);
/* Note when this mailbox was exposed, for use in auto-expunge. */
- balsa_mailbox_node_set_last_use(index->mailbox_node);
+ balsa_index_set_last_use(index);
mailbox = balsa_index_get_mailbox(index);
if (libbalsa_mailbox_get_name(mailbox)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]