summaryrefslogtreecommitdiff
authorzecke <zecke>2003-11-30 13:23:51 (UTC)
committer zecke <zecke>2003-11-30 13:23:51 (UTC)
commit16756af1bf59a8c59b16c852e311316aacd3351f (patch) (unidiff)
treefb173ed7bdca4a1691ce5ed31bebf436624f74b1
parent8339a705567a3bd50af2e41805e9256973eedcc4 (diff)
downloadopie-16756af1bf59a8c59b16c852e311316aacd3351f.zip
opie-16756af1bf59a8c59b16c852e311316aacd3351f.tar.gz
opie-16756af1bf59a8c59b16c852e311316aacd3351f.tar.bz2
Allow to process mouse and key events during document scanning...
I use 20 as a value for now... someone tuned it but forgot to commit it?!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index 1a7de33..ece6931 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -1,338 +1,338 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "documentlist.h" 20#include "documentlist.h"
21#include "serverinterface.h" 21#include "serverinterface.h"
22#include "launcherglobal.h" 22#include "launcherglobal.h"
23 23
24#include <qtopia/config.h> 24#include <qtopia/config.h>
25#include <qtopia/mimetype.h> 25#include <qtopia/mimetype.h>
26#include <qtopia/resource.h> 26#include <qtopia/resource.h>
27#include <qtopia/global.h> 27#include <qtopia/global.h>
28#include <qtopia/private/categories.h> 28#include <qtopia/private/categories.h>
29#include <qtopia/qpeapplication.h> 29#include <qtopia/qpeapplication.h>
30#include <qtopia/applnk.h> 30#include <qtopia/applnk.h>
31#include <qtopia/storage.h> 31#include <qtopia/storage.h>
32#ifdef Q_WS_QWS 32#ifdef Q_WS_QWS
33#include <qtopia/qcopenvelope_qws.h> 33#include <qtopia/qcopenvelope_qws.h>
34#endif 34#endif
35 35
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qtextstream.h> 38#include <qtextstream.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qimage.h> 42#include <qimage.h>
43#include <qcopchannel_qws.h> 43#include <qcopchannel_qws.h>
44#include <qlistview.h> 44#include <qlistview.h>
45#include <qlist.h> 45#include <qlist.h>
46#include <qpixmap.h> 46#include <qpixmap.h>
47 47
48 48
49AppLnkSet *DocumentList::appLnkSet = 0; 49AppLnkSet *DocumentList::appLnkSet = 0;
50 50
51static const int MAX_SEARCH_DEPTH = 10; 51static const int MAX_SEARCH_DEPTH = 10;
52 52
53 53
54class DocumentListPrivate : public QObject { 54class DocumentListPrivate : public QObject {
55 Q_OBJECT 55 Q_OBJECT
56public: 56public:
57 DocumentListPrivate( ServerInterface *gui ); 57 DocumentListPrivate( ServerInterface *gui );
58 ~DocumentListPrivate(); 58 ~DocumentListPrivate();
59 59
60 void initialize(); 60 void initialize();
61 61
62 const QString nextFile(); 62 const QString nextFile();
63 const DocLnk *iterate(); 63 const DocLnk *iterate();
64 bool store( DocLnk* dl ); 64 bool store( DocLnk* dl );
65 void estimatedPercentScanned(); 65 void estimatedPercentScanned();
66 66
67 DocLnkSet dls; 67 DocLnkSet dls;
68 QDict<void> reference; 68 QDict<void> reference;
69 QDictIterator<void> *dit; 69 QDictIterator<void> *dit;
70 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; 70 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state;
71 71
72 QStringList docPaths; 72 QStringList docPaths;
73 unsigned int docPathsSearched; 73 unsigned int docPathsSearched;
74 74
75 int searchDepth; 75 int searchDepth;
76 QDir *listDirs[MAX_SEARCH_DEPTH]; 76 QDir *listDirs[MAX_SEARCH_DEPTH];
77 const QFileInfoList *lists[MAX_SEARCH_DEPTH]; 77 const QFileInfoList *lists[MAX_SEARCH_DEPTH];
78 unsigned int listPositions[MAX_SEARCH_DEPTH]; 78 unsigned int listPositions[MAX_SEARCH_DEPTH];
79 79
80 StorageInfo *storage; 80 StorageInfo *storage;
81 81
82 int tid; 82 int tid;
83 83
84 ServerInterface *serverGui; 84 ServerInterface *serverGui;
85 85
86 bool needToSendAllDocLinks; 86 bool needToSendAllDocLinks;
87 bool sendAppLnks; 87 bool sendAppLnks;
88 bool sendDocLnks; 88 bool sendDocLnks;
89 bool scanDocs; 89 bool scanDocs;
90}; 90};
91 91
92 92
93DocumentList::DocumentList( ServerInterface *serverGui, bool scanDocs, 93DocumentList::DocumentList( ServerInterface *serverGui, bool scanDocs,
94 QObject *parent, const char *name ) 94 QObject *parent, const char *name )
95 : QObject( parent, name ) 95 : QObject( parent, name )
96{ 96{
97 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 97 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
98 d = new DocumentListPrivate( serverGui ); 98 d = new DocumentListPrivate( serverGui );
99 d->needToSendAllDocLinks = false; 99 d->needToSendAllDocLinks = false;
100 100
101 Config cfg( "Launcher" ); 101 Config cfg( "Launcher" );
102 cfg.setGroup( "DocTab" ); 102 cfg.setGroup( "DocTab" );
103 d->scanDocs = cfg.readBoolEntry( "Enable", true ); 103 d->scanDocs = cfg.readBoolEntry( "Enable", true );
104 qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs ); 104 qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs );
105 105
106 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); 106 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) );
107} 107}
108 108
109void DocumentList::startInitialScan() 109void DocumentList::startInitialScan()
110{ 110{
111 reloadAppLnks(); 111 reloadAppLnks();
112 reloadDocLnks(); 112 reloadDocLnks();
113} 113}
114 114
115DocumentList::~DocumentList() 115DocumentList::~DocumentList()
116{ 116{
117 delete appLnkSet; 117 delete appLnkSet;
118 delete d; 118 delete d;
119} 119}
120 120
121 121
122void DocumentList::add( const DocLnk& doc ) 122void DocumentList::add( const DocLnk& doc )
123{ 123{
124 if ( d->serverGui && QFile::exists( doc.file() ) ) 124 if ( d->serverGui && QFile::exists( doc.file() ) )
125 d->serverGui->documentAdded( doc ); 125 d->serverGui->documentAdded( doc );
126} 126}
127 127
128 128
129void DocumentList::start() 129void DocumentList::start()
130{ 130{
131 resume(); 131 resume();
132} 132}
133 133
134 134
135void DocumentList::pause() 135void DocumentList::pause()
136{ 136{
137 //qDebug("pause %i", d->tid); 137 //qDebug("pause %i", d->tid);
138 killTimer( d->tid ); 138 killTimer( d->tid );
139 d->tid = 0; 139 d->tid = 0;
140} 140}
141 141
142 142
143void DocumentList::resume() 143void DocumentList::resume()
144{ 144{
145 if ( d->tid == 0 ) { 145 if ( d->tid == 0 ) {
146 d->tid = startTimer( 0 ); 146 d->tid = startTimer( 20 );
147 //qDebug("resumed %i", d->tid); 147 //qDebug("resumed %i", d->tid);
148 } 148 }
149} 149}
150 150
151/* 151/*
152void DocumentList::resend() 152void DocumentList::resend()
153{ 153{
154 // Re-emits all the added items to the list (firstly letting everyone know to 154 // Re-emits all the added items to the list (firstly letting everyone know to
155 // clear what they have as it is being sent again) 155 // clear what they have as it is being sent again)
156 pause(); 156 pause();
157 emit allRemoved(); 157 emit allRemoved();
158 QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); 158 QTimer::singleShot( 5, this, SLOT( resendWorker() ) );
159} 159}
160 160
161 161
162void DocumentList::resendWorker() 162void DocumentList::resendWorker()
163{ 163{
164 const QList<DocLnk> &list = d->dls.children(); 164 const QList<DocLnk> &list = d->dls.children();
165 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) 165 for ( QListIterator<DocLnk> it( list ); it.current(); ++it )
166 add( *(*it) ); 166 add( *(*it) );
167 resume(); 167 resume();
168} 168}
169*/ 169*/
170 170
171void DocumentList::rescan() 171void DocumentList::rescan()
172{ 172{
173 //qDebug("rescan"); 173 //qDebug("rescan");
174 pause(); 174 pause();
175 d->initialize(); 175 d->initialize();
176 resume(); 176 resume();
177} 177}
178 178
179 179
180void DocumentList::timerEvent( QTimerEvent *te ) 180void DocumentList::timerEvent( QTimerEvent *te )
181{ 181{
182 if ( te->timerId() == d->tid ) { 182 if ( te->timerId() == d->tid ) {
183 // Do 3 at a time 183 // Do 3 at a time
184 for (int i = 0; i < 3; i++ ) { 184 for (int i = 0; i < 3; i++ ) {
185 const DocLnk *lnk = d->iterate(); 185 const DocLnk *lnk = d->iterate();
186 if ( lnk ) { 186 if ( lnk ) {
187 add( *lnk ); 187 add( *lnk );
188 } else { 188 } else {
189 // stop when done 189 // stop when done
190 pause(); 190 pause();
191 if ( d->serverGui ) 191 if ( d->serverGui )
192 d->serverGui->documentScanningProgress( 100 ); 192 d->serverGui->documentScanningProgress( 100 );
193 if ( d->needToSendAllDocLinks ) 193 if ( d->needToSendAllDocLinks )
194 sendAllDocLinks(); 194 sendAllDocLinks();
195 break; 195 break;
196 } 196 }
197 } 197 }
198 } 198 }
199} 199}
200 200
201 201
202void DocumentList::reloadAppLnks() 202void DocumentList::reloadAppLnks()
203{ 203{
204 if ( d->sendAppLnks && d->serverGui ) { 204 if ( d->sendAppLnks && d->serverGui ) {
205 d->serverGui->applicationScanningProgress( 0 ); 205 d->serverGui->applicationScanningProgress( 0 );
206 d->serverGui->allApplicationsRemoved(); 206 d->serverGui->allApplicationsRemoved();
207 } 207 }
208 208
209 delete appLnkSet; 209 delete appLnkSet;
210 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 210 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
211 211
212 if ( d->sendAppLnks && d->serverGui ) { 212 if ( d->sendAppLnks && d->serverGui ) {
213 static QStringList prevTypeList; 213 static QStringList prevTypeList;
214 QStringList types = appLnkSet->types(); 214 QStringList types = appLnkSet->types();
215 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { 215 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
216 if ( !(*ittypes).isEmpty() ) { 216 if ( !(*ittypes).isEmpty() ) {
217 if ( !prevTypeList.contains(*ittypes) ) { 217 if ( !prevTypeList.contains(*ittypes) ) {
218 QString name = appLnkSet->typeName(*ittypes); 218 QString name = appLnkSet->typeName(*ittypes);
219 QPixmap pm = appLnkSet->typePixmap(*ittypes); 219 QPixmap pm = appLnkSet->typePixmap(*ittypes);
220 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); 220 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes);
221 221
222 if (pm.isNull()) { 222 if (pm.isNull()) {
223 QImage img( Resource::loadImage( "UnknownDocument" ) ); 223 QImage img( Resource::loadImage( "UnknownDocument" ) );
224 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 224 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
225 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); 225 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() );
226 } 226 }
227 227
228 //qDebug("adding type %s", (*ittypes).latin1()); 228 //qDebug("adding type %s", (*ittypes).latin1());
229 229
230 // ### our current launcher expects docs tab to be last 230 // ### our current launcher expects docs tab to be last
231 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); 231 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
232 } 232 }
233 prevTypeList.remove(*ittypes); 233 prevTypeList.remove(*ittypes);
234 } 234 }
235 } 235 }
236 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { 236 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) {
237 //qDebug("removing type %s", (*ittypes).latin1()); 237 //qDebug("removing type %s", (*ittypes).latin1());
238 d->serverGui->typeRemoved(*ittypes); 238 d->serverGui->typeRemoved(*ittypes);
239 } 239 }
240 prevTypeList = types; 240 prevTypeList = types;
241 } 241 }
242 242
243 QListIterator<AppLnk> itapp( appLnkSet->children() ); 243 QListIterator<AppLnk> itapp( appLnkSet->children() );
244 AppLnk* l; 244 AppLnk* l;
245 while ( (l=itapp.current()) ) { 245 while ( (l=itapp.current()) ) {
246 ++itapp; 246 ++itapp;
247 if ( d->sendAppLnks && d->serverGui ) 247 if ( d->sendAppLnks && d->serverGui )
248 d->serverGui->applicationAdded( l->type(), *l ); 248 d->serverGui->applicationAdded( l->type(), *l );
249 } 249 }
250 250
251 if ( d->sendAppLnks && d->serverGui ) 251 if ( d->sendAppLnks && d->serverGui )
252 d->serverGui->applicationScanningProgress( 100 ); 252 d->serverGui->applicationScanningProgress( 100 );
253} 253}
254 254
255void DocumentList::reloadDocLnks() 255void DocumentList::reloadDocLnks()
256{ 256{
257 if ( !d->scanDocs ) 257 if ( !d->scanDocs )
258 return; 258 return;
259 259
260 if ( d->sendDocLnks && d->serverGui ) { 260 if ( d->sendDocLnks && d->serverGui ) {
261 d->serverGui->documentScanningProgress( 0 ); 261 d->serverGui->documentScanningProgress( 0 );
262 d->serverGui->allDocumentsRemoved(); 262 d->serverGui->allDocumentsRemoved();
263 } 263 }
264 264
265 rescan(); 265 rescan();
266} 266}
267 267
268void DocumentList::linkChanged( QString arg ) 268void DocumentList::linkChanged( QString arg )
269{ 269{
270 //qDebug( "linkchanged( %s )", arg.latin1() ); 270 //qDebug( "linkchanged( %s )", arg.latin1() );
271 271
272 if ( arg.isNull() || Opie::Global::isAppLnkFileName( arg ) ) { 272 if ( arg.isNull() || Opie::Global::isAppLnkFileName( arg ) ) {
273 reloadAppLnks(); 273 reloadAppLnks();
274 } else { 274 } else {
275 275
276 const QList<DocLnk> &list = d->dls.children(); 276 const QList<DocLnk> &list = d->dls.children();
277 QListIterator<DocLnk> it( list ); 277 QListIterator<DocLnk> it( list );
278 while ( it.current() ) { 278 while ( it.current() ) {
279 DocLnk *doc = it.current(); 279 DocLnk *doc = it.current();
280 ++it; 280 ++it;
281 if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) 281 if ( ( doc->linkFileKnown() && doc->linkFile() == arg )
282 || ( doc->fileKnown() && doc->file() == arg ) ) { 282 || ( doc->fileKnown() && doc->file() == arg ) ) {
283 //qDebug( "found old link" ); 283 //qDebug( "found old link" );
284 DocLnk* dl = new DocLnk( arg ); 284 DocLnk* dl = new DocLnk( arg );
285 // add new one if it exists and matches the mimetype 285 // add new one if it exists and matches the mimetype
286 if ( d->store( dl ) ) { 286 if ( d->store( dl ) ) {
287 // Existing link has been changed, send old link ref and a ref 287 // Existing link has been changed, send old link ref and a ref
288 // to the new link 288 // to the new link
289 //qDebug( "change case" ); 289 //qDebug( "change case" );
290 if ( d->serverGui ) 290 if ( d->serverGui )
291 d->serverGui->documentChanged( *doc, *dl ); 291 d->serverGui->documentChanged( *doc, *dl );
292 292
293 } else { 293 } else {
294 // Link has been removed or doesn't match the mimetypes any more 294 // Link has been removed or doesn't match the mimetypes any more
295 // so we aren't interested in it, so take it away from the list 295 // so we aren't interested in it, so take it away from the list
296 //qDebug( "removal case" ); 296 //qDebug( "removal case" );
297 if ( d->serverGui ) 297 if ( d->serverGui )
298 d->serverGui->documentRemoved( *doc ); 298 d->serverGui->documentRemoved( *doc );
299 299
300 } 300 }
301 d->dls.remove( doc ); // remove old link from docLnkSet 301 d->dls.remove( doc ); // remove old link from docLnkSet
302 delete doc; 302 delete doc;
303 return; 303 return;
304 } 304 }
305 } 305 }
306 // Didn't find existing link, must be new 306 // Didn't find existing link, must be new
307 DocLnk* dl = new DocLnk( arg ); 307 DocLnk* dl = new DocLnk( arg );
308 if ( d->store( dl ) ) { 308 if ( d->store( dl ) ) {
309 // Add if it's a link we are interested in 309 // Add if it's a link we are interested in
310 //qDebug( "add case" ); 310 //qDebug( "add case" );
311 add( *dl ); 311 add( *dl );
312 } 312 }
313 313
314 } 314 }
315} 315}
316 316
317void DocumentList::restoreDone() 317void DocumentList::restoreDone()
318{ 318{
319 reloadAppLnks(); 319 reloadAppLnks();
320 reloadDocLnks(); 320 reloadDocLnks();
321} 321}
322 322
323void DocumentList::storageChanged() 323void DocumentList::storageChanged()
324{ 324{
325 // ### can implement better 325 // ### can implement better
326 reloadAppLnks(); 326 reloadAppLnks();
327 reloadDocLnks(); 327 reloadDocLnks();
328 // ### Optimization opportunity 328 // ### Optimization opportunity
329 // Could be a bit more intelligent and somehow work out which 329 // Could be a bit more intelligent and somehow work out which
330 // mtab entry has changed and then only scan that and add and remove 330 // mtab entry has changed and then only scan that and add and remove
331 // links appropriately. 331 // links appropriately.
332// rescan(); 332// rescan();
333} 333}
334 334
335void DocumentList::sendAllDocLinks() 335void DocumentList::sendAllDocLinks()
336{ 336{
337 if ( d->tid != 0 ) { 337 if ( d->tid != 0 ) {
338 // We are in the middle of scanning, set a flag so 338 // We are in the middle of scanning, set a flag so