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>
27
#include <ktoolinvocation.h>
32
#include <QRadioButton>
34
#include <QGridLayout>
37
#include "HostConnector.h"
39
HostConnector::HostConnector( QWidget *parent, const char *name )
42
setObjectName( name );
44
setCaption( i18n( "Connect Host" ) );
45
setButtons( Help | Ok | Cancel );
47
QFrame *page = new QFrame( this );
48
setMainWidget( page );
50
QGridLayout *layout = new QGridLayout( page );
51
layout->setSpacing( spacingHint() );
52
layout->setMargin( 0 );
53
layout->setColumnStretch( 1, 1 );
55
QLabel *label = new QLabel( i18n( "Host:" ), page );
56
layout->addWidget( label, 0, 0 );
58
mHostNames = new KComboBox( true, page );
59
mHostNames->setMaxCount( 20 );
60
mHostNames->setInsertPolicy( QComboBox::InsertAtTop );
61
mHostNames->setAutoCompletion( true );
62
mHostNames->setDuplicatesEnabled( false );
63
layout->addWidget( mHostNames, 0, 1 );
64
label->setBuddy( mHostNames );
65
mHostNames->setWhatsThis( i18n( "Enter the name of the host you want to connect to." ) );
67
mHostNameLabel = new QLabel( page );
68
mHostNameLabel->hide();
69
layout->addWidget( mHostNameLabel, 0, 1 );
71
QGroupBox *group = new QGroupBox(i18n( "Connection Type" ), page );
72
QGridLayout *groupLayout = new QGridLayout();
73
group->setLayout(groupLayout);
74
groupLayout->setSpacing( spacingHint() );
75
groupLayout->setAlignment( Qt::AlignTop );
77
mUseSsh = new QRadioButton( i18n( "ssh" ));
78
mUseSsh->setEnabled( true );
79
mUseSsh->setChecked( true );
80
mUseSsh->setWhatsThis( i18n( "Select this to use the secure shell to login to the remote host." ) );
81
groupLayout->addWidget( mUseSsh, 0, 0 );
83
mUseRsh = new QRadioButton( i18n( "rsh" ));
84
mUseRsh->setWhatsThis( i18n( "Select this to use the remote shell to login to the remote host." ) );
85
groupLayout->addWidget( mUseRsh, 0, 1 );
87
mUseDaemon = new QRadioButton( i18n( "Daemon" ));
88
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." ) );
89
groupLayout->addWidget( mUseDaemon, 0, 2 );
91
mUseCustom = new QRadioButton( i18n( "Custom command" ));
92
mUseCustom->setWhatsThis( i18n( "Select this to use the command you entered below to start ksysguardd on the remote host." ) );
93
groupLayout->addWidget( mUseCustom, 0, 3 );
95
label = new QLabel( i18n( "Port:" ));
96
groupLayout->addWidget( label, 1, 0 );
98
mPort = new KIntSpinBox();
99
mPort->setRange( 1, 65535 );
100
mPort->setEnabled( false );
101
mPort->setValue( 3112 );
102
mPort->setToolTip( i18n( "Enter the port number on which the ksysguard daemon is listening for connections." ) );
103
groupLayout->addWidget( mPort, 1, 2 );
105
label = new QLabel( i18n( "e.g. 3112" ));
106
groupLayout->addWidget( label, 1, 3 );
108
label = new QLabel( i18n( "Command:" ) );
109
groupLayout->addWidget( label, 2, 0 );
111
mCommands = new KComboBox( true );
112
mCommands->setEnabled( false );
113
mCommands->setMaxCount( 20 );
114
mCommands->setInsertPolicy( QComboBox::InsertAtTop );
115
mCommands->setAutoCompletion( true );
116
mCommands->setDuplicatesEnabled( false );
117
mCommands->setWhatsThis( i18n( "Enter the command that runs ksysguardd on the host you want to monitor." ) );
118
groupLayout->addWidget( mCommands, 2, 2, 1, 2 );
119
label->setBuddy( mCommands );
121
label = new QLabel( i18n( "e.g. ssh -l root remote.host.org ksysguardd" ) );
122
groupLayout->addWidget( label, 3, 2, 1, 2 );
124
layout->addWidget( group, 1, 0, 1, 2 );
126
connect( mUseCustom, SIGNAL( toggled( bool ) ),
127
mCommands, SLOT( setEnabled( bool ) ) );
128
connect( mUseDaemon, SIGNAL( toggled( bool ) ),
129
mPort, SLOT( setEnabled( bool ) ) );
130
connect( mHostNames->lineEdit(), SIGNAL( textChanged ( const QString & ) ),
131
this, SLOT( slotHostNameChanged( const QString & ) ) );
132
enableButtonOk( !mHostNames->lineEdit()->text().isEmpty() );
133
KAcceleratorManager::manage( this );
134
connect(this,SIGNAL(helpClicked()),this,SLOT(slotHelp()));
137
HostConnector::~HostConnector()
141
void HostConnector::slotHostNameChanged( const QString &_text )
143
enableButtonOk( !_text.isEmpty() );
146
void HostConnector::setHostNames( const QStringList &list )
148
mHostNames->addItems( list );
151
QStringList HostConnector::hostNames() const
155
for ( int i = 0; i < mHostNames->count(); ++i )
156
list.append( mHostNames->itemText( i ) );
161
void HostConnector::setCommands( const QStringList &list )
163
mCommands->addItems( list );
166
QStringList HostConnector::commands() const
170
for ( int i = 0; i < mCommands->count(); ++i )
171
list.append( mCommands->itemText( i ) );
176
void HostConnector::setCurrentHostName( const QString &hostName )
178
if ( !hostName.isEmpty() ) {
180
mHostNameLabel->setText( hostName );
181
mHostNameLabel->show();
182
enableButtonOk( true );//enable true when mHostNames is empty and hidden fix #66955
184
mHostNameLabel->hide();
186
mHostNames->setFocus();
190
QString HostConnector::currentHostName() const
192
return mHostNames->currentText();
195
QString HostConnector::currentCommand() const
197
return mCommands->currentText();
200
int HostConnector::port() const
202
return mPort->value();
205
bool HostConnector::useSsh() const
207
return mUseSsh->isChecked();
210
bool HostConnector::useRsh() const
212
return mUseRsh->isChecked();
215
bool HostConnector::useDaemon() const
217
return mUseDaemon->isChecked();
220
bool HostConnector::useCustom() const
222
return mUseCustom->isChecked();
225
void HostConnector::slotHelp()
227
KToolInvocation::invokeHelp( "connectingtootherhosts", "ksysguard" );
230
#include "HostConnector.moc"