diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2012-03-11 14:40:18 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2012-03-11 14:40:18 -0700 |
commit | 18765430261248d35ad6443f1af2f82c45fb1349 (patch) | |
tree | 9cdb5d721a4b37312106c68596edc6d8d7f91f6d /src | |
parent | 6ca9391d0a727afac01ad07fa5335eda3f19060b (diff) |
Begin EvbpViewer widget
Start building up a widget object, EvbpViewer, again. Once we're doing
anything more complicated than just putting an EvView in a scrolled
window, it'll help to keep most of it in it's own widget. The widget
subclasses GtkBox so we can just put a toolbar and scrolled window in.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/evbp-viewer.c | 93 | ||||
-rw-r--r-- | src/evbp-viewer.h | 66 | ||||
-rw-r--r-- | src/evbp.c | 35 |
4 files changed, 170 insertions, 27 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ff75495..1353106 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,4 +4,5 @@ plugindir = $(libdir)/mozilla/plugins plugin_LTLIBRARIES = libevbp.la libevbp_la_LDFLAGS = -avoid-version -module libevbp_la_LIBADD = $(EVINCE_LIBS) -libevbp_la_SOURCES = evbp.c evbp-mime.h evbp-mime.c +libevbp_la_SOURCES = evbp.c evbp-viewer.h evbp-viewer.c evbp-mime.h \ + evbp-mime.c diff --git a/src/evbp-viewer.c b/src/evbp-viewer.c new file mode 100644 index 0000000..4e66c01 --- /dev/null +++ b/src/evbp-viewer.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2012 Dan Nicholson <dbn.lists@gmail.com> + * + * 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 2 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 <config.h> +#include "evbp-viewer.h" +#include <gtk/gtk.h> + +G_DEFINE_TYPE(EvbpViewer, evbp_viewer, GTK_TYPE_BOX) + +static void +evbp_viewer_dispose(GObject *object) +{ + EvbpViewer *viewer = EVBP_VIEWER(object); + + if (viewer->document) { + g_object_unref(viewer->document); + viewer->document = NULL; + } + if (viewer->model) { + g_object_unref(viewer->model); + viewer->model = NULL; + } + + G_OBJECT_CLASS(evbp_viewer_parent_class)->dispose(object); +} + +static void +evbp_viewer_class_init(EvbpViewerClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS(class); + + object_class->dispose = evbp_viewer_dispose; +} + +static void +evbp_viewer_init(EvbpViewer *viewer) +{ + gtk_orientable_set_orientation(GTK_ORIENTABLE(viewer), + GTK_ORIENTATION_VERTICAL); + + viewer->model = ev_document_model_new(); + viewer->scroll = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(viewer->scroll), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_widget_show(viewer->scroll); + + viewer->view = ev_view_new(); + ev_view_set_model(EV_VIEW(viewer->view), viewer->model); + ev_view_set_loading(EV_VIEW(viewer->view), TRUE); + gtk_widget_show(viewer->view); + + gtk_container_add(GTK_CONTAINER(viewer->scroll), viewer->view); + gtk_box_pack_end(GTK_BOX(viewer), viewer->scroll, TRUE, TRUE, 0); +} + +GtkWidget * +evbp_viewer_new(void) +{ + return g_object_new(EVBP_TYPE_VIEWER, NULL); +} + +gboolean +evbp_viewer_load_uri(EvbpViewer *viewer, const gchar *uri, GError **error) +{ + if (viewer->document) + g_object_unref(viewer->document); + + viewer->document = ev_document_factory_get_document(uri, error); + g_return_val_if_fail(viewer->document, FALSE); + + g_debug("loading document \"%s\"", uri); + ev_document_model_set_document(viewer->model, viewer->document); + ev_view_set_loading(EV_VIEW(viewer->view), FALSE); + + return TRUE; +} diff --git a/src/evbp-viewer.h b/src/evbp-viewer.h new file mode 100644 index 0000000..d0c5897 --- /dev/null +++ b/src/evbp-viewer.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2012 Dan Nicholson <dbn.lists@gmail.com> + * + * 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 2 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. + */ + +#ifndef _EVBP_MIME_H_ +#define _EVBP_VIEWER_H_ + +#include <glib-object.h> +#include <evince-document.h> +#include <evince-view.h> + +G_BEGIN_DECLS + +#define EVBP_TYPE_VIEWER \ + (evbp_viewer_get_type()) +#define EVBP_VIEWER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), EVBP_TYPE_VIEWER, EvbpViewer)) +#define EVBP_VIEWER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), EVBP_TYPE_VIEWER, EvbpViewerClass)) +#define EVBP_IS_VIEWER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), EVBP_TYPE_VIEWER)) +#define EVBP_IS_VIEWER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), EVBP_TYPE_VIEWER)) +#define EVBP_GET_VIEWER_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), EVBP_TYPE_VIEWER, EvbpViewerClass)) + +typedef struct _EvbpViewer EvbpViewer; +typedef struct _EvbpViewerClass EvbpViewerClass; + +struct _EvbpViewer { + GtkBox box; + + /* FIXME: should be in a private */ + EvDocument *document; + EvDocumentModel *model; + GtkWidget *scroll; + GtkWidget *view; +}; + +struct _EvbpViewerClass { + GtkBoxClass parent_class; +}; + +GType evbp_viewer_get_type(void) G_GNUC_CONST; +GtkWidget *evbp_viewer_new(void); +gboolean evbp_viewer_load_uri(EvbpViewer *viewer, const char *uri, + GError **error); + +G_END_DECLS + +#endif /* _EVBP_VIEWER_H_ */ @@ -18,6 +18,7 @@ */ #include <config.h> +#include "evbp-viewer.h" #include "evbp-mime.h" #include <stdlib.h> @@ -39,10 +40,7 @@ typedef struct evbp_priv { NPP npp; NPWindow *window; - EvDocument *document; - EvDocumentModel *model; - GtkWidget *scroll; - GtkWidget *view; + GtkWidget *viewer; } evbp_priv_t; static char *evbp_mime_string = NULL; @@ -146,29 +144,17 @@ evbp_new(NPMIMEType pluginType, NPP instance, uint16_t mode, priv->npp = instance; instance->pdata = priv; - /* create new previewer */ - priv->model = ev_document_model_new(); - priv->scroll = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(priv->scroll), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - priv->view = ev_view_new(); - ev_view_set_model(EV_VIEW(priv->view), priv->model); - ev_view_set_loading(EV_VIEW(priv->view), TRUE); - gtk_container_add(GTK_CONTAINER(priv->scroll), priv->view); + /* create new viewer */ + priv->viewer = evbp_viewer_new(); return NPERR_NO_ERROR; } static NPError -evbp_destroy(NPP instance, NPSavedData** save) +evbp_destroy(NPP instance, NPSavedData **save) { - evbp_priv_t *priv = instance->pdata; - g_debug("%s", __func__); - g_object_unref(priv->document); - g_object_unref(priv->model); npn_funcs->memfree(instance->pdata); instance->pdata = NULL; @@ -196,7 +182,7 @@ evbp_set_window(NPP instance, NPWindow *window) id = (GdkNativeWindow)(unsigned long)window->window; g_debug("plugging into window id %u", id); plug = gtk_plug_new(id); - gtk_container_add(GTK_CONTAINER(plug), priv->scroll); + gtk_container_add(GTK_CONTAINER(plug), priv->viewer); gtk_widget_show_all(plug); return NPERR_NO_ERROR; @@ -260,17 +246,14 @@ evbp_stream_as_file(NPP instance, NPStream *stream, const char *fname) uri = g_file_get_uri(file); g_object_unref(file); - /* create a new document */ - priv->document = ev_document_factory_get_document(uri, &error); - if (error) { + /* load the document */ + g_debug("loading document \"%s\"", uri); + if (!evbp_viewer_load_uri(EVBP_VIEWER(priv->viewer), uri, &error)) { g_warning("failed to load document \"%s\": %s\n", uri, error->message); g_error_free(error); return; } - g_debug("loading document \"%s\"", uri); - ev_document_model_set_document(priv->model, priv->document); - ev_view_set_loading(EV_VIEW(priv->view), FALSE); } static void |