Commit 29c572b4 authored by guinux's avatar guinux

add option to automatically download updates

parent 66fb9b93
......@@ -24,3 +24,6 @@ KeepNumPackages = 3
## Remove only the versions of uninstalled packages when clean cache:
#OnlyRmUninstalled
## Download updates in background
#DownloadUpdates
# Translation of Pamac.
# Copyright (C) 2013-2017 Manjaro Developers <manjaro-dev@manjaro.org>
# Copyright (C) 2013-2018 Manjaro Developers <manjaro-dev@manjaro.org>
# This file is distributed under the same license as the Pamac package.
# Guillaume Benoit <guillaume@manjaro.org>, 2013-2017.
# Guillaume Benoit <guillaume@manjaro.org>, 2013-2018.
#
msgid ""
msgstr ""
"Project-Id-Version: Pamac\n"
"Report-Msgid-Bugs-To: guillaume@manjaro.org\n"
"POT-Creation-Date: 2017-09-09 09:46+0200\n"
"POT-Creation-Date: 2018-05-26 17:59+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -125,6 +125,10 @@ msgstr ""
msgid "failed retrieving file '%s' from %s : %s\n"
msgstr ""
#: src/transaction.vala src/tray.vala src/manager_window.vala
msgid "Package Manager"
msgstr ""
#: src/transaction.vala
msgid "Copy"
msgstr ""
......@@ -342,11 +346,11 @@ msgid "_Close"
msgstr ""
#: src/transaction.vala
msgid "Nothing to do"
msgid "Transaction successfully finished"
msgstr ""
#: src/transaction.vala
msgid "Transaction successfully finished"
msgid "Nothing to do"
msgstr ""
#: src/installer.vala src/manager.vala
......@@ -361,10 +365,6 @@ msgstr ""
msgid "Your system is up-to-date"
msgstr ""
#: src/tray.vala src/manager_window.vala
msgid "Package Manager"
msgstr ""
#: src/tray.vala
msgid "_Quit"
msgstr ""
......@@ -641,14 +641,6 @@ msgstr ""
msgid "Worldwide"
msgstr ""
#: src/preferences_dialog.vala
msgid "Speed"
msgstr ""
#: src/preferences_dialog.vala
msgid "Random"
msgstr ""
#: resources/choose_provider_dialog.ui
msgid "Choose a Provider"
msgstr ""
......@@ -739,6 +731,10 @@ msgstr ""
msgid "Check for updates"
msgstr ""
#: resources/preferences_dialog.ui
msgid "Automatically download updates"
msgstr ""
#: resources/preferences_dialog.ui
msgid "Hide tray icon when no update available"
msgstr ""
......@@ -755,10 +751,6 @@ msgstr ""
msgid "Use mirrors from:"
msgstr ""
#: resources/preferences_dialog.ui
msgid "Sort mirrors by:"
msgstr ""
#: resources/preferences_dialog.ui
msgid "Refresh Mirrors List"
msgstr ""
......
# Translation of Pamac.
# Copyright (C) 2013-2017 Manjaro Developers <manjaro-dev@manjaro.org>
# Copyright (C) 2013-2018 Manjaro Developers <manjaro-dev@manjaro.org>
# This file is distributed under the same license as the Pamac package.
# Guillaume Benoit <guillaume@manjaro.org>, 2013-2017.
# Guillaume Benoit <guillaume@manjaro.org>, 2013-2018.
#
msgid ""
msgstr ""
"Project-Id-Version: Pamac\n"
"Report-Msgid-Bugs-To: guillaume@manjaro.org\n"
"POT-Creation-Date: 2017-09-09 09:46+0200\n"
"POT-Creation-Date: 2018-05-26 17:59+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="cache_keep_nb_adjustment">
......@@ -22,6 +22,9 @@
<property name="window_position">center-on-parent</property>
<property name="icon_name">system-software-install</property>
<property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox">
<property name="can_focus">False</property>
......@@ -240,6 +243,24 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="download_updates_checkbutton">
<property name="label" translatable="yes">Automatically download updates</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="margin_left">22</property>
<property name="margin_start">22</property>
<property name="hexpand">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="no_update_hide_icon_checkbutton">
<property name="label" translatable="yes">Hide tray icon when no update available</property>
......@@ -255,7 +276,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
<child>
......@@ -378,7 +399,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">6</property>
</packing>
</child>
</object>
......@@ -781,8 +802,5 @@ All AUR users should be familiar with the build process.</property>
<action-widgets>
<action-widget response="-7">close_button</action-widget>
</action-widgets>
<child>
<placeholder/>
</child>
</template>
</interface>
......@@ -28,6 +28,7 @@ namespace Pamac {
public bool enable_aur { get; private set; }
public string aur_build_dir { get; private set; }
public bool check_aur_updates { get; private set; }
public bool download_updates { get; private set; }
public uint64 keep_num_pkgs { get; private set; }
public bool rm_only_uninstalled { get; private set; }
public unowned HashTable<string,string> environment_variables {
......@@ -74,6 +75,7 @@ namespace Pamac {
enable_aur = false;
aur_build_dir = "/tmp";
check_aur_updates = false;
download_updates = false;
keep_num_pkgs = 3;
rm_only_uninstalled = false;
parse_file (conf_path);
......@@ -124,6 +126,8 @@ namespace Pamac {
}
} else if (key == "CheckAURUpdates") {
check_aur_updates = true;
} else if (key == "DownloadUpdates") {
download_updates = true;
}
}
} catch (GLib.Error e) {
......@@ -226,6 +230,17 @@ namespace Pamac {
} else {
data.append (line + "\n");
}
} else if (line.contains ("DownloadUpdates")) {
if (new_conf.lookup_extended ("DownloadUpdates", null, out variant)) {
if (variant.get_boolean ()) {
data.append ("DownloadUpdates\n");
} else {
data.append ("#DownloadUpdates\n");
}
new_conf.remove ("DownloadUpdates");
} else {
data.append (line + "\n");
}
} else {
data.append (line + "\n");
}
......@@ -281,6 +296,12 @@ namespace Pamac {
} else {
data.append ("#CheckAURUpdates\n");
}
} else if (key == "DownloadUpdates") {
if (val.get_boolean ()) {
data.append ("DownloadUpdates\n");
} else {
data.append ("#DownloadUpdates\n");
}
}
}
}
......
......@@ -35,6 +35,8 @@ namespace Pamac {
[GtkChild]
Gtk.CheckButton no_update_hide_icon_checkbutton;
[GtkChild]
Gtk.CheckButton download_updates_checkbutton;
[GtkChild]
Gtk.Box ignorepkgs_box;
[GtkChild]
Gtk.TreeView ignorepkgs_treeview;
......@@ -83,6 +85,7 @@ namespace Pamac {
previous_refresh_period = 6;
refresh_period_spin_button.sensitive = false;
no_update_hide_icon_checkbutton.sensitive = false;
download_updates_checkbutton.sensitive = false;
ignorepkgs_box.sensitive = false;
} else {
check_updates_button.active = true;
......@@ -90,6 +93,7 @@ namespace Pamac {
previous_refresh_period = transaction.refresh_period;
}
no_update_hide_icon_checkbutton.active = transaction.no_update_hide_icon;
download_updates_checkbutton.active = transaction.download_updates;
cache_keep_nb_spin_button.value = transaction.keep_num_pkgs;
cache_only_uninstalled_checkbutton.active = transaction.rm_only_uninstalled;
......@@ -105,6 +109,7 @@ namespace Pamac {
check_updates_button.state_set.connect (on_check_updates_button_state_set);
refresh_period_spin_button.value_changed.connect (on_refresh_period_spin_button_value_changed);
no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled);
download_updates_checkbutton.toggled.connect (on_download_updates_checkbutton_toggled);
cache_keep_nb_spin_button.value_changed.connect (on_cache_keep_nb_spin_button_value_changed);
cache_only_uninstalled_checkbutton.toggled.connect (on_cache_only_uninstalled_checkbutton_toggled);
transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
......@@ -159,6 +164,7 @@ namespace Pamac {
refresh_period_label.sensitive = new_state;
refresh_period_spin_button.sensitive = new_state;
no_update_hide_icon_checkbutton.sensitive = new_state;
download_updates_checkbutton.sensitive = new_state;
ignorepkgs_box.sensitive = new_state;
if (new_state) {
new_pamac_conf.insert ("RefreshPeriod", new Variant.uint64 (previous_refresh_period));
......@@ -193,6 +199,12 @@ namespace Pamac {
transaction.start_write_pamac_config (new_pamac_conf);
}
void on_download_updates_checkbutton_toggled () {
var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
new_pamac_conf.insert ("DownloadUpdates", new Variant.boolean (download_updates_checkbutton.active));
transaction.start_write_pamac_config (new_pamac_conf);
}
bool on_enable_aur_button_state_set (bool new_state) {
var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
new_pamac_conf.insert ("EnableAUR", new Variant.boolean (new_state));
......@@ -213,13 +225,15 @@ namespace Pamac {
}
void on_write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
bool enable_aur, string aur_build_dir, bool check_aur_updates) {
bool enable_aur, string aur_build_dir, bool check_aur_updates,
bool download_updates) {
remove_unrequired_deps_button.state = recurse;
if (refresh_period == 0) {
check_updates_button.state = false;
refresh_period_label.sensitive = false;
refresh_period_spin_button.sensitive = false;
no_update_hide_icon_checkbutton.sensitive = false;
download_updates_checkbutton.sensitive = false;
ignorepkgs_box.sensitive = false;
} else {
check_updates_button.state = true;
......@@ -228,9 +242,11 @@ namespace Pamac {
previous_refresh_period = refresh_period;
refresh_period_spin_button.sensitive = true;
no_update_hide_icon_checkbutton.sensitive = true;
download_updates_checkbutton.sensitive = true;
ignorepkgs_box.sensitive = true;
}
no_update_hide_icon_checkbutton.active = no_update_hide_icon;
download_updates_checkbutton.active = download_updates;
enable_aur_button.state = enable_aur;
aur_build_dir_label.sensitive = enable_aur;
aur_build_dir_file_chooser.sensitive = enable_aur;
......
......@@ -75,6 +75,7 @@ namespace Pamac {
public Cancellable cancellable;
public Curl.Easy curl;
private bool authorized;
private bool downloading_updates;
public signal void emit_event (uint primary_event, uint secondary_event, string[] details);
public signal void emit_providers (string depend, string[] providers);
......@@ -85,11 +86,13 @@ namespace Pamac {
public signal void set_pkgreason_finished ();
public signal void refresh_finished (bool success);
public signal void get_updates_finished (Updates updates);
public signal void download_updates_finished ();
public signal void trans_prepare_finished (bool success);
public signal void trans_commit_finished (bool success);
public signal void get_authorization_finished (bool authorized);
public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
bool enable_aur, string aur_build_dir, bool check_aur_updates);
bool enable_aur, string aur_build_dir, bool check_aur_updates,
bool download_updates);
public signal void write_alpm_config_finished (bool checkspace);
public signal void generate_mirrors_list_data (string line);
public signal void generate_mirrors_list_finished ();
......@@ -113,6 +116,7 @@ namespace Pamac {
curl = new Curl.Easy ();
authorized = false;
refreshed = false;
downloading_updates = false;
}
public void set_environment_variables (HashTable<string,string> variables) throws Error {
......@@ -308,7 +312,8 @@ namespace Pamac {
pamac_config.reload ();
}
write_pamac_config_finished (pamac_config.recurse, pamac_config.refresh_period, pamac_config.no_update_hide_icon,
pamac_config.enable_aur, pamac_config.aur_build_dir, pamac_config.check_aur_updates);
pamac_config.enable_aur, pamac_config.aur_build_dir, pamac_config.check_aur_updates,
pamac_config.download_updates);
});
}
......@@ -480,6 +485,19 @@ namespace Pamac {
refresh_finished (true);
return;
}
if (downloading_updates) {
cancellable.cancel ();
// let time to cancel download updates
Timeout.add (1000, () => {
launch_refresh_thread ();
return false;
});
} else {
launch_refresh_thread ();
}
}
private void launch_refresh_thread () {
try {
thread_pool.add (new AlpmAction (refresh));
} catch (ThreadError e) {
......@@ -820,6 +838,37 @@ namespace Pamac {
}
}
private int download_updates () {
downloading_updates = true;
// use a independant handle
var handle = alpm_config.get_handle ();
handle.fetchcb = (Alpm.FetchCallBack) cb_fetch;
cancellable.reset ();
int success = handle.trans_init (Alpm.TransFlag.DOWNLOADONLY);
// can't add nolock flag with commit so remove unneeded lock
handle.unlock ();
if (success == 0) {
success = handle.trans_sysupgrade (0);
if (success == 0) {
Alpm.List err_data;
success = handle.trans_prepare (out err_data);
if (success == 0) {
handle.unlock ();
success = handle.trans_commit (out err_data);
}
}
handle.trans_release ();
}
downloading_updates = false;
download_updates_finished ();
return success;
}
public void start_download_updates () throws Error {
// do not add this thread to the threadpool so it won't be queued
new Thread<int> ("download updates thread", download_updates);
}
private bool trans_init (Alpm.TransFlag flags) {
current_error = ErrorInfos ();
cancellable.reset ();
......@@ -865,20 +914,15 @@ namespace Pamac {
to_build = to_build_;
to_build_infos = {};
aur_pkgbases_to_build = new GLib.List<string> ();
if (to_build.length != 0) {
compute_aur_build_list.begin (to_build, (obj, res) => {
try {
thread_pool.add (new AlpmAction (build_prepare));
} catch (ThreadError e) {
stderr.printf ("Thread Error %s\n", e.message);
}
if (downloading_updates) {
cancellable.cancel ();
// let time to cancel download updates
Timeout.add (1000, () => {
launch_prepare_thread ();
return false;
});
} else {
try {
thread_pool.add (new AlpmAction (trans_prepare));
} catch (ThreadError e) {
stderr.printf ("Thread Error %s\n", e.message);
}
launch_prepare_thread ();
}
}
......@@ -1343,6 +1387,19 @@ namespace Pamac {
to_build_infos = {};
aur_pkgbases_to_build = new GLib.List<string> ();
sysupgrade = false;
if (downloading_updates) {
cancellable.cancel ();
// let time to cancel download updates
Timeout.add (1000, () => {
launch_prepare_thread ();
return false;
});
} else {
launch_prepare_thread ();
}
}
private void launch_prepare_thread () {
if (to_build.length != 0) {
compute_aur_build_list.begin (to_build, (obj, res) => {
try {
......@@ -1553,6 +1610,10 @@ namespace Pamac {
public void quit () throws Error {
// wait for all tasks to be processed
ThreadPool.free ((owned) thread_pool, false, true);
// do not quit if downloading updates
if (downloading_updates) {
return;
}
loop.quit ();
}
// End of Daemon Object
......
......@@ -91,7 +91,8 @@ namespace Pamac {
public signal void trans_commit_finished (bool success);
public signal void get_authorization_finished (bool authorized);
public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
bool enable_aur, string aur_build_dir, bool check_aur_updates);
bool enable_aur, string aur_build_dir, bool check_aur_updates,
bool download_updates);
public signal void write_alpm_config_finished (bool checkspace);
public signal void generate_mirrors_list_data (string line);
public signal void generate_mirrors_list_finished ();
......@@ -119,6 +120,7 @@ namespace Pamac {
public bool enable_aur { get { return pamac_config.enable_aur; } }
public unowned GLib.HashTable<string,string> environment_variables { get {return pamac_config.environment_variables; } }
public bool no_update_hide_icon { get { return pamac_config.no_update_hide_icon; } }
public bool download_updates { get { return pamac_config.download_updates; } }
public bool recurse { get { return pamac_config.recurse; } }
public uint64 refresh_period { get { return pamac_config.refresh_period; } }
public string aur_build_dir { get { return pamac_config.aur_build_dir; } }
......@@ -177,7 +179,8 @@ namespace Pamac {
public signal void finished (bool success);
public signal void set_pkgreason_finished ();
public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
bool enable_aur, string aur_build_dir, bool check_aur_updates);
bool enable_aur, string aur_build_dir, bool check_aur_updates,
bool download_updates);
public signal void write_alpm_config_finished (bool checkspace);
public signal void generate_mirrors_list ();
public signal void generate_mirrors_list_finished ();
......@@ -1826,7 +1829,8 @@ namespace Pamac {
flags |= (1 << 5); //Alpm.TransFlag.RECURSE
}
write_pamac_config_finished (recurse, refresh_period, no_update_hide_icon,
enable_aur, aur_build_dir, check_aur_updates);
enable_aur, aur_build_dir, check_aur_updates,
download_updates);
}
void on_write_alpm_config_finished (bool checkspace) {
......
......@@ -34,14 +34,24 @@ namespace Pamac {
public abstract void quit () throws Error;
public signal void get_updates_finished (Updates updates);
}
[DBus (name = "org.manjaro.pamac.system")]
interface SystemDaemon : Object {
public abstract void set_environment_variables (HashTable<string,string> variables) throws Error;
public abstract void start_download_updates () throws Error;
[DBus (no_reply = true)]
public abstract void quit () throws Error;
public signal void download_updates_finished ();
}
public abstract class TrayIcon: Gtk.Application {
Notify.Notification notification;
UserDaemon daemon;
UserDaemon user_daemon;
SystemDaemon system_daemon;
bool extern_lock;
uint refresh_timeout_id;
public Gtk.Menu menu;
GLib.File lockfile;
uint updates_nb;
public TrayIcon () {
application_id = "org.manjaro.pamac.tray";
......@@ -50,19 +60,45 @@ namespace Pamac {
public abstract void init_status_icon ();
void start_daemon () {
try {
daemon = Bus.get_proxy_sync (BusType.SESSION, "org.manjaro.pamac.user", "/org/manjaro/pamac/user");
daemon.get_updates_finished.connect (on_get_updates_finished);
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
void start_user_daemon () {
if (user_daemon == null) {
try {
user_daemon = Bus.get_proxy_sync (BusType.SESSION, "org.manjaro.pamac.user", "/org/manjaro/pamac/user");
user_daemon.get_updates_finished.connect (on_get_updates_finished);
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
}
}
void stop_daemon () {
void stop_user_daemon () {
if (!check_pamac_running ()) {
try {
daemon.quit ();
user_daemon.quit ();
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
}
}
void start_system_daemon () {
if (system_daemon == null) {
try {
system_daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac.system", "/org/manjaro/pamac/system");
// Set environment variables
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
system_daemon.set_environment_variables (pamac_config.environment_variables);
system_daemon.download_updates_finished.connect (on_download_updates_finished);
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
}
}
void stop_system_daemon () {
if (!check_pamac_running ()) {
try {
system_daemon.quit ();
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
......@@ -117,7 +153,7 @@ namespace Pamac {
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
if (pamac_config.refresh_period != 0) {
try {
daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates, true);
user_daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates, true);
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
......@@ -126,25 +162,43 @@ namespace Pamac {
}
void on_get_updates_finished (Updates updates) {
uint updates_nb = updates.repos_updates.length + updates.aur_updates.length;
updates_nb = updates.repos_updates.length + updates.aur_updates.length;
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
if (updates_nb == 0) {
set_icon (noupdate_icon_name);
set_tooltip (noupdate_info);
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
set_icon_visible (!pamac_config.no_update_hide_icon);
close_notification ();
} else {
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
set_icon (update_icon_name);
set_tooltip (info);
set_icon_visible (true);
if (check_pamac_running ()) {
update_notification (info);
if (!check_pamac_running () && pamac_config.download_updates) {
start_system_daemon ();
try {
system_daemon.start_download_updates ();
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
} else {
show_notification (info);
show_or_update_notification ();
}
}
stop_daemon ();
stop_user_daemon ();
}
void on_download_updates_finished () {
show_or_update_notification ();
stop_system_daemon ();
}
void show_or_update_notification () {
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
set_icon (update_icon_name);
set_tooltip (info);
set_icon_visible (true);
if (check_pamac_running ()) {
update_notification (info);
} else {
show_notification (info);
}
}
void show_notification (string info) {
......@@ -212,7 +266,7 @@ namespace Pamac {
if (!lockfile.query_exists ()) {
extern_lock = false;
try {
daemon.refresh_handle ();
user_daemon.refresh_handle ();
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
......@@ -262,9 +316,9 @@ namespace Pamac {
Notify.init (_("Package Manager"));
start_daemon ();
start_user_daemon ();
try {
lockfile = GLib.File.new_for_path (daemon.get_lockfile ());
lockfile = GLib.File.new_for_path (user_daemon.get_lockfile ());
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
//try standard lock file
......
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