File indexing completed on 2024-04-21 05:41:02

0001 /*
0002     SPDX-FileCopyrightText: 2011 Vishesh Yadav <vishesh3y@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "pathselector.h"
0008 #include "hgconfig.h"
0009 
0010 #include <QHBoxLayout>
0011 #include <QVBoxLayout>
0012 #include <QLineEdit>
0013 #include <KComboBox>
0014 #include <KLocalizedString>
0015 
0016 HgPathSelector::HgPathSelector(QWidget *parent) :
0017     QWidget(parent)
0018 {
0019     setupUI();
0020     reload();
0021 
0022     // connections
0023     connect(m_selectPathAlias, SIGNAL(currentIndexChanged(int)), 
0024             this, SLOT(slotChangeEditUrl(int)));
0025     connect(m_selectPathAlias, SIGNAL(highlighted(int)), 
0026             this, SLOT(slotChangeEditUrl(int)));
0027 }
0028 
0029 void HgPathSelector::setupUI()
0030 {
0031     QHBoxLayout *urlLayout = new QHBoxLayout;
0032     m_selectPathAlias = new KComboBox;
0033     m_urlEdit = new QLineEdit;
0034     m_urlEdit->setReadOnly(true);
0035 
0036     urlLayout->addWidget(m_selectPathAlias);
0037     urlLayout->addWidget(m_urlEdit);
0038 
0039     setLayout(urlLayout);
0040 }
0041 
0042 void HgPathSelector::reload()
0043 {
0044     HgConfig hgc(HgConfig::RepoConfig);
0045     m_pathList = hgc.repoRemotePathList();
0046 
0047     m_selectPathAlias->clear();
0048 
0049     QMutableMapIterator<QString, QString> it(m_pathList);
0050     while (it.hasNext()) {
0051         it.next();
0052         if (it.key() == QLatin1String("default")) {
0053             m_selectPathAlias->insertItem(0, it.key());
0054         }
0055         else {
0056             m_selectPathAlias->addItem(it.key());
0057         }
0058     }
0059 
0060     m_selectPathAlias->addItem(xi18nc("@label:combobox", "edit"));
0061     slotChangeEditUrl(0);
0062 }
0063 
0064 
0065 void HgPathSelector::slotChangeEditUrl(int index)
0066 {
0067     if (index == m_selectPathAlias->count() - 1) { ///enter URL manually
0068         m_urlEdit->setReadOnly(false);
0069         m_urlEdit->clear();
0070         m_urlEdit->setFocus();
0071     }
0072     else {
0073         QString url = m_pathList[m_selectPathAlias->itemText(index)];
0074         m_urlEdit->setText(url);
0075         m_urlEdit->setReadOnly(true);
0076     }
0077 }
0078 
0079 const QString HgPathSelector::remote() const
0080 {
0081     return (m_selectPathAlias->currentIndex() == m_selectPathAlias->count()-1)?m_urlEdit->text():m_selectPathAlias->currentText();
0082 }
0083 
0084 
0085 
0086 #include "moc_pathselector.cpp"