~ubuntu-branches/ubuntu/edgy/service-discovery-applet/edgy

« back to all changes in this revision

Viewing changes to plugins/gconfterminal.py.in

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-27 20:55:49 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060827205549-eh91f7einmxl0i49
Tags: 0.4.3-1
* New upstream release
* debian/patches/01_webdav-uri-scheme.diff,
  debian/patches/02_sftp-handler.diff:
  + Dropped, merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
 
2
# -*- python -*-
 
3
# Copyright (C) 2005 by Sebastien Estienne
 
4
#
 
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.
 
11
#
 
12
# $Id: gconfterminal.py.in 123 2006-08-26 01:59:32Z sebest $
 
13
#
 
14
 
 
15
from sdapplet.pluginutils import *
 
16
 
 
17
import os
 
18
import pwd
 
19
import subprocess
 
20
 
 
21
try:
 
22
    import gettext
 
23
    gettext.bindtextdomain("service-discovery-applet", "/usr/share/locale")
 
24
    gettext.textdomain("service-discovery-applet")
 
25
    _ = gettext.gettext
 
26
    import pygtk
 
27
    pygtk.require('2.0')
 
28
    import gtk
 
29
    import gconf
 
30
    import gnome
 
31
except ImportError, e:
 
32
    error_msg(_("A required python module is missing!\n%s") % (e))
 
33
    os._exit()
 
34
 
 
35
class plugin_gnometerminal:
 
36
    def __init__(self):
 
37
        self.service_type = ["_ssh._tcp", "_sftp-ssh._tcp" ]
 
38
        self.author = "Sébastien Estienne"
 
39
 
 
40
    def enter_callback(self, widget, win):
 
41
        win.response(gtk.RESPONSE_OK)
 
42
 
 
43
    def SshLogin(self, hostname, username = None):
 
44
        self.win = gtk.Dialog(_("SSH Connection"), None,
 
45
                              gtk.DIALOG_MODAL,
 
46
                              (gtk.STOCK_OK, gtk.RESPONSE_OK,
 
47
                               gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
48
 
 
49
        vbox = gtk.VBox(False, 5)
 
50
        self.win.vbox.pack_start(vbox, True, True, 0)
 
51
        vbox.set_border_width(5)
 
52
    
 
53
        label = gtk.Label()
 
54
        label.set_markup(_("Connecting to <b>%s</b>.\nPlease enter your <b>login</b>:") % (hostname))
 
55
        
 
56
        vbox.pack_start(label, False, False, 0)
 
57
    
 
58
        # Create our entry
 
59
        entry = gtk.Entry()
 
60
        if username!= None:
 
61
            entry.set_text(username)
 
62
        entry.connect("activate", self.enter_callback, self.win)
 
63
        vbox.pack_start(entry, False, False, 0)
 
64
    
 
65
        # Create the completion object
 
66
        completion = gtk.EntryCompletion()
 
67
    
 
68
        # Assign the completion to the entry
 
69
        entry.set_completion(completion)
 
70
    
 
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)
 
74
    
 
75
        # Use model column 0 as the text column
 
76
        completion.set_text_column(0)
 
77
    
 
78
        self.win.show_all()
 
79
        if self.win.run() == gtk.RESPONSE_OK:
 
80
            self.win.destroy()
 
81
            return entry.get_text()
 
82
        else:
 
83
            self.win.destroy()
 
84
            return None
 
85
    
 
86
    def __create_completion_model(self):
 
87
        ''' Creates a tree model containing the completions.
 
88
        '''
 
89
        store = gtk.ListStore(str)
 
90
        
 
91
        iter = store.append()
 
92
        store.set(iter, 0, "root")
 
93
    
 
94
        current_user = pwd.getpwuid(os.getuid())[0]
 
95
        iter = store.append()
 
96
        store.set(iter, 0, current_user)
 
97
    
 
98
        return store
 
99
 
 
100
    def connect(self, use_host_names, name, stype, hostname, address, port, txts):
 
101
        try:
 
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")
 
104
        except:
 
105
            terminal = "gnome-terminal -x"
 
106
        if use_host_names == True:
 
107
            address = hostname
 
108
        print "connecting using %s" % (terminal)
 
109
        if txts.has_key("u"):
 
110
            username = self.SshLogin(name, txts["u"])
 
111
        else:
 
112
            username = self.SshLogin(name)
 
113
 
 
114
 
 
115
        if stype == "_ssh._tcp":
 
116
            scheme = "@toolsdir@/exec_wrapper ssh -X -p %d" % (port)
 
117
        else:
 
118
            scheme = "@toolsdir@/exec_wrapper sftp -oPort=%d" % (port)
 
119
        if username == None:
 
120
            return
 
121
        elif username != "":
 
122
            sshline = "%s %s@%s" % (scheme, username, address)
 
123
        else:
 
124
            sshline = "%s %s " % (scheme, address)
 
125
 
 
126
        cmdline = terminal.split(" ")
 
127
        cmdline.extend(sshline.split(" "))
 
128
        print cmdline
 
129
        pid = subprocess.Popen(cmdline).pid
 
130
        os.waitpid(pid)
 
131
        
 
132
def load():
 
133
    return plugin_gnometerminal()