Commit 4da778df authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Coding style

parent 66fba87b
/*******************************************************************
* kfinddlg.cpp
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
******************************************************************/
#include "kfinddlg.h"
......@@ -35,263 +35,255 @@
#include "kquery.h"
#include "kfindtreeview.h"
KfindDlg::KfindDlg(const QUrl & url, QWidget *parent)
: KDialog( parent )
KfindDlg::KfindDlg(const QUrl &url, QWidget *parent)
: KDialog(parent)
{
setButtons( User1 | User2 | User3 | Close | Help );
setDefaultButton( User3 );
setModal( true );
setButtons(User1 | User2 | User3 | Close | Help);
setDefaultButton(User3);
setModal(true);
setButtonGuiItem( User3, KStandardGuiItem::find());
setButtonGuiItem( User2, KStandardGuiItem::stop() );
setButtonGuiItem( User1, KStandardGuiItem::saveAs() );
setButtonGuiItem(User3, KStandardGuiItem::find());
setButtonGuiItem(User2, KStandardGuiItem::stop());
setButtonGuiItem(User1, KStandardGuiItem::saveAs());
QWidget::setWindowTitle( i18nc("@title:window", "Find Files/Folders" ) );
setButtonsOrientation(Qt::Vertical);
QWidget::setWindowTitle(i18nc("@title:window", "Find Files/Folders"));
setButtonsOrientation(Qt::Vertical);
enableButton(User3, true); // Enable "Find"
enableButton(User2, false); // Disable "Stop"
enableButton(User1, false); // Disable "Save As..."
enableButton(User3, true); // Enable "Find"
enableButton(User2, false); // Disable "Stop"
enableButton(User1, false); // Disable "Save As..."
isResultReported = false;
isResultReported = false;
QFrame *frame = new QFrame;
setMainWidget( frame );
QFrame *frame = new QFrame;
setMainWidget(frame);
// create tabwidget
tabWidget = new KfindTabWidget( frame );
tabWidget->setURL( url );
tabWidget->setFocus();
// create tabwidget
tabWidget = new KfindTabWidget(frame);
tabWidget->setURL(url);
tabWidget->setFocus();
// prepare window for find results
win = new KFindTreeView(frame, this);
// prepare window for find results
win = new KFindTreeView(frame, this);
mStatusBar = new KStatusBar(frame);
mStatusBar->insertItem(QStringLiteral("AMiddleLengthText..."), 0);
setStatusMsg( i18nc("the application is currently idle, there is no active search", "Idle.") );
mStatusBar->setItemAlignment(0, Qt::AlignLeft | Qt::AlignVCenter);
mStatusBar->insertPermanentItem(QString(), 1, 1);
mStatusBar->setItemAlignment(1, Qt::AlignRight | Qt::AlignVCenter);
mStatusBar = new KStatusBar(frame);
mStatusBar->insertItem(QStringLiteral("AMiddleLengthText..."), 0);
setStatusMsg(i18nc("the application is currently idle, there is no active search", "Idle."));
mStatusBar->setItemAlignment(0, Qt::AlignLeft | Qt::AlignVCenter);
mStatusBar->insertPermanentItem(QString(), 1, 1);
mStatusBar->setItemAlignment(1, Qt::AlignRight | Qt::AlignVCenter);
QVBoxLayout *vBox = new QVBoxLayout(frame);
vBox->addWidget(tabWidget, 0);
vBox->addWidget(win, 1);
vBox->addWidget(mStatusBar, 0);
QVBoxLayout *vBox = new QVBoxLayout(frame);
vBox->addWidget(tabWidget, 0);
vBox->addWidget(win, 1);
vBox->addWidget(mStatusBar, 0);
connect(tabWidget, SIGNAL(startSearch()),
this, SLOT(startSearch()));
connect(this, SIGNAL(user3Clicked()),
this, SLOT(startSearch()));
connect(this, SIGNAL(user2Clicked()),
this, SLOT(stopSearch()));
connect(this, SIGNAL(user1Clicked()),
win, SLOT(saveResults()));
connect(tabWidget, SIGNAL(startSearch()),
this, SLOT(startSearch()));
connect(this, SIGNAL(user3Clicked()),
this, SLOT(startSearch()));
connect(this, SIGNAL(user2Clicked()),
this, SLOT(stopSearch()));
connect(this, SIGNAL(user1Clicked()),
win, SLOT(saveResults()));
connect( this, SIGNAL(closeClicked()), this, SLOT(finishAndClose()) );
connect(this, SIGNAL(closeClicked()), this, SLOT(finishAndClose()));
connect(win ,SIGNAL(resultSelected(bool)),
this,SIGNAL(resultSelected(bool)));
connect(win, SIGNAL(resultSelected(bool)),
this, SIGNAL(resultSelected(bool)));
query = new KQuery(frame);
query = new KQuery(frame);
connect(query, SIGNAL(result(int)), SLOT(slotResult(int)));
connect(query, SIGNAL(foundFileList(QList<QPair<KFileItem,QString> >)), SLOT(addFiles(QList<QPair<KFileItem,QString> >)));
KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true);
setButtonMenu( Help, helpMenu->menu() );
dirwatch=NULL;
KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true);
setButtonMenu(Help, helpMenu->menu());
dirwatch = NULL;
}
KfindDlg::~KfindDlg()
{
stopSearch();
delete dirwatch;
stopSearch();
delete dirwatch;
}
void KfindDlg::finishAndClose()
{
//Stop the current search and closes the dialog
stopSearch();
close();
//Stop the current search and closes the dialog
stopSearch();
close();
}
void KfindDlg::setProgressMsg(const QString &msg)
{
mStatusBar->changeItem(msg, 1);
mStatusBar->changeItem(msg, 1);
}
void KfindDlg::setStatusMsg(const QString &msg)
{
mStatusBar->changeItem(msg, 0);
mStatusBar->changeItem(msg, 0);
}
void KfindDlg::startSearch()
{
tabWidget->setQuery(query);
tabWidget->setQuery(query);
isResultReported = false;
isResultReported = false;
// Reset count - use the same i18n as below
setProgressMsg(i18np("one file found", "%1 files found", 0));
// Reset count - use the same i18n as below
setProgressMsg(i18np("one file found", "%1 files found", 0));
emit resultSelected(false);
emit haveResults(false);
emit resultSelected(false);
emit haveResults(false);
enableButton(User3, false); // Disable "Find"
enableButton(User2, true); // Enable "Stop"
enableButton(User1, false); // Disable "Save As..."
enableButton(User3, false); // Disable "Find"
enableButton(User2, true); // Enable "Stop"
enableButton(User1, false); // Disable "Save As..."
delete dirwatch;
dirwatch=new KDirWatch();
connect(dirwatch, SIGNAL(created(QString)), this, SLOT(slotNewItems(QString)));
connect(dirwatch, SIGNAL(deleted(QString)), this, SLOT(slotDeleteItem(QString)));
dirwatch->addDir(query->url().toLocalFile(), KDirWatch::WatchFiles);
delete dirwatch;
dirwatch = new KDirWatch();
connect(dirwatch, SIGNAL(created(QString)), this, SLOT(slotNewItems(QString)));
connect(dirwatch, SIGNAL(deleted(QString)), this, SLOT(slotDeleteItem(QString)));
dirwatch->addDir(query->url().toLocalFile(), KDirWatch::WatchFiles);
#if 0
// waba: Watching for updates is disabled for now because even with FAM it causes too
// much problems. See BR68220, BR77854, BR77846, BR79512 and BR85802
// There are 3 problems:
// 1) addDir() keeps looping on recursive symlinks
// 2) addDir() scans all subdirectories, so it basically does the same as the process that
// is started by KQuery but in-process, undoing the advantages of using a separate find process
// A solution could be to let KQuery emit all the directories it has searched in.
// Either way, putting dirwatchers on a whole file system is probably just too much.
// 3) FAM has a tendency to deadlock with so many files (See BR77854) This has hopefully
// been fixed in KDirWatch, but that has not yet been confirmed.
//Getting a list of all subdirs
if(tabWidget->isSearchRecursive() && (dirwatch->internalMethod() == KDirWatch::FAM))
{
const QStringList subdirs=getAllSubdirs(query->url().path());
for(QStringList::const_iterator it = subdirs.constBegin(); it != subdirs.constEnd(); ++it)
dirwatch->addDir(*it,true);
}
// waba: Watching for updates is disabled for now because even with FAM it causes too
// much problems. See BR68220, BR77854, BR77846, BR79512 and BR85802
// There are 3 problems:
// 1) addDir() keeps looping on recursive symlinks
// 2) addDir() scans all subdirectories, so it basically does the same as the process that
// is started by KQuery but in-process, undoing the advantages of using a separate find process
// A solution could be to let KQuery emit all the directories it has searched in.
// Either way, putting dirwatchers on a whole file system is probably just too much.
// 3) FAM has a tendency to deadlock with so many files (See BR77854) This has hopefully
// been fixed in KDirWatch, but that has not yet been confirmed.
//Getting a list of all subdirs
if (tabWidget->isSearchRecursive() && (dirwatch->internalMethod() == KDirWatch::FAM)) {
const QStringList subdirs = getAllSubdirs(query->url().path());
for (QStringList::const_iterator it = subdirs.constBegin(); it != subdirs.constEnd(); ++it) {
dirwatch->addDir(*it, true);
}
}
#endif
win->beginSearch(query->url());
tabWidget->beginSearch();
win->beginSearch(query->url());
tabWidget->beginSearch();
setStatusMsg(i18n("Searching..."));
query->start();
setStatusMsg(i18n("Searching..."));
query->start();
}
void KfindDlg::stopSearch()
{
query->kill();
query->kill();
}
void KfindDlg::newSearch()
{
// WABA: Not used any longer?
stopSearch();
// WABA: Not used any longer?
stopSearch();
tabWidget->setDefaults();
tabWidget->setDefaults();
emit haveResults(false);
emit resultSelected(false);
emit haveResults(false);
emit resultSelected(false);
setFocus();
setFocus();
}
void KfindDlg::slotResult(int errorCode)
{
if (errorCode == 0)
setStatusMsg( i18nc("the application is currently idle, there is no active search", "Idle.") );
else if (errorCode == KIO::ERR_USER_CANCELED)
setStatusMsg(i18n("Canceled."));
else if (errorCode == KIO::ERR_MALFORMED_URL)
{
setStatusMsg(i18n("Error."));
KMessageBox::sorry( this, i18n("Please specify an absolute path in the \"Look in\" box."));
}
else if (errorCode == KIO::ERR_DOES_NOT_EXIST)
{
setStatusMsg(i18n("Error."));
KMessageBox::sorry( this, i18n("Could not find the specified folder."));
}
else
{
//qDebug()<<"KIO error code: "<<errorCode;
setStatusMsg(i18n("Error."));
};
enableButton(User3, true); // Enable "Find"
enableButton(User2, false); // Disable "Stop"
enableButton(User1, true); // Enable "Save As..."
win->endSearch();
tabWidget->endSearch();
setFocus();
if (errorCode == 0) {
setStatusMsg(i18nc("the application is currently idle, there is no active search", "Idle."));
} else if (errorCode == KIO::ERR_USER_CANCELED) {
setStatusMsg(i18n("Canceled."));
} else if (errorCode == KIO::ERR_MALFORMED_URL) {
setStatusMsg(i18n("Error."));
KMessageBox::sorry(this, i18n("Please specify an absolute path in the \"Look in\" box."));
} else if (errorCode == KIO::ERR_DOES_NOT_EXIST) {
setStatusMsg(i18n("Error."));
KMessageBox::sorry(this, i18n("Could not find the specified folder."));
} else {
//qDebug()<<"KIO error code: "<<errorCode;
setStatusMsg(i18n("Error."));
}
enableButton(User3, true); // Enable "Find"
enableButton(User2, false); // Disable "Stop"
enableButton(User1, true); // Enable "Save As..."
win->endSearch();
tabWidget->endSearch();
setFocus();
}
void KfindDlg::addFiles( const QList< QPair<KFileItem,QString> > & pairs)
void KfindDlg::addFiles(const QList< QPair<KFileItem, QString> > &pairs)
{
win->insertItems( pairs );
win->insertItems(pairs);
if (!isResultReported)
{
emit haveResults(true);
isResultReported = true;
}
if (!isResultReported) {
emit haveResults(true);
isResultReported = true;
}
QString str = i18np("one file found", "%1 files found", win->itemCount());
setProgressMsg( str );
QString str = i18np("one file found", "%1 files found", win->itemCount());
setProgressMsg(str);
}
void KfindDlg::setFocus()
{
tabWidget->setFocus();
tabWidget->setFocus();
}
void KfindDlg::copySelection()
{
win->copySelection();
win->copySelection();
}
void KfindDlg::about ()
void KfindDlg::about()
{
KAboutApplicationDialog dlg(KAboutData::applicationData(), 0, this);
dlg.exec ();
KAboutApplicationDialog dlg(KAboutData::applicationData(), 0, this);
dlg.exec();
}
void KfindDlg::slotDeleteItem(const QString& file)
void KfindDlg::slotDeleteItem(const QString &file)
{
//qDebug()<<QString("Will remove one item: %1").arg(file);
win->removeItem( QUrl::fromLocalFile(file) );
QString str = i18np("one file found", "%1 files found", win->itemCount());
setProgressMsg( str );
//qDebug()<<QString("Will remove one item: %1").arg(file);
win->removeItem(QUrl::fromLocalFile(file));
QString str = i18np("one file found", "%1 files found", win->itemCount());
setProgressMsg(str);
}
void KfindDlg::slotNewItems( const QString& file )
void KfindDlg::slotNewItems(const QString &file)
{
//qDebug()<<QString("Will add this item") << file;
const QUrl url = QUrl::fromLocalFile(file);
if( query->url().isParentOf(url) )
{
if ( !win->isInserted( url ) )
query->slotListEntries( QStringList() << file );
if (query->url().isParentOf(url)) {
if (!win->isInserted(url)) {
query->slotListEntries(QStringList() << file);
}
}
}
QStringList KfindDlg::getAllSubdirs(QDir d)
{
QStringList dirs;
QStringList subdirs;
d.setFilter( QDir::Dirs );
dirs = d.entryList();
for(QStringList::const_iterator it = dirs.constBegin(); it != dirs.constEnd(); ++it)
{
if((*it==QLatin1String(".")) || (*it==QLatin1String("..")))
continue;
subdirs.append(d.path()+QLatin1Char('/')+*it);
subdirs+=getAllSubdirs(QString(d.path()+QLatin1Char('/')+*it));
}
return subdirs;
QStringList dirs;
QStringList subdirs;
d.setFilter(QDir::Dirs);
dirs = d.entryList();
for (QStringList::const_iterator it = dirs.constBegin(); it != dirs.constEnd(); ++it) {
if ((*it == QLatin1String(".")) || (*it == QLatin1String(".."))) {
continue;
}
subdirs.append(d.path()+QLatin1Char('/')+*it);
subdirs += getAllSubdirs(QString(d.path()+QLatin1Char('/')+*it));
}
return subdirs;
}
/*******************************************************************
* kfinddlg.h
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
******************************************************************/
#ifndef KFINDDLG_H
......@@ -35,49 +35,49 @@ class KfindTabWidget;
class KFindTreeView;
class KStatusBar;
class KfindDlg: public KDialog
class KfindDlg : public KDialog
{
Q_OBJECT
Q_OBJECT
public:
explicit KfindDlg(const QUrl & url, QWidget * parent = 0);
~KfindDlg();
void copySelection();
explicit KfindDlg(const QUrl &url, QWidget *parent = 0);
~KfindDlg();
void copySelection();
void setStatusMsg(const QString &);
void setProgressMsg(const QString &);
void setStatusMsg(const QString &);
void setProgressMsg(const QString &);
private:
/*Return a QStringList of all subdirs of d*/
QStringList getAllSubdirs(QDir d);
/*Return a QStringList of all subdirs of d*/
QStringList getAllSubdirs(QDir d);
public Q_SLOTS:
void startSearch();
void stopSearch();
void newSearch();
void addFiles( const QList< QPair<KFileItem,QString> > & );
void setFocus();
void slotResult(int);
void startSearch();
void stopSearch();
void newSearch();
void addFiles(const QList< QPair<KFileItem, QString> > &);
void setFocus();
void slotResult(int);
// void slotSearchDone();
void about ();
void slotDeleteItem(const QString&);
void slotNewItems( const QString& );
void finishAndClose();
void about();
void slotDeleteItem(const QString &);
void slotNewItems(const QString &);
void finishAndClose();
Q_SIGNALS:
void haveResults(bool);
void resultSelected(bool);
void haveResults(bool);
void resultSelected(bool);
private:
KfindTabWidget *tabWidget;
KFindTreeView * win;
KfindTabWidget *tabWidget;
KFindTreeView *win;
bool isResultReported;
KQuery *query;
KStatusBar *mStatusBar;
KDirLister *dirlister;
KDirWatch *dirwatch;
bool isResultReported;
KQuery *query;
KStatusBar *mStatusBar;
KDirLister *dirlister;
KDirWatch *dirwatch;
};
#endif
This diff is collapsed.
/*******************************************************************
* kfindtreeview.h
* Copyright 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
******************************************************************/
#ifndef KFINDTREEVIEW__H
......@@ -38,122 +38,151 @@ class KfindDlg;
class KFindItem
{
public:
explicit KFindItem( const KFileItem & = KFileItem(), const QString & subDir = QString(), const QString & matchingLine = QString() );
QVariant data(int column, int role) const;
KFileItem getFileItem() const { return m_fileItem; }
bool isValid() const { return !m_fileItem.isNull(); }
private:
KFileItem m_fileItem;
QString m_matchingLine;
QString m_subDir;
QString m_permission;
QIcon m_icon;
public:
explicit KFindItem(const KFileItem & = KFileItem(), const QString &subDir = QString(), const QString &matchingLine = QString());
QVariant data(int column, int role) const;
KFileItem getFileItem() const
{
return m_fileItem;
}
bool isValid() const
{
return !m_fileItem.isNull();
}
private:
KFileItem m_fileItem;
QString m_matchingLine;
QString m_subDir;