File indexing completed on 2024-09-15 07:54:56
0001 /* 0002 SPDX-FileCopyrightText: 2011 Vishesh Yadav <vishesh3y@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "renamedialog.h" 0008 #include "hgwrapper.h" 0009 0010 #include <QGroupBox> 0011 #include <QGridLayout> 0012 #include <QLabel> 0013 #include <QDir> 0014 #include <QLineEdit> 0015 #include <KLocalizedString> 0016 #include <KFileItem> 0017 0018 HgRenameDialog::HgRenameDialog(const KFileItem &source, QWidget *parent): 0019 DialogBase(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, parent), 0020 m_source(source.name()), 0021 m_source_dir(QDir(source.url().fileName()).dirName()) //FIXME seems to be unused at all, anyway be careful porting to pure KF5 0022 // m_source_dir(source.url().directory()) 0023 { 0024 this->setWindowTitle(xi18nc("@title:window", 0025 "<application>Hg</application> Rename")); 0026 0027 okButton()->setText(xi18nc("@action:button", "Rename")); 0028 okButton()->setIcon(QIcon::fromTheme(QStringLiteral("list-rename"))); 0029 0030 QGridLayout *mainLayout = new QGridLayout(this); 0031 0032 QLabel *sourceLabel = new QLabel(xi18nc("@label:label to source file", 0033 "Source "), this); 0034 QLabel *sourceFileLabel = new QLabel(QLatin1String("<b>") + m_source + QLatin1String("</b>")); 0035 mainLayout->addWidget(sourceLabel, 0, 0); 0036 mainLayout->addWidget(sourceFileLabel, 0, 1); 0037 0038 QLabel *destinationLabel 0039 = new QLabel(xi18nc("@label:rename", "Rename to "), this); 0040 m_destinationFile = new QLineEdit(m_source, this); 0041 mainLayout->addWidget(destinationLabel, 1, 0); 0042 mainLayout->addWidget(m_destinationFile, 1, 1); 0043 0044 layout()->insertLayout(0, mainLayout); 0045 0046 m_destinationFile->setFocus(); 0047 m_destinationFile->selectAll(); 0048 0049 connect(m_destinationFile, &QLineEdit::textChanged, 0050 this, &HgRenameDialog::slotTextChanged); 0051 } 0052 0053 void HgRenameDialog::slotTextChanged(const QString &text) 0054 { 0055 okButton()->setEnabled(text.length() != 0); 0056 } 0057 0058 void HgRenameDialog::done(int r) 0059 { 0060 if (r == QDialog::Accepted) { 0061 HgWrapper *hgi = HgWrapper::instance(); 0062 hgi->renameFile(source(), destination()); 0063 } 0064 QDialog::done(r); 0065 } 0066 0067 QString HgRenameDialog::source() const 0068 { 0069 return m_source; 0070 } 0071 0072 QString HgRenameDialog::destination() const 0073 { 0074 return m_destinationFile->text(); 0075 } 0076 0077 0078 0079 #include "moc_renamedialog.cpp"