Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / kfind / kfind.cpp
blob29c14e7f7ce35604e8a13e5b7d43ea26a98d3759
1 /***********************************************************************
3 * Kfind.cpp
5 * This is KFind, released under GPL
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * KFind (c) 1998-2003 The KDE Developers
13 Martin Hartig
14 Stephan Kulow <coolo@kde.org>
15 Mario Weilguni <mweilguni@sime.com>
16 Alex Zepeda <zipzippy@sonic.net>
17 Miroslav Flídr <flidr@kky.zcu.cz>
18 Harri Porten <porten@kde.org>
19 Dima Rogozin <dima@mercury.co.il>
20 Carsten Pfeiffer <pfeiffer@kde.org>
21 Hans Petter Bieker <bieker@kde.org>
22 Waldo Bastian <bastian@kde.org>
23 Beppe Grimaldi <grimalkin@ciaoweb.it>
24 Eric Coquelle <coquelle@caramail.com>
26 **********************************************************************/
28 #include <QtGui/QLayout>
29 #include <QtGui/QLineEdit>
30 #include <QtGui/QCheckBox>
32 #include <kpushbutton.h>
33 #include <kvbox.h>
34 #include <kdialog.h>
35 #include <kdebug.h>
36 #include <klocale.h>
37 #include <kstandardguiitem.h>
38 #include <kdirlister.h>
40 #include "kftabdlg.h"
41 #include "kquery.h"
43 #include "kfind.moc"
45 Kfind::Kfind(QWidget *parent)
46 : QWidget( parent )
48 kDebug() << "Kfind::Kfind " << this;
49 QBoxLayout * mTopLayout = new QBoxLayout( QBoxLayout::LeftToRight, this );
51 // create tabwidget
52 tabWidget = new KfindTabWidget( this );
53 mTopLayout->addWidget(tabWidget);
55 // create button box
56 KVBox * mButtonBox = new KVBox( this );
57 QVBoxLayout *lay = (QVBoxLayout*)mButtonBox->layout();
58 lay->addStretch(1);
59 mTopLayout->addWidget(mButtonBox);
61 mSearch = new KPushButton( KStandardGuiItem::find(), mButtonBox );
62 mButtonBox->setSpacing( (tabWidget->sizeHint().height()-4*mSearch->sizeHint().height()) / 4);
63 connect( mSearch, SIGNAL(clicked()), this, SLOT( startSearch() ) );
64 mStop = new KPushButton( KStandardGuiItem::stop(), mButtonBox );
65 connect( mStop, SIGNAL(clicked()), this, SLOT( stopSearch() ) );
66 mSave = new KPushButton( KStandardGuiItem::saveAs(), mButtonBox );
67 connect( mSave, SIGNAL(clicked()), this, SLOT( saveResults() ) );
69 KPushButton * mClose = new KPushButton( KStandardGuiItem::close(), mButtonBox );
70 connect( mClose, SIGNAL(clicked()), this, SIGNAL( destroyMe() ) );
72 // react to search requests from widget
73 connect( tabWidget, SIGNAL(startSearch()), this, SLOT( startSearch() ) );
75 mSearch->setEnabled(true); // Enable "Search"
76 mStop->setEnabled(false); // Disable "Stop"
77 mSave->setEnabled(false); // Disable "Save..."
79 dirlister=new KDirLister();
82 Kfind::~Kfind()
84 stopSearch();
85 dirlister->stop();
86 delete dirlister;
87 kDebug() << "Kfind::~Kfind";
90 void Kfind::setURL( const KUrl &url )
92 tabWidget->setURL( url );
95 void Kfind::startSearch()
97 tabWidget->setQuery(query);
98 emit started();
100 //emit resultSelected(false);
101 //emit haveResults(false);
103 mSearch->setEnabled(false); // Disable "Search"
104 mStop->setEnabled(true); // Enable "Stop"
105 mSave->setEnabled(false); // Disable "Save..."
107 tabWidget->beginSearch();
109 dirlister->openUrl(KUrl(tabWidget->dirBox->currentText().trimmed()));
111 query->start();
114 void Kfind::stopSearch()
116 // will call KFindPart::slotResult, which calls searchFinished here
117 query->kill();
120 void Kfind::searchFinished()
122 mSearch->setEnabled(true); // Enable "Search"
123 mStop->setEnabled(false); // Disable "Stop"
124 // ## TODO mSave->setEnabled(true); // Enable "Save..."
126 tabWidget->endSearch();
127 setFocus();
131 void Kfind::saveResults()
133 // TODO
136 void Kfind::setFocus()
138 tabWidget->setFocus();
141 void Kfind::saveState( QDataStream *stream )
143 query->kill();
144 *stream << tabWidget->nameBox->currentText();
145 *stream << tabWidget->dirBox->currentText();
146 *stream << tabWidget->typeBox->currentIndex();
147 *stream << tabWidget->textEdit->text();
148 *stream << (int)( tabWidget->subdirsCb->isChecked() ? 0 : 1 );
151 void Kfind::restoreState( QDataStream *stream )
153 QString namesearched, dirsearched,containing;
154 int typeIdx;
155 int subdirs;
156 *stream >> namesearched;
157 *stream >> dirsearched;
158 *stream >> typeIdx;
159 *stream >> containing;
160 *stream >> subdirs;
161 tabWidget->nameBox->addItem( namesearched, 0);
162 tabWidget->dirBox->addItem ( dirsearched, 0);
163 tabWidget->typeBox->setCurrentIndex(typeIdx);
164 tabWidget->textEdit->setText ( containing );
165 tabWidget->subdirsCb->setChecked( ( subdirs==0 ? true : false ));