1
# -*- coding: UTF-8 -*-
3
# Copyright (C) 2005 by Sebastien Estienne
5
# This file may be distributed and/or modified under the terms of
6
# the GNU General Public License version 2 as published by
7
# the Free Software Foundation.
8
# This file is distributed without any warranty; without even the implied
9
# warranty of merchantability or fitness for a particular purpose.
10
# See "COPYING" in the source distribution for more information.
12
# $Id: gconfterminal.py.in 123 2006-08-26 01:59:32Z sebest $
15
from sdapplet.pluginutils import *
23
gettext.bindtextdomain("service-discovery-applet", "/usr/share/locale")
24
gettext.textdomain("service-discovery-applet")
31
except ImportError, e:
32
error_msg(_("A required python module is missing!\n%s") % (e))
35
class plugin_gnometerminal:
37
self.service_type = ["_ssh._tcp", "_sftp-ssh._tcp" ]
38
self.author = "Sébastien Estienne"
40
def enter_callback(self, widget, win):
41
win.response(gtk.RESPONSE_OK)
43
def SshLogin(self, hostname, username = None):
44
self.win = gtk.Dialog(_("SSH Connection"), None,
46
(gtk.STOCK_OK, gtk.RESPONSE_OK,
47
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
49
vbox = gtk.VBox(False, 5)
50
self.win.vbox.pack_start(vbox, True, True, 0)
51
vbox.set_border_width(5)
54
label.set_markup(_("Connecting to <b>%s</b>.\nPlease enter your <b>login</b>:") % (hostname))
56
vbox.pack_start(label, False, False, 0)
61
entry.set_text(username)
62
entry.connect("activate", self.enter_callback, self.win)
63
vbox.pack_start(entry, False, False, 0)
65
# Create the completion object
66
completion = gtk.EntryCompletion()
68
# Assign the completion to the entry
69
entry.set_completion(completion)
71
# Create a tree model and use it as the completion model
72
completion_model = self.__create_completion_model()
73
completion.set_model(completion_model)
75
# Use model column 0 as the text column
76
completion.set_text_column(0)
79
if self.win.run() == gtk.RESPONSE_OK:
81
return entry.get_text()
86
def __create_completion_model(self):
87
''' Creates a tree model containing the completions.
89
store = gtk.ListStore(str)
92
store.set(iter, 0, "root")
94
current_user = pwd.getpwuid(os.getuid())[0]
96
store.set(iter, 0, current_user)
100
def connect(self, use_host_names, name, stype, hostname, address, port, txts):
102
terminal = gconf.client_get_default().get_string ("/desktop/gnome/applications/terminal/exec")
103
terminal = terminal + " " + gconf.client_get_default().get_string ("/desktop/gnome/applications/terminal/exec_arg")
105
terminal = "gnome-terminal -x"
106
if use_host_names == True:
108
print "connecting using %s" % (terminal)
109
if txts.has_key("u"):
110
username = self.SshLogin(name, txts["u"])
112
username = self.SshLogin(name)
115
if stype == "_ssh._tcp":
116
scheme = "@toolsdir@/exec_wrapper ssh -X -p %d" % (port)
118
scheme = "@toolsdir@/exec_wrapper sftp -oPort=%d" % (port)
122
sshline = "%s %s@%s" % (scheme, username, address)
124
sshline = "%s %s " % (scheme, address)
126
cmdline = terminal.split(" ")
127
cmdline.extend(sshline.split(" "))
129
pid = subprocess.Popen(cmdline).pid
133
return plugin_gnometerminal()