[Commits] [SCM] claws branch, gtk3, updated. 3.16.0-91-g4be4535

ticho at claws-mail.org ticho at claws-mail.org
Sat Feb 17 19:13:08 CET 2018


The branch, gtk3 has been updated
       via  4be4535e717bb7d31cf44bd72a35a0f321ee8587 (commit)
       via  c40b4f33b5812c43baf8f0ebaa454f8f519de83a (commit)
      from  ab0270f13ee257ef7d721217e66623df64779ae9 (commit)

Summary of changes:
 src/addrgather.c     |   85 +++++++++++++-------
 src/gtk/foldersort.c |  212 ++++++++++++++++++++++++++++++++++++--------------
 src/gtk/foldersort.h |    4 +-
 3 files changed, 212 insertions(+), 89 deletions(-)


- Log -----------------------------------------------------------------
commit 4be4535e717bb7d31cf44bd72a35a0f321ee8587
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Sat Feb 17 18:23:48 2018 +0100

    Replace GtkCMCList in addrgather dialog with GtkTreeView.

diff --git a/src/addrgather.c b/src/addrgather.c
index abacec1..2fded27 100644
--- a/src/addrgather.c
+++ b/src/addrgather.c
@@ -89,7 +89,7 @@ static struct _AddrHarvest {
 	gboolean  cancelled;
 	gboolean  done;
 	gchar     *folderPath;
-	GtkWidget *clistCount;
+	GtkWidget *viewCount;
 } addrgather_dlg;
 
 #ifndef USE_ALT_ADDRBOOK
@@ -106,6 +106,12 @@ static gchar *_harv_headerNames_[] = {
 };
 static GList *_harv_messageList_;
 
