summaryrefslogtreecommitdiff
path: root/examples/applet
authorzecke <zecke>2004-03-14 20:08:59 (UTC)
committer zecke <zecke>2004-03-14 20:08:59 (UTC)
commit0d79c003839718ae70b3b997162044abd5c26bf6 (patch) (unidiff)
tree19708b041da3a09df8f3b571cd634a846f4ad6d7 /examples/applet
parent05c8d999941989a97a581fb5822437034ec10fd7 (diff)
downloadopie-0d79c003839718ae70b3b997162044abd5c26bf6.zip
opie-0d79c003839718ae70b3b997162044abd5c26bf6.tar.gz
opie-0d79c003839718ae70b3b997162044abd5c26bf6.tar.bz2
Update the Examples
Diffstat (limited to 'examples/applet') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/applet/config.in2
-rw-r--r--examples/applet/example.pro2
-rw-r--r--examples/applet/simpleimpl.cpp96
-rw-r--r--examples/applet/simpleimpl.h23
4 files changed, 16 insertions, 107 deletions
diff --git a/examples/applet/config.in b/examples/applet/config.in
index 177de27..c3fb6dd 100644
--- a/examples/applet/config.in
+++ b/examples/applet/config.in
@@ -1,4 +1,4 @@
1 config APPLET_EXAMPLE 1 config APPLET_EXAMPLE
2 boolean "Taskbar Applet Example" 2 boolean "Taskbar Applet Example"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && EXAMPLES 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIEUI2 &&EXAMPLES
diff --git a/examples/applet/example.pro b/examples/applet/example.pro
index 3efd31e..5ae540b 100644
--- a/examples/applet/example.pro
+++ b/examples/applet/example.pro
@@ -10,7 +10,7 @@ HEADERS = simpleimpl.h
10INCLUDEPATH += $(OPIEDIR)/include 10INCLUDEPATH += $(OPIEDIR)/include
11DEPENDSPATH += $(OPIEDIR)/include 11DEPENDSPATH += $(OPIEDIR)/include
12 12
13LIBS += -lqpe 13LIBS += -lqpe -lopieui2
14 14
15 15
16include ( $(OPIEDIR)/include.pro ) 16include ( $(OPIEDIR)/include.pro )
diff --git a/examples/applet/simpleimpl.cpp b/examples/applet/simpleimpl.cpp
index 82fc6e5..62d9bf7 100644
--- a/examples/applet/simpleimpl.cpp
+++ b/examples/applet/simpleimpl.cpp
@@ -1,11 +1,16 @@
1
2#include "simpleimpl.h"
3
4#include <opie2/otaskbarapplet.h>
5
6#include <qpe/applnk.h> // for AppLnk
7#include <qpe/resource.h> // for Resource loading
8
1#include <qlabel.h> 9#include <qlabel.h>
2#include <qpainter.h> 10#include <qpainter.h>
3#include <qmessagebox.h> 11#include <qmessagebox.h>
4 12
5#include <qpe/applnk.h> // for AppLnk
6#include <qpe/resource.h> // for Resource loading
7 13
8#include "simpleimpl.h"
9 14
10 15
11SimpleApplet::SimpleApplet(QWidget *parent) 16SimpleApplet::SimpleApplet(QWidget *parent)
@@ -71,92 +76,15 @@ void SimpleApplet::paintEvent( QPaintEvent* ) {
71} 76}
72 77
73/* 78/*
74 * Here comes the implementation of the interface 79 * We need to add this symbol for the plugin exporter!
75 */ 80 */
76SimpleAppletImpl::SimpleAppletImpl() { 81int SimpleApplet::position(){
77}
78/* needed cause until it is only pure virtual */
79SimpleAppletImpl::~SimpleAppletImpl() {
80 /*
81 * we will delete our applets as well
82 * setAUtoDelete makes the QList free
83 * the objects behind the pointers
84 */
85 m_applets.setAutoDelete( true );
86 m_applets.clear();
87}
88
89/*
90 * For the taskbar interface return a Widget
91 */
92QWidget* SimpleAppletImpl::applet( QWidget* parent ) {
93 /*
94 * There are problems with ownership. So we add
95 * our ownlist and clear this;
96 */
97 SimpleApplet* ap = new SimpleApplet( parent );
98 m_applets.append( ap );
99
100 return ap;
101}
102
103/*
104 * A small hint where the Applet Should be displayed
105 */
106int SimpleAppletImpl::position()const {
107 return 1; 82 return 1;
108} 83}
109 84
110 85
111/*
112 * Now the important QUnkownInterface method without
113 * this one your applet won't load
114 * @param uuid The uuid of the interface
115 * @param iface The pointer to the interface ptr
116 */
117QRESULT SimpleAppletImpl::queryInterface( const QUuid& uuid, QUnknownInterface** iface) {
118 /* set the pointer to the interface to 0 */
119 *iface = 0;
120
121 /*
122 * we check if we support the requested interface
123 * and then assign to the pointer.
124 * You may alos create another interface here so
125 * *iface = this is only in this simple case true you
126 * could also support more interfaces.
127 * But this example below is the most common use.
128 * Now the caller knows that the Interface Pointer
129 * is valid and the interface supported
130 */
131 if ( uuid == IID_QUnknown )
132 *iface = this;
133 else if ( uuid == IID_TaskbarApplet )
134 *iface = this;
135 else
136 return QS_FALSE;
137
138 if ( *iface )
139 (*iface)->addRef();
140
141 return QS_OK;
142}
143
144 86
145/* 87/*
146 * Finally we need to export the Interface. 88 * Here comes the implementation of the interface
147 * CREATE_INSTANCE creates a interface and calls
148 * queryInterface for the QUnknownInterface once
149 * With out this function the applet can't be loaded.
150 *
151 * NOTE: If your applet does not load it's likely you've an
152 * unresolved symbol. Change the .pro TEMPLATE = lib to TEMPLATE= app
153 * and recompile. If the linker only complains about a missing
154 * main method the problem is more complex. In most cases it'll say
155 * you which symbols are missing and you can implement them.
156 * The main(int argc, char* argv[] ) does not need to be
157 * included in a library so it's ok that the linker complains
158 */ 89 */
159Q_EXPORT_INTERFACE() { 90EXPORT_OPIE_APPLET_v1( SimpleApplet ) \ No newline at end of file
160 Q_CREATE_INSTANCE( SimpleAppletImpl )
161}
162
diff --git a/examples/applet/simpleimpl.h b/examples/applet/simpleimpl.h
index f58e2af..90c632f 100644
--- a/examples/applet/simpleimpl.h
+++ b/examples/applet/simpleimpl.h
@@ -17,6 +17,7 @@
17 * need to implement. The interfaces inherits from QUnknownInterface and 17 * need to implement. The interfaces inherits from QUnknownInterface and
18 * you'll need inherit from the interface. 18 * you'll need inherit from the interface.
19 * As example we will use the Taskbar interface 19 * As example we will use the Taskbar interface
20 * the OTaskBarAppletWrapper implements the factory for us
20 */ 21 */
21 22
22#ifndef SIMPLE_OPIE_EXAMPLE_APPLET_H 23#ifndef SIMPLE_OPIE_EXAMPLE_APPLET_H
@@ -45,33 +46,13 @@ class SimpleApplet : public QWidget {
45public: 46public:
46 SimpleApplet(QWidget *parent); 47 SimpleApplet(QWidget *parent);
47 ~SimpleApplet(); 48 ~SimpleApplet();
49 static int position();
48private: 50private:
49 void mousePressEvent( QMouseEvent* ); 51 void mousePressEvent( QMouseEvent* );
50 void paintEvent( QPaintEvent* ); 52 void paintEvent( QPaintEvent* );
51 QPixmap *m_pix; 53 QPixmap *m_pix;
52}; 54};
53 55
54class SimpleAppletImpl : public TaskbarAppletInterface {
55public:
56
57 SimpleAppletImpl();
58 virtual ~SimpleAppletImpl();
59
60 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
61
62 QWidget *applet( QWidget* parent );
63 int position()const;
64
65 /*
66 * macro for reference countint
67 * if reference drops to zero
68 * delete this is called
69 */
70 Q_REFCOUNT
71
72private:
73 QList<SimpleApplet> m_applets;
74};
75 56
76 57
77#endif 58#endif