2020-11-11 20:42:31 +01:00
|
|
|
/*
|
|
|
|
** Copyright (C) 2008-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mug-msg-list-view.h"
|
|
|
|
#include "mu-query.hh"
|
|
|
|
#include "utils/mu-str.h"
|
|
|
|
#include "utils/mu-date.h"
|
2020-11-28 09:07:13 +01:00
|
|
|
|
|
|
|
using namespace Mu;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
|
|
|
/* 'private'/'protected' functions */
|
2021-10-20 11:18:15 +02:00
|
|
|
static void mug_msg_list_view_finalize(GObject* obj);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
|
|
|
/* list my signals */
|
2021-10-20 11:18:15 +02:00
|
|
|
enum { MUG_MSG_SELECTED, MUG_ERROR_OCCURED, LAST_SIGNAL };
|
2020-11-11 20:42:31 +01:00
|
|
|
|
|
|
|
enum {
|
2021-10-20 11:18:15 +02:00
|
|
|
MUG_COL_DATESTR,
|
|
|
|
MUG_COL_MAILDIR,
|
|
|
|
MUG_COL_FLAGSSTR,
|
|
|
|
MUG_COL_FROM,
|
|
|
|
MUG_COL_TO,
|
|
|
|
MUG_COL_SUBJECT,
|
|
|
|
MUG_COL_PATH,
|
|
|
|
MUG_COL_PRIO,
|
|
|
|
MUG_COL_FLAGS,
|
|
|
|
MUG_COL_TIME,
|
|
|
|
MUG_N_COLS
|
2020-11-11 20:42:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _MugMsgListViewPrivate MugMsgListViewPrivate;
|
|
|
|
struct _MugMsgListViewPrivate {
|
2021-10-20 11:18:15 +02:00
|
|
|
GtkTreeStore* _store;
|
|
|
|
char* _xpath;
|
|
|
|
char* _query;
|
2020-11-11 20:42:31 +01:00
|
|
|
};
|
2021-10-20 11:18:15 +02:00
|
|
|
#define MUG_MSG_LIST_VIEW_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), MUG_TYPE_MSG_LIST_VIEW, MugMsgListViewPrivate))
|
2020-11-11 20:42:31 +01:00
|
|
|
/* globals */
|
2021-10-20 11:18:15 +02:00
|
|
|
static GtkTreeViewClass* parent_class = NULL;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
|
|
|
/* uncomment the following if you have defined any signals */
|
2021-10-20 11:18:15 +02:00
|
|
|
static guint signals[LAST_SIGNAL] = {0};
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
G_DEFINE_TYPE(MugMsgListView, mug_msg_list_view, GTK_TYPE_TREE_VIEW);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
mug_msg_list_view_class_init(MugMsgListViewClass* klass)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
GObjectClass* gobject_class;
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
|
|
|
|
parent_class = (GtkTreeViewClass*)g_type_class_peek_parent(klass);
|
|
|
|
gobject_class->finalize = mug_msg_list_view_finalize;
|
|
|
|
|
|
|
|
g_type_class_add_private(gobject_class, sizeof(MugMsgListViewPrivate));
|
|
|
|
|
|
|
|
signals[MUG_MSG_SELECTED] = g_signal_new("msg-selected",
|
|
|
|
G_TYPE_FROM_CLASS(gobject_class),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET(MugMsgListViewClass, msg_selected),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
g_cclosure_marshal_VOID__STRING,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
1,
|
|
|
|
G_TYPE_STRING);
|
|
|
|
signals[MUG_ERROR_OCCURED] =
|
|
|
|
g_signal_new("error-occured",
|
|
|
|
G_TYPE_FROM_CLASS(gobject_class),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET(MugMsgListViewClass, error_occured),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
g_cclosure_marshal_VOID__UINT,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
1,
|
|
|
|
G_TYPE_UINT);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
on_cursor_changed(GtkTreeView* tview, MugMsgListView* lst)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
GtkTreeSelection* sel;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
MugMsgListViewPrivate* priv;
|
|
|
|
|
|
|
|
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(tview);
|
|
|
|
|
|
|
|
sel = gtk_tree_view_get_selection(tview);
|
|
|
|
if (!sel)
|
|
|
|
return; /* hmmm */
|
|
|
|
if (gtk_tree_selection_get_selected(sel, NULL, &iter)) {
|
|
|
|
char* path;
|
|
|
|
gtk_tree_model_get(GTK_TREE_MODEL(priv->_store), &iter, MUG_COL_PATH, &path, -1);
|
|
|
|
g_signal_emit(G_OBJECT(lst), signals[MUG_MSG_SELECTED], 0, path);
|
|
|
|
g_free(path);
|
|
|
|
}
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
treecell_func(GtkTreeViewColumn* tree_column,
|
|
|
|
GtkCellRenderer* renderer,
|
|
|
|
GtkTreeModel* tree_model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
gpointer data)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuFlags flags;
|
|
|
|
MuMsgPrio prio;
|
|
|
|
|
|
|
|
gtk_tree_model_get(tree_model, iter, MUG_COL_FLAGS, &flags, MUG_COL_PRIO, &prio, -1);
|
|
|
|
|
|
|
|
g_object_set(G_OBJECT(renderer),
|
|
|
|
"weight",
|
|
|
|
(flags & MU_FLAG_NEW) ? 800 : 400,
|
|
|
|
"weight",
|
|
|
|
(flags & MU_FLAG_SEEN) ? 400 : 800,
|
|
|
|
"foreground",
|
|
|
|
prio == MU_MSG_PRIO_HIGH ? "red" : NULL,
|
|
|
|
NULL);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sortcolidx == -1 means 'sortcolidx = colidx' */
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
append_col(GtkTreeView* treeview, const char* label, int colidx, int sortcolidx, gint maxwidth)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
GtkTreeViewColumn* col;
|
|
|
|
GtkCellRenderer* renderer;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
col = gtk_tree_view_column_new_with_attributes(label, renderer, "text", colidx, NULL);
|
|
|
|
g_object_set(G_OBJECT(col), "resizable", TRUE, NULL);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_tree_view_column_set_sort_indicator(col, TRUE);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (sortcolidx == -1)
|
|
|
|
sortcolidx = colidx;
|
|
|
|
gtk_tree_view_column_set_sort_column_id(col, sortcolidx);
|
|
|
|
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (maxwidth) {
|
|
|
|
gtk_tree_view_column_set_fixed_width(col, maxwidth);
|
|
|
|
gtk_tree_view_column_set_expand(col, FALSE);
|
|
|
|
} else
|
|
|
|
gtk_tree_view_column_set_expand(col, TRUE);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_tree_view_column_set_cell_data_func(col,
|
|
|
|
renderer,
|
|
|
|
(GtkTreeCellDataFunc)treecell_func,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_tree_view_append_column(treeview, col);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_tree_view_columns_autosize(treeview);
|
|
|
|
gtk_tree_view_set_fixed_height_mode(treeview, TRUE);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
mug_msg_list_view_init(MugMsgListView* obj)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MugMsgListViewPrivate* priv;
|
|
|
|
GtkTreeView* tview;
|
|
|
|
|
|
|
|
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(obj);
|
|
|
|
|
|
|
|
priv->_xpath = priv->_query = NULL;
|
|
|
|
priv->_store = gtk_tree_store_new(MUG_N_COLS,
|
|
|
|
G_TYPE_STRING, /* date */
|
|
|
|
G_TYPE_STRING, /* folder */
|
|
|
|
G_TYPE_STRING, /* flagstr */
|
|
|
|
G_TYPE_STRING, /* from */
|
|
|
|
G_TYPE_STRING, /* to */
|
|
|
|
G_TYPE_STRING, /* subject */
|
|
|
|
G_TYPE_STRING, /* path */
|
|
|
|
G_TYPE_UINT, /* prio */
|
|
|
|
G_TYPE_UINT, /* flags */
|
|
|
|
G_TYPE_INT); /* timeval */
|
|
|
|
|
|
|
|
tview = GTK_TREE_VIEW(obj);
|
|
|
|
gtk_tree_view_set_model(tview, GTK_TREE_MODEL(priv->_store));
|
|
|
|
gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(obj), TRUE);
|
|
|
|
gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(obj), GTK_TREE_VIEW_GRID_LINES_VERTICAL);
|
|
|
|
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(obj), TRUE);
|
|
|
|
|
|
|
|
append_col(tview, "Date", MUG_COL_DATESTR, MUG_COL_TIME, 80);
|
|
|
|
append_col(tview, "Folder", MUG_COL_MAILDIR, -1, 60);
|
|
|
|
append_col(tview, "F", MUG_COL_FLAGSSTR, -1, 25);
|
|
|
|
append_col(tview, "From", MUG_COL_FROM, -1, 0);
|
|
|
|
append_col(tview, "To", MUG_COL_TO, -1, 0);
|
|
|
|
append_col(tview, "Subject", MUG_COL_SUBJECT, -1, 0);
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(obj), "cursor-changed", G_CALLBACK(on_cursor_changed), obj);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
mug_msg_list_view_finalize(GObject* obj)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MugMsgListViewPrivate* priv;
|
|
|
|
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(obj);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (priv->_store)
|
|
|
|
g_object_unref(priv->_store);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(priv->_xpath);
|
|
|
|
g_free(priv->_query);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
G_OBJECT_CLASS(parent_class)->finalize(obj);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-10-20 11:18:15 +02:00
|
|
|
mug_msg_list_view_move_first(MugMsgListView* self)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
GtkTreePath* path;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_if_fail(MUG_IS_MSG_LIST_VIEW(self));
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
path = gtk_tree_path_new_first();
|
|
|
|
gtk_tree_view_set_cursor(GTK_TREE_VIEW(self), path, NULL, FALSE);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_tree_path_free(path);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
msg_list_view_move(MugMsgListView* self, gboolean next)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
GtkTreePath* path;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_tree_view_get_cursor(GTK_TREE_VIEW(self), &path, NULL);
|
|
|
|
if (!path)
|
|
|
|
return FALSE;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (next)
|
|
|
|
gtk_tree_path_next(path);
|
|
|
|
else
|
|
|
|
gtk_tree_path_prev(path);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_tree_view_set_cursor(GTK_TREE_VIEW(self), path, NULL, FALSE);
|
|
|
|
gtk_tree_path_free(path);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return TRUE;
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
mug_msg_list_view_move_next(MugMsgListView* self)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(MUG_IS_MSG_LIST_VIEW(self), FALSE);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return msg_list_view_move(self, TRUE);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
mug_msg_list_view_move_prev(MugMsgListView* self)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(MUG_IS_MSG_LIST_VIEW(self), FALSE);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return msg_list_view_move(self, FALSE);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
GtkWidget*
|
|
|
|
mug_msg_list_view_new(const char* xpath)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
GtkWidget* w;
|
|
|
|
MugMsgListViewPrivate* priv;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(xpath, NULL);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
w = GTK_WIDGET(g_object_new(MUG_TYPE_MSG_LIST_VIEW, NULL));
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(w);
|
|
|
|
priv->_xpath = g_strdup(xpath);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return w;
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
static gchar*
|
|
|
|
empty_or_display_contact(const gchar* str)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!str || *str == '\0')
|
|
|
|
return g_strdup("-");
|
|
|
|
else
|
|
|
|
return mu_str_display_contact(str);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
2020-11-28 09:07:13 +01:00
|
|
|
static Mu::Option<Mu::QueryResults>
|
2021-10-20 11:18:15 +02:00
|
|
|
run_query(const char* xpath, const char* expr, MugMsgListView* self)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::Store store{xpath};
|
|
|
|
Mu::Query query{store};
|
|
|
|
|
|
|
|
return query.run(expr,
|
|
|
|
MU_MSG_FIELD_ID_DATE,
|
|
|
|
Mu::QueryFlags::Descending | Mu::QueryFlags::SkipUnreadable |
|
|
|
|
Mu::QueryFlags::SkipDuplicates | Mu::QueryFlags::IncludeRelated |
|
|
|
|
Mu::QueryFlags::Threading);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
add_row(GtkTreeStore* store, MuMsg* msg, GtkTreeIter* treeiter)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
const gchar *datestr, *flagstr;
|
|
|
|
gchar * from, *to;
|
|
|
|
time_t timeval;
|
|
|
|
|
|
|
|
timeval = mu_msg_get_date(msg);
|
|
|
|
datestr = timeval == 0 ? "-" : mu_date_display_s(timeval);
|
|
|
|
from = empty_or_display_contact(mu_msg_get_from(msg));
|
|
|
|
to = empty_or_display_contact(mu_msg_get_to(msg));
|
|
|
|
flagstr = mu_flags_to_str_s(mu_msg_get_flags(msg), MU_FLAG_TYPE_ANY);
|
|
|
|
|
|
|
|
/* if (0) { */
|
|
|
|
/* GtkTreeIter myiter; */
|
|
|
|
/* if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(store), */
|
|
|
|
/* &myiter, path)) */
|
|
|
|
/* g_warning ("%s: cannot get iter for %s",
|
|
|
|
* __func__, path); */
|
|
|
|
/* } */
|
|
|
|
|
|
|
|
gtk_tree_store_set(store,
|
|
|
|
treeiter,
|
|
|
|
MUG_COL_DATESTR,
|
|
|
|
datestr,
|
|
|
|
MUG_COL_MAILDIR,
|
|
|
|
mu_msg_get_maildir(msg),
|
|
|
|
MUG_COL_FLAGSSTR,
|
|
|
|
flagstr,
|
|
|
|
MUG_COL_FROM,
|
|
|
|
from,
|
|
|
|
MUG_COL_TO,
|
|
|
|
to,
|
|
|
|
MUG_COL_SUBJECT,
|
|
|
|
mu_msg_get_subject(msg),
|
|
|
|
MUG_COL_PATH,
|
|
|
|
mu_msg_get_path(msg),
|
|
|
|
MUG_COL_PRIO,
|
|
|
|
mu_msg_get_prio(msg),
|
|
|
|
MUG_COL_FLAGS,
|
|
|
|
mu_msg_get_flags(msg),
|
|
|
|
MUG_COL_TIME,
|
|
|
|
timeval,
|
|
|
|
-1);
|
|
|
|
g_free(from);
|
|
|
|
g_free(to);
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-10-20 11:18:15 +02:00
|
|
|
update_model(GtkTreeStore* store, const char* xpath, const char* query, MugMsgListView* self)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
const auto res{run_query(xpath, query, self)};
|
|
|
|
if (!res) {
|
|
|
|
g_warning("error: running query failed");
|
|
|
|
return -1;
|
|
|
|
}
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
auto count{0};
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
std::string prev_thread_path;
|
|
|
|
for (auto&& it : *res) {
|
|
|
|
GtkTreeIter treeiter, prev_treeiter;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
const auto thread_path{it.query_match().thread_path};
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (prev_thread_path.find(thread_path) == 0)
|
|
|
|
gtk_tree_store_append(store, &treeiter, &prev_treeiter);
|
|
|
|
else
|
|
|
|
gtk_tree_store_append(store, &treeiter, NULL);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
/* don't unref msg */
|
|
|
|
add_row(store, it.floating_msg(), &treeiter);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
// prev_ti = ti;
|
|
|
|
prev_treeiter = treeiter;
|
|
|
|
prev_thread_path = thread_path;
|
|
|
|
++count;
|
|
|
|
}
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return count;
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2021-10-20 11:18:15 +02:00
|
|
|
mug_msg_list_view_query(MugMsgListView* self, const char* query)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MugMsgListViewPrivate* priv;
|
|
|
|
gboolean rv;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(MUG_IS_MSG_LIST_VIEW(self), FALSE);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(self);
|
|
|
|
gtk_tree_store_clear(priv->_store);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(priv->_query);
|
|
|
|
priv->_query = query ? g_strdup(query) : NULL;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!query)
|
|
|
|
return TRUE;
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
rv = update_model(priv->_store, priv->_xpath, query, self);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_tree_view_expand_all(GTK_TREE_VIEW(self));
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return rv;
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
const gchar*
|
|
|
|
mug_msg_list_view_get_query(MugMsgListView* self)
|
2020-11-11 20:42:31 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_val_if_fail(MUG_IS_MSG_LIST_VIEW(self), NULL);
|
2020-11-11 20:42:31 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return MUG_MSG_LIST_VIEW_GET_PRIVATE(self)->_query;
|
2020-11-11 20:42:31 +01:00
|
|
|
}
|