[Commits] [SCM] claws branch, master, updated. 3.16.0-76-gb357c3b
ticho at claws-mail.org
ticho at claws-mail.org
Tue Feb 27 19:46:09 CET 2018
The branch, master has been updated
via b357c3b93e69f90077bfb7c3884b91e5c0ac45e1 (commit)
from 6329dc382d539135add187c5b1e8cf6efe1a9d22 (commit)
Summary of changes:
src/account.c | 29 +++++++----------------------
src/addressadd.c | 12 ++----------
src/gtk/gtkutils.c | 32 ++++++++++++++++++++++++++++++++
src/gtk/gtkutils.h | 4 ++++
src/importldif.c | 10 +++-------
src/mimeview.c | 12 ++----------
src/plugins/pgpcore/select-keys.c | 11 ++---------
src/ssl_manager.c | 13 +++----------
8 files changed, 55 insertions(+), 68 deletions(-)
- Log -----------------------------------------------------------------
commit b357c3b93e69f90077bfb7c3884b91e5c0ac45e1
Author: Andrej Kacian <ticho at claws-mail.org>
Date: Sun Feb 25 20:40:38 2018 +0100
Add gtkut_tree_view_get_selected_pointer() helper function.
It's meant for the simple cases when you just want to get
a pointer out of a treeview's selected row and you're not
going to do anything with the view, nor the model.
diff --git a/src/account.c b/src/account.c
index 87f8953..52e88f5 100644
--- a/src/account.c
+++ b/src/account.c
@@ -1630,19 +1630,12 @@ static void account_create_list_view_columns(GtkWidget *list_view)
*/
static gint account_list_view_get_selected_account_id(GtkWidget *list_view)
{
- GtkTreeSelection *selector;
- GtkTreeModel *model;
- GtkTreeIter iter;
PrefsAccount *res = NULL;
- selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
-
- if (!gtk_tree_selection_get_selected(selector, &model, &iter))
- return -1;
-
- gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
+ res = (PrefsAccount *)gtkut_tree_view_get_selected_pointer(
+ GTK_TREE_VIEW(list_view), ACCOUNT_DATA);
- return res->account_id;
+ return (res != NULL ? res->account_id : -1);
}
/*!
@@ -1668,19 +1661,11 @@ static GtkTreePath *account_list_view_get_selected_account_path(GtkWidget *list_
*/
static PrefsAccount *account_list_view_get_selected_account(GtkWidget *list_view)
{
- GtkTreeSelection *selector;
- GtkTreeModel *model;
- GtkTreeIter iter;
- PrefsAccount *res = NULL;
-
- selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
-
- if (!gtk_tree_selection_get_selected(selector, &model, &iter))
- return NULL;
-
- gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
+ PrefsAccount *res =
+ (PrefsAccount *)gtkut_tree_view_get_selected_pointer(
+ GTK_TREE_VIEW(list_view), ACCOUNT_DATA);
- return res;
+ return res;
}
/*!
diff --git a/src/addressadd.c b/src/addressadd.c
index 44e28ca..a6a7f2a 100644
--- a/src/addressadd.c
+++ b/src/addressadd.c
@@ -131,16 +131,8 @@ static gboolean addressadd_key_pressed( GtkWidget *widget, GdkEventKey *event, g
/* Points addressadd_dlg.fiSelected to the selected item */
static void set_selected_ptr()
{
- GtkWidget *view = addressadd_dlg.tree_folder;
- GtkTreeModel *model;
- GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
- GtkTreeIter iter;
-
- if (gtk_tree_selection_get_selected(sel, &model, &iter)) {
- gtk_tree_model_get(model, &iter,
- ADDRADD_COL_PTR, &addressadd_dlg.fiSelected,
- -1);
- }
+ addressadd_dlg.fiSelected = gtkut_tree_view_get_selected_pointer(
+ GTK_TREE_VIEW(addressadd_dlg.tree_folder), ADDRADD_COL_PTR);
}
static void addressadd_ok( GtkWidget *widget, gboolean *cancelled ) {
diff --git a/src/gtk/gtkutils.c b/src/gtk/gtkutils.c
index a933471..689af37 100644
--- a/src/gtk/gtkutils.c
+++ b/src/gtk/gtkutils.c
@@ -1989,3 +1989,35 @@ gboolean auto_configure_service_sync(const gchar *service, const gchar *domain,
return result;
}
#endif
+
+gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
+ gint column)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeSelection *sel;
+ gpointer ptr;
+
+ cm_return_val_if_fail(view != NULL, NULL);
+ cm_return_val_if_fail(column >= 0, NULL);
+
+ sel = gtk_tree_view_get_selection(view);
+
+ cm_return_val_if_fail(
+ gtk_tree_selection_count_selected_rows(sel) == 1,
+ NULL);
+
+ if (!gtk_tree_selection_get_selected(sel, &model, &iter))
+ return NULL; /* No row selected */
+
+ cm_return_val_if_fail(
+ gtk_tree_model_get_n_columns(model) > column,
+ NULL);
+ cm_return_val_if_fail(
+ gtk_tree_model_get_column_type(model, column) == G_TYPE_POINTER,
+ NULL);
+
+ gtk_tree_model_get(model, &iter, column, &ptr, -1);
+
+ return ptr;
+}
diff --git a/src/gtk/gtkutils.h b/src/gtk/gtkutils.h
index 6942831..eaf0fb0 100644
--- a/src/gtk/gtkutils.h
+++ b/src/gtk/gtkutils.h
@@ -232,6 +232,10 @@ void auto_configure_service(AutoConfigureData *data);
gboolean auto_configure_service_sync(const gchar *service, const gchar *domain, gchar **srvhost, guint16 *srvport);
#endif
+/* Returns pointer stored in selected row of a tree view's model
+ * in a given column. The column has to be of type G_TYPE_POINTER. */
+gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
+ gint column);
#if GTK_CHECK_VERSION (3, 2, 0)
#define GTK_TYPE_VBOX GTK_TYPE_BOX
diff --git a/src/importldif.c b/src/importldif.c
index 379ea7c..707146c 100644
--- a/src/importldif.c
+++ b/src/importldif.c
@@ -588,16 +588,12 @@ static void imp_ldif_page_file( gint pageNum, gchar *pageLbl ) {
static void imp_ldif_field_list_cursor_changed(GtkTreeView *view,
gpointer user_data)
{
- GtkTreeModel *model;
- GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
- GtkTreeIter iter;
Ldif_FieldRec *rec;
- if (!gtk_tree_selection_get_selected(sel, &model, &iter))
- return; /* No row selected */
- gtk_tree_model_get(model, &iter, FIELD_COL_PTR, &rec, -1);
-
gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" );
+
+ rec = gtkut_tree_view_get_selected_pointer(view, FIELD_COL_PTR);
+
if( rec != NULL) {
/* Update widget contents */
gtk_label_set_text(
diff --git a/src/mimeview.c b/src/mimeview.c
index 223af09..82cfd78 100644
--- a/src/mimeview.c
+++ b/src/mimeview.c
@@ -568,16 +568,8 @@ void mimeview_destroy(MimeView *mimeview)
MimeInfo *mimeview_get_selected_part(MimeView *mimeview)
{
- GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview->ctree));
- GtkTreeIter iter;
- GtkTreeSelection *selection;
- MimeInfo *partinfo = NULL;
-
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mimeview->ctree));
- if (gtk_tree_selection_get_selected(selection, NULL, &iter))
- gtk_tree_model_get(model, &iter, COL_DATA, &partinfo, -1);
-
- return partinfo;
+ return gtkut_tree_view_get_selected_pointer(
+ GTK_TREE_VIEW(mimeview->ctree), COL_DATA);
}
MimeInfo *mimeview_get_node_part(MimeView *mimeview, GtkTreePath *path)
diff --git a/src/plugins/pgpcore/select-keys.c b/src/plugins/pgpcore/select-keys.c
index f558f6b..0598851 100644
--- a/src/plugins/pgpcore/select-keys.c
+++ b/src/plugins/pgpcore/select-keys.c
@@ -610,18 +610,11 @@ select_btn_cb (GtkWidget *widget, gpointer data)
struct select_keys_s *sk = data;
gboolean use_key;
gpgme_key_t key;
- GtkTreeModel *model;
- GtkTreeSelection *sel;
- GtkTreeIter iter;
cm_return_if_fail (sk);
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(sk->view));
- if (!gtk_tree_selection_get_selected(sel, &model, &iter)) {
- debug_print ("** nothing selected\n");
- return;
- }
- gtk_tree_model_get(model, &iter, COL_PTR, &key, -1);
+ key = gtkut_tree_view_get_selected_pointer(
+ GTK_TREE_VIEW(sk->view), COL_PTR);
if (key) {
gpgme_user_id_t uid;
for (uid = key->uids; uid; uid = uid->next) {
diff --git a/src/ssl_manager.c b/src/ssl_manager.c
index 9c75cf0..1792b35 100644
--- a/src/ssl_manager.c
+++ b/src/ssl_manager.c
@@ -425,17 +425,10 @@ static void ssl_manager_view_cb(GtkWidget *widget,
gpointer data)
{
SSLCertificate *cert;
- GtkTreeIter sel;
- GtkTreeModel *model;
- if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection
- (GTK_TREE_VIEW(manager.certlist)),
- &model, &sel))
- return;
-
- gtk_tree_model_get(model, &sel,
- SSL_MANAGER_CERT, &cert,
- -1);
+ cert = gtkut_tree_view_get_selected_pointer(
+ GTK_TREE_VIEW(manager.certlist), SSL_MANAGER_CERT);
+
if (!cert)
return;
-----------------------------------------------------------------------
hooks/post-receive
--
Claws Mail
More information about the Commits
mailing list