summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-13 02:33:32 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-13 02:33:32 (EDT)
commit3d395133aeed47b08c6f8baecb71c64b2ffa173d (patch)
tree91f903f9290731ce13526b81f474eb9f447f1c01 /src
parentc55c0d12887d1aec9d4c1e2d2fd34c2a86a7696a (diff)
downloadmarquee-3d395133aeed47b08c6f8baecb71c64b2ffa173d.zip
marquee-3d395133aeed47b08c6f8baecb71c64b2ffa173d.tar.gz
marquee-3d395133aeed47b08c6f8baecb71c64b2ffa173d.tar.bz2
MqStopReloadButton: New class
Diffstat (limited to 'src')
-rw-r--r--src/local.mk1
-rw-r--r--src/stop-reload-button.c176
-rw-r--r--src/stop-reload-button.h60
3 files changed, 237 insertions, 0 deletions
diff --git a/src/local.mk b/src/local.mk
index 172be5c..998c669 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -7,6 +7,7 @@ marquee_SOURCES += \
%reldir%/tab.c \
%reldir%/tab-chrome.c \
%reldir%/back-forward-button-box.c \
+ %reldir%/stop-reload-button.c \
%reldir%/uri-entry.c \
%reldir%/main-menu.c \
%reldir%/find-toolbar.c \
diff --git a/src/stop-reload-button.c b/src/stop-reload-button.c
new file mode 100644
index 0000000..a55f571
--- /dev/null
+++ b/src/stop-reload-button.c
@@ -0,0 +1,176 @@
+/*
+ * Stop/reload button
+ *
+ * Copyright (C) 2017 Patrick McDermott
+ *
+ * This file is part of Marquee.
+ *
+ * Marquee 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
+ * (at your option) any later version.
+ *
+ * Marquee 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 Marquee. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+
+#include "stop-reload-button.h"
+#include "web-view.h"
+
+struct _MqStopReloadButton {
+ GtkToolButton parent_instance;
+ GtkWidget *stop_icon;
+ GtkWidget *reload_icon;
+ MqWebView *web_view;
+};
+
+enum {
+ PROP_WEB_VIEW = 1,
+ N_PROPERTIES
+};
+
+static GParamSpec *obj_properties[N_PROPERTIES] = {NULL,};
+
+struct _MqStopReloadButtonClass {
+ GtkToolButtonClass parent_class;
+};
+
+G_DEFINE_TYPE(MqStopReloadButton, mq_stop_reload_button, GTK_TYPE_TOOL_BUTTON)
+
+static void
+loading_cb(MqWebView *web_view, GParamSpec G_GNUC_UNUSED *paramspec,
+ MqStopReloadButton *stop_reload_button)
+{
+ if (webkit_web_view_is_loading(WEBKIT_WEB_VIEW(web_view))) {
+ gtk_tool_button_set_icon_widget(
+ GTK_TOOL_BUTTON(stop_reload_button),
+ stop_reload_button->stop_icon);
+ gtk_tool_button_set_label(
+ GTK_TOOL_BUTTON(stop_reload_button), "Stop");
+ gtk_widget_set_tooltip_text(
+ GTK_WIDGET(stop_reload_button),
+ "Stop loading the current page");
+ } else {
+ gtk_tool_button_set_icon_widget(
+ GTK_TOOL_BUTTON(stop_reload_button),
+ stop_reload_button->reload_icon);
+ gtk_tool_button_set_label(
+ GTK_TOOL_BUTTON(stop_reload_button), "Reload");
+ gtk_widget_set_tooltip_text(
+ GTK_WIDGET(stop_reload_button),
+ "Reload the current page");
+ }
+ gtk_widget_show_all(GTK_WIDGET(stop_reload_button));
+}
+
+static void
+clicked_cb(MqStopReloadButton *stop_reload_button)
+{
+ WebKitWebView *web_view;
+
+ web_view = WEBKIT_WEB_VIEW(stop_reload_button->web_view);
+
+ if (webkit_web_view_is_loading(web_view)) {
+ webkit_web_view_stop_loading(web_view);
+ } else {
+ webkit_web_view_reload(web_view);
+ }
+}
+
+static void
+set_web_view(MqStopReloadButton *stop_reload_button, MqWebView *web_view)
+{
+ stop_reload_button->web_view = web_view;
+
+ g_signal_connect(web_view, "notify::is-loading",
+ G_CALLBACK(loading_cb), stop_reload_button);
+}
+
+static void
+get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_WEB_VIEW:
+ g_value_set_object(value, NULL);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
+ pspec);
+ break;
+ }
+}
+
+static void
+set_property(GObject *object, guint property_id, const GValue *value,
+ GParamSpec *pspec)
+{
+ MqStopReloadButton *stop_reload_button;
+
+ stop_reload_button = MQ_STOP_RELOAD_BUTTON(object);
+
+ switch (property_id) {
+ case PROP_WEB_VIEW:
+ set_web_view(stop_reload_button,
+ g_value_get_object(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
+ pspec);
+ break;
+ }
+}
+
+static void
+mq_stop_reload_button_class_init(MqStopReloadButtonClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+
+ obj_properties[PROP_WEB_VIEW] = g_param_spec_object(
+ "web-view",
+ "MqWebView",
+ "The associated MqWebView instance",
+ MQ_TYPE_WEB_VIEW,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
+ g_object_class_install_properties(object_class, N_PROPERTIES,
+ obj_properties);
+}
+
+static void
+mq_stop_reload_button_init(MqStopReloadButton *stop_reload_button)
+{
+ stop_reload_button->stop_icon = gtk_image_new_from_icon_name(
+ "process-stop", GTK_ICON_SIZE_SMALL_TOOLBAR);
+ g_object_ref_sink(stop_reload_button->stop_icon);
+ stop_reload_button->reload_icon = gtk_image_new_from_icon_name(
+ "view-refresh", GTK_ICON_SIZE_SMALL_TOOLBAR);
+ g_object_ref_sink(stop_reload_button->reload_icon);
+ gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(stop_reload_button),
+ stop_reload_button->stop_icon);
+ gtk_tool_button_set_label(GTK_TOOL_BUTTON(stop_reload_button), "Stop");
+ gtk_widget_set_tooltip_text(GTK_WIDGET(stop_reload_button),
+ "Stop loading the current page");
+ g_signal_connect(stop_reload_button, "clicked",
+ G_CALLBACK(clicked_cb), NULL);
+}
+
+GtkToolItem *
+mq_stop_reload_button_new(MqWebView *web_view)
+{
+ return g_object_new(MQ_TYPE_STOP_RELOAD_BUTTON,
+ "web-view", web_view,
+ NULL);
+}
diff --git a/src/stop-reload-button.h b/src/stop-reload-button.h
new file mode 100644
index 0000000..3d76340
--- /dev/null
+++ b/src/stop-reload-button.h
@@ -0,0 +1,60 @@
+/*
+ * Stop/reload button
+ *
+ * Copyright (C) 2017 Patrick McDermott
+ *
+ * This file is part of Marquee.
+ *
+ * Marquee 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
+ * (at your option) any later version.
+ *
+ * Marquee 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 Marquee. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+typedef struct _MqStopReloadButton MqStopReloadButton;
+typedef struct _MqStopReloadButtonClass MqStopReloadButtonClass;
+
+#ifndef MQ_STOP_RELOAD_BUTTON_H
+#define MQ_STOP_RELOAD_BUTTON_H
+
+#include <gtk/gtk.h>
+
+#include "tab.h"
+#include "find-toolbar.h"
+#include "web-view.h"
+
+G_BEGIN_DECLS
+
+#define MQ_TYPE_STOP_RELOAD_BUTTON \
+ (mq_stop_reload_button_get_type())
+#define MQ_STOP_RELOAD_BUTTON(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), MQ_TYPE_STOP_RELOAD_BUTTON, \
+ MqStopReloadButton))
+#define MQ_IS_STOP_RELOAD_BUTTON(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), MQ_TYPE_STOP_RELOAD_BUTTON))
+#define MQ_STOP_RELOAD_BUTTON_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), MQ_TYPE_STOP_RELOAD_BUTTON, \
+ MqStopReloadButtonClass))
+#define MQ_IS_STOP_RELOAD_BUTTON_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE( (klass), MQ_TYPE_STOP_RELOAD_BUTTON))
+#define MQ_STOP_RELOAD_BUTTON_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), MQ_TYPE_STOP_RELOAD_BUTTON, \
+ MqStopReloadButtonClass))
+
+GType
+mq_stop_reload_button_get_type(void);
+
+GtkToolItem *
+mq_stop_reload_button_new(MqWebView *web_view);
+
+G_END_DECLS
+
+#endif /* MQ_STOP_RELOAD_BUTTON_H */