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

0001 /*
0002     SPDX-FileCopyrightText: 2004 Otto Bruggeman <otto.bruggeman@home.nl>
0003     SPDX-FileCopyrightText: 2007-2011 Kevin Kofler <kevin.kofler@chello.at>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "filespage.h"
0009 
0010 #include <QLayout>
0011 #include <QGroupBox>
0012 #include <QVBoxLayout>
0013 #include <QHBoxLayout>
0014 
0015 #include <KCharsets>
0016 #include <KConfig>
0017 #include <KLocalizedString>
0018 #include <KUrlComboBox>
0019 #include <KUrlRequester>
0020 
0021 #include "filessettings.h"
0022 
0023 FilesPage::FilesPage() : QFrame()
0024 {
0025     QVBoxLayout* layout = new QVBoxLayout(this);
0026 
0027     m_firstGB = new QGroupBox(QStringLiteral("You have to set this moron :)"), this);  // whut?
0028     layout->addWidget(m_firstGB);
0029     QHBoxLayout* gb1Layout = new QHBoxLayout(m_firstGB);
0030     m_firstURLComboBox = new KUrlComboBox(KUrlComboBox::Both, true, m_firstGB);
0031     m_firstURLComboBox->setMaxItems(10);
0032     m_firstURLComboBox->setObjectName(QStringLiteral("SourceURLComboBox"));
0033     m_firstURLRequester = new KUrlRequester(m_firstURLComboBox, nullptr);
0034     gb1Layout->addWidget(m_firstURLComboBox);
0035     m_firstURLComboBox->setFocus();
0036 
0037     QPushButton* button = new QPushButton(this);
0038     button->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
0039     button->setToolTip(i18nc("@info:tooltip", "Select file"));
0040     button->setProperty("combobox", QStringLiteral("SourceURLComboBox"));
0041     button->setProperty("folder", false);
0042     connect(button, &QPushButton::clicked, this, &FilesPage::open);
0043     gb1Layout->addWidget(button);
0044 
0045     button = new QPushButton(this);
0046     button->setIcon(QIcon::fromTheme(QStringLiteral("folder-open")));
0047     QSizePolicy sp = button->sizePolicy();
0048     sp.setRetainSizeWhenHidden(true);
0049     button->setSizePolicy(sp);
0050     button->setObjectName(QStringLiteral("firstURLOpenFolder"));
0051     button->setToolTip(i18nc("@info:tooltip", "Select folder"));
0052     button->setProperty("combobox", QStringLiteral("SourceURLComboBox"));
0053     button->setProperty("folder", true);
0054     connect(button, &QPushButton::clicked, this, &FilesPage::open);
0055     gb1Layout->addWidget(button);
0056 
0057     m_secondGB = new QGroupBox(QStringLiteral("This too moron !"), this);  // whut again?
0058     layout->addWidget(m_secondGB);
0059     QHBoxLayout* gb2Layout = new QHBoxLayout(m_secondGB);
0060     m_secondURLComboBox = new KUrlComboBox(KUrlComboBox::Both, true, m_secondGB);
0061     m_secondURLComboBox->setMaxItems(10);
0062     m_secondURLComboBox->setObjectName(QStringLiteral("DestURLComboBox"));
0063     m_secondURLRequester = new KUrlRequester(m_secondURLComboBox, nullptr);
0064     gb2Layout->addWidget(m_secondURLComboBox);
0065 
0066     button = new QPushButton(this);
0067     button->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
0068     button->setToolTip(i18nc("@info:tooltip", "Select file"));
0069     button->setProperty("combobox", QStringLiteral("DestURLComboBox"));
0070     button->setProperty("folder", false);
0071     connect(button, &QPushButton::clicked, this, &FilesPage::open);
0072     gb2Layout->addWidget(button);
0073 
0074     button = new QPushButton(this);
0075     button->setIcon(QIcon::fromTheme(QStringLiteral("folder-open")));
0076     button->setObjectName(QStringLiteral("secondURLOpenFolder"));
0077     sp = button->sizePolicy();
0078     sp.setRetainSizeWhenHidden(true);
0079     button->setSizePolicy(sp);
0080     button->setToolTip(i18nc("@info:tooltip", "Select folder"));
0081     button->setProperty("combobox", QStringLiteral("DestURLComboBox"));
0082     button->setProperty("folder", true);
0083     connect(button, &QPushButton::clicked, this, &FilesPage::open);
0084     gb2Layout->addWidget(button);
0085 
0086 
0087     m_thirdGB = new QGroupBox(i18nc("@title:group", "Encoding"), this);
0088     layout->addWidget(m_thirdGB);
0089     QHBoxLayout* gb3Layout = new QHBoxLayout(m_thirdGB);
0090     m_encodingComboBox = new KComboBox(false, m_thirdGB);
0091     m_encodingComboBox->setObjectName(QStringLiteral("encoding_combobox"));
0092     m_encodingComboBox->insertItem(0, i18nc("@item:inlistbox encoding", "Default"));
0093     m_encodingComboBox->insertItems(1, KCharsets::charsets()->availableEncodingNames());
0094     gb3Layout->addWidget(m_encodingComboBox);
0095 
0096     layout->addWidget(m_firstGB);
0097     layout->addWidget(m_secondGB);
0098     layout->addWidget(m_thirdGB);
0099 
0100     layout->addStretch(1);
0101 }
0102 
0103 FilesPage::~FilesPage()
0104 {
0105     delete m_firstURLRequester;
0106     m_firstURLRequester = nullptr;
0107     delete m_secondURLRequester;
0108     m_secondURLRequester = nullptr;
0109     m_settings = nullptr;
0110 }
0111 
0112 void FilesPage::open()
0113 {
0114     QPushButton* button = (QPushButton*) sender();
0115     bool selectFolders = button->property("folder").toBool();
0116     KUrlComboBox* urlComboBox = findChild<KUrlComboBox*>(button->property("combobox").toString());
0117 
0118     doOpen(urlComboBox, selectFolders);
0119 }
0120 
0121 void FilesPage::doOpen(KUrlComboBox* urlComboBox, bool selectFolders)
0122 {
0123     QUrl currentUrl = QUrl::fromUserInput(urlComboBox->currentText());
0124 
0125     QUrl newUrl = selectFolders ? QFileDialog::getExistingDirectoryUrl(this,
0126                                                                        i18nc("@title:window", "Select Folder"),
0127                                                                        currentUrl,
0128                                                                        QFileDialog::ReadOnly | QFileDialog::ShowDirsOnly)
0129                                 : QFileDialog::getOpenFileUrl(this,
0130                                                               i18nc("@title:window", "Select File"),
0131                                                               currentUrl);
0132     if (!newUrl.isEmpty())
0133     {
0134         // remove newUrl if already exists and add it as the first item
0135         urlComboBox->setUrl(newUrl);
0136         Q_EMIT urlChanged();
0137     }
0138 
0139 }
0140 
0141 KUrlRequester* FilesPage::firstURLRequester() const
0142 {
0143     return m_firstURLRequester;
0144 }
0145 
0146 KUrlRequester* FilesPage::secondURLRequester() const
0147 {
0148     return m_secondURLRequester;
0149 }
0150 
0151 QString FilesPage::encoding() const
0152 {
0153     return m_encodingComboBox->currentText();
0154 }
0155 
0156 void FilesPage::setFirstGroupBoxTitle(const QString& title)
0157 {
0158     m_firstGB->setTitle(title);
0159 }
0160 
0161 void FilesPage::setSecondGroupBoxTitle(const QString& title)
0162 {
0163     m_secondGB->setTitle(title);
0164 }
0165 
0166 void FilesPage::setURLsInComboBoxes()
0167 {
0168 //     qDebug() << "first : " << m_firstURLComboBox->currentText() ;
0169 //     qDebug() << "second: " << m_secondURLComboBox->currentText() ;
0170     m_firstURLComboBox->setUrl(QUrl::fromUserInput(m_firstURLComboBox->currentText(), QDir::currentPath(), QUrl::AssumeLocalFile));
0171     m_secondURLComboBox->setUrl(QUrl::fromUserInput(m_secondURLComboBox->currentText(), QDir::currentPath(), QUrl::AssumeLocalFile));
0172 }
0173 
0174 
0175 void FilesPage::setFirstURLRequesterMode(unsigned int mode)
0176 {
0177     m_firstURLRequester->setMode((KFile::Mode) mode);
0178     if ((mode & KFile::Directory) == 0)
0179     {
0180         QPushButton* button = findChild<QPushButton*>(QStringLiteral("firstURLOpenFolder"));
0181         button->setVisible(false);
0182     }
0183 }
0184 
0185 void FilesPage::setSecondURLRequesterMode(unsigned int mode)
0186 {
0187     m_secondURLRequester->setMode((KFile::Mode) mode);
0188     if ((mode & KFile::Directory) == 0)
0189     {
0190         QPushButton* button = findChild<QPushButton*>(QStringLiteral("secondURLOpenFolder"));
0191         button->setVisible(false);
0192     }
0193 }
0194 
0195 void FilesPage::setSettings(FilesSettings* settings)
0196 {
0197     m_settings = settings;
0198 
0199     m_firstURLComboBox->setUrls(m_settings->m_recentSources);
0200     m_firstURLComboBox->setUrl(QUrl::fromUserInput(m_settings->m_lastChosenSourceURL, QDir::currentPath(), QUrl::AssumeLocalFile));
0201     m_secondURLComboBox->setUrls(m_settings->m_recentDestinations);
0202     m_secondURLComboBox->setUrl(QUrl::fromUserInput(m_settings->m_lastChosenDestinationURL, QDir::currentPath(), QUrl::AssumeLocalFile));
0203     m_encodingComboBox->setCurrentIndex(m_encodingComboBox->findText(m_settings->m_encoding, Qt::MatchFixedString));
0204 }
0205 
0206 void FilesPage::restore()
0207 {
0208     // this shouldn't do a thing...
0209 }
0210 
0211 void FilesPage::apply()
0212 {
0213     // set the current items as the first ones
0214     m_firstURLComboBox->insertUrl(0, QUrl(m_firstURLComboBox->currentText()));
0215     m_secondURLComboBox->insertUrl(0, QUrl(m_secondURLComboBox->currentText()));
0216 
0217     m_settings->m_recentSources            = m_firstURLComboBox->urls();
0218     m_settings->m_lastChosenSourceURL      = m_firstURLComboBox->currentText();
0219     m_settings->m_recentDestinations       = m_secondURLComboBox->urls();
0220     m_settings->m_lastChosenDestinationURL = m_secondURLComboBox->currentText();
0221     m_settings->m_encoding                 = m_encodingComboBox->currentText();
0222 }
0223 
0224 void FilesPage::setDefaults()
0225 {
0226     m_firstURLComboBox->setUrls(QStringList());
0227     m_firstURLComboBox->setUrl(QUrl());
0228     m_secondURLComboBox->setUrls(QStringList());
0229     m_secondURLComboBox->setUrl(QUrl());
0230     m_encodingComboBox->setCurrentIndex(0);   // "Default"
0231 }
0232 
0233 #include "moc_filespage.cpp"