diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2015-01-29 13:24:20 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2015-01-29 13:24:20 +0900 |
commit | 570104ceed8613903f249f2e5768c5cceb6f0012 (patch) | |
tree | 50f4806b7a615ec7f92cd27b7d5c5df56f569eaa /tdefilereplace | |
parent | 08f2b5848ddd09e0da7e2d42a8743f0b40f1c717 (diff) | |
download | tdeutils-570104ceed8613903f249f2e5768c5cceb6f0012.tar.gz tdeutils-570104ceed8613903f249f2e5768c5cceb6f0012.zip |
Added 'max depth' search option to TDEFileReplace. This resolves bug 1238.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdefilereplace')
-rw-r--r-- | tdefilereplace/configurationclasses.cpp | 5 | ||||
-rw-r--r-- | tdefilereplace/configurationclasses.h | 7 | ||||
-rw-r--r-- | tdefilereplace/knewprojectdlg.cpp | 24 | ||||
-rw-r--r-- | tdefilereplace/knewprojectdlg.h | 2 | ||||
-rw-r--r-- | tdefilereplace/knewprojectdlgs.ui | 36 | ||||
-rw-r--r-- | tdefilereplace/tdefilereplacepart.cpp | 24 | ||||
-rw-r--r-- | tdefilereplace/tdefilereplacepart.h | 2 | ||||
-rw-r--r-- | tdefilereplace/whatthis.h | 2 |
8 files changed, 89 insertions, 13 deletions
diff --git a/tdefilereplace/configurationclasses.cpp b/tdefilereplace/configurationclasses.cpp index f0c6bcc..356d8c4 100644 --- a/tdefilereplace/configurationclasses.cpp +++ b/tdefilereplace/configurationclasses.cpp @@ -28,6 +28,8 @@ using namespace whatthisNameSpace; RCOptions::RCOptions() { m_searchingOnlyMode = false; + m_limitDepth = false; + m_maxDepth = 0; } RCOptions& RCOptions::operator=(const RCOptions& ci) @@ -39,6 +41,9 @@ RCOptions& RCOptions::operator=(const RCOptions& ci) m_currentDirectory = ci.m_currentDirectory; m_minSize = ci.m_minSize; m_maxSize = ci.m_maxSize; + + m_limitDepth = ci.m_limitDepth; + m_maxDepth = ci.m_maxDepth; m_dateAccess = ci.m_dateAccess; m_minDate = ci.m_minDate; diff --git a/tdefilereplace/configurationclasses.h b/tdefilereplace/configurationclasses.h index 206de1c..b42bb17 100644 --- a/tdefilereplace/configurationclasses.h +++ b/tdefilereplace/configurationclasses.h @@ -39,6 +39,8 @@ const TQString rcFollowSymLinks = "Follow symbolic links"; const TQString rcHaltOnFirstOccur = "Halt on first occurrence"; const TQString rcIgnoreHidden = "Ignore hidden files"; const TQString rcRecursive = "Search/replace in sub folders"; +const TQString rcLimitDepth = "Limit search to sub folder level"; +const TQString rcMaxDepth = "Max depth level value"; const TQString rcVariables = "Enable variables"; const TQString rcRegularExpressions = "Enable regular expressions"; const TQString rcMinFileSize = "Minimum file size"; @@ -63,6 +65,8 @@ const bool RegularExpressionsOption = false; const bool VariablesOption = false; const bool StopWhenFirstOccurenceOption = false; const bool IgnoreHiddenOption = false; +const bool LimitDepthOption = false; +const int MaxDepthOption = 0; const int FileSizeOption = -1; const TQString AccessDateOption="unknown"; const TQString ValidAccessDateOption="unknown"; @@ -88,6 +92,9 @@ class RCOptions int m_minSize, m_maxSize; + + bool m_limitDepth; + int m_maxDepth; TQString m_dateAccess, m_minDate, diff --git a/tdefilereplace/knewprojectdlg.cpp b/tdefilereplace/knewprojectdlg.cpp index 06b703d..372ba18 100644 --- a/tdefilereplace/knewprojectdlg.cpp +++ b/tdefilereplace/knewprojectdlg.cpp @@ -58,6 +58,8 @@ KNewProjectDlg::KNewProjectDlg(RCOptions* info, TQWidget *parent, const char *na initGUI(); + connect(m_chbIncludeSubfolders, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotEnableMaxDepthControls(bool))); + connect(m_chbLimitDepth, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotEnableSpinboxMaxDepth(bool))); connect(m_pbLocation, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotDir())); connect(m_pbCancel, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotReject())); connect(m_pbSearchNow, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSearchNow())); @@ -176,6 +178,17 @@ void KNewProjectDlg::slotEnableSpinboxSizeMax(bool b) m_spbSizeMax->setEnabled(b); } +void KNewProjectDlg::slotEnableSpinboxMaxDepth(bool b) +{ + m_spbMaxDepth->setEnabled(b); +} + +void KNewProjectDlg::slotEnableMaxDepthControls(bool b) +{ + m_chbLimitDepth->setEnabled(b); + m_spbMaxDepth->setEnabled(b && m_chbLimitDepth->isChecked()); +} + void KNewProjectDlg::slotEnableCbValidDate(bool b) { Q_UNUSED(b); @@ -251,6 +264,10 @@ void KNewProjectDlg::loadOptions() m_chbCaseSensitive->setChecked(m_option->m_caseSensitive); m_chbEnableVariables->setChecked(m_option->m_variables); m_chbRegularExpressions->setChecked(m_option->m_regularExpressions); + m_chbLimitDepth->setEnabled(m_option->m_recursive); + m_chbLimitDepth->setChecked(m_option->m_limitDepth); + m_spbMaxDepth->setEnabled(m_option->m_recursive && m_option->m_limitDepth); + m_spbMaxDepth->setValue(m_option->m_maxDepth); } void KNewProjectDlg::loadFileSizeOptions() @@ -373,6 +390,9 @@ void KNewProjectDlg::saveOptions() m_option->m_caseSensitive = m_chbCaseSensitive->isChecked(); m_option->m_variables = m_chbEnableVariables->isChecked(); m_option->m_regularExpressions = m_chbRegularExpressions->isChecked(); + m_option->m_limitDepth = m_chbLimitDepth->isChecked(); + m_option->m_maxDepth = m_spbMaxDepth->value(); + } void KNewProjectDlg::saveFileSizeOptions() @@ -512,8 +532,12 @@ void KNewProjectDlg::whatsThis() TQWhatsThis::add(m_cbLocation, cbLocationWhatthis); TQWhatsThis::add(m_cbFilter, cbFilterWhatthis); + TQWhatsThis::add(m_chbSizeMin, edSizeMinWhatthis); TQWhatsThis::add(m_spbSizeMin, edSizeMinWhatthis); + TQWhatsThis::add(m_chbSizeMax, edSizeMaxWhatthis); TQWhatsThis::add(m_spbSizeMax, edSizeMaxWhatthis); + TQWhatsThis::add(m_chbLimitDepth, edMaxDepthWhatthis); + TQWhatsThis::add(m_spbMaxDepth, edMaxDepthWhatthis); TQWhatsThis::add(m_cbDateValid, cbDateValidWhatthis); TQWhatsThis::add(m_chbDateMin, chbDateMinWhatthis); diff --git a/tdefilereplace/knewprojectdlg.h b/tdefilereplace/knewprojectdlg.h index b8b87da..82e08ad 100644 --- a/tdefilereplace/knewprojectdlg.h +++ b/tdefilereplace/knewprojectdlg.h @@ -52,6 +52,8 @@ class KNewProjectDlg : public KNewProjectDlgS void slotSearchLineEdit(const TQString& t); void slotEnableSpinboxSizeMin(bool b); void slotEnableSpinboxSizeMax(bool b); + void slotEnableSpinboxMaxDepth(bool b); + void slotEnableMaxDepthControls(bool b); void slotEnableCbValidDate(bool b); void slotEnableChbUser(bool b); void slotEnableChbGroup(bool b); diff --git a/tdefilereplace/knewprojectdlgs.ui b/tdefilereplace/knewprojectdlgs.ui index b3509c1..bff975e 100644 --- a/tdefilereplace/knewprojectdlgs.ui +++ b/tdefilereplace/knewprojectdlgs.ui @@ -254,17 +254,41 @@ <string></string> </property> </widget> - <widget class="TQCheckBox" row="2" column="0" rowspan="1" colspan="3"> + <hbox row="2" column="0"> + <widget class="TQCheckBox"> + <property name="name"> + <cstring>m_chbIncludeSubfolders</cstring> + </property> + <property name="text"> + <string>&Include subfolders</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="TQCheckBox"> <property name="name"> - <cstring>m_chbIncludeSubfolders</cstring> + <cstring>m_chbLimitDepth</cstring> </property> <property name="text"> - <string>&Include subfolders</string> + <string>&Max depth</string> </property> <property name="checked"> - <bool>true</bool> + <bool>false</bool> </property> - </widget> + </widget> + <widget class="TQSpinBox"> + <property name="name"> + <cstring>m_spbMaxDepth</cstring> + </property> + <property name="minValue"> + <number>0</number> + </property> + <property name="maxValue"> + <number>255</number> + </property> + </widget> + </hbox> </grid> </widget> <widget class="TQGroupBox" row="0" column="0"> @@ -866,6 +890,8 @@ <tabstop>m_pbLocation</tabstop> <tabstop>m_cbFilter</tabstop> <tabstop>m_chbIncludeSubfolders</tabstop> + <tabstop>m_chbLimitDepth</tabstop> + <tabstop>m_spbMaxDepth</tabstop> <tabstop>m_cbEncoding</tabstop> <tabstop>m_chbCaseSensitive</tabstop> <tabstop>m_chbRegularExpressions</tabstop> diff --git a/tdefilereplace/tdefilereplacepart.cpp b/tdefilereplace/tdefilereplacepart.cpp index 008198e..dc96db4 100644 --- a/tdefilereplace/tdefilereplacepart.cpp +++ b/tdefilereplace/tdefilereplacepart.cpp @@ -130,7 +130,7 @@ void TDEFileReplacePart::slotSearchingOperation() uint filesNumber = 0; if(m_option->m_recursive) - recursiveFileSearch(currentDirectory, currentFilter, filesNumber); + recursiveFileSearch(currentDirectory, currentFilter, filesNumber, 0); else fileSearch(currentDirectory, currentFilter); @@ -687,6 +687,8 @@ void TDEFileReplacePart::loadOptions() m_option->m_encoding = m_config->readEntry(rcEncoding, EncodingOption); m_option->m_recursive = m_config->readBoolEntry(rcRecursive, RecursiveOption); + m_option->m_limitDepth = m_config->readBoolEntry(rcLimitDepth, LimitDepthOption); + m_option->m_maxDepth = m_config->readNumEntry(rcMaxDepth, MaxDepthOption); m_option->m_caseSensitive = m_config->readBoolEntry(rcCaseSensitive, CaseSensitiveOption); m_option->m_variables = m_config->readBoolEntry(rcVariables, VariablesOption); @@ -822,6 +824,8 @@ void TDEFileReplacePart::saveOptions() m_config->writeEntry(rcEncoding, m_option->m_encoding); m_config->writeEntry(rcRecursive, m_option->m_recursive); + m_config->writeEntry(rcLimitDepth, m_option->m_limitDepth); + m_config->writeEntry(rcMaxDepth, m_option->m_maxDepth); m_config->writeEntry(rcCaseSensitive, m_option->m_caseSensitive); m_config->writeEntry(rcVariables, m_option->m_variables); m_config->writeEntry(rcRegularExpressions, m_option->m_regularExpressions); @@ -1281,10 +1285,11 @@ void TDEFileReplacePart::fileSearch(const TQString& directoryName, const TQStrin } } -void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, const TQString& filters, uint& filesNumber) +void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, const TQString& filters, + uint& filesNumber, int depth) { - // if m_stop == true then interrupt recursion - if(m_stop) + // if m_stop == true or the max depth level is reached, then interrupt recursion + if (m_stop || (m_option->m_limitDepth && depth > m_option->m_maxDepth)) return; else { @@ -1313,9 +1318,14 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons m_view->displayScannedFiles(filesNumber); - // Searchs recursively if "filePath" is a directory - if(fileInfo.isDir()) - recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber); + // Searchs recursively if "filePath" is a directory and we have not reached the max depth level + if (fileInfo.isDir()) + { + if (!m_option->m_limitDepth || depth < m_option->m_maxDepth) + { + recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber, depth+1); + } + } else { kapp->processEvents(); diff --git a/tdefilereplace/tdefilereplacepart.h b/tdefilereplace/tdefilereplacepart.h index 0ca917e..ee5352d 100644 --- a/tdefilereplace/tdefilereplacepart.h +++ b/tdefilereplace/tdefilereplacepart.h @@ -142,7 +142,7 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart * Searching methods */ void fileSearch(const TQString& dirName, const TQString& filters); - void recursiveFileSearch(const TQString& dirName, const TQString& filters, uint& filesNumber); + void recursiveFileSearch(const TQString& dirName, const TQString& filters, uint& filesNumber, int depth); void search(const TQString& currentDir, const TQString& fileName); /** diff --git a/tdefilereplace/whatthis.h b/tdefilereplace/whatthis.h index 0539537..6693931 100644 --- a/tdefilereplace/whatthis.h +++ b/tdefilereplace/whatthis.h @@ -39,6 +39,8 @@ namespace whatthisNameSpace const TQString edSizeMaxWhatthis = i18n("Insert the maximum file size you want to search, or leave it unchecked if you don't want maximum size limit."); + const TQString edMaxDepthWhatthis = i18n("Insert the maximum depth sublevel you want to search, or leave it unchecked if you don't want to limit the search. A level of 0 searches only the current level."); + const TQString edDateMinWhatthis = i18n("Insert the minimum value for file access date that you want to search, or leave it unchecked if you don't a minimum limit."); const TQString edDateMaxWhatthis = i18n("Insert the maximum value for file access date that you want to search, or leave it unchecked if you don't a maximum limit."); |