add more spacing
[personal-kdebase.git] / apps / konqueror / settings / kio / useragentselectordlg.cpp
blob7aa58486f88edb3128073eef1dba182dded43497
1 /**
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.
19 // Own
20 #include "useragentselectordlg.h"
21 #include "ui_useragentselectordlg.h"
23 // Local
24 #include "useragentinfo.h"
26 // Qt
27 #include <QtGui/QBoxLayout>
28 #include <QtGui/QKeyEvent>
29 #include <QtGui/QLabel>
30 #include <QtGui/QLayout>
31 #include <QtGui/QPushButton>
32 #include <QtGui/QValidator>
33 #include <QtGui/QWidget>
35 // KDE
36 #include <kcombobox.h>
37 #include <kdebug.h>
38 #include <klineedit.h>
39 #include <klocale.h>
40 #include <kurllabel.h>
43 class UserAgentSelectorWidget : public QWidget, public Ui::UserAgentSelectorWidget
45 public:
46 UserAgentSelectorWidget(QWidget * parent = 0, Qt::WindowFlags f = 0)
47 :QWidget(parent, f)
49 setupUi(this);
53 class UserAgentSiteNameValidator : public QValidator
55 public:
56 UserAgentSiteNameValidator(QObject *parent)
57 :QValidator(parent)
59 setObjectName("UserAgentSiteNameValidator");
62 State validate(QString &input, int &) const
64 if (input.isEmpty())
65 return Intermediate;
67 if (input.startsWith(QChar('.')))
68 return Invalid;
70 const int length = input.length();
72 for(int i = 0 ; i < length; i++)
74 if (!input[i].isLetterOrNumber() && input[i] != '.' && input[i] != '-')
75 return Invalid;
78 return Acceptable;
83 UserAgentSelectorDlg::UserAgentSelectorDlg( const QString& caption, UserAgentInfo* info,
84 QWidget *parent, Qt::WindowFlags f )
85 :KDialog(parent, f),
86 m_userAgentInfo(info)
88 m_widget = new UserAgentSelectorWidget(this);
89 setMainWidget(m_widget);
91 setModal( true );
92 setWindowTitle ( caption );
93 setButtons( Ok|Cancel );
94 showButtonSeparator( true );
96 if (!m_userAgentInfo)
98 setEnabled( false );
99 return;
102 m_widget->aliasComboBox->clear();
103 m_widget->aliasComboBox->addItems( m_userAgentInfo->userAgentAliasList() );
104 m_widget->aliasComboBox->insertItem(0, QString());
105 m_widget->aliasComboBox->model()->sort(0);
106 m_widget->aliasComboBox->setCurrentIndex(0);
107 UserAgentSiteNameValidator* validator = new UserAgentSiteNameValidator(this);
108 m_widget->siteLineEdit->setValidator(validator);
109 m_widget->siteLineEdit->setFocus();
111 connect(m_widget->siteLineEdit, SIGNAL(textChanged(const QString&)),
112 SLOT(onHostNameChanged(const QString&)));
114 connect(m_widget->aliasComboBox, SIGNAL(activated(const QString&)),
115 SLOT(onAliasChanged(const QString&)));
117 enableButtonOk(false);
120 UserAgentSelectorDlg::~UserAgentSelectorDlg()
124 void UserAgentSelectorDlg::onAliasChanged( const QString& text )
126 if ( text.isEmpty() )
127 m_widget->identityLineEdit->setText( QString() );
128 else
129 m_widget->identityLineEdit->setText( m_userAgentInfo->agentStr(text) );
131 const bool enable = (!m_widget->siteLineEdit->text().isEmpty() && !text.isEmpty());
132 enableButtonOk(enable);
135 void UserAgentSelectorDlg::onHostNameChanged( const QString& text )
137 const bool enable = (!text.isEmpty() && !m_widget->aliasComboBox->currentText().isEmpty());
138 enableButtonOk(enable);
141 void UserAgentSelectorDlg::setSiteName( const QString& text )
143 m_widget->siteLineEdit->setText( text );
146 void UserAgentSelectorDlg::setIdentity( const QString& text )
148 int id = m_widget->aliasComboBox->findText( text );
149 if ( id != -1 )
150 m_widget->aliasComboBox->setCurrentIndex( id );
151 m_widget->identityLineEdit->setText(m_userAgentInfo->agentStr(m_widget->aliasComboBox->currentText() ));
152 if ( !m_widget->siteLineEdit->isEnabled() )
153 m_widget->aliasComboBox->setFocus();
156 QString UserAgentSelectorDlg::siteName()
158 return m_widget->siteLineEdit->text().toLower();
161 QString UserAgentSelectorDlg::identity()
163 return m_widget->aliasComboBox->currentText();
166 QString UserAgentSelectorDlg::alias()
168 return m_widget->identityLineEdit->text();
171 #include "useragentselectordlg.moc"