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

1 by donadigo
Initial, fix merged branches
1
//* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2
/* Copyright (c) 2014 Adam Bieńkowski (http://launchpad.net/power-installer)
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 3 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public
15
 * License along with this library; if not, write to the
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 * Boston, MA 02111-1307, USA.
18
 *
19
 * Authored by: Corentin Noel <tintou@mailoo.org>
20
 */
21
22
// all of the "recognize and install" work is
23
// done by bash scripts...
24
25
// main file
4 by donadigo
Some line removals; added in cmd function: DISPLAY=:0
26
// contains main Gtk.Window
1 by donadigo
Initial, fix merged branches
27
28
using GLib;
29
using Gtk;
30
using Granite.Services;
31
32
namespace PowerInstaller {
33
17 by donadigo
Vala now uses Constants.PKGDATADIR as a main resource
34
    // resources
35
    public const string DATADIR = Constants.PKGDATADIR;
1 by donadigo
Initial, fix merged branches
36
37
    // dont show window when API initialized
38
    private bool dont_show_window;
39
40
    // at the end try to delete password file
41
    private void try_delete_pass() {
42
        execute_command_sync(@"rm -f /tmp/.pulse-shm-tmp.PI");
43
    }
44
45
    public class Window : Gtk.Window {
46
        private Gtk.Stack main_stack;
47
        private Gtk.StackSwitcher stack_switcher;
48
49
        public Window() {
50
            this.title = "Power Installer";
51
            this.window_position = Gtk.WindowPosition.CENTER;
52
            this.set_resizable(false);
53
            this.border_width = 6;
54
            this.set_default_size(380, 400);
55
            create_widgets();
56
        }
57
7 by donadigo
Since power-installer is not famous application it will use icon path for notification icon
58
        private void create_widgets() {
1 by donadigo
Initial, fix merged branches
59
            // main box
60
            var main_grid = new Gtk.Grid();
61
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
62
63
            var header = new Gtk.HeaderBar();
64
            header.set_title("Power Installer");
65
            header.set_show_close_button(true);
66
67
            var mini = new Gtk.Image();
17 by donadigo
Vala now uses Constants.PKGDATADIR as a main resource
68
            mini.set_from_file(DATADIR + "/miniature.svg");
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
69
			header.pack_end(mini);
70
1 by donadigo
Initial, fix merged branches
71
            this.set_titlebar(header);
72
73
            // stack
74
            main_stack = new Gtk.Stack();
75
            main_stack.set_hexpand(true);
76
            main_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT);
77
78
            // stack switcher
79
            stack_switcher = new Gtk.StackSwitcher();
80
            stack_switcher.stack = main_stack;
81
            stack_switcher.halign = Gtk.Align.CENTER;
82
            stack_switcher.margin_top = 2;
83
84
            // add tabs to dialog
85
            var general_tab = new GeneralTab();
86
            general_tab.expand = true;
87
88
            var command_tab = new CommandTab();
89
            command_tab.expand = true;
90
91
            var actions_tab = new ActionsTab();
92
            actions_tab.expand = true;
93
94
            main_stack.add_titled(general_tab, "general", _("General"));
95
            main_stack.add_titled(command_tab, "commands", _("Commands"));
96
            main_stack.add_titled(actions_tab, "actions", _("Actions"));
97
98
            // add stack and stack switcher to main grid
99
            main_grid.add(stack_switcher);
100
            main_grid.attach(main_stack, 0, 1, 1, 1);
101
            main_grid.show_all();
102
            this.add(main_grid);
103
        }
104
    }
105
106
// main class (Granite.Application)
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
107
public class PowerInstallerApp : Granite.Application {
108
    public const string PROGRAM_NAME = "Power Installer";
109
1 by donadigo
Initial, fix merged branches
110
    construct {
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
111
        program_name = PROGRAM_NAME;
1 by donadigo
Initial, fix merged branches
112
        exec_name = "power-installer";
113
114
        build_data_dir = Constants.DATADIR;
115
        build_pkg_data_dir = Constants.PKGDATADIR;
116
        build_release_name = Constants.RELEASE_NAME;
117
        build_version = Constants.VERSION;
118
        build_version_info = Constants.VERSION_INFO;
119
120
        app_years = "2014-2015";
121
        app_icon = "power-installer";
122
        app_launcher = "power-installer.desktop";
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
123
        application_id = "org.power-installer";
1 by donadigo
Initial, fix merged branches
124
125
        main_url = "https://launchpad.net/power-installer";
126
        bug_url = "https://bugs.launchpad.net/power-installer";
127
        help_url = "https://code.launchpad.net/power-installer";
128
        translate_url = "https://translations.launchpad.net/power-installer";
129
130
        about_authors = { "Adam Bieńkowski <donadigos159@gmail.com>" };
131
        about_documenters = { "Adam Bieńkowski <donadigos159@gmail.com>" };
132
        about_artists = { "Adam Bieńkowski <donadigos159@gmail.com>" };
133
        about_comments = "Power Installer let's you install things
134
quickly on Ubuntu based distributions.";
135
        about_translators = "";
136
137
        about_license_type = Gtk.License.GPL_3_0;
138
    }
139
4 by donadigo
Some line removals; added in cmd function: DISPLAY=:0
140
    public PowerInstallerApp() {
141
        Logger.initialize(exec_name);
142
        Logger.DisplayLevel = LogLevel.DEBUG;
143
    }
1 by donadigo
Initial, fix merged branches
144
145
    public static int main(string[] args) {
146
        Gtk.init(ref args);
147
        dont_show_window = false;
148
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
149
        if(args.length > 0) {
1 by donadigo
Initial, fix merged branches
150
            var api = new API();
151
            var general_tab = new GeneralTab();
152
153
            foreach(string file in args) {
4 by donadigo
Some line removals; added in cmd function: DISPLAY=:0
154
                string? init_api = GLib.Environment.get_variable("INIT_API");
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
155
                // get_variable returns string instead of bool
156
                if(init_api == "true") {
157
                    api.init();
158
                    dont_show_window = true;
159
                }
160
161
                // first argument is always the invocation of the program itself
162
                if(file != args[0]) {
163
                    general_tab.execute(file, false, false, false);
164
                } else {
165
                    continue;
166
                }
1 by donadigo
Initial, fix merged branches
167
            }
168
        }
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
169
            // run app
170
            var app = new PowerInstallerApp();
171
            return app.run(args);
172
        }
1 by donadigo
Initial, fix merged branches
173
174
        public override void activate() {
15 by donadigo
Switch to Policykit, first ports to python (general.sh), fix for arguments
175
            try_delete_pass();
1 by donadigo
Initial, fix merged branches
176
            if(dont_show_window == false) {
177
                var window = new Window();
178
                window.destroy.connect(try_delete_pass);
179
                window.destroy.connect(Gtk.main_quit);
180
                window.show_all();
181
                Gtk.main();
182
            }
183
        }
184
    }
185
}