2014-10-22 13:44:02 -03:00
|
|
|
/*
|
|
|
|
* pamac-vala
|
|
|
|
*
|
2017-01-03 05:43:19 -03:00
|
|
|
* Copyright (C) 2014-2017 Guillaume Benoit <guillaume@manjaro.org>
|
2014-10-22 13:44:02 -03:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a get of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pamac {
|
|
|
|
|
|
|
|
public class Installer: Gtk.Application {
|
|
|
|
Transaction transaction;
|
2016-05-18 10:25:31 -04:00
|
|
|
ProgressDialog progress_dialog;
|
2014-11-03 17:04:44 -03:00
|
|
|
bool pamac_run;
|
2016-05-18 10:25:31 -04:00
|
|
|
bool important_details;
|
2014-10-22 13:44:02 -03:00
|
|
|
|
|
|
|
public Installer () {
|
|
|
|
application_id = "org.manjaro.pamac.install";
|
|
|
|
flags |= ApplicationFlags.HANDLES_OPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void startup () {
|
|
|
|
// i18n
|
|
|
|
Intl.textdomain ("pamac");
|
|
|
|
Intl.setlocale (LocaleCategory.ALL, "");
|
|
|
|
|
|
|
|
base.startup ();
|
|
|
|
|
2014-11-03 17:04:44 -03:00
|
|
|
pamac_run = check_pamac_running ();
|
|
|
|
if (pamac_run) {
|
2016-02-26 06:37:26 -03:00
|
|
|
var msg = new Gtk.MessageDialog (null,
|
|
|
|
Gtk.DialogFlags.MODAL,
|
|
|
|
Gtk.MessageType.ERROR,
|
|
|
|
Gtk.ButtonsType.OK,
|
|
|
|
dgettext (null, "Pamac is already running"));
|
|
|
|
msg.run ();
|
|
|
|
msg.destroy ();
|
2014-11-03 17:04:44 -03:00
|
|
|
} else {
|
2016-05-18 10:25:31 -04:00
|
|
|
important_details = false;
|
|
|
|
// integrate progress box and term widget
|
|
|
|
progress_dialog = new ProgressDialog ();
|
|
|
|
transaction = new Pamac.Transaction (progress_dialog as Gtk.ApplicationWindow);
|
2016-02-02 05:28:07 -03:00
|
|
|
transaction.finished.connect (on_transaction_finished);
|
2016-05-18 10:25:31 -04:00
|
|
|
transaction.important_details_outpout.connect (on_important_details_outpout);
|
|
|
|
progress_dialog.box.pack_start (transaction.progress_box);
|
|
|
|
progress_dialog.box.reorder_child (transaction.progress_box, 0);
|
2017-02-18 13:10:26 -03:00
|
|
|
progress_dialog.expander.add (transaction.term_window);
|
2016-05-18 10:25:31 -04:00
|
|
|
progress_dialog.close_button.clicked.connect (on_close_button_clicked);
|
|
|
|
progress_dialog.close_button.visible = false;
|
2014-11-03 17:04:44 -03:00
|
|
|
this.hold ();
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void activate () {
|
2016-02-02 05:28:07 -03:00
|
|
|
if (!pamac_run) {
|
2014-11-03 17:04:44 -03:00
|
|
|
print ("\nError: Path(s) of tarball(s) to install is needed\n");
|
|
|
|
transaction.stop_daemon ();
|
|
|
|
this.release ();
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void open (File[] files, string hint) {
|
2016-02-02 05:28:07 -03:00
|
|
|
if (!pamac_run) {
|
|
|
|
foreach (unowned File file in files) {
|
|
|
|
transaction.to_load.add (file.get_path ());
|
2014-11-03 17:04:44 -03:00
|
|
|
}
|
|
|
|
transaction.run ();
|
2016-05-18 10:25:31 -04:00
|
|
|
progress_dialog.show ();
|
2014-11-03 17:04:44 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool check_pamac_running () {
|
|
|
|
Application app;
|
|
|
|
bool run = false;
|
|
|
|
app = new Application ("org.manjaro.pamac.manager", 0);
|
|
|
|
try {
|
|
|
|
app.register ();
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("%s\n", e.message);
|
|
|
|
}
|
2015-03-28 11:17:14 -03:00
|
|
|
run = app.get_is_remote ();
|
2015-03-04 11:55:36 -03:00
|
|
|
if (run) {
|
2014-11-03 17:04:44 -03:00
|
|
|
return run;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2015-03-28 11:17:14 -03:00
|
|
|
app = new Application ("org.manjaro.pamac.updater", 0);
|
|
|
|
try {
|
|
|
|
app.register ();
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("%s\n", e.message);
|
|
|
|
}
|
|
|
|
run = app.get_is_remote ();
|
|
|
|
return run;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2016-05-18 10:25:31 -04:00
|
|
|
void on_important_details_outpout (bool must_show) {
|
|
|
|
important_details = true;
|
|
|
|
progress_dialog.expander.expanded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_close_button_clicked () {
|
|
|
|
this.release ();
|
|
|
|
}
|
|
|
|
|
2016-02-26 06:37:26 -03:00
|
|
|
void on_transaction_finished () {
|
2014-10-22 13:44:02 -03:00
|
|
|
transaction.stop_daemon ();
|
2016-05-18 10:25:31 -04:00
|
|
|
if (important_details) {
|
|
|
|
progress_dialog.close_button.visible = true;
|
|
|
|
} else {
|
|
|
|
this.release ();
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int main (string[] args) {
|
|
|
|
var installer = new Installer();
|
|
|
|
return installer.run (args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|