2017-07-31 21:14:19 +01:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2015 Erasmo Marín <erasmo.marin@gmail.com>
|
|
|
|
* Copyright (c) 2017-2017 Artem Anufrij <artem.anufrij@live.de>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* 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 <artem.anufrij@live.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Webpin {
|
2017-09-02 23:54:07 +01:00
|
|
|
public class WebWindow : Gtk.Window {
|
2017-07-31 21:14:19 +01:00
|
|
|
|
|
|
|
private bool is_full_screen = false;
|
|
|
|
|
|
|
|
//widgets
|
|
|
|
private WebApp web_app;
|
|
|
|
|
2017-08-11 17:58:46 +01:00
|
|
|
Gtk.Spinner spinner;
|
|
|
|
|
2017-09-02 23:54:07 +01:00
|
|
|
public DesktopFile desktop_file { get; private set; }
|
2017-07-31 21:14:19 +01:00
|
|
|
|
2017-09-02 23:54:07 +01:00
|
|
|
public WebWindow (DesktopFile desktop_file) {
|
|
|
|
this.desktop_file = desktop_file;
|
|
|
|
this.events |= Gdk.EventMask.STRUCTURE_MASK;
|
|
|
|
|
2017-09-05 19:37:48 +01:00
|
|
|
set_wmclass (desktop_file.url, desktop_file.url);
|
|
|
|
web_app = new WebApp (desktop_file.url);
|
2017-07-31 21:14:19 +01:00
|
|
|
|
2017-08-10 20:12:33 +01:00
|
|
|
var headerbar = new Gtk.HeaderBar ();
|
2017-09-02 23:54:07 +01:00
|
|
|
headerbar.title = desktop_file.name;
|
2017-08-10 20:18:37 +01:00
|
|
|
headerbar.show_close_button = true;
|
2017-08-11 17:58:46 +01:00
|
|
|
|
2017-10-15 18:45:04 +01:00
|
|
|
var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU);
|
2017-10-15 18:26:23 +01:00
|
|
|
copy_url.tooltip_text = _("Copy URI into clipboard");
|
|
|
|
copy_url.clicked.connect (() => {
|
|
|
|
Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (web_app.app_view.uri, -1);
|
|
|
|
});
|
|
|
|
headerbar.pack_end (copy_url);
|
|
|
|
|
2017-08-11 17:58:46 +01:00
|
|
|
spinner = new Gtk.Spinner ();
|
|
|
|
spinner.set_size_request (16, 16);
|
|
|
|
headerbar.pack_end (spinner);
|
2017-09-07 19:01:06 +01:00
|
|
|
|
2017-09-03 18:16:39 +01:00
|
|
|
var stay_open = new Gtk.ToggleButton ();
|
|
|
|
stay_open.active = desktop_file.hide_on_close;
|
2017-09-03 18:19:30 +01:00
|
|
|
stay_open.tooltip_text = _("Run in background when closed");
|
|
|
|
stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU);
|
2017-09-03 18:16:39 +01:00
|
|
|
stay_open.toggled.connect (() => {
|
|
|
|
desktop_file.edit_propertie ("WebpinStayOpen", stay_open.active.to_string ());
|
|
|
|
desktop_file.save_to_file ();
|
|
|
|
});
|
|
|
|
headerbar.pack_start (stay_open);
|
2017-08-11 17:58:46 +01:00
|
|
|
|
2017-07-31 21:14:19 +01:00
|
|
|
this.set_titlebar (headerbar);
|
2017-07-31 19:27:03 +01:00
|
|
|
|
2017-09-02 23:54:07 +01:00
|
|
|
var width = desktop_file.info.get_string ("WebpinWindowWidth");
|
|
|
|
var height = desktop_file.info.get_string ("WebpinWindowHeight");
|
|
|
|
var state = desktop_file.info.get_string ("WebpinWindowMaximized");
|
|
|
|
var zoom = desktop_file.info.get_string ("WebpinWindowZoom");
|
2017-08-11 20:13:39 +01:00
|
|
|
|
2017-08-11 20:16:18 +01:00
|
|
|
if (width != null && height != null) {
|
2017-08-11 20:13:39 +01:00
|
|
|
set_default_size (int.parse(width), int.parse(height));
|
|
|
|
} else {
|
|
|
|
set_default_size (1000, 600);
|
|
|
|
}
|
2017-07-31 19:27:03 +01:00
|
|
|
|
2017-08-11 20:16:18 +01:00
|
|
|
if (state != null && state == "max") {
|
|
|
|
this.maximize ();
|
|
|
|
}
|
|
|
|
|
2017-08-16 18:25:01 +01:00
|
|
|
if (zoom != null) {
|
|
|
|
web_app.app_view.zoom_level = double.parse (zoom);
|
|
|
|
}
|
|
|
|
|
2017-07-31 21:14:19 +01:00
|
|
|
this.delete_event.connect (() => {
|
2017-08-11 20:13:39 +01:00
|
|
|
update_window_state(this.get_allocated_width (), this.get_allocated_height (), this.is_maximized);
|
2017-09-02 23:54:07 +01:00
|
|
|
if (desktop_file.hide_on_close) {
|
2017-09-03 18:16:39 +01:00
|
|
|
this.hide_on_delete ();
|
2017-09-02 23:54:07 +01:00
|
|
|
}
|
|
|
|
return desktop_file.hide_on_close;
|
2017-08-11 20:13:39 +01:00
|
|
|
});
|
2017-07-31 19:27:03 +01:00
|
|
|
|
2017-08-10 20:12:33 +01:00
|
|
|
web_app.external_request.connect ((action) => {
|
|
|
|
debug ("Web app external request: %s", action.get_request ().uri);
|
|
|
|
try {
|
|
|
|
Process.spawn_command_line_async ("xdg-open " + action.get_request ().uri);
|
|
|
|
} catch (Error e) {
|
|
|
|
warning (e.message);
|
|
|
|
}
|
2017-07-31 21:14:19 +01:00
|
|
|
});
|
2017-07-31 19:27:03 +01:00
|
|
|
|
2017-09-10 20:18:06 +01:00
|
|
|
web_app.desktop_notification.connect ((title, body, icon) => {
|
2017-09-10 21:51:20 +01:00
|
|
|
var desktop_notification = new Notification (title);
|
2017-09-10 20:18:06 +01:00
|
|
|
desktop_notification.set_body (body);
|
|
|
|
desktop_notification.set_icon (icon);
|
2017-09-10 21:51:20 +01:00
|
|
|
desktop_notification.add_button_with_target_value (_("Open %s").printf (desktop_file.name), "app.open-web-app", new GLib.Variant.string (desktop_file.url));
|
2017-09-10 20:18:06 +01:00
|
|
|
WebpinApp.instance.send_notification (null, desktop_notification);
|
2017-09-07 19:01:06 +01:00
|
|
|
});
|
|
|
|
|
2017-08-11 17:58:46 +01:00
|
|
|
web_app.request_begin.connect (() => {
|
|
|
|
spinner.active = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
web_app.request_finished.connect (() => {
|
|
|
|
spinner.active = false;
|
|
|
|
});
|
|
|
|
|
2017-07-31 21:14:19 +01:00
|
|
|
add(web_app);
|
|
|
|
show_all();
|
|
|
|
}
|
2017-07-31 19:27:03 +01:00
|
|
|
|
2017-07-31 21:14:19 +01:00
|
|
|
public new void fullscreen () {
|
|
|
|
is_full_screen = true;
|
|
|
|
base.fullscreen();
|
|
|
|
}
|
2017-07-31 19:27:03 +01:00
|
|
|
|
2017-07-31 21:14:19 +01:00
|
|
|
public new void unfullscreen () {
|
|
|
|
is_full_screen = false;
|
|
|
|
base.unfullscreen();
|
|
|
|
}
|
2017-07-31 19:27:03 +01:00
|
|
|
|
2017-07-31 21:14:19 +01:00
|
|
|
public void toggle_fullscreen() {
|
2017-09-05 19:37:48 +01:00
|
|
|
if(is_full_screen) {
|
2017-07-31 21:14:19 +01:00
|
|
|
unfullscreen();
|
2017-09-05 19:37:48 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-07-31 21:14:19 +01:00
|
|
|
fullscreen();
|
2017-09-05 19:37:48 +01:00
|
|
|
}
|
2017-07-31 21:14:19 +01:00
|
|
|
is_full_screen = !is_full_screen;
|
2017-07-31 19:27:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-11 20:16:18 +01:00
|
|
|
public void update_window_state (int width, int height, bool is_maximized) {
|
|
|
|
var file = web_app.get_desktop_file();
|
|
|
|
|
|
|
|
if (is_maximized) {
|
|
|
|
file.edit_propertie ("WebpinWindowMaximized", "max");
|
|
|
|
} else {
|
|
|
|
file.edit_propertie ("WebpinWindowWidth", width.to_string());
|
|
|
|
file.edit_propertie ("WebpinWindowHeight", height.to_string());
|
|
|
|
file.edit_propertie ("WebpinWindowMaximized", "norm");
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 21:14:19 +01:00
|
|
|
|
|
|
|
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;
|
2017-08-16 18:25:01 +01:00
|
|
|
case Gdk.Key.KP_Add:
|
|
|
|
case Gdk.Key.plus:
|
|
|
|
if (Gdk.ModifierType.CONTROL_MASK in event.state) {
|
|
|
|
web_app.app_view.zoom_level += 0.1;
|
|
|
|
web_app.get_desktop_file().edit_propertie ("WebpinWindowZoom", web_app.app_view.zoom_level.to_string ());
|
2017-08-16 18:27:51 +01:00
|
|
|
} else {
|
|
|
|
handled = false;
|
2017-08-16 18:25:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Gdk.Key.KP_Subtract:
|
|
|
|
case Gdk.Key.minus:
|
|
|
|
if (Gdk.ModifierType.CONTROL_MASK in event.state) {
|
|
|
|
web_app.app_view.zoom_level -= 0.1;
|
|
|
|
web_app.get_desktop_file().edit_propertie ("WebpinWindowZoom", web_app.app_view.zoom_level.to_string ());
|
2017-08-16 18:27:51 +01:00
|
|
|
} else {
|
|
|
|
handled = false;
|
2017-08-16 18:25:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Gdk.Key.KP_0:
|
|
|
|
case Gdk.Key.@0:
|
|
|
|
if (Gdk.ModifierType.CONTROL_MASK in event.state) {
|
|
|
|
web_app.app_view.zoom_level = 1;
|
|
|
|
web_app.get_desktop_file().edit_propertie ("WebpinWindowZoom", web_app.app_view.zoom_level.to_string ());
|
2017-08-16 18:27:51 +01:00
|
|
|
} else {
|
|
|
|
handled = false;
|
2017-08-16 18:25:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-08-11 19:48:53 +01:00
|
|
|
case Gdk.Key.F5:
|
|
|
|
if (Gdk.ModifierType.CONTROL_MASK in event.state) {
|
|
|
|
web_app.app_view.reload ();
|
|
|
|
} else {
|
|
|
|
web_app.app_view.reload_bypass_cache ();
|
|
|
|
}
|
|
|
|
break;
|
2017-08-11 19:05:11 +01:00
|
|
|
case Gdk.Key.Left:
|
|
|
|
if (Gdk.ModifierType.MOD1_MASK in event.state) {
|
|
|
|
web_app.app_view.go_back ();
|
2017-08-11 19:13:26 +01:00
|
|
|
} else {
|
|
|
|
handled = false;
|
2017-08-11 19:05:11 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Gdk.Key.Right:
|
|
|
|
if (Gdk.ModifierType.MOD1_MASK in event.state) {
|
|
|
|
web_app.app_view.go_forward ();
|
2017-08-11 19:13:26 +01:00
|
|
|
} else {
|
|
|
|
handled = false;
|
2017-08-11 19:05:11 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-07-31 21:14:19 +01:00
|
|
|
default:
|
|
|
|
handled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handled)
|
|
|
|
return true;
|
2017-07-31 19:27:03 +01:00
|
|
|
|
2017-07-31 22:49:48 +01:00
|
|
|
return (base.key_press_event != null) ? base.key_press_event (event) : true;
|
2017-07-31 21:14:19 +01:00
|
|
|
}
|
2017-07-31 19:27:03 +01:00
|
|
|
}
|
|
|
|
}
|