From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kfind/kfind.cpp | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 kfind/kfind.cpp (limited to 'kfind/kfind.cpp') diff --git a/kfind/kfind.cpp b/kfind/kfind.cpp new file mode 100644 index 000000000..93c646a91 --- /dev/null +++ b/kfind/kfind.cpp @@ -0,0 +1,192 @@ +/*********************************************************************** + * + * Kfind.cpp + * + * This is KFind, released under GPL + * + * 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 the License, or + * (at your option) any later version. + * + * KFind (c) 1998-2003 The KDE Developers + Martin Hartig + Stephan Kulow + Mario Weilguni + Alex Zepeda + Miroslav Flídr + Harri Porten + Dima Rogozin + Carsten Pfeiffer + Hans Petter Bieker + Waldo Bastian + Beppe Grimaldi + Eric Coquelle + + **********************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "kftabdlg.h" +#include "kquery.h" + +#include "kfind.moc" + +Kfind::Kfind(QWidget *parent, const char *name) + : QWidget( parent, name ) +{ + kdDebug() << "Kfind::Kfind " << this << endl; + QBoxLayout * mTopLayout = new QBoxLayout( this, QBoxLayout::LeftToRight, + KDialog::marginHint(), KDialog::spacingHint() ); + + // create tabwidget + tabWidget = new KfindTabWidget( this ); + mTopLayout->addWidget(tabWidget); + + /* + * This is ugly. Might be a KSeparator bug, but it makes a small black + * pixel for me which is visually distracting (GS). + // create separator + KSeparator * mActionSep = new KSeparator( this ); + mActionSep->setFocusPolicy( QWidget::ClickFocus ); + mActionSep->setOrientation( QFrame::VLine ); + mTopLayout->addWidget(mActionSep); + */ + + // create button box + QVBox * mButtonBox = new QVBox( this ); + QVBoxLayout *lay = (QVBoxLayout*)mButtonBox->layout(); + lay->addStretch(1); + mTopLayout->addWidget(mButtonBox); + + mSearch = new KPushButton( KGuiItem(i18n("&Find"), "find"), mButtonBox ); + mButtonBox->setSpacing( (tabWidget->sizeHint().height()-4*mSearch->sizeHint().height()) / 4); + connect( mSearch, SIGNAL(clicked()), this, SLOT( startSearch() ) ); + mStop = new KPushButton( KGuiItem(i18n("Stop"), "stop"), mButtonBox ); + connect( mStop, SIGNAL(clicked()), this, SLOT( stopSearch() ) ); + mSave = new KPushButton( KStdGuiItem::saveAs(), mButtonBox ); + connect( mSave, SIGNAL(clicked()), this, SLOT( saveResults() ) ); + + KPushButton * mClose = new KPushButton( KStdGuiItem::close(), mButtonBox ); + connect( mClose, SIGNAL(clicked()), this, SIGNAL( destroyMe() ) ); + + // react to search requests from widget + connect( tabWidget, SIGNAL(startSearch()), this, SLOT( startSearch() ) ); + + mSearch->setEnabled(true); // Enable "Search" + mStop->setEnabled(false); // Disable "Stop" + mSave->setEnabled(false); // Disable "Save..." + + dirlister=new KDirLister(); +} + +Kfind::~Kfind() +{ + stopSearch(); + dirlister->stop(); + delete dirlister; + kdDebug() << "Kfind::~Kfind" << endl; +} + +void Kfind::setURL( const KURL &url ) +{ + tabWidget->setURL( url ); +} + +void Kfind::startSearch() +{ + tabWidget->setQuery(query); + emit started(); + + //emit resultSelected(false); + //emit haveResults(false); + + mSearch->setEnabled(false); // Disable "Search" + mStop->setEnabled(true); // Enable "Stop" + mSave->setEnabled(false); // Disable "Save..." + + tabWidget->beginSearch(); + + dirlister->openURL(KURL(tabWidget->dirBox->currentText().stripWhiteSpace())); + + query->start(); +} + +void Kfind::stopSearch() +{ + // will call KFindPart::slotResult, which calls searchFinished here + query->kill(); +} + +/* +void Kfind::newSearch() +{ + // WABA: Not used any longer? + stopSearch(); + + tabWidget->setDefaults(); + + emit haveResults(false); + emit resultSelected(false); + + setFocus(); +} +*/ + +void Kfind::searchFinished() +{ + mSearch->setEnabled(true); // Enable "Search" + mStop->setEnabled(false); // Disable "Stop" + // ## TODO mSave->setEnabled(true); // Enable "Save..." + + tabWidget->endSearch(); + setFocus(); +} + + +void Kfind::saveResults() +{ + // TODO +} + +void Kfind::setFocus() +{ + tabWidget->setFocus(); +} + +void Kfind::saveState( QDataStream *stream ) +{ + query->kill(); + *stream << tabWidget->nameBox->currentText(); + *stream << tabWidget->dirBox->currentText(); + *stream << tabWidget->typeBox->currentItem(); + *stream << tabWidget->textEdit->text(); + *stream << (int)( tabWidget->subdirsCb->isChecked() ? 0 : 1 ); +} + +void Kfind::restoreState( QDataStream *stream ) +{ + QString namesearched, dirsearched,containing; + int typeIdx; + int subdirs; + *stream >> namesearched; + *stream >> dirsearched; + *stream >> typeIdx; + *stream >> containing; + *stream >> subdirs; + tabWidget->nameBox->insertItem( namesearched, 0); + tabWidget->dirBox->insertItem ( dirsearched, 0); + tabWidget->typeBox->setCurrentItem(typeIdx); + tabWidget->textEdit->setText ( containing ); + tabWidget->subdirsCb->setChecked( ( subdirs==0 ? true : false )); +} -- cgit v1.2.3