From 8184058a60a504aff222328a7131d9a191f26f6c Mon Sep 17 00:00:00 2001 From: Sebastian Droege Date: Sat, 4 Mar 2006 16:19:06 +0000 Subject: * rename gnometerminal.py to gconfterminal.py and use the gconf key for the default terminal if present or gnome-terminal otherwise git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@95 3be567f1-68ff-0310-b24a-ad7cc433fd2f --- plugins/Makefile.am | 2 +- plugins/gconfterminal.py | 131 +++++++++++++++++++++++++++++++++++++++++++++++ plugins/gnometerminal.py | 128 --------------------------------------------- 3 files changed, 132 insertions(+), 129 deletions(-) create mode 100644 plugins/gconfterminal.py delete mode 100644 plugins/gnometerminal.py diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 37902fb..772cd8b 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,7 +1,7 @@ pluginsdir = $(PLUGINSDIR) plugins_DATA = \ - gnometerminal.py \ + gconfterminal.py \ nautilus.py diff --git a/plugins/gconfterminal.py b/plugins/gconfterminal.py new file mode 100644 index 0000000..54d8961 --- /dev/null +++ b/plugins/gconfterminal.py @@ -0,0 +1,131 @@ +# -*- coding: UTF-8 -*- +# -*- python -*- +# Copyright (C) 2005 by Sebastien Estienne +# +# This file may be distributed and/or modified under the terms of +# the GNU General Public License version 2 as published by +# the Free Software Foundation. +# This file is distributed without any warranty; without even the implied +# warranty of merchantability or fitness for a particular purpose. +# See "COPYING" in the source distribution for more information. +# +# $id$ +# + +from sdapplet.pluginutils import * + +try: + import gettext + gettext.bindtextdomain("service-discovery-applet", "/usr/share/locale") + gettext.textdomain("service-discovery-applet") + _ = gettext.gettext + import pygtk + pygtk.require('2.0') + import gtk + import os + import pwd + import subprocess + import gconf + import gnome +except ImportError, e: + error_msg(_("A required python module is missing!\n%s") % (e)) + sys.exit() + +class plugin_gnometerminal: + def __init__(self): + self.service_type = ["_ssh._tcp", "_sftp-ssh._tcp" ] + self.author = "Sébastien Estienne" + + def enter_callback(self, widget, win): + win.response(gtk.RESPONSE_OK) + + def SshLogin(self, hostname, username = None): + self.win = gtk.Dialog(_("SSH Connection"), None, + gtk.DIALOG_MODAL, + (gtk.STOCK_OK, gtk.RESPONSE_OK, + gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + + vbox = gtk.VBox(False, 5) + self.win.vbox.pack_start(vbox, True, True, 0) + vbox.set_border_width(5) + + label = gtk.Label() + label.set_markup(_("Connecting to %s.\nPlease enter your login:") % (hostname)) + + vbox.pack_start(label, False, False, 0) + + # Create our entry + entry = gtk.Entry() + if username!= None: + entry.set_text(username) + entry.connect("activate", self.enter_callback, self.win) + vbox.pack_start(entry, False, False, 0) + + # Create the completion object + completion = gtk.EntryCompletion() + + # Assign the completion to the entry + entry.set_completion(completion) + + # Create a tree model and use it as the completion model + completion_model = self.__create_completion_model() + completion.set_model(completion_model) + + # Use model column 0 as the text column + completion.set_text_column(0) + + self.win.show_all() + if self.win.run() == gtk.RESPONSE_OK: + self.win.destroy() + return entry.get_text() + else: + self.win.destroy() + return None + + def __create_completion_model(self): + ''' Creates a tree model containing the completions. + ''' + store = gtk.ListStore(str) + + iter = store.append() + store.set(iter, 0, "root") + + current_user = pwd.getpwuid(os.getuid())[0] + iter = store.append() + store.set(iter, 0, current_user) + + return store + + def connect(self, use_host_names, name, stype, hostname, address, port, txts): + try: + terminal = gconf.client_get_default().get_string ("/desktop/gnome/applications/terminal/exec") + terminal = terminal + " " + gconf.client_get_default().get_string ("/desktop/gnome/applications/terminal/exec_arg") + except: + terminal = "gnome-terminal -x" + if use_host_names == True: + address = hostname + print "connecting using %s" % (terminal) + if txts.has_key("u"): + username = self.SshLogin(name, txts["u"]) + else: + username = self.SshLogin(name) + + + if stype == "_ssh._tcp": + scheme = "ssh -X" + else: + scheme = "sftp" + if username == None: + return + elif username != "": + sshline = "%s -p %i %s@%s" % (scheme, port, username, address) + else: + sshline = "%s -p %i %s " % (scheme, port, address) + + cmdline = terminal.split(" ") + cmdline.extend(sshline.split(" ")) + print cmdline + pid = subprocess.Popen(cmdline).pid + +def load(): + return plugin_gnometerminal() diff --git a/plugins/gnometerminal.py b/plugins/gnometerminal.py deleted file mode 100644 index 306173f..0000000 --- a/plugins/gnometerminal.py +++ /dev/null @@ -1,128 +0,0 @@ -# -*- coding: UTF-8 -*- -# -*- python -*- -# Copyright (C) 2005 by Sebastien Estienne -# -# This file may be distributed and/or modified under the terms of -# the GNU General Public License version 2 as published by -# the Free Software Foundation. -# This file is distributed without any warranty; without even the implied -# warranty of merchantability or fitness for a particular purpose. -# See "COPYING" in the source distribution for more information. -# -# $id$ -# - -from sdapplet.pluginutils import * - -try: - import gettext - gettext.bindtextdomain("service-discovery-applet", "/usr/share/locale") - gettext.textdomain("service-discovery-applet") - _ = gettext.gettext - import pygtk - pygtk.require('2.0') - import gtk - import os - import pwd - import subprocess - import gnome -except ImportError, e: - error_msg(_("A required python module is missing!\n%s") % (e)) - sys.exit() - -class plugin_gnometerminal: - def __init__(self): - self.service_type = ["_ssh._tcp", "_sftp-ssh._tcp" ] - self.author = "Sébastien Estienne" - - def enter_callback(self, widget, win): - win.response(gtk.RESPONSE_OK) - - def SshLogin(self, hostname, username = None): - self.win = gtk.Dialog(_("SSH Connection"), None, - gtk.DIALOG_MODAL, - (gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) - - vbox = gtk.VBox(False, 5) - self.win.vbox.pack_start(vbox, True, True, 0) - vbox.set_border_width(5) - - label = gtk.Label() - label.set_markup(_("Connecting to %s.\nPlease enter your login:") % (hostname)) - - vbox.pack_start(label, False, False, 0) - - # Create our entry - entry = gtk.Entry() - if username!= None: - entry.set_text(username) - entry.connect("activate", self.enter_callback, self.win) - vbox.pack_start(entry, False, False, 0) - - # Create the completion object - completion = gtk.EntryCompletion() - - # Assign the completion to the entry - entry.set_completion(completion) - - # Create a tree model and use it as the completion model - completion_model = self.__create_completion_model() - completion.set_model(completion_model) - - # Use model column 0 as the text column - completion.set_text_column(0) - - self.win.show_all() - if self.win.run() == gtk.RESPONSE_OK: - self.win.destroy() - return entry.get_text() - else: - self.win.destroy() - return None - - def __create_completion_model(self): - ''' Creates a tree model containing the completions. - ''' - store = gtk.ListStore(str) - - iter = store.append() - store.set(iter, 0, "root") - - current_user = pwd.getpwuid(os.getuid())[0] - iter = store.append() - store.set(iter, 0, current_user) - - return store - - def connect(self, use_host_names, name, stype, hostname, address, port, txts): - if use_host_names == True: - address = hostname - print "connecting using gnometerminal" - if txts.has_key("u"): - username = self.SshLogin(name, txts["u"]) - else: - username = self.SshLogin(name) - - - if stype == "_ssh._tcp": - scheme = "ssh" - else: - scheme = "sftp" - if username == None: - return - elif username != "": - sshline = "%s -X -p %i %s@%s" % (scheme, port, username, address) - else: - sshline = "%s -X -p %i %s " % (scheme, port, address) - - cmdline = [] - cmdline.append("gnome-terminal") - cmdline.append("--tab") - cmdline.append("-t %s" % name) - cmdline.append("-e %s" % sshline) - print cmdline - pid = subprocess.Popen(cmdline).pid - -def load(): - return plugin_gnometerminal() -- cgit