summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
Unidiff
Diffstat (limited to 'library/applnk.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index e9d519e..1c1a227 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,541 +1,542 @@
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 20
21#define QTOPIA_INTERNAL_MIMEEXT 21#define QTOPIA_INTERNAL_MIMEEXT
22#define QTOPIA_INTERNAL_PRELOADACCESS 22#define QTOPIA_INTERNAL_PRELOADACCESS
23#define QTOPIA_INTERNAL_APPLNKASSIGN 23#define QTOPIA_INTERNAL_APPLNKASSIGN
24 24
25#include "applnk.h" 25#include "applnk.h"
26 26
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/categories.h> 28#include <qpe/categories.h>
29#include <qpe/categoryselect.h> 29#include <qpe/categoryselect.h>
30#include <qpe/global.h>
30#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
31#include <qpe/mimetype.h> 32#include <qpe/mimetype.h>
32#include <qpe/config.h> 33#include <qpe/config.h>
33#include <qpe/storage.h> 34#include <qpe/storage.h>
34#include <qpe/resource.h> 35#include <qpe/resource.h>
35 36
36#include <qdir.h> 37#include <qdir.h>
37 38
38 39
39#include <stdlib.h> 40#include <stdlib.h>
40 41
41int AppLnk::lastId = 5000; 42int AppLnk::lastId = 5000;
42 43
43static int smallSize = 14; 44static int smallSize = 14;
44static int bigSize = 32; 45static int bigSize = 32;
45 46
46static QString safeFileName(const QString& n) 47static QString safeFileName(const QString& n)
47{ 48{
48 QString safename=n; 49 QString safename=n;
49 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); 50 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
50 safename.replace(QRegExp("^[^A-Za-z]*"),""); 51 safename.replace(QRegExp("^[^A-Za-z]*"),"");
51 if ( safename.isEmpty() ) 52 if ( safename.isEmpty() )
52 safename = "_"; 53 safename = "_";
53 return safename; 54 return safename;
54} 55}
55 56
56static bool prepareDirectories(const QString& lf) 57static bool prepareDirectories(const QString& lf)
57{ 58{
58 if ( !QFile::exists(lf) ) { 59 if ( !QFile::exists(lf) ) {
59 // May need to create directories 60 // May need to create directories
60 QFileInfo fi(lf); 61 QFileInfo fi(lf);
61 if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) 62 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
62 return FALSE; 63 return FALSE;
63 } 64 }
64 return TRUE; 65 return TRUE;
65} 66}
66 67
67class AppLnkPrivate 68class AppLnkPrivate
68{ 69{
69public: 70public:
70 /* the size of the Pixmap */ 71 /* the size of the Pixmap */
71 enum Size {Normal = 0, Big }; 72 enum Size {Normal = 0, Big };
72 AppLnkPrivate() { 73 AppLnkPrivate() {
73 /* we want one normal and one big item */ 74 /* we want one normal and one big item */
74 75
75 QPixmap pix; 76 QPixmap pix;
76 mPixmaps.insert(0, pix ); 77 mPixmaps.insert(0, pix );
77 mPixmaps.insert(1, pix); 78 mPixmaps.insert(1, pix);
78 } 79 }
79 80
80 QStringList mCatList; // always correct 81 QStringList mCatList; // always correct
81 QArray<int> mCat; // cached value; correct if not empty 82 QArray<int> mCat; // cached value; correct if not empty
82 QMap<int, QPixmap> mPixmaps; 83 QMap<int, QPixmap> mPixmaps;
83 84
84 void updateCatListFromArray() 85 void updateCatListFromArray()
85 { 86 {
86 Categories cat( 0 ); 87 Categories cat( 0 );
87 cat.load( categoryFileName() ); 88 cat.load( categoryFileName() );
88 // we need to update the names for the mCat... to mCatList 89 // we need to update the names for the mCat... to mCatList
89 mCatList.clear(); 90 mCatList.clear();
90 for (uint i = 0; i < mCat.count(); i++ ) 91 for (uint i = 0; i < mCat.count(); i++ )
91 mCatList << cat.label("Document View", mCat[i] ); 92 mCatList << cat.label("Document View", mCat[i] );
92 93
93 } 94 }
94 95
95 void setCatArrayDirty() 96 void setCatArrayDirty()
96 { 97 {
97 mCat.resize(0); 98 mCat.resize(0);
98 } 99 }
99 100
100 void ensureCatArray() 101 void ensureCatArray()
101 { 102 {
102 if ( mCat.count() > 0 || mCatList.count()==0 ) 103 if ( mCat.count() > 0 || mCatList.count()==0 )
103 return; 104 return;
104 105
105 Categories cat( 0 ); 106 Categories cat( 0 );
106 cat.load( categoryFileName() ); 107 cat.load( categoryFileName() );
107 mCat.resize( mCatList.count() ); 108 mCat.resize( mCatList.count() );
108 int i; 109 int i;
109 QStringList::ConstIterator it; 110 QStringList::ConstIterator it;
110 for ( i = 0, it = mCatList.begin(); it != mCatList.end(); 111 for ( i = 0, it = mCatList.begin(); it != mCatList.end();
111 ++it, i++ ) { 112 ++it, i++ ) {
112 113
113 bool number; 114 bool number;
114 int id = (*it).toInt( &number ); 115 int id = (*it).toInt( &number );
115 if ( !number ) { 116 if ( !number ) {
116 id = cat.id( "Document View", *it ); 117 id = cat.id( "Document View", *it );
117 if ( id == 0 ) 118 if ( id == 0 )
118 id = cat.addCategory( "Document View", *it ); 119 id = cat.addCategory( "Document View", *it );
119 } 120 }
120 mCat[i] = id; 121 mCat[i] = id;
121 } 122 }
122 } 123 }
123}; 124};
124 125
125/*! 126/*!
126 \class AppLnk applnk.h 127 \class AppLnk applnk.h
127 \brief The AppLnk class represents an application available on the system. 128 \brief The AppLnk class represents an application available on the system.
128 129
129 Every Qtopia application \e app has a corresponding \e app.desktop 130 Every Qtopia application \e app has a corresponding \e app.desktop
130 file. When one of these files is read its data is stored as an 131 file. When one of these files is read its data is stored as an
131 AppLnk object. 132 AppLnk object.
132 133
133 The AppLnk class introduces some Qtopia-specific concepts, and 134 The AppLnk class introduces some Qtopia-specific concepts, and
134 provides a variety of functions, as described in the following 135 provides a variety of functions, as described in the following
135 sections. 136 sections.
136 \tableofcontents 137 \tableofcontents
137 138
138 \target Types 139 \target Types
139 \section1 Types 140 \section1 Types
140 141
141 Every AppLnk object has a \e type. For applications, games and 142 Every AppLnk object has a \e type. For applications, games and
142 settings the type is \c Application; for documents the 143 settings the type is \c Application; for documents the
143 type is the document's MIME type. 144 type is the document's MIME type.
144 145
145 \target files-and-links 146 \target files-and-links
146 \section1 Files and Links 147 \section1 Files and Links
147 148
148 When you create an AppLnk (or more likely, a \link doclnk.html 149 When you create an AppLnk (or more likely, a \link doclnk.html
149 DocLnk\endlink), you don't deal directly with filenames in the 150 DocLnk\endlink), you don't deal directly with filenames in the
150 filesystem. Instead you do this: 151 filesystem. Instead you do this:
151 \code 152 \code
152 DocLnk d; 153 DocLnk d;
153 d.setType("text/plain"); 154 d.setType("text/plain");
154 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. 155 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal.
155 \endcode 156 \endcode
156 At this point, the file() and linkFile() are unknown. Normally 157 At this point, the file() and linkFile() are unknown. Normally
157 this is uninteresting, and the names become automatically known, 158 this is uninteresting, and the names become automatically known,
158 and more importantly, becomes reserved, when you ask what they are: 159 and more importantly, becomes reserved, when you ask what they are:
159 160
160 \code 161 \code
161 QString fn = d.file(); 162 QString fn = d.file();
162 \endcode 163 \endcode
163 This invents a filename, and creates the file on disk (an empty 164 This invents a filename, and creates the file on disk (an empty
164 reservation file) to prevent the name being used by another 165 reservation file) to prevent the name being used by another
165 application. 166 application.
166 167
167 In some circumstances, you don't want to create the file if it 168 In some circumstances, you don't want to create the file if it
168 doesn't already exist (e.g. in the Document tab, some of the \link 169 doesn't already exist (e.g. in the Document tab, some of the \link
169 doclnk.html DocLnk\endlink objects represented by icons are 170 doclnk.html DocLnk\endlink objects represented by icons are
170 DocLnk's created just for that view - they don't have 171 DocLnk's created just for that view - they don't have
171 corresponding \c .desktop files. To avoid littering empty 172 corresponding \c .desktop files. To avoid littering empty
172 reservation files around, we check in a few places to see whether 173 reservation files around, we check in a few places to see whether
173 the file really needs to exist). 174 the file really needs to exist).
174 175
175 \section1 Functionality 176 \section1 Functionality
176 177
177 AppLnk objects are created by calling the constructor with the 178 AppLnk objects are created by calling the constructor with the
178 name of a \e .desktop file. The object can be checked for validity 179 name of a \e .desktop file. The object can be checked for validity
179 using isValid(). 180 using isValid().
180 181
181 The following functions are used to set or retrieve information 182 The following functions are used to set or retrieve information
182 about the application: 183 about the application:
183 \table 184 \table
184 \header \i Get Function \i Set Function \i Short Description 185 \header \i Get Function \i Set Function \i Short Description
185 \row \i \l name() \i \l setName() \i application's name 186 \row \i \l name() \i \l setName() \i application's name
186 \row \i \l pixmap() \i \e none \i application's icon 187 \row \i \l pixmap() \i \e none \i application's icon
187 \row \i \l bigPixmap() \i \e none \i application's large icon 188 \row \i \l bigPixmap() \i \e none \i application's large icon
188 \row \i \e none \i setIcon() \i sets the icon's filename 189 \row \i \e none \i setIcon() \i sets the icon's filename
189 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above 190 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above
190 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees 191 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees
191 \row \i \l comment() \i \l setComment() \i text for the Details dialog 192 \row \i \l comment() \i \l setComment() \i text for the Details dialog
192 \row \i \l exec() \i \l setExec() \i executable's filename 193 \row \i \l exec() \i \l setExec() \i executable's filename
193 \row \i \l file() \i \e none \i document's filename 194 \row \i \l file() \i \e none \i document's filename
194 \row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename 195 \row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename
195 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit 196 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit
196 \row \i \l categories() \i \l setCategories() \i \e{see the function descriptions} 197 \row \i \l categories() \i \l setCategories() \i \e{see the function descriptions}
197 \row \i \l fileKnown() \i \e none \i see \link 198 \row \i \l fileKnown() \i \e none \i see \link
198#files-and-links Files and Links\endlink above 199#files-and-links Files and Links\endlink above
199 \row \i \l linkFileKnown() \i \e none \i see \link 200 \row \i \l linkFileKnown() \i \e none \i see \link
200#files-and-links Files and Links\endlink above 201#files-and-links Files and Links\endlink above
201 \row \i \l property() \i \l setProperty() \i any AppLnk property 202 \row \i \l property() \i \l setProperty() \i any AppLnk property
202 can be retrieved or set (if writeable) using these 203 can be retrieved or set (if writeable) using these
203 \endtable 204 \endtable
204 205
205 To save an AppLnk to disk use writeLink(). To execute the 206 To save an AppLnk to disk use writeLink(). To execute the
206 application that the AppLnk object refers to, use execute(). 207 application that the AppLnk object refers to, use execute().
207 208
208 AppLnk's can be deleted from disk using removeLinkFile(). To 209 AppLnk's can be deleted from disk using removeLinkFile(). To
209 remove both the link and the application's executable use 210 remove both the link and the application's executable use
210 removeFiles(). 211 removeFiles().
211 212
212 Icon sizes can be globally changed (but only for AppLnk objects 213 Icon sizes can be globally changed (but only for AppLnk objects
213 created after the calls) with setSmallIconSize() and 214 created after the calls) with setSmallIconSize() and
214 setBigIconSize(). 215 setBigIconSize().
215 216
216 \ingroup qtopiaemb 217 \ingroup qtopiaemb
217*/ 218*/
218 219
219/*! 220/*!
220 Sets the size used for small icons to \a small pixels. 221 Sets the size used for small icons to \a small pixels.
221 Only affects AppLnk objects created after the call. 222 Only affects AppLnk objects created after the call.
222 223
223 \sa smallIconSize() setIcon() 224 \sa smallIconSize() setIcon()
224*/ 225*/
225void AppLnk::setSmallIconSize(int small) 226void AppLnk::setSmallIconSize(int small)
226{ 227{
227 smallSize = small; 228 smallSize = small;
228} 229}
229 230
230/*! 231/*!
231 Returns the size used for small icons. 232 Returns the size used for small icons.
232 233
233 \sa setSmallIconSize() setIcon() 234 \sa setSmallIconSize() setIcon()
234*/ 235*/
235int AppLnk::smallIconSize() 236int AppLnk::smallIconSize()
236{ 237{
237 return smallSize; 238 return smallSize;
238} 239}
239 240
240 241
241/*! 242/*!
242 Sets the size used for large icons to \a big pixels. 243 Sets the size used for large icons to \a big pixels.
243 Only affects AppLnk objects created after the call. 244 Only affects AppLnk objects created after the call.
244 245
245 \sa bigIconSize() setIcon() 246 \sa bigIconSize() setIcon()
246*/ 247*/
247void AppLnk::setBigIconSize(int big) 248void AppLnk::setBigIconSize(int big)
248{ 249{
249 bigSize = big; 250 bigSize = big;
250} 251}
251 252
252/*! 253/*!
253 Returns the size used for large icons. 254 Returns the size used for large icons.
254 255
255 \sa setBigIconSize() setIcon() 256 \sa setBigIconSize() setIcon()
256*/ 257*/
257int AppLnk::bigIconSize() 258int AppLnk::bigIconSize()
258{ 259{
259 return bigSize; 260 return bigSize;
260} 261}
261 262
262 263
263/*! 264/*!
264 \fn QString AppLnk::name() const 265 \fn QString AppLnk::name() const
265 266
266 Returns the Name property. This is the user-visible name for the 267 Returns the Name property. This is the user-visible name for the
267 document or application, not the filename. 268 document or application, not the filename.
268 269
269 See \link #files-and-links Files and Links\endlink. 270 See \link #files-and-links Files and Links\endlink.
270 271
271 \sa setName() 272 \sa setName()
272*/ 273*/
273/*! 274/*!
274 \fn QString AppLnk::exec() const 275 \fn QString AppLnk::exec() const
275 276
276 Returns the Exec property. This is the name of the executable 277 Returns the Exec property. This is the name of the executable
277 program associated with the AppLnk. 278 program associated with the AppLnk.
278 279
279 \sa setExec() 280 \sa setExec()
280*/ 281*/
281/*! 282/*!
282 \fn QString AppLnk::rotation() const 283 \fn QString AppLnk::rotation() const
283 284
284 Returns the Rotation property. The value is 0, 90, 180 or 270 285 Returns the Rotation property. The value is 0, 90, 180 or 270
285 degrees. 286 degrees.
286*/ 287*/
287/*! 288/*!
288 \fn QString AppLnk::comment() const 289 \fn QString AppLnk::comment() const
289 290
290 Returns the Comment property. 291 Returns the Comment property.
291 292
292 \sa setComment() 293 \sa setComment()
293*/ 294*/
294/*! 295/*!
295 \fn QStringList AppLnk::mimeTypes() const 296 \fn QStringList AppLnk::mimeTypes() const
296 297
297 Returns the MimeTypes property. This is the list of MIME types 298 Returns the MimeTypes property. This is the list of MIME types
298 that the application can view or edit. 299 that the application can view or edit.
299*/ 300*/
300/*! 301/*!
301 \fn const QArray<int>& AppLnk::categories() const 302 \fn const QArray<int>& AppLnk::categories() const
302 303
303 Returns the Categories property. 304 Returns the Categories property.
304 305
305 See the CategoryWidget for more details. 306 See the CategoryWidget for more details.
306 307
307 \sa setCategories() 308 \sa setCategories()
308*/ 309*/
309 310
310const QArray<int>& AppLnk::categories() const 311const QArray<int>& AppLnk::categories() const
311{ 312{
312 d->ensureCatArray(); 313 d->ensureCatArray();
313 return d->mCat; 314 return d->mCat;
314} 315}
315 316
316/*! 317/*!
317 \fn int AppLnk::id() const 318 \fn int AppLnk::id() const
318 319
319 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, 320 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet,
320 this value is 0, otherwise it is a value that is unique for the 321 this value is 0, otherwise it is a value that is unique for the
321 duration of the current process. 322 duration of the current process.
322 323
323 \sa AppLnkSet::find() 324 \sa AppLnkSet::find()
324*/ 325*/
325 326
326/*! 327/*!
327 \fn bool AppLnk::isValid() const 328 \fn bool AppLnk::isValid() const
328 329
329 Returns TRUE if this AppLnk is valid; otherwise returns FALSE. 330 Returns TRUE if this AppLnk is valid; otherwise returns FALSE.
330*/ 331*/
331/*! 332/*!
332 \fn bool AppLnk::fileKnown() const 333 \fn bool AppLnk::fileKnown() const
333 334
334 If the with the AppLnk associated file is not equal to QString::null 335 If the with the AppLnk associated file is not equal to QString::null
335*/ 336*/
336/*! 337/*!
337 \fn bool AppLnk::linkFileKnown()const 338 \fn bool AppLnk::linkFileKnown()const
338 339
339 The filename of the AppLnk 340 The filename of the AppLnk
340 341
341*/ 342*/
342/*! 343/*!
343 \fn void AppLnk::setRotation( const QString& ) 344 \fn void AppLnk::setRotation( const QString& )
344 345
345 The default rotation of the associated application. This 346 The default rotation of the associated application. This
346 function is included inline for binary compatible issues 347 function is included inline for binary compatible issues
347*/ 348*/
348/*! 349/*!
349 Creates an invalid AppLnk. 350 Creates an invalid AppLnk.
350 351
351 \sa isValid() 352 \sa isValid()
352*/ 353*/
353AppLnk::AppLnk() 354AppLnk::AppLnk()
354{ 355{
355 mId = 0; 356 mId = 0;
356 d = new AppLnkPrivate(); 357 d = new AppLnkPrivate();
357} 358}
358 359
359/*! 360/*!
360 Loads \a file (e.g. \e app.desktop) as an AppLnk. 361 Loads \a file (e.g. \e app.desktop) as an AppLnk.
361 362
362 \sa writeLink() 363 \sa writeLink()
363*/ 364*/
364AppLnk::AppLnk( const QString &file ) 365AppLnk::AppLnk( const QString &file )
365{ 366{
366 QStringList sl; 367 QStringList sl;
367 d = new AppLnkPrivate(); 368 d = new AppLnkPrivate();
368 if ( !file.isNull() ) { 369 if ( !file.isNull() ) {
369 Config config( file, Config::File ); 370 Config config( file, Config::File );
370 371
371 if ( config.isValid() ) { 372 if ( config.isValid() ) {
372 config.setGroup( "Desktop Entry" ); 373 config.setGroup( "Desktop Entry" );
373 374
374 mName = config.readEntry( "Name", file ); 375 mName = config.readEntry( "Name", file );
375 mExec = config.readEntry( "Exec" ); 376 mExec = config.readEntry( "Exec" );
376 mType = config.readEntry( "Type", QString::null ); 377 mType = config.readEntry( "Type", QString::null );
377 mIconFile = config.readEntry( "Icon", QString::null ); 378 mIconFile = config.readEntry( "Icon", QString::null );
378 mRotation = config.readEntry( "Rotation", "" ); 379 mRotation = config.readEntry( "Rotation", "" );
379 mComment = config.readEntry( "Comment", QString::null ); 380 mComment = config.readEntry( "Comment", QString::null );
380 // MIME types are case-insensitive. 381 // MIME types are case-insensitive.
381 mMimeTypes = config.readListEntry( "MimeType", ';' ); 382 mMimeTypes = config.readListEntry( "MimeType", ';' );
382 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) 383 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
383 *it = (*it).lower(); 384 *it = (*it).lower();
384 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 385 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
385 mLinkFile = file; 386 mLinkFile = file;
386 mFile = config.readEntry("File", QString::null); 387 mFile = config.readEntry("File", QString::null);
387 if ( !mExec. isEmpty ( )) { 388 if ( !mExec. isEmpty ( )) {
388 mFile = QString::null; 389 mFile = QString::null;
389 } 390 }
390 else if ( mFile[0] != '/' ) { 391 else if ( mFile[0] != '/' ) {
391 int slash = file.findRev('/'); 392 int slash = file.findRev('/');
392 if ( slash >= 0 ) { 393 if ( slash >= 0 ) {
393 mFile = file.left(slash) + '/' + mFile; 394 mFile = file.left(slash) + '/' + mFile;
394 } 395 }
395 } 396 }
396 d->mCatList = config.readListEntry("Categories", ';'); 397 d->mCatList = config.readListEntry("Categories", ';');
397 if ( d->mCatList[0].toInt() < -1 ) { 398 if ( d->mCatList[0].toInt() < -1 ) {
398 // numeric cats in file! convert to text 399 // numeric cats in file! convert to text
399 Categories cat( 0 ); 400 Categories cat( 0 );
400 cat.load( categoryFileName() ); 401 cat.load( categoryFileName() );
401 d->mCat.resize( d->mCatList.count() ); 402 d->mCat.resize( d->mCatList.count() );
402 int i; 403 int i;
403 QStringList::ConstIterator it; 404 QStringList::ConstIterator it;
404 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); 405 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
405 ++it, i++ ) { 406 ++it, i++ ) {
406 bool number; 407 bool number;
407 int id = (*it).toInt( &number ); 408 int id = (*it).toInt( &number );
408 if ( !number ) { 409 if ( !number ) {
409 // convert from text 410 // convert from text
410 id = cat.id( "Document View", *it ); 411 id = cat.id( "Document View", *it );
411 if ( id == 0 ) 412 if ( id == 0 )
412 id = cat.addCategory( "Document View", *it ); 413 id = cat.addCategory( "Document View", *it );
413 } 414 }
414 d->mCat[i] = id; 415 d->mCat[i] = id;
415 } 416 }
416 d->updateCatListFromArray(); 417 d->updateCatListFromArray();
417 } 418 }
418 } 419 }
419 } 420 }
420 mId = 0; 421 mId = 0;
421} 422}
422 423
423AppLnk& AppLnk::operator=(const AppLnk &copy) 424AppLnk& AppLnk::operator=(const AppLnk &copy)
424{ 425{
425 if ( this == &copy ) return *this; 426 if ( this == &copy ) return *this;
426 if ( mId ) 427 if ( mId )
427 qWarning("Deleting AppLnk that is in an AppLnkSet"); 428 qWarning("Deleting AppLnk that is in an AppLnkSet");
428 if ( d ) 429 if ( d )
429 delete d; 430 delete d;
430 431
431 432
432 mName = copy.mName; 433 mName = copy.mName;
433 434
434 /* remove for Qtopia 3.0 -zecke */ 435 /* remove for Qtopia 3.0 -zecke */
435 mPixmap = copy.mPixmap; 436 mPixmap = copy.mPixmap;
436 mBigPixmap = copy.mBigPixmap; 437 mBigPixmap = copy.mBigPixmap;
437 438
438 mExec = copy.mExec; 439 mExec = copy.mExec;
439 mType = copy.mType; 440 mType = copy.mType;
440 mRotation = copy.mRotation; 441 mRotation = copy.mRotation;
441 mComment = copy.mComment; 442 mComment = copy.mComment;
442 mFile = copy.mFile; 443 mFile = copy.mFile;
443 mLinkFile = copy.mLinkFile; 444 mLinkFile = copy.mLinkFile;
444 mIconFile = copy.mIconFile; 445 mIconFile = copy.mIconFile;
445 mMimeTypes = copy.mMimeTypes; 446 mMimeTypes = copy.mMimeTypes;
446 mMimeTypeIcons = copy.mMimeTypeIcons; 447 mMimeTypeIcons = copy.mMimeTypeIcons;
447 mId = 0; 448 mId = 0;
448 d = new AppLnkPrivate(); 449 d = new AppLnkPrivate();
449 d->mCat = copy.d->mCat; 450 d->mCat = copy.d->mCat;
450 d->mCatList = copy.d->mCatList; 451 d->mCatList = copy.d->mCatList;
451 d->mPixmaps = copy.d->mPixmaps; 452 d->mPixmaps = copy.d->mPixmaps;
452 453
453 return *this; 454 return *this;
454} 455}
455/*! 456/*!
456 protected internally to share code 457 protected internally to share code
457 should I document that at all? 458 should I document that at all?
458 I don't know the TT style for that 459 I don't know the TT style for that
459*/ 460*/
460const QPixmap& AppLnk::pixmap( int pos, int size ) const { 461const QPixmap& AppLnk::pixmap( int pos, int size ) const {
461 if ( d->mPixmaps[pos].isNull() ) { 462 if ( d->mPixmaps[pos].isNull() ) {
462 AppLnk* that = (AppLnk*)this; 463 AppLnk* that = (AppLnk*)this;
463 if ( mIconFile.isEmpty() ) { 464 if ( mIconFile.isEmpty() ) {
464 MimeType mt(type()); 465 MimeType mt(type());
465 that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap(); 466 that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap();
466 if ( that->d->mPixmaps[pos].isNull() ) 467 if ( that->d->mPixmaps[pos].isNull() )
467 that->d->mPixmaps[pos].convertFromImage( 468 that->d->mPixmaps[pos].convertFromImage(
468 Resource::loadImage("UnknownDocument") 469 Resource::loadImage("UnknownDocument")
469 .smoothScale( size, size ) ); 470 .smoothScale( size, size ) );
470 return that->d->mPixmaps[pos]; 471 return that->d->mPixmaps[pos];
471 } 472 }
472 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 473 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
473 if ( unscaledIcon.isNull() ) { 474 if ( unscaledIcon.isNull() ) {
474 // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); 475 // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
475 that->d->mPixmaps[pos].convertFromImage( 476 that->d->mPixmaps[pos].convertFromImage(
476 Resource::loadImage("UnknownDocument") 477 Resource::loadImage("UnknownDocument")
477 .smoothScale( size, size ) ); 478 .smoothScale( size, size ) );
478 } else { 479 } else {
479 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 480 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
480 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 481 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
481 } 482 }
482 return that->d->mPixmaps[pos]; 483 return that->d->mPixmaps[pos];
483 } 484 }
484 return d->mPixmaps[pos]; 485 return d->mPixmaps[pos];
485} 486}
486 487
487/*! 488/*!
488 Returns a small pixmap associated with the application. 489 Returns a small pixmap associated with the application.
489 490
490 \sa bigPixmap() setIcon() 491 \sa bigPixmap() setIcon()
491*/ 492*/
492const QPixmap& AppLnk::pixmap() const 493const QPixmap& AppLnk::pixmap() const
493{ 494{
494 if ( d->mPixmaps[0].isNull() ) { 495 if ( d->mPixmaps[0].isNull() ) {
495 return pixmap(AppLnkPrivate::Normal, smallSize ); 496 return pixmap(AppLnkPrivate::Normal, smallSize );
496 } 497 }
497 return d->mPixmaps[0]; 498 return d->mPixmaps[0];
498} 499}
499 500
500/*! 501/*!
501 Returns a large pixmap associated with the application. 502 Returns a large pixmap associated with the application.
502 503
503 \sa pixmap() setIcon() 504 \sa pixmap() setIcon()
504*/ 505*/
505const QPixmap& AppLnk::bigPixmap() const 506const QPixmap& AppLnk::bigPixmap() const
506{ 507{
507 if ( d->mPixmaps[1].isNull() ) { 508 if ( d->mPixmaps[1].isNull() ) {
508 return pixmap( AppLnkPrivate::Big, bigSize ); 509 return pixmap( AppLnkPrivate::Big, bigSize );
509 } 510 }
510 return d->mPixmaps[1]; 511 return d->mPixmaps[1];
511} 512}
512 513
513/*! 514/*!
514 Returns the type of the AppLnk. For applications, games and 515 Returns the type of the AppLnk. For applications, games and
515 settings the type is \c Application; for documents the type is the 516 settings the type is \c Application; for documents the type is the
516 document's MIME type. 517 document's MIME type.
517*/ 518*/
518QString AppLnk::type() const 519QString AppLnk::type() const
519{ 520{
520 if ( mType.isNull() ) { 521 if ( mType.isNull() ) {
521 AppLnk* that = (AppLnk*)this; 522 AppLnk* that = (AppLnk*)this;
522 QString f = file(); 523 QString f = file();
523 if ( !f.isNull() ) { 524 if ( !f.isNull() ) {
524 MimeType mt(f); 525 MimeType mt(f);
525 that->mType = mt.id(); 526 that->mType = mt.id();
526 return that->mType; 527 return that->mType;
527 } 528 }
528 } 529 }
529 return mType; 530 return mType;
530} 531}
531 532
532/*! 533/*!
533 Returns the file associated with the AppLnk. 534 Returns the file associated with the AppLnk.
534 535
535 \sa exec() name() 536 \sa exec() name()
536*/ 537*/
537QString AppLnk::file() const 538QString AppLnk::file() const
538{ 539{
539 if ( mExec.isEmpty ( ) && mFile.isNull() ) { 540 if ( mExec.isEmpty ( ) && mFile.isNull() ) {
540 AppLnk* that = (AppLnk*)this; 541 AppLnk* that = (AppLnk*)this;
541 QString ext = MimeType(mType).extension(); 542 QString ext = MimeType(mType).extension();