From 23fa0bf8e6b4e74107feb86445d16735592872b1 Mon Sep 17 00:00:00 2001 From: Tomasz Melcer Date: Thu, 22 Jun 2006 22:49:39 +0000 Subject: [PATCH] First version of commands window. Added: glade file for commands window, src/adhoc_commands.py with a class to create/manage the window. For now, progressbar bounces :-). --- data/glade/adhoc_commands_window.glade | 449 +++++++++++++++++++++++++ src/adhoc_commands.py | 79 +++++ src/roster_window.py | 16 +- 3 files changed, 542 insertions(+), 2 deletions(-) create mode 100644 data/glade/adhoc_commands_window.glade create mode 100644 src/adhoc_commands.py diff --git a/data/glade/adhoc_commands_window.glade b/data/glade/adhoc_commands_window.glade new file mode 100644 index 000000000..25c068a39 --- /dev/null +++ b/data/glade/adhoc_commands_window.glade @@ -0,0 +1,449 @@ + + + + + + + True + Ad-hoc Commands - Gajim + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + + + + 6 + True + False + 0 + + + + True + False + False + GTK_POS_TOP + False + False + + + + True + False + 0 + + + + True + Please wait while retrieving command list... + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + True + False + + + + + + True + GTK_PROGRESS_LEFT_TO_RIGHT + 0 + 0.0500000007451 + PANGO_ELLIPSIZE_NONE + + + 0 + True + False + + + + + + + + + False + True + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + + True + False + 0 + + + + True + Choose command to execute: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + False + 0 + + + 0 + True + True + + + + + False + True + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + + True + False + 0 + + + + True + Fill in the form + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + + + + + True + GTK_PROGRESS_LEFT_TO_RIGHT + 0 + 0.0500000007451 + Please wait... + PANGO_ELLIPSIZE_NONE + + + 0 + False + False + + + + + False + True + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + + True + This jabber entity doesn't expose any commands. + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + False + True + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + 0 + True + True + + + + + + True + + + 3 + False + False + + + + + + True + False + 0 + + + + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + + + + 3 + False + False + + + + + + + + + + True + True + gtk-go-back + True + GTK_RELIEF_NORMAL + True + + + + 3 + False + False + + + + + + True + True + gtk-go-forward + True + GTK_RELIEF_NORMAL + True + + + + 3 + False + False + + + + + + True + True + gtk-execute + True + GTK_RELIEF_NORMAL + True + + + + 3 + False + False + + + + + 0 + False + False + + + + + + + diff --git a/src/adhoc_commands.py b/src/adhoc_commands.py new file mode 100644 index 000000000..f87c1fb19 --- /dev/null +++ b/src/adhoc_commands.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +## config.py +## +## Copyright (C) 2003-2004 Yann Le Boulanger +## Vincent Hanquez +## Copyright (C) 2005 Yann Le Boulanger +## Vincent Hanquez +## Nikos Kouremenos +## Dimitur Kirov +## Travis Shirk +## Norman Rasmussen +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published +## by the Free Software Foundation; version 2 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +import gobject +import gtk + +import gtkgui_helpers + +class CommandWindow: + '''Class for a window for single ad-hoc commands session. Note, that + there might be more than one for one account/jid pair in one moment. + + TODO: maybe put this window into MessageWindow? consider this when + TODO: it will be possible to manage more than one window of one + TODO: account/jid pair in MessageWindowMgr.''' + + def __init__(self, account, jid): + '''Create new window.''' + + self.pulse_id=None # to satisfy self..setup_pulsing() + + # connecting to handlers + + # retrieving widgets from xml + self.xml = gtkgui_helpers.get_glade('adhoc_commands_window.glade') + self.window = self.xml.get_widget('adhoc_commands_window') + + # setting initial state of widgets + self.setup_pulsing(self.xml.get_widget('retrieving_commands_progressbar')) + + # invoking disco to find commands + + # displaying the window + self.xml.signal_autoconnect(self) + self.window.show_all() + + def on_cancel_button_clicked(self, *anything): pass + def on_back_button_clicked(self, *anything): pass + def on_forward_button_clicked(self, *anything): pass + def on_execute_button_clicked(self, *anything): pass + + def setup_pulsing(self, progressbar): + '''Useful to set the progressbar to pulse. Makes a custom + function to repeatedly call progressbar.pulse() method.''' + assert self.pulse_id is None + assert isinstance(progressbar, Gtk.ProgressBar) + assert False + + def callback(): + progressbar.pulse() + return True # important to keep callback be called back! + + # 12 times per second (40 miliseconds) + self.pulse_id = gobject.timeout_add(80, callback) + progressbar.pulse() # start from now! + + def remove_pulsing(self): + '''Useful to stop pulsing, especially when removing widget.''' + if self.pulse_id is not None: + gobject.source_remove(self.pulse_id) + self.pulse_id=None diff --git a/src/roster_window.py b/src/roster_window.py index c7c0576b1..553c97d14 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -29,6 +29,7 @@ import gtkgui_helpers import cell_renderer_image import tooltips import message_control +import adhoc_commands from common import gajim from common import helpers @@ -1302,15 +1303,17 @@ class RosterWindow: return sub_menu start_chat_menuitem.set_submenu(resources_submenu(self.on_open_chat_window)) - execute_command_menuitem.set_submenu(resources_submenu(self.on_open_chat_window)) + execute_command_menuitem.set_submenu(resources_submenu(self.on_execute_command)) else: # one resource start_chat_menuitem.connect('activate', self.on_open_chat_window, contact, account) # we cannot execute commands when the resource is unknown + # TODO: that's true only if the entity is a contact, + # TODO: we need to show this also for transports if contact.resource: execute_command_menuitem.connect('activate', - self.on_roster_treeview_row_activated, path) + self.on_execute_command, contact, account, contact.resource) else: execute_command_menuitem.hide() execute_command_menuitem.set_no_show_all(True) @@ -2490,6 +2493,15 @@ _('If "%s" accepts this request you will know his or her status.') % jid) return True return False + def on_execute_command(self, widget, contact, account, resource=None): + '''Execute command. Full JID needed; if it is other contact, + resource is necessary. Widget is unnecessary, only to be + able to make this a callback.''' + jid = contact.jid + if resource is not None: + jid = jid+u'/'+resource + adhoc_commands.CommandWindow(account, jid) + def on_open_chat_window(self, widget, contact, account, resource = None): # Get the window containing the chat fjid = contact.jid