File indexing completed on 2022-10-04 17:30:24

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2010 Dominik Seichter <domseichter@web.de>
0003 
0004 #include "tokensortmodedialog.h"
0005 
0006 #include "pluginloader.h"
0007 #include "plugin.h"
0008 
0009 TokenSortModeDialog::TokenSortModeDialog(KRenameTokenSorter::ESimpleSortMode eSortMode, QWidget *parent)
0010     : QDialog(parent)
0011 {
0012     m_dialog.setupUi(this);
0013 
0014     m_dialog.radioAscending->setChecked(eSortMode == KRenameTokenSorter::eSimpleSortMode_Ascending);
0015     m_dialog.radioDescending->setChecked(eSortMode == KRenameTokenSorter::eSimpleSortMode_Descending);
0016     m_dialog.radioNumeric->setChecked(eSortMode == KRenameTokenSorter::eSimpleSortMode_Numeric);
0017 
0018     connect(m_dialog.radioPredefined, &QRadioButton::clicked,
0019             this, &TokenSortModeDialog::slotEnableControls);
0020     connect(m_dialog.radioCustom, &QRadioButton::clicked,
0021             this, &TokenSortModeDialog::slotEnableControls);
0022 
0023     m_dialog.comboPredefined->addItem(i18n("Access Date"), "accessdate;yyyyMMddHHmm");
0024     m_dialog.comboPredefined->addItem(i18n("Creation Date"), "creationdate;yyyyMMddHHmm");
0025     m_dialog.comboPredefined->addItem(i18n("Filesize"), "filesize");
0026     m_dialog.comboPredefined->addItem(i18n("Group"), "group");
0027     m_dialog.comboPredefined->addItem(i18n("Modification Date"), "modificationdate;yyyyMMddHHmm");
0028     m_dialog.comboPredefined->addItem(i18n("User"), "user");
0029 
0030     initTokens();
0031     slotEnableControls();
0032 }
0033 
0034 void TokenSortModeDialog::initTokens()
0035 {
0036     QStringList allTokens;
0037 
0038     QList<Plugin *>::const_iterator it = PluginLoader::Instance()->plugins().begin();
0039     while (it != PluginLoader::Instance()->plugins().end()) {
0040         if (((*it)->type() & ePluginType_Token)) {
0041             const QStringList &tokens = (*it)->supportedTokens();
0042             allTokens.append(tokens);
0043         }
0044 
0045         ++it;
0046     }
0047 
0048     allTokens.sort();
0049     m_dialog.comboToken->insertItems(-1, allTokens);
0050 }
0051 
0052 void TokenSortModeDialog::slotEnableControls()
0053 {
0054     m_dialog.comboToken->setEnabled(m_dialog.radioCustom->isChecked());
0055     m_dialog.comboPredefined->setEnabled(m_dialog.radioPredefined->isChecked());
0056 
0057 }
0058 
0059 KRenameTokenSorter::ESimpleSortMode TokenSortModeDialog::getSortMode() const
0060 {
0061     KRenameTokenSorter::ESimpleSortMode eMode = KRenameTokenSorter::eSimpleSortMode_Ascending;
0062 
0063     if (m_dialog.radioAscending->isChecked()) {
0064         eMode = KRenameTokenSorter::eSimpleSortMode_Ascending;
0065     } else if (m_dialog.radioDescending->isChecked()) {
0066         eMode = KRenameTokenSorter::eSimpleSortMode_Descending;
0067     } else if (m_dialog.radioNumeric->isChecked()) {
0068         eMode = KRenameTokenSorter::eSimpleSortMode_Numeric;
0069     }
0070 
0071     return eMode;
0072 }
0073 
0074 QString TokenSortModeDialog::getToken() const
0075 {
0076     if (m_dialog.radioCustom->isChecked()) {
0077         return m_dialog.comboToken->currentText();
0078     } else {
0079         int index = m_dialog.comboPredefined->currentIndex();
0080         return m_dialog.comboPredefined->itemData(index).toString();
0081     }
0082 }