summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
authorzecke <zecke>2002-09-10 14:21:14 (UTC)
committer zecke <zecke>2002-09-10 14:21:14 (UTC)
commit8b59b498892b0e345d977ccd520087b660a91437 (patch) (unidiff)
tree4b9fef30cc51cce8e50c072038d15d8e10b29fb2 /library/applnk.cpp
parent4aad041a733e2478ff29330e1544e5fefcfb5cde (diff)
downloadopie-8b59b498892b0e345d977ccd520087b660a91437.zip
opie-8b59b498892b0e345d977ccd520087b660a91437.tar.gz
opie-8b59b498892b0e345d977ccd520087b660a91437.tar.bz2
AppLnk fix QArray -> QMAp
Diffstat (limited to 'library/applnk.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 298581a..41b3008 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,183 +1,186 @@
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#ifdef QWS 30#ifdef QWS
31#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
32#endif 32#endif
33#include <qpe/global.h> 33#include <qpe/global.h>
34#include <qpe/mimetype.h> 34#include <qpe/mimetype.h>
35#include <qpe/config.h> 35#include <qpe/config.h>
36#include <qpe/storage.h> 36#include <qpe/storage.h>
37#include <qpe/resource.h> 37#include <qpe/resource.h>
38 38
39#include <qdict.h> 39#include <qdict.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qregexp.h> 41#include <qregexp.h>
42 42
43#ifdef Q_WS_QWS 43#ifdef Q_WS_QWS
44#include <qgfx_qws.h> 44#include <qgfx_qws.h>
45#endif 45#endif
46 46
47#include <stdlib.h> 47#include <stdlib.h>
48 48
49int AppLnk::lastId = 5000; 49int AppLnk::lastId = 5000;
50 50
51static int smallSize = 14; 51static int smallSize = 14;
52static int bigSize = 32; 52static int bigSize = 32;
53 53
54static QString safeFileName(const QString& n) 54static QString safeFileName(const QString& n)
55{ 55{
56 QString safename=n; 56 QString safename=n;
57 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); 57 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
58 safename.replace(QRegExp("^[^A-Za-z]*"),""); 58 safename.replace(QRegExp("^[^A-Za-z]*"),"");
59 if ( safename.isEmpty() ) 59 if ( safename.isEmpty() )
60 safename = "_"; 60 safename = "_";
61 return safename; 61 return safename;
62} 62}
63 63
64static bool prepareDirectories(const QString& lf) 64static bool prepareDirectories(const QString& lf)
65{ 65{
66 if ( !QFile::exists(lf) ) { 66 if ( !QFile::exists(lf) ) {
67 // May need to create directories 67 // May need to create directories
68 QFileInfo fi(lf); 68 QFileInfo fi(lf);
69 if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) 69 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
70 return FALSE; 70 return FALSE;
71 } 71 }
72 return TRUE; 72 return TRUE;
73} 73}
74 74
75class AppLnkPrivate 75class AppLnkPrivate
76{ 76{
77public: 77public:
78 /* the size of the Pixmap */ 78 /* the size of the Pixmap */
79 enum Size {Normal = 0, Big }; 79 enum Size {Normal = 0, Big };
80 AppLnkPrivate() { 80 AppLnkPrivate() {
81 /* we want one normal and one big item */ 81 /* we want one normal and one big item */
82 mPixmaps = QArray<QPixmap>(2); 82
83 QPixmap pix;
84 mPixmaps.insert(0, pix );
85 mPixmaps.insert(1, pix);
83 } 86 }
84 87
85 QStringList mCatList; // always correct 88 QStringList mCatList; // always correct
86 QArray<int> mCat; // cached value; correct if not empty 89 QArray<int> mCat; // cached value; correct if not empty
87 QArray<QPixmap> mPixmaps; 90 QMap<int, QPixmap> mPixmaps;
88 91
89 void updateCatListFromArray() 92 void updateCatListFromArray()
90 { 93 {
91 Categories cat( 0 ); 94 Categories cat( 0 );
92 cat.load( categoryFileName() ); 95 cat.load( categoryFileName() );
93 mCatList = cat.labels("Document View",mCat); 96 mCatList = cat.labels("Document View",mCat);
94 } 97 }
95 98
96 void setCatArrayDirty() 99 void setCatArrayDirty()
97 { 100 {
98 mCat.resize(0); 101 mCat.resize(0);
99 } 102 }
100 103
101 void ensureCatArray() 104 void ensureCatArray()
102 { 105 {
103 if ( mCat.count() > 0 || mCatList.count()==0 ) 106 if ( mCat.count() > 0 || mCatList.count()==0 )
104 return; 107 return;
105 108
106 Categories cat( 0 ); 109 Categories cat( 0 );
107 cat.load( categoryFileName() ); 110 cat.load( categoryFileName() );
108 mCat.resize( mCatList.count() ); 111 mCat.resize( mCatList.count() );
109 int i; 112 int i;
110 QStringList::ConstIterator it; 113 QStringList::ConstIterator it;
111 for ( i = 0, it = mCatList.begin(); it != mCatList.end(); 114 for ( i = 0, it = mCatList.begin(); it != mCatList.end();
112 ++it, i++ ) { 115 ++it, i++ ) {
113 116
114 bool number; 117 bool number;
115 int id = (*it).toInt( &number ); 118 int id = (*it).toInt( &number );
116 if ( !number ) { 119 if ( !number ) {
117 id = cat.id( "Document View", *it ); 120 id = cat.id( "Document View", *it );
118 if ( id == 0 ) 121 if ( id == 0 )
119 id = cat.addCategory( "Document View", *it ); 122 id = cat.addCategory( "Document View", *it );
120 } 123 }
121 mCat[i] = id; 124 mCat[i] = id;
122 } 125 }
123 } 126 }
124}; 127};
125 128
126/*! 129/*!
127 \class AppLnk applnk.h 130 \class AppLnk applnk.h
128 \brief The AppLnk class represents an application available on the system. 131 \brief The AppLnk class represents an application available on the system.
129 132
130 Every Qtopia application \e app has a corresponding \e app.desktop 133 Every Qtopia application \e app has a corresponding \e app.desktop
131 file. When one of these files is read its data is stored as an 134 file. When one of these files is read its data is stored as an
132 AppLnk object. 135 AppLnk object.
133 136
134 The AppLnk class introduces some Qtopia-specific concepts, and 137 The AppLnk class introduces some Qtopia-specific concepts, and
135 provides a variety of functions, as described in the following 138 provides a variety of functions, as described in the following
136 sections. 139 sections.
137 \tableofcontents 140 \tableofcontents
138 141
139 \target Types 142 \target Types
140 \section1 Types 143 \section1 Types
141 144
142 Every AppLnk object has a \e type. For applications, games and 145 Every AppLnk object has a \e type. For applications, games and
143 settings the type is \c Application; for documents the 146 settings the type is \c Application; for documents the
144 type is the document's MIME type. 147 type is the document's MIME type.
145 148
146 \target files-and-links 149 \target files-and-links
147 \section1 Files and Links 150 \section1 Files and Links
148 151
149 When you create an AppLnk (or more likely, a \link doclnk.html 152 When you create an AppLnk (or more likely, a \link doclnk.html
150 DocLnk\endlink), you don't deal directly with filenames in the 153 DocLnk\endlink), you don't deal directly with filenames in the
151 filesystem. Instead you do this: 154 filesystem. Instead you do this:
152 \code 155 \code
153 DocLnk d; 156 DocLnk d;
154 d.setType("text/plain"); 157 d.setType("text/plain");
155 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. 158 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal.
156 \endcode 159 \endcode
157 At this point, the file() and linkFile() are unknown. Normally 160 At this point, the file() and linkFile() are unknown. Normally
158 this is uninteresting, and the names become automatically known, 161 this is uninteresting, and the names become automatically known,
159 and more importantly, becomes reserved, when you ask what they are: 162 and more importantly, becomes reserved, when you ask what they are:
160 163
161 \code 164 \code
162 QString fn = d.file(); 165 QString fn = d.file();
163 \endcode 166 \endcode
164 This invents a filename, and creates the file on disk (an empty 167 This invents a filename, and creates the file on disk (an empty
165 reservation file) to prevent the name being used by another 168 reservation file) to prevent the name being used by another
166 application. 169 application.
167 170
168 In some circumstances, you don't want to create the file if it 171 In some circumstances, you don't want to create the file if it
169 doesn't already exist (e.g. in the Document tab, some of the \link 172 doesn't already exist (e.g. in the Document tab, some of the \link
170 doclnk.html DocLnk\endlink objects represented by icons are 173 doclnk.html DocLnk\endlink objects represented by icons are
171 DocLnk's created just for that view - they don't have 174 DocLnk's created just for that view - they don't have
172 corresponding \c .desktop files. To avoid littering empty 175 corresponding \c .desktop files. To avoid littering empty
173 reservation files around, we check in a few places to see whether 176 reservation files around, we check in a few places to see whether
174 the file really needs to exist). 177 the file really needs to exist).
175 178
176 \section1 Functionality 179 \section1 Functionality
177 180
178 AppLnk objects are created by calling the constructor with the 181 AppLnk objects are created by calling the constructor with the
179 name of a \e .desktop file. The object can be checked for validity 182 name of a \e .desktop file. The object can be checked for validity
180 using isValid(). 183 using isValid().
181 184
182 The following functions are used to set or retrieve information 185 The following functions are used to set or retrieve information
183 about the application: 186 about the application: