-rw-r--r-- | core/launcher/documentlist.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp index 033dd10..7f9366e 100644 --- a/core/launcher/documentlist.cpp +++ b/core/launcher/documentlist.cpp | |||
@@ -1,646 +1,647 @@ | |||
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 | 23 | ||
23 | #include <qtopia/mimetype.h> | 24 | #include <qtopia/mimetype.h> |
24 | #include <qtopia/resource.h> | 25 | #include <qtopia/resource.h> |
25 | #include <qtopia/global.h> | 26 | #include <qtopia/global.h> |
26 | #include <qtopia/categories.h> | 27 | #include <qtopia/private/categories.h> |
27 | #include <qtopia/qpeapplication.h> | 28 | #include <qtopia/qpeapplication.h> |
28 | #include <qtopia/applnk.h> | 29 | #include <qtopia/applnk.h> |
29 | #include <qtopia/storage.h> | 30 | #include <qtopia/storage.h> |
30 | #ifdef Q_WS_QWS | 31 | #ifdef Q_WS_QWS |
31 | #include <qtopia/qcopenvelope_qws.h> | 32 | #include <qtopia/qcopenvelope_qws.h> |
32 | #endif | 33 | #endif |
33 | 34 | ||
34 | #include <qtimer.h> | 35 | #include <qtimer.h> |
35 | #include <qfileinfo.h> | 36 | #include <qfileinfo.h> |
36 | #include <qtextstream.h> | 37 | #include <qtextstream.h> |
37 | #include <qfile.h> | 38 | #include <qfile.h> |
38 | #include <qdir.h> | 39 | #include <qdir.h> |
39 | #include <qpainter.h> | 40 | #include <qpainter.h> |
40 | #include <qimage.h> | 41 | #include <qimage.h> |
41 | #include <qcopchannel_qws.h> | 42 | #include <qcopchannel_qws.h> |
42 | #include <qlistview.h> | 43 | #include <qlistview.h> |
43 | #include <qlist.h> | 44 | #include <qlist.h> |
44 | #include <qpixmap.h> | 45 | #include <qpixmap.h> |
45 | 46 | ||
46 | 47 | ||
47 | AppLnkSet *DocumentList::appLnkSet = 0; | 48 | AppLnkSet *DocumentList::appLnkSet = 0; |
48 | 49 | ||
49 | static const int MAX_SEARCH_DEPTH = 10; | 50 | static const int MAX_SEARCH_DEPTH = 10; |
50 | 51 | ||
51 | 52 | ||
52 | class DocumentListPrivate : public QObject { | 53 | class DocumentListPrivate : public QObject { |
53 | Q_OBJECT | 54 | Q_OBJECT |
54 | public: | 55 | public: |
55 | DocumentListPrivate( ServerInterface *gui ); | 56 | DocumentListPrivate( ServerInterface *gui ); |
56 | ~DocumentListPrivate(); | 57 | ~DocumentListPrivate(); |
57 | 58 | ||
58 | void initialize(); | 59 | void initialize(); |
59 | 60 | ||
60 | const QString nextFile(); | 61 | const QString nextFile(); |
61 | const DocLnk *iterate(); | 62 | const DocLnk *iterate(); |
62 | bool store( DocLnk* dl ); | 63 | bool store( DocLnk* dl ); |
63 | void estimatedPercentScanned(); | 64 | void estimatedPercentScanned(); |
64 | 65 | ||
65 | DocLnkSet dls; | 66 | DocLnkSet dls; |
66 | QDict<void> reference; | 67 | QDict<void> reference; |
67 | QDictIterator<void> *dit; | 68 | QDictIterator<void> *dit; |
68 | enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; | 69 | enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; |
69 | 70 | ||
70 | QStringList docPaths; | 71 | QStringList docPaths; |
71 | unsigned int docPathsSearched; | 72 | unsigned int docPathsSearched; |
72 | 73 | ||
73 | int searchDepth; | 74 | int searchDepth; |
74 | QDir *listDirs[MAX_SEARCH_DEPTH]; | 75 | QDir *listDirs[MAX_SEARCH_DEPTH]; |
75 | const QFileInfoList *lists[MAX_SEARCH_DEPTH]; | 76 | const QFileInfoList *lists[MAX_SEARCH_DEPTH]; |
76 | unsigned int listPositions[MAX_SEARCH_DEPTH]; | 77 | unsigned int listPositions[MAX_SEARCH_DEPTH]; |
77 | 78 | ||
78 | StorageInfo *storage; | 79 | StorageInfo *storage; |
79 | 80 | ||
80 | int tid; | 81 | int tid; |
81 | 82 | ||
82 | ServerInterface *serverGui; | 83 | ServerInterface *serverGui; |
83 | 84 | ||
84 | bool needToSendAllDocLinks; | 85 | bool needToSendAllDocLinks; |
85 | bool sendAppLnks; | 86 | bool sendAppLnks; |
86 | bool sendDocLnks; | 87 | bool sendDocLnks; |
87 | bool scanDocs; | 88 | bool scanDocs; |
88 | }; | 89 | }; |
89 | 90 | ||
90 | 91 | ||
91 | DocumentList::DocumentList( ServerInterface *serverGui, bool scanDocs, | 92 | DocumentList::DocumentList( ServerInterface *serverGui, bool scanDocs, |
92 | QObject *parent, const char *name ) | 93 | QObject *parent, const char *name ) |
93 | : QObject( parent, name ) | 94 | : QObject( parent, name ) |
94 | { | 95 | { |
95 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); | 96 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); |
96 | d = new DocumentListPrivate( serverGui ); | 97 | d = new DocumentListPrivate( serverGui ); |
97 | d->scanDocs = scanDocs; | 98 | d->scanDocs = scanDocs; |
98 | d->needToSendAllDocLinks = false; | 99 | d->needToSendAllDocLinks = false; |
99 | 100 | ||
100 | QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); | 101 | QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); |
101 | } | 102 | } |
102 | 103 | ||
103 | void DocumentList::startInitialScan() | 104 | void DocumentList::startInitialScan() |
104 | { | 105 | { |
105 | reloadAppLnks(); | 106 | reloadAppLnks(); |
106 | reloadDocLnks(); | 107 | reloadDocLnks(); |
107 | } | 108 | } |
108 | 109 | ||
109 | DocumentList::~DocumentList() | 110 | DocumentList::~DocumentList() |
110 | { | 111 | { |
111 | delete appLnkSet; | 112 | delete appLnkSet; |
112 | delete d; | 113 | delete d; |
113 | } | 114 | } |
114 | 115 | ||
115 | 116 | ||
116 | void DocumentList::add( const DocLnk& doc ) | 117 | void DocumentList::add( const DocLnk& doc ) |
117 | { | 118 | { |
118 | if ( d->serverGui && QFile::exists( doc.file() ) ) | 119 | if ( d->serverGui && QFile::exists( doc.file() ) ) |
119 | d->serverGui->documentAdded( doc ); | 120 | d->serverGui->documentAdded( doc ); |
120 | } | 121 | } |
121 | 122 | ||
122 | 123 | ||
123 | void DocumentList::start() | 124 | void DocumentList::start() |
124 | { | 125 | { |
125 | resume(); | 126 | resume(); |
126 | } | 127 | } |
127 | 128 | ||
128 | 129 | ||
129 | void DocumentList::pause() | 130 | void DocumentList::pause() |
130 | { | 131 | { |
131 | //qDebug("pause %i", d->tid); | 132 | //qDebug("pause %i", d->tid); |
132 | killTimer( d->tid ); | 133 | killTimer( d->tid ); |
133 | d->tid = 0; | 134 | d->tid = 0; |
134 | } | 135 | } |
135 | 136 | ||
136 | 137 | ||
137 | void DocumentList::resume() | 138 | void DocumentList::resume() |
138 | { | 139 | { |
139 | if ( d->tid == 0 ) { | 140 | if ( d->tid == 0 ) { |
140 | d->tid = startTimer( 0 ); | 141 | d->tid = startTimer( 0 ); |
141 | //qDebug("resumed %i", d->tid); | 142 | //qDebug("resumed %i", d->tid); |
142 | } | 143 | } |
143 | } | 144 | } |
144 | 145 | ||
145 | /* | 146 | /* |
146 | void DocumentList::resend() | 147 | void DocumentList::resend() |
147 | { | 148 | { |
148 | // Re-emits all the added items to the list (firstly letting everyone know to | 149 | // Re-emits all the added items to the list (firstly letting everyone know to |
149 | // clear what they have as it is being sent again) | 150 | // clear what they have as it is being sent again) |
150 | pause(); | 151 | pause(); |
151 | emit allRemoved(); | 152 | emit allRemoved(); |
152 | QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); | 153 | QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); |
153 | } | 154 | } |
154 | 155 | ||
155 | 156 | ||
156 | void DocumentList::resendWorker() | 157 | void DocumentList::resendWorker() |
157 | { | 158 | { |
158 | const QList<DocLnk> &list = d->dls.children(); | 159 | const QList<DocLnk> &list = d->dls.children(); |
159 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) | 160 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) |
160 | add( *(*it) ); | 161 | add( *(*it) ); |
161 | resume(); | 162 | resume(); |
162 | } | 163 | } |
163 | */ | 164 | */ |
164 | 165 | ||
165 | void DocumentList::rescan() | 166 | void DocumentList::rescan() |
166 | { | 167 | { |
167 | //qDebug("rescan"); | 168 | //qDebug("rescan"); |
168 | pause(); | 169 | pause(); |
169 | d->initialize(); | 170 | d->initialize(); |
170 | resume(); | 171 | resume(); |
171 | } | 172 | } |
172 | 173 | ||
173 | 174 | ||
174 | void DocumentList::timerEvent( QTimerEvent *te ) | 175 | void DocumentList::timerEvent( QTimerEvent *te ) |
175 | { | 176 | { |
176 | if ( te->timerId() == d->tid ) { | 177 | if ( te->timerId() == d->tid ) { |
177 | // Do 3 at a time | 178 | // Do 3 at a time |
178 | for (int i = 0; i < 3; i++ ) { | 179 | for (int i = 0; i < 3; i++ ) { |
179 | const DocLnk *lnk = d->iterate(); | 180 | const DocLnk *lnk = d->iterate(); |
180 | if ( lnk ) { | 181 | if ( lnk ) { |
181 | add( *lnk ); | 182 | add( *lnk ); |
182 | } else { | 183 | } else { |
183 | // stop when done | 184 | // stop when done |
184 | pause(); | 185 | pause(); |
185 | if ( d->serverGui ) | 186 | if ( d->serverGui ) |
186 | d->serverGui->documentScanningProgress( 100 ); | 187 | d->serverGui->documentScanningProgress( 100 ); |
187 | if ( d->needToSendAllDocLinks ) | 188 | if ( d->needToSendAllDocLinks ) |
188 | sendAllDocLinks(); | 189 | sendAllDocLinks(); |
189 | break; | 190 | break; |
190 | } | 191 | } |
191 | } | 192 | } |
192 | } | 193 | } |
193 | } | 194 | } |
194 | 195 | ||
195 | 196 | ||
196 | void DocumentList::reloadAppLnks() | 197 | void DocumentList::reloadAppLnks() |
197 | { | 198 | { |
198 | if ( d->sendAppLnks && d->serverGui ) { | 199 | if ( d->sendAppLnks && d->serverGui ) { |
199 | d->serverGui->applicationScanningProgress( 0 ); | 200 | d->serverGui->applicationScanningProgress( 0 ); |
200 | d->serverGui->allApplicationsRemoved(); | 201 | d->serverGui->allApplicationsRemoved(); |
201 | } | 202 | } |
202 | 203 | ||
203 | delete appLnkSet; | 204 | delete appLnkSet; |
204 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); | 205 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); |
205 | 206 | ||
206 | if ( d->sendAppLnks && d->serverGui ) { | 207 | if ( d->sendAppLnks && d->serverGui ) { |
207 | static QStringList prevTypeList; | 208 | static QStringList prevTypeList; |
208 | QStringList types = appLnkSet->types(); | 209 | QStringList types = appLnkSet->types(); |
209 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { | 210 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { |
210 | if ( !(*ittypes).isEmpty() ) { | 211 | if ( !(*ittypes).isEmpty() ) { |
211 | if ( !prevTypeList.contains(*ittypes) ) { | 212 | if ( !prevTypeList.contains(*ittypes) ) { |
212 | QString name = appLnkSet->typeName(*ittypes); | 213 | QString name = appLnkSet->typeName(*ittypes); |
213 | QPixmap pm = appLnkSet->typePixmap(*ittypes); | 214 | QPixmap pm = appLnkSet->typePixmap(*ittypes); |
214 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); | 215 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); |
215 | 216 | ||
216 | if (pm.isNull()) { | 217 | if (pm.isNull()) { |
217 | QImage img( Resource::loadImage( "UnknownDocument" ) ); | 218 | QImage img( Resource::loadImage( "UnknownDocument" ) ); |
218 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 219 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
219 | bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); | 220 | bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); |
220 | } | 221 | } |
221 | 222 | ||
222 | //qDebug("adding type %s", (*ittypes).latin1()); | 223 | //qDebug("adding type %s", (*ittypes).latin1()); |
223 | 224 | ||
224 | // ### our current launcher expects docs tab to be last | 225 | // ### our current launcher expects docs tab to be last |
225 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); | 226 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); |
226 | } | 227 | } |
227 | prevTypeList.remove(*ittypes); | 228 | prevTypeList.remove(*ittypes); |
228 | } | 229 | } |
229 | } | 230 | } |
230 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { | 231 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { |
231 | //qDebug("removing type %s", (*ittypes).latin1()); | 232 | //qDebug("removing type %s", (*ittypes).latin1()); |
232 | d->serverGui->typeRemoved(*ittypes); | 233 | d->serverGui->typeRemoved(*ittypes); |
233 | } | 234 | } |
234 | prevTypeList = types; | 235 | prevTypeList = types; |
235 | } | 236 | } |
236 | 237 | ||
237 | QListIterator<AppLnk> itapp( appLnkSet->children() ); | 238 | QListIterator<AppLnk> itapp( appLnkSet->children() ); |
238 | AppLnk* l; | 239 | AppLnk* l; |
239 | while ( (l=itapp.current()) ) { | 240 | while ( (l=itapp.current()) ) { |
240 | ++itapp; | 241 | ++itapp; |
241 | if ( d->sendAppLnks && d->serverGui ) | 242 | if ( d->sendAppLnks && d->serverGui ) |
242 | d->serverGui->applicationAdded( l->type(), *l ); | 243 | d->serverGui->applicationAdded( l->type(), *l ); |
243 | } | 244 | } |
244 | 245 | ||
245 | if ( d->sendAppLnks && d->serverGui ) | 246 | if ( d->sendAppLnks && d->serverGui ) |
246 | d->serverGui->applicationScanningProgress( 100 ); | 247 | d->serverGui->applicationScanningProgress( 100 ); |
247 | } | 248 | } |
248 | 249 | ||
249 | void DocumentList::reloadDocLnks() | 250 | void DocumentList::reloadDocLnks() |
250 | { | 251 | { |
251 | if ( !d->scanDocs ) | 252 | if ( !d->scanDocs ) |
252 | return; | 253 | return; |
253 | 254 | ||
254 | if ( d->sendDocLnks && d->serverGui ) { | 255 | if ( d->sendDocLnks && d->serverGui ) { |
255 | d->serverGui->documentScanningProgress( 0 ); | 256 | d->serverGui->documentScanningProgress( 0 ); |
256 | d->serverGui->allDocumentsRemoved(); | 257 | d->serverGui->allDocumentsRemoved(); |
257 | } | 258 | } |
258 | 259 | ||
259 | rescan(); | 260 | rescan(); |
260 | } | 261 | } |
261 | 262 | ||
262 | void DocumentList::linkChanged( QString arg ) | 263 | void DocumentList::linkChanged( QString arg ) |
263 | { | 264 | { |
264 | //qDebug( "linkchanged( %s )", arg.latin1() ); | 265 | //qDebug( "linkchanged( %s )", arg.latin1() ); |
265 | 266 | ||
266 | if ( arg.isNull() || Global::isAppLnkFileName( arg ) ) { | 267 | if ( arg.isNull() || Opie::Global::isAppLnkFileName( arg ) ) { |
267 | reloadAppLnks(); | 268 | reloadAppLnks(); |
268 | } else { | 269 | } else { |
269 | 270 | ||
270 | const QList<DocLnk> &list = d->dls.children(); | 271 | const QList<DocLnk> &list = d->dls.children(); |
271 | QListIterator<DocLnk> it( list ); | 272 | QListIterator<DocLnk> it( list ); |
272 | while ( it.current() ) { | 273 | while ( it.current() ) { |
273 | DocLnk *doc = it.current(); | 274 | DocLnk *doc = it.current(); |
274 | ++it; | 275 | ++it; |
275 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) | 276 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) |
276 | || ( doc->fileKnown() && doc->file() == arg ) ) { | 277 | || ( doc->fileKnown() && doc->file() == arg ) ) { |
277 | //qDebug( "found old link" ); | 278 | //qDebug( "found old link" ); |
278 | DocLnk* dl = new DocLnk( arg ); | 279 | DocLnk* dl = new DocLnk( arg ); |
279 | // add new one if it exists and matches the mimetype | 280 | // add new one if it exists and matches the mimetype |
280 | if ( d->store( dl ) ) { | 281 | if ( d->store( dl ) ) { |
281 | // Existing link has been changed, send old link ref and a ref | 282 | // Existing link has been changed, send old link ref and a ref |
282 | // to the new link | 283 | // to the new link |
283 | //qDebug( "change case" ); | 284 | //qDebug( "change case" ); |
284 | if ( d->serverGui ) | 285 | if ( d->serverGui ) |
285 | d->serverGui->documentChanged( *doc, *dl ); | 286 | d->serverGui->documentChanged( *doc, *dl ); |
286 | 287 | ||
287 | } else { | 288 | } else { |
288 | // Link has been removed or doesn't match the mimetypes any more | 289 | // Link has been removed or doesn't match the mimetypes any more |
289 | // so we aren't interested in it, so take it away from the list | 290 | // so we aren't interested in it, so take it away from the list |
290 | //qDebug( "removal case" ); | 291 | //qDebug( "removal case" ); |
291 | if ( d->serverGui ) | 292 | if ( d->serverGui ) |
292 | d->serverGui->documentRemoved( *doc ); | 293 | d->serverGui->documentRemoved( *doc ); |
293 | 294 | ||
294 | } | 295 | } |
295 | d->dls.remove( doc ); // remove old link from docLnkSet | 296 | d->dls.remove( doc ); // remove old link from docLnkSet |
296 | delete doc; | 297 | delete doc; |
297 | return; | 298 | return; |
298 | } | 299 | } |
299 | } | 300 | } |
300 | // Didn't find existing link, must be new | 301 | // Didn't find existing link, must be new |
301 | DocLnk* dl = new DocLnk( arg ); | 302 | DocLnk* dl = new DocLnk( arg ); |
302 | if ( d->store( dl ) ) { | 303 | if ( d->store( dl ) ) { |
303 | // Add if it's a link we are interested in | 304 | // Add if it's a link we are interested in |
304 | //qDebug( "add case" ); | 305 | //qDebug( "add case" ); |
305 | add( *dl ); | 306 | add( *dl ); |
306 | } | 307 | } |
307 | 308 | ||
308 | } | 309 | } |
309 | } | 310 | } |
310 | 311 | ||
311 | void DocumentList::restoreDone() | 312 | void DocumentList::restoreDone() |
312 | { | 313 | { |
313 | reloadAppLnks(); | 314 | reloadAppLnks(); |
314 | reloadDocLnks(); | 315 | reloadDocLnks(); |
315 | } | 316 | } |
316 | 317 | ||
317 | void DocumentList::storageChanged() | 318 | void DocumentList::storageChanged() |
318 | { | 319 | { |
319 | // ### can implement better | 320 | // ### can implement better |
320 | reloadAppLnks(); | 321 | reloadAppLnks(); |
321 | reloadDocLnks(); | 322 | reloadDocLnks(); |
322 | // ### Optimization opportunity | 323 | // ### Optimization opportunity |
323 | // Could be a bit more intelligent and somehow work out which | 324 | // Could be a bit more intelligent and somehow work out which |
324 | // mtab entry has changed and then only scan that and add and remove | 325 | // mtab entry has changed and then only scan that and add and remove |
325 | // links appropriately. | 326 | // links appropriately. |
326 | // rescan(); | 327 | // rescan(); |
327 | } | 328 | } |
328 | 329 | ||
329 | void DocumentList::sendAllDocLinks() | 330 | void DocumentList::sendAllDocLinks() |
330 | { | 331 | { |
331 | if ( d->tid != 0 ) { | 332 | if ( d->tid != 0 ) { |
332 | // We are in the middle of scanning, set a flag so | 333 | // We are in the middle of scanning, set a flag so |
333 | // we do this when we finish our scanning | 334 | // we do this when we finish our scanning |
334 | d->needToSendAllDocLinks = true; | 335 | d->needToSendAllDocLinks = true; |
335 | return; | 336 | return; |
336 | } | 337 | } |
337 | 338 | ||
338 | QString contents; | 339 | QString contents; |
339 | Categories cats; | 340 | Categories cats; |
340 | for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { | 341 | for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { |
341 | DocLnk *doc = it.current(); | 342 | DocLnk *doc = it.current(); |
342 | QFileInfo fi( doc->file() ); | 343 | QFileInfo fi( doc->file() ); |
343 | if ( !fi.exists() ) | 344 | if ( !fi.exists() ) |
344 | continue; | 345 | continue; |
345 | 346 | ||
346 | bool fake = !doc->linkFileKnown(); | 347 | bool fake = !doc->linkFileKnown(); |
347 | if ( !fake ) { | 348 | if ( !fake ) { |
348 | QFile f( doc->linkFile() ); | 349 | QFile f( doc->linkFile() ); |
349 | if ( f.open( IO_ReadOnly ) ) { | 350 | if ( f.open( IO_ReadOnly ) ) { |
350 | QTextStream ts( &f ); | 351 | QTextStream ts( &f ); |
351 | ts.setEncoding( QTextStream::UnicodeUTF8 ); | 352 | ts.setEncoding( QTextStream::UnicodeUTF8 ); |
352 | contents += ts.read(); | 353 | contents += ts.read(); |
353 | f.close(); | 354 | f.close(); |
354 | } else | 355 | } else |
355 | fake = TRUE; | 356 | fake = TRUE; |
356 | } | 357 | } |
357 | if (fake) { | 358 | if (fake) { |
358 | contents += "[Desktop Entry]\n"; // No tr | 359 | contents += "[Desktop Entry]\n"; // No tr |
359 | contents += "Categories = " + // No tr | 360 | contents += "Categories = " + // No tr |
360 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr | 361 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr |
361 | contents += "Name = "+doc->name()+"\n"; // No tr | 362 | contents += "Name = "+doc->name()+"\n"; // No tr |
362 | contents += "Type = "+doc->type()+"\n"; // No tr | 363 | contents += "Type = "+doc->type()+"\n"; // No tr |
363 | } | 364 | } |
364 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) | 365 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) |
365 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr | 366 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr |
366 | } | 367 | } |
367 | 368 | ||
368 | //qDebug( "sending length %d", contents.length() ); | 369 | //qDebug( "sending length %d", contents.length() ); |
369 | #ifndef QT_NO_COP | 370 | #ifndef QT_NO_COP |
370 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); | 371 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); |
371 | e << contents; | 372 | e << contents; |
372 | #endif | 373 | #endif |
373 | //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); | 374 | //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); |
374 | 375 | ||
375 | d->needToSendAllDocLinks = false; | 376 | d->needToSendAllDocLinks = false; |
376 | } | 377 | } |
377 | 378 | ||
378 | 379 | ||
379 | 380 | ||
380 | 381 | ||
381 | 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 | DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) | 402 | DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) |
402 | { | 403 | { |
403 | storage = new StorageInfo( this ); | 404 | storage = new StorageInfo( this ); |
404 | serverGui = gui; | 405 | serverGui = gui; |
405 | if ( serverGui ) { | 406 | if ( serverGui ) { |
406 | sendAppLnks = serverGui->requiresApplications(); | 407 | sendAppLnks = serverGui->requiresApplications(); |
407 | sendDocLnks = serverGui->requiresDocuments(); | 408 | sendDocLnks = serverGui->requiresDocuments(); |
408 | } else { | 409 | } else { |
409 | sendAppLnks = false; | 410 | sendAppLnks = false; |
410 | sendDocLnks = false; | 411 | sendDocLnks = false; |
411 | } | 412 | } |
412 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { | 413 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { |
413 | listDirs[i] = 0; | 414 | listDirs[i] = 0; |
414 | lists[i] = 0; | 415 | lists[i] = 0; |
415 | listPositions[i] = 0; | 416 | listPositions[i] = 0; |
416 | } | 417 | } |
417 | initialize(); | 418 | initialize(); |
418 | tid = 0; | 419 | tid = 0; |
419 | } | 420 | } |
420 | 421 | ||
421 | 422 | ||
422 | void DocumentListPrivate::initialize() | 423 | void DocumentListPrivate::initialize() |
423 | { | 424 | { |
424 | // Reset | 425 | // Reset |
425 | dls.clear(); | 426 | dls.clear(); |
426 | docPaths.clear(); | 427 | docPaths.clear(); |
427 | reference.clear(); | 428 | reference.clear(); |
428 | 429 | ||
429 | QDir docDir( QPEApplication::documentDir() ); | 430 | QDir docDir( QPEApplication::documentDir() ); |
430 | if ( docDir.exists() ) | 431 | if ( docDir.exists() ) |
431 | docPaths += QPEApplication::documentDir(); | 432 | docPaths += QPEApplication::documentDir(); |
432 | int i = 1; | 433 | int i = 1; |
433 | const QList<FileSystem> &fs = storage->fileSystems(); | 434 | const QList<FileSystem> &fs = storage->fileSystems(); |
434 | QListIterator<FileSystem> it( fs ); | 435 | QListIterator<FileSystem> it( fs ); |
435 | for ( ; it.current(); ++it ) | 436 | for ( ; it.current(); ++it ) |
436 | if ( (*it)->isRemovable() ) { | 437 | if ( (*it)->isRemovable() ) { |
437 | docPaths += (*it)->path(); | 438 | docPaths += (*it)->path(); |
438 | i++; | 439 | i++; |
439 | } | 440 | } |
440 | 441 | ||
441 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { | 442 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { |
442 | if ( listDirs[i] ) { | 443 | if ( listDirs[i] ) { |
443 | delete listDirs[i]; | 444 | delete listDirs[i]; |
444 | listDirs[i] = 0; | 445 | listDirs[i] = 0; |
445 | } | 446 | } |
446 | lists[i] = 0; | 447 | lists[i] = 0; |
447 | listPositions[i] = 0; | 448 | listPositions[i] = 0; |
448 | } | 449 | } |
449 | 450 | ||
450 | docPathsSearched = 0; | 451 | docPathsSearched = 0; |
451 | searchDepth = -1; | 452 | searchDepth = -1; |
452 | state = Find; | 453 | state = Find; |
453 | dit = 0; | 454 | dit = 0; |
454 | } | 455 | } |
455 | 456 | ||
456 | 457 | ||
457 | DocumentListPrivate::~DocumentListPrivate() | 458 | DocumentListPrivate::~DocumentListPrivate() |
458 | { | 459 | { |
459 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) | 460 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) |
460 | if ( listDirs[i] ) | 461 | if ( listDirs[i] ) |
461 | delete listDirs[i]; | 462 | delete listDirs[i]; |
462 | delete dit; | 463 | delete dit; |
463 | } | 464 | } |
464 | 465 | ||
465 | 466 | ||
466 | void DocumentListPrivate::estimatedPercentScanned() | 467 | void DocumentListPrivate::estimatedPercentScanned() |
467 | { | 468 | { |
468 | double overallProgress = 0.0; | 469 | double overallProgress = 0.0; |
469 | double levelWeight = 75.0; | 470 | double levelWeight = 75.0; |
470 | 471 | ||
471 | int topCount = docPaths.count(); | 472 | int topCount = docPaths.count(); |
472 | if ( topCount > 1 ) { | 473 | if ( topCount > 1 ) { |
473 | levelWeight = levelWeight / topCount; | 474 | levelWeight = levelWeight / topCount; |
474 | overallProgress += (docPathsSearched - 1) * levelWeight; | 475 | overallProgress += (docPathsSearched - 1) * levelWeight; |
475 | } | 476 | } |
476 | 477 | ||
477 | for ( int d = 0; d <= searchDepth; d++ ) { | 478 | for ( int d = 0; d <= searchDepth; d++ ) { |
478 | if ( listDirs[d] ) { | 479 | if ( listDirs[d] ) { |
479 | int items = lists[d]->count(); | 480 | int items = lists[d]->count(); |
480 | if ( items > 1 ) { | 481 | if ( items > 1 ) { |
481 | levelWeight = levelWeight / items; | 482 | levelWeight = levelWeight / items; |
482 | // Take in to account "." and ".." | 483 | // Take in to account "." and ".." |
483 | overallProgress += (listPositions[d] - 3) * levelWeight; | 484 | overallProgress += (listPositions[d] - 3) * levelWeight; |
484 | } | 485 | } |
485 | } else { | 486 | } else { |
486 | break; | 487 | break; |
487 | } | 488 | } |
488 | } | 489 | } |
489 | 490 | ||
490 | // qDebug( "overallProgress: %f", overallProgress ); | 491 | // qDebug( "overallProgress: %f", overallProgress ); |
491 | 492 | ||
492 | if ( serverGui ) | 493 | if ( serverGui ) |
493 | serverGui->documentScanningProgress( (int)overallProgress ); | 494 | serverGui->documentScanningProgress( (int)overallProgress ); |
494 | } | 495 | } |
495 | 496 | ||
496 | 497 | ||
497 | const QString DocumentListPrivate::nextFile() | 498 | const QString DocumentListPrivate::nextFile() |
498 | { | 499 | { |
499 | while ( TRUE ) { | 500 | while ( TRUE ) { |
500 | while ( searchDepth < 0 ) { | 501 | while ( searchDepth < 0 ) { |
501 | // go to next base path | 502 | // go to next base path |
502 | if ( docPathsSearched >= docPaths.count() ) { | 503 | if ( docPathsSearched >= docPaths.count() ) { |
503 | // end of base paths | 504 | // end of base paths |
504 | return QString::null; | 505 | return QString::null; |
505 | } else { | 506 | } else { |
506 | QDir dir( docPaths[docPathsSearched] ); | 507 | QDir dir( docPaths[docPathsSearched] ); |
507 | // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); | 508 | // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); |
508 | docPathsSearched++; | 509 | docPathsSearched++; |
509 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 510 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
510 | listDirs[0] = new QDir( dir ); | 511 | listDirs[0] = new QDir( dir ); |
511 | lists[0] = listDirs[0]->entryInfoList(); | 512 | lists[0] = listDirs[0]->entryInfoList(); |
512 | listPositions[0] = 0; | 513 | listPositions[0] = 0; |
513 | searchDepth = 0; | 514 | searchDepth = 0; |
514 | } | 515 | } |
515 | } | 516 | } |
516 | } | 517 | } |
517 | 518 | ||
518 | const QFileInfoList *fil = lists[searchDepth]; | 519 | const QFileInfoList *fil = lists[searchDepth]; |
519 | QFileInfoList *fl = (QFileInfoList *)fil; | 520 | QFileInfoList *fl = (QFileInfoList *)fil; |
520 | unsigned int pos = listPositions[searchDepth]; | 521 | unsigned int pos = listPositions[searchDepth]; |
521 | 522 | ||
522 | if ( pos >= fl->count() ) { | 523 | if ( pos >= fl->count() ) { |
523 | // go up a depth | 524 | // go up a depth |
524 | delete listDirs[searchDepth]; | 525 | delete listDirs[searchDepth]; |
525 | listDirs[searchDepth] = 0; | 526 | listDirs[searchDepth] = 0; |
526 | lists[searchDepth] = 0; | 527 | lists[searchDepth] = 0; |
527 | listPositions[searchDepth] = 0; | 528 | listPositions[searchDepth] = 0; |
528 | searchDepth--; | 529 | searchDepth--; |
529 | } else { | 530 | } else { |
530 | const QFileInfo *fi = fl->at(pos); | 531 | const QFileInfo *fi = fl->at(pos); |
531 | listPositions[searchDepth]++; | 532 | listPositions[searchDepth]++; |
532 | QString bn = fi->fileName(); | 533 | QString bn = fi->fileName(); |
533 | if ( bn[0] != '.' ) { | 534 | if ( bn[0] != '.' ) { |
534 | if ( fi->isDir() ) { | 535 | if ( fi->isDir() ) { |
535 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { | 536 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { |
536 | // go down a depth | 537 | // go down a depth |
537 | QDir dir( fi->filePath() ); | 538 | QDir dir( fi->filePath() ); |
538 | // qDebug("now going in to path: %s", bn.latin1() ); | 539 | // qDebug("now going in to path: %s", bn.latin1() ); |
539 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 540 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
540 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { | 541 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { |
541 | searchDepth++; | 542 | searchDepth++; |
542 | listDirs[searchDepth] = new QDir( dir ); | 543 | listDirs[searchDepth] = new QDir( dir ); |
543 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); | 544 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); |
544 | listPositions[searchDepth] = 0; | 545 | listPositions[searchDepth] = 0; |
545 | } | 546 | } |
546 | } | 547 | } |
547 | } | 548 | } |
548 | } else { | 549 | } else { |
549 | estimatedPercentScanned(); | 550 | estimatedPercentScanned(); |
550 | return fl->at(pos)->filePath(); | 551 | return fl->at(pos)->filePath(); |
551 | } | 552 | } |
552 | } | 553 | } |
553 | } | 554 | } |
554 | } | 555 | } |
555 | 556 | ||
556 | return QString::null; | 557 | return QString::null; |
557 | } | 558 | } |
558 | 559 | ||
559 | 560 | ||
560 | bool DocumentListPrivate::store( DocLnk* dl ) | 561 | bool DocumentListPrivate::store( DocLnk* dl ) |
561 | { | 562 | { |
562 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { | 563 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { |
563 | if ( dl && dl->fileKnown() ) { | 564 | if ( dl && dl->fileKnown() ) { |
564 | dls.add( dl ); // store | 565 | dls.add( dl ); // store |
565 | return TRUE; | 566 | return TRUE; |
566 | } | 567 | } |
567 | 568 | ||
568 | // don't store - delete | 569 | // don't store - delete |
569 | delete dl; | 570 | delete dl; |
570 | return FALSE; | 571 | return FALSE; |
571 | } | 572 | } |
572 | 573 | ||
573 | 574 | ||
574 | #define MAGIC_NUMBER((void*)2) | 575 | #define MAGIC_NUMBER((void*)2) |
575 | 576 | ||
576 | const DocLnk *DocumentListPrivate::iterate() | 577 | const DocLnk *DocumentListPrivate::iterate() |
577 | { | 578 | { |
578 | if ( state == Find ) { | 579 | if ( state == Find ) { |
579 | //qDebug("state Find"); | 580 | //qDebug("state Find"); |
580 | QString file = nextFile(); | 581 | QString file = nextFile(); |
581 | while ( !file.isNull() ) { | 582 | while ( !file.isNull() ) { |
582 | if ( file.right(8) == ".desktop" ) { // No tr | 583 | if ( file.right(8) == ".desktop" ) { // No tr |
583 | DocLnk* dl = new DocLnk( file ); | 584 | DocLnk* dl = new DocLnk( file ); |
584 | if ( store(dl) ) | 585 | if ( store(dl) ) |
585 | return dl; | 586 | return dl; |
586 | } else { | 587 | } else { |
587 | reference.insert( file, MAGIC_NUMBER ); | 588 | reference.insert( file, MAGIC_NUMBER ); |
588 | } | 589 | } |
589 | file = nextFile(); | 590 | file = nextFile(); |
590 | } | 591 | } |
591 | state = RemoveKnownFiles; | 592 | state = RemoveKnownFiles; |
592 | 593 | ||
593 | if ( serverGui ) | 594 | if ( serverGui ) |
594 | serverGui->documentScanningProgress( 75 ); | 595 | serverGui->documentScanningProgress( 75 ); |
595 | } | 596 | } |
596 | 597 | ||
597 | static int iterationI; | 598 | static int iterationI; |
598 | static int iterationCount; | 599 | static int iterationCount; |
599 | 600 | ||
600 | if ( state == RemoveKnownFiles ) { | 601 | if ( state == RemoveKnownFiles ) { |
601 | //qDebug("state RemoveKnownFiles"); | 602 | //qDebug("state RemoveKnownFiles"); |
602 | const QList<DocLnk> &list = dls.children(); | 603 | const QList<DocLnk> &list = dls.children(); |
603 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 604 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
604 | reference.remove( (*it)->file() ); | 605 | reference.remove( (*it)->file() ); |
605 | // ### does this need to be deleted? | 606 | // ### does this need to be deleted? |
606 | } | 607 | } |
607 | dit = new QDictIterator<void>(reference); | 608 | dit = new QDictIterator<void>(reference); |
608 | state = MakeUnknownFiles; | 609 | state = MakeUnknownFiles; |
609 | 610 | ||
610 | iterationI = 0; | 611 | iterationI = 0; |
611 | iterationCount = dit->count(); | 612 | iterationCount = dit->count(); |
612 | } | 613 | } |
613 | 614 | ||
614 | if ( state == MakeUnknownFiles ) { | 615 | if ( state == MakeUnknownFiles ) { |
615 | //qDebug("state MakeUnknownFiles"); | 616 | //qDebug("state MakeUnknownFiles"); |
616 | for (void* c; (c=dit->current()); ++(*dit) ) { | 617 | for (void* c; (c=dit->current()); ++(*dit) ) { |
617 | if ( c == MAGIC_NUMBER ) { | 618 | if ( c == MAGIC_NUMBER ) { |
618 | DocLnk* dl = new DocLnk; | 619 | DocLnk* dl = new DocLnk; |
619 | QFileInfo fi( dit->currentKey() ); | 620 | QFileInfo fi( dit->currentKey() ); |
620 | dl->setFile( fi.filePath() ); | 621 | dl->setFile( fi.filePath() ); |
621 | dl->setName( fi.baseName() ); | 622 | dl->setName( fi.baseName() ); |
622 | if ( store(dl) ) { | 623 | if ( store(dl) ) { |
623 | ++*dit; | 624 | ++*dit; |
624 | iterationI++; | 625 | iterationI++; |
625 | if ( serverGui ) | 626 | if ( serverGui ) |
626 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); | 627 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); |
627 | return dl; | 628 | return dl; |
628 | } | 629 | } |
629 | } | 630 | } |
630 | iterationI++; | 631 | iterationI++; |
631 | } | 632 | } |
632 | 633 | ||
633 | delete dit; | 634 | delete dit; |
634 | dit = 0; | 635 | dit = 0; |
635 | state = Done; | 636 | state = Done; |
636 | } | 637 | } |
637 | 638 | ||
638 | //qDebug("state Done"); | 639 | //qDebug("state Done"); |
639 | return NULL; | 640 | return NULL; |
640 | } | 641 | } |
641 | 642 | ||
642 | 643 | ||
643 | #include "documentlist.moc" | 644 | #include "documentlist.moc" |
644 | 645 | ||
645 | 646 | ||
646 | 647 | ||