From 570104ceed8613903f249f2e5768c5cceb6f0012 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 29 Jan 2015 13:24:20 +0900 Subject: Added 'max depth' search option to TDEFileReplace. This resolves bug 1238. Signed-off-by: Michele Calgaro --- tdefilereplace/configurationclasses.cpp | 5 +++++ tdefilereplace/configurationclasses.h | 7 +++++++ tdefilereplace/knewprojectdlg.cpp | 24 ++++++++++++++++++++++ tdefilereplace/knewprojectdlg.h | 2 ++ tdefilereplace/knewprojectdlgs.ui | 36 ++++++++++++++++++++++++++++----- tdefilereplace/tdefilereplacepart.cpp | 24 +++++++++++++++------- tdefilereplace/tdefilereplacepart.h | 2 +- tdefilereplace/whatthis.h | 2 ++ 8 files changed, 89 insertions(+), 13 deletions(-) (limited to 'tdefilereplace') 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 @@ - + + + + m_chbIncludeSubfolders + + + &Include subfolders + + + true + + + - m_chbIncludeSubfolders + m_chbLimitDepth - &Include subfolders + &Max depth - true + false - + + + + m_spbMaxDepth + + + 0 + + + 255 + + + @@ -866,6 +890,8 @@ m_pbLocation m_cbFilter m_chbIncludeSubfolders + m_chbLimitDepth + m_spbMaxDepth m_cbEncoding m_chbCaseSensitive m_chbRegularExpressions 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."); -- cgit v1.2.3