File indexing completed on 2025-01-05 05:14:49

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "diffopendialog.h"
0008 
0009 #include <KLocalizedString>
0010 #include <QFileDialog>
0011 #include <QSettings>
0012 
0013 DiffOpenDialog::DiffOpenDialog(QWidget *parent)
0014     : AppDialog(parent)
0015 {
0016     setupUi(this);
0017     radioButtonCompareFiles->setChecked(true);
0018     widgetSelectDirectories->hide();
0019     readSettings();
0020     // TODO update ok button enabled
0021 
0022     lineEditNewDirectory->setMode(KFile::Mode::Directory);
0023     lineEditOldDirectory->setMode(KFile::Mode::Directory);
0024 }
0025 
0026 DiffOpenDialog::~DiffOpenDialog()
0027 {
0028     readSettings();
0029 }
0030 
0031 void DiffOpenDialog::readSettings()
0032 {
0033     QSettings s;
0034     s.beginGroup(QStringLiteral("diff"));
0035     s.setValue(QStringLiteral("oldFile"), lineEditOldFile->text());
0036     s.setValue(QStringLiteral("newFile"), lineEditNewFile->text());
0037     s.setValue(QStringLiteral("oldDir"), lineEditOldDirectory->url().toLocalFile());
0038     s.setValue(QStringLiteral("newDir"), lineEditNewDirectory->url().toLocalFile());
0039     s.endGroup();
0040     s.sync();
0041 }
0042 
0043 void DiffOpenDialog::saveSettings()
0044 {
0045     QSettings s;
0046     s.beginGroup(QStringLiteral("diff"));
0047     lineEditOldFile->setText(s.value(QStringLiteral("oldFile")).toString());
0048     lineEditNewFile->setText(s.value(QStringLiteral("newFile")).toString());
0049     lineEditOldDirectory->setText(s.value(QStringLiteral("oldDir")).toString());
0050     lineEditNewDirectory->setText(s.value(QStringLiteral("newDir")).toString());
0051     s.endGroup();
0052 }
0053 
0054 QString DiffOpenDialog::oldFile() const
0055 {
0056     return lineEditOldFile->text();
0057 }
0058 
0059 QString DiffOpenDialog::newFile() const
0060 {
0061     return lineEditNewFile->text();
0062 }
0063 
0064 QString DiffOpenDialog::oldDir() const
0065 {
0066     return lineEditOldDirectory->text();
0067 }
0068 
0069 QString DiffOpenDialog::newDir() const
0070 {
0071     return lineEditNewDirectory->text();
0072 }
0073 
0074 DiffOpenDialog::Mode DiffOpenDialog::mode() const
0075 {
0076     return radioButtonCompareFiles->isChecked() ? Files : Dirs;
0077 }
0078 
0079 #include "moc_diffopendialog.cpp"