Graphical package manager for pacman based on pamac 5.x.x
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2178 lines
72KB

  1. /*
  2. * pamac-vala
  3. *
  4. * Copyright (C) 2017-2019 Chris Cromer <cromer@cromnix.org>
  5. * Copyright (C) 2014-2017 Guillaume Benoit <guillaume@manjaro.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a get of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. //using Math
  21. //using Vte
  22. //using Posix
  23. namespace Pamac {
  24. [DBus (name = "org.pamac.user")]
  25. interface UserDaemon : Object {
  26. public abstract void refresh_handle () throws DBusError, IOError;
  27. public abstract AlpmPackage get_installed_pkg (string pkgname) throws DBusError, IOError;
  28. public abstract bool get_checkspace () throws DBusError, IOError;
  29. public abstract string[] get_ignorepkgs () throws DBusError, IOError;
  30. public abstract bool should_hold (string pkgname) throws DBusError, IOError;
  31. public abstract uint get_pkg_reason (string pkgname) throws DBusError, IOError;
  32. public abstract uint get_pkg_origin (string pkgname) throws DBusError, IOError;
  33. public abstract async AlpmPackage[] get_installed_pkgs () throws DBusError, IOError;
  34. public abstract async AlpmPackage[] get_explicitly_installed_pkgs () throws DBusError, IOError;
  35. public abstract async AlpmPackage[] get_foreign_pkgs () throws DBusError, IOError;
  36. public abstract async AlpmPackage[] get_orphans () throws DBusError, IOError;
  37. public abstract AlpmPackage find_installed_satisfier (string depstring) throws DBusError, IOError;
  38. public abstract AlpmPackage get_sync_pkg (string pkgname) throws DBusError, IOError;
  39. public abstract AlpmPackage find_sync_satisfier (string depstring) throws DBusError, IOError;
  40. public abstract async AlpmPackage[] search_pkgs (string search_string) throws DBusError, IOError;
  41. #if DISABLE_AUR
  42. #else
  43. public abstract async AURPackage[] search_in_aur (string search_string) throws DBusError, IOError;
  44. #endif
  45. public abstract string[] get_repos_names () throws DBusError, IOError;
  46. public abstract async AlpmPackage[] get_repo_pkgs (string repo) throws DBusError, IOError;
  47. public abstract string[] get_groups_names () throws DBusError, IOError;
  48. public abstract async AlpmPackage[] get_group_pkgs (string groupname) throws DBusError, IOError;
  49. public abstract AlpmPackageDetails get_pkg_details (string pkgname) throws DBusError, IOError;
  50. public abstract string[] get_pkg_files (string pkgname) throws DBusError, IOError;
  51. #if DISABLE_AUR
  52. #else
  53. public abstract async AURPackageDetails get_aur_details (string pkgname) throws DBusError, IOError;
  54. #endif
  55. public abstract string[] get_pkg_uninstalled_optdeps (string pkgname) throws DBusError, IOError;
  56. #if DISABLE_AUR
  57. public abstract void start_get_updates () throws DBusError, IOError;
  58. #else
  59. public abstract void start_get_updates (bool check_aur_updates) throws DBusError, IOError;
  60. #endif
  61. [DBus (no_reply = true)]
  62. public abstract void quit () throws DBusError, IOError;
  63. public signal void get_updates_finished (Updates updates);
  64. }
  65. [DBus (name = "org.pamac.system")]
  66. interface SystemDaemon : Object {
  67. public abstract void set_environment_variables (HashTable<string,string> variables) throws DBusError, IOError;
  68. public abstract string[] get_mirrors_countries () throws DBusError, IOError;
  69. public abstract ErrorInfos get_current_error () throws DBusError, IOError;
  70. public abstract bool get_lock () throws DBusError, IOError;
  71. public abstract bool unlock () throws DBusError, IOError;
  72. public abstract void start_get_authorization () throws DBusError, IOError;
  73. public abstract void start_save_pamac_config () throws DBusError, IOError;
  74. public abstract void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf) throws DBusError, IOError;
  75. public abstract void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf) throws DBusError, IOError;
  76. public abstract void start_generate_mirrors_list () throws DBusError, IOError;
  77. public abstract void clean_cache (uint64 keep_nb, bool only_uninstalled) throws DBusError, IOError;
  78. public abstract void start_set_pkgreason (string pkgname, uint reason) throws DBusError, IOError;
  79. public abstract void start_refresh (bool force) throws DBusError, IOError;
  80. public abstract void start_sysupgrade_prepare (bool enable_downgrade, string[] temporary_ignorepkgs) throws DBusError, IOError;
  81. #if DISABLE_AUR
  82. public abstract void start_trans_prepare (int transflags, string[] to_install, string[] to_remove, string[] to_load) throws DBusError, IOError;
  83. #else
  84. public abstract void start_trans_prepare (int transflags, string[] to_install, string[] to_remove, string[] to_load, string[] to_build) throws DBusError, IOError;
  85. #endif
  86. public abstract void choose_provider (int provider) throws DBusError, IOError;
  87. public abstract TransactionSummary get_transaction_summary () throws DBusError, IOError;
  88. public abstract void start_trans_commit () throws DBusError, IOError;
  89. public abstract void trans_release () throws DBusError, IOError;
  90. public abstract void trans_cancel () throws DBusError, IOError;
  91. #if DISABLE_AUR
  92. public abstract void start_get_updates () throws DBusError, IOError;
  93. #else
  94. public abstract void start_get_updates (bool check_aur_updates) throws DBusError, IOError;
  95. #endif
  96. [DBus (no_reply = true)]
  97. public abstract void quit () throws DBusError, IOError;
  98. public signal void get_updates_finished (Updates updates);
  99. public signal void emit_event (uint primary_event, uint secondary_event, string[] details);
  100. public signal void emit_providers (string depend, string[] providers);
  101. public signal void emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target);
  102. public signal void emit_download (string filename, uint64 xfered, uint64 total);
  103. public signal void emit_totaldownload (uint64 total);
  104. public signal void emit_log (uint level, string msg);
  105. public signal void set_pkgreason_finished ();
  106. public signal void refresh_finished (bool success);
  107. public signal void trans_prepare_finished (bool success);
  108. public signal void trans_commit_finished (bool success);
  109. public signal void get_authorization_finished (bool authorized);
  110. #if DISABLE_AUR
  111. public signal void save_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon);
  112. #else
  113. public signal void save_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  114. bool enable_aur, bool search_aur, string aur_build_dir, bool check_aur_updates);
  115. #endif
  116. public signal void write_alpm_config_finished (bool checkspace);
  117. public signal void write_mirrors_config_finished (string choosen_country, string choosen_generation_method);
  118. public signal void generate_mirrors_list_data (string line);
  119. public signal void generate_mirrors_list_finished ();
  120. }
  121. public class Transaction: Object {
  122. enum Type {
  123. STANDARD = (1 << 0),
  124. UPDATE = (1 << 1),
  125. BUILD = (1 << 2)
  126. }
  127. public enum Mode {
  128. MANAGER,
  129. INSTALLER
  130. }
  131. UserDaemon user_daemon;
  132. SystemDaemon system_daemon;
  133. public Mode mode;
  134. Pamac.Config pamac_config;
  135. #if DISABLE_AUR
  136. #else
  137. public bool check_aur_updates { get { return pamac_config.check_aur_updates; } }
  138. public bool enable_aur { get { return pamac_config.enable_aur; } }
  139. public bool search_aur { get { return pamac_config.search_aur; } }
  140. public string aur_build_dir { get { return pamac_config.aur_build_dir; } }
  141. #endif
  142. public uint64 keep_num_pkgs { get { return pamac_config.keep_num_pkgs; } }
  143. public bool rm_only_uninstalled { get { return pamac_config.rm_only_uninstalled; } }
  144. public string terminal_background { get { return pamac_config.terminal_background; } }
  145. public string terminal_foreground { get { return pamac_config.terminal_foreground; } }
  146. public string terminal_font { get { return pamac_config.terminal_font; } }
  147. public unowned GLib.HashTable<string,string> environment_variables { get { return pamac_config.environment_variables; } }
  148. public bool no_update_hide_icon { get { return pamac_config.no_update_hide_icon; } }
  149. public bool recurse { get { return pamac_config.recurse; } }
  150. public bool update_files_db { get { return pamac_config.update_files_db; } }
  151. public uint64 refresh_period { get { return pamac_config.refresh_period; } }
  152. //Alpm.TransFlag
  153. int flags;
  154. public GenericSet<string?> to_install;
  155. public GenericSet<string?> to_remove;
  156. public GenericSet<string?> to_load;
  157. #if DISABLE_AUR
  158. #else
  159. public GenericSet<string?> to_build;
  160. #endif
  161. public GenericSet<string?> to_update;
  162. #if DISABLE_AUR
  163. #else
  164. Queue<string> to_build_queue;
  165. string[] aur_pkgs_to_install;
  166. #endif
  167. GenericSet<string?> previous_to_install;
  168. GenericSet<string?> previous_to_remove;
  169. public GenericSet<string?> transaction_summary;
  170. public GenericSet<string?> temporary_ignorepkgs;
  171. uint64 total_download;
  172. uint64 already_downloaded;
  173. string previous_textbar;
  174. float previous_percent;
  175. string previous_filename;
  176. uint pulse_timeout_id;
  177. bool sysupgrade_after_trans;
  178. bool enable_downgrade;
  179. bool no_confirm_commit;
  180. #if DISABLE_AUR
  181. #else
  182. bool build_after_sysupgrade;
  183. bool building;
  184. #endif
  185. uint64 previous_xfered;
  186. uint64 download_rate;
  187. uint64 rates_nb;
  188. Timer timer;
  189. bool success;
  190. StringBuilder warning_textbuffer;
  191. //dialogs
  192. TransactionSumDialog transaction_sum_dialog;
  193. public ProgressBox progress_box;
  194. //Pango.FontDescription pfd;
  195. Vte.Terminal term;
  196. Vte.Pty pty;
  197. #if DISABLE_AUR
  198. #else
  199. Cancellable build_cancellable;
  200. #endif
  201. public Gtk.ScrolledWindow term_window;
  202. //parent window
  203. public Gtk.ApplicationWindow? application_window { get; private set; }
  204. public signal void start_downloading ();
  205. public signal void stop_downloading ();
  206. #if DISABLE_AUR
  207. #else
  208. public signal void start_building ();
  209. public signal void stop_building ();
  210. #endif
  211. public signal void important_details_outpout (bool must_show);
  212. public signal void finished (bool success);
  213. public signal void set_pkgreason_finished ();
  214. #if DISABLE_AUR
  215. public signal void save_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon);
  216. #else
  217. public signal void save_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  218. bool enable_aur, bool search_aur, string aur_build_dir, bool check_aur_updates);
  219. #endif
  220. public signal void write_alpm_config_finished (bool checkspace);
  221. public signal void write_mirrors_config_finished (string choosen_country, string choosen_generation_method);
  222. public signal void generate_mirrors_list ();
  223. public signal void run_preferences_dialog_finished ();
  224. public signal void get_updates_finished (Updates updates);
  225. public Transaction (Gtk.ApplicationWindow? application_window) {
  226. mode = Mode.MANAGER;
  227. pamac_config = new Pamac.Config ();
  228. flags = (1 << 4); //Alpm.TransFlag.CASCADE
  229. if (pamac_config.recurse) {
  230. flags |= (1 << 5); //Alpm.TransFlag.RECURSE
  231. }
  232. to_install = new GenericSet<string?> (str_hash, str_equal);
  233. to_remove = new GenericSet<string?> (str_hash, str_equal);
  234. to_load = new GenericSet<string?> (str_hash, str_equal);
  235. #if DISABLE_AUR
  236. #else
  237. to_build = new GenericSet<string?> (str_hash, str_equal);
  238. #endif
  239. to_update = new GenericSet<string?> (str_hash, str_equal);
  240. #if DISABLE_AUR
  241. #else
  242. to_build_queue = new Queue<string> ();
  243. #endif
  244. previous_to_install = new GenericSet<string?> (str_hash, str_equal);
  245. previous_to_remove = new GenericSet<string?> (str_hash, str_equal);
  246. transaction_summary = new GenericSet<string?> (str_hash, str_equal);
  247. temporary_ignorepkgs = new GenericSet<string?> (str_hash, str_equal);
  248. connecting_user_daemon ();
  249. //creating dialogs
  250. this.application_window = application_window;
  251. transaction_sum_dialog = new TransactionSumDialog (application_window);
  252. progress_box = new ProgressBox ();
  253. progress_box.progressbar.text = "";
  254. //creating terminal
  255. term = new Vte.Terminal ();
  256. term.set_scrollback_lines (-1);
  257. term.expand = true;
  258. term.visible = true;
  259. var tmp = Gdk.RGBA ();
  260. tmp.parse (terminal_background);
  261. term.set_color_cursor (tmp);
  262. term.set_color_background (tmp);
  263. tmp.parse (terminal_foreground);
  264. term.set_color_foreground (tmp);
  265. term.set_font (Pango.FontDescription.from_string (terminal_font));
  266. term.button_press_event.connect (on_term_button_press_event);
  267. term.key_press_event.connect (on_term_key_press_event);
  268. // creating pty for term
  269. try {
  270. pty = term.pty_new_sync (Vte.PtyFlags.NO_HELPER);
  271. } catch (Error e) {
  272. stderr.printf ("Error: %s\n", e.message);
  273. }
  274. // add term in a grid with a scrollbar
  275. term_window = new Gtk.ScrolledWindow (null, term.vadjustment);
  276. term_window.expand = true;
  277. term_window.visible = true;
  278. term_window.propagate_natural_height = true;
  279. term_window.add (term);
  280. #if DISABLE_AUR
  281. #else
  282. build_cancellable = new Cancellable ();
  283. #endif
  284. // progress data
  285. previous_textbar = "";
  286. previous_filename = "";
  287. sysupgrade_after_trans = false;
  288. no_confirm_commit = false;
  289. #if DISABLE_AUR
  290. #else
  291. build_after_sysupgrade = false;
  292. building = false;
  293. #endif
  294. timer = new Timer ();
  295. success = false;
  296. warning_textbuffer = new StringBuilder ();
  297. }
  298. public void config_changed() {
  299. pamac_config.reload();
  300. }
  301. public void update_terminal_background (string background) {
  302. var tmp = Gdk.RGBA ();
  303. tmp.parse (background);
  304. term.set_color_cursor (tmp);
  305. term.set_color_background (tmp);
  306. }
  307. public void update_terminal_foreground (string foreground) {
  308. var tmp = Gdk.RGBA ();
  309. tmp.parse (foreground);
  310. term.set_color_foreground (tmp);
  311. }
  312. public void update_terminal_font (string font) {
  313. term.set_font (Pango.FontDescription.from_string (terminal_font));
  314. }
  315. public void run_preferences_dialog () {
  316. var preferences_dialog = new PreferencesDialog (this);
  317. preferences_dialog.run ();
  318. preferences_dialog.destroy ();
  319. while (Gtk.events_pending ()) {
  320. Gtk.main_iteration ();
  321. }
  322. run_preferences_dialog_finished ();
  323. }
  324. public ErrorInfos get_current_error () {
  325. try {
  326. return system_daemon.get_current_error ();
  327. } catch (IOError e) {
  328. stderr.printf ("IOError: %s\n", e.message);
  329. return ErrorInfos ();
  330. } catch (DBusError e) {
  331. stderr.printf ("DBusError: %s\n", e.message);
  332. return ErrorInfos ();
  333. }
  334. }
  335. public string[] get_mirrors_countries () {
  336. string[] countries = {};
  337. connecting_system_daemon ();
  338. try {
  339. countries = system_daemon.get_mirrors_countries ();
  340. } catch (IOError e) {
  341. stderr.printf ("IOError: %s\n", e.message);
  342. } catch (DBusError e) {
  343. stderr.printf ("DBusError: %s\n", e.message);
  344. }
  345. return countries;
  346. }
  347. public bool get_lock () {
  348. bool locked = false;
  349. connecting_system_daemon ();
  350. try {
  351. locked = system_daemon.get_lock ();
  352. } catch (IOError e) {
  353. stderr.printf ("IOError: %s\n", e.message);
  354. } catch (DBusError e) {
  355. stderr.printf ("DBusError: %s\n", e.message);
  356. }
  357. return locked;
  358. }
  359. public bool unlock () {
  360. bool unlocked = false;
  361. try {
  362. unlocked = system_daemon.unlock ();
  363. } catch (IOError e) {
  364. stderr.printf ("IOError: %s\n", e.message);
  365. } catch (DBusError e) {
  366. stderr.printf ("DBusError: %s\n", e.message);
  367. }
  368. return unlocked;
  369. }
  370. async bool check_authorization () {
  371. SourceFunc callback = check_authorization.callback;
  372. bool authorized = false;
  373. ulong handler_id = system_daemon.get_authorization_finished.connect ((authorized_) => {
  374. authorized = authorized_;
  375. Idle.add ((owned) callback);
  376. });
  377. try {
  378. system_daemon.start_get_authorization ();
  379. } catch (IOError e) {
  380. stderr.printf ("IOError: %s\n", e.message);
  381. } catch (DBusError e) {
  382. stderr.printf ("DBusError: %s\n", e.message);
  383. }
  384. yield;
  385. system_daemon.disconnect (handler_id);
  386. return authorized;
  387. }
  388. public void start_save_pamac_config () {
  389. try {
  390. system_daemon.save_pamac_config_finished.connect (on_save_pamac_config_finished);
  391. system_daemon.start_save_pamac_config ();
  392. } catch (IOError e) {
  393. stderr.printf ("IOError: %s\n", e.message);
  394. system_daemon.save_pamac_config_finished.disconnect (on_save_pamac_config_finished);
  395. } catch (DBusError e) {
  396. stderr.printf ("DBusError: %s\n", e.message);
  397. system_daemon.save_pamac_config_finished.disconnect (on_save_pamac_config_finished);
  398. }
  399. }
  400. public void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf) {
  401. try {
  402. system_daemon.write_alpm_config_finished.connect (on_write_alpm_config_finished);
  403. system_daemon.start_write_alpm_config (new_alpm_conf);
  404. } catch (IOError e) {
  405. stderr.printf ("IOError: %s\n", e.message);
  406. system_daemon.write_alpm_config_finished.disconnect (on_write_alpm_config_finished);
  407. } catch (DBusError e) {
  408. stderr.printf ("DBusError: %s\n", e.message);
  409. system_daemon.write_alpm_config_finished.disconnect (on_write_alpm_config_finished);
  410. }
  411. }
  412. public void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf) {
  413. try {
  414. system_daemon.write_mirrors_config_finished.connect (on_write_mirrors_config_finished);
  415. system_daemon.start_write_mirrors_config (new_mirrors_conf);
  416. } catch (IOError e) {
  417. stderr.printf ("IOError: %s\n", e.message);
  418. system_daemon.write_mirrors_config_finished.disconnect (on_write_mirrors_config_finished);
  419. } catch (DBusError e) {
  420. stderr.printf ("DBusError: %s\n", e.message);
  421. system_daemon.write_mirrors_config_finished.disconnect (on_write_mirrors_config_finished);
  422. }
  423. }
  424. bool on_term_button_press_event (Gdk.EventButton event) {
  425. // Check if right mouse button was clicked
  426. if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == 3) {
  427. if (term.get_has_selection ()) {
  428. var right_click_menu = new Gtk.Menu ();
  429. var copy_item = new Gtk.MenuItem.with_label (dgettext (null, "Copy"));
  430. copy_item.activate.connect (() => {term.copy_clipboard ();});
  431. right_click_menu.append (copy_item);
  432. right_click_menu.show_all ();
  433. right_click_menu.popup_at_pointer (event);
  434. return true;
  435. }
  436. }
  437. return false;
  438. }
  439. bool on_term_key_press_event (Gdk.EventKey event) {
  440. // Check if Ctrl + c keys were pressed
  441. if (((event.state & Gdk.ModifierType.CONTROL_MASK) != 0) && (Gdk.keyval_name (event.keyval) == "c")) {
  442. term.copy_clipboard ();
  443. return true;
  444. }
  445. return false;
  446. }
  447. void show_in_term (string message) {
  448. term.set_pty (pty);
  449. try {
  450. Process.spawn_async (null, {"echo", message}, null, SpawnFlags.SEARCH_PATH, pty.child_setup, null);
  451. } catch (SpawnError e) {
  452. stderr.printf ("SpawnError: %s\n", e.message);
  453. }
  454. }
  455. #if DISABLE_AUR
  456. #else
  457. async int spawn_in_term (string[] args, string? working_directory = null) {
  458. SourceFunc callback = spawn_in_term.callback;
  459. int status = 1;
  460. term.set_pty (pty);
  461. var launcher = new SubprocessLauncher (SubprocessFlags.NONE);
  462. launcher.set_cwd (working_directory);
  463. launcher.set_environ (Environ.get ());
  464. launcher.set_child_setup (pty.child_setup);
  465. try {
  466. Subprocess process = launcher.spawnv (args);
  467. process.wait_async.begin (build_cancellable, (obj, res) => {
  468. try {
  469. process.wait_async.end (res);
  470. if (process.get_if_exited ()) {
  471. status = process.get_exit_status ();
  472. }
  473. } catch (Error e) {
  474. // cancelled
  475. process.send_signal (Posix.Signal.INT);
  476. process.send_signal (Posix.Signal.KILL);
  477. }
  478. Idle.add ((owned) callback);
  479. });
  480. yield;
  481. } catch (Error e) {
  482. stderr.printf ("Error: %s\n", e.message);
  483. }
  484. return status;
  485. }
  486. #endif
  487. void reset_progress_box (string action) {
  488. show_in_term (action);
  489. progress_box.action_label.label = action;
  490. stop_progressbar_pulse ();
  491. progress_box.progressbar.fraction = 0;
  492. progress_box.progressbar.text = "";
  493. }
  494. public void start_progressbar_pulse () {
  495. stop_progressbar_pulse ();
  496. pulse_timeout_id = Timeout.add (500, (GLib.SourceFunc) progress_box.progressbar.pulse);
  497. }
  498. public void stop_progressbar_pulse () {
  499. if (pulse_timeout_id != 0) {
  500. Source.remove (pulse_timeout_id);
  501. pulse_timeout_id = 0;
  502. progress_box.progressbar.fraction = 0;
  503. }
  504. }
  505. public void start_generate_mirrors_list () {
  506. string action = dgettext (null, "Refreshing mirrors list") + "...";
  507. reset_progress_box (action);
  508. start_progressbar_pulse ();
  509. important_details_outpout (false);
  510. generate_mirrors_list ();
  511. try {
  512. system_daemon.generate_mirrors_list_data.connect (on_generate_mirrors_list_data);
  513. system_daemon.generate_mirrors_list_finished.connect (on_generate_mirrors_list_finished);
  514. system_daemon.start_generate_mirrors_list ();
  515. } catch (IOError e) {
  516. stderr.printf ("IOError: %s\n", e.message);
  517. stop_progressbar_pulse ();
  518. system_daemon.generate_mirrors_list_data.disconnect (on_generate_mirrors_list_data);
  519. system_daemon.generate_mirrors_list_finished.disconnect (on_generate_mirrors_list_finished);
  520. } catch (DBusError e) {
  521. stderr.printf ("DBusError: %s\n", e.message);
  522. stop_progressbar_pulse ();
  523. system_daemon.generate_mirrors_list_data.disconnect (on_generate_mirrors_list_data);
  524. system_daemon.generate_mirrors_list_finished.disconnect (on_generate_mirrors_list_finished);
  525. }
  526. }
  527. public void clean_cache (uint64 keep_nb, bool only_uninstalled) {
  528. try {
  529. system_daemon.clean_cache (keep_nb, only_uninstalled);
  530. } catch (IOError e) {
  531. stderr.printf ("IOError: %s\n", e.message);
  532. } catch (DBusError e) {
  533. stderr.printf ("DBusError: %s\n", e.message);
  534. }
  535. }
  536. public void start_set_pkgreason (string pkgname, uint reason) {
  537. try {
  538. system_daemon.set_pkgreason_finished.connect (on_set_pkgreason_finished);
  539. system_daemon.start_set_pkgreason (pkgname, reason);
  540. } catch (IOError e) {
  541. stderr.printf ("IOError: %s\n", e.message);
  542. system_daemon.set_pkgreason_finished.disconnect (on_set_pkgreason_finished);
  543. } catch (DBusError e) {
  544. stderr.printf ("DBusError: %s\n", e.message);
  545. system_daemon.set_pkgreason_finished.disconnect (on_set_pkgreason_finished);
  546. }
  547. }
  548. public void start_refresh (bool force) {
  549. check_authorization.begin ((obj, res) => {
  550. bool authorized = check_authorization.end (res);
  551. if (authorized) {
  552. string action = dgettext (null, "Synchronizing package databases") + "...";
  553. reset_progress_box (action);
  554. connecting_system_daemon ();
  555. connecting_dbus_signals ();
  556. try {
  557. system_daemon.refresh_finished.connect (on_refresh_finished);
  558. system_daemon.start_refresh (force);
  559. } catch (IOError e) {
  560. stderr.printf ("IOError: %s\n", e.message);
  561. system_daemon.refresh_finished.disconnect (on_refresh_finished);
  562. success = false;
  563. finish_transaction ();
  564. } catch (DBusError e) {
  565. stderr.printf ("DBusError: %s\n", e.message);
  566. system_daemon.refresh_finished.disconnect (on_refresh_finished);
  567. success = false;
  568. finish_transaction ();
  569. }
  570. } else {
  571. success = false;
  572. finish_transaction ();
  573. }
  574. });
  575. }
  576. public void refresh_handle () {
  577. try {
  578. user_daemon.refresh_handle ();
  579. } catch (IOError e) {
  580. stderr.printf ("IOError: %s\n", e.message);
  581. } catch (DBusError e) {
  582. stderr.printf ("DBusError: %s\n", e.message);
  583. }
  584. }
  585. public bool get_checkspace () {
  586. bool checkspace = false;
  587. try {
  588. checkspace = user_daemon.get_checkspace ();
  589. } catch (IOError e) {
  590. stderr.printf ("IOError: %s\n", e.message);
  591. } catch (DBusError e) {
  592. stderr.printf ("DBusError: %s\n", e.message);
  593. }
  594. return checkspace;
  595. }
  596. public string[] get_ignorepkgs () {
  597. string[] ignorepkgs = {};
  598. try {
  599. ignorepkgs = user_daemon.get_ignorepkgs ();
  600. } catch (IOError e) {
  601. stderr.printf ("IOError: %s\n", e.message);
  602. } catch (DBusError e) {
  603. stderr.printf ("DBusError: %s\n", e.message);
  604. }
  605. return ignorepkgs;
  606. }
  607. public AlpmPackage get_installed_pkg (string pkgname) {
  608. try {
  609. return user_daemon.get_installed_pkg (pkgname);
  610. } catch (IOError e) {
  611. stderr.printf ("IOError: %s\n", e.message);
  612. return AlpmPackage () {
  613. name = "",
  614. version = "",
  615. desc = "",
  616. repo = ""
  617. };
  618. } catch (DBusError e) {
  619. stderr.printf ("DBusError: %s\n", e.message);
  620. return AlpmPackage () {
  621. name = "",
  622. version = "",
  623. desc = "",
  624. repo = ""
  625. };
  626. }
  627. }
  628. public AlpmPackage find_installed_satisfier (string depstring) {
  629. try {
  630. return user_daemon.find_installed_satisfier (depstring);
  631. } catch (IOError e) {
  632. stderr.printf ("IOError: %s\n", e.message);
  633. return AlpmPackage () {
  634. name = "",
  635. version = "",
  636. desc = "",
  637. repo = ""
  638. };
  639. } catch (DBusError e) {
  640. stderr.printf ("DBusError: %s\n", e.message);
  641. return AlpmPackage () {
  642. name = "",
  643. version = "",
  644. desc = "",
  645. repo = ""
  646. };
  647. }
  648. }
  649. public bool should_hold (string pkgname) {
  650. bool should_hold = false;
  651. try {
  652. should_hold = user_daemon.should_hold (pkgname);
  653. } catch (IOError e) {
  654. stderr.printf ("IOError: %s\n", e.message);
  655. } catch (DBusError e) {
  656. stderr.printf ("DBusError: %s\n", e.message);
  657. }
  658. return should_hold;
  659. }
  660. public uint get_pkg_reason (string pkgname) {
  661. uint reason = 0;
  662. try {
  663. reason = user_daemon.get_pkg_reason (pkgname);
  664. } catch (IOError e) {
  665. stderr.printf ("IOError: %s\n", e.message);
  666. } catch (DBusError e) {
  667. stderr.printf ("DBusError: %s\n", e.message);
  668. }
  669. return reason;
  670. }
  671. public uint get_pkg_origin (string pkgname) {
  672. uint origin = 0;
  673. try {
  674. origin = user_daemon.get_pkg_origin (pkgname);
  675. } catch (IOError e) {
  676. stderr.printf ("IOError: %s\n", e.message);
  677. } catch (DBusError e) {
  678. stderr.printf ("DBusError: %s\n", e.message);
  679. }
  680. return origin;
  681. }
  682. public async AlpmPackage[] get_installed_pkgs () {
  683. AlpmPackage[] pkgs = {};
  684. try {
  685. pkgs = yield user_daemon.get_installed_pkgs ();
  686. } catch (IOError e) {
  687. stderr.printf ("IOError: %s\n", e.message);
  688. } catch (DBusError e) {
  689. stderr.printf ("DBusError: %s\n", e.message);
  690. }
  691. return pkgs;
  692. }
  693. public async AlpmPackage[] get_explicitly_installed_pkgs () {
  694. AlpmPackage[] pkgs = {};
  695. try {
  696. pkgs = yield user_daemon.get_explicitly_installed_pkgs ();
  697. } catch (IOError e) {
  698. stderr.printf ("IOError: %s\n", e.message);
  699. } catch (DBusError e) {
  700. stderr.printf ("DBusError: %s\n", e.message);
  701. }
  702. return pkgs;
  703. }
  704. public async AlpmPackage[] get_foreign_pkgs () {
  705. AlpmPackage[] pkgs = {};
  706. try {
  707. pkgs = yield user_daemon.get_foreign_pkgs ();
  708. } catch (IOError e) {
  709. stderr.printf ("IOError: %s\n", e.message);
  710. } catch (DBusError e) {
  711. stderr.printf ("DBusError: %s\n", e.message);
  712. }
  713. return pkgs;
  714. }
  715. public async AlpmPackage[] get_orphans () {
  716. AlpmPackage[] pkgs = {};
  717. try {
  718. pkgs = yield user_daemon.get_orphans ();
  719. } catch (IOError e) {
  720. stderr.printf ("IOError: %s\n", e.message);
  721. } catch (DBusError e) {
  722. stderr.printf ("DBusError: %s\n", e.message);
  723. }
  724. return pkgs;
  725. }
  726. public AlpmPackage get_sync_pkg (string pkgname) {
  727. try {
  728. return user_daemon.get_sync_pkg (pkgname);
  729. } catch (IOError e) {
  730. stderr.printf ("IOError: %s\n", e.message);
  731. return AlpmPackage () {
  732. name = "",
  733. version = "",
  734. desc = "",
  735. repo = ""
  736. };
  737. } catch (DBusError e) {
  738. stderr.printf ("DBusError: %s\n", e.message);
  739. return AlpmPackage () {
  740. name = "",
  741. version = "",
  742. desc = "",
  743. repo = ""
  744. };
  745. }
  746. }
  747. public AlpmPackage find_sync_satisfier (string depstring) {
  748. try {
  749. return user_daemon.find_sync_satisfier (depstring);
  750. } catch (IOError e) {
  751. stderr.printf ("IOError: %s\n", e.message);
  752. return AlpmPackage () {
  753. name = "",
  754. version = "",
  755. desc = "",
  756. repo = ""
  757. };
  758. } catch (DBusError e) {
  759. stderr.printf ("DBusError: %s\n", e.message);
  760. return AlpmPackage () {
  761. name = "",
  762. version = "",
  763. desc = "",
  764. repo = ""
  765. };
  766. }
  767. }
  768. public async AlpmPackage[] search_pkgs (string search_string) {
  769. AlpmPackage[] pkgs = {};
  770. try {
  771. pkgs = yield user_daemon.search_pkgs (search_string);
  772. } catch (IOError e) {
  773. stderr.printf ("IOError: %s\n", e.message);
  774. } catch (DBusError e) {
  775. stderr.printf ("DBusError: %s\n", e.message);
  776. }
  777. return pkgs;
  778. }
  779. #if DISABLE_AUR
  780. #else
  781. public async AURPackage[] search_in_aur (string search_string) {
  782. AURPackage[] pkgs = {};
  783. try {
  784. pkgs = yield user_daemon.search_in_aur (search_string);
  785. } catch (IOError e) {
  786. stderr.printf ("IOError: %s\n", e.message);
  787. } catch (DBusError e) {
  788. stderr.printf ("DBusError: %s\n", e.message);
  789. }
  790. return pkgs;
  791. }
  792. #endif
  793. public string[] get_repos_names () {
  794. string[] repos_names = {};
  795. try {
  796. repos_names = user_daemon.get_repos_names ();
  797. } catch (IOError e) {
  798. stderr.printf ("IOError: %s\n", e.message);
  799. } catch (DBusError e) {
  800. stderr.printf ("DBusError: %s\n", e.message);
  801. }
  802. return repos_names;
  803. }
  804. public async AlpmPackage[] get_repo_pkgs (string repo) {
  805. AlpmPackage[] pkgs = {};
  806. try {
  807. pkgs = yield user_daemon.get_repo_pkgs (repo);
  808. } catch (IOError e) {
  809. stderr.printf ("IOError: %s\n", e.message);
  810. } catch (DBusError e) {
  811. stderr.printf ("DBusError: %s\n", e.message);
  812. }
  813. return pkgs;
  814. }
  815. public string[] get_groups_names () {
  816. string[] groups_names = {};
  817. try {
  818. groups_names = user_daemon.get_groups_names ();
  819. } catch (IOError e) {
  820. stderr.printf ("IOError: %s\n", e.message);
  821. } catch (DBusError e) {
  822. stderr.printf ("DBusError: %s\n", e.message);
  823. }
  824. return groups_names;
  825. }
  826. public async AlpmPackage[] get_group_pkgs (string group_name) {
  827. AlpmPackage[] pkgs = {};
  828. try {
  829. pkgs = yield user_daemon.get_group_pkgs (group_name);
  830. } catch (IOError e) {
  831. stderr.printf ("IOError: %s\n", e.message);
  832. } catch (DBusError e) {
  833. stderr.printf ("DBusError: %s\n", e.message);
  834. }
  835. return pkgs;
  836. }
  837. public string[] get_pkg_uninstalled_optdeps (string pkgname) {
  838. string[] optdeps = {};
  839. try {
  840. optdeps = user_daemon.get_pkg_uninstalled_optdeps (pkgname);
  841. } catch (IOError e) {
  842. stderr.printf ("IOError: %s\n", e.message);
  843. } catch (DBusError e) {
  844. stderr.printf ("DBusError: %s\n", e.message);
  845. }
  846. return optdeps;
  847. }
  848. public AlpmPackageDetails get_pkg_details (string pkgname) {
  849. try {
  850. return user_daemon.get_pkg_details (pkgname);
  851. } catch (IOError e) {
  852. stderr.printf ("IOError: %s\n", e.message);
  853. return AlpmPackageDetails () {
  854. name = "",
  855. version = "",
  856. desc = "",
  857. repo = "",
  858. url = "",
  859. packager = "",
  860. builddate = "",
  861. installdate = "",
  862. reason = "",
  863. has_signature = "",
  864. downloadsize = "",
  865. installsize = ""
  866. };
  867. } catch (DBusError e) {
  868. stderr.printf ("DBusError: %s\n", e.message);
  869. return AlpmPackageDetails () {
  870. name = "",
  871. version = "",
  872. desc = "",
  873. repo = "",
  874. url = "",
  875. packager = "",
  876. builddate = "",
  877. installdate = "",
  878. reason = "",
  879. has_signature = "",
  880. downloadsize = "",
  881. installsize = ""
  882. };
  883. }
  884. }
  885. public string[] get_pkg_files (string pkgname) {
  886. try {
  887. return user_daemon.get_pkg_files (pkgname);
  888. } catch (IOError e) {
  889. stderr.printf ("IOError: %s\n", e.message);
  890. return {};
  891. } catch (DBusError e) {
  892. stderr.printf ("DBusError: %s\n", e.message);
  893. return {};
  894. }
  895. }
  896. #if DISABLE_AUR
  897. #else
  898. public async AURPackageDetails get_aur_details (string pkgname) {
  899. var pkg = AURPackageDetails () {
  900. name = "",
  901. version = "",
  902. desc = "",
  903. packagebase = "",
  904. url = "",
  905. maintainer = ""
  906. };
  907. try {
  908. pkg = yield user_daemon.get_aur_details (pkgname);
  909. } catch (IOError e) {
  910. stderr.printf ("IOError: %s\n", e.message);
  911. } catch (DBusError e) {
  912. stderr.printf ("DBusError: %s\n", e.message);
  913. }
  914. return pkg;
  915. }
  916. #endif
  917. public void start_get_updates () {
  918. user_daemon.get_updates_finished.connect (on_get_updates_finished);
  919. try {
  920. #if DISABLE_AUR
  921. user_daemon.start_get_updates ();
  922. #else
  923. user_daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates);
  924. #endif
  925. } catch (IOError e) {
  926. stderr.printf ("IOError: %s\n", e.message);
  927. success = false;
  928. finish_transaction ();
  929. } catch (DBusError e) {
  930. stderr.printf ("DBusError: %s\n", e.message);
  931. success = false;
  932. finish_transaction ();
  933. }
  934. }
  935. void start_get_updates_for_sysupgrade () {
  936. system_daemon.get_updates_finished.connect (on_get_updates_for_sysupgrade_finished);
  937. try {
  938. #if DISABLE_AUR
  939. system_daemon.start_get_updates ();
  940. #else
  941. system_daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates);
  942. #endif
  943. } catch (IOError e) {
  944. stderr.printf ("IOError: %s\n", e.message);
  945. success = false;
  946. finish_transaction ();
  947. } catch (DBusError e) {
  948. stderr.printf ("DBusError: %s\n", e.message);
  949. success = false;
  950. finish_transaction ();
  951. }
  952. }
  953. void sysupgrade_simple (bool enable_downgrade) {
  954. progress_box.progressbar.fraction = 0;
  955. string[] temporary_ignorepkgs_ = {};
  956. foreach (unowned string pkgname in temporary_ignorepkgs) {
  957. temporary_ignorepkgs_ += pkgname;
  958. }
  959. connecting_system_daemon ();
  960. connecting_dbus_signals ();
  961. try {
  962. // this will respond with trans_prepare_finished signal
  963. system_daemon.start_sysupgrade_prepare (enable_downgrade, temporary_ignorepkgs_);
  964. } catch (IOError e) {
  965. stderr.printf ("IOError: %s\n", e.message);
  966. success = false;
  967. finish_transaction ();
  968. } catch (DBusError e) {
  969. stderr.printf ("DBusError: %s\n", e.message);
  970. success = false;
  971. finish_transaction ();
  972. }
  973. }
  974. public void sysupgrade (bool enable_downgrade) {
  975. this.enable_downgrade = enable_downgrade;
  976. string action = dgettext (null, "Starting full system upgrade") + "...";
  977. reset_progress_box (action);
  978. start_get_updates_for_sysupgrade ();
  979. }
  980. void on_get_updates_finished (Updates updates) {
  981. user_daemon.get_updates_finished.disconnect (on_get_updates_finished);
  982. get_updates_finished (updates);
  983. }
  984. void on_get_updates_for_sysupgrade_finished (Updates updates) {
  985. system_daemon.get_updates_finished.disconnect (on_get_updates_for_sysupgrade_finished);
  986. // get syncfirst updates
  987. if (updates.is_syncfirst) {
  988. clear_lists ();
  989. sysupgrade_after_trans = true;
  990. no_confirm_commit = true;
  991. foreach (unowned AlpmPackage infos in updates.repos_updates) {
  992. to_install.add (infos.name);
  993. }
  994. // run as a standard transaction
  995. run ();
  996. } else {
  997. #if DISABLE_AUR
  998. if (updates.repos_updates.length != 0) {
  999. sysupgrade_simple (enable_downgrade);
  1000. } else {
  1001. finish_transaction ();
  1002. stop_progressbar_pulse ();
  1003. }
  1004. #else
  1005. if (updates.aur_updates.length != 0) {
  1006. clear_lists ();
  1007. foreach (unowned AURPackage infos in updates.aur_updates) {
  1008. if (!(infos.name in temporary_ignorepkgs)) {
  1009. to_build.add (infos.name);
  1010. }
  1011. }
  1012. if (updates.repos_updates.length != 0) {
  1013. build_after_sysupgrade = true;
  1014. sysupgrade_simple (enable_downgrade);
  1015. } else {
  1016. // only aur updates
  1017. // run as a standard transaction
  1018. run ();
  1019. }
  1020. } else {
  1021. if (updates.repos_updates.length != 0) {
  1022. sysupgrade_simple (enable_downgrade);
  1023. } else {
  1024. finish_transaction ();
  1025. stop_progressbar_pulse ();
  1026. }
  1027. }
  1028. #endif
  1029. }
  1030. }
  1031. public void clear_lists () {
  1032. to_install.remove_all ();
  1033. to_remove.remove_all ();
  1034. #if DISABLE_AUR
  1035. #else
  1036. to_build.remove_all ();
  1037. #endif
  1038. to_load.remove_all ();
  1039. }
  1040. void clear_previous_lists () {
  1041. previous_to_install.remove_all ();
  1042. previous_to_remove.remove_all ();
  1043. }
  1044. #if DISABLE_AUR
  1045. void start_trans_prepare (int transflags, string[] to_install, string[] to_remove, string[] to_load) {
  1046. try {
  1047. system_daemon.start_trans_prepare (transflags, to_install, to_remove, to_load);
  1048. #else
  1049. void start_trans_prepare (int transflags, string[] to_install, string[] to_remove, string[] to_load, string[] to_build) {
  1050. try {
  1051. system_daemon.start_trans_prepare (transflags, to_install, to_remove, to_load, to_build);
  1052. #endif
  1053. } catch (IOError e) {
  1054. stderr.printf ("IOError: %s\n", e.message);
  1055. stop_progressbar_pulse ();
  1056. success = false;
  1057. finish_transaction ();
  1058. } catch (DBusError e) {
  1059. stderr.printf ("DBusError: %s\n", e.message);
  1060. stop_progressbar_pulse ();
  1061. success = false;
  1062. finish_transaction ();
  1063. }
  1064. }
  1065. public void run () {
  1066. string action = dgettext (null, "Preparing") + "...";
  1067. reset_progress_box (action);
  1068. start_progressbar_pulse ();
  1069. string[] to_install_ = {};
  1070. string[] to_remove_ = {};
  1071. string[] to_load_ = {};
  1072. #if DISABLE_AUR
  1073. #else
  1074. string[] to_build_ = {};
  1075. #endif
  1076. foreach (unowned string name in to_install) {
  1077. to_install_ += name;
  1078. }
  1079. foreach (unowned string name in to_remove) {
  1080. to_remove_ += name;
  1081. }
  1082. foreach (unowned string path in to_load) {
  1083. to_load_ += path;
  1084. }
  1085. #if DISABLE_AUR
  1086. #else
  1087. foreach (unowned string name in to_build) {
  1088. to_build_ += name;
  1089. }
  1090. #endif
  1091. connecting_system_daemon ();
  1092. connecting_dbus_signals ();
  1093. #if DISABLE_AUR
  1094. start_trans_prepare (flags, to_install_, to_remove_, to_load_);
  1095. #else
  1096. start_trans_prepare (flags, to_install_, to_remove_, to_load_, to_build_);
  1097. #endif
  1098. }
  1099. void choose_provider (string depend, string[] providers) {
  1100. var choose_provider_dialog = new ChooseProviderDialog (application_window);
  1101. choose_provider_dialog.title = dgettext (null, "Choose a provider for %s").printf (depend);
  1102. unowned Gtk.Box box = choose_provider_dialog.get_content_area ();
  1103. Gtk.RadioButton? last_radiobutton = null;
  1104. Gtk.RadioButton? first_radiobutton = null;
  1105. foreach (unowned string provider in providers) {
  1106. var radiobutton = new Gtk.RadioButton.with_label_from_widget (last_radiobutton, provider);
  1107. radiobutton.visible = true;
  1108. // active first provider
  1109. if (last_radiobutton == null) {
  1110. radiobutton.active = true;
  1111. first_radiobutton = radiobutton;
  1112. }
  1113. last_radiobutton = radiobutton;
  1114. box.add (radiobutton);
  1115. }
  1116. choose_provider_dialog.run ();
  1117. // get active provider
  1118. int index = 0;
  1119. // list is given in reverse order so reverse it !
  1120. SList<unowned Gtk.RadioButton> list = last_radiobutton.get_group ().copy ();
  1121. list.reverse ();
  1122. foreach (var radiobutton in list) {
  1123. if (radiobutton.active) {
  1124. try {
  1125. system_daemon.choose_provider (index);
  1126. } catch (IOError e) {
  1127. stderr.printf ("IOError: %s\n", e.message);
  1128. } catch (DBusError e) {
  1129. stderr.printf ("DBusError: %s\n", e.message);
  1130. }
  1131. }
  1132. index++;
  1133. }
  1134. choose_provider_dialog.destroy ();
  1135. while (Gtk.events_pending ()) {
  1136. Gtk.main_iteration ();
  1137. }
  1138. }
  1139. Type set_transaction_sum () {
  1140. // return 0 if transaction_sum is empty, 2, if there are only aur updates, 1 otherwise
  1141. Type type = 0;
  1142. uint64 dsize = 0;
  1143. transaction_summary.remove_all ();
  1144. var summary = TransactionSummary ();
  1145. transaction_sum_dialog.sum_list.clear ();
  1146. try {
  1147. summary = system_daemon.get_transaction_summary ();
  1148. } catch (IOError e) {
  1149. stderr.printf ("IOError: %s\n", e.message);
  1150. } catch (DBusError e) {
  1151. stderr.printf ("DBusError: %s\n", e.message);
  1152. }
  1153. var iter = Gtk.TreeIter ();
  1154. if (summary.to_remove.length > 0) {
  1155. type |= Type.STANDARD;
  1156. foreach (unowned UpdateInfos infos in summary.to_remove) {
  1157. transaction_summary.add (infos.name);
  1158. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  1159. 1, infos.name,
  1160. 2, infos.old_version);
  1161. }
  1162. Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
  1163. int pos = (path.get_indices ()[0]) - (summary.to_remove.length - 1);
  1164. transaction_sum_dialog.sum_list.get_iter (out iter, new Gtk.TreePath.from_indices (pos));
  1165. transaction_sum_dialog.sum_list.set (iter, 0, "<b>%s</b>".printf (dgettext (null, "To remove") + ":"));
  1166. }
  1167. #if DISABLE_AUR
  1168. #else
  1169. if (summary.aur_conflicts_to_remove.length > 0) {
  1170. // do not add type enum because it is just infos
  1171. foreach (unowned UpdateInfos infos in summary.aur_conflicts_to_remove) {
  1172. transaction_summary.add (infos.name);
  1173. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  1174. 1, infos.name,
  1175. 2, infos.old_version);
  1176. }
  1177. Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
  1178. int pos = (path.get_indices ()[0]) - (summary.aur_conflicts_to_remove.length - 1);
  1179. transaction_sum_dialog.sum_list.get_iter (out iter, new Gtk.TreePath.from_indices (pos));
  1180. transaction_sum_dialog.sum_list.set (iter, 0, "<b>%s</b>".printf (dgettext (null, "To remove") + ":"));
  1181. }
  1182. #endif
  1183. if (summary.to_downgrade.length > 0) {
  1184. type |= Type.STANDARD;
  1185. foreach (unowned UpdateInfos infos in summary.to_downgrade) {
  1186. dsize += infos.download_size;
  1187. transaction_summary.add (infos.name);
  1188. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  1189. 1, infos.name,
  1190. 2, infos.new_version,
  1191. 3, "(%s)".printf (infos.old_version));
  1192. }
  1193. Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
  1194. int pos = (path.get_indices ()[0]) - (summary.to_downgrade.length - 1);
  1195. transaction_sum_dialog.sum_list.get_iter (out iter, new Gtk.TreePath.from_indices (pos));
  1196. transaction_sum_dialog.sum_list.set (iter, 0, "<b>%s</b>".printf (dgettext (null, "To downgrade") + ":"));
  1197. }
  1198. #if DISABLE_AUR
  1199. #else
  1200. if (summary.to_build.length > 0) {
  1201. type |= Type.BUILD;
  1202. // populate build queue
  1203. foreach (unowned string name in summary.aur_pkgbases_to_build) {
  1204. to_build_queue.push_tail (name);
  1205. }
  1206. aur_pkgs_to_install = {};
  1207. foreach (unowned UpdateInfos infos in summary.to_build) {
  1208. aur_pkgs_to_install += infos.name;
  1209. transaction_summary.add (infos.name);
  1210. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  1211. 1, infos.name,
  1212. 2, infos.new_version);
  1213. }
  1214. Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
  1215. int pos = (path.get_indices ()[0]) - (summary.to_build.length - 1);
  1216. transaction_sum_dialog.sum_list.get_iter (out iter, new Gtk.TreePath.from_indices (pos));
  1217. transaction_sum_dialog.sum_list.set (iter, 0, "<b>%s</b>".printf (dgettext (null, "To build") + ":"));
  1218. }
  1219. #endif
  1220. if (summary.to_install.length > 0) {
  1221. type |= Type.STANDARD;
  1222. foreach (unowned UpdateInfos infos in summary.to_install) {
  1223. dsize += infos.download_size;
  1224. transaction_summary.add (infos.name);
  1225. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  1226. 1, infos.name,
  1227. 2, infos.new_version);
  1228. }
  1229. Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
  1230. int pos = (path.get_indices ()[0]) - (summary.to_install.length - 1);
  1231. transaction_sum_dialog.sum_list.get_iter (out iter, new Gtk.TreePath.from_indices (pos));
  1232. transaction_sum_dialog.sum_list.set (iter, 0, "<b>%s</b>".printf (dgettext (null, "To install") + ":"));
  1233. }
  1234. if (summary.to_reinstall.length > 0) {
  1235. type |= Type.STANDARD;
  1236. foreach (unowned UpdateInfos infos in summary.to_reinstall) {
  1237. dsize += infos.download_size;
  1238. transaction_summary.add (infos.name);
  1239. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  1240. 1, infos.name,
  1241. 2, infos.old_version);
  1242. }
  1243. Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
  1244. int pos = (path.get_indices ()[0]) - (summary.to_reinstall.length - 1);
  1245. transaction_sum_dialog.sum_list.get_iter (out iter, new Gtk.TreePath.from_indices (pos));
  1246. transaction_sum_dialog.sum_list.set (iter, 0, "<b>%s</b>".printf (dgettext (null, "To reinstall") + ":"));
  1247. }
  1248. if (summary.to_upgrade.length > 0) {
  1249. type |= Type.UPDATE;
  1250. if (mode == Mode.INSTALLER) {
  1251. foreach (unowned UpdateInfos infos in summary.to_upgrade) {
  1252. dsize += infos.download_size;
  1253. transaction_summary.add (infos.name);
  1254. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  1255. 1, infos.name,
  1256. 2, infos.new_version,
  1257. 3, "(%s)".printf (infos.old_version));
  1258. }
  1259. Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
  1260. int pos = (path.get_indices ()[0]) - (summary.to_upgrade.length - 1);
  1261. transaction_sum_dialog.sum_list.get_iter (out iter, new Gtk.TreePath.from_indices (pos));
  1262. transaction_sum_dialog.sum_list.set (iter, 0, "<b>%s</b>".printf (dgettext (null, "To upgrade") + ":"));
  1263. }
  1264. }
  1265. if (dsize == 0) {
  1266. transaction_sum_dialog.top_label.visible = false;
  1267. } else {
  1268. transaction_sum_dialog.top_label.set_markup ("<b>%s: %s</b>".printf (dgettext (null, "Total download size"), format_size (dsize)));
  1269. transaction_sum_dialog.top_label.visible = true;
  1270. }
  1271. return type;
  1272. }
  1273. void start_commit () {
  1274. try {
  1275. system_daemon.start_trans_commit ();
  1276. } catch (IOError e) {
  1277. stderr.printf ("IOError: %s\n", e.message);
  1278. success = false;
  1279. finish_transaction ();
  1280. } catch (DBusError e) {
  1281. stderr.printf ("DBusError: %s\n", e.message);
  1282. success = false;
  1283. finish_transaction ();
  1284. }
  1285. }
  1286. #if DISABLE_AUR
  1287. #else
  1288. async void build_aur_packages () {
  1289. string pkgname = to_build_queue.pop_head ();
  1290. string action = dgettext (null, "Building %s").printf (pkgname) + "...";
  1291. reset_progress_box (action);
  1292. build_cancellable.reset ();
  1293. start_progressbar_pulse ();
  1294. important_details_outpout (false);
  1295. to_build.remove_all ();
  1296. string [] built_pkgs = {};
  1297. int status = 1;
  1298. string builddir;
  1299. if (aur_build_dir == "/tmp") {
  1300. builddir = "/tmp/pamac-build-%s".printf (Environment.get_user_name ());
  1301. } else {
  1302. builddir = aur_build_dir;
  1303. }
  1304. status = yield spawn_in_term ({"mkdir", "-p", builddir});
  1305. if (status == 0) {
  1306. status = yield spawn_in_term ({"rm", "-rf", pkgname}, builddir);
  1307. if (!build_cancellable.is_cancelled ()) {
  1308. if (status == 0) {
  1309. building = true;
  1310. start_building ();
  1311. status = yield spawn_in_term ({"git", "clone", "https://aur.archlinux.org/%s.git".printf (pkgname)}, builddir);
  1312. if (status == 0) {
  1313. string pkgdir = "%s/%s".printf (builddir, pkgname);
  1314. status = yield spawn_in_term ({"makepkg", "-c"}, pkgdir);
  1315. building = false;
  1316. if (status == 0) {
  1317. foreach (unowned string aurpkg in aur_pkgs_to_install) {
  1318. string standard_output;
  1319. try {
  1320. Process.spawn_command_line_sync ("find %s -name %s".printf (pkgdir, "'%s-*.pkg.tar*'".printf (aurpkg)),
  1321. out standard_output,
  1322. null,
  1323. out status);
  1324. if (status == 0) {
  1325. foreach (unowned string path in standard_output.split ("\n")) {
  1326. if (path != "" && !(path in built_pkgs)) {
  1327. built_pkgs += path;
  1328. }
  1329. }
  1330. }
  1331. } catch (SpawnError e) {
  1332. stderr.printf ("SpawnError: %s\n", e.message);
  1333. status = 1;
  1334. }
  1335. }
  1336. }
  1337. }
  1338. stop_building ();
  1339. }
  1340. } else {
  1341. status = 1;
  1342. }
  1343. }
  1344. building = false;
  1345. if (status == 0) {
  1346. if (built_pkgs.length > 0) {
  1347. no_confirm_commit = true;
  1348. show_in_term ("");
  1349. stop_progressbar_pulse ();
  1350. start_trans_prepare (flags, {}, {}, built_pkgs, {});
  1351. }
  1352. } else {
  1353. important_details_outpout (true);
  1354. to_load.remove_all ();
  1355. to_build_queue.clear ();
  1356. stop_progressbar_pulse ();
  1357. success = false;
  1358. finish_transaction ();
  1359. }
  1360. }
  1361. #endif
  1362. public void cancel () {
  1363. #if DISABLE_AUR
  1364. #else
  1365. if (building) {
  1366. build_cancellable.cancel ();
  1367. } else {
  1368. #endif
  1369. try {
  1370. system_daemon.trans_cancel ();
  1371. } catch (IOError e) {
  1372. stderr.printf ("IOError: %s\n", e.message);
  1373. } catch (DBusError e) {
  1374. stderr.printf ("DBusError: %s\n", e.message);
  1375. }
  1376. #if DISABLE_AUR
  1377. #else
  1378. }
  1379. #endif
  1380. show_in_term ("\n" + dgettext (null, "Transaction cancelled") + ".\n");
  1381. progress_box.action_label.label = "";
  1382. warning_textbuffer = new StringBuilder ();
  1383. }
  1384. public void release () {
  1385. try {
  1386. system_daemon.trans_release ();
  1387. } catch (IOError e) {
  1388. stderr.printf ("IOError: %s\n", e.message);
  1389. } catch (DBusError e) {
  1390. stderr.printf ("DBusError: %s\n", e.message);
  1391. }
  1392. warning_textbuffer = new StringBuilder ();
  1393. }
  1394. public void stop_daemon () {
  1395. try {
  1396. user_daemon.quit ();
  1397. if (system_daemon != null) {
  1398. system_daemon.quit ();
  1399. }
  1400. } catch (IOError e) {
  1401. stderr.printf ("IOError: %s\n", e.message);
  1402. } catch (DBusError e) {
  1403. stderr.printf ("DBusError: %s\n", e.message);
  1404. }
  1405. }
  1406. void on_emit_event (uint primary_event, uint secondary_event, string[] details) {
  1407. string? action = null;
  1408. string? detailed_action = null;
  1409. switch (primary_event) {
  1410. case Alpm.Event.Type.CHECKDEPS_START:
  1411. action = dgettext (null, "Checking dependencies") + "...";
  1412. break;
  1413. case Alpm.Event.Type.FILECONFLICTS_START:
  1414. action = dgettext (null, "Checking file conflicts") + "...";
  1415. break;
  1416. case Alpm.Event.Type.RESOLVEDEPS_START:
  1417. action = dgettext (null, "Resolving dependencies") + "...";
  1418. break;
  1419. case Alpm.Event.Type.INTERCONFLICTS_START:
  1420. action = dgettext (null, "Checking inter-conflicts") + "...";
  1421. break;
  1422. case Alpm.Event.Type.PACKAGE_OPERATION_START:
  1423. switch (secondary_event) {
  1424. // special case handle differently
  1425. case Alpm.Package.Operation.INSTALL:
  1426. previous_filename = details[0];
  1427. string msg = dgettext (null, "Installing %s").printf (details[0]) + "...";
  1428. progress_box.action_label.label = msg;
  1429. show_in_term (dgettext (null, "Installing %s").printf ("%s (%s)".printf (details[0], details[1])) + "...");
  1430. break;
  1431. case Alpm.Package.Operation.UPGRADE:
  1432. previous_filename = details[0];
  1433. string msg = dgettext (null, "Upgrading %s").printf (details[0]) + "...";
  1434. progress_box.action_label.label = msg;
  1435. show_in_term (dgettext (null, "Upgrading %s").printf ("%s (%s -> %s)".printf (details[0], details[1], details[2])) + "...");
  1436. break;
  1437. case Alpm.Package.Operation.REINSTALL:
  1438. previous_filename = details[0];
  1439. string msg = dgettext (null, "Reinstalling %s").printf (details[0]) + "...";
  1440. progress_box.action_label.label = msg;
  1441. show_in_term (dgettext (null, "Reinstalling %s").printf ("%s (%s)".printf (details[0], details[1])) + "...");
  1442. break;
  1443. case Alpm.Package.Operation.DOWNGRADE:
  1444. previous_filename = details[0];
  1445. string msg = dgettext (null, "Downgrading %s").printf (details[0]) + "...";
  1446. progress_box.action_label.label = msg;
  1447. show_in_term (dgettext (null, "Downgrading %s").printf ("%s (%s -> %s)".printf (details[0], details[1], details[2])) + "...");
  1448. break;
  1449. case Alpm.Package.Operation.REMOVE:
  1450. previous_filename = details[0];
  1451. string msg = dgettext (null, "Removing %s").printf (details[0]) + "...";
  1452. progress_box.action_label.label = msg;
  1453. show_in_term (dgettext (null, "Removing %s").printf ("%s (%s)".printf (details[0], details[1])) + "...");
  1454. break;
  1455. }
  1456. break;
  1457. case Alpm.Event.Type.INTEGRITY_START:
  1458. action = dgettext (null, "Checking integrity") + "...";
  1459. break;
  1460. case Alpm.Event.Type.LOAD_START:
  1461. action = dgettext (null, "Loading packages files") + "...";
  1462. break;
  1463. case Alpm.Event.Type.SCRIPTLET_INFO:
  1464. // hooks output are also emitted as SCRIPTLET_INFO
  1465. if (previous_filename != "") {
  1466. progress_box.action_label.label = dgettext (null, "Configuring %s").printf (previous_filename) + "...";
  1467. }
  1468. detailed_action = details[0].replace ("\n", "");
  1469. important_details_outpout (false);
  1470. break;
  1471. case Alpm.Event.Type.RETRIEVE_START:
  1472. start_downloading ();
  1473. action = dgettext (null, "Downloading") + "...";
  1474. break;
  1475. case Alpm.Event.Type.RETRIEVE_DONE:
  1476. case Alpm.Event.Type.RETRIEVE_FAILED:
  1477. stop_downloading ();
  1478. break;
  1479. case Alpm.Event.Type.PKGDOWNLOAD_START:
  1480. // special case handle differently
  1481. show_in_term (dgettext (null, "Downloading %s").printf (details[0]) + "...");
  1482. string name_version_release = details[0].slice (0, details[0].last_index_of_char ('-'));
  1483. string name_version = name_version_release.slice (0, name_version_release.last_index_of_char ('-'));
  1484. string name = name_version.slice (0, name_version.last_index_of_char ('-'));
  1485. progress_box.action_label.label = dgettext (null, "Downloading %s").printf (name) + "...";
  1486. break;
  1487. case Alpm.Event.Type.DISKSPACE_START:
  1488. action = dgettext (null, "Checking available disk space") + "...";
  1489. break;
  1490. case Alpm.Event.Type.OPTDEP_REMOVAL:
  1491. detailed_action = dgettext (null, "%s optionally requires %s").printf (details[0], details[1]);
  1492. warning_textbuffer.append (detailed_action + "\n");
  1493. break;
  1494. case Alpm.Event.Type.DATABASE_MISSING:
  1495. detailed_action = dgettext (null, "Database file for %s does not exist").printf (details[0]);
  1496. break;
  1497. case Alpm.Event.Type.KEYRING_START:
  1498. action = dgettext (null, "Checking keyring") + "...";
  1499. break;
  1500. case Alpm.Event.Type.KEY_DOWNLOAD_START:
  1501. action = dgettext (null, "Downloading required keys") + "...";
  1502. break;
  1503. case Alpm.Event.Type.PACNEW_CREATED:
  1504. detailed_action = dgettext (null, "%s installed as %s.pacnew").printf (details[0], details[0]);
  1505. break;
  1506. case Alpm.Event.Type.PACSAVE_CREATED:
  1507. detailed_action = dgettext (null, "%s installed as %s.pacsave").printf (details[0], details[0]);
  1508. break;
  1509. case Alpm.Event.Type.HOOK_START:
  1510. switch (secondary_event) {
  1511. case Alpm.HookWhen.PRE_TRANSACTION:
  1512. action = dgettext (null, "Running pre-transaction hooks") + "...";
  1513. break;
  1514. case Alpm.HookWhen.POST_TRANSACTION:
  1515. previous_filename = "";
  1516. action = dgettext (null, "Running post-transaction hooks") + "...";
  1517. break;
  1518. default:
  1519. break;
  1520. }
  1521. break;
  1522. case Alpm.Event.Type.HOOK_RUN_START:
  1523. float fraction = (float) int.parse (details[2]) / int.parse (details[3]);
  1524. if (fraction != previous_percent) {
  1525. previous_percent = fraction;
  1526. progress_box.progressbar.fraction = fraction;
  1527. }
  1528. string textbar = "%s/%s".printf (details[2], details[3]);
  1529. if (textbar != previous_textbar) {
  1530. previous_textbar = textbar;
  1531. progress_box.progressbar.text = textbar;
  1532. }
  1533. if (details[1] != "") {
  1534. detailed_action = details[1];
  1535. } else {
  1536. detailed_action = details[0];
  1537. }
  1538. break;
  1539. default:
  1540. break;
  1541. }
  1542. if (action != null) {
  1543. progress_box.action_label.label = action;
  1544. show_in_term (action);
  1545. }
  1546. if (detailed_action != null) {
  1547. show_in_term (detailed_action);
  1548. }
  1549. }
  1550. void on_emit_providers (string depend, string[] providers) {
  1551. choose_provider (depend, providers);
  1552. }
  1553. void on_emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target) {
  1554. float fraction;
  1555. switch (progress) {
  1556. case Alpm.Progress.ADD_START:
  1557. case Alpm.Progress.UPGRADE_START:
  1558. case Alpm.Progress.DOWNGRADE_START:
  1559. case Alpm.Progress.REINSTALL_START:
  1560. case Alpm.Progress.REMOVE_START:
  1561. fraction = ((float) (current_target - 1) / n_targets) + ((float) percent / (100 * n_targets));
  1562. break;
  1563. case Alpm.Progress.CONFLICTS_START:
  1564. case Alpm.Progress.DISKSPACE_START:
  1565. case Alpm.Progress.INTEGRITY_START:
  1566. case Alpm.Progress.LOAD_START:
  1567. case Alpm.Progress.KEYRING_START:
  1568. default:
  1569. fraction = (float) percent / 100;
  1570. break;
  1571. }
  1572. string textbar = "%lu/%lu".printf (current_target, n_targets);
  1573. if (textbar != previous_textbar) {
  1574. previous_textbar = textbar;
  1575. progress_box.progressbar.text = textbar;
  1576. }
  1577. if (fraction != previous_percent) {
  1578. previous_percent = fraction;
  1579. progress_box.progressbar.fraction = fraction;
  1580. }
  1581. }
  1582. void on_emit_download (string filename, uint64 xfered, uint64 total) {
  1583. var text = new StringBuilder ();
  1584. float fraction;
  1585. if (total_download > 0) {
  1586. if (xfered == 0) {
  1587. // start download pkg is handled by Alpm.Event.Type.PKGDOWNLOAD_START
  1588. previous_xfered = 0;
  1589. fraction = previous_percent;
  1590. text.append (previous_textbar);
  1591. timer.start ();
  1592. } else {
  1593. if (timer.elapsed () > 0.1) {
  1594. download_rate = ((download_rate * rates_nb) + (uint64) ((xfered - previous_xfered) / timer.elapsed ())) / (rates_nb + 1);
  1595. rates_nb++;
  1596. }
  1597. previous_xfered = xfered;
  1598. uint64 downloaded_total = xfered + already_downloaded;
  1599. fraction = (float) downloaded_total / total_download;
  1600. if (fraction <= 1) {
  1601. text.append ("%s/%s ".printf (format_size (xfered + already_downloaded), format_size (total_download)));
  1602. uint64 remaining_seconds = 0;
  1603. if (download_rate > 0) {
  1604. remaining_seconds = (total_download - downloaded_total) / download_rate;
  1605. }
  1606. // display remaining time after 5s and only if more than 10s are remaining
  1607. if (remaining_seconds > 9 && rates_nb > 9) {
  1608. if (remaining_seconds <= 50) {
  1609. text.append (dgettext (null, "About %u seconds remaining").printf ((uint) Math.ceilf ((float) remaining_seconds / 10) * 10));
  1610. } else {
  1611. uint remaining_minutes = (uint) Math.ceilf ((float) remaining_seconds / 60);
  1612. text.append (dngettext (null, "About %lu minute remaining",
  1613. "About %lu minutes remaining", remaining_minutes).printf (remaining_minutes));
  1614. }
  1615. }
  1616. } else {
  1617. text.append ("%s".printf (format_size (xfered + already_downloaded)));
  1618. }
  1619. if (xfered == total) {
  1620. previous_filename = "";
  1621. already_downloaded += total;
  1622. } else {
  1623. timer.start ();
  1624. }
  1625. }
  1626. } else {
  1627. if (xfered == 0) {
  1628. previous_xfered = 0;
  1629. download_rate = 0;
  1630. rates_nb = 0;
  1631. fraction = 0;
  1632. timer.start ();
  1633. if (filename.has_suffix (".db") || filename.has_suffix (".files")) {
  1634. string action = dgettext (null, "Refreshing %s").printf (filename) + "...";
  1635. reset_progress_box (action);
  1636. }
  1637. } else if (xfered == total) {
  1638. timer.stop ();
  1639. fraction = 1;
  1640. previous_filename = "";
  1641. } else {
  1642. if (timer.elapsed () > 0.1) {
  1643. download_rate = ((download_rate * rates_nb) + (uint64) ((xfered - previous_xfered) / timer.elapsed ())) / (rates_nb + 1);
  1644. rates_nb++;
  1645. }
  1646. previous_xfered = xfered;
  1647. fraction = (float) xfered / total;
  1648. if (fraction <= 1) {
  1649. text.append ("%s/%s ".printf (format_size (xfered), format_size (total)));
  1650. uint64 remaining_seconds = 0;
  1651. if (download_rate > 0) {
  1652. remaining_seconds = (total - xfered) / download_rate;
  1653. }
  1654. // display remaining time after 5s and only if more than 10s are remaining
  1655. if (remaining_seconds > 9 && rates_nb > 9) {
  1656. if (remaining_seconds <= 50) {
  1657. text.append (dgettext (null, "About %u seconds remaining").printf ((uint) Math.ceilf ((float) remaining_seconds / 10) * 10));
  1658. } else {
  1659. uint remaining_minutes = (uint) Math.ceilf ((float) remaining_seconds / 60);
  1660. text.append (dngettext (null, "About %lu minute remaining",
  1661. "About %lu minutes remaining", remaining_minutes).printf (remaining_minutes));
  1662. }
  1663. }
  1664. } else {
  1665. text.append ("%s".printf (format_size (xfered)));
  1666. }
  1667. // reinitialize timer
  1668. timer.start ();
  1669. }
  1670. }
  1671. if (fraction != previous_percent) {
  1672. previous_percent = fraction;
  1673. progress_box.progressbar.fraction = fraction;
  1674. }
  1675. if (text.str != previous_textbar) {
  1676. previous_textbar = text.str;
  1677. progress_box.progressbar.text = text.str;
  1678. }
  1679. }
  1680. void on_emit_totaldownload (uint64 total) {
  1681. download_rate = 0;
  1682. rates_nb = 0;
  1683. previous_percent = 0;
  1684. previous_textbar = "";
  1685. total_download = total;
  1686. // this is emitted at the end of the total download
  1687. // with the value 0 so stop our timer
  1688. if (total == 0) {
  1689. timer.stop ();
  1690. progress_box.progressbar.text = "";
  1691. }
  1692. }
  1693. void on_emit_log (uint level, string msg) {
  1694. // msg ends with \n
  1695. string? line = null;
  1696. if (level == 1) { //Alpm.LogLevel.ERROR
  1697. if (previous_filename != "") {
  1698. line = dgettext (null, "Error") + ": " + previous_filename + ": " + msg;
  1699. } else {
  1700. line = dgettext (null, "Error") + ": " + msg;
  1701. }
  1702. important_details_outpout (false);
  1703. } else if (level == (1 << 1)) { //Alpm.LogLevel.WARNING
  1704. // do not show warning when manjaro-system remove db.lck
  1705. if (previous_filename != "manjaro-system") {
  1706. if (previous_filename != "") {
  1707. line = dgettext (null, "Warning") + ": " + previous_filename + ": " + msg;
  1708. } else {
  1709. line = dgettext (null, "Warning") + ": " + msg;
  1710. }
  1711. warning_textbuffer.append (msg);
  1712. }
  1713. }
  1714. if (line != null) {
  1715. show_in_term (line.replace ("\n", ""));
  1716. }
  1717. }
  1718. void show_warnings () {
  1719. if (warning_textbuffer.len > 0) {
  1720. var flags = Gtk.DialogFlags.MODAL;
  1721. int use_header_bar;
  1722. Gtk.Settings.get_default ().get ("gtk-dialogs-use-header", out use_header_bar);
  1723. if (use_header_bar == 1) {
  1724. flags |= Gtk.DialogFlags.USE_HEADER_BAR;
  1725. }
  1726. var dialog = new Gtk.Dialog.with_buttons (dgettext (null, "Warning"),
  1727. application_window,
  1728. flags);
  1729. dialog.border_width = 6;
  1730. dialog.icon_name = "system-software-install";
  1731. dialog.deletable = false;
  1732. unowned Gtk.Widget widget = dialog.add_button (dgettext (null, "_Close"), Gtk.ResponseType.CLOSE);
  1733. widget.can_focus = true;
  1734. widget.has_focus = true;
  1735. widget.can_default = true;
  1736. widget.has_default = true;
  1737. var scrolledwindow = new Gtk.ScrolledWindow (null, null);
  1738. var label = new Gtk.Label (warning_textbuffer.str);
  1739. label.margin = 12;
  1740. scrolledwindow.visible = true;
  1741. label.visible = true;
  1742. scrolledwindow.add (label);
  1743. scrolledwindow.expand = true;
  1744. unowned Gtk.Box box = dialog.get_content_area ();
  1745. box.add (scrolledwindow);
  1746. dialog.default_width = 600;
  1747. dialog.default_height = 300;
  1748. dialog.run ();
  1749. dialog.destroy ();
  1750. warning_textbuffer = new StringBuilder ();
  1751. }
  1752. }
  1753. public void display_error (string message, string[] details) {
  1754. var flags = Gtk.DialogFlags.MODAL;
  1755. int use_header_bar;
  1756. Gtk.Settings.get_default ().get ("gtk-dialogs-use-header", out use_header_bar);
  1757. if (use_header_bar == 1) {
  1758. flags |= Gtk.DialogFlags.USE_HEADER_BAR;
  1759. }
  1760. var dialog = new Gtk.Dialog.with_buttons (message,
  1761. application_window,
  1762. flags);
  1763. dialog.border_width = 6;
  1764. dialog.icon_name = "system-software-install";
  1765. var textbuffer = new StringBuilder ();
  1766. if (details.length != 0) {
  1767. show_in_term (message + ":");
  1768. foreach (unowned string detail in details) {
  1769. show_in_term (detail);
  1770. textbuffer.append (detail + "\n");
  1771. }
  1772. } else {
  1773. show_in_term (message);
  1774. textbuffer.append (message);
  1775. }
  1776. dialog.deletable = false;
  1777. unowned Gtk.Widget widget = dialog.add_button (dgettext (null, "_Close"), Gtk.ResponseType.CLOSE);
  1778. widget.can_focus = true;
  1779. widget.has_focus = true;
  1780. widget.can_default = true;
  1781. widget.has_default = true;
  1782. var scrolledwindow = new Gtk.ScrolledWindow (null, null);
  1783. var label = new Gtk.Label (textbuffer.str);
  1784. label.margin = 12;
  1785. scrolledwindow.visible = true;
  1786. label.visible = true;
  1787. scrolledwindow.add (label);
  1788. scrolledwindow.expand = true;
  1789. unowned Gtk.Box box = dialog.get_content_area ();
  1790. box.add (scrolledwindow);
  1791. dialog.default_width = 600;
  1792. dialog.default_height = 300;
  1793. dialog.run ();
  1794. dialog.destroy ();
  1795. }
  1796. void handle_error (ErrorInfos error) {
  1797. if (error.message != "") {
  1798. reset_progress_box ("");
  1799. display_error (error.message, error.details);
  1800. }
  1801. finish_transaction ();
  1802. }
  1803. void finish_transaction () {
  1804. disconnecting_dbus_signals ();
  1805. transaction_summary.remove_all ();
  1806. reset_progress_box ("");
  1807. finished (success);
  1808. success = false;
  1809. }
  1810. void on_refresh_finished (bool success) {
  1811. stop_progressbar_pulse ();
  1812. this.success = success;
  1813. if (success) {
  1814. finished (success);
  1815. reset_progress_box ("");
  1816. success = false;
  1817. } else {
  1818. handle_error (get_current_error ());
  1819. }
  1820. previous_filename = "";
  1821. disconnecting_dbus_signals ();
  1822. system_daemon.refresh_finished.disconnect (on_refresh_finished);
  1823. }
  1824. void on_trans_prepare_finished (bool success) {
  1825. stop_progressbar_pulse ();
  1826. this.success = success;
  1827. if (success) {
  1828. show_warnings ();
  1829. Type type = set_transaction_sum ();
  1830. if (mode != Mode.INSTALLER && (no_confirm_commit || type == Type.UPDATE)) {
  1831. // no_confirm_commit or only updates
  1832. to_install.remove_all ();
  1833. start_commit ();
  1834. } else if (type != 0) {
  1835. if (transaction_sum_dialog.run () == Gtk.ResponseType.OK) {
  1836. transaction_sum_dialog.hide ();
  1837. while (Gtk.events_pending ()) {
  1838. Gtk.main_iteration ();
  1839. }
  1840. #if DISABLE_AUR
  1841. #else
  1842. if (type == Type.BUILD) {
  1843. // there only AUR packages to build
  1844. release ();
  1845. on_trans_commit_finished (true);
  1846. } else {
  1847. #endif
  1848. // backup to_install and to_remove
  1849. foreach (unowned string name in to_install) {
  1850. previous_to_install.add (name);
  1851. }
  1852. foreach (unowned string name in to_remove) {
  1853. previous_to_remove.add (name);
  1854. }
  1855. to_install.remove_all ();
  1856. to_remove.remove_all ();
  1857. start_commit ();
  1858. #if DISABLE_AUR
  1859. #else
  1860. }
  1861. #endif
  1862. } else {
  1863. transaction_sum_dialog.hide ();
  1864. unowned string action = dgettext (null, "Transaction cancelled");
  1865. show_in_term (action + ".\n");
  1866. progress_box.action_label.label = action;
  1867. release ();
  1868. transaction_summary.remove_all ();
  1869. #if DISABLE_AUR
  1870. #else
  1871. to_build_queue.clear ();
  1872. #endif
  1873. sysupgrade_after_trans = false;
  1874. success = false;
  1875. finish_transaction ();
  1876. }
  1877. #if DISABLE_AUR
  1878. #else
  1879. } else if (build_after_sysupgrade) {
  1880. // there only AUR packages to build
  1881. release ();
  1882. on_trans_commit_finished (true);
  1883. #endif
  1884. } else {
  1885. //var err = ErrorInfos ();
  1886. //err.message = dgettext (null, "Nothing to do") + "\n";
  1887. show_in_term (dgettext (null, "Nothing to do") + ".\n");
  1888. release ();
  1889. clear_lists ();
  1890. finish_transaction ();
  1891. //handle_error (err);
  1892. }
  1893. } else {
  1894. to_load.remove_all ();
  1895. warning_textbuffer = new StringBuilder ();
  1896. handle_error (get_current_error ());
  1897. }
  1898. }
  1899. void on_trans_commit_finished (bool success) {
  1900. this.success = success;
  1901. // needed before build_aur_packages and remove_makedeps
  1902. no_confirm_commit = false;
  1903. Notify.init ("pamac-classic");
  1904. if (success) {
  1905. string summary = dgettext (null, "Transaction successful");
  1906. string body = dgettext (null, "The transaction has been completed successfully");
  1907. string icon = "system-software-install";
  1908. Notify.Notification notification = new Notify.Notification (summary, body, icon);
  1909. try {
  1910. notification.show ();
  1911. } catch (Error e) {
  1912. stderr.printf ("Error: %s\n", e.message);
  1913. }
  1914. show_warnings ();
  1915. to_load.remove_all ();
  1916. #if DISABLE_AUR
  1917. #else
  1918. if (to_build_queue.get_length () != 0) {
  1919. show_in_term ("");
  1920. clear_previous_lists ();
  1921. check_authorization.begin ((obj, res) => {
  1922. bool authorized = check_authorization.end (res);
  1923. if (authorized) {
  1924. build_aur_packages.begin ();
  1925. } else {
  1926. to_build_queue.clear ();
  1927. on_trans_commit_finished (false);
  1928. }
  1929. });
  1930. } else {
  1931. #endif
  1932. clear_previous_lists ();
  1933. if (sysupgrade_after_trans) {
  1934. sysupgrade_after_trans = false;
  1935. sysupgrade (false);
  1936. #if DISABLE_AUR
  1937. #else
  1938. } else if (build_after_sysupgrade) {
  1939. build_after_sysupgrade = false;
  1940. disconnecting_dbus_signals ();
  1941. // build aur updates in to_build
  1942. run ();
  1943. #endif
  1944. } else {
  1945. unowned string action = dgettext (null, "Transaction successfully finished");
  1946. show_in_term (action + ".\n");
  1947. progress_box.action_label.label = action;
  1948. finish_transaction ();
  1949. }
  1950. #if DISABLE_AUR
  1951. #else
  1952. }
  1953. #endif
  1954. } else {
  1955. string summary = dgettext (null, "Transaction failed");
  1956. string body = dgettext (null, "The transaction failed and no packages have been updated/installed");
  1957. string icon = "system-software-install";
  1958. Notify.Notification notification = new Notify.Notification (summary, body, icon);
  1959. try {
  1960. notification.show ();
  1961. } catch (Error e) {
  1962. stderr.printf ("Error: %s\n", e.message);
  1963. }
  1964. // if it is an authentication or a download error, database was not modified
  1965. var err = get_current_error ();
  1966. if (err.message == dgettext (null, "Authentication failed")
  1967. || err.errnos == 54) { //Alpm.Errno.EXTERNAL_DOWNLOAD
  1968. // recover old pkgnames
  1969. foreach (unowned string name in previous_to_install) {
  1970. to_install.add (name);
  1971. }
  1972. foreach (unowned string name in previous_to_remove) {
  1973. to_remove.add (name);
  1974. }
  1975. } else {
  1976. to_load.remove_all ();
  1977. }
  1978. clear_previous_lists ();
  1979. #if DISABLE_AUR
  1980. #else
  1981. to_build_queue.clear ();
  1982. #endif
  1983. warning_textbuffer = new StringBuilder ();
  1984. handle_error (err);
  1985. }
  1986. Notify.uninit ();
  1987. total_download = 0;
  1988. already_downloaded = 0;
  1989. previous_filename = "";
  1990. }
  1991. void on_set_pkgreason_finished () {
  1992. system_daemon.set_pkgreason_finished.disconnect (on_set_pkgreason_finished);
  1993. set_pkgreason_finished ();
  1994. }
  1995. #if DISABLE_AUR
  1996. void on_save_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon) {
  1997. #else
  1998. void on_save_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  1999. bool enable_aur, bool search_aur, string aur_build_dir, bool check_aur_updates) {
  2000. #endif
  2001. system_daemon.save_pamac_config_finished.disconnect (on_save_pamac_config_finished);
  2002. pamac_config.reload ();
  2003. flags = (1 << 4); //Alpm.TransFlag.CASCADE
  2004. if (pamac_config.recurse) {
  2005. flags |= (1 << 5); //Alpm.TransFlag.RECURSE
  2006. }
  2007. #if DISABLE_AUR
  2008. save_pamac_config_finished (recurse, refresh_period, no_update_hide_icon);
  2009. #else
  2010. save_pamac_config_finished (recurse, refresh_period, no_update_hide_icon,
  2011. enable_aur, search_aur, aur_build_dir, check_aur_updates);
  2012. #endif
  2013. }
  2014. void on_write_alpm_config_finished (bool checkspace) {
  2015. refresh_handle ();
  2016. system_daemon.write_alpm_config_finished.disconnect (on_write_alpm_config_finished);
  2017. write_alpm_config_finished (checkspace);
  2018. }
  2019. void on_write_mirrors_config_finished (string choosen_country, string choosen_generation_method) {
  2020. system_daemon.write_mirrors_config_finished.disconnect (on_write_mirrors_config_finished);
  2021. write_mirrors_config_finished (choosen_country, choosen_generation_method);
  2022. }
  2023. void on_generate_mirrors_list_data (string line) {
  2024. show_in_term (line);
  2025. }
  2026. void on_generate_mirrors_list_finished () {
  2027. refresh_handle ();
  2028. system_daemon.generate_mirrors_list_data.disconnect (on_generate_mirrors_list_data);
  2029. system_daemon.generate_mirrors_list_finished.disconnect (on_generate_mirrors_list_finished);
  2030. reset_progress_box ("");
  2031. }
  2032. void connecting_user_daemon () {
  2033. try {
  2034. user_daemon = Bus.get_proxy_sync (BusType.SESSION, "org.pamac.user", "/org/pamac/user");
  2035. } catch (IOError e) {
  2036. stderr.printf ("IOError: %s\n", e.message);
  2037. }
  2038. }
  2039. void connecting_system_daemon () {
  2040. try {
  2041. system_daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.pamac.system", "/org/pamac/system");
  2042. // Set environment variables
  2043. system_daemon.set_environment_variables (pamac_config.environment_variables);
  2044. } catch (IOError e) {
  2045. stderr.printf ("IOError: %s\n", e.message);
  2046. } catch (DBusError e) {
  2047. stderr.printf ("DBusError: %s\n", e.message);
  2048. }
  2049. }
  2050. void connecting_dbus_signals () {
  2051. system_daemon.emit_event.connect (on_emit_event);
  2052. system_daemon.emit_providers.connect (on_emit_providers);
  2053. system_daemon.emit_progress.connect (on_emit_progress);
  2054. system_daemon.emit_download.connect (on_emit_download);
  2055. system_daemon.emit_totaldownload.connect (on_emit_totaldownload);
  2056. system_daemon.emit_log.connect (on_emit_log);
  2057. system_daemon.trans_prepare_finished.connect (on_trans_prepare_finished);
  2058. system_daemon.trans_commit_finished.connect (on_trans_commit_finished);
  2059. }
  2060. void disconnecting_dbus_signals () {
  2061. system_daemon.emit_event.disconnect (on_emit_event);
  2062. system_daemon.emit_providers.disconnect (on_emit_providers);
  2063. system_daemon.emit_progress.disconnect (on_emit_progress);
  2064. system_daemon.emit_download.disconnect (on_emit_download);
  2065. system_daemon.emit_totaldownload.disconnect (on_emit_totaldownload);
  2066. system_daemon.emit_log.disconnect (on_emit_log);
  2067. system_daemon.trans_prepare_finished.disconnect (on_trans_prepare_finished);
  2068. system_daemon.trans_commit_finished.disconnect (on_trans_commit_finished);
  2069. }
  2070. }
  2071. }