-rw-r--r-- | examples/simple-pim/config.in | 2 | ||||
-rw-r--r-- | examples/simple-pim/example.pro | 2 | ||||
-rw-r--r-- | examples/simple-pim/simple.cpp | 39 | ||||
-rw-r--r-- | examples/simple-pim/simple.h | 26 |
4 files changed, 37 insertions, 32 deletions
diff --git a/examples/simple-pim/config.in b/examples/simple-pim/config.in index 5d80f21..aa1a426 100644 --- a/examples/simple-pim/config.in +++ b/examples/simple-pim/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config SIMPLE_PIM_EXAMPLE | 1 | config SIMPLE_PIM_EXAMPLE |
2 | boolean "Mainwindow with PIM and QCOP usage" | 2 | boolean "Mainwindow with PIM and QCOP usage" |
3 | default "y" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) && EXAMPLES && LIBOPIE | 4 | depends ( LIBQPE || LIBQPE-X11 ) && EXAMPLES && LIBOPIEPIM2 |
diff --git a/examples/simple-pim/example.pro b/examples/simple-pim/example.pro index c3aab53..ebcdb2b 100644 --- a/examples/simple-pim/example.pro +++ b/examples/simple-pim/example.pro | |||
@@ -1,17 +1,17 @@ | |||
1 | CONFIG += qt warn_on quick-app | 1 | CONFIG += qt warn_on quick-app |
2 | 2 | ||
3 | 3 | ||
4 | TARGET = simple-pim | 4 | TARGET = simple-pim |
5 | 5 | ||
6 | HEADERS = simple.h | 6 | HEADERS = simple.h |
7 | SOURCES = simple.cpp | 7 | SOURCES = simple.cpp |
8 | 8 | ||
9 | 9 | ||
10 | INCLUDEPATH += $(OPIEDIR)/include | 10 | INCLUDEPATH += $(OPIEDIR)/include |
11 | DEPENDPATH += $(OPIEDIR)/include | 11 | DEPENDPATH += $(OPIEDIR)/include |
12 | 12 | ||
13 | 13 | ||
14 | # we now also include opie | 14 | # we now also include opie |
15 | LIBS += -lqpe -lopie | 15 | LIBS += -lqpe -lopiepim2 -lopieui2 |
16 | 16 | ||
17 | include ( $(OPIEDIR)/include.pro ) | 17 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/examples/simple-pim/simple.cpp b/examples/simple-pim/simple.cpp index 029e71b..50905bf 100644 --- a/examples/simple-pim/simple.cpp +++ b/examples/simple-pim/simple.cpp | |||
@@ -1,445 +1,446 @@ | |||
1 | #include <qaction.h> // action | 1 | #include <qaction.h> // action |
2 | #include <qmenubar.h> // menubar | 2 | #include <qmenubar.h> // menubar |
3 | #include <qtoolbar.h> // toolbar | 3 | #include <qtoolbar.h> // toolbar |
4 | #include <qlabel.h> // a label | 4 | #include <qlabel.h> // a label |
5 | #include <qpushbutton.h> // the header file for the QPushButton | 5 | #include <qpushbutton.h> // the header file for the QPushButton |
6 | #include <qlayout.h> | 6 | #include <qlayout.h> |
7 | #include <qtimer.h> // we use it for the singleShot | 7 | #include <qtimer.h> // we use it for the singleShot |
8 | #include <qdatetime.h> // for QDate | 8 | #include <qdatetime.h> // for QDate |
9 | #include <qtextview.h> // a rich text widget | 9 | #include <qtextview.h> // a rich text widget |
10 | #include <qdialog.h> | 10 | #include <qdialog.h> |
11 | #include <qwhatsthis.h> // for whats this | 11 | #include <qwhatsthis.h> // for whats this |
12 | 12 | ||
13 | #include <qpe/qpeapplication.h> // the QPEApplication | 13 | #include <qpe/qpeapplication.h> // the QPEApplication |
14 | #include <qpe/resource.h> | 14 | #include <qpe/resource.h> |
15 | #include <qpe/sound.h> | 15 | #include <qpe/sound.h> |
16 | #include <qpe/qcopenvelope_qws.h> | 16 | #include <qpe/qcopenvelope_qws.h> |
17 | #include <qpe/datebookmonth.h> | 17 | #include <qpe/datebookmonth.h> |
18 | #include <qpe/timestring.h> | 18 | #include <qpe/timestring.h> |
19 | 19 | ||
20 | #include <opie/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching | 20 | #include <opie2/oapplicationfactory.h> // a template + macro to save the main method and allow quick launching |
21 | #include <opie/otabwidget.h> | 21 | #include <opie2/otabwidget.h> |
22 | #include <opie/owait.h> | 22 | #include <opie2/owait.h> |
23 | 23 | ||
24 | #include "simple.h" | 24 | #include "simple.h" |
25 | 25 | ||
26 | /* | 26 | /* |
27 | * implementation of simple | 27 | * implementation of simple |
28 | */ | 28 | */ |
29 | 29 | ||
30 | /* | 30 | /* |
31 | * The factory is used for quicklaunching | 31 | * The factory is used for quicklaunching |
32 | * It needs a constructor ( c'tor ) with at least QWidget, const char* and WFlags as parameter and a static QString appName() matching the TARGET of the .pro | 32 | * It needs a constructor ( c'tor ) with at least QWidget, const char* and WFlags as parameter and a static QString appName() matching the TARGET of the .pro |
33 | * | 33 | * |
34 | * Depending on the global quick launch setting this will create | 34 | * Depending on the global quick launch setting this will create |
35 | * either a main method or one for our component plugin system | 35 | * either a main method or one for our component plugin system |
36 | */ | 36 | */ |
37 | 37 | ||
38 | using namespace Opie::Core; | ||
38 | OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) | 39 | OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) |
39 | 40 | ||
40 | MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl ) | 41 | MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl ) |
41 | : QMainWindow( parent, name, fl ) { | 42 | : QMainWindow( parent, name, fl ) { |
42 | setCaption(tr("My MainWindow") ); | 43 | setCaption(tr("My MainWindow") ); |
43 | 44 | ||
44 | m_desktopChannel = 0; | 45 | m_desktopChannel = 0; |
45 | m_loading = 0; | 46 | m_loading = 0; |
46 | 47 | ||
47 | initUI(); | 48 | initUI(); |
48 | 49 | ||
49 | 50 | ||
50 | /* | 51 | /* |
51 | * Tab widget as central | 52 | * Tab widget as central |
52 | */ | 53 | */ |
53 | m_tab = new OTabWidget(this); | 54 | m_tab = new Opie::Ui::OTabWidget(this); |
54 | 55 | ||
55 | setCentralWidget( m_tab ); | 56 | setCentralWidget( m_tab ); |
56 | 57 | ||
57 | m_todoView = new PIMListView(m_tab, "Todo view" ); | 58 | m_todoView = new PIMListView(m_tab, "Todo view" ); |
58 | m_tab->addTab( m_todoView,"todo/TodoList", tr("Todos") ); | 59 | m_tab->addTab( m_todoView,"todo/TodoList", tr("Todos") ); |
59 | 60 | ||
60 | m_dateView = new PIMListView(m_tab, "Datebook view" ); | 61 | m_dateView = new PIMListView(m_tab, "Datebook view" ); |
61 | m_tab->addTab( m_dateView, "datebook/DateBook", tr("Events") ); | 62 | m_tab->addTab( m_dateView, "datebook/DateBook", tr("Events") ); |
62 | 63 | ||
63 | /* now connect the actions */ | 64 | /* now connect the actions */ |
64 | /* | 65 | /* |
65 | * we connect the activated to our show | 66 | * we connect the activated to our show |
66 | * and on activation we will show a detailed | 67 | * and on activation we will show a detailed |
67 | * summary of the record | 68 | * summary of the record |
68 | */ | 69 | */ |
69 | connect(m_fire, SIGNAL(activated() ), | 70 | connect(m_fire, SIGNAL(activated() ), |
70 | this, SLOT(slotShow() ) ); | 71 | this, SLOT(slotShow() ) ); |
71 | 72 | ||
72 | /* | 73 | /* |
73 | * We will change the date | 74 | * We will change the date |
74 | */ | 75 | */ |
75 | connect(m_dateAction, SIGNAL(activated() ), | 76 | connect(m_dateAction, SIGNAL(activated() ), |
76 | this, SLOT(slotDate() ) ); | 77 | this, SLOT(slotDate() ) ); |
77 | 78 | ||
78 | /* | 79 | /* |
79 | * connect the show signal of the PIMListView | 80 | * connect the show signal of the PIMListView |
80 | * to a slot to show a dialog | 81 | * to a slot to show a dialog |
81 | */ | 82 | */ |
82 | connect(m_todoView, SIGNAL(showRecord(const OPimRecord&) ), | 83 | connect(m_todoView, SIGNAL(showRecord(const OPimRecord&) ), |
83 | this, SLOT(slotShowRecord(const OPimRecord&) ) ); | 84 | this, SLOT(slotShowRecord(const OPimRecord&) ) ); |
84 | connect(m_dateView, SIGNAL(showRecord(const OPimRecord&) ), | 85 | connect(m_dateView, SIGNAL(showRecord(const OPimRecord&) ), |
85 | this, SLOT(slotShowRecord(const OPimRecord&) ) ); | 86 | this, SLOT(slotShowRecord(const OPimRecord&) ) ); |
86 | 87 | ||
87 | /* | 88 | /* |
88 | * Now comes the important lines of code for this example | 89 | * Now comes the important lines of code for this example |
89 | * We do not directly call load but delay loading until | 90 | * We do not directly call load but delay loading until |
90 | * all Events are dispatches and handled. | 91 | * all Events are dispatches and handled. |
91 | * SO we will load once our window is mapped to screen | 92 | * SO we will load once our window is mapped to screen |
92 | * to achieve that we use a QTimer::singleShot | 93 | * to achieve that we use a QTimer::singleShot |
93 | * After 10 milli seconds the timer fires and on TimerEvent | 94 | * After 10 milli seconds the timer fires and on TimerEvent |
94 | * out slot slotLoad will be called | 95 | * out slot slotLoad will be called |
95 | * Remember this a Constructor to construct your object and not | 96 | * Remember this a Constructor to construct your object and not |
96 | * to load | 97 | * to load |
97 | */ | 98 | */ |
98 | QTimer::singleShot( 10, this, SLOT(slotLoad() ) ); | 99 | QTimer::singleShot( 10, this, SLOT(slotLoad() ) ); |
99 | } | 100 | } |
100 | 101 | ||
101 | MainWindow::~MainWindow() { | 102 | MainWindow::~MainWindow() { |
102 | // again nothing to delete because Qt takes care | 103 | // again nothing to delete because Qt takes care |
103 | } | 104 | } |
104 | 105 | ||
105 | 106 | ||
106 | void MainWindow::setDocument( const QString& /*str*/ ) { | 107 | void MainWindow::setDocument( const QString& /*str*/ ) { |
107 | } | 108 | } |
108 | 109 | ||
109 | 110 | ||
110 | void MainWindow::initUI() { | 111 | void MainWindow::initUI() { |
111 | 112 | ||
112 | setToolBarsMovable( false ); | 113 | setToolBarsMovable( false ); |
113 | 114 | ||
114 | QToolBar *menuBarHolder = new QToolBar( this ); | 115 | QToolBar *menuBarHolder = new QToolBar( this ); |
115 | 116 | ||
116 | menuBarHolder->setHorizontalStretchable( true ); | 117 | menuBarHolder->setHorizontalStretchable( true ); |
117 | QMenuBar *mb = new QMenuBar( menuBarHolder ); | 118 | QMenuBar *mb = new QMenuBar( menuBarHolder ); |
118 | QToolBar *tb = new QToolBar( this ); | 119 | QToolBar *tb = new QToolBar( this ); |
119 | 120 | ||
120 | QPopupMenu *fileMenu = new QPopupMenu( this ); | 121 | QPopupMenu *fileMenu = new QPopupMenu( this ); |
121 | 122 | ||
122 | 123 | ||
123 | QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"), | 124 | QAction *a = new QAction( tr("Quit"), Resource::loadIconSet("quit_icon"), |
124 | QString::null, 0, this, "quit_action" ); | 125 | QString::null, 0, this, "quit_action" ); |
125 | /* | 126 | /* |
126 | * Connect quit to the QApplication quit slot | 127 | * Connect quit to the QApplication quit slot |
127 | */ | 128 | */ |
128 | connect(a, SIGNAL(activated() ), | 129 | connect(a, SIGNAL(activated() ), |
129 | qApp, SLOT(quit() ) ); | 130 | qApp, SLOT(quit() ) ); |
130 | a->addTo( fileMenu ); | 131 | a->addTo( fileMenu ); |
131 | 132 | ||
132 | a = new QAction(tr("View Current"), | 133 | a = new QAction(tr("View Current"), |
133 | Resource::loadIconSet("zoom"), | 134 | Resource::loadIconSet("zoom"), |
134 | QString::null, 0, this, "view current"); | 135 | QString::null, 0, this, "view current"); |
135 | /* a simple whats this online explanation of out button */ | 136 | /* a simple whats this online explanation of out button */ |
136 | a->setWhatsThis(tr("Views the current record") ); | 137 | a->setWhatsThis(tr("Views the current record") ); |
137 | /* or QWhatsThis::add(widget, "description" ); */ | 138 | /* or QWhatsThis::add(widget, "description" ); */ |
138 | 139 | ||
139 | /* see the power? */ | 140 | /* see the power? */ |
140 | a->addTo( fileMenu ); | 141 | a->addTo( fileMenu ); |
141 | a->addTo( tb ); | 142 | a->addTo( tb ); |
142 | m_fire = a; | 143 | m_fire = a; |
143 | 144 | ||
144 | a = new QAction(tr("Choose Date"), | 145 | a = new QAction(tr("Choose Date"), |
145 | Resource::loadIconSet("day"), | 146 | Resource::loadIconSet("day"), |
146 | QString::null, 0, this, "choose date" ); | 147 | QString::null, 0, this, "choose date" ); |
147 | a->addTo( fileMenu ); | 148 | a->addTo( fileMenu ); |
148 | a->addTo( tb ); | 149 | a->addTo( tb ); |
149 | m_dateAction = a; | 150 | m_dateAction = a; |
150 | 151 | ||
151 | mb->insertItem(tr("File"), fileMenu ); | 152 | mb->insertItem(tr("File"), fileMenu ); |
152 | 153 | ||
153 | } | 154 | } |
154 | 155 | ||
155 | void MainWindow::slotLoad() { | 156 | void MainWindow::slotLoad() { |
156 | /* | 157 | /* |
157 | * There is no real shared access in the PIM API | 158 | * There is no real shared access in the PIM API |
158 | * It wasn't finish cause of health problems of one | 159 | * It wasn't finish cause of health problems of one |
159 | * of the authors so we do something fancy and use QCOP | 160 | * of the authors so we do something fancy and use QCOP |
160 | * the IPC system to get a current copy | 161 | * the IPC system to get a current copy |
161 | */ | 162 | */ |
162 | /* NOTES to QCOP: QCOP operates over channels and use QDataStream | 163 | /* NOTES to QCOP: QCOP operates over channels and use QDataStream |
163 | * to send data. You can check if a channel isRegistered or hook | 164 | * to send data. You can check if a channel isRegistered or hook |
164 | * yourself to that channel. A Channel is QCString and normally | 165 | * yourself to that channel. A Channel is QCString and normally |
165 | * prefix with QPE/ and then the system in example QPE/System, | 166 | * prefix with QPE/ and then the system in example QPE/System, |
166 | * QPE/Desktop a special channel is the application channel | 167 | * QPE/Desktop a special channel is the application channel |
167 | * it QPE/Application/appname this channel gets created on app | 168 | * it QPE/Application/appname this channel gets created on app |
168 | * startup by QPEApplication. QCOP is asynchronous | 169 | * startup by QPEApplication. QCOP is asynchronous |
169 | * | 170 | * |
170 | * To send you'll use QCopEnevelope | 171 | * To send you'll use QCopEnevelope |
171 | * | 172 | * |
172 | */ | 173 | */ |
173 | /* | 174 | /* |
174 | * What we will do is first is get to know if either | 175 | * What we will do is first is get to know if either |
175 | * datebook or todolist are running if so we will kindly | 176 | * datebook or todolist are running if so we will kindly |
176 | * asked to save the data for us. | 177 | * asked to save the data for us. |
177 | * If neither are running we can load directly | 178 | * If neither are running we can load directly |
178 | */ | 179 | */ |
179 | if (!QCopChannel::isRegistered("QPE/Application/todolist") && | 180 | if (!QCopChannel::isRegistered("QPE/Application/todolist") && |
180 | !QCopChannel::isRegistered("QPE/Application/datebook") ) { | 181 | !QCopChannel::isRegistered("QPE/Application/datebook") ) { |
181 | m_db.load(); | 182 | m_db.load(); |
182 | m_tb.load(); | 183 | m_tb.load(); |
183 | return slotLoadForDay( QDate::currentDate() ); | 184 | return slotLoadForDay( QDate::currentDate() ); |
184 | } | 185 | } |
185 | 186 | ||
186 | /* | 187 | /* |
187 | * prepare our answer machine the QCopChannel | 188 | * prepare our answer machine the QCopChannel |
188 | * QPE/Desktop will send "flushDone(QString)" when | 189 | * QPE/Desktop will send "flushDone(QString)" when |
189 | * the flush is done it emits a signal on receive | 190 | * the flush is done it emits a signal on receive |
190 | */ | 191 | */ |
191 | m_desktopChannel = new QCopChannel("QPE/Desktop"); | 192 | m_desktopChannel = new QCopChannel("QPE/Desktop"); |
192 | connect(m_desktopChannel, SIGNAL(received(const QCString&,const QByteArray&) ), | 193 | connect(m_desktopChannel, SIGNAL(received(const QCString&,const QByteArray&) ), |
193 | this, SLOT(slotDesktopReceive(const QCString&,const QByteArray&) ) ); | 194 | this, SLOT(slotDesktopReceive(const QCString&,const QByteArray&) ) ); |
194 | /* the numberof synced channels will be set to zero */ | 195 | /* the numberof synced channels will be set to zero */ |
195 | m_synced = 0; | 196 | m_synced = 0; |
196 | 197 | ||
197 | /* | 198 | /* |
198 | * We use {} around the QCopEnvelope because it sends its | 199 | * We use {} around the QCopEnvelope because it sends its |
199 | * data on destruction of QCopEnvelope with | 200 | * data on destruction of QCopEnvelope with |
200 | */ | 201 | */ |
201 | /* check again if not present increment synced*/ | 202 | /* check again if not present increment synced*/ |
202 | if ( QCopChannel::isRegistered("QPE/Application/todolist") ) { | 203 | if ( QCopChannel::isRegistered("QPE/Application/todolist") ) { |
203 | QCopEnvelope env("QPE/Application/todolist", "flush()" ); | 204 | QCopEnvelope env("QPE/Application/todolist", "flush()" ); |
204 | // env << data; but we do not have any parameters here | 205 | // env << data; but we do not have any parameters here |
205 | }else | 206 | }else |
206 | m_synced++; | 207 | m_synced++; |
207 | 208 | ||
208 | if ( QCopChannel::isRegistered("QPE/Application/datebook") ) { | 209 | if ( QCopChannel::isRegistered("QPE/Application/datebook") ) { |
209 | QCopEnvelope env("QPE/Application/datebook", "flush()" ); | 210 | QCopEnvelope env("QPE/Application/datebook", "flush()" ); |
210 | }else | 211 | }else |
211 | m_synced++; | 212 | m_synced++; |
212 | 213 | ||
213 | /* we will provide a wait scrren */ | 214 | /* we will provide a wait scrren */ |
214 | m_loading = new OWait(this, "wait screen" ); | 215 | m_loading = new Opie::Ui::OWait(this, "wait screen" ); |
215 | } | 216 | } |
216 | 217 | ||
217 | void MainWindow::slotDesktopReceive(const QCString& cmd, const QByteArray& data ) { | 218 | void MainWindow::slotDesktopReceive(const QCString& cmd, const QByteArray& data ) { |
218 | /* the bytearray was filled with the QDataStream now | 219 | /* the bytearray was filled with the QDataStream now |
219 | * we open it read only to get the value(s) | 220 | * we open it read only to get the value(s) |
220 | */ | 221 | */ |
221 | QDataStream stream(data, IO_ReadOnly ); | 222 | QDataStream stream(data, IO_ReadOnly ); |
222 | /* | 223 | /* |
223 | * we're only interested in the flushDone | 224 | * we're only interested in the flushDone |
224 | */ | 225 | */ |
225 | if ( cmd == "flushDone(QString)" ) { | 226 | if ( cmd == "flushDone(QString)" ) { |
226 | QString appname; | 227 | QString appname; |
227 | stream >> appname; // get the first argument out of stream | 228 | stream >> appname; // get the first argument out of stream |
228 | if (appname == QString::fromLatin1("datebook") || | 229 | if (appname == QString::fromLatin1("datebook") || |
229 | appname == QString::fromLatin1("todolist") ) | 230 | appname == QString::fromLatin1("todolist") ) |
230 | m_synced++; | 231 | m_synced++; |
231 | } | 232 | } |
232 | 233 | ||
233 | /* | 234 | /* |
234 | * If we synced both we can go ahead | 235 | * If we synced both we can go ahead |
235 | * In future this is not needed anymore when we finally | 236 | * In future this is not needed anymore when we finally |
236 | * implemented X-Ref and other PIM features | 237 | * implemented X-Ref and other PIM features |
237 | */ | 238 | */ |
238 | if (m_synced >= 2 ) { | 239 | if (m_synced >= 2 ) { |
239 | delete m_loading; | 240 | delete m_loading; |
240 | delete m_desktopChannel; | 241 | delete m_desktopChannel; |
241 | /* now we finally can start doing the actual loading */ | 242 | /* now we finally can start doing the actual loading */ |
242 | m_tb.load(); | 243 | m_tb.load(); |
243 | m_db.load(); | 244 | m_db.load(); |
244 | { | 245 | { |
245 | /* tell the applications to reload */ | 246 | /* tell the applications to reload */ |
246 | QCopEnvelope("QPE/Application/todolist", "reload()"); | 247 | QCopEnvelope("QPE/Application/todolist", "reload()"); |
247 | QCopEnvelope("QPE/Application/datebook", "reload()"); | 248 | QCopEnvelope("QPE/Application/datebook", "reload()"); |
248 | } | 249 | } |
249 | slotLoadForDay( QDate::currentDate() ); | 250 | slotLoadForDay( QDate::currentDate() ); |
250 | } | 251 | } |
251 | 252 | ||
252 | } | 253 | } |
253 | 254 | ||
254 | /* overloaded member for shortcoming of libqpe */ | 255 | /* overloaded member for shortcoming of libqpe */ |
255 | void MainWindow::slotLoadForDay(int y, int m, int d) { | 256 | void MainWindow::slotLoadForDay(int y, int m, int d) { |
256 | /* year,month, day */ | 257 | /* year,month, day */ |
257 | slotLoadForDay( QDate(y, m, d ) ); | 258 | slotLoadForDay( QDate(y, m, d ) ); |
258 | } | 259 | } |
259 | 260 | ||
260 | void MainWindow::slotLoadForDay(const QDate& date) { | 261 | void MainWindow::slotLoadForDay(const QDate& date) { |
261 | 262 | ||
262 | 263 | ||
263 | /* all todos for today including the ones without dueDate */ | 264 | /* all todos for today including the ones without dueDate */ |
264 | m_todoView->set( m_tb.effectiveToDos(date, date ) ); | 265 | m_todoView->set( m_tb.effectiveToDos(date, date ) ); |
265 | m_dateView->set( m_db.effectiveEvents( date, date ) ); | 266 | m_dateView->set( m_db.effectiveEvents( date, date ) ); |
266 | } | 267 | } |
267 | 268 | ||
268 | /* we want to show the current record */ | 269 | /* we want to show the current record */ |
269 | void MainWindow::slotShow() { | 270 | void MainWindow::slotShow() { |
270 | /* we only added PIMListViews so we can safely cast */ | 271 | /* we only added PIMListViews so we can safely cast */ |
271 | PIMListView *view = static_cast<PIMListView*>(m_tab->currentWidget() ); | 272 | PIMListView *view = static_cast<PIMListView*>(m_tab->currentWidget() ); |
272 | 273 | ||
273 | /* ask the view to send a signal */ | 274 | /* ask the view to send a signal */ |
274 | view->showCurrentRecord(); | 275 | view->showCurrentRecord(); |
275 | 276 | ||
276 | } | 277 | } |
277 | 278 | ||
278 | /* as answer this slot will be called */ | 279 | /* as answer this slot will be called */ |
279 | void MainWindow::slotShowRecord( const OPimRecord& rec) { | 280 | void MainWindow::slotShowRecord( const Opie::OPimRecord& rec) { |
280 | /* got a parent but still is a toplevel MODAL dialog */ | 281 | /* got a parent but still is a toplevel MODAL dialog */ |
281 | QDialog* dia = new QDialog(this,"dialog",TRUE ); | 282 | QDialog* dia = new QDialog(this,"dialog",TRUE ); |
282 | QVBoxLayout *box = new QVBoxLayout( dia ); | 283 | QVBoxLayout *box = new QVBoxLayout( dia ); |
283 | dia->setCaption( tr("View Record") ); | 284 | dia->setCaption( tr("View Record") ); |
284 | 285 | ||
285 | 286 | ||
286 | QTextView *view = new QTextView(dia ); | 287 | QTextView *view = new QTextView(dia ); |
287 | view->setText( rec.toRichText() ); | 288 | view->setText( rec.toRichText() ); |
288 | box->addWidget( view ); | 289 | box->addWidget( view ); |
289 | /* | 290 | /* |
290 | * execute via QPEApplication | 291 | * execute via QPEApplication |
291 | * this allows QPEApplication to make a sane decision | 292 | * this allows QPEApplication to make a sane decision |
292 | * on the size | 293 | * on the size |
293 | */ | 294 | */ |
294 | dia->showMaximized(); | 295 | dia->showMaximized(); |
295 | QPEApplication::execDialog( dia ); | 296 | QPEApplication::execDialog( dia ); |
296 | delete dia; | 297 | delete dia; |
297 | } | 298 | } |
298 | 299 | ||
299 | 300 | ||
300 | void MainWindow::slotDate() { | 301 | void MainWindow::slotDate() { |
301 | /* | 302 | /* |
302 | * called by the action we will show a Popup | 303 | * called by the action we will show a Popup |
303 | * at the current mouse position with a DateChooser | 304 | * at the current mouse position with a DateChooser |
304 | * to select the day | 305 | * to select the day |
305 | */ | 306 | */ |
306 | qWarning("slot Date"); | 307 | qWarning("slot Date"); |
307 | QPopupMenu *menu = new QPopupMenu(); | 308 | QPopupMenu *menu = new QPopupMenu(); |
308 | /* A Month to select a date from TRUE for auto close */ | 309 | /* A Month to select a date from TRUE for auto close */ |
309 | DateBookMonth *month = new DateBookMonth(menu, 0, true ); | 310 | DateBookMonth *month = new DateBookMonth(menu, 0, true ); |
310 | connect(month, SIGNAL(dateClicked(int,int,int) ), | 311 | connect(month, SIGNAL(dateClicked(int,int,int) ), |
311 | this, SLOT(slotLoadForDay(int,int,int) ) ); | 312 | this, SLOT(slotLoadForDay(int,int,int) ) ); |
312 | 313 | ||
313 | menu->insertItem( month ); | 314 | menu->insertItem( month ); |
314 | 315 | ||
315 | menu->exec( QCursor::pos() ); | 316 | menu->exec( QCursor::pos() ); |
316 | 317 | ||
317 | /* | 318 | /* |
318 | * we do not need to delete month because | 319 | * we do not need to delete month because |
319 | * we delete its parent menu | 320 | * we delete its parent menu |
320 | */ | 321 | */ |
321 | 322 | ||
322 | delete menu; | 323 | delete menu; |
323 | } | 324 | } |
324 | 325 | ||
325 | /* | 326 | /* |
326 | * An anonymous namespace this symbol is only available here | 327 | * An anonymous namespace this symbol is only available here |
327 | * so truely private | 328 | * so truely private |
328 | */ | 329 | */ |
329 | namespace { | 330 | namespace { |
330 | /* not static cause namespace does that what static would do */ | 331 | /* not static cause namespace does that what static would do */ |
331 | const int RTTI = 5050; | 332 | const int RTTI = 5050; |
332 | /* | 333 | /* |
333 | * every ListView got Items. we've special pim items | 334 | * every ListView got Items. we've special pim items |
334 | * holding ownership and the pointer to a pim record | 335 | * holding ownership and the pointer to a pim record |
335 | * it can't hold a pimrecord directly because this | 336 | * it can't hold a pimrecord directly because this |
336 | * would introduce slicing... any break | 337 | * would introduce slicing... any break |
337 | */ | 338 | */ |
338 | /* | 339 | /* |
339 | * A struct is a special class. Everything is public by | 340 | * A struct is a special class. Everything is public by |
340 | * default. | 341 | * default. |
341 | */ | 342 | */ |
342 | struct PIMListViewItem : public QListViewItem { | 343 | struct PIMListViewItem : public QListViewItem { |
343 | /* | 344 | /* |
344 | *currently no hierachies are planed for the example | 345 | *currently no hierachies are planed for the example |
345 | * so only one constructor with a QListView as parent | 346 | * so only one constructor with a QListView as parent |
346 | */ | 347 | */ |
347 | PIMListViewItem( QListView*, OPimRecord* record ); | 348 | PIMListViewItem( QListView*, Opie::OPimRecord* record ); |
348 | ~PIMListViewItem(); | 349 | ~PIMListViewItem(); |
349 | 350 | ||
350 | /* used by the QListViewItem to easily allow identifiying of different | 351 | /* used by the QListViewItem to easily allow identifiying of different |
351 | * items. Values greater than 1000 should be used */ | 352 | * items. Values greater than 1000 should be used */ |
352 | int rtti()const; | 353 | int rtti()const; |
353 | OPimRecord* record()const; | 354 | Opie::OPimRecord* record()const; |
354 | 355 | ||
355 | private: | 356 | private: |
356 | OPimRecord* m_record; | 357 | Opie::OPimRecord* m_record; |
357 | }; | 358 | }; |
358 | 359 | ||
359 | PIMListViewItem::PIMListViewItem( QListView *p, OPimRecord* rec ) | 360 | PIMListViewItem::PIMListViewItem( QListView *p, Opie::OPimRecord* rec ) |
360 | : QListViewItem(p), m_record( rec ) { | 361 | : QListViewItem(p), m_record( rec ) { |
361 | } | 362 | } |
362 | 363 | ||
363 | PIMListViewItem::~PIMListViewItem() { | 364 | PIMListViewItem::~PIMListViewItem() { |
364 | /* we've the onwership so we need to delete it */ | 365 | /* we've the onwership so we need to delete it */ |
365 | delete m_record; | 366 | delete m_record; |
366 | } | 367 | } |
367 | 368 | ||
368 | OPimRecord* PIMListViewItem::record()const { | 369 | Opie::OPimRecord* PIMListViewItem::record()const { |
369 | return m_record; | 370 | return m_record; |
370 | } | 371 | } |
371 | 372 | ||
372 | } | 373 | } |
373 | 374 | ||
374 | 375 | ||
375 | PIMListView::PIMListView( QWidget* widget, const char* name, WFlags fl ) | 376 | PIMListView::PIMListView( QWidget* widget, const char* name, WFlags fl ) |
376 | : QListView(widget, name, fl ) | 377 | : QListView(widget, name, fl ) |
377 | { | 378 | { |
378 | addColumn("Summary"); | 379 | addColumn("Summary"); |
379 | } | 380 | } |
380 | 381 | ||
381 | PIMListView::~PIMListView() { | 382 | PIMListView::~PIMListView() { |
382 | 383 | ||
383 | } | 384 | } |
384 | 385 | ||
385 | void PIMListView::set( OTodoAccess::List list ) { | 386 | void PIMListView::set( Opie::OPimTodoAccess::List list ) { |
386 | /* clear first and then add new items */ | 387 | /* clear first and then add new items */ |
387 | clear(); | 388 | clear(); |
388 | 389 | ||
389 | OTodoAccess::List::Iterator it; | 390 | Opie::OPimTodoAccess::List::Iterator it; |
390 | for (it = list.begin(); it != list.end(); ++it ) { | 391 | for (it = list.begin(); it != list.end(); ++it ) { |
391 | /* | 392 | /* |
392 | * make a new item which automatically gets added to the listview | 393 | * make a new item which automatically gets added to the listview |
393 | * and call the copy c'tor to create a new OTodo | 394 | * and call the copy c'tor to create a new OPimTodo |
394 | */ | 395 | */ |
395 | PIMListViewItem *i = new PIMListViewItem(this, new OTodo( *it ) ); | 396 | PIMListViewItem *i = new PIMListViewItem(this, new Opie::OPimTodo( *it ) ); |
396 | i->setText(0, (*it).summary() ); | 397 | i->setText(0, (*it).summary() ); |
397 | } | 398 | } |
398 | } | 399 | } |
399 | 400 | ||
400 | void PIMListView::set( const OEffectiveEvent::ValueList& lst ) { | 401 | void PIMListView::set( const Opie::OEffectiveEvent::ValueList& lst ) { |
401 | /* clear first and then add items */ | 402 | /* clear first and then add items */ |
402 | clear(); | 403 | clear(); |
403 | 404 | ||
404 | OEffectiveEvent::ValueList::ConstIterator it; | 405 | Opie::OEffectiveEvent::ValueList::ConstIterator it; |
405 | for ( it = lst.begin(); it != lst.end(); ++it ) { | 406 | for ( it = lst.begin(); it != lst.end(); ++it ) { |
406 | PIMListViewItem *i = new PIMListViewItem(this, new OEvent( (*it).event() ) ); | 407 | PIMListViewItem *i = new PIMListViewItem(this, new Opie::OPimEvent( (*it).event() ) ); |
407 | i->setText( 0, PIMListView::makeString( (*it) ) ); | 408 | i->setText( 0, PIMListView::makeString( (*it) ) ); |
408 | } | 409 | } |
409 | 410 | ||
410 | } | 411 | } |
411 | 412 | ||
412 | void PIMListView::showCurrentRecord() { | 413 | void PIMListView::showCurrentRecord() { |
413 | /* it could be possible that their is no currentItem */ | 414 | /* it could be possible that their is no currentItem */ |
414 | if (!currentItem() ) | 415 | if (!currentItem() ) |
415 | return; | 416 | return; |
416 | 417 | ||
417 | /* | 418 | /* |
418 | * we only add PIMListViewItems so it is save | 419 | * we only add PIMListViewItems so it is save |
419 | * to do this case. If this would not be the case | 420 | * to do this case. If this would not be the case |
420 | * use rtti() to check in a switch() case | 421 | * use rtti() to check in a switch() case |
421 | */ | 422 | */ |
422 | PIMListViewItem *item = static_cast<PIMListViewItem*>( currentItem() ); | 423 | PIMListViewItem *item = static_cast<PIMListViewItem*>( currentItem() ); |
423 | 424 | ||
424 | /* finally you see how to emit a signal */ | 425 | /* finally you see how to emit a signal */ |
425 | emit showRecord( (*item->record() ) ); | 426 | emit showRecord( (*item->record() ) ); |
426 | } | 427 | } |
427 | 428 | ||
428 | QString PIMListView::makeString( const OEffectiveEvent& ev ) { | 429 | QString PIMListView::makeString( const Opie::OEffectiveEvent& ev ) { |
429 | QString str; | 430 | QString str; |
430 | str += ev.description(); | 431 | str += ev.description(); |
431 | if ( !ev.event().isAllDay() ) { | 432 | if ( !ev.event().isAllDay() ) { |
432 | if ( ev.startDate() != ev.endDate() ) { | 433 | if ( ev.startDate() != ev.endDate() ) { |
433 | str += tr("Start ") + TimeString::timeString( ev.event().startDateTime().time() ); | 434 | str += tr("Start ") + TimeString::timeString( ev.event().startDateTime().time() ); |
434 | str += " - " + TimeString::longDateString( ev.startDate() ); | 435 | str += " - " + TimeString::longDateString( ev.startDate() ); |
435 | str += tr("End ") + TimeString::timeString( ev.event().endDateTime().time() ); | 436 | str += tr("End ") + TimeString::timeString( ev.event().endDateTime().time() ); |
436 | str += " - " + TimeString::longDateString( ev.endDate() ); | 437 | str += " - " + TimeString::longDateString( ev.endDate() ); |
437 | }else{ | 438 | }else{ |
438 | str += tr("Time ") + TimeString::timeString( ev.startTime() ); | 439 | str += tr("Time ") + TimeString::timeString( ev.startTime() ); |
439 | str += " - " + TimeString::timeString( ev.endTime() ); | 440 | str += " - " + TimeString::timeString( ev.endTime() ); |
440 | } | 441 | } |
441 | }else | 442 | }else |
442 | str += tr(" This is an All-Day Event"); | 443 | str += tr(" This is an All-Day Event"); |
443 | 444 | ||
444 | return str; | 445 | return str; |
445 | } | 446 | } |
diff --git a/examples/simple-pim/simple.h b/examples/simple-pim/simple.h index bf9ede7..2a6e8ce 100644 --- a/examples/simple-pim/simple.h +++ b/examples/simple-pim/simple.h | |||
@@ -1,95 +1,99 @@ | |||
1 | 1 | ||
2 | /* | 2 | /* |
3 | * A Simple widget with a button to quit | 3 | * A Simple widget with a button to quit |
4 | * | 4 | * |
5 | */ | 5 | */ |
6 | 6 | ||
7 | /* | 7 | /* |
8 | * The below sequence is called a guard and guards | 8 | * The below sequence is called a guard and guards |
9 | * against multiple inclusion of header files | 9 | * against multiple inclusion of header files |
10 | * NOTE: you need to use unique names among the header files | 10 | * NOTE: you need to use unique names among the header files |
11 | */ | 11 | */ |
12 | #ifndef QUIET_SIMPLE_DEMO_H | 12 | #ifndef QUIET_SIMPLE_DEMO_H |
13 | #define QUIET_SIMPLE_DEMO_H | 13 | #define QUIET_SIMPLE_DEMO_H |
14 | 14 | ||
15 | 15 | ||
16 | 16 | ||
17 | 17 | ||
18 | #include <qmainwindow.h> // from this class we will inherit | 18 | #include <qmainwindow.h> // from this class we will inherit |
19 | #include <qlistview.h> // A ListView for our PIM records | 19 | #include <qlistview.h> // A ListView for our PIM records |
20 | 20 | ||
21 | #include <opie/otodoaccess.h> | 21 | #include <opie2/otodoaccess.h> |
22 | #include <opie/odatebookaccess.h> | 22 | #include <opie2/odatebookaccess.h> |
23 | 23 | ||
24 | class QPushButton; // forward declaration to not include the header. This can save time when compiling | 24 | class QPushButton; // forward declaration to not include the header. This can save time when compiling |
25 | class QAction; | 25 | class QAction; |
26 | class PIMListView; | 26 | class PIMListView; |
27 | class QDate; | 27 | class QDate; |
28 | class QCopChannel; | 28 | class QCopChannel; |
29 | namespace Opie{ | ||
30 | namespace Ui { | ||
29 | class OWait; | 31 | class OWait; |
30 | class OTabWidget; | 32 | class OTabWidget; |
33 | } | ||
34 | } | ||
31 | 35 | ||
32 | /* | 36 | /* |
33 | * A mainwindow is a special QWidget it helps layouting | 37 | * A mainwindow is a special QWidget it helps layouting |
34 | * toolbar, statusbar, menubar. Got dockable areas | 38 | * toolbar, statusbar, menubar. Got dockable areas |
35 | * So in one sentence it is a MainWindow :) | 39 | * So in one sentence it is a MainWindow :) |
36 | */ | 40 | */ |
37 | class MainWindow : public QMainWindow { | 41 | class MainWindow : public QMainWindow { |
38 | Q_OBJECT | 42 | Q_OBJECT |
39 | public: | 43 | public: |
40 | static QString appName() { return QString::fromLatin1("simple-pim"); } | 44 | static QString appName() { return QString::fromLatin1("simple-pim"); } |
41 | MainWindow( QWidget* parent, const char* name, WFlags fl ); | 45 | MainWindow( QWidget* parent, const char* name, WFlags fl ); |
42 | ~MainWindow(); | 46 | ~MainWindow(); |
43 | 47 | ||
44 | public slots: | 48 | public slots: |
45 | void setDocument( const QString& ); | 49 | void setDocument( const QString& ); |
46 | private slots: | 50 | private slots: |
47 | void slotDesktopReceive( const QCString&, const QByteArray& ); | 51 | void slotDesktopReceive( const QCString&, const QByteArray& ); |
48 | void slotLoad(); | 52 | void slotLoad(); |
49 | void slotLoadForDay(int, int, int ); | 53 | void slotLoadForDay(int, int, int ); |
50 | void slotLoadForDay(const QDate&); | 54 | void slotLoadForDay(const QDate&); |
51 | void slotShow(); | 55 | void slotShow(); |
52 | void slotDate(); | 56 | void slotDate(); |
53 | void slotShowRecord( const OPimRecord& ); | 57 | void slotShowRecord( const Opie::OPimRecord& ); |
54 | 58 | ||
55 | private: | 59 | private: |
56 | void initUI(); | 60 | void initUI(); |
57 | QAction *m_fire; | 61 | QAction *m_fire; |
58 | QAction *m_dateAction; | 62 | QAction *m_dateAction; |
59 | OTabWidget* m_tab; | 63 | Opie::Ui::OTabWidget* m_tab; |
60 | 64 | ||
61 | OTodoAccess m_tb; | 65 | Opie::OPimTodoAccess m_tb; |
62 | ODateBookAccess m_db; | 66 | Opie::ODateBookAccess m_db; |
63 | PIMListView *m_todoView; | 67 | PIMListView *m_todoView; |
64 | PIMListView *m_dateView; | 68 | PIMListView *m_dateView; |
65 | 69 | ||
66 | int m_synced; // a counter for synced objects.. | 70 | int m_synced; // a counter for synced objects.. |
67 | QCopChannel *m_desktopChannel; | 71 | QCopChannel *m_desktopChannel; |
68 | OWait *m_loading; | 72 | Opie::Ui::OWait *m_loading; |
69 | }; | 73 | }; |
70 | 74 | ||
71 | /* | 75 | /* |
72 | * Instead of the simple QWidgets we will design | 76 | * Instead of the simple QWidgets we will design |
73 | * a new widget based on a QListView | 77 | * a new widget based on a QListView |
74 | * it should show either Todos or EffectiveEvents | 78 | * it should show either Todos or EffectiveEvents |
75 | */ | 79 | */ |
76 | class PIMListView : public QListView { | 80 | class PIMListView : public QListView { |
77 | Q_OBJECT | 81 | Q_OBJECT |
78 | public: | 82 | public: |
79 | PIMListView( QWidget* parent, const char* name, WFlags fl= 0 ); | 83 | PIMListView( QWidget* parent, const char* name, WFlags fl= 0 ); |
80 | ~PIMListView(); | 84 | ~PIMListView(); |
81 | 85 | ||
82 | 86 | ||
83 | void set( OTodoAccess::List ); | 87 | void set( Opie::OPimTodoAccess::List ); |
84 | void set( const OEffectiveEvent::ValueList& ); | 88 | void set( const Opie::OEffectiveEvent::ValueList& ); |
85 | void showCurrentRecord(); | 89 | void showCurrentRecord(); |
86 | 90 | ||
87 | signals: | 91 | signals: |
88 | void showRecord( const OPimRecord& ); | 92 | void showRecord( const Opie::OPimRecord& ); |
89 | 93 | ||
90 | private: | 94 | private: |
91 | static QString makeString( const OEffectiveEvent& ev ); | 95 | static QString makeString( const Opie::OEffectiveEvent& ev ); |
92 | 96 | ||
93 | }; | 97 | }; |
94 | 98 | ||
95 | #endif | 99 | #endif |