+enum {
+	ADDRGATHER_COL_HEADER,
+	ADDRGATHER_COL_COUNT,
+	N_ADDRGATHER_COLS
+};
+
 static void addrgather_dlg_status_show( gchar *msg ) {
 	if( addrgather_dlg.statusbar != NULL ) {
 		gtk_statusbar_pop( GTK_STATUSBAR(addrgather_dlg.statusbar),
@@ -148,8 +154,9 @@ static void addrgather_size_allocate(
 #define FMT_BUFSIZE 32
 
 static gboolean addrgather_dlg_harvest() {
-	GtkCMCList *clist;
-	gchar *text[ FIELDS_N_COLS ];
+	GtkWidget *view;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
 	AddressHarvester *harvester;
 	gchar *name;
 #ifndef USE_ALT_ADDRBOOK
@@ -255,19 +262,22 @@ static gboolean addrgather_dlg_harvest() {
 #endif
 
 	/* Update summary count */
-	clist = GTK_CMCLIST(addrgather_dlg.clistCount);
-	gtk_cmclist_clear( clist );
+	view = addrgather_dlg.viewCount;
+	model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
+	gtk_list_store_clear( GTK_LIST_STORE(model) );
 	for( i = 0; i < NUM_FIELDS; i++ ) {
 		cnt = addrharvest_get_count( harvester, _harv_headerNames_[i] );
 		if( cnt < 1 ) {
 			strcpy( str, "-" );
 		}
 		else {
-			sprintf( str, "%d", cnt );
+			snprintf( str, FMT_BUFSIZE, "%d", cnt );
 		}
-		text[ FIELD_COL_HEADER ] = _harv_headerNames_[i];
-		text[ FIELD_COL_COUNT  ] = str;
-		gtk_cmclist_append( clist, text );
+		gtk_list_store_append(GTK_LIST_STORE(model), &iter);
+		gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+				ADDRGATHER_COL_HEADER, _harv_headerNames_[i],
+				ADDRGATHER_COL_COUNT, str,
+				-1);
 	}
 
 	addrharvest_free( harvester );
@@ -441,12 +451,12 @@ static void addrgather_page_fields(gint pageNum, gchar *pageLbl)
 static void addrgather_page_finish( gint pageNum, gchar *pageLbl ) {
 	GtkWidget *label;
 	GtkWidget *vbox;
-	GtkWidget *clistSWin;
-	GtkWidget *clistCount;
-	gchar *titles[ FIELDS_N_COLS ];
-	gint i;
-	titles[ FIELD_COL_HEADER ] = _("Header Name");
-	titles[ FIELD_COL_COUNT  ] = _("Address Count");
+	GtkWidget *scrollwin;
+	GtkWidget *viewCount;
+	GtkTreeViewColumn *col;
+	GtkCellRenderer *rdr;
+	GtkTreeSelection *sel;
+	GtkTreeModel *model;
 
 	vbox = gtk_vbox_new(FALSE, 8);
 	gtk_container_add( GTK_CONTAINER( addrgather_dlg.notebook ), vbox );
@@ -460,24 +470,39 @@ static void addrgather_page_finish( gint pageNum, gchar *pageLbl ) {
 		label );
 
 	/* Summary count */
-	clistSWin = gtk_scrolled_window_new( NULL, NULL );
-	gtk_container_add( GTK_CONTAINER(vbox), clistSWin );
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clistSWin),
+	scrollwin = gtk_scrolled_window_new( NULL, NULL );
+	gtk_container_add( GTK_CONTAINER(vbox), scrollwin );
+	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
 				       GTK_POLICY_AUTOMATIC,
 				       GTK_POLICY_AUTOMATIC);
 
-	clistCount = gtk_cmclist_new_with_titles( FIELDS_N_COLS, titles );
-	gtk_container_add( GTK_CONTAINER(clistSWin), clistCount );
-	gtk_cmclist_set_selection_mode( GTK_CMCLIST(clistCount), GTK_SELECTION_BROWSE );
-	gtk_cmclist_set_column_width(
-			GTK_CMCLIST(clistCount), FIELD_COL_HEADER, FIELDS_COL_WIDTH_HEADER );
-	gtk_cmclist_set_column_width(
-			GTK_CMCLIST(clistCount), FIELD_COL_COUNT, FIELDS_COL_WIDTH_COUNT );
-
-	for( i = 0; i < FIELDS_N_COLS; i++ )
-		gtk_widget_set_can_focus(GTK_CMCLIST(clistCount)->column[i].button, FALSE);
-
-	addrgather_dlg.clistCount = clistCount;
+	/* Treeview */
+	model = GTK_TREE_MODEL(gtk_list_store_new(N_ADDRGATHER_COLS,
+			G_TYPE_STRING, G_TYPE_STRING, -1));
+
+	viewCount = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(viewCount), TRUE);
+	gtk_tree_view_set_reorderable(GTK_TREE_VIEW(viewCount), FALSE);
+	sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(viewCount));
+	gtk_tree_selection_set_mode(sel, GTK_SELECTION_NONE);
+
+	/* Columns for the treeview */
+	rdr = gtk_cell_renderer_text_new();
+	col = gtk_tree_view_column_new_with_attributes(_("Header Name"), rdr,
+			"markup", ADDRGATHER_COL_HEADER,
+			NULL);
+	gtk_tree_view_column_set_min_width(col, FIELDS_COL_WIDTH_HEADER);
+	gtk_tree_view_append_column(GTK_TREE_VIEW(viewCount), col);
+
+	col = gtk_tree_view_column_new_with_attributes(_("Address Count"), rdr,
+			"text", ADDRGATHER_COL_COUNT,
+			NULL);
+	gtk_tree_view_column_set_min_width(col, FIELDS_COL_WIDTH_COUNT);
+	gtk_tree_view_append_column(GTK_TREE_VIEW(viewCount), col);
+
+	gtk_container_add( GTK_CONTAINER(scrollwin), viewCount );
+
+	addrgather_dlg.viewCount = viewCount;
 }
 
 /*

commit c40b4f33b5812c43baf8f0ebaa454f8f519de83a
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Sat Feb 17 17:49:08 2018 +0100

    Replace GtkCMCList in folder sort dialog with GtkTreeView.

diff --git a/src/gtk/foldersort.c b/src/gtk/foldersort.c
index 659303f..79f85a8 100644
--- a/src/gtk/foldersort.c
+++ b/src/gtk/foldersort.c
@@ -1,6 +1,6 @@
 /*
  * Claws-Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2004-2012 the Claws Mail Team
+ * Copyright (C) 2004-2018 the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,6 +27,12 @@
 #include "inc.h"
 #include "utils.h"
 
+enum {
+	FOLDERSORT_COL_NAME,
+	FOLDERSORT_COL_PTR,
+	N_FOLDERSORT_COLS
+};
+
 typedef struct _FolderSortDialog FolderSortDialog;
 
 struct _FolderSortDialog
@@ -35,8 +41,7 @@ struct _FolderSortDialog
 	GtkWidget *moveup_btn;
 	GtkWidget *movedown_btn;
 	GtkWidget *folderlist;
-
-	gint rows, selected;
+	gint rows;
 };
 
 static void destroy_dialog(FolderSortDialog *dialog)
@@ -50,10 +55,17 @@ static void destroy_dialog(FolderSortDialog *dialog)
 static void ok_clicked(GtkWidget *widget, FolderSortDialog *dialog)
 {
 	Folder *folder;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
 	int i;
 
+	model = gtk_tree_view_get_model(GTK_TREE_VIEW(dialog->folderlist));
+
 	for (i = 0; i < dialog->rows; i++) {
-		folder = gtk_cmclist_get_row_data(GTK_CMCLIST(dialog->folderlist), i);
+		if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, i))
+			continue;
+
+		gtk_tree_model_get(model, &iter, FOLDERSORT_COL_PTR, &folder, -1);
 
 		folder_set_sort(folder, dialog->rows - i);
 	}
@@ -66,53 +78,119 @@ static void cancel_clicked(GtkWidget *widget, FolderSortDialog *dialog)
 	destroy_dialog(dialog);
 }
 
-static void set_selected(FolderSortDialog *dialog, gint row)
+static void set_selected(FolderSortDialog *dialog)
 {
-	if (row >= 0) {
-		gtk_widget_set_sensitive(dialog->moveup_btn, row > 0);
-		gtk_widget_set_sensitive(dialog->movedown_btn, row < (dialog->rows - 1));
+	GtkTreeSelection *sel;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	GtkTreePath *path;
+	gint *indices;
+	gint selected;
+
+	/* Get row number of the selected row */
+	sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->folderlist));
+	gtk_tree_selection_get_selected(sel, &model, &iter);
+	path = gtk_tree_model_get_path(model, &iter);
+	indices = gtk_tree_path_get_indices(path);
+	selected = indices[0];
+	gtk_tree_path_free(path);
+
+	if (selected >= 0) {
+		gtk_widget_set_sensitive(dialog->moveup_btn, selected > 0);
+		gtk_widget_set_sensitive(dialog->movedown_btn, selected < (dialog->rows - 1));
 	} else {
 		gtk_widget_set_sensitive(dialog->moveup_btn, FALSE);
 		gtk_widget_set_sensitive(dialog->movedown_btn, FALSE);
 	}
