add new pacman-mirrors support

This commit is contained in:
guinux 2017-04-15 21:34:35 +02:00
parent c071258c24
commit 7c2aa35931
2 changed files with 18 additions and 19 deletions

View File

@ -20,27 +20,29 @@
namespace Pamac { namespace Pamac {
class MirrorsConfig { class MirrorsConfig {
string conf_path; string conf_path;
GLib.List<string> _countrys ; GLib.List<string> _countries ;
public string mirrorlists_dir { get; private set; }
public string choosen_generation_method { get; private set; } public string choosen_generation_method { get; private set; }
public string choosen_country { get; private set; } public string choosen_country { get; private set; }
public unowned GLib.List<string> countrys { public unowned GLib.List<string> countries {
get { get {
try { try {
var directory = GLib.File.new_for_path (mirrorlists_dir); string countries_str;
var enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0); int status;
FileInfo file_info; Process.spawn_command_line_sync ("pacman-mirrors -l",
_countrys = new GLib.List<string> (); out countries_str,
while ((file_info = enumerator.next_file ()) != null) { null,
_countrys.append(file_info.get_name ()); out status);
_countries = new GLib.List<string> ();
if (status == 0) {
foreach (unowned string country in countries_str.split ("\n")) {
_countries.append (country);
}
} }
_countrys.sort (strcmp); } catch (SpawnError e) {
} catch (Error e) { stdout.printf ("Error: %s\n", e.message);
stderr.printf ("%s\n", e.message);
} }
return _countrys; return _countries;
} }
} }
@ -54,7 +56,6 @@ namespace Pamac {
// set default options // set default options
choosen_generation_method = "rank"; choosen_generation_method = "rank";
choosen_country = "ALL"; choosen_country = "ALL";
mirrorlists_dir = "/etc/pacman.d/mirrors";
parse_file (conf_path); parse_file (conf_path);
} }
@ -87,8 +88,6 @@ namespace Pamac {
choosen_generation_method = val; choosen_generation_method = val;
} else if (key == "OnlyCountry") { } else if (key == "OnlyCountry") {
choosen_country = val; choosen_country = val;
} else if (key == "MirrorlistsDir") {
mirrorlists_dir = val.replace ("\"", "");
} }
} }
} catch (Error e) { } catch (Error e) {

View File

@ -101,7 +101,7 @@ namespace Pamac {
no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled); no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled);
transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished); transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
AlpmPackage pkg = transaction.find_installed_satisfier ("pacman-mirrorlist"); AlpmPackage pkg = transaction.find_installed_satisfier ("pacman-mirrors");
if (pkg.name == "") { if (pkg.name == "") {
mirrors_config_box.visible = false; mirrors_config_box.visible = false;
} else { } else {
@ -109,7 +109,7 @@ namespace Pamac {
mirrors_country_comboboxtext.append_text (dgettext (null, "Worldwide")); mirrors_country_comboboxtext.append_text (dgettext (null, "Worldwide"));
mirrors_country_comboboxtext.active = 0; mirrors_country_comboboxtext.active = 0;
int index = 1; int index = 1;
foreach (unowned string country in mirrors_config.countrys) { foreach (unowned string country in mirrors_config.countries) {
mirrors_country_comboboxtext.append_text (country); mirrors_country_comboboxtext.append_text (country);
if (country == mirrors_config.choosen_country) { if (country == mirrors_config.choosen_country) {
mirrors_country_comboboxtext.active = index; mirrors_country_comboboxtext.active = index;