From b8edbbab56423c07c829d337faa07d21d6bd17bc Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 2 Oct 2011 00:29:04 +0200 Subject: [PATCH] jp: added --connect option --- frontends/src/jp/jp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/frontends/src/jp/jp b/frontends/src/jp/jp index ccc3ee79..9a72e88e 100755 --- a/frontends/src/jp/jp +++ b/frontends/src/jp/jp @@ -103,6 +103,8 @@ class JP(): 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 @@ class JP(): 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 @@ class JP(): 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 @@ class JP(): 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 @@ class JP(): 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__":