2001-10-18 09:14:25 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Kfinddlg.cpp
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2007-05-09 22:23:52 +00:00
|
|
|
#include <QtGui/QLayout>
|
|
|
|
#include <QtGui/QPushButton>
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kglobal.h>
|
2002-08-23 00:01:25 +00:00
|
|
|
#include <kguiitem.h>
|
2001-10-18 09:14:25 +00:00
|
|
|
#include <kstatusbar.h>
|
|
|
|
#include <kmessagebox.h>
|
|
|
|
#include <kdebug.h>
|
2007-01-29 23:28:40 +00:00
|
|
|
#include <kaboutapplicationdialog.h>
|
2003-12-10 11:48:22 +00:00
|
|
|
#include <kstandarddirs.h>
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
#include "kftabdlg.h"
|
|
|
|
#include "kquery.h"
|
|
|
|
#include "kfwin.h"
|
|
|
|
|
|
|
|
#include "kfinddlg.h"
|
|
|
|
#include "kfinddlg.moc"
|
|
|
|
|
2006-08-13 20:14:25 +00:00
|
|
|
KfindDlg::KfindDlg(const KUrl & url, QWidget *parent)
|
2006-06-13 17:41:00 +00:00
|
|
|
: KDialog( parent )
|
2001-10-18 09:14:25 +00:00
|
|
|
{
|
2006-08-13 20:14:25 +00:00
|
|
|
setButtons( User1 | User2 | User3 | Close | Help );
|
|
|
|
setDefaultButton( User3 );
|
2006-06-13 17:41:00 +00:00
|
|
|
setModal( true );
|
|
|
|
|
2006-12-27 01:38:51 +00:00
|
|
|
setButtonGuiItem( User3, KStandardGuiItem::find());
|
|
|
|
setButtonGuiItem( User2, KStandardGuiItem::stop() );
|
|
|
|
setButtonGuiItem( User1, KStandardGuiItem::saveAs() );
|
2006-06-13 17:41:00 +00:00
|
|
|
|
2006-02-22 09:43:36 +00:00
|
|
|
QWidget::setWindowTitle( i18n("Find Files/Folders" ) );
|
2006-08-13 20:14:25 +00:00
|
|
|
setButtonsOrientation(Qt::Vertical);
|
2001-10-18 09:14:25 +00:00
|
|
|
|
2006-08-13 20:14:25 +00:00
|
|
|
enableButton(User3, true); // Enable "Find"
|
|
|
|
enableButton(User2, false); // Disable "Stop"
|
|
|
|
enableButton(User1, false); // Disable "Save As..."
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
isResultReported = false;
|
|
|
|
|
2006-06-13 17:41:00 +00:00
|
|
|
QFrame *frame = new QFrame;
|
|
|
|
setMainWidget( frame );
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
// create tabwidget
|
2006-08-13 20:14:25 +00:00
|
|
|
tabWidget = new KfindTabWidget( frame );
|
2002-02-10 00:23:04 +00:00
|
|
|
tabWidget->setURL( url );
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
// prepare window for find results
|
2005-10-03 13:23:25 +00:00
|
|
|
win = new KfindWindow(frame );
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
mStatusBar = new KStatusBar(frame);
|
2006-02-06 19:08:42 +00:00
|
|
|
mStatusBar->insertFixedItem(i18n("AMiddleLengthText..."), 0);
|
2001-10-18 09:14:25 +00:00
|
|
|
setStatusMsg(i18n("Ready."));
|
2005-07-28 14:59:42 +00:00
|
|
|
mStatusBar->setItemAlignment(0, Qt::AlignLeft | Qt::AlignVCenter);
|
2006-02-27 09:22:21 +00:00
|
|
|
mStatusBar->insertPermanentItem(QString(), 1, 1);
|
2005-07-28 14:59:42 +00:00
|
|
|
mStatusBar->setItemAlignment(1, Qt::AlignLeft | Qt::AlignVCenter);
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
QVBoxLayout *vBox = new QVBoxLayout(frame);
|
|
|
|
vBox->addWidget(tabWidget, 0);
|
|
|
|
vBox->addWidget(win, 1);
|
|
|
|
vBox->addWidget(mStatusBar, 0);
|
|
|
|
|
2006-08-13 20:14:25 +00:00
|
|
|
connect(this, SIGNAL(user3Clicked()),
|
2001-10-18 09:14:25 +00:00
|
|
|
this, SLOT(startSearch()));
|
2004-07-22 10:12:24 +00:00
|
|
|
connect(this, SIGNAL(user2Clicked()),
|
2006-08-13 20:14:25 +00:00
|
|
|
this, SLOT(stopSearch()));
|
|
|
|
connect(this, SIGNAL(user1Clicked()),
|
2001-10-18 09:14:25 +00:00
|
|
|
win, SLOT(saveResults()));
|
|
|
|
|
|
|
|
connect(win ,SIGNAL(resultSelected(bool)),
|
|
|
|
this,SIGNAL(resultSelected(bool)));
|
|
|
|
|
|
|
|
query = new KQuery(frame);
|
2001-11-04 11:38:26 +00:00
|
|
|
connect(query, SIGNAL(addFile(const KFileItem*,const QString&)),
|
|
|
|
SLOT(addFile(const KFileItem*,const QString&)));
|
2001-10-18 09:14:25 +00:00
|
|
|
connect(query, SIGNAL(result(int)), SLOT(slotResult(int)));
|
2003-12-10 11:48:22 +00:00
|
|
|
|
2003-08-17 16:50:46 +00:00
|
|
|
dirwatch=NULL;
|
2001-10-18 09:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KfindDlg::~KfindDlg()
|
|
|
|
{
|
|
|
|
stopSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::closeEvent(QCloseEvent *)
|
|
|
|
{
|
2006-01-10 20:04:44 +00:00
|
|
|
slotButtonClicked(KDialog::Close);
|
2001-10-18 09:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::setProgressMsg(const QString &msg)
|
|
|
|
{
|
|
|
|
mStatusBar->changeItem(msg, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::setStatusMsg(const QString &msg)
|
|
|
|
{
|
|
|
|
mStatusBar->changeItem(msg, 0);
|
|
|
|
}
|
|
|
|
|
2002-04-10 22:25:55 +00:00
|
|
|
|
2001-10-18 09:14:25 +00:00
|
|
|
void KfindDlg::startSearch()
|
|
|
|
{
|
|
|
|
tabWidget->setQuery(query);
|
|
|
|
|
|
|
|
isResultReported = false;
|
|
|
|
|
2002-04-04 12:48:41 +00:00
|
|
|
// Reset count - use the same i18n as below
|
2007-02-12 15:11:00 +00:00
|
|
|
setProgressMsg(i18np("one file found", "%1 files found", 0));
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
emit resultSelected(false);
|
|
|
|
emit haveResults(false);
|
|
|
|
|
2006-08-13 20:14:25 +00:00
|
|
|
enableButton(User3, false); // Disable "Find"
|
|
|
|
enableButton(User2, true); // Enable "Stop"
|
|
|
|
enableButton(User1, false); // Disable "Save As..."
|
2001-10-18 09:14:25 +00:00
|
|
|
|
2003-08-17 16:50:46 +00:00
|
|
|
if(dirwatch!=NULL)
|
|
|
|
delete dirwatch;
|
|
|
|
dirwatch=new KDirWatch();
|
|
|
|
connect(dirwatch, SIGNAL(created(const QString&)), this, SLOT(slotNewItems(const QString&)));
|
|
|
|
connect(dirwatch, SIGNAL(deleted(const QString&)), this, SLOT(slotDeleteItem(const QString&)));
|
|
|
|
dirwatch->addDir(query->url().path(),true);
|
2003-12-10 11:48:22 +00:00
|
|
|
|
2005-01-25 17:47:56 +00:00
|
|
|
#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
|
2006-05-31 16:23:36 +00:00
|
|
|
// is started by KQuery but in-process, undoing the advantages of using a separate find process
|
2005-01-25 17:47:56 +00:00
|
|
|
// 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.
|
|
|
|
|
2003-07-28 15:17:58 +00:00
|
|
|
//Getting a list of all subdirs
|
2004-01-05 20:46:00 +00:00
|
|
|
if(tabWidget->isSearchRecursive() && (dirwatch->internalMethod() == KDirWatch::FAM))
|
2003-07-28 15:17:58 +00:00
|
|
|
{
|
|
|
|
QStringList subdirs=getAllSubdirs(query->url().path());
|
|
|
|
for(QStringList::Iterator it = subdirs.begin(); it != subdirs.end(); ++it)
|
2003-08-18 16:25:16 +00:00
|
|
|
dirwatch->addDir(*it,true);
|
2003-07-28 15:17:58 +00:00
|
|
|
}
|
2005-01-25 17:47:56 +00:00
|
|
|
#endif
|
2004-07-22 10:12:24 +00:00
|
|
|
|
2002-04-10 22:25:55 +00:00
|
|
|
win->beginSearch(query->url());
|
2001-10-18 09:14:25 +00:00
|
|
|
tabWidget->beginSearch();
|
|
|
|
|
2003-07-28 15:17:58 +00:00
|
|
|
setStatusMsg(i18n("Searching..."));
|
2001-10-18 09:14:25 +00:00
|
|
|
query->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::stopSearch()
|
|
|
|
{
|
|
|
|
query->kill();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::newSearch()
|
|
|
|
{
|
|
|
|
// WABA: Not used any longer?
|
|
|
|
stopSearch();
|
|
|
|
|
|
|
|
tabWidget->setDefaults();
|
|
|
|
|
|
|
|
emit haveResults(false);
|
|
|
|
emit resultSelected(false);
|
|
|
|
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::slotResult(int errorCode)
|
|
|
|
{
|
|
|
|
if (errorCode == 0)
|
|
|
|
setStatusMsg(i18n("Ready."));
|
|
|
|
else if (errorCode == KIO::ERR_USER_CANCELED)
|
|
|
|
setStatusMsg(i18n("Aborted."));
|
2003-06-28 20:27:17 +00:00
|
|
|
else if (errorCode == KIO::ERR_MALFORMED_URL)
|
|
|
|
{
|
|
|
|
setStatusMsg(i18n("Error."));
|
|
|
|
KMessageBox::sorry( this, i18n("Please specify an absolute path in the \"Look in\" box."));
|
|
|
|
}
|
2001-10-18 09:14:25 +00:00
|
|
|
else if (errorCode == KIO::ERR_DOES_NOT_EXIST)
|
|
|
|
{
|
|
|
|
setStatusMsg(i18n("Error."));
|
2003-10-22 07:40:35 +00:00
|
|
|
KMessageBox::sorry( this, i18n("Could not find the specified folder."));
|
2001-10-18 09:14:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-06 15:07:10 +00:00
|
|
|
kDebug()<<"KIO error code: "<<errorCode<<endl;
|
2001-10-18 09:14:25 +00:00
|
|
|
setStatusMsg(i18n("Error."));
|
|
|
|
};
|
|
|
|
|
2006-08-13 20:14:25 +00:00
|
|
|
enableButton(User3, true); // Enable "Find"
|
|
|
|
enableButton(User2, false); // Disable "Stop"
|
|
|
|
enableButton(User1, true); // Enable "Save As..."
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
win->endSearch();
|
|
|
|
tabWidget->endSearch();
|
|
|
|
setFocus();
|
2003-07-24 17:20:12 +00:00
|
|
|
|
2001-10-18 09:14:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-04 11:38:26 +00:00
|
|
|
void KfindDlg::addFile(const KFileItem* item, const QString& matchingLine)
|
2001-10-18 09:14:25 +00:00
|
|
|
{
|
2001-11-04 11:38:26 +00:00
|
|
|
win->insertItem(*item,matchingLine);
|
2001-10-18 09:14:25 +00:00
|
|
|
|
|
|
|
if (!isResultReported)
|
|
|
|
{
|
|
|
|
emit haveResults(true);
|
|
|
|
isResultReported = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = win->childCount();
|
2007-02-12 15:11:00 +00:00
|
|
|
QString str = i18np("one file found", "%1 files found", count);
|
2001-10-18 09:14:25 +00:00
|
|
|
setProgressMsg(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::setFocus()
|
|
|
|
{
|
|
|
|
tabWidget->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::copySelection()
|
|
|
|
{
|
|
|
|
win->copySelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KfindDlg::about ()
|
|
|
|
{
|
2007-01-29 23:28:40 +00:00
|
|
|
KAboutApplicationDialog dlg(0, this);
|
2004-03-28 07:17:00 +00:00
|
|
|
dlg.exec ();
|
2001-10-18 09:14:25 +00:00
|
|
|
}
|
2003-07-24 17:20:12 +00:00
|
|
|
|
2003-08-17 16:50:46 +00:00
|
|
|
void KfindDlg::slotDeleteItem(const QString& file)
|
2003-07-24 17:20:12 +00:00
|
|
|
{
|
2006-02-06 15:07:10 +00:00
|
|
|
kDebug()<<QString("Will remove one item: %1").arg(file)<<endl;
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItem *iter;
|
2003-07-24 17:20:12 +00:00
|
|
|
QString iterwithpath;
|
|
|
|
|
|
|
|
iter=win->firstChild();
|
|
|
|
while( iter ) {
|
2006-05-08 13:46:00 +00:00
|
|
|
iterwithpath=query->url().path(KUrl::AddTrailingSlash)+iter->text(1)+iter->text(0);
|
2003-07-28 20:06:57 +00:00
|
|
|
|
2003-08-17 16:50:46 +00:00
|
|
|
if(iterwithpath==file)
|
2003-07-24 17:20:12 +00:00
|
|
|
{
|
|
|
|
win->takeItem(iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iter = iter->nextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-17 16:50:46 +00:00
|
|
|
void KfindDlg::slotNewItems( const QString& file )
|
2003-07-24 17:20:12 +00:00
|
|
|
{
|
2006-02-06 15:07:10 +00:00
|
|
|
kDebug()<<QString("Will add this item")<<endl;
|
2003-07-24 17:20:12 +00:00
|
|
|
QStringList newfiles;
|
2005-07-28 14:59:42 +00:00
|
|
|
Q3ListViewItem *checkiter;
|
2003-07-28 15:17:58 +00:00
|
|
|
QString checkiterwithpath;
|
2004-07-22 10:12:24 +00:00
|
|
|
|
2006-05-08 13:46:00 +00:00
|
|
|
if(file.indexOf(query->url().path(KUrl::AddTrailingSlash))==0)
|
2003-07-24 17:20:12 +00:00
|
|
|
{
|
2006-02-06 15:07:10 +00:00
|
|
|
kDebug()<<QString("Can be added, path OK")<<endl;
|
2003-08-17 16:50:46 +00:00
|
|
|
checkiter=win->firstChild();
|
|
|
|
while( checkiter ) {
|
2006-05-08 13:46:00 +00:00
|
|
|
checkiterwithpath=query->url().path(KUrl::AddTrailingSlash)+checkiter->text(1)+checkiter->text(0);
|
2003-08-17 16:50:46 +00:00
|
|
|
if(file==checkiterwithpath)
|
|
|
|
return;
|
|
|
|
checkiter = checkiter->nextSibling();
|
2003-07-24 17:20:12 +00:00
|
|
|
}
|
2003-08-17 16:50:46 +00:00
|
|
|
query->slotListEntries(QStringList(file));
|
2003-07-24 17:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-28 15:17:58 +00:00
|
|
|
|
|
|
|
QStringList KfindDlg::getAllSubdirs(QDir d)
|
|
|
|
{
|
|
|
|
QStringList dirs;
|
|
|
|
QStringList subdirs;
|
|
|
|
|
2003-07-28 20:06:57 +00:00
|
|
|
d.setFilter( QDir::Dirs );
|
2003-07-28 15:17:58 +00:00
|
|
|
dirs = d.entryList();
|
|
|
|
|
|
|
|
for(QStringList::Iterator it = dirs.begin(); it != dirs.end(); ++it)
|
|
|
|
{
|
|
|
|
if((*it==".")||(*it==".."))
|
|
|
|
continue;
|
2006-05-31 16:23:36 +00:00
|
|
|
subdirs.append(d.path()+'/'+*it);
|
|
|
|
subdirs+=getAllSubdirs(d.path()+'/'+*it);
|
2003-07-28 15:17:58 +00:00
|
|
|
}
|
|
|
|
return subdirs;
|
|
|
|
}
|