pamac-classic/src/updater_window.vala

379 lines
11 KiB
Vala
Raw Normal View History

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 {
[GtkTemplate (ui = "/org/manjaro/pamac/updater/updater_window.ui")]
class UpdaterWindow : Gtk.ApplicationWindow {
2014-10-22 13:44:02 -03:00
[GtkChild]
Gtk.HeaderBar headerbar;
2014-10-22 13:44:02 -03:00
[GtkChild]
2016-05-17 13:11:49 -04:00
Gtk.Button button_back;
[GtkChild]
Gtk.ModelButton preferences_button;
[GtkChild]
2016-05-17 13:11:49 -04:00
Gtk.Stack stack;
[GtkChild]
2016-04-14 13:19:20 -03:00
Gtk.StackSwitcher stackswitcher;
2014-10-22 13:44:02 -03:00
[GtkChild]
Gtk.ScrolledWindow repos_scrolledwindow;
2016-02-02 05:28:07 -03:00
[GtkChild]
Gtk.ScrolledWindow aur_scrolledwindow;
2016-02-02 05:28:07 -03:00
[GtkChild]
Gtk.TreeView repos_updates_treeview;
2016-02-02 05:28:07 -03:00
[GtkChild]
Gtk.CellRendererToggle repos_select_update;
2016-02-02 05:28:07 -03:00
[GtkChild]
Gtk.TreeView aur_updates_treeview;
2016-02-02 05:28:07 -03:00
[GtkChild]
Gtk.CellRendererToggle aur_select_update;
[GtkChild]
Gtk.Box transaction_infobox;
[GtkChild]
Gtk.Button details_button;
[GtkChild]
Gtk.Button apply_button;
[GtkChild]
Gtk.Button cancel_button;
2015-03-04 11:55:36 -03:00
Gtk.ListStore repos_updates_list;
Gtk.ListStore aur_updates_list;
2014-10-22 13:44:02 -03:00
public Pamac.Transaction transaction;
bool transaction_running;
bool generate_mirrors_list;
2016-05-17 13:11:49 -04:00
bool important_details;
2016-08-05 10:33:20 -04:00
string previous_visible_child_name;
2014-10-22 13:44:02 -03:00
public UpdaterWindow (Gtk.Application application) {
Object (application: application);
2016-05-17 13:11:49 -04:00
button_back.visible = false;
apply_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
2016-05-17 13:11:49 -04:00
apply_button.sensitive = false;
2016-04-14 13:19:20 -03:00
stackswitcher.visible = false;
aur_scrolledwindow.visible = false;
transaction_running = false;
2016-05-17 13:11:49 -04:00
important_details = false;
generate_mirrors_list = false;
2016-02-04 12:20:50 -03:00
2017-02-18 13:10:26 -03:00
headerbar.title = dgettext (null, "Update Manager");
2016-02-04 12:20:50 -03:00
Timeout.add (100, populate_window);
}
bool populate_window () {
2016-02-04 12:20:50 -03:00
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
2016-07-06 03:59:38 -04:00
repos_updates_list = new Gtk.ListStore (7, typeof (bool), typeof (string), typeof (string), typeof (string),typeof (string), typeof (string), typeof (uint64));
2016-02-02 05:28:07 -03:00
repos_updates_treeview.set_model (repos_updates_list);
2016-04-15 07:50:35 -03:00
aur_updates_list = new Gtk.ListStore (4, typeof (bool), typeof (string), typeof (string), typeof (string));
2016-02-02 05:28:07 -03:00
aur_updates_treeview.set_model (aur_updates_list);
2014-10-22 13:44:02 -03:00
2015-03-04 11:55:36 -03:00
transaction = new Transaction (this as Gtk.ApplicationWindow);
2014-10-22 13:44:02 -03:00
transaction.mode = Mode.UPDATER;
2017-03-06 16:58:30 -03:00
transaction.start_waiting.connect (on_start_waiting);
transaction.stop_waiting.connect (on_stop_waiting);
transaction.start_downloading.connect (on_start_downloading);
transaction.stop_downloading.connect (on_stop_downloading);
2017-02-18 13:10:26 -03:00
transaction.start_building.connect (on_start_building);
2017-03-06 16:58:30 -03:00
transaction.stop_building.connect (on_stop_building);
transaction.important_details_outpout.connect (on_important_details_output);
transaction.finished.connect (populate_updates_list);
transaction.get_updates_finished.connect (on_get_updates_finished);
transaction.generate_mirrors_list.connect (on_generate_mirrors_list);
2016-02-02 05:28:07 -03:00
2016-05-17 13:11:49 -04:00
// integrate progress box and term widget
2017-02-18 13:10:26 -03:00
stack.add_named (transaction.term_window, "term");
2016-05-17 13:11:49 -04:00
transaction_infobox.pack_start (transaction.progress_box);
2016-08-27 11:38:20 -03:00
// A timeout is needed to let the time to the daemon to deal
// with potential other package manager process running.
Timeout.add (500, () => {
on_refresh_button_clicked ();
return false;
});
2016-02-04 12:20:50 -03:00
2016-05-17 13:11:49 -04:00
stack.notify["visible-child"].connect (on_stack_visible_child_changed);
2016-02-04 12:20:50 -03:00
return false;
2014-10-22 13:44:02 -03:00
}
void set_transaction_infobox_visible () {
if (important_details) {
transaction_infobox.show_all ();
return;
}
if (!generate_mirrors_list) {
bool visible = false;
uint64 total_dsize = 0;
repos_updates_list.foreach ((model, path, iter) => {
2016-04-14 13:19:20 -03:00
bool selected;
uint64 dsize;
repos_updates_list.get (iter, 0, out selected, 6, out dsize);
2016-07-06 03:59:38 -04:00
visible |= selected;
if (selected) {
total_dsize += dsize;
}
return false;
2016-02-02 05:28:07 -03:00
});
if (!visible) {
aur_updates_list.foreach ((model, path, iter) => {
bool selected;
aur_updates_list.get (iter, 0, out selected);
visible |= selected;
return visible;
});
}
if (visible) {
if (total_dsize != 0) {
transaction.progress_box.action_label.set_markup("<b>%s: %s</b>".printf (dgettext (null, "Total download size"), format_size (total_dsize)));
} else {
transaction.progress_box.action_label.label = "";
}
// fix an possible visibility issue
transaction_infobox.show_all ();
2016-07-06 03:59:38 -04:00
} else {
transaction_infobox.visible = false;
2016-07-06 03:59:38 -04:00
}
2016-05-17 13:11:49 -04:00
}
2016-02-02 05:28:07 -03:00
}
[GtkCallback]
void on_repos_select_update_toggled (string path) {
if (!transaction_running) {
Gtk.TreePath treepath = new Gtk.TreePath.from_string (path);
Gtk.TreeIter iter;
string pkgname;
repos_updates_list.get_iter (out iter, treepath);
repos_updates_list.get (iter, 1, out pkgname);
if (repos_select_update.active) {
repos_updates_list.set (iter, 0, false);
transaction.temporary_ignorepkgs.add (pkgname);
} else {
repos_updates_list.set (iter, 0, true);
transaction.temporary_ignorepkgs.remove (pkgname);
}
set_transaction_infobox_visible ();
2016-02-02 05:28:07 -03:00
}
}
[GtkCallback]
void on_aur_select_update_toggled (string path) {
if (!transaction_running) {
Gtk.TreePath treepath = new Gtk.TreePath.from_string (path);
Gtk.TreeIter iter;
string pkgname;
aur_updates_list.get_iter (out iter, treepath);
aur_updates_list.get (iter, 1, out pkgname);
if (aur_select_update.active) {
aur_updates_list.set (iter, 0, false);
transaction.temporary_ignorepkgs.add (pkgname);
} else {
aur_updates_list.set (iter, 0, true);
transaction.temporary_ignorepkgs.remove (pkgname);
}
set_transaction_infobox_visible ();
2016-02-02 05:28:07 -03:00
}
}
2016-05-17 13:11:49 -04:00
[GtkCallback]
void on_button_back_clicked () {
2016-08-05 10:33:20 -04:00
if (aur_scrolledwindow.visible) {
stackswitcher.visible = true;
stack.visible_child_name = previous_visible_child_name;
} else {
stack.visible_child_name = "repos";
}
2016-05-17 13:11:49 -04:00
}
void on_stack_visible_child_changed () {
if (stack.visible_child_name == "term") {
button_back.visible = true;
}
}
[GtkCallback]
void on_menu_button_toggled () {
preferences_button.sensitive = !transaction_running;
}
2014-10-22 13:44:02 -03:00
[GtkCallback]
void on_preferences_button_clicked () {
transaction.run_preferences_dialog.begin (() => {
if (!generate_mirrors_list) {
populate_updates_list ();
}
2015-03-04 11:55:36 -03:00
});
2014-10-22 13:44:02 -03:00
}
[GtkCallback]
void on_apply_button_clicked () {
transaction_running = true;
2016-02-02 05:28:07 -03:00
transaction.sysupgrade (false);
2016-05-17 13:11:49 -04:00
apply_button.sensitive = false;
details_button.sensitive = true;
cancel_button.sensitive = true;
2014-10-22 13:44:02 -03:00
}
[GtkCallback]
void on_refresh_button_clicked () {
2015-04-12 11:04:30 -03:00
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
transaction_infobox.show_all ();
2016-05-17 13:11:49 -04:00
apply_button.sensitive = false;
details_button.sensitive = true;
cancel_button.sensitive = true;
2016-02-02 05:28:07 -03:00
transaction.start_refresh (false);
2014-10-22 13:44:02 -03:00
}
[GtkCallback]
void on_history_button_clicked () {
transaction.run_history_dialog ();
}
[GtkCallback]
void on_about_button_clicked () {
transaction.run_about_dialog ();
}
[GtkCallback]
void on_details_button_clicked () {
2016-05-17 13:11:49 -04:00
details_button.get_style_context ().remove_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
important_details = false;
2016-08-05 10:33:20 -04:00
previous_visible_child_name = stack.visible_child_name;
2016-05-17 13:11:49 -04:00
stack.visible_child_name = "term";
}
[GtkCallback]
void on_cancel_button_clicked () {
transaction.cancel ();
}
2017-03-06 16:58:30 -03:00
void on_start_waiting () {
cancel_button.sensitive = true;
}
void on_stop_waiting () {
populate_updates_list ();
}
void on_start_downloading () {
cancel_button.sensitive = true;
}
void on_stop_downloading () {
2016-05-17 13:11:49 -04:00
cancel_button.sensitive = false;
}
2017-02-18 13:10:26 -03:00
void on_start_building () {
cancel_button.sensitive = true;
}
2017-03-06 16:58:30 -03:00
void on_stop_building () {
cancel_button.sensitive = false;
}
void on_important_details_output (bool must_show) {
2016-05-17 13:11:49 -04:00
if (must_show) {
2016-08-05 10:33:20 -04:00
stackswitcher.visible = false;
previous_visible_child_name = stack.visible_child_name;
2016-05-17 13:11:49 -04:00
stack.visible_child_name = "term";
button_back.visible = false;
} else if (stack.visible_child_name != "term") {
important_details = true;
details_button.sensitive = true;
2016-05-17 13:11:49 -04:00
details_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
}
2014-10-22 13:44:02 -03:00
}
void on_generate_mirrors_list () {
generate_mirrors_list = true;
apply_button.sensitive = false;
transaction_infobox.show_all ();
}
void populate_updates_list () {
transaction_running = false;
generate_mirrors_list = false;
apply_button.grab_default ();
if (!important_details) {
details_button.sensitive = false;
}
2016-05-17 13:11:49 -04:00
cancel_button.sensitive = false;
if (stack.visible_child_name == "term") {
button_back.visible = true;
}
2015-04-12 11:04:30 -03:00
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
2016-05-17 13:11:49 -04:00
transaction.progress_box.action_label.label = "";
2016-02-02 05:28:07 -03:00
transaction.start_get_updates ();
}
void on_get_updates_finished (Updates updates) {
2017-02-18 13:10:26 -03:00
headerbar.title = dgettext (null, "Update Manager");
2016-02-02 05:28:07 -03:00
repos_updates_list.clear ();
2016-04-14 13:19:20 -03:00
stackswitcher.visible = false;
repos_scrolledwindow.visible = true;
2016-02-02 05:28:07 -03:00
aur_updates_list.clear ();
2016-04-14 13:19:20 -03:00
aur_scrolledwindow.visible = false;
2016-02-02 05:28:07 -03:00
uint repos_updates_nb = 0;
uint aur_updates_nb = 0;
2016-04-14 13:19:20 -03:00
foreach (unowned UpdateInfos infos in updates.repos_updates) {
2016-02-02 05:28:07 -03:00
string size = infos.download_size != 0 ? format_size (infos.download_size) : "";
repos_updates_nb++;
2016-04-14 13:19:20 -03:00
repos_updates_list.insert_with_values (null, -1,
0, !transaction.temporary_ignorepkgs.contains (infos.name),
1, infos.name,
2, infos.new_version,
3, "(%s)".printf (infos.old_version),
4, infos.repo,
2016-07-06 03:59:38 -04:00
5, size,
6, infos.download_size);
2015-03-04 11:55:36 -03:00
}
2016-04-14 13:19:20 -03:00
foreach (unowned UpdateInfos infos in updates.aur_updates) {
2016-02-02 05:28:07 -03:00
aur_updates_nb++;
2016-04-14 13:19:20 -03:00
aur_updates_list.insert_with_values (null, -1,
0, !transaction.temporary_ignorepkgs.contains (infos.name),
1, infos.name,
2016-04-15 07:50:35 -03:00
2, infos.new_version,
3, "(%s)".printf (infos.old_version));
2014-10-22 13:44:02 -03:00
}
2016-02-02 05:28:07 -03:00
uint updates_nb = repos_updates_nb + aur_updates_nb;
2014-10-22 13:44:02 -03:00
if (updates_nb == 0) {
headerbar.title = dgettext (null, "Your system is up-to-date");
2016-08-27 11:38:20 -03:00
apply_button.sensitive = false;
2014-10-22 13:44:02 -03:00
} else {
headerbar.title = dngettext (null, "%u available update", "%u available updates", updates_nb).printf (updates_nb);
2016-08-27 11:38:20 -03:00
apply_button.sensitive = true;
2014-10-22 13:44:02 -03:00
}
set_transaction_infobox_visible ();
if (aur_updates_nb != 0) {
2016-04-14 13:19:20 -03:00
aur_scrolledwindow.visible = true;
2016-02-02 05:28:07 -03:00
if (repos_updates_nb == 0) {
2016-04-14 13:19:20 -03:00
repos_scrolledwindow.visible = false;
2016-02-02 05:28:07 -03:00
}
2016-08-05 10:33:20 -04:00
if (stack.visible_child_name != "term") {
stackswitcher.visible = true;
}
2016-02-02 05:28:07 -03:00
}
2014-11-16 07:31:44 -03:00
this.get_window ().set_cursor (null);
2014-10-22 13:44:02 -03:00
}
}
}