add most of the functionality from the python version
This commit is contained in:
parent
819522f1a2
commit
dec437969c
|
@ -5,6 +5,29 @@ namespace Deskcandy {
|
|||
|
||||
public Application() {
|
||||
Object(application_id: "moe.solarpunk.Deskcandy");
|
||||
|
||||
var xwinwrap_enabled_prop = new PropertyAction("xwinwrap-enabled", this, "xwinwrap-enabled");
|
||||
xwinwrap_enabled_prop.notify.connect(this.on_xwinwrap_enabled_changed);
|
||||
|
||||
this.set_up_actions();
|
||||
}
|
||||
|
||||
private void on_xwinwrap_enabled_changed() {
|
||||
}
|
||||
|
||||
private void set_up_actions() {
|
||||
var a_about = new SimpleAction("about", null);
|
||||
a_about.activate.connect((widget) => {
|
||||
var about_dialog = new Gtk.AboutDialog();
|
||||
about_dialog.destroy_with_parent = true;
|
||||
about_dialog.transient_for = this.window;
|
||||
about_dialog.modal = true;
|
||||
});
|
||||
this.add_action(a_about);
|
||||
|
||||
var a_quit = new SimpleAction("quit", null);
|
||||
a_quit.activate.connect(this.quit);
|
||||
this.add_action(a_quit);
|
||||
}
|
||||
|
||||
public override void activate() {
|
||||
|
|
|
@ -3,15 +3,92 @@ using GLib;
|
|||
namespace Deskcandy {
|
||||
[GtkTemplate (ui = "/moe/solarpunk/Deskcandy/window.ui")]
|
||||
public class Window : Gtk.ApplicationWindow {
|
||||
private Gtk.Socket socket;
|
||||
|
||||
[GtkChild]
|
||||
private unowned Gtk.Switch enabler_toggle;
|
||||
[GtkChild]
|
||||
private unowned Gtk.MenuButton open_menu_button;
|
||||
[GtkChild]
|
||||
private unowned Gtk.Box preview;
|
||||
[GtkChild]
|
||||
private unowned Gtk.HeaderBar headerbar;
|
||||
[GtkChild]
|
||||
private unowned Gtk.Stack main_stack;
|
||||
|
||||
public Window (Gtk.Application app) {
|
||||
Object (application: app);
|
||||
|
||||
var preset_action_group = new SimpleActionGroup();
|
||||
var create_preset = new SimpleAction("create", null);
|
||||
preset_action_group.add_action(create_preset);
|
||||
create_preset.activate.connect(this.on_create_preset);
|
||||
var delete_preset = new SimpleAction("delete", null);
|
||||
delete_preset.activate.connect(this.on_delete_preset);
|
||||
preset_action_group.add_action(delete_preset);
|
||||
|
||||
this.insert_action_group("presets", preset_action_group);
|
||||
|
||||
var builder = new Gtk.Builder.from_resource("/moe/solarpunk/Deskcandy/main_menu.ui");
|
||||
var menu = (GLib.MenuModel)builder.get_object("main_menu");
|
||||
this.open_menu_button.menu_model = menu;
|
||||
|
||||
app.connect("notify::xwinwrap-enabled", this.on_notify_xwinwrap_enabled);
|
||||
|
||||
this.refresh_socket();
|
||||
}
|
||||
|
||||
private void refresh_socket() {
|
||||
if (this.socket != null) {
|
||||
this.preview.remove(this.socket);
|
||||
}
|
||||
|
||||
this.socket = new Gtk.Socket();
|
||||
this.socket.expand = true;
|
||||
this.socket.visible = true;
|
||||
this.preview.add(this.socket);
|
||||
|
||||
try {
|
||||
var subprocess = new Subprocess(SubprocessFlags.NONE, "/usr/lib64/misc/xscreensaver/abstractile", "-window-id", ((uint)this.socket.get_id()).to_string());
|
||||
} catch (Error e) {
|
||||
error(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void on_window_destroy(Gtk.Widget self) {
|
||||
private void on_window_destroy(Gtk.Widget w) {
|
||||
message("bye");
|
||||
this.application.quit();
|
||||
}
|
||||
|
||||
private void on_create_preset(SimpleAction a, Variant? v) {
|
||||
this.main_stack.visible_child_name = "editor_page";
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void on_cancel_edit_preset_button_clicked(Gtk.Widget w) {
|
||||
this.main_stack.visible_child_name = "presets_page";
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void on_cancel_new_preset_button_clicked(Gtk.Widget w) {
|
||||
var popover = (Gtk.Popover)w.get_ancestor(typeof(Gtk.Popover));
|
||||
popover.popdown();
|
||||
this.main_stack.visible_child_name = "presets_page";
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void on_cancel_delete_preset_button_clicked(Gtk.Widget w) {
|
||||
var popover = (Gtk.Popover)w.get_ancestor(typeof(Gtk.Popover));
|
||||
popover.popdown();
|
||||
}
|
||||
|
||||
private void on_delete_preset(SimpleAction a, Variant? v) {
|
||||
message("delete");
|
||||
}
|
||||
|
||||
private void on_notify_xwinwrap_enabled(Gtk.Widget w, Gtk.Application app, GLib.PropertyAction prop) {
|
||||
this.headerbar.subtitle = prop.enabled ? "started" : "stopped";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue