~donadigo/power-installer/power-installer-legacy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
/* Copyright (c) 2014 Adam Bieńkowski (http://launchpad.net/power-installer)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authored by: Corentin Noel <tintou@mailoo.org>
 */

// all of the "recognize and install" work is
// done by bash scripts...

// main file
// contains main Gtk.Window

using GLib;
using Gtk;
using Granite.Services;

namespace PowerInstaller {

    // resources
    public const string DATADIR = Constants.PKGDATADIR;

    // dont show window when API initialized
    private bool dont_show_window;

    // at the end try to delete password file
    private void try_delete_pass() {
        execute_command_sync(@"rm -f /tmp/.pulse-shm-tmp.PI");
    }

    public class Window : Gtk.Window {
        private Gtk.Stack main_stack;
        private Gtk.StackSwitcher stack_switcher;

        public Window() {
            this.title = "Power Installer";
            this.window_position = Gtk.WindowPosition.CENTER;
            this.set_resizable(false);
            this.border_width = 6;
            this.set_default_size(380, 400);
            create_widgets();
        }

        private void create_widgets() {
            // main box
            var main_grid = new Gtk.Grid();


            var header = new Gtk.HeaderBar();
            header.set_title("Power Installer");
            header.set_show_close_button(true);

            var mini = new Gtk.Image();
            mini.set_from_file(DATADIR + "/miniature.svg");
			header.pack_end(mini);

            this.set_titlebar(header);

            // stack
            main_stack = new Gtk.Stack();
            main_stack.set_hexpand(true);
            main_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT);

            // stack switcher
            stack_switcher = new Gtk.StackSwitcher();
            stack_switcher.stack = main_stack;
            stack_switcher.halign = Gtk.Align.CENTER;
            stack_switcher.margin_top = 2;

            // add tabs to dialog
            var general_tab = new GeneralTab();
            general_tab.expand = true;

            var command_tab = new CommandTab();
            command_tab.expand = true;

            var actions_tab = new ActionsTab();
            actions_tab.expand = true;

            main_stack.add_titled(general_tab, "general", _("General"));
            main_stack.add_titled(command_tab, "commands", _("Commands"));
            main_stack.add_titled(actions_tab, "actions", _("Actions"));

            // add stack and stack switcher to main grid
            main_grid.add(stack_switcher);
            main_grid.attach(main_stack, 0, 1, 1, 1);
            main_grid.show_all();
            this.add(main_grid);
        }
    }

// main class (Granite.Application)
public class PowerInstallerApp : Granite.Application {
    public const string PROGRAM_NAME = "Power Installer";

    construct {
        program_name = PROGRAM_NAME;
        exec_name = "power-installer";

        build_data_dir = Constants.DATADIR;
        build_pkg_data_dir = Constants.PKGDATADIR;
        build_release_name = Constants.RELEASE_NAME;
        build_version = Constants.VERSION;
        build_version_info = Constants.VERSION_INFO;

        app_years = "2014-2015";
        app_icon = "power-installer";
        app_launcher = "power-installer.desktop";
        application_id = "org.power-installer";

        main_url = "https://launchpad.net/power-installer";
        bug_url = "https://bugs.launchpad.net/power-installer";
        help_url = "https://code.launchpad.net/power-installer";
        translate_url = "https://translations.launchpad.net/power-installer";

        about_authors = { "Adam Bieńkowski <donadigos159@gmail.com>" };
        about_documenters = { "Adam Bieńkowski <donadigos159@gmail.com>" };
        about_artists = { "Adam Bieńkowski <donadigos159@gmail.com>" };
        about_comments = "Power Installer let's you install things
quickly on Ubuntu based distributions.";
        about_translators = "";

        about_license_type = Gtk.License.GPL_3_0;
    }

    public PowerInstallerApp() {
        Logger.initialize(exec_name);
        Logger.DisplayLevel = LogLevel.DEBUG;
    }

    public static int main(string[] args) {
        Gtk.init(ref args);
        dont_show_window = false;

        if(args.length > 0) {
            var api = new API();
            var general_tab = new GeneralTab();

            foreach(string file in args) {
                string? init_api = GLib.Environment.get_variable("INIT_API");
                // get_variable returns string instead of bool
                if(init_api == "true") {
                    api.init();
                    dont_show_window = true;
                }

                // first argument is always the invocation of the program itself
                if(file != args[0]) {
                    general_tab.execute(file, false, false, false);
                } else {
                    continue;
                }
            }
        }
            // run app
            var app = new PowerInstallerApp();
            return app.run(args);
        }

        public override void activate() {
            try_delete_pass();
            if(dont_show_window == false) {
                var window = new Window();
                window.destroy.connect(try_delete_pass);
                window.destroy.connect(Gtk.main_quit);
                window.show_all();
                Gtk.main();
            }
        }
    }
}