* move widgets/ -> toys/mug2; remove toys/mug; rename toys/mug2 -> toys/mug
This commit is contained in:
@ -18,12 +18,7 @@ include $(top_srcdir)/gtest.mk
|
||||
|
||||
SUBDIRS=
|
||||
|
||||
# build if there is some gtk available
|
||||
if HAVE_GTK
|
||||
SUBDIRS += mug
|
||||
endif
|
||||
|
||||
# for mug2 and msg2pdf, we need webkit
|
||||
if BUILD_WIDGETS
|
||||
SUBDIRS += mug2 msg2pdf
|
||||
if BUILD_GUI
|
||||
SUBDIRS += mug msg2pdf
|
||||
endif
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
## Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
## Copyright (C) 2008-2012 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 of the License, or
|
||||
## t he Free Software Foundation; either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
@ -19,8 +19,9 @@ include $(top_srcdir)/gtest.mk
|
||||
# enforce compiling this dir first before decending into tests/
|
||||
SUBDIRS= .
|
||||
|
||||
|
||||
INCLUDES=-I${top_srcdir}/lib $(GTK_CFLAGS) -DICONDIR='"$(icondir)"'
|
||||
INCLUDES=-I${top_srcdir} -I${top_srcdir}/lib $(GTK_CFLAGS) $(WEBKIT_CFLAGS) \
|
||||
-DICONDIR='"$(icondir)"' -DMUGDIR='"$(abs_srcdir)"' \
|
||||
-DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE
|
||||
|
||||
# don't use -Werror, as it might break on other compilers
|
||||
# use -Wno-unused-parameters, because some callbacks may not
|
||||
@ -28,35 +29,60 @@ INCLUDES=-I${top_srcdir}/lib $(GTK_CFLAGS) -DICONDIR='"$(icondir)"'
|
||||
AM_CFLAGS=-Wall -Wextra -Wno-unused-parameter -Wdeclaration-after-statement
|
||||
AM_CXXFLAGS=-Wall -Wextra -Wno-unused-parameter
|
||||
|
||||
|
||||
noinst_PROGRAMS= \
|
||||
noinst_PROGRAMS= \
|
||||
mug
|
||||
|
||||
# note, mug.cc is '.cc' only because libmu must explicitly
|
||||
# be linked as c++, not c.
|
||||
mug_SOURCES= \
|
||||
mug.c \
|
||||
mug-msg-list-view.c \
|
||||
mug-msg-list-view.h \
|
||||
mug-msg-view.h \
|
||||
mug-msg-view.c \
|
||||
mug-query-bar.h \
|
||||
mug-query-bar.c \
|
||||
mug-shortcuts.c \
|
||||
mug-shortcuts.h \
|
||||
mug_SOURCES= \
|
||||
mug.c \
|
||||
mug-msg-list-view.c \
|
||||
mug-msg-list-view.h \
|
||||
mug-msg-view.h \
|
||||
mug-msg-view.c \
|
||||
mug-query-bar.h \
|
||||
mug-query-bar.c \
|
||||
mug-shortcuts.c \
|
||||
mug-shortcuts.h \
|
||||
dummy.cc
|
||||
|
||||
# we need to use dummy.cc to enforce c++ linking...
|
||||
BUILT_SOURCES= \
|
||||
BUILT_SOURCES= \
|
||||
dummy.cc
|
||||
|
||||
dummy.cc:
|
||||
touch dummy.cc
|
||||
|
||||
DISTCLEANFILES= \
|
||||
DISTCLEANFILES= \
|
||||
$(BUILT_SOURCES)
|
||||
|
||||
|
||||
mug_LDADD= \
|
||||
${top_builddir}/lib/libmu.la \
|
||||
mug_LDADD= \
|
||||
${top_builddir}/lib/libmu.la \
|
||||
libmuwidgets.la \
|
||||
${GTK_LIBS}
|
||||
|
||||
|
||||
noinst_LTLIBRARIES= \
|
||||
libmuwidgets.la
|
||||
|
||||
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
|
||||
|
||||
libmuwidgets_la_LIBADD= \
|
||||
${top_builddir}/lib/libmu.la \
|
||||
${GTK_LIBS} \
|
||||
${WEBKIT_LIBS} \
|
||||
${GIO_LIBS}
|
||||
|
||||
EXTRA_DIST= \
|
||||
mug.svg
|
||||
|
||||
297
toys/mug/mu-msg-attach-view.c
Normal file
297
toys/mug/mu-msg-attach-view.c
Normal file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
** Copyright (C) 2011-2012 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 "mu-msg-attach-view.h"
|
||||
#include "mu-widget-util.h"
|
||||
#include <mu-msg-part.h>
|
||||
|
||||
enum {
|
||||
ICON_COL,
|
||||
NAME_COL,
|
||||
PARTNUM_COL,
|
||||
|
||||
NUM_COL
|
||||
};
|
||||
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mu_msg_attach_view_class_init (MuMsgAttachViewClass *klass);
|
||||
static void mu_msg_attach_view_init (MuMsgAttachView *obj);
|
||||
static void mu_msg_attach_view_finalize (GObject *obj);
|
||||
|
||||
/* list my signals */
|
||||
enum {
|
||||
ATTACH_ACTIVATED,
|
||||
/* MY_SIGNAL_2, */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
struct _MuMsgAttachViewPrivate {
|
||||
MuMsg *_msg;
|
||||
};
|
||||
#define MU_MSG_ATTACH_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MU_TYPE_MSG_ATTACH_VIEW, \
|
||||
MuMsgAttachViewPrivate))
|
||||
/* globals */
|
||||
static GtkIconViewClass *parent_class = NULL;
|
||||
|
||||
static guint signals[LAST_SIGNAL] = {0};
|
||||
|
||||
G_DEFINE_TYPE (MuMsgAttachView, mu_msg_attach_view, GTK_TYPE_ICON_VIEW);
|
||||
|
||||
|
||||
static void
|
||||
set_message (MuMsgAttachView *self, MuMsg *msg)
|
||||
{
|
||||
if (self->_priv->_msg == msg)
|
||||
return; /* nothing to todo */
|
||||
|
||||
if (self->_priv->_msg) {
|
||||
mu_msg_unref (self->_priv->_msg);
|
||||
self->_priv->_msg = NULL;
|
||||
}
|
||||
|
||||
if (msg)
|
||||
self->_priv->_msg = mu_msg_ref (msg);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mu_msg_attach_view_class_init (MuMsgAttachViewClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = (GObjectClass*) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = mu_msg_attach_view_finalize;
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof(MuMsgAttachViewPrivate));
|
||||
|
||||
signals[ATTACH_ACTIVATED] =
|
||||
g_signal_new ("attach-activated",
|
||||
G_TYPE_FROM_CLASS (gobject_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (MuMsgAttachViewClass,
|
||||
attach_activated),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__UINT_POINTER,
|
||||
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_POINTER);
|
||||
}
|
||||
|
||||
static void
|
||||
item_activated (MuMsgAttachView *self, GtkTreePath *tpath)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
guint partnum;
|
||||
|
||||
model = gtk_icon_view_get_model (GTK_ICON_VIEW(self));
|
||||
if (!gtk_tree_model_get_iter (model, &iter, tpath)) {
|
||||
g_warning ("could not find path");
|
||||
}
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
PARTNUM_COL, &partnum,
|
||||
-1);
|
||||
|
||||
g_signal_emit (G_OBJECT (self),
|
||||
signals[ATTACH_ACTIVATED], 0,
|
||||
partnum, self->_priv->_msg);
|
||||
}
|
||||
|
||||
static void
|
||||
accumulate_parts (MuMsgAttachView *self, GtkTreePath *path, GSList **lst)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
|
||||
/* don't unref */
|
||||
model = gtk_icon_view_get_model (GTK_ICON_VIEW(self));
|
||||
|
||||
if (gtk_tree_model_get_iter (model, &iter, path)) {
|
||||
gchar *filepath;
|
||||
gint idx;
|
||||
gtk_tree_model_get (model, &iter, PARTNUM_COL, &idx, -1);
|
||||
filepath = mu_msg_part_get_cache_path (self->_priv->_msg,
|
||||
MU_MSG_OPTION_NONE,
|
||||
idx, NULL);
|
||||
if (filepath) {
|
||||
if (mu_msg_part_save (self->_priv->_msg,
|
||||
MU_MSG_OPTION_USE_EXISTING,
|
||||
filepath,
|
||||
idx, NULL)) {
|
||||
GFile *file;
|
||||
file = g_file_new_for_path (filepath);
|
||||
*lst = g_slist_prepend (*lst, g_file_get_uri(file));
|
||||
g_object_unref (file);
|
||||
} else
|
||||
g_warning ("error saving msg part");
|
||||
g_free (filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
on_drag_data_get (MuMsgAttachView *self, GdkDragContext *drag_context,
|
||||
GtkSelectionData *data, guint info, guint time, gpointer user_data)
|
||||
{
|
||||
GSList *lst, *cur;
|
||||
char **uris;
|
||||
int i;
|
||||
|
||||
lst = NULL;
|
||||
gtk_icon_view_selected_foreach (GTK_ICON_VIEW(self),
|
||||
(GtkIconViewForeachFunc)accumulate_parts,
|
||||
&lst);
|
||||
|
||||
uris = g_new(char*, g_slist_length(lst) + 1);
|
||||
for (cur = lst, i = 0; cur; cur = g_slist_next(cur))
|
||||
uris[i++] = (gchar*)cur->data;
|
||||
|
||||
uris[i] = NULL;
|
||||
gtk_selection_data_set_uris (data, uris);
|
||||
|
||||
g_free (uris);
|
||||
g_slist_foreach (lst, (GFunc)g_free, NULL);
|
||||
g_slist_free (lst);
|
||||
}
|
||||
|
||||
static void
|
||||
mu_msg_attach_view_init (MuMsgAttachView *obj)
|
||||
{
|
||||
GtkListStore *store;
|
||||
|
||||
obj->_priv = MU_MSG_ATTACH_VIEW_GET_PRIVATE(obj);
|
||||
obj->_priv->_msg = NULL;
|
||||
|
||||
store = gtk_list_store_new (NUM_COL,GDK_TYPE_PIXBUF,
|
||||
G_TYPE_STRING, G_TYPE_UINT);
|
||||
gtk_icon_view_set_model (GTK_ICON_VIEW(obj), GTK_TREE_MODEL(store));
|
||||
g_object_unref (store);
|
||||
|
||||
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW(obj), ICON_COL);
|
||||
gtk_icon_view_set_text_column (GTK_ICON_VIEW(obj), NAME_COL);
|
||||
|
||||
gtk_icon_view_set_margin (GTK_ICON_VIEW(obj), 0);
|
||||
gtk_icon_view_set_spacing (GTK_ICON_VIEW(obj), 0);
|
||||
gtk_icon_view_set_item_padding (GTK_ICON_VIEW(obj), 0);
|
||||
|
||||
/* note: only since GTK+ 2.22 */
|
||||
/* gtk_icon_view_set_item_orientation (GTK_ICON_VIEW(obj), */
|
||||
/* GTK_ORIENTATION_HORIZONTAL); */
|
||||
|
||||
g_signal_connect (G_OBJECT(obj), "item-activated",
|
||||
G_CALLBACK(item_activated), NULL);
|
||||
|
||||
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,
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mu_msg_attach_view_finalize (GObject *obj)
|
||||
{
|
||||
set_message (MU_MSG_ATTACH_VIEW(obj), NULL);
|
||||
|
||||
G_OBJECT_CLASS(parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
mu_msg_attach_view_new (void)
|
||||
{
|
||||
return GTK_WIDGET(g_object_new(MU_TYPE_MSG_ATTACH_VIEW, NULL));
|
||||
}
|
||||
|
||||
struct _CBData {
|
||||
GtkListStore *store;
|
||||
guint count;
|
||||
};
|
||||
typedef struct _CBData CBData;
|
||||
|
||||
|
||||
|
||||
static void
|
||||
each_part (MuMsg *msg, MuMsgPart *part, CBData *cbdata)
|
||||
{
|
||||
GtkTreeIter treeiter;
|
||||
GdkPixbuf *pixbuf;
|
||||
char ctype[128];
|
||||
|
||||
if (!mu_msg_part_looks_like_attachment(part, FALSE))
|
||||
return;
|
||||
|
||||
if (!part->type || !part->subtype)
|
||||
snprintf (ctype, sizeof(ctype), "%s",
|
||||
"application/octet-stream");
|
||||
else
|
||||
snprintf (ctype, sizeof(ctype), "%s/%s",
|
||||
part->type, part->subtype);
|
||||
|
||||
pixbuf = mu_widget_util_get_icon_pixbuf_for_content_type (ctype, 16);
|
||||
if (!pixbuf) {
|
||||
g_warning ("%s: could not get icon pixbuf for '%s'",
|
||||
__FUNCTION__, ctype);
|
||||
pixbuf = mu_widget_util_get_icon_pixbuf_for_content_type
|
||||
("application/octet-stream", 16);
|
||||
}
|
||||
|
||||
gtk_list_store_append (cbdata->store, &treeiter);
|
||||
gtk_list_store_set (cbdata->store, &treeiter,
|
||||
NAME_COL, mu_msg_part_get_filename (part, TRUE),
|
||||
ICON_COL, pixbuf,
|
||||
PARTNUM_COL, part->index,
|
||||
-1);
|
||||
if (pixbuf)
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
++cbdata->count;
|
||||
}
|
||||
|
||||
gint
|
||||
mu_msg_attach_view_set_message (MuMsgAttachView *self, MuMsg *msg)
|
||||
{
|
||||
GtkListStore *store;
|
||||
CBData cbdata;
|
||||
|
||||
g_return_val_if_fail (MU_IS_MSG_ATTACH_VIEW(self), -1);
|
||||
|
||||
store = GTK_LIST_STORE (gtk_icon_view_get_model (GTK_ICON_VIEW(self)));
|
||||
gtk_list_store_clear (store);
|
||||
|
||||
set_message (self, msg);
|
||||
|
||||
if (!msg)
|
||||
return 0;
|
||||
|
||||
|
||||
cbdata.store = store;
|
||||
cbdata.count = 0;
|
||||
mu_msg_part_foreach (msg, MU_MSG_OPTION_NONE,
|
||||
(MuMsgPartForeachFunc)each_part, &cbdata);
|
||||
|
||||
return cbdata.count;
|
||||
}
|
||||
67
toys/mug/mu-msg-attach-view.h
Normal file
67
toys/mug/mu-msg-attach-view.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MU_MSG_ATTACH_VIEW_H__
|
||||
#define __MU_MSG_ATTACH_VIEW_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <mu-msg.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* convenience macros */
|
||||
#define MU_TYPE_MSG_ATTACH_VIEW (mu_msg_attach_view_get_type())
|
||||
#define MU_MSG_ATTACH_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MU_TYPE_MSG_ATTACH_VIEW,MuMsgAttachView))
|
||||
#define MU_MSG_ATTACH_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MU_TYPE_MSG_ATTACH_VIEW,MuMsgAttachViewClass))
|
||||
#define MU_IS_MSG_ATTACH_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MU_TYPE_MSG_ATTACH_VIEW))
|
||||
#define MU_IS_MSG_ATTACH_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MU_TYPE_MSG_ATTACH_VIEW))
|
||||
#define MU_MSG_ATTACH_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MU_TYPE_MSG_ATTACH_VIEW,MuMsgAttachViewClass))
|
||||
|
||||
typedef struct _MuMsgAttachView MuMsgAttachView;
|
||||
typedef struct _MuMsgAttachViewClass MuMsgAttachViewClass;
|
||||
typedef struct _MuMsgAttachViewPrivate MuMsgAttachViewPrivate;
|
||||
|
||||
struct _MuMsgAttachView {
|
||||
GtkIconView parent;
|
||||
/* insert public members, if any */
|
||||
|
||||
/* private */
|
||||
MuMsgAttachViewPrivate *_priv;
|
||||
};
|
||||
|
||||
struct _MuMsgAttachViewClass {
|
||||
GtkIconViewClass parent_class;
|
||||
void (* attach_activated) (MuMsgAttachView* obj, guint partnum,
|
||||
MuMsg *msg);
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType mu_msg_attach_view_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
|
||||
GtkWidget* mu_msg_attach_view_new (void);
|
||||
|
||||
/* returns # of attachments */
|
||||
int mu_msg_attach_view_set_message (MuMsgAttachView *self, MuMsg *msg);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MU_MSG_ATTACH_VIEW_H__ */
|
||||
400
toys/mug/mu-msg-body-view.c
Normal file
400
toys/mug/mu-msg-body-view.c
Normal file
@ -0,0 +1,400 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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 <webkit/webkitwebview.h>
|
||||
#include <webkit/webkitnetworkresponse.h>
|
||||
#include <webkit/webkitwebnavigationaction.h>
|
||||
#include <webkit/webkitwebpolicydecision.h>
|
||||
#include "mu-msg-body-view.h"
|
||||
#include <mu-msg-part.h>
|
||||
|
||||
enum _ViewMode {
|
||||
VIEW_MODE_MSG,
|
||||
VIEW_MODE_SOURCE,
|
||||
VIEW_MODE_NOTE,
|
||||
|
||||
VIEW_MODE_NONE
|
||||
};
|
||||
typedef enum _ViewMode ViewMode;
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mu_msg_body_view_class_init (MuMsgBodyViewClass *klass);
|
||||
static void mu_msg_body_view_init (MuMsgBodyView *obj);
|
||||
static void mu_msg_body_view_finalize (GObject *obj);
|
||||
|
||||
/* list my signals */
|
||||
enum {
|
||||
ACTION_REQUESTED,
|
||||
/* MY_SIGNAL_2, */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
|
||||
struct _MuMsgBodyViewPrivate {
|
||||
WebKitWebSettings *_settings;
|
||||
MuMsg *_msg;
|
||||
ViewMode _view_mode;
|
||||
};
|
||||
#define MU_MSG_BODY_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MU_TYPE_MSG_BODY_VIEW, \
|
||||
MuMsgBodyViewPrivate))
|
||||
/* globals */
|
||||
static WebKitWebViewClass *parent_class = NULL;
|
||||
|
||||
static guint signals[LAST_SIGNAL] = {0};
|
||||
|
||||
G_DEFINE_TYPE (MuMsgBodyView, mu_msg_body_view, WEBKIT_TYPE_WEB_VIEW);
|
||||
|
||||
static void
|
||||
set_message (MuMsgBodyView *self, MuMsg *msg)
|
||||
{
|
||||
if (self->_priv->_msg == msg)
|
||||
return; /* nothing to todo */
|
||||
|
||||
if (self->_priv->_msg) {
|
||||
mu_msg_unref (self->_priv->_msg);
|
||||
self->_priv->_msg = NULL;
|
||||
}
|
||||
|
||||
if (msg)
|
||||
self->_priv->_msg = mu_msg_ref (msg);
|
||||
}
|
||||
|
||||
static void
|
||||
mu_msg_body_view_class_init (MuMsgBodyViewClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = (GObjectClass*) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = mu_msg_body_view_finalize;
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof(MuMsgBodyViewPrivate));
|
||||
|
||||
signals[ACTION_REQUESTED] =
|
||||
g_signal_new ("action-requested",
|
||||
G_TYPE_FROM_CLASS (gobject_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (MuMsgBodyViewClass,
|
||||
action_requested),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
}
|
||||
|
||||
static char*
|
||||
save_file_for_cid (MuMsg *msg, const char* cid)
|
||||
{
|
||||
gint idx;
|
||||
gchar *filepath;
|
||||
gboolean rv;
|
||||
GError *err;
|
||||
|
||||
g_return_val_if_fail (msg, NULL);
|
||||
g_return_val_if_fail (cid, NULL);
|
||||
|
||||
idx = mu_msg_find_index_for_cid (msg, MU_MSG_OPTION_NONE, cid);
|
||||
if (idx < 0) {
|
||||
g_warning ("%s: cannot find %s", __FUNCTION__, cid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
filepath = mu_msg_part_get_cache_path (msg, MU_MSG_OPTION_NONE, idx, NULL);
|
||||
if (!filepath) {
|
||||
g_warning ("%s: cannot create filepath", filepath);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = NULL;
|
||||
rv = mu_msg_part_save (msg, MU_MSG_OPTION_USE_EXISTING,
|
||||
filepath, idx, &err);
|
||||
if (!rv) {
|
||||
g_warning ("%s: failed to save %s: %s", __FUNCTION__, filepath,
|
||||
err&&err->message?err->message:"error");
|
||||
g_clear_error (&err);
|
||||
g_free (filepath);
|
||||
filepath = NULL;
|
||||
}
|
||||
|
||||
return filepath;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
on_navigation_policy_decision_requested (MuMsgBodyView *self, WebKitWebFrame *frame,
|
||||
WebKitNetworkRequest *request,
|
||||
WebKitWebNavigationAction *nav_action,
|
||||
WebKitWebPolicyDecision *policy_decision,
|
||||
gpointer data)
|
||||
{
|
||||
const char* uri;
|
||||
WebKitWebNavigationReason reason;
|
||||
|
||||
uri = webkit_network_request_get_uri (request);
|
||||
reason = webkit_web_navigation_action_get_reason (nav_action);
|
||||
|
||||
/* if it wasn't a user click, don't the navigation */
|
||||
if (reason != WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
|
||||
webkit_web_policy_decision_ignore (policy_decision);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* we handle links clicked ourselves, no need for navigation */
|
||||
webkit_web_policy_decision_ignore (policy_decision);
|
||||
|
||||
/* if there are 'cmd:<action>" links in the body text of
|
||||
* mu-internal messages (ie., notification from mu, not real
|
||||
* e-mail messages), we emit the 'action requested'
|
||||
* signal. this allows e.g triggering a database refresh from
|
||||
* a <a href="cmd:refresh">Refresh</a> link
|
||||
*/
|
||||
if (g_ascii_strncasecmp (uri, "cmd:", 4) == 0) {
|
||||
if (self->_priv->_view_mode == VIEW_MODE_NOTE) {
|
||||
g_signal_emit (G_OBJECT(self),
|
||||
signals[ACTION_REQUESTED], 0,
|
||||
uri + 4);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* don't try to play files on our local file system, this is not something
|
||||
* external content should do.*/
|
||||
if (!mu_util_is_local_file(uri))
|
||||
mu_util_play (uri, FALSE, TRUE, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
on_resource_request_starting (MuMsgBodyView *self, WebKitWebFrame *frame,
|
||||
WebKitWebResource *resource, WebKitNetworkRequest *request,
|
||||
WebKitNetworkResponse *response, gpointer data)
|
||||
{
|
||||
const char* uri;
|
||||
MuMsg *msg;
|
||||
|
||||
msg = self->_priv->_msg;
|
||||
uri = webkit_network_request_get_uri (request);
|
||||
|
||||
/* g_warning ("%s: %s", __FUNCTION__, uri); */
|
||||
|
||||
if (g_ascii_strncasecmp (uri, "cid:", 4) == 0) {
|
||||
gchar *filepath;
|
||||
filepath = save_file_for_cid (msg, uri);
|
||||
if (filepath) {
|
||||
gchar *fileuri;
|
||||
fileuri = g_strdup_printf ("file://%s", filepath);
|
||||
webkit_network_request_set_uri (request, fileuri);
|
||||
g_free (fileuri);
|
||||
g_free (filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
on_menu_item_activate (GtkMenuItem *item, MuMsgBodyView *self)
|
||||
{
|
||||
g_signal_emit (G_OBJECT(self),
|
||||
signals[ACTION_REQUESTED], 0,
|
||||
g_object_get_data (G_OBJECT(item), "action"));
|
||||
}
|
||||
|
||||
static void
|
||||
popup_menu (MuMsgBodyView *self, guint button, guint32 activate_time)
|
||||
{
|
||||
GtkWidget *menu;
|
||||
int i;
|
||||
struct {
|
||||
const char* title;
|
||||
const char* action;
|
||||
ViewMode mode;
|
||||
} actions[] = {
|
||||
{ "View source...", "view-source", VIEW_MODE_MSG },
|
||||
{ "View message...", "view-message", VIEW_MODE_SOURCE },
|
||||
};
|
||||
|
||||
menu = gtk_menu_new ();
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(actions); ++i) {
|
||||
GtkWidget *item;
|
||||
|
||||
if (self->_priv->_view_mode != actions[i].mode)
|
||||
continue;
|
||||
|
||||
item = gtk_menu_item_new_with_label(actions[i].title);
|
||||
g_object_set_data (G_OBJECT(item), "action", (gpointer)actions[i].action);
|
||||
g_signal_connect (item, "activate", G_CALLBACK(on_menu_item_activate),
|
||||
self);
|
||||
gtk_menu_attach (GTK_MENU(menu), item, 0, 1, i, i+1);
|
||||
gtk_widget_show (item);
|
||||
}
|
||||
gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
on_button_press_event (MuMsgBodyView *self, GdkEventButton *event, gpointer data)
|
||||
{
|
||||
/* ignore all but the first (typically, left) mouse button */
|
||||
switch (event->button) {
|
||||
case 1: return FALSE; /* propagate, let widget handle it */
|
||||
case 3:
|
||||
/* no popup menus for notes */
|
||||
if (self->_priv->_view_mode != VIEW_MODE_NOTE)
|
||||
popup_menu (self, event->button, event->time);
|
||||
break;
|
||||
default: return TRUE; /* ignore */
|
||||
}
|
||||
|
||||
return (event->button > 1) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mu_msg_body_view_init (MuMsgBodyView *obj)
|
||||
{
|
||||
obj->_priv = MU_MSG_BODY_VIEW_GET_PRIVATE(obj);
|
||||
|
||||
obj->_priv->_msg = NULL;
|
||||
obj->_priv->_view_mode = VIEW_MODE_NONE;
|
||||
|
||||
obj->_priv->_settings = webkit_web_settings_new ();
|
||||
g_object_set (G_OBJECT(obj->_priv->_settings),
|
||||
"enable-scripts", FALSE,
|
||||
"auto-load-images", TRUE,
|
||||
"enable-plugins", FALSE,
|
||||
NULL);
|
||||
|
||||
webkit_web_view_set_settings (WEBKIT_WEB_VIEW(obj),
|
||||
obj->_priv->_settings);
|
||||
webkit_web_view_set_editable (WEBKIT_WEB_VIEW(obj), FALSE);
|
||||
|
||||
/* to support cid: */
|
||||
g_signal_connect (obj, "resource-request-starting",
|
||||
G_CALLBACK (on_resource_request_starting), NULL);
|
||||
/* handle navigation requests */
|
||||
g_signal_connect (obj, "navigation-policy-decision-requested",
|
||||
G_CALLBACK (on_navigation_policy_decision_requested), NULL);
|
||||
/* handle right-button clicks */
|
||||
g_signal_connect (obj, "button-press-event",
|
||||
G_CALLBACK(on_button_press_event), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
mu_msg_body_view_finalize (GObject *obj)
|
||||
{
|
||||
MuMsgBodyViewPrivate *priv;
|
||||
|
||||
priv = MU_MSG_BODY_VIEW_GET_PRIVATE(obj);
|
||||
if (priv && priv->_settings)
|
||||
g_object_unref (priv->_settings);
|
||||
|
||||
set_message (MU_MSG_BODY_VIEW(obj), NULL);
|
||||
|
||||
G_OBJECT_CLASS(parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
mu_msg_body_view_new (void)
|
||||
{
|
||||
return GTK_WIDGET(g_object_new(MU_TYPE_MSG_BODY_VIEW, NULL));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
set_html (MuMsgBodyView *self, const char* html)
|
||||
{
|
||||
g_return_if_fail (MU_IS_MSG_BODY_VIEW(self));
|
||||
|
||||
webkit_web_view_load_string (WEBKIT_WEB_VIEW(self),
|
||||
html ? html : "",
|
||||
"text/html",
|
||||
"utf-8",
|
||||
"");
|
||||
}
|
||||
|
||||
static void
|
||||
set_text (MuMsgBodyView *self, const char* txt)
|
||||
{
|
||||
g_return_if_fail (MU_IS_MSG_BODY_VIEW(self));
|
||||
|
||||
webkit_web_view_load_string (WEBKIT_WEB_VIEW(self),
|
||||
txt ? txt : "",
|
||||
"text/plain",
|
||||
"utf-8",
|
||||
"");
|
||||
}
|
||||
|
||||
void
|
||||
mu_msg_body_view_set_message (MuMsgBodyView *self, MuMsg *msg)
|
||||
{
|
||||
const char* data;
|
||||
|
||||
g_return_if_fail (self);
|
||||
|
||||
set_message (self, msg);
|
||||
|
||||
data = msg ? mu_msg_get_body_html (msg) : "";
|
||||
if (data)
|
||||
set_html (self, data);
|
||||
else
|
||||
set_text (self, mu_msg_get_body_text (msg));
|
||||
|
||||
self->_priv->_view_mode = VIEW_MODE_MSG;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_msg_body_view_set_message_source (MuMsgBodyView *self, MuMsg *msg)
|
||||
{
|
||||
const gchar *path;
|
||||
gchar *data;
|
||||
|
||||
g_return_if_fail (MU_IS_MSG_BODY_VIEW(self));
|
||||
g_return_if_fail (msg);
|
||||
|
||||
set_message (self, NULL);
|
||||
|
||||
path = msg ? mu_msg_get_path (msg) : NULL;
|
||||
|
||||
if (path && g_file_get_contents (path, &data, NULL, NULL)) {
|
||||
set_text (self, data);
|
||||
g_free (data);
|
||||
} else
|
||||
set_text (self, "");
|
||||
|
||||
self->_priv->_view_mode = VIEW_MODE_SOURCE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
mu_msg_body_view_set_note (MuMsgBodyView *self, const gchar *html)
|
||||
{
|
||||
g_return_if_fail (self);
|
||||
g_return_if_fail (html);
|
||||
|
||||
set_message (self, NULL);
|
||||
|
||||
set_html (self, html);
|
||||
|
||||
self->_priv->_view_mode = VIEW_MODE_NOTE;
|
||||
}
|
||||
70
toys/mug/mu-msg-body-view.h
Normal file
70
toys/mug/mu-msg-body-view.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_MSG_BODY_VIEW_H__
|
||||
#define __MU_MSG_BODY_VIEW_H__
|
||||
|
||||
#include <webkit/webkitwebview.h>
|
||||
#include <mu-msg.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* convenience macros */
|
||||
#define MU_TYPE_MSG_BODY_VIEW (mu_msg_body_view_get_type())
|
||||
#define MU_MSG_BODY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MU_TYPE_MSG_BODY_VIEW,MuMsgBodyView))
|
||||
#define MU_MSG_BODY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MU_TYPE_MSG_BODY_VIEW,MuMsgBodyViewClass))
|
||||
#define MU_IS_MSG_BODY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MU_TYPE_MSG_BODY_VIEW))
|
||||
#define MU_IS_MSG_BODY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MU_TYPE_MSG_BODY_VIEW))
|
||||
#define MU_MSG_BODY_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MU_TYPE_MSG_BODY_VIEW,MuMsgBodyViewClass))
|
||||
|
||||
typedef struct _MuMsgBodyView MuMsgBodyView;
|
||||
typedef struct _MuMsgBodyViewClass MuMsgBodyViewClass;
|
||||
typedef struct _MuMsgBodyViewPrivate MuMsgBodyViewPrivate;
|
||||
|
||||
|
||||
struct _MuMsgBodyView {
|
||||
WebKitWebView parent;
|
||||
/* insert public members, if any */
|
||||
|
||||
/* private */
|
||||
MuMsgBodyViewPrivate *_priv;
|
||||
};
|
||||
|
||||
struct _MuMsgBodyViewClass {
|
||||
WebKitWebViewClass parent_class;
|
||||
|
||||
/* supported actions: "reindex", "view-source" */
|
||||
void (* action_requested) (MuMsgBodyView* self, const char* action);
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType mu_msg_body_view_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* 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_note (MuMsgBodyView *self, const gchar *html);
|
||||
void mu_msg_body_view_set_message_source (MuMsgBodyView *self, MuMsg *msg);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MU_MSG_BODY_VIEW_H__ */
|
||||
|
||||
204
toys/mug/mu-msg-header-view.c
Normal file
204
toys/mug/mu-msg-header-view.c
Normal file
@ -0,0 +1,204 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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 "mu-msg-header-view.h"
|
||||
|
||||
#include <mu-str.h>
|
||||
#include <mu-date.h>
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mu_msg_header_view_class_init (MuMsgHeaderViewClass *klass);
|
||||
static void mu_msg_header_view_init (MuMsgHeaderView *obj);
|
||||
static void mu_msg_header_view_finalize (GObject *obj);
|
||||
|
||||
/* list my signals */
|
||||
enum {
|
||||
/* MY_SIGNAL_1, */
|
||||
/* MY_SIGNAL_2, */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
struct _MuMsgHeaderViewPrivate {
|
||||
GtkWidget *_table;
|
||||
};
|
||||
#define MU_MSG_HEADER_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MU_TYPE_MSG_HEADER_VIEW, \
|
||||
MuMsgHeaderViewPrivate))
|
||||
/* globals */
|
||||
#ifdef HAVE_GTK3
|
||||
static GtkBoxClass *parent_class = NULL;
|
||||
#else
|
||||
static GtkVBoxClass *parent_class = NULL;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
|
||||
/* uncomment the following if you have defined any signals */
|
||||
/* static guint signals[LAST_SIGNAL] = {0}; */
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
G_DEFINE_TYPE (MuMsgHeaderView, mu_msg_header_view, GTK_TYPE_BOX);
|
||||
#else
|
||||
G_DEFINE_TYPE (MuMsgHeaderView, mu_msg_header_view, GTK_TYPE_VBOX);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
|
||||
static void
|
||||
mu_msg_header_view_class_init (MuMsgHeaderViewClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = (GObjectClass*) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = mu_msg_header_view_finalize;
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof(MuMsgHeaderViewPrivate));
|
||||
|
||||
/* signal definitions go here, e.g.: */
|
||||
/* signals[MY_SIGNAL_1] = */
|
||||
/* g_signal_new ("my_signal_1",....); */
|
||||
/* signals[MY_SIGNAL_2] = */
|
||||
/* g_signal_new ("my_signal_2",....); */
|
||||
/* etc. */
|
||||
}
|
||||
|
||||
static void
|
||||
mu_msg_header_view_init (MuMsgHeaderView *obj)
|
||||
{
|
||||
|
||||
/* #ifdef HAVE_GTK3 */
|
||||
/* static GtkBoxClass *parent_class = NULL; */
|
||||
/* #endif /\*!HAVE_GTK3*\/ */
|
||||
|
||||
|
||||
obj->_priv = MU_MSG_HEADER_VIEW_GET_PRIVATE(obj);
|
||||
obj->_priv->_table = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
mu_msg_header_view_finalize (GObject *obj)
|
||||
{
|
||||
G_OBJECT_CLASS(parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
mu_msg_header_view_new (void)
|
||||
{
|
||||
return GTK_WIDGET(g_object_new(MU_TYPE_MSG_HEADER_VIEW, NULL));
|
||||
}
|
||||
|
||||
|
||||
static GtkWidget*
|
||||
get_label (const gchar *txt, gboolean istitle)
|
||||
{
|
||||
GtkWidget *label;
|
||||
|
||||
label = gtk_label_new (NULL);
|
||||
if (istitle) {
|
||||
char* markup;
|
||||
markup = g_strdup_printf ("<b>%s</b>: ", txt);
|
||||
gtk_label_set_markup (GTK_LABEL(label), markup);
|
||||
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
|
||||
g_free (markup);
|
||||
} else {
|
||||
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
||||
gtk_label_set_text (GTK_LABEL(label), txt ? txt : "");
|
||||
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_row (GtkWidget *table, guint row, const char* fieldname, const char *value,
|
||||
gboolean showempty)
|
||||
{
|
||||
GtkWidget *label, *al;
|
||||
|
||||
if (!value && !showempty)
|
||||
return FALSE;
|
||||
|
||||
label = get_label (fieldname, TRUE);
|
||||
al = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
|
||||
gtk_container_add (GTK_CONTAINER (al), label);
|
||||
|
||||
gtk_table_attach (
|
||||
GTK_TABLE(table), al,
|
||||
0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
|
||||
|
||||
al = gtk_alignment_new (0.0, 1.0, 0.0, 0.0);
|
||||
|
||||
label = get_label (value, FALSE);
|
||||
gtk_container_add (GTK_CONTAINER (al), label);
|
||||
|
||||
gtk_table_attach (
|
||||
GTK_TABLE(table), al, 1, 2, row, row + 1, GTK_FILL,
|
||||
0, 0, 0);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
GtkWidget *
|
||||
get_table (MuMsg *msg)
|
||||
{
|
||||
GtkWidget *table;
|
||||
int row;
|
||||
|
||||
row = 0;
|
||||
|
||||
table = gtk_table_new (5, 2, FALSE);
|
||||
|
||||
if (add_row (table, row, "From", mu_msg_get_from (msg), TRUE))
|
||||
++row;
|
||||
if (add_row (table, row, "To", mu_msg_get_to (msg), FALSE))
|
||||
++row;
|
||||
if (add_row (table, row, "Cc", mu_msg_get_cc (msg), FALSE))
|
||||
++row;
|
||||
if (add_row (table, row, "Subject", mu_msg_get_subject (msg), TRUE))
|
||||
++row;
|
||||
if (add_row (table, row, "Date", mu_date_str_s
|
||||
("%c", mu_msg_get_date (msg)),TRUE))
|
||||
++row;
|
||||
|
||||
gtk_table_resize (GTK_TABLE(table), row, 2);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
void
|
||||
mu_msg_header_view_set_message (MuMsgHeaderView *self, MuMsg *msg)
|
||||
{
|
||||
g_return_if_fail (MU_IS_MSG_HEADER_VIEW(self));
|
||||
|
||||
if (self->_priv->_table) {
|
||||
gtk_container_remove (GTK_CONTAINER(self), self->_priv->_table);
|
||||
self->_priv->_table = NULL;
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
self->_priv->_table = get_table (msg);
|
||||
gtk_box_pack_start (GTK_BOX(self), self->_priv->_table,
|
||||
TRUE, TRUE, 0);
|
||||
gtk_widget_show_all (self->_priv->_table);
|
||||
}
|
||||
}
|
||||
79
toys/mug/mu-msg-header-view.h
Normal file
79
toys/mug/mu-msg-header-view.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_MSG_HEADER_VIEW_H__
|
||||
#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*/
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* convenience macros */
|
||||
#define MU_TYPE_MSG_HEADER_VIEW (mu_msg_header_view_get_type())
|
||||
#define MU_MSG_HEADER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MU_TYPE_MSG_HEADER_VIEW,MuMsgHeaderView))
|
||||
#define MU_MSG_HEADER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MU_TYPE_MSG_HEADER_VIEW,MuMsgHeaderViewClass))
|
||||
#define MU_IS_MSG_HEADER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MU_TYPE_MSG_HEADER_VIEW))
|
||||
#define MU_IS_MSG_HEADER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MU_TYPE_MSG_HEADER_VIEW))
|
||||
#define MU_MSG_HEADER_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MU_TYPE_MSG_HEADER_VIEW,MuMsgHeaderViewClass))
|
||||
|
||||
typedef struct _MuMsgHeaderView MuMsgHeaderView;
|
||||
typedef struct _MuMsgHeaderViewClass MuMsgHeaderViewClass;
|
||||
typedef struct _MuMsgHeaderViewPrivate MuMsgHeaderViewPrivate;
|
||||
|
||||
struct _MuMsgHeaderView {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
#else
|
||||
GtkVBox parent;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* insert public members, if any */
|
||||
|
||||
/* private */
|
||||
MuMsgHeaderViewPrivate *_priv;
|
||||
};
|
||||
|
||||
struct _MuMsgHeaderViewClass {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBoxClass parent_class;
|
||||
#else
|
||||
GtkVBoxClass parent_class;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
/* insert signal callback declarations, e.g. */
|
||||
/* void (* my_event) (MuMsgHeaderView* obj); */
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType mu_msg_header_view_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* 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);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MU_MSG_HEADER_VIEW_H__ */
|
||||
251
toys/mug/mu-msg-view.c
Normal file
251
toys/mug/mu-msg-view.c
Normal file
@ -0,0 +1,251 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#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>
|
||||
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mu_msg_view_class_init (MuMsgViewClass *klass);
|
||||
static void mu_msg_view_init (MuMsgView *obj);
|
||||
static void mu_msg_view_finalize (GObject *obj);
|
||||
|
||||
/* list my signals */
|
||||
enum {
|
||||
/* MY_SIGNAL_1, */
|
||||
/* MY_SIGNAL_2, */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
struct _MuMsgViewPrivate {
|
||||
GtkWidget *_headers, *_attach, *_attachexpander, *_body;
|
||||
MuMsg *_msg;
|
||||
};
|
||||
#define MU_MSG_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MU_TYPE_MSG_VIEW, \
|
||||
MuMsgViewPrivate))
|
||||
/* globals */
|
||||
#ifdef HAVE_GTK3
|
||||
static GtkBoxClass *parent_class = NULL;
|
||||
#else
|
||||
static GtkVBoxClass *parent_class = NULL;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
|
||||
/* uncomment the following if you have defined any signals */
|
||||
/* static guint signals[LAST_SIGNAL] = {0}; */
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
G_DEFINE_TYPE (MuMsgView, mu_msg_view, GTK_TYPE_BOX);
|
||||
#else
|
||||
G_DEFINE_TYPE (MuMsgView, mu_msg_view, GTK_TYPE_VBOX);
|
||||
#endif /*HAVE_GTK3*/
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
set_message (MuMsgView *self, MuMsg *msg)
|
||||
{
|
||||
if (self->_priv->_msg == msg)
|
||||
return; /* nothing to todo */
|
||||
|
||||
if (self->_priv->_msg) {
|
||||
mu_msg_unref (self->_priv->_msg);
|
||||
self->_priv->_msg = NULL;
|
||||
}
|
||||
|
||||
if (msg)
|
||||
self->_priv->_msg = mu_msg_ref (msg);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mu_msg_view_class_init (MuMsgViewClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = (GObjectClass*) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = mu_msg_view_finalize;
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof(MuMsgViewPrivate));
|
||||
|
||||
/* signal definitions go here, e.g.: */
|
||||
/* signals[MY_SIGNAL_1] = */
|
||||
/* g_signal_new ("my_signal_1",....); */
|
||||
/* signals[MY_SIGNAL_2] = */
|
||||
/* g_signal_new ("my_signal_2",....); */
|
||||
/* etc. */
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
on_body_action_requested (GtkWidget *w, const char* action,
|
||||
MuMsgView *self)
|
||||
{
|
||||
if (g_strcmp0 (action, "view-source") == 0) {
|
||||
if (self->_priv->_msg)
|
||||
mu_msg_view_set_message_source (self, self->_priv->_msg);
|
||||
|
||||
} else if (g_strcmp0 (action, "view-message") == 0) {
|
||||
if (self->_priv->_msg)
|
||||
mu_msg_view_set_message (self, self->_priv->_msg);
|
||||
|
||||
} else if (g_strcmp0 (action, "reindex") == 0)
|
||||
g_warning ("reindex");
|
||||
else
|
||||
g_warning ("unknown action '%s'", action);
|
||||
}
|
||||
|
||||
static void
|
||||
on_attach_activated (GtkWidget *w, guint partnum, MuMsg *msg)
|
||||
{
|
||||
gchar *filepath;
|
||||
GError *err;
|
||||
|
||||
err = NULL;
|
||||
filepath = mu_msg_part_get_cache_path (msg, MU_MSG_OPTION_NONE, partnum,
|
||||
&err);
|
||||
if (!filepath) {
|
||||
g_warning ("failed to get cache path: %s",
|
||||
err&&err->message?err->message:"error");
|
||||
g_clear_error (&err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mu_msg_part_save (msg, MU_MSG_OPTION_USE_EXISTING,
|
||||
filepath, partnum, &err)) {
|
||||
g_warning ("failed to save %s: %s", filepath,
|
||||
err&&err->message?err->message:"error");
|
||||
g_clear_error (&err);
|
||||
return;
|
||||
|
||||
} else
|
||||
mu_util_play (filepath, TRUE, FALSE, NULL);
|
||||
|
||||
g_free (filepath);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mu_msg_view_init (MuMsgView *self)
|
||||
{
|
||||
self->_priv = MU_MSG_VIEW_GET_PRIVATE(self);
|
||||
|
||||
self->_priv->_msg = NULL;
|
||||
self->_priv->_headers = mu_msg_header_view_new ();
|
||||
|
||||
self->_priv->_attach = mu_msg_attach_view_new ();
|
||||
self->_priv->_attachexpander = gtk_expander_new_with_mnemonic
|
||||
("_Attachments");
|
||||
gtk_container_add (GTK_CONTAINER(self->_priv->_attachexpander),
|
||||
self->_priv->_attach);
|
||||
g_signal_connect (self->_priv->_attach, "attach-activated",
|
||||
G_CALLBACK(on_attach_activated),
|
||||
self);
|
||||
|
||||
self->_priv->_body = mu_msg_body_view_new ();
|
||||
g_signal_connect (self->_priv->_body,
|
||||
"action-requested",
|
||||
G_CALLBACK(on_body_action_requested),
|
||||
self);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX(self), self->_priv->_headers,
|
||||
FALSE, FALSE, 2);
|
||||
gtk_box_pack_start (GTK_BOX(self), self->_priv->_attachexpander,
|
||||
FALSE, FALSE, 2);
|
||||
gtk_box_pack_start (GTK_BOX(self), self->_priv->_body,
|
||||
TRUE, TRUE, 2);
|
||||
}
|
||||
|
||||
static void
|
||||
mu_msg_view_finalize (GObject *obj)
|
||||
{
|
||||
set_message (MU_MSG_VIEW (obj), NULL);
|
||||
|
||||
G_OBJECT_CLASS(parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
mu_msg_view_new (void)
|
||||
{
|
||||
return GTK_WIDGET(g_object_new(MU_TYPE_MSG_VIEW, NULL));
|
||||
}
|
||||
|
||||
void
|
||||
mu_msg_view_set_message (MuMsgView *self, MuMsg *msg)
|
||||
{
|
||||
gint attachnum;
|
||||
|
||||
g_return_if_fail (MU_IS_MSG_VIEW(self));
|
||||
|
||||
set_message (self, msg);
|
||||
|
||||
mu_msg_header_view_set_message (MU_MSG_HEADER_VIEW(self->_priv->_headers),
|
||||
msg);
|
||||
attachnum = mu_msg_attach_view_set_message (MU_MSG_ATTACH_VIEW(self->_priv->_attach),
|
||||
msg);
|
||||
|
||||
mu_msg_body_view_set_message (MU_MSG_BODY_VIEW(self->_priv->_body),
|
||||
msg);
|
||||
|
||||
gtk_widget_set_visible (self->_priv->_headers, TRUE);
|
||||
gtk_widget_set_visible (self->_priv->_attachexpander, attachnum > 0);
|
||||
gtk_widget_set_visible (self->_priv->_body, TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
mu_msg_view_set_message_source (MuMsgView *self, MuMsg *msg)
|
||||
{
|
||||
g_return_if_fail (MU_IS_MSG_VIEW(self));
|
||||
|
||||
set_message (self, msg);
|
||||
|
||||
mu_msg_body_view_set_message_source (MU_MSG_BODY_VIEW(self->_priv->_body),
|
||||
msg);
|
||||
|
||||
gtk_widget_set_visible (self->_priv->_headers, FALSE);
|
||||
gtk_widget_set_visible (self->_priv->_attachexpander, FALSE);
|
||||
gtk_widget_set_visible (self->_priv->_body, TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
mu_msg_view_set_note (MuMsgView *self, const gchar* html)
|
||||
{
|
||||
g_return_if_fail (MU_IS_MSG_VIEW(self));
|
||||
|
||||
gtk_widget_set_visible (self->_priv->_headers, FALSE);
|
||||
gtk_widget_set_visible (self->_priv->_attachexpander, FALSE);
|
||||
gtk_widget_set_visible (self->_priv->_body, TRUE);
|
||||
|
||||
mu_msg_body_view_set_note (MU_MSG_BODY_VIEW(self->_priv->_body),
|
||||
html);
|
||||
}
|
||||
77
toys/mug/mu-msg-view.h
Normal file
77
toys/mug/mu-msg-view.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_MSG_VIEW_H__
|
||||
#define __MU_MSG_VIEW_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <mu-msg.h>
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* convenience macros */
|
||||
#define MU_TYPE_MSG_VIEW (mu_msg_view_get_type())
|
||||
#define MU_MSG_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MU_TYPE_MSG_VIEW,MuMsgView))
|
||||
#define MU_MSG_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MU_TYPE_MSG_VIEW,MuMsgViewClass))
|
||||
#define MU_IS_MSG_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MU_TYPE_MSG_VIEW))
|
||||
#define MU_IS_MSG_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MU_TYPE_MSG_VIEW))
|
||||
#define MU_MSG_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MU_TYPE_MSG_VIEW,MuMsgViewClass))
|
||||
|
||||
typedef struct _MuMsgView MuMsgView;
|
||||
typedef struct _MuMsgViewClass MuMsgViewClass;
|
||||
typedef struct _MuMsgViewPrivate MuMsgViewPrivate;
|
||||
|
||||
struct _MuMsgView {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
#else
|
||||
GtkVBox parent;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* private */
|
||||
MuMsgViewPrivate *_priv;
|
||||
};
|
||||
|
||||
struct _MuMsgViewClass {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBoxClass parent_class;
|
||||
#else
|
||||
GtkVBoxClass parent_class;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
/* void (* my_event) (MuMsgView* obj); */
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType mu_msg_view_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* 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);
|
||||
void mu_msg_view_set_note (MuMsgView *self, const gchar* html);
|
||||
void mu_msg_view_set_message_source (MuMsgView *self, MuMsg *msg);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MU_MSG_VIEW_H__ */
|
||||
89
toys/mug/mu-widget-util.c
Normal file
89
toys/mug/mu-widget-util.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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 <gtk/gtk.h>
|
||||
#include <gio/gio.h>
|
||||
#include "mu-widget-util.h"
|
||||
|
||||
static const char*
|
||||
second_guess_content_type (const char *ctype)
|
||||
{
|
||||
int i;
|
||||
struct {
|
||||
const char *orig, *subst;
|
||||
} substtable [] = {
|
||||
{"text", "text/plain"},
|
||||
{"image/pjpeg", "image/jpeg" }
|
||||
};
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(substtable); ++i)
|
||||
if (g_str_has_prefix (ctype, substtable[i].orig))
|
||||
return substtable[i].subst;
|
||||
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
||||
static GdkPixbuf*
|
||||
get_icon_pixbuf_for_content_type (const char *ctype, size_t size)
|
||||
{
|
||||
GIcon *icon;
|
||||
GdkPixbuf *pixbuf;
|
||||
|
||||
icon = g_content_type_get_icon (ctype);
|
||||
pixbuf = NULL;
|
||||
|
||||
/* based on a snippet from http://www.gtkforums.com/about4721.html */
|
||||
if (G_IS_THEMED_ICON(icon)) {
|
||||
gchar const * const *names;
|
||||
names = g_themed_icon_get_names (G_THEMED_ICON(icon));
|
||||
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(),
|
||||
*names, size, 0, NULL);
|
||||
} else if (G_IS_FILE_ICON(icon)) {
|
||||
GFile *icon_file;
|
||||
gchar *path;
|
||||
icon_file = g_file_icon_get_file (G_FILE_ICON(icon));
|
||||
path = g_file_get_path (icon_file);
|
||||
pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, NULL);
|
||||
g_free (path);
|
||||
g_object_unref(icon_file);
|
||||
}
|
||||
g_object_unref(icon);
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
|
||||
GdkPixbuf*
|
||||
mu_widget_util_get_icon_pixbuf_for_content_type (const char *ctype, size_t size)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
|
||||
g_return_val_if_fail (ctype, NULL);
|
||||
g_return_val_if_fail (size > 0, NULL);
|
||||
|
||||
pixbuf = get_icon_pixbuf_for_content_type (ctype, size);
|
||||
if (!pixbuf)
|
||||
pixbuf = get_icon_pixbuf_for_content_type
|
||||
(second_guess_content_type (ctype), size);
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
|
||||
39
toys/mug/mu-widget-util.h
Normal file
39
toys/mug/mu-widget-util.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_WIDGET_UTIL_H__
|
||||
#define __MU_WIDGET_UTIL_H__
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
/**
|
||||
* get a pixbuf (icon) for a certain content-type (ie., 'image/jpeg')
|
||||
*
|
||||
* @param ctype the content-type (MIME-type)
|
||||
* @param size the size of the icon
|
||||
*
|
||||
* @return a new GdkPixbuf, or NULL in case of error. Use
|
||||
* g_object_unref when the pixbuf is no longer needed.
|
||||
*/
|
||||
GdkPixbuf* mu_widget_util_get_icon_pixbuf_for_content_type (const char *ctype,
|
||||
size_t size)
|
||||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
#endif /*__MU_WIDGET_UTIL_H__*/
|
||||
@ -1,6 +1,6 @@
|
||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||
/*
|
||||
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2008-2011 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,6 +22,7 @@
|
||||
#include "mu-query.h"
|
||||
#include "mu-str.h"
|
||||
#include "mu-date.h"
|
||||
#include "mu-threader.h"
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mug_msg_list_view_class_init (MugMsgListViewClass * klass);
|
||||
@ -51,7 +52,7 @@ enum {
|
||||
|
||||
typedef struct _MugMsgListViewPrivate MugMsgListViewPrivate;
|
||||
struct _MugMsgListViewPrivate {
|
||||
GtkListStore *_store;
|
||||
GtkTreeStore *_store;
|
||||
char *_xpath;
|
||||
char *_query;
|
||||
};
|
||||
@ -158,10 +159,9 @@ append_col (GtkTreeView * treeview, const char *label, int colidx,
|
||||
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);
|
||||
|
||||
if (maxwidth) {
|
||||
gtk_tree_view_column_set_sizing (col,
|
||||
GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (col, maxwidth);
|
||||
gtk_tree_view_column_set_expand (col, FALSE);
|
||||
} else
|
||||
@ -172,6 +172,9 @@ append_col (GtkTreeView * treeview, const char *label, int colidx,
|
||||
treecell_func, NULL, NULL);
|
||||
|
||||
gtk_tree_view_append_column (treeview, col);
|
||||
|
||||
gtk_tree_view_columns_autosize (treeview);
|
||||
gtk_tree_view_set_fixed_height_mode (treeview, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -183,13 +186,13 @@ mug_msg_list_view_init (MugMsgListView * obj)
|
||||
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE (obj);
|
||||
|
||||
priv->_xpath = priv->_query = NULL;
|
||||
priv->_store = gtk_list_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 */
|
||||
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 */
|
||||
@ -326,7 +329,6 @@ run_query (const char *xpath, const char *query, MugMsgListView * self)
|
||||
MuStore *store;
|
||||
|
||||
err = NULL;
|
||||
|
||||
if (! (store = mu_store_new_read_only (xpath, &err)) ||
|
||||
! (xapian = mu_query_new (store, &err))) {
|
||||
if (store)
|
||||
@ -340,7 +342,7 @@ run_query (const char *xpath, const char *query, MugMsgListView * self)
|
||||
}
|
||||
mu_store_unref (store);
|
||||
|
||||
iter = mu_query_run (xapian, query, FALSE, MU_MSG_FIELD_ID_DATE,
|
||||
iter = mu_query_run (xapian, query, TRUE, MU_MSG_FIELD_ID_DATE,
|
||||
TRUE, -1, &err);
|
||||
mu_query_destroy (xapian);
|
||||
if (!iter) {
|
||||
@ -356,9 +358,8 @@ run_query (const char *xpath, const char *query, MugMsgListView * self)
|
||||
}
|
||||
|
||||
static void
|
||||
add_row (GtkListStore * store, MuMsg *msg)
|
||||
add_row (GtkTreeStore * store, MuMsg *msg, GtkTreeIter *treeiter)
|
||||
{
|
||||
GtkTreeIter treeiter;
|
||||
const gchar *datestr, *flagstr;
|
||||
gchar *from, *to;
|
||||
time_t timeval;
|
||||
@ -369,8 +370,15 @@ add_row (GtkListStore * store, MuMsg *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);
|
||||
|
||||
gtk_list_store_append (store, &treeiter);
|
||||
gtk_list_store_set (store, &treeiter,
|
||||
/* 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",
|
||||
* __FUNCTION__, path); */
|
||||
/* } */
|
||||
|
||||
gtk_tree_store_set (store, treeiter,
|
||||
MUG_COL_DATESTR, datestr,
|
||||
MUG_COL_MAILDIR, mu_msg_get_maildir (msg),
|
||||
MUG_COL_FLAGSSTR, flagstr,
|
||||
@ -386,11 +394,12 @@ add_row (GtkListStore * store, MuMsg *msg)
|
||||
}
|
||||
|
||||
static int
|
||||
update_model (GtkListStore * store, const char *xpath, const char *query,
|
||||
MugMsgListView * self)
|
||||
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) {
|
||||
@ -399,15 +408,31 @@ update_model (GtkListStore * store, const char *xpath, const char *query,
|
||||
}
|
||||
|
||||
for (count = 0; !mu_msg_iter_is_done (iter);
|
||||
mu_msg_iter_next (iter), ++count)
|
||||
add_row (store, mu_msg_iter_get_msg_floating(iter)); /* don't unref */
|
||||
mu_msg_iter_next (iter), ++count) {
|
||||
|
||||
GtkTreeIter treeiter, prev_treeiter;
|
||||
const MuMsgIterThreadInfo *ti;
|
||||
|
||||
ti = mu_msg_iter_get_thread_info (iter);
|
||||
|
||||
if (!prev_ti || !g_str_has_prefix (ti->threadpath,
|
||||
prev_ti->threadpath))
|
||||
gtk_tree_store_append (store, &treeiter, NULL);
|
||||
else
|
||||
gtk_tree_store_append (store, &treeiter, &prev_treeiter);
|
||||
|
||||
/* don't unref msg */
|
||||
add_row (store, mu_msg_iter_get_msg_floating (iter), &treeiter);
|
||||
|
||||
prev_ti = ti;
|
||||
prev_treeiter = treeiter;
|
||||
}
|
||||
|
||||
mu_msg_iter_destroy (iter);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
mug_msg_list_view_query (MugMsgListView * self, const char *query)
|
||||
{
|
||||
@ -417,7 +442,7 @@ mug_msg_list_view_query (MugMsgListView * self, const char *query)
|
||||
g_return_val_if_fail (MUG_IS_MSG_LIST_VIEW (self), FALSE);
|
||||
|
||||
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE (self);
|
||||
gtk_list_store_clear (priv->_store);
|
||||
gtk_tree_store_clear (priv->_store);
|
||||
|
||||
g_free (priv->_query);
|
||||
priv->_query = query ? g_strdup (query) : NULL;
|
||||
@ -427,7 +452,7 @@ mug_msg_list_view_query (MugMsgListView * self, const char *query)
|
||||
|
||||
rv = update_model (priv->_store, priv->_xpath, query, self);
|
||||
|
||||
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (self));
|
||||
gtk_tree_view_expand_all (GTK_TREE_VIEW(self));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2008-2010 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,12 +16,15 @@
|
||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
#include <config.h>
|
||||
#ifdef HAVE_CONFIG
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include "mu-msg-view.h"
|
||||
#include "mug-msg-view.h"
|
||||
#include "mu-msg.h"
|
||||
#include "mu-str.h"
|
||||
#include "mu-date.h"
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mug_msg_view_class_init (MugMsgViewClass * klass);
|
||||
@ -35,58 +38,25 @@ enum {
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum _HeaderRow {
|
||||
HEADER_ROW_FROM,
|
||||
HEADER_ROW_TO,
|
||||
HEADER_ROW_SUBJECT,
|
||||
HEADER_ROW_CC,
|
||||
HEADER_ROW_DATE,
|
||||
HEADER_ROW_PATH,
|
||||
HEADER_ROW_MSGID,
|
||||
HEADER_ROW_SIZE,
|
||||
HEADER_ROW_NUM
|
||||
};
|
||||
typedef enum _HeaderRow HeaderRow;
|
||||
|
||||
struct _HeaderInfo {
|
||||
HeaderRow row;
|
||||
const char *title;
|
||||
};
|
||||
typedef struct _HeaderInfo HeaderInfo;
|
||||
|
||||
static const HeaderInfo HEADER_INFO[] = {
|
||||
{HEADER_ROW_CC, "Cc"},
|
||||
{HEADER_ROW_SUBJECT, "Subject"},
|
||||
{HEADER_ROW_DATE, "Date"}
|
||||
};
|
||||
|
||||
static const HeaderInfo HEADER_INFO_EXPANDER[] = {
|
||||
{HEADER_ROW_FROM, "From"},
|
||||
{HEADER_ROW_TO, "To"},
|
||||
{HEADER_ROW_PATH, "Path"},
|
||||
{HEADER_ROW_MSGID, "Message-Id"},
|
||||
{HEADER_ROW_SIZE, "Size"}
|
||||
};
|
||||
|
||||
typedef struct _MugMsgViewPrivate MugMsgViewPrivate;
|
||||
struct _MugMsgViewPrivate {
|
||||
|
||||
GtkWidget *_headers_area;
|
||||
GtkWidget *_tablemain, *_tableexpander;
|
||||
GtkWidget *_headervals[HEADER_ROW_NUM];
|
||||
|
||||
GtkWidget *_expander_header, *_expander;
|
||||
GtkWidget *_view;
|
||||
};
|
||||
#define MUG_MSG_VIEW_GET_PRIVATE(o)(G_TYPE_INSTANCE_GET_PRIVATE((o),MUG_TYPE_MSG_VIEW, MugMsgViewPrivate))
|
||||
/* globals */
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
static GtkBoxClass *parent_class = NULL;
|
||||
G_DEFINE_TYPE (MugMsgView, mug_msg_view, GTK_TYPE_BOX);
|
||||
#else
|
||||
static GtkVBoxClass *parent_class = NULL;
|
||||
G_DEFINE_TYPE (MugMsgView, mug_msg_view, GTK_TYPE_VBOX);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* uncomment the following if you have defined any signals */
|
||||
/* static guint signals[LAST_SIGNAL] = {0}; */
|
||||
|
||||
G_DEFINE_TYPE (MugMsgView, mug_msg_view, GTK_TYPE_VBOX);
|
||||
|
||||
static void
|
||||
mug_msg_view_class_init (MugMsgViewClass * klass)
|
||||
{
|
||||
@ -106,82 +76,6 @@ mug_msg_view_class_init (MugMsgViewClass * klass)
|
||||
/* etc. */
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_table (MugMsgViewPrivate * priv, const HeaderInfo * hinfo, guint num)
|
||||
{
|
||||
guint i;
|
||||
GtkWidget *table;
|
||||
|
||||
table = gtk_table_new (num, 2, FALSE);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 5);
|
||||
|
||||
for (i = 0; i < num; ++i) {
|
||||
|
||||
char *str;
|
||||
GtkWidget *l, *al;
|
||||
|
||||
l = gtk_label_new (NULL);
|
||||
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
|
||||
|
||||
gtk_label_set_justify (GTK_LABEL (l), GTK_JUSTIFY_LEFT);
|
||||
str = g_strdup_printf ("<b>%s</b>:", hinfo[i].title);
|
||||
gtk_label_set_markup (GTK_LABEL (l), str);
|
||||
g_free (str);
|
||||
|
||||
al = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
|
||||
gtk_container_add (GTK_CONTAINER (al), l);
|
||||
gtk_table_attach (GTK_TABLE (table), al, 0, 1, i, i + 1,
|
||||
GTK_FILL, 0, 0, 0);
|
||||
|
||||
l = priv->_headervals[hinfo[i].row] = gtk_label_new (NULL);
|
||||
al = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
|
||||
gtk_label_set_selectable (GTK_LABEL (l), TRUE);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (al), l);
|
||||
gtk_label_set_justify (GTK_LABEL (l), GTK_JUSTIFY_LEFT);
|
||||
gtk_label_set_line_wrap_mode (GTK_LABEL (l),
|
||||
PANGO_WRAP_WORD_CHAR);
|
||||
gtk_label_set_line_wrap (GTK_LABEL (l), FALSE);
|
||||
gtk_table_attach (GTK_TABLE (table), al,
|
||||
1, 2, i, i + 1, GTK_FILL, 0, 0, 0);
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
headers_area (MugMsgViewPrivate * priv)
|
||||
{
|
||||
GtkWidget *scrolled, *vbox;
|
||||
|
||||
priv->_tablemain = create_table (priv, HEADER_INFO,
|
||||
G_N_ELEMENTS (HEADER_INFO));
|
||||
priv->_tableexpander = create_table
|
||||
(priv, HEADER_INFO_EXPANDER, G_N_ELEMENTS (HEADER_INFO_EXPANDER));
|
||||
priv->_expander = gtk_expander_new ("Details");
|
||||
gtk_container_add (GTK_CONTAINER (priv->_expander),
|
||||
priv->_tableexpander);
|
||||
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
#else
|
||||
vbox = gtk_vbox_new (FALSE, 0);
|
||||
#endif /*!HAVE_GTK3 */
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), priv->_tablemain, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), priv->_expander, FALSE, FALSE, 0);
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
|
||||
vbox);
|
||||
|
||||
return priv->_headers_area = scrolled;
|
||||
}
|
||||
|
||||
static void
|
||||
mug_msg_view_init (MugMsgView * obj)
|
||||
{
|
||||
@ -190,19 +84,15 @@ mug_msg_view_init (MugMsgView * obj)
|
||||
|
||||
priv = MUG_MSG_VIEW_GET_PRIVATE (obj);
|
||||
|
||||
priv->_view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (priv->_view), FALSE);
|
||||
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (priv->_view), 10);
|
||||
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (priv->_view), 10);
|
||||
priv->_view = mu_msg_view_new ();
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), priv->_view);
|
||||
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
|
||||
priv->_view);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (obj), headers_area (priv), FALSE, FALSE,
|
||||
0);
|
||||
gtk_box_pack_start (GTK_BOX (obj), scrolled, TRUE, TRUE, 0);
|
||||
}
|
||||
|
||||
@ -219,98 +109,50 @@ mug_msg_view_new (void)
|
||||
return GTK_WIDGET (g_object_new (MUG_TYPE_MSG_VIEW, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
empty_message (MugMsgView * self)
|
||||
{
|
||||
int i;
|
||||
MugMsgViewPrivate *priv;
|
||||
GtkTextBuffer *buf;
|
||||
|
||||
priv = MUG_MSG_VIEW_GET_PRIVATE (self);
|
||||
|
||||
for (i = 0; i != HEADER_ROW_NUM; ++i)
|
||||
gtk_label_set_markup (GTK_LABEL (priv->_headervals[i]), "");
|
||||
|
||||
buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->_view));
|
||||
gtk_text_buffer_set_text (buf, "", -1);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_text (MugMsgView * self, const char *txt)
|
||||
{
|
||||
MugMsgViewPrivate *priv;
|
||||
GtkTextBuffer *buf;
|
||||
|
||||
g_return_val_if_fail (MUG_IS_MSG_VIEW (self), FALSE);
|
||||
priv = MUG_MSG_VIEW_GET_PRIVATE (self);
|
||||
|
||||
buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->_view));
|
||||
gtk_text_buffer_set_text (buf, txt ? txt : "", -1);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
fill_header (MugMsgViewPrivate * priv, MuMsg * msg)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i != HEADER_ROW_NUM; ++i) {
|
||||
const gchar *val;
|
||||
switch (i) {
|
||||
case HEADER_ROW_FROM: val = mu_msg_get_from (msg); break;
|
||||
case HEADER_ROW_TO: val = mu_msg_get_to (msg); break;
|
||||
case HEADER_ROW_SUBJECT: val = mu_msg_get_subject (msg); break;
|
||||
case HEADER_ROW_MSGID: val = mu_msg_get_msgid (msg);break;
|
||||
case HEADER_ROW_CC: val = mu_msg_get_cc (msg); break;
|
||||
case HEADER_ROW_PATH: val = mu_msg_get_path (msg); break;
|
||||
case HEADER_ROW_DATE:
|
||||
val = mu_date_str_s ("%c", mu_msg_get_date (msg));
|
||||
break;
|
||||
case HEADER_ROW_SIZE:
|
||||
val = mu_str_size_s (mu_msg_get_size (msg));
|
||||
break;
|
||||
default:
|
||||
val = NULL;
|
||||
}
|
||||
|
||||
{
|
||||
gchar *str;
|
||||
str = g_markup_escape_text (val ? val : "", -1);
|
||||
gtk_label_set_markup
|
||||
(GTK_LABEL (priv->_headervals[i]), str);
|
||||
g_free (str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
mug_msg_view_set_msg (MugMsgView * self, const char *msgpath)
|
||||
{
|
||||
MugMsgViewPrivate *priv;
|
||||
MuMsg *msg;
|
||||
gboolean rv;
|
||||
|
||||
g_return_val_if_fail (MUG_IS_MSG_VIEW (self), FALSE);
|
||||
|
||||
priv = MUG_MSG_VIEW_GET_PRIVATE (self);
|
||||
|
||||
if (!msgpath) {
|
||||
empty_message (self);
|
||||
return TRUE;
|
||||
if (!msgpath)
|
||||
mu_msg_view_set_message (MU_MSG_VIEW(priv->_view), NULL);
|
||||
else {
|
||||
MuMsg *msg;
|
||||
|
||||
if (access (msgpath, R_OK) == 0) {
|
||||
msg = mu_msg_new_from_file (msgpath, NULL, NULL);
|
||||
mu_msg_view_set_message (MU_MSG_VIEW(priv->_view), msg);
|
||||
if (msg)
|
||||
mu_msg_unref (msg);
|
||||
} else {
|
||||
gchar *note;
|
||||
note = g_strdup_printf (
|
||||
"<h1>Note</h1><hr>"
|
||||
"<p>Message <tt>%s</tt> does not seem to be present "
|
||||
"on the file system."
|
||||
"<p>Maybe you need to run <tt>mu index</tt>?",
|
||||
msgpath);
|
||||
mu_msg_view_set_note (MU_MSG_VIEW (priv->_view), note);
|
||||
g_free (note);
|
||||
}
|
||||
}
|
||||
|
||||
msg = mu_msg_new_from_file (msgpath, NULL, NULL);
|
||||
if (!msg) {
|
||||
empty_message (self);
|
||||
set_text (self, "Message not found; " "please run 'mu index'");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
rv = set_text (self, mu_msg_get_body_text (msg));
|
||||
fill_header (priv, msg);
|
||||
|
||||
mu_msg_unref (msg);
|
||||
|
||||
return rv;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mug_msg_view_set_note (MugMsgView * self, const char* html)
|
||||
{
|
||||
MugMsgViewPrivate *priv;
|
||||
g_return_if_fail (MUG_IS_MSG_VIEW (self));
|
||||
|
||||
priv = MUG_MSG_VIEW_GET_PRIVATE (self);
|
||||
|
||||
mu_msg_view_set_note (MU_MSG_VIEW (priv->_view), html);
|
||||
}
|
||||
|
||||
@ -23,6 +23,9 @@
|
||||
#include <gtk/gtk.h>
|
||||
/* other include files */
|
||||
|
||||
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/* convenience macros */
|
||||
#define MUG_TYPE_MSG_VIEW (mug_msg_view_get_type())
|
||||
@ -35,27 +38,32 @@ typedef struct _MugMsgView MugMsgView;
|
||||
typedef struct _MugMsgViewClass MugMsgViewClass;
|
||||
|
||||
struct _MugMsgView {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
#else
|
||||
GtkVBox parent;
|
||||
/* insert public members, if any */
|
||||
#endif /*!HAVE_GTK3*/
|
||||
};
|
||||
|
||||
struct _MugMsgViewClass {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBoxClass parent_class;
|
||||
#else
|
||||
GtkVBoxClass parent_class;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* insert signal callback declarations, e.g. */
|
||||
/* void (* my_event) (MugMsg* obj); */
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType
|
||||
mug_msg_view_get_type (void)
|
||||
G_GNUC_CONST;
|
||||
GType mug_msg_view_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
|
||||
GtkWidget *
|
||||
mug_msg_view_new (void);
|
||||
gboolean
|
||||
mug_msg_view_set_msg (MugMsgView * self, const char *msgpath);
|
||||
GtkWidget* mug_msg_view_new (void);
|
||||
gboolean mug_msg_view_set_msg (MugMsgView * self, const char *msgpath);
|
||||
void mug_msg_view_set_note (MugMsgView * self, const char* html);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __MUG_MSG_VIEW_H__ */
|
||||
|
||||
@ -1,22 +1,6 @@
|
||||
/*
|
||||
** Copyright (C) 2011 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.
|
||||
**
|
||||
*/
|
||||
/* mug-query-bar.c */
|
||||
|
||||
/* insert (c)/licensing information) */
|
||||
|
||||
#include "mug-query-bar.h"
|
||||
/* include other impl specific header files */
|
||||
@ -42,30 +26,16 @@ struct _MugQueryBarPrivate {
|
||||
/* globals */
|
||||
static GtkContainerClass *parent_class = NULL;
|
||||
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
GType
|
||||
mug_query_bar_get_type (void)
|
||||
{
|
||||
static GType my_type = 0;
|
||||
if (!my_type) {
|
||||
static const GTypeInfo my_info = {
|
||||
sizeof (MugQueryBarClass),
|
||||
NULL, /* base init */
|
||||
NULL, /* base finalize */
|
||||
(GClassInitFunc) mug_query_bar_class_init,
|
||||
NULL, /* class finalize */
|
||||
NULL, /* class data */
|
||||
sizeof (MugQueryBar),
|
||||
0, /* n_preallocs, ignored since 2.10 */
|
||||
(GInstanceInitFunc) mug_query_bar_init,
|
||||
NULL
|
||||
};
|
||||
my_type = g_type_register_static (GTK_TYPE_HBOX,
|
||||
"MugQueryBar", &my_info, 0);
|
||||
}
|
||||
return my_type;
|
||||
}
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
G_DEFINE_TYPE (MugQueryBar, mug_query_bar, GTK_TYPE_BOX);
|
||||
#else
|
||||
G_DEFINE_TYPE (MugQueryBar, mug_query_bar, GTK_TYPE_HBOX);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
|
||||
static void
|
||||
mug_query_bar_class_init (MugQueryBarClass * klass)
|
||||
|
||||
@ -4,8 +4,11 @@
|
||||
#ifndef __MUG_QUERY_BAR_H__
|
||||
#define __MUG_QUERY_BAR_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
/* other include files */
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/* convenience macros */
|
||||
@ -19,12 +22,22 @@ typedef struct _MugQueryBar MugQueryBar;
|
||||
typedef struct _MugQueryBarClass MugQueryBarClass;
|
||||
|
||||
struct _MugQueryBar {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
#else
|
||||
GtkHBox parent;
|
||||
/* insert public members, if any */
|
||||
#endif /*!HAVE_GTK3*/
|
||||
};
|
||||
|
||||
struct _MugQueryBarClass {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
GtkBoxClass parent_class;
|
||||
#else
|
||||
GtkHBox parent;
|
||||
GtkHBoxClass parent_class;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* insert signal callback declarations, e.g. */
|
||||
void (*query_changed) (MugQueryBar * obj, const char *query);
|
||||
};
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#include "mug-shortcuts.h"
|
||||
#include "mu-bookmarks.h"
|
||||
@ -46,11 +45,17 @@ struct _MugShortcutsPrivate {
|
||||
MUG_TYPE_SHORTCUTS, \
|
||||
MugShortcutsPrivate))
|
||||
/* globals */
|
||||
static GtkVBoxClass *parent_class = NULL;
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
static GtkBoxClass *parent_class = NULL;
|
||||
G_DEFINE_TYPE (MugShortcuts, mug_shortcuts, GTK_TYPE_BOX);
|
||||
#else
|
||||
static GtkVBoxClass *parent_class = NULL;
|
||||
G_DEFINE_TYPE (MugShortcuts, mug_shortcuts, GTK_TYPE_VBOX);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
static void
|
||||
mug_shortcuts_class_init (MugShortcutsClass * klass)
|
||||
@ -87,8 +92,7 @@ mug_shortcuts_init (MugShortcuts * obj)
|
||||
obj->_priv->_bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
|
||||
#else
|
||||
obj->_priv->_bbox = gtk_vbutton_box_new ();
|
||||
|
||||
#endif /*!HAVE_GTK3 */
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
gtk_button_box_set_layout (GTK_BUTTON_BOX (obj->_priv->_bbox),
|
||||
GTK_BUTTONBOX_START);
|
||||
|
||||
@ -20,6 +20,11 @@
|
||||
#ifndef __MUG_SHORTCUTS_H__
|
||||
#define __MUG_SHORTCUTS_H__
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
/* other include files */
|
||||
|
||||
@ -36,15 +41,23 @@ typedef struct _MugShortcutsClass MugShortcutsClass;
|
||||
typedef struct _MugShortcutsPrivate MugShortcutsPrivate;
|
||||
|
||||
struct _MugShortcuts {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
#else
|
||||
GtkVBox parent;
|
||||
/* insert public members, if any */
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* private */
|
||||
MugShortcutsPrivate *_priv;
|
||||
};
|
||||
|
||||
struct _MugShortcutsClass {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBoxClass parent_class;
|
||||
#else
|
||||
GtkVBoxClass parent_class;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
void (*clicked) (MugShortcuts * obj, const char *query);
|
||||
};
|
||||
|
||||
|
||||
@ -25,8 +25,10 @@
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <string.h> /* for memset */
|
||||
|
||||
#include "mu-util.h"
|
||||
#include "mu-runtime.h"
|
||||
#include <mu-util.h>
|
||||
#include <mu-store.h>
|
||||
#include <mu-runtime.h>
|
||||
#include <mu-index.h>
|
||||
|
||||
#include "mug-msg-list-view.h"
|
||||
#include "mug-query-bar.h"
|
||||
@ -45,6 +47,7 @@ struct _MugData {
|
||||
};
|
||||
typedef struct _MugData MugData;
|
||||
|
||||
|
||||
static void
|
||||
about_mug (MugData * mugdata)
|
||||
{
|
||||
@ -64,6 +67,7 @@ about_mug (MugData * mugdata)
|
||||
enum _ToolAction {
|
||||
ACTION_PREV_MSG = 1,
|
||||
ACTION_NEXT_MSG,
|
||||
ACTION_REINDEX,
|
||||
ACTION_DO_QUIT,
|
||||
ACTION_ABOUT,
|
||||
ACTION_SEPARATOR /* pseudo action */
|
||||
@ -124,6 +128,8 @@ mug_toolbar (MugData * mugdata)
|
||||
{GTK_STOCK_GO_UP, ACTION_PREV_MSG},
|
||||
{GTK_STOCK_GO_DOWN, ACTION_NEXT_MSG},
|
||||
{NULL, ACTION_SEPARATOR},
|
||||
{GTK_STOCK_REFRESH, ACTION_REINDEX},
|
||||
{NULL, ACTION_SEPARATOR},
|
||||
{GTK_STOCK_ABOUT, ACTION_ABOUT},
|
||||
{NULL, ACTION_SEPARATOR},
|
||||
{GTK_STOCK_QUIT, ACTION_DO_QUIT}};
|
||||
@ -178,7 +184,6 @@ on_query_changed (MugQueryBar * bar, const char *query, MugData * mugdata)
|
||||
int count;
|
||||
|
||||
/* clear the old message */
|
||||
//mug_msg_view_set_text (MUG_MSG_VIEW(mugdata->msgview), NULL);
|
||||
mug_msg_view_set_msg (MUG_MSG_VIEW (mugdata->msgview), NULL);
|
||||
|
||||
count = mug_msg_list_view_query (MUG_MSG_LIST_VIEW (mugdata->mlist),
|
||||
@ -205,7 +210,6 @@ on_query_changed (MugQueryBar * bar, const char *query, MugData * mugdata)
|
||||
static void
|
||||
on_msg_selected (MugMsgListView * mlist, const char *mpath, MugData * mugdata)
|
||||
{
|
||||
// g_warning ("msg selected: %s", mpath);
|
||||
mug_msg_view_set_msg (MUG_MSG_VIEW (mugdata->msgview), mpath);
|
||||
}
|
||||
|
||||
@ -240,9 +244,8 @@ on_list_view_error (MugMsgListView * mlist, MugError err, MugData * mugdata)
|
||||
gtk_dialog_run (GTK_DIALOG (errdialog));
|
||||
gtk_widget_destroy (errdialog);
|
||||
|
||||
if (err == MUG_ERROR_QUERY) {
|
||||
if (err == MUG_ERROR_QUERY)
|
||||
mug_query_bar_grab_focus (MUG_QUERY_BAR (mugdata->querybar));
|
||||
}
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
@ -258,9 +261,7 @@ mug_querybar (void)
|
||||
static GtkWidget *
|
||||
mug_query_area (MugData * mugdata)
|
||||
{
|
||||
GtkWidget *queryarea;
|
||||
GtkWidget *paned;
|
||||
GtkWidget *scrolled;
|
||||
GtkWidget *queryarea, *paned, *scrolled;
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
queryarea = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
||||
@ -268,7 +269,7 @@ mug_query_area (MugData * mugdata)
|
||||
#else
|
||||
queryarea = gtk_vbox_new (FALSE, 2);
|
||||
paned = gtk_vpaned_new ();
|
||||
#endif /*!HAVE_GTK3 */
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
|
||||
mugdata->mlist = mug_msg_list_view_new
|
||||
@ -282,8 +283,10 @@ mug_query_area (MugData * mugdata)
|
||||
gtk_paned_add1 (GTK_PANED (paned), scrolled);
|
||||
|
||||
mugdata->msgview = mug_msg_view_new ();
|
||||
|
||||
mug_msg_view_set_msg (MUG_MSG_VIEW (mugdata->msgview), NULL);
|
||||
mug_msg_view_set_note (MUG_MSG_VIEW(mugdata->msgview),
|
||||
"<h1>Welcome to <i>mug</i>!</h1><hr>"
|
||||
"<tt>mug</tt> is an experimental UI for <tt>mu</tt>, which will "
|
||||
"slowly evolve into something useful.<br><br>Enjoy the ride.");
|
||||
g_signal_connect (G_OBJECT (mugdata->mlist), "msg-selected",
|
||||
G_CALLBACK (on_msg_selected), mugdata);
|
||||
g_signal_connect (G_OBJECT (mugdata->mlist), "error-occured",
|
||||
@ -311,7 +314,7 @@ mug_main_area (MugData * mugdata)
|
||||
mainarea = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
||||
#else
|
||||
mainarea = gtk_hbox_new (FALSE, 5);
|
||||
#endif /*!HAVE_GTK3 */
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
w = mug_shortcuts_bar (mugdata);
|
||||
gtk_box_pack_start (GTK_BOX (mainarea), w, FALSE, FALSE, 0);
|
||||
@ -336,7 +339,7 @@ mug_shell (MugData * mugdata)
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
||||
#else
|
||||
vbox = gtk_vbox_new (FALSE, 2);
|
||||
#endif /*!HAVE_GTK3 */
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
mugdata->toolbar = mug_toolbar (mugdata);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), mugdata->toolbar, FALSE, FALSE, 2);
|
||||
@ -353,12 +356,13 @@ mug_shell (MugData * mugdata)
|
||||
gtk_window_set_default_size (GTK_WINDOW (mugdata->win), 700, 500);
|
||||
gtk_window_set_resizable (GTK_WINDOW (mugdata->win), TRUE);
|
||||
|
||||
// {
|
||||
// gchar *icon;
|
||||
// icon = g_strdup_printf ("%s%cmug.svg", ICONDIR, G_DIR_SEPARATOR);
|
||||
// gtk_window_set_icon_from_file (GTK_WINDOW (mugdata->win), icon, NULL);
|
||||
// g_free (icon);
|
||||
// }
|
||||
{
|
||||
gchar *icon;
|
||||
icon = g_strdup_printf ("%s%cmug.svg",
|
||||
MUGDIR, G_DIR_SEPARATOR);
|
||||
gtk_window_set_icon_from_file (GTK_WINDOW (mugdata->win), icon, NULL);
|
||||
g_free (icon);
|
||||
}
|
||||
|
||||
return mugdata->win;
|
||||
}
|
||||
@ -392,10 +396,12 @@ main (int argc, char *argv[])
|
||||
|
||||
memset (&mugdata, 0, sizeof (MugData));
|
||||
if (!g_option_context_parse (octx, &argc, &argv, NULL)) {
|
||||
g_option_context_free (octx);
|
||||
g_printerr ("mug: error in options\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_option_context_free (octx);
|
||||
mu_runtime_init (mugdata.muhome, "mug");
|
||||
|
||||
mugshell = mug_shell (&mugdata);
|
||||
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@ -1,65 +0,0 @@
|
||||
## Copyright (C) 2008-2011 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
|
||||
## t he Free Software Foundation; either version 3 of the License, 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 $(top_srcdir)/gtest.mk
|
||||
|
||||
# enforce compiling this dir first before decending into tests/
|
||||
SUBDIRS= .
|
||||
|
||||
INCLUDES=-I${top_srcdir} -I${top_srcdir}/lib $(GTK_CFLAGS) $(WEBKIT_CFLAGS) -DICONDIR='"$(icondir)"' \
|
||||
-DMUG2DIR='"$(abs_srcdir)"' -DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE
|
||||
|
||||
# don't use -Werror, as it might break on other compilers
|
||||
# use -Wno-unused-parameters, because some callbacks may not
|
||||
# really need all the params they get
|
||||
AM_CFLAGS=-Wall -Wextra -Wno-unused-parameter -Wdeclaration-after-statement
|
||||
AM_CXXFLAGS=-Wall -Wextra -Wno-unused-parameter
|
||||
|
||||
noinst_PROGRAMS= \
|
||||
mug2
|
||||
|
||||
# note, mug.cc is '.cc' only because libmu must explicitly
|
||||
# be linked as c++, not c.
|
||||
mug2_SOURCES= \
|
||||
mug.c \
|
||||
mug-msg-list-view.c \
|
||||
mug-msg-list-view.h \
|
||||
mug-msg-view.h \
|
||||
mug-msg-view.c \
|
||||
mug-query-bar.h \
|
||||
mug-query-bar.c \
|
||||
mug-shortcuts.c \
|
||||
mug-shortcuts.h \
|
||||
dummy.cc
|
||||
|
||||
# we need to use dummy.cc to enforce c++ linking...
|
||||
BUILT_SOURCES= \
|
||||
dummy.cc
|
||||
|
||||
dummy.cc:
|
||||
touch dummy.cc
|
||||
|
||||
DISTCLEANFILES= \
|
||||
$(BUILT_SOURCES)
|
||||
|
||||
|
||||
mug2_LDADD= \
|
||||
${top_builddir}/lib/libmu.la \
|
||||
${top_builddir}/widgets/libmuwidgets.la \
|
||||
${GTK_LIBS}
|
||||
|
||||
EXTRA_DIST= \
|
||||
mug.svg
|
||||
@ -1,466 +0,0 @@
|
||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||
/*
|
||||
** Copyright (C) 2008-2011 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.h"
|
||||
#include "mu-str.h"
|
||||
#include "mu-date.h"
|
||||
#include "mu-threader.h"
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mug_msg_list_view_class_init (MugMsgListViewClass * klass);
|
||||
static void mug_msg_list_view_init (MugMsgListView * obj);
|
||||
static void mug_msg_list_view_finalize (GObject * obj);
|
||||
|
||||
/* list my signals */
|
||||
enum {
|
||||
MUG_MSG_SELECTED,
|
||||
MUG_ERROR_OCCURED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum {
|
||||
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
|
||||
};
|
||||
|
||||
typedef struct _MugMsgListViewPrivate MugMsgListViewPrivate;
|
||||
struct _MugMsgListViewPrivate {
|
||||
GtkTreeStore *_store;
|
||||
char *_xpath;
|
||||
char *_query;
|
||||
};
|
||||
#define MUG_MSG_LIST_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MUG_TYPE_MSG_LIST_VIEW, \
|
||||
MugMsgListViewPrivate))
|
||||
/* globals */
|
||||
static GtkTreeViewClass *parent_class = NULL;
|
||||
|
||||
/* uncomment the following if you have defined any signals */
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE (MugMsgListView, mug_msg_list_view, GTK_TYPE_TREE_VIEW);
|
||||
|
||||
static void
|
||||
mug_msg_list_view_class_init (MugMsgListViewClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
|
||||
parent_class = 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);
|
||||
}
|
||||
|
||||
static void
|
||||
on_cursor_changed (GtkTreeView * tview, MugMsgListView * lst)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
treecell_func (GtkTreeViewColumn * tree_column, GtkCellRenderer * renderer,
|
||||
GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/* sortcolidx == -1 means 'sortcolidx = colidx' */
|
||||
static void
|
||||
append_col (GtkTreeView * treeview, const char *label, int colidx,
|
||||
int sortcolidx, gint maxwidth)
|
||||
{
|
||||
GtkTreeViewColumn *col;
|
||||
GtkCellRenderer *renderer;
|
||||
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END,
|
||||
NULL);
|
||||
|
||||
col = gtk_tree_view_column_new_with_attributes (label, renderer, "text",
|
||||
colidx, NULL);
|
||||
g_object_set (G_OBJECT (col), "resizable", TRUE, NULL);
|
||||
|
||||
gtk_tree_view_column_set_sort_indicator (col, TRUE);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
gtk_tree_view_column_set_cell_data_func (col, renderer,
|
||||
(GtkTreeCellDataFunc)
|
||||
treecell_func, NULL, NULL);
|
||||
|
||||
gtk_tree_view_append_column (treeview, col);
|
||||
|
||||
gtk_tree_view_columns_autosize (treeview);
|
||||
gtk_tree_view_set_fixed_height_mode (treeview, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
mug_msg_list_view_init (MugMsgListView * obj)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
mug_msg_list_view_finalize (GObject * obj)
|
||||
{
|
||||
MugMsgListViewPrivate *priv;
|
||||
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE (obj);
|
||||
|
||||
if (priv->_store)
|
||||
g_object_unref (priv->_store);
|
||||
|
||||
g_free (priv->_xpath);
|
||||
g_free (priv->_query);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
void
|
||||
mug_msg_list_view_move_first (MugMsgListView * self)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
|
||||
g_return_if_fail (MUG_IS_MSG_LIST_VIEW (self));
|
||||
|
||||
path = gtk_tree_path_new_first ();
|
||||
gtk_tree_view_set_cursor (GTK_TREE_VIEW (self), path, NULL, FALSE);
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
msg_list_view_move (MugMsgListView * self, gboolean next)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
|
||||
gtk_tree_view_get_cursor (GTK_TREE_VIEW (self), &path, NULL);
|
||||
if (!path)
|
||||
return FALSE;
|
||||
|
||||
if (next)
|
||||
gtk_tree_path_next (path);
|
||||
else
|
||||
gtk_tree_path_prev (path);
|
||||
|
||||
gtk_tree_view_set_cursor (GTK_TREE_VIEW (self), path, NULL, FALSE);
|
||||
gtk_tree_path_free (path);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mug_msg_list_view_move_next (MugMsgListView * self)
|
||||
{
|
||||
g_return_val_if_fail (MUG_IS_MSG_LIST_VIEW (self), FALSE);
|
||||
|
||||
return msg_list_view_move (self, TRUE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mug_msg_list_view_move_prev (MugMsgListView * self)
|
||||
{
|
||||
g_return_val_if_fail (MUG_IS_MSG_LIST_VIEW (self), FALSE);
|
||||
|
||||
return msg_list_view_move (self, FALSE);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
mug_msg_list_view_new (const char *xpath)
|
||||
{
|
||||
GtkWidget *w;
|
||||
MugMsgListViewPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (xpath, NULL);
|
||||
|
||||
w = GTK_WIDGET (g_object_new (MUG_TYPE_MSG_LIST_VIEW, NULL));
|
||||
|
||||
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE (w);
|
||||
priv->_xpath = g_strdup (xpath);
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
empty_or_display_contact (const gchar * str)
|
||||
{
|
||||
if (!str || *str == '\0')
|
||||
return g_strdup ("-");
|
||||
else
|
||||
return mu_str_display_contact (str);
|
||||
|
||||
}
|
||||
|
||||
static MugError
|
||||
mu_result_to_mug_error (MuError r)
|
||||
{
|
||||
switch (r) {
|
||||
case MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE:
|
||||
return MUG_ERROR_XAPIAN_DIR;
|
||||
case MU_ERROR_XAPIAN_NOT_UP_TO_DATE:
|
||||
return MUG_ERROR_XAPIAN_NOT_UPTODATE;
|
||||
case MU_ERROR_XAPIAN_QUERY:
|
||||
return MUG_ERROR_QUERY;
|
||||
default:
|
||||
return MUG_ERROR_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
static MuMsgIter *
|
||||
run_query (const char *xpath, const char *query, MugMsgListView * self)
|
||||
{
|
||||
GError *err;
|
||||
MuQuery *xapian;
|
||||
MuMsgIter *iter;
|
||||
MuStore *store;
|
||||
|
||||
err = NULL;
|
||||
if (! (store = mu_store_new_read_only (xpath, &err)) ||
|
||||
! (xapian = mu_query_new (store, &err))) {
|
||||
if (store)
|
||||
mu_store_unref (store);
|
||||
g_warning ("Error: %s", err->message);
|
||||
g_signal_emit (G_OBJECT (self),
|
||||
signals[MUG_ERROR_OCCURED], 0,
|
||||
mu_result_to_mug_error (err->code));
|
||||
g_error_free (err);
|
||||
return NULL;
|
||||
}
|
||||
mu_store_unref (store);
|
||||
|
||||
iter = mu_query_run (xapian, query, TRUE, MU_MSG_FIELD_ID_DATE,
|
||||
TRUE, -1, &err);
|
||||
mu_query_destroy (xapian);
|
||||
if (!iter) {
|
||||
g_warning ("Error: %s", err->message);
|
||||
g_signal_emit (G_OBJECT (self),
|
||||
signals[MUG_ERROR_OCCURED], 0,
|
||||
mu_result_to_mug_error (err->code));
|
||||
g_error_free (err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
static void
|
||||
add_row (GtkTreeStore * store, MuMsg *msg, GtkTreeIter *treeiter)
|
||||
{
|
||||
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",
|
||||
* __FUNCTION__, 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);
|
||||
}
|
||||
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (count = 0; !mu_msg_iter_is_done (iter);
|
||||
mu_msg_iter_next (iter), ++count) {
|
||||
|
||||
GtkTreeIter treeiter, prev_treeiter;
|
||||
const MuMsgIterThreadInfo *ti;
|
||||
|
||||
ti = mu_msg_iter_get_thread_info (iter);
|
||||
|
||||
if (!prev_ti || !g_str_has_prefix (ti->threadpath,
|
||||
prev_ti->threadpath))
|
||||
gtk_tree_store_append (store, &treeiter, NULL);
|
||||
else
|
||||
gtk_tree_store_append (store, &treeiter, &prev_treeiter);
|
||||
|
||||
/* don't unref msg */
|
||||
add_row (store, mu_msg_iter_get_msg_floating (iter), &treeiter);
|
||||
|
||||
prev_ti = ti;
|
||||
prev_treeiter = treeiter;
|
||||
}
|
||||
|
||||
mu_msg_iter_destroy (iter);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int
|
||||
mug_msg_list_view_query (MugMsgListView * self, const char *query)
|
||||
{
|
||||
MugMsgListViewPrivate *priv;
|
||||
gboolean rv;
|
||||
|
||||
g_return_val_if_fail (MUG_IS_MSG_LIST_VIEW (self), FALSE);
|
||||
|
||||
priv = MUG_MSG_LIST_VIEW_GET_PRIVATE (self);
|
||||
gtk_tree_store_clear (priv->_store);
|
||||
|
||||
g_free (priv->_query);
|
||||
priv->_query = query ? g_strdup (query) : NULL;
|
||||
|
||||
if (!query)
|
||||
return TRUE;
|
||||
|
||||
rv = update_model (priv->_store, priv->_xpath, query, self);
|
||||
|
||||
gtk_tree_view_expand_all (GTK_TREE_VIEW(self));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
mug_msg_list_view_get_query (MugMsgListView * self)
|
||||
{
|
||||
g_return_val_if_fail (MUG_IS_MSG_LIST_VIEW (self), NULL);
|
||||
|
||||
return MUG_MSG_LIST_VIEW_GET_PRIVATE (self)->_query;
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
/*
|
||||
** Copyright (C) 2008-2010 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MUG_MSG_LIST_VIEW_H__
|
||||
#define __MUG_MSG_LIST_VIEW_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <mu-util.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/* convenience macros */
|
||||
#define MUG_TYPE_MSG_LIST_VIEW (mug_msg_list_view_get_type())
|
||||
#define MUG_MSG_LIST_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MUG_TYPE_MSG_LIST_VIEW,MugMsgListView))
|
||||
#define MUG_MSG_LIST_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MUG_TYPE_MSG_LIST_VIEW,MugMsgListViewClass))
|
||||
#define MUG_IS_MSG_LIST_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MUG_TYPE_MSG_LIST_VIEW))
|
||||
#define MUG_IS_MSG_LIST_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MUG_TYPE_MSG_LIST_VIEW))
|
||||
#define MUG_MSG_LIST_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MUG_TYPE_MSG_LIST_VIEW,MugMsgListViewClass))
|
||||
typedef struct _MugMsgListView MugMsgListView;
|
||||
typedef struct _MugMsgListViewClass MugMsgListViewClass;
|
||||
|
||||
struct _MugMsgListView {
|
||||
GtkTreeView parent;
|
||||
/* insert public members, if any */
|
||||
};
|
||||
|
||||
enum _MugError {
|
||||
MUG_ERROR_XAPIAN_NOT_UPTODATE,
|
||||
MUG_ERROR_XAPIAN_DIR,
|
||||
MUG_ERROR_QUERY,
|
||||
MUG_ERROR_OTHER
|
||||
};
|
||||
typedef enum _MugError MugError;
|
||||
|
||||
struct _MugMsgListViewClass {
|
||||
GtkTreeViewClass parent_class;
|
||||
/* insert signal callback declarations, e.g. */
|
||||
void (*msg_selected) (MugMsgListView * obj, const char *msgpath);
|
||||
void (*error_occured) (MugMsgListView * obj, MugError err);
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType
|
||||
mug_msg_list_view_get_type (void)
|
||||
G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
|
||||
GtkWidget *
|
||||
mug_msg_list_view_new (const char *xpath);
|
||||
|
||||
int
|
||||
mug_msg_list_view_query (MugMsgListView * self, const char *query);
|
||||
|
||||
void
|
||||
mug_msg_list_view_move_first (MugMsgListView * self);
|
||||
|
||||
gboolean
|
||||
mug_msg_list_view_move_prev (MugMsgListView * self);
|
||||
gboolean
|
||||
mug_msg_list_view_move_next (MugMsgListView * self);
|
||||
|
||||
const gchar *
|
||||
mug_msg_list_view_get_query (MugMsgListView * self);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __MUG_MSG_LIST_VIEW_H__ */
|
||||
@ -1,159 +0,0 @@
|
||||
/*
|
||||
** Copyright (C) 2008-2010 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.
|
||||
**
|
||||
*/
|
||||
#ifdef HAVE_CONFIG
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <widgets/mu-msg-view.h>
|
||||
|
||||
#include "mug-msg-view.h"
|
||||
#include "mu-msg.h"
|
||||
#include "mu-str.h"
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mug_msg_view_class_init (MugMsgViewClass * klass);
|
||||
static void mug_msg_view_init (MugMsgView * obj);
|
||||
static void mug_msg_view_finalize (GObject * obj);
|
||||
|
||||
/* list my signals */
|
||||
enum {
|
||||
/* MY_SIGNAL_1, */
|
||||
/* MY_SIGNAL_2, */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
|
||||
typedef struct _MugMsgViewPrivate MugMsgViewPrivate;
|
||||
struct _MugMsgViewPrivate {
|
||||
GtkWidget *_view;
|
||||
};
|
||||
#define MUG_MSG_VIEW_GET_PRIVATE(o)(G_TYPE_INSTANCE_GET_PRIVATE((o),MUG_TYPE_MSG_VIEW, MugMsgViewPrivate))
|
||||
/* globals */
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
static GtkBoxClass *parent_class = NULL;
|
||||
G_DEFINE_TYPE (MugMsgView, mug_msg_view, GTK_TYPE_BOX);
|
||||
#else
|
||||
static GtkVBoxClass *parent_class = NULL;
|
||||
G_DEFINE_TYPE (MugMsgView, mug_msg_view, GTK_TYPE_VBOX);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* uncomment the following if you have defined any signals */
|
||||
/* static guint signals[LAST_SIGNAL] = {0}; */
|
||||
|
||||
static void
|
||||
mug_msg_view_class_init (MugMsgViewClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = mug_msg_view_finalize;
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (MugMsgViewPrivate));
|
||||
|
||||
/* signal definitions go here, e.g.: */
|
||||
/* signals[MY_SIGNAL_1] = */
|
||||
/* g_signal_new ("my_signal_1",....); */
|
||||
/* signals[MY_SIGNAL_2] = */
|
||||
/* g_signal_new ("my_signal_2",....); */
|
||||
/* etc. */
|
||||
}
|
||||
|
||||
static void
|
||||
mug_msg_view_init (MugMsgView * obj)
|
||||
{
|
||||
MugMsgViewPrivate *priv;
|
||||
GtkWidget *scrolled;
|
||||
|
||||
priv = MUG_MSG_VIEW_GET_PRIVATE (obj);
|
||||
|
||||
priv->_view = mu_msg_view_new ();
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
|
||||
priv->_view);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (obj), scrolled, TRUE, TRUE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
mug_msg_view_finalize (GObject * obj)
|
||||
{
|
||||
/* free/unref instance resources here */
|
||||
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
mug_msg_view_new (void)
|
||||
{
|
||||
return GTK_WIDGET (g_object_new (MUG_TYPE_MSG_VIEW, NULL));
|
||||
}
|
||||
|
||||
|
||||
|
||||
gboolean
|
||||
mug_msg_view_set_msg (MugMsgView * self, const char *msgpath)
|
||||
{
|
||||
MugMsgViewPrivate *priv;
|
||||
g_return_val_if_fail (MUG_IS_MSG_VIEW (self), FALSE);
|
||||
|
||||
priv = MUG_MSG_VIEW_GET_PRIVATE (self);
|
||||
|
||||
if (!msgpath)
|
||||
mu_msg_view_set_message (MU_MSG_VIEW(priv->_view), NULL);
|
||||
else {
|
||||
MuMsg *msg;
|
||||
|
||||
if (access (msgpath, R_OK) == 0) {
|
||||
msg = mu_msg_new_from_file (msgpath, NULL, NULL);
|
||||
mu_msg_view_set_message (MU_MSG_VIEW(priv->_view), msg);
|
||||
if (msg)
|
||||
mu_msg_unref (msg);
|
||||
} else {
|
||||
gchar *note;
|
||||
note = g_strdup_printf (
|
||||
"<h1>Note</h1><hr>"
|
||||
"<p>Message <tt>%s</tt> does not seem to be present "
|
||||
"on the file system."
|
||||
"<p>Maybe you need to run <tt>mu index</tt>?",
|
||||
msgpath);
|
||||
mu_msg_view_set_note (MU_MSG_VIEW (priv->_view), note);
|
||||
g_free (note);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mug_msg_view_set_note (MugMsgView * self, const char* html)
|
||||
{
|
||||
MugMsgViewPrivate *priv;
|
||||
g_return_if_fail (MUG_IS_MSG_VIEW (self));
|
||||
|
||||
priv = MUG_MSG_VIEW_GET_PRIVATE (self);
|
||||
|
||||
mu_msg_view_set_note (MU_MSG_VIEW (priv->_view), html);
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
/*
|
||||
** Copyright (C) 2010 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MUG_MSG_VIEW_H__
|
||||
#define __MUG_MSG_VIEW_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
/* other include files */
|
||||
|
||||
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/* convenience macros */
|
||||
#define MUG_TYPE_MSG_VIEW (mug_msg_view_get_type())
|
||||
#define MUG_MSG_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MUG_TYPE_MSG_VIEW,MugMsgView))
|
||||
#define MUG_MSG_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MUG_TYPE_MSG_VIEW,MugMsgViewClass))
|
||||
#define MUG_IS_MSG_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MUG_TYPE_MSG_VIEW))
|
||||
#define MUG_IS_MSG_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MUG_TYPE_MSG_VIEW))
|
||||
#define MUG_MSG_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MUG_TYPE_MSG_VIEW,MugMsgViewClass))
|
||||
typedef struct _MugMsgView MugMsgView;
|
||||
typedef struct _MugMsgViewClass MugMsgViewClass;
|
||||
|
||||
struct _MugMsgView {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
#else
|
||||
GtkVBox parent;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
};
|
||||
|
||||
struct _MugMsgViewClass {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBoxClass parent_class;
|
||||
#else
|
||||
GtkVBoxClass parent_class;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* insert signal callback declarations, e.g. */
|
||||
/* void (* my_event) (MugMsg* obj); */
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType mug_msg_view_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
|
||||
GtkWidget* mug_msg_view_new (void);
|
||||
gboolean mug_msg_view_set_msg (MugMsgView * self, const char *msgpath);
|
||||
void mug_msg_view_set_note (MugMsgView * self, const char* html);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __MUG_MSG_VIEW_H__ */
|
||||
@ -1,118 +0,0 @@
|
||||
/* mug-query-bar.c */
|
||||
|
||||
/* insert (c)/licensing information) */
|
||||
|
||||
#include "mug-query-bar.h"
|
||||
/* include other impl specific header files */
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mug_query_bar_class_init (MugQueryBarClass * klass);
|
||||
static void mug_query_bar_init (MugQueryBar * obj);
|
||||
static void mug_query_bar_finalize (GObject * obj);
|
||||
|
||||
/* list my signals */
|
||||
enum {
|
||||
MUG_QUERY_CHANGED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
typedef struct _MugQueryBarPrivate MugQueryBarPrivate;
|
||||
struct _MugQueryBarPrivate {
|
||||
GtkWidget *_entry;
|
||||
};
|
||||
#define MUG_QUERY_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MUG_TYPE_QUERY_BAR, \
|
||||
MugQueryBarPrivate))
|
||||
/* globals */
|
||||
static GtkContainerClass *parent_class = NULL;
|
||||
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
G_DEFINE_TYPE (MugQueryBar, mug_query_bar, GTK_TYPE_BOX);
|
||||
#else
|
||||
G_DEFINE_TYPE (MugQueryBar, mug_query_bar, GTK_TYPE_HBOX);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
|
||||
static void
|
||||
mug_query_bar_class_init (MugQueryBarClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = mug_query_bar_finalize;
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (MugQueryBarPrivate));
|
||||
|
||||
/* signal definitions go here, e.g.: */
|
||||
signals[MUG_QUERY_CHANGED] =
|
||||
g_signal_new ("query_changed",
|
||||
G_TYPE_FROM_CLASS (gobject_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (MugQueryBarClass, query_changed),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
}
|
||||
|
||||
static void
|
||||
on_entry_activated (GtkWidget * w, MugQueryBar * bar)
|
||||
{
|
||||
g_signal_emit (G_OBJECT (bar), signals[MUG_QUERY_CHANGED], 0,
|
||||
gtk_entry_get_text (GTK_ENTRY (w)));
|
||||
}
|
||||
|
||||
static void
|
||||
mug_query_bar_init (MugQueryBar * obj)
|
||||
{
|
||||
MugQueryBarPrivate *priv;
|
||||
|
||||
priv = MUG_QUERY_BAR_GET_PRIVATE (obj);
|
||||
|
||||
priv->_entry = gtk_entry_new ();
|
||||
|
||||
g_signal_connect (priv->_entry, "activate",
|
||||
G_CALLBACK (on_entry_activated), obj);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (obj), priv->_entry, TRUE, TRUE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
mug_query_bar_finalize (GObject * obj)
|
||||
{
|
||||
/* free/unref instance resources here */
|
||||
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
mug_query_bar_new (void)
|
||||
{
|
||||
return GTK_WIDGET (g_object_new (MUG_TYPE_QUERY_BAR, NULL));
|
||||
}
|
||||
|
||||
void
|
||||
mug_query_bar_set_query (MugQueryBar * self, const char *query, gboolean run)
|
||||
{
|
||||
MugQueryBarPrivate *priv;
|
||||
|
||||
g_return_if_fail (MUG_IS_QUERY_BAR (self));
|
||||
priv = MUG_QUERY_BAR_GET_PRIVATE (self);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (priv->_entry), query ? query : "");
|
||||
|
||||
if (run)
|
||||
on_entry_activated (priv->_entry, self);
|
||||
}
|
||||
|
||||
void
|
||||
mug_query_bar_grab_focus (MugQueryBar * self)
|
||||
{
|
||||
g_return_if_fail (MUG_IS_QUERY_BAR (self));
|
||||
|
||||
gtk_widget_grab_focus
|
||||
(GTK_WIDGET (MUG_QUERY_BAR_GET_PRIVATE (self)->_entry));
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
/* mug-query-bar.h */
|
||||
/* insert (c)/licensing information) */
|
||||
|
||||
#ifndef __MUG_QUERY_BAR_H__
|
||||
#define __MUG_QUERY_BAR_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/* convenience macros */
|
||||
#define MUG_TYPE_QUERY_BAR (mug_query_bar_get_type())
|
||||
#define MUG_QUERY_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MUG_TYPE_QUERY_BAR,MugQueryBar))
|
||||
#define MUG_QUERY_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MUG_TYPE_QUERY_BAR,MugQueryBarClass))
|
||||
#define MUG_IS_QUERY_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MUG_TYPE_QUERY_BAR))
|
||||
#define MUG_IS_QUERY_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MUG_TYPE_QUERY_BAR))
|
||||
#define MUG_QUERY_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MUG_TYPE_QUERY_BAR,MugQueryBarClass))
|
||||
typedef struct _MugQueryBar MugQueryBar;
|
||||
typedef struct _MugQueryBarClass MugQueryBarClass;
|
||||
|
||||
struct _MugQueryBar {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
#else
|
||||
GtkHBox parent;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
};
|
||||
|
||||
struct _MugQueryBarClass {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
GtkBoxClass parent_class;
|
||||
#else
|
||||
GtkHBox parent;
|
||||
GtkHBoxClass parent_class;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* insert signal callback declarations, e.g. */
|
||||
void (*query_changed) (MugQueryBar * obj, const char *query);
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType
|
||||
mug_query_bar_get_type (void)
|
||||
G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
|
||||
GtkWidget *
|
||||
mug_query_bar_new (void);
|
||||
|
||||
void
|
||||
mug_query_bar_grab_focus (MugQueryBar * self);
|
||||
|
||||
void
|
||||
mug_query_bar_set_query (MugQueryBar * self, const char *query, gboolean run);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __MUG_QUERY_BAR_H__ */
|
||||
@ -1,163 +0,0 @@
|
||||
/*
|
||||
** Copyright (C) 2010 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-shortcuts.h"
|
||||
#include "mu-bookmarks.h"
|
||||
|
||||
/* include other impl specific header files */
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mug_shortcuts_class_init (MugShortcutsClass * klass);
|
||||
static void mug_shortcuts_init (MugShortcuts * obj);
|
||||
static void mug_shortcuts_finalize (GObject * obj);
|
||||
|
||||
#define MUG_SHORTCUT_BOOKMARK "bookmark"
|
||||
|
||||
/* list my signals */
|
||||
enum {
|
||||
SHORTCUT_CLICKED,
|
||||
/* MY_SIGNAL_1, */
|
||||
/* MY_SIGNAL_2, */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
struct _MugShortcutsPrivate {
|
||||
GtkWidget *_bbox;
|
||||
|
||||
};
|
||||
#define MUG_SHORTCUTS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MUG_TYPE_SHORTCUTS, \
|
||||
MugShortcutsPrivate))
|
||||
/* globals */
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
static GtkBoxClass *parent_class = NULL;
|
||||
G_DEFINE_TYPE (MugShortcuts, mug_shortcuts, GTK_TYPE_BOX);
|
||||
#else
|
||||
static GtkVBoxClass *parent_class = NULL;
|
||||
G_DEFINE_TYPE (MugShortcuts, mug_shortcuts, GTK_TYPE_VBOX);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
static void
|
||||
mug_shortcuts_class_init (MugShortcutsClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
gobject_class->finalize = mug_shortcuts_finalize;
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (MugShortcutsPrivate));
|
||||
|
||||
/* signal definitions go here, e.g.: */
|
||||
signals[SHORTCUT_CLICKED] =
|
||||
g_signal_new ("clicked",
|
||||
G_TYPE_FROM_CLASS (gobject_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (MugShortcutsClass, clicked),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
|
||||
/* signals[MY_SIGNAL_2] = */
|
||||
/* g_signal_new ("my_signal_2",....); */
|
||||
/* etc. */
|
||||
}
|
||||
|
||||
static void
|
||||
mug_shortcuts_init (MugShortcuts * obj)
|
||||
{
|
||||
obj->_priv = MUG_SHORTCUTS_GET_PRIVATE (obj);
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
obj->_priv->_bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
|
||||
#else
|
||||
obj->_priv->_bbox = gtk_vbutton_box_new ();
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
gtk_button_box_set_layout (GTK_BUTTON_BOX (obj->_priv->_bbox),
|
||||
GTK_BUTTONBOX_START);
|
||||
gtk_box_pack_start (GTK_BOX (obj), obj->_priv->_bbox, TRUE, TRUE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
mug_shortcuts_finalize (GObject * obj)
|
||||
{
|
||||
/* free/unref instance resources here */
|
||||
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
on_button_clicked (GtkWidget * button, MugShortcuts * self)
|
||||
{
|
||||
g_signal_emit (G_OBJECT (self),
|
||||
signals[SHORTCUT_CLICKED], 0,
|
||||
(const gchar *)g_object_get_data (G_OBJECT (button),
|
||||
MUG_SHORTCUT_BOOKMARK));
|
||||
}
|
||||
|
||||
static void
|
||||
each_bookmark (const char *key, const char *val, MugShortcuts * self)
|
||||
{
|
||||
GtkWidget *button;
|
||||
|
||||
button = gtk_button_new_with_label (key);
|
||||
g_object_set_data_full (G_OBJECT (button), MUG_SHORTCUT_BOOKMARK,
|
||||
g_strdup (val), g_free);
|
||||
g_signal_connect (G_OBJECT (button), "clicked",
|
||||
G_CALLBACK (on_button_clicked), self);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (self->_priv->_bbox), button);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
init_shortcuts (MugShortcuts * self, const char *bmpath)
|
||||
{
|
||||
MuBookmarks *bookmarks;
|
||||
|
||||
bookmarks = mu_bookmarks_new (bmpath);
|
||||
if (!bookmarks)
|
||||
return TRUE;
|
||||
|
||||
mu_bookmarks_foreach (bookmarks, (MuBookmarksForeachFunc) each_bookmark,
|
||||
self);
|
||||
|
||||
mu_bookmarks_destroy (bookmarks);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
mug_shortcuts_new (const char *bmpath)
|
||||
{
|
||||
MugShortcuts *self;
|
||||
|
||||
self = MUG_SHORTCUTS (g_object_new (MUG_TYPE_SHORTCUTS, NULL));
|
||||
if (!init_shortcuts (self, bmpath)) {
|
||||
g_object_unref (self);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return GTK_WIDGET (self);
|
||||
}
|
||||
|
||||
/* following: other function implementations */
|
||||
/* such as mug_shortcuts_do_something, or mug_shortcuts_has_foo */
|
||||
@ -1,79 +0,0 @@
|
||||
/*
|
||||
** Copyright (C) 2010 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MUG_SHORTCUTS_H__
|
||||
#define __MUG_SHORTCUTS_H__
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
/* other include files */
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/* convenience macros */
|
||||
#define MUG_TYPE_SHORTCUTS (mug_shortcuts_get_type())
|
||||
#define MUG_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MUG_TYPE_SHORTCUTS,MugShortcuts))
|
||||
#define MUG_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MUG_TYPE_SHORTCUTS,MugShortcutsClass))
|
||||
#define MUG_IS_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MUG_TYPE_SHORTCUTS))
|
||||
#define MUG_IS_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MUG_TYPE_SHORTCUTS))
|
||||
#define MUG_SHORTCUTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MUG_TYPE_SHORTCUTS,MugShortcutsClass))
|
||||
typedef struct _MugShortcuts MugShortcuts;
|
||||
typedef struct _MugShortcutsClass MugShortcutsClass;
|
||||
typedef struct _MugShortcutsPrivate MugShortcutsPrivate;
|
||||
|
||||
struct _MugShortcuts {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBox parent;
|
||||
#else
|
||||
GtkVBox parent;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
/* private */
|
||||
MugShortcutsPrivate *_priv;
|
||||
};
|
||||
|
||||
struct _MugShortcutsClass {
|
||||
#ifdef HAVE_GTK3
|
||||
GtkBoxClass parent_class;
|
||||
#else
|
||||
GtkVBoxClass parent_class;
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
void (*clicked) (MugShortcuts * obj, const char *query);
|
||||
};
|
||||
|
||||
/* member functions */
|
||||
GType
|
||||
mug_shortcuts_get_type (void)
|
||||
G_GNUC_CONST;
|
||||
|
||||
/* parameter-less _new function (constructor) */
|
||||
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
|
||||
GtkWidget *
|
||||
mug_shortcuts_new (const char *bmpath);
|
||||
|
||||
/* fill in other public functions, e.g.: */
|
||||
/* void mug_shortcuts_do_something (MugShortcuts *self, const gchar* param); */
|
||||
/* gboolean mug_shortcuts_has_foo (MugShortcuts *self, gint value); */
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __MUG_SHORTCUTS_H__ */
|
||||
422
toys/mug2/mug.c
422
toys/mug2/mug.c
@ -1,422 +0,0 @@
|
||||
/*
|
||||
** Copyright (C) 2010-2011 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <string.h> /* for memset */
|
||||
|
||||
#include <mu-util.h>
|
||||
#include <mu-store.h>
|
||||
#include <mu-runtime.h>
|
||||
#include <mu-index.h>
|
||||
|
||||
#include "mug-msg-list-view.h"
|
||||
#include "mug-query-bar.h"
|
||||
#include "mug-msg-view.h"
|
||||
#include "mug-shortcuts.h"
|
||||
|
||||
struct _MugData {
|
||||
GtkWidget *win;
|
||||
GtkWidget *statusbar;
|
||||
GtkWidget *mlist;
|
||||
GtkWidget *toolbar;
|
||||
GtkWidget *msgview;
|
||||
GtkWidget *querybar;
|
||||
GtkWidget *shortcuts;
|
||||
gchar *muhome;
|
||||
};
|
||||
typedef struct _MugData MugData;
|
||||
|
||||
|
||||
static void
|
||||
about_mug (MugData * mugdata)
|
||||
{
|
||||
GtkWidget *about;
|
||||
about = gtk_message_dialog_new
|
||||
(GTK_WINDOW (mugdata->win), GTK_DIALOG_MODAL,
|
||||
GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
|
||||
"Mug version %s\n"
|
||||
"A graphical frontend to the 'mu' e-mail search engine\n\n"
|
||||
"(c) 2010-2011 Dirk-Jan C. Binnema\n"
|
||||
"Released under the terms of the GPLv3+", VERSION);
|
||||
|
||||
gtk_dialog_run (GTK_DIALOG (about));
|
||||
gtk_widget_destroy (about);
|
||||
}
|
||||
|
||||
enum _ToolAction {
|
||||
ACTION_PREV_MSG = 1,
|
||||
ACTION_NEXT_MSG,
|
||||
ACTION_REINDEX,
|
||||
ACTION_DO_QUIT,
|
||||
ACTION_ABOUT,
|
||||
ACTION_SEPARATOR /* pseudo action */
|
||||
};
|
||||
typedef enum _ToolAction ToolAction;
|
||||
|
||||
static void
|
||||
on_tool_button_clicked (GtkToolButton * btn, MugData * mugdata)
|
||||
{
|
||||
ToolAction action;
|
||||
action = (ToolAction)
|
||||
GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (btn), "action"));
|
||||
switch (action) {
|
||||
|
||||
case ACTION_DO_QUIT:
|
||||
gtk_main_quit ();
|
||||
break;
|
||||
case ACTION_NEXT_MSG:
|
||||
mug_msg_list_view_move_next (MUG_MSG_LIST_VIEW
|
||||
(mugdata->mlist));
|
||||
break;
|
||||
case ACTION_PREV_MSG:
|
||||
mug_msg_list_view_move_prev (MUG_MSG_LIST_VIEW
|
||||
(mugdata->mlist));
|
||||
break;
|
||||
case ACTION_ABOUT:
|
||||
about_mug (mugdata);
|
||||
break;
|
||||
default:
|
||||
g_print ("%u\n", action);
|
||||
}
|
||||
}
|
||||
|
||||
static GtkToolItem*
|
||||
get_connected_tool_button (const char* stock_id, ToolAction action,
|
||||
MugData *mugdata)
|
||||
{
|
||||
GtkToolItem *btn;
|
||||
|
||||
btn = gtk_tool_button_new_from_stock (stock_id);
|
||||
g_object_set_data (G_OBJECT (btn), "action",
|
||||
GUINT_TO_POINTER (action));
|
||||
g_signal_connect (G_OBJECT (btn), "clicked",
|
||||
G_CALLBACK (on_tool_button_clicked),
|
||||
mugdata);
|
||||
return btn;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
mug_toolbar (MugData * mugdata)
|
||||
{
|
||||
GtkWidget *toolbar;
|
||||
int i;
|
||||
struct {
|
||||
const char *stock_id;
|
||||
ToolAction action;
|
||||
} tools[] = {
|
||||
{GTK_STOCK_GO_UP, ACTION_PREV_MSG},
|
||||
{GTK_STOCK_GO_DOWN, ACTION_NEXT_MSG},
|
||||
{NULL, ACTION_SEPARATOR},
|
||||
{GTK_STOCK_REFRESH, ACTION_REINDEX},
|
||||
{NULL, ACTION_SEPARATOR},
|
||||
{GTK_STOCK_ABOUT, ACTION_ABOUT},
|
||||
{NULL, ACTION_SEPARATOR},
|
||||
{GTK_STOCK_QUIT, ACTION_DO_QUIT}};
|
||||
|
||||
toolbar = gtk_toolbar_new ();
|
||||
for (i = 0; i != G_N_ELEMENTS (tools); ++i) {
|
||||
if (tools[i].action == ACTION_SEPARATOR) { /* separator? */
|
||||
gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
|
||||
gtk_separator_tool_item_new (), i);
|
||||
continue;
|
||||
} else /* nope: a real item */
|
||||
gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
|
||||
get_connected_tool_button
|
||||
(tools[i].stock_id, tools[i].action,
|
||||
mugdata), i);
|
||||
}
|
||||
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
static void
|
||||
on_shortcut_clicked (GtkWidget * w, const gchar * query, MugData * mdata)
|
||||
{
|
||||
mug_query_bar_set_query (MUG_QUERY_BAR (mdata->querybar), query, TRUE);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
mug_shortcuts_bar (MugData * data)
|
||||
{
|
||||
data->shortcuts = mug_shortcuts_new
|
||||
(mu_runtime_path(MU_RUNTIME_PATH_BOOKMARKS));
|
||||
|
||||
g_signal_connect (G_OBJECT (data->shortcuts), "clicked",
|
||||
G_CALLBACK (on_shortcut_clicked), data);
|
||||
|
||||
return data->shortcuts;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
mug_statusbar (void)
|
||||
{
|
||||
GtkWidget *statusbar;
|
||||
|
||||
statusbar = gtk_statusbar_new ();
|
||||
|
||||
return statusbar;
|
||||
}
|
||||
|
||||
static void
|
||||
on_query_changed (MugQueryBar * bar, const char *query, MugData * mugdata)
|
||||
{
|
||||
int count;
|
||||
|
||||
/* clear the old message */
|
||||
mug_msg_view_set_msg (MUG_MSG_VIEW (mugdata->msgview), NULL);
|
||||
|
||||
count = mug_msg_list_view_query (MUG_MSG_LIST_VIEW (mugdata->mlist),
|
||||
query);
|
||||
if (count >= 0) {
|
||||
gchar *msg =
|
||||
g_strdup_printf ("%d message%s found matching '%s'",
|
||||
count,
|
||||
count > 1 ? "s" : "",
|
||||
mug_msg_list_view_get_query
|
||||
(MUG_MSG_LIST_VIEW (mugdata->mlist)));
|
||||
gtk_statusbar_push (GTK_STATUSBAR (mugdata->statusbar), 0, msg);
|
||||
g_free (msg);
|
||||
|
||||
mug_msg_list_view_move_first (MUG_MSG_LIST_VIEW
|
||||
(mugdata->mlist));
|
||||
gtk_widget_grab_focus (GTK_WIDGET (mugdata->mlist));
|
||||
}
|
||||
|
||||
if (count == 0) /* nothing found */
|
||||
mug_query_bar_grab_focus (MUG_QUERY_BAR (bar));
|
||||
}
|
||||
|
||||
static void
|
||||
on_msg_selected (MugMsgListView * mlist, const char *mpath, MugData * mugdata)
|
||||
{
|
||||
mug_msg_view_set_msg (MUG_MSG_VIEW (mugdata->msgview), mpath);
|
||||
}
|
||||
|
||||
static void
|
||||
on_list_view_error (MugMsgListView * mlist, MugError err, MugData * mugdata)
|
||||
{
|
||||
GtkWidget *errdialog;
|
||||
const char *msg;
|
||||
|
||||
switch (err) {
|
||||
case MUG_ERROR_XAPIAN_NOT_UPTODATE:
|
||||
msg = "The Xapian Database has the wrong version\n"
|
||||
"Please run 'mu index --rebuild'";
|
||||
break;
|
||||
case MUG_ERROR_XAPIAN_DIR:
|
||||
msg = "Cannot find the Xapian database dir\n"
|
||||
"Please restart mug with --muhome=... pointing\n"
|
||||
"to your mu home directory";
|
||||
break;
|
||||
case MUG_ERROR_QUERY:
|
||||
msg = "Error in query";
|
||||
break;
|
||||
default:
|
||||
msg = "Some error occured";
|
||||
break;
|
||||
}
|
||||
|
||||
errdialog = gtk_message_dialog_new
|
||||
(GTK_WINDOW (mugdata->win), GTK_DIALOG_MODAL,
|
||||
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", msg);
|
||||
|
||||
gtk_dialog_run (GTK_DIALOG (errdialog));
|
||||
gtk_widget_destroy (errdialog);
|
||||
|
||||
if (err == MUG_ERROR_QUERY)
|
||||
mug_query_bar_grab_focus (MUG_QUERY_BAR (mugdata->querybar));
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
mug_querybar (void)
|
||||
{
|
||||
GtkWidget *querybar;
|
||||
|
||||
querybar = mug_query_bar_new ();
|
||||
|
||||
return querybar;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
mug_query_area (MugData * mugdata)
|
||||
{
|
||||
GtkWidget *queryarea, *paned, *scrolled;
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
queryarea = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
||||
paned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
|
||||
#else
|
||||
queryarea = gtk_vbox_new (FALSE, 2);
|
||||
paned = gtk_vpaned_new ();
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
|
||||
mugdata->mlist = mug_msg_list_view_new
|
||||
(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB));
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), mugdata->mlist);
|
||||
gtk_paned_add1 (GTK_PANED (paned), scrolled);
|
||||
|
||||
mugdata->msgview = mug_msg_view_new ();
|
||||
mug_msg_view_set_note (MUG_MSG_VIEW(mugdata->msgview),
|
||||
"<h1>Welcome to <i>mug</i>!</h1><hr>"
|
||||
"<tt>mug</tt> is an experimental UI for <tt>mu</tt>, which will "
|
||||
"slowly evolve into something useful.<br><br>Enjoy the ride.");
|
||||
g_signal_connect (G_OBJECT (mugdata->mlist), "msg-selected",
|
||||
G_CALLBACK (on_msg_selected), mugdata);
|
||||
g_signal_connect (G_OBJECT (mugdata->mlist), "error-occured",
|
||||
G_CALLBACK (on_list_view_error), mugdata);
|
||||
gtk_paned_add2 (GTK_PANED (paned), mugdata->msgview);
|
||||
|
||||
mugdata->querybar = mug_querybar ();
|
||||
g_signal_connect (G_OBJECT (mugdata->querybar), "query-changed",
|
||||
G_CALLBACK (on_query_changed), mugdata);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (queryarea),
|
||||
mugdata->querybar, FALSE, FALSE, 2);
|
||||
gtk_box_pack_start (GTK_BOX (queryarea), paned, TRUE, TRUE, 2);
|
||||
|
||||
gtk_widget_show_all (queryarea);
|
||||
return queryarea;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
mug_main_area (MugData * mugdata)
|
||||
{
|
||||
GtkWidget *mainarea, *w;
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
mainarea = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
||||
#else
|
||||
mainarea = gtk_hbox_new (FALSE, 5);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
w = mug_shortcuts_bar (mugdata);
|
||||
gtk_box_pack_start (GTK_BOX (mainarea), w, FALSE, FALSE, 0);
|
||||
gtk_widget_show (w);
|
||||
|
||||
w = mug_query_area (mugdata);
|
||||
gtk_box_pack_start (GTK_BOX (mainarea), w, TRUE, TRUE, 0);
|
||||
gtk_widget_show (w);
|
||||
|
||||
return mainarea;
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
mug_shell (MugData * mugdata)
|
||||
{
|
||||
GtkWidget *vbox;
|
||||
|
||||
mugdata->win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title (GTK_WINDOW (mugdata->win), "Mug Mail Search");
|
||||
|
||||
#ifdef HAVE_GTK3
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
||||
#else
|
||||
vbox = gtk_vbox_new (FALSE, 2);
|
||||
#endif /*!HAVE_GTK3*/
|
||||
|
||||
mugdata->toolbar = mug_toolbar (mugdata);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), mugdata->toolbar, FALSE, FALSE, 2);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), mug_main_area (mugdata), TRUE,
|
||||
TRUE, 2);
|
||||
|
||||
mugdata->statusbar = mug_statusbar ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), mugdata->statusbar, FALSE, FALSE,
|
||||
2);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (mugdata->win), vbox);
|
||||
gtk_widget_show_all (vbox);
|
||||
|
||||
gtk_window_set_default_size (GTK_WINDOW (mugdata->win), 700, 500);
|
||||
gtk_window_set_resizable (GTK_WINDOW (mugdata->win), TRUE);
|
||||
|
||||
{
|
||||
gchar *icon;
|
||||
icon = g_strdup_printf ("%s%cmug.svg",
|
||||
MUG2DIR, G_DIR_SEPARATOR);
|
||||
gtk_window_set_icon_from_file (GTK_WINDOW (mugdata->win), icon, NULL);
|
||||
g_free (icon);
|
||||
}
|
||||
|
||||
return mugdata->win;
|
||||
}
|
||||
|
||||
static gint
|
||||
on_focus_query_bar (GtkWidget* ignored, GdkEventKey *event, MugData* mugdata)
|
||||
{
|
||||
if (event->type==GDK_KEY_RELEASE && event->keyval==GDK_KEY_Escape) {
|
||||
mug_query_bar_grab_focus (MUG_QUERY_BAR (mugdata->querybar));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
MugData mugdata;
|
||||
GtkWidget *mugshell;
|
||||
GOptionContext *octx;
|
||||
GOptionEntry entries[] = {
|
||||
{"muhome", 0, 0, G_OPTION_ARG_FILENAME, &mugdata.muhome,
|
||||
"specify an alternative mu directory", NULL},
|
||||
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
octx = g_option_context_new ("- mug options");
|
||||
g_option_context_add_main_entries (octx, entries, "Mug");
|
||||
|
||||
memset (&mugdata, 0, sizeof (MugData));
|
||||
if (!g_option_context_parse (octx, &argc, &argv, NULL)) {
|
||||
g_option_context_free (octx);
|
||||
g_printerr ("mug: error in options\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_option_context_free (octx);
|
||||
mu_runtime_init (mugdata.muhome, "mug2");
|
||||
|
||||
mugshell = mug_shell (&mugdata);
|
||||
g_signal_connect (G_OBJECT (mugshell), "destroy",
|
||||
G_CALLBACK (gtk_main_quit), NULL);
|
||||
g_signal_connect (G_OBJECT (mugshell), "key_release_event",
|
||||
G_CALLBACK ( on_focus_query_bar ), (gpointer)&mugdata );
|
||||
|
||||
gtk_widget_show (mugshell);
|
||||
mug_query_bar_grab_focus (MUG_QUERY_BAR (mugdata.querybar));
|
||||
|
||||
gtk_main ();
|
||||
g_free (mugdata.muhome);
|
||||
|
||||
mu_runtime_uninit ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user