-rw-r--r-- | core/launcher/documentlist.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp index fd385d6..35a5d56 100644 --- a/core/launcher/documentlist.cpp +++ b/core/launcher/documentlist.cpp | |||
@@ -1,815 +1,817 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2000-2002 Trolltech AS | 3 | =. (C) 2000-2002 Trolltech AS |
4 | .=l. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> | 4 | .=l. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; version 2 of the License. | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : | 11 | ._= =} : |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | #include "documentlist.h" | 28 | #include "documentlist.h" |
29 | #include "serverinterface.h" | 29 | #include "serverinterface.h" |
30 | #include "mediadlg.h" | 30 | #include "mediadlg.h" |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <opie2/oglobal.h> | 33 | #include <opie2/oglobal.h> |
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | #include <opie2/oresource.h> | 35 | #include <opie2/oresource.h> |
36 | #include <qtopia/config.h> | 36 | #include <qtopia/config.h> |
37 | #include <qtopia/mimetype.h> | 37 | #include <qtopia/mimetype.h> |
38 | #include <qtopia/private/categories.h> | 38 | #include <qtopia/private/categories.h> |
39 | #include <qtopia/qpeapplication.h> | 39 | #include <qtopia/qpeapplication.h> |
40 | #include <qtopia/applnk.h> | 40 | #include <qtopia/applnk.h> |
41 | #include <qtopia/storage.h> | 41 | #include <qtopia/storage.h> |
42 | #ifdef Q_WS_QWS | 42 | #ifdef Q_WS_QWS |
43 | #include <qtopia/qcopenvelope_qws.h> | 43 | #include <qtopia/qcopenvelope_qws.h> |
44 | #endif | 44 | #endif |
45 | using namespace Opie::Core; | 45 | using namespace Opie::Core; |
46 | 46 | ||
47 | /* QT */ | 47 | /* QT */ |
48 | #include <qtimer.h> | 48 | #include <qtimer.h> |
49 | #include <qfileinfo.h> | 49 | #include <qfileinfo.h> |
50 | #include <qtextstream.h> | 50 | #include <qtextstream.h> |
51 | #include <qfile.h> | 51 | #include <qfile.h> |
52 | #include <qdir.h> | 52 | #include <qdir.h> |
53 | #include <qpainter.h> | 53 | #include <qpainter.h> |
54 | #include <qimage.h> | 54 | #include <qimage.h> |
55 | #include <qcopchannel_qws.h> | 55 | #include <qcopchannel_qws.h> |
56 | #include <qlistview.h> | 56 | #include <qlistview.h> |
57 | #include <qlist.h> | 57 | #include <qlist.h> |
58 | #include <qpixmap.h> | 58 | #include <qpixmap.h> |
59 | 59 | ||
60 | 60 | ||
61 | AppLnkSet *DocumentList::appLnkSet = 0; | 61 | AppLnkSet *DocumentList::appLnkSet = 0; |
62 | 62 | ||
63 | static const int MAX_SEARCH_DEPTH = 10; | 63 | static const int MAX_SEARCH_DEPTH = 10; |
64 | 64 | ||
65 | 65 | ||
66 | class DocumentListPrivate : public QObject { | 66 | class DocumentListPrivate : public QObject { |
67 | Q_OBJECT | 67 | Q_OBJECT |
68 | public: | 68 | public: |
69 | DocumentListPrivate( ServerInterface *gui ); | 69 | DocumentListPrivate( ServerInterface *gui ); |
70 | ~DocumentListPrivate(); | 70 | ~DocumentListPrivate(); |
71 | 71 | ||
72 | void initialize(); | 72 | void initialize(); |
73 | 73 | ||
74 | const QString nextFile(); | 74 | const QString nextFile(); |
75 | const DocLnk *iterate(); | 75 | const DocLnk *iterate(); |
76 | bool store( DocLnk* dl ); | 76 | bool store( DocLnk* dl ); |
77 | void estimatedPercentScanned(); | 77 | void estimatedPercentScanned(); |
78 | void appendDocpath(FileSystem*); | 78 | void appendDocpath(FileSystem*); |
79 | 79 | ||
80 | 80 | ||
81 | DocLnkSet dls; | 81 | DocLnkSet dls; |
82 | QDict<void> reference; | 82 | QDict<void> reference; |
83 | QDictIterator<void> *dit; | 83 | QDictIterator<void> *dit; |
84 | enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; | 84 | enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; |
85 | 85 | ||
86 | QStringList docPaths; | 86 | QStringList docPaths; |
87 | unsigned int docPathsSearched; | 87 | unsigned int docPathsSearched; |
88 | 88 | ||
89 | int searchDepth; | 89 | int searchDepth; |
90 | QDir *listDirs[MAX_SEARCH_DEPTH]; | 90 | QDir *listDirs[MAX_SEARCH_DEPTH]; |
91 | const QFileInfoList *lists[MAX_SEARCH_DEPTH]; | 91 | const QFileInfoList *lists[MAX_SEARCH_DEPTH]; |
92 | unsigned int listPositions[MAX_SEARCH_DEPTH]; | 92 | unsigned int listPositions[MAX_SEARCH_DEPTH]; |
93 | 93 | ||
94 | StorageInfo *storage; | 94 | StorageInfo *storage; |
95 | 95 | ||
96 | int tid; | 96 | int tid; |
97 | 97 | ||
98 | ServerInterface *serverGui; | 98 | ServerInterface *serverGui; |
99 | 99 | ||
100 | bool needToSendAllDocLinks; | 100 | bool needToSendAllDocLinks; |
101 | bool sendAppLnks; | 101 | bool sendAppLnks; |
102 | bool sendDocLnks; | 102 | bool sendDocLnks; |
103 | bool scanDocs; | 103 | bool scanDocs; |
104 | }; | 104 | }; |
105 | 105 | ||
106 | 106 | ||
107 | /* | 107 | /* |
108 | * scandocs will be read from Config | 108 | * scandocs will be read from Config |
109 | */ | 109 | */ |
110 | DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, | 110 | DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, |
111 | QObject *parent, const char *name ) | 111 | QObject *parent, const char *name ) |
112 | : QObject( parent, name ) | 112 | : QObject( parent, name ) |
113 | { | 113 | { |
114 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); | 114 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); |
115 | d = new DocumentListPrivate( serverGui ); | 115 | d = new DocumentListPrivate( serverGui ); |
116 | d->needToSendAllDocLinks = false; | 116 | d->needToSendAllDocLinks = false; |
117 | 117 | ||
118 | Config cfg( "Launcher" ); | 118 | Config cfg( "Launcher" ); |
119 | cfg.setGroup( "DocTab" ); | 119 | cfg.setGroup( "DocTab" ); |
120 | d->scanDocs = cfg.readBoolEntry( "Enable", true ); | 120 | d->scanDocs = cfg.readBoolEntry( "Enable", true ); |
121 | odebug << "DocumentList::DocumentList() : scanDocs = " << d->scanDocs << "" << oendl; | 121 | odebug << "DocumentList::DocumentList() : scanDocs = " << d->scanDocs << "" << oendl; |
122 | 122 | ||
123 | QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); | 123 | QTimer::singleShot( 0, this, SLOT( startInitialScan() ) ); |
124 | } | 124 | } |
125 | 125 | ||
126 | void DocumentList::startInitialScan() | 126 | void DocumentList::startInitialScan() |
127 | { | 127 | { |
128 | reloadAppLnks(); | 128 | reloadAppLnks(); |
129 | reloadDocLnks(); | 129 | reloadDocLnks(); |
130 | } | 130 | } |
131 | 131 | ||
132 | DocumentList::~DocumentList() | 132 | DocumentList::~DocumentList() |
133 | { | 133 | { |
134 | delete appLnkSet; | 134 | delete appLnkSet; |
135 | delete d; | 135 | delete d; |
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | void DocumentList::add( const DocLnk& doc ) | 139 | void DocumentList::add( const DocLnk& doc ) |
140 | { | 140 | { |
141 | if ( d->serverGui && QFile::exists( doc.file() ) ) | 141 | if ( d->serverGui && QFile::exists( doc.file() ) ) |
142 | d->serverGui->documentAdded( doc ); | 142 | d->serverGui->documentAdded( doc ); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | void DocumentList::start() | 146 | void DocumentList::start() |
147 | { | 147 | { |
148 | resume(); | 148 | resume(); |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | void DocumentList::pause() | 152 | void DocumentList::pause() |
153 | { | 153 | { |
154 | //odebug << "pause " << d->tid << "" << oendl; | 154 | //odebug << "pause " << d->tid << "" << oendl; |
155 | killTimer( d->tid ); | 155 | killTimer( d->tid ); |
156 | d->tid = 0; | 156 | d->tid = 0; |
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
160 | void DocumentList::resume() | 160 | void DocumentList::resume() |
161 | { | 161 | { |
162 | if ( d->tid == 0 ) { | 162 | if ( d->tid == 0 ) { |
163 | d->tid = startTimer( 20 ); | 163 | d->tid = startTimer( 20 ); |
164 | //odebug << "resumed " << d->tid << "" << oendl; | 164 | //odebug << "resumed " << d->tid << "" << oendl; |
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | /* | 168 | /* |
169 | void DocumentList::resend() | 169 | void DocumentList::resend() |
170 | { | 170 | { |
171 | // Re-emits all the added items to the list (firstly letting everyone know to | 171 | // Re-emits all the added items to the list (firstly letting everyone know to |
172 | // clear what they have as it is being sent again) | 172 | // clear what they have as it is being sent again) |
173 | pause(); | 173 | pause(); |
174 | emit allRemoved(); | 174 | emit allRemoved(); |
175 | QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); | 175 | QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | void DocumentList::resendWorker() | 179 | void DocumentList::resendWorker() |
180 | { | 180 | { |
181 | const QList<DocLnk> &list = d->dls.children(); | 181 | const QList<DocLnk> &list = d->dls.children(); |
182 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) | 182 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) |
183 | add( *(*it) ); | 183 | add( *(*it) ); |
184 | resume(); | 184 | resume(); |
185 | } | 185 | } |
186 | */ | 186 | */ |
187 | 187 | ||
188 | void DocumentList::rescan() | 188 | void DocumentList::rescan() |
189 | { | 189 | { |
190 | //odebug << "rescan" << oendl; | 190 | owarn << "XXXXXXXXXXX rescan" << oendl; |
191 | pause(); | 191 | pause(); |
192 | d->initialize(); | 192 | d->initialize(); |
193 | resume(); | 193 | resume(); |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | void DocumentList::timerEvent( QTimerEvent *te ) | 197 | void DocumentList::timerEvent( QTimerEvent *te ) |
198 | { | 198 | { |
199 | if ( te->timerId() == d->tid ) { | 199 | if ( te->timerId() == d->tid ) { |
200 | // Do 3 at a time | 200 | // Do 3 at a time |
201 | if ( d->serverGui ) | 201 | if ( d->serverGui ) |
202 | d->serverGui->aboutToAddBegin(); | 202 | d->serverGui->aboutToAddBegin(); |
203 | for (int i = 0; i < 3; i++ ) { | 203 | for (int i = 0; i < 3; i++ ) { |
204 | const DocLnk *lnk = d->iterate(); | 204 | const DocLnk *lnk = d->iterate(); |
205 | if ( lnk ) { | 205 | if ( lnk ) { |
206 | add( *lnk ); | 206 | add( *lnk ); |
207 | } else { | 207 | } else { |
208 | // stop when done | 208 | // stop when done |
209 | pause(); | 209 | pause(); |
210 | if ( d->serverGui ) | 210 | if ( d->serverGui ) |
211 | d->serverGui->documentScanningProgress( 100 ); | 211 | d->serverGui->documentScanningProgress( 100 ); |
212 | if ( d->needToSendAllDocLinks ) | 212 | if ( d->needToSendAllDocLinks ) |
213 | sendAllDocLinks(); | 213 | sendAllDocLinks(); |
214 | break; | 214 | break; |
215 | } | 215 | } |
216 | } | 216 | } |
217 | if ( d->serverGui ) | 217 | if ( d->serverGui ) |
218 | d->serverGui->aboutToAddEnd(); | 218 | d->serverGui->aboutToAddEnd(); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | void DocumentList::reloadAppLnks() | 223 | void DocumentList::reloadAppLnks() |
224 | { | 224 | { |
225 | if ( d->sendAppLnks && d->serverGui ) { | 225 | if ( d->sendAppLnks && d->serverGui ) { |
226 | d->serverGui->applicationScanningProgress( 0 ); | 226 | d->serverGui->applicationScanningProgress( 0 ); |
227 | d->serverGui->allApplicationsRemoved(); | 227 | d->serverGui->allApplicationsRemoved(); |
228 | } | 228 | } |
229 | 229 | ||
230 | delete appLnkSet; | 230 | delete appLnkSet; |
231 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); | 231 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); |
232 | 232 | ||
233 | if ( d->sendAppLnks && d->serverGui ) { | 233 | if ( d->sendAppLnks && d->serverGui ) { |
234 | static QStringList prevTypeList; | 234 | static QStringList prevTypeList; |
235 | QStringList types = appLnkSet->types(); | 235 | QStringList types = appLnkSet->types(); |
236 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { | 236 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { |
237 | if ( !(*ittypes).isEmpty() ) { | 237 | if ( !(*ittypes).isEmpty() ) { |
238 | if ( !prevTypeList.contains(*ittypes) ) { | 238 | if ( !prevTypeList.contains(*ittypes) ) { |
239 | QString name = appLnkSet->typeName(*ittypes); | 239 | QString name = appLnkSet->typeName(*ittypes); |
240 | QPixmap pm = appLnkSet->typePixmap(*ittypes); | 240 | QPixmap pm = appLnkSet->typePixmap(*ittypes); |
241 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); | 241 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); |
242 | 242 | ||
243 | if (pm.isNull()) | 243 | if (pm.isNull()) |
244 | { | 244 | { |
245 | pm = OResource::loadImage( "UnknownDocument", OResource::SmallIcon ); | 245 | pm = OResource::loadImage( "UnknownDocument", OResource::SmallIcon ); |
246 | bgPm = OResource::loadImage( "UnknownDocument", OResource::BigIcon ); | 246 | bgPm = OResource::loadImage( "UnknownDocument", OResource::BigIcon ); |
247 | } | 247 | } |
248 | 248 | ||
249 | //FIXME our current launcher expects docs tab to be last | 249 | //FIXME our current launcher expects docs tab to be last |
250 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); | 250 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); |
251 | } | 251 | } |
252 | prevTypeList.remove(*ittypes); | 252 | prevTypeList.remove(*ittypes); |
253 | } | 253 | } |
254 | } | 254 | } |
255 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { | 255 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { |
256 | d->serverGui->typeRemoved(*ittypes); | 256 | d->serverGui->typeRemoved(*ittypes); |
257 | } | 257 | } |
258 | prevTypeList = types; | 258 | prevTypeList = types; |
259 | } | 259 | } |
260 | 260 | ||
261 | QListIterator<AppLnk> itapp( appLnkSet->children() ); | 261 | QListIterator<AppLnk> itapp( appLnkSet->children() ); |
262 | AppLnk* l; | 262 | AppLnk* l; |
263 | while ( (l=itapp.current()) ) { | 263 | while ( (l=itapp.current()) ) { |
264 | ++itapp; | 264 | ++itapp; |
265 | if ( d->sendAppLnks && d->serverGui ) | 265 | if ( d->sendAppLnks && d->serverGui ) |
266 | d->serverGui->applicationAdded( l->type(), *l ); | 266 | d->serverGui->applicationAdded( l->type(), *l ); |
267 | } | 267 | } |
268 | 268 | ||
269 | if ( d->sendAppLnks && d->serverGui ) | 269 | if ( d->sendAppLnks && d->serverGui ) |
270 | d->serverGui->applicationScanningProgress( 100 ); | 270 | d->serverGui->applicationScanningProgress( 100 ); |
271 | } | 271 | } |
272 | 272 | ||
273 | void DocumentList::reloadDocLnks() | 273 | void DocumentList::reloadDocLnks() |
274 | { | 274 | { |
275 | if ( !d->scanDocs ) | 275 | if ( !d->scanDocs ) |
276 | return; | 276 | return; |
277 | 277 | ||
278 | if ( d->sendDocLnks && d->serverGui ) { | 278 | if ( d->sendDocLnks && d->serverGui ) { |
279 | d->serverGui->documentScanningProgress( 0 ); | 279 | d->serverGui->documentScanningProgress( 0 ); |
280 | d->serverGui->allDocumentsRemoved(); | 280 | d->serverGui->allDocumentsRemoved(); |
281 | } | 281 | } |
282 | 282 | ||
283 | rescan(); | 283 | rescan(); |
284 | } | 284 | } |
285 | 285 | ||
286 | void DocumentList::reforceDocuments() | 286 | void DocumentList::reforceDocuments() |
287 | { | 287 | { |
288 | Config cfg( "Launcher" ); | 288 | Config cfg( "Launcher" ); |
289 | cfg.setGroup( "DocTab" ); | 289 | cfg.setGroup( "DocTab" ); |
290 | d->scanDocs = cfg.readBoolEntry( "Enable", true ); | 290 | d->scanDocs = cfg.readBoolEntry( "Enable", true ); |
291 | reloadDocLnks(); | 291 | reloadDocLnks(); |
292 | } | 292 | } |
293 | 293 | ||
294 | void DocumentList::linkChanged( QString arg ) | 294 | void DocumentList::linkChanged( QString arg ) |
295 | { | 295 | { |
296 | odebug << "linkchanged( " << arg << " )" << oendl; | 296 | odebug << "linkchanged( " << arg << " )" << oendl; |
297 | 297 | ||
298 | if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { | 298 | if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { |
299 | reloadAppLnks(); | 299 | reloadAppLnks(); |
300 | } else { | 300 | } else { |
301 | 301 | ||
302 | const QList<DocLnk> &list = d->dls.children(); | 302 | const QList<DocLnk> &list = d->dls.children(); |
303 | QListIterator<DocLnk> it( list ); | 303 | QListIterator<DocLnk> it( list ); |
304 | while ( it.current() ) { | 304 | while ( it.current() ) { |
305 | DocLnk *doc = it.current(); | 305 | DocLnk *doc = it.current(); |
306 | ++it; | 306 | ++it; |
307 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) | 307 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) |
308 | || ( doc->fileKnown() && doc->file() == arg ) ) { | 308 | || ( doc->fileKnown() && doc->file() == arg ) ) { |
309 | //odebug << "found old link" << oendl; | 309 | //odebug << "found old link" << oendl; |
310 | DocLnk* dl = new DocLnk( arg ); | 310 | DocLnk* dl = new DocLnk( arg ); |
311 | // add new one if it exists and matches the mimetype | 311 | // add new one if it exists and matches the mimetype |
312 | if ( d->store( dl ) ) { | 312 | if ( d->store( dl ) ) { |
313 | // Existing link has been changed, send old link ref and a ref | 313 | // Existing link has been changed, send old link ref and a ref |
314 | // to the new link | 314 | // to the new link |
315 | //odebug << "change case" << oendl; | 315 | //odebug << "change case" << oendl; |
316 | if ( d->serverGui ) | 316 | if ( d->serverGui ) |
317 | d->serverGui->documentChanged( *doc, *dl ); | 317 | d->serverGui->documentChanged( *doc, *dl ); |
318 | 318 | ||
319 | } else { | 319 | } else { |
320 | // Link has been removed or doesn't match the mimetypes any more | 320 | // Link has been removed or doesn't match the mimetypes any more |
321 | // so we aren't interested in it, so take it away from the list | 321 | // so we aren't interested in it, so take it away from the list |
322 | //odebug << "removal case" << oendl; | 322 | //odebug << "removal case" << oendl; |
323 | if ( d->serverGui ) | 323 | if ( d->serverGui ) |
324 | d->serverGui->documentRemoved( *doc ); | 324 | d->serverGui->documentRemoved( *doc ); |
325 | 325 | ||
326 | } | 326 | } |
327 | d->dls.remove( doc ); // remove old link from docLnkSet | 327 | d->dls.remove( doc ); // remove old link from docLnkSet |
328 | delete doc; | 328 | delete doc; |
329 | return; | 329 | return; |
330 | } | 330 | } |
331 | } | 331 | } |
332 | // Didn't find existing link, must be new | 332 | // Didn't find existing link, must be new |
333 | DocLnk* dl = new DocLnk( arg ); | 333 | DocLnk* dl = new DocLnk( arg ); |
334 | if ( d->store( dl ) ) { | 334 | if ( d->store( dl ) ) { |
335 | // Add if it's a link we are interested in | 335 | // Add if it's a link we are interested in |
336 | //odebug << "add case" << oendl; | 336 | //odebug << "add case" << oendl; |
337 | add( *dl ); | 337 | add( *dl ); |
338 | } | 338 | } |
339 | 339 | ||
340 | } | 340 | } |
341 | } | 341 | } |
342 | 342 | ||
343 | void DocumentList::restoreDone() | 343 | void DocumentList::restoreDone() |
344 | { | 344 | { |
345 | reloadAppLnks(); | 345 | reloadAppLnks(); |
346 | reloadDocLnks(); | 346 | reloadDocLnks(); |
347 | } | 347 | } |
348 | 348 | ||
349 | void DocumentList::DiffAppLnks() | 349 | void DocumentList::DiffAppLnks() |
350 | { | 350 | { |
351 | static AppLnkSet *appLnkSet2; | 351 | static AppLnkSet *appLnkSet2; |
352 | 352 | ||
353 | appLnkSet2 = new AppLnkSet( MimeType::appsFolderName() ); | 353 | appLnkSet2 = new AppLnkSet( MimeType::appsFolderName() ); |
354 | 354 | ||
355 | if ( d->sendAppLnks && d->serverGui ) { | 355 | if ( d->sendAppLnks && d->serverGui ) { |
356 | static QStringList prevTypeList = appLnkSet->types(); | 356 | static QStringList prevTypeList = appLnkSet->types(); |
357 | QStringList types = appLnkSet2->types(); | 357 | QStringList types = appLnkSet2->types(); |
358 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { | 358 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { |
359 | if ( !(*ittypes).isEmpty() ) { | 359 | if ( !(*ittypes).isEmpty() ) { |
360 | if ( !prevTypeList.contains(*ittypes) ) { | 360 | if ( !prevTypeList.contains(*ittypes) ) { |
361 | QString name = appLnkSet2->typeName(*ittypes); | 361 | QString name = appLnkSet2->typeName(*ittypes); |
362 | QPixmap pm = appLnkSet2->typePixmap(*ittypes); | 362 | QPixmap pm = appLnkSet2->typePixmap(*ittypes); |
363 | QPixmap bgPm = appLnkSet2->typeBigPixmap(*ittypes); | 363 | QPixmap bgPm = appLnkSet2->typeBigPixmap(*ittypes); |
364 | 364 | ||
365 | if (pm.isNull()) | 365 | if (pm.isNull()) |
366 | { | 366 | { |
367 | pm = OResource::loadImage( "UnknownDocument", OResource::SmallIcon ); | 367 | pm = OResource::loadImage( "UnknownDocument", OResource::SmallIcon ); |
368 | bgPm = OResource::loadImage( "UnknownDocument", OResource::BigIcon ); | 368 | bgPm = OResource::loadImage( "UnknownDocument", OResource::BigIcon ); |
369 | } | 369 | } |
370 | 370 | ||
371 | // ### our current launcher expects docs tab to be last | 371 | // ### our current launcher expects docs tab to be last |
372 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); | 372 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); |
373 | } | 373 | } |
374 | prevTypeList.remove(*ittypes); | 374 | prevTypeList.remove(*ittypes); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { | 377 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { |
378 | d->serverGui->typeRemoved(*ittypes); | 378 | d->serverGui->typeRemoved(*ittypes); |
379 | } | 379 | } |
380 | prevTypeList = types; | 380 | prevTypeList = types; |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | QListIterator<AppLnk> it1( appLnkSet->children() ); | 384 | QListIterator<AppLnk> it1( appLnkSet->children() ); |
385 | QListIterator<AppLnk> it2( appLnkSet2->children() ); | 385 | QListIterator<AppLnk> it2( appLnkSet2->children() ); |
386 | 386 | ||
387 | AppLnk *i; | 387 | AppLnk *i; |
388 | AppLnk *j; | 388 | AppLnk *j; |
389 | bool found; | 389 | bool found; |
390 | 390 | ||
391 | while ( (j=it2.current()) ) { | 391 | while ( (j=it2.current()) ) { |
392 | it1 = appLnkSet->children(); | 392 | it1 = appLnkSet->children(); |
393 | found = false; | 393 | found = false; |
394 | while ( (i=it1.current()) ){ | 394 | while ( (i=it1.current()) ){ |
395 | if (j->name().ascii() && i->name().ascii() && strcmp(i->name().ascii(),j->name().ascii()) == 0) | 395 | if (j->name().ascii() && i->name().ascii() && strcmp(i->name().ascii(),j->name().ascii()) == 0) |
396 | found = true; | 396 | found = true; |
397 | ++it1; | 397 | ++it1; |
398 | } | 398 | } |
399 | if (!found) { | 399 | if (!found) { |
400 | odebug << "Item " << j->name().ascii() << " needs to be added" << oendl; | 400 | odebug << "Item " << j->name().ascii() << " needs to be added" << oendl; |
401 | d->serverGui->applicationAdded( j->type(), *j ); | 401 | d->serverGui->applicationAdded( j->type(), *j ); |
402 | } | 402 | } |
403 | ++it2; | 403 | ++it2; |
404 | } | 404 | } |
405 | 405 | ||
406 | it1 = appLnkSet->children(); | 406 | it1 = appLnkSet->children(); |
407 | while ( (i=it1.current()) ) { | 407 | while ( (i=it1.current()) ) { |
408 | it2 = appLnkSet2->children(); | 408 | it2 = appLnkSet2->children(); |
409 | found = false; | 409 | found = false; |
410 | while ( (j=it2.current()) ){ | 410 | while ( (j=it2.current()) ){ |
411 | if (j->name().ascii() && i->name().ascii() && strcmp(i->name().ascii(),j->name().ascii()) == 0) | 411 | if (j->name().ascii() && i->name().ascii() && strcmp(i->name().ascii(),j->name().ascii()) == 0) |
412 | found = true; | 412 | found = true; |
413 | ++it2; | 413 | ++it2; |
414 | } | 414 | } |
415 | if (!found) { | 415 | if (!found) { |
416 | odebug << "Item " << i->name().ascii() << " needs to be removed" << oendl; | 416 | odebug << "Item " << i->name().ascii() << " needs to be removed" << oendl; |
417 | d->serverGui->applicationRemoved( i->type(), *i ); | 417 | d->serverGui->applicationRemoved( i->type(), *i ); |
418 | } | 418 | } |
419 | 419 | ||
420 | ++it1; | 420 | ++it1; |
421 | } | 421 | } |
422 | 422 | ||
423 | delete appLnkSet; | 423 | delete appLnkSet; |
424 | appLnkSet = appLnkSet2; | 424 | appLnkSet = appLnkSet2; |
425 | 425 | ||
426 | } | 426 | } |
427 | void DocumentList::storageChanged() | 427 | void DocumentList::storageChanged() |
428 | { | 428 | { |
429 | QTime t; | 429 | QTime t; |
430 | // ### can implement better | 430 | // ### can implement better |
431 | 431 | ||
432 | t.start(); | 432 | t.start(); |
433 | DiffAppLnks(); | 433 | DiffAppLnks(); |
434 | // reloadAppLnks(); | 434 | // reloadAppLnks(); |
435 | odebug << "Reload App links took " << t.elapsed() << " ms" << oendl; | 435 | odebug << "Reload App links took " << t.elapsed() << " ms" << oendl; |
436 | reloadDocLnks(); | 436 | reloadDocLnks(); |
437 | // odebug << "Reload links took " << t.elapsed() << " ms " << oendl; | 437 | // odebug << "Reload links took " << t.elapsed() << " ms " << oendl; |
438 | odebug << "Reload All links took " << t.elapsed() << " ms" << oendl; | 438 | odebug << "Reload All links took " << t.elapsed() << " ms" << oendl; |
439 | // ### Optimization opportunity | 439 | // ### Optimization opportunity |
440 | // Could be a bit more intelligent and somehow work out which | 440 | // Could be a bit more intelligent and somehow work out which |
441 | // mtab entry has changed and then only scan that and add and remove | 441 | // mtab entry has changed and then only scan that and add and remove |
442 | // links appropriately. | 442 | // links appropriately. |
443 | // rescan(); | 443 | // rescan(); |
444 | } | 444 | } |
445 | 445 | ||
446 | void DocumentList::sendAllDocLinks() | 446 | void DocumentList::sendAllDocLinks() |
447 | { | 447 | { |
448 | if ( d->tid != 0 ) { | 448 | if ( d->tid != 0 ) { |
449 | // We are in the middle of scanning, set a flag so | 449 | // We are in the middle of scanning, set a flag so |
450 | // we do this when we finish our scanning | 450 | // we do this when we finish our scanning |
451 | d->needToSendAllDocLinks = true; | 451 | d->needToSendAllDocLinks = true; |
452 | return; | 452 | return; |
453 | } | 453 | } |
454 | 454 | ||
455 | QString contents; | 455 | QString contents; |
456 | Categories cats; | 456 | Categories cats; |
457 | for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { | 457 | for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { |
458 | DocLnk *doc = it.current(); | 458 | DocLnk *doc = it.current(); |
459 | QFileInfo fi( doc->file() ); | 459 | QFileInfo fi( doc->file() ); |
460 | if ( !fi.exists() ) | 460 | if ( !fi.exists() ) |
461 | continue; | 461 | continue; |
462 | 462 | ||
463 | bool fake = !doc->linkFileKnown(); | 463 | bool fake = !doc->linkFileKnown(); |
464 | if ( !fake ) { | 464 | if ( !fake ) { |
465 | QFile f( doc->linkFile() ); | 465 | QFile f( doc->linkFile() ); |
466 | if ( f.open( IO_ReadOnly ) ) { | 466 | if ( f.open( IO_ReadOnly ) ) { |
467 | QTextStream ts( &f ); | 467 | QTextStream ts( &f ); |
468 | ts.setEncoding( QTextStream::UnicodeUTF8 ); | 468 | ts.setEncoding( QTextStream::UnicodeUTF8 ); |
469 | QString docLnk = ts.read(); | 469 | QString docLnk = ts.read(); |
470 | // Strip out the (stale) LinkFile entry | 470 | // Strip out the (stale) LinkFile entry |
471 | int start = docLnk.find( "\nLinkFile = " ) + 1; | 471 | int start = docLnk.find( "\nLinkFile = " ) + 1; |
472 | if ( start > 0 ) { | 472 | if ( start > 0 ) { |
473 | int end = docLnk.find( "\n", start + 1 ) + 1; | 473 | int end = docLnk.find( "\n", start + 1 ) + 1; |
474 | contents += docLnk.left(start); | 474 | contents += docLnk.left(start); |
475 | contents += docLnk.mid(end); | 475 | contents += docLnk.mid(end); |
476 | } else { | 476 | } else { |
477 | contents += docLnk; | 477 | contents += docLnk; |
478 | } | 478 | } |
479 | contents += "LinkFile = " + doc->linkFile() + "\n"; | 479 | contents += "LinkFile = " + doc->linkFile() + "\n"; |
480 | 480 | ||
481 | f.close(); | 481 | f.close(); |
482 | } else | 482 | } else |
483 | fake = TRUE; | 483 | fake = TRUE; |
484 | } | 484 | } |
485 | if (fake) { | 485 | if (fake) { |
486 | contents += "[Desktop Entry]\n"; // No tr | 486 | contents += "[Desktop Entry]\n"; // No tr |
487 | contents += "Categories = " + // No tr | 487 | contents += "Categories = " + // No tr |
488 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr | 488 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr |
489 | contents += "Name = "+doc->name()+"\n"; // No tr | 489 | contents += "Name = "+doc->name()+"\n"; // No tr |
490 | contents += "Type = "+doc->type()+"\n"; // No tr | 490 | contents += "Type = "+doc->type()+"\n"; // No tr |
491 | } | 491 | } |
492 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) | 492 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) |
493 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr | 493 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr |
494 | } | 494 | } |
495 | 495 | ||
496 | //odebug << "sending length " << contents.length() << "" << oendl; | 496 | //odebug << "sending length " << contents.length() << "" << oendl; |
497 | #ifndef QT_NO_COP | 497 | #ifndef QT_NO_COP |
498 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); | 498 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); |
499 | e << contents; | 499 | e << contents; |
500 | #endif | 500 | #endif |
501 | //odebug << "================ \n\n" << contents << "\n\n===============" << oendl; | 501 | //odebug << "================ \n\n" << contents << "\n\n===============" << oendl; |
502 | 502 | ||
503 | d->needToSendAllDocLinks = false; | 503 | d->needToSendAllDocLinks = false; |
504 | } | 504 | } |
505 | 505 | ||
506 | 506 | ||
507 | 507 | ||
508 | 508 | ||
509 | 509 | ||
510 | 510 | ||
511 | 511 | ||
512 | 512 | ||
513 | 513 | ||
514 | 514 | ||
515 | 515 | ||
516 | 516 | ||
517 | 517 | ||
518 | 518 | ||
519 | 519 | ||
520 | 520 | ||
521 | 521 | ||
522 | 522 | ||
523 | 523 | ||
524 | 524 | ||
525 | 525 | ||
526 | 526 | ||
527 | 527 | ||
528 | 528 | ||
529 | DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) | 529 | DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) |
530 | { | 530 | { |
531 | storage = new StorageInfo( this ); | 531 | storage = new StorageInfo( this ); |
532 | serverGui = gui; | 532 | serverGui = gui; |
533 | if ( serverGui ) { | 533 | if ( serverGui ) { |
534 | sendAppLnks = serverGui->requiresApplications(); | 534 | sendAppLnks = serverGui->requiresApplications(); |
535 | sendDocLnks = serverGui->requiresDocuments(); | 535 | sendDocLnks = serverGui->requiresDocuments(); |
536 | } else { | 536 | } else { |
537 | sendAppLnks = false; | 537 | sendAppLnks = false; |
538 | sendDocLnks = false; | 538 | sendDocLnks = false; |
539 | } | 539 | } |
540 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { | 540 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { |
541 | listDirs[i] = 0; | 541 | listDirs[i] = 0; |
542 | lists[i] = 0; | 542 | lists[i] = 0; |
543 | listPositions[i] = 0; | 543 | listPositions[i] = 0; |
544 | } | 544 | } |
545 | initialize(); | 545 | initialize(); |
546 | tid = 0; | 546 | tid = 0; |
547 | } | 547 | } |
548 | 548 | ||
549 | void DocumentListPrivate::appendDocpath(FileSystem*fs) | 549 | void DocumentListPrivate::appendDocpath(FileSystem*fs) |
550 | { | 550 | { |
551 | Config c( "qpe" ); | 551 | Config c( "qpe" ); |
552 | c.setGroup( "Startup" ); | 552 | c.setGroup( "Startup" ); |
553 | QDir defPath(fs->path()+"/Documents"); | 553 | QDir defPath(fs->path()+"/Documents"); |
554 | QFileInfo f(fs->path()+"/.opiestorage.cf"); | 554 | QFileInfo f(fs->path()+"/.opiestorage.cf"); |
555 | if ( c.readNumEntry( "FirstUse", 42 ) == 0 && !f.exists()) { | 555 | if ( c.readNumEntry( "FirstUse", 42 ) == 0 && !f.exists()) { |
556 | Mediadlg dlg(fs); | 556 | Mediadlg dlg(fs); |
557 | if (QDialog::Accepted != QPEApplication::execDialog( &dlg )) { | 557 | if (QDialog::Accepted != QPEApplication::execDialog( &dlg )) { |
558 | return; | 558 | return; |
559 | } | 559 | } |
560 | } | 560 | } |
561 | Config conf(f.filePath(), Config::File ); | 561 | Config conf(f.filePath(), Config::File ); |
562 | conf.setGroup("main"); | 562 | conf.setGroup("main"); |
563 | if (!conf.readBoolEntry("check",false)) { | 563 | if (!conf.readBoolEntry("check",false)) { |
564 | return; | 564 | return; |
565 | } | 565 | } |
566 | conf.setGroup("subdirs"); | 566 | conf.setGroup("subdirs"); |
567 | bool read_all = conf.readBoolEntry("wholemedia",true); | 567 | bool read_all = conf.readBoolEntry("wholemedia",true); |
568 | if (read_all) { | 568 | if (read_all) { |
569 | docPaths+=fs->path(); | 569 | docPaths+=fs->path(); |
570 | return; | 570 | return; |
571 | } | 571 | } |
572 | QStringList subDirs = conf.readListEntry("subdirs",':'); | 572 | QStringList subDirs = conf.readListEntry("subdirs",':'); |
573 | if (subDirs.isEmpty()) { | 573 | if (subDirs.isEmpty()) { |
574 | if (defPath.exists()) { | 574 | if (defPath.exists()) { |
575 | docPaths+=defPath.path(); | 575 | docPaths+=defPath.path(); |
576 | } | 576 | } |
577 | return; | 577 | return; |
578 | } | 578 | } |
579 | for (unsigned c = 0; c < subDirs.count();++c) { | 579 | for (unsigned c = 0; c < subDirs.count();++c) { |
580 | QDir docDir(QString(fs->path()+"/"+subDirs[c])); | 580 | QDir docDir(QString(fs->path()+"/"+subDirs[c])); |
581 | if (docDir.exists()) { | 581 | if (docDir.exists()) { |
582 | docPaths+=docDir.path(); | 582 | docPaths+=docDir.path(); |
583 | } | 583 | } |
584 | } | 584 | } |
585 | } | 585 | } |
586 | 586 | ||
587 | void DocumentListPrivate::initialize() | 587 | void DocumentListPrivate::initialize() |
588 | { | 588 | { |
589 | // Reset | 589 | // Reset |
590 | dls.clear(); | 590 | dls.clear(); |
591 | docPaths.clear(); | 591 | docPaths.clear(); |
592 | reference.clear(); | 592 | reference.clear(); |
593 | 593 | ||
594 | QDir docDir( QPEApplication::documentDir() ); | 594 | QDir docDir( QPEApplication::documentDir() ); |
595 | if ( docDir.exists() ) | 595 | if ( docDir.exists() ) |
596 | docPaths += QPEApplication::documentDir(); | 596 | docPaths += QPEApplication::documentDir(); |
597 | int i = 1; | 597 | int i = 1; |
598 | const QList<FileSystem> &fs = storage->fileSystems(); | 598 | const QList<FileSystem> &fs = storage->fileSystems(); |
599 | QListIterator<FileSystem> it( fs ); | 599 | QListIterator<FileSystem> it( fs ); |
600 | for ( ; it.current(); ++it ) { | 600 | for ( ; it.current(); ++it ) { |
601 | if ( (*it)->isRemovable() ) { | 601 | if ( (*it)->isRemovable() ) { |
602 | appendDocpath((*it)); | 602 | appendDocpath((*it)); |
603 | ++i; | 603 | ++i; |
604 | } | 604 | } |
605 | } | 605 | } |
606 | 606 | ||
607 | for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) { | 607 | for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) { |
608 | if ( listDirs[i] ) { | 608 | if ( listDirs[i] ) { |
609 | delete listDirs[i]; | 609 | delete listDirs[i]; |
610 | listDirs[i] = 0; | 610 | listDirs[i] = 0; |
611 | } | 611 | } |
612 | lists[i] = 0; | 612 | lists[i] = 0; |
613 | listPositions[i] = 0; | 613 | listPositions[i] = 0; |
614 | } | 614 | } |
615 | 615 | ||
616 | docPathsSearched = 0; | 616 | docPathsSearched = 0; |
617 | searchDepth = -1; | 617 | searchDepth = -1; |
618 | state = Find; | 618 | state = Find; |
619 | dit = 0; | 619 | dit = 0; |
620 | } | 620 | } |
621 | 621 | ||
622 | 622 | ||
623 | DocumentListPrivate::~DocumentListPrivate() | 623 | DocumentListPrivate::~DocumentListPrivate() |
624 | { | 624 | { |
625 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) | 625 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) |
626 | if ( listDirs[i] ) | 626 | if ( listDirs[i] ) |
627 | delete listDirs[i]; | 627 | delete listDirs[i]; |
628 | delete dit; | 628 | delete dit; |
629 | } | 629 | } |
630 | 630 | ||
631 | 631 | ||
632 | void DocumentListPrivate::estimatedPercentScanned() | 632 | void DocumentListPrivate::estimatedPercentScanned() |
633 | { | 633 | { |
634 | double overallProgress = 0.0; | 634 | double overallProgress = 0.0; |
635 | double levelWeight = 75.0; | 635 | double levelWeight = 75.0; |
636 | 636 | ||
637 | int topCount = docPaths.count(); | 637 | int topCount = docPaths.count(); |
638 | if ( topCount > 1 ) { | 638 | if ( topCount > 1 ) { |
639 | levelWeight = levelWeight / topCount; | 639 | levelWeight = levelWeight / topCount; |
640 | overallProgress += (docPathsSearched - 1) * levelWeight; | 640 | overallProgress += (docPathsSearched - 1) * levelWeight; |
641 | } | 641 | } |
642 | 642 | ||
643 | for ( int d = 0; d <= searchDepth; d++ ) { | 643 | for ( int d = 0; d <= searchDepth; d++ ) { |
644 | if ( listDirs[d] ) { | 644 | if ( listDirs[d] ) { |
645 | int items = lists[d]->count(); | 645 | int items = lists[d]->count(); |
646 | if ( items > 1 ) { | 646 | if ( items > 1 ) { |
647 | levelWeight = levelWeight / items; | 647 | levelWeight = levelWeight / items; |
648 | // Take in to account "." and ".." | 648 | // Take in to account "." and ".." |
649 | overallProgress += (listPositions[d] - 3) * levelWeight; | 649 | overallProgress += (listPositions[d] - 3) * levelWeight; |
650 | } | 650 | } |
651 | } else { | 651 | } else { |
652 | break; | 652 | break; |
653 | } | 653 | } |
654 | } | 654 | } |
655 | 655 | ||
656 | // odebug << "overallProgress: " << overallProgress << "" << oendl; | 656 | // odebug << "overallProgress: " << overallProgress << "" << oendl; |
657 | 657 | ||
658 | if ( serverGui ) | 658 | if ( serverGui ) |
659 | serverGui->documentScanningProgress( (int)overallProgress ); | 659 | serverGui->documentScanningProgress( (int)overallProgress ); |
660 | } | 660 | } |
661 | 661 | ||
662 | 662 | ||
663 | const QString DocumentListPrivate::nextFile() | 663 | const QString DocumentListPrivate::nextFile() |
664 | { | 664 | { |
665 | while ( TRUE ) { | 665 | while ( TRUE ) { |
666 | while ( searchDepth < 0 ) { | 666 | while ( searchDepth < 0 ) { |
667 | // go to next base path | 667 | // go to next base path |
668 | if ( docPathsSearched >= docPaths.count() ) { | 668 | if ( docPathsSearched >= docPaths.count() ) { |
669 | // end of base paths | 669 | // end of base paths |
670 | return QString::null; | 670 | return QString::null; |
671 | } else { | 671 | } else { |
672 | QDir dir( docPaths[docPathsSearched] ); | 672 | QDir dir( docPaths[docPathsSearched] ); |
673 | // odebug << "now using base path: " << docPaths[docPathsSearched] << "" << oendl; | 673 | // odebug << "now using base path: " << docPaths[docPathsSearched] << "" << oendl; |
674 | docPathsSearched++; | 674 | docPathsSearched++; |
675 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 675 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
676 | listDirs[0] = new QDir( dir ); | 676 | listDirs[0] = new QDir( dir ); |
677 | lists[0] = listDirs[0]->entryInfoList(); | 677 | lists[0] = listDirs[0]->entryInfoList(); |
678 | listPositions[0] = 0; | 678 | listPositions[0] = 0; |
679 | searchDepth = 0; | 679 | searchDepth = 0; |
680 | } | 680 | } |
681 | } | 681 | } |
682 | } | 682 | } |
683 | 683 | ||
684 | const QFileInfoList *fil = lists[searchDepth]; | 684 | const QFileInfoList *fil = lists[searchDepth]; |
685 | if (!fil) { | 685 | if (!fil) { |
686 | return QString::null; | 686 | return QString::null; |
687 | } | 687 | } |
688 | QFileInfoList *fl = (QFileInfoList *)fil; | 688 | QFileInfoList *fl = (QFileInfoList *)fil; |
689 | unsigned int pos = listPositions[searchDepth]; | 689 | unsigned int pos = listPositions[searchDepth]; |
690 | 690 | ||
691 | if ( pos >= fl->count() ) { | 691 | if ( pos >= fl->count() ) { |
692 | // go up a depth | 692 | // go up a depth |
693 | delete listDirs[searchDepth]; | 693 | delete listDirs[searchDepth]; |
694 | listDirs[searchDepth] = 0; | 694 | listDirs[searchDepth] = 0; |
695 | lists[searchDepth] = 0; | 695 | lists[searchDepth] = 0; |
696 | listPositions[searchDepth] = 0; | 696 | listPositions[searchDepth] = 0; |
697 | searchDepth--; | 697 | searchDepth--; |
698 | } else { | 698 | } else { |
699 | const QFileInfo *fi = fl->at(pos); | 699 | const QFileInfo *fi = fl->at(pos); |
700 | listPositions[searchDepth]++; | 700 | listPositions[searchDepth]++; |
701 | QString bn = fi->fileName(); | 701 | QString bn = fi->fileName(); |
702 | if ( bn[0] != '.' ) { | 702 | if ( bn[0] != '.' ) { |
703 | if ( fi->isDir() ) { | 703 | if ( fi->isDir() ) { |
704 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { | 704 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" |
705 | && bn != "proc" && bn != "dev" && bn != "bin" && bn != "usr" | ||
706 | && bn != "etc" && bn != "lib" && bn != "sbin" && bn != "tmp" && bn != "var") { | ||
705 | // go down a depth | 707 | // go down a depth |
706 | QDir dir( fi->filePath() ); | 708 | QDir dir( fi->filePath() ); |
707 | // odebug << "now going in to path: " << bn << "" << oendl; | 709 | // odebug << "now going in to path: " << bn << "" << oendl; |
708 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 710 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
709 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { | 711 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { |
710 | searchDepth++; | 712 | searchDepth++; |
711 | listDirs[searchDepth] = new QDir( dir ); | 713 | listDirs[searchDepth] = new QDir( dir ); |
712 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); | 714 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); |
713 | listPositions[searchDepth] = 0; | 715 | listPositions[searchDepth] = 0; |
714 | } | 716 | } |
715 | } | 717 | } |
716 | } | 718 | } |
717 | } else { | 719 | } else { |
718 | estimatedPercentScanned(); | 720 | estimatedPercentScanned(); |
719 | return fl->at(pos)->filePath(); | 721 | return fl->at(pos)->filePath(); |
720 | } | 722 | } |
721 | } | 723 | } |
722 | } | 724 | } |
723 | } | 725 | } |
724 | 726 | ||
725 | return QString::null; | 727 | return QString::null; |
726 | } | 728 | } |
727 | 729 | ||
728 | 730 | ||
729 | bool DocumentListPrivate::store( DocLnk* dl ) | 731 | bool DocumentListPrivate::store( DocLnk* dl ) |
730 | { | 732 | { |
731 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { | 733 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { |
732 | if ( dl && dl->fileKnown() ) { | 734 | if ( dl && dl->fileKnown() ) { |
733 | dls.add( dl ); // store | 735 | dls.add( dl ); // store |
734 | return TRUE; | 736 | return TRUE; |
735 | } | 737 | } |
736 | 738 | ||
737 | // don't store - delete | 739 | // don't store - delete |
738 | delete dl; | 740 | delete dl; |
739 | return FALSE; | 741 | return FALSE; |
740 | } | 742 | } |
741 | 743 | ||
742 | 744 | ||
743 | #define MAGIC_NUMBER ((void*)2) | 745 | #define MAGIC_NUMBER ((void*)2) |
744 | 746 | ||
745 | const DocLnk *DocumentListPrivate::iterate() | 747 | const DocLnk *DocumentListPrivate::iterate() |
746 | { | 748 | { |
747 | if ( state == Find ) { | 749 | if ( state == Find ) { |
748 | //odebug << "state Find" << oendl; | 750 | //odebug << "state Find" << oendl; |
749 | QString file = nextFile(); | 751 | QString file = nextFile(); |
750 | while ( !file.isNull() ) { | 752 | while ( !file.isNull() ) { |
751 | if ( file.right(8) == ".desktop" ) { // No tr | 753 | if ( file.right(8) == ".desktop" ) { // No tr |
752 | DocLnk* dl = new DocLnk( file ); | 754 | DocLnk* dl = new DocLnk( file ); |
753 | if ( store(dl) ) | 755 | if ( store(dl) ) |
754 | return dl; | 756 | return dl; |
755 | } else { | 757 | } else { |
756 | reference.insert( file, MAGIC_NUMBER ); | 758 | reference.insert( file, MAGIC_NUMBER ); |
757 | } | 759 | } |
758 | file = nextFile(); | 760 | file = nextFile(); |
759 | } | 761 | } |
760 | state = RemoveKnownFiles; | 762 | state = RemoveKnownFiles; |
761 | 763 | ||
762 | if ( serverGui ) | 764 | if ( serverGui ) |
763 | serverGui->documentScanningProgress( 75 ); | 765 | serverGui->documentScanningProgress( 75 ); |
764 | } | 766 | } |
765 | 767 | ||
766 | static int iterationI; | 768 | static int iterationI; |
767 | static int iterationCount; | 769 | static int iterationCount; |
768 | 770 | ||
769 | if ( state == RemoveKnownFiles ) { | 771 | if ( state == RemoveKnownFiles ) { |
770 | //odebug << "state RemoveKnownFiles" << oendl; | 772 | //odebug << "state RemoveKnownFiles" << oendl; |
771 | const QList<DocLnk> &list = dls.children(); | 773 | const QList<DocLnk> &list = dls.children(); |
772 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 774 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
773 | reference.remove( (*it)->file() ); | 775 | reference.remove( (*it)->file() ); |
774 | // ### does this need to be deleted? | 776 | // ### does this need to be deleted? |
775 | } | 777 | } |
776 | dit = new QDictIterator<void>(reference); | 778 | dit = new QDictIterator<void>(reference); |
777 | state = MakeUnknownFiles; | 779 | state = MakeUnknownFiles; |
778 | 780 | ||
779 | iterationI = 0; | 781 | iterationI = 0; |
780 | iterationCount = dit->count(); | 782 | iterationCount = dit->count(); |
781 | } | 783 | } |
782 | 784 | ||
783 | if ( state == MakeUnknownFiles ) { | 785 | if ( state == MakeUnknownFiles ) { |
784 | //odebug << "state MakeUnknownFiles" << oendl; | 786 | //odebug << "state MakeUnknownFiles" << oendl; |
785 | for (void* c; (c=dit->current()); ++(*dit) ) { | 787 | for (void* c; (c=dit->current()); ++(*dit) ) { |
786 | if ( c == MAGIC_NUMBER ) { | 788 | if ( c == MAGIC_NUMBER ) { |
787 | DocLnk* dl = new DocLnk; | 789 | DocLnk* dl = new DocLnk; |
788 | QFileInfo fi( dit->currentKey() ); | 790 | QFileInfo fi( dit->currentKey() ); |
789 | dl->setFile( fi.filePath() ); | 791 | dl->setFile( fi.filePath() ); |
790 | dl->setName( fi.baseName() ); | 792 | dl->setName( fi.baseName() ); |
791 | if ( store(dl) ) { | 793 | if ( store(dl) ) { |
792 | ++*dit; | 794 | ++*dit; |
793 | iterationI++; | 795 | iterationI++; |
794 | if ( serverGui ) | 796 | if ( serverGui ) |
795 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); | 797 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); |
796 | return dl; | 798 | return dl; |
797 | } | 799 | } |
798 | } | 800 | } |
799 | iterationI++; | 801 | iterationI++; |
800 | } | 802 | } |
801 | 803 | ||
802 | delete dit; | 804 | delete dit; |
803 | dit = 0; | 805 | dit = 0; |
804 | state = Done; | 806 | state = Done; |
805 | } | 807 | } |
806 | 808 | ||
807 | //odebug << "state Done" << oendl; | 809 | //odebug << "state Done" << oendl; |
808 | return NULL; | 810 | return NULL; |
809 | } | 811 | } |
810 | 812 | ||
811 | 813 | ||
812 | #include "documentlist.moc" | 814 | #include "documentlist.moc" |
813 | 815 | ||
814 | 816 | ||
815 | 817 | ||