File indexing completed on 2024-04-14 05:34:16

0001 /*
0002     SPDX-FileCopyrightText: 2011 Vishesh Yadav <vishesh3y@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "tagdialog.h"
0008 #include "hgwrapper.h"
0009 
0010 #include <QLineEdit>
0011 #include <KComboBox>
0012 #include <KLocalizedString>
0013 #include <KMessageBox>
0014 
0015 HgTagDialog::HgTagDialog(QWidget *parent):
0016     DialogBase(QDialogButtonBox::NoButton, parent)
0017 {
0018     // dialog properties
0019     this->setWindowTitle(xi18nc("@title:window",
0020                 "<application>Hg</application> Tag"));
0021 
0022     // UI 
0023     QVBoxLayout *vbox = new QVBoxLayout;
0024 
0025     m_tagComboBox = new KComboBox;
0026     m_tagComboBox->setEditable(true);
0027     vbox->addWidget(m_tagComboBox);
0028 
0029     QHBoxLayout *buttonLayout = new QHBoxLayout;
0030     m_createTag = new QPushButton(i18n("Create New Tag"));
0031     m_removeTag = new QPushButton(i18n("Remove Tag"));
0032     m_updateTag = new QPushButton(i18n("Switch Tag"));
0033     buttonLayout->addWidget(m_createTag);
0034     buttonLayout->addWidget(m_removeTag);
0035     buttonLayout->addWidget(m_updateTag);
0036     vbox->addLayout(buttonLayout);
0037 
0038     m_createTag->setEnabled(false);
0039     m_updateTag->setEnabled(false);
0040     m_removeTag->setEnabled(false);
0041 
0042     updateInitialDialog();
0043     slotUpdateDialog(QString());
0044     layout()->insertLayout(0, vbox);
0045 
0046     slotUpdateDialog(m_tagComboBox->currentText());
0047     
0048     // connections
0049     connect(m_createTag, &QAbstractButton::clicked,
0050             this, &HgTagDialog::slotCreateTag);
0051     connect(m_removeTag, &QAbstractButton::clicked,
0052             this, &HgTagDialog::slotRemoveTag);
0053     connect(m_updateTag, &QAbstractButton::clicked,
0054             this, &HgTagDialog::slotSwitch);
0055     connect(m_tagComboBox, &QComboBox::editTextChanged,
0056             this, &HgTagDialog::slotUpdateDialog);
0057     connect(m_tagComboBox->lineEdit(), &QLineEdit::textChanged,
0058             this, &HgTagDialog::slotUpdateDialog);
0059 }
0060 
0061 void HgTagDialog::updateInitialDialog()
0062 {
0063     HgWrapper *hgWrapper = HgWrapper::instance();
0064     // update combo box
0065     m_tagList = hgWrapper->getTags();
0066     m_tagComboBox->addItems(m_tagList);
0067 
0068 }
0069 
0070 void HgTagDialog::slotUpdateDialog(const QString &text)
0071 {
0072     // update pushbuttons
0073     if (text.length() == 0) {
0074         m_createTag->setEnabled(false);
0075         m_updateTag->setEnabled(false);
0076         m_removeTag->setEnabled(false);
0077     }
0078     else if (m_tagList.contains(text)) {
0079         m_createTag->setEnabled(false);
0080         m_updateTag->setEnabled(true);
0081         m_removeTag->setEnabled(true);
0082     }
0083     else {
0084         m_createTag->setEnabled(true);
0085         m_updateTag->setEnabled(false);
0086         m_removeTag->setEnabled(false);
0087     }
0088 }
0089 
0090 void HgTagDialog::slotSwitch()
0091 {
0092     HgWrapper *hgWrapper = HgWrapper::instance();
0093     QString out;
0094     QStringList args;
0095     args << QLatin1String("-c");
0096     args << m_tagComboBox->currentText();
0097     if (hgWrapper->executeCommand(QLatin1String("update"), args, out)) {
0098         //KMessageBox::information(this, i18n("Updated working directory!"));
0099         done(QDialog::Accepted);
0100     }
0101     else {
0102         KMessageBox::error(this, i18n("Some error occurred"));
0103     }
0104 }
0105 
0106 void HgTagDialog::slotRemoveTag()
0107 {
0108     HgWrapper *hgWrapper = HgWrapper::instance();
0109     QString out;
0110     QStringList args;
0111     args << QLatin1String("--remove");
0112     args << m_tagComboBox->currentText();
0113     if (hgWrapper->executeCommand(QLatin1String("tag"), args, out)) {
0114         //KMessageBox::information(this, xi18nc("Removed tag successfully!"));
0115         done(QDialog::Accepted);
0116     }
0117     else {
0118         KMessageBox::error(this, i18n("Some error occurred"));
0119     }
0120 }
0121 
0122 void HgTagDialog::slotCreateTag()
0123 {
0124     HgWrapper *hgWrapper = HgWrapper::instance();
0125     QString out;
0126     QStringList args;
0127     args << m_tagComboBox->currentText();
0128     if (hgWrapper->executeCommand(QLatin1String("tag"), args, out)) {
0129         KMessageBox::information(this, i18n("Created tag successfully!"));
0130         done(QDialog::Accepted);
0131     }
0132     else {
0133         KMessageBox::error(this, i18n("Some error occurred"));
0134     }
0135 }
0136 
0137 
0138 
0139 #include "moc_tagdialog.cpp"