Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / ksysguard / gui / HostConnector.cc
blob74fb748494bb80dffd5d3f91c7ba7a4bddec72d3
1 /*
2 KSysGuard, the KDE System Guard
4 Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License version 2 or at your option version 3 as published by
9 the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <kapplication.h>
23 #include <kacceleratormanager.h>
24 #include <kcombobox.h>
25 #include <klocale.h>
26 #include <ktoolinvocation.h>
28 #include <QGroupBox>
29 #include <QLabel>
30 #include <QLayout>
31 #include <QRadioButton>
32 #include <QSpinBox>
34 #include <QGridLayout>
35 #include <QLineEdit>
37 #include "HostConnector.h"
39 HostConnector::HostConnector( QWidget *parent, const char *name )
40 : KDialog( parent )
42 setObjectName( name );
43 setModal( true );
44 setCaption( i18n( "Connect Host" ) );
45 setButtons( Help | Ok | Cancel );
46 showButtonSeparator( true );
48 QFrame *page = new QFrame( this );
49 setMainWidget( page );
51 QGridLayout *layout = new QGridLayout( page );
52 layout->setSpacing( spacingHint() );
53 layout->setMargin( 0 );
54 layout->setColumnStretch( 1, 1 );
56 QLabel *label = new QLabel( i18n( "Host:" ), page );
57 layout->addWidget( label, 0, 0 );
59 mHostNames = new KComboBox( true, page );
60 mHostNames->setMaxCount( 20 );
61 mHostNames->setInsertPolicy( QComboBox::InsertAtTop );
62 mHostNames->setAutoCompletion( true );
63 mHostNames->setDuplicatesEnabled( false );
64 layout->addWidget( mHostNames, 0, 1 );
65 label->setBuddy( mHostNames );
66 mHostNames->setWhatsThis( i18n( "Enter the name of the host you want to connect to." ) );
68 mHostNameLabel = new QLabel( page );
69 mHostNameLabel->hide();
70 layout->addWidget( mHostNameLabel, 0, 1 );
72 QGroupBox *group = new QGroupBox(i18n( "Connection Type" ), page );
73 QGridLayout *groupLayout = new QGridLayout();
74 group->setLayout(groupLayout);
75 groupLayout->setSpacing( spacingHint() );
76 groupLayout->setAlignment( Qt::AlignTop );
78 mUseSsh = new QRadioButton( i18n( "ssh" ));
79 mUseSsh->setEnabled( true );
80 mUseSsh->setChecked( true );
81 mUseSsh->setWhatsThis( i18n( "Select this to use the secure shell to login to the remote host." ) );
82 groupLayout->addWidget( mUseSsh, 0, 0 );
84 mUseRsh = new QRadioButton( i18n( "rsh" ));
85 mUseRsh->setWhatsThis( i18n( "Select this to use the remote shell to login to the remote host." ) );
86 groupLayout->addWidget( mUseRsh, 0, 1 );
88 mUseDaemon = new QRadioButton( i18n( "Daemon" ));
89 mUseDaemon->setWhatsThis( i18n( "Select this if you want to connect to a ksysguard daemon that is running on the machine you want to connect to, and is listening for client requests." ) );
90 groupLayout->addWidget( mUseDaemon, 0, 2 );
92 mUseCustom = new QRadioButton( i18n( "Custom command" ));
93 mUseCustom->setWhatsThis( i18n( "Select this to use the command you entered below to start ksysguardd on the remote host." ) );
94 groupLayout->addWidget( mUseCustom, 0, 3 );
96 label = new QLabel( i18n( "Port:" ));
97 groupLayout->addWidget( label, 1, 0 );
99 mPort = new QSpinBox();
100 mPort->setRange( 1, 65535 );
101 mPort->setEnabled( false );
102 mPort->setValue( 3112 );
103 mPort->setToolTip( i18n( "Enter the port number on which the ksysguard daemon is listening for connections." ) );
104 groupLayout->addWidget( mPort, 1, 2 );
106 label = new QLabel( i18n( "e.g. 3112" ));
107 groupLayout->addWidget( label, 1, 3 );
109 label = new QLabel( i18n( "Command:" ) );
110 groupLayout->addWidget( label, 2, 0 );
112 mCommands = new KComboBox( true );
113 mCommands->setEnabled( false );
114 mCommands->setMaxCount( 20 );
115 mCommands->setInsertPolicy( QComboBox::InsertAtTop );
116 mCommands->setAutoCompletion( true );
117 mCommands->setDuplicatesEnabled( false );
118 mCommands->setWhatsThis( i18n( "Enter the command that runs ksysguardd on the host you want to monitor." ) );
119 groupLayout->addWidget( mCommands, 2, 2, 1, 2 );
120 label->setBuddy( mCommands );
122 label = new QLabel( i18n( "e.g. ssh -l root remote.host.org ksysguardd" ) );
123 groupLayout->addWidget( label, 3, 2, 1, 2 );
125 layout->addWidget( group, 1, 0, 1, 2 );
127 connect( mUseCustom, SIGNAL( toggled( bool ) ),
128 mCommands, SLOT( setEnabled( bool ) ) );
129 connect( mUseDaemon, SIGNAL( toggled( bool ) ),
130 mPort, SLOT( setEnabled( bool ) ) );
131 connect( mHostNames->lineEdit(), SIGNAL( textChanged ( const QString & ) ),
132 this, SLOT( slotHostNameChanged( const QString & ) ) );
133 enableButtonOk( !mHostNames->lineEdit()->text().isEmpty() );
134 KAcceleratorManager::manage( this );
135 connect(this,SIGNAL(helpClicked()),this,SLOT(slotHelp()));
138 HostConnector::~HostConnector()
142 void HostConnector::slotHostNameChanged( const QString &_text )
144 enableButtonOk( !_text.isEmpty() );
147 void HostConnector::setHostNames( const QStringList &list )
149 mHostNames->addItems( list );
152 QStringList HostConnector::hostNames() const
154 QStringList list;
156 for ( int i = 0; i < mHostNames->count(); ++i )
157 list.append( mHostNames->itemText( i ) );
159 return list;
162 void HostConnector::setCommands( const QStringList &list )
164 mCommands->addItems( list );
167 QStringList HostConnector::commands() const
169 QStringList list;
171 for ( int i = 0; i < mCommands->count(); ++i )
172 list.append( mCommands->itemText( i ) );
174 return list;
177 void HostConnector::setCurrentHostName( const QString &hostName )
179 if ( !hostName.isEmpty() ) {
180 mHostNames->hide();
181 mHostNameLabel->setText( hostName );
182 mHostNameLabel->show();
183 enableButtonOk( true );//enable true when mHostNames is empty and hidden fix #66955
184 } else {
185 mHostNameLabel->hide();
186 mHostNames->show();
187 mHostNames->setFocus();
191 QString HostConnector::currentHostName() const
193 return mHostNames->currentText();
196 QString HostConnector::currentCommand() const
198 return mCommands->currentText();
201 int HostConnector::port() const
203 return mPort->value();
206 bool HostConnector::useSsh() const
208 return mUseSsh->isChecked();
211 bool HostConnector::useRsh() const
213 return mUseRsh->isChecked();
216 bool HostConnector::useDaemon() const
218 return mUseDaemon->isChecked();
221 bool HostConnector::useCustom() const
223 return mUseCustom->isChecked();
226 void HostConnector::slotHelp()
228 KToolInvocation::invokeHelp( "CONNECTINGTOOTHERHOSTS", "ksysguard/the-sensor-browser.html" );
231 #include "HostConnector.moc"