-
-	dialog->selected = row;
 }
 
 static void moveup_clicked(GtkWidget *widget, FolderSortDialog *dialog)
 {
-	cm_return_if_fail(dialog->selected > 0);
+	GtkTreeSelection *sel;
+	GtkTreeModel *model;
+	GtkTreeIter iter, previter;
+#if !GTK_CHECK_VERSION(3, 0, 0)
+	GtkTreePath *path;
+#endif
+
+	/* Get currently selected iter */
+	sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->folderlist));
+	gtk_tree_selection_get_selected(sel, &model, &iter);
+
+	/* Now get the iter above it, if any */
+#if GTK_CHECK_VERSION(3, 0, 0)
+	previter = iter;
+	if (!gtk_tree_model_iter_previous(model, &previter)) {
+		/* No previous iter, are we already on top? */
+		return;
+	}
+#else
+	/* GTK+2 does not have gtk_tree_model_iter_previous(), so
+	 * we have to get through GtkPath */
+	path = gtk_tree_model_get_path(model, &iter);
+	if (!gtk_tree_path_prev(path)) {
+		/* No previous path, are we already on top? */
+		gtk_tree_path_free(path);
+		return;
+	}
+
+	if (!gtk_tree_model_get_iter(model, &previter, path)) {
+		/* Eh? */
+		gtk_tree_path_free(path);
+		return;
+	}
+
+	gtk_tree_path_free(path);
+#endif
 
