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.

1384 lines
48KB

  1. /*
  2. * pamac-vala
  3. *
  4. * Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a get of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. namespace Pamac {
  20. [DBus (name = "org.manjaro.pamac")]
  21. interface Daemon : Object {
  22. public abstract void set_environment_variables (HashTable<string,string> variables) throws IOError;
  23. public abstract ErrorInfos get_current_error () throws IOError;
  24. public abstract void start_get_authorization () throws IOError;
  25. public abstract void start_write_pamac_config (HashTable<string,Variant> new_pamac_conf) throws IOError;
  26. public abstract void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf) throws IOError;
  27. public abstract void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf) throws IOError;
  28. public abstract void start_generate_mirrors_list () throws IOError;
  29. public abstract void start_set_pkgreason (string pkgname, uint reason) throws IOError;
  30. public abstract PackageInfos get_installed_pkg (string pkgname) throws IOError;
  31. public abstract void start_refresh (bool force) throws IOError;
  32. public abstract void add_ignorepkg (string pkgname) throws IOError;
  33. public abstract void remove_ignorepkg (string pkgname) throws IOError;
  34. public abstract void start_get_updates (bool check_aur_updates) throws IOError;
  35. public abstract bool trans_init (Alpm.TransFlag transflags) throws IOError;
  36. public abstract bool trans_sysupgrade (bool enable_downgrade) throws IOError;
  37. public abstract bool trans_add_pkg (string pkgname) throws IOError;
  38. public abstract bool trans_remove_pkg (string pkgname) throws IOError;
  39. public abstract bool trans_load_pkg (string pkgpath) throws IOError;
  40. public abstract void start_trans_prepare () throws IOError;
  41. public abstract void choose_provider (int provider) throws IOError;
  42. public abstract PackageInfos[] trans_to_add () throws IOError;
  43. public abstract PackageInfos[] trans_to_remove () throws IOError;
  44. public abstract void start_trans_commit () throws IOError;
  45. public abstract void trans_release () throws IOError;
  46. [DBus (no_reply = true)]
  47. public abstract void trans_cancel () throws IOError;
  48. [DBus (no_reply = true)]
  49. public abstract void quit () throws IOError;
  50. public signal void emit_event (uint primary_event, uint secondary_event, string[] details);
  51. public signal void emit_providers (string depend, string[] providers);
  52. public signal void emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target);
  53. public signal void emit_download (string filename, uint64 xfered, uint64 total);
  54. public signal void emit_totaldownload (uint64 total);
  55. public signal void emit_log (uint level, string msg);
  56. public signal void set_pkgreason_finished ();
  57. public signal void refresh_finished (bool success);
  58. public signal void get_updates_finished (Updates updates);
  59. public signal void trans_prepare_finished (bool success);
  60. public signal void trans_commit_finished (bool success);
  61. public signal void get_authorization_finished (bool authorized);
  62. public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  63. bool enable_aur, bool search_aur, bool check_aur_updates,
  64. bool no_confirm_build);
  65. public signal void write_alpm_config_finished (bool checkspace);
  66. public signal void write_mirrors_config_finished (string choosen_country, string choosen_generation_method);
  67. public signal void generate_mirrors_list_data (string line);
  68. public signal void generate_mirrors_list_finished ();
  69. }
  70. public enum Mode {
  71. MANAGER,
  72. UPDATER
  73. }
  74. public class Transaction: Object {
  75. enum Type {
  76. STANDARD = (1 << 0),
  77. UPDATE = (1 << 1),
  78. BUILD = (1 << 2)
  79. }
  80. Daemon daemon;
  81. public AlpmUtils alpm_utils;
  82. public Pamac.Config pamac_config;
  83. public Alpm.TransFlag flags;
  84. public GenericSet<string?> to_add;
  85. public GenericSet<string?> to_remove;
  86. public GenericSet<string?> to_load;
  87. public GenericSet<string?> to_build;
  88. public GenericSet<string?> temporary_ignorepkgs;
  89. HashTable<string,Json.Object> aur_infos;
  90. public Mode mode;
  91. uint64 total_download;
  92. uint64 already_downloaded;
  93. string previous_label;
  94. string previous_textbar;
  95. float previous_percent;
  96. string previous_filename;
  97. uint pulse_timeout_id;
  98. bool sysupgrade_after_trans;
  99. bool enable_downgrade;
  100. uint64 previous_xfered;
  101. uint64 download_rate;
  102. uint64 rates_nb;
  103. Timer timer;
  104. bool database_modified;
  105. bool success;
  106. //dialogs
  107. TransactionSumDialog transaction_sum_dialog;
  108. TransactionInfoDialog transaction_info_dialog;
  109. ProgressDialog progress_dialog;
  110. //parent window
  111. public Gtk.ApplicationWindow? application_window;
  112. public signal void finished (bool success);
  113. public signal void set_pkgreason_finished ();
  114. public signal void get_updates_finished (Updates updates);
  115. public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  116. bool enable_aur, bool search_aur, bool check_aur_updates,
  117. bool no_confirm_build);
  118. public signal void write_alpm_config_finished (bool checkspace);
  119. public signal void write_mirrors_config_finished (string choosen_country, string choosen_generation_method);
  120. public Transaction (Gtk.ApplicationWindow? application_window) {
  121. alpm_utils = new AlpmUtils ("/etc/pacman.conf");
  122. pamac_config = new Pamac.Config ("/etc/pamac.conf");
  123. flags = Alpm.TransFlag.CASCADE;
  124. if (pamac_config.recurse) {
  125. flags |= Alpm.TransFlag.RECURSE;
  126. }
  127. to_add = new GenericSet<string?> (str_hash, str_equal);
  128. to_remove = new GenericSet<string?> (str_hash, str_equal);
  129. to_load = new GenericSet<string?> (str_hash, str_equal);
  130. to_build = new GenericSet<string?> (str_hash, str_equal);
  131. temporary_ignorepkgs = new GenericSet<string?> (str_hash, str_equal);
  132. aur_infos = new HashTable<string,Json.Object> (str_hash, str_equal);
  133. connecting_dbus_signals ();
  134. //creating dialogs
  135. this.application_window = application_window;
  136. transaction_sum_dialog = new TransactionSumDialog (application_window);
  137. transaction_info_dialog = new TransactionInfoDialog (application_window);
  138. progress_dialog = new ProgressDialog (application_window);
  139. progress_dialog.close_button.clicked.connect (on_progress_dialog_close_button_clicked);
  140. progress_dialog.cancel_button.clicked.connect (on_progress_dialog_cancel_button_clicked);
  141. // connect to child_exited signal which will only be emit after a call to watch_child
  142. progress_dialog.term.child_exited.connect (on_term_child_exited);
  143. // progress data
  144. previous_label = "";
  145. previous_textbar = "";
  146. previous_filename = "";
  147. sysupgrade_after_trans = false;
  148. timer = new Timer ();
  149. database_modified = false;
  150. success = false;
  151. }
  152. public async void run_preferences_dialog () {
  153. SourceFunc callback = run_preferences_dialog.callback;
  154. ulong handler_id = daemon.get_authorization_finished.connect ((authorized) => {
  155. if (authorized) {
  156. var preferences_dialog = new PreferencesDialog (this);
  157. preferences_dialog.run ();
  158. preferences_dialog.destroy ();
  159. while (Gtk.events_pending ()) {
  160. Gtk.main_iteration ();
  161. }
  162. }
  163. Idle.add((owned) callback);
  164. });
  165. start_get_authorization ();
  166. yield;
  167. daemon.disconnect (handler_id);
  168. }
  169. public ErrorInfos get_current_error () {
  170. try {
  171. return daemon.get_current_error ();
  172. } catch (IOError e) {
  173. stderr.printf ("IOError: %s\n", e.message);
  174. return ErrorInfos ();
  175. }
  176. }
  177. public void start_get_authorization () {
  178. try {
  179. daemon.start_get_authorization ();
  180. } catch (IOError e) {
  181. stderr.printf ("IOError: %s\n", e.message);
  182. }
  183. }
  184. public void start_write_pamac_config (HashTable<string,Variant> new_pamac_conf) {
  185. try {
  186. daemon.start_write_pamac_config (new_pamac_conf);
  187. } catch (IOError e) {
  188. stderr.printf ("IOError: %s\n", e.message);
  189. }
  190. }
  191. public void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf) {
  192. try {
  193. daemon.start_write_alpm_config (new_alpm_conf);
  194. } catch (IOError e) {
  195. stderr.printf ("IOError: %s\n", e.message);
  196. }
  197. }
  198. public void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf) {
  199. try {
  200. daemon.start_write_mirrors_config (new_mirrors_conf);
  201. } catch (IOError e) {
  202. stderr.printf ("IOError: %s\n", e.message);
  203. }
  204. }
  205. public void start_generate_mirrors_list () {
  206. string action = dgettext (null, "Refreshing mirrors list") + "...";
  207. progress_dialog.spawn_in_term ({"echo", action});
  208. progress_dialog.action_label.set_text (action);
  209. progress_dialog.progressbar.set_fraction (0);
  210. progress_dialog.progressbar.set_text ("");
  211. progress_dialog.cancel_button.set_visible (false);
  212. progress_dialog.close_button.set_visible (false);
  213. progress_dialog.expander.set_expanded (true);
  214. progress_dialog.width_request = 700;
  215. pulse_timeout_id = Timeout.add (500, (GLib.SourceFunc) progress_dialog.progressbar.pulse);
  216. progress_dialog.show ();
  217. while (Gtk.events_pending ()) {
  218. Gtk.main_iteration ();
  219. }
  220. try {
  221. daemon.start_generate_mirrors_list ();
  222. } catch (IOError e) {
  223. stderr.printf ("IOError: %s\n", e.message);
  224. Source.remove (pulse_timeout_id);
  225. }
  226. }
  227. public void start_set_pkgreason (string pkgname, Alpm.Package.Reason reason) {
  228. try {
  229. daemon.start_set_pkgreason (pkgname, (uint) reason);
  230. } catch (IOError e) {
  231. stderr.printf ("IOError: %s\n", e.message);
  232. }
  233. }
  234. public void start_refresh (bool force) {
  235. string action = dgettext (null, "Synchronizing package databases") + "...";
  236. progress_dialog.spawn_in_term ({"echo", action});
  237. progress_dialog.action_label.set_text (action);
  238. progress_dialog.progressbar.set_fraction (0);
  239. progress_dialog.progressbar.set_text ("");
  240. progress_dialog.cancel_button.set_visible (true);
  241. progress_dialog.close_button.set_visible (false);
  242. progress_dialog.show ();
  243. while (Gtk.events_pending ()) {
  244. Gtk.main_iteration ();
  245. }
  246. try {
  247. daemon.refresh_finished.connect (on_refresh_finished);
  248. daemon.start_refresh (force);
  249. } catch (IOError e) {
  250. stderr.printf ("IOError: %s\n", e.message);
  251. daemon.refresh_finished.disconnect (on_refresh_finished);
  252. database_modified = true;
  253. success = false;
  254. finish_transaction ();
  255. }
  256. }
  257. public void start_get_updates () {
  258. daemon.get_updates_finished.connect (on_get_updates_finished);
  259. try {
  260. daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates);
  261. } catch (IOError e) {
  262. stderr.printf ("IOError: %s\n", e.message);
  263. success = false;
  264. finish_transaction ();
  265. }
  266. }
  267. void start_get_updates_for_sysupgrade () {
  268. daemon.get_updates_finished.connect (on_get_updates_for_sysupgrade_finished);
  269. try {
  270. daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates);
  271. } catch (IOError e) {
  272. stderr.printf ("IOError: %s\n", e.message);
  273. success = false;
  274. finish_transaction ();
  275. }
  276. }
  277. public void add_ignorepkg (string pkgname) {
  278. try {
  279. daemon.add_ignorepkg (pkgname);
  280. //temporary_ignorepkgs.add (pkgname);
  281. } catch (IOError e) {
  282. stderr.printf ("IOError: %s\n", e.message);
  283. }
  284. }
  285. public void remove_ignorepkg (string pkgname) {
  286. try {
  287. daemon.remove_ignorepkg (pkgname);
  288. } catch (IOError e) {
  289. stderr.printf ("IOError: %s\n", e.message);
  290. }
  291. }
  292. public bool init (Alpm.TransFlag flags) {
  293. foreach (unowned string pkgname in temporary_ignorepkgs) {
  294. add_ignorepkg (pkgname);
  295. }
  296. try {
  297. return daemon.trans_init (flags);
  298. } catch (IOError e) {
  299. stderr.printf ("IOError: %s\n", e.message);
  300. return false;
  301. }
  302. }
  303. void sysupgrade_simple (bool enable_downgrade) {
  304. progress_dialog.progressbar.set_fraction (0);
  305. progress_dialog.cancel_button.set_visible (true);
  306. success = init (0);
  307. if (success) {
  308. try {
  309. success = daemon.trans_sysupgrade (enable_downgrade);
  310. } catch (IOError e) {
  311. stderr.printf ("IOError: %s\n", e.message);
  312. success = false;
  313. }
  314. if (success) {
  315. progress_dialog.show ();
  316. while (Gtk.events_pending ()) {
  317. Gtk.main_iteration ();
  318. }
  319. try {
  320. daemon.start_trans_prepare ();
  321. } catch (IOError e) {
  322. stderr.printf ("IOError: %s\n", e.message);
  323. release ();
  324. success = false;
  325. finish_transaction ();
  326. }
  327. } else {
  328. release ();
  329. handle_error (get_current_error ());
  330. }
  331. } else {
  332. handle_error (get_current_error ());
  333. }
  334. }
  335. public void sysupgrade (bool enable_downgrade) {
  336. this.enable_downgrade = enable_downgrade;
  337. string action = dgettext (null, "Starting full system upgrade") + "...";
  338. progress_dialog.spawn_in_term ({"echo", action});
  339. progress_dialog.action_label.set_text (action);
  340. progress_dialog.progressbar.set_fraction (0);
  341. progress_dialog.progressbar.set_text ("");
  342. progress_dialog.cancel_button.set_visible (true);
  343. progress_dialog.close_button.set_visible (false);
  344. while (Gtk.events_pending ()) {
  345. Gtk.main_iteration ();
  346. }
  347. start_get_updates_for_sysupgrade ();
  348. }
  349. void on_get_updates_finished (Updates updates) {
  350. daemon.get_updates_finished.disconnect (on_get_updates_finished);
  351. get_updates_finished (updates);
  352. }
  353. void on_get_updates_for_sysupgrade_finished (Updates updates) {
  354. daemon.get_updates_finished.disconnect (on_get_updates_for_sysupgrade_finished);
  355. // get syncfirst updates
  356. if (updates.is_syncfirst) {
  357. clear_lists ();
  358. if (mode == Mode.MANAGER) {
  359. sysupgrade_after_trans = true;
  360. }
  361. foreach (unowned PackageInfos infos in updates.repos_updates) {
  362. to_add.add (infos.name);
  363. }
  364. // run as a standard transaction
  365. run ();
  366. } else {
  367. if (updates.aur_updates.length != 0) {
  368. clear_lists ();
  369. foreach (unowned PackageInfos infos in updates.aur_updates) {
  370. if (!(infos.name in temporary_ignorepkgs)) {
  371. to_build.add (infos.name);
  372. }
  373. }
  374. }
  375. if (updates.repos_updates.length != 0) {
  376. sysupgrade_simple (enable_downgrade);
  377. } else {
  378. progress_dialog.show ();
  379. while (Gtk.events_pending ()) {
  380. Gtk.main_iteration ();
  381. }
  382. on_trans_prepare_finished (true);
  383. }
  384. }
  385. }
  386. public void clear_lists () {
  387. to_add.remove_all ();
  388. to_remove.remove_all ();
  389. to_build.remove_all ();
  390. }
  391. public void run () {
  392. string action = dgettext (null, "Preparing") + "...";
  393. progress_dialog.spawn_in_term ({"echo", action});
  394. progress_dialog.action_label.set_text (action);
  395. progress_dialog.progressbar.set_fraction (0);
  396. progress_dialog.progressbar.set_text ("");
  397. progress_dialog.cancel_button.set_visible (true);
  398. progress_dialog.close_button.set_visible (false);
  399. progress_dialog.show ();
  400. while (Gtk.events_pending ()) {
  401. Gtk.main_iteration ();
  402. }
  403. // run
  404. if (to_add.length == 0
  405. && to_remove.length == 0
  406. && to_load.length == 0
  407. && to_build.length != 0) {
  408. // there only AUR packages to build so no need to prepare transaction
  409. on_trans_prepare_finished (true);
  410. } else {
  411. success = false;
  412. try {
  413. success = daemon.trans_init (flags);
  414. } catch (IOError e) {
  415. stderr.printf ("IOError: %s\n", e.message);
  416. }
  417. if (success) {
  418. success = false;
  419. foreach (unowned string name in to_add) {
  420. try {
  421. success = daemon.trans_add_pkg (name);
  422. } catch (IOError e) {
  423. stderr.printf ("IOError: %s\n", e.message);
  424. }
  425. if (!success) {
  426. break;
  427. }
  428. }
  429. foreach (unowned string name in to_remove) {
  430. try {
  431. success = daemon.trans_remove_pkg (name);
  432. } catch (IOError e) {
  433. stderr.printf ("IOError: %s\n", e.message);
  434. }
  435. if (!success) {
  436. break;
  437. }
  438. }
  439. foreach (unowned string path in to_load) {
  440. try {
  441. success = daemon.trans_load_pkg (path);
  442. } catch (IOError e) {
  443. stderr.printf ("IOError: %s\n", e.message);
  444. }
  445. if (!success) {
  446. break;
  447. }
  448. }
  449. if (success) {
  450. try {
  451. daemon.start_trans_prepare ();
  452. } catch (IOError e) {
  453. stderr.printf ("IOError: %s\n", e.message);
  454. release ();
  455. success = false;
  456. finish_transaction ();
  457. }
  458. } else {
  459. release ();
  460. handle_error (get_current_error ());
  461. }
  462. } else {
  463. handle_error (get_current_error ());
  464. }
  465. }
  466. }
  467. void choose_provider (string depend, string[] providers) {
  468. var choose_provider_dialog = new ChooseProviderDialog (application_window);
  469. choose_provider_dialog.label.set_markup ("<b>%s</b>".printf (dgettext (null, "Choose a provider for %s").printf (depend)));
  470. foreach (unowned string provider in providers) {
  471. choose_provider_dialog.comboboxtext.append_text (provider);
  472. }
  473. choose_provider_dialog.comboboxtext.active = 0;
  474. choose_provider_dialog.run ();
  475. try {
  476. daemon.choose_provider (choose_provider_dialog.comboboxtext.active);
  477. } catch (IOError e) {
  478. stderr.printf ("IOError: %s\n", e.message);
  479. }
  480. choose_provider_dialog.destroy ();
  481. while (Gtk.events_pending ()) {
  482. Gtk.main_iteration ();
  483. }
  484. }
  485. Type set_transaction_sum () {
  486. // return 0 if transaction_sum is empty, 2, if there are only aur updates, 1 otherwise
  487. Type type = 0;
  488. uint64 dsize = 0;
  489. PackageInfos[] prepared_to_add = {};
  490. PackageInfos[] prepared_to_remove = {};
  491. string[] to_downgrade = {};
  492. string[] to_install = {};
  493. string[] to_reinstall = {};
  494. string[] to_update = {};
  495. string[] _to_build = {};
  496. Gtk.TreeIter iter;
  497. transaction_sum_dialog.top_label.set_markup ("<big><b>%s</b></big>".printf (dgettext (null, "Transaction Summary")));
  498. transaction_sum_dialog.sum_list.clear ();
  499. try {
  500. prepared_to_add = daemon.trans_to_add ();
  501. prepared_to_remove = daemon.trans_to_remove ();
  502. } catch (IOError e) {
  503. stderr.printf ("IOError: %s\n", e.message);
  504. }
  505. foreach (unowned PackageInfos pkg_info in prepared_to_add) {
  506. dsize += pkg_info.download_size;
  507. try {
  508. PackageInfos local_pkg_info = daemon.get_installed_pkg (pkg_info.name);
  509. if (local_pkg_info.name == "") {
  510. to_install += "%s %s".printf (pkg_info.name, pkg_info.version);
  511. } else {
  512. int cmp = Alpm.pkg_vercmp (pkg_info.version, local_pkg_info.version);
  513. if (cmp == 1) {
  514. to_update += "%s %s".printf (pkg_info.name, pkg_info.version);
  515. } else if (cmp == 0) {
  516. to_reinstall += "%s %s".printf (pkg_info.name, pkg_info.version);
  517. } else {
  518. to_downgrade += "%s %s".printf (pkg_info.name, pkg_info.version);
  519. }
  520. }
  521. } catch (IOError e) {
  522. stderr.printf ("IOError: %s\n", e.message);
  523. }
  524. }
  525. foreach (unowned string name in to_build) {
  526. _to_build += name;
  527. }
  528. int len = prepared_to_remove.length;
  529. int i;
  530. if (len != 0) {
  531. type |= Type.STANDARD;
  532. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  533. 0, dgettext (null, "To remove") + ":",
  534. 1, "%s %s".printf (prepared_to_remove[0].name, prepared_to_remove[0].version));
  535. i = 1;
  536. while (i < len) {
  537. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  538. 1, "%s %s".printf (prepared_to_remove[i].name, prepared_to_remove[i].version));
  539. i++;
  540. }
  541. }
  542. len = to_downgrade.length;
  543. if (len != 0) {
  544. type |= Type.STANDARD;
  545. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  546. 0, dgettext (null, "To downgrade") + ":",
  547. 1, to_downgrade[0]);
  548. i = 1;
  549. while (i < len) {
  550. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  551. 1, to_downgrade[i]);
  552. i++;
  553. }
  554. }
  555. len = _to_build.length;
  556. if (len != 0) {
  557. type |= Type.BUILD;
  558. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  559. 0, dgettext (null, "To build") + ":",
  560. 1, _to_build[0]);
  561. i = 1;
  562. while (i < len) {
  563. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  564. 1, _to_build[i]);
  565. i++;
  566. }
  567. }
  568. len = to_install.length;
  569. if (len != 0) {
  570. type |= Type.STANDARD;
  571. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  572. 0, dgettext (null, "To install") + ":",
  573. 1, to_install[0]);
  574. i = 1;
  575. while (i < len) {
  576. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  577. 1, to_install[i]);
  578. i++;
  579. }
  580. }
  581. len = to_reinstall.length;
  582. if (len != 0) {
  583. type |= Type.STANDARD;
  584. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  585. 0, dgettext (null, "To reinstall") + ":",
  586. 1, to_reinstall[0]);
  587. i = 1;
  588. while (i < len) {
  589. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  590. 1, to_reinstall[i]);
  591. i++;
  592. }
  593. }
  594. len = to_update.length;
  595. if (len != 0) {
  596. type |= Type.UPDATE;
  597. if (mode != Mode.UPDATER) {
  598. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  599. 0, dgettext (null, "To update") + ":",
  600. 1, to_update[0]);
  601. i = 1;
  602. while (i < len) {
  603. transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
  604. 1, to_update[i]);
  605. i++;
  606. }
  607. }
  608. }
  609. if (dsize == 0) {
  610. transaction_sum_dialog.bottom_label.set_visible (false);
  611. } else {
  612. transaction_sum_dialog.bottom_label.set_markup ("<b>%s: %s</b>".printf (dgettext (null, "Total download size"), format_size (dsize)));
  613. transaction_sum_dialog.bottom_label.set_visible (true);
  614. }
  615. return type;
  616. }
  617. public void start_commit () {
  618. progress_dialog.cancel_button.set_visible (false);
  619. try {
  620. daemon.start_trans_commit ();
  621. } catch (IOError e) {
  622. stderr.printf ("IOError: %s\n", e.message);
  623. database_modified = true;
  624. success = false;
  625. finish_transaction ();
  626. }
  627. }
  628. public void build_aur_packages () {
  629. string action = dgettext (null, "Building packages") + "...";
  630. progress_dialog.spawn_in_term ({"echo", action});
  631. progress_dialog.action_label.set_text (action);
  632. progress_dialog.progressbar.set_fraction (0);
  633. progress_dialog.progressbar.set_text ("");
  634. progress_dialog.cancel_button.set_visible (false);
  635. progress_dialog.close_button.set_visible (false);
  636. progress_dialog.expander.set_expanded (true);
  637. progress_dialog.width_request = 700;
  638. progress_dialog.term.grab_focus ();
  639. pulse_timeout_id = Timeout.add (500, (GLib.SourceFunc) progress_dialog.progressbar.pulse);
  640. string[] cmds = {"yaourt", "-S"};
  641. if (pamac_config.no_confirm_build) {
  642. cmds += "--noconfirm";
  643. }
  644. foreach (unowned string name in to_build) {
  645. cmds += name;
  646. }
  647. Pid child_pid;
  648. progress_dialog.spawn_in_term (cmds, out child_pid);
  649. // watch_child is needed in order to have the child_exited signal emitted
  650. progress_dialog.term.watch_child (child_pid);
  651. }
  652. public async Json.Object get_aur_infos (string aur_name) {
  653. if (!aur_infos.contains (aur_name)) {
  654. Json.Array results = AUR.multiinfo ({aur_name});
  655. aur_infos.insert (aur_name, results.get_object_element (0));
  656. }
  657. return aur_infos.lookup (aur_name);
  658. }
  659. public void cancel () {
  660. try {
  661. daemon.trans_cancel ();
  662. } catch (IOError e) {
  663. stderr.printf ("IOError: %s\n", e.message);
  664. }
  665. progress_dialog.expander.set_expanded (false);
  666. Gtk.TextIter start_iter;
  667. Gtk.TextIter end_iter;
  668. transaction_info_dialog.textbuffer.get_start_iter (out start_iter);
  669. transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
  670. transaction_info_dialog.textbuffer.delete (ref start_iter, ref end_iter);
  671. }
  672. public void release () {
  673. try {
  674. daemon.trans_release ();
  675. } catch (IOError e) {
  676. stderr.printf ("IOError: %s\n", e.message);
  677. }
  678. foreach (unowned string pkgname in temporary_ignorepkgs) {
  679. remove_ignorepkg (pkgname);
  680. }
  681. }
  682. public void stop_daemon () {
  683. try {
  684. daemon.quit ();
  685. } catch (IOError e) {
  686. stderr.printf ("IOError: %s\n", e.message);
  687. }
  688. }
  689. void on_emit_event (uint primary_event, uint secondary_event, string[] details) {
  690. string msg;
  691. switch (primary_event) {
  692. case Alpm.Event.Type.HOOK_START:
  693. switch (secondary_event) {
  694. case Alpm.HookWhen.PRE_TRANSACTION:
  695. msg = dgettext (null, "Running pre-transaction hooks") + "...";
  696. progress_dialog.action_label.set_text (msg);
  697. progress_dialog.spawn_in_term ({"echo", msg});
  698. break;
  699. case Alpm.HookWhen.POST_TRANSACTION:
  700. msg = dgettext (null, "Running post-transaction hooks") + "...";
  701. progress_dialog.action_label.set_text (msg);
  702. progress_dialog.spawn_in_term ({"echo", msg});
  703. break;
  704. default:
  705. break;
  706. }
  707. break;
  708. case Alpm.Event.Type.HOOK_RUN_START:
  709. string textbar = "%s/%s".printf (details[2], details[3]);
  710. if (textbar != previous_textbar) {
  711. previous_textbar = textbar;
  712. progress_dialog.progressbar.set_text (textbar);
  713. }
  714. float fraction = (float) int.parse (details[2]) / int.parse (details[3]);
  715. if (fraction != previous_percent) {
  716. previous_percent = fraction;
  717. progress_dialog.progressbar.set_fraction (fraction);
  718. }
  719. if (details[1] != "") {
  720. msg = details[1] + ":";
  721. } else {
  722. msg = details[0] + ":";
  723. }
  724. progress_dialog.spawn_in_term ({"echo", msg});
  725. break;
  726. case Alpm.Event.Type.CHECKDEPS_START:
  727. msg = dgettext (null, "Checking dependencies") + "...";
  728. progress_dialog.action_label.set_text (msg);
  729. progress_dialog.spawn_in_term ({"echo", msg});
  730. break;
  731. case Alpm.Event.Type.FILECONFLICTS_START:
  732. msg = dgettext (null, "Checking file conflicts") + "...";
  733. progress_dialog.action_label.set_text (msg);
  734. progress_dialog.spawn_in_term ({"echo", msg});
  735. break;
  736. case Alpm.Event.Type.RESOLVEDEPS_START:
  737. msg = dgettext (null, "Resolving dependencies") + "...";
  738. progress_dialog.action_label.set_text (msg);
  739. progress_dialog.spawn_in_term ({"echo", msg});
  740. break;
  741. case Alpm.Event.Type.INTERCONFLICTS_START:
  742. msg = dgettext (null, "Checking inter-conflicts") + "...";
  743. progress_dialog.action_label.set_text (msg);
  744. progress_dialog.spawn_in_term ({"echo", msg});
  745. break;
  746. case Alpm.Event.Type.TRANSACTION_START:
  747. progress_dialog.cancel_button.set_visible (false);
  748. break;
  749. case Alpm.Event.Type.PACKAGE_OPERATION_START:
  750. switch (secondary_event) {
  751. case Alpm.Package.Operation.INSTALL:
  752. previous_filename = details[0];
  753. msg = dgettext (null, "Installing %s").printf (details[0]) + "...";
  754. progress_dialog.action_label.set_text (msg);
  755. msg = dgettext (null, "Installing %s").printf ("%s (%s)".printf (details[0], details[1]))+ "...";
  756. progress_dialog.spawn_in_term ({"echo", msg});
  757. break;
  758. case Alpm.Package.Operation.REINSTALL:
  759. previous_filename = details[0];
  760. msg = dgettext (null, "Reinstalling %s").printf (details[0]) + "...";
  761. progress_dialog.action_label.set_text (msg);
  762. msg = dgettext (null, "Reinstalling %s").printf ("%s (%s)".printf (details[0], details[1]))+ "...";
  763. progress_dialog.spawn_in_term ({"echo", msg});
  764. break;
  765. case Alpm.Package.Operation.REMOVE:
  766. previous_filename = details[0];
  767. msg = dgettext (null, "Removing %s").printf (details[0]) + "...";
  768. progress_dialog.action_label.set_text (msg);
  769. msg = dgettext (null, "Removing %s").printf ("%s (%s)".printf (details[0], details[1]))+ "...";
  770. progress_dialog.spawn_in_term ({"echo", msg});
  771. break;
  772. case Alpm.Package.Operation.UPGRADE:
  773. previous_filename = details[0];
  774. msg = dgettext (null, "Upgrading %s").printf (details[0]) + "...";
  775. progress_dialog.action_label.set_text (msg);
  776. msg = dgettext (null, "Upgrading %s").printf ("%s (%s -> %s)".printf (details[0], details[1], details[2]))+ "...";
  777. progress_dialog.spawn_in_term ({"echo", msg});
  778. break;
  779. case Alpm.Package.Operation.DOWNGRADE:
  780. previous_filename = details[0];
  781. msg = dgettext (null, "Downgrading %s").printf (details[0]) + "...";
  782. progress_dialog.action_label.set_text (msg);
  783. msg = dgettext (null, "Downgrading %s").printf ("%s (%s -> %s)".printf (details[0], details[1], details[2]))+ "...";
  784. progress_dialog.spawn_in_term ({"echo", msg});
  785. break;
  786. }
  787. break;
  788. case Alpm.Event.Type.INTEGRITY_START:
  789. msg = dgettext (null, "Checking integrity") + "...";
  790. progress_dialog.action_label.set_text (msg);
  791. progress_dialog.spawn_in_term ({"echo", msg});
  792. break;
  793. case Alpm.Event.Type.KEYRING_START:
  794. progress_dialog.cancel_button.set_visible (true);
  795. msg = dgettext (null, "Checking keyring") + "...";
  796. progress_dialog.action_label.set_text (msg);
  797. progress_dialog.spawn_in_term ({"echo", msg});
  798. break;
  799. case Alpm.Event.Type.KEY_DOWNLOAD_START:
  800. msg = dgettext (null, "Downloading required keys") + "...";
  801. progress_dialog.action_label.set_text (msg);
  802. progress_dialog.spawn_in_term ({"echo", msg});
  803. break;
  804. case Alpm.Event.Type.LOAD_START:
  805. msg = dgettext (null, "Loading packages files") + "...";
  806. progress_dialog.action_label.set_text (msg);
  807. progress_dialog.spawn_in_term ({"echo", msg});
  808. break;
  809. case Alpm.Event.Type.DELTA_INTEGRITY_START:
  810. msg = dgettext (null, "Checking delta integrity") + "...";
  811. progress_dialog.action_label.set_text (msg);
  812. progress_dialog.spawn_in_term ({"echo", msg});
  813. break;
  814. case Alpm.Event.Type.DELTA_PATCHES_START:
  815. msg = dgettext (null, "Applying deltas") + "...";
  816. progress_dialog.action_label.set_text (msg);
  817. progress_dialog.spawn_in_term ({"echo", msg});
  818. break;
  819. case Alpm.Event.Type.DELTA_PATCH_START:
  820. msg = dgettext (null, "Generating %s with %s").printf (details[0], details[1]) + "...";
  821. progress_dialog.action_label.set_text (msg);
  822. progress_dialog.spawn_in_term ({"echo", msg});
  823. break;
  824. case Alpm.Event.Type.DELTA_PATCH_DONE:
  825. msg = dgettext (null, "Generation succeeded") + "...";
  826. progress_dialog.action_label.set_text (msg);
  827. progress_dialog.spawn_in_term ({"echo", msg});
  828. break;
  829. case Alpm.Event.Type.DELTA_PATCH_FAILED:
  830. msg = dgettext (null, "Generation failed") + "...";
  831. progress_dialog.action_label.set_text (msg);
  832. progress_dialog.spawn_in_term ({"echo", msg});
  833. break;
  834. case Alpm.Event.Type.SCRIPTLET_INFO:
  835. progress_dialog.action_label.set_text (dgettext (null, "Configuring %s").printf (previous_filename) + "...");
  836. progress_dialog.expander.set_expanded (true);
  837. progress_dialog.spawn_in_term ({"echo", "-n", details[0]});
  838. break;
  839. case Alpm.Event.Type.RETRIEVE_START:
  840. progress_dialog.cancel_button.set_visible (true);
  841. msg = dgettext (null, "Downloading") + "...";
  842. progress_dialog.action_label.set_text (msg);
  843. progress_dialog.spawn_in_term ({"echo", msg});
  844. break;
  845. case Alpm.Event.Type.DISKSPACE_START:
  846. msg = dgettext (null, "Checking available disk space") + "...";
  847. progress_dialog.action_label.set_text (msg);
  848. progress_dialog.spawn_in_term ({"echo", msg});
  849. break;
  850. case Alpm.Event.Type.OPTDEP_REMOVAL:
  851. msg = dgettext (null, "%s optionally requires %s").printf (details[0], details[1]);
  852. progress_dialog.spawn_in_term ({"echo", msg});
  853. Gtk.TextIter end_iter;
  854. msg += "\n";
  855. transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
  856. transaction_info_dialog.textbuffer.insert (ref end_iter, msg, msg.length);
  857. break;
  858. case Alpm.Event.Type.DATABASE_MISSING:
  859. progress_dialog.spawn_in_term ({"echo", dgettext (null, "Database file for %s does not exist").printf (details[0])});
  860. break;
  861. case Alpm.Event.Type.PACNEW_CREATED:
  862. progress_dialog.spawn_in_term ({"echo", dgettext (null, "%s installed as %s.pacnew").printf (details[0])});
  863. break;
  864. case Alpm.Event.Type.PACSAVE_CREATED:
  865. progress_dialog.spawn_in_term ({"echo", dgettext (null, "%s installed as %s.pacsave").printf (details[0])});
  866. break;
  867. default:
  868. break;
  869. }
  870. while (Gtk.events_pending ()) {
  871. Gtk.main_iteration ();
  872. }
  873. }
  874. void on_emit_providers (string depend, string[] providers) {
  875. choose_provider (depend, providers);
  876. }
  877. void on_emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target) {
  878. float fraction;
  879. switch (progress) {
  880. case Alpm.Progress.ADD_START:
  881. case Alpm.Progress.UPGRADE_START:
  882. case Alpm.Progress.DOWNGRADE_START:
  883. case Alpm.Progress.REINSTALL_START:
  884. case Alpm.Progress.REMOVE_START:
  885. fraction = ((float) (current_target - 1) / n_targets) + ((float) percent / (100 * n_targets));
  886. break;
  887. case Alpm.Progress.CONFLICTS_START:
  888. case Alpm.Progress.DISKSPACE_START:
  889. case Alpm.Progress.INTEGRITY_START:
  890. case Alpm.Progress.KEYRING_START:
  891. case Alpm.Progress.LOAD_START:
  892. default:
  893. fraction = (float) percent / 100;
  894. break;
  895. }
  896. string textbar = "%lu/%lu".printf (current_target, n_targets);
  897. if (textbar != previous_textbar) {
  898. previous_textbar = textbar;
  899. progress_dialog.progressbar.set_text (textbar);
  900. }
  901. if (fraction != previous_percent) {
  902. previous_percent = fraction;
  903. progress_dialog.progressbar.set_fraction (fraction);
  904. }
  905. //~ while (Gtk.events_pending ()) {
  906. //~ Gtk.main_iteration ();
  907. //~ }
  908. }
  909. void on_emit_download (string filename, uint64 xfered, uint64 total) {
  910. string label;
  911. var text = new StringBuilder ();
  912. float fraction;
  913. if (filename != previous_filename) {
  914. previous_filename = filename;
  915. if (filename.has_suffix (".db")) {
  916. label = dgettext (null, "Refreshing %s").printf (filename.replace (".db", "")) + "...";
  917. } else {
  918. label = dgettext (null, "Downloading %s").printf (filename.replace (".pkg.tar.xz", "")) + "...";
  919. }
  920. if (label != previous_label) {
  921. previous_label = label;
  922. progress_dialog.action_label.set_text (label);
  923. progress_dialog.spawn_in_term ({"echo", label});
  924. }
  925. }
  926. if (total_download > 0) {
  927. if (xfered == 0) {
  928. previous_xfered = 0;
  929. fraction = previous_percent;
  930. text.append (previous_textbar);
  931. timer.start ();
  932. } else {
  933. if (timer.elapsed () > 0) {
  934. download_rate = ((download_rate * rates_nb) + (uint64) ((xfered - previous_xfered) / timer.elapsed ())) / (rates_nb + 1);
  935. rates_nb++;
  936. }
  937. previous_xfered = xfered;
  938. uint64 downloaded_total = xfered + already_downloaded;
  939. fraction = (float) downloaded_total / total_download;
  940. if (fraction <= 1) {
  941. text.append ("%s/%s ".printf (format_size (xfered + already_downloaded), format_size (total_download)));
  942. uint64 remaining_seconds = 0;
  943. if (download_rate > 0) {
  944. remaining_seconds = (total_download - downloaded_total) / download_rate;
  945. }
  946. // display remaining time after 5s and only if more than 10s are remaining
  947. if (remaining_seconds > 9 && rates_nb > 9) {
  948. if (remaining_seconds <= 50) {
  949. text.append (dgettext (null, "About %u seconds remaining").printf ((uint) Math.ceilf ((float) remaining_seconds / 10) * 10));
  950. } else {
  951. uint remaining_minutes = (uint) Math.ceilf ((float) remaining_seconds / 60);
  952. text.append (dngettext (null, "About %lu minute remaining",
  953. "About %lu minutes remaining", remaining_minutes).printf (remaining_minutes));
  954. }
  955. }
  956. } else {
  957. text.append ("%s".printf (format_size (xfered + already_downloaded)));
  958. }
  959. if (xfered == total) {
  960. previous_filename = "";
  961. already_downloaded += total;
  962. } else {
  963. timer.start ();
  964. }
  965. }
  966. } else {
  967. if (xfered == 0) {
  968. previous_xfered = 0;
  969. download_rate = 0;
  970. rates_nb = 0;
  971. fraction = 0;
  972. timer.start ();
  973. } else if (xfered == total) {
  974. timer.stop ();
  975. fraction = 1;
  976. previous_filename = "";
  977. } else {
  978. if (timer.elapsed () > 0) {
  979. download_rate = ((download_rate * rates_nb) + (uint64) ((xfered - previous_xfered) / timer.elapsed ())) / (rates_nb + 1);
  980. rates_nb++;
  981. }
  982. previous_xfered = xfered;
  983. fraction = (float) xfered / total;
  984. if (fraction <= 1) {
  985. text.append ("%s/%s ".printf (format_size (xfered), format_size (total)));
  986. uint64 remaining_seconds = 0;
  987. if (download_rate > 0) {
  988. remaining_seconds = (total - xfered) / download_rate;
  989. }
  990. // display remaining time after 5s and only if more than 10s are remaining
  991. if (remaining_seconds > 9 && rates_nb > 9) {
  992. if (remaining_seconds <= 50) {
  993. text.append (dgettext (null, "About %u seconds remaining").printf ((uint) Math.ceilf ((float) remaining_seconds / 10) * 10));
  994. } else {
  995. uint remaining_minutes = (uint) Math.ceilf ((float) remaining_seconds / 60);
  996. text.append (dngettext (null, "About %lu minute remaining",
  997. "About %lu minutes remaining", remaining_minutes).printf (remaining_minutes));
  998. }
  999. }
  1000. } else {
  1001. text.append ("%s".printf (format_size (xfered)));
  1002. }
  1003. // reinitialize timer
  1004. timer.start ();
  1005. }
  1006. }
  1007. if (fraction != previous_percent) {
  1008. previous_percent = fraction;
  1009. progress_dialog.progressbar.set_fraction (fraction);
  1010. }
  1011. if (text.str != previous_textbar) {
  1012. previous_textbar = text.str;
  1013. progress_dialog.progressbar.set_text (text.str);
  1014. }
  1015. }
  1016. void on_emit_totaldownload (uint64 total) {
  1017. download_rate = 0;
  1018. rates_nb = 0;
  1019. previous_percent = 0;
  1020. previous_textbar = "";
  1021. total_download = total;
  1022. // this is emitted at the end of the total download
  1023. // with the value 0 so stop our timer
  1024. if (total == 0) {
  1025. timer.stop ();
  1026. }
  1027. }
  1028. void on_emit_log (uint level, string msg) {
  1029. // msg ends with \n
  1030. string? line = null;
  1031. Gtk.TextIter end_iter;
  1032. if ((Alpm.LogLevel) level == Alpm.LogLevel.WARNING) {
  1033. // do not show warning when manjaro-system remove db.lck
  1034. if (previous_filename != "manjaro-system") {
  1035. if (previous_filename != "") {
  1036. line = dgettext (null, "Warning") + ": " + previous_filename + ": " + msg;
  1037. } else {
  1038. line = dgettext (null, "Warning") + ": " + msg;
  1039. }
  1040. transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
  1041. transaction_info_dialog.textbuffer.insert (ref end_iter, msg, msg.length);
  1042. }
  1043. } else if ((Alpm.LogLevel) level == Alpm.LogLevel.ERROR) {
  1044. if (previous_filename != "") {
  1045. line = dgettext (null, "Error") + ": " + previous_filename + ": " + msg;
  1046. } else {
  1047. line = dgettext (null, "Error") + ": " + msg;
  1048. }
  1049. }
  1050. if (line != null) {
  1051. progress_dialog.expander.set_expanded (true);
  1052. progress_dialog.spawn_in_term ({"echo", "-n", line});
  1053. }
  1054. }
  1055. void show_warnings () {
  1056. if (transaction_info_dialog.textbuffer.text != "") {
  1057. transaction_info_dialog.set_title (dgettext (null, "Warning"));
  1058. transaction_info_dialog.label.set_visible (false);
  1059. transaction_info_dialog.expander.set_visible (true);
  1060. transaction_info_dialog.expander.set_expanded (true);
  1061. transaction_info_dialog.run ();
  1062. transaction_info_dialog.hide ();
  1063. while (Gtk.events_pending ()) {
  1064. Gtk.main_iteration ();
  1065. }
  1066. Gtk.TextIter start_iter;
  1067. Gtk.TextIter end_iter;
  1068. transaction_info_dialog.textbuffer.get_start_iter (out start_iter);
  1069. transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
  1070. transaction_info_dialog.textbuffer.delete (ref start_iter, ref end_iter);
  1071. }
  1072. }
  1073. void handle_error (ErrorInfos error) {
  1074. if (error.message != "") {
  1075. progress_dialog.action_label.set_text ("");
  1076. progress_dialog.progressbar.set_fraction (0);
  1077. progress_dialog.expander.set_expanded (true);
  1078. progress_dialog.spawn_in_term ({"echo", "-n", error.message});
  1079. Gtk.TextIter start_iter;
  1080. Gtk.TextIter end_iter;
  1081. transaction_info_dialog.set_title (dgettext (null, "Error"));
  1082. transaction_info_dialog.label.set_visible (true);
  1083. transaction_info_dialog.label.set_markup (error.message);
  1084. if (error.details.length != 0) {
  1085. transaction_info_dialog.textbuffer.get_start_iter (out start_iter);
  1086. transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
  1087. transaction_info_dialog.textbuffer.delete (ref start_iter, ref end_iter);
  1088. transaction_info_dialog.expander.set_visible (true);
  1089. transaction_info_dialog.expander.set_expanded (true);
  1090. progress_dialog.spawn_in_term ({"echo", ":"});
  1091. foreach (unowned string detail in error.details) {
  1092. progress_dialog.spawn_in_term ({"echo", detail});
  1093. string str = detail + "\n";
  1094. transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
  1095. transaction_info_dialog.textbuffer.insert (ref end_iter, str, str.length);
  1096. }
  1097. } else {
  1098. transaction_info_dialog.expander.set_visible (false);
  1099. }
  1100. progress_dialog.spawn_in_term ({"echo"});
  1101. transaction_info_dialog.run ();
  1102. transaction_info_dialog.hide ();
  1103. transaction_info_dialog.textbuffer.get_start_iter (out start_iter);
  1104. transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
  1105. transaction_info_dialog.textbuffer.delete (ref start_iter, ref end_iter);
  1106. progress_dialog.spawn_in_term ({"echo"});
  1107. while (Gtk.events_pending ()) {
  1108. Gtk.main_iteration ();
  1109. }
  1110. }
  1111. finish_transaction ();
  1112. }
  1113. void finish_transaction () {
  1114. if (database_modified) {
  1115. alpm_utils.reload ();
  1116. database_modified = false;
  1117. }
  1118. if (progress_dialog.expander.get_expanded ()) {
  1119. progress_dialog.cancel_button.set_visible (false);
  1120. progress_dialog.close_button.set_visible (true);
  1121. } else {
  1122. on_progress_dialog_close_button_clicked ();
  1123. }
  1124. }
  1125. void on_refresh_finished (bool success) {
  1126. this.success = success;
  1127. clear_lists ();
  1128. if (success) {
  1129. // database is modified
  1130. alpm_utils.reload ();
  1131. finished (success);
  1132. if (mode == Mode.UPDATER) {
  1133. progress_dialog.hide ();
  1134. }
  1135. success = false;
  1136. } else {
  1137. database_modified = true;
  1138. handle_error (get_current_error ());
  1139. }
  1140. previous_filename = "";
  1141. daemon.refresh_finished.disconnect (on_refresh_finished);
  1142. }
  1143. void on_progress_dialog_close_button_clicked () {
  1144. finished (success);
  1145. progress_dialog.hide ();
  1146. while (Gtk.events_pending ()) {
  1147. Gtk.main_iteration ();
  1148. }
  1149. success = false;
  1150. }
  1151. void on_progress_dialog_cancel_button_clicked () {
  1152. cancel ();
  1153. clear_lists ();
  1154. progress_dialog.spawn_in_term ({"/usr/bin/echo", dgettext (null, "Transaction cancelled") + ".\n"});
  1155. progress_dialog.hide ();
  1156. while (Gtk.events_pending ()) {
  1157. Gtk.main_iteration ();
  1158. }
  1159. }
  1160. void on_trans_prepare_finished (bool success) {
  1161. this.success = success;
  1162. if (success) {
  1163. show_warnings ();
  1164. Type type = set_transaction_sum ();
  1165. if (type == Type.UPDATE && mode == Mode.UPDATER) {
  1166. // there only updates
  1167. start_commit ();
  1168. } else if (type != 0) {
  1169. if (transaction_sum_dialog.run () == Gtk.ResponseType.OK) {
  1170. transaction_sum_dialog.hide ();
  1171. while (Gtk.events_pending ()) {
  1172. Gtk.main_iteration ();
  1173. }
  1174. if (type == Type.BUILD) {
  1175. // there only AUR packages to build
  1176. release ();
  1177. on_trans_commit_finished (true);
  1178. } else {
  1179. start_commit ();
  1180. }
  1181. } else {
  1182. transaction_sum_dialog.hide ();
  1183. unowned string action = dgettext (null, "Transaction cancelled");
  1184. progress_dialog.spawn_in_term ({"echo", action + ".\n"});
  1185. progress_dialog.action_label.set_text (action);
  1186. release ();
  1187. //to_build.remove_all ();
  1188. sysupgrade_after_trans = false;
  1189. success = false;
  1190. finish_transaction ();
  1191. }
  1192. } else {
  1193. //var err = ErrorInfos ();
  1194. //err.message = dgettext (null, "Nothing to do") + "\n";
  1195. progress_dialog.spawn_in_term ({"echo", dgettext (null, "Nothing to do") + ".\n"});
  1196. release ();
  1197. clear_lists ();
  1198. finish_transaction ();
  1199. //handle_error (err);
  1200. }
  1201. } else {
  1202. handle_error (get_current_error ());
  1203. }
  1204. }
  1205. void on_trans_commit_finished (bool success) {
  1206. this.success = success;
  1207. if (success) {
  1208. if (to_build.length != 0) {
  1209. if (to_add.length != 0
  1210. || to_remove.length != 0
  1211. || to_load.length != 0) {
  1212. progress_dialog.spawn_in_term ({"echo", dgettext (null, "Transaction successfully finished") + ".\n"});
  1213. }
  1214. build_aur_packages ();
  1215. } else {
  1216. clear_lists ();
  1217. show_warnings ();
  1218. if (sysupgrade_after_trans) {
  1219. sysupgrade_after_trans = false;
  1220. sysupgrade (false);
  1221. } else {
  1222. unowned string action = dgettext (null, "Transaction successfully finished");
  1223. progress_dialog.spawn_in_term ({"echo", action + ".\n"});
  1224. progress_dialog.action_label.set_text (action);
  1225. database_modified = true;
  1226. finish_transaction ();
  1227. }
  1228. }
  1229. } else {
  1230. // if it is an authentication or a download error, database was not modified
  1231. var err = get_current_error ();
  1232. if (err.message != dgettext (null, "Authentication failed")
  1233. && err.errno != Alpm.Errno.EXTERNAL_DOWNLOAD) {
  1234. clear_lists ();
  1235. database_modified = true;
  1236. }
  1237. handle_error (err);
  1238. }
  1239. total_download = 0;
  1240. already_downloaded = 0;
  1241. previous_filename = "";
  1242. }
  1243. void on_term_child_exited (int status) {
  1244. Source.remove (pulse_timeout_id);
  1245. clear_lists ();
  1246. // let the time to the daemon to update databases
  1247. Timeout.add (1000, () => {
  1248. if (status == 0) {
  1249. success = true;
  1250. unowned string action = dgettext (null, "Transaction successfully finished");
  1251. progress_dialog.spawn_in_term ({"echo", action + ".\n"});
  1252. progress_dialog.action_label.set_text (action);
  1253. } else {
  1254. success = false;
  1255. progress_dialog.spawn_in_term ({"echo"});
  1256. }
  1257. progress_dialog.progressbar.set_fraction (1);
  1258. alpm_utils.reload ();
  1259. database_modified = false;
  1260. progress_dialog.cancel_button.set_visible (false);
  1261. progress_dialog.close_button.set_visible (true);
  1262. return false;
  1263. });
  1264. }
  1265. void on_set_pkgreason_finished () {
  1266. alpm_utils.reload ();
  1267. set_pkgreason_finished ();
  1268. }
  1269. void on_write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  1270. bool enable_aur, bool search_aur, bool check_aur_updates,
  1271. bool no_confirm_build) {
  1272. pamac_config.reload ();
  1273. write_pamac_config_finished (recurse, refresh_period, no_update_hide_icon,
  1274. enable_aur, search_aur, check_aur_updates,
  1275. no_confirm_build);
  1276. }
  1277. void on_write_alpm_config_finished (bool checkspace) {
  1278. alpm_utils.reload ();
  1279. write_alpm_config_finished (checkspace);
  1280. }
  1281. void on_write_mirrors_config_finished (string choosen_country, string choosen_generation_method) {
  1282. write_mirrors_config_finished (choosen_country, choosen_generation_method);
  1283. }
  1284. void on_generate_mirrors_list_data (string line) {
  1285. progress_dialog.spawn_in_term ({"echo", "-n", line});
  1286. }
  1287. void on_generate_mirrors_list_finished () {
  1288. Source.remove (pulse_timeout_id);
  1289. progress_dialog.spawn_in_term ({"echo"});
  1290. // force a dbs refresh
  1291. start_refresh (true);
  1292. }
  1293. void connecting_dbus_signals () {
  1294. try {
  1295. daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac", "/org/manjaro/pamac");
  1296. // Set environment variables
  1297. daemon.set_environment_variables (pamac_config.environment_variables);
  1298. // Connecting to signals
  1299. daemon.emit_event.connect (on_emit_event);
  1300. daemon.emit_providers.connect (on_emit_providers);
  1301. daemon.emit_progress.connect (on_emit_progress);
  1302. daemon.emit_download.connect (on_emit_download);
  1303. daemon.emit_totaldownload.connect (on_emit_totaldownload);
  1304. daemon.emit_log.connect (on_emit_log);
  1305. daemon.trans_prepare_finished.connect (on_trans_prepare_finished);
  1306. daemon.trans_commit_finished.connect (on_trans_commit_finished);
  1307. daemon.set_pkgreason_finished.connect (on_set_pkgreason_finished);
  1308. daemon.write_mirrors_config_finished.connect (on_write_mirrors_config_finished);
  1309. daemon.write_alpm_config_finished.connect (on_write_alpm_config_finished);
  1310. daemon.write_pamac_config_finished.connect (on_write_pamac_config_finished);
  1311. daemon.generate_mirrors_list_data.connect (on_generate_mirrors_list_data);
  1312. daemon.generate_mirrors_list_finished.connect (on_generate_mirrors_list_finished);
  1313. } catch (IOError e) {
  1314. stderr.printf ("IOError: %s\n", e.message);
  1315. }
  1316. }
  1317. }
  1318. }