delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / kfind / kfind.cpp
blobf560fc2e7be9f0cdb6f41532ecc8f42c4942d042
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>
39 #include <KLineEdit>
41 #include "kftabdlg.h"
42 #include "kquery.h"
44 #include "kfind.moc"
46 Kfind::Kfind(QWidget *parent)
47 : QWidget( parent )
49 kDebug() << "Kfind::Kfind " << this;
50 QBoxLayout * mTopLayout = new QBoxLayout( QBoxLayout::LeftToRight, this );
52 // create tabwidget
53 tabWidget = new KfindTabWidget( this );
54 mTopLayout->addWidget(tabWidget);
56 // create button box
57 KVBox * mButtonBox = new KVBox( this );
58 QVBoxLayout *lay = (QVBoxLayout*)mButtonBox->layout();
59 lay->addStretch(1);
60 mTopLayout->addWidget(mButtonBox);
62 mSearch = new KPushButton( KStandardGuiItem::find(), mButtonBox );
63 mButtonBox->setSpacing( (tabWidget->sizeHint().height()-4*mSearch->sizeHint().height()) / 4);
64 connect( mSearch, SIGNAL(clicked()), this, SLOT( startSearch() ) );
65 mStop = new KPushButton( KStandardGuiItem::stop(), mButtonBox );
66 connect( mStop, SIGNAL(clicked()), this, SLOT( stopSearch() ) );
67 mSave = new KPushButton( KStandardGuiItem::saveAs(), mButtonBox );
68 connect( mSave, SIGNAL(clicked()), this, SLOT( saveResults() ) );
70 KPushButton * mClose = new KPushButton( KStandardGuiItem::close(), mButtonBox );
71 connect( mClose, SIGNAL(clicked()), this, SIGNAL( destroyMe() ) );
73 // react to search requests from widget
74 connect( tabWidget, SIGNAL(startSearch()), this, SLOT( startSearch() ) );
76 mSearch->setEnabled(true); // Enable "Search"
77 mStop->setEnabled(false); // Disable "Stop"
78 mSave->setEnabled(false); // Disable "Save..."
80 dirlister=new KDirLister();
83 Kfind::~Kfind()
85 stopSearch();
86 dirlister->stop();
87 delete dirlister;
88 kDebug() << "Kfind::~Kfind";
91 void Kfind::setURL( const KUrl &url )
93 tabWidget->setURL( url );
96 void Kfind::startSearch()
98 tabWidget->setQuery(query);
99 emit started();
101 //emit resultSelected(false);
102 //emit haveResults(false);
104 mSearch->setEnabled(false); // Disable "Search"
105 mStop->setEnabled(true); // Enable "Stop"
106 mSave->setEnabled(false); // Disable "Save..."
108 tabWidget->beginSearch();
110 dirlister->openUrl(KUrl(tabWidget->dirBox->currentText().trimmed()));
112 query->start();
115 void Kfind::stopSearch()
117 // will call KFindPart::slotResult, which calls searchFinished here
118 query->kill();
121 void Kfind::searchFinished()
123 mSearch->setEnabled(true); // Enable "Search"
124 mStop->setEnabled(false); // Disable "Stop"
125 // ## TODO mSave->setEnabled(true); // Enable "Save..."
127 tabWidget->endSearch();
128 setFocus();
132 void Kfind::saveResults()
134 // TODO
137 void Kfind::setFocus()
139 tabWidget->setFocus();
142 void Kfind::saveState( QDataStream *stream )
144 query->kill();
145 *stream << tabWidget->nameBox->currentText();
146 *stream << tabWidget->dirBox->currentText();
147 *stream << tabWidget->typeBox->currentIndex();
148 *stream << tabWidget->textEdit->text();
149 *stream << (int)( tabWidget->subdirsCb->isChecked() ? 0 : 1 );
152 void Kfind::restoreState( QDataStream *stream )
154 QString namesearched, dirsearched,containing;
155 int typeIdx;
156 int subdirs;
157 *stream >> namesearched;
158 *stream >> dirsearched;
159 *stream >> typeIdx;
160 *stream >> containing;
161 *stream >> subdirs;
162 tabWidget->nameBox->addItem( namesearched, 0);
163 tabWidget->dirBox->addItem ( dirsearched, 0);
164 tabWidget->typeBox->setCurrentIndex(typeIdx);
165 tabWidget->textEdit->setText ( containing );
166 tabWidget->subdirsCb->setChecked( ( subdirs==0 ? true : false ));