[epiphany/wip/exalm/gtk4: 2/3] location-entry: Replace get_reader_mode_widget() with a signal
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/gtk4: 2/3] location-entry: Replace get_reader_mode_widget() with a signal
- Date: Tue, 22 Feb 2022 12:46:51 +0000 (UTC)
commit 948a3298223ec2b2af605f9c20f8f9e1edadf800
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Feb 22 13:11:38 2022 +0500
location-entry: Replace get_reader_mode_widget() with a signal
We don't need to expose widgetry for EphyLocationController to be able to
interact with it. This will make GTK4 port easier.
lib/widgets/ephy-location-entry.c | 34 ++++++++++++++++++++++++++++------
lib/widgets/ephy-location-entry.h | 2 --
src/ephy-location-controller.c | 19 +++++++------------
3 files changed, 35 insertions(+), 20 deletions(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index ccb85da0f..036d5d592 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -104,6 +104,7 @@ enum {
enum signalsEnum {
USER_CHANGED,
+ READER_MODE_CHANGED,
GET_LOCATION,
GET_TITLE,
LAST_SIGNAL
@@ -526,6 +527,22 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass)
0,
G_TYPE_NONE);
+ /**
+ * EphyLocationEntry::reader-mode-changed:
+ * @entry: the object on which the signal is emitted
+ * @active: whether reader mode is active
+ *
+ * Emitted when the user clicks the reader mode icon inside the
+ * #EphyLocationEntry.
+ *
+ */
+ signals[READER_MODE_CHANGED] = g_signal_new ("reader-mode-changed", G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_BOOLEAN);
+
/**
* EphyLocationEntry::get-location:
* @entry: the object on which the signal is emitted
@@ -1029,6 +1046,15 @@ update_reader_icon (EphyLocationEntry *entry)
name, GTK_ICON_SIZE_MENU);
}
+static void
+reader_mode_clicked_cb (EphyLocationEntry *self)
+{
+ self->reader_mode_active = !self->reader_mode_active;
+
+ g_signal_emit (G_OBJECT (self), signals[READER_MODE_CHANGED], 0,
+ self->reader_mode_active);
+}
+
static void
ephy_location_entry_construct_contents (EphyLocationEntry *entry)
{
@@ -1097,6 +1123,8 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
gtk_widget_set_tooltip_text (entry->reader_mode_button, _("Toggle reader mode"));
entry->reader_mode_icon = gtk_button_get_image (GTK_BUTTON (entry->reader_mode_button));
gtk_box_pack_start (GTK_BOX (box), entry->reader_mode_button, FALSE, TRUE, 0);
+ g_signal_connect_swapped (entry->reader_mode_button, "clicked",
+ G_CALLBACK (reader_mode_clicked_cb), entry);
context = gtk_widget_get_style_context (entry->reader_mode_icon);
gtk_style_context_add_class (context, "entry_icon");
@@ -1452,12 +1480,6 @@ ephy_location_entry_get_entry (EphyLocationEntry *entry)
return GTK_WIDGET (entry->url_entry);
}
-GtkWidget *
-ephy_location_entry_get_reader_mode_widget (EphyLocationEntry *entry)
-{
- return entry->reader_mode_button;
-}
-
void
ephy_location_entry_set_reader_mode_visible (EphyLocationEntry *entry,
gboolean visible)
diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h
index da8fdc79c..516ca9a1f 100644
--- a/lib/widgets/ephy-location-entry.h
+++ b/lib/widgets/ephy-location-entry.h
@@ -61,8 +61,6 @@ void ephy_location_entry_show_add_bookmark_popover (EphyLocationEntr
GtkWidget *ephy_location_entry_get_entry (EphyLocationEntry *entry);
-GtkWidget *ephy_location_entry_get_reader_mode_widget (EphyLocationEntry *entry);
-
void ephy_location_entry_set_reader_mode_visible (EphyLocationEntry *entry,
gboolean visible);
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index b9d37ae19..31370aac8 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -314,21 +314,16 @@ longpress_gesture_cb (GtkGestureLongPress *gesture,
}
static void
-reader_mode_button_clicked_cb (GtkButton *button,
- gpointer user_data)
+reader_mode_changed_cb (EphyLocationEntry *lentry,
+ gboolean active,
+ gpointer user_data)
{
EphyLocationController *controller = EPHY_LOCATION_CONTROLLER (user_data);
EphyWindow *window = controller->window;
EphyEmbed *embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
EphyWebView *view = ephy_embed_get_web_view (embed);
- EphyLocationEntry *lentry;
- g_assert (EPHY_IS_LOCATION_ENTRY (controller->title_widget));
-
- lentry = EPHY_LOCATION_ENTRY (controller->title_widget);
-
- ephy_location_entry_set_reader_mode_state (lentry, !ephy_location_entry_get_reader_mode_state (lentry));
- ephy_web_view_toggle_reader_mode (view, ephy_location_entry_get_reader_mode_state (lentry));
+ ephy_web_view_toggle_reader_mode (view, active);
}
static void
@@ -339,7 +334,7 @@ ephy_location_controller_constructed (GObject *object)
EphyBookmarksManager *bookmarks_manager;
EphySuggestionModel *model;
EphyTabView *tab_view;
- GtkWidget *widget, *reader_mode, *entry;
+ GtkWidget *widget, *entry;
G_OBJECT_CLASS (ephy_location_controller_parent_class)->constructed (object);
@@ -370,8 +365,8 @@ ephy_location_controller_constructed (GObject *object)
dzl_suggestion_entry_set_model (DZL_SUGGESTION_ENTRY (entry), G_LIST_MODEL (model));
g_object_unref (model);
- reader_mode = ephy_location_entry_get_reader_mode_widget (EPHY_LOCATION_ENTRY (controller->title_widget));
- g_signal_connect (G_OBJECT (reader_mode), "clicked", G_CALLBACK (reader_mode_button_clicked_cb),
controller);
+ g_signal_connect (controller->title_widget, "reader-mode-changed",
+ G_CALLBACK (reader_mode_changed_cb), controller);
g_object_bind_property (controller, "editable",
entry, "editable",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]