-	gtk_cmclist_swap_rows(GTK_CMCLIST(dialog->folderlist), dialog->selected, dialog->selected - 1);
+	gtk_list_store_move_before(GTK_LIST_STORE(model), &iter, &previter);
+
+	set_selected(dialog);
 }
 
 static void movedown_clicked(GtkWidget *widget, FolderSortDialog *dialog)
 {
-	cm_return_if_fail(dialog->selected < (dialog->rows - 1));
+	GtkTreeSelection *sel;
+	GtkTreeModel *model;
+	GtkTreeIter iter, nextiter;
+
+	/* Get currently selected iter */
+	sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->folderlist));
+	gtk_tree_selection_get_selected(sel, &model, &iter);
+
+	/* Now get the iter above it, if any */
+	nextiter = iter;
+	if (!gtk_tree_model_iter_next(model, &nextiter)) {
+		/* No next iter, are we already on the bottom? */
+		return;
+	}
 
-	gtk_cmclist_swap_rows(GTK_CMCLIST(dialog->folderlist), dialog->selected, dialog->selected + 1);
-}
+	gtk_list_store_move_after(GTK_LIST_STORE(model), &iter, &nextiter);
 
-static void row_selected(GtkCMCList *clist, gint row, gint column, GdkEventButton *event, FolderSortDialog *dialog)
-{
-	set_selected(dialog, row);
+	set_selected(dialog);
 }
 
-static void row_unselected(GtkCMCList *clist, gint row, gint column, GdkEventButton *event, FolderSortDialog *dialog)
+static void folderlist_cursor_changed_cb(GtkTreeView *view, gpointer user_data)
 {
-	set_selected(dialog, -1);
+	FolderSortDialog *dialog = (FolderSortDialog *)user_data;
+	set_selected(dialog);
 }
 
-static void row_moved(GtkCMCList *clist, gint srcpos, gint destpos, FolderSortDialog *dialog)
+static void folderlist_row_inserted_cb(GtkTreeModel *model,
+		GtkTreePath *path, GtkTreeIter *iter,
+		gpointer user_data)
 {
-	if (dialog->selected == -1)
-		return;
-	else if (srcpos == dialog->selected)
-		set_selected(dialog, destpos);
-	else if (srcpos < dialog->selected && destpos >= dialog->selected)
-		set_selected(dialog, dialog->selected - 1);
-	else if (srcpos > dialog->selected && destpos <= dialog->selected)
-		set_selected(dialog, dialog->selected + 1);
+	FolderSortDialog *dialog = (FolderSortDialog *)user_data;
+	GtkTreeSelection *sel;
+
+	/* The only time "row-inserted" signal should be fired is when
+	 * a row is reordered using drag&drop. So we want to select
+	 * the recently moved row, and call set_selected(), to update
+	 * the up/down button sensitivity. */
+	sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->folderlist));
+	gtk_tree_selection_select_iter(sel, iter);
+
+	set_selected(dialog);
 }
 
 static gint delete_event(GtkWidget *widget, GdkEventAny *event, FolderSortDialog *dialog)
@@ -147,7 +225,11 @@ void foldersort_open()
 	GtkWidget *btn_vbox;
 	GtkWidget *scrolledwindow1;
 	GtkWidget *folderlist;
-	GtkWidget *label2;
+	GtkTreeViewColumn *col;
+	GtkListStore *store;
+	GtkCellRenderer *rdr;
+	GtkTreeSelection *selector;
+	GtkTreeIter iter;
 
 	window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "foldersort");
 	g_object_set_data(G_OBJECT(window), "window", window);
@@ -207,17 +289,26 @@ void foldersort_open()
 				       GTK_POLICY_AUTOMATIC,
 				       GTK_POLICY_AUTOMATIC);
 
-	folderlist = gtk_cmclist_new(1);
+	/* Create the list store */
+	store = gtk_list_store_new(N_FOLDERSORT_COLS,
+			G_TYPE_STRING, G_TYPE_POINTER, -1);
+
+	/* Create the view widget */
+	folderlist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(folderlist), TRUE);
+	gtk_tree_view_set_reorderable(GTK_TREE_VIEW(folderlist), TRUE);
+	selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(folderlist));
+	gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
+
+	/* The only column for the view widget */
+	rdr = gtk_cell_renderer_text_new();
+	col = gtk_tree_view_column_new_with_attributes(_("Mailboxes"),
+			rdr, "markup", FOLDERSORT_COL_NAME, NULL);
+	gtk_tree_view_column_set_min_width(col, 80);
+	gtk_tree_view_append_column(GTK_TREE_VIEW(folderlist), col);
+
 	gtk_widget_show(folderlist);
 	gtk_container_add(GTK_CONTAINER(scrolledwindow1), folderlist);
