From af68b178a1129e73ee8a5713dc07c0135df17707 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Tue, 19 Sep 2006 08:17:36 +0000
Subject: [PATCH] add progressbar in vcard window and hide it when we get vcard
 and os info. For #1840

---
 data/glade/vcard_information_window.glade | 15 +++++++++++++++
 src/common/connection_handlers.py         |  6 ++++++
 src/gajim.py                              |  1 +
 src/vcard.py                              | 22 ++++++++++++++++++++++
 4 files changed, 44 insertions(+)

diff --git a/data/glade/vcard_information_window.glade b/data/glade/vcard_information_window.glade
index 79d0aa1353..34b6da092e 100644
--- a/data/glade/vcard_information_window.glade
+++ b/data/glade/vcard_information_window.glade
@@ -2553,6 +2553,21 @@
 	  <property name="fill">True</property>
 	</packing>
       </child>
+
+      <child>
+	<widget class="GtkProgressBar" id="progressbar">
+	  <property name="visible">True</property>
+	  <property name="orientation">GTK_PROGRESS_LEFT_TO_RIGHT</property>
+	  <property name="fraction">0</property>
+	  <property name="pulse_step">0.10000000149</property>
+	  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">False</property>
+	</packing>
+      </child>
     </widget>
   </child>
 </widget>
diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index 8b249fc60d..c29cf539a1 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -1134,6 +1134,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
 		raise common.xmpp.NodeProcessed
 
 	def _ErrorCB(self, con, iq_obj):
+		gajim.log.debug('ErrorCB')
+		if iq_obj.getQueryNS() == common.xmpp.NS_VERSION:
+			who = helpers.get_full_jid_from_iq(iq_obj)
+			jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who)
+			self.dispatch('OS_INFO', (jid_stripped, resource, '', ''))
+			return
 		errmsg = iq_obj.getErrorMsg()
 		errcode = iq_obj.getErrorCode()
 		jid_from = helpers.get_full_jid_from_iq(iq_obj)
diff --git a/src/gajim.py b/src/gajim.py
index 4a602a397c..609fafd13e 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -850,6 +850,7 @@ class Interface:
 			self.remote_ctrl.raise_signal('LastStatusTime', (account, array))
 
 	def handle_event_os_info(self, account, array):
+		#'OS_INFO' (account, (jid, resource, client_info, os_info))
 		win = None
 		if self.instances[account]['infos'].has_key(array[0]):
 			win = self.instances[account]['infos'][array[0]]
diff --git a/src/vcard.py b/src/vcard.py
index ee36e1e330..bdee6b1db9 100644
--- a/src/vcard.py
+++ b/src/vcard.py
@@ -61,6 +61,7 @@ class VcardWindow:
 		# the contact variable is the jid if vcard is true
 		self.xml = gtkgui_helpers.get_glade('vcard_information_window.glade')
 		self.window = self.xml.get_widget('vcard_information_window')
+		self.progressbar = self.xml.get_widget('progressbar')
 
 		self.contact = contact
 		self.account = account
@@ -68,13 +69,23 @@ class VcardWindow:
 
 		self.avatar_mime_type = None
 		self.avatar_encoded = None
+		self.vcard_arrived = False
+		self.os_info_arrived = False
+		self.update_progressbar_timeout_id = gobject.timeout_add(100,
+			self.update_progressbar)
 
 		self.fill_jabber_page()
 
 		self.xml.signal_autoconnect(self)
 		self.window.show_all()
 
+	def update_progressbar(self):
+		self.progressbar.pulse()
+		return True # loop forever
+
 	def on_vcard_information_window_destroy(self, widget):
+		if self.update_progressbar_timeout_id is not None:
+			gobject.source_remove(self.update_progressbar_timeout_id)
 		del gajim.interface.instances[self.account]['infos'][self.contact.jid]
 
 	def on_vcard_information_window_key_press_event(self, widget, event):
@@ -154,6 +165,15 @@ class VcardWindow:
 						vcard[i], 0)
 				else:
 					self.set_value(i + '_label', vcard[i])
+		self.vcard_arrived = True
+		self.test_remove_progressbar()
+
+	def test_remove_progressbar(self):
+		if self.update_progressbar_timeout_id is not None and \
+		self.vcard_arrived and self.os_info_arrived:
+			gobject.source_remove(self.update_progressbar_timeout_id)
+			self.progressbar.hide()
+			self.update_progressbar_timeout_id = None
 
 	def set_last_status_time(self):
 		self.fill_status_label()
@@ -182,6 +202,8 @@ class VcardWindow:
 			os = Q_('?OS:Unknown')
 		self.xml.get_widget('client_name_version_label').set_text(client)
 		self.xml.get_widget('os_label').set_text(os)
+		self.os_info_arrived = True
+		self.test_remove_progressbar()
 
 	def fill_status_label(self):
 		if self.xml.get_widget('information_notebook').get_n_pages() < 4:
-- 
GitLab