2
* Copyright (c) 2001 Dawit Alemayehu <adawit@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include <qwhatsthis.h>
23
#include <qpushbutton.h>
27
#include <kcombobox.h>
28
#include <klineedit.h>
29
#include <kurllabel.h>
31
#include "fakeuaprovider.h"
32
#include "uagentproviderdlg.h"
33
#include "uagentproviderdlg_ui.h"
35
UALineEdit::UALineEdit( QWidget *parent, const char *name )
36
:KLineEdit( parent, name )
38
// For now do not accept any drops since they might contain
39
// characters we do not accept.
40
// TODO: Re-implement ::dropEvent to allow acceptable formats...
41
setAcceptDrops( false );
44
void UALineEdit::keyPressEvent( QKeyEvent* e )
47
QString keycode = e->text();
48
if ( (key >= Qt::Key_Escape && key <= Qt::Key_Help) || key == Qt::Key_Period ||
49
(cursorPosition() > 0 && key == Qt::Key_Minus) ||
50
(!keycode.isEmpty() && keycode.unicode()->isLetterOrNumber()) )
52
KLineEdit::keyPressEvent(e);
58
UAProviderDlg::UAProviderDlg( const QString& caption, QWidget *parent,
59
FakeUASProvider* provider, const char *name )
60
:KDialog(parent, name, true), m_provider(provider)
62
setCaption ( caption );
64
QVBoxLayout* mainLayout = new QVBoxLayout(this, 0, 0);
66
dlg = new UAProviderDlgUI (this);
67
mainLayout->addWidget(dlg);
68
//dlg->leIdentity->setEnableSqueezedText( true );
79
UAProviderDlg::~UAProviderDlg()
83
void UAProviderDlg::init()
85
connect( dlg->pbOk, SIGNAL(clicked()), SLOT(accept()) );
86
connect( dlg->pbCancel, SIGNAL(clicked()), SLOT(reject()) );
88
connect( dlg->leSite, SIGNAL(textChanged(const QString&)),
89
SLOT(slotTextChanged( const QString&)) );
91
connect( dlg->cbAlias, SIGNAL(activated(const QString&)),
92
SLOT(slotActivated(const QString&)) );
94
dlg->cbAlias->clear();
95
dlg->cbAlias->insertStringList( m_provider->userAgentAliasList() );
96
dlg->cbAlias->insertItem( "", 0 );
97
dlg->cbAlias->listBox()->sort();
99
dlg->leSite->setFocus();
102
void UAProviderDlg::slotActivated( const QString& text )
104
if ( text.isEmpty() )
105
dlg->leIdentity->setText( "" );
107
dlg->leIdentity->setText( m_provider->agentStr(text) );
109
dlg->pbOk->setEnabled( (!dlg->leSite->text().isEmpty() && !text.isEmpty()) );
112
void UAProviderDlg::slotTextChanged( const QString& text )
114
dlg->pbOk->setEnabled( (!text.isEmpty() && !dlg->cbAlias->currentText().isEmpty()) );
117
void UAProviderDlg::setSiteName( const QString& text )
119
dlg->leSite->setText( text );
122
void UAProviderDlg::setIdentity( const QString& text )
124
int id = dlg->cbAlias->listBox()->index( dlg->cbAlias->listBox()->findItem(text) );
125
dlg->cbAlias->setCurrentItem( id );
126
slotActivated( dlg->cbAlias->currentText() );
127
if ( !dlg->leSite->isEnabled() )
128
dlg->cbAlias->setFocus();
131
QString UAProviderDlg::siteName()
133
QString site_name=dlg->leSite->text().lower();
134
site_name = site_name.remove( "https://" );
135
site_name = site_name.remove( "http://" );
139
QString UAProviderDlg::identity()
141
return dlg->cbAlias->currentText();
144
QString UAProviderDlg::alias()
146
return dlg->leIdentity->text();
149
#include "uagentproviderdlg.moc"