This commit is contained in:
Artem Anufrij 2018-11-03 15:41:59 +01:00
parent d61c4b0b7f
commit 4901b46257
3 changed files with 138 additions and 99 deletions

View file

@ -44,6 +44,7 @@ namespace Webpin {
X-GNOME-UsesNotifications=true X-GNOME-UsesNotifications=true
StartupWMClass=Webpin StartupWMClass=Webpin
X-Webpin-PrimaryColor=rgba (222,222,222,1) X-Webpin-PrimaryColor=rgba (222,222,222,1)
X-Webpin-View-Mode=default
Actions=Remove; Actions=Remove;
[Desktop Action 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.name = name;
this.url = url.replace ("%", "%%"); this.url = url.replace ("%", "%%");
this.icon = icon; this.icon = icon;
@ -119,6 +136,7 @@ namespace Webpin {
file.set_string ("Desktop Entry", "Icon", icon); file.set_string ("Desktop Entry", "Icon", icon);
file.set_string ("Desktop Entry", "StartupWMClass", url); 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-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); file.set_string ("Desktop Action Remove", "Exec", "com.github.artemanufrij.webpin --remove " + url);
} }

View file

@ -41,6 +41,7 @@ namespace Webpin.Widgets.Views {
Gtk.CheckButton save_cookies_check; Gtk.CheckButton save_cookies_check;
Gtk.CheckButton save_password_check; Gtk.CheckButton save_password_check;
Gtk.CheckButton stay_open_when_closed; Gtk.CheckButton stay_open_when_closed;
Gtk.CheckButton minimal_view_mode;
Gtk.Popover icon_selector_popover; Gtk.Popover icon_selector_popover;
Gtk.FileChooserDialog file_chooser; Gtk.FileChooserDialog file_chooser;
Gtk.Button accept_button; Gtk.Button accept_button;
@ -119,8 +120,7 @@ namespace Webpin.Widgets.Views {
primary_color_button = new Gtk.ColorButton.with_rgba (default_color); primary_color_button = new Gtk.ColorButton.with_rgba (default_color);
primary_color_button.use_alpha = false; primary_color_button.use_alpha = false;
primary_color_button.color_activated.connect ( primary_color_button.color_activated.connect ((color) => {
(color) => {
stdout.printf ("COLOR %s\n", color.to_string ()); stdout.printf ("COLOR %s\n", color.to_string ());
}); });
@ -131,6 +131,9 @@ namespace Webpin.Widgets.Views {
save_password_check.active = false; save_password_check.active = false;
stay_open_when_closed = new Gtk.CheckButton.with_label (_ ("Run in background if closed")); stay_open_when_closed = new Gtk.CheckButton.with_label (_ ("Run in background if closed"));
stay_open_when_closed.active = false; 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 //app information section
var app_input_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 5); 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_cookies_check, true, false, 0);
app_options_box.pack_start (save_password_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 (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; app_options_box.halign = Gtk.Align.CENTER;
//create button //create button
@ -166,13 +170,11 @@ namespace Webpin.Widgets.Views {
pack_end (accept_button, false, false, 0); pack_end (accept_button, false, false, 0);
//signals and handlers //signals and handlers
icon_button.clicked.connect ( icon_button.clicked.connect (() => {
() => {
icon_selector_popover.show_all (); icon_selector_popover.show_all ();
}); });
app_url_entry.changed.connect ( app_url_entry.changed.connect (() => {
() => {
if (!this.protocol_regex.match (app_url_entry.get_text ())) { if (!this.protocol_regex.match (app_url_entry.get_text ())) {
reset_grab_color_and_icon (); reset_grab_color_and_icon ();
app_url_entry.get_style_context ().add_class ("error"); app_url_entry.get_style_context ().add_class ("error");
@ -188,8 +190,7 @@ namespace Webpin.Widgets.Views {
validate (); validate ();
}); });
app_name_entry.changed.connect ( app_name_entry.changed.connect (() => {
() => {
if (mode == assistant_mode.new_app && Services.DesktopFilesManager.get_applications ().has_key (app_name_entry.get_text ())) { 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.get_style_context ().add_class ("error");
app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information"); app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information");
@ -502,14 +503,13 @@ namespace Webpin.Widgets.Views {
} }
string name = app_name_entry.get_text (); string name = app_name_entry.get_text ();
string url = app_url_entry.get_text ().replace ("%", "%%"); string url = app_url_entry.get_text ().replace ("%", "%%");
bool stay_open = stay_open_when_closed.active;
if (icon == "") { if (icon == "") {
icon = default_app_icon; icon = default_app_icon;
} }
if (app_icon_valid && app_name_valid && app_url_valid) { 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) { switch (mode) {
case assistant_mode.new_app : case assistant_mode.new_app :
application_created (desktop_file.save_to_file ()); application_created (desktop_file.save_to_file ());
@ -533,6 +533,7 @@ namespace Webpin.Widgets.Views {
app_url_entry.text = desktop_file.url.replace ("%%", "%"); app_url_entry.text = desktop_file.url.replace ("%%", "%");
icon_name_entry.text = desktop_file.icon; icon_name_entry.text = desktop_file.icon;
stay_open_when_closed.active = desktop_file.hide_on_close; stay_open_when_closed.active = desktop_file.hide_on_close;
minimal_view_mode.active = desktop_file.view_mode == "minimal";
if (desktop_file.color != null) { if (desktop_file.color != null) {
primary_color_button.set_rgba (desktop_file.color); primary_color_button.set_rgba (desktop_file.color);
} else { } else {

View file

@ -30,6 +30,9 @@ namespace Webpin.Windows {
public class WebApp : Gtk.Window { public class WebApp : Gtk.Window {
Gdk.WindowState current_state; Gdk.WindowState current_state;
Gtk.HeaderBar headerbar;
Gtk.Button button_back;
Gtk.Button button_forward;
Widgets.Browser browser; Widgets.Browser browser;
Gtk.Spinner spinner; Gtk.Spinner spinner;
@ -46,67 +49,25 @@ namespace Webpin.Windows {
} }
browser = new Widgets.Browser (desktop_file); browser = new Widgets.Browser (desktop_file);
var headerbar = new Gtk.HeaderBar (); headerbar = new Gtk.HeaderBar ();
headerbar.title = desktop_file.name; headerbar.title = desktop_file.name;
headerbar.show_close_button = true; headerbar.show_close_button = true;
headerbar.get_style_context ().add_class ("default-decoration"); headerbar.get_style_context ().add_class ("default-decoration");
var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU); if (desktop_file.view_mode == "default") {
copy_url.valign = Gtk.Align.CENTER; header_build_copy_button ();
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);
var stay_open = new Gtk.ToggleButton (); header_build_pin_button ();
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);
spinner = new Gtk.Spinner (); spinner = new Gtk.Spinner ();
spinner.set_size_request (16, 16); spinner.set_size_request (16, 16);
headerbar.pack_end (spinner); headerbar.pack_end (spinner);
var button_back = new Gtk.Button.from_icon_name ("go-previous-symbolic", Gtk.IconSize.MENU); if (desktop_file.view_mode == "default") {
button_back.tooltip_text = _("Back"); header_build_navi_buttons ();
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);
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.set_titlebar (headerbar);
this.delete_event.connect (() => { 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) { private void set_color (Gdk.RGBA color) {
var mid = color.red + color.blue + color.green; var mid = color.red + color.blue + color.green;
color.alpha = 1; color.alpha = 1;