You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
228 lines
5.8 KiB
228 lines
5.8 KiB
15 years ago
|
/*
|
||
|
|
||
13 years ago
|
chooser widget for TDM
|
||
15 years ago
|
|
||
|
Copyright (C) 2002-2003 Oswald Buddenhagen <ossi@kde.org>
|
||
|
based on the chooser (C) 1999 by Harald Hoyer <Harald.Hoyer@RedHat.de>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation; either version 2 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
|
||
|
*/
|
||
|
|
||
|
#include <config.h>
|
||
|
|
||
|
#ifdef XDMCP
|
||
|
|
||
|
#include "kchooser.h"
|
||
|
#include "kconsole.h"
|
||
13 years ago
|
#include "tdmconfig.h"
|
||
|
#include "tdm_greet.h"
|
||
15 years ago
|
|
||
|
#include <klocale.h>
|
||
|
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqpopupmenu.h>
|
||
|
#include <tqsocketnotifier.h>
|
||
|
#include <tqlistview.h>
|
||
|
#include <tqlineedit.h>
|
||
15 years ago
|
|
||
|
#include <stdlib.h> // for free()
|
||
|
|
||
15 years ago
|
class ChooserListViewItem : public TQListViewItem {
|
||
15 years ago
|
public:
|
||
15 years ago
|
ChooserListViewItem( TQListView* parent, int _id, const TQString& nam, const TQString& sts )
|
||
|
: TQListViewItem( parent, nam, sts ) { id = _id; };
|
||
15 years ago
|
|
||
|
int id;
|
||
|
};
|
||
|
|
||
|
|
||
|
ChooserDlg::ChooserDlg()
|
||
|
: inherited()
|
||
|
{
|
||
|
completeMenu( LOGIN_REMOTE_ONLY, ex_greet, i18n("&Local Login"), ALT+Key_L );
|
||
|
|
||
15 years ago
|
TQBoxLayout *vbox = new TQVBoxLayout( this, 10, 10 );
|
||
15 years ago
|
|
||
15 years ago
|
TQLabel *title = new TQLabel( i18n("XDMCP Host Menu"), this );
|
||
13 years ago
|
title->setAlignment( AlignCenter );
|
||
15 years ago
|
vbox->addWidget( title );
|
||
|
|
||
15 years ago
|
host_view = new TQListView( this, "hosts" );
|
||
15 years ago
|
host_view->addColumn( i18n("Hostname") );
|
||
|
host_view->setColumnWidth( 0, fontMetrics().width( "login.crap.net" ) );
|
||
14 years ago
|
host_view->addColumn( i18n("Status") );
|
||
15 years ago
|
host_view->setMinimumWidth( fontMetrics().width( "login.crap.com Display not authorized to connect this server" ) );
|
||
15 years ago
|
host_view->setResizeMode( TQListView::LastColumn );
|
||
15 years ago
|
host_view->setAllColumnsShowFocus( true );
|
||
|
vbox->addWidget( host_view );
|
||
|
|
||
15 years ago
|
iline = new TQLineEdit( this );
|
||
15 years ago
|
iline->setEnabled( TRUE );
|
||
15 years ago
|
TQLabel *itxt = new TQLabel( iline, i18n("Hos&t:"), this );
|
||
|
TQPushButton *addButton = new TQPushButton( i18n("A&dd"), this );
|
||
|
connect( addButton, TQT_SIGNAL(clicked()), TQT_SLOT(addHostname()) );
|
||
|
TQBoxLayout *hibox = new TQHBoxLayout( vbox, 10 );
|
||
15 years ago
|
hibox->addWidget( itxt );
|
||
|
hibox->addWidget( iline );
|
||
|
hibox->addWidget( addButton );
|
||
|
|
||
|
// Buttons
|
||
15 years ago
|
TQPushButton *acceptButton = new TQPushButton( i18n("&Accept"), this );
|
||
15 years ago
|
acceptButton->setDefault( true );
|
||
15 years ago
|
TQPushButton *pingButton = new TQPushButton( i18n("&Refresh"), this );
|
||
15 years ago
|
|
||
15 years ago
|
TQBoxLayout *hbox = new TQHBoxLayout( vbox, 20 );
|
||
15 years ago
|
hbox->addWidget( acceptButton );
|
||
|
hbox->addWidget( pingButton );
|
||
|
hbox->addStretch( 1 );
|
||
|
|
||
|
if (optMenu) {
|
||
15 years ago
|
TQPushButton *menuButton = new TQPushButton( i18n("&Menu"), this );
|
||
15 years ago
|
menuButton->setPopup( optMenu );
|
||
|
hbox->addWidget( menuButton );
|
||
|
hbox->addStretch( 1 );
|
||
|
}
|
||
|
|
||
15 years ago
|
// TQPushButton *helpButton = new TQPushButton( i18n("&Help"), this );
|
||
15 years ago
|
// hbox->addWidget( helpButton );
|
||
|
|
||
13 years ago
|
#ifdef WITH_TDM_XCONSOLE
|
||
15 years ago
|
if (consoleView)
|
||
|
vbox->addWidget( consoleView );
|
||
|
#endif
|
||
|
|
||
14 years ago
|
sn = new TQSocketNotifier( rfd, TQSocketNotifier::Read, TQT_TQOBJECT(this) );
|
||
15 years ago
|
connect( sn, TQT_SIGNAL(activated( int )), TQT_SLOT(slotReadPipe()) );
|
||
15 years ago
|
|
||
15 years ago
|
connect( pingButton, TQT_SIGNAL(clicked()), TQT_SLOT(pingHosts()) );
|
||
|
connect( acceptButton, TQT_SIGNAL(clicked()), TQT_SLOT(accept()) );
|
||
|
// connect( helpButton, TQT_SIGNAL(clicked()), TQT_SLOT(slotHelp()) );
|
||
|
connect( host_view, TQT_SIGNAL(doubleClicked(TQListViewItem *)), TQT_SLOT(accept()) );
|
||
15 years ago
|
|
||
|
adjustGeometry();
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
void ChooserDlg::slotHelp()
|
||
|
{
|
||
|
KMessageBox::information(0,
|
||
|
i18n("Choose a host, you want to work on,\n"
|
||
|
"in the list or add one.\n\n"
|
||
|
"After this box, you must press cancel\n"
|
||
|
"in the Host Menu to enter a host. :("));
|
||
|
iline->setFocus();
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
void ChooserDlg::addHostname()
|
||
|
{
|
||
|
if (!iline->text().isEmpty()) {
|
||
|
GSendInt( G_Ch_RegisterHost );
|
||
|
GSendStr( iline->text().latin1() );
|
||
|
iline->clear();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ChooserDlg::pingHosts()
|
||
|
{
|
||
|
GSendInt( G_Ch_Refresh );
|
||
|
}
|
||
|
|
||
|
void ChooserDlg::accept()
|
||
|
{
|
||
13 years ago
|
if (focusWidget() == iline) {
|
||
15 years ago
|
if (!iline->text().isEmpty()) {
|
||
|
GSendInt( G_Ch_DirectChoice );
|
||
|
GSendStr( iline->text().latin1() );
|
||
|
iline->clear();
|
||
|
}
|
||
|
return;
|
||
13 years ago
|
} else /*if (focusWidget() == host_view)*/ {
|
||
15 years ago
|
TQListViewItem *item = host_view->currentItem();
|
||
15 years ago
|
if (item) {
|
||
|
GSendInt( G_Ready );
|
||
|
GSendInt( ((ChooserListViewItem *)item)->id );
|
||
|
::exit( EX_NORMAL );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ChooserDlg::reject()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString ChooserDlg::recvStr()
|
||
15 years ago
|
{
|
||
|
char *arr = GRecvStr();
|
||
|
if (arr) {
|
||
13 years ago
|
TQString str = TQString::fromLatin1( arr );
|
||
15 years ago
|
free( arr );
|
||
|
return str;
|
||
|
} else
|
||
|
return i18n("<unknown>");
|
||
|
}
|
||
|
|
||
15 years ago
|
TQListViewItem *ChooserDlg::findItem( int id )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListViewItem *itm;
|
||
|
for (TQListViewItemIterator it( host_view ); (itm = it.current()); ++it)
|
||
15 years ago
|
if (((ChooserListViewItem *)itm)->id == id)
|
||
|
return itm;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void ChooserDlg::slotReadPipe()
|
||
|
{
|
||
|
int id;
|
||
15 years ago
|
TQString nam, sts;
|
||
15 years ago
|
|
||
|
int cmd = GRecvInt();
|
||
|
switch (cmd) {
|
||
|
case G_Ch_AddHost:
|
||
|
case G_Ch_ChangeHost:
|
||
|
id = GRecvInt();
|
||
|
nam = recvStr();
|
||
|
sts = recvStr();
|
||
|
GRecvInt(); /* swallow willing for now */
|
||
|
if (cmd == G_Ch_AddHost)
|
||
|
host_view->insertItem(
|
||
|
new ChooserListViewItem( host_view, id, nam, sts ) );
|
||
|
else {
|
||
15 years ago
|
TQListViewItem *itm = findItem( id );
|
||
15 years ago
|
itm->setText( 0, nam );
|
||
|
itm->setText( 1, sts );
|
||
|
}
|
||
|
break;
|
||
|
case G_Ch_RemoveHost:
|
||
|
delete findItem( GRecvInt() );
|
||
|
break;
|
||
|
case G_Ch_BadHost:
|
||
15 years ago
|
KFMsgBox::box( this, TQMessageBox::Warning, i18n("Unknown host %1").arg( recvStr() ) );
|
||
15 years ago
|
break;
|
||
|
case G_Ch_Exit:
|
||
|
done( ex_exit );
|
||
|
break;
|
||
|
default: /* XXX huuh ...? */
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#include "kchooser.moc"
|
||
|
|
||
|
#endif
|