File indexing completed on 2024-12-08 13:34:36
0001 /*************************************************************************** 0002 tokensortmodedialog.cpp - description 0003 ------------------- 0004 begin : Wed Sep 15 2010 0005 copyright : (C) 2010 by Dominik Seichter 0006 email : domseichter@web.de 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "tokensortmodedialog.h" 0019 0020 #include "pluginloader.h" 0021 #include "plugin.h" 0022 0023 TokenSortModeDialog::TokenSortModeDialog(KRenameTokenSorter::ESimpleSortMode eSortMode, QWidget *parent) 0024 : QDialog(parent) 0025 { 0026 m_dialog.setupUi(this); 0027 0028 m_dialog.radioAscending->setChecked(eSortMode == KRenameTokenSorter::eSimpleSortMode_Ascending); 0029 m_dialog.radioDescending->setChecked(eSortMode == KRenameTokenSorter::eSimpleSortMode_Descending); 0030 m_dialog.radioNumeric->setChecked(eSortMode == KRenameTokenSorter::eSimpleSortMode_Numeric); 0031 0032 connect(m_dialog.radioPredefined, &QRadioButton::clicked, 0033 this, &TokenSortModeDialog::slotEnableControls); 0034 connect(m_dialog.radioCustom, &QRadioButton::clicked, 0035 this, &TokenSortModeDialog::slotEnableControls); 0036 0037 m_dialog.comboPredefined->addItem(i18n("Access Date"), "accessdate;yyyyMMddHHmm"); 0038 m_dialog.comboPredefined->addItem(i18n("Creation Date"), "creationdate;yyyyMMddHHmm"); 0039 m_dialog.comboPredefined->addItem(i18n("Filesize"), "filesize"); 0040 m_dialog.comboPredefined->addItem(i18n("Group"), "group"); 0041 m_dialog.comboPredefined->addItem(i18n("Modification Date"), "modificationdate;yyyyMMddHHmm"); 0042 m_dialog.comboPredefined->addItem(i18n("User"), "user"); 0043 0044 initTokens(); 0045 slotEnableControls(); 0046 } 0047 0048 void TokenSortModeDialog::initTokens() 0049 { 0050 QStringList allTokens; 0051 0052 QList<Plugin *>::const_iterator it = PluginLoader::Instance()->plugins().begin(); 0053 while (it != PluginLoader::Instance()->plugins().end()) { 0054 if (((*it)->type() & ePluginType_Token)) { 0055 const QStringList &tokens = (*it)->supportedTokens(); 0056 allTokens.append(tokens); 0057 } 0058 0059 ++it; 0060 } 0061 0062 allTokens.sort(); 0063 m_dialog.comboToken->insertItems(-1, allTokens); 0064 } 0065 0066 void TokenSortModeDialog::slotEnableControls() 0067 { 0068 m_dialog.comboToken->setEnabled(m_dialog.radioCustom->isChecked()); 0069 m_dialog.comboPredefined->setEnabled(m_dialog.radioPredefined->isChecked()); 0070 0071 } 0072 0073 KRenameTokenSorter::ESimpleSortMode TokenSortModeDialog::getSortMode() const 0074 { 0075 KRenameTokenSorter::ESimpleSortMode eMode = KRenameTokenSorter::eSimpleSortMode_Ascending; 0076 0077 if (m_dialog.radioAscending->isChecked()) { 0078 eMode = KRenameTokenSorter::eSimpleSortMode_Ascending; 0079 } else if (m_dialog.radioDescending->isChecked()) { 0080 eMode = KRenameTokenSorter::eSimpleSortMode_Descending; 0081 } else if (m_dialog.radioNumeric->isChecked()) { 0082 eMode = KRenameTokenSorter::eSimpleSortMode_Numeric; 0083 } 0084 0085 return eMode; 0086 } 0087 0088 QString TokenSortModeDialog::getToken() const 0089 { 0090 if (m_dialog.radioCustom->isChecked()) { 0091 return m_dialog.comboToken->currentText(); 0092 } else { 0093 int index = m_dialog.comboPredefined->currentIndex(); 0094 return m_dialog.comboPredefined->itemData(index).toString(); 0095 } 0096 }