pamac-classic/src/pamac-manager/manager.vala

146 lines
4.4 KiB
Vala
Raw Normal View History

2014-10-22 13:44:02 -03:00
/*
* pamac-vala
*
2017-10-10 16:29:22 -03:00
* Copyright (C) 2017 Chris Cromer <cromer@cromnix.org>
2017-05-13 18:11:45 -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 {
2017-05-13 18:11:45 -03:00
class Manager : Gtk.Application {
2014-10-22 13:44:02 -03:00
ManagerWindow manager_window;
2014-11-03 17:04:44 -03:00
bool pamac_run;
2017-07-29 10:35:04 -04:00
bool started;
2014-10-22 13:44:02 -03:00
public Manager () {
2017-10-10 16:29:22 -03:00
application_id = "org.pamac.manager";
2017-07-29 10:35:04 -04:00
flags = ApplicationFlags.HANDLES_COMMAND_LINE;
2014-10-22 13:44:02 -03:00
}
public override void startup () {
// i18n
2019-07-06 20:28:51 -04:00
Intl.bindtextdomain(Constants.GETTEXT_PACKAGE, Path.build_filename(Constants.DATADIR,"locale"));
2014-10-22 13:44:02 -03:00
Intl.setlocale (LocaleCategory.ALL, "");
2019-07-06 20:28:51 -04:00
Intl.textdomain(Constants.GETTEXT_PACKAGE);
Intl.bind_textdomain_codeset(Constants.GETTEXT_PACKAGE, "utf-8" );
2014-10-22 13:44:02 -03:00
base.startup ();
2014-11-03 17:04:44 -03:00
pamac_run = check_pamac_running ();
if (pamac_run) {
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 ();
2015-03-04 11:55:36 -03:00
} else {
2014-11-03 17:04:44 -03:00
manager_window = new ManagerWindow (this);
2017-11-06 22:22:10 -03:00
#if ENABLE_HAMBURGER
#else
var menu = new Menu ();
menu.append (dgettext (null, "Refresh Databases"), "win.refreshdb");
menu.append (dgettext (null, "View History"), "win.viewhistory");
menu.append (dgettext (null, "Install Local Packages"), "win.installlocal");
menu.append (dgettext (null, "Preferences"), "win.preferences");
menu.append (dgettext (null, "About"), "win.about");
menu.append (dgettext (null, "Quit"), "app.quit");
this.app_menu = menu;
var quit_action = new SimpleAction ("quit", null);
quit_action.activate.connect (this.quit);
this.add_action (quit_action);
#endif
2017-06-03 09:22:29 -04:00
// quit accel
2017-02-20 17:21:10 -03:00
var action = new SimpleAction ("quit", null);
action.activate.connect (() => {this.quit ();});
this.add_action (action);
string[] accels = {"<Ctrl>Q", "<Ctrl>W"};
2017-02-20 17:21:10 -03:00
this.set_accels_for_action ("app.quit", accels);
2017-06-03 09:22:29 -04:00
// back accel
action = new SimpleAction ("back", null);
action.activate.connect (() => {manager_window.on_button_back_clicked ();});
this.add_action (action);
accels = {"<Alt>Left"};
this.set_accels_for_action ("app.back", accels);
// search accel
action = new SimpleAction ("search", null);
2017-10-02 10:23:53 -03:00
action.activate.connect (() => {manager_window.filters_stack.visible_child_name = "search";});
this.add_action (action);
accels = {"<Ctrl>F"};
this.set_accels_for_action ("app.search", accels);
2017-11-08 16:25:49 -03:00
manager_window.present ();
2015-03-04 11:55:36 -03:00
}
2014-10-22 13:44:02 -03:00
}
2017-07-29 10:35:04 -04:00
public override int command_line (ApplicationCommandLine cmd) {
if (cmd.get_arguments ()[0] == "pamac-updater") {
manager_window.display_package_queue.clear ();
manager_window.main_stack.visible_child_name = "browse";
manager_window.filters_stack.visible_child_name = "updates";
} else if (!started) {
2017-10-02 10:23:53 -03:00
manager_window.show_default_pkgs ();
2017-07-29 10:35:04 -04:00
started = true;
}
2016-02-02 05:28:07 -03:00
if (!pamac_run) {
2014-11-03 17:04:44 -03:00
manager_window.present ();
2015-03-04 11:55:36 -03:00
while (Gtk.events_pending ()) {
2014-11-16 07:31:44 -03:00
Gtk.main_iteration ();
2015-03-04 11:55:36 -03:00
}
2014-11-16 07:31:44 -03:00
}
2017-07-29 10:35:04 -04:00
return 0;
2014-10-22 13:44:02 -03:00
}
public override void shutdown () {
base.shutdown ();
2016-02-02 05:28:07 -03:00
if (!pamac_run) {
2014-11-03 17:04:44 -03:00
manager_window.transaction.stop_daemon ();
2015-03-04 11:55:36 -03:00
}
2014-11-03 17:04:44 -03:00
}
bool check_pamac_running () {
Application app;
bool run = false;
2017-10-10 16:29:22 -03:00
app = new Application ("org.pamac.installer", 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
}
2017-11-06 22:22:10 -03:00
#if ENABLE_HAMBURGER
#else
protected override void activate () {
new ManagerWindow (this);
}
#endif
2014-10-22 13:44:02 -03:00
}
2017-05-13 18:11:45 -03:00
static int main (string[] args) {
2017-11-06 22:22:10 -03:00
// This forces the gtk to show the menu icon instead of the global menu to debug
//Gtk.init (ref args);
//Gtk.Settings.get_default ().gtk_shell_shows_app_menu = false;
2014-10-22 13:44:02 -03:00
var manager = new Manager ();
return manager.run (args);
}
}