1 /***********************************************************************
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
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>
37 #include <kstandardguiitem.h>
38 #include <kdirlister.h>
46 Kfind::Kfind(QWidget
*parent
)
49 kDebug() << "Kfind::Kfind " << this;
50 QBoxLayout
* mTopLayout
= new QBoxLayout( QBoxLayout::LeftToRight
, this );
53 tabWidget
= new KfindTabWidget( this );
54 mTopLayout
->addWidget(tabWidget
);
57 KVBox
* mButtonBox
= new KVBox( this );
58 QVBoxLayout
*lay
= (QVBoxLayout
*)mButtonBox
->layout();
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();
88 kDebug() << "Kfind::~Kfind";
91 void Kfind::setURL( const KUrl
&url
)
93 tabWidget
->setURL( url
);
96 void Kfind::startSearch()
98 tabWidget
->setQuery(query
);
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()));
115 void Kfind::stopSearch()
117 // will call KFindPart::slotResult, which calls searchFinished here
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();
132 void Kfind::saveResults()
137 void Kfind::setFocus()
139 tabWidget
->setFocus();
142 void Kfind::saveState( QDataStream
*stream
)
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
;
157 *stream
>> namesearched
;
158 *stream
>> dirsearched
;
160 *stream
>> containing
;
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 ));