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.

transaction.vala 72KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168
  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 1: //Alpm.Event.Type.CHECKDEPS_START
  1411. action = dgettext (null, "Checking dependencies") + "...";
  1412. break;
  1413. case 3: //Alpm.Event.Type.FILECONFLICTS_START
  1414. action = dgettext (null, "Checking file conflicts") + "...";
  1415. break;
  1416. case 5: //Alpm.Event.Type.RESOLVEDEPS_START
  1417. action = dgettext (null, "Resolving dependencies") + "...";
  1418. break;
  1419. case 7: //Alpm.Event.Type.INTERCONFLICTS_START
  1420. action = dgettext (null, "Checking inter-conflicts") + "...";
  1421. break;
  1422. case 11: //Alpm.Event.Type.PACKAGE_OPERATION_START
  1423. switch (secondary_event) {
  1424. // special case handle differently
  1425. case 1: //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 2: //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 3: //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 4: //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 5: //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 13: //Alpm.Event.Type.INTEGRITY_START
  1458. action = dgettext (null, "Checking integrity") + "...";
  1459. break;
  1460. case 15: //Alpm.Event.Type.LOAD_START
  1461. action = dgettext (null, "Loading packages files") + "...";
  1462. break;
  1463. case 17: //Alpm.Event.Type.DELTA_INTEGRITY_START
  1464. action = dgettext (null, "Checking delta integrity") + "...";
  1465. break;
  1466. case 19: //Alpm.Event.Type.DELTA_PATCHES_START
  1467. action = dgettext (null, "Applying deltas") + "...";
  1468. break;
  1469. case 21: //Alpm.Event.Type.DELTA_PATCH_START
  1470. detailed_action = dgettext (null, "Generating %s with %s").printf (details[0], details[1]) + "...";
  1471. break;
  1472. case 22: //Alpm.Event.Type.DELTA_PATCH_DONE
  1473. detailed_action = dgettext (null, "Generation succeeded") + "...";
  1474. break;
  1475. case 23: //Alpm.Event.Type.DELTA_PATCH_FAILED
  1476. detailed_action = dgettext (null, "Generation failed") + "...";
  1477. break;
  1478. case 24: //Alpm.Event.Type.SCRIPTLET_INFO
  1479. // hooks output are also emitted as SCRIPTLET_INFO
  1480. if (previous_filename != "") {
  1481. progress_box.action_label.label = dgettext (null, "Configuring %s").printf (previous_filename) + "...";
  1482. }
  1483. detailed_action = details[0].replace ("\n", "");
  1484. important_details_outpout (false);
  1485. break;
  1486. case 25: //Alpm.Event.Type.RETRIEVE_START
  1487. start_downloading ();
  1488. action = dgettext (null, "Downloading") + "...";
  1489. break;
  1490. case 26: //Alpm.Event.Type.RETRIEVE_DONE
  1491. case 27: //Alpm.Event.Type.RETRIEVE_FAILED
  1492. stop_downloading ();
  1493. break;
  1494. case 28: //Alpm.Event.Type.PKGDOWNLOAD_START
  1495. // special case handle differently
  1496. show_in_term (dgettext (null, "Downloading %s").printf (details[0]) + "...");
  1497. string name_version_release = details[0].slice (0, details[0].last_index_of_char ('-'));
  1498. string name_version = name_version_release.slice (0, name_version_release.last_index_of_char ('-'));
  1499. string name = name_version.slice (0, name_version.last_index_of_char ('-'));
  1500. progress_box.action_label.label = dgettext (null, "Downloading %s").printf (name) + "...";
  1501. break;
  1502. case 31: //Alpm.Event.Type.DISKSPACE_START
  1503. action = dgettext (null, "Checking available disk space") + "...";
  1504. break;
  1505. case 33: //Alpm.Event.Type.OPTDEP_REMOVAL
  1506. detailed_action = dgettext (null, "%s optionally requires %s").printf (details[0], details[1]);
  1507. warning_textbuffer.append (detailed_action + "\n");
  1508. break;
  1509. case 34: //Alpm.Event.Type.DATABASE_MISSING
  1510. detailed_action = dgettext (null, "Database file for %s does not exist").printf (details[0]);
  1511. break;
  1512. case 35: //Alpm.Event.Type.KEYRING_START
  1513. action = dgettext (null, "Checking keyring") + "...";
  1514. break;
  1515. case 37: //Alpm.Event.Type.KEY_DOWNLOAD_START
  1516. action = dgettext (null, "Downloading required keys") + "...";
  1517. break;
  1518. case 39: //Alpm.Event.Type.PACNEW_CREATED
  1519. detailed_action = dgettext (null, "%s installed as %s.pacnew").printf (details[0], details[0]);
  1520. break;
  1521. case 40: //Alpm.Event.Type.PACSAVE_CREATED
  1522. detailed_action = dgettext (null, "%s installed as %s.pacsave").printf (details[0], details[0]);
  1523. break;
  1524. case 41: //Alpm.Event.Type.HOOK_START
  1525. switch (secondary_event) {
  1526. case 1: //Alpm.HookWhen.PRE_TRANSACTION
  1527. action = dgettext (null, "Running pre-transaction hooks") + "...";
  1528. break;
  1529. case 2: //Alpm.HookWhen.POST_TRANSACTION
  1530. previous_filename = "";
  1531. action = dgettext (null, "Running post-transaction hooks") + "...";
  1532. break;
  1533. default:
  1534. break;
  1535. }
  1536. break;
  1537. case 43: // Alpm.Event.Type.HOOK_RUN_START
  1538. float fraction = (float) int.parse (details[2]) / int.parse (details[3]);
  1539. if (fraction != previous_percent) {
  1540. previous_percent = fraction;
  1541. progress_box.progressbar.fraction = fraction;
  1542. }
  1543. string textbar = "%s/%s".printf (details[2], details[3]);
  1544. if (textbar != previous_textbar) {
  1545. previous_textbar = textbar;
  1546. progress_box.progressbar.text = textbar;
  1547. }
  1548. if (details[1] != "") {
  1549. detailed_action = details[1];
  1550. } else {
  1551. detailed_action = details[0];
  1552. }
  1553. break;
  1554. default:
  1555. break;
  1556. }
  1557. if (action != null) {
  1558. progress_box.action_label.label = action;
  1559. show_in_term (action);
  1560. }
  1561. if (detailed_action != null) {
  1562. show_in_term (detailed_action);
  1563. }
  1564. }
  1565. void on_emit_providers (string depend, string[] providers) {
  1566. choose_provider (depend, providers);
  1567. }
  1568. void on_emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target) {
  1569. float fraction;
  1570. switch (progress) {
  1571. case 0: //Alpm.Progress.ADD_START
  1572. case 1: //Alpm.Progress.UPGRADE_START
  1573. case 2: //Alpm.Progress.DOWNGRADE_START
  1574. case 3: //Alpm.Progress.REINSTALL_START
  1575. case 4: //Alpm.Progress.REMOVE_START
  1576. fraction = ((float) (current_target - 1) / n_targets) + ((float) percent / (100 * n_targets));
  1577. break;
  1578. case 5: //Alpm.Progress.CONFLICTS_START
  1579. case 6: //Alpm.Progress.DISKSPACE_START
  1580. case 7: //Alpm.Progress.INTEGRITY_START
  1581. case 8: //Alpm.Progress.LOAD_START
  1582. case 9: //Alpm.Progress.KEYRING_START
  1583. default:
  1584. fraction = (float) percent / 100;
  1585. break;
  1586. }
  1587. string textbar = "%lu/%lu".printf (current_target, n_targets);
  1588. if (textbar != previous_textbar) {
  1589. previous_textbar = textbar;
  1590. progress_box.progressbar.text = textbar;
  1591. }
  1592. if (fraction != previous_percent) {
  1593. previous_percent = fraction;
  1594. progress_box.progressbar.fraction = fraction;
  1595. }
  1596. }
  1597. void on_emit_download (string filename, uint64 xfered, uint64 total) {
  1598. var text = new StringBuilder ();
  1599. float fraction;
  1600. if (total_download > 0) {
  1601. if (xfered == 0) {
  1602. // start download pkg is handled by Alpm.Event.Type.PKGDOWNLOAD_START
  1603. previous_xfered = 0;
  1604. fraction = previous_percent;
  1605. text.append (previous_textbar);
  1606. timer.start ();
  1607. } else {
  1608. if (timer.elapsed () > 0.1) {
  1609. download_rate = ((download_rate * rates_nb) + (uint64) ((xfered - previous_xfered) / timer.elapsed ())) / (rates_nb + 1);
  1610. rates_nb++;
  1611. }
  1612. previous_xfered = xfered;
  1613. uint64 downloaded_total = xfered + already_downloaded;
  1614. fraction = (float) downloaded_total / total_download;
  1615. if (fraction <= 1) {
  1616. text.append ("%s/%s ".printf (format_size (xfered + already_downloaded), format_size (total_download)));
  1617. uint64 remaining_seconds = 0;
  1618. if (download_rate > 0) {
  1619. remaining_seconds = (total_download - downloaded_total) / download_rate;
  1620. }
  1621. // display remaining time after 5s and only if more than 10s are remaining
  1622. if (remaining_seconds > 9 && rates_nb > 9) {
  1623. if (remaining_seconds <= 50) {
  1624. text.append (dgettext (null, "About %u seconds remaining").printf ((uint) Math.ceilf ((float) remaining_seconds / 10) * 10));
  1625. } else {
  1626. uint remaining_minutes = (uint) Math.ceilf ((float) remaining_seconds / 60);
  1627. text.append (dngettext (null, "About %lu minute remaining",
  1628. "About %lu minutes remaining", remaining_minutes).printf (remaining_minutes));
  1629. }
  1630. }
  1631. } else {
  1632. text.append ("%s".printf (format_size (xfered + already_downloaded)));
  1633. }
  1634. if (xfered == total) {
  1635. previous_filename = "";
  1636. already_downloaded += total;
  1637. } else {
  1638. timer.start ();
  1639. }
  1640. }
  1641. } else {
  1642. if (xfered == 0) {
  1643. previous_xfered = 0;
  1644. download_rate = 0;
  1645. rates_nb = 0;
  1646. fraction = 0;
  1647. timer.start ();
  1648. if (filename.has_suffix (".db") || filename.has_suffix (".files")) {
  1649. string action = dgettext (null, "Refreshing %s").printf (filename) + "...";
  1650. reset_progress_box (action);
  1651. }
  1652. } else if (xfered == total) {
  1653. timer.stop ();
  1654. fraction = 1;
  1655. previous_filename = "";
  1656. } else {
  1657. if (timer.elapsed () > 0.1) {
  1658. download_rate = ((download_rate * rates_nb) + (uint64) ((xfered - previous_xfered) / timer.elapsed ())) / (rates_nb + 1);
  1659. rates_nb++;
  1660. }
  1661. previous_xfered = xfered;
  1662. fraction = (float) xfered / total;
  1663. if (fraction <= 1) {
  1664. text.append ("%s/%s ".printf (format_size (xfered), format_size (total)));
  1665. uint64 remaining_seconds = 0;
  1666. if (download_rate > 0) {
  1667. remaining_seconds = (total - xfered) / download_rate;
  1668. }
  1669. // display remaining time after 5s and only if more than 10s are remaining
  1670. if (remaining_seconds > 9 && rates_nb > 9) {
  1671. if (remaining_seconds <= 50) {
  1672. text.append (dgettext (null, "About %u seconds remaining").printf ((uint) Math.ceilf ((float) remaining_seconds / 10) * 10));
  1673. } else {
  1674. uint remaining_minutes = (uint) Math.ceilf ((float) remaining_seconds / 60);
  1675. text.append (dngettext (null, "About %lu minute remaining",
  1676. "About %lu minutes remaining", remaining_minutes).printf (remaining_minutes));
  1677. }
  1678. }
  1679. } else {
  1680. text.append ("%s".printf (format_size (xfered)));
  1681. }
  1682. // reinitialize timer
  1683. timer.start ();
  1684. }
  1685. }
  1686. if (fraction != previous_percent) {
  1687. previous_percent = fraction;
  1688. progress_box.progressbar.fraction = fraction;
  1689. }
  1690. if (text.str != previous_textbar) {
  1691. previous_textbar = text.str;
  1692. progress_box.progressbar.text = text.str;
  1693. }
  1694. }
  1695. void on_emit_totaldownload (uint64 total) {
  1696. download_rate = 0;
  1697. rates_nb = 0;
  1698. previous_percent = 0;
  1699. previous_textbar = "";
  1700. total_download = total;
  1701. // this is emitted at the end of the total download
  1702. // with the value 0 so stop our timer
  1703. if (total == 0) {
  1704. timer.stop ();
  1705. progress_box.progressbar.text = "";
  1706. }
  1707. }
  1708. void on_emit_log (uint level, string msg) {
  1709. // msg ends with \n
  1710. string? line = null;
  1711. if (level == 1) { //Alpm.LogLevel.ERROR
  1712. if (previous_filename != "") {
  1713. line = dgettext (null, "Error") + ": " + previous_filename + ": " + msg;
  1714. } else {
  1715. line = dgettext (null, "Error") + ": " + msg;
  1716. }
  1717. important_details_outpout (false);
  1718. } else if (level == (1 << 1)) { //Alpm.LogLevel.WARNING
  1719. // do not show warning when manjaro-system remove db.lck
  1720. if (previous_filename != "manjaro-system") {
  1721. if (previous_filename != "") {
  1722. line = dgettext (null, "Warning") + ": " + previous_filename + ": " + msg;
  1723. } else {
  1724. line = dgettext (null, "Warning") + ": " + msg;
  1725. }
  1726. warning_textbuffer.append (msg);
  1727. }
  1728. }
  1729. if (line != null) {
  1730. show_in_term (line.replace ("\n", ""));
  1731. }
  1732. }
  1733. void show_warnings () {
  1734. if (warning_textbuffer.len > 0) {
  1735. var flags = Gtk.DialogFlags.MODAL;
  1736. int use_header_bar;
  1737. Gtk.Settings.get_default ().get ("gtk-dialogs-use-header", out use_header_bar);
  1738. if (use_header_bar == 1) {
  1739. flags |= Gtk.DialogFlags.USE_HEADER_BAR;
  1740. }
  1741. var dialog = new Gtk.Dialog.with_buttons (dgettext (null, "Warning"),
  1742. application_window,
  1743. flags);
  1744. dialog.border_width = 6;
  1745. dialog.icon_name = "system-software-install";
  1746. dialog.deletable = false;
  1747. unowned Gtk.Widget widget = dialog.add_button (dgettext (null, "_Close"), Gtk.ResponseType.CLOSE);
  1748. widget.can_focus = true;
  1749. widget.has_focus = true;
  1750. widget.can_default = true;
  1751. widget.has_default = true;
  1752. var scrolledwindow = new Gtk.ScrolledWindow (null, null);
  1753. var label = new Gtk.Label (warning_textbuffer.str);
  1754. label.margin = 12;
  1755. scrolledwindow.visible = true;
  1756. label.visible = true;
  1757. scrolledwindow.add (label);
  1758. scrolledwindow.expand = true;
  1759. unowned Gtk.Box box = dialog.get_content_area ();
  1760. box.add (scrolledwindow);
  1761. dialog.default_width = 600;
  1762. dialog.default_height = 300;
  1763. dialog.run ();
  1764. dialog.destroy ();
  1765. warning_textbuffer = new StringBuilder ();
  1766. }
  1767. }
  1768. public void display_error (string message, string[] details) {
  1769. var flags = Gtk.DialogFlags.MODAL;
  1770. int use_header_bar;
  1771. Gtk.Settings.get_default ().get ("gtk-dialogs-use-header", out use_header_bar);
  1772. if (use_header_bar == 1) {
  1773. flags |= Gtk.DialogFlags.USE_HEADER_BAR;
  1774. }
  1775. var dialog = new Gtk.Dialog.with_buttons (message,
  1776. application_window,
  1777. flags);
  1778. dialog.border_width = 6;
  1779. dialog.icon_name = "system-software-install";
  1780. var textbuffer = new StringBuilder ();
  1781. if (details.length != 0) {
  1782. show_in_term (message + ":");
  1783. foreach (unowned string detail in details) {
  1784. show_in_term (detail);
  1785. textbuffer.append (detail + "\n");
  1786. }
  1787. } else {
  1788. show_in_term (message);
  1789. textbuffer.append (message);
  1790. }
  1791. dialog.deletable = false;
  1792. unowned Gtk.Widget widget = dialog.add_button (dgettext (null, "_Close"), Gtk.ResponseType.CLOSE);
  1793. widget.can_focus = true;
  1794. widget.has_focus = true;
  1795. widget.can_default = true;
  1796. widget.has_default = true;
  1797. var scrolledwindow = new Gtk.ScrolledWindow (null, null);
  1798. var label = new Gtk.Label (textbuffer.str);
  1799. label.margin = 12;
  1800. scrolledwindow.visible = true;
  1801. label.visible = true;
  1802. scrolledwindow.add (label);
  1803. scrolledwindow.expand = true;
  1804. unowned Gtk.Box box = dialog.get_content_area ();
  1805. box.add (scrolledwindow);
  1806. dialog.default_width = 600;
  1807. dialog.default_height = 300;
  1808. dialog.run ();
  1809. dialog.destroy ();
  1810. }
  1811. void handle_error (ErrorInfos error) {
  1812. if (error.message != "") {
  1813. reset_progress_box ("");
  1814. display_error (error.message, error.details);
  1815. }
  1816. finish_transaction ();
  1817. }
  1818. void finish_transaction () {
  1819. disconnecting_dbus_signals ();
  1820. transaction_summary.remove_all ();
  1821. reset_progress_box ("");
  1822. finished (success);
  1823. success = false;
  1824. }
  1825. void on_refresh_finished (bool success) {
  1826. stop_progressbar_pulse ();
  1827. this.success = success;
  1828. if (success) {
  1829. finished (success);
  1830. reset_progress_box ("");
  1831. success = false;
  1832. } else {
  1833. handle_error (get_current_error ());
  1834. }
  1835. previous_filename = "";
  1836. disconnecting_dbus_signals ();
  1837. system_daemon.refresh_finished.disconnect (on_refresh_finished);
  1838. }
  1839. void on_trans_prepare_finished (bool success) {
  1840. stop_progressbar_pulse ();
  1841. this.success = success;
  1842. if (success) {
  1843. show_warnings ();
  1844. Type type = set_transaction_sum ();
  1845. if (mode != Mode.INSTALLER && (no_confirm_commit || type == Type.UPDATE)) {
  1846. // no_confirm_commit or only updates
  1847. to_install.remove_all ();
  1848. start_commit ();
  1849. } else if (type != 0) {
  1850. if (transaction_sum_dialog.run () == Gtk.ResponseType.OK) {
  1851. transaction_sum_dialog.hide ();
  1852. while (Gtk.events_pending ()) {
  1853. Gtk.main_iteration ();
  1854. }
  1855. #if DISABLE_AUR
  1856. #else
  1857. if (type == Type.BUILD) {
  1858. // there only AUR packages to build
  1859. release ();
  1860. on_trans_commit_finished (true);
  1861. } else {
  1862. #endif
  1863. // backup to_install and to_remove
  1864. foreach (unowned string name in to_install) {
  1865. previous_to_install.add (name);
  1866. }
  1867. foreach (unowned string name in to_remove) {
  1868. previous_to_remove.add (name);
  1869. }
  1870. to_install.remove_all ();
  1871. to_remove.remove_all ();
  1872. start_commit ();
  1873. #if DISABLE_AUR
  1874. #else
  1875. }
  1876. #endif
  1877. } else {
  1878. transaction_sum_dialog.hide ();
  1879. unowned string action = dgettext (null, "Transaction cancelled");
  1880. show_in_term (action + ".\n");
  1881. progress_box.action_label.label = action;
  1882. release ();
  1883. transaction_summary.remove_all ();
  1884. #if DISABLE_AUR
  1885. #else
  1886. to_build_queue.clear ();
  1887. #endif
  1888. sysupgrade_after_trans = false;
  1889. success = false;
  1890. finish_transaction ();
  1891. }
  1892. #if DISABLE_AUR
  1893. #else
  1894. } else if (build_after_sysupgrade) {
  1895. // there only AUR packages to build
  1896. release ();
  1897. on_trans_commit_finished (true);
  1898. #endif
  1899. } else {
  1900. //var err = ErrorInfos ();
  1901. //err.message = dgettext (null, "Nothing to do") + "\n";
  1902. show_in_term (dgettext (null, "Nothing to do") + ".\n");
  1903. release ();
  1904. clear_lists ();
  1905. finish_transaction ();
  1906. //handle_error (err);
  1907. }
  1908. } else {
  1909. to_load.remove_all ();
  1910. warning_textbuffer = new StringBuilder ();
  1911. handle_error (get_current_error ());
  1912. }
  1913. }
  1914. void on_trans_commit_finished (bool success) {
  1915. this.success = success;
  1916. // needed before build_aur_packages and remove_makedeps
  1917. no_confirm_commit = false;
  1918. if (success) {
  1919. show_warnings ();
  1920. to_load.remove_all ();
  1921. #if DISABLE_AUR
  1922. #else
  1923. if (to_build_queue.get_length () != 0) {
  1924. show_in_term ("");
  1925. clear_previous_lists ();
  1926. check_authorization.begin ((obj, res) => {
  1927. bool authorized = check_authorization.end (res);
  1928. if (authorized) {
  1929. build_aur_packages.begin ();
  1930. } else {
  1931. to_build_queue.clear ();
  1932. on_trans_commit_finished (false);
  1933. }
  1934. });
  1935. } else {
  1936. #endif
  1937. clear_previous_lists ();
  1938. if (sysupgrade_after_trans) {
  1939. sysupgrade_after_trans = false;
  1940. sysupgrade (false);
  1941. #if DISABLE_AUR
  1942. #else
  1943. } else if (build_after_sysupgrade) {
  1944. build_after_sysupgrade = false;
  1945. disconnecting_dbus_signals ();
  1946. // build aur updates in to_build
  1947. run ();
  1948. #endif
  1949. } else {
  1950. unowned string action = dgettext (null, "Transaction successfully finished");
  1951. show_in_term (action + ".\n");
  1952. progress_box.action_label.label = action;
  1953. finish_transaction ();
  1954. }
  1955. #if DISABLE_AUR
  1956. #else
  1957. }
  1958. #endif
  1959. } else {
  1960. // if it is an authentication or a download error, database was not modified
  1961. var err = get_current_error ();
  1962. if (err.message == dgettext (null, "Authentication failed")
  1963. || err.errno == 54) { //Alpm.Errno.EXTERNAL_DOWNLOAD
  1964. // recover old pkgnames
  1965. foreach (unowned string name in previous_to_install) {
  1966. to_install.add (name);
  1967. }
  1968. foreach (unowned string name in previous_to_remove) {
  1969. to_remove.add (name);
  1970. }
  1971. } else {
  1972. to_load.remove_all ();
  1973. }
  1974. clear_previous_lists ();
  1975. #if DISABLE_AUR
  1976. #else
  1977. to_build_queue.clear ();
  1978. #endif
  1979. warning_textbuffer = new StringBuilder ();
  1980. handle_error (err);
  1981. }
  1982. total_download = 0;
  1983. already_downloaded = 0;
  1984. previous_filename = "";
  1985. }
  1986. void on_set_pkgreason_finished () {
  1987. system_daemon.set_pkgreason_finished.disconnect (on_set_pkgreason_finished);
  1988. set_pkgreason_finished ();
  1989. }
  1990. #if DISABLE_AUR
  1991. void on_save_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon) {
  1992. #else
  1993. void on_save_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  1994. bool enable_aur, bool search_aur, string aur_build_dir, bool check_aur_updates) {
  1995. #endif
  1996. system_daemon.save_pamac_config_finished.disconnect (on_save_pamac_config_finished);
  1997. pamac_config.reload ();
  1998. flags = (1 << 4); //Alpm.TransFlag.CASCADE
  1999. if (pamac_config.recurse) {
  2000. flags |= (1 << 5); //Alpm.TransFlag.RECURSE
  2001. }
  2002. #if DISABLE_AUR
  2003. save_pamac_config_finished (recurse, refresh_period, no_update_hide_icon);
  2004. #else
  2005. save_pamac_config_finished (recurse, refresh_period, no_update_hide_icon,
  2006. enable_aur, search_aur, aur_build_dir, check_aur_updates);
  2007. #endif
  2008. }
  2009. void on_write_alpm_config_finished (bool checkspace) {
  2010. refresh_handle ();
  2011. system_daemon.write_alpm_config_finished.disconnect (on_write_alpm_config_finished);
  2012. write_alpm_config_finished (checkspace);
  2013. }
  2014. void on_write_mirrors_config_finished (string choosen_country, string choosen_generation_method) {
  2015. system_daemon.write_mirrors_config_finished.disconnect (on_write_mirrors_config_finished);
  2016. write_mirrors_config_finished (choosen_country, choosen_generation_method);
  2017. }
  2018. void on_generate_mirrors_list_data (string line) {
  2019. show_in_term (line);
  2020. }
  2021. void on_generate_mirrors_list_finished () {
  2022. refresh_handle ();
  2023. system_daemon.generate_mirrors_list_data.disconnect (on_generate_mirrors_list_data);
  2024. system_daemon.generate_mirrors_list_finished.disconnect (on_generate_mirrors_list_finished);
  2025. reset_progress_box ("");
  2026. }
  2027. void connecting_user_daemon () {
  2028. try {
  2029. user_daemon = Bus.get_proxy_sync (BusType.SESSION, "org.pamac.user", "/org/pamac/user");
  2030. } catch (IOError e) {
  2031. stderr.printf ("IOError: %s\n", e.message);
  2032. }
  2033. }
  2034. void connecting_system_daemon () {
  2035. try {
  2036. system_daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.pamac.system", "/org/pamac/system");
  2037. // Set environment variables
  2038. system_daemon.set_environment_variables (pamac_config.environment_variables);
  2039. } catch (IOError e) {
  2040. stderr.printf ("IOError: %s\n", e.message);
  2041. } catch (DBusError e) {
  2042. stderr.printf ("DBusError: %s\n", e.message);
  2043. }
  2044. }
  2045. void connecting_dbus_signals () {
  2046. system_daemon.emit_event.connect (on_emit_event);
  2047. system_daemon.emit_providers.connect (on_emit_providers);
  2048. system_daemon.emit_progress.connect (on_emit_progress);
  2049. system_daemon.emit_download.connect (on_emit_download);
  2050. system_daemon.emit_totaldownload.connect (on_emit_totaldownload);
  2051. system_daemon.emit_log.connect (on_emit_log);
  2052. system_daemon.trans_prepare_finished.connect (on_trans_prepare_finished);
  2053. system_daemon.trans_commit_finished.connect (on_trans_commit_finished);
  2054. }
  2055. void disconnecting_dbus_signals () {
  2056. system_daemon.emit_event.disconnect (on_emit_event);
  2057. system_daemon.emit_providers.disconnect (on_emit_providers);
  2058. system_daemon.emit_progress.disconnect (on_emit_progress);
  2059. system_daemon.emit_download.disconnect (on_emit_download);
  2060. system_daemon.emit_totaldownload.disconnect (on_emit_totaldownload);
  2061. system_daemon.emit_log.disconnect (on_emit_log);
  2062. system_daemon.trans_prepare_finished.disconnect (on_trans_prepare_finished);
  2063. system_daemon.trans_commit_finished.disconnect (on_trans_commit_finished);
  2064. }
  2065. }
  2066. }