[epiphany] title-box: Implement EphyTitleWidget
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] title-box: Implement EphyTitleWidget
- Date: Thu, 22 Sep 2016 05:02:30 +0000 (UTC)
commit 102706f740eae0b415369de94c09a97b598055f0
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Tue Sep 20 22:59:25 2016 -0500
title-box: Implement EphyTitleWidget
lib/widgets/ephy-title-box.c | 165 ++++++++++++++++++++++++++++++----------
lib/widgets/ephy-title-box.h | 7 +--
src/ephy-location-controller.c | 3 +-
src/ephy-shell.c | 3 +-
src/ephy-window.c | 3 +-
5 files changed, 130 insertions(+), 51 deletions(-)
---
diff --git a/lib/widgets/ephy-title-box.c b/lib/widgets/ephy-title-box.c
index 135dcf4..96879a7 100644
--- a/lib/widgets/ephy-title-box.c
+++ b/lib/widgets/ephy-title-box.c
@@ -20,6 +20,16 @@
#include "config.h"
#include "ephy-title-box.h"
+#include "ephy-lib-type-builtins.h"
+#include "ephy-title-widget.h"
+
+enum {
+ PROP_0,
+ PROP_ADDRESS,
+ PROP_SECURITY_LEVEL,
+ LAST_PROP
+};
+
enum {
LOCK_CLICKED,
LAST_SIGNAL
@@ -33,9 +43,15 @@ struct _EphyTitleBox {
GtkWidget *lock_image;
GtkWidget *title;
GtkWidget *subtitle;
+
+ EphySecurityLevel security_level;
};
-G_DEFINE_TYPE (EphyTitleBox, ephy_title_box, GTK_TYPE_EVENT_BOX)
+static void ephy_title_box_title_widget_interface_init (EphyTitleWidgetInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (EphyTitleBox, ephy_title_box, GTK_TYPE_EVENT_BOX,
+ G_IMPLEMENT_INTERFACE (EPHY_TYPE_TITLE_WIDGET,
+ ephy_title_box_title_widget_interface_init))
static gboolean
ephy_title_box_button_press_event (GtkWidget *widget,
@@ -117,6 +133,107 @@ ephy_title_box_get_preferred_width (GtkWidget *widget,
*natural_width = 860;
}
+static const char *
+ephy_title_box_title_widget_get_address (EphyTitleWidget *widget)
+{
+ EphyTitleBox *title_box = EPHY_TITLE_BOX (widget);
+
+ g_return_val_if_fail (title_box, NULL);
+
+ return gtk_label_get_text (GTK_LABEL (title_box->subtitle));
+}
+
+static void
+ephy_title_box_title_widget_set_address (EphyTitleWidget *widget,
+ const char *address)
+{
+ EphyTitleBox *title_box = EPHY_TITLE_BOX (widget);
+
+ g_return_if_fail (title_box);
+
+ if (address && *address)
+ gtk_label_set_text (GTK_LABEL (title_box->subtitle), address);
+}
+
+static EphySecurityLevel
+ephy_title_box_title_widget_get_security_level (EphyTitleWidget *widget)
+{
+ EphyTitleBox *title_box = EPHY_TITLE_BOX (widget);
+
+ g_return_val_if_fail (title_box, EPHY_SECURITY_LEVEL_TO_BE_DETERMINED);
+
+ return title_box->security_level;
+}
+
+static void
+ephy_title_box_title_widget_set_security_level (EphyTitleWidget *widget,
+ EphySecurityLevel security_level)
+{
+ EphyTitleBox *title_box = EPHY_TITLE_BOX (widget);
+ const char *icon_name;
+
+ g_return_if_fail (title_box);
+
+ icon_name = ephy_security_level_to_icon_name (security_level);
+
+ g_object_set (title_box->lock_image,
+ "icon-name", icon_name,
+ NULL);
+
+ gtk_widget_set_visible (title_box->lock_image, icon_name != NULL);
+
+ title_box->security_level = security_level;
+}
+
+static void
+ephy_title_box_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyTitleWidget *widget = EPHY_TITLE_WIDGET (object);
+
+ switch (prop_id) {
+ case PROP_ADDRESS:
+ ephy_title_widget_set_address (widget, g_value_get_string (value));
+ break;
+ case PROP_SECURITY_LEVEL:
+ ephy_title_widget_set_security_level (widget, g_value_get_enum (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_title_box_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyTitleWidget *widget = EPHY_TITLE_WIDGET (object);
+
+ switch (prop_id) {
+ case PROP_ADDRESS:
+ g_value_set_string (value, ephy_title_widget_get_address (widget));
+ break;
+ case PROP_SECURITY_LEVEL:
+ g_value_set_enum (value, ephy_title_widget_get_security_level (widget));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_title_box_title_widget_interface_init (EphyTitleWidgetInterface *iface)
+{
+ iface->get_address = ephy_title_box_title_widget_get_address;
+ iface->set_address = ephy_title_box_title_widget_set_address;
+ iface->get_security_level = ephy_title_box_title_widget_get_security_level;
+ iface->set_security_level = ephy_title_box_title_widget_set_security_level;
+}
+
static void
ephy_title_box_class_init (EphyTitleBoxClass *klass)
{
@@ -124,9 +241,14 @@ ephy_title_box_class_init (EphyTitleBoxClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = ephy_title_box_constructed;
+ object_class->get_property = ephy_title_box_get_property;
+ object_class->set_property = ephy_title_box_set_property;
widget_class->button_press_event = ephy_title_box_button_press_event;
widget_class->get_preferred_width = ephy_title_box_get_preferred_width;
+ g_object_class_override_property (object_class, PROP_ADDRESS, "address");
+ g_object_class_override_property (object_class, PROP_SECURITY_LEVEL, "security-level");
+
/**
* EphyTitleBox::lock-clicked:
* @title_box: the object on which the signal is emitted
@@ -163,44 +285,3 @@ ephy_title_box_new (void)
"valign", GTK_ALIGN_CENTER,
NULL);
}
-
-/**
- * ephy_title_box_set_security_level:
- * @title_box: an #EphyTitleBox
- * @mode: an #EphySecurityLevel
- *
- * Sets the lock icon to be displayed by the title box and location entry
- **/
-void
-ephy_title_box_set_security_level (EphyTitleBox *title_box,
- EphySecurityLevel security_level)
-{
- const char *icon_name;
-
- g_return_if_fail (EPHY_IS_TITLE_BOX (title_box));
-
- icon_name = ephy_security_level_to_icon_name (security_level);
-
- g_object_set (title_box->lock_image,
- "icon-name", icon_name,
- NULL);
-
- gtk_widget_set_visible (title_box->lock_image, icon_name != NULL);
-}
-
-/**
- * ephy_title_box_set_address:
- * @title_box: an #EphyTitleBox
- * @address: (nullable): the URI to use for the subtitle of this #EphyTitleBox
- *
- * Sets the address of @title_box to @address
- */
-void
-ephy_title_box_set_address (EphyTitleBox *title_box,
- const char *address)
-{
- g_return_if_fail (EPHY_IS_TITLE_BOX (title_box));
-
- if (address && *address)
- gtk_label_set_text (GTK_LABEL (title_box->subtitle), address);
-}
diff --git a/lib/widgets/ephy-title-box.h b/lib/widgets/ephy-title-box.h
index a74e570..7067333 100644
--- a/lib/widgets/ephy-title-box.h
+++ b/lib/widgets/ephy-title-box.h
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Copyright © 2013, 2014 Yosef Or Boczko <yoseforb gnome org>
+ * Copyright © 2016 Igalia S.L.
*
* 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
@@ -31,10 +32,4 @@ G_DECLARE_FINAL_TYPE (EphyTitleBox, ephy_title_box, EPHY, TITLE_BOX, GtkEventBox
EphyTitleBox *ephy_title_box_new (void);
-void ephy_title_box_set_security_level (EphyTitleBox *title_box,
- EphySecurityLevel security_level);
-
-void ephy_title_box_set_address (EphyTitleBox *title_box,
- const char *address);
-
G_END_DECLS
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index 98c4c10..5fd0096 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -30,6 +30,7 @@
#include "ephy-location-entry.h"
#include "ephy-shell.h"
#include "ephy-title-box.h"
+#include "ephy-title-widget.h"
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
@@ -274,7 +275,7 @@ sync_address (EphyLocationController *controller,
g_signal_handlers_block_by_func (widget, G_CALLBACK (user_changed_cb), controller);
ephy_location_entry_set_location (lentry, controller->address);
- ephy_title_box_set_address (controller->title_box, controller->address);
+ ephy_title_widget_set_address (EPHY_TITLE_WIDGET (controller->title_box), controller->address);
g_signal_handlers_unblock_by_func (widget, G_CALLBACK (user_changed_cb), controller);
}
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 65fab1b..8695539 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -37,6 +37,7 @@
#include "ephy-session.h"
#include "ephy-settings.h"
#include "ephy-title-box.h"
+#include "ephy-title-widget.h"
#include "ephy-type-builtins.h"
#include "ephy-web-view.h"
#include "ephy-window.h"
@@ -1018,7 +1019,7 @@ ephy_shell_open_uris_idle (OpenURIsData *data)
header_bar = EPHY_HEADER_BAR (ephy_window_get_header_bar (data->window));
title_box = ephy_header_bar_get_title_box (header_bar);
- ephy_title_box_set_address (title_box, url);
+ ephy_title_widget_set_address (EPHY_TITLE_WIDGET (title_box), url);
}
data->current_uri++;
diff --git a/src/ephy-window.c b/src/ephy-window.c
index a412380..40f0b9f 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -46,6 +46,7 @@
#include "ephy-settings.h"
#include "ephy-shell.h"
#include "ephy-title-box.h"
+#include "ephy-title-widget.h"
#include "ephy-type-builtins.h"
#include "ephy-web-view.h"
#include "ephy-zoom.h"
@@ -501,7 +502,7 @@ sync_tab_security (EphyWebView *view,
ephy_web_view_get_security_level (view, &security_level, NULL, NULL);
title_box = ephy_header_bar_get_title_box (EPHY_HEADER_BAR (window->header_bar));
- ephy_title_box_set_security_level (title_box, security_level);
+ ephy_title_widget_set_security_level (EPHY_TITLE_WIDGET (title_box), security_level);
location_entry = ephy_header_bar_get_location_entry (EPHY_HEADER_BAR (window->header_bar));
ephy_location_entry_set_security_level (EPHY_LOCATION_ENTRY (location_entry), security_level);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]