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,157 +1,158 @@
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,