toys/mug: upgrade for query changes

Mostly, port to c++.
This commit is contained in:
Dirk-Jan C. Binnema 2020-11-28 10:07:13 +02:00
parent 4daa7105d2
commit 90e35a9732
12 changed files with 320 additions and 316 deletions

View File

@ -35,8 +35,12 @@ AM_CFLAGS= \
-Wno-deprecated-declarations \
-Wno-switch-enum
AM_CXXFLAGS=$(WARN_CXXFLAGS)
AM_CXXFLAGS= \
$(WARN_CXXFLAGS) \
$(ASAN_CFLAGS) \
-Wno-redundant-decls \
-Wno-deprecated-declarations \
-Wno-switch-enum
#
# Distributors: this is a _toy_, not for distribution. the "noinst_" says enough
#
@ -48,7 +52,7 @@ mug_SOURCES= \
mug-msg-list-view.cc \
mug-msg-list-view.h \
mug-msg-view.h \
mug-msg-view.c \
mug-msg-view.cc \
mug-query-bar.h \
mug-query-bar.c \
mug-shortcuts.cc \
@ -70,14 +74,14 @@ noinst_LTLIBRARIES= \
libmuwidgets_la_SOURCES= \
mu-widget-util.h \
mu-widget-util.c \
mu-msg-attach-view.c \
mu-msg-attach-view.h \
mu-msg-body-view.c \
mu-msg-body-view.h \
mu-msg-header-view.c \
mu-msg-header-view.h \
mu-msg-view.h \
mu-msg-view.c
mu-msg-attach-view.cc \
mu-msg-attach-view.hh \
mu-msg-body-view.cc \
mu-msg-body-view.hh \
mu-msg-header-view.cc \
mu-msg-header-view.hh \
mu-msg-view.hh \
mu-msg-view.cc
libmuwidgets_la_LIBADD= \
${top_builddir}/lib/libmu.la \

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-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
@ -17,9 +17,12 @@
**
*/
#include "mu-msg-attach-view.h"
#include "mu-msg-attach-view.hh"
#include "mu-widget-util.h"
#include <mu-msg-part.h>
#include <mu-msg.hh>
#include <mu-msg-part.hh>
using namespace Mu;
enum {
ICON_COL,
@ -78,7 +81,7 @@ mu_msg_attach_view_class_init (MuMsgAttachViewClass *klass)
GObjectClass *gobject_class;
gobject_class = (GObjectClass*) klass;
parent_class = g_type_class_peek_parent (klass);
parent_class = (GtkIconViewClass*)g_type_class_peek_parent (klass);
gobject_class->finalize = mu_msg_attach_view_finalize;
g_type_class_add_private (gobject_class, sizeof(MuMsgAttachViewPrivate));
@ -204,7 +207,8 @@ mu_msg_attach_view_init (MuMsgAttachView *obj)
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW(obj),
GTK_SELECTION_MULTIPLE);
/* drag & drop */
gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW(obj), 0, NULL, 0,
gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW(obj),
(GdkModifierType)0, NULL, 0,
GDK_ACTION_COPY);
gtk_drag_source_add_uri_targets(GTK_WIDGET(obj));
g_signal_connect (obj, "drag-data-get", G_CALLBACK(on_drag_data_get), NULL);

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-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
@ -22,7 +22,7 @@
#define __MU_MSG_ATTACH_VIEW_H__
#include <gtk/gtk.h>
#include <mu-msg.h>
#include <mu-msg.hh>
G_BEGIN_DECLS
@ -49,7 +49,7 @@ struct _MuMsgAttachView {
struct _MuMsgAttachViewClass {
GtkIconViewClass parent_class;
void (* attach_activated) (MuMsgAttachView* obj, guint partnum,
MuMsg *msg);
Mu::MuMsg *msg);
};
/* member functions */
@ -60,7 +60,7 @@ GType mu_msg_attach_view_get_type (void) G_GNUC_CONST;
GtkWidget* mu_msg_attach_view_new (void);
/* returns # of attachments */
int mu_msg_attach_view_set_message (MuMsgAttachView *self, MuMsg *msg);
int mu_msg_attach_view_set_message (MuMsgAttachView *self, Mu::MuMsg *msg);
G_END_DECLS

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011-2017 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-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
@ -17,8 +17,10 @@
**
*/
#include "mu-msg-body-view.h"
#include <mu-msg-part.h>
#include "mu-msg-body-view.hh"
#include <mu-msg-part.hh>
using namespace Mu;
enum _ViewMode {
VIEW_MODE_MSG,
@ -79,7 +81,7 @@ mu_msg_body_view_class_init (MuMsgBodyViewClass *klass)
GObjectClass *gobject_class;
gobject_class = (GObjectClass*) klass;
parent_class = g_type_class_peek_parent (klass);
parent_class = (WebKitWebViewClass*)g_type_class_peek_parent (klass);
gobject_class->finalize = mu_msg_body_view_finalize;
g_type_class_add_private (gobject_class, sizeof(MuMsgBodyViewPrivate));

View File

@ -21,7 +21,7 @@
#define __MU_MSG_BODY_VIEW_H__
#include <webkit2/webkit2.h>
#include <mu-msg.h>
#include <mu-msg.hh>
G_BEGIN_DECLS
@ -60,9 +60,9 @@ GType mu_msg_body_view_get_type (void) G_GNUC_CONST;
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
GtkWidget* mu_msg_body_view_new (void);
void mu_msg_body_view_set_message (MuMsgBodyView *self, MuMsg *msg);
void mu_msg_body_view_set_message (MuMsgBodyView *self, Mu::MuMsg *msg);
void mu_msg_body_view_set_note (MuMsgBodyView *self, const gchar *html);
void mu_msg_body_view_set_message_source (MuMsgBodyView *self, MuMsg *msg);
void mu_msg_body_view_set_message_source (MuMsgBodyView *self, Mu::MuMsg *msg);
G_END_DECLS

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-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
@ -16,15 +16,14 @@
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
#include "mu-msg-header-view.h"
#include <config.h>
#include "mu-msg-header-view.hh"
#include "mu-msg.hh"
#include <utils/mu-str.h>
#include <utils/mu-date.h>
#if HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
using namespace Mu;
/* 'private'/'protected' functions */
static void mu_msg_header_view_class_init (MuMsgHeaderViewClass *klass);
@ -59,7 +58,7 @@ mu_msg_header_view_class_init (MuMsgHeaderViewClass *klass)
GObjectClass *gobject_class;
gobject_class = (GObjectClass*) klass;
parent_class = g_type_class_peek_parent (klass);
parent_class = (GtkBoxClass*)g_type_class_peek_parent (klass);
gobject_class->finalize = mu_msg_header_view_finalize;
g_type_class_add_private (gobject_class, sizeof(MuMsgHeaderViewPrivate));
@ -115,7 +114,7 @@ get_label (const gchar *txt, gboolean istitle)
return label;
}
static gboolean
G_GNUC_UNUSED static gboolean
add_row (GtkWidget *grid, guint row, const char* fieldname, const char *value,
gboolean showempty)
{
@ -143,7 +142,7 @@ add_row (GtkWidget *grid, guint row, const char* fieldname, const char *value,
static GtkWidget*
get_grid (MuMsg *msg)
get_grid (Mu::MuMsg *msg)
{
GtkWidget *grid;
int row;
@ -170,7 +169,7 @@ get_grid (MuMsg *msg)
}
void
mu_msg_header_view_set_message (MuMsgHeaderView *self, MuMsg *msg)
mu_msg_header_view_set_message (MuMsgHeaderView *self, Mu::MuMsg *msg)
{
g_return_if_fail (MU_IS_MSG_HEADER_VIEW(self));

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-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
@ -21,11 +21,7 @@
#define __MU_MSG_HEADER_VIEW_H__
#include <gtk/gtk.h>
#include <mu-msg.h>
#if HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <mu-msg.hh>
G_BEGIN_DECLS
@ -61,7 +57,8 @@ GType mu_msg_header_view_get_type (void) G_GNUC_CONST;
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
GtkWidget* mu_msg_header_view_new (void);
void mu_msg_header_view_set_message (MuMsgHeaderView *self, MuMsg *msg);
struct MuMsg;
void mu_msg_header_view_set_message (MuMsgHeaderView *self, Mu::MuMsg *msg);
G_END_DECLS

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-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
@ -17,16 +17,18 @@
**
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include "mu-msg-view.h"
#include "mu-msg-body-view.h"
#include "mu-msg-header-view.h"
#include "mu-msg-attach-view.h"
#include <mu-msg-part.h>
#include "mu-msg-view.hh"
#include "mu-msg-body-view.hh"
#include "mu-msg-header-view.hh"
#include "mu-msg-attach-view.hh"
#include <utils/mu-util.h>
#include <mu-msg.hh>
#include <mu-msg-part.hh>
using namespace Mu;
/* 'private'/'protected' functions */
static void mu_msg_view_class_init (MuMsgViewClass *klass);
@ -42,7 +44,7 @@ enum {
struct _MuMsgViewPrivate {
GtkWidget *_headers, *_attach, *_attachexpander, *_body;
MuMsg *_msg;
Mu::MuMsg *_msg;
};
#define MU_MSG_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
MU_TYPE_MSG_VIEW, \
@ -56,7 +58,7 @@ static GtkBoxClass *parent_class = NULL;
G_DEFINE_TYPE (MuMsgView, mu_msg_view, GTK_TYPE_BOX);
static void
set_message (MuMsgView *self, MuMsg *msg)
set_message (MuMsgView *self, Mu::MuMsg *msg)
{
if (self->_priv->_msg == msg)
return; /* nothing to todo */
@ -77,7 +79,7 @@ mu_msg_view_class_init (MuMsgViewClass *klass)
GObjectClass *gobject_class;
gobject_class = (GObjectClass*) klass;
parent_class = g_type_class_peek_parent (klass);
parent_class = (GtkBoxClass*)g_type_class_peek_parent (klass);
gobject_class->finalize = mu_msg_view_finalize;
g_type_class_add_private (gobject_class, sizeof(MuMsgViewPrivate));
@ -110,7 +112,7 @@ on_body_action_requested (GtkWidget *w, const char* action,
}
static void
on_attach_activated (GtkWidget *w, guint partnum, MuMsg *msg)
on_attach_activated (GtkWidget *w, guint partnum, Mu::MuMsg *msg)
{
gchar *filepath;
GError *err;
@ -188,7 +190,7 @@ mu_msg_view_new (void)
}
void
mu_msg_view_set_message (MuMsgView *self, MuMsg *msg)
mu_msg_view_set_message (MuMsgView *self, Mu::MuMsg *msg)
{
gint attachnum;
@ -212,7 +214,8 @@ mu_msg_view_set_message (MuMsgView *self, MuMsg *msg)
void
mu_msg_view_set_message_source (MuMsgView *self, MuMsg *msg)
mu_msg_view_set_message_source (MuMsgView *self,
Mu::MuMsg *msg)
{
g_return_if_fail (MU_IS_MSG_VIEW(self));

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-2020Dirk-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
@ -21,11 +21,7 @@
#define __MU_MSG_VIEW_H__
#include <gtk/gtk.h>
#include <mu-msg.h>
#if HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include "mu-msg.hh"
G_BEGIN_DECLS
@ -59,9 +55,11 @@ GType mu_msg_view_get_type (void) G_GNUC_CONST;
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
GtkWidget* mu_msg_view_new (void);
void mu_msg_view_set_message (MuMsgView *self, MuMsg *msg);
struct MuMsg;
void mu_msg_view_set_message (MuMsgView *self, Mu::MuMsg *msg);
void mu_msg_view_set_note (MuMsgView *self, const gchar* html);
void mu_msg_view_set_message_source (MuMsgView *self, MuMsg *msg);
void mu_msg_view_set_message_source (MuMsgView *self, Mu::MuMsg *msg);
G_END_DECLS

View File

@ -22,6 +22,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
G_BEGIN_DECLS
/**
* get a pixbuf (icon) for a certain content-type (ie., 'image/jpeg')
*
@ -36,4 +37,6 @@ GdkPixbuf* mu_widget_util_get_icon_pixbuf_for_content_type (const char *ctype,
G_GNUC_WARN_UNUSED_RESULT;
G_END_DECLS
#endif /*__MU_WIDGET_UTIL_H__*/

View File

@ -21,7 +21,8 @@
#include "mu-query.hh"
#include "utils/mu-str.h"
#include "utils/mu-date.h"
#include "mu-threader.hh"
using namespace Mu;
/* 'private'/'protected' functions */
static void mug_msg_list_view_finalize (GObject * obj);
@ -302,20 +303,18 @@ empty_or_display_contact (const gchar * str)
}
static MuMsgIter *
run_query (const char *xpath, const char *expr, MugMsgListView * self) try
static Mu::Option<Mu::QueryResults>
run_query (const char *xpath, const char *expr, MugMsgListView * self)
{
Mu::Store store{xpath};
Mu::Query query{store};
return query.run(expr, MU_MSG_FIELD_ID_DATE,
Mu::Query::Flags::Descending |
Mu::Query::Flags::SkipUnreadable |
Mu::Query::Flags::SkipDups |
Mu::Query::Flags::IncludeRelated |
Mu::Query::Flags::Threading);
} catch (...) {
return NULL;
Mu::QueryFlags::Descending |
Mu::QueryFlags::SkipUnreadable |
Mu::QueryFlags::SkipDuplicates |
Mu::QueryFlags::IncludeRelated |
Mu::QueryFlags::Threading);
}
static void
@ -358,39 +357,34 @@ static int
update_model (GtkTreeStore *store, const char *xpath, const char *query,
MugMsgListView *self)
{
MuMsgIter *iter;
int count;
const MuMsgIterThreadInfo *prev_ti = NULL;
iter = run_query (xpath, query, self);
if (!iter) {
g_warning ("error: running query failed\n");
const auto res{run_query (xpath, query, self)};
if (!res) {
g_warning ("error: running query failed");
return -1;
}
for (count = 0; !mu_msg_iter_is_done (iter);
mu_msg_iter_next (iter), ++count) {
auto count{0};
std::string prev_thread_path;
for (auto&& it: *res) {
GtkTreeIter treeiter, prev_treeiter;
const MuMsgIterThreadInfo *ti;
ti = mu_msg_iter_get_thread_info (iter);
const auto thread_path{it.query_match().thread_path};
if (!prev_ti || !g_str_has_prefix (ti->threadpath,
prev_ti->threadpath))
gtk_tree_store_append (store, &treeiter, NULL);
else
if (prev_thread_path.find(thread_path) == 0)
gtk_tree_store_append (store, &treeiter, &prev_treeiter);
else
gtk_tree_store_append (store, &treeiter, NULL);
/* don't unref msg */
add_row (store, mu_msg_iter_get_msg_floating (iter), &treeiter);
add_row (store, it.floating_msg(), &treeiter);
prev_ti = ti;
//prev_ti = ti;
prev_treeiter = treeiter;
prev_thread_path = thread_path;
++count;
}
mu_msg_iter_destroy (iter);
return count;
}

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** 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
@ -16,16 +16,16 @@
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
#ifdef HAVE_CONFIG
#include "config.h"
#endif /*HAVE_CONFIG*/
#include <unistd.h>
#include "mu-msg-view.h"
#include "mu-msg-view.hh"
#include "mug-msg-view.h"
#include "mu-msg.h"
#include "mu-msg.hh"
#include "utils/mu-str.h"
using namespace Mu;
/* 'private'/'protected' functions */
static void mug_msg_view_class_init (MugMsgViewClass * klass);
static void mug_msg_view_init (MugMsgView * obj);
@ -58,7 +58,7 @@ mug_msg_view_class_init (MugMsgViewClass * klass)
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
parent_class = g_type_class_peek_parent (klass);
parent_class = (GtkBoxClass*)g_type_class_peek_parent (klass);
gobject_class->finalize = mug_msg_view_finalize;
g_type_class_add_private (gobject_class, sizeof (MugMsgViewPrivate));
@ -116,7 +116,7 @@ mug_msg_view_set_msg (MugMsgView * self, const char *msgpath)
if (!msgpath)
mu_msg_view_set_message (MU_MSG_VIEW(priv->_view), NULL);
else {
MuMsg *msg;
Mu::MuMsg *msg;
if (access (msgpath, R_OK) == 0) {
msg = mu_msg_new_from_file (msgpath, NULL, NULL);