add clean cache feature in preferences (as paccache frontend)

This commit is contained in:
guinux
2016-08-25 12:33:16 +02:00
parent eb57d65876
commit 412d1f9a02
6 changed files with 192 additions and 26 deletions

View File

@@ -281,12 +281,50 @@ namespace Pamac {
generate_mirrors_list_finished ();
}
public void start_generate_mirrors_list () {
try {
thread_pool.add (new AlpmAction (generate_mirrors_list));
} catch (ThreadError e) {
stderr.printf ("Thread Error %s\n", e.message);
}
public void start_generate_mirrors_list (GLib.BusName sender) {
check_authorization.begin (sender, (obj, res) => {
bool authorized = check_authorization.end (res);
if (authorized) {
try {
thread_pool.add (new AlpmAction (generate_mirrors_list));
} catch (ThreadError e) {
stderr.printf ("Thread Error %s\n", e.message);
}
} else {
current_error = ErrorInfos () {
message = _("Authentication failed")
};
}
});
}
public void clean_cache (uint keep_nb, bool only_uninstalled, GLib.BusName sender) {
check_authorization.begin (sender, (obj, res) => {
bool authorized = check_authorization.end (res);
if (authorized) {
string[] commands = {"paccache", "-rq"};
commands += "-k%u".printf (keep_nb);
if (only_uninstalled) {
commands += "-u";
}
try {
var process = new Subprocess.newv (
commands,
SubprocessFlags.STDOUT_PIPE | SubprocessFlags.STDERR_MERGE);
var dis = new DataInputStream (process.get_stdout_pipe ());
string? line;
while ((line = dis.read_line ()) != null) {
print ("%s\n",line);
}
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
} else {
current_error = ErrorInfos () {
message = _("Authentication failed")
};
}
});
}
public void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf, GLib.BusName sender) {

View File

@@ -56,6 +56,10 @@ namespace Pamac {
Gtk.CheckButton check_aur_updates_checkbutton;
[GtkChild]
Gtk.CheckButton no_confirm_build_checkbutton;
[GtkChild]
Gtk.SpinButton cache_keep_nb_spin_button;
[GtkChild]
Gtk.CheckButton cache_only_uninstalled_checkbutton;
Gtk.ListStore ignorepkgs_liststore;
Transaction transaction;
@@ -368,5 +372,11 @@ namespace Pamac {
transaction.start_generate_mirrors_list ();
generate_mirrors_list_button.get_style_context ().remove_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
}
[GtkCallback]
void on_cache_clean_button_clicked () {
transaction.clean_cache ((uint) cache_keep_nb_spin_button.get_value_as_int (),
cache_only_uninstalled_checkbutton.active);
}
}
}

View File

@@ -29,6 +29,7 @@ namespace Pamac {
public abstract void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf) throws IOError;
public abstract void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf) throws IOError;
public abstract void start_generate_mirrors_list () throws IOError;
public abstract void clean_cache (uint keep_nb, bool only_uninstalled) throws IOError;
public abstract void start_set_pkgreason (string pkgname, uint reason) throws IOError;
public abstract AlpmPackage get_installed_pkg (string pkgname) throws IOError;
public abstract void start_refresh (bool force) throws IOError;
@@ -351,6 +352,14 @@ namespace Pamac {
}
}
public void clean_cache (uint keep_nb, bool only_uninstalled) {
try {
daemon.clean_cache (keep_nb, only_uninstalled);
} catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message);
}
}
public void start_set_pkgreason (string pkgname, uint reason) {
try {
daemon.start_set_pkgreason (pkgname, reason);