Commit a94f2157 authored by Guillaume Benoit's avatar Guillaume Benoit

stabilize ui

parent 52f5a7af
......@@ -133,78 +133,23 @@ namespace Pamac {
}
public async List<Package> get_installed_pkgs_async () {
var pkgs = new List<Package> ();
new Thread<int> ("get_installed_pkgs", () => {
pkgs = alpm_utils.get_installed_pkgs ();
Idle.add (get_installed_pkgs_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.get_installed_pkgs ();
}
public async List<Package> get_installed_apps_async () {
var pkgs = new List<Package> ();
new Thread<int> ("get_installed_apps", () => {
pkgs = alpm_utils.get_installed_apps ();
Idle.add (get_installed_apps_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.get_installed_apps ();
}
public async List<Package> get_explicitly_installed_pkgs_async () {
var pkgs = new List<Package> ();
new Thread<int> ("get_explicitly_installed_pkgs", () => {
pkgs = alpm_utils.get_explicitly_installed_pkgs ();
Idle.add (get_explicitly_installed_pkgs_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.get_explicitly_installed_pkgs ();
}
public async List<Package> get_foreign_pkgs_async () {
var pkgs = new List<Package> ();
new Thread<int> ("get_foreign_pkgs", () => {
pkgs = alpm_utils.get_foreign_pkgs ();
Idle.add (get_foreign_pkgs_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.get_foreign_pkgs ();
}
public async List<Package> get_orphans_async () {
var pkgs = new List<Package> ();
new Thread<int> ("get_orphans", () => {
pkgs = alpm_utils.get_orphans ();
Idle.add (get_orphans_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.get_orphans ();
}
public Package get_sync_pkg (string pkgname) {
......@@ -220,18 +165,7 @@ namespace Pamac {
}
public async List<Package> search_pkgs_async (string search_string) {
var pkgs = new List<Package> ();
new Thread<int> ("search_pkgs", () => {
pkgs = alpm_utils.search_pkgs (search_string);
Idle.add (search_pkgs_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.search_pkgs (search_string);
}
public List<AURPackage> search_in_aur (string search_string) {
......@@ -243,18 +177,7 @@ namespace Pamac {
}
public async List<AURPackage> search_in_aur_async (string search_string) {
var pkgs = new List<AURPackage> ();
new Thread<int> ("search_in_aur", () => {
pkgs = alpm_utils.search_in_aur (search_string);
Idle.add (search_in_aur_async.callback);
return 0;
});
yield;
var result = new List<AURPackage> ();
foreach (unowned AURPackage pkg in pkgs) {
result.append (pkg);
}
return result;
return search_in_aur (search_string);
}
public HashTable<string, Variant> search_files (string[] files) {
......@@ -266,18 +189,7 @@ namespace Pamac {
}
public async List<Package> get_category_pkgs_async (string category) {
var pkgs = new List<Package> ();
new Thread<int> ("get_category_pkgs", () => {
pkgs = alpm_utils.get_category_pkgs (category);
Idle.add (get_category_pkgs_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.get_category_pkgs (category);
}
public List<string> get_repos_names () {
......@@ -289,18 +201,7 @@ namespace Pamac {
}
public async List<Package> get_repo_pkgs_async (string repo) {
var pkgs = new List<Package> ();
new Thread<int> ("get_repo_pkgs", () => {
pkgs = alpm_utils.get_repo_pkgs (repo);
Idle.add (get_repo_pkgs_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.get_repo_pkgs (repo);
}
public List<string> get_groups_names () {
......@@ -312,18 +213,7 @@ namespace Pamac {
}
public async List<Package> get_group_pkgs_async (string group_name) {
var pkgs = new List<Package> ();
new Thread<int> ("get_group_pkgs", () => {
pkgs = alpm_utils.get_group_pkgs (group_name);
Idle.add (get_group_pkgs_async.callback);
return 0;
});
yield;
var result = new List<Package> ();
foreach (unowned Package pkg in pkgs) {
result.append (pkg);
}
return result;
return alpm_utils.get_group_pkgs (group_name);
}
public List<string> get_pkg_uninstalled_optdeps (string pkgname) {
......@@ -339,18 +229,7 @@ namespace Pamac {
}
public async List<string> get_pkg_files_async (string pkgname) {
var files = new List<string> ();
new Thread<int> ("get_pkg_files", () => {
files = alpm_utils.get_pkg_files (pkgname);
Idle.add (get_pkg_files_async.callback);
return 0;
});
yield;
var result = new List<string> ();
foreach (unowned string file in files) {
result.append (file);
}
return result;
return alpm_utils.get_pkg_files (pkgname);
}
public AURPackage get_aur_pkg (string pkgname) {
......@@ -362,14 +241,7 @@ namespace Pamac {
}
public async AURPackage get_aur_pkg_async (string pkgname) {
var pkg = new AURPackage ();
new Thread<int> ("get_aur_pkg", () => {
pkg = alpm_utils.get_aur_pkg (pkgname);
Idle.add (get_aur_pkg_async.callback);
return 0;
});
yield;
return pkg;
return get_aur_pkg (pkgname);
}
public AURPackageDetails get_aur_pkg_details (string pkgname) {
......@@ -381,14 +253,7 @@ namespace Pamac {
}
public async AURPackageDetails get_aur_pkg_details_async (string pkgname) {
var pkg = new AURPackageDetails ();
new Thread<int> ("get_aur_pkg_details", () => {
pkg = alpm_utils.get_aur_pkg_details (pkgname);
Idle.add (get_aur_pkg_details_async.callback);
return 0;
});
yield;
return pkg;
return get_aur_pkg_details (pkgname);
}
public Updates get_updates () {
......@@ -400,14 +265,7 @@ namespace Pamac {
}
public async Updates get_updates_async () {
var updates = new Updates ();
new Thread<int> ("get_updates", () => {
updates = get_updates ();
Idle.add (get_updates_async.callback);
return 0;
});
yield;
return updates;
return get_updates ();
}
void on_emit_get_updates_progress (uint percent) {
......
......@@ -2333,8 +2333,11 @@ namespace Pamac {
} else if (category == dgettext (null, "System Tools")) {
matching_cat = "System";
}
database.get_category_pkgs_async.begin (matching_cat, (obj, res) => {
populate_packages_list (database.get_category_pkgs_async.end (res));
Timeout.add (200, () => {
database.get_category_pkgs_async.begin (matching_cat, (obj, res) => {
populate_packages_list (database.get_category_pkgs_async.end (res));
});
return false;
});
}
......@@ -2345,8 +2348,11 @@ namespace Pamac {
var label = row.get_child () as Gtk.Label;
string group_name = label.label;
this.title = group_name;
database.get_group_pkgs_async.begin (group_name, (obj, res) => {
populate_packages_list (database.get_group_pkgs_async.end (res));
Timeout.add (200, () => {
database.get_group_pkgs_async.begin (group_name, (obj, res) => {
populate_packages_list (database.get_group_pkgs_async.end (res));
});
return false;
});
}
......@@ -2359,23 +2365,35 @@ namespace Pamac {
int index = row.get_index ();
switch (index) {
case 0: // Installed
database.get_installed_pkgs_async.begin ((obj, res) => {
populate_packages_list (database.get_installed_pkgs_async.end (res));
Timeout.add (200, () => {
database.get_installed_pkgs_async.begin ((obj, res) => {
populate_packages_list (database.get_installed_pkgs_async.end (res));
});
return false;
});
break;
case 1: // Explicitly installed
database.get_explicitly_installed_pkgs_async.begin ((obj, res) => {
populate_packages_list (database.get_explicitly_installed_pkgs_async.end (res));
Timeout.add (200, () => {
database.get_explicitly_installed_pkgs_async.begin ((obj, res) => {
populate_packages_list (database.get_explicitly_installed_pkgs_async.end (res));
});
return false;
});
break;
case 2: // Orphans
database.get_orphans_async.begin ((obj, res) => {
populate_packages_list (database.get_orphans_async.end (res));
Timeout.add (200, () => {
database.get_orphans_async.begin ((obj, res) => {
populate_packages_list (database.get_orphans_async.end (res));
});
return false;
});
break;
case 3: // Foreign
database.get_foreign_pkgs_async.begin ((obj, res) => {
populate_packages_list (database.get_foreign_pkgs_async.end (res));
Timeout.add (200, () => {
database.get_foreign_pkgs_async.begin ((obj, res) => {
populate_packages_list (database.get_foreign_pkgs_async.end (res));
});
return false;
});
break;
default:
......@@ -2390,8 +2408,11 @@ namespace Pamac {
var label = row.get_child () as Gtk.Label;
string repo = label.label;
this.title = repo;
database.get_repo_pkgs_async.begin (repo, (obj, res) => {
populate_packages_list (database.get_repo_pkgs_async.end (res));
Timeout.add (200, () => {
database.get_repo_pkgs_async.begin (repo, (obj, res) => {
populate_packages_list (database.get_repo_pkgs_async.end (res));
});
return false;
});
}
......@@ -2524,18 +2545,21 @@ namespace Pamac {
}
public void run_preferences_dialog () {
transaction.check_authorization.begin ((obj, res) => {
bool authorized = transaction.check_authorization.end (res);
if (authorized) {
var preferences_dialog = new PreferencesDialog (transaction);
preferences_dialog.run ();
preferences_dialog.destroy ();
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
transaction.get_authorization_finished.connect (launch_preferences_dialog);
transaction.start_get_authorization ();
}
void launch_preferences_dialog (bool authorized) {
transaction.get_authorization_finished.disconnect (launch_preferences_dialog);
if (authorized) {
var preferences_dialog = new PreferencesDialog (transaction);
preferences_dialog.run ();
preferences_dialog.destroy ();
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
on_run_preferences_dialog_finished ();
});
}
on_run_preferences_dialog_finished ();
}
void on_run_preferences_dialog_finished () {
......
......@@ -35,6 +35,7 @@ namespace Pamac {
bool no_confirm_commit;
bool enable_downgrade;
bool sysupgrading;
bool force_refresh;
string[] to_install_first;
string[] temporary_ignorepkgs;
string[] overwrite_files;
......@@ -67,6 +68,7 @@ namespace Pamac {
public signal void stop_building ();
public signal void important_details_outpout (bool must_show);
public signal void downloading_updates_finished ();
public signal void get_authorization_finished (bool authorized);
public signal void refresh_finished (bool success);
public signal void finished (bool success);
public signal void sysupgrade_finished (bool success);
......@@ -90,6 +92,7 @@ namespace Pamac {
// use dbus daemon
transaction_interface = new TransactionInterfaceDaemon (database.config);
}
transaction_interface.get_authorization_finished.connect (on_get_authorization_finished);
// transaction options
flags = 0;
enable_downgrade = false;
......@@ -137,16 +140,12 @@ namespace Pamac {
return transaction_interface.unlock ();
}
public async bool check_authorization () {
bool authorized = false;
ulong handler_id = transaction_interface.get_authorization_finished.connect ((authorized_) => {
authorized = authorized_;
Idle.add (check_authorization.callback);
});
public void start_get_authorization () {
transaction_interface.start_get_authorization ();
yield;
transaction_interface.disconnect (handler_id);
return authorized;
}
void on_get_authorization_finished (bool authorized) {
get_authorization_finished (authorized);
}
public void start_write_pamac_config (HashTable<string,Variant> new_pamac_conf) {
......@@ -177,20 +176,24 @@ namespace Pamac {
transaction_interface.start_set_pkgreason (pkgname, reason);
}
void launch_refresh (bool authorized) {
get_authorization_finished.disconnect (launch_refresh);
if (authorized) {
emit_action (dgettext (null, "Synchronizing package databases") + "...");
connecting_signals ();
transaction_interface.refresh_finished.connect (on_refresh_finished);
transaction_interface.start_refresh (force_refresh);
start_downloading ();
} else {
on_refresh_finished (false);
}
}
public void start_refresh (bool force) {
force_refresh = force;
// check autorization to send start_downloading signal after that
check_authorization.begin ((obj, res) => {
bool authorized = check_authorization.end (res);
if (authorized) {
emit_action (dgettext (null, "Synchronizing package databases") + "...");
connecting_signals ();
transaction_interface.refresh_finished.connect (on_refresh_finished);
transaction_interface.start_refresh (force);
start_downloading ();
} else {
on_refresh_finished (false);
}
});
get_authorization_finished.connect (launch_refresh);
start_get_authorization ();
}
public void start_downloading_updates () {
......@@ -803,19 +806,22 @@ namespace Pamac {
}
}
void launch_build_next_aur_package (bool authorized) {
get_authorization_finished.disconnect (launch_build_next_aur_package);
if (authorized) {
build_next_aur_package.begin ();
} else {
to_build_queue.clear ();
on_trans_commit_finished (false);
}
}
void on_trans_commit_finished (bool success) {
if (success) {
if (to_build_queue.get_length () != 0) {
emit_script_output ("");
check_authorization.begin ((obj, res) => {
bool authorized = check_authorization.end (res);
if (authorized) {
build_next_aur_package.begin ();
} else {
to_build_queue.clear ();
on_trans_commit_finished (false);
}
});
get_authorization_finished.connect (launch_build_next_aur_package);
start_get_authorization ();
} else {
if (sysupgrade_after_trans) {
sysupgrade_after_trans = false;
......
......@@ -110,6 +110,7 @@ namespace Pamac {
}
void on_get_authorization_finished (bool authorized) {
system_daemon.get_authorization_finished.disconnect (on_get_authorization_finished);
get_authorization_finished (authorized);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment