This commit is contained in:
guinux
2016-02-02 09:28:07 +01:00
parent d7d393ed4e
commit 00553e5e58
30 changed files with 3058 additions and 2398 deletions

View File

@@ -1,23 +1,28 @@
COMMON_VALA_FLAGS = -X -w \
COMMON_VALA_FLAGS = -g --save-temps -X -w \
--pkg=libalpm \
--pkg=gio-2.0 \
--pkg=posix \
--pkg=json-glib-1.0 \
--pkg=libsoup-2.4 \
--vapidir=../vapi \
--Xcc=-I../util \
-X -D_FILE_OFFSET_BITS=64 \
-X -DGETTEXT_PACKAGE="pamac" \
--target-glib=2.38
TRANSACTION_VALA_FLAGS = --pkg=json-glib-1.0 \
--pkg=gtk+-3.0 \
TRANSACTION_VALA_FLAGS = --pkg=gtk+-3.0 \
--pkg=gmodule-2.0 \
--pkg=gdk-3.0 \
--pkg=vte-2.91
--pkg=vte-2.91 \
-X -lm
COMMON_SOURCES = ../util/alpm-util.c \
common.vala \
pamac_config.vala \
package.vala \
alpm_config.vala \
alpm_utils.vala \
aur.vala \
TRANSACTION_SOURCES = transaction.vala \
choose_provider_dialog.vala \
@@ -44,37 +49,28 @@ pamac-refresh: pamac_config.vala refresh.vala
valac -o pamac-refresh \
-X -w \
--pkg=gio-2.0 \
--pkg=posix \
pamac_config.vala \
refresh.vala
pamac-tray: ../vapi/libalpm.vapi ../util/alpm-util.c common.vala alpm_config.vala pamac_config.vala tray.vala
pamac-tray: ../vapi/libalpm.vapi $(COMMON_SOURCES) tray.vala
valac -o pamac-tray \
$(COMMON_VALA_FLAGS) \
../util/alpm-util.c \
--pkg=posix \
--pkg=gtk+-3.0 \
--pkg=libnotify \
common.vala \
alpm_config.vala \
pamac_config.vala \
$(COMMON_SOURCES) \
tray.vala
pamac-daemon: ../vapi/libalpm.vapi ../vapi/polkit-gobject-1.vapi $(COMMON_SOURCES) mirrors_config.vala alpm_config.vala alpm_utils.vala aur.vala daemon.vala
pamac-daemon: ../vapi/libalpm.vapi ../vapi/polkit-gobject-1.vapi $(COMMON_SOURCES) mirrors_config.vala daemon.vala
valac -o pamac-daemon \
$(COMMON_VALA_FLAGS) \
--pkg=posix \
--pkg=json-glib-1.0 \
--pkg=libsoup-2.4 \
--pkg=polkit-gobject-1 \
--thread \
$(COMMON_SOURCES) \
mirrors_config.vala \
alpm_config.vala \
aur.vala \
alpm_utils.vala \
daemon.vala
pamac-manager: ../vapi/libalpm.vapi $(COMMON_SOURCES) $(TRANSACTION_SOURCES) $(PREFERENCES_SOURCES) choose_dep_dialog.vala history_dialog.vala ../resources/manager_resources.c packages_model.vala manager_window.vala manager.vala
pamac-manager: ../vapi/libalpm.vapi $(COMMON_SOURCES) $(TRANSACTION_SOURCES) $(PREFERENCES_SOURCES) choose_dep_dialog.vala history_dialog.vala ../resources/manager_resources.c packages_model.vala aur_model.vala manager_window.vala manager.vala
valac -o pamac-manager \
$(COMMON_VALA_FLAGS) \
$(TRANSACTION_VALA_FLAGS) \
@@ -86,6 +82,7 @@ pamac-manager: ../vapi/libalpm.vapi $(COMMON_SOURCES) $(TRANSACTION_SOURCES) $(P
choose_dep_dialog.vala \
history_dialog.vala \
packages_model.vala \
aur_model.vala \
manager_window.vala \
manager.vala

View File

@@ -1,7 +1,7 @@
/*
* pamac-vala
*
* Copyright (C) 2014-2015 Guillaume Benoit <guillaume@manjaro.org>
* Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
*
* 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
@@ -18,112 +18,163 @@
*/
namespace Alpm {
class Repo {
[Compact]
public class Repo {
public string name;
public Signature.Level siglevel;
public Signature.Level siglevel_mask;
public DB.Usage usage;
public string[] urls;
public GLib.List<string> urls;
public Repo (string name) {
this.name = name;
siglevel = Signature.Level.USE_DEFAULT;
usage = 0;
urls = {};
}
urls = new GLib.List<string> ();
}
public static int compare_name (Repo a, Repo b) {
return strcmp (a.name, b.name);
}
public static int search_name (Repo a, string name) {
return strcmp (a.name, name);
}
}
[Compact]
public class Config {
string conf_path;
string rootdir;
string dbpath;
string gpgdir;
string logfile;
string arch;
double deltaratio;
int usesyslog;
public string conf_path;
public string? rootdir;
public string? dbpath;
public string? logfile;
public string? gpgdir;
public string? arch;
public double deltaratio;
public int usesyslog;
public int checkspace;
Alpm.List<string> *cachedirs;
Alpm.List<string> *ignoregroups;
public Alpm.List<string> *ignorepkgs;
Alpm.List<string> *noextracts;
Alpm.List<string> *noupgrades;
public GLib.List<string> holdpkgs;
public GLib.List<string> syncfirsts;
Signature.Level defaultsiglevel;
Signature.Level localfilesiglevel;
Signature.Level remotefilesiglevel;
Repo[] repo_order;
public unowned Handle? handle;
public Alpm.List<string>? cachedirs;
public Alpm.List<string?>? hookdirs;
public Alpm.List<string>? ignoregroups;
public Alpm.List<string>? ignorepkgs;
public Alpm.List<string>? noextracts;
public Alpm.List<string>? noupgrades;
public GLib.List<string>? holdpkgs;
public GLib.List<string>? syncfirsts;
public Signature.Level siglevel;
public Signature.Level localfilesiglevel;
public Signature.Level remotefilesiglevel;
public Signature.Level siglevel_mask;
public Signature.Level localfilesiglevel_mask;
public Signature.Level remotefilesiglevel_mask;
public GLib.List<Repo> repo_order;
public Handle? handle;
public Config (string path) {
conf_path = path;
handle = null;
reload ();
}
public void reload () {
// set default options
rootdir = "/";
dbpath = "/var/lib/pacman";
gpgdir = "/etc/pacman.d/gnupg/";
logfile = "/var/log/pacman.log";
string default_cachedir = "/var/cache/pacman/pkg/";
arch = Posix.utsname().machine;
holdpkgs = new GLib.List<string> ();
syncfirsts = new GLib.List<string> ();
Alpm.List.free_all (cachedirs);
Alpm.List.free_all (ignoregroups);
Alpm.List.free_all (ignorepkgs);
Alpm.List.free_all (noextracts);
Alpm.List.free_all (noupgrades);
cachedirs = new Alpm.List<string> ();
cachedirs->add_str (default_cachedir);
ignoregroups = new Alpm.List<string> ();
ignorepkgs = new Alpm.List<string> ();
noextracts = new Alpm.List<string> ();
noupgrades = new Alpm.List<string> ();
// free internal data of alpm lists
if (cachedirs != null) {
cachedirs.free_data ();
}
if (hookdirs != null) {
hookdirs.free_data ();
}
if (ignoregroups != null) {
ignoregroups.free_data ();
}
if (ignorepkgs != null) {
ignorepkgs.free_data ();
}
if (noextracts != null) {
noextracts.free_data ();
}
if (noupgrades != null) {
noupgrades.free_data ();
}
usesyslog = 0;
checkspace = 0;
deltaratio = 0.7;
defaultsiglevel = Signature.Level.PACKAGE | Signature.Level.PACKAGE_OPTIONAL | Signature.Level.DATABASE | Signature.Level.DATABASE_OPTIONAL;
siglevel = Signature.Level.PACKAGE | Signature.Level.PACKAGE_OPTIONAL | Signature.Level.DATABASE | Signature.Level.DATABASE_OPTIONAL;
localfilesiglevel = Signature.Level.USE_DEFAULT;
remotefilesiglevel = Signature.Level.USE_DEFAULT;
repo_order = {};
repo_order = new GLib.List<Repo> ();
// parse conf file
parse_file (conf_path);
// if rootdir is set and dbpath/logfile are not
// set, then set those as well to reside under the root.
if (rootdir != null) {
if (dbpath == null) {
dbpath = Path.build_path ("/", rootdir, "var/lib/pacman/");
}
if (logfile == null) {
logfile = Path.build_path ("/", rootdir, "var/log/pacman.log");
}
} else {
rootdir = "/";
if (dbpath == null) {
dbpath = "/var/lib/pacman/";
}
if (logfile == null) {
logfile = "/var/log/pacman.log";
}
}
if (cachedirs.length == 0) {
cachedirs.add ("/var/cache/pacman/pkg/");
}
if (hookdirs.length == 0) {
hookdirs.add ("/etc/pacman.d/hooks/");
}
if (gpgdir == null) {
// gpgdir it is not relative to rootdir, even if
// rootdir is defined because it contains configuration data.
gpgdir = "/etc/pacman.d/gnupg/";
}
if (arch == null) {
arch = Posix.utsname().machine;
}
}
public void get_handle () {
Alpm.Errno error;
if (handle != null) {
Handle.release (handle);
}
handle = Handle.new (rootdir, dbpath, out error);
if (handle == null) {
stderr.printf ("Failed to initialize alpm library" + " (%s)\n".printf(Alpm.strerror (error)));
return;
}
// define options
handle.gpgdir = gpgdir;
handle.logfile = logfile;
handle.gpgdir = gpgdir;
handle.arch = arch;
handle.deltaratio = deltaratio;
handle.usesyslog = usesyslog;
handle.checkspace = checkspace;
handle.defaultsiglevel = defaultsiglevel;
localfilesiglevel = merge_siglevel (defaultsiglevel, localfilesiglevel);
remotefilesiglevel = merge_siglevel (defaultsiglevel, remotefilesiglevel);
handle.defaultsiglevel = siglevel;
localfilesiglevel = merge_siglevel (siglevel, localfilesiglevel, localfilesiglevel_mask);
remotefilesiglevel = merge_siglevel (siglevel, remotefilesiglevel, remotefilesiglevel_mask);
handle.localfilesiglevel = localfilesiglevel;
handle.remotefilesiglevel = remotefilesiglevel;
handle.cachedirs = cachedirs;
// add hook directories 1-by-1 to avoid overwriting the system directory
foreach (unowned string hookdir in hookdirs) {
handle.add_hookdir (hookdir);
}
handle.ignoregroups = ignoregroups;
handle.ignorepkgs = ignorepkgs;
handle.noextracts = noextracts;
handle.noupgrades = noupgrades;
// register dbs
foreach (var repo in repo_order) {
foreach (unowned Repo repo in repo_order) {
repo.siglevel = merge_siglevel (siglevel, repo.siglevel, repo.siglevel_mask);
unowned DB db = handle.register_syncdb (repo.name, repo.siglevel);
foreach (var url in repo.urls) {
foreach (unowned string url in repo.urls) {
db.add_server (url.replace ("$repo", repo.name).replace ("$arch", handle.arch));
}
if (repo.usage == 0) {
@@ -158,21 +209,37 @@ namespace Alpm {
current_section = line[1:-1];
if (current_section != "options") {
var repo = new Repo (current_section);
repo_order += repo;
if (repo_order.find_custom (repo, Repo.compare_name) == null) {
repo_order.append ((owned) repo);
}
}
continue;
}
splitted = line.split ("=", 2);
string key = splitted[0].strip ();
string? val = null;
if (splitted[1] != null) {
val = splitted[1].strip ();
unowned string key = splitted[0]._strip ();
unowned string? val = null;
if (splitted.length == 2) {
val = splitted[1]._strip ();
}
if (key == "Include") {
parse_file (val, current_section);
}
if (current_section == "options") {
if (key == "GPGDir") {
if (key == "RootDir") {
rootdir = val;
} else if (key == "DBPath") {
dbpath = val;
} else if (key == "CacheDir") {
foreach (unowned string dir in val.split (" ")) {
cachedirs.add (dir);
}
} else if (key == "HookDir") {
foreach (unowned string dir in val.split (" ")) {
hookdirs.add (dir);
}
} else if (key == "LogFile") {
logfile = val;
} else if (key == "GPGDir") {
gpgdir = val;
} else if (key == "LogFile") {
logfile = val;
@@ -189,53 +256,46 @@ namespace Alpm {
} else if (key == "CheckSpace") {
checkspace = 1;
} else if (key == "SigLevel") {
defaultsiglevel = define_siglevel (defaultsiglevel, val);
process_siglevel (val, ref siglevel, ref siglevel_mask);
} else if (key == "LocalFileSigLevel") {
localfilesiglevel = define_siglevel (localfilesiglevel, val);
process_siglevel (val, ref localfilesiglevel, ref localfilesiglevel_mask);
} else if (key == "RemoteFileSigLevel") {
remotefilesiglevel = define_siglevel (remotefilesiglevel, val);
process_siglevel (val, ref remotefilesiglevel, ref remotefilesiglevel_mask);
} else if (key == "HoldPkg") {
foreach (string name in val.split (" ")) {
foreach (unowned string name in val.split (" ")) {
holdpkgs.append (name);
}
} else if (key == "SyncFirst") {
foreach (string name in val.split (" ")) {
foreach (unowned string name in val.split (" ")) {
syncfirsts.append (name);
}
} else if (key == "CacheDir") {
foreach (string dir in val.split (" ")) {
cachedirs->add_str (dir);
}
} else if (key == "IgnoreGroup") {
foreach (string name in val.split (" ")) {
ignoregroups->add_str (name);
foreach (unowned string name in val.split (" ")) {
ignoregroups.add (name);
}
} else if (key == "IgnorePkg") {
foreach (string name in val.split (" ")) {
ignorepkgs->add_str (name);
foreach (unowned string name in val.split (" ")) {
ignorepkgs.add (name);
}
} else if (key == "Noextract") {
foreach (string name in val.split (" ")) {
noextracts->add_str (name);
foreach (unowned string name in val.split (" ")) {
noextracts.add (name);
}
} else if (key == "NoUpgrade") {
foreach (string name in val.split (" ")) {
noupgrades->add_str (name);
foreach (unowned string name in val.split (" ")) {
noupgrades.add (name);
}
}
} else {
foreach (var repo in repo_order) {
if (repo.name == current_section) {
if (key == "Server") {
repo.urls += val;
} else if (key == "SigLevel") {
if (repo.siglevel == Signature.Level.USE_DEFAULT) {
repo.siglevel = defaultsiglevel;
}
repo.siglevel = define_siglevel (repo.siglevel, val);
} else if (key == "Usage") {
repo.usage = define_usage (val);
}
unowned GLib.List<Repo>? found = repo_order.search (current_section, (SearchFunc) Repo.search_name);
if (found != null) {
unowned Repo repo = found.data;
if (key == "Server") {
repo.urls.append (val);
} else if (key == "SigLevel") {
process_siglevel (val, ref repo.siglevel, ref repo.siglevel_mask);
} else if (key == "Usage") {
repo.usage = define_usage (val);
}
}
}
@@ -295,7 +355,7 @@ namespace Alpm {
file.delete ();
// creating a DataOutputStream to the file
var dos = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION));
foreach (string new_line in data) {
foreach (unowned string new_line in data) {
// writing a short string to the stream
dos.put_string (new_line);
}
@@ -309,7 +369,7 @@ namespace Alpm {
public DB.Usage define_usage (string conf_string) {
DB.Usage usage = 0;
foreach (string directive in conf_string.split(" ")) {
foreach (unowned string directive in conf_string.split(" ")) {
if (directive == "Sync") {
usage |= DB.Usage.SYNC;
} else if (directive == "Search") {
@@ -325,8 +385,8 @@ namespace Alpm {
return usage;
}
public Signature.Level define_siglevel (Signature.Level default_level, string conf_string) {
foreach (string directive in conf_string.split(" ")) {
public void process_siglevel (string conf_string, ref Signature.Level siglevel, ref Signature.Level siglevel_mask) {
foreach (unowned string directive in conf_string.split(" ")) {
bool affect_package = false;
bool affect_database = false;
if ("Package" in directive) {
@@ -339,72 +399,62 @@ namespace Alpm {
}
if ("Never" in directive) {
if (affect_package) {
default_level &= ~Signature.Level.PACKAGE;
default_level |= Signature.Level.PACKAGE_SET;
siglevel &= ~Signature.Level.PACKAGE;
siglevel_mask |= Signature.Level.PACKAGE;
}
if (affect_database) {
default_level &= ~Signature.Level.DATABASE;
siglevel &= ~Signature.Level.DATABASE;
siglevel_mask |= Signature.Level.DATABASE;
}
} else if ("Optional" in directive) {
if (affect_package) {
default_level |= Signature.Level.PACKAGE;
default_level |= Signature.Level.PACKAGE_OPTIONAL;
default_level |= Signature.Level.PACKAGE_SET;
siglevel |= (Signature.Level.PACKAGE | Signature.Level.PACKAGE_OPTIONAL);
siglevel_mask |= (Signature.Level.PACKAGE | Signature.Level.PACKAGE_OPTIONAL);
}
if (affect_database) {
default_level |= Signature.Level.DATABASE;
default_level |= Signature.Level.DATABASE_OPTIONAL;
siglevel |= (Signature.Level.DATABASE | Signature.Level.DATABASE_OPTIONAL);
siglevel_mask |= (Signature.Level.DATABASE | Signature.Level.DATABASE_OPTIONAL);
}
} else if ("Required" in directive) {
if (affect_package) {
default_level |= Signature.Level.PACKAGE;
default_level &= ~Signature.Level.PACKAGE_OPTIONAL;
default_level |= Signature.Level.PACKAGE_SET;
siglevel |= Signature.Level.PACKAGE;
siglevel_mask |= Signature.Level.PACKAGE;
siglevel &= ~Signature.Level.PACKAGE_OPTIONAL;
siglevel_mask |= Signature.Level.PACKAGE_OPTIONAL;
}
if (affect_database) {
default_level |= Signature.Level.DATABASE;
default_level &= ~Signature.Level.DATABASE_OPTIONAL;
siglevel |= Signature.Level.DATABASE;
siglevel_mask |= Signature.Level.DATABASE;
siglevel &= ~Signature.Level.DATABASE_OPTIONAL;
siglevel_mask |= Signature.Level.DATABASE_OPTIONAL;
}
} else if ("TrustedOnly" in directive) {
if (affect_package) {
default_level &= ~Signature.Level.PACKAGE_MARGINAL_OK;
default_level &= ~Signature.Level.PACKAGE_UNKNOWN_OK;
default_level |= Signature.Level.PACKAGE_TRUST_SET;
siglevel &= ~(Signature.Level.PACKAGE_MARGINAL_OK | Signature.Level.PACKAGE_UNKNOWN_OK);
siglevel_mask |= (Signature.Level.PACKAGE_MARGINAL_OK | Signature.Level.PACKAGE_UNKNOWN_OK);
}
if (affect_database) {
default_level &= ~Signature.Level.DATABASE_MARGINAL_OK;
default_level &= ~Signature.Level.DATABASE_UNKNOWN_OK;
siglevel &= ~(Signature.Level.DATABASE_MARGINAL_OK | Signature.Level.DATABASE_UNKNOWN_OK);
siglevel_mask |= (Signature.Level.DATABASE_MARGINAL_OK | Signature.Level.DATABASE_UNKNOWN_OK);
}
} else if ("TrustAll" in directive) {
if (affect_package) {
default_level |= Signature.Level.PACKAGE_MARGINAL_OK;
default_level |= Signature.Level.PACKAGE_UNKNOWN_OK;
default_level |= Signature.Level.PACKAGE_TRUST_SET;
siglevel |= (Signature.Level.PACKAGE_MARGINAL_OK | Signature.Level.PACKAGE_UNKNOWN_OK);
siglevel_mask |= (Signature.Level.PACKAGE_MARGINAL_OK | Signature.Level.PACKAGE_UNKNOWN_OK);
}
if (affect_database) {
default_level |= Signature.Level.DATABASE_MARGINAL_OK;
default_level |= Signature.Level.DATABASE_UNKNOWN_OK;
siglevel |= (Signature.Level.DATABASE_MARGINAL_OK | Signature.Level.DATABASE_UNKNOWN_OK);
siglevel_mask |= (Signature.Level.DATABASE_MARGINAL_OK | Signature.Level.DATABASE_UNKNOWN_OK);
}
} else {
GLib.stderr.printf("unrecognized siglevel: %s\n", conf_string);
}
}
default_level &= ~Signature.Level.USE_DEFAULT;
return default_level;
siglevel &= ~Signature.Level.USE_DEFAULT;
}
public Signature.Level merge_siglevel (Signature.Level base_level, Signature.Level over_level) {
if ((over_level & Signature.Level.USE_DEFAULT) == 0) {
if ((over_level & Signature.Level.PACKAGE_SET) == 0) {
over_level |= base_level & Signature.Level.PACKAGE;
over_level |= base_level & Signature.Level.PACKAGE_OPTIONAL;
}
if ((over_level & Signature.Level.PACKAGE_TRUST_SET) == 0) {
over_level |= base_level & Signature.Level.PACKAGE_MARGINAL_OK;
over_level |= base_level & Signature.Level.PACKAGE_UNKNOWN_OK;
}
}
return over_level;
public Signature.Level merge_siglevel(Signature.Level sigbase, Signature.Level sigover, Signature.Level sigmask) {
return (sigmask != 0) ? (sigover & sigmask) | (sigbase & ~sigmask) : sigover;
}
}
}

View File

@@ -17,59 +17,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public int pkgcmp (Alpm.Package pkg1, Alpm.Package pkg2) {
return strcmp (pkg1.name, pkg2.name);
public int compare_name (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return strcmp (pkg_a.name, pkg_b.name);
}
public Alpm.List<unowned Alpm.Package?> search_all_dbs (Alpm.Handle handle, Alpm.List<string?> needles) {
var syncpkgs = new Alpm.List<unowned Alpm.Package?> ();
var result = handle.localdb.search (needles);
foreach (var db in handle.syncdbs) {
if (syncpkgs.length == 0)
syncpkgs = db.search (needles);
else {
syncpkgs.join (db.search (needles).diff (syncpkgs, (Alpm.List.CompareFunc) pkgcmp));
}
}
result.join (syncpkgs.diff (result, (Alpm.List.CompareFunc) pkgcmp));
//result.sort ((Alpm.List.CompareFunc) pkgcmp);
return result;
public int compare_state (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return (int) (pkg_a.origin > pkg_b.origin) - (int) (pkg_a.origin < pkg_b.origin);
}
public Alpm.List<unowned Alpm.Package?> group_pkgs (Alpm.Handle handle, string grp_name) {
var result = new Alpm.List<unowned Alpm.Package?> ();
unowned Alpm.Group? grp = handle.localdb.get_group (grp_name);
if (grp != null) {
foreach (var pkg in grp.packages)
result.add (pkg);
}
result.join (Alpm.find_group_pkgs (handle.syncdbs, grp_name).diff (result, (Alpm.List.CompareFunc) pkgcmp));
//result.sort ((Alpm.List.CompareFunc) pkgcmp);
return result;
public int compare_version (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return Alpm.pkg_vercmp (pkg_a.version, pkg_b.version);
}
public Alpm.List<unowned Alpm.Package?> all_pkgs (Alpm.Handle handle) {
var syncpkgs = new Alpm.List<unowned Alpm.Package?> ();
var result = new Alpm.List<unowned Alpm.Package?> ();
result = handle.localdb.pkgcache.copy ();
foreach (var db in handle.syncdbs) {
if (syncpkgs.length == 0)
syncpkgs = db.pkgcache.copy ();
else {
syncpkgs.join (db.pkgcache.diff (syncpkgs, (Alpm.List.CompareFunc) pkgcmp));
}
}
result.join (syncpkgs.diff (result, (Alpm.List.CompareFunc) pkgcmp));
//result.sort ((Alpm.List.CompareFunc) pkgcmp);
return result;
public int compare_repo (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return strcmp (pkg_a.db.name, pkg_b.db.name);
}
public int compare_size (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return (int) (pkg_a.isize > pkg_b.isize) - (int) (pkg_a.isize < pkg_b.isize);
}

271
src/aur_model.vala Normal file
View File

@@ -0,0 +1,271 @@
/*
* pamac-vala
*
* Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
*
* 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/>.
*/
Pamac.ManagerWindow manager_window;
// custom sort functions
public int aur_compare_name (Json.Object pkg_a, Json.Object pkg_b) {
return strcmp (pkg_a.get_string_member ("Name"), pkg_b.get_string_member ("Name"));
}
public int aur_compare_state (Json.Object pkg_a, Json.Object pkg_b) {
unowned Alpm.Package? alpm_pkg_a = manager_window.alpm_config.handle.localdb.get_pkg (pkg_a.get_string_member ("Name"));
unowned Alpm.Package? alpm_pkg_b = manager_window.alpm_config.handle.localdb.get_pkg (pkg_b.get_string_member ("Name"));
if (pkg_a != null) {
if (pkg_b != null) {
return (int) (alpm_pkg_a.origin > alpm_pkg_b.origin) - (int) (alpm_pkg_a.origin < alpm_pkg_b.origin);
} else {
return 1;
}
} else {
if (pkg_b != null) {
return -1;
} else {
return 0;
}
}
}
public int aur_compare_version (Json.Object pkg_a, Json.Object pkg_b) {
return Alpm.pkg_vercmp (pkg_a.get_string_member ("Version"), pkg_b.get_string_member ("Version"));
}
public int aur_compare_votes (Json.Object pkg_a, Json.Object pkg_b) {
return (int) (pkg_a.get_int_member ("NumVotes") > pkg_b.get_int_member ("NumVotes")) - (int) (pkg_a.get_int_member ("NumVotes") < pkg_b.get_int_member ("NumVotes"));
}
namespace Pamac {
public class AURModel : Object, Gtk.TreeModel {
private Json.Array pkgs_infos;
private GLib.List<Json.Object?> pkgs;
public AURModel (Json.Array? pkgs_infos, ManagerWindow _manager_window) {
manager_window = _manager_window;
this.pkgs_infos = pkgs_infos;
pkgs = new GLib.List<Json.Object?> ();
if (pkgs_infos != null) {
pkgs_infos.foreach_element ((array, index, node) => {
pkgs.append (node.get_object ());
});
}
}
// TreeModel interface
public Type get_column_type (int index) {
switch (index) {
case 0: // name
case 2: // version
return typeof (string);
case 3: // votes
return typeof (int64);
case 1: // icon
return typeof (Gdk.Pixbuf);
default:
return Type.INVALID;
}
}
public Gtk.TreeModelFlags get_flags () {
return Gtk.TreeModelFlags.LIST_ONLY | Gtk.TreeModelFlags.ITERS_PERSIST;
}
public void get_value (Gtk.TreeIter iter, int column, out Value val) {
unowned Json.Object? pkg_info = pkgs.nth_data (iter.stamp);
switch (column) {
case 0:
val = Value (typeof (string));
if (pkg_info == null) {
val.set_string (dgettext (null, "No package found"));
} else {
val.set_string (pkg_info.get_string_member ("Name"));
}
break;
case 1:
val = Value (typeof (Object));
if (pkg_info != null) {
unowned Alpm.Package? pkg = manager_window.alpm_config.handle.localdb.get_pkg (pkg_info.get_string_member ("Name"));
if (pkg != null) {
if (manager_window.alpm_config.holdpkgs.find_custom (pkg.name, strcmp) != null) {
val.set_object (manager_window.locked_icon);
} else if (manager_window.transaction.to_add.contains (pkg.name)) {
val.set_object (manager_window.to_reinstall_icon);
} else if (manager_window.transaction.to_remove.contains (pkg.name)) {
val.set_object (manager_window.to_remove_icon);
} else {
val.set_object (manager_window.installed_icon);
}
} else if (manager_window.transaction.to_build.contains (pkg_info.get_string_member ("Name"))) {
val.set_object (manager_window.to_install_icon);
} else {
val.set_object (manager_window.uninstalled_icon);
}
}
break;
case 2:
val = Value (typeof (string));
if (pkg_info != null) {
unowned Alpm.Package? pkg = manager_window.alpm_config.handle.localdb.get_pkg (pkg_info.get_string_member ("Name"));
if (pkg != null) {
val.set_string (pkg.version);
} else {
val.set_string (pkg_info.get_string_member ("Version"));
}
}
break;
case 3:
if (pkg_info != null) {
val = Value (typeof (int64));
val.set_int64 (pkg_info.get_int_member ("NumVotes"));
} else {
// if pkg_info is null, set val to an empty string to not display "0"
val = Value (typeof (string));
}
break;
default:
val = Value (Type.INVALID);
break;
}
}
public bool get_iter (out Gtk.TreeIter iter, Gtk.TreePath path) {;
if (path.get_depth () != 1) {
return invalid_iter (out iter);
}
iter = Gtk.TreeIter ();
int pos = path.get_indices ()[0];
iter.stamp = pos;
return true;
}
public int get_n_columns () {
// name, icon, version, votes
return 4;
}
public Gtk.TreePath? get_path (Gtk.TreeIter iter) {
return new Gtk.TreePath.from_indices (iter.stamp);
}
public int iter_n_children (Gtk.TreeIter? iter) {
return 0;
}
public bool iter_next (ref Gtk.TreeIter iter) {
int pos = (iter.stamp) + 1;
if (pos >= pkgs.length ()) {
return false;
}
iter.stamp = pos;
return true;
}
public bool iter_previous (ref Gtk.TreeIter iter) {
int pos = iter.stamp;
if (pos >= 0) {
return false;
}
iter.stamp = (--pos);
return true;
}
public bool iter_nth_child (out Gtk.TreeIter iter, Gtk.TreeIter? parent, int n) {
return invalid_iter (out iter);
}
public bool iter_children (out Gtk.TreeIter iter, Gtk.TreeIter? parent) {
return invalid_iter (out iter);
}
public bool iter_has_child (Gtk.TreeIter iter) {
return false;
}
public bool iter_parent (out Gtk.TreeIter iter, Gtk.TreeIter child) {
return invalid_iter (out iter);
}
private bool invalid_iter (out Gtk.TreeIter iter) {
iter = Gtk.TreeIter ();
iter.stamp = -1;
return false;
}
// custom get pkg function
public unowned Json.Object? get_pkg_at_path (Gtk.TreePath path) {
return pkgs.nth_data (path.get_indices ()[0]);
}
public void sort_by_name (Gtk.SortType order) {
pkgs.sort ((GLib.CompareFunc) aur_compare_name);
if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse ();
}
manager_window.aur_name_column.sort_order = order;
manager_window.aur_state_column.sort_indicator = false;
manager_window.aur_name_column.sort_indicator = true;
manager_window.aur_version_column.sort_indicator = false;
manager_window.aur_votes_column.sort_indicator = false;
manager_window.sortinfo.column_number = 0;
manager_window.sortinfo.sort_type = order;
}
public void sort_by_state (Gtk.SortType order) {
pkgs.sort ((GLib.CompareFunc) aur_compare_state);
if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse ();
}
manager_window.aur_state_column.sort_order = order;
manager_window.aur_state_column.sort_indicator = true;
manager_window.aur_name_column.sort_indicator = false;
manager_window.aur_version_column.sort_indicator = false;
manager_window.aur_votes_column.sort_indicator = false;
manager_window.sortinfo.column_number = 1;
manager_window.sortinfo.sort_type = order;
}
public void sort_by_version (Gtk.SortType order) {
pkgs.sort ((GLib.CompareFunc) aur_compare_version);
if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse ();
}
manager_window.aur_version_column.sort_order = order;
manager_window.aur_state_column.sort_indicator = false;
manager_window.aur_name_column.sort_indicator = false;
manager_window.aur_version_column.sort_indicator = true;
manager_window.aur_votes_column.sort_indicator = false;
manager_window.sortinfo.column_number = 2;
manager_window.sortinfo.sort_type = order;
}
public void sort_by_votes (Gtk.SortType order) {
pkgs.sort ((GLib.CompareFunc) aur_compare_votes);
if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse ();
}
manager_window.aur_votes_column.sort_order = order;
manager_window.aur_state_column.sort_indicator = false;
manager_window.aur_name_column.sort_indicator = false;
manager_window.aur_version_column.sort_indicator = false;
manager_window.aur_votes_column.sort_indicator = true;
manager_window.sortinfo.column_number = 3;
manager_window.sortinfo.sort_type = order;
}
}
}

View File

@@ -31,38 +31,20 @@ namespace Pamac {
public Gtk.ListStore deps_list;
Transaction transaction;
public ChooseDependenciesDialog (Transaction transaction, string pkgname, Gtk.ApplicationWindow? window) {
public ChooseDependenciesDialog (Gtk.ApplicationWindow? window) {
Object (transient_for: window, use_header_bar: 0);
this.transaction = transaction;
string[] optdeps = transaction.get_pkg_uninstalled_optdeps (pkgname);
label.set_markup ("<b>%s</b>".printf (
dngettext (null, "%s has %u uninstalled optional dependency.\nChoose if you would like to install it",
"%s has %u uninstalled optional dependencies.\nChoose those you would like to install", optdeps.length).printf (pkgname, optdeps.length)));
deps_list = new Gtk.ListStore (3, typeof (bool), typeof (string), typeof (string));
treeview.set_model (deps_list);
Gtk.TreeIter iter;
foreach (var optdep in optdeps) {
string[] split = optdep.split (":", 2);
deps_list.insert_with_values (out iter, -1,
0, false,
1, split[0],
2, split[1]);
}
}
[GtkCallback]
void on_renderertoggle_toggled (string path) {
Gtk.TreeIter iter;
GLib.Value val;
bool selected;
GLib.Value selected;
if (deps_list.get_iter_from_string (out iter, path)) {;
deps_list.get_value (iter, 0, out val);
selected = val.get_boolean ();
deps_list.set_value (iter, 0, !selected);
deps_list.get_value (iter, 0, out selected);
deps_list.set_value (iter, 0, !((bool) selected));
}
}
}

View File

@@ -31,39 +31,21 @@ namespace Pamac {
public Gtk.ListStore pkgs_list;
Transaction transaction;
public ChooseIgnorepkgsDialog (Gtk.Window window, Transaction transaction) {
public ChooseIgnorepkgsDialog (Gtk.Window window) {
Object (transient_for: window, use_header_bar: 0);
this.transaction = transaction;
label.set_markup ("<b>%s</b>".printf (dgettext (null, "Choose the packages you do not want to upgrade")));
pkgs_list = new Gtk.ListStore (2, typeof (bool), typeof (string));
treeview.set_model (pkgs_list);
transaction.get_installed_pkgs.begin ((obj, res) => {
Pamac.Package[] pkgs = transaction.get_installed_pkgs.end (res);
Gtk.TreeIter iter;
string[] already_ignorepkgs = transaction.get_ignorepkgs ();
foreach (var pkg in pkgs) {
if (pkg.name in already_ignorepkgs) {
pkgs_list.insert_with_values (out iter, -1, 0, true, 1, pkg.name);
} else {
pkgs_list.insert_with_values (out iter, -1, 0, false, 1, pkg.name);
}
}
});
}
[GtkCallback]
void on_renderertoggle_toggled (string path) {
Gtk.TreeIter iter;
GLib.Value val;
bool selected;
if (pkgs_list.get_iter_from_string (out iter, path)) {;
pkgs_list.get_value (iter, 0, out val);
selected = val.get_boolean ();
pkgs_list.set_value (iter, 0, !selected);
GLib.Value selected;
if (pkgs_list.get_iter_from_string (out iter, path)) {
pkgs_list.get_value (iter, 0, out selected);
pkgs_list.set_value (iter, 0, !((bool) selected));
}
}
}

View File

@@ -27,14 +27,8 @@ namespace Pamac {
[GtkChild]
public Gtk.ComboBoxText comboboxtext;
public ChooseProviderDialog (string depend, string[] providers, Gtk.ApplicationWindow? window) {
public ChooseProviderDialog (Gtk.ApplicationWindow? window) {
Object (transient_for: window, use_header_bar: 0);
label.set_markup ("<b>%s</b>".printf (dgettext (null, "Choose a provider for %s").printf (depend)));
foreach (string provider in providers) {
comboboxtext.append_text (provider);
}
comboboxtext.active = 0;
}
}
}

View File

@@ -18,7 +18,7 @@
*/
namespace Pamac {
public struct UpdateInfos {
public struct PackageInfos {
public string name;
public string version;
public string db_name;
@@ -27,13 +27,8 @@ namespace Pamac {
public struct Updates {
public bool is_syncfirst;
public UpdateInfos[] repos_updates;
public UpdateInfos[] aur_updates;
public Updates () {
is_syncfirst = false;
repos_updates = {};
aur_updates = {};
}
public PackageInfos[] repos_updates;
public PackageInfos[] aur_updates;
}
public struct ErrorInfos {

File diff suppressed because it is too large Load Diff

View File

@@ -46,13 +46,13 @@ namespace Pamac {
transaction_info_dialog.hide ();
} else {
transaction = new Pamac.Transaction (null);
transaction.finished.connect (on_emit_trans_finished);
transaction.finished.connect (on_transaction_finished);
this.hold ();
}
}
public override void activate () {
if (pamac_run == false) {
if (!pamac_run) {
print ("\nError: Path(s) of tarball(s) to install is needed\n");
transaction.stop_daemon ();
this.release ();
@@ -60,10 +60,9 @@ namespace Pamac {
}
public override void open (File[] files, string hint) {
if (pamac_run == false) {
foreach (File file in files) {
string? path = file.get_path ();
transaction.to_load.add ((owned) path);
if (!pamac_run) {
foreach (unowned File file in files) {
transaction.to_load.add (file.get_path ());
}
transaction.run ();
}
@@ -92,7 +91,7 @@ namespace Pamac {
return run;
}
public void on_emit_trans_finished (bool error) {
public void on_transaction_finished () {
transaction.stop_daemon ();
this.release ();
}

View File

@@ -50,18 +50,17 @@ namespace Pamac {
}
public override void activate () {
if (pamac_run == false) {
if (!pamac_run) {
manager_window.present ();
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
manager_window.show_all_pkgs ();
}
}
public override void shutdown () {
base.shutdown ();
if (pamac_run == false) {
if (!pamac_run) {
manager_window.transaction.stop_daemon ();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,9 +18,10 @@
*/
namespace Alpm {
[Compact]
public class MirrorsConfig: Object {
string conf_path;
string mirrorlists_dir;
public string conf_path;
public string mirrorlists_dir;
public string choosen_generation_method;
public string choosen_country;
public GLib.List<string> countrys;
@@ -47,9 +48,7 @@ namespace Alpm {
while ((file_info = enumerator.next_file ()) != null) {
countrys.append(file_info.get_name ());
}
countrys.sort ((a, b) => {
return strcmp (a, b);
});
countrys.sort (strcmp);
} catch (Error e) {
stderr.printf ("%s\n", e.message);
}
@@ -57,9 +56,7 @@ namespace Alpm {
public void parse_file (string path) {
var file = GLib.File.new_for_path (path);
if (file.query_exists () == false) {
GLib.stderr.printf ("File '%s' doesn't exist.\n", path);
} else {
if (file.query_exists ()) {
try {
// Open file for reading and wrap returned FileInputStream into a
// DataInputStream, so we can read line by line
@@ -76,11 +73,11 @@ namespace Alpm {
if (line.length == 0) {
continue;
}
splitted = line.split ("=");
string key = splitted[0].strip ();
string? val = null;
if (splitted[1] != null) {
val = splitted[1].strip ();
splitted = line.split ("=", 2);
unowned string key = splitted[0]._strip ();
unowned string? val = null;
if (splitted.length == 2) {
val = splitted[1]._strip ();
}
if (key == "Method") {
choosen_generation_method = val;
@@ -93,59 +90,60 @@ namespace Alpm {
} catch (Error e) {
GLib.stderr.printf("%s\n", e.message);
}
} else {
GLib.stderr.printf ("File '%s' doesn't exist.\n", path);
}
}
public void write (HashTable<string,Variant> new_conf) {
var file = GLib.File.new_for_path (conf_path);
if (file.query_exists () == false) {
GLib.stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
} else {
if (file.query_exists ()) {
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;
string[] data = {};
var data = new GLib.List<string> ();
// Read lines until end of file (null) is reached
while ((line = dis.read_line ()) != null) {
if (line.length == 0) {
data += "\n";
data.append ("\n");
continue;
}
unowned Variant variant;
if (line.contains ("Method")) {
if (new_conf.contains ("Method")) {
string val = new_conf.get ("Method").get_string ();
data += "Method=%s\n".printf (val);
if (new_conf.lookup_extended ("Method", null, out variant)) {
data.append ("Method=%s\n".printf (variant.get_string ()));
} else {
data += line + "\n";
data.append (line + "\n");
}
} else if (line.contains ("OnlyCountry")) {
if (new_conf.contains ("OnlyCountry")) {
string val = new_conf.get ("OnlyCountry").get_string ();
if (val == dgettext (null, "Worldwide")) {
data += "#%s\n".printf (line);
if (new_conf.lookup_extended ("OnlyCountry", null, out variant)) {
if (variant.get_string () == dgettext (null, "Worldwide")) {
data.append ("#%s\n".printf (line));
} else {
data += "OnlyCountry=%s\n".printf (val);
data.append ("OnlyCountry=%s\n".printf (variant.get_string ()));
}
} else {
data += line + "\n";
data.append (line + "\n");
}
} else {
data += line + "\n";
data.append (line + "\n");
}
}
// delete the file before rewrite it
file.delete ();
// creating a DataOutputStream to the file
var dos = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION));
foreach (string new_line in data) {
foreach (unowned string new_line in data) {
// writing a short string to the stream
dos.put_string (new_line);
}
} catch (GLib.Error e) {
GLib.stderr.printf("%s\n", e.message);
}
} else {
GLib.stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
}
}
}

View File

@@ -31,12 +31,13 @@ namespace Pamac {
public Package (Alpm.Package? alpm_pkg, Json.Object? aur_json) {
if (alpm_pkg != null) {
name = alpm_pkg.name ?? "";
version = alpm_pkg.version ?? "";
desc = alpm_pkg.desc ?? "";
repo = (alpm_pkg.db != null ? (alpm_pkg.db.name ?? "") : "");
name = alpm_pkg.name;
version = alpm_pkg.version;
desc = alpm_pkg.desc;
repo = alpm_pkg.db != null ? alpm_pkg.db.name : "";
size = alpm_pkg.isize;
size_string = format_size (alpm_pkg.isize);
// alpm pkg url can be null
url = alpm_pkg.url ?? "";
StringBuilder licenses_build = new StringBuilder ();
foreach (var license in alpm_pkg.licenses) {
@@ -48,9 +49,9 @@ namespace Pamac {
licenses = licenses_build.str;
reason = alpm_pkg.reason;
} else if (aur_json != null ) {
name = aur_json.get_string_member ("Name") ?? "";
version = aur_json.get_string_member ("Version") ?? "";
desc = aur_json.get_string_member ("Description") ?? "";
name = aur_json.get_string_member ("Name");
version = aur_json.get_string_member ("Version");
desc = aur_json.get_string_member ("Description");
repo = "AUR";
size = 0;
size_string = "";
@@ -73,15 +74,9 @@ namespace Pamac {
public struct PackageDetails {
string repo;
// for AUR package it is OutOfDate
string has_signature;
// for AUR package it is NumVotes
int reason;
// for AUR package it is Maintainer
string packager;
// for AUR package it is FirstSubmitted
string build_date;
// for AUR package it is LastModified
string install_date;
string[] groups;
string[] backups;

View File

@@ -20,21 +20,12 @@
namespace Pamac {
public class PackagesModel : Object, Gtk.TreeModel {
private GLib.List<Pamac.Package?> all_pkgs;
public ManagerWindow manager_window;
private Alpm.List<unowned Alpm.Package?>? pkgs;
private ManagerWindow manager_window;
public PackagesModel (Pamac.Package[] pkgs, ManagerWindow manager_window) {
public PackagesModel (owned Alpm.List<unowned Alpm.Package?>? pkgs, ManagerWindow manager_window) {
this.manager_window = manager_window;
all_pkgs = new GLib.List<Pamac.Package?> ();
foreach (var pkg in pkgs) {
all_pkgs.append (pkg);
}
if (all_pkgs.length () == 0) {
// create a fake "No package found" package
var fake_pkg = Pamac.Package (null, null);
fake_pkg.name = dgettext (null, "No package found");
all_pkgs.append (fake_pkg);
}
this.pkgs = (owned) pkgs;
}
// TreeModel interface
@@ -57,16 +48,21 @@ namespace Pamac {
}
public void get_value (Gtk.TreeIter iter, int column, out Value val) {
Pamac.Package pkg = all_pkgs.nth_data (iter.stamp);
unowned Alpm.Package? pkg = pkgs.nth (iter.stamp).data;
switch (column) {
case 0:
val = Value (typeof (string));
val.set_string (pkg.name);
if (pkg == null) {
val.set_string (dgettext (null, "No package found"));
} else {
val.set_string (pkg.name);
}
break;
case 1:
val = Value (typeof (Object));
if (pkg.repo == "local") {
if (manager_window.transaction.should_hold (pkg.name)) {
if (pkg != null) {
if (pkg.origin == Alpm.Package.From.LOCALDB) {
if (manager_window.alpm_config.holdpkgs.find_custom (pkg.name, strcmp) != null) {
val.set_object (manager_window.locked_icon);
} else if (manager_window.transaction.to_add.contains (pkg.name)) {
val.set_object (manager_window.to_reinstall_icon);
@@ -75,32 +71,30 @@ namespace Pamac {
} else {
val.set_object (manager_window.installed_icon);
}
} else if (pkg.repo == "AUR") {
if (manager_window.transaction.to_build.contains (pkg.name)) {
val.set_object (manager_window.to_install_icon);
} else {
val.set_object (manager_window.uninstalled_icon);
}
} else if (pkg.name == dgettext (null, "No package found")) {
// nothing to do
break;
} else if (manager_window.transaction.to_add.contains (pkg.name)) {
val.set_object (manager_window.to_install_icon);
} else {
val.set_object (manager_window.uninstalled_icon);
}
}
break;
case 2:
val = Value (typeof (string));
val.set_string (pkg.version);
if (pkg != null) {
val.set_string (pkg.version);
}
break;
case 3:
val = Value (typeof (string));
val.set_string (pkg.repo);
if (pkg != null) {
val.set_string (pkg.db.name);
}
break;
case 4:
val = Value (typeof (string));
val.set_string (pkg.size_string);
if (pkg != null) {
val.set_string (format_size (pkg.isize));
}
break;
default:
val = Value (Type.INVALID);
@@ -109,7 +103,7 @@ namespace Pamac {
}
public bool get_iter (out Gtk.TreeIter iter, Gtk.TreePath path) {;
if (path.get_depth () != 1 || all_pkgs.length () == 0) {
if (path.get_depth () != 1) {
return invalid_iter (out iter);
}
iter = Gtk.TreeIter ();
@@ -133,7 +127,7 @@ namespace Pamac {
public bool iter_next (ref Gtk.TreeIter iter) {
int pos = (iter.stamp) + 1;
if (pos >= all_pkgs.length ()) {
if (pos >= pkgs.length) {
return false;
}
iter.stamp = pos;
@@ -172,109 +166,82 @@ namespace Pamac {
}
// custom get pkg function
public Pamac.Package get_pkg_at_path (Gtk.TreePath path) {
return all_pkgs.nth_data (path.get_indices ()[0]);
public unowned Alpm.Package? get_pkg_at_path (Gtk.TreePath path) {
return pkgs.nth (path.get_indices ()[0]).data;
}
// custom sort functions
public void sort_by_name (Gtk.SortType order) {
CompareFunc<Pamac.Package?> namecmp = (pkg_a, pkg_b) => {
return strcmp (pkg_a.name, pkg_b.name);
};
all_pkgs.sort (namecmp);
pkgs.sort ((Alpm.List.CompareFunc) compare_name);
if (order == Gtk.SortType.DESCENDING) {
all_pkgs.reverse ();
pkgs.reverse ();
}
manager_window.name_column.sort_order = order;
manager_window.state_column.sort_indicator = false;
manager_window.name_column.sort_indicator = true;
manager_window.version_column.sort_indicator = false;
manager_window.repo_column.sort_indicator = false;
manager_window.size_column.sort_indicator = false;
manager_window.packages_name_column.sort_order = order;
manager_window.packages_state_column.sort_indicator = false;
manager_window.packages_name_column.sort_indicator = true;
manager_window.packages_version_column.sort_indicator = false;
manager_window.packages_repo_column.sort_indicator = false;
manager_window.packages_size_column.sort_indicator = false;
manager_window.sortinfo.column_number = 0;
manager_window.sortinfo.sort_type = order;
}
public void sort_by_state (Gtk.SortType order) {
CompareFunc<Pamac.Package?> statecmp = (pkg_a, pkg_b) => {
int state_a;
int state_b;
if (pkg_a.repo == "local") {
state_a = 0;
} else {
state_a = 1;
}
if (pkg_b.repo == "local") {
state_b = 0;
} else {
state_b = 1;
}
return (int) (state_a > state_b) - (int) (state_a < state_b);
};
all_pkgs.sort (statecmp);
pkgs.sort ((Alpm.List.CompareFunc) compare_state);
if (order == Gtk.SortType.DESCENDING) {
all_pkgs.reverse ();
pkgs.reverse ();
}
manager_window.state_column.sort_order = order;
manager_window.state_column.sort_indicator = true;
manager_window.name_column.sort_indicator = false;
manager_window.version_column.sort_indicator = false;
manager_window.repo_column.sort_indicator = false;
manager_window.size_column.sort_indicator = false;
manager_window.packages_state_column.sort_order = order;
manager_window.packages_state_column.sort_indicator = true;
manager_window.packages_name_column.sort_indicator = false;
manager_window.packages_version_column.sort_indicator = false;
manager_window.packages_repo_column.sort_indicator = false;
manager_window.packages_size_column.sort_indicator = false;
manager_window.sortinfo.column_number = 1;
manager_window.sortinfo.sort_type = order;
}
public void sort_by_version (Gtk.SortType order) {
CompareFunc<Pamac.Package?> versioncmp = (pkg_a, pkg_b) => {
return Alpm.pkg_vercmp (pkg_a.version, pkg_b.version);
};
all_pkgs.sort (versioncmp);
pkgs.sort ((Alpm.List.CompareFunc) compare_version);
if (order == Gtk.SortType.DESCENDING) {
all_pkgs.reverse ();
pkgs.reverse ();
}
manager_window.version_column.sort_order = order;
manager_window.state_column.sort_indicator = false;
manager_window.name_column.sort_indicator = false;
manager_window.version_column.sort_indicator = true;
manager_window.repo_column.sort_indicator = false;
manager_window.size_column.sort_indicator = false;
manager_window.packages_version_column.sort_order = order;
manager_window.packages_state_column.sort_indicator = false;
manager_window.packages_name_column.sort_indicator = false;
manager_window.packages_version_column.sort_indicator = true;
manager_window.packages_repo_column.sort_indicator = false;
manager_window.packages_size_column.sort_indicator = false;
manager_window.sortinfo.column_number = 2;
manager_window.sortinfo.sort_type = order;
}
public void sort_by_repo (Gtk.SortType order) {
CompareFunc<Pamac.Package?> repocmp = (pkg_a, pkg_b) => {
return strcmp (pkg_a.repo, pkg_b.repo);
};
all_pkgs.sort (repocmp);
pkgs.sort ((Alpm.List.CompareFunc) compare_repo);
if (order == Gtk.SortType.DESCENDING) {
all_pkgs.reverse ();
pkgs.reverse ();
}
manager_window.repo_column.sort_order = order;
manager_window.state_column.sort_indicator = false;
manager_window.name_column.sort_indicator = false;
manager_window.version_column.sort_indicator = false;
manager_window.repo_column.sort_indicator = true;
manager_window.size_column.sort_indicator = false;
manager_window.packages_repo_column.sort_order = order;
manager_window.packages_state_column.sort_indicator = false;
manager_window.packages_name_column.sort_indicator = false;
manager_window.packages_version_column.sort_indicator = false;
manager_window.packages_repo_column.sort_indicator = true;
manager_window.packages_size_column.sort_indicator = false;
manager_window.sortinfo.column_number = 3;
manager_window.sortinfo.sort_type = order;
}
public void sort_by_size (Gtk.SortType order) {
CompareFunc<Pamac.Package?> sizecmp = (pkg_a, pkg_b) => {
return (int) (pkg_a.size > pkg_b.size) - (int) (pkg_a.size < pkg_b.size);
};
all_pkgs.sort (sizecmp);
pkgs.sort ((Alpm.List.CompareFunc) compare_size);
if (order == Gtk.SortType.DESCENDING) {
all_pkgs.reverse ();
pkgs.reverse ();
}
manager_window.size_column.sort_order = order;
manager_window.state_column.sort_indicator = false;
manager_window.name_column.sort_indicator = false;
manager_window.version_column.sort_indicator = false;
manager_window.repo_column.sort_indicator = false;
manager_window.size_column.sort_indicator = true;
manager_window.packages_size_column.sort_order = order;
manager_window.packages_state_column.sort_indicator = false;
manager_window.packages_name_column.sort_indicator = false;
manager_window.packages_version_column.sort_indicator = false;
manager_window.packages_repo_column.sort_indicator = false;
manager_window.packages_size_column.sort_indicator = true;
manager_window.sortinfo.column_number = 4;
manager_window.sortinfo.sort_type = order;
}

View File

@@ -17,19 +17,47 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const string VERSION = "3.0.0";
namespace Pamac {
public class Config: Object {
string conf_path;
[Compact]
public class Config {
public string conf_path;
public bool recurse;
public int refresh_period;
public uint64 refresh_period;
public bool no_update_hide_icon;
public bool enable_aur;
public bool search_aur;
public bool check_aur_updates;
public bool no_confirm_build;
public HashTable<string,string> environment_variables;
public Config (string path) {
conf_path = path;
//get environment variables
environment_variables = new HashTable<string,string> (str_hash, str_equal);
var utsname = Posix.utsname();
environment_variables.insert ("HTTP_USER_AGENT", "pamac/%s (%s %s)".printf (VERSION, utsname.sysname, utsname.machine));
unowned string? variable = Environment.get_variable ("http_proxy");
if (variable != null) {
environment_variables.insert ("http_proxy", variable);
}
variable = Environment.get_variable ("https_proxy");
if (variable != null) {
environment_variables.insert ("https_proxy", variable);
}
variable = Environment.get_variable ("ftp_proxy");
if (variable != null) {
environment_variables.insert ("ftp_proxy", variable);
}
variable = Environment.get_variable ("socks_proxy");
if (variable != null) {
environment_variables.insert ("socks_proxy", variable);
}
variable = Environment.get_variable ("no_proxy");
if (variable != null) {
environment_variables.insert ("no_proxy", variable);
}
// set default option
refresh_period = 6;
reload ();
@@ -65,16 +93,15 @@ namespace Pamac {
if (line.length == 0) {
continue;
}
splitted = line.split ("=");
string key = splitted[0].strip ();
string? val = null;
if (splitted[1] != null) {
val = splitted[1].strip ();
}
splitted = line.split ("=", 2);
unowned string key = splitted[0]._strip ();
if (key == "RemoveUnrequiredDeps") {
recurse = true;
} else if (key == "RefreshPeriod") {
refresh_period = int.parse (val);
if (splitted.length == 2) {
unowned string val = splitted[1]._strip ();
refresh_period = uint64.parse (val);
}
} else if (key == "NoUpdateHideIcon") {
no_update_hide_icon = true;
} else if (key == "EnableAUR") {
@@ -97,7 +124,7 @@ namespace Pamac {
public void write (HashTable<string,Variant> new_conf) {
var file = GLib.File.new_for_path (conf_path);
string[] data = {};
var data = new GLib.List<string> ();
if (file.query_exists ()) {
try {
// Open file for reading and wrap returned FileInputStream into a
@@ -107,91 +134,85 @@ namespace Pamac {
// Read lines until end of file (null) is reached
while ((line = dis.read_line ()) != null) {
if (line.length == 0) {
data += "\n";
data.append ("\n");
continue;
}
unowned Variant variant;
if (line.contains ("RemoveUnrequiredDeps")) {
if (new_conf.contains ("RemoveUnrequiredDeps")) {
bool val = new_conf.get ("RemoveUnrequiredDeps").get_boolean ();
if (val == true) {
data += "RemoveUnrequiredDeps\n";
if (new_conf.lookup_extended ("RemoveUnrequiredDeps", null, out variant)) {
if (variant.get_boolean ()) {
data.append ("RemoveUnrequiredDeps\n");
} else {
data += "#RemoveUnrequiredDeps\n";
data.append ("#RemoveUnrequiredDeps\n");
}
new_conf.remove ("RemoveUnrequiredDeps");
} else {
data += line + "\n";
data.append (line + "\n");
}
} else if (line.contains ("RefreshPeriod")) {
if (new_conf.contains ("RefreshPeriod")) {
int val = new_conf.get ("RefreshPeriod").get_int32 ();
data += "RefreshPeriod = %u\n".printf (val);
if (new_conf.lookup_extended ("RefreshPeriod", null, out variant)) {
data.append ("RefreshPeriod = %llu\n".printf (variant.get_uint64 ()));
new_conf.remove ("RefreshPeriod");
} else {
data += line + "\n";
data.append (line + "\n");
}
} else if (line.contains ("NoUpdateHideIcon")) {
if (new_conf.contains ("NoUpdateHideIcon")) {
bool val = new_conf.get ("NoUpdateHideIcon").get_boolean ();
if (val == true) {
data += "NoUpdateHideIcon\n";
if (new_conf.lookup_extended ("NoUpdateHideIcon", null, out variant)) {
if (variant.get_boolean ()) {
data.append ("NoUpdateHideIcon\n");
} else {
data += "#NoUpdateHideIcon\n";
data.append ("#NoUpdateHideIcon\n");
}
new_conf.remove ("NoUpdateHideIcon");
} else {
data += line + "\n";
data.append (line + "\n");
}
} else if (line.contains ("EnableAUR")) {
if (new_conf.contains ("EnableAUR")) {
bool val = new_conf.get ("EnableAUR").get_boolean ();
if (val == true) {
data += "EnableAUR\n";
if (new_conf.lookup_extended ("EnableAUR", null, out variant)) {
if (variant.get_boolean ()) {
data.append ("EnableAUR\n");
} else {
data += "#EnableAUR\n";
data.append ("#EnableAUR\n");
}
new_conf.remove ("EnableAUR");
} else {
data += line + "\n";
data.append (line + "\n");
}
} else if (line.contains ("SearchInAURByDefault")) {
if (new_conf.contains ("SearchInAURByDefault")) {
bool val = new_conf.get ("SearchInAURByDefault").get_boolean ();
if (val == true) {
data += "SearchInAURByDefault\n";
if (new_conf.lookup_extended ("SearchInAURByDefault", null, out variant)) {
if (variant.get_boolean ()) {
data.append ("SearchInAURByDefault\n");
} else {
data += "#SearchInAURByDefault\n";
data.append ("#SearchInAURByDefault\n");
}
new_conf.remove ("SearchInAURByDefault");
} else {
data += line + "\n";
data.append (line + "\n");
}
} else if (line.contains ("CheckAURUpdates")) {
if (new_conf.contains ("CheckAURUpdates")) {
bool val = new_conf.get ("CheckAURUpdates").get_boolean ();
if (val == true) {
data += "CheckAURUpdates\n";
if (new_conf.lookup_extended ("CheckAURUpdates", null, out variant)) {
if (variant.get_boolean ()) {
data.append ("CheckAURUpdates\n");
} else {
data += "#CheckAURUpdates\n";
data.append ("#CheckAURUpdates\n");
}
new_conf.remove ("CheckAURUpdates");
} else {
data += line + "\n";
data.append (line + "\n");
}
} else if (line.contains ("NoConfirmBuild")) {
if (new_conf.contains ("NoConfirmBuild")) {
bool val = new_conf.get ("NoConfirmBuild").get_boolean ();
if (val == true) {
data += "NoConfirmBuild\n";
if (new_conf.lookup_extended ("NoConfirmBuild", null, out variant)) {
if (variant.get_boolean ()) {
data.append ("NoConfirmBuild\n");
} else {
data += "#NoConfirmBuild\n";
data.append ("#NoConfirmBuild\n");
}
new_conf.remove ("NoConfirmBuild");
} else {
data += line + "\n";
data.append (line + "\n");
}
} else {
data += line + "\n";
data.append (line + "\n");
}
}
// delete the file before rewrite it
@@ -204,54 +225,57 @@ namespace Pamac {
}
// create lines for unexisted options
if (new_conf.size () != 0) {
data += "\n";
new_conf.foreach ((key, val) => {
data.append ("\n");
var iter = HashTableIter<string,Variant> (new_conf);
unowned string key;
unowned Variant val;
while (iter.next (out key, out val)) {
if (key == "RemoveUnrequiredDeps") {
if (val.get_boolean () == true) {
data += "RemoveUnrequiredDeps\n";
if (val.get_boolean ()) {
data.append ("RemoveUnrequiredDeps\n");
} else {
data += "#RemoveUnrequiredDeps\n";
data.append ("#RemoveUnrequiredDeps\n");
}
} else if (key == "RefreshPeriod") {
data += "RefreshPeriod = %u\n".printf (val.get_int32 ());
data.append ("RefreshPeriod = %llu\n".printf (val.get_uint64 ()));
} else if (key =="NoUpdateHideIcon") {
if (val.get_boolean () == true) {
data += "NoUpdateHideIcon\n";
if (val.get_boolean ()) {
data.append ("NoUpdateHideIcon\n");
} else {
data += "#NoUpdateHideIcon\n";
data.append ("#NoUpdateHideIcon\n");
}
} else if (key == "EnableAUR") {
if (val.get_boolean () == true) {
data += "EnableAUR\n";
if (val.get_boolean ()) {
data.append ("EnableAUR\n");
} else {
data += "#EnableAUR\n";
data.append ("#EnableAUR\n");
}
} else if (key == "SearchInAURByDefault") {
if (val.get_boolean () == true) {
data += "SearchInAURByDefault\n";
if (val.get_boolean ()) {
data.append ("SearchInAURByDefault\n");
} else {
data += "#SearchInAURByDefault\n";
data.append ("#SearchInAURByDefault\n");
}
} else if (key == "CheckAURUpdates") {
if (val.get_boolean () == true) {
data += "CheckAURUpdates\n";
if (val.get_boolean ()) {
data.append ("CheckAURUpdates\n");
} else {
data += "#CheckAURUpdates\n";
data.append ("#CheckAURUpdates\n");
}
} else if (key == "NoConfirmBuild") {
if (val.get_boolean () == true) {
data += "NoConfirmBuild\n";
if (val.get_boolean ()) {
data.append ("NoConfirmBuild\n");
} else {
data += "#NoConfirmBuild\n";
data.append ("#NoConfirmBuild\n");
}
}
});
}
}
// write the file
try {
// creating a DataOutputStream to the file
var dos = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION));
foreach (string new_line in data) {
foreach (unowned string new_line in data) {
// writing a short string to the stream
dos.put_string (new_line);
}

View File

@@ -60,17 +60,22 @@ namespace Pamac {
public Gtk.CheckButton no_confirm_build_checkbutton;
Transaction transaction;
int previous_refresh_period;
Alpm.Config alpm_config;
uint64 previous_refresh_period;
public PreferencesDialog (Transaction transaction, Gtk.ApplicationWindow? window) {
public PreferencesDialog (Gtk.ApplicationWindow? window, Transaction transaction) {
Object (transient_for: window, use_header_bar: 0);
this.transaction = transaction;
alpm_config = new Alpm.Config ("/etc/pacman.conf");
alpm_config.get_handle ();
if (alpm_config.handle == null) {
stderr.printf (dgettext (null, "Failed to initialize alpm library"));
}
refresh_period_label.set_markup (dgettext (null, "How often to check for updates, value in hours") +":");
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
remove_unrequired_deps_button.active = pamac_config.recurse;
check_space_button.active = transaction.get_checkspace ();
if (pamac_config.refresh_period == 0) {
remove_unrequired_deps_button.active = transaction.pamac_config.recurse;
check_space_button.active = (alpm_config.checkspace == 1);
if (transaction.pamac_config.refresh_period == 0) {
check_updates_button.active = false;
refresh_period_label.sensitive = false;
// set default value
@@ -81,15 +86,15 @@ namespace Pamac {
ignorepkgs_box.sensitive = false;
} else {
check_updates_button.active = true;
refresh_period_spin_button.value = pamac_config.refresh_period;
previous_refresh_period = pamac_config.refresh_period;
refresh_period_spin_button.value = transaction.pamac_config.refresh_period;
previous_refresh_period = transaction.pamac_config.refresh_period;
}
no_update_hide_icon_checkbutton.active = pamac_config.no_update_hide_icon;
no_update_hide_icon_checkbutton.active = transaction.pamac_config.no_update_hide_icon;
// populate ignorepkgs_liststore
Gtk.TreeIter iter;
foreach (var name in transaction.get_ignorepkgs ()) {
ignorepkgs_liststore.insert_with_values (out iter, -1, 0, name);
for (unowned Alpm.List<string> list = alpm_config.ignorepkgs; list != null; list = list.next ()) {
ignorepkgs_liststore.insert_with_values (out iter, -1, 0, list.data);
}
remove_unrequired_deps_button.state_set.connect (on_remove_unrequired_deps_button_state_set);
check_space_button.state_set.connect (on_check_space_button_state_set);
@@ -98,8 +103,8 @@ namespace Pamac {
no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled);
transaction.daemon.write_pamac_config_finished.connect (on_write_pamac_config_finished);
Pamac.Package pkg = this.transaction.find_local_satisfier ("pacman-mirrorlist");
if (pkg.name == "") {
unowned Alpm.Package? pkg = Alpm.find_satisfier (alpm_config.handle.localdb.pkgcache, "pacman-mirrorlist");
if (pkg == null) {
mirrors_config_box.visible = false;
} else {
var mirrors_config = new Alpm.MirrorsConfig ("/etc/pacman-mirrors.conf");
@@ -107,7 +112,7 @@ namespace Pamac {
mirrors_country_comboboxtext.active = 0;
int index = 1;
mirrors_config.get_countrys ();
foreach (string country in mirrors_config.countrys) {
foreach (unowned string country in mirrors_config.countrys) {
mirrors_country_comboboxtext.append_text (country);
if (country == mirrors_config.choosen_country) {
mirrors_country_comboboxtext.active = index;
@@ -126,17 +131,17 @@ namespace Pamac {
transaction.daemon.write_mirrors_config_finished.connect (on_write_mirrors_config_finished);
}
pkg = this.transaction.find_local_satisfier ("yaourt");
if (pkg.name == "") {
pkg = Alpm.find_satisfier (alpm_config.handle.localdb.pkgcache, "yaourt");
if (pkg == null) {
aur_config_box.visible = false;
} else {
enable_aur_button.active = pamac_config.enable_aur;
search_aur_checkbutton.active = pamac_config.search_aur;
search_aur_checkbutton.sensitive = pamac_config.enable_aur;
check_aur_updates_checkbutton.active = pamac_config.check_aur_updates;
check_aur_updates_checkbutton.sensitive = pamac_config.enable_aur;
no_confirm_build_checkbutton.active = pamac_config.no_confirm_build;
no_confirm_build_checkbutton.sensitive = pamac_config.enable_aur;
enable_aur_button.active = transaction.pamac_config.enable_aur;
search_aur_checkbutton.active = transaction.pamac_config.search_aur;
search_aur_checkbutton.sensitive = transaction.pamac_config.enable_aur;
check_aur_updates_checkbutton.active = transaction.pamac_config.check_aur_updates;
check_aur_updates_checkbutton.sensitive = transaction.pamac_config.enable_aur;
no_confirm_build_checkbutton.active = transaction.pamac_config.no_confirm_build;
no_confirm_build_checkbutton.sensitive = transaction.pamac_config.enable_aur;
enable_aur_button.state_set.connect (on_enable_aur_button_state_set);
search_aur_checkbutton.toggled.connect (on_search_aur_checkbutton_toggled);
check_aur_updates_checkbutton.toggled.connect (on_check_aur_updates_checkbutton_toggled);
@@ -158,10 +163,10 @@ namespace Pamac {
refresh_period_spin_button.sensitive = new_state;
no_update_hide_icon_checkbutton.sensitive = new_state;
ignorepkgs_box.sensitive = new_state;
if (new_state == true) {
new_pamac_conf.insert ("RefreshPeriod", new Variant.int32 (previous_refresh_period));
if (new_state) {
new_pamac_conf.insert ("RefreshPeriod", new Variant.uint64 (previous_refresh_period));
} else {
new_pamac_conf.insert ("RefreshPeriod", new Variant.int32 (0));
new_pamac_conf.insert ("RefreshPeriod", new Variant.uint64 (0));
}
transaction.start_write_pamac_config (new_pamac_conf);
return true;
@@ -204,7 +209,7 @@ namespace Pamac {
transaction.start_write_pamac_config (new_pamac_conf);
}
void on_write_pamac_config_finished (bool recurse, int refresh_period, bool no_update_hide_icon,
void on_write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
bool enable_aur, bool search_aur, bool check_aur_updates,
bool no_confirm_build) {
remove_unrequired_deps_button.state = recurse;
@@ -248,7 +253,15 @@ namespace Pamac {
[GtkCallback]
void on_add_ignorepkgs_button_clicked () {
var choose_ignorepkgs_dialog = new ChooseIgnorepkgsDialog (this, transaction);
var choose_ignorepkgs_dialog = new ChooseIgnorepkgsDialog (this);
foreach (var pkg in alpm_config.handle.localdb.pkgcache) {
Gtk.TreeIter iter;
if (alpm_config.ignorepkgs.find_str (pkg.name) == null) {
choose_ignorepkgs_dialog.pkgs_list.insert_with_values (out iter, -1, 0, false, 1, pkg.name);
} else {
choose_ignorepkgs_dialog.pkgs_list.insert_with_values (out iter, -1, 0, true, 1, pkg.name);
}
}
if (choose_ignorepkgs_dialog.run () == Gtk.ResponseType.OK) {
var ignorepkg_string = new StringBuilder ();
choose_ignorepkgs_dialog.pkgs_list.foreach ((model, path, iter) => {
@@ -257,7 +270,7 @@ namespace Pamac {
bool selected = val.get_boolean ();
if (selected) {
choose_ignorepkgs_dialog.pkgs_list.get_value (iter, 1, out val);
string name = val.get_string ();
unowned string name = val.get_string ();
if (ignorepkg_string.len != 0) {
ignorepkg_string.append (" ");
}
@@ -287,7 +300,7 @@ namespace Pamac {
ignorepkgs_liststore.foreach ((model, path, iter) => {
GLib.Value val;
ignorepkgs_liststore.get_value (iter, 0, out val);
string name = val.get_string ();
unowned string name = val.get_string ();
if (ignorepkg_string.len != 0) {
ignorepkg_string.append (" ");
}
@@ -305,8 +318,8 @@ namespace Pamac {
// re-populate ignorepkgs_liststore
Gtk.TreeIter iter;
ignorepkgs_liststore.clear ();
foreach (var name in transaction.get_ignorepkgs ()) {
ignorepkgs_liststore.insert_with_values (out iter, -1, 0, name);
for (unowned Alpm.List<string> list = alpm_config.ignorepkgs; list != null; list = list.next ()) {
ignorepkgs_liststore.insert_with_values (out iter, -1, 0, list.data);
}
}
@@ -331,7 +344,7 @@ namespace Pamac {
mirrors_country_comboboxtext.model.foreach ((model, path, iter) => {
GLib.Value val;
model.get_value (iter, 0, out val);
string country = val.get_string ();
unowned string country = val.get_string ();
if (choosen_country == country) {
return true;
}

View File

@@ -33,14 +33,12 @@ namespace Pamac {
[GtkChild]
public Gtk.Expander expander;
Transaction transaction;
public Vte.Terminal term;
Vte.Pty pty;
public ProgressDialog (Transaction transaction, Gtk.ApplicationWindow? window) {
public ProgressDialog (Gtk.ApplicationWindow? window) {
Object (transient_for: window, use_header_bar: 0);
this.transaction = transaction;
//creating terminal
term = new Vte.Terminal ();
term.scroll_on_output = false;
@@ -72,18 +70,6 @@ namespace Pamac {
}
}
[GtkCallback]
public void on_cancel_button_clicked () {
transaction.cancel ();
transaction.clear_lists ();
spawn_in_term ({"/usr/bin/echo", dgettext (null, "Transaction cancelled") + ".\n"});
this.hide ();
transaction.finished (false);
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
}
public void spawn_in_term (string[] args, out Pid child_pid = null) {
Pid intern_pid;
try {

View File

@@ -1,7 +1,7 @@
/*
* pamac-vala
*
* Copyright (C) 2014-2015 Guillaume Benoit <guillaume@manjaro.org>
* Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
*
* 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
@@ -24,10 +24,10 @@ namespace Pamac {
}
[DBus (name = "org.manjaro.pamac")]
public interface Daemon : Object {
public abstract void start_refresh (int force) throws IOError;
public abstract void start_refresh (bool force) throws IOError;
[DBus (no_reply = true)]
public abstract void quit () throws IOError;
public signal void refresh_finished (ErrorInfos error);
public signal void refresh_finished (bool success);
}
}
@@ -84,10 +84,9 @@ int main () {
if (pamac_config.refresh_period != 0) {
if (!check_pamac_running ()) {
try {
pamac_daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac",
"/org/manjaro/pamac");
pamac_daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac", "/org/manjaro/pamac");
pamac_daemon.refresh_finished.connect (on_refresh_finished);
pamac_daemon.start_refresh (0);
pamac_daemon.start_refresh (false);
loop = new MainLoop ();
loop.run ();
} catch (IOError e) {

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/*
* pamac-vala
*
* Copyright (C) 2014-2015 Guillaume Benoit <guillaume@manjaro.org>
* Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
*
* 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
@@ -27,12 +27,12 @@ const string noupdate_info = _("Your system is up-to-date");
namespace Pamac {
[DBus (name = "org.manjaro.pamac")]
public interface Daemon : Object {
public abstract void start_refresh (int force) throws IOError;
public abstract async Updates get_updates (bool check_aur_updates) throws IOError;
public abstract void start_refresh (bool force) throws IOError;
public abstract void start_get_updates (bool check_aur_updates) throws IOError;
[DBus (no_reply = true)]
public abstract void quit () throws IOError;
public signal void refresh_finished (ErrorInfos error);
public signal void write_pamac_config_finished (bool recurse, int refresh_period, bool no_update_hide_icon,
public signal void get_updates_finished (Updates updates);
public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
bool enable_aur, bool search_aur, bool check_aur_updates,
bool no_confirm_build);
public signal void write_alpm_config_finished (bool checkspace);
@@ -40,6 +40,7 @@ namespace Pamac {
public class TrayIcon: Gtk.Application {
Notify.Notification notification;
//~ Notification notification;
Daemon daemon;
bool extern_lock;
uint refresh_timeout_id;
@@ -54,9 +55,9 @@ namespace Pamac {
void start_daemon () {
try {
daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac",
"/org/manjaro/pamac");
daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac", "/org/manjaro/pamac");
// Connecting to signals
daemon.get_updates_finished.connect (on_get_updates_finished);
daemon.write_pamac_config_finished.connect (on_write_pamac_config_finished);
daemon.write_alpm_config_finished.connect (on_write_alpm_config_finished);
} catch (IOError e) {
@@ -65,7 +66,7 @@ namespace Pamac {
}
void stop_daemon () {
if (check_pamac_running () == false) {
if (!check_pamac_running ()) {
try {
daemon.quit ();
} catch (IOError e) {
@@ -128,7 +129,7 @@ namespace Pamac {
check_updates ();
} else {
try {
daemon.start_refresh (0);
daemon.start_refresh (false);
} catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message);
}
@@ -136,10 +137,8 @@ namespace Pamac {
return true;
}
void on_write_pamac_config_finished (bool recurse, int refresh_period, bool no_update_hide_icon,
bool enable_aur, bool search_aur, bool check_aur_updates,
bool no_confirm_build) {
launch_refresh_timeout ((uint) refresh_period);
void on_write_pamac_config_finished (bool recurse, uint64 refresh_period) {
launch_refresh_timeout (refresh_period);
if (refresh_period == 0) {
status_icon.visible = false;
} else {
@@ -151,36 +150,40 @@ namespace Pamac {
check_updates ();
}
void on_get_updates_finished (Updates updates) {
uint updates_nb = updates.repos_updates.length + updates.aur_updates.length;
if (updates_nb == 0) {
this.update_icon (noupdate_icon_name, noupdate_info);
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
if (pamac_config.no_update_hide_icon) {
status_icon.visible = false;
} else {
status_icon.visible = true;
}
close_notification();
} else {
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
this.update_icon (update_icon_name, info);
status_icon.visible = true;
if (check_pamac_running ()) {
update_notification (info);
} else {
show_notification (info);
}
}
stop_daemon ();
}
void check_updates () {
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
if (pamac_config.refresh_period == 0) {
return;
}
daemon.get_updates.begin ((pamac_config.enable_aur && pamac_config.check_aur_updates), (obj, res) => {
var updates = Updates ();
try {
updates = daemon.get_updates.end (res);
} catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message);
}
uint updates_nb = updates.repos_updates.length + updates.aur_updates.length;
if (updates_nb == 0) {
this.update_icon (noupdate_icon_name, noupdate_info);
if (pamac_config.no_update_hide_icon) {
status_icon.visible = false;
} else {
status_icon.visible = true;
}
} else {
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
this.update_icon (update_icon_name, info);
status_icon.visible = true;
if (check_pamac_running () == false) {
show_notification (info);
}
}
stop_daemon ();
});
try {
daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates);
} catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message);
}
}
void show_notification (string info) {
@@ -193,16 +196,44 @@ namespace Pamac {
//~ action.activate.connect (execute_updater);
//~ this.add_action (action);
//~ notification.add_button (_("Show available updates"), "app.update");
//~ notification.set_default_action ("app.update");
//~ this.send_notification (_("Update Manager"), notification);
try {
close_notification();
notification = new Notify.Notification (_("Update Manager"), info, "system-software-update");
notification.add_action ("update", _("Show available updates"), execute_updater);
notification.add_action ("default", _("Show available updates"), execute_updater);
notification.show ();
} catch (Error e) {
stderr.printf ("Notify Error: %s", e.message);
}
}
void update_notification (string info) {
try {
if (notification != null) {
if (notification.get_closed_reason() == -1 && notification.body != info) {
notification.update (_("Update Manager"), info, "system-software-update");
notification.show ();
}
} else {
show_notification (info);
}
} catch (Error e) {
stderr.printf ("Notify Error: %s", e.message);
}
}
void close_notification () {
try {
if (notification != null) {
notification.close();
notification = null;
}
} catch (Error e) {
stderr.printf ("Notify Error: %s", e.message);
}
}
bool check_pamac_running () {
Application app;
bool run = false;
@@ -238,7 +269,7 @@ namespace Pamac {
bool check_pacman_running () {
if (extern_lock) {
if (lockfile.query_exists () == false) {
if (!lockfile.query_exists ()) {
extern_lock = false;
// let the time to the daemon to update packages
Timeout.add (1000, () => {
@@ -247,20 +278,20 @@ namespace Pamac {
});
}
} else {
if (lockfile.query_exists () == true) {
if (lockfile.query_exists ()) {
extern_lock = true;
}
}
return true;
}
void launch_refresh_timeout (uint refresh_period_in_hours) {
void launch_refresh_timeout (uint64 refresh_period_in_hours) {
if (refresh_timeout_id != 0) {
Source.remove (refresh_timeout_id);
refresh_timeout_id = 0;
}
if (refresh_period_in_hours != 0) {
refresh_timeout_id = Timeout.add_seconds (refresh_period_in_hours*3600, start_refresh);
refresh_timeout_id = Timeout.add_seconds ((uint) refresh_period_in_hours*3600, start_refresh);
}
}
@@ -293,9 +324,9 @@ namespace Pamac {
alpm_config.get_handle ();
lockfile = GLib.File.new_for_path (alpm_config.handle.lockfile);
start_daemon ();
Timeout.add (500, check_pacman_running);
Timeout.add (200, check_pacman_running);
start_refresh ();
launch_refresh_timeout ((uint) pamac_config.refresh_period);
launch_refresh_timeout (pamac_config.refresh_period);
this.hold ();
}

View File

@@ -50,14 +50,14 @@ namespace Pamac {
}
public override void activate () {
if (pamac_run == false) {
if (!pamac_run) {
updater_window.present ();
}
}
public override void shutdown () {
base.shutdown ();
if (pamac_run == false) {
if (!pamac_run) {
updater_window.transaction.stop_daemon ();
}
}

View File

@@ -1,7 +1,7 @@
/*
* pamac-vala
*
* Copyright (C) 2014-2015 Guillaume Benoit <guillaume@manjaro.org>
* Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
*
* 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
@@ -25,58 +25,114 @@ namespace Pamac {
[GtkChild]
public Gtk.Label top_label;
[GtkChild]
public Gtk.TreeView updates_treeview;
public Gtk.Notebook notebook;
[GtkChild]
public Gtk.CellRendererToggle select_update;
public Gtk.ScrolledWindow repos_scrolledwindow;
[GtkChild]
public Gtk.ScrolledWindow aur_scrolledwindow;
[GtkChild]
public Gtk.TreeView repos_updates_treeview;
[GtkChild]
public Gtk.CellRendererToggle repos_select_update;
[GtkChild]
public Gtk.TreeView aur_updates_treeview;
[GtkChild]
public Gtk.CellRendererToggle aur_select_update;
[GtkChild]
public Gtk.Label bottom_label;
[GtkChild]
public Gtk.Button apply_button;
public Gtk.ListStore updates_list;
public Gtk.ListStore repos_updates_list;
public Gtk.ListStore aur_updates_list;
public Pamac.Transaction transaction;
public UpdaterWindow (Gtk.Application application) {
Object (application: application);
updates_list = new Gtk.ListStore (3, typeof (bool), typeof (string), typeof (string));
updates_treeview.set_model (updates_list);
repos_updates_list = new Gtk.ListStore (3, typeof (bool), typeof (string), typeof (string));
repos_updates_treeview.set_model (repos_updates_list);
aur_updates_list = new Gtk.ListStore (2, typeof (bool), typeof (string));
aur_updates_treeview.set_model (aur_updates_list);
transaction = new Transaction (this as Gtk.ApplicationWindow);
transaction.mode = Mode.UPDATER;
transaction.finished.connect (on_transaction_finished);
transaction.daemon.get_updates_finished.connect (on_get_updates_finished);
bottom_label.set_visible (false);
apply_button.set_sensitive (false);
notebook.set_show_tabs (false);
aur_scrolledwindow.set_visible (false);
on_refresh_button_clicked ();
}
public void set_apply_button_sensitive () {
bool sensitive = false;
repos_updates_list.foreach ((model, path, iter) => {
GLib.Value selected;
repos_updates_list.get_value (iter, 0, out selected);
sensitive = (bool) selected;
return sensitive;
});
if (!sensitive) {
aur_updates_list.foreach ((model, path, iter) => {
GLib.Value selected;
aur_updates_list.get_value (iter, 0, out selected);
sensitive = (bool) selected;
return sensitive;
});
}
apply_button.set_sensitive (sensitive);
}
[GtkCallback]
public void on_select_update_toggled (string path) {
public void on_repos_select_update_toggled (string path) {
Gtk.TreePath treepath = new Gtk.TreePath.from_string (path);
Gtk.TreeIter iter;
updates_list.get_iter (out iter, treepath);
updates_list.set (iter, 0, !select_update.active);
updates_list.foreach ((model, path, iter) => {
GLib.Value val;
updates_list.get_value (iter, 0, out val);
bool selected = val.get_boolean ();
if (selected) {
apply_button.set_sensitive (true);
return true;
}
apply_button.set_sensitive (false);
return false;
});
GLib.Value name_string;
repos_updates_list.get_iter (out iter, treepath);
repos_updates_list.get_value (iter, 1, out name_string);
// string has the form "pkgname pkgversion"
string pkgname = name_string.get_string ().split (" ", 2)[0];
if (repos_select_update.active) {
repos_updates_list.set (iter, 0, false);
transaction.special_ignorepkgs.add (pkgname);
} else {
repos_updates_list.set (iter, 0, true);
transaction.special_ignorepkgs.remove (pkgname);
}
set_apply_button_sensitive ();
}
[GtkCallback]
public void on_aur_select_update_toggled (string path) {
Gtk.TreePath treepath = new Gtk.TreePath.from_string (path);
Gtk.TreeIter iter;
GLib.Value name_string;
aur_updates_list.get_iter (out iter, treepath);
aur_updates_list.get_value (iter, 1, out name_string);
// string has the form "pkgname pkgversion"
string pkgname = name_string.get_string ().split (" ", 2)[0];
if (aur_select_update.active) {
aur_updates_list.set (iter, 0, false);
transaction.special_ignorepkgs.add (pkgname);
} else {
aur_updates_list.set (iter, 0, true);
transaction.special_ignorepkgs.remove (pkgname);
}
set_apply_button_sensitive ();
}
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);
var preferences_dialog = new PreferencesDialog (this, transaction);
preferences_dialog.run ();
preferences_dialog.destroy ();
while (Gtk.events_pending ()) {
@@ -93,37 +149,20 @@ namespace Pamac {
[GtkCallback]
public void on_preferences_button_clicked () {
run_preferences_dialog.begin (() => {
set_updates_list.begin ();
populate_updates_list ();
});
}
[GtkCallback]
public void on_apply_button_clicked () {
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
updates_list.foreach ((model, path, iter) => {
GLib.Value val;
updates_list.get_value (iter, 0, out val);
bool selected = val.get_boolean ();
if (selected) {
updates_list.get_value (iter, 1, out val);
// string has the form "pkgname pkgversion"
string pkgname = val.get_string ().split (" ", 2)[0];
transaction.special_ignorepkgs.remove (pkgname);
} else {
updates_list.get_value (iter, 1, out val);
// string has the form "pkgname pkgversion"
string pkgname = val.get_string ().split (" ", 2)[0];
transaction.special_ignorepkgs.add ((owned) pkgname);
}
return false;
});
transaction.sysupgrade (0);
transaction.sysupgrade (false);
}
[GtkCallback]
public void on_refresh_button_clicked () {
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
transaction.start_refresh (0);
transaction.start_refresh (false);
}
[GtkCallback]
@@ -131,55 +170,75 @@ namespace Pamac {
this.application.quit ();
}
public void on_transaction_finished (bool error) {
set_updates_list.begin ();
public void on_transaction_finished (bool database_modified) {
if (database_modified) {
populate_updates_list ();
} else {
this.get_window ().set_cursor (null);
}
}
public async void set_updates_list () {
public void populate_updates_list () {
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
transaction.start_get_updates ();
}
public void on_get_updates_finished (Updates updates) {
top_label.set_markup ("");
updates_list.clear ();
repos_updates_list.clear ();
notebook.set_show_tabs (false);
repos_scrolledwindow.set_visible (true);
aur_updates_list.clear ();
bottom_label.set_visible (false);
Gtk.TreeIter iter;
string name;
string size;
uint64 dsize = 0;
uint updates_nb = 0;
Updates updates = yield transaction.get_updates ();
foreach (UpdateInfos infos in updates.repos_updates) {
name = infos.name + " " + infos.version;
if (infos.download_size != 0) {
size = format_size (infos.download_size);
} else {
size = "";
}
uint repos_updates_nb = 0;
uint aur_updates_nb = 0;
foreach (unowned PackageInfos infos in updates.repos_updates) {
string name = infos.name + " " + infos.version;
string size = infos.download_size != 0 ? format_size (infos.download_size) : "";
dsize += infos.download_size;
updates_nb++;
repos_updates_nb++;
if (infos.name in transaction.special_ignorepkgs) {
updates_list.insert_with_values (out iter, -1, 0, false, 1, name, 2, size);
repos_updates_list.insert_with_values (out iter, -1, 0, false, 1, name, 2, size);
} else {
updates_list.insert_with_values (out iter, -1, 0, true, 1, name, 2, size);
repos_updates_list.insert_with_values (out iter, -1, 0, true, 1, name, 2, size);
}
}
foreach (UpdateInfos infos in updates.aur_updates) {
name = infos.name + " " + infos.version;
size = "";
updates_nb++;
updates_list.insert_with_values (out iter, -1, 0, true, 1, name, 2, size);
foreach (unowned PackageInfos infos in updates.aur_updates) {
string name = infos.name + " " + infos.version;
aur_updates_nb++;
if (infos.name in transaction.special_ignorepkgs) {
aur_updates_list.insert_with_values (out iter, -1, 0, false, 1, name);
} else {
aur_updates_list.insert_with_values (out iter, -1, 0, true, 1, name);
}
}
uint updates_nb = repos_updates_nb + aur_updates_nb;
if (updates_nb == 0) {
top_label.set_markup("<b>%s</b>".printf (dgettext (null, "Your system is up-to-date")));
apply_button.set_sensitive (false);
} else {
top_label.set_markup("<b>%s</b>".printf (dngettext (null, "%u available update", "%u available updates", updates_nb).printf (updates_nb)));
apply_button.set_sensitive (true);
}
set_apply_button_sensitive ();
if (dsize != 0) {
bottom_label.set_markup("<b>%s: %s</b>".printf (dgettext (null, "Total download size"), format_size(dsize)));
bottom_label.set_visible (true);
} else {
bottom_label.set_visible (false);
}
if (repos_updates_nb != 0) {
notebook.set_show_tabs (true);
}
if (aur_updates_nb == 0) {
aur_scrolledwindow.set_visible (false);
} else {
aur_scrolledwindow.set_visible (true);
if (repos_updates_nb == 0) {
repos_scrolledwindow.set_visible (false);
}
notebook.set_show_tabs (true);
}
this.get_window ().set_cursor (null);
}
}