summaryrefslogtreecommitdiff
authorzecke <zecke>2003-10-08 08:01:46 (UTC)
committer zecke <zecke>2003-10-08 08:01:46 (UTC)
commit5517443d9ebe96ff9c30d91b2254418964d5c410 (patch) (unidiff)
treedf0b7d5ca0bade7efba6182224402a30ffceec4b
parentb941b5b3e805e9d57cda58be73a6d4255fcb9e8b (diff)
downloadopie-5517443d9ebe96ff9c30d91b2254418964d5c410.zip
opie-5517443d9ebe96ff9c30d91b2254418964d5c410.tar.gz
opie-5517443d9ebe96ff9c30d91b2254418964d5c410.tar.bz2
include QPEApplication if you need it
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/oapplicationfactory.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/libopie/oapplicationfactory.h b/libopie/oapplicationfactory.h
index 418a82e..ab88d80 100644
--- a/libopie/oapplicationfactory.h
+++ b/libopie/oapplicationfactory.h
@@ -41,222 +41,224 @@ namespace Opie {
41 typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, 41 typename T10 = NullType, typename T11 = NullType, typename T12 = NullType,
42 typename T13 = NullType, typename T14 = NullType, typename T15 = NullType, 42 typename T13 = NullType, typename T14 = NullType, typename T15 = NullType,
43 typename T16 = NullType, typename T17 = NullType, typename T18 = NullType 43 typename T16 = NullType, typename T17 = NullType, typename T18 = NullType
44 > 44 >
45 struct MakeTypelist{ 45 struct MakeTypelist{
46 private: 46 private:
47 typedef typename MakeTypelist 47 typedef typename MakeTypelist
48 < 48 <
49 T2 , T3 , T4 , 49 T2 , T3 , T4 ,
50 T5 , T6 , T7 , 50 T5 , T6 , T7 ,
51 T8 , T9 , T10, 51 T8 , T9 , T10,
52 T11, T12, T13, 52 T11, T12, T13,
53 T14, T15, T16, 53 T14, T15, T16,
54 T17, T18 54 T17, T18
55 > 55 >
56 ::Result TailResult; 56 ::Result TailResult;
57 57
58public: 58public:
59 typedef Typelist<T1, TailResult> Result; 59 typedef Typelist<T1, TailResult> Result;
60}; 60};
61 61
62template<> 62template<>
63struct MakeTypelist<> 63struct MakeTypelist<>
64{ 64{
65 typedef NullType Result; 65 typedef NullType Result;
66}; 66};
67 67
68} 68}
69 69
70/** 70/**
71 * To allow your application to be quick launched some one needs 71 * To allow your application to be quick launched some one needs
72 * to create the QWidget. 72 * to create the QWidget.
73 * This is this factory. Make surce your widget has static QString Widget::appName() 73 * This is this factory. Make surce your widget has static QString Widget::appName()
74 * as one of its functions. 74 * as one of its functions.
75 * 75 *
76 * This template takes one QWidget and initialized it in the form of 76 * This template takes one QWidget and initialized it in the form of
77 * MyWidget::MyWidget( QWidget* parent, const char* name, WFlags f ); 77 * MyWidget::MyWidget( QWidget* parent, const char* name, WFlags f );
78 * 78 *
79 * To use it on your app do that: 79 * To use it on your app do that:
80 * typedef OApplicationFactory<MyWidget> MyFactory; 80 * typedef OApplicationFactory<MyWidget> MyFactory;
81 * OPIE_EXPORT_APP( MyFactory ) 81 * OPIE_EXPORT_APP( MyFactory )
82 * 82 *
83 */ 83 */
84template <class Product> 84template <class Product>
85struct OApplicationFactory : public ApplicationInterface { 85struct OApplicationFactory : public ApplicationInterface {
86 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { 86 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
87 *iface = 0; 87 *iface = 0;
88 if ( uuid == IID_QUnknown ) *iface = this; 88 if ( uuid == IID_QUnknown ) *iface = this;
89 else if ( uuid == IID_QtopiaApplication ) *iface = this; 89 else if ( uuid == IID_QtopiaApplication ) *iface = this;
90 else return QS_FALSE; 90 else return QS_FALSE;
91 (*iface)->addRef(); 91 (*iface)->addRef();
92 return QS_OK; 92 return QS_OK;
93 } 93 }
94 94
95 /* 95 /*
96 * 96 *
97 */ 97 */
98 virtual QWidget *createMainWindow( const QString& appName, QWidget* parent, 98 virtual QWidget *createMainWindow( const QString& appName, QWidget* parent,
99 const char* name, Qt::WFlags f ) { 99 const char* name, Qt::WFlags f ) {
100 if (appName == Product::appName() ) 100 if (appName == Product::appName() )
101 return new Product(parent, name, f ); 101 return new Product(parent, name, f );
102 else 102 else
103 return 0l; 103 return 0l;
104 } 104 }
105 105
106 virtual QStringList applications()const { 106 virtual QStringList applications()const {
107 QStringList list; 107 QStringList list;
108 list << Product::appName() ; 108 list << Product::appName() ;
109 109
110 return list; 110 return list;
111 } 111 }
112 Q_REFCOUNT 112 Q_REFCOUNT
113 113
114}; 114};
115 115
116 116
117/* Internal */ 117/* Internal */
118 118
119template< class Product > 119template< class Product >
120struct OPrivate { 120struct OPrivate {
121 inline static QWidget *multiFactory( const QString& appName, QWidget* parent, 121 inline static QWidget *multiFactory( const QString& appName, QWidget* parent,
122 const char* name, Qt::WFlags fl ) { 122 const char* name, Qt::WFlags fl ) {
123 if ( appName == Product::appName() ) 123 if ( appName == Product::appName() )
124 return new Product( parent, name, fl ); 124 return new Product( parent, name, fl );
125 else 125 else
126 return 0; 126 return 0;
127 } 127 }
128 128
129 inline static QStringList multiString( const QStringList& _list ) { 129 inline static QStringList multiString( const QStringList& _list ) {
130 QStringList list = _list; 130 QStringList list = _list;
131 list << Product::appName(); 131 list << Product::appName();
132 return list; 132 return list;
133 } 133 }
134}; 134};
135 135
136template <> 136template <>
137struct OPrivate<Opie::NullType > { 137struct OPrivate<Opie::NullType > {
138 inline static QWidget* multiFactory ( const QString& , QWidget* , 138 inline static QWidget* multiFactory ( const QString& , QWidget* ,
139 const char* , Qt::WFlags ) { 139 const char* , Qt::WFlags ) {
140 return 0l; 140 return 0l;
141 } 141 }
142 inline static QStringList multiString( const QStringList& _list ) { 142 inline static QStringList multiString( const QStringList& _list ) {
143 return _list; 143 return _list;
144 } 144 }
145}; 145};
146 146
147/* 147/*
148template <> 148template <>
149struct OPrivate <Opie::NullType, Opie::NullType > { 149struct OPrivate <Opie::NullType, Opie::NullType > {
150 inline static QWidget* multiFactory( const QString& , QWidget* , 150 inline static QWidget* multiFactory( const QString& , QWidget* ,
151 const char* , Qt::WFlags ) { 151 const char* , Qt::WFlags ) {
152 return 0l; 152 return 0l;
153 } 153 }
154 154
155 inline static QStringList multiString( const QStringList& _list ) { 155 inline static QStringList multiString( const QStringList& _list ) {
156 return _list; 156 return _list;
157 } 157 }
158}; 158};
159*/ 159*/
160 160
161template <class Product, class ProductListTail> 161template <class Product, class ProductListTail>
162struct OPrivate< Opie::Typelist<Product, ProductListTail> > { 162struct OPrivate< Opie::Typelist<Product, ProductListTail> > {
163 inline static QWidget* multiFactory( const QString& appName, QWidget* parent, 163 inline static QWidget* multiFactory( const QString& appName, QWidget* parent,
164 const char* name, Qt::WFlags fl) { 164 const char* name, Qt::WFlags fl) {
165 QWidget* wid = OPrivate<Product>::multiFactory( appName, parent, name, fl ); 165 QWidget* wid = OPrivate<Product>::multiFactory( appName, parent, name, fl );
166 166
167 if (!wid ) 167 if (!wid )
168 wid = OPrivate<ProductListTail>::multiFactory( appName, parent, name, fl ); 168 wid = OPrivate<ProductListTail>::multiFactory( appName, parent, name, fl );
169 169
170 return wid; 170 return wid;
171 } 171 }
172 172
173 inline static QStringList multiString( const QStringList& _list ) { 173 inline static QStringList multiString( const QStringList& _list ) {
174 QStringList list = _list; 174 QStringList list = _list;
175 175
176 list = OPrivate<Product>::multiString( list ); 176 list = OPrivate<Product>::multiString( list );
177 list = OPrivate<ProductListTail>::multiString( list ); 177 list = OPrivate<ProductListTail>::multiString( list );
178 178
179 return list; 179 return list;
180 } 180 }
181}; 181};
182 182
183 183
184 184
185 185
186 186
187 187
188 188
189 189
190/* Internal END */ 190/* Internal END */
191 191
192/* 192/*
193 * If you want to export more than one Widget use that function 193 * If you want to export more than one Widget use that function
194 * Make sure all your Widgets provide the appName() static method 194 * Make sure all your Widgets provide the appName() static method
195 * otherwise you'll get a compiler error 195 * otherwise you'll get a compiler error
196 * 196 *
197 * typedef Opie::MakeTypeList<MyWidget, MyDialog, MyMediaPlayer >::Result MyTypes; 197 * typedef Opie::MakeTypeList<MyWidget, MyDialog, MyMediaPlayer >::Result MyTypes;
198 * OPIE_EXPORT_APP( OApplicationFactory<MyTypes> ) 198 * OPIE_EXPORT_APP( OApplicationFactory<MyTypes> )
199 */ 199 */
200 200
201template<class Product, class ProductListTail> 201template<class Product, class ProductListTail>
202struct OApplicationFactory< Opie::Typelist<Product, ProductListTail > > 202struct OApplicationFactory< Opie::Typelist<Product, ProductListTail > >
203 : ApplicationInterface { 203 : ApplicationInterface {
204 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { 204 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
205 *iface = 0; 205 *iface = 0;
206 if ( uuid == IID_QUnknown ) *iface = this; 206 if ( uuid == IID_QUnknown ) *iface = this;
207 else if ( uuid ==IID_QtopiaApplication ) *iface = this; 207 else if ( uuid ==IID_QtopiaApplication ) *iface = this;
208 else return QS_FALSE; 208 else return QS_FALSE;
209 (*iface)->addRef(); 209 (*iface)->addRef();
210 return QS_OK; 210 return QS_OK;
211 } 211 }
212 212
213 QWidget* createMainWindow ( const QString& appName, QWidget* parent, 213 QWidget* createMainWindow ( const QString& appName, QWidget* parent,
214 const char* name, Qt::WFlags fl ) { 214 const char* name, Qt::WFlags fl ) {
215 qWarning("StringList is %s", applications().join(":").latin1() ); 215 qWarning("StringList is %s", applications().join(":").latin1() );
216 return OPrivate< Opie::Typelist<Product, ProductListTail > >::multiFactory( appName, parent, name, fl ); 216 return OPrivate< Opie::Typelist<Product, ProductListTail > >::multiFactory( appName, parent, name, fl );
217 } 217 }
218 218
219 QStringList applications()const { 219 QStringList applications()const {
220 QStringList _list; 220 QStringList _list;
221 return OPrivate< Opie::Typelist<Product, ProductListTail> >::multiString( _list ); 221 return OPrivate< Opie::Typelist<Product, ProductListTail> >::multiString( _list );
222 } 222 }
223 223
224 Q_REFCOUNT 224 Q_REFCOUNT
225}; 225};
226 226
227 227
228/* If the library version should be build */ 228/* If the library version should be build */
229#ifdef OPIE_APP_INTERFACE 229#ifdef OPIE_APP_INTERFACE
230#define OPIE_EXPORT_APP( factory ) Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( factory ) } 230#define OPIE_EXPORT_APP( factory ) Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( factory ) }
231#else 231#else
232 232
233#include <qpe/qpeapplication.h>
234
233#define OPIE_EXPORT_APP( Factory ) \ 235#define OPIE_EXPORT_APP( Factory ) \
234int main( int argc, char **argv ) { \ 236int main( int argc, char **argv ) { \
235 QPEApplication a(argc, argv ); \ 237 QPEApplication a(argc, argv ); \
236 QWidget *mw = 0;\ 238 QWidget *mw = 0;\
237\ 239\
238 /* method from TT */ \ 240 /* method from TT */ \
239 QString executableName = QString::fromLatin1( argv[0] ); \ 241 QString executableName = QString::fromLatin1( argv[0] ); \
240 executableName = executableName.right(executableName.length() \ 242 executableName = executableName.right(executableName.length() \
241 - executableName.findRev('/') - 1); \ 243 - executableName.findRev('/') - 1); \
242 \ 244 \
243 Factory f; \ 245 Factory f; \
244 QStringList list = f.applications(); \ 246 QStringList list = f.applications(); \
245 if (list.contains(executableName) ) \ 247 if (list.contains(executableName) ) \
246 mw = f.createMainWindow(executableName, 0, 0, 0 ); \ 248 mw = f.createMainWindow(executableName, 0, 0, 0 ); \
247 else \ 249 else \
248 mw = f.createMainWindow( list[0], 0, 0, 0 ); \ 250 mw = f.createMainWindow( list[0], 0, 0, 0 ); \
249\ 251\
250 if( mw ) { \ 252 if( mw ) { \
251 if ( mw->metaObject()->slotNames().contains("setDocument(const QString&)" ) ) \ 253 if ( mw->metaObject()->slotNames().contains("setDocument(const QString&)" ) ) \
252 a.showMainDocumentWidget( mw ); \ 254 a.showMainDocumentWidget( mw ); \
253 else \ 255 else \
254 a.showMainWidget( mw ); \ 256 a.showMainWidget( mw ); \
255\ 257\
256 int rv = a.exec(); \ 258 int rv = a.exec(); \
257 delete mw; \ 259 delete mw; \
258 return rv; \ 260 return rv; \
259 }else \ 261 }else \
260 return -1; \ 262 return -1; \
261} 263}
262#endif 264#endif