2 * Copyright (c) 2000 Malte Starostik <malte@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 #include "searchproviderdlg.h"
21 #include <kapplication.h>
22 #include <kcharsets.h>
23 #include <kmessagebox.h>
25 #include "searchprovider.h"
27 SearchProviderDialog::SearchProviderDialog(SearchProvider
*provider
,
33 setButtons( Ok
| Cancel
);
35 m_dlg
= new SearchProviderDlgUI (this);
38 showButtonSeparator(true);
40 m_dlg
->leQuery
->setMinimumWidth(kapp
->fontMetrics().maxWidth() * 40);
42 connect(m_dlg
->leName
, SIGNAL(textChanged(const QString
&)), SLOT(slotChanged()));
43 connect(m_dlg
->leQuery
, SIGNAL(textChanged(const QString
&)), SLOT(slotChanged()));
44 connect(m_dlg
->leShortcut
, SIGNAL(textChanged(const QString
&)), SLOT(slotChanged()));
47 QStringList charsets
= KGlobal::charsets()->availableEncodingNames();
48 charsets
.prepend(i18n("Default"));
49 m_dlg
->cbCharset
->addItems(charsets
);
50 connect(this,SIGNAL(okClicked()), this, SLOT(slotOk()));
53 setPlainCaption(i18n("Modify Search Provider"));
54 m_dlg
->leName
->setText(m_provider
->name());
55 m_dlg
->leQuery
->setText(m_provider
->query());
56 m_dlg
->leShortcut
->setText(m_provider
->keys().join(","));
57 m_dlg
->cbCharset
->setCurrentIndex(m_provider
->charset().isEmpty() ? 0 : charsets
.indexOf(m_provider
->charset()));
58 m_dlg
->leName
->setEnabled(false);
59 m_dlg
->leQuery
->setFocus();
63 setPlainCaption(i18n("New Search Provider"));
64 m_dlg
->leName
->setFocus();
65 enableButton(Ok
, false);
69 void SearchProviderDialog::slotChanged()
71 enableButton(Ok
, !(m_dlg
->leName
->text().isEmpty()
72 || m_dlg
->leShortcut
->text().isEmpty()
73 || m_dlg
->leQuery
->text().isEmpty()));
77 void SearchProviderDialog::slotButtonClicked(int button
) {
78 if (button
== KDialog::Ok
) {
79 if ((m_dlg
->leQuery
->text().indexOf("\\{") == -1)
80 && KMessageBox::warningContinueCancel(0,
81 i18n("The URI does not contain a \\{...} placeholder for the user query.\n"
82 "This means that the same page is always going to be visited, "
83 "regardless of what the user types."),
84 QString(), KGuiItem(i18n("Keep It"))) == KMessageBox::Cancel
) {
89 m_provider
= new SearchProvider
;
90 m_provider
->setName(m_dlg
->leName
->text().trimmed());
91 m_provider
->setQuery(m_dlg
->leQuery
->text().trimmed());
92 m_provider
->setKeys(m_dlg
->leShortcut
->text().trimmed().split(",", QString::SkipEmptyParts
));
93 m_provider
->setCharset(m_dlg
->cbCharset
->currentIndex() ? m_dlg
->cbCharset
->currentText() : QString());
96 KDialog::slotButtonClicked(button
);
100 #include "searchproviderdlg.moc"