diff options
author | Adrien Plazas <kekun.plazas@laposte.net> | 2018-05-07 13:29:09 +0200 |
---|---|---|
committer | Adrien Plazas <kekun.plazas@laposte.net> | 2018-06-21 23:39:22 +0200 |
commit | 9d4634373b1bfb221bbb33fc77308ff812a3362c (patch) | |
tree | ae2ce4bc4b785f05714a18f0fcc2a17e245cff5e | |
parent | f9732f9802620bd2135cab361f28299e717b8395 (diff) | |
download | epiphany-9d4634373b1bfb221bbb33fc77308ff812a3362c.tar.gz |
Add EphyActionBarEnd
This contains the elements at the end of the header bar and will be used
to have both in the hader bar and in a new action bar in a factorized
way.
-rw-r--r-- | po/POTFILES.in | 2 | ||||
-rw-r--r-- | src/ephy-action-bar-end.c | 186 | ||||
-rw-r--r-- | src/ephy-action-bar-end.h | 38 | ||||
-rw-r--r-- | src/meson.build | 1 | ||||
-rw-r--r-- | src/resources/epiphany.gresource.xml | 1 | ||||
-rw-r--r-- | src/resources/gtk/action-bar-end.ui | 85 |
6 files changed, 313 insertions, 0 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index dc5756b24..a98b37e08 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -38,6 +38,7 @@ src/bookmarks/ephy-bookmarks-manager.h src/bookmarks/ephy-bookmarks-popover.c src/clear-data-dialog.c src/cookies-dialog.c +src/ephy-action-bar-end.c src/ephy-action-bar-start.c src/ephy-encoding-dialog.c src/ephy-header-bar.c @@ -52,6 +53,7 @@ src/passwords-dialog.c src/popup-commands.c src/prefs-dialog.c src/profile-migrator/ephy-profile-migrator.c +src/resources/gtk/action-bar-end.ui src/resources/gtk/action-bar-start.ui src/resources/gtk/application-menu.ui src/resources/gtk/bookmark-properties-grid.ui diff --git a/src/ephy-action-bar-end.c b/src/ephy-action-bar-end.c new file mode 100644 index 000000000..79d94725a --- /dev/null +++ b/src/ephy-action-bar-end.c @@ -0,0 +1,186 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Copyright © 2018 Purism SPC + * Copyright © 2018 Adrien Plazas <kekun.plazas@laposte.net> + * + * This file is part of Epiphany. + * + * Epiphany 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. + * + * Epiphany 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 Epiphany. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "ephy-action-bar-end.h" + +#include "ephy-downloads-popover.h" +#include "ephy-downloads-progress-icon.h" +#include "ephy-shell.h" +#include "ephy-window.h" + +struct _EphyActionBarEnd { + GtkBox parent_instance; + + GtkWidget *bookmarks_button; + GtkWidget *new_tab_revealer; + GtkWidget *new_tab_button; + GtkWidget *downloads_revealer; + GtkWidget *downloads_button; + GtkWidget *downloads_popover; +}; + +G_DEFINE_TYPE (EphyActionBarEnd, ephy_action_bar_end, GTK_TYPE_BOX) + +static gboolean +is_for_active_window (EphyActionBarEnd *action_bar_end) +{ + EphyShell *shell = ephy_shell_get_default (); + GtkWidget *ancestor; + GtkWindow *active_window; + + ancestor = gtk_widget_get_ancestor (GTK_WIDGET (action_bar_end), GTK_TYPE_WINDOW); + active_window = gtk_application_get_active_window (GTK_APPLICATION (shell)); + + return active_window == GTK_WINDOW (ancestor); +} + +static void +download_added_cb (EphyDownloadsManager *manager, + EphyDownload *download, + EphyActionBarEnd *action_bar_end) +{ + if (!action_bar_end->downloads_popover) { + action_bar_end->downloads_popover = ephy_downloads_popover_new (action_bar_end->downloads_button); + gtk_menu_button_set_popover (GTK_MENU_BUTTON (action_bar_end->downloads_button), + action_bar_end->downloads_popover); + } + + gtk_revealer_set_reveal_child (GTK_REVEALER (action_bar_end->downloads_revealer), TRUE); + + if (is_for_active_window (action_bar_end) && + gtk_widget_get_mapped (GTK_WIDGET (action_bar_end))) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (action_bar_end->downloads_button), TRUE); +} + +static void +download_completed_cb (EphyDownloadsManager *manager, + EphyDownload *download, + EphyActionBarEnd *action_bar_end) +{ + if (is_for_active_window (action_bar_end) && + gtk_widget_get_mapped (GTK_WIDGET (action_bar_end))) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (action_bar_end->downloads_button), TRUE); +} + +static void +download_removed_cb (EphyDownloadsManager *manager, + EphyDownload *download, + EphyActionBarEnd *action_bar_end) +{ + if (!ephy_downloads_manager_get_downloads (manager)) + gtk_revealer_set_reveal_child (GTK_REVEALER (action_bar_end->downloads_revealer), FALSE); +} + +static void +downloads_estimated_progress_cb (EphyDownloadsManager *manager, + EphyActionBarEnd *action_bar_end) +{ + gtk_widget_queue_draw (gtk_button_get_image (GTK_BUTTON (action_bar_end->downloads_button))); +} + +static void +ephy_action_bar_end_class_init (EphyActionBarEndClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, + "/org/gnome/epiphany/gtk/action-bar-end.ui"); + + gtk_widget_class_bind_template_child (widget_class, + EphyActionBarEnd, + bookmarks_button); + gtk_widget_class_bind_template_child (widget_class, + EphyActionBarEnd, + new_tab_revealer); + gtk_widget_class_bind_template_child (widget_class, + EphyActionBarEnd, + new_tab_button); + gtk_widget_class_bind_template_child (widget_class, + EphyActionBarEnd, + downloads_revealer); + gtk_widget_class_bind_template_child (widget_class, + EphyActionBarEnd, + downloads_button); +} + +static void +ephy_action_bar_end_init (EphyActionBarEnd *action_bar_end) +{ + GObject *object = G_OBJECT (action_bar_end); + EphyDownloadsManager *downloads_manager; + + /* Ensure the types used by the template have been initialized. */ + EPHY_TYPE_DOWNLOADS_PROGRESS_ICON; + + gtk_widget_init_template (GTK_WIDGET (action_bar_end)); + + /* Downloads */ + downloads_manager = ephy_embed_shell_get_downloads_manager (ephy_embed_shell_get_default ()); + + gtk_revealer_set_reveal_child (GTK_REVEALER (action_bar_end->downloads_revealer), + ephy_downloads_manager_get_downloads (downloads_manager) != NULL); + + if (ephy_downloads_manager_get_downloads (downloads_manager)) { + action_bar_end->downloads_popover = ephy_downloads_popover_new (action_bar_end->downloads_button); + gtk_menu_button_set_popover (GTK_MENU_BUTTON (action_bar_end->downloads_button), action_bar_end->downloads_popover); + } + + g_signal_connect_object (downloads_manager, "download-added", + G_CALLBACK (download_added_cb), + object, 0); + g_signal_connect_object (downloads_manager, "download-completed", + G_CALLBACK (download_completed_cb), + object, 0); + g_signal_connect_object (downloads_manager, "download-removed", + G_CALLBACK (download_removed_cb), + object, 0); + g_signal_connect_object (downloads_manager, "estimated-progress-changed", + G_CALLBACK (downloads_estimated_progress_cb), + object, 0); +} + +EphyActionBarEnd * +ephy_action_bar_end_new (void) +{ + return g_object_new (EPHY_TYPE_ACTION_BAR_END, + NULL); +} + +void +ephy_action_bar_end_set_show_bookmarks_button (EphyActionBarEnd *action_bar_end, + gboolean show) +{ + gtk_widget_set_visible (action_bar_end->bookmarks_button, show); +} + +void +ephy_action_bar_end_set_show_new_tab_button (EphyActionBarEnd *action_bar_end, + gboolean show) +{ + gtk_widget_set_visible (action_bar_end->new_tab_revealer, show); + gtk_revealer_set_reveal_child (GTK_REVEALER (action_bar_end->new_tab_revealer), show); +} + +GtkWidget * +ephy_action_bar_end_get_bookmarks_button (EphyActionBarEnd *action_bar_end) +{ + return action_bar_end->bookmarks_button; +} diff --git a/src/ephy-action-bar-end.h b/src/ephy-action-bar-end.h new file mode 100644 index 000000000..56646c99a --- /dev/null +++ b/src/ephy-action-bar-end.h @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Copyright © 2018 Purism SPC + * Copyright © 2018 Adrien Plazas <kekun.plazas@laposte.net> + * + * This file is part of Epiphany. + * + * Epiphany 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. + * + * Epiphany 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 Epiphany. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define EPHY_TYPE_ACTION_BAR_END (ephy_action_bar_end_get_type ()) + +G_DECLARE_FINAL_TYPE (EphyActionBarEnd, ephy_action_bar_end, EPHY, ACTION_BAR_END, GtkBox); + +EphyActionBarEnd *ephy_action_bar_end_new (void); +void ephy_action_bar_end_set_show_bookmarks_button (EphyActionBarEnd *action_bar_end, + gboolean show); +void ephy_action_bar_end_set_show_new_tab_button (EphyActionBarEnd *action_bar_end, + gboolean show); + +G_END_DECLS diff --git a/src/meson.build b/src/meson.build index d560c91e5..c27f46c4e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -21,6 +21,7 @@ libephymain_sources = [ 'bookmarks/ephy-bookmarks-popover.c', 'clear-data-dialog.c', 'cookies-dialog.c', + 'ephy-action-bar-end.c', 'ephy-action-bar-start.c', 'ephy-action-helper.c', 'ephy-completion-model.c', diff --git a/src/resources/epiphany.gresource.xml b/src/resources/epiphany.gresource.xml index fe6b6b36b..6bddbad94 100644 --- a/src/resources/epiphany.gresource.xml +++ b/src/resources/epiphany.gresource.xml @@ -12,6 +12,7 @@ <file alias="page-templates/error.css" compressed="true">error.css</file> <file alias="page-templates/error.html" compressed="true">error.html</file> <file preprocess="xml-stripblanks" compressed="true">mime-types-permissions.xml</file> + <file preprocess="xml-stripblanks" compressed="true">gtk/action-bar-end.ui</file> <file preprocess="xml-stripblanks" compressed="true">gtk/action-bar-start.ui</file> <file preprocess="xml-stripblanks" compressed="true">gtk/application-menu.ui</file> <file preprocess="xml-stripblanks" compressed="true">gtk/bookmark-properties-grid.ui</file> diff --git a/src/resources/gtk/action-bar-end.ui b/src/resources/gtk/action-bar-end.ui new file mode 100644 index 000000000..bc0ba95c3 --- /dev/null +++ b/src/resources/gtk/action-bar-end.ui @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <template class="EphyActionBarEnd" parent="GtkBox"> + <property name="spacing">6</property> + <child> + <object class="GtkMenuButton" id="bookmarks_button"> + <property name="visible">True</property> + <property name="valign">center</property> + <!-- Translators: tooltip for the bookmarks popover button --> + <property name="tooltip_text" translatable="yes">View and manage your bookmarks</property> + <property name="popover">bookmarks_popover</property> + <style> + <class name="image-button"/> + </style> + <child> + <object class="GtkImage" id="bookmarks_image"> + <property name="visible">True</property> + <property name="icon-name">ephy-bookmarks-symbolic</property> + <property name="icon-size">1</property> + </object> + </child> + </object> + <packing> + <property name="pack-type">end</property> + </packing> + </child> + <child> + <object class="GtkRevealer" id="new_tab_revealer"> + <property name="visible">False</property> + <property name="transition-type">crossfade</property> + <child> + <object class="GtkButton" id="new_tab_button"> + <property name="visible">True</property> + <property name="action-name">win.new-tab</property> + <property name="valign">center</property> + <!-- Translators: tooltip for the new tab button --> + <property name="tooltip_text" translatable="yes">Open a new tab</property> + <style> + <class name="image-button"/> + </style> + <child> + <object class="GtkImage" id="new_tab_image"> + <property name="visible">True</property> + <property name="icon-name">tab-new-symbolic</property> + <property name="icon-size">1</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="pack-type">end</property> + </packing> + </child> + <child> + <object class="GtkRevealer" id="downloads_revealer"> + <property name="visible">True</property> + <property name="transition-type">crossfade</property> + <child> + <object class="GtkMenuButton" id="downloads_button"> + <property name="visible">True</property> + <property name="valign">center</property> + <!-- Translators: tooltip for the downloads button --> + <property name="tooltip_text" translatable="yes">View downloads</property> + <property name="image">downloads_image</property> + <style> + <class name="image-button"/> + </style> + <child> + <object class="EphyDownloadsProgressIcon" id="downloads_image"> + <property name="visible">True</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="pack-type">end</property> + </packing> + </child> + </template> + <object class="EphyBookmarksPopover" id="bookmarks_popover"> + <property name="visible">True</property> + </object> +</interface>
\ No newline at end of file |