* start working on some mu-based widgets (widgets/), create toys2/mug2 for testing
This commit is contained in:
43
widgets/Makefile.am
Normal file
43
widgets/Makefile.am
Normal file
@ -0,0 +1,43 @@
|
||||
## 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
|
||||
## 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}/src $(GTK_CFLAGS) $(WEBKIT_CFLAGS) -DICONDIR='"$(icondir)"' \
|
||||
-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_LTLIBRARIES= \
|
||||
libmuwidgets.la
|
||||
|
||||
libmuwidgets_la_SOURCES= \
|
||||
mu-msg-body-view.c \
|
||||
mu-msg-body-view.h \
|
||||
mu-msg-view.h \
|
||||
mu-msg-view.c
|
||||
|
||||
libmuwidgets_la_LIBADD= \
|
||||
${top_builddir}/src/libmu.la \
|
||||
${GTK_LIBS} \
|
||||
${WEBKIT_LIBS}
|
||||
|
||||
128
widgets/mu-msg-body-view.c
Normal file
128
widgets/mu-msg-body-view.c
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
** 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 "mu-msg-body-view.h"
|
||||
|
||||
/* include other impl specific header files */
|
||||
|
||||
/* '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 {
|
||||
/* MY_SIGNAL_1, */
|
||||
/* MY_SIGNAL_2, */
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
struct _MuMsgBodyViewPrivate {
|
||||
WebKitWebSettings *_settings;
|
||||
};
|
||||
#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;
|
||||
|
||||
/* uncomment the following if you have defined any signals */
|
||||
/* static guint signals[LAST_SIGNAL] = {0}; */
|
||||
|
||||
G_DEFINE_TYPE (MuMsgBodyView, mu_msg_body_view, WEBKIT_TYPE_WEB_VIEW);
|
||||
|
||||
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));
|
||||
|
||||
/* 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_body_view_init (MuMsgBodyView *obj)
|
||||
{
|
||||
obj->_priv = MU_MSG_BODY_VIEW_GET_PRIVATE(obj);
|
||||
|
||||
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);
|
||||
/* other settings */
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
mu_msg_body_view_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",
|
||||
"");
|
||||
}
|
||||
|
||||
void
|
||||
mu_msg_body_view_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",
|
||||
"");
|
||||
}
|
||||
66
widgets/mu-msg-body-view.h
Normal file
66
widgets/mu-msg-body-view.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
** 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>
|
||||
|
||||
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;
|
||||
/* insert signal callback declarations, e.g. */
|
||||
/* void (* my_event) (MuMsgBodyView* obj); */
|
||||
};
|
||||
|
||||
/* 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_html (MuMsgBodyView *self, const char* html);
|
||||
void mu_msg_body_view_set_text (MuMsgBodyView *self, const char* html);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MU_MSG_BODY_VIEW_H__ */
|
||||
|
||||
122
widgets/mu-msg-view.c
Normal file
122
widgets/mu-msg-view.c
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
** 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-view.h"
|
||||
#include "mu-msg-body-view.h"
|
||||
#include "mu-msg.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 *_body;
|
||||
};
|
||||
#define MU_MSG_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MU_TYPE_MSG_VIEW, \
|
||||
MuMsgViewPrivate))
|
||||
/* globals */
|
||||
static GtkVBoxClass *parent_class = NULL;
|
||||
|
||||
/* uncomment the following if you have defined any signals */
|
||||
/* static guint signals[LAST_SIGNAL] = {0}; */
|
||||
|
||||
G_DEFINE_TYPE (MuMsgView, mu_msg_view, GTK_TYPE_VBOX);
|
||||
|
||||
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
|
||||
mu_msg_view_init (MuMsgView *obj)
|
||||
{
|
||||
GtkWidget *scrolledwin;
|
||||
|
||||
obj->_priv = MU_MSG_VIEW_GET_PRIVATE(obj);
|
||||
|
||||
obj->_priv->_body = mu_msg_body_view_new ();
|
||||
scrolledwin = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_container_add (GTK_CONTAINER(scrolledwin),
|
||||
obj->_priv->_body);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX(obj), scrolledwin,
|
||||
TRUE, TRUE, 2);
|
||||
|
||||
/* to init any of the private data, do e.g: */
|
||||
/* obj->_priv->_frobnicate_mode = FALSE; */
|
||||
}
|
||||
|
||||
static void
|
||||
mu_msg_view_finalize (GObject *obj)
|
||||
{
|
||||
/* free/unref instance resources here */
|
||||
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)
|
||||
{
|
||||
const char *data;
|
||||
|
||||
g_return_if_fail (MU_IS_MSG_VIEW(self));
|
||||
|
||||
if (!msg) { /* clear */
|
||||
mu_msg_body_view_set_text
|
||||
(MU_MSG_BODY_VIEW(self->_priv->_body),"");
|
||||
return;
|
||||
}
|
||||
|
||||
data = mu_msg_get_body_html (msg);
|
||||
if (data)
|
||||
mu_msg_body_view_set_html (MU_MSG_BODY_VIEW(self->_priv->_body),
|
||||
data);
|
||||
else
|
||||
mu_msg_body_view_set_text (MU_MSG_BODY_VIEW(self->_priv->_body),
|
||||
mu_msg_get_body_text (msg));
|
||||
}
|
||||
|
||||
66
widgets/mu-msg-view.h
Normal file
66
widgets/mu-msg-view.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
** 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>
|
||||
|
||||
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 {
|
||||
GtkVBox parent;
|
||||
/* insert public members, if any */
|
||||
|
||||
/* private */
|
||||
MuMsgViewPrivate *_priv;
|
||||
};
|
||||
|
||||
struct _MuMsgViewClass {
|
||||
GtkVBoxClass parent_class;
|
||||
/* insert signal callback declarations, e.g. */
|
||||
/* 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);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MU_MSG_VIEW_H__ */
|
||||
|
||||
Reference in New Issue
Block a user