fix#82
This commit is contained in:
parent
d61c4b0b7f
commit
4901b46257
3 changed files with 138 additions and 99 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,10 +120,9 @@ 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 ());
|
});
|
||||||
});
|
|
||||||
|
|
||||||
//checkbuttons
|
//checkbuttons
|
||||||
save_cookies_check = new Gtk.CheckButton.with_label (_ ("Save cookies"));
|
save_cookies_check = new Gtk.CheckButton.with_label (_ ("Save cookies"));
|
||||||
|
@ -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
|
||||||
|
@ -160,48 +164,45 @@ namespace Webpin.Widgets.Views {
|
||||||
accept_button.clicked.connect (on_accept);
|
accept_button.clicked.connect (on_accept);
|
||||||
|
|
||||||
//all sections together
|
//all sections together
|
||||||
pack_start (message, true, false, 0);
|
pack_start (message, true, false, 0);
|
||||||
pack_start (app_info_box, true, false, 0);
|
pack_start (app_info_box, true, false, 0);
|
||||||
pack_start (app_options_box, true, false, 0);
|
pack_start (app_options_box, true, false, 0);
|
||||||
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");
|
app_url_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information");
|
||||||
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_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _ ("url must start with http:// or https:// or file:///"));
|
app_url_valid = false;
|
||||||
app_url_valid = false;
|
} else {
|
||||||
} else {
|
grab_color_and_icon ();
|
||||||
grab_color_and_icon ();
|
app_url_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, null);
|
||||||
app_url_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, null);
|
app_url_entry.get_style_context ().remove_class ("error");
|
||||||
app_url_entry.get_style_context ().remove_class ("error");
|
app_url_valid = true;
|
||||||
app_url_valid = true;
|
}
|
||||||
}
|
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");
|
app_name_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _ ("App already exist"));
|
||||||
app_name_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _ ("App already exist"));
|
app_name_valid = false;
|
||||||
app_name_valid = false;
|
} else {
|
||||||
} else {
|
app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, null);
|
||||||
app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, null);
|
app_name_entry.get_style_context ().remove_class ("error");
|
||||||
app_name_entry.get_style_context ().remove_class ("error");
|
app_name_valid = true;
|
||||||
app_name_valid = true;
|
}
|
||||||
}
|
validate ();
|
||||||
validate ();
|
});
|
||||||
});
|
|
||||||
|
|
||||||
icon_chooser_button.activate.connect (on_icon_chooser_activate);
|
icon_chooser_button.activate.connect (on_icon_chooser_activate);
|
||||||
icon_chooser_button.clicked.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 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 ());
|
||||||
break;
|
break;
|
||||||
case assistant_mode.edit_app :
|
case assistant_mode.edit_app :
|
||||||
application_edited (desktop_file.save_to_file ());
|
application_edited (desktop_file.save_to_file ());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stdout.printf ("Custom Color %s\n", primary_color_button.rgba.to_string ());
|
stdout.printf ("Custom Color %s\n", primary_color_button.rgba.to_string ());
|
||||||
desktop_file.color = primary_color_button.rgba;
|
desktop_file.color = primary_color_button.rgba;
|
||||||
|
@ -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 {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue