2014-10-22 13:44:02 -03:00
|
|
|
/*
|
|
|
|
* pamac-vala
|
|
|
|
*
|
2016-02-02 05:28:07 -03:00
|
|
|
* Copyright (C) 2014-2016 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")]
|
2016-02-26 06:37:26 -03:00
|
|
|
class UpdaterWindow : Gtk.ApplicationWindow {
|
2014-10-22 13:44:02 -03:00
|
|
|
|
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.Label top_label;
|
2014-10-22 13:44:02 -03:00
|
|
|
[GtkChild]
|
2016-04-14 13:19:20 -03:00
|
|
|
Gtk.StackSwitcher stackswitcher;
|
2014-10-22 13:44:02 -03:00
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.ScrolledWindow repos_scrolledwindow;
|
2016-02-02 05:28:07 -03:00
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.ScrolledWindow aur_scrolledwindow;
|
2016-02-02 05:28:07 -03:00
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.TreeView repos_updates_treeview;
|
2016-02-02 05:28:07 -03:00
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.CellRendererToggle repos_select_update;
|
2016-02-02 05:28:07 -03:00
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.TreeView aur_updates_treeview;
|
2016-02-02 05:28:07 -03:00
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.CellRendererToggle aur_select_update;
|
2015-04-11 13:00:49 -03:00
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.Label bottom_label;
|
2014-10-22 13:44:02 -03:00
|
|
|
[GtkChild]
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.Button apply_button;
|
2015-03-04 11:55:36 -03:00
|
|
|
|
2016-02-26 06:37:26 -03:00
|
|
|
Gtk.ListStore repos_updates_list;
|
|
|
|
Gtk.ListStore aur_updates_list;
|
2014-10-22 13:44:02 -03:00
|
|
|
|
|
|
|
public Pamac.Transaction transaction;
|
|
|
|
|
|
|
|
public UpdaterWindow (Gtk.Application application) {
|
|
|
|
Object (application: application);
|
|
|
|
|
2016-04-14 13:19:20 -03:00
|
|
|
bottom_label.visible = false;
|
|
|
|
apply_button.sensitive = false;
|
|
|
|
stackswitcher.visible = false;
|
|
|
|
aur_scrolledwindow.visible = false;
|
2016-02-04 12:20:50 -03:00
|
|
|
|
|
|
|
Timeout.add (100, populate_window);
|
|
|
|
}
|
|
|
|
|
2016-02-26 06:37:26 -03:00
|
|
|
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-04-14 13:19:20 -03:00
|
|
|
repos_updates_list = new Gtk.ListStore (6, typeof (bool), typeof (string), typeof (string), typeof (string),typeof (string), typeof (string));
|
2016-02-02 05:28:07 -03:00
|
|
|
repos_updates_treeview.set_model (repos_updates_list);
|
2016-04-14 13:19:20 -03:00
|
|
|
aur_updates_list = new Gtk.ListStore (3, typeof (bool), 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;
|
2016-03-01 11:04:02 -03:00
|
|
|
transaction.finished.connect (populate_updates_list);
|
2016-02-26 06:37:26 -03:00
|
|
|
transaction.get_updates_finished.connect (on_get_updates_finished);
|
2016-02-02 05:28:07 -03:00
|
|
|
|
2014-11-16 07:31:44 -03:00
|
|
|
on_refresh_button_clicked ();
|
2016-02-04 12:20:50 -03:00
|
|
|
|
|
|
|
return false;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2016-02-26 06:37:26 -03:00
|
|
|
void set_apply_button_sensitive () {
|
2016-02-02 05:28:07 -03:00
|
|
|
bool sensitive = false;
|
|
|
|
repos_updates_list.foreach ((model, path, iter) => {
|
2016-04-14 13:19:20 -03:00
|
|
|
bool selected;
|
|
|
|
repos_updates_list.get (iter, 0, out selected);
|
|
|
|
sensitive = selected;
|
2016-02-02 05:28:07 -03:00
|
|
|
return sensitive;
|
|
|
|
});
|
|
|
|
if (!sensitive) {
|
|
|
|
aur_updates_list.foreach ((model, path, iter) => {
|
2016-04-14 13:19:20 -03:00
|
|
|
bool selected;
|
|
|
|
aur_updates_list.get (iter, 0, out selected);
|
|
|
|
sensitive = selected;
|
2016-02-02 05:28:07 -03:00
|
|
|
return sensitive;
|
|
|
|
});
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
apply_button.sensitive = sensitive;
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
|
|
|
|
2015-04-11 13:00:49 -03:00
|
|
|
[GtkCallback]
|
2016-02-26 06:37:26 -03:00
|
|
|
void on_repos_select_update_toggled (string path) {
|
2015-04-11 13:00:49 -03:00
|
|
|
Gtk.TreePath treepath = new Gtk.TreePath.from_string (path);
|
|
|
|
Gtk.TreeIter iter;
|
2016-04-14 13:19:20 -03:00
|
|
|
string pkgname;
|
2016-02-02 05:28:07 -03:00
|
|
|
repos_updates_list.get_iter (out iter, treepath);
|
2016-04-14 13:19:20 -03:00
|
|
|
repos_updates_list.get (iter, 1, out pkgname);
|
2016-02-02 05:28:07 -03:00
|
|
|
if (repos_select_update.active) {
|
|
|
|
repos_updates_list.set (iter, 0, false);
|
2016-02-26 06:37:26 -03:00
|
|
|
transaction.temporary_ignorepkgs.add (pkgname);
|
2016-02-02 05:28:07 -03:00
|
|
|
} else {
|
|
|
|
repos_updates_list.set (iter, 0, true);
|
2016-02-26 06:37:26 -03:00
|
|
|
transaction.temporary_ignorepkgs.remove (pkgname);
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
|
|
|
set_apply_button_sensitive ();
|
|
|
|
}
|
|
|
|
|
|
|
|
[GtkCallback]
|
2016-02-26 06:37:26 -03:00
|
|
|
void on_aur_select_update_toggled (string path) {
|
2016-02-02 05:28:07 -03:00
|
|
|
Gtk.TreePath treepath = new Gtk.TreePath.from_string (path);
|
|
|
|
Gtk.TreeIter iter;
|
2016-04-14 13:19:20 -03:00
|
|
|
string pkgname;
|
2016-02-02 05:28:07 -03:00
|
|
|
aur_updates_list.get_iter (out iter, treepath);
|
2016-04-14 13:19:20 -03:00
|
|
|
aur_updates_list.get (iter, 1, out pkgname);
|
2016-02-02 05:28:07 -03:00
|
|
|
if (aur_select_update.active) {
|
|
|
|
aur_updates_list.set (iter, 0, false);
|
2016-02-26 06:37:26 -03:00
|
|
|
transaction.temporary_ignorepkgs.add (pkgname);
|
2016-02-02 05:28:07 -03:00
|
|
|
} else {
|
|
|
|
aur_updates_list.set (iter, 0, true);
|
2016-02-26 06:37:26 -03:00
|
|
|
transaction.temporary_ignorepkgs.remove (pkgname);
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
|
|
|
set_apply_button_sensitive ();
|
2015-04-11 13:00:49 -03:00
|
|
|
}
|
|
|
|
|
2014-10-22 13:44:02 -03:00
|
|
|
[GtkCallback]
|
2016-02-26 06:37:26 -03:00
|
|
|
void on_preferences_button_clicked () {
|
|
|
|
transaction.run_preferences_dialog.begin (() => {
|
2016-02-02 05:28:07 -03:00
|
|
|
populate_updates_list ();
|
2015-03-04 11:55:36 -03:00
|
|
|
});
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
[GtkCallback]
|
2016-02-26 06:37:26 -03:00
|
|
|
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));
|
2016-02-02 05:28:07 -03:00
|
|
|
transaction.sysupgrade (false);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
[GtkCallback]
|
2016-02-26 06:37:26 -03:00
|
|
|
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));
|
2016-02-02 05:28:07 -03:00
|
|
|
transaction.start_refresh (false);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
[GtkCallback]
|
2016-02-26 06:37:26 -03:00
|
|
|
void on_close_button_clicked () {
|
2014-10-22 13:44:02 -03:00
|
|
|
this.application.quit ();
|
|
|
|
}
|
|
|
|
|
2016-02-26 06:37:26 -03:00
|
|
|
void populate_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));
|
2016-02-02 05:28:07 -03:00
|
|
|
transaction.start_get_updates ();
|
|
|
|
}
|
|
|
|
|
2016-02-26 06:37:26 -03:00
|
|
|
void on_get_updates_finished (Updates updates) {
|
2015-02-09 13:44:09 -03:00
|
|
|
top_label.set_markup ("");
|
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;
|
|
|
|
bottom_label.visible = false;
|
2014-10-22 13:44:02 -03:00
|
|
|
uint64 dsize = 0;
|
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) : "";
|
2015-02-09 13:44:09 -03:00
|
|
|
dsize += infos.download_size;
|
2016-02-02 05:28:07 -03:00
|
|
|
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,
|
|
|
|
5, 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,
|
|
|
|
2, "%s\t (%s)".printf (infos.new_version, 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) {
|
|
|
|
top_label.set_markup("<b>%s</b>".printf (dgettext (null, "Your system is up-to-date")));
|
|
|
|
} 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
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
set_apply_button_sensitive ();
|
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)));
|
2016-04-14 13:19:20 -03:00
|
|
|
bottom_label.visible = true;
|
2015-02-09 13:44:09 -03:00
|
|
|
} else {
|
2016-04-14 13:19:20 -03:00
|
|
|
bottom_label.visible = false;
|
2015-02-09 13:44:09 -03:00
|
|
|
}
|
2016-02-05 07:11:51 -03:00
|
|
|
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-04-14 13:19:20 -03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|