00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include <qstring.h>
00052 #include <qmetaobject.h>
00053
00054 #include <qtopia/qcom.h>
00055 #include <qtopia/applicationinterface.h>
00056
00057 #include <opie2/odebug.h>
00058
00059 namespace Opie {
00060 namespace Core {
00061 struct NullType;
00062
00063 template <class T, class U>
00064 struct Typelist
00065 {
00066 typedef T Head;
00067 typedef U Tail;
00068 };
00069 template<
00070 typename T1 = NullType, typename T2 = NullType, typename T3 = NullType,
00071 typename T4 = NullType, typename T5 = NullType, typename T6 = NullType,
00072 typename T7 = NullType, typename T8 = NullType, typename T9 = NullType,
00073 typename T10 = NullType, typename T11 = NullType, typename T12 = NullType,
00074 typename T13 = NullType, typename T14 = NullType, typename T15 = NullType,
00075 typename T16 = NullType, typename T17 = NullType, typename T18 = NullType
00076 >
00077 struct MakeTypelist{
00078 private:
00079 typedef typename MakeTypelist
00080 <
00081 T2 , T3 , T4 ,
00082 T5 , T6 , T7 ,
00083 T8 , T9 , T10,
00084 T11, T12, T13,
00085 T14, T15, T16,
00086 T17, T18
00087 >
00088 ::Result TailResult;
00089
00090 public:
00091 typedef Typelist<T1, TailResult> Result;
00092 };
00093
00094 template<>
00095 struct MakeTypelist<>
00096 {
00097 typedef NullType Result;
00098 };
00099
00100
00115 template <class Product>
00116 struct OApplicationFactory : public ApplicationInterface {
00117 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
00118 *iface = 0;
00119 if ( uuid == IID_QUnknown ) *iface = this;
00120 else if ( uuid == IID_QtopiaApplication ) *iface = this;
00121 else return QS_FALSE;
00122 (*iface)->addRef();
00123 return QS_OK;
00124 }
00125
00126
00127
00128
00129 virtual QWidget *createMainWindow( const QString& appName, QWidget* parent,
00130 const char* name, Qt::WFlags f ) {
00131 if (appName == Product::appName() )
00132 return new Product(parent, name, f );
00133 else{
00134 odebug << "Application Name = " << appName.latin1() << oendl;
00135 odebug << "ProductName = " << Product::appName().latin1() << oendl;
00136 odebug << "The application name is not equal to the product name!" << oendl;
00137 odebug << "Please compare TARGET entry in the project file (*.pro) and the call of the OApplicationFactory< productName >" << oendl;
00138 return 0l;
00139 }
00140 }
00141
00142 virtual QStringList applications()const {
00143 QStringList list;
00144 list << Product::appName() ;
00145
00146 return list;
00147 }
00148 Q_REFCOUNT
00149
00150 };
00151
00152
00153
00154
00155 template< class Product >
00156 struct OPrivate {
00157 inline static QWidget *multiFactory( const QString& appName, QWidget* parent,
00158 const char* name, Qt::WFlags fl ) {
00159 if ( appName == Product::appName() )
00160 return new Product( parent, name, fl );
00161 else
00162 return 0;
00163 }
00164
00165 inline static QStringList multiString( const QStringList& _list ) {
00166 QStringList list = _list;
00167 list << Product::appName();
00168 return list;
00169 }
00170 };
00171
00172 template <>
00173 struct OPrivate<Opie::Core::NullType > {
00174 inline static QWidget* multiFactory ( const QString& , QWidget* ,
00175 const char* , Qt::WFlags ) {
00176 return 0l;
00177 }
00178 inline static QStringList multiString( const QStringList& _list ) {
00179 return _list;
00180 }
00181 };
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 template <class Product, class ProductListTail>
00198 struct OPrivate< Opie::Core::Typelist<Product, ProductListTail> > {
00199 inline static QWidget* multiFactory( const QString& appName, QWidget* parent,
00200 const char* name, Qt::WFlags fl) {
00201 QWidget* wid = OPrivate<Product>::multiFactory( appName, parent, name, fl );
00202
00203 if (!wid )
00204 wid = OPrivate<ProductListTail>::multiFactory( appName, parent, name, fl );
00205
00206 return wid;
00207 }
00208
00209 inline static QStringList multiString( const QStringList& _list ) {
00210 QStringList list = _list;
00211
00212 list = OPrivate<Product>::multiString( list );
00213 list = OPrivate<ProductListTail>::multiString( list );
00214
00215 return list;
00216 }
00217 };
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 template<class Product, class ProductListTail>
00238 struct OApplicationFactory< Opie::Core::Typelist<Product, ProductListTail > >
00239 : ApplicationInterface {
00240 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
00241 *iface = 0;
00242 if ( uuid == IID_QUnknown ) *iface = this;
00243 else if ( uuid ==IID_QtopiaApplication ) *iface = this;
00244 else return QS_FALSE;
00245 (*iface)->addRef();
00246 return QS_OK;
00247 }
00248
00249 QWidget* createMainWindow ( const QString& appName, QWidget* parent,
00250 const char* name, Qt::WFlags fl ) {
00251 qWarning("StringList is %s", applications().join(":").latin1() );
00252 return OPrivate< Opie::Core::Typelist<Product, ProductListTail > >::multiFactory( appName, parent, name, fl );
00253 }
00254
00255 QStringList applications()const {
00256 QStringList _list;
00257 return OPrivate< Opie::Core::Typelist<Product, ProductListTail> >::multiString( _list );
00258 }
00259
00260 Q_REFCOUNT
00261 };
00262
00263 }
00264 }
00265
00266
00267 #ifdef OPIE_APP_INTERFACE
00268 #define OPIE_EXPORT_APP( factory ) Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( factory ) }
00269 #else
00270
00271 #include <qpe/qpeapplication.h>
00272
00273 #define OPIE_EXPORT_APP( Factory ) \
00274 int main( int argc, char **argv ) { \
00275 QPEApplication a(argc, argv ); \
00276 QWidget *mw = 0;\
00277 \
00278 \
00279 QString executableName = QString::fromLatin1( argv[0] ); \
00280 executableName = executableName.right(executableName.length() \
00281 - executableName.findRev('/') - 1); \
00282 \
00283 Factory f; \
00284 QStringList list = f.applications(); \
00285 if (list.contains(executableName) ) \
00286 mw = f.createMainWindow(executableName, 0, 0, 0 ); \
00287 else \
00288 mw = f.createMainWindow( list[0], 0, 0, 0 ); \
00289 \
00290 if( mw ) { \
00291 if ( mw->metaObject()->slotNames().contains("setDocument(const QString&)" ) ) \
00292 a.showMainDocumentWidget( mw ); \
00293 else \
00294 a.showMainWidget( mw ); \
00295 \
00296 int rv = a.exec(); \
00297 delete mw; \
00298 return rv; \
00299 }else \
00300 return -1; \
00301 }
00302 #endif
00303
00304 #ifdef OPIE_APP_INTERFACE
00305 #define OPIE_EXPORT_APP_V2( factory,name ) Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( factory ) }
00306 #else
00307
00308 #include <opie2/oapplication.h>
00309
00310 #define OPIE_EXPORT_APP_V2( Factory,name ) \
00311 int main( int argc, char **argv ) { \
00312 Opie::Core::OApplication a(argc, argv, name ); \
00313 QWidget *mw = 0;\
00314 \
00315 \
00316 QString executableName = QString::fromLatin1( argv[0] ); \
00317 executableName = executableName.right(executableName.length() \
00318 - executableName.findRev('/') - 1); \
00319 \
00320 Factory f; \
00321 QStringList list = f.applications(); \
00322 if (list.contains(executableName) ) \
00323 mw = f.createMainWindow(executableName, 0, 0, 0 ); \
00324 else \
00325 mw = f.createMainWindow( list[0], 0, 0, 0 ); \
00326 \
00327 if( mw ) { \
00328 if ( mw->metaObject()->slotNames().contains("setDocument(const QString&)" ) ) \
00329 a.showMainDocumentWidget( mw ); \
00330 else \
00331 a.showMainWidget( mw ); \
00332 \
00333 int rv = a.exec(); \
00334 delete mw; \
00335 return rv; \
00336 }else \
00337 return -1; \
00338 }
00339 #endif
00340
00341
00342 #define OPIE_EXPORT_APPNAME static QString appName() { return QString::fromLatin1( QUICKAPP_NAME ); }