diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 1a42a46..be9be1f 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -44,6 +44,7 @@ namespace Webpin { X-GNOME-UsesNotifications=true StartupWMClass=Webpin X-Webpin-PrimaryColor=rgba (222,222,222,1) + X-Webpin-View-Mode=default Actions=Remove; [Desktop Action Remove] @@ -100,7 +101,23 @@ namespace Webpin { } } - public DesktopFile (string name, string url, string icon, bool stay_open) { + string _view_mode = ""; + public string view_mode { + get { + try { + file.load_from_file (info.filename, KeyFileFlags.NONE); + _view_mode = file.get_string ("Desktop Entry", "X-Webpin-View-Mode"); + } catch (Error err) { + warning (err.message); + } + return _view_mode; + } set { + edit_property ("X-Webpin-View-Mode", value); + _view_mode = value; + } + } + + public DesktopFile (string name, string url, string icon, bool stay_open, bool minimal_ui) { this.name = name; this.url = url.replace ("%", "%%"); this.icon = icon; @@ -119,6 +136,7 @@ namespace Webpin { file.set_string ("Desktop Entry", "Icon", icon); file.set_string ("Desktop Entry", "StartupWMClass", url); file.set_string ("Desktop Entry", "X-Webpin-StayOpen", stay_open.to_string ()); + file.set_string ("Desktop Entry", "X-Webpin-View-Mode", minimal_ui ? "minimal" : "default"); file.set_string ("Desktop Action Remove", "Exec", "com.github.artemanufrij.webpin --remove " + url); } diff --git a/src/Widgets/Views/Editor.vala b/src/Widgets/Views/Editor.vala index 6c674c1..56c2937 100644 --- a/src/Widgets/Views/Editor.vala +++ b/src/Widgets/Views/Editor.vala @@ -41,6 +41,7 @@ namespace Webpin.Widgets.Views { Gtk.CheckButton save_cookies_check; Gtk.CheckButton save_password_check; Gtk.CheckButton stay_open_when_closed; + Gtk.CheckButton minimal_view_mode; Gtk.Popover icon_selector_popover; Gtk.FileChooserDialog file_chooser; Gtk.Button accept_button; @@ -119,10 +120,9 @@ namespace Webpin.Widgets.Views { primary_color_button = new Gtk.ColorButton.with_rgba (default_color); primary_color_button.use_alpha = false; - primary_color_button.color_activated.connect ( - (color) => { - stdout.printf ("COLOR %s\n", color.to_string ()); - }); + primary_color_button.color_activated.connect ((color) => { + stdout.printf ("COLOR %s\n", color.to_string ()); + }); //checkbuttons save_cookies_check = new Gtk.CheckButton.with_label (_ ("Save cookies")); @@ -131,6 +131,9 @@ namespace Webpin.Widgets.Views { save_password_check.active = false; stay_open_when_closed = new Gtk.CheckButton.with_label (_ ("Run in background if closed")); stay_open_when_closed.active = false; + minimal_view_mode = new Gtk.CheckButton.with_label (_("Use minimal UI")); + minimal_view_mode.active = false; + //app information section var app_input_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 5); @@ -149,6 +152,7 @@ namespace Webpin.Widgets.Views { app_options_box.pack_start (save_cookies_check, true, false, 0); app_options_box.pack_start (save_password_check, true, false, 0); app_options_box.pack_start (stay_open_when_closed, true, false, 0); + app_options_box.pack_start (minimal_view_mode, true, false, 0); app_options_box.halign = Gtk.Align.CENTER; //create button @@ -160,48 +164,45 @@ namespace Webpin.Widgets.Views { accept_button.clicked.connect (on_accept); //all sections together - pack_start (message, true, false, 0); - pack_start (app_info_box, true, false, 0); + pack_start (message, true, false, 0); + pack_start (app_info_box, true, false, 0); pack_start (app_options_box, true, false, 0); pack_end (accept_button, false, false, 0); //signals and handlers - icon_button.clicked.connect ( - () => { - icon_selector_popover.show_all (); - }); + icon_button.clicked.connect (() => { + icon_selector_popover.show_all (); + }); - app_url_entry.changed.connect ( - () => { - if (!this.protocol_regex.match (app_url_entry.get_text ())) { - reset_grab_color_and_icon (); - app_url_entry.get_style_context ().add_class ("error"); - app_url_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information"); - app_url_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _ ("url must start with http:// or https:// or file:///")); - app_url_valid = false; - } else { - grab_color_and_icon (); - app_url_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, null); - app_url_entry.get_style_context ().remove_class ("error"); - app_url_valid = true; - } - validate (); - }); + app_url_entry.changed.connect (() => { + if (!this.protocol_regex.match (app_url_entry.get_text ())) { + reset_grab_color_and_icon (); + app_url_entry.get_style_context ().add_class ("error"); + app_url_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information"); + app_url_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _ ("url must start with http:// or https:// or file:///")); + app_url_valid = false; + } else { + grab_color_and_icon (); + app_url_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, null); + app_url_entry.get_style_context ().remove_class ("error"); + app_url_valid = true; + } + validate (); + }); - app_name_entry.changed.connect ( - () => { - if (mode == assistant_mode.new_app && Services.DesktopFilesManager.get_applications ().has_key (app_name_entry.get_text ())) { - app_name_entry.get_style_context ().add_class ("error"); - app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information"); - app_name_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _ ("App already exist")); - app_name_valid = false; - } else { - app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, null); - app_name_entry.get_style_context ().remove_class ("error"); - app_name_valid = true; - } - validate (); - }); + app_name_entry.changed.connect (() => { + if (mode == assistant_mode.new_app && Services.DesktopFilesManager.get_applications ().has_key (app_name_entry.get_text ())) { + app_name_entry.get_style_context ().add_class ("error"); + app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information"); + app_name_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _ ("App already exist")); + app_name_valid = false; + } else { + app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, null); + app_name_entry.get_style_context ().remove_class ("error"); + app_name_valid = true; + } + validate (); + }); icon_chooser_button.activate.connect (on_icon_chooser_activate); icon_chooser_button.clicked.connect (on_icon_chooser_activate); @@ -502,21 +503,20 @@ namespace Webpin.Widgets.Views { } string name = app_name_entry.get_text (); string url = app_url_entry.get_text ().replace ("%", "%%"); - bool stay_open = stay_open_when_closed.active; if (icon == "") { icon = default_app_icon; } if (app_icon_valid && app_name_valid && app_url_valid) { - var desktop_file = new DesktopFile (name, url, icon, stay_open); + var desktop_file = new DesktopFile (name, url, icon, stay_open_when_closed.active, minimal_view_mode.active); switch (mode) { - case assistant_mode.new_app : - application_created (desktop_file.save_to_file ()); - break; - case assistant_mode.edit_app : - application_edited (desktop_file.save_to_file ()); - break; + case assistant_mode.new_app : + application_created (desktop_file.save_to_file ()); + break; + case assistant_mode.edit_app : + application_edited (desktop_file.save_to_file ()); + break; } stdout.printf ("Custom Color %s\n", primary_color_button.rgba.to_string ()); desktop_file.color = primary_color_button.rgba; @@ -533,6 +533,7 @@ namespace Webpin.Widgets.Views { app_url_entry.text = desktop_file.url.replace ("%%", "%"); icon_name_entry.text = desktop_file.icon; stay_open_when_closed.active = desktop_file.hide_on_close; + minimal_view_mode.active = desktop_file.view_mode == "minimal"; if (desktop_file.color != null) { primary_color_button.set_rgba (desktop_file.color); } else { diff --git a/src/Windows/WebApp.vala b/src/Windows/WebApp.vala index 1844556..d07d6c4 100644 --- a/src/Windows/WebApp.vala +++ b/src/Windows/WebApp.vala @@ -30,6 +30,9 @@ namespace Webpin.Windows { public class WebApp : Gtk.Window { Gdk.WindowState current_state; + Gtk.HeaderBar headerbar; + Gtk.Button button_back; + Gtk.Button button_forward; Widgets.Browser browser; Gtk.Spinner spinner; @@ -46,67 +49,25 @@ namespace Webpin.Windows { } browser = new Widgets.Browser (desktop_file); - var headerbar = new Gtk.HeaderBar (); + headerbar = new Gtk.HeaderBar (); headerbar.title = desktop_file.name; headerbar.show_close_button = true; headerbar.get_style_context ().add_class ("default-decoration"); - var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU); - copy_url.valign = Gtk.Align.CENTER; - copy_url.tooltip_text = _ ("Copy URL into clipboard"); - copy_url.clicked.connect (() => { - Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (browser.web_view.uri, -1); - }); - headerbar.pack_end (copy_url); + if (desktop_file.view_mode == "default") { + header_build_copy_button (); - var stay_open = new Gtk.ToggleButton (); - stay_open.valign = Gtk.Align.CENTER; - stay_open.active = desktop_file.hide_on_close; - stay_open.tooltip_text = _ ("Run in background if closed"); - stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU); - stay_open.toggled.connect (() => { - desktop_file.edit_property ("X-Webpin-StayOpen", stay_open.active.to_string ()); - desktop_file.save_to_file (); - }); - headerbar.pack_end (stay_open); - - var button_refresh = new Gtk.Button.from_icon_name ("view-refresh-symbolic", Gtk.IconSize.MENU); - button_refresh.tooltip_text = _("Reload"); - button_refresh.valign = Gtk.Align.CENTER; - button_refresh.clicked.connect (() => { - browser.reload (); - }); - headerbar.pack_end (button_refresh); + header_build_pin_button (); + } spinner = new Gtk.Spinner (); spinner.set_size_request (16, 16); headerbar.pack_end (spinner); - var button_back = new Gtk.Button.from_icon_name ("go-previous-symbolic", Gtk.IconSize.MENU); - button_back.tooltip_text = _("Back"); - button_back.sensitive = false; - button_back.valign = Gtk.Align.CENTER; - button_back.clicked.connect (() => { - browser.go_back (); - }); - headerbar.pack_start (button_back); + if (desktop_file.view_mode == "default") { + header_build_navi_buttons (); + } - var button_home = new Gtk.Button.from_icon_name ("go-home-symbolic", Gtk.IconSize.MENU); - button_home.tooltip_text = _("Home"); - button_home.valign = Gtk.Align.CENTER; - button_home.clicked.connect (() => { - browser.go_home (); - }); - headerbar.pack_start (button_home); - - var button_forward = new Gtk.Button.from_icon_name ("go-next-symbolic", Gtk.IconSize.MENU); - button_forward.tooltip_text = _("Forward"); - button_forward.sensitive = false; - button_forward.valign = Gtk.Align.CENTER; - button_forward.clicked.connect (() => { - browser.go_forward (); - }); - headerbar.pack_start (button_forward); this.set_titlebar (headerbar); this.delete_event.connect (() => { @@ -172,6 +133,65 @@ namespace Webpin.Windows { }); } + private void header_build_navi_buttons () { + button_back = new Gtk.Button.from_icon_name ("go-previous-symbolic", Gtk.IconSize.MENU); + button_back.tooltip_text = _("Back"); + button_back.sensitive = false; + button_back.valign = Gtk.Align.CENTER; + button_back.clicked.connect (() => { + browser.go_back (); + }); + headerbar.pack_start (button_back); + + var button_home = new Gtk.Button.from_icon_name ("go-home-symbolic", Gtk.IconSize.MENU); + button_home.tooltip_text = _("Home"); + button_home.valign = Gtk.Align.CENTER; + button_home.clicked.connect (() => { + browser.go_home (); + }); + headerbar.pack_start (button_home); + + button_forward = new Gtk.Button.from_icon_name ("go-next-symbolic", Gtk.IconSize.MENU); + button_forward.tooltip_text = _("Forward"); + button_forward.sensitive = false; + button_forward.valign = Gtk.Align.CENTER; + button_forward.clicked.connect (() => { + browser.go_forward (); + }); + headerbar.pack_start (button_forward); + + var button_refresh = new Gtk.Button.from_icon_name ("view-refresh-symbolic", Gtk.IconSize.MENU); + button_refresh.tooltip_text = _("Reload"); + button_refresh.valign = Gtk.Align.CENTER; + button_refresh.clicked.connect (() => { + browser.reload (); + }); + headerbar.pack_start (button_refresh); + } + + private void header_build_copy_button () { + var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU); + copy_url.valign = Gtk.Align.CENTER; + copy_url.tooltip_text = _ ("Copy URL into clipboard"); + copy_url.clicked.connect (() => { + Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (browser.web_view.uri, -1); + }); + headerbar.pack_end (copy_url); + } + + private void header_build_pin_button () { + var stay_open = new Gtk.ToggleButton (); + stay_open.valign = Gtk.Align.CENTER; + stay_open.active = desktop_file.hide_on_close; + stay_open.tooltip_text = _ ("Run in background if closed"); + stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU); + stay_open.toggled.connect (() => { + desktop_file.edit_property ("X-Webpin-StayOpen", stay_open.active.to_string ()); + desktop_file.save_to_file (); + }); + headerbar.pack_end (stay_open); + } + private void set_color (Gdk.RGBA color) { var mid = color.red + color.blue + color.green; color.alpha = 1;