Warning, file /sdk/kdesvn/src/urldlg.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2009 by Rajko Albrecht                             *
0003  *   ral@alwins-world.de                                                   *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0019  ***************************************************************************/
0020 #include "urldlg.h"
0021 #include "ui_urldlg.h"
0022 
0023 #include <KUrlRequester>
0024 #include <KConfigGroup>
0025 #include <KHistoryComboBox>
0026 #include <KLocalizedString>
0027 #include <KSharedConfig>
0028 #include <QLabel>
0029 #include <QVBoxLayout>
0030 
0031 UrlDlg::UrlDlg(QWidget *parent)
0032     : QDialog(parent)
0033     , m_urlRequester(nullptr)
0034     , m_ui(new Ui::UrlDlg)
0035 {
0036     m_ui->setupUi(this);
0037     m_ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
0038     m_ui->buttonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::CTRL | Qt::Key_Return);
0039 
0040     KHistoryComboBox *combo = new KHistoryComboBox(this);
0041     combo->setDuplicatesEnabled(false);
0042     KConfigGroup kc = KSharedConfig::openConfig()->group("Open-repository settings");
0043     int max = kc.readEntry(QLatin1String("Maximum history"), 15);
0044     combo->setMaxCount(max);
0045     const QStringList list = kc.readEntry(QLatin1String("History"), QStringList());
0046     combo->setHistoryItems(list);
0047     combo->setMinimumWidth(100);
0048     combo->adjustSize();
0049     if (combo->width() > 300) {
0050         combo->resize(300, combo->height());
0051     }
0052 
0053     m_urlRequester = new KUrlRequester(combo, this);
0054     m_ui->topLayout->insertWidget(1, m_urlRequester);
0055     m_urlRequester->setFocus();
0056     m_urlRequester->setMode(KFile::ExistingOnly | KFile::Directory);
0057     connect(m_urlRequester->comboBox(), &KComboBox::currentTextChanged,
0058             this, &UrlDlg::slotTextChanged);
0059 
0060     slotTextChanged(QString());
0061     m_urlRequester->adjustSize();
0062 
0063     connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &UrlDlg::accept);
0064 }
0065 
0066 UrlDlg::~UrlDlg()
0067 {
0068     delete m_ui;
0069 }
0070 
0071 void UrlDlg::accept()
0072 {
0073     KHistoryComboBox *combo = static_cast<KHistoryComboBox *>(m_urlRequester->comboBox());
0074     if (combo) {
0075         combo->addToHistory(m_urlRequester->url().url());
0076         KConfigGroup kc = KSharedConfig::openConfig()->group("Open-repository settings");
0077         kc.writeEntry(QLatin1String("History"), combo->historyItems());
0078         kc.sync();
0079     }
0080     QDialog::accept();
0081 }
0082 
0083 /*!
0084     \fn UrlDlg::slotTextChanged(const QString&)
0085  */
0086 void UrlDlg::slotTextChanged(const QString &text)
0087 {
0088     bool state = !text.trimmed().isEmpty();
0089     m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(state);
0090 }
0091 
0092 /*!
0093     \fn UrlDlg::getUrl(QWidget*parent)
0094  */
0095 QUrl UrlDlg::getUrl(QWidget *parent)
0096 {
0097     QUrl ret;
0098     QPointer<UrlDlg> dlg(new UrlDlg(parent));
0099     dlg->setWindowTitle(i18nc("@title:window", "Open"));
0100     if (dlg->exec() == QDialog::Accepted) {
0101         // added by Wellu Mäkinen <wellu@wellu.org>
0102         //
0103         // get rid of leading whitespace
0104         // that is %20 in encoded form
0105         QString url = dlg->m_urlRequester->url().toString();
0106 
0107         // decodes %20 to normal spaces
0108         // trims the whitespace from both ends
0109         // of the URL
0110         ret = QUrl(url.trimmed());
0111     }
0112     delete dlg;
0113     return ret;
0114 }