delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / kfind / kfindpart.cpp
blob6b31ea1a9c8e55bf31b661d6a2749d02a6507185
1 /* This file is part of the KDE projects
2 Copyright (C) 2000 David Faure <faure@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "kfindpart.h"
21 #include "kfind.h"
22 #include "kquery.h"
24 #include <kparts/genericfactory.h>
25 #include <kdebug.h>
26 #include <klocale.h>
27 #include <kfileitem.h>
28 #include <kdirlister.h>
29 #include <kcomponentdata.h>
31 #include <QtCore/QDir>
33 typedef KParts::GenericFactory<KFindPart> KFindFactory;
34 K_EXPORT_COMPONENT_FACTORY( libkfindpart, KFindFactory )
36 KFindPart::KFindPart( QWidget * parentWidget, QObject *parent, const QStringList & /*args*/ )
37 : KParts::ReadOnlyPart(parent)
39 setComponentData( KFindFactory::componentData() );
41 // setBrowserExtension( new KonqDirPartBrowserExtension( this ) );
43 kDebug() << "KFindPart::KFindPart " << this;
44 m_kfindWidget = new Kfind( parentWidget );
45 m_kfindWidget->setMaximumHeight(m_kfindWidget->minimumSizeHint().height());
47 #if 0 // TODO port?
48 const KFileItem item = ((KonqDirPart*)parent)->currentItem();
49 kDebug() << "Kfind: currentItem: " << ( !item.isNull() ? item.url().path().toLocal8Bit() : QString("null") );
50 QDir d;
51 if( !item.isNull() && d.exists( item.url().path() ))
52 m_kfindWidget->setURL( item.url() );
53 #endif
55 setWidget( m_kfindWidget );
57 connect( m_kfindWidget, SIGNAL(started()),
58 this, SLOT(slotStarted()) );
59 connect( m_kfindWidget, SIGNAL(destroyMe()),
60 this, SLOT(slotDestroyMe()) );
61 connect(m_kfindWidget->dirlister,SIGNAL(deleteItem(const KFileItem&)), this, SLOT(removeFile(const KFileItem&)));
62 connect(m_kfindWidget->dirlister,SIGNAL(newItems(const KFileItemList&)), this, SLOT(newFiles(const KFileItemList&)));
63 //setXMLFile( "kfind.rc" );
64 query = new KQuery(this);
65 connect(query, SIGNAL(addFile(const KFileItem &, const QString&)),
66 SLOT(addFile(const KFileItem &, const QString&)));
67 connect(query, SIGNAL(result(int)),
68 SLOT(slotResult(int)));
70 m_kfindWidget->setQuery(query);
71 m_bShowsResult = false;
74 KFindPart::~KFindPart()
76 m_lstFileItems.clear();
79 KAboutData *KFindPart::createAboutData()
81 return new KAboutData( "kfindpart", 0, ki18nc( "Name of the component that finds things", "Find Component" ), "1.0" );
84 bool KFindPart::openUrl( const KUrl &url )
86 m_kfindWidget->setURL( url );
87 return true;
90 void KFindPart::slotStarted()
92 kDebug() << "KFindPart::slotStarted";
93 m_bShowsResult = true;
94 m_lstFileItems.clear(); // clear our internal list
95 emit started();
96 emit clear();
99 void KFindPart::addFile(const KFileItem &item, const QString& /*matchingLine*/)
101 m_lstFileItems.append( item );
103 KFileItemList lstNewItems;
104 lstNewItems.append(item);
105 emit newItems(lstNewItems);
108 win->insertItem(item);
110 if (!isResultReported)
112 emit haveResults(true);
113 isResultReported = true;
119 /* An item has been removed, so update konqueror's view */
120 void KFindPart::removeFile(const KFileItem &item)
122 KFileItemList listiter;
124 emit started();
125 emit clear();
127 m_lstFileItems.removeAll( item ); //not working ?
129 foreach(const KFileItem &iter, m_lstFileItems) {
130 if(iter.url() != item.url())
131 listiter.append(iter);
134 if (listiter.count())
135 emit newItems(listiter);
136 emit finished();
139 void KFindPart::newFiles(const KFileItemList&)
141 if(m_bShowsResult)
142 return;
143 emit started();
144 emit clear();
145 if (m_lstFileItems.count())
146 emit newItems(m_lstFileItems);
147 emit finished();
150 void KFindPart::slotResult(int errorCode)
152 if (errorCode == 0)
153 emit finished();
154 //setStatusMsg(i18n("Ready."));
155 else if (errorCode == KIO::ERR_USER_CANCELED)
156 emit canceled();
157 //setStatusMsg(i18n("Aborted."));
158 else
159 emit canceled(); // TODO ?
160 //setStatusMsg(i18n("Error."));
161 m_bShowsResult=false;
162 m_kfindWidget->searchFinished();
165 void KFindPart::slotDestroyMe()
167 m_kfindWidget->stopSearch();
168 emit clear(); // this is necessary to clear the delayed-mimetypes items list
169 m_lstFileItems.clear(); // clear our internal list
170 emit findClosed();
173 void KFindPart::saveState( QDataStream& stream )
175 //KonqDirPart::saveState(stream);
177 m_kfindWidget->saveState( &stream );
178 //Now we'll save the search result
179 stream << m_lstFileItems.count();
180 foreach(const KFileItem &fileitem, m_lstFileItems)
182 stream << fileitem;
186 void KFindPart::restoreState( QDataStream& stream )
188 //KonqDirPart::restoreState(stream);
189 int nbitems;
190 KUrl itemUrl;
192 m_kfindWidget->restoreState( &stream );
194 stream >> nbitems;
195 slotStarted();
196 for(int i=0;i<nbitems;i++)
198 KFileItem item( KFileItem::Unknown, KFileItem::Unknown, KUrl() );
199 stream >> item;
200 m_lstFileItems.append(item);
202 if (nbitems)
203 emit newItems(m_lstFileItems);
205 emit finished();
208 #include "kfindpart.moc"