-	gtk_cmclist_set_column_width(GTK_CMCLIST(folderlist), 0, 80);
-	gtk_cmclist_column_titles_show(GTK_CMCLIST(folderlist));
-
-	label2 = gtk_label_new(_("Mailboxes"));
-	gtk_widget_show(label2);
-	gtk_cmclist_set_column_widget(GTK_CMCLIST(folderlist), 0, label2);
-	gtk_label_set_justify(GTK_LABEL(label2), GTK_JUSTIFY_LEFT);
-	gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
 
 	btn_vbox = gtk_vbox_new(FALSE, 8);
 	gtk_widget_show(btn_vbox);
@@ -239,38 +330,45 @@ void foldersort_open()
 	gtk_widget_show(window);
 	gtk_widget_set_sensitive(moveup_btn, FALSE);
 	gtk_widget_set_sensitive(movedown_btn, FALSE);
-	gtk_cmclist_set_reorderable(GTK_CMCLIST(folderlist), TRUE);
 
+	/* Connect up the signals for the up/down buttons */
 	g_signal_connect(G_OBJECT(moveup_btn), "clicked",
                          G_CALLBACK(moveup_clicked), dialog);
 	g_signal_connect(G_OBJECT(movedown_btn), "clicked",
                          G_CALLBACK(movedown_clicked), dialog);
 
-	g_signal_connect(G_OBJECT(folderlist), "select-row",
-			 G_CALLBACK(row_selected), dialog);
-	g_signal_connect(G_OBJECT(folderlist), "unselect-row",
-			 G_CALLBACK(row_unselected), dialog);
-	g_signal_connect(G_OBJECT(folderlist), "row-move",
-			 G_CALLBACK(row_moved), dialog);
+//	g_signal_connect(G_OBJECT(folderlist), "select-row",
+//			 G_CALLBACK(row_selected), dialog);
+//	g_signal_connect(G_OBJECT(folderlist), "unselect-row",
+//			 G_CALLBACK(row_unselected), dialog);
+//	g_signal_connect(G_OBJECT(folderlist), "row-move",
+//			 G_CALLBACK(row_moved), dialog);
 
+	/* Populate the list with mailboxes */
 	dialog->rows = 0;
-	dialog->selected = -1;
 	for (flist = folder_get_list(); flist != NULL; flist = g_list_next(flist)) {
 		Folder *folder = flist->data;
-		int row;
-		gchar *text[1];
 
-		text[0] = folder->name;
-		row = gtk_cmclist_append(GTK_CMCLIST(folderlist), text);
-		gtk_cmclist_set_row_data(GTK_CMCLIST(folderlist), row, folder);
+		gtk_list_store_append(store, &iter);
+		gtk_list_store_set(store, &iter,
+				FOLDERSORT_COL_NAME, folder->name,
+				FOLDERSORT_COL_PTR, folder,
+				-1);
 		dialog->rows++;
 	}
 
-	/* We are setting the selection mode here, after the list has been
-	 * populated, so that when the first row gets selected by default,
-	 * the triggered set_selected() function can correctly set sensitivity
-	 * on up/down buttons. */
-	gtk_cmclist_set_selection_mode(GTK_CMCLIST(folderlist), GTK_SELECTION_BROWSE);
+	/* Connect up the signals for the folderlist */
+	g_signal_connect(G_OBJECT(folderlist), "cursor-changed",
+			G_CALLBACK(folderlist_cursor_changed_cb), dialog);
+	g_signal_connect(G_OBJECT(store), "row-inserted",
+			G_CALLBACK(folderlist_row_inserted_cb), dialog);
+
+	/* Select the first row and adjust the sensitivity of
+	 * the up/down buttons */
+	if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) {
+		gtk_tree_selection_select_iter(selector, &iter);
+		set_selected(dialog);
+	}
 
 	inc_lock();
 }
diff --git a/src/gtk/foldersort.h b/src/gtk/foldersort.h
index 21c2564..505dbb2 100644
--- a/src/gtk/foldersort.h
+++ b/src/gtk/foldersort.h
@@ -1,6 +1,6 @@
 /*
  * Claws-Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2004-2012 the Claws Mail Team
+ * Copyright (C) 2004-2018 the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
  */
 
 #ifndef FOLDERSORT_H
-#define FOLDERSORT_H 1
+#define FOLDERSORT_H
 
 void foldersort_open(void);
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list