pamac-classic/src/updater_window.vala

187 lines
5.9 KiB
Vala
Raw Normal View History

2014-10-22 13:44:02 -03:00
/*
* pamac-vala
*
2015-03-04 11:55:36 -03:00
* Copyright (C) 2014-2015 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")]
public class UpdaterWindow : Gtk.ApplicationWindow {
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Label top_label;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeView updates_treeview;
2014-10-22 13:44:02 -03:00
[GtkChild]
public Gtk.CellRendererToggle select_update;
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Label bottom_label;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Button apply_button;
public Gtk.ListStore updates_list;
2014-10-22 13:44:02 -03:00
public Pamac.Transaction transaction;
public UpdaterWindow (Gtk.Application application) {
Object (application: application);
updates_list = new Gtk.ListStore (3, typeof (bool), typeof (string), typeof (string));
2014-10-22 13:44:02 -03:00
updates_treeview.set_model (updates_list);
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;
2015-03-04 11:55:36 -03:00
transaction.finished.connect (on_transaction_finished);
2014-10-22 13:44:02 -03:00
bottom_label.set_visible (false);
apply_button.set_sensitive (false);
2014-11-16 07:31:44 -03:00
on_refresh_button_clicked ();
2014-10-22 13:44:02 -03:00
}
[GtkCallback]
public void on_select_update_toggled (string path) {
Gtk.TreePath treepath = new Gtk.TreePath.from_string (path);
Gtk.TreeIter iter;
updates_list.get_iter (out iter, treepath);
updates_list.set (iter, 0, !select_update.active);
2015-04-13 04:41:30 -03:00
updates_list.foreach ((model, path, iter) => {
GLib.Value val;
updates_list.get_value (iter, 0, out val);
bool selected = val.get_boolean ();
if (selected) {
apply_button.set_sensitive (true);
return true;
}
apply_button.set_sensitive (false);
return false;
});
}
2015-08-20 10:11:18 -03:00
public async void run_preferences_dialog () {
SourceFunc callback = run_preferences_dialog.callback;
ulong handler_id = transaction.daemon.get_authorization_finished.connect ((authorized) => {
if (authorized) {
var preferences_dialog = new PreferencesDialog (transaction, this);
preferences_dialog.run ();
preferences_dialog.destroy ();
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
}
Idle.add((owned) callback);
});
transaction.start_get_authorization ();
yield;
transaction.daemon.disconnect (handler_id);
}
2014-10-22 13:44:02 -03:00
[GtkCallback]
public void on_preferences_button_clicked () {
2015-08-20 10:11:18 -03:00
run_preferences_dialog.begin (() => {
set_updates_list.begin ();
2015-03-04 11:55:36 -03:00
});
2014-10-22 13:44:02 -03:00
}
[GtkCallback]
public void on_apply_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));
updates_list.foreach ((model, path, iter) => {
GLib.Value val;
updates_list.get_value (iter, 0, out val);
bool selected = val.get_boolean ();
if (selected) {
updates_list.get_value (iter, 1, out val);
// string has the form "pkgname pkgversion"
string pkgname = val.get_string ().split (" ", 2)[0];
transaction.special_ignorepkgs.remove (pkgname);
} else {
updates_list.get_value (iter, 1, out val);
// string has the form "pkgname pkgversion"
string pkgname = val.get_string ().split (" ", 2)[0];
transaction.special_ignorepkgs.add ((owned) pkgname);
}
return false;
});
2014-10-22 13:44:02 -03:00
transaction.sysupgrade (0);
}
[GtkCallback]
public 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));
2015-03-04 11:55:36 -03:00
transaction.start_refresh (0);
2014-10-22 13:44:02 -03:00
}
[GtkCallback]
public void on_close_button_clicked () {
this.application.quit ();
}
2015-03-04 11:55:36 -03:00
public void on_transaction_finished (bool error) {
2014-11-16 07:31:44 -03:00
set_updates_list.begin ();
2014-10-22 13:44:02 -03:00
}
public async void set_updates_list () {
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));
top_label.set_markup ("");
updates_list.clear ();
2015-03-04 11:55:36 -03:00
bottom_label.set_visible (false);
Gtk.TreeIter iter;
2014-10-22 13:44:02 -03:00
string name;
string size;
uint64 dsize = 0;
uint updates_nb = 0;
2015-03-04 11:55:36 -03:00
Updates updates = yield transaction.get_updates ();
foreach (UpdateInfos infos in updates.repos_updates) {
name = infos.name + " " + infos.version;
if (infos.download_size != 0) {
size = format_size (infos.download_size);
} else {
size = "";
2014-10-22 13:44:02 -03:00
}
dsize += infos.download_size;
2015-03-04 11:55:36 -03:00
updates_nb++;
if (infos.name in transaction.special_ignorepkgs) {
updates_list.insert_with_values (out iter, -1, 0, false, 1, name, 2, size);
} else {
updates_list.insert_with_values (out iter, -1, 0, true, 1, name, 2, size);
}
2015-03-04 11:55:36 -03:00
}
foreach (UpdateInfos infos in updates.aur_updates) {
name = infos.name + " " + infos.version;
size = "";
updates_nb++;
updates_list.insert_with_values (out iter, -1, 0, true, 1, name, 2, size);
2014-10-22 13:44:02 -03:00
}
if (updates_nb == 0) {
top_label.set_markup("<b>%s</b>".printf (dgettext (null, "Your system is up-to-date")));
apply_button.set_sensitive (false);
} else {
2014-11-19 10:46:44 -03:00
top_label.set_markup("<b>%s</b>".printf (dngettext (null, "%u available update", "%u available updates", updates_nb).printf (updates_nb)));
2014-10-22 13:44:02 -03:00
apply_button.set_sensitive (true);
}
2014-10-26 08:30:04 -03:00
if (dsize != 0) {
bottom_label.set_markup("<b>%s: %s</b>".printf (dgettext (null, "Total download size"), format_size(dsize)));
2014-10-22 13:44:02 -03:00
bottom_label.set_visible (true);
} else {
2014-10-26 08:30:04 -03:00
bottom_label.set_visible (false);
}
2014-11-16 07:31:44 -03:00
this.get_window ().set_cursor (null);
2014-10-22 13:44:02 -03:00
}
}
}