-rw-r--r-- | core/launcher/documentlist.cpp | 2 |
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,652 +1,652 @@ | |||
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 | ||
49 | AppLnkSet *DocumentList::appLnkSet = 0; | 49 | AppLnkSet *DocumentList::appLnkSet = 0; |
50 | 50 | ||
51 | static const int MAX_SEARCH_DEPTH = 10; | 51 | static const int MAX_SEARCH_DEPTH = 10; |
52 | 52 | ||
53 | 53 | ||
54 | class DocumentListPrivate : public QObject { | 54 | class DocumentListPrivate : public QObject { |
55 | Q_OBJECT | 55 | Q_OBJECT |
56 | public: | 56 | public: |
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 | ||
93 | DocumentList::DocumentList( ServerInterface *serverGui, bool scanDocs, | 93 | DocumentList::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 | ||
109 | void DocumentList::startInitialScan() | 109 | void DocumentList::startInitialScan() |
110 | { | 110 | { |
111 | reloadAppLnks(); | 111 | reloadAppLnks(); |
112 | reloadDocLnks(); | 112 | reloadDocLnks(); |
113 | } | 113 | } |
114 | 114 | ||
115 | DocumentList::~DocumentList() | 115 | DocumentList::~DocumentList() |
116 | { | 116 | { |
117 | delete appLnkSet; | 117 | delete appLnkSet; |
118 | delete d; | 118 | delete d; |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | void DocumentList::add( const DocLnk& doc ) | 122 | void 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 | ||
129 | void DocumentList::start() | 129 | void DocumentList::start() |
130 | { | 130 | { |
131 | resume(); | 131 | resume(); |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | void DocumentList::pause() | 135 | void 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 | ||
143 | void DocumentList::resume() | 143 | void 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 | /* |
152 | void DocumentList::resend() | 152 | void 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 | ||
162 | void DocumentList::resendWorker() | 162 | void 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 | ||
171 | void DocumentList::rescan() | 171 | void 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 | ||
180 | void DocumentList::timerEvent( QTimerEvent *te ) | 180 | void 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 | ||
202 | void DocumentList::reloadAppLnks() | 202 | void 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 | ||
255 | void DocumentList::reloadDocLnks() | 255 | void 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 | ||
268 | void DocumentList::linkChanged( QString arg ) | 268 | void 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 | ||
317 | void DocumentList::restoreDone() | 317 | void DocumentList::restoreDone() |
318 | { | 318 | { |
319 | reloadAppLnks(); | 319 | reloadAppLnks(); |
320 | reloadDocLnks(); | 320 | reloadDocLnks(); |
321 | } | 321 | } |
322 | 322 | ||
323 | void DocumentList::storageChanged() | 323 | void 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 | ||
335 | void DocumentList::sendAllDocLinks() | 335 | void 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 |
339 | // we do this when we finish our scanning | 339 | // we do this when we finish our scanning |
340 | d->needToSendAllDocLinks = true; | 340 | d->needToSendAllDocLinks = true; |
341 | return; | 341 | return; |
342 | } | 342 | } |
343 | 343 | ||
344 | QString contents; | 344 | QString contents; |
345 | Categories cats; | 345 | Categories cats; |
346 | for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { | 346 | for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { |
347 | DocLnk *doc = it.current(); | 347 | DocLnk *doc = it.current(); |
348 | QFileInfo fi( doc->file() ); | 348 | QFileInfo fi( doc->file() ); |
349 | if ( !fi.exists() ) | 349 | if ( !fi.exists() ) |
350 | continue; | 350 | continue; |
351 | 351 | ||
352 | bool fake = !doc->linkFileKnown(); | 352 | bool fake = !doc->linkFileKnown(); |
353 | if ( !fake ) { | 353 | if ( !fake ) { |
354 | QFile f( doc->linkFile() ); | 354 | QFile f( doc->linkFile() ); |
355 | if ( f.open( IO_ReadOnly ) ) { | 355 | if ( f.open( IO_ReadOnly ) ) { |
356 | QTextStream ts( &f ); | 356 | QTextStream ts( &f ); |
357 | ts.setEncoding( QTextStream::UnicodeUTF8 ); | 357 | ts.setEncoding( QTextStream::UnicodeUTF8 ); |
358 | contents += ts.read(); | 358 | contents += ts.read(); |
359 | f.close(); | 359 | f.close(); |
360 | } else | 360 | } else |
361 | fake = TRUE; | 361 | fake = TRUE; |
362 | } | 362 | } |
363 | if (fake) { | 363 | if (fake) { |
364 | contents += "[Desktop Entry]\n"; // No tr | 364 | contents += "[Desktop Entry]\n"; // No tr |
365 | contents += "Categories = " + // No tr | 365 | contents += "Categories = " + // No tr |
366 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr | 366 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr |
367 | contents += "Name = "+doc->name()+"\n"; // No tr | 367 | contents += "Name = "+doc->name()+"\n"; // No tr |
368 | contents += "Type = "+doc->type()+"\n"; // No tr | 368 | contents += "Type = "+doc->type()+"\n"; // No tr |
369 | } | 369 | } |
370 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) | 370 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) |
371 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr | 371 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr |
372 | } | 372 | } |
373 | 373 | ||
374 | //qDebug( "sending length %d", contents.length() ); | 374 | //qDebug( "sending length %d", contents.length() ); |
375 | #ifndef QT_NO_COP | 375 | #ifndef QT_NO_COP |
376 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); | 376 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); |
377 | e << contents; | 377 | e << contents; |
378 | #endif | 378 | #endif |
379 | //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); | 379 | //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); |
380 | 380 | ||
381 | d->needToSendAllDocLinks = false; | 381 | d->needToSendAllDocLinks = false; |
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | 385 | ||
386 | 386 | ||
387 | 387 | ||
388 | 388 | ||
389 | 389 | ||
390 | 390 | ||
391 | 391 | ||
392 | 392 | ||
393 | 393 | ||
394 | 394 | ||
395 | 395 | ||
396 | 396 | ||
397 | 397 | ||
398 | 398 | ||
399 | 399 | ||
400 | 400 | ||
401 | 401 | ||
402 | 402 | ||
403 | 403 | ||
404 | 404 | ||
405 | 405 | ||
406 | 406 | ||
407 | DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) | 407 | DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) |
408 | { | 408 | { |
409 | storage = new StorageInfo( this ); | 409 | storage = new StorageInfo( this ); |
410 | serverGui = gui; | 410 | serverGui = gui; |
411 | if ( serverGui ) { | 411 | if ( serverGui ) { |
412 | sendAppLnks = serverGui->requiresApplications(); | 412 | sendAppLnks = serverGui->requiresApplications(); |
413 | sendDocLnks = serverGui->requiresDocuments(); | 413 | sendDocLnks = serverGui->requiresDocuments(); |
414 | } else { | 414 | } else { |
415 | sendAppLnks = false; | 415 | sendAppLnks = false; |
416 | sendDocLnks = false; | 416 | sendDocLnks = false; |
417 | } | 417 | } |
418 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { | 418 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { |
419 | listDirs[i] = 0; | 419 | listDirs[i] = 0; |
420 | lists[i] = 0; | 420 | lists[i] = 0; |
421 | listPositions[i] = 0; | 421 | listPositions[i] = 0; |
422 | } | 422 | } |
423 | initialize(); | 423 | initialize(); |
424 | tid = 0; | 424 | tid = 0; |
425 | } | 425 | } |
426 | 426 | ||
427 | 427 | ||
428 | void DocumentListPrivate::initialize() | 428 | void DocumentListPrivate::initialize() |
429 | { | 429 | { |
430 | // Reset | 430 | // Reset |
431 | dls.clear(); | 431 | dls.clear(); |
432 | docPaths.clear(); | 432 | docPaths.clear(); |
433 | reference.clear(); | 433 | reference.clear(); |
434 | 434 | ||
435 | QDir docDir( QPEApplication::documentDir() ); | 435 | QDir docDir( QPEApplication::documentDir() ); |
436 | if ( docDir.exists() ) | 436 | if ( docDir.exists() ) |
437 | docPaths += QPEApplication::documentDir(); | 437 | docPaths += QPEApplication::documentDir(); |
438 | int i = 1; | 438 | int i = 1; |
439 | const QList<FileSystem> &fs = storage->fileSystems(); | 439 | const QList<FileSystem> &fs = storage->fileSystems(); |
440 | QListIterator<FileSystem> it( fs ); | 440 | QListIterator<FileSystem> it( fs ); |
441 | for ( ; it.current(); ++it ) | 441 | for ( ; it.current(); ++it ) |
442 | if ( (*it)->isRemovable() ) { | 442 | if ( (*it)->isRemovable() ) { |
443 | docPaths += (*it)->path(); | 443 | docPaths += (*it)->path(); |
444 | i++; | 444 | i++; |
445 | } | 445 | } |
446 | 446 | ||
447 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { | 447 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { |
448 | if ( listDirs[i] ) { | 448 | if ( listDirs[i] ) { |
449 | delete listDirs[i]; | 449 | delete listDirs[i]; |
450 | listDirs[i] = 0; | 450 | listDirs[i] = 0; |
451 | } | 451 | } |
452 | lists[i] = 0; | 452 | lists[i] = 0; |
453 | listPositions[i] = 0; | 453 | listPositions[i] = 0; |
454 | } | 454 | } |
455 | 455 | ||
456 | docPathsSearched = 0; | 456 | docPathsSearched = 0; |
457 | searchDepth = -1; | 457 | searchDepth = -1; |
458 | state = Find; | 458 | state = Find; |
459 | dit = 0; | 459 | dit = 0; |
460 | } | 460 | } |
461 | 461 | ||
462 | 462 | ||
463 | DocumentListPrivate::~DocumentListPrivate() | 463 | DocumentListPrivate::~DocumentListPrivate() |
464 | { | 464 | { |
465 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) | 465 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) |
466 | if ( listDirs[i] ) | 466 | if ( listDirs[i] ) |
467 | delete listDirs[i]; | 467 | delete listDirs[i]; |
468 | delete dit; | 468 | delete dit; |
469 | } | 469 | } |
470 | 470 | ||
471 | 471 | ||
472 | void DocumentListPrivate::estimatedPercentScanned() | 472 | void DocumentListPrivate::estimatedPercentScanned() |
473 | { | 473 | { |
474 | double overallProgress = 0.0; | 474 | double overallProgress = 0.0; |
475 | double levelWeight = 75.0; | 475 | double levelWeight = 75.0; |
476 | 476 | ||
477 | int topCount = docPaths.count(); | 477 | int topCount = docPaths.count(); |
478 | if ( topCount > 1 ) { | 478 | if ( topCount > 1 ) { |
479 | levelWeight = levelWeight / topCount; | 479 | levelWeight = levelWeight / topCount; |
480 | overallProgress += (docPathsSearched - 1) * levelWeight; | 480 | overallProgress += (docPathsSearched - 1) * levelWeight; |
481 | } | 481 | } |
482 | 482 | ||
483 | for ( int d = 0; d <= searchDepth; d++ ) { | 483 | for ( int d = 0; d <= searchDepth; d++ ) { |
484 | if ( listDirs[d] ) { | 484 | if ( listDirs[d] ) { |
485 | int items = lists[d]->count(); | 485 | int items = lists[d]->count(); |
486 | if ( items > 1 ) { | 486 | if ( items > 1 ) { |
487 | levelWeight = levelWeight / items; | 487 | levelWeight = levelWeight / items; |
488 | // Take in to account "." and ".." | 488 | // Take in to account "." and ".." |
489 | overallProgress += (listPositions[d] - 3) * levelWeight; | 489 | overallProgress += (listPositions[d] - 3) * levelWeight; |
490 | } | 490 | } |
491 | } else { | 491 | } else { |
492 | break; | 492 | break; |
493 | } | 493 | } |
494 | } | 494 | } |
495 | 495 | ||
496 | // qDebug( "overallProgress: %f", overallProgress ); | 496 | // qDebug( "overallProgress: %f", overallProgress ); |
497 | 497 | ||
498 | if ( serverGui ) | 498 | if ( serverGui ) |
499 | serverGui->documentScanningProgress( (int)overallProgress ); | 499 | serverGui->documentScanningProgress( (int)overallProgress ); |
500 | } | 500 | } |
501 | 501 | ||
502 | 502 | ||
503 | const QString DocumentListPrivate::nextFile() | 503 | const QString DocumentListPrivate::nextFile() |
504 | { | 504 | { |
505 | while ( TRUE ) { | 505 | while ( TRUE ) { |
506 | while ( searchDepth < 0 ) { | 506 | while ( searchDepth < 0 ) { |
507 | // go to next base path | 507 | // go to next base path |
508 | if ( docPathsSearched >= docPaths.count() ) { | 508 | if ( docPathsSearched >= docPaths.count() ) { |
509 | // end of base paths | 509 | // end of base paths |
510 | return QString::null; | 510 | return QString::null; |
511 | } else { | 511 | } else { |
512 | QDir dir( docPaths[docPathsSearched] ); | 512 | QDir dir( docPaths[docPathsSearched] ); |
513 | // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); | 513 | // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); |
514 | docPathsSearched++; | 514 | docPathsSearched++; |
515 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 515 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
516 | listDirs[0] = new QDir( dir ); | 516 | listDirs[0] = new QDir( dir ); |
517 | lists[0] = listDirs[0]->entryInfoList(); | 517 | lists[0] = listDirs[0]->entryInfoList(); |
518 | listPositions[0] = 0; | 518 | listPositions[0] = 0; |
519 | searchDepth = 0; | 519 | searchDepth = 0; |
520 | } | 520 | } |
521 | } | 521 | } |
522 | } | 522 | } |
523 | 523 | ||
524 | const QFileInfoList *fil = lists[searchDepth]; | 524 | const QFileInfoList *fil = lists[searchDepth]; |
525 | QFileInfoList *fl = (QFileInfoList *)fil; | 525 | QFileInfoList *fl = (QFileInfoList *)fil; |
526 | unsigned int pos = listPositions[searchDepth]; | 526 | unsigned int pos = listPositions[searchDepth]; |
527 | 527 | ||
528 | if ( pos >= fl->count() ) { | 528 | if ( pos >= fl->count() ) { |
529 | // go up a depth | 529 | // go up a depth |
530 | delete listDirs[searchDepth]; | 530 | delete listDirs[searchDepth]; |
531 | listDirs[searchDepth] = 0; | 531 | listDirs[searchDepth] = 0; |
532 | lists[searchDepth] = 0; | 532 | lists[searchDepth] = 0; |
533 | listPositions[searchDepth] = 0; | 533 | listPositions[searchDepth] = 0; |
534 | searchDepth--; | 534 | searchDepth--; |
535 | } else { | 535 | } else { |
536 | const QFileInfo *fi = fl->at(pos); | 536 | const QFileInfo *fi = fl->at(pos); |
537 | listPositions[searchDepth]++; | 537 | listPositions[searchDepth]++; |
538 | QString bn = fi->fileName(); | 538 | QString bn = fi->fileName(); |
539 | if ( bn[0] != '.' ) { | 539 | if ( bn[0] != '.' ) { |
540 | if ( fi->isDir() ) { | 540 | if ( fi->isDir() ) { |
541 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { | 541 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { |
542 | // go down a depth | 542 | // go down a depth |
543 | QDir dir( fi->filePath() ); | 543 | QDir dir( fi->filePath() ); |
544 | // qDebug("now going in to path: %s", bn.latin1() ); | 544 | // qDebug("now going in to path: %s", bn.latin1() ); |
545 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 545 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
546 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { | 546 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { |
547 | searchDepth++; | 547 | searchDepth++; |
548 | listDirs[searchDepth] = new QDir( dir ); | 548 | listDirs[searchDepth] = new QDir( dir ); |
549 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); | 549 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); |
550 | listPositions[searchDepth] = 0; | 550 | listPositions[searchDepth] = 0; |
551 | } | 551 | } |
552 | } | 552 | } |
553 | } | 553 | } |
554 | } else { | 554 | } else { |
555 | estimatedPercentScanned(); | 555 | estimatedPercentScanned(); |
556 | return fl->at(pos)->filePath(); | 556 | return fl->at(pos)->filePath(); |
557 | } | 557 | } |
558 | } | 558 | } |
559 | } | 559 | } |
560 | } | 560 | } |
561 | 561 | ||
562 | return QString::null; | 562 | return QString::null; |
563 | } | 563 | } |
564 | 564 | ||
565 | 565 | ||
566 | bool DocumentListPrivate::store( DocLnk* dl ) | 566 | bool DocumentListPrivate::store( DocLnk* dl ) |
567 | { | 567 | { |
568 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { | 568 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { |
569 | if ( dl && dl->fileKnown() ) { | 569 | if ( dl && dl->fileKnown() ) { |
570 | dls.add( dl ); // store | 570 | dls.add( dl ); // store |
571 | return TRUE; | 571 | return TRUE; |
572 | } | 572 | } |
573 | 573 | ||
574 | // don't store - delete | 574 | // don't store - delete |
575 | delete dl; | 575 | delete dl; |
576 | return FALSE; | 576 | return FALSE; |
577 | } | 577 | } |
578 | 578 | ||
579 | 579 | ||
580 | #define MAGIC_NUMBER((void*)2) | 580 | #define MAGIC_NUMBER((void*)2) |
581 | 581 | ||
582 | const DocLnk *DocumentListPrivate::iterate() | 582 | const DocLnk *DocumentListPrivate::iterate() |
583 | { | 583 | { |
584 | if ( state == Find ) { | 584 | if ( state == Find ) { |
585 | //qDebug("state Find"); | 585 | //qDebug("state Find"); |
586 | QString file = nextFile(); | 586 | QString file = nextFile(); |
587 | while ( !file.isNull() ) { | 587 | while ( !file.isNull() ) { |
588 | if ( file.right(8) == ".desktop" ) { // No tr | 588 | if ( file.right(8) == ".desktop" ) { // No tr |
589 | DocLnk* dl = new DocLnk( file ); | 589 | DocLnk* dl = new DocLnk( file ); |
590 | if ( store(dl) ) | 590 | if ( store(dl) ) |
591 | return dl; | 591 | return dl; |
592 | } else { | 592 | } else { |
593 | reference.insert( file, MAGIC_NUMBER ); | 593 | reference.insert( file, MAGIC_NUMBER ); |
594 | } | 594 | } |
595 | file = nextFile(); | 595 | file = nextFile(); |
596 | } | 596 | } |
597 | state = RemoveKnownFiles; | 597 | state = RemoveKnownFiles; |
598 | 598 | ||
599 | if ( serverGui ) | 599 | if ( serverGui ) |
600 | serverGui->documentScanningProgress( 75 ); | 600 | serverGui->documentScanningProgress( 75 ); |
601 | } | 601 | } |
602 | 602 | ||
603 | static int iterationI; | 603 | static int iterationI; |
604 | static int iterationCount; | 604 | static int iterationCount; |
605 | 605 | ||
606 | if ( state == RemoveKnownFiles ) { | 606 | if ( state == RemoveKnownFiles ) { |
607 | //qDebug("state RemoveKnownFiles"); | 607 | //qDebug("state RemoveKnownFiles"); |
608 | const QList<DocLnk> &list = dls.children(); | 608 | const QList<DocLnk> &list = dls.children(); |
609 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 609 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
610 | reference.remove( (*it)->file() ); | 610 | reference.remove( (*it)->file() ); |
611 | // ### does this need to be deleted? | 611 | // ### does this need to be deleted? |
612 | } | 612 | } |
613 | dit = new QDictIterator<void>(reference); | 613 | dit = new QDictIterator<void>(reference); |
614 | state = MakeUnknownFiles; | 614 | state = MakeUnknownFiles; |
615 | 615 | ||
616 | iterationI = 0; | 616 | iterationI = 0; |
617 | iterationCount = dit->count(); | 617 | iterationCount = dit->count(); |
618 | } | 618 | } |
619 | 619 | ||
620 | if ( state == MakeUnknownFiles ) { | 620 | if ( state == MakeUnknownFiles ) { |
621 | //qDebug("state MakeUnknownFiles"); | 621 | //qDebug("state MakeUnknownFiles"); |
622 | for (void* c; (c=dit->current()); ++(*dit) ) { | 622 | for (void* c; (c=dit->current()); ++(*dit) ) { |
623 | if ( c == MAGIC_NUMBER ) { | 623 | if ( c == MAGIC_NUMBER ) { |
624 | DocLnk* dl = new DocLnk; | 624 | DocLnk* dl = new DocLnk; |
625 | QFileInfo fi( dit->currentKey() ); | 625 | QFileInfo fi( dit->currentKey() ); |
626 | dl->setFile( fi.filePath() ); | 626 | dl->setFile( fi.filePath() ); |
627 | dl->setName( fi.baseName() ); | 627 | dl->setName( fi.baseName() ); |
628 | if ( store(dl) ) { | 628 | if ( store(dl) ) { |
629 | ++*dit; | 629 | ++*dit; |
630 | iterationI++; | 630 | iterationI++; |
631 | if ( serverGui ) | 631 | if ( serverGui ) |
632 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); | 632 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); |
633 | return dl; | 633 | return dl; |
634 | } | 634 | } |
635 | } | 635 | } |
636 | iterationI++; | 636 | iterationI++; |
637 | } | 637 | } |
638 | 638 | ||
639 | delete dit; | 639 | delete dit; |
640 | dit = 0; | 640 | dit = 0; |
641 | state = Done; | 641 | state = Done; |
642 | } | 642 | } |
643 | 643 | ||
644 | //qDebug("state Done"); | 644 | //qDebug("state Done"); |
645 | return NULL; | 645 | return NULL; |
646 | } | 646 | } |
647 | 647 | ||
648 | 648 | ||
649 | #include "documentlist.moc" | 649 | #include "documentlist.moc" |
650 | 650 | ||
651 | 651 | ||
652 | 652 | ||