pamac-classic/src/manager_window.vala

1159 lines
38 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 2 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/>.
*/
using Gtk;
using Alpm;
const string VERSION = "2.4.2";
2014-10-22 13:44:02 -03:00
namespace Pamac {
public struct SortInfo {
public int column_number;
public Gtk.SortType sort_type;
}
[GtkTemplate (ui = "/org/manjaro/pamac/manager/manager_window.ui")]
public class ManagerWindow : Gtk.ApplicationWindow {
// icons
public Gdk.Pixbuf? installed_icon;
public Gdk.Pixbuf? uninstalled_icon;
public Gdk.Pixbuf? to_install_icon;
public Gdk.Pixbuf? to_reinstall_icon;
public Gdk.Pixbuf? to_remove_icon;
public Gdk.Pixbuf? locked_icon;
// manager objects
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeView packages_treeview;
[GtkChild]
public Gtk.TreeViewColumn state_column;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeViewColumn name_column;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeViewColumn version_column;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeViewColumn repo_column;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeViewColumn size_column;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Notebook filters_notebook;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.SearchEntry search_entry;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeView search_treeview;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeView groups_treeview;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeView states_treeview;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeView repos_treeview;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Notebook properties_notebook;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeView deps_treeview;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TreeView details_treeview;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.ScrolledWindow deps_scrolledwindow;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.ScrolledWindow details_scrolledwindow;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.ScrolledWindow files_scrolledwindow;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Label name_label;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Label desc_label;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Label link_label;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Label licenses_label;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.TextView files_textview;
2014-10-22 13:44:02 -03:00
[GtkChild]
public Gtk.Box search_aur_box;
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Switch search_aur_button;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Button valid_button;
2014-10-22 13:44:02 -03:00
[GtkChild]
2015-03-04 11:55:36 -03:00
public Gtk.Button cancel_button;
2014-10-22 13:44:02 -03:00
2014-11-16 07:31:44 -03:00
// menu
Gtk.Menu right_click_menu;
Gtk.MenuItem deselect_item;
Gtk.MenuItem install_item;
Gtk.MenuItem remove_item;
Gtk.SeparatorMenuItem separator_item;
Gtk.MenuItem reinstall_item;
Gtk.MenuItem install_optional_deps_item;
Gtk.MenuItem explicitly_installed_item;
2015-03-04 11:55:36 -03:00
Pamac.Package[] selected_pkgs;
2014-11-16 07:31:44 -03:00
// liststore
2015-03-04 11:55:36 -03:00
Gtk.ListStore search_list;
Gtk.ListStore groups_list;
Gtk.ListStore states_list;
Gtk.ListStore repos_list;
Gtk.ListStore deps_list;
Gtk.ListStore details_list;
2014-10-22 13:44:02 -03:00
PackagesModel packages_list;
public Transaction transaction;
public SortInfo sortinfo;
public ManagerWindow (Gtk.Application application) {
Object (application: application);
right_click_menu = new Gtk.Menu ();
deselect_item = new Gtk.MenuItem.with_label (dgettext (null, "Deselect"));
deselect_item.activate.connect (on_deselect_item_activate);
right_click_menu.append (deselect_item);
install_item = new Gtk.MenuItem.with_label (dgettext (null, "Install"));
install_item.activate.connect (on_install_item_activate);
right_click_menu.append (install_item);
remove_item = new Gtk.MenuItem.with_label (dgettext (null, "Remove"));
remove_item.activate.connect (on_remove_item_activate);
right_click_menu.append (remove_item);
separator_item = new Gtk.SeparatorMenuItem ();
right_click_menu.append (separator_item);
reinstall_item = new Gtk.MenuItem.with_label (dgettext (null, "Reinstall"));
reinstall_item.activate.connect (on_reinstall_item_activate);
right_click_menu.append (reinstall_item);
install_optional_deps_item = new Gtk.MenuItem.with_label (dgettext (null, "Install optional dependencies"));
install_optional_deps_item.activate.connect (on_install_optional_deps_item_activate);
right_click_menu.append (install_optional_deps_item);
explicitly_installed_item = new Gtk.MenuItem.with_label (dgettext (null, "Mark as explicitly installed"));
explicitly_installed_item.activate.connect (on_explicitly_installed_item_activate);
right_click_menu.append (explicitly_installed_item);
right_click_menu.show_all ();
2014-10-22 13:44:02 -03:00
search_list = new Gtk.ListStore (1, typeof (string));
search_treeview.set_model (search_list);
groups_list = new Gtk.ListStore (1, typeof (string));
groups_treeview.set_model (groups_list);
states_list = new Gtk.ListStore (1, typeof (string));
states_treeview.set_model (states_list);
repos_list = new Gtk.ListStore (1, typeof (string));
repos_treeview.set_model (repos_list);
deps_list = new Gtk.ListStore (2, typeof (string), typeof (string));
deps_treeview.set_model (deps_list);
details_list = new Gtk.ListStore (2, typeof (string), typeof (string));
details_treeview.set_model (details_list);;
try {
installed_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-installed-updated.png");
uninstalled_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-available.png");
to_install_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-install.png");
to_reinstall_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-reinstall.png");
to_remove_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-remove.png");
locked_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-installed-locked.png");
} catch (GLib.Error e) {
stderr.printf (e.message);
}
2015-03-04 11:55:36 -03:00
transaction = new Pamac.Transaction (this as Gtk.ApplicationWindow);
transaction.mode = Mode.MANAGER;
transaction.finished.connect (on_transaction_finished);
2015-08-24 11:13:18 -03:00
transaction.support_aur.connect (support_aur);
2015-03-04 11:55:36 -03:00
transaction.daemon.set_pkgreason_finished.connect (display_package_properties);
2014-10-22 13:44:02 -03:00
2015-03-04 11:55:36 -03:00
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
if (pamac_config.recurse) {
transaction.flags |= Alpm.TransFlag.RECURSE;
}
Pamac.Package pkg = transaction.find_local_satisfier ("yaourt");
2015-08-20 10:11:18 -03:00
if (pkg.name == "") {
2015-08-24 11:13:18 -03:00
support_aur (false, false);
2015-08-20 10:11:18 -03:00
} else {
2015-08-24 11:13:18 -03:00
support_aur (pamac_config.enable_aur, pamac_config.search_aur);
2015-08-20 10:11:18 -03:00
}
2014-10-22 13:44:02 -03:00
set_buttons_sensitive (false);
// sort by name by default
2015-03-04 11:55:36 -03:00
sortinfo = {0, Gtk.SortType.ASCENDING};
2014-10-22 13:44:02 -03:00
update_lists ();
}
2015-08-24 11:13:18 -03:00
public void support_aur (bool enable_aur, bool search_aur) {
if (enable_aur) {
search_aur_button.set_active (search_aur);
search_aur_box.set_visible (true);
} else {
search_aur_button.set_active (false);
search_aur_box.set_visible (false);
}
2014-10-22 13:44:02 -03:00
}
public void set_buttons_sensitive (bool sensitive) {
valid_button.set_sensitive (sensitive);
cancel_button.set_sensitive (sensitive);
}
2014-11-16 07:31:44 -03:00
public void show_all_pkgs () {
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.get_all_pkgs.begin ((obj, res) => {
var pkgs = transaction.get_all_pkgs.end (res);
populate_packages_list (pkgs);
this.get_window ().set_cursor (null);
});
2014-11-16 07:31:44 -03:00
}
2014-10-22 13:44:02 -03:00
public void update_lists () {
2015-03-04 11:55:36 -03:00
Gtk.TreeIter iter;
Gtk.TreeSelection selection;
2014-11-16 07:31:44 -03:00
selection = repos_treeview.get_selection ();
selection.changed.disconnect (on_repos_treeview_selection_changed);
2015-03-04 11:55:36 -03:00
foreach (var repo in transaction.get_repos_names ()) {
repos_list.insert_with_values (out iter, -1, 0, repo);
2014-10-22 13:44:02 -03:00
}
repos_list.insert_with_values (out iter, -1, 0, dgettext (null, "local"));
2014-11-16 07:31:44 -03:00
repos_list.get_iter_first (out iter);
selection.select_iter (iter);
selection.changed.connect_after (on_repos_treeview_selection_changed);
selection = groups_treeview.get_selection ();
selection.changed.disconnect (on_groups_treeview_selection_changed);
2015-03-04 11:55:36 -03:00
foreach (var grpname in transaction.get_groups_names ()) {
groups_list.insert_with_values (out iter, -1, 0, grpname);
}
groups_list.set_sort_column_id (0, Gtk.SortType.ASCENDING);
2014-11-16 07:31:44 -03:00
groups_list.get_iter_first (out iter);
selection.select_iter (iter);
selection.changed.connect_after (on_groups_treeview_selection_changed);
selection = states_treeview.get_selection ();
selection.changed.disconnect (on_states_treeview_selection_changed);
2014-10-22 13:44:02 -03:00
states_list.insert_with_values (out iter, -1, 0, dgettext (null, "Installed"));
//states_list.insert_with_values (out iter, -1, 0, dgettext (null, "Uninstalled"));
states_list.insert_with_values (out iter, -1, 0, dgettext (null, "Orphans"));
states_list.insert_with_values (out iter, -1, 0, dgettext (null, "To install"));
states_list.insert_with_values (out iter, -1, 0, dgettext (null, "To remove"));
2014-11-16 07:31:44 -03:00
states_list.get_iter_first (out iter);
selection.select_iter (iter);
selection.changed.connect_after (on_states_treeview_selection_changed);
2014-10-22 13:44:02 -03:00
}
public void set_infos_list (Pamac.Package pkg) {
name_label.set_markup ("<big><b>%s %s</b></big>".printf (pkg.name, pkg.version));
2015-03-04 11:55:36 -03:00
desc_label.set_markup (Markup.escape_text (pkg.desc));
string url = Markup.escape_text (pkg.url);
if (pkg.repo == "AUR") {
string aur_url = "http://aur.archlinux.org/packages/" + pkg.name;
link_label.set_markup ("<a href=\"%s\">%s</a>\n\n<a href=\"%s\">%s</a>".printf (url, url, aur_url, aur_url));
} else {
link_label.set_markup ("<a href=\"%s\">%s</a>".printf (url, url));
}
2014-10-22 13:44:02 -03:00
StringBuilder licenses = new StringBuilder ();
licenses.append (dgettext (null, "Licenses"));
2015-03-04 11:55:36 -03:00
licenses.append (": ");
licenses.append (pkg.licenses);
2014-10-22 13:44:02 -03:00
licenses_label.set_markup (licenses.str);
}
2015-03-04 11:55:36 -03:00
public void set_deps_list (string pkgname) {
2014-10-22 13:44:02 -03:00
deps_list.clear ();
2015-03-04 11:55:36 -03:00
Gtk.TreeIter iter;
PackageDeps deps = transaction.get_pkg_deps (pkgname);
int i;
if (deps.depends.length != 0) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
0, dgettext (null, "Depends On") + ":",
2015-03-04 11:55:36 -03:00
1, deps.depends[0]);
2014-10-22 13:44:02 -03:00
i = 1;
2015-03-04 11:55:36 -03:00
while (i < deps.depends.length) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
2015-03-04 11:55:36 -03:00
1, deps.depends[i]);
2014-10-22 13:44:02 -03:00
i++;
}
}
2015-03-04 11:55:36 -03:00
if (deps.optdepends.length != 0) {
string[] uninstalled_optdeps = transaction.get_pkg_uninstalled_optdeps (pkgname);
string optdep = deps.optdepends[0];
if ((optdep in uninstalled_optdeps) == false) {
optdep = optdep + " [" + dgettext (null, "Installed") + "]";
}
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
2014-10-26 08:30:04 -03:00
0, dgettext (null, "Optional Dependencies") + ":",
2015-03-04 11:55:36 -03:00
1, optdep);
2014-10-22 13:44:02 -03:00
i = 1;
2015-03-04 11:55:36 -03:00
while (i < deps.optdepends.length) {
optdep = deps.optdepends[i];
if ((optdep in uninstalled_optdeps) == false) {
optdep = optdep + " [" + dgettext (null, "Installed") + "]";
}
deps_list.insert_with_values (out iter, -1, 1, optdep);
2014-10-22 13:44:02 -03:00
i++;
}
}
2015-03-04 11:55:36 -03:00
if (deps.repo == "local") {
if (deps.requiredby.length != 0) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
0, dgettext (null, "Required By") + ":",
2015-03-04 11:55:36 -03:00
1, deps.requiredby[0]);
2014-10-22 13:44:02 -03:00
i = 1;
2015-03-04 11:55:36 -03:00
while (i < deps.requiredby.length) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
2015-03-04 11:55:36 -03:00
1, deps.requiredby[i]);
2014-10-22 13:44:02 -03:00
i++;
}
}
}
if (deps.repo == "local") {
if (deps.optionalfor.length != 0) {
deps_list.insert_with_values (out iter, -1,
0, dgettext (null, "Optional For") + ":",
1, deps.optionalfor[0]);
i = 1;
while (i < deps.optionalfor.length) {
deps_list.insert_with_values (out iter, -1,
1, deps.optionalfor[i]);
i++;
}
}
}
2015-03-04 11:55:36 -03:00
if (deps.provides.length != 0) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
0, dgettext (null, "Provides") + ":",
2015-03-04 11:55:36 -03:00
1, deps.provides[0]);
2014-10-22 13:44:02 -03:00
i = 1;
2015-03-04 11:55:36 -03:00
while (i < deps.provides.length) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
2015-03-04 11:55:36 -03:00
1, deps.provides[i]);
2014-10-22 13:44:02 -03:00
i++;
}
}
2015-03-04 11:55:36 -03:00
if (deps.replaces.length != 0) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
0, dgettext (null, "Replaces") + ":",
2015-03-04 11:55:36 -03:00
1, deps.replaces[0]);
2014-10-22 13:44:02 -03:00
i = 1;
2015-03-04 11:55:36 -03:00
while (i < deps.replaces.length) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
2015-03-04 11:55:36 -03:00
1, deps.replaces[i]);
2014-10-22 13:44:02 -03:00
i++;
}
}
2015-03-04 11:55:36 -03:00
if (deps.conflicts.length != 0) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
0, dgettext (null, "Conflicts With") + ":",
2015-03-04 11:55:36 -03:00
1, deps.conflicts[0]);
2014-10-22 13:44:02 -03:00
i = 1;
2015-03-04 11:55:36 -03:00
while (i < deps.conflicts.length) {
2014-10-22 13:44:02 -03:00
deps_list.insert_with_values (out iter, -1,
2015-03-04 11:55:36 -03:00
1, deps.conflicts[i]);
2014-10-22 13:44:02 -03:00
i++;
}
}
}
2015-03-04 11:55:36 -03:00
public void set_details_list (string pkgname) {
2014-10-22 13:44:02 -03:00
details_list.clear ();
2015-03-04 11:55:36 -03:00
Gtk.TreeIter iter;
PackageDetails details = transaction.get_pkg_details (pkgname);
int i;
if (details.repo != "local" && details.repo != "AUR") {
2014-10-22 13:44:02 -03:00
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Repository") + ":",
2015-03-04 11:55:36 -03:00
1, details.repo);
2014-10-22 13:44:02 -03:00
}
2015-03-04 11:55:36 -03:00
if (details.groups.length != 0) {
2014-10-22 13:44:02 -03:00
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Groups") + ":",
2015-03-04 11:55:36 -03:00
1, details.groups[0]);
2014-10-22 13:44:02 -03:00
i = 1;
2015-03-04 11:55:36 -03:00
while (i < details.groups.length) {
2014-10-22 13:44:02 -03:00
details_list.insert_with_values (out iter, -1,
2015-03-04 11:55:36 -03:00
1, details.groups[i]);
2014-10-22 13:44:02 -03:00
i++;
}
}
if (details.repo == "AUR") {
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Maintainer") + ":",
1, details.packager);
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "First Submitted") + ":",
1, details.build_date);
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Last Modified") + ":",
1, details.install_date);
} else {
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Packager") + ":",
1, details.packager);
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Build Date") + ":",
1, details.build_date);
}
2015-03-04 11:55:36 -03:00
if (details.repo == "local") {
2014-10-22 13:44:02 -03:00
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Install Date") + ":",
2015-03-04 11:55:36 -03:00
1, details.install_date);
2014-10-22 13:44:02 -03:00
string reason;
2015-03-04 11:55:36 -03:00
if (details.reason == Alpm.Package.Reason.EXPLICIT) {
2014-10-22 13:44:02 -03:00
reason = dgettext (null, "Explicitly installed");
2015-03-04 11:55:36 -03:00
} else if (details.reason == Alpm.Package.Reason.DEPEND) {
2014-10-22 13:44:02 -03:00
reason = dgettext (null, "Installed as a dependency for another package");
2015-03-04 11:55:36 -03:00
} else {
2014-10-22 13:44:02 -03:00
reason = dgettext (null, "Unknown");
2015-03-04 11:55:36 -03:00
}
2014-10-22 13:44:02 -03:00
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Install Reason") + ":",
1, reason);
}
if (details.repo != "local" && details.repo != "AUR") {
2014-10-22 13:44:02 -03:00
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Signatures") + ":",
2015-03-04 11:55:36 -03:00
1, details.has_signature);
2014-10-22 13:44:02 -03:00
}
if (details.repo == "AUR") {
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Votes") + ":",
1, details.reason.to_string ());
if (details.has_signature != "") {
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Out of Date") + ":",
1, details.has_signature);
}
}
2015-03-04 11:55:36 -03:00
if (details.repo == "local") {
if (details.backups.length != 0) {
2014-10-22 13:44:02 -03:00
details_list.insert_with_values (out iter, -1,
0, dgettext (null, "Backup files") + ":",
2015-03-04 11:55:36 -03:00
1, "/" + details.backups[0]);
2014-10-22 13:44:02 -03:00
i = 1;
2015-03-04 11:55:36 -03:00
while (i < details.backups.length) {
2014-10-22 13:44:02 -03:00
details_list.insert_with_values (out iter, -1,
2015-03-04 11:55:36 -03:00
1, "/" + details.backups[i]);
2014-10-22 13:44:02 -03:00
i++;
}
}
}
}
2015-03-04 11:55:36 -03:00
public void set_files_list (string pkgname) {
2014-10-22 13:44:02 -03:00
StringBuilder text = new StringBuilder ();
2015-03-04 11:55:36 -03:00
foreach (var file in transaction.get_pkg_files (pkgname)) {
if (text.len != 0) {
2014-10-22 13:44:02 -03:00
text.append ("\n");
2015-03-04 11:55:36 -03:00
}
2014-10-22 13:44:02 -03:00
text.append ("/");
2015-03-04 11:55:36 -03:00
text.append (file);
2014-10-22 13:44:02 -03:00
}
files_textview.buffer.set_text (text.str, (int) text.len);
}
2015-03-04 11:55:36 -03:00
public void populate_packages_list (Pamac.Package[] pkgs) {
2014-10-22 13:44:02 -03:00
packages_treeview.freeze_child_notify ();
packages_treeview.set_model (null);
// populate liststore
2015-03-04 11:55:36 -03:00
packages_list = new PackagesModel (pkgs, this);
2014-10-22 13:44:02 -03:00
// sort liststore
int column = sortinfo.column_number;
2015-03-04 11:55:36 -03:00
switch (column) {
case 0:
packages_list.sort_by_name (sortinfo.sort_type);
break;
case 1:
packages_list.sort_by_state (sortinfo.sort_type);
break;
case 2:
packages_list.sort_by_version (sortinfo.sort_type);
break;
case 3:
packages_list.sort_by_repo (sortinfo.sort_type);
break;
case 4:
packages_list.sort_by_size (sortinfo.sort_type);
break;
default:
break;
}
2014-10-22 13:44:02 -03:00
packages_treeview.set_model (packages_list);
packages_treeview.thaw_child_notify ();
this.get_window ().set_cursor (null);
}
public void refresh_packages_list () {
int current_page = filters_notebook.get_current_page ();
if (current_page == 0) {
2015-03-04 11:55:36 -03:00
Gtk.TreeSelection selection = search_treeview.get_selection ();
if (selection.get_selected (null, null)) {
2014-10-22 13:44:02 -03:00
on_search_treeview_selection_changed ();
2014-11-24 17:34:23 -03:00
} else {
show_all_pkgs ();
2014-10-22 13:44:02 -03:00
}
} else if (current_page == 1) {
on_groups_treeview_selection_changed ();
} else if (current_page == 2) {
on_states_treeview_selection_changed ();
} else if (current_page == 3) {
on_repos_treeview_selection_changed ();
}
}
2015-03-04 11:55:36 -03:00
public void display_package_properties () {
Gtk.TreeSelection selection = packages_treeview.get_selection ();
GLib.List<Gtk.TreePath> selected = selection.get_selected_rows (null);
if (selected.length () > 0) {
// display info for the first package of the selection
Pamac.Package pkg = packages_list.get_pkg_at_path (selected.nth_data (0));
if (pkg.name == dgettext (null, "No package found")) {
return;
}
2015-04-12 11:22:52 -03:00
if (pkg.repo == "local") {
deps_scrolledwindow.visible = true;
2015-04-12 11:22:52 -03:00
files_scrolledwindow.visible = true;
} else if (pkg.repo == "AUR") {
deps_scrolledwindow.visible = false;
files_scrolledwindow.visible = false;
2015-04-12 11:22:52 -03:00
} else {
deps_scrolledwindow.visible = true;
2015-04-12 11:22:52 -03:00
files_scrolledwindow.visible = false;
}
switch (properties_notebook.get_current_page ()) {
2015-03-04 11:55:36 -03:00
case 0:
set_infos_list (pkg);
break;
case 1:
set_deps_list (pkg.name);
2015-03-04 11:55:36 -03:00
break;
case 2:
set_details_list (pkg.name);
2015-03-04 11:55:36 -03:00
break;
case 3:
set_files_list (pkg.name);
2015-03-04 11:55:36 -03:00
break;
default:
break;
2014-10-22 13:44:02 -03:00
}
}
}
[GtkCallback]
2015-03-04 11:55:36 -03:00
public void on_packages_treeview_selection_changed () {
display_package_properties ();
}
[GtkCallback]
public void on_properties_notebook_switch_page (Gtk.Widget page, uint page_num) {
display_package_properties ();
}
[GtkCallback]
public void on_packages_treeview_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) {
Gtk.TreeIter iter;
2014-10-22 13:44:02 -03:00
if (packages_list.get_iter (out iter, path)) {
GLib.Value val;
packages_list.get_value (iter, 0, out val);
string name = val.get_string ();
if (name != dgettext (null, "No package found")) {
if (transaction.to_add.remove (name)) {
} else if (transaction.to_remove.remove (name)) {
} else if (transaction.to_build.remove (name)) {
2014-10-22 13:44:02 -03:00
} else {
packages_list.get_value (iter, 3, out val);
string db_name = val.get_string ();
if (db_name == "local") {
2015-03-04 11:55:36 -03:00
if (transaction.should_hold (name) == false) {
transaction.to_remove.add ((owned) name);
2014-10-22 13:44:02 -03:00
}
} else if (db_name == "AUR") {
transaction.to_build.add ((owned) name);
2014-10-22 13:44:02 -03:00
} else {
transaction.to_add.add ((owned) name);
2014-10-22 13:44:02 -03:00
}
}
}
}
if (transaction.to_add.length + transaction.to_remove.length + transaction.to_build.length == 0) {
2014-10-22 13:44:02 -03:00
set_buttons_sensitive (false);
} else {
set_buttons_sensitive (true);
}
// force a display refresh
packages_treeview.queue_draw ();
}
void on_install_item_activate () {
2015-03-04 11:55:36 -03:00
Pamac.Package find_pkg;
foreach (Pamac.Package pkg in selected_pkgs) {
2015-03-04 11:55:36 -03:00
if (pkg.repo == "AUR") {
transaction.to_build.add (pkg.name);
2015-03-04 11:55:36 -03:00
} else {
find_pkg = transaction.find_local_pkg (pkg.name);
if (find_pkg.name == "") {
transaction.to_add.add (pkg.name);
2015-03-04 11:55:36 -03:00
}
}
}
if (transaction.to_add.length != 0 || transaction.to_build.length != 0) {
set_buttons_sensitive (true);
}
}
void on_reinstall_item_activate () {
foreach (Pamac.Package pkg in selected_pkgs) {
transaction.to_remove.remove (pkg.name);
2015-03-04 11:55:36 -03:00
if (pkg.repo == "local") {
transaction.to_add.add (pkg.name);
2015-03-04 11:55:36 -03:00
}
}
if (transaction.to_add.length != 0) {
set_buttons_sensitive (true);
2015-03-18 12:07:18 -03:00
}
}
void on_remove_item_activate () {
foreach (Pamac.Package pkg in selected_pkgs) {
transaction.to_add.remove (pkg.name);
2015-03-04 11:55:36 -03:00
if (transaction.should_hold (pkg.name) == false) {
if (pkg.repo == "local") {
transaction.to_remove.add (pkg.name);
2015-03-04 11:55:36 -03:00
}
}
}
if (transaction.to_remove.length != 0) {
set_buttons_sensitive (true);
2015-03-04 11:55:36 -03:00
}
}
void on_deselect_item_activate () {
foreach (Pamac.Package pkg in selected_pkgs) {
if (transaction.to_add.remove (pkg.name)) {
} else if (transaction.to_remove.remove (pkg.name)) {
} else if (transaction.to_build.remove (pkg.name)) {
}
}
if (transaction.to_add.length == 0 && transaction.to_remove.length == 0
&& transaction.to_load.length == 0 && transaction.to_build.length == 0) {
set_buttons_sensitive (false);
}
}
2015-03-04 11:55:36 -03:00
public void choose_opt_dep (Pamac.Package[] pkgs) {
foreach (Pamac.Package pkg in pkgs) {
2015-08-20 10:11:18 -03:00
var choose_dep_dialog = new ChooseDependenciesDialog (transaction, pkg.name, this);
if (choose_dep_dialog.run () == Gtk.ResponseType.OK) {
choose_dep_dialog.deps_list.foreach ((model, path, iter) => {
GLib.Value val;
choose_dep_dialog.deps_list.get_value (iter, 0, out val);
bool selected = val.get_boolean ();
if (selected) {
choose_dep_dialog.deps_list.get_value (iter, 1, out val);
string name = val.get_string ();
transaction.to_add.add ((owned) name);
}
return false;
});
}
choose_dep_dialog.destroy ();
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
}
}
void on_install_optional_deps_item_activate () {
choose_opt_dep (selected_pkgs);
if (transaction.to_add.length != 0) {
set_buttons_sensitive (true);
2015-03-04 11:55:36 -03:00
}
}
void on_explicitly_installed_item_activate () {
foreach (Pamac.Package pkg in selected_pkgs) {
2015-03-04 11:55:36 -03:00
transaction.start_set_pkgreason (pkg.name, Alpm.Package.Reason.EXPLICIT);
}
2014-11-16 07:31:44 -03:00
refresh_packages_list ();
}
2014-10-22 13:44:02 -03:00
[GtkCallback]
public bool on_packages_treeview_button_press_event (Gdk.EventButton event) {
packages_treeview.grab_focus ();
// Check if right mouse button was clicked
if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == 3) {
2015-03-04 11:55:36 -03:00
Gtk.TreePath? treepath;
Pamac.Package clicked_pkg;
2015-03-04 11:55:36 -03:00
Gtk.TreeSelection selection = packages_treeview.get_selection ();
packages_treeview.get_path_at_pos ((int) event.x, (int) event.y, out treepath, null, null, null);
2015-03-04 11:55:36 -03:00
clicked_pkg = packages_list.get_pkg_at_path (treepath);;
if (clicked_pkg.name == dgettext (null, "No package found")) {
return true;
2015-03-04 11:55:36 -03:00
}
if (selection.path_is_selected (treepath) == false) {
selection.unselect_all ();
selection.select_path (treepath);
}
2015-03-04 11:55:36 -03:00
GLib.List<Gtk.TreePath> selected_paths = selection.get_selected_rows (null);
deselect_item.set_sensitive (false);
install_item.set_sensitive (false);
remove_item.set_sensitive (false);
reinstall_item.set_sensitive (false);
install_optional_deps_item.set_sensitive (false);
explicitly_installed_item.set_sensitive (false);
2015-03-04 11:55:36 -03:00
selected_pkgs = {};
foreach (Gtk.TreePath path in selected_paths) {
selected_pkgs += packages_list.get_pkg_at_path (path);
}
foreach (Pamac.Package pkg in selected_pkgs) {
if (transaction.to_add.contains (pkg.name)
|| transaction.to_remove.contains (pkg.name)
|| transaction.to_build.contains (pkg.name)) {
deselect_item.set_sensitive (true);
break;
}
}
foreach (Pamac.Package pkg in selected_pkgs) {
if (pkg.repo != "local") {
install_item.set_sensitive (true);
break;
}
}
foreach (Pamac.Package pkg in selected_pkgs) {
if (pkg.repo == "local") {
remove_item.set_sensitive (true);
break;
}
}
2015-03-04 11:55:36 -03:00
if (selected_pkgs.length == 1) {
clicked_pkg = selected_pkgs[0];
if (clicked_pkg.repo == "local") {
2015-03-04 11:55:36 -03:00
if (transaction.get_pkg_uninstalled_optdeps (clicked_pkg.name).length != 0) {
install_optional_deps_item.set_sensitive (true);
}
2015-03-04 11:55:36 -03:00
if (clicked_pkg.reason == Alpm.Package.Reason.DEPEND) {
explicitly_installed_item.set_sensitive (true);
2015-03-04 11:55:36 -03:00
}
Pamac.Package find_pkg = transaction.find_sync_pkg (clicked_pkg.name);
if (find_pkg.name != "") {
if (Alpm.pkg_vercmp (find_pkg.version, clicked_pkg.version) == 0) {
reinstall_item.set_sensitive (true);
2015-03-04 11:55:36 -03:00
}
}
}
}
right_click_menu.popup (null, null, null, event.button, event.time);
return true;
2015-03-04 11:55:36 -03:00
} else {
return false;
2015-03-04 11:55:36 -03:00
}
2014-10-22 13:44:02 -03:00
}
[GtkCallback]
public void on_name_column_clicked () {
2015-03-04 11:55:36 -03:00
Gtk.SortType new_order;
if (name_column.sort_indicator == false) {
new_order = Gtk.SortType.ASCENDING;
} else {
if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
new_order = Gtk.SortType.DESCENDING;
} else {
new_order = Gtk.SortType.ASCENDING;
}
2014-10-22 13:44:02 -03:00
}
packages_list.sort_by_name (new_order);
// force a display refresh
packages_treeview.queue_draw ();
}
[GtkCallback]
public void on_state_column_clicked () {
2015-03-04 11:55:36 -03:00
Gtk.SortType new_order;
if (state_column.sort_indicator == false) {
new_order = Gtk.SortType.ASCENDING;
} else {
if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
new_order = Gtk.SortType.DESCENDING;
} else {
new_order = Gtk.SortType.ASCENDING;
}
2014-10-22 13:44:02 -03:00
}
packages_list.sort_by_state (new_order);
// force a display refresh
packages_treeview.queue_draw ();
}
[GtkCallback]
public void on_version_column_clicked () {
2015-03-04 11:55:36 -03:00
Gtk.SortType new_order;
if (version_column.sort_indicator == false) {
new_order = Gtk.SortType.ASCENDING;
} else {
if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
new_order = Gtk.SortType.DESCENDING;
} else {
new_order = Gtk.SortType.ASCENDING;
}
2014-10-22 13:44:02 -03:00
}
packages_list.sort_by_version (new_order);
// force a display refresh
packages_treeview.queue_draw ();
}
[GtkCallback]
public void on_repo_column_clicked () {
2015-03-04 11:55:36 -03:00
Gtk.SortType new_order;
if (repo_column.sort_indicator == false) {
new_order = Gtk.SortType.ASCENDING;
} else {
if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
new_order = Gtk.SortType.DESCENDING;
} else {
new_order = Gtk.SortType.ASCENDING;
}
2014-10-22 13:44:02 -03:00
}
packages_list.sort_by_repo (new_order);
// force a display refresh
packages_treeview.queue_draw ();
}
[GtkCallback]
public void on_size_column_clicked () {
2015-03-04 11:55:36 -03:00
Gtk.SortType new_order;
if (size_column.sort_indicator == false) {
new_order = Gtk.SortType.ASCENDING;
} else {
if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
new_order = Gtk.SortType.DESCENDING;
} else {
new_order = Gtk.SortType.ASCENDING;
}
2014-10-22 13:44:02 -03:00
}
packages_list.sort_by_size (new_order);
// force a display refresh
packages_treeview.queue_draw ();
}
[GtkCallback]
public void on_search_entry_activate () {
string search_string = search_entry.get_text ();
if (search_string != "") {
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.search_pkgs.begin (search_string, search_aur_button.get_active (), (obj, res) => {
var pkgs = transaction.search_pkgs.end (res);
if (pkgs.length != 0) {
2014-10-22 13:44:02 -03:00
// add search string in search_list if needed
bool found = false;
2015-03-04 11:55:36 -03:00
Gtk.TreeIter? iter;
Gtk.TreeModel model;
Gtk.TreeSelection selection = search_treeview.get_selection ();
2014-10-22 13:44:02 -03:00
// check if search string is already selected in search list
if (selection.get_selected (out model, out iter)) {
GLib.Value val;
model.get_value (iter, 0, out val);
string selected_string = val.get_string ();
if (selected_string == search_string) {
found = true;
// we need to populate packages_list
2015-03-04 11:55:36 -03:00
populate_packages_list (pkgs);
2014-10-22 13:44:02 -03:00
} else {
search_list.foreach ((_model, _path, _iter) => {
GLib.Value line;
model.get_value (_iter, 0, out line);
if ((string) line == search_string) {
found = true;
2014-10-30 10:44:09 -03:00
// block the signal to not populate when we select the iter in search_list
2014-11-16 07:31:44 -03:00
selection.changed.disconnect (on_search_treeview_selection_changed);
2014-10-22 13:44:02 -03:00
selection.select_iter (_iter);
2014-11-16 07:31:44 -03:00
selection.changed.connect_after (on_search_treeview_selection_changed);
2015-03-04 11:55:36 -03:00
populate_packages_list (pkgs);
2014-10-22 13:44:02 -03:00
}
return found;
});
}
}
2014-11-16 07:31:44 -03:00
if (found == false) {
2014-10-22 13:44:02 -03:00
search_list.insert_with_values (out iter, -1, 0, search_string);
2014-10-30 10:44:09 -03:00
// block the signal to not populate when we select the iter in search_list
2014-11-16 07:31:44 -03:00
selection.changed.disconnect (on_search_treeview_selection_changed);
2014-10-22 13:44:02 -03:00
selection.select_iter (iter);
2014-11-16 07:31:44 -03:00
selection.changed.connect_after (on_search_treeview_selection_changed);
2015-03-04 11:55:36 -03:00
populate_packages_list (pkgs);
2014-10-22 13:44:02 -03:00
}
2014-11-16 07:31:44 -03:00
} else {
2014-10-22 13:44:02 -03:00
// populate with empty lists
2015-03-04 11:55:36 -03:00
populate_packages_list (pkgs);
2014-11-16 07:31:44 -03:00
}
});
2014-10-22 13:44:02 -03:00
}
}
[GtkCallback]
2015-03-04 11:55:36 -03:00
public void on_search_entry_icon_press (Gtk.EntryIconPosition p0, Gdk.Event? p1) {
2014-10-22 13:44:02 -03:00
on_search_entry_activate ();
}
[GtkCallback]
public void on_search_treeview_selection_changed () {
2015-03-04 11:55:36 -03:00
Gtk.TreeModel model;
Gtk.TreeIter? iter;
Gtk.TreeSelection selection = search_treeview.get_selection ();
2014-10-22 13:44:02 -03:00
if (selection.get_selected (out model, out iter)) {
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));
2014-10-22 13:44:02 -03:00
GLib.Value val;
model.get_value (iter, 0, out val);
string search_string = val.get_string ();
2015-03-04 11:55:36 -03:00
transaction.search_pkgs.begin (search_string, search_aur_button.get_active (), (obj, res) => {
var pkgs = transaction.search_pkgs.end (res);
populate_packages_list (pkgs);
2015-01-28 12:40:05 -03:00
});
2014-10-22 13:44:02 -03:00
}
}
[GtkCallback]
public void on_groups_treeview_selection_changed () {
2015-03-04 11:55:36 -03:00
Gtk.TreeModel model;
Gtk.TreeIter? iter;
Gtk.TreeSelection selection = groups_treeview.get_selection ();
2014-10-22 13:44:02 -03:00
if (selection.get_selected (out model, out iter)) {
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));
2014-10-22 13:44:02 -03:00
GLib.Value val;
model.get_value (iter, 0, out val);
string grp_name = val.get_string ();
2015-03-04 11:55:36 -03:00
transaction.get_group_pkgs.begin (grp_name, (obj, res) => {
var pkgs = transaction.get_group_pkgs.end (res);
populate_packages_list (pkgs);
});
2014-10-22 13:44:02 -03:00
}
}
[GtkCallback]
public void on_states_treeview_selection_changed () {
2015-03-04 11:55:36 -03:00
Gtk.TreeModel model;
Gtk.TreeIter? iter;
Gtk.TreeSelection selection = states_treeview.get_selection ();
2014-10-22 13:44:02 -03:00
if (selection.get_selected (out model, out iter)) {
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));
2014-10-22 13:44:02 -03:00
GLib.Value val;
model.get_value (iter, 0, out val);
string state = val.get_string ();
2015-03-04 11:55:36 -03:00
Pamac.Package[] pkgs = {};
Pamac.Package find_pkg;
2014-10-22 13:44:02 -03:00
if (state == dgettext (null, "To install")) {
foreach (string name in transaction.to_add) {
2015-03-04 11:55:36 -03:00
find_pkg = transaction.find_local_pkg (name);
if (find_pkg.name != "") {
pkgs += find_pkg;
} else {
find_pkg = transaction.find_sync_pkg (name);
if (find_pkg.name != "") {
pkgs += find_pkg;
}
2014-10-22 13:44:02 -03:00
}
}
2015-03-04 11:55:36 -03:00
populate_packages_list (pkgs);
2014-10-22 13:44:02 -03:00
} else if (state == dgettext (null, "To remove")) {
foreach (string name in transaction.to_remove) {
2015-03-04 11:55:36 -03:00
find_pkg = transaction.find_local_pkg (name);
if (find_pkg.name != "") {
pkgs += find_pkg;
}
2014-10-22 13:44:02 -03:00
}
2015-03-04 11:55:36 -03:00
populate_packages_list (pkgs);
2014-10-22 13:44:02 -03:00
} else if (state == dgettext (null, "Installed")) {
2015-03-04 11:55:36 -03:00
transaction.get_installed_pkgs.begin ((obj, res) => {
pkgs = transaction.get_installed_pkgs.end (res);
populate_packages_list (pkgs);
});
2014-10-22 13:44:02 -03:00
} else if (state == dgettext (null, "Uninstalled")) {
2015-03-04 11:55:36 -03:00
//transaction.get_sync_pkgs.begin ((obj, res) => {
//pkgs = transaction.get_sync_pkgs.end (res);
//populate_packages_list (pkgs);
//});
2014-10-22 13:44:02 -03:00
} else if (state == dgettext (null, "Orphans")) {
2015-03-04 11:55:36 -03:00
transaction.get_orphans.begin ((obj, res) => {
pkgs = transaction.get_orphans.end (res);
populate_packages_list (pkgs);
});
2014-10-22 13:44:02 -03:00
}
}
}
[GtkCallback]
public void on_repos_treeview_selection_changed () {
2015-03-04 11:55:36 -03:00
Gtk.TreeModel model;
Gtk.TreeIter? iter;
Gtk.TreeSelection selection = repos_treeview.get_selection ();
2014-10-22 13:44:02 -03:00
if (selection.get_selected (out model, out iter)) {
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));
2014-10-22 13:44:02 -03:00
GLib.Value val;
model.get_value (iter, 0, out val);
string repo = val.get_string ();
if (repo == dgettext (null, "local")) {
2015-03-04 11:55:36 -03:00
transaction.get_local_pkgs.begin ((obj, res) => {
var pkgs = transaction.get_local_pkgs.end (res);
populate_packages_list (pkgs);
});
2014-10-22 13:44:02 -03:00
} else {
2015-03-04 11:55:36 -03:00
transaction.get_repo_pkgs.begin (repo, (obj, res) => {
var pkgs = transaction.get_repo_pkgs.end (res);
populate_packages_list (pkgs);
});
2014-10-22 13:44:02 -03:00
}
}
}
[GtkCallback]
2015-03-04 11:55:36 -03:00
public void on_filters_notebook_switch_page (Gtk.Widget page, uint page_num) {
2014-10-22 13:44:02 -03:00
refresh_packages_list ();
}
[GtkCallback]
public void on_history_item_activate () {
2014-10-22 13:44:02 -03:00
var file = GLib.File.new_for_path ("/var/log/pamac.log");
2015-03-18 12:07:18 -03:00
if (!file.query_exists ()) {
2014-10-22 13:44:02 -03:00
GLib.stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
2015-03-18 12:07:18 -03:00
} else {
2014-10-22 13:44:02 -03:00
StringBuilder text = new StringBuilder ();
try {
// Open file for reading and wrap returned FileInputStream into a
// DataInputStream, so we can read line by line
var dis = new DataInputStream (file.read ());
string line;
// Read lines until end of file (null) is reached
while ((line = dis.read_line ()) != null) {
// construct text in reverse order
text.prepend (line + "\n");
2014-10-22 13:44:02 -03:00
}
} catch (GLib.Error e) {
2015-01-28 12:40:05 -03:00
GLib.stderr.printf ("%s\n", e.message);
2014-10-22 13:44:02 -03:00
}
var history_dialog = new HistoryDialog (this);
2014-10-22 13:44:02 -03:00
history_dialog.textview.buffer.set_text (text.str, (int) text.len);
history_dialog.run ();
history_dialog.destroy ();
2015-03-18 12:07:18 -03:00
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
2015-03-18 12:07:18 -03:00
}
2014-10-22 13:44:02 -03:00
}
}
[GtkCallback]
public void on_local_item_activate () {
Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog (
2015-08-20 10:11:18 -03:00
dgettext (null, "Install Local Packages"), this, Gtk.FileChooserAction.OPEN,
dgettext (null, "_Cancel"), Gtk.ResponseType.CANCEL,
dgettext (null, "_Open"),Gtk.ResponseType.ACCEPT);
chooser.window_position = Gtk.WindowPosition.CENTER_ON_PARENT;
chooser.icon_name = "system-software-install";
chooser.default_width = 900;
chooser.select_multiple = true;
chooser.local_only = false;
chooser.create_folders = false;
Gtk.FileFilter package_filter = new Gtk.FileFilter ();
package_filter.set_filter_name (dgettext (null, "Alpm Package"));
package_filter.add_pattern ("*.pkg.tar.xz");
chooser.add_filter (package_filter);
if (chooser.run () == Gtk.ResponseType.ACCEPT) {
SList<string> packages_paths = chooser.get_filenames ();
2014-10-22 13:44:02 -03:00
if (packages_paths.length () != 0) {
foreach (string path in packages_paths) {
transaction.to_load.add (path);
2014-10-22 13:44:02 -03:00
}
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));
chooser.destroy ();
2015-03-18 12:07:18 -03:00
while (Gtk.events_pending ()) {
2014-10-22 13:44:02 -03:00
Gtk.main_iteration ();
2015-03-18 12:07:18 -03:00
}
2014-10-22 13:44:02 -03:00
transaction.run ();
}
2015-03-04 11:55:36 -03:00
} else {
chooser.destroy ();
2015-03-04 11:55:36 -03:00
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
2015-03-04 11:55:36 -03:00
}
}
2015-08-20 10:11:18 -03:00
}
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_item_activate () {
2015-08-20 10:11:18 -03:00
run_preferences_dialog.begin ();
2014-10-22 13:44:02 -03:00
}
[GtkCallback]
public void on_about_item_activate () {
Gtk.show_about_dialog (
this,
"program_name", "Pamac",
"logo_icon_name", "system-software-install",
2014-10-26 08:30:04 -03:00
"comments", dgettext (null, "A Gtk3 frontend for libalpm"),
2015-03-18 12:17:30 -03:00
"copyright", dgettext (null, "Copyright © 2015 Guillaume Benoit"),
2014-10-22 13:44:02 -03:00
"version", VERSION,
2015-03-04 11:55:36 -03:00
"license_type", Gtk.License.GPL_3_0,
2014-10-22 13:44:02 -03:00
"website", "http://manjaro.org");
}
[GtkCallback]
public void on_valid_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));
2014-10-22 13:44:02 -03:00
transaction.run ();
}
[GtkCallback]
public void on_cancel_button_clicked () {
transaction.clear_lists ();
set_buttons_sensitive (false);
// force a display refresh
packages_treeview.queue_draw ();
}
[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
}
2015-03-04 11:55:36 -03:00
public void on_transaction_finished (bool error) {
2014-10-22 13:44:02 -03:00
if (error == false) {
set_buttons_sensitive (false);
refresh_packages_list ();
}
transaction.to_load.remove_all ();
2014-10-22 13:44:02 -03:00
this.get_window ().set_cursor (null);
}
}
}