Diffstat (limited to 'core/launcher/documentlist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/documentlist.cpp | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp index 3e0a96c..92b8c25 100644 --- a/core/launcher/documentlist.cpp +++ b/core/launcher/documentlist.cpp | |||
@@ -1,74 +1,76 @@ | |||
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 "mediadlg.h" | 22 | #include "mediadlg.h" |
23 | 23 | ||
24 | /* OPIE */ | ||
24 | #include <opie2/oglobal.h> | 25 | #include <opie2/oglobal.h> |
25 | 26 | #include <opie2/odebug.h> | |
26 | #include <qtopia/config.h> | 27 | #include <qtopia/config.h> |
27 | #include <qtopia/mimetype.h> | 28 | #include <qtopia/mimetype.h> |
28 | #include <qtopia/resource.h> | 29 | #include <qtopia/resource.h> |
29 | #include <qtopia/private/categories.h> | 30 | #include <qtopia/private/categories.h> |
30 | #include <qtopia/qpeapplication.h> | 31 | #include <qtopia/qpeapplication.h> |
31 | #include <qtopia/applnk.h> | 32 | #include <qtopia/applnk.h> |
32 | #include <qtopia/storage.h> | 33 | #include <qtopia/storage.h> |
33 | #ifdef Q_WS_QWS | 34 | #ifdef Q_WS_QWS |
34 | #include <qtopia/qcopenvelope_qws.h> | 35 | #include <qtopia/qcopenvelope_qws.h> |
35 | #endif | 36 | #endif |
37 | using namespace Opie::Core; | ||
36 | 38 | ||
39 | /* QT */ | ||
37 | #include <qtimer.h> | 40 | #include <qtimer.h> |
38 | #include <qfileinfo.h> | 41 | #include <qfileinfo.h> |
39 | #include <qtextstream.h> | 42 | #include <qtextstream.h> |
40 | #include <qfile.h> | 43 | #include <qfile.h> |
41 | #include <qdir.h> | 44 | #include <qdir.h> |
42 | #include <qpainter.h> | 45 | #include <qpainter.h> |
43 | #include <qimage.h> | 46 | #include <qimage.h> |
44 | #include <qcopchannel_qws.h> | 47 | #include <qcopchannel_qws.h> |
45 | #include <qlistview.h> | 48 | #include <qlistview.h> |
46 | #include <qlist.h> | 49 | #include <qlist.h> |
47 | #include <qpixmap.h> | 50 | #include <qpixmap.h> |
48 | 51 | ||
49 | 52 | ||
50 | using namespace Opie::Core; | ||
51 | AppLnkSet *DocumentList::appLnkSet = 0; | 53 | AppLnkSet *DocumentList::appLnkSet = 0; |
52 | 54 | ||
53 | static const int MAX_SEARCH_DEPTH = 10; | 55 | static const int MAX_SEARCH_DEPTH = 10; |
54 | 56 | ||
55 | 57 | ||
56 | class DocumentListPrivate : public QObject { | 58 | class DocumentListPrivate : public QObject { |
57 | Q_OBJECT | 59 | Q_OBJECT |
58 | public: | 60 | public: |
59 | DocumentListPrivate( ServerInterface *gui ); | 61 | DocumentListPrivate( ServerInterface *gui ); |
60 | ~DocumentListPrivate(); | 62 | ~DocumentListPrivate(); |
61 | 63 | ||
62 | void initialize(); | 64 | void initialize(); |
63 | 65 | ||
64 | const QString nextFile(); | 66 | const QString nextFile(); |
65 | const DocLnk *iterate(); | 67 | const DocLnk *iterate(); |
66 | bool store( DocLnk* dl ); | 68 | bool store( DocLnk* dl ); |
67 | void estimatedPercentScanned(); | 69 | void estimatedPercentScanned(); |
68 | void appendDocpath(FileSystem*); | 70 | void appendDocpath(FileSystem*); |
69 | 71 | ||
70 | 72 | ||
71 | DocLnkSet dls; | 73 | DocLnkSet dls; |
72 | QDict<void> reference; | 74 | QDict<void> reference; |
73 | QDictIterator<void> *dit; | 75 | QDictIterator<void> *dit; |
74 | enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; | 76 | enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; |
@@ -87,118 +89,118 @@ public: | |||
87 | 89 | ||
88 | ServerInterface *serverGui; | 90 | ServerInterface *serverGui; |
89 | 91 | ||
90 | bool needToSendAllDocLinks; | 92 | bool needToSendAllDocLinks; |
91 | bool sendAppLnks; | 93 | bool sendAppLnks; |
92 | bool sendDocLnks; | 94 | bool sendDocLnks; |
93 | bool scanDocs; | 95 | bool scanDocs; |
94 | }; | 96 | }; |
95 | 97 | ||
96 | 98 | ||
97 | /* | 99 | /* |
98 | * scandocs will be read from Config | 100 | * scandocs will be read from Config |
99 | */ | 101 | */ |
100 | DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, | 102 | DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, |
101 | QObject *parent, const char *name ) | 103 | QObject *parent, const char *name ) |
102 | : QObject( parent, name ) | 104 | : QObject( parent, name ) |
103 | { | 105 | { |
104 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); | 106 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); |
105 | d = new DocumentListPrivate( serverGui ); | 107 | d = new DocumentListPrivate( serverGui ); |
106 | d->needToSendAllDocLinks = false; | 108 | d->needToSendAllDocLinks = false; |
107 | 109 | ||
108 | Config cfg( "Launcher" ); | 110 | Config cfg( "Launcher" ); |
109 | cfg.setGroup( "DocTab" ); | 111 | cfg.setGroup( "DocTab" ); |
110 | d->scanDocs = cfg.readBoolEntry( "Enable", true ); | 112 | d->scanDocs = cfg.readBoolEntry( "Enable", true ); |
111 | qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs ); | 113 | odebug << "DocumentList::DocumentList() : scanDocs = " << d->scanDocs << "" << oendl; |
112 | 114 | ||
113 | QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); | 115 | QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); |
114 | } | 116 | } |
115 | 117 | ||
116 | void DocumentList::startInitialScan() | 118 | void DocumentList::startInitialScan() |
117 | { | 119 | { |
118 | reloadAppLnks(); | 120 | reloadAppLnks(); |
119 | reloadDocLnks(); | 121 | reloadDocLnks(); |
120 | } | 122 | } |
121 | 123 | ||
122 | DocumentList::~DocumentList() | 124 | DocumentList::~DocumentList() |
123 | { | 125 | { |
124 | delete appLnkSet; | 126 | delete appLnkSet; |
125 | delete d; | 127 | delete d; |
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
129 | void DocumentList::add( const DocLnk& doc ) | 131 | void DocumentList::add( const DocLnk& doc ) |
130 | { | 132 | { |
131 | if ( d->serverGui && QFile::exists( doc.file() ) ) | 133 | if ( d->serverGui && QFile::exists( doc.file() ) ) |
132 | d->serverGui->documentAdded( doc ); | 134 | d->serverGui->documentAdded( doc ); |
133 | } | 135 | } |
134 | 136 | ||
135 | 137 | ||
136 | void DocumentList::start() | 138 | void DocumentList::start() |
137 | { | 139 | { |
138 | resume(); | 140 | resume(); |
139 | } | 141 | } |
140 | 142 | ||
141 | 143 | ||
142 | void DocumentList::pause() | 144 | void DocumentList::pause() |
143 | { | 145 | { |
144 | //qDebug("pause %i", d->tid); | 146 | //odebug << "pause " << d->tid << "" << oendl; |
145 | killTimer( d->tid ); | 147 | killTimer( d->tid ); |
146 | d->tid = 0; | 148 | d->tid = 0; |
147 | } | 149 | } |
148 | 150 | ||
149 | 151 | ||
150 | void DocumentList::resume() | 152 | void DocumentList::resume() |
151 | { | 153 | { |
152 | if ( d->tid == 0 ) { | 154 | if ( d->tid == 0 ) { |
153 | d->tid = startTimer( 20 ); | 155 | d->tid = startTimer( 20 ); |
154 | //qDebug("resumed %i", d->tid); | 156 | //odebug << "resumed " << d->tid << "" << oendl; |
155 | } | 157 | } |
156 | } | 158 | } |
157 | 159 | ||
158 | /* | 160 | /* |
159 | void DocumentList::resend() | 161 | void DocumentList::resend() |
160 | { | 162 | { |
161 | // Re-emits all the added items to the list (firstly letting everyone know to | 163 | // Re-emits all the added items to the list (firstly letting everyone know to |
162 | // clear what they have as it is being sent again) | 164 | // clear what they have as it is being sent again) |
163 | pause(); | 165 | pause(); |
164 | emit allRemoved(); | 166 | emit allRemoved(); |
165 | QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); | 167 | QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); |
166 | } | 168 | } |
167 | 169 | ||
168 | 170 | ||
169 | void DocumentList::resendWorker() | 171 | void DocumentList::resendWorker() |
170 | { | 172 | { |
171 | const QList<DocLnk> &list = d->dls.children(); | 173 | const QList<DocLnk> &list = d->dls.children(); |
172 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) | 174 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) |
173 | add( *(*it) ); | 175 | add( *(*it) ); |
174 | resume(); | 176 | resume(); |
175 | } | 177 | } |
176 | */ | 178 | */ |
177 | 179 | ||
178 | void DocumentList::rescan() | 180 | void DocumentList::rescan() |
179 | { | 181 | { |
180 | //qDebug("rescan"); | 182 | //odebug << "rescan" << oendl; |
181 | pause(); | 183 | pause(); |
182 | d->initialize(); | 184 | d->initialize(); |
183 | resume(); | 185 | resume(); |
184 | } | 186 | } |
185 | 187 | ||
186 | 188 | ||
187 | void DocumentList::timerEvent( QTimerEvent *te ) | 189 | void DocumentList::timerEvent( QTimerEvent *te ) |
188 | { | 190 | { |
189 | if ( te->timerId() == d->tid ) { | 191 | if ( te->timerId() == d->tid ) { |
190 | // Do 3 at a time | 192 | // Do 3 at a time |
191 | for (int i = 0; i < 3; i++ ) { | 193 | for (int i = 0; i < 3; i++ ) { |
192 | const DocLnk *lnk = d->iterate(); | 194 | const DocLnk *lnk = d->iterate(); |
193 | if ( lnk ) { | 195 | if ( lnk ) { |
194 | add( *lnk ); | 196 | add( *lnk ); |
195 | } else { | 197 | } else { |
196 | // stop when done | 198 | // stop when done |
197 | pause(); | 199 | pause(); |
198 | if ( d->serverGui ) | 200 | if ( d->serverGui ) |
199 | d->serverGui->documentScanningProgress( 100 ); | 201 | d->serverGui->documentScanningProgress( 100 ); |
200 | if ( d->needToSendAllDocLinks ) | 202 | if ( d->needToSendAllDocLinks ) |
201 | sendAllDocLinks(); | 203 | sendAllDocLinks(); |
202 | break; | 204 | break; |
203 | } | 205 | } |
204 | } | 206 | } |
@@ -211,131 +213,131 @@ void DocumentList::reloadAppLnks() | |||
211 | if ( d->sendAppLnks && d->serverGui ) { | 213 | if ( d->sendAppLnks && d->serverGui ) { |
212 | d->serverGui->applicationScanningProgress( 0 ); | 214 | d->serverGui->applicationScanningProgress( 0 ); |
213 | d->serverGui->allApplicationsRemoved(); | 215 | d->serverGui->allApplicationsRemoved(); |
214 | } | 216 | } |
215 | 217 | ||
216 | delete appLnkSet; | 218 | delete appLnkSet; |
217 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); | 219 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); |
218 | 220 | ||
219 | if ( d->sendAppLnks && d->serverGui ) { | 221 | if ( d->sendAppLnks && d->serverGui ) { |
220 | static QStringList prevTypeList; | 222 | static QStringList prevTypeList; |
221 | QStringList types = appLnkSet->types(); | 223 | QStringList types = appLnkSet->types(); |
222 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { | 224 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { |
223 | if ( !(*ittypes).isEmpty() ) { | 225 | if ( !(*ittypes).isEmpty() ) { |
224 | if ( !prevTypeList.contains(*ittypes) ) { | 226 | if ( !prevTypeList.contains(*ittypes) ) { |
225 | QString name = appLnkSet->typeName(*ittypes); | 227 | QString name = appLnkSet->typeName(*ittypes); |
226 | QPixmap pm = appLnkSet->typePixmap(*ittypes); | 228 | QPixmap pm = appLnkSet->typePixmap(*ittypes); |
227 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); | 229 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); |
228 | 230 | ||
229 | if (pm.isNull()) { | 231 | if (pm.isNull()) { |
230 | QImage img( Resource::loadImage( "UnknownDocument" ) ); | 232 | QImage img( Resource::loadImage( "UnknownDocument" ) ); |
231 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 233 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
232 | bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); | 234 | bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); |
233 | } | 235 | } |
234 | 236 | ||
235 | //qDebug("adding type %s", (*ittypes).latin1()); | 237 | //odebug << "adding type " << (*ittypes) << "" << oendl; |
236 | 238 | ||
237 | // ### our current launcher expects docs tab to be last | 239 | // ### our current launcher expects docs tab to be last |
238 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); | 240 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); |
239 | } | 241 | } |
240 | prevTypeList.remove(*ittypes); | 242 | prevTypeList.remove(*ittypes); |
241 | } | 243 | } |
242 | } | 244 | } |
243 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { | 245 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { |
244 | //qDebug("removing type %s", (*ittypes).latin1()); | 246 | //odebug << "removing type " << (*ittypes) << "" << oendl; |
245 | d->serverGui->typeRemoved(*ittypes); | 247 | d->serverGui->typeRemoved(*ittypes); |
246 | } | 248 | } |
247 | prevTypeList = types; | 249 | prevTypeList = types; |
248 | } | 250 | } |
249 | 251 | ||
250 | QListIterator<AppLnk> itapp( appLnkSet->children() ); | 252 | QListIterator<AppLnk> itapp( appLnkSet->children() ); |
251 | AppLnk* l; | 253 | AppLnk* l; |
252 | while ( (l=itapp.current()) ) { | 254 | while ( (l=itapp.current()) ) { |
253 | ++itapp; | 255 | ++itapp; |
254 | if ( d->sendAppLnks && d->serverGui ) | 256 | if ( d->sendAppLnks && d->serverGui ) |
255 | d->serverGui->applicationAdded( l->type(), *l ); | 257 | d->serverGui->applicationAdded( l->type(), *l ); |
256 | } | 258 | } |
257 | 259 | ||
258 | if ( d->sendAppLnks && d->serverGui ) | 260 | if ( d->sendAppLnks && d->serverGui ) |
259 | d->serverGui->applicationScanningProgress( 100 ); | 261 | d->serverGui->applicationScanningProgress( 100 ); |
260 | } | 262 | } |
261 | 263 | ||
262 | void DocumentList::reloadDocLnks() | 264 | void DocumentList::reloadDocLnks() |
263 | { | 265 | { |
264 | if ( !d->scanDocs ) | 266 | if ( !d->scanDocs ) |
265 | return; | 267 | return; |
266 | 268 | ||
267 | if ( d->sendDocLnks && d->serverGui ) { | 269 | if ( d->sendDocLnks && d->serverGui ) { |
268 | d->serverGui->documentScanningProgress( 0 ); | 270 | d->serverGui->documentScanningProgress( 0 ); |
269 | d->serverGui->allDocumentsRemoved(); | 271 | d->serverGui->allDocumentsRemoved(); |
270 | } | 272 | } |
271 | 273 | ||
272 | rescan(); | 274 | rescan(); |
273 | } | 275 | } |
274 | 276 | ||
275 | void DocumentList::linkChanged( QString arg ) | 277 | void DocumentList::linkChanged( QString arg ) |
276 | { | 278 | { |
277 | //qDebug( "linkchanged( %s )", arg.latin1() ); | 279 | //odebug << "linkchanged( " << arg << " )" << oendl; |
278 | 280 | ||
279 | if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { | 281 | if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { |
280 | reloadAppLnks(); | 282 | reloadAppLnks(); |
281 | } else { | 283 | } else { |
282 | 284 | ||
283 | const QList<DocLnk> &list = d->dls.children(); | 285 | const QList<DocLnk> &list = d->dls.children(); |
284 | QListIterator<DocLnk> it( list ); | 286 | QListIterator<DocLnk> it( list ); |
285 | while ( it.current() ) { | 287 | while ( it.current() ) { |
286 | DocLnk *doc = it.current(); | 288 | DocLnk *doc = it.current(); |
287 | ++it; | 289 | ++it; |
288 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) | 290 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) |
289 | || ( doc->fileKnown() && doc->file() == arg ) ) { | 291 | || ( doc->fileKnown() && doc->file() == arg ) ) { |
290 | //qDebug( "found old link" ); | 292 | //odebug << "found old link" << oendl; |
291 | DocLnk* dl = new DocLnk( arg ); | 293 | DocLnk* dl = new DocLnk( arg ); |
292 | // add new one if it exists and matches the mimetype | 294 | // add new one if it exists and matches the mimetype |
293 | if ( d->store( dl ) ) { | 295 | if ( d->store( dl ) ) { |
294 | // 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 |
295 | // to the new link | 297 | // to the new link |
296 | //qDebug( "change case" ); | 298 | //odebug << "change case" << oendl; |
297 | if ( d->serverGui ) | 299 | if ( d->serverGui ) |
298 | d->serverGui->documentChanged( *doc, *dl ); | 300 | d->serverGui->documentChanged( *doc, *dl ); |
299 | 301 | ||
300 | } else { | 302 | } else { |
301 | // 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 |
302 | // 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 |
303 | //qDebug( "removal case" ); | 305 | //odebug << "removal case" << oendl; |
304 | if ( d->serverGui ) | 306 | if ( d->serverGui ) |
305 | d->serverGui->documentRemoved( *doc ); | 307 | d->serverGui->documentRemoved( *doc ); |
306 | 308 | ||
307 | } | 309 | } |
308 | d->dls.remove( doc ); // remove old link from docLnkSet | 310 | d->dls.remove( doc ); // remove old link from docLnkSet |
309 | delete doc; | 311 | delete doc; |
310 | return; | 312 | return; |
311 | } | 313 | } |
312 | } | 314 | } |
313 | // Didn't find existing link, must be new | 315 | // Didn't find existing link, must be new |
314 | DocLnk* dl = new DocLnk( arg ); | 316 | DocLnk* dl = new DocLnk( arg ); |
315 | if ( d->store( dl ) ) { | 317 | if ( d->store( dl ) ) { |
316 | // Add if it's a link we are interested in | 318 | // Add if it's a link we are interested in |
317 | //qDebug( "add case" ); | 319 | //odebug << "add case" << oendl; |
318 | add( *dl ); | 320 | add( *dl ); |
319 | } | 321 | } |
320 | 322 | ||
321 | } | 323 | } |
322 | } | 324 | } |
323 | 325 | ||
324 | void DocumentList::restoreDone() | 326 | void DocumentList::restoreDone() |
325 | { | 327 | { |
326 | reloadAppLnks(); | 328 | reloadAppLnks(); |
327 | reloadDocLnks(); | 329 | reloadDocLnks(); |
328 | } | 330 | } |
329 | 331 | ||
330 | void DocumentList::storageChanged() | 332 | void DocumentList::storageChanged() |
331 | { | 333 | { |
332 | // ### can implement better | 334 | // ### can implement better |
333 | reloadAppLnks(); | 335 | reloadAppLnks(); |
334 | reloadDocLnks(); | 336 | reloadDocLnks(); |
335 | // ### Optimization opportunity | 337 | // ### Optimization opportunity |
336 | // Could be a bit more intelligent and somehow work out which | 338 | // Could be a bit more intelligent and somehow work out which |
337 | // mtab entry has changed and then only scan that and add and remove | 339 | // mtab entry has changed and then only scan that and add and remove |
338 | // links appropriately. | 340 | // links appropriately. |
339 | // rescan(); | 341 | // rescan(); |
340 | } | 342 | } |
341 | 343 | ||
@@ -357,54 +359,54 @@ void DocumentList::sendAllDocLinks() | |||
357 | continue; | 359 | continue; |
358 | 360 | ||
359 | bool fake = !doc->linkFileKnown(); | 361 | bool fake = !doc->linkFileKnown(); |
360 | if ( !fake ) { | 362 | if ( !fake ) { |
361 | QFile f( doc->linkFile() ); | 363 | QFile f( doc->linkFile() ); |
362 | if ( f.open( IO_ReadOnly ) ) { | 364 | if ( f.open( IO_ReadOnly ) ) { |
363 | QTextStream ts( &f ); | 365 | QTextStream ts( &f ); |
364 | ts.setEncoding( QTextStream::UnicodeUTF8 ); | 366 | ts.setEncoding( QTextStream::UnicodeUTF8 ); |
365 | contents += ts.read(); | 367 | contents += ts.read(); |
366 | f.close(); | 368 | f.close(); |
367 | } else | 369 | } else |
368 | fake = TRUE; | 370 | fake = TRUE; |
369 | } | 371 | } |
370 | if (fake) { | 372 | if (fake) { |
371 | contents += "[Desktop Entry]\n"; // No tr | 373 | contents += "[Desktop Entry]\n"; // No tr |
372 | contents += "Categories = " + // No tr | 374 | contents += "Categories = " + // No tr |
373 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr | 375 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr |
374 | contents += "Name = "+doc->name()+"\n"; // No tr | 376 | contents += "Name = "+doc->name()+"\n"; // No tr |
375 | contents += "Type = "+doc->type()+"\n"; // No tr | 377 | contents += "Type = "+doc->type()+"\n"; // No tr |
376 | } | 378 | } |
377 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) | 379 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) |
378 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr | 380 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr |
379 | } | 381 | } |
380 | 382 | ||
381 | //qDebug( "sending length %d", contents.length() ); | 383 | //odebug << "sending length " << contents.length() << "" << oendl; |
382 | #ifndef QT_NO_COP | 384 | #ifndef QT_NO_COP |
383 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); | 385 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); |
384 | e << contents; | 386 | e << contents; |
385 | #endif | 387 | #endif |
386 | //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); | 388 | //odebug << "================ \n\n" << contents << "\n\n===============" << oendl; |
387 | 389 | ||
388 | d->needToSendAllDocLinks = false; | 390 | d->needToSendAllDocLinks = false; |
389 | } | 391 | } |
390 | 392 | ||
391 | 393 | ||
392 | 394 | ||
393 | 395 | ||
394 | 396 | ||
395 | 397 | ||
396 | 398 | ||
397 | 399 | ||
398 | 400 | ||
399 | 401 | ||
400 | 402 | ||
401 | 403 | ||
402 | 404 | ||
403 | 405 | ||
404 | 406 | ||
405 | 407 | ||
406 | 408 | ||
407 | 409 | ||
408 | 410 | ||
409 | 411 | ||
410 | 412 | ||
@@ -515,184 +517,184 @@ DocumentListPrivate::~DocumentListPrivate() | |||
515 | void DocumentListPrivate::estimatedPercentScanned() | 517 | void DocumentListPrivate::estimatedPercentScanned() |
516 | { | 518 | { |
517 | double overallProgress = 0.0; | 519 | double overallProgress = 0.0; |
518 | double levelWeight = 75.0; | 520 | double levelWeight = 75.0; |
519 | 521 | ||
520 | int topCount = docPaths.count(); | 522 | int topCount = docPaths.count(); |
521 | if ( topCount > 1 ) { | 523 | if ( topCount > 1 ) { |
522 | levelWeight = levelWeight / topCount; | 524 | levelWeight = levelWeight / topCount; |
523 | overallProgress += (docPathsSearched - 1) * levelWeight; | 525 | overallProgress += (docPathsSearched - 1) * levelWeight; |
524 | } | 526 | } |
525 | 527 | ||
526 | for ( int d = 0; d <= searchDepth; d++ ) { | 528 | for ( int d = 0; d <= searchDepth; d++ ) { |
527 | if ( listDirs[d] ) { | 529 | if ( listDirs[d] ) { |
528 | int items = lists[d]->count(); | 530 | int items = lists[d]->count(); |
529 | if ( items > 1 ) { | 531 | if ( items > 1 ) { |
530 | levelWeight = levelWeight / items; | 532 | levelWeight = levelWeight / items; |
531 | // Take in to account "." and ".." | 533 | // Take in to account "." and ".." |
532 | overallProgress += (listPositions[d] - 3) * levelWeight; | 534 | overallProgress += (listPositions[d] - 3) * levelWeight; |
533 | } | 535 | } |
534 | } else { | 536 | } else { |
535 | break; | 537 | break; |
536 | } | 538 | } |
537 | } | 539 | } |
538 | 540 | ||
539 | // qDebug( "overallProgress: %f", overallProgress ); | 541 | // odebug << "overallProgress: " << overallProgress << "" << oendl; |
540 | 542 | ||
541 | if ( serverGui ) | 543 | if ( serverGui ) |
542 | serverGui->documentScanningProgress( (int)overallProgress ); | 544 | serverGui->documentScanningProgress( (int)overallProgress ); |
543 | } | 545 | } |
544 | 546 | ||
545 | 547 | ||
546 | const QString DocumentListPrivate::nextFile() | 548 | const QString DocumentListPrivate::nextFile() |
547 | { | 549 | { |
548 | while ( TRUE ) { | 550 | while ( TRUE ) { |
549 | while ( searchDepth < 0 ) { | 551 | while ( searchDepth < 0 ) { |
550 | // go to next base path | 552 | // go to next base path |
551 | if ( docPathsSearched >= docPaths.count() ) { | 553 | if ( docPathsSearched >= docPaths.count() ) { |
552 | // end of base paths | 554 | // end of base paths |
553 | return QString::null; | 555 | return QString::null; |
554 | } else { | 556 | } else { |
555 | QDir dir( docPaths[docPathsSearched] ); | 557 | QDir dir( docPaths[docPathsSearched] ); |
556 | // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); | 558 | // odebug << "now using base path: " << docPaths[docPathsSearched] << "" << oendl; |
557 | docPathsSearched++; | 559 | docPathsSearched++; |
558 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 560 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
559 | listDirs[0] = new QDir( dir ); | 561 | listDirs[0] = new QDir( dir ); |
560 | lists[0] = listDirs[0]->entryInfoList(); | 562 | lists[0] = listDirs[0]->entryInfoList(); |
561 | listPositions[0] = 0; | 563 | listPositions[0] = 0; |
562 | searchDepth = 0; | 564 | searchDepth = 0; |
563 | } | 565 | } |
564 | } | 566 | } |
565 | } | 567 | } |
566 | 568 | ||
567 | const QFileInfoList *fil = lists[searchDepth]; | 569 | const QFileInfoList *fil = lists[searchDepth]; |
568 | if (!fil) { | 570 | if (!fil) { |
569 | return QString::null; | 571 | return QString::null; |
570 | } | 572 | } |
571 | QFileInfoList *fl = (QFileInfoList *)fil; | 573 | QFileInfoList *fl = (QFileInfoList *)fil; |
572 | unsigned int pos = listPositions[searchDepth]; | 574 | unsigned int pos = listPositions[searchDepth]; |
573 | 575 | ||
574 | if ( pos >= fl->count() ) { | 576 | if ( pos >= fl->count() ) { |
575 | // go up a depth | 577 | // go up a depth |
576 | delete listDirs[searchDepth]; | 578 | delete listDirs[searchDepth]; |
577 | listDirs[searchDepth] = 0; | 579 | listDirs[searchDepth] = 0; |
578 | lists[searchDepth] = 0; | 580 | lists[searchDepth] = 0; |
579 | listPositions[searchDepth] = 0; | 581 | listPositions[searchDepth] = 0; |
580 | searchDepth--; | 582 | searchDepth--; |
581 | } else { | 583 | } else { |
582 | const QFileInfo *fi = fl->at(pos); | 584 | const QFileInfo *fi = fl->at(pos); |
583 | listPositions[searchDepth]++; | 585 | listPositions[searchDepth]++; |
584 | QString bn = fi->fileName(); | 586 | QString bn = fi->fileName(); |
585 | if ( bn[0] != '.' ) { | 587 | if ( bn[0] != '.' ) { |
586 | if ( fi->isDir() ) { | 588 | if ( fi->isDir() ) { |
587 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { | 589 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { |
588 | // go down a depth | 590 | // go down a depth |
589 | QDir dir( fi->filePath() ); | 591 | QDir dir( fi->filePath() ); |
590 | // qDebug("now going in to path: %s", bn.latin1() ); | 592 | // odebug << "now going in to path: " << bn << "" << oendl; |
591 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 593 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
592 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { | 594 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { |
593 | searchDepth++; | 595 | searchDepth++; |
594 | listDirs[searchDepth] = new QDir( dir ); | 596 | listDirs[searchDepth] = new QDir( dir ); |
595 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); | 597 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); |
596 | listPositions[searchDepth] = 0; | 598 | listPositions[searchDepth] = 0; |
597 | } | 599 | } |
598 | } | 600 | } |
599 | } | 601 | } |
600 | } else { | 602 | } else { |
601 | estimatedPercentScanned(); | 603 | estimatedPercentScanned(); |
602 | return fl->at(pos)->filePath(); | 604 | return fl->at(pos)->filePath(); |
603 | } | 605 | } |
604 | } | 606 | } |
605 | } | 607 | } |
606 | } | 608 | } |
607 | 609 | ||
608 | return QString::null; | 610 | return QString::null; |
609 | } | 611 | } |
610 | 612 | ||
611 | 613 | ||
612 | bool DocumentListPrivate::store( DocLnk* dl ) | 614 | bool DocumentListPrivate::store( DocLnk* dl ) |
613 | { | 615 | { |
614 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { | 616 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { |
615 | if ( dl && dl->fileKnown() ) { | 617 | if ( dl && dl->fileKnown() ) { |
616 | dls.add( dl ); // store | 618 | dls.add( dl ); // store |
617 | return TRUE; | 619 | return TRUE; |
618 | } | 620 | } |
619 | 621 | ||
620 | // don't store - delete | 622 | // don't store - delete |
621 | delete dl; | 623 | delete dl; |
622 | return FALSE; | 624 | return FALSE; |
623 | } | 625 | } |
624 | 626 | ||
625 | 627 | ||
626 | #define MAGIC_NUMBER((void*)2) | 628 | #define MAGIC_NUMBER((void*)2) |
627 | 629 | ||
628 | const DocLnk *DocumentListPrivate::iterate() | 630 | const DocLnk *DocumentListPrivate::iterate() |
629 | { | 631 | { |
630 | if ( state == Find ) { | 632 | if ( state == Find ) { |
631 | //qDebug("state Find"); | 633 | //odebug << "state Find" << oendl; |
632 | QString file = nextFile(); | 634 | QString file = nextFile(); |
633 | while ( !file.isNull() ) { | 635 | while ( !file.isNull() ) { |
634 | if ( file.right(8) == ".desktop" ) { // No tr | 636 | if ( file.right(8) == ".desktop" ) { // No tr |
635 | DocLnk* dl = new DocLnk( file ); | 637 | DocLnk* dl = new DocLnk( file ); |
636 | if ( store(dl) ) | 638 | if ( store(dl) ) |
637 | return dl; | 639 | return dl; |
638 | } else { | 640 | } else { |
639 | reference.insert( file, MAGIC_NUMBER ); | 641 | reference.insert( file, MAGIC_NUMBER ); |
640 | } | 642 | } |
641 | file = nextFile(); | 643 | file = nextFile(); |
642 | } | 644 | } |
643 | state = RemoveKnownFiles; | 645 | state = RemoveKnownFiles; |
644 | 646 | ||
645 | if ( serverGui ) | 647 | if ( serverGui ) |
646 | serverGui->documentScanningProgress( 75 ); | 648 | serverGui->documentScanningProgress( 75 ); |
647 | } | 649 | } |
648 | 650 | ||
649 | static int iterationI; | 651 | static int iterationI; |
650 | static int iterationCount; | 652 | static int iterationCount; |
651 | 653 | ||
652 | if ( state == RemoveKnownFiles ) { | 654 | if ( state == RemoveKnownFiles ) { |
653 | //qDebug("state RemoveKnownFiles"); | 655 | //odebug << "state RemoveKnownFiles" << oendl; |
654 | const QList<DocLnk> &list = dls.children(); | 656 | const QList<DocLnk> &list = dls.children(); |
655 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 657 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
656 | reference.remove( (*it)->file() ); | 658 | reference.remove( (*it)->file() ); |
657 | // ### does this need to be deleted? | 659 | // ### does this need to be deleted? |
658 | } | 660 | } |
659 | dit = new QDictIterator<void>(reference); | 661 | dit = new QDictIterator<void>(reference); |
660 | state = MakeUnknownFiles; | 662 | state = MakeUnknownFiles; |
661 | 663 | ||
662 | iterationI = 0; | 664 | iterationI = 0; |
663 | iterationCount = dit->count(); | 665 | iterationCount = dit->count(); |
664 | } | 666 | } |
665 | 667 | ||
666 | if ( state == MakeUnknownFiles ) { | 668 | if ( state == MakeUnknownFiles ) { |
667 | //qDebug("state MakeUnknownFiles"); | 669 | //odebug << "state MakeUnknownFiles" << oendl; |
668 | for (void* c; (c=dit->current()); ++(*dit) ) { | 670 | for (void* c; (c=dit->current()); ++(*dit) ) { |
669 | if ( c == MAGIC_NUMBER ) { | 671 | if ( c == MAGIC_NUMBER ) { |
670 | DocLnk* dl = new DocLnk; | 672 | DocLnk* dl = new DocLnk; |
671 | QFileInfo fi( dit->currentKey() ); | 673 | QFileInfo fi( dit->currentKey() ); |
672 | dl->setFile( fi.filePath() ); | 674 | dl->setFile( fi.filePath() ); |
673 | dl->setName( fi.baseName() ); | 675 | dl->setName( fi.baseName() ); |
674 | if ( store(dl) ) { | 676 | if ( store(dl) ) { |
675 | ++*dit; | 677 | ++*dit; |
676 | iterationI++; | 678 | iterationI++; |
677 | if ( serverGui ) | 679 | if ( serverGui ) |
678 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); | 680 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); |
679 | return dl; | 681 | return dl; |
680 | } | 682 | } |
681 | } | 683 | } |
682 | iterationI++; | 684 | iterationI++; |
683 | } | 685 | } |
684 | 686 | ||
685 | delete dit; | 687 | delete dit; |
686 | dit = 0; | 688 | dit = 0; |
687 | state = Done; | 689 | state = Done; |
688 | } | 690 | } |
689 | 691 | ||
690 | //qDebug("state Done"); | 692 | //odebug << "state Done" << oendl; |
691 | return NULL; | 693 | return NULL; |
692 | } | 694 | } |
693 | 695 | ||
694 | 696 | ||
695 | #include "documentlist.moc" | 697 | #include "documentlist.moc" |
696 | 698 | ||
697 | 699 | ||
698 | 700 | ||