Added 'max depth' search option to TDEFileReplace. This resolves bug 1238.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/1/head
Michele Calgaro 9 years ago
parent 08f2b5848d
commit 570104ceed

@ -28,6 +28,8 @@ using namespace whatthisNameSpace;
RCOptions::RCOptions() RCOptions::RCOptions()
{ {
m_searchingOnlyMode = false; m_searchingOnlyMode = false;
m_limitDepth = false;
m_maxDepth = 0;
} }
RCOptions& RCOptions::operator=(const RCOptions& ci) RCOptions& RCOptions::operator=(const RCOptions& ci)
@ -39,6 +41,9 @@ RCOptions& RCOptions::operator=(const RCOptions& ci)
m_currentDirectory = ci.m_currentDirectory; m_currentDirectory = ci.m_currentDirectory;
m_minSize = ci.m_minSize; m_minSize = ci.m_minSize;
m_maxSize = ci.m_maxSize; m_maxSize = ci.m_maxSize;
m_limitDepth = ci.m_limitDepth;
m_maxDepth = ci.m_maxDepth;
m_dateAccess = ci.m_dateAccess; m_dateAccess = ci.m_dateAccess;
m_minDate = ci.m_minDate; m_minDate = ci.m_minDate;

@ -39,6 +39,8 @@ const TQString rcFollowSymLinks = "Follow symbolic links";
const TQString rcHaltOnFirstOccur = "Halt on first occurrence"; const TQString rcHaltOnFirstOccur = "Halt on first occurrence";
const TQString rcIgnoreHidden = "Ignore hidden files"; const TQString rcIgnoreHidden = "Ignore hidden files";
const TQString rcRecursive = "Search/replace in sub folders"; 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 rcVariables = "Enable variables";
const TQString rcRegularExpressions = "Enable regular expressions"; const TQString rcRegularExpressions = "Enable regular expressions";
const TQString rcMinFileSize = "Minimum file size"; const TQString rcMinFileSize = "Minimum file size";
@ -63,6 +65,8 @@ const bool RegularExpressionsOption = false;
const bool VariablesOption = false; const bool VariablesOption = false;
const bool StopWhenFirstOccurenceOption = false; const bool StopWhenFirstOccurenceOption = false;
const bool IgnoreHiddenOption = false; const bool IgnoreHiddenOption = false;
const bool LimitDepthOption = false;
const int MaxDepthOption = 0;
const int FileSizeOption = -1; const int FileSizeOption = -1;
const TQString AccessDateOption="unknown"; const TQString AccessDateOption="unknown";
const TQString ValidAccessDateOption="unknown"; const TQString ValidAccessDateOption="unknown";
@ -88,6 +92,9 @@ class RCOptions
int m_minSize, int m_minSize,
m_maxSize; m_maxSize;
bool m_limitDepth;
int m_maxDepth;
TQString m_dateAccess, TQString m_dateAccess,
m_minDate, m_minDate,

