~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksysguard/gui/HostConnector.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    KSysGuard, the KDE System Guard
 
3
 
 
4
    Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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.
 
19
 
 
20
*/
 
21
 
 
22
#include <kapplication.h>
 
23
#include <kacceleratormanager.h>
 
24
#include <kcombobox.h>
 
25
#include <klocale.h>
 
26
#include <KNumInput>
 
27
#include <ktoolinvocation.h>
 
28
 
 
29
#include <QGroupBox>
 
30
#include <QLabel>
 
31
#include <QLayout>
 
32
#include <QRadioButton>
 
33
 
 
34
#include <QGridLayout>
 
35
#include <QLineEdit>
 
36
 
 
37
#include "HostConnector.h"
 
38
 
 
39
HostConnector::HostConnector( QWidget *parent, const char *name )
 
40
  : KDialog( parent )
 
41
{
 
42
  setObjectName( name );
 
43
  setModal( true );
 
44
  setCaption( i18n( "Connect Host" ) );
 
45
  setButtons( Help | Ok | Cancel );
 
46
 
 
47
  QFrame *page = new QFrame( this );
 
48
  setMainWidget( page );
 
49
 
 
50
  QGridLayout *layout = new QGridLayout( page );
 
51
  layout->setSpacing( spacingHint() );
 
52
  layout->setMargin( 0 );
 
53
  layout->setColumnStretch( 1, 1 );
 
54
 
 
55
  QLabel *label = new QLabel( i18n( "Host:" ), page );
 
56
  layout->addWidget( label, 0, 0 );
 
57
 
 
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." ) );
 
66
 
 
67
  mHostNameLabel = new QLabel( page );
 
68
  mHostNameLabel->hide();
 
69
  layout->addWidget( mHostNameLabel, 0, 1 );
 
70
 
 
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 );
 
76
 
 
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 );
 
82
 
 
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 );
 
86
 
 
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 );
 
90
 
 
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 );
 
94
 
 
95
  label = new QLabel( i18n( "Port:" ));
 
96
  groupLayout->addWidget( label, 1, 0 );
 
97
 
 
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 );
 
104
 
 
105
  label = new QLabel( i18n( "e.g.  3112" ));
 
106
  groupLayout->addWidget( label, 1, 3 );
 
107
 
 
108
  label = new QLabel( i18n( "Command:" ) );
 
109
  groupLayout->addWidget( label, 2, 0 );
 
110
 
 
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 );
 
120
 
 
121
  label = new QLabel( i18n( "e.g. ssh -l root remote.host.org ksysguardd" ) );
 
122
  groupLayout->addWidget( label, 3, 2, 1, 2 );
 
123
 
 
124
  layout->addWidget( group, 1, 0, 1, 2 );
 
125
 
 
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()));
 
135
}
 
136
 
 
137
HostConnector::~HostConnector()
 
138
{
 
139
}
 
140
 
 
141
void HostConnector::slotHostNameChanged( const QString &_text )
 
142
{
 
143
    enableButtonOk( !_text.isEmpty() );
 
144
}
 
145
 
 
146
void HostConnector::setHostNames( const QStringList &list )
 
147
{
 
148
  mHostNames->addItems( list );
 
149
}
 
150
 
 
151
QStringList HostConnector::hostNames() const
 
152
{
 
153
  QStringList list;
 
154
 
 
155
        for ( int i = 0; i < mHostNames->count(); ++i )
 
156
    list.append( mHostNames->itemText( i ) );
 
157
 
 
158
  return list;
 
159
}
 
160
 
 
161
void HostConnector::setCommands( const QStringList &list )
 
162
{
 
163
  mCommands->addItems( list );
 
164
}
 
165
 
 
166
QStringList HostConnector::commands() const
 
167
{
 
168
  QStringList list;
 
169
 
 
170
        for ( int i = 0; i < mCommands->count(); ++i )
 
171
    list.append( mCommands->itemText( i ) );
 
172
 
 
173
  return list;
 
174
}
 
175
 
 
176
void HostConnector::setCurrentHostName( const QString &hostName )
 
177
{
 
178
  if ( !hostName.isEmpty() ) {
 
179
    mHostNames->hide();
 
180
    mHostNameLabel->setText( hostName );
 
181
    mHostNameLabel->show();
 
182
    enableButtonOk( true );//enable true when mHostNames is empty and hidden fix #66955
 
183
  } else {
 
184
    mHostNameLabel->hide();
 
185
    mHostNames->show();
 
186
    mHostNames->setFocus();
 
187
  }
 
188
}
 
189
 
 
190
QString HostConnector::currentHostName() const
 
191
{
 
192
  return mHostNames->currentText();
 
193
}
 
194
 
 
195
QString HostConnector::currentCommand() const
 
196
{
 
197
  return mCommands->currentText();
 
198
}
 
199
 
 
200
int HostConnector::port() const
 
201
{
 
202
  return mPort->value();
 
203
}
 
204
 
 
205
bool HostConnector::useSsh() const
 
206
{
 
207
  return mUseSsh->isChecked();
 
208
}
 
209
 
 
210
bool HostConnector::useRsh() const
 
211
{
 
212
  return mUseRsh->isChecked();
 
213
}
 
214
 
 
215
bool HostConnector::useDaemon() const
 
216
{
 
217
  return mUseDaemon->isChecked();
 
218
}
 
219
 
 
220
bool HostConnector::useCustom() const
 
221
{
 
222
  return mUseCustom->isChecked();
 
223
}
 
224
 
 
225
void HostConnector::slotHelp()
 
226
{
 
227
  KToolInvocation::invokeHelp( "connectingtootherhosts", "ksysguard" );
 
228
}
 
229
 
 
230
#include "HostConnector.moc"