-rw-r--r-- | libopie2/opiepim/ui/opimmainwindow.cpp | 259 | ||||
-rw-r--r-- | libopie2/opiepim/ui/opimmainwindow.h | 65 |
2 files changed, 308 insertions, 16 deletions
diff --git a/libopie2/opiepim/ui/opimmainwindow.cpp b/libopie2/opiepim/ui/opimmainwindow.cpp index 058a428..40bbb7b 100644 --- a/libopie2/opiepim/ui/opimmainwindow.cpp +++ b/libopie2/opiepim/ui/opimmainwindow.cpp | |||
@@ -35,17 +35,27 @@ | |||
35 | 35 | ||
36 | #include <qpe/sound.h> | 36 | #include <qpe/categoryselect.h> |
37 | #include <qpe/ir.h> | ||
37 | #include <qpe/qcopenvelope_qws.h> | 38 | #include <qpe/qcopenvelope_qws.h> |
38 | #include <qpe/qpeapplication.h> | 39 | #include <qpe/qpeapplication.h> |
40 | #include <qpe/resource.h> | ||
41 | #include <qpe/sound.h> | ||
39 | 42 | ||
40 | /* QT */ | 43 | /* QT */ |
44 | #include <qaction.h> | ||
41 | #include <qapplication.h> | 45 | #include <qapplication.h> |
42 | #include <qdatetime.h> | ||
43 | #include <qcopchannel_qws.h> | 46 | #include <qcopchannel_qws.h> |
44 | 47 | #include <qdatetime.h> | |
45 | 48 | #include <qmenubar.h> | |
49 | #include <qobjectlist.h> | ||
50 | #include <qpopupmenu.h> | ||
51 | #include <qtoolbar.h> | ||
46 | 52 | ||
47 | namespace Opie { | 53 | namespace Opie { |
48 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | 54 | OPimMainWindow::OPimMainWindow( const QString &serviceName, |
49 | const char* name, WFlags flag ) | 55 | const QString &appName, const QString &catName, |
50 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { | 56 | const QString &itemName, const QString &configName, |
57 | QWidget *parent, const char* name, WFlags f ) | ||
58 | : QMainWindow( parent, name, f ), m_rtti(-1), m_service( serviceName ), m_fallBack( 0l ), | ||
59 | m_appName( appName ), m_catGroupName( catName ), m_config( configName ), m_itemContextMenu( 0l ) | ||
60 | { | ||
51 | 61 | ||
@@ -56,6 +66,6 @@ OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | |||
56 | m_channel= new QCopChannel(m_str, this ); | 66 | m_channel= new QCopChannel(m_str, this ); |
57 | connect(m_channel, SIGNAL(received(const QCString&,const QByteArray&) ), | 67 | connect(m_channel, SIGNAL(received(const QCString&,const QByteArray&)), |
58 | this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); | 68 | this, SLOT(appMessage(const QCString&,const QByteArray&)) ); |
59 | connect(qApp, SIGNAL(appMessage(const QCString&,const QByteArray&) ), | 69 | connect(qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
60 | this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); | 70 | this, SLOT(appMessage(const QCString&,const QByteArray&)) ); |
61 | 71 | ||
@@ -66,3 +76,8 @@ OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | |||
66 | this, SLOT(reload() ) ); | 76 | this, SLOT(reload() ) ); |
77 | |||
78 | // Initialize user interface items | ||
79 | setCaption( m_appName ); | ||
80 | initBars( itemName ); | ||
67 | } | 81 | } |
82 | |||
68 | OPimMainWindow::~OPimMainWindow() { | 83 | OPimMainWindow::~OPimMainWindow() { |
@@ -70,2 +85,3 @@ OPimMainWindow::~OPimMainWindow() { | |||
70 | } | 85 | } |
86 | |||
71 | QCopChannel* OPimMainWindow::channel() { | 87 | QCopChannel* OPimMainWindow::channel() { |
@@ -73,2 +89,3 @@ QCopChannel* OPimMainWindow::channel() { | |||
73 | } | 89 | } |
90 | |||
74 | void OPimMainWindow::doSetDocument( const QString& ) { | 91 | void OPimMainWindow::doSetDocument( const QString& ) { |
@@ -76,2 +93,3 @@ void OPimMainWindow::doSetDocument( const QString& ) { | |||
76 | } | 93 | } |
94 | |||
77 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { | 95 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { |
@@ -135,2 +153,3 @@ void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) | |||
135 | } | 153 | } |
154 | |||
136 | /* implement the url scripting here */ | 155 | /* implement the url scripting here */ |
@@ -139,2 +158,3 @@ void OPimMainWindow::setDocument( const QString& str) { | |||
139 | } | 158 | } |
159 | |||
140 | /* | 160 | /* |
@@ -156,2 +176,3 @@ OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { | |||
156 | } | 176 | } |
177 | |||
157 | /* | 178 | /* |
@@ -165,2 +186,3 @@ int OPimMainWindow::service() { | |||
165 | } | 186 | } |
187 | |||
166 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { | 188 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { |
@@ -168,2 +190,3 @@ void OPimMainWindow::doAlarm( const QDateTime&, int ) { | |||
168 | } | 190 | } |
191 | |||
169 | void OPimMainWindow::startAlarm(int count ) { | 192 | void OPimMainWindow::startAlarm(int count ) { |
@@ -174,2 +197,3 @@ void OPimMainWindow::startAlarm(int count ) { | |||
174 | } | 197 | } |
198 | |||
175 | void OPimMainWindow::killAlarm() { | 199 | void OPimMainWindow::killAlarm() { |
@@ -177,2 +201,3 @@ void OPimMainWindow::killAlarm() { | |||
177 | } | 201 | } |
202 | |||
178 | void OPimMainWindow::timerEvent( QTimerEvent* e) { | 203 | void OPimMainWindow::timerEvent( QTimerEvent* e) { |
@@ -186,2 +211,214 @@ void OPimMainWindow::timerEvent( QTimerEvent* e) { | |||
186 | 211 | ||
212 | QPopupMenu *OPimMainWindow::itemContextMenu() { | ||
213 | if ( !m_itemContextMenu ) { | ||
214 | // Create context menu if hasn't been done before | ||
215 | m_itemContextMenu = new QPopupMenu( this ); | ||
216 | m_itemEditAction->addTo( m_itemContextMenu ); | ||
217 | m_itemDuplicateAction->addTo( m_itemContextMenu ); | ||
218 | m_itemDeleteAction->addTo( m_itemContextMenu ); | ||
219 | } | ||
220 | |||
221 | return m_itemContextMenu; | ||
222 | } | ||
223 | |||
224 | void OPimMainWindow::insertItemMenuItems( QActionGroup *items ) { | ||
225 | // Insert menu items into Item menu | ||
226 | if ( items ) { | ||
227 | // Rebuild Item menu | ||
228 | m_itemMenu->clear(); | ||
229 | m_itemMenuGroup1->addTo( m_itemMenu ); | ||
230 | m_itemMenu->insertSeparator(); | ||
231 | items->addTo( m_itemMenu ); | ||
232 | m_itemMenu->insertSeparator(); | ||
233 | m_itemMenuGroup2->addTo( m_itemMenu ); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | void OPimMainWindow::insertViewMenuItems( QActionGroup *items ) { | ||
238 | // Insert menu items into View menu | ||
239 | if ( items ) { | ||
240 | // Rebuild Item menu | ||
241 | m_viewMenu->clear(); | ||
242 | m_viewMenuCategories->addTo( m_viewMenu ); | ||
243 | m_viewMenu->insertSeparator(); | ||
244 | m_viewMenuGroup->addTo( m_viewMenu ); | ||
245 | m_viewMenu->insertSeparator(); | ||
246 | m_viewMenuAppGroup = items; | ||
247 | m_viewMenuAppGroup->addTo( m_viewMenu ); | ||
248 | } | ||
249 | } | ||
250 | |||
251 | void OPimMainWindow::slotViewCategory( QAction *category ) { | ||
252 | // Set application caption | ||
253 | QString caption = m_appName; | ||
254 | if ( category->text() != tr( "All" ) ) | ||
255 | caption.append( QString( " - %1" ).arg( category->text() ) ); | ||
256 | setCaption( caption ); | ||
257 | |||
258 | // Notify application | ||
259 | emit categorySelected( category->text() ); | ||
260 | } | ||
261 | |||
262 | void OPimMainWindow::setViewCategory( const QString &category ) { | ||
263 | // Find category in menu | ||
264 | QObjectListIt kidIt( *(m_viewMenuCategories->children()) ); | ||
265 | QObject *obj; | ||
266 | while ( (obj=kidIt.current()) != 0 ) { | ||
267 | QAction *currAction = reinterpret_cast<QAction*>(obj); | ||
268 | if ( currAction->text() == category ) { | ||
269 | // Category was found, enable it | ||
270 | currAction->setOn( true ); | ||
271 | return; | ||
272 | } | ||
273 | ++kidIt; | ||
274 | } | ||
187 | } | 275 | } |
276 | |||
277 | void OPimMainWindow::reloadCategories() { | ||
278 | QString selected; | ||
279 | |||
280 | // Remove old categories from View menu | ||
281 | if ( m_viewMenuCategories ) { | ||
282 | QObjectListIt kidIt( *(m_viewMenuCategories->children()) ); | ||
283 | QObject *obj; | ||
284 | while ( (obj=kidIt.current()) != 0 ) { | ||
285 | QAction *currAction = reinterpret_cast<QAction*>(obj); | ||
286 | if ( currAction->isOn() ) | ||
287 | selected = currAction->text(); | ||
288 | ++kidIt; | ||
289 | delete currAction; | ||
290 | } | ||
291 | } | ||
292 | else { | ||
293 | m_viewMenuCategories = new QActionGroup( this ); | ||
294 | connect( m_viewMenuCategories, SIGNAL(selected(QAction*)), this, SLOT(slotViewCategory(QAction*)) ); | ||
295 | |||
296 | selected = tr( "All" ); | ||
297 | } | ||
298 | |||
299 | m_viewMenu->clear(); | ||
300 | |||
301 | // Add categories to View menu | ||
302 | QAction *a = new QAction( tr( "All" ), QString::null, 0, m_viewMenuCategories, QString::null, true ); | ||
303 | a->setWhatsThis( tr( "Click here to view all items." ) ); | ||
304 | a->setOn( selected == tr( "All" ) ); | ||
305 | |||
306 | Categories cats; | ||
307 | cats.load( categoryFileName() ); | ||
308 | QStringList catList = cats.labels( m_catGroupName ); | ||
309 | for ( QStringList::Iterator it = catList.begin(); it != catList.end(); ++it ) { | ||
310 | a = new QAction( tr( (*it) ), QString::null, 0, m_viewMenuCategories, QString::null, true ); | ||
311 | a->setWhatsThis( tr( "Click here to view items belonging to %1." ).arg( (*it) ) ); | ||
312 | a->setOn( selected == (*it) ); | ||
313 | } | ||
314 | |||
315 | a = new QAction( tr( "Unfiled" ), QString::null, 0, m_viewMenuCategories, QString::null, true ); | ||
316 | a->setWhatsThis( tr( "Click here to view all unfiled items." ) ); | ||
317 | a->setOn( selected == tr( "Unfiled" ) ); | ||
318 | |||
319 | m_viewMenuCategories->addTo( m_viewMenu ); | ||
320 | |||
321 | // Add default items to View menu | ||
322 | m_viewMenu->insertSeparator(); | ||
323 | m_viewMenuGroup->addTo( m_viewMenu ); | ||
324 | |||
325 | // Insert application-specific items (if any) | ||
326 | if ( m_viewMenuAppGroup ) { | ||
327 | m_viewMenu->insertSeparator(); | ||
328 | m_viewMenuAppGroup->addTo( m_viewMenu ); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | void OPimMainWindow::initBars( const QString &itemName ) { | ||
333 | QString itemStr = itemName.lower(); | ||
334 | |||
335 | setToolBarsMovable( false ); | ||
336 | |||
337 | // Create application menu bar | ||
338 | QToolBar *mbHold = new QToolBar( this ); | ||
339 | mbHold->setHorizontalStretchable( true ); | ||
340 | QMenuBar *menubar = new QMenuBar( mbHold ); | ||
341 | menubar->setMargin( 0 ); | ||
342 | |||
343 | // Create application menu bar | ||
344 | QToolBar *toolbar = new QToolBar( this ); | ||
345 | |||
346 | // Create sub-menus | ||
347 | m_itemMenu = new QPopupMenu( this ); | ||
348 | m_itemMenu->setCheckable( true ); | ||
349 | menubar->insertItem( itemName, m_itemMenu ); | ||
350 | m_viewMenu = new QPopupMenu( this ); | ||
351 | m_viewMenu->setCheckable( true ); | ||
352 | menubar->insertItem( tr( "View" ), m_viewMenu ); | ||
353 | |||
354 | m_viewMenuCategories = 0l; | ||
355 | m_viewMenuAppGroup = 0l; | ||
356 | |||
357 | // Item menu | ||
358 | m_itemMenuGroup1 = new QActionGroup( this, QString::null, false ); | ||
359 | |||
360 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | ||
361 | QString::null, 0, m_itemMenuGroup1, 0 ); | ||
362 | connect( a, SIGNAL(activated()), this, SLOT(slotItemNew()) ); | ||
363 | a->setWhatsThis( tr( "Click here to create a new item." ) ); | ||
364 | a->addTo( toolbar ); | ||
365 | |||
366 | m_itemEditAction = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), | ||
367 | QString::null, 0, m_itemMenuGroup1, 0 ); | ||
368 | connect( m_itemEditAction, SIGNAL(activated()), this, SLOT(slotItemEdit()) ); | ||
369 | m_itemEditAction->setWhatsThis( tr( "Click here to edit the selected item." ) ); | ||
370 | m_itemEditAction->addTo( toolbar ); | ||
371 | |||
372 | m_itemDuplicateAction = new QAction( tr( "Duplicate" ), QString::null, 0, m_itemMenuGroup1, 0 ); | ||
373 | connect( m_itemDuplicateAction, SIGNAL(activated()), this, SLOT(slotItemDuplicate()) ); | ||
374 | m_itemDuplicateAction->setWhatsThis( tr( "Click here to duplicate the selected item." ) ); | ||
375 | |||
376 | m_itemDeleteAction = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), | ||
377 | QString::null, 0, m_itemMenuGroup1, 0 ); | ||
378 | connect( m_itemDeleteAction, SIGNAL(activated()), this, SLOT(slotItemDelete()) ); | ||
379 | m_itemDeleteAction->setWhatsThis( tr( "Click here to delete the selected item." ) ); | ||
380 | m_itemDeleteAction->addTo( toolbar ); | ||
381 | |||
382 | if ( Ir::supported() ) { | ||
383 | a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), | ||
384 | QString::null, 0, m_itemMenuGroup1, 0 ); | ||
385 | connect( a, SIGNAL(activated()), this, SLOT(slotItemBeam()) ); | ||
386 | a->setWhatsThis( tr( "Click here to transmit the selected item." ) ); | ||
387 | //a->addTo( m_itemMenu ); | ||
388 | a->addTo( toolbar ); | ||
389 | } | ||
390 | |||
391 | m_itemMenuGroup1->addTo( m_itemMenu ); | ||
392 | |||
393 | m_itemMenu->insertSeparator(); | ||
394 | |||
395 | m_itemMenuGroup2 = new QActionGroup( this, QString::null, false ); | ||
396 | |||
397 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), | ||
398 | QString::null, 0, m_itemMenuGroup2, 0 ); | ||
399 | connect( a, SIGNAL(activated()), this, SLOT(slotItemFind()) ); | ||
400 | a->setWhatsThis( tr( "Click here to search for an item." ) ); | ||
401 | a->addTo( toolbar ); | ||
402 | |||
403 | a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), | ||
404 | QString::null, 0, m_itemMenuGroup2, 0 ); | ||
405 | connect( a, SIGNAL(activated()), this, SLOT(slotConfigure()) ); | ||
406 | a->setWhatsThis( tr( "Click here to set your preferences for this application." ) ); | ||
407 | |||
408 | m_itemMenuGroup2->addTo( m_itemMenu ); | ||
409 | |||
410 | // View menu | ||
411 | m_viewMenuGroup = new QActionGroup( this, QString::null, false ); | ||
412 | |||
413 | a = new QAction( tr( "Filter" ), QString::null, 0, m_viewMenuGroup, 0 ); | ||
414 | connect( a, SIGNAL(activated()), this, SLOT(slotViewFilter()) ); | ||
415 | a->setWhatsThis( tr( "Click here to filter the items displayed." ) ); | ||
416 | |||
417 | a = new QAction( tr( "Filter Settings" ), QString::null, 0, m_viewMenuGroup, 0 ); | ||
418 | connect( a, SIGNAL(activated()), this, SLOT(slotViewFilterSettings()) ); | ||
419 | a->setWhatsThis( tr( "Click here to modify the current filter settings." ) ); | ||
420 | |||
421 | reloadCategories(); | ||
422 | } | ||
423 | |||
424 | } // namespace Opie | ||
diff --git a/libopie2/opiepim/ui/opimmainwindow.h b/libopie2/opiepim/ui/opimmainwindow.h index abad630..4aed8b8 100644 --- a/libopie2/opiepim/ui/opimmainwindow.h +++ b/libopie2/opiepim/ui/opimmainwindow.h | |||
@@ -31,7 +31,14 @@ | |||
31 | 31 | ||
32 | #include <opie2/opimrecord.h> | ||
33 | |||
34 | #include <qpe/categories.h> | ||
35 | #include <qpe/config.h> | ||
36 | |||
32 | #include <qmainwindow.h> | 37 | #include <qmainwindow.h> |
33 | 38 | ||
34 | #include <opie2/opimrecord.h> | 39 | class QAction; |
40 | class QActionGroup; | ||
35 | class QCopChannel; | 41 | class QCopChannel; |
36 | class QDateTime; | 42 | class QDateTime; |
43 | class QPopupMenu; | ||
37 | 44 | ||
@@ -58,4 +65,8 @@ public: | |||
58 | 65 | ||
59 | OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0, | 66 | OPimMainWindow( const QString &serviceName, |
60 | WFlags f = WType_TopLevel); | 67 | const QString &appName = QString::null, |
68 | const QString &catName = QString::null, | ||
69 | const QString &itemName = QString::null, | ||
70 | const QString &configName = QString::null, | ||
71 | QWidget *parent = 0l, const char* name = 0l, WFlags f = WType_TopLevel ); | ||
61 | virtual ~OPimMainWindow(); | 72 | virtual ~OPimMainWindow(); |
@@ -92,2 +103,11 @@ protected slots: | |||
92 | 103 | ||
104 | /** UI-related slots */ | ||
105 | virtual void slotItemNew() = 0; | ||
106 | virtual void slotItemEdit() = 0; | ||
107 | virtual void slotItemDuplicate() = 0; | ||
108 | virtual void slotItemDelete() = 0; | ||
109 | virtual void slotItemBeam() = 0; | ||
110 | virtual void slotItemFind() = 0; | ||
111 | virtual void slotConfigure() = 0; | ||
112 | |||
93 | protected: | 113 | protected: |
@@ -97,3 +117,3 @@ protected: | |||
97 | */ | 117 | */ |
98 | void startAlarm(int count = 10); | 118 | void startAlarm( int count = 10 ); |
99 | void killAlarm(); | 119 | void killAlarm(); |
@@ -101,2 +121,11 @@ protected: | |||
101 | 121 | ||
122 | /** UI-related functions */ | ||
123 | QPopupMenu *itemContextMenu(); | ||
124 | |||
125 | void insertItemMenuItems( QActionGroup *items ); | ||
126 | void insertViewMenuItems( QActionGroup *items ); | ||
127 | |||
128 | void setViewCategory( const QString &category ); | ||
129 | void reloadCategories(); | ||
130 | |||
102 | private slots: | 131 | private slots: |
@@ -105,3 +134,5 @@ private slots: | |||
105 | 134 | ||
106 | 135 | /** UI-related slots */ | |
136 | void slotViewCategory( QAction *category ); | ||
137 | |||
107 | private: | 138 | private: |
@@ -118,2 +149,20 @@ private: | |||
118 | int m_timerId; | 149 | int m_timerId; |
150 | |||
151 | QString m_appName; // Name of application for title bar | ||
152 | QString m_catGroupName; // Name of category group | ||
153 | Config m_config; // Configuration settings file | ||
154 | |||
155 | // Menu bar data | ||
156 | QPopupMenu *m_itemContextMenu; // Pointer to context-sensitive menu | ||
157 | QPopupMenu *m_itemMenu; // Pointer to item menu | ||
158 | QPopupMenu *m_viewMenu; // Pointer to view menu | ||
159 | QActionGroup *m_itemMenuGroup1; // Action group containing default items in Item menu | ||
160 | QActionGroup *m_itemMenuGroup2; // Action group containing default items in Item menu | ||
161 | QActionGroup *m_viewMenuAppGroup; // Action group containing application items in View menu | ||
162 | QActionGroup *m_viewMenuGroup; // Action group containing default items in View menu | ||
163 | QActionGroup *m_viewMenuCategories; // Pointer to action group containing categories in View menu | ||
164 | QAction *m_itemEditAction; // Edit current item action | ||
165 | QAction *m_itemDuplicateAction; // Duplicate current item action | ||
166 | QAction *m_itemDeleteAction; // Delete current item action | ||
167 | |||
119 | /* I would love to do this as a template | 168 | /* I would love to do this as a template |
@@ -124,2 +173,8 @@ private: | |||
124 | int service(); | 173 | int service(); |
174 | |||
175 | /** UI-related functions */ | ||
176 | void initBars( const QString &itemName = tr( "Item" ) ); | ||
177 | |||
178 | signals: | ||
179 | void categorySelected( const QString &cat ); | ||
125 | }; | 180 | }; |