@ -58,6 +58,8 @@ KNewProjectDlg::KNewProjectDlg(RCOptions* info, TQWidget *parent, const char *na
initGUI(); 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_pbLocation, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotDir()));
connect(m_pbCancel, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotReject())); connect(m_pbCancel, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotReject()));
connect(m_pbSearchNow, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSearchNow())); connect(m_pbSearchNow, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSearchNow()));
@ -176,6 +178,17 @@ void KNewProjectDlg::slotEnableSpinboxSizeMax(bool b)
m_spbSizeMax->setEnabled(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) void KNewProjectDlg::slotEnableCbValidDate(bool b)
{ {
Q_UNUSED(b); Q_UNUSED(b);
@ -251,6 +264,10 @@ void KNewProjectDlg::loadOptions()
m_chbCaseSensitive->setChecked(m_option->m_caseSensitive); m_chbCaseSensitive->setChecked(m_option->m_caseSensitive);
m_chbEnableVariables->setChecked(m_option->m_variables); m_chbEnableVariables->setChecked(m_option->m_variables);
m_chbRegularExpressions->setChecked(m_option->m_regularExpressions); 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() void KNewProjectDlg::loadFileSizeOptions()
@ -373,6 +390,9 @@ void KNewProjectDlg::saveOptions()
m_option->m_caseSensitive = m_chbCaseSensitive->isChecked(); m_option->m_caseSensitive = m_chbCaseSensitive->isChecked();
m_option->m_variables = m_chbEnableVariables->isChecked(); m_option->m_variables = m_chbEnableVariables->isChecked();
m_option->m_regularExpressions = m_chbRegularExpressions->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() void KNewProjectDlg::saveFileSizeOptions()
@ -512,8 +532,12 @@ void KNewProjectDlg::whatsThis()
TQWhatsThis::add(m_cbLocation, cbLocationWhatthis); TQWhatsThis::add(m_cbLocation, cbLocationWhatthis);
TQWhatsThis::add(m_cbFilter, cbFilterWhatthis); TQWhatsThis::add(m_cbFilter, cbFilterWhatthis);
TQWhatsThis::add(m_chbSizeMin, edSizeMinWhatthis);
TQWhatsThis::add(m_spbSizeMin, edSizeMinWhatthis); TQWhatsThis::add(m_spbSizeMin, edSizeMinWhatthis);
TQWhatsThis::add(m_chbSizeMax, edSizeMaxWhatthis);
TQWhatsThis::add(m_spbSizeMax, edSizeMaxWhatthis); TQWhatsThis::add(m_spbSizeMax, edSizeMaxWhatthis);
TQWhatsThis::add(m_chbLimitDepth, edMaxDepthWhatthis);
TQWhatsThis::add(m_spbMaxDepth, edMaxDepthWhatthis);
TQWhatsThis::add(m_cbDateValid, cbDateValidWhatthis); TQWhatsThis::add(m_cbDateValid, cbDateValidWhatthis);
TQWhatsThis::add(m_chbDateMin, chbDateMinWhatthis); TQWhatsThis::add(m_chbDateMin, chbDateMinWhatthis);

@ -52,6 +52,8 @@ class KNewProjectDlg : public KNewProjectDlgS
void slotSearchLineEdit(const TQString& t); void slotSearchLineEdit(const TQString& t);
void slotEnableSpinboxSizeMin(bool b); void slotEnableSpinboxSizeMin(bool b);
void slotEnableSpinboxSizeMax(bool b); void slotEnableSpinboxSizeMax(bool b);
void slotEnableSpinboxMaxDepth(bool b);
void slotEnableMaxDepthControls(bool b);
void slotEnableCbValidDate(bool b); void slotEnableCbValidDate(bool b);
void slotEnableChbUser(bool b); void slotEnableChbUser(bool b);
void slotEnableChbGroup(bool b); void slotEnableChbGroup(bool b);

@ -254,17 +254,41 @@
<string></string> <string></string>
</property> </property>
</widget> </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>&amp;Include subfolders</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="TQCheckBox">
<property name="name"> <property name="name">
<cstring>m_chbIncludeSubfolders</cstring> <cstring>m_chbLimitDepth</cstring>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Include subfolders</string> <string>&amp;Max depth</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>false</bool>
</property> </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> </grid>
</widget> </widget>
<widget class="TQGroupBox" row="0" column="0"> <widget class="TQGroupBox" row="0" column="0">
@ -866,6 +890,8 @@
<tabstop>m_pbLocation</tabstop> <tabstop>m_pbLocation</tabstop>
<tabstop>m_cbFilter</tabstop> <tabstop>m_cbFilter</tabstop>
<tabstop>m_chbIncludeSubfolders</tabstop> <tabstop>m_chbIncludeSubfolders</tabstop>
<tabstop>m_chbLimitDepth</tabstop>
<tabstop>m_spbMaxDepth</tabstop>
<tabstop>m_cbEncoding</tabstop> <tabstop>m_cbEncoding</tabstop>
<tabstop>m_chbCaseSensitive</tabstop> <tabstop>m_chbCaseSensitive</tabstop>
<tabstop>m_chbRegularExpressions</tabstop> <tabstop>m_chbRegularExpressions</tabstop>

@ -130,7 +130,7 @@ void TDEFileReplacePart::slotSearchingOperation()
uint filesNumber = 0; uint filesNumber = 0;
if(m_option->m_recursive) if(m_option->m_recursive)
recursiveFileSearch(currentDirectory, currentFilter, filesNumber); recursiveFileSearch(currentDirectory, currentFilter, filesNumber, 0);
else else
fileSearch(currentDirectory, currentFilter); fileSearch(currentDirectory, currentFilter);
@ -687,6 +687,8 @@ void TDEFileReplacePart::loadOptions()
m_option->m_encoding = m_config->readEntry(rcEncoding, EncodingOption); m_option->m_encoding = m_config->readEntry(rcEncoding, EncodingOption);
m_option->m_recursive = m_config->readBoolEntry(rcRecursive, RecursiveOption); 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_caseSensitive = m_config->readBoolEntry(rcCaseSensitive, CaseSensitiveOption);
m_option->m_variables = m_config->readBoolEntry(rcVariables, VariablesOption); 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(rcEncoding, m_option->m_encoding);
m_config->writeEntry(rcRecursive, m_option->m_recursive); 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(rcCaseSensitive, m_option->m_caseSensitive);
m_config->writeEntry(rcVariables, m_option->m_variables); m_config->writeEntry(rcVariables, m_option->m_variables);
m_config->writeEntry(rcRegularExpressions, m_option->m_regularExpressions); 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 == true or the max depth level is reached, then interrupt recursion
if(m_stop) if (m_stop || (m_option->m_limitDepth && depth > m_option->m_maxDepth))
return; return;
else else
{ {
@ -1313,9 +1318,14 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
m_view->displayScannedFiles(filesNumber); m_view->displayScannedFiles(filesNumber);
// Searchs recursively if "filePath" is a directory // Searchs recursively if "filePath" is a directory and we have not reached the max depth level
if(fileInfo.isDir()) if (fileInfo.isDir())
recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber); {
if (!m_option->m_limitDepth || depth < m_option->m_maxDepth)
{
recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber, depth+1);
}
}
else else
{ {
kapp->processEvents(); kapp->processEvents();

@ -142,7 +142,7 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
* Searching methods * Searching methods
*/ */
void fileSearch(const TQString& dirName, const TQString& filters); 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); void search(const TQString& currentDir, const TQString& fileName);
/** /**

@ -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 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 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."); 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.");

Loading…
Cancel
Save