summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-13 02:58:27 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-13 02:58:27 (EDT)
commit8a6b0aa358c5f3686a6cb26e50cbfb6e439fd7f8 (patch)
treec94dd7c1082d73d7e9ebb8ccbade0c4bda78b561 /src
parent980fefc173df2cd805f8fa7987d3544a34d2b342 (diff)
downloadmarquee-8a6b0aa358c5f3686a6cb26e50cbfb6e439fd7f8.zip
marquee-8a6b0aa358c5f3686a6cb26e50cbfb6e439fd7f8.tar.gz
marquee-8a6b0aa358c5f3686a6cb26e50cbfb6e439fd7f8.tar.bz2
MqHomeButton: New class
Diffstat (limited to 'src')
-rw-r--r--src/home-button.c158
-rw-r--r--src/home-button.h55
-rw-r--r--src/local.mk1
3 files changed, 214 insertions, 0 deletions
diff --git a/src/home-button.c b/src/home-button.c
new file mode 100644
index 0000000..ee46497
--- /dev/null
+++ b/src/home-button.c
@@ -0,0 +1,158 @@
+/*
+ * Home 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 "home-button.h"
+#include "config.h"
+#include "web-view.h"
+
+struct _MqHomeButton {
+ GtkToolButton parent_instance;
+ MqConfig *config;
+ MqWebView *web_view;
+ GtkWidget *stop_icon;
+ GtkWidget *reload_icon;
+};
+
+enum {
+ PROP_CONFIG = 1,
+ PROP_WEB_VIEW,
+ N_PROPERTIES
+};
+
+static GParamSpec *obj_properties[N_PROPERTIES] = {NULL,};
+
+struct _MqHomeButtonClass {
+ GtkToolButtonClass parent_class;
+};
+
+G_DEFINE_TYPE(MqHomeButton, mq_home_button, GTK_TYPE_TOOL_BUTTON)
+
+static void
+clicked_cb(MqHomeButton *home_button)
+{
+ const gchar *uri;
+
+ uri = mq_config_get_string(home_button->config, "tabs.home");
+
+ mq_web_view_load_uri(home_button->web_view, uri);
+}
+
+static void
+set_config(MqHomeButton *home_button, MqConfig *config)
+{
+ home_button->config = config;
+}
+
+static void
+set_web_view(MqHomeButton *home_button, MqWebView *web_view)
+{
+ home_button->web_view = web_view;
+}
+
+static void
+get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_CONFIG:
+ g_value_set_pointer(value, NULL);
+ break;
+ 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)
+{
+ MqHomeButton *home_button;
+
+ home_button = MQ_HOME_BUTTON(object);
+
+ switch (property_id) {
+ case PROP_CONFIG:
+ set_config(home_button, g_value_get_pointer(value));
+ break;
+ case PROP_WEB_VIEW:
+ set_web_view(home_button, g_value_get_object(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
+ pspec);
+ break;
+ }
+}
+
+static void
+mq_home_button_class_init(MqHomeButtonClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+
+ obj_properties[PROP_CONFIG] = g_param_spec_pointer(
+ "config",
+ "MqConfig",
+ "The application's MqConfig instance",
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
+ 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_home_button_init(MqHomeButton *home_button)
+{
+ gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(home_button),
+ gtk_image_new_from_icon_name("go-home",
+ GTK_ICON_SIZE_SMALL_TOOLBAR));
+ gtk_tool_button_set_label(GTK_TOOL_BUTTON(home_button), "Home");
+ gtk_widget_set_tooltip_text(GTK_WIDGET(home_button),
+ "Load the home page");
+ g_signal_connect(home_button, "clicked", G_CALLBACK(clicked_cb), NULL);
+}
+
+GtkToolItem *
+mq_home_button_new(MqConfig *config, MqWebView *web_view)
+{
+ return g_object_new(MQ_TYPE_HOME_BUTTON,
+ "config", config,
+ "web-view", web_view,
+ NULL);
+}
diff --git a/src/home-button.h b/src/home-button.h
new file mode 100644
index 0000000..b7356e0
--- /dev/null
+++ b/src/home-button.h
@@ -0,0 +1,55 @@
+/*
+ * Home 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 _MqHomeButton MqHomeButton;
+typedef struct _MqHomeButtonClass MqHomeButtonClass;
+
+#ifndef MQ_STOP_HOME_BUTTON_H
+#define MQ_STOP_HOME_BUTTON_H
+
+#include <gtk/gtk.h>
+
+#include "config.h"
+#include "web-view.h"
+
+G_BEGIN_DECLS
+
+#define MQ_TYPE_HOME_BUTTON (mq_home_button_get_type())
+#define MQ_HOME_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ MQ_TYPE_HOME_BUTTON, MqHomeButton))
+#define MQ_IS_HOME_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ MQ_TYPE_HOME_BUTTON))
+#define MQ_HOME_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
+ MQ_TYPE_HOME_BUTTON, MqHomeButtonClass))
+#define MQ_IS_HOME_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE( (klass), \
+ MQ_TYPE_HOME_BUTTON))
+#define MQ_HOME_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ MQ_TYPE_HOME_BUTTON, MqHomeButtonClass))
+
+GType
+mq_home_button_get_type(void);
+
+GtkToolItem *
+mq_home_button_new(MqConfig *config, MqWebView *web_view);
+
+G_END_DECLS
+
+#endif /* MQ_STOP_HOME_BUTTON_H */
diff --git a/src/local.mk b/src/local.mk
index 998c669..6573473 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -9,6 +9,7 @@ marquee_SOURCES += \
%reldir%/back-forward-button-box.c \
%reldir%/stop-reload-button.c \
%reldir%/uri-entry.c \
+ %reldir%/home-button.c \
%reldir%/main-menu.c \
%reldir%/find-toolbar.c \
%reldir%/web-view.c \