From bd084718ffc28e22090a13a131bc38c98d65d6d1 Mon Sep 17 00:00:00 2001
From: guinux <nuxgui@gmail.com>
Date: Wed, 18 May 2016 16:25:31 +0200
Subject: [PATCH] fix installer

---
 resources/Makefile                      | 12 +++-
 resources/pamac.installer.gresource.xml |  6 ++
 resources/progress_dialog.ui            | 83 ++++++++++---------------
 src/Makefile                            |  8 ++-
 src/installer.vala                      | 29 ++++++++-
 src/progress_dialog.vala                | 11 ++--
 6 files changed, 84 insertions(+), 65 deletions(-)
 create mode 100644 resources/pamac.installer.gresource.xml

diff --git a/resources/Makefile b/resources/Makefile
index ac843baa..1007b0d8 100644
--- a/resources/Makefile
+++ b/resources/Makefile
@@ -11,8 +11,9 @@ MANAGER_RESOURCES_FILES = 	manager_window.ui \
 
 UPDATER_RESOURCES_FILES = 	updater_window.ui
 
-TRANSACTION_RESOURCES_FILES = 	progress_dialog.ui \
-								progress_box.ui \
+INSTALLER_RESOURCES_FILES = 	progress_dialog.ui
+
+TRANSACTION_RESOURCES_FILES = 	progress_box.ui \
 								choose_provider_dialog.ui \
 								transaction_sum_dialog.ui \
 								preferences_dialog.ui \
@@ -24,7 +25,9 @@ MANAGER_GRESOURCE_FILE = pamac.manager.gresource.xml
 
 UPDATER_GRESOURCE_FILE = pamac.updater.gresource.xml
 
-resources: transaction_resources.c manager_resources.c updater_resources.c
+INSTALLER_GRESOURCE_FILE = pamac.installer.gresource.xml
+
+resources: transaction_resources.c manager_resources.c updater_resources.c installer_resources.c
 
 clean:
 	rm -f *.c
@@ -37,3 +40,6 @@ manager_resources.c: $(MANAGER_GRESOURCE_FILE) $(MANAGER_RESOURCES_FILES)
 
 updater_resources.c: $(UPDATER_GRESOURCE_FILE) $(UPDATER_RESOURCES_FILES)
 	glib-compile-resources $(UPDATER_GRESOURCE_FILE) --target=updater_resources.c --generate-source
+
+installer_resources.c: $(INSTALLER_GRESOURCE_FILE) $(INSTALLER_RESOURCES_FILE)
+	glib-compile-resources $(INSTALLER_GRESOURCE_FILE) --target=installer_resources.c --generate-source
diff --git a/resources/pamac.installer.gresource.xml b/resources/pamac.installer.gresource.xml
new file mode 100644
index 00000000..a4e7da0f
--- /dev/null
+++ b/resources/pamac.installer.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/manjaro/pamac/installer">
+    <file preprocess="xml-stripblanks">progress_dialog.ui</file>
+  </gresource>
+</gresources>
diff --git a/resources/progress_dialog.ui b/resources/progress_dialog.ui
index 8018d308..4aef5f90 100644
--- a/resources/progress_dialog.ui
+++ b/resources/progress_dialog.ui
@@ -2,61 +2,20 @@
 <!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.12"/>
-  <template class="PamacProgressDialog" parent="GtkDialog">
+  <template class="PamacProgressDialog" parent="GtkApplicationWindow">
     <property name="can_focus">False</property>
-    <property name="border_width">3</property>
+    <property name="border_width">6</property>
     <property name="title" translatable="yes">Progress</property>
-    <property name="window_position">center-on-parent</property>
+    <property name="window_position">center</property>
     <property name="default_width">600</property>
     <property name="icon_name">system-software-install</property>
-    <property name="type_hint">dialog</property>
     <property name="deletable">False</property>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox1">
+    <child>
+      <object class="GtkBox" id="box">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">12</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="cancel_button">
-                <property name="label" translatable="yes">_Cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="close_button">
-                <property name="label" translatable="yes">_Hide</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
         <child>
           <placeholder/>
         </child>
@@ -79,14 +38,36 @@
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">3</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButtonBox" id="button_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="close_button">
+                <property name="label" translatable="yes">_Close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
           </packing>
         </child>
       </object>
     </child>
-    <action-widgets>
-      <action-widget response="-6">cancel_button</action-widget>
-      <action-widget response="-7">close_button</action-widget>
-    </action-widgets>
   </template>
 </interface>
diff --git a/src/Makefile b/src/Makefile
index dcd085e5..085149ed 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -28,8 +28,7 @@ TRANSACTION_SOURCES = 	package.vala \
 						history_dialog.vala \
 						choose_provider_dialog.vala \
 						transaction_sum_dialog.vala \
-						progress_box.vala \
-						progress_dialog.vala
+						progress_box.vala
 
 PREFERENCES_SOURCES = 	preferences_dialog.vala \
 						choose_ignorepkgs_dialog.vala \
@@ -119,10 +118,13 @@ pamac-updater: libpamac.so ../resources/updater_resources.c updater_window.vala
 			updater_window.vala \
 			updater.vala
 
-pamac-install: libpamac.so installer.vala
+pamac-install: libpamac.so ../resources/installer_resources.c progress_dialog.vala installer.vala
 	valac 	-o pamac-install \
 			$(COMMON_VALA_FLAGS) \
 			$(PAMAC_LIB_FLAGS) \
 			--pkg=json-glib-1.0 \
 			--pkg=gtk+-3.0 \
+			--gresources=$(INSTALLER_GRESOURCE_FILE) \
+			../resources/installer_resources.c \
+			progress_dialog.vala \
 			installer.vala
diff --git a/src/installer.vala b/src/installer.vala
index aa05bb47..e2b95638 100644
--- a/src/installer.vala
+++ b/src/installer.vala
@@ -21,7 +21,9 @@ namespace Pamac {
 
 	public class Installer: Gtk.Application {
 		Transaction transaction;
+		ProgressDialog progress_dialog;
 		bool pamac_run;
+		bool important_details;
 
 		public Installer () {
 			application_id = "org.manjaro.pamac.install";
@@ -45,8 +47,17 @@ namespace Pamac {
 				msg.run ();
 				msg.destroy ();
 			} else {
-				transaction = new Pamac.Transaction (null);
+				important_details = false;
+				// integrate progress box and term widget
+				progress_dialog = new ProgressDialog ();
+				transaction = new Pamac.Transaction (progress_dialog as Gtk.ApplicationWindow);
 				transaction.finished.connect (on_transaction_finished);
+				transaction.important_details_outpout.connect (on_important_details_outpout);
+				progress_dialog.box.pack_start (transaction.progress_box);
+				progress_dialog.box.reorder_child (transaction.progress_box, 0);
+				progress_dialog.expander.add (transaction.term_grid);
+				progress_dialog.close_button.clicked.connect (on_close_button_clicked);
+				progress_dialog.close_button.visible = false;
 				this.hold ();
 			}
 		}
@@ -65,6 +76,7 @@ namespace Pamac {
 					transaction.to_load.add (file.get_path ());
 				}
 				transaction.run ();
+				progress_dialog.show ();
 			}
 		}
 
@@ -91,9 +103,22 @@ namespace Pamac {
 			return run;
 		}
 
+		void on_important_details_outpout (bool must_show) {
+			important_details = true;
+			progress_dialog.expander.expanded = true;
+		}
+
+		void on_close_button_clicked () {
+			this.release ();
+		}
+
 		void on_transaction_finished () {
 			transaction.stop_daemon ();
-			this.release ();
+			if (important_details) {
+				progress_dialog.close_button.visible = true;
+			} else {
+				this.release ();
+			}
 		}
 
 		public static int main (string[] args) {
diff --git a/src/progress_dialog.vala b/src/progress_dialog.vala
index b713b624..058f0223 100644
--- a/src/progress_dialog.vala
+++ b/src/progress_dialog.vala
@@ -19,19 +19,18 @@
 
 namespace Pamac {
 
-	[GtkTemplate (ui = "/org/manjaro/pamac/transaction/progress_dialog.ui")]
-	class ProgressDialog : Gtk.Dialog {
+	[GtkTemplate (ui = "/org/manjaro/pamac/installer/progress_dialog.ui")]
+	class ProgressDialog : Gtk.ApplicationWindow {
 
 		[GtkChild]
-		public Gtk.Button cancel_button;
+		public Gtk.Box box;
 		[GtkChild]
 		public Gtk.Button close_button;
 		[GtkChild]
 		public Gtk.Expander expander;
 
-		public ProgressDialog (Gtk.ApplicationWindow? window) {
-			Object (transient_for: window, use_header_bar: 1);
-
+		public ProgressDialog () {
+			Object ();
 		}
 
 	}
-- 
GitLab