diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index c14ec46..21d6517 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -1,5 +1,5 @@ install (FILES com.github.artemanufrij.webpin.desktop DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications) -install (FILES com.github.artemanufrij.webpin.appdata.xml DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/metainfo) +#install (FILES com.github.artemanufrij.webpin.appdata.xml DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/metainfo) install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/) install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/48x48/apps/) diff --git a/data/com.github.artemanufrij.webpin.desktop b/data/com.github.artemanufrij.webpin.desktop index 82b9c38..a130149 100644 --- a/data/com.github.artemanufrij.webpin.desktop +++ b/data/com.github.artemanufrij.webpin.desktop @@ -1,20 +1,11 @@ [Desktop Entry] -Version=1.0 -Name=Webby -GenericName=Webby -Comment=Create your apps +Name=Webpin +GenericName=Webpin +Comment=Pin your websites on your desktop Keywords=internet;webapp; -Exec=webby %u -Icon=webby +Exec=com.github.artemanufrij.webpin %u +Icon=artemanufrij.webpin Terminal=false Type=Application Categories=Network;GNOME;GTK; -X-GIO-NoFuse=true -X-GNOME-Gettext-Domain=webby -X-GNOME-FullName=Webby -StartupWMClass=Webby -Actions=AboutDialog; - -[Desktop Action AboutDialog] -Exec=webby --about -Name=About Webby +X-GNOME-Gettext-Domain=webpin diff --git a/src/Application.vala b/src/Application.vala new file mode 100644 index 0000000..aa4d2aa --- /dev/null +++ b/src/Application.vala @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2015 Erasmo Marín + * Copyright (c) 2017-2017 Artem Anufrij + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * The Noise authors hereby grant permission for non-GPL compatible + * GStreamer plugins to be used and distributed together with GStreamer + * and Noise. This permission is above and beyond the permissions granted + * by the GPL license by which Noise is covered. If you modify this code + * you may extend this exception to your version of the code, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * + * Authored by: Artem Anufrij + */ + +namespace Webpin { + public class WebpinApp : Granite.Application { + + static WebpinApp _instance = null; + + public static WebpinApp instance { + get { + if (_instance == null) + _instance = new WebpinApp (); + return _instance; + } + } + + construct { + program_name = "Image Burner"; + exec_name = "com.github.artemanufrij.webpin"; + application_id = "com.github.artemanufrij.webpin"; + app_launcher = application_id + ".desktop"; + } + + public Gtk.Window mainwindow; + + protected override void activate () { + if (mainwindow != null) { + mainwindow.present (); + return; + } + + mainwindow = new MainWindow (); + mainwindow.set_application(this); + } + } +} +static int main (string[] args) { + + Gtk.init (ref args); + + if (args.length < 2 || args[1] == "--about" || args[1] == "-d") { + var app = Webpin.WebpinApp.instance; + return app.run (args); + } else { + var app_info = DesktopFile.get_app_by_url (args[1]); + var app = new Webpin.WebAppWindow(app_info.get_display_name (), args[1]); + app.show_all (); + } + + Gtk.main (); + return 0; +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 268f30c..932d582 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,8 @@ vala_precompile(VALA_C ${CMAKE_PROJECT_NAME} Widgets/ApplicationIcon.vala Widgets/ApplicationsView.vala - AppWindow.vala + Application.vala + MainWindow.vala Assistant.vala DesktopFile.vala InfoDialog.vala @@ -9,7 +10,6 @@ vala_precompile(VALA_C ${CMAKE_PROJECT_NAME} UrlEntry.vala WebApp.vala WebBar.vala - Webby.vala WebAppWindow.vala PACKAGES gtk+-3.0 diff --git a/src/MainWindow.vala b/src/MainWindow.vala new file mode 100644 index 0000000..b9fa524 --- /dev/null +++ b/src/MainWindow.vala @@ -0,0 +1,185 @@ +/*- + * Copyright (c) 2015 Erasmo Marín + * Copyright (c) 2017-2017 Artem Anufrij + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * The Noise authors hereby grant permission for non-GPL compatible + * GStreamer plugins to be used and distributed together with GStreamer + * and Noise. This permission is above and beyond the permissions granted + * by the GPL license by which Noise is covered. If you modify this code + * you may extend this exception to your version of the code, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * + * Authored by: Artem Anufrij + */ + +namespace Webpin { + public class MainWindow : Gtk.ApplicationWindow { + private Settings settings; + + private Gtk.Stack stack; + private Gtk.HeaderBar headerbar; + private Gtk.Button back_button; + private Gtk.Button add_button; + + private WebbyAssistant assistant; + private ApplicationsView apps_view; + + public MainWindow () { + settings = Settings.get_default (); + + build_ui (); + } + + private void build_ui () { + set_default_size (700, 500); + + //headerbar + headerbar = new Gtk.HeaderBar (); + headerbar.show_close_button = true; + headerbar.title = "Webpin"; + set_titlebar (headerbar); + + back_button = new Gtk.Button.with_label (_("Applications")); + back_button.get_style_context ().add_class ("back-button"); + headerbar.pack_start (back_button); + + add_button = new Gtk.Button (); + add_button.image = new Gtk.Image.from_icon_name ("add", Gtk.IconSize.LARGE_TOOLBAR); + add_button.tooltip_text = _("Add a new Web App"); + headerbar.pack_start (add_button); + + var welcome = new Granite.Widgets.Welcome (_("No Web Apps Availible"), _("Create a new Webby Web App.")); + welcome.append ("add", _("Create App"), _("Create a new Webby web app.")); + welcome.activated.connect ((index) => { + switch (index) { + case 0: + show_assistant (); + break; + } + }); + + apps_view = new ApplicationsView(); + assistant = new WebbyAssistant(); + stack = new Gtk.Stack (); + stack.set_transition_duration (500); + + stack.add_named (welcome, "welcome"); + stack.add_named (apps_view, "apps_view"); + stack.add_named (assistant, "assistant"); + + add (stack); + + apps_view.add_request.connect (() => { + show_assistant (); + }); + + apps_view.edit_request.connect ((desktop_file) => { + show_assistant (desktop_file); + }); + + apps_view.app_deleted.connect (() => { + if (!apps_view.has_items) { + show_welcome_view (Gtk.StackTransitionType.NONE); + } + }); + + assistant.application_created.connect ((new_file) => { + apps_view.add_button (new_file); + apps_view.select_last_item (); + show_apps_view (); + }); + + assistant.application_edited.connect ((edited_file) => { + apps_view.update_button (edited_file); + show_apps_view (); + }); + + back_button.clicked.connect (() => { + if (apps_view.has_items) + show_apps_view (); + else + show_welcome_view (); + }); + + add_button.clicked.connect (() => { + show_assistant (); + }); + + delete_event.connect (() => { + this.store_settings (); + return false; + }); + + this.restore_settings (); + show_all (); + + if (apps_view.has_items) + show_apps_view (Gtk.StackTransitionType.NONE); + else + show_welcome_view (Gtk.StackTransitionType.NONE); + + this.present (); + } + + private void show_assistant (DesktopFile? desktop_file = null) { + stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT); + stack.set_visible_child_name("assistant"); + back_button.show_all (); + add_button.hide (); + //fix ugly border at the bottom of headerbar + queue_draw (); + + if (desktop_file != null) + assistant.edit_desktop_file (desktop_file); + } + + private void show_apps_view (Gtk.StackTransitionType slide = Gtk.StackTransitionType.SLIDE_RIGHT) { + stack.set_transition_type (slide); + stack.set_visible_child_name ("apps_view"); + back_button.hide (); + add_button.show_all (); + assistant.reset_fields (); + //fix ugly border at the bottom of headerbar + queue_draw (); + } + + private void show_welcome_view (Gtk.StackTransitionType slide = Gtk.StackTransitionType.SLIDE_RIGHT) { + stack.set_transition_type (slide); + stack.set_visible_child_name ("welcome"); + back_button.hide (); + add_button.hide (); + assistant.reset_fields (); + //fix ugly border at the bottom of headerbar + queue_draw (); + } + + private void restore_settings () { + this.set_default_size (settings.window_width, settings.window_height); + + if (settings.window_state == Settings.WindowState.MAXIMIZED) + this.maximize (); + } + + private void store_settings () { + settings.window_state = (this.is_maximized ? Settings.WindowState.MAXIMIZED: Settings.WindowState.NORMAL); + if (settings.window_state == Settings.WindowState.NORMAL) { + settings.window_height = this.get_allocated_height (); + settings.window_width = this.get_allocated_width (); + } + } + } +} diff --git a/src/Settings.vala b/src/Settings.vala index 98864ae..2170de1 100644 --- a/src/Settings.vala +++ b/src/Settings.vala @@ -1,23 +1,53 @@ -public class Settings : Granite.Services.Settings { +/*- + * Copyright (c) 2015 Erasmo Marín + * Copyright (c) 2017-2017 Artem Anufrij + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * The Noise authors hereby grant permission for non-GPL compatible + * GStreamer plugins to be used and distributed together with GStreamer + * and Noise. This permission is above and beyond the permissions granted + * by the GPL license by which Noise is covered. If you modify this code + * you may extend this exception to your version of the code, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * + * Authored by: Artem Anufrij + */ - private static Settings settings; - public static Settings get_default () { - if (settings == null) - settings = new Settings (); +namespace Webpin { + public class Settings : Granite.Services.Settings { - return settings; - } - public int window_width { get; set; } - public int window_height { get; set; } - public WindowState window_state { get; set; } + private static Settings settings; + public static Settings get_default () { + if (settings == null) + settings = new Settings (); - private Settings () { - base ("com.github.artemanufrij.webpin"); - } + return settings; + } + public int window_width { get; set; } + public int window_height { get; set; } + public WindowState window_state { get; set; } - public enum WindowState { - NORMAL, - MAXIMIZED, - FULLSCREEN + private Settings () { + base ("com.github.artemanufrij.webpin"); + } + + public enum WindowState { + NORMAL, + MAXIMIZED, + FULLSCREEN + } } } diff --git a/src/WebAppWindow.vala b/src/WebAppWindow.vala index 5538c6a..eb73175 100644 --- a/src/WebAppWindow.vala +++ b/src/WebAppWindow.vala @@ -1,142 +1,172 @@ -public class WebAppWindow : Gtk.ApplicationWindow { +/*- + * Copyright (c) 2015 Erasmo Marín + * Copyright (c) 2017-2017 Artem Anufrij + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * The Noise authors hereby grant permission for non-GPL compatible + * GStreamer plugins to be used and distributed together with GStreamer + * and Noise. This permission is above and beyond the permissions granted + * by the GPL license by which Noise is covered. If you modify this code + * you may extend this exception to your version of the code, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * + * Authored by: Artem Anufrij + */ - private bool is_full_screen = false; +namespace Webpin { + public class WebAppWindow : Gtk.ApplicationWindow { - private string style_str = """@define-color titlebar_color @titlebar_color;"""; + private bool is_full_screen = false; - //widgets - private WebApp web_app; - private WebBar headerbar; + private string style_str = """@define-color titlebar_color @titlebar_color;"""; - public WebAppWindow (string webapp_name, string webapp_uri) { + //widgets + private WebApp web_app; + private WebBar headerbar; - set_wmclass(webapp_uri, webapp_uri); - web_app = new WebApp(webapp_name, webapp_uri); + public WebAppWindow (string webapp_name, string webapp_uri) { - headerbar = new WebBar(web_app.external_view); - headerbar.show_close_button = true; - headerbar.title = webapp_name; - headerbar.set_title_mode (WebBar.title_mode.TITLE); + set_wmclass(webapp_uri, webapp_uri); + web_app = new WebApp(webapp_name, webapp_uri); - //style - if (web_app.ui_color != "none") { - try { - print("set color"); - var style_cp = style_str.replace ("@titlebar_color", web_app.ui_color); - var style_provider = new Gtk.CssProvider (); - style_provider.load_from_data (style_cp, -1); - headerbar.get_style_context ().add_provider (style_provider, -1); - Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (web_app.ui_color)); - } catch (GLib.Error err) { - warning("Loading style failed"); - } - } - - web_app.theme_color_changed.connect( (color)=> { - try { - print("set color"); - var style_cp = style_str.replace ("@titlebar_color", color); - var style_provider = new Gtk.CssProvider (); - style_provider.load_from_data (style_cp, -1); - headerbar.get_style_context ().add_provider (style_provider, -1); - Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (color)); - } catch (GLib.Error err) { - warning("Loading style failed"); - } - }); - - this.set_titlebar (headerbar); - - var info = DesktopFile.get_app_by_url(webapp_uri); - var width = info.get_string("WebbyWindowWidth"); - var height = info.get_string("WebbyWindowHeight"); - - if(width !=null && height != null) - set_default_size (int.parse(width), int.parse(height)); - else - set_default_size (1000, 600); - this.delete_event.connect (() => { - update_window_state(this.get_allocated_width (), this.get_allocated_height () ); - return false; - }); - - this.destroy.connect(Gtk.main_quit); - - web_app.external_request.connect ( () => { - print("Web app external request\n"); - web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT); - headerbar.set_title_mode (WebBar.title_mode.BROWSER); - web_app.set_visible_child_name ("external"); - }); - - headerbar.back_event.connect ( () => { - print ("back"); + headerbar = new WebBar(web_app.external_view); + headerbar.show_close_button = true; + headerbar.title = webapp_name; headerbar.set_title_mode (WebBar.title_mode.TITLE); - web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT); - web_app.set_visible_child_name ("app"); - //wait the animation to end before "cleaning" the web view - GLib.Timeout.add(web_app.get_transition_duration(), () => { - web_app.external_view.load_uri ("about:blank"); - return false; + + //style + if (web_app.ui_color != "none") { + try { + print("set color"); + var style_cp = style_str.replace ("@titlebar_color", web_app.ui_color); + var style_provider = new Gtk.CssProvider (); + style_provider.load_from_data (style_cp, -1); + headerbar.get_style_context ().add_provider (style_provider, -1); + Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (web_app.ui_color)); + } catch (GLib.Error err) { + warning("Loading style failed"); + } + } + + web_app.theme_color_changed.connect( (color)=> { + try { + print("set color"); + var style_cp = style_str.replace ("@titlebar_color", color); + var style_provider = new Gtk.CssProvider (); + style_provider.load_from_data (style_cp, -1); + headerbar.get_style_context ().add_provider (style_provider, -1); + Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (color)); + } catch (GLib.Error err) { + warning("Loading style failed"); + } }); - }); - add(web_app); - show_all(); - } + this.set_titlebar (headerbar); - public new void fullscreen () { - is_full_screen = true; - base.fullscreen(); - } + var info = DesktopFile.get_app_by_url(webapp_uri); + var width = info.get_string("WebbyWindowWidth"); + var height = info.get_string("WebbyWindowHeight"); - public new void unfullscreen () { - is_full_screen = false; - base.unfullscreen(); - } + if(width !=null && height != null) + set_default_size (int.parse(width), int.parse(height)); + else + set_default_size (1000, 600); + this.delete_event.connect (() => { + update_window_state(this.get_allocated_width (), this.get_allocated_height () ); + return false; + }); - public void toggle_fullscreen() { - if(is_full_screen) - unfullscreen(); - else - fullscreen(); - is_full_screen = !is_full_screen; - } + this.destroy.connect(Gtk.main_quit); - public void update_window_state (int width, int height) { - var file = web_app.get_desktop_file(); - file.edit_propertie ("WebbyWindowWidth", width.to_string()); - file.edit_propertie ("WebbyWindowHeight", height.to_string()); - } + web_app.external_request.connect ( () => { + print("Web app external request\n"); + web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT); + headerbar.set_title_mode (WebBar.title_mode.BROWSER); + web_app.set_visible_child_name ("external"); + }); - public override bool key_press_event (Gdk.EventKey event) { - bool handled = true; - switch (event.keyval) { - case Gdk.Key.Escape: - unfullscreen(); - break; - case Gdk.Key.F11: - toggle_fullscreen(); - break; - default: - handled = false; - break; + headerbar.back_event.connect ( () => { + print ("back"); + headerbar.set_title_mode (WebBar.title_mode.TITLE); + web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT); + web_app.set_visible_child_name ("app"); + //wait the animation to end before "cleaning" the web view + GLib.Timeout.add(web_app.get_transition_duration(), () => { + web_app.external_view.load_uri ("about:blank"); + return false; + }); + }); + + add(web_app); + show_all(); } - if (handled) - return true; + public new void fullscreen () { + is_full_screen = true; + base.fullscreen(); + } - return (base.key_press_event != null) ? base.key_press_event (event) : true; - } + public new void unfullscreen () { + is_full_screen = false; + base.unfullscreen(); + } - private bool should_use_dark_theme (string theme_color) { - Gdk.RGBA color = {}; - color.parse (theme_color); + public void toggle_fullscreen() { + if(is_full_screen) + unfullscreen(); + else + fullscreen(); + is_full_screen = !is_full_screen; + } - double prom = (color.red + color.blue + color.green)/3; + public void update_window_state (int width, int height) { + var file = web_app.get_desktop_file(); + file.edit_propertie ("WebbyWindowWidth", width.to_string()); + file.edit_propertie ("WebbyWindowHeight", height.to_string()); + } - if (prom < 0.5) - return true; - return false; + public override bool key_press_event (Gdk.EventKey event) { + bool handled = true; + switch (event.keyval) { + case Gdk.Key.Escape: + unfullscreen(); + break; + case Gdk.Key.F11: + toggle_fullscreen(); + break; + default: + handled = false; + break; + } + + if (handled) + return true; + + return (base.key_press_event != null) ? base.key_press_event (event) : true; + } + + private bool should_use_dark_theme (string theme_color) { + Gdk.RGBA color = {}; + color.parse (theme_color); + + double prom = (color.red + color.blue + color.green)/3; + + if (prom < 0.5) + return true; + return false; + } } } diff --git a/src/WebBar.vala b/src/WebBar.vala index ee103c5..f80d4a3 100644 --- a/src/WebBar.vala +++ b/src/WebBar.vala @@ -1,70 +1,97 @@ -public class WebBar : Gtk.HeaderBar { +/*- + * Copyright (c) 2015 Erasmo Marín + * Copyright (c) 2017-2017 Artem Anufrij + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * The Noise authors hereby grant permission for non-GPL compatible + * GStreamer plugins to be used and distributed together with GStreamer + * and Noise. This permission is above and beyond the permissions granted + * by the GPL license by which Noise is covered. If you modify this code + * you may extend this exception to your version of the code, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * + * Authored by: Artem Anufrij + */ +namespace Webpin { + public class WebBar : Gtk.HeaderBar { - public enum title_mode { - TITLE, - BROWSER; - } + public enum title_mode { + TITLE, + BROWSER; + } - UrlEntry url_entry; - Gtk.Button share_button; - Gtk.Button back_button; - WebKit.WebView webview; + UrlEntry url_entry; + Gtk.Button share_button; + Gtk.Button back_button; + WebKit.WebView webview; - public signal void back_event(); + public signal void back_event(); - public WebBar (WebKit.WebView webview) { + public WebBar (WebKit.WebView webview) { - this.get_style_context ().remove_class ("header-bar"); - this.webview = webview; - - url_entry = new UrlEntry(); - url_entry.show_all(); - - share_button = new Gtk.Button.from_icon_name ("application-menu-symbolic", Gtk.IconSize.SMALL_TOOLBAR); - share_button.margin_left = 15; - share_button.show_all (); - - back_button = new Gtk.Button.from_icon_name ("go-next-symbolic-rtl", Gtk.IconSize.SMALL_TOOLBAR); - back_button.margin_right = 15; - back_button.show_all (); - - pack_start (back_button); - pack_start (url_entry); - pack_end (share_button); - - custom_title = new Gtk.Label(null); - connect_signals (); - show(); - } - - - private void connect_signals () { - webview.load_changed.connect ( (event) => { - if (event == WebKit.LoadEvent.STARTED) - url_entry.set_text (webview.uri); - }); - - back_button.clicked.connect( () => { back_event(); }); - back_button.activate.connect( () => { back_event(); }); - } - - public void set_title_mode (title_mode mode) { - - if (mode == title_mode.TITLE) { - custom_title = null; - remove (share_button); - remove (back_button); - remove (url_entry); this.get_style_context ().remove_class ("header-bar"); - } else { + this.webview = webview; + + url_entry = new UrlEntry(); + url_entry.show_all(); + + share_button = new Gtk.Button.from_icon_name ("application-menu-symbolic", Gtk.IconSize.SMALL_TOOLBAR); + share_button.margin_left = 15; + share_button.show_all (); + + back_button = new Gtk.Button.from_icon_name ("go-next-symbolic-rtl", Gtk.IconSize.SMALL_TOOLBAR); + back_button.margin_right = 15; + back_button.show_all (); + pack_start (back_button); pack_start (url_entry); pack_end (share_button); + custom_title = new Gtk.Label(null); - this.get_style_context ().add_class ("header-bar"); + connect_signals (); + show(); + } + + + private void connect_signals () { + webview.load_changed.connect ( (event) => { + if (event == WebKit.LoadEvent.STARTED) + url_entry.set_text (webview.uri); + }); + + back_button.clicked.connect( () => { back_event(); }); + back_button.activate.connect( () => { back_event(); }); + } + + public void set_title_mode (title_mode mode) { + + if (mode == title_mode.TITLE) { + custom_title = null; + remove (share_button); + remove (back_button); + remove (url_entry); + this.get_style_context ().remove_class ("header-bar"); + } else { + pack_start (back_button); + pack_start (url_entry); + pack_end (share_button); + custom_title = new Gtk.Label(null); + this.get_style_context ().add_class ("header-bar"); + } } } - - }