summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp92
-rw-r--r--core/launcher/documentlist.h1
2 files changed, 91 insertions, 2 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index 92b8c25..59dd721 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -236,198 +236,286 @@ void DocumentList::reloadAppLnks()
236 236
237 //odebug << "adding type " << (*ittypes) << "" << oendl; 237 //odebug << "adding type " << (*ittypes) << "" << oendl;
238 238
239 // ### our current launcher expects docs tab to be last 239 // ### our current launcher expects docs tab to be last
240 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); 240 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
241 } 241 }
242 prevTypeList.remove(*ittypes); 242 prevTypeList.remove(*ittypes);
243 } 243 }
244 } 244 }
245 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { 245 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) {
246 //odebug << "removing type " << (*ittypes) << "" << oendl; 246 //odebug << "removing type " << (*ittypes) << "" << oendl;
247 d->serverGui->typeRemoved(*ittypes); 247 d->serverGui->typeRemoved(*ittypes);
248 } 248 }
249 prevTypeList = types; 249 prevTypeList = types;
250 } 250 }
251 251
252 QListIterator<AppLnk> itapp( appLnkSet->children() ); 252 QListIterator<AppLnk> itapp( appLnkSet->children() );
253 AppLnk* l; 253 AppLnk* l;
254 while ( (l=itapp.current()) ) { 254 while ( (l=itapp.current()) ) {
255 ++itapp; 255 ++itapp;
256 if ( d->sendAppLnks && d->serverGui ) 256 if ( d->sendAppLnks && d->serverGui )
257 d->serverGui->applicationAdded( l->type(), *l ); 257 d->serverGui->applicationAdded( l->type(), *l );
258 } 258 }
259 259
260 if ( d->sendAppLnks && d->serverGui ) 260 if ( d->sendAppLnks && d->serverGui )
261 d->serverGui->applicationScanningProgress( 100 ); 261 d->serverGui->applicationScanningProgress( 100 );
262} 262}
263 263
264void DocumentList::reloadDocLnks() 264void DocumentList::reloadDocLnks()
265{ 265{
266 if ( !d->scanDocs ) 266 if ( !d->scanDocs )
267 return; 267 return;
268 268
269 if ( d->sendDocLnks && d->serverGui ) { 269 if ( d->sendDocLnks && d->serverGui ) {
270 d->serverGui->documentScanningProgress( 0 ); 270 d->serverGui->documentScanningProgress( 0 );
271 d->serverGui->allDocumentsRemoved(); 271 d->serverGui->allDocumentsRemoved();
272 } 272 }
273 273
274 rescan(); 274 rescan();
275} 275}
276 276
277void DocumentList::linkChanged( QString arg ) 277void DocumentList::linkChanged( QString arg )
278{ 278{
279 //odebug << "linkchanged( " << arg << " )" << oendl; 279 //odebug << "linkchanged( " << arg << " )" << oendl;
280 280
281 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { 281 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) {
282 reloadAppLnks(); 282 reloadAppLnks();
283 } else { 283 } else {
284 284
285 const QList<DocLnk> &list = d->dls.children(); 285 const QList<DocLnk> &list = d->dls.children();
286 QListIterator<DocLnk> it( list ); 286 QListIterator<DocLnk> it( list );
287 while ( it.current() ) { 287 while ( it.current() ) {
288 DocLnk *doc = it.current(); 288 DocLnk *doc = it.current();
289 ++it; 289 ++it;
290 if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) 290 if ( ( doc->linkFileKnown() && doc->linkFile() == arg )
291 || ( doc->fileKnown() && doc->file() == arg ) ) { 291 || ( doc->fileKnown() && doc->file() == arg ) ) {
292 //odebug << "found old link" << oendl; 292 //odebug << "found old link" << oendl;
293 DocLnk* dl = new DocLnk( arg ); 293 DocLnk* dl = new DocLnk( arg );
294 // add new one if it exists and matches the mimetype 294 // add new one if it exists and matches the mimetype
295 if ( d->store( dl ) ) { 295 if ( d->store( dl ) ) {
296 // Existing link has been changed, send old link ref and a ref 296 // Existing link has been changed, send old link ref and a ref
297 // to the new link 297 // to the new link
298 //odebug << "change case" << oendl; 298 //odebug << "change case" << oendl;
299 if ( d->serverGui ) 299 if ( d->serverGui )
300 d->serverGui->documentChanged( *doc, *dl ); 300 d->serverGui->documentChanged( *doc, *dl );
301 301
302 } else { 302 } else {
303 // Link has been removed or doesn't match the mimetypes any more 303 // Link has been removed or doesn't match the mimetypes any more
304 // so we aren't interested in it, so take it away from the list 304 // so we aren't interested in it, so take it away from the list
305 //odebug << "removal case" << oendl; 305 //odebug << "removal case" << oendl;
306 if ( d->serverGui ) 306 if ( d->serverGui )
307 d->serverGui->documentRemoved( *doc ); 307 d->serverGui->documentRemoved( *doc );
308 308
309 } 309 }
310 d->dls.remove( doc ); // remove old link from docLnkSet 310 d->dls.remove( doc ); // remove old link from docLnkSet
311 delete doc; 311 delete doc;
312 return; 312 return;
313 } 313 }
314 } 314 }
315 // Didn't find existing link, must be new 315 // Didn't find existing link, must be new
316 DocLnk* dl = new DocLnk( arg ); 316 DocLnk* dl = new DocLnk( arg );
317 if ( d->store( dl ) ) { 317 if ( d->store( dl ) ) {
318 // Add if it's a link we are interested in 318 // Add if it's a link we are interested in
319 //odebug << "add case" << oendl; 319 //odebug << "add case" << oendl;
320 add( *dl ); 320 add( *dl );
321 } 321 }
322 322
323 } 323 }
324} 324}
325 325
326void DocumentList::restoreDone() 326void DocumentList::restoreDone()
327{ 327{
328 reloadAppLnks(); 328 reloadAppLnks();
329 reloadDocLnks(); 329 reloadDocLnks();
330} 330}
331 331
332void DocumentList::DiffAppLnks()
333{
334 static AppLnkSet *appLnkSet2;
335
336 appLnkSet2 = new AppLnkSet( MimeType::appsFolderName() );
337
338 if ( d->sendAppLnks && d->serverGui ) {
339 static QStringList prevTypeList = appLnkSet->types();
340 QStringList types = appLnkSet2->types();
341 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
342 if ( !(*ittypes).isEmpty() ) {
343 if ( !prevTypeList.contains(*ittypes) ) {
344 QString name = appLnkSet2->typeName(*ittypes);
345 QPixmap pm = appLnkSet2->typePixmap(*ittypes);
346 QPixmap bgPm = appLnkSet2->typeBigPixmap(*ittypes);
347
348 if (pm.isNull()) {
349 QImage img( Resource::loadImage( "UnknownDocument" ) );
350 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
351 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() );
352 }
353
354 odebug << "adding type " << (*ittypes) << "" << oendl;
355
356 // ### our current launcher expects docs tab to be last
357 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
358 }
359 prevTypeList.remove(*ittypes);
360 }
361 }
362 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) {
363 odebug << "removing type " << (*ittypes) << "" << oendl;
364 d->serverGui->typeRemoved(*ittypes);
365 }
366 prevTypeList = types;
367 }
368
369
370 QListIterator<AppLnk> it1( appLnkSet->children() );
371 QListIterator<AppLnk> it2( appLnkSet2->children() );
372
373 AppLnk *i;
374 AppLnk *j;
375 bool found;
376
377 while ( (j=it2.current()) ) {
378 it1 = appLnkSet->children();
379 found = false;
380 while ( (i=it1.current()) ){
381 if (strcmp(i->name().ascii(),j->name().ascii()) == 0)
382 found = true;
383 ++it1;
384 }
385 if (!found) {
386 qDebug("Item %s needs to be added",j->name().ascii() );
387 d->serverGui->applicationAdded( j->type(), *j );
388 }
389 ++it2;
390 }
391
392 it1 = appLnkSet->children();
393 while ( (i=it1.current()) ) {
394 it2 = appLnkSet2->children();
395 found = false;
396 while ( (j=it2.current()) ){
397 if (strcmp(i->name().ascii(),j->name().ascii()) == 0)
398 found = true;
399 ++it2;
400 }
401 if (!found) {
402 qDebug("Item %s needs to be removed",i->name().ascii() );
403 d->serverGui->applicationRemoved( i->type(), *i );
404 }
405
406 ++it1;
407 }
408
409 delete appLnkSet;
410 appLnkSet = appLnkSet2;
411
412}
332void DocumentList::storageChanged() 413void DocumentList::storageChanged()
333{ 414{
415 QTime t;
334 // ### can implement better 416 // ### can implement better
335 reloadAppLnks(); 417
418 t.start();
419 DiffAppLnks();
420// reloadAppLnks();
421 qDebug("Reload App links took %i ms",t.elapsed() );
336 reloadDocLnks(); 422 reloadDocLnks();
337 // ### Optimization opportunity 423// odebug << "Reload links took " << t.elapsed() << " ms " << oendl;
424 qDebug("Reload All links took %i ms",t.elapsed() );
425// ### Optimization opportunity
338 // Could be a bit more intelligent and somehow work out which 426 // Could be a bit more intelligent and somehow work out which
339 // mtab entry has changed and then only scan that and add and remove 427 // mtab entry has changed and then only scan that and add and remove
340 // links appropriately. 428 // links appropriately.
341// rescan(); 429// rescan();
342} 430}
343 431
344void DocumentList::sendAllDocLinks() 432void DocumentList::sendAllDocLinks()
345{ 433{
346 if ( d->tid != 0 ) { 434 if ( d->tid != 0 ) {
347 // We are in the middle of scanning, set a flag so 435 // We are in the middle of scanning, set a flag so
348 // we do this when we finish our scanning 436 // we do this when we finish our scanning
349 d->needToSendAllDocLinks = true; 437 d->needToSendAllDocLinks = true;
350 return; 438 return;
351 } 439 }
352 440
353 QString contents; 441 QString contents;
354 Categories cats; 442 Categories cats;
355 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { 443 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) {
356 DocLnk *doc = it.current(); 444 DocLnk *doc = it.current();
357 QFileInfo fi( doc->file() ); 445 QFileInfo fi( doc->file() );
358 if ( !fi.exists() ) 446 if ( !fi.exists() )
359 continue; 447 continue;
360 448
361 bool fake = !doc->linkFileKnown(); 449 bool fake = !doc->linkFileKnown();
362 if ( !fake ) { 450 if ( !fake ) {
363 QFile f( doc->linkFile() ); 451 QFile f( doc->linkFile() );
364 if ( f.open( IO_ReadOnly ) ) { 452 if ( f.open( IO_ReadOnly ) ) {
365 QTextStream ts( &f ); 453 QTextStream ts( &f );
366 ts.setEncoding( QTextStream::UnicodeUTF8 ); 454 ts.setEncoding( QTextStream::UnicodeUTF8 );
367 contents += ts.read(); 455 contents += ts.read();
368 f.close(); 456 f.close();
369 } else 457 } else
370 fake = TRUE; 458 fake = TRUE;
371 } 459 }
372 if (fake) { 460 if (fake) {
373 contents += "[Desktop Entry]\n"; // No tr 461 contents += "[Desktop Entry]\n"; // No tr
374 contents += "Categories = " + // No tr 462 contents += "Categories = " + // No tr
375 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr 463 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr
376 contents += "Name = "+doc->name()+"\n"; // No tr 464 contents += "Name = "+doc->name()+"\n"; // No tr
377 contents += "Type = "+doc->type()+"\n"; // No tr 465 contents += "Type = "+doc->type()+"\n"; // No tr
378 } 466 }
379 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) 467 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
380 contents += QString("Size = %1\n").arg( fi.size() ); // No tr 468 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
381 } 469 }
382 470
383 //odebug << "sending length " << contents.length() << "" << oendl; 471 //odebug << "sending length " << contents.length() << "" << oendl;
384#ifndef QT_NO_COP 472#ifndef QT_NO_COP
385 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); 473 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
386 e << contents; 474 e << contents;
387#endif 475#endif
388 //odebug << "================ \n\n" << contents << "\n\n===============" << oendl; 476 //odebug << "================ \n\n" << contents << "\n\n===============" << oendl;
389 477
390 d->needToSendAllDocLinks = false; 478 d->needToSendAllDocLinks = false;
391} 479}
392 480
393 481
394 482
395 483
396 484
397 485
398 486
399 487
400 488
401 489
402 490
403 491
404 492
405 493
406 494
407 495
408 496
409 497
410 498
411 499
412 500
413 501
414 502
415 503
416DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) 504DocumentListPrivate::DocumentListPrivate( ServerInterface *gui )
417{ 505{
418 storage = new StorageInfo( this ); 506 storage = new StorageInfo( this );
419 serverGui = gui; 507 serverGui = gui;
420 if ( serverGui ) { 508 if ( serverGui ) {
421 sendAppLnks = serverGui->requiresApplications(); 509 sendAppLnks = serverGui->requiresApplications();
422 sendDocLnks = serverGui->requiresDocuments(); 510 sendDocLnks = serverGui->requiresDocuments();
423 } else { 511 } else {
424 sendAppLnks = false; 512 sendAppLnks = false;
425 sendDocLnks = false; 513 sendDocLnks = false;
426 } 514 }
427 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { 515 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) {
428 listDirs[i] = 0; 516 listDirs[i] = 0;
429 lists[i] = 0; 517 lists[i] = 0;
430 listPositions[i] = 0; 518 listPositions[i] = 0;
431 } 519 }
432 initialize(); 520 initialize();
433 tid = 0; 521 tid = 0;
diff --git a/core/launcher/documentlist.h b/core/launcher/documentlist.h
index bd5c031..232bb6a 100644
--- a/core/launcher/documentlist.h
+++ b/core/launcher/documentlist.h
@@ -1,77 +1,78 @@
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#ifndef DOCUMENT_LIST_H 20#ifndef DOCUMENT_LIST_H
21#define DOCUMENT_LIST_H 21#define DOCUMENT_LIST_H
22 22
23 23
24#include <qobject.h> 24#include <qobject.h>
25#include <qtopia/applnk.h> 25#include <qtopia/applnk.h>
26 26
27 27
28class DocumentListPrivate; 28class DocumentListPrivate;
29class ServerInterface; 29class ServerInterface;
30 30
31class DocumentList : public QObject { 31class DocumentList : public QObject {
32 Q_OBJECT 32 Q_OBJECT
33public: 33public:
34 DocumentList( ServerInterface *serverGui, bool scanDocs = TRUE, 34 DocumentList( ServerInterface *serverGui, bool scanDocs = TRUE,
35 QObject *parent = 0, const char *name = 0 ); 35 QObject *parent = 0, const char *name = 0 );
36 ~DocumentList(); 36 ~DocumentList();
37 37
38 void linkChanged( QString link ); 38 void linkChanged( QString link );
39 void restoreDone(); 39 void restoreDone();
40 void storageChanged(); 40 void storageChanged();
41 void sendAllDocLinks(); 41 void sendAllDocLinks();
42 42
43 void reloadAppLnks(); 43 void reloadAppLnks();
44 void reloadDocLnks(); 44 void reloadDocLnks();
45 void DiffAppLnks();
45 46
46// Orig DocList stuff 47// Orig DocList stuff
47 void start(); 48 void start();
48 void pause(); 49 void pause();
49 void resume(); 50 void resume();
50 void rescan(); 51 void rescan();
51 52
52 static AppLnkSet *appLnkSet; 53 static AppLnkSet *appLnkSet;
53 54
54/* 55/*
55 void resend(); 56 void resend();
56signals: 57signals:
57 void added( const DocLnk& doc ); 58 void added( const DocLnk& doc );
58 void removed( const DocLnk& doc ); 59 void removed( const DocLnk& doc );
59 void changed( const DocLnk& oldDoc, const DocLnk& newDoc ); 60 void changed( const DocLnk& oldDoc, const DocLnk& newDoc );
60 void allRemoved(); 61 void allRemoved();
61 void doneForNow(); 62 void doneForNow();
62private slots: 63private slots:
63 void resendWorker(); 64 void resendWorker();
64*/ 65*/
65private slots: 66private slots:
66 void startInitialScan(); 67 void startInitialScan();
67protected: 68protected:
68 void timerEvent( QTimerEvent *te ); 69 void timerEvent( QTimerEvent *te );
69private: 70private:
70 void add( const DocLnk& doc ); 71 void add( const DocLnk& doc );
71 DocumentListPrivate *d; 72 DocumentListPrivate *d;
72 73
73}; 74};
74 75
75 76
76#endif 77#endif
77 78