author | mickeyl <mickeyl> | 2004-01-15 15:50:38 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-15 15:50:38 (UTC) |
commit | 53fa609d585216173c834cd1f22678a087394cde (patch) (unidiff) | |
tree | 750759ec9a94326fc68e3ae573350c47b7aa52fe | |
parent | 84bb8c9046007fe2adfaa016aded88b961c65e62 (diff) | |
download | opie-53fa609d585216173c834cd1f22678a087394cde.zip opie-53fa609d585216173c834cd1f22678a087394cde.tar.gz opie-53fa609d585216173c834cd1f22678a087394cde.tar.bz2 |
- add oapplicationfactory to opiecore
- add big screen examples
13 files changed, 689 insertions, 1 deletions
diff --git a/libopie2/examples/opieui/opieui.pro b/libopie2/examples/opieui/opieui.pro index ad66f47..853ac50 100644 --- a/libopie2/examples/opieui/opieui.pro +++ b/libopie2/examples/opieui/opieui.pro | |||
@@ -1,3 +1,5 @@ | |||
1 | TEMPLATE = subdirs | 1 | TEMPLATE = subdirs |
2 | SUBDIRS = olistviewdemo | 2 | SUBDIRS = olistviewdemo owidgetstack_example osplitter_example |
3 | |||
4 | |||
3 | 5 | ||
diff --git a/libopie2/examples/opieui/osplitter_example/.cvsignore b/libopie2/examples/opieui/osplitter_example/.cvsignore new file mode 100644 index 0000000..8f7300c --- a/dev/null +++ b/libopie2/examples/opieui/osplitter_example/.cvsignore | |||
@@ -0,0 +1,6 @@ | |||
1 | Makefile* | ||
2 | moc* | ||
3 | *moc | ||
4 | *.o | ||
5 | ~* | ||
6 | |||
diff --git a/libopie2/examples/opieui/osplitter_example/osplitter_example.cpp b/libopie2/examples/opieui/osplitter_example/osplitter_example.cpp new file mode 100644 index 0000000..7ba0f0d --- a/dev/null +++ b/libopie2/examples/opieui/osplitter_example/osplitter_example.cpp | |||
@@ -0,0 +1,32 @@ | |||
1 | #include "osplitter_example.h" | ||
2 | |||
3 | /* OPIE */ | ||
4 | |||
5 | #include <opie2/osplitter.h> | ||
6 | #include <qpe/qpeapplication.h> | ||
7 | #include <opie2/oapplicationfactory.h> | ||
8 | |||
9 | /* QT*/ | ||
10 | #include <qdir.h> | ||
11 | #include <qlayout.h> | ||
12 | |||
13 | using namespace Opie; | ||
14 | |||
15 | OPIE_EXPORT_APP( OApplicationFactory<OSplitterExample> ) | ||
16 | |||
17 | OSplitterExample::OSplitterExample( QWidget *w,const char* n,WFlags f ) | ||
18 | : QWidget( w, n, f ){ | ||
19 | QVBoxLayout * lay = new QVBoxLayout(this); | ||
20 | OSplitter * splitter = new OSplitter( Horizontal, this ); | ||
21 | lay->addWidget( splitter ); | ||
22 | |||
23 | OFileSelector *selector = new OFileSelector( splitter, OFileSelector::FileSelector, | ||
24 | OFileSelector::Normal, QDir::homeDirPath(), | ||
25 | QString::null ); | ||
26 | splitter->addWidget( selector, "zoom", tr("Selector 1") ); | ||
27 | |||
28 | selector = new OFileSelector( splitter, OFileSelector::FileSelector, OFileSelector::Normal, | ||
29 | QDir::homeDirPath(), QString::null ); | ||
30 | splitter->addWidget( selector, "zoom", tr("Selector 2") ); | ||
31 | |||
32 | } | ||
diff --git a/libopie2/examples/opieui/osplitter_example/osplitter_example.h b/libopie2/examples/opieui/osplitter_example/osplitter_example.h new file mode 100644 index 0000000..176ad62 --- a/dev/null +++ b/libopie2/examples/opieui/osplitter_example/osplitter_example.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* | ||
2 | * May be used, copied and modified wihtout any limitation | ||
3 | */ | ||
4 | |||
5 | #ifndef OSPlitter_EXAMPLE_H | ||
6 | #define OSPlitter_EXAMPLE_H | ||
7 | |||
8 | #include <qvbox.h> | ||
9 | #include <opie2/ofileselector.h> | ||
10 | |||
11 | class OSplitterExample : public QWidget { | ||
12 | Q_OBJECT | ||
13 | public: | ||
14 | static QString appName() { return QString::fromLatin1("osplitter_example"); } | ||
15 | OSplitterExample( QWidget *parent, const char* name, WFlags fl ); | ||
16 | |||
17 | }; | ||
18 | |||
19 | |||
20 | #endif | ||
diff --git a/libopie2/examples/opieui/osplitter_example/osplitter_example.pro b/libopie2/examples/opieui/osplitter_example/osplitter_example.pro new file mode 100644 index 0000000..224a1ee --- a/dev/null +++ b/libopie2/examples/opieui/osplitter_example/osplitter_example.pro | |||
@@ -0,0 +1,13 @@ | |||
1 | CONFIG = qt warn_on | ||
2 | TEMPLATE = app | ||
3 | TARGET = osplitter_example | ||
4 | |||
5 | HEADERS = osplitter_example.h | ||
6 | SOURCES = osplitter_example.cpp | ||
7 | |||
8 | INCLUDEPATH += $(OPIEDIR)/include | ||
9 | DEPENDSPATH += $(OPIEDIR)/include | ||
10 | |||
11 | LIBS += -lqpe -lopieui2 | ||
12 | |||
13 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/libopie2/examples/opieui/osplitter_example/osplitter_mail.cpp b/libopie2/examples/opieui/osplitter_example/osplitter_mail.cpp new file mode 100644 index 0000000..4eaf3a9 --- a/dev/null +++ b/libopie2/examples/opieui/osplitter_example/osplitter_mail.cpp | |||
@@ -0,0 +1,82 @@ | |||
1 | |||
2 | #include <qstring.h> | ||
3 | #include <qlabel.h> | ||
4 | #include <qheader.h> | ||
5 | #include <qlayout.h> | ||
6 | |||
7 | #include <qpe/qpeapplication.h> | ||
8 | #include <opie/oapplicationfactory.h> | ||
9 | |||
10 | #include "../osplitter.h" | ||
11 | |||
12 | #include "osplitter_mail.h" | ||
13 | |||
14 | |||
15 | OPIE_EXPORT_APP( OApplicationFactory<ListViews> ) | ||
16 | |||
17 | class Folder { | ||
18 | int dummy; | ||
19 | }; | ||
20 | |||
21 | // ----------------------------------------------------------------- | ||
22 | |||
23 | ListViews::ListViews( QWidget* p, const char* name, WFlags fl ) | ||
24 | : QWidget( p, name, fl ) { | ||
25 | qApp->installEventFilter( this ); | ||
26 | m_lstFolders.setAutoDelete( true ); | ||
27 | QHBoxLayout *lay = new QHBoxLayout(this); | ||
28 | |||
29 | m_splitter = new OSplitter( Horizontal, this, "SPlitter 1" ); | ||
30 | lay->addWidget( m_splitter ); | ||
31 | connect(m_splitter, SIGNAL(sizeChange(bool, const QSize& ) ), | ||
32 | this, SLOT(slotSizeChange(bool, const QSize& ) ) ); | ||
33 | |||
34 | m_overview = new QListView( m_splitter ); | ||
35 | m_overview->header()->setClickEnabled( FALSE ); | ||
36 | m_overview->addColumn( tr("Folder") ); | ||
37 | m_overview->setMaximumWidth( 200 ); | ||
38 | m_splitter->addWidget( m_overview, "zoom", tr("Folder Overview") ); | ||
39 | m_splitter->setSizeChange( 300 ); | ||
40 | |||
41 | /* OSplitter starts with the small mode */ | ||
42 | m_messages = 0; | ||
43 | m_message = m_attach = 0; | ||
44 | |||
45 | splitti = new OSplitter( Vertical, m_splitter, "Splitti2" ); | ||
46 | splitti->setSizeChange( 300 ); | ||
47 | splitti->setSizePolicy( QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) ); | ||
48 | |||
49 | QLabel *lbl = new QLabel(splitti); | ||
50 | lbl->setTextFormat ( Qt::RichText ); | ||
51 | lbl->setText("<br><br><b>Test Test Test</b><br><br><p>Fooooo hjhh</p>"); | ||
52 | |||
53 | m_messages = new QListView( splitti ); | ||
54 | m_messages->addColumn(" Messages "); | ||
55 | |||
56 | folder1 = new QListView( splitti ); | ||
57 | folder1->addColumn( "Messages 2 " ); | ||
58 | |||
59 | splitti->addWidget(m_messages, "mail", tr("Mails") ); | ||
60 | splitti->addWidget(folder1, "folder", tr("Folder") ); | ||
61 | splitti->addWidget( lbl, "logo", tr("Label") ); | ||
62 | m_message = lbl; | ||
63 | |||
64 | m_splitter->addWidget( splitti ); | ||
65 | |||
66 | } | ||
67 | |||
68 | |||
69 | ListViews::~ListViews() { | ||
70 | |||
71 | } | ||
72 | |||
73 | |||
74 | bool ListViews::eventFilter( QObject* obj, QEvent* ev ) { | ||
75 | if (!obj->isWidgetType() ) | ||
76 | return false; | ||
77 | if ( ev->type() == QEvent::MouseButtonRelease ) { | ||
78 | qWarning(" name %s, class %s", obj->name(), obj->className() ); | ||
79 | } | ||
80 | |||
81 | return false; | ||
82 | } | ||
diff --git a/libopie2/examples/opieui/osplitter_example/osplitter_mail.h b/libopie2/examples/opieui/osplitter_example/osplitter_mail.h new file mode 100644 index 0000000..b7e7efe --- a/dev/null +++ b/libopie2/examples/opieui/osplitter_example/osplitter_mail.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * You may use, modify and distribute this code without any limitation | ||
3 | */ | ||
4 | |||
5 | /* | ||
6 | * Header file for a more complete email client like | ||
7 | * layout | ||
8 | */ | ||
9 | |||
10 | #ifndef OPIE_SPLITTER_MAIL_EXAMPLE_H | ||
11 | #define OPIE_SPLITTER_MAIL_EXAMPLE_H | ||
12 | |||
13 | #include <qwidget.h> | ||
14 | #include <qlist.h> | ||
15 | #include <qlistview.h> | ||
16 | |||
17 | class Folder; | ||
18 | class QLabel; | ||
19 | |||
20 | class OSplitter; | ||
21 | class ListViews : public QWidget { | ||
22 | Q_OBJECT | ||
23 | public: | ||
24 | static QString appName() { return QString::fromLatin1("osplitter-mail"); } | ||
25 | ListViews( QWidget* parent, const char * name, WFlags fl ); | ||
26 | ~ListViews(); | ||
27 | |||
28 | bool eventFilter( QObject* , QEvent* ); | ||
29 | private: | ||
30 | void initFolders(); | ||
31 | void initFolder( Folder *folder, unsigned int &count ); | ||
32 | |||
33 | QListView *m_messages, *m_overview; | ||
34 | QLabel *m_message, *m_attach; | ||
35 | QList<QListView> m_folders; // used in tab mode | ||
36 | QList<Folder> m_lstFolders; | ||
37 | bool m_mode : 1; // bitfield | ||
38 | OSplitter *m_splitter; | ||
39 | OSplitter *splitti; | ||
40 | QListView *folder1; | ||
41 | #if 0 | ||
42 | //private slots: | ||
43 | // void slotFolderChanged( QListViewItem* ); | ||
44 | // void slotMessageChanged(); | ||
45 | // void slotSizeChange( bool, const QSize& ); | ||
46 | #endif | ||
47 | }; | ||
48 | |||
49 | #endif | ||
diff --git a/libopie2/examples/opieui/osplitter_example/osplitter_mail.pro b/libopie2/examples/opieui/osplitter_example/osplitter_mail.pro new file mode 100644 index 0000000..ec6e626 --- a/dev/null +++ b/libopie2/examples/opieui/osplitter_example/osplitter_mail.pro | |||
@@ -0,0 +1,12 @@ | |||
1 | CONFIG += qt warn_on | ||
2 | TEMPLATE = app | ||
3 | TARGET = osplitter-mail | ||
4 | |||
5 | INCLUDEPATH += $(OPIEDIR)/include | ||
6 | DEPENDSPATH += $(OPIEDIR)/include | ||
7 | |||
8 | HEADERS = osplitter_mail.h | ||
9 | SOURCES = osplitter_mail.cpp | ||
10 | |||
11 | LIBS += -lqpe -lopie | ||
12 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/libopie2/examples/opieui/owidgetstack_example/.cvsignore b/libopie2/examples/opieui/owidgetstack_example/.cvsignore new file mode 100644 index 0000000..8f7300c --- a/dev/null +++ b/libopie2/examples/opieui/owidgetstack_example/.cvsignore | |||
@@ -0,0 +1,6 @@ | |||
1 | Makefile* | ||
2 | moc* | ||
3 | *moc | ||
4 | *.o | ||
5 | ~* | ||
6 | |||
diff --git a/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.cpp b/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.cpp new file mode 100644 index 0000000..b1c5e70 --- a/dev/null +++ b/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | /* | ||
2 | * You may use, modify and distribute this example without any limitation | ||
3 | */ | ||
4 | |||
5 | #include "owidgetstack_example.h" | ||
6 | |||
7 | /* OPIE */ | ||
8 | #include <opie2/oapplicationfactory.h> | ||
9 | #include <opie2/owidgetstack.h> | ||
10 | #include <qpe/resource.h> | ||
11 | |||
12 | /* QT */ | ||
13 | #include <qaction.h> | ||
14 | #include <qtoolbar.h> | ||
15 | #include <qpopupmenu.h> | ||
16 | #include <qmenubar.h> | ||
17 | #include <qlayout.h> | ||
18 | #include <qlabel.h> | ||
19 | #include <qpushbutton.h> | ||
20 | #include <qsignalmapper.h> | ||
21 | |||
22 | using namespace Opie; | ||
23 | |||
24 | OPIE_EXPORT_APP( OApplicationFactory<StackExample> ) | ||
25 | |||
26 | StackExample::StackExample( QWidget* parent, const char* name, WFlags fl ) | ||
27 | : QMainWindow( parent, name, fl ) | ||
28 | { | ||
29 | m_stack = new OWidgetStack( this ); | ||
30 | setCentralWidget( m_stack ); | ||
31 | |||
32 | /* nice Signal Mapper ;) */ | ||
33 | QSignalMapper *sm = new QSignalMapper(this); | ||
34 | connect(sm, SIGNAL(mapped(int) ), m_stack, SLOT(raiseWidget(int)) ); | ||
35 | |||
36 | /* toolbar first but this should be known from the other examples */ | ||
37 | setToolBarsMovable( false ); | ||
38 | |||
39 | /* only a menubar here */ | ||
40 | QToolBar* holder = new QToolBar( this ); | ||
41 | holder->setHorizontalStretchable( true ); | ||
42 | |||
43 | QMenuBar *bar = new QMenuBar( holder ); | ||
44 | QPopupMenu *menu = new QPopupMenu( this ); | ||
45 | |||
46 | QAction* a = new QAction( tr("Show MainWidget"), Resource::loadPixmap("zoom"), | ||
47 | QString::null, 0, this, 0 ); | ||
48 | sm->setMapping(a, 1 ); | ||
49 | connect(a, SIGNAL(activated() ), | ||
50 | sm, SLOT(map() ) ); | ||
51 | a->addTo( menu ); | ||
52 | |||
53 | a = new QAction( tr("Show Details Small"), Resource::loadPixmap("zoom"), | ||
54 | QString::null, 0, this, 0 ); | ||
55 | sm->setMapping(a, 2 ); | ||
56 | connect(a, SIGNAL(activated() ), | ||
57 | sm, SLOT(map() ) ); | ||
58 | a->addTo( menu ); | ||
59 | |||
60 | a = new QAction( tr("Show Details More"), Resource::loadPixmap("zoom"), | ||
61 | QString::null, 0, this, 0 ); | ||
62 | sm->setMapping(a, 3 ); | ||
63 | connect(a, SIGNAL(activated() ), | ||
64 | sm, SLOT(map() ) ); | ||
65 | a->addTo( menu ); | ||
66 | |||
67 | a = new QAction( tr("Show Details All"), Resource::loadPixmap("zoom"), | ||
68 | QString::null, 0, this, 0 ); | ||
69 | sm->setMapping(a, 4 ); | ||
70 | connect(a, SIGNAL(activated() ), | ||
71 | sm, SLOT(map() ) ); | ||
72 | |||
73 | bar->insertItem( tr("Actions"), menu ); | ||
74 | |||
75 | /* now the gui */ | ||
76 | |||
77 | /* first widget, main widget */ | ||
78 | QWidget * wid = new QWidget( m_stack ); | ||
79 | QGridLayout *grid = new QGridLayout(wid, 2, 2 ); | ||
80 | |||
81 | QPushButton *btn = new QPushButton( tr("Show Details Small"), wid, "details1" ); | ||
82 | sm->setMapping(btn, 2 ); | ||
83 | connect(btn, SIGNAL(clicked()), sm, SLOT(map() ) ); | ||
84 | grid->addWidget( btn, 0, 0 ); | ||
85 | |||
86 | btn = new QPushButton( tr("Show Details Medium"), wid, "details2"); | ||
87 | sm->setMapping(btn, 3 ); | ||
88 | connect(btn, SIGNAL(clicked()), sm, SLOT(map() ) ); | ||
89 | grid->addWidget( btn, 0, 1 ); | ||
90 | |||
91 | btn = new QPushButton( tr("Show Details All"), wid, "details3"); | ||
92 | sm->setMapping(btn, 4 ); | ||
93 | connect(btn, SIGNAL(clicked()), sm, SLOT(map() ) ); | ||
94 | grid->addWidget( btn, 1, 1 ); | ||
95 | |||
96 | m_stack->addWidget( wid, 1 ); | ||
97 | m_main = wid; | ||
98 | |||
99 | QLabel *lbl = new QLabel(m_stack ); | ||
100 | lbl->setText(tr("Only small Details are shown here. Määh") ); | ||
101 | m_stack->addWidget( lbl, 2 ); | ||
102 | |||
103 | lbl = new QLabel( m_stack ); | ||
104 | lbl->setText( tr("Some more details....Wo ist das Schaf?") ); | ||
105 | m_stack->addWidget( lbl, 3 ); | ||
106 | |||
107 | lbl = new QLabel( m_stack ); | ||
108 | lbl->setText( tr("<qt>Ne nicht in Bayerisch Gmain sondern in Berlin<br>Vermiss und meine Augen werden nicht eckig, da mein Bildschirm abgerundet ist<br>Es lebe Hamburg Süd,weiss du, verstehst du? ;)<br>Susi ist dOOf, es lebe die Ofenecke...", "hard to translate that") ); | ||
109 | m_stack->addWidget( lbl, 4 ); | ||
110 | |||
111 | |||
112 | /* THE signal mapper does all the magic */ | ||
113 | m_stack->raiseWidget( m_main ); | ||
114 | } | ||
115 | |||
116 | |||
117 | StackExample::~StackExample() { | ||
118 | |||
119 | } | ||
120 | |||
121 | |||
122 | |||
123 | void StackExample::closeEvent( QCloseEvent* ev) { | ||
124 | /* if the close even came when we displayed a details */ | ||
125 | if (m_stack->visibleWidget() != m_main ) { | ||
126 | m_stack->raiseWidget( m_main ); | ||
127 | ev->ignore(); | ||
128 | return; | ||
129 | } | ||
130 | |||
131 | ev->accept(); | ||
132 | } | ||
diff --git a/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.h b/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.h new file mode 100644 index 0000000..aea85cb --- a/dev/null +++ b/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * You may use, modify and distribute this example without any limitation | ||
3 | */ | ||
4 | |||
5 | #ifndef O_STACK_EXAMPLE_SIMPLE_H | ||
6 | #define O_STACK_EXAMPLE_SIMPLE_H | ||
7 | |||
8 | #include <qmainwindow.h> | ||
9 | #include <opie2/owidgetstack.h> | ||
10 | |||
11 | using namespace Opie; | ||
12 | |||
13 | class StackExample : public QMainWindow { | ||
14 | Q_OBJECT | ||
15 | public: | ||
16 | StackExample( QWidget* paren, const char* name, WFlags fl ); | ||
17 | ~StackExample(); | ||
18 | static QString appName() { return QString::fromLatin1("owidgetstack-example"); } | ||
19 | |||
20 | protected: | ||
21 | void closeEvent( QCloseEvent* e ); | ||
22 | private: | ||
23 | OWidgetStack* m_stack; | ||
24 | QWidget* m_main; | ||
25 | |||
26 | }; | ||
27 | |||
28 | #endif | ||
diff --git a/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.pro b/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.pro new file mode 100644 index 0000000..395a4fb --- a/dev/null +++ b/libopie2/examples/opieui/owidgetstack_example/owidgetstack_example.pro | |||
@@ -0,0 +1,13 @@ | |||
1 | CONFIG += qt warn_on | ||
2 | TEMPLATE = app | ||
3 | TARGET = owidgetstack-example | ||
4 | |||
5 | SOURCES = owidgetstack_example.cpp | ||
6 | HEADERS = owidgetstack_example.h | ||
7 | |||
8 | INCLUDEPATH += $(OPIEDIR)/include | ||
9 | DEPENDSPATH += $(OPIEDIR)/include | ||
10 | |||
11 | LIBS += -lqpe -lopieui2 | ||
12 | |||
13 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/libopie2/opiecore/oapplicationfactory.h b/libopie2/opiecore/oapplicationfactory.h new file mode 100644 index 0000000..6e10552 --- a/dev/null +++ b/libopie2/opiecore/oapplicationfactory.h | |||
@@ -0,0 +1,293 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Holger Freyther <zecke@handhelds.org> | ||
4 | =. | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
30 | /* | ||
31 | This work is derived from: | ||
32 | ---- | ||
33 | The Loki Library | ||
34 | Copyright (c) 2001 by Andrei Alexandrescu | ||
35 | This code accompanies the book: | ||
36 | Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design | ||
37 | Patterns Applied". Copyright (c) 2001. Addison-Wesley. | ||
38 | Permission to use, copy, modify, distribute and sell this software for any | ||
39 | purpose is hereby granted without fee, provided that the above copyright | ||
40 | notice appear in all copies and that both that copyright notice and this | ||
41 | permission notice appear in supporting documentation. | ||
42 | The author or Addison-Welsey Longman make no representations about the | ||
43 | suitability of this software for any purpose. It is provided "as is" | ||
44 | without express or implied warranty. | ||
45 | ---- | ||
46 | |||
47 | And KGenericFactor et all from Simon Hausmann <tronical@kde.org> | ||
48 | |||
49 | */ | ||
50 | |||
51 | #include <qstring.h> | ||
52 | #include <qmetaobject.h> | ||
53 | |||
54 | #include <qtopia/qcom.h> | ||
55 | #include <qtopia/applicationinterface.h> | ||
56 | |||
57 | namespace Opie { | ||
58 | struct NullType; | ||
59 | |||
60 | template <class T, class U> | ||
61 | struct Typelist | ||
62 | { | ||
63 | typedef T Head; | ||
64 | typedef U Tail; | ||
65 | }; | ||
66 | template< | ||
67 | typename T1 = NullType, typename T2 = NullType, typename T3 = NullType, | ||
68 | typename T4 = NullType, typename T5 = NullType, typename T6 = NullType, | ||
69 | typename T7 = NullType, typename T8 = NullType, typename T9 = NullType, | ||
70 | typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, | ||
71 | typename T13 = NullType, typename T14 = NullType, typename T15 = NullType, | ||
72 | typename T16 = NullType, typename T17 = NullType, typename T18 = NullType | ||
73 | > | ||
74 | struct MakeTypelist{ | ||
75 | private: | ||
76 | typedef typename MakeTypelist | ||
77 | < | ||
78 | T2 , T3 , T4 , | ||
79 | T5 , T6 , T7 , | ||
80 | T8 , T9 , T10, | ||
81 | T11, T12, T13, | ||
82 | T14, T15, T16, | ||
83 | T17, T18 | ||
84 | > | ||
85 | ::Result TailResult; | ||
86 | |||
87 | public: | ||
88 | typedef Typelist<T1, TailResult> Result; | ||
89 | }; | ||
90 | |||
91 | template<> | ||
92 | struct MakeTypelist<> | ||
93 | { | ||
94 | typedef NullType Result; | ||
95 | }; | ||
96 | |||
97 | } | ||
98 | |||
99 | /** | ||
100 | * To allow your application to be quick launched some one needs | ||
101 | * to create the QWidget. | ||
102 | * This is this factory. Make surce your widget has static QString Widget::appName() | ||
103 | * as one of its functions. | ||
104 | * | ||
105 | * This template takes one QWidget and initialized it in the form of | ||
106 | * MyWidget::MyWidget( QWidget* parent, const char* name, WFlags f ); | ||
107 | * | ||
108 | * To use it on your app do that: | ||
109 | * typedef OApplicationFactory<MyWidget> MyFactory; | ||
110 | * OPIE_EXPORT_APP( MyFactory ) | ||
111 | * | ||
112 | */ | ||
113 | template <class Product> | ||
114 | struct OApplicationFactory : public ApplicationInterface { | ||
115 | QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { | ||
116 | *iface = 0; | ||
117 | if ( uuid == IID_QUnknown ) *iface = this; | ||
118 | else if ( uuid == IID_QtopiaApplication ) *iface = this; | ||
119 | else return QS_FALSE; | ||
120 | (*iface)->addRef(); | ||
121 | return QS_OK; | ||
122 | } | ||
123 | |||
124 | /* | ||
125 | * | ||
126 | */ | ||
127 | virtual QWidget *createMainWindow( const QString& appName, QWidget* parent, | ||
128 | const char* name, Qt::WFlags f ) { | ||
129 | if (appName == Product::appName() ) | ||
130 | return new Product(parent, name, f ); | ||
131 | else | ||
132 | return 0l; | ||
133 | } | ||
134 | |||
135 | virtual QStringList applications()const { | ||
136 | QStringList list; | ||
137 | list << Product::appName() ; | ||
138 | |||
139 | return list; | ||
140 | } | ||
141 | Q_REFCOUNT | ||
142 | |||
143 | }; | ||
144 | |||
145 | |||
146 | /* Internal */ | ||
147 | |||
148 | template< class Product > | ||
149 | struct OPrivate { | ||
150 | inline static QWidget *multiFactory( const QString& appName, QWidget* parent, | ||
151 | const char* name, Qt::WFlags fl ) { | ||
152 | if ( appName == Product::appName() ) | ||
153 | return new Product( parent, name, fl ); | ||
154 | else | ||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | inline static QStringList multiString( const QStringList& _list ) { | ||
159 | QStringList list = _list; | ||
160 | list << Product::appName(); | ||
161 | return list; | ||
162 | } | ||
163 | }; | ||
164 | |||
165 | template <> | ||
166 | struct OPrivate<Opie::NullType > { | ||
167 | inline static QWidget* multiFactory ( const QString& , QWidget* , | ||
168 | const char* , Qt::WFlags ) { | ||
169 | return 0l; | ||
170 | } | ||
171 | inline static QStringList multiString( const QStringList& _list ) { | ||
172 | return _list; | ||
173 | } | ||
174 | }; | ||
175 | |||
176 | /* | ||
177 | template <> | ||
178 | struct OPrivate <Opie::NullType, Opie::NullType > { | ||
179 | inline static QWidget* multiFactory( const QString& , QWidget* , | ||
180 | const char* , Qt::WFlags ) { | ||
181 | return 0l; | ||
182 | } | ||
183 | |||
184 | inline static QStringList multiString( const QStringList& _list ) { | ||
185 | return _list; | ||
186 | } | ||
187 | }; | ||
188 | */ | ||
189 | |||
190 | template <class Product, class ProductListTail> | ||
191 | struct OPrivate< Opie::Typelist<Product, ProductListTail> > { | ||
192 | inline static QWidget* multiFactory( const QString& appName, QWidget* parent, | ||
193 | const char* name, Qt::WFlags fl) { | ||
194 | QWidget* wid = OPrivate<Product>::multiFactory( appName, parent, name, fl ); | ||
195 | |||
196 | if (!wid ) | ||
197 | wid = OPrivate<ProductListTail>::multiFactory( appName, parent, name, fl ); | ||
198 | |||
199 | return wid; | ||
200 | } | ||
201 | |||
202 | inline static QStringList multiString( const QStringList& _list ) { | ||
203 | QStringList list = _list; | ||
204 | |||
205 | list = OPrivate<Product>::multiString( list ); | ||
206 | list = OPrivate<ProductListTail>::multiString( list ); | ||
207 | |||
208 | return list; | ||
209 | } | ||
210 | }; | ||
211 | |||
212 | |||
213 | |||
214 | |||
215 | |||
216 | |||
217 | |||
218 | |||
219 | /* Internal END */ | ||
220 | |||
221 | /* | ||
222 | * If you want to export more than one Widget use that function | ||
223 | * Make sure all your Widgets provide the appName() static method | ||
224 | * otherwise you'll get a compiler error | ||
225 | * | ||
226 | * typedef Opie::MakeTypeList<MyWidget, MyDialog, MyMediaPlayer >::Result MyTypes; | ||
227 | * OPIE_EXPORT_APP( OApplicationFactory<MyTypes> ) | ||
228 | */ | ||
229 | |||
230 | template<class Product, class ProductListTail> | ||
231 | struct OApplicationFactory< Opie::Typelist<Product, ProductListTail > > | ||
232 | : ApplicationInterface { | ||
233 | QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { | ||
234 | *iface = 0; | ||
235 | if ( uuid == IID_QUnknown ) *iface = this; | ||
236 | else if ( uuid ==IID_QtopiaApplication ) *iface = this; | ||
237 | else return QS_FALSE; | ||
238 | (*iface)->addRef(); | ||
239 | return QS_OK; | ||
240 | } | ||
241 | |||
242 | QWidget* createMainWindow ( const QString& appName, QWidget* parent, | ||
243 | const char* name, Qt::WFlags fl ) { | ||
244 | qWarning("StringList is %s", applications().join(":").latin1() ); | ||
245 | return OPrivate< Opie::Typelist<Product, ProductListTail > >::multiFactory( appName, parent, name, fl ); | ||
246 | } | ||
247 | |||
248 | QStringList applications()const { | ||
249 | QStringList _list; | ||
250 | return OPrivate< Opie::Typelist<Product, ProductListTail> >::multiString( _list ); | ||
251 | } | ||
252 | |||
253 | Q_REFCOUNT | ||
254 | }; | ||
255 | |||
256 | |||
257 | /* If the library version should be build */ | ||
258 | #ifdef OPIE_APP_INTERFACE | ||
259 | #define OPIE_EXPORT_APP( factory ) Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( factory ) } | ||
260 | #else | ||
261 | |||
262 | #include <qpe/qpeapplication.h> | ||
263 | |||
264 | #define OPIE_EXPORT_APP( Factory ) \ | ||
265 | int main( int argc, char **argv ) { \ | ||
266 | QPEApplication a(argc, argv ); \ | ||
267 | QWidget *mw = 0;\ | ||
268 | \ | ||
269 | /* method from TT */ \ | ||
270 | QString executableName = QString::fromLatin1( argv[0] ); \ | ||
271 | executableName = executableName.right(executableName.length() \ | ||
272 | - executableName.findRev('/') - 1); \ | ||
273 | \ | ||
274 | Factory f; \ | ||
275 | QStringList list = f.applications(); \ | ||
276 | if (list.contains(executableName) ) \ | ||
277 | mw = f.createMainWindow(executableName, 0, 0, 0 ); \ | ||
278 | else \ | ||
279 | mw = f.createMainWindow( list[0], 0, 0, 0 ); \ | ||
280 | \ | ||
281 | if( mw ) { \ | ||
282 | if ( mw->metaObject()->slotNames().contains("setDocument(const QString&)" ) ) \ | ||
283 | a.showMainDocumentWidget( mw ); \ | ||
284 | else \ | ||
285 | a.showMainWidget( mw ); \ | ||
286 | \ | ||
287 | int rv = a.exec(); \ | ||
288 | delete mw; \ | ||
289 | return rv; \ | ||
290 | }else \ | ||
291 | return -1; \ | ||
292 | } | ||
293 | #endif | ||