changeset 393:393b35aa86d2

jp: added --connect option
author Goffi <goffi@goffi.org>
date Sun, 02 Oct 2011 00:29:04 +0200
parents 20f11097d99b
children 8f3551ceee17
files frontends/src/jp/jp
diffstat 1 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/jp	Thu Sep 29 15:13:54 2011 +0200
+++ b/frontends/src/jp/jp	Sun Oct 02 00:29:04 2011 +0200
@@ -103,6 +103,8 @@
                     help=_("Separate xmpp messages: send one message per line instead of one message alone."))
         parser.add_option("-n", "--new-line", action="store_true", default=False,
                     help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
+        parser.add_option("--connect", action="store_true", default=False,
+                    help=_("Connect the profile before doing anything else"))
 
         (self.options, args) = parser.parse_args()
 
@@ -124,7 +126,7 @@
             self.options.progress = False
             error (_("Option progress is not available, deactivated."))
 
-        if self.options.progress or self.options.wait_file:
+        if self.options.progress or self.options.wait_file or self.options.connect:
             self.start_loop = True  #We have to use loop for these options
         else:
             self.start_loop = False
@@ -134,16 +136,26 @@
 
     def check_jabber_status(self):
         """Check that jabber status is allright"""
+        def cantConnect():
+            error(_(u"Can't connect profile"))
+            exit(1)
+
         
         self.profile = self.bridge.getProfileName(self.options.profile)
         if not self.profile:
             error(_("The profile asked doesn't exist"))
             exit(1)
 
-        if not self.bridge.isConnected(self.profile):
+        if self.options.connect: #if connection is asked, we connect the profile
+            self.bridge.asyncConnect(self.profile, self.connected, cantConnect)
+            return
+        elif not self.bridge.isConnected(self.profile):
             error(_(u"SàT is not conneted, please connect before using jp"))
             exit(1)
 
+        self.connected()
+
+
 
     def send_stdin(self):
         """Send incomming data on stdin to jabber contact"""
@@ -248,6 +260,15 @@
     def go(self):
         self.check_options()
         self.check_jabber_status()
+        if self.start_loop:
+            self.loop = gobject.MainLoop()
+            try:
+                self.loop.run()
+            except KeyboardInterrupt:
+                info(_("User interruption: good bye"))
+
+    def connected(self):
+        """This is called when the profile is connected"""
         if self.options.wait_file:
             self.wait_file()
         else:
@@ -256,15 +277,12 @@
             else:
                 self.send_files()
 
-        if self.start_loop:
-            self.loop = gobject.MainLoop()
-            if self.options.progress:
-                self.pbar = None
-                gobject.timeout_add(10, self.progressCB)
-            try:
-                self.loop.run()
-            except KeyboardInterrupt:
-                info(_("User interruption: good bye"))
+        if self.options.progress:
+            self.pbar = None
+            gobject.timeout_add(10, self.progressCB)
+
+        if not self.options.progress and not self.options.wait_file:
+            self.loop.quit()
 
 
 if __name__ == "__main__":