summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.cpp259
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.h65
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
@@ -30,53 +30,71 @@
30#include "opimmainwindow.h" 30#include "opimmainwindow.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimresolver.h> 33#include <opie2/opimresolver.h>
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
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
47namespace Opie { 53namespace Opie {
48OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, 54OPimMainWindow::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
52 /* 62 /*
53 * let's generate our QCopChannel 63 * let's generate our QCopChannel
54 */ 64 */
55 m_str = QString("QPE/"+m_service).local8Bit(); 65 m_str = QString("QPE/"+m_service).local8Bit();
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
62 /* connect flush and reload */ 72 /* connect flush and reload */
63 connect(qApp, SIGNAL(flush() ), 73 connect(qApp, SIGNAL(flush() ),
64 this, SLOT(flush() ) ); 74 this, SLOT(flush() ) );
65 connect(qApp, SIGNAL(reload() ), 75 connect(qApp, SIGNAL(reload() ),
66 this, SLOT(reload() ) ); 76 this, SLOT(reload() ) );
77
78 // Initialize user interface items
79 setCaption( m_appName );
80 initBars( itemName );
67} 81}
82
68OPimMainWindow::~OPimMainWindow() { 83OPimMainWindow::~OPimMainWindow() {
69 delete m_channel; 84 delete m_channel;
70} 85}
86
71QCopChannel* OPimMainWindow::channel() { 87QCopChannel* OPimMainWindow::channel() {
72 return m_channel; 88 return m_channel;
73} 89}
90
74void OPimMainWindow::doSetDocument( const QString& ) { 91void OPimMainWindow::doSetDocument( const QString& ) {
75 92
76} 93}
94
77void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { 95void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) {
78 bool needShow = false; 96 bool needShow = false;
79 /* 97 /*
80 * create demands to create 98 * create demands to create
81 * a new record... 99 * a new record...
82 */ 100 */
@@ -130,16 +148,18 @@ void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array )
130 needShow = true; 148 needShow = true;
131 } 149 }
132 150
133 if (needShow ) 151 if (needShow )
134 QPEApplication::setKeepRunning(); 152 QPEApplication::setKeepRunning();
135} 153}
154
136/* implement the url scripting here */ 155/* implement the url scripting here */
137void OPimMainWindow::setDocument( const QString& str) { 156void OPimMainWindow::setDocument( const QString& str) {
138 doSetDocument( str ); 157 doSetDocument( str );
139} 158}
159
140/* 160/*
141 * we now try to get the array demarshalled 161 * we now try to get the array demarshalled
142 * check if the rtti matches this one 162 * check if the rtti matches this one
143 */ 163 */
144OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { 164OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) {
145 if ( service() != rtti ) 165 if ( service() != rtti )
@@ -151,37 +171,254 @@ OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) {
151 delete record; 171 delete record;
152 record = 0l; 172 record = 0l;
153 } 173 }
154 174
155 return record; 175 return record;
156} 176}
177
157/* 178/*
158 * get the rtti for the service 179 * get the rtti for the service
159 */ 180 */
160int OPimMainWindow::service() { 181int OPimMainWindow::service() {
161 if ( m_rtti == -1 ) 182 if ( m_rtti == -1 )
162 m_rtti = OPimResolver::self()->serviceId( m_service ); 183 m_rtti = OPimResolver::self()->serviceId( m_service );
163 184
164 return m_rtti; 185 return m_rtti;
165} 186}
187
166void OPimMainWindow::doAlarm( const QDateTime&, int ) { 188void OPimMainWindow::doAlarm( const QDateTime&, int ) {
167 189
168} 190}
191
169void OPimMainWindow::startAlarm(int count ) { 192void OPimMainWindow::startAlarm(int count ) {
170 m_alarmCount = count; 193 m_alarmCount = count;
171 m_playedCount = 0; 194 m_playedCount = 0;
172 Sound::soundAlarm(); 195 Sound::soundAlarm();
173 m_timerId = startTimer( 5000 ); 196 m_timerId = startTimer( 5000 );
174} 197}
198
175void OPimMainWindow::killAlarm() { 199void OPimMainWindow::killAlarm() {
176 killTimer( m_timerId ); 200 killTimer( m_timerId );
177} 201}
202
178void OPimMainWindow::timerEvent( QTimerEvent* e) { 203void OPimMainWindow::timerEvent( QTimerEvent* e) {
179 if ( m_playedCount <m_alarmCount ) { 204 if ( m_playedCount <m_alarmCount ) {
180 m_playedCount++; 205 m_playedCount++;
181 Sound::soundAlarm(); 206 Sound::soundAlarm();
182 }else { 207 }else {
183 killTimer( e->timerId() ); 208 killTimer( e->timerId() );
184 } 209 }
185} 210}
186 211
212QPopupMenu *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
224void 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
237void 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
251void 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
262void 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
277void 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
332void 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
@@ -26,17 +26,24 @@
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_PIM_MAINWINDOW_H 29#ifndef OPIE_PIM_MAINWINDOW_H
30#define OPIE_PIM_MAINWINDOW_H 30#define OPIE_PIM_MAINWINDOW_H
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> 39class QAction;
40class QActionGroup;
35class QCopChannel; 41class QCopChannel;
36class QDateTime; 42class QDateTime;
43class QPopupMenu;
37 44
38namespace Opie { 45namespace Opie {
39/** 46/**
40 * This is a common Opie PIM MainWindow 47 * This is a common Opie PIM MainWindow
41 * it takes care of the QCOP internals 48 * it takes care of the QCOP internals
42 * and implements some functions 49 * and implements some functions
@@ -53,14 +60,18 @@ namespace Opie {
53class OPimMainWindow : public QMainWindow { 60class OPimMainWindow : public QMainWindow {
54 Q_OBJECT 61 Q_OBJECT
55public: 62public:
56 enum TransPort { BlueTooth=0, 63 enum TransPort { BlueTooth=0,
57 IrDa }; 64 IrDa };
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();
62 73
63 74
64protected slots: 75protected slots:
65 /* 76 /*
66 * called when a setDocument 77 * called when a setDocument
@@ -87,43 +98,87 @@ protected slots:
87 virtual void add( const OPimRecord& ) = 0; 98 virtual void add( const OPimRecord& ) = 0;
88 99
89 virtual void doAlarm( const QDateTime&, int uid ); 100 virtual void doAlarm( const QDateTime&, int uid );
90 101
91 QCopChannel* channel(); 102 QCopChannel* channel();
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
93protected: 113protected:
94 /** 114 /**
95 * start to play soundAlarm() 115 * start to play soundAlarm()
96 * @param count How many times the alarm is played 116 * @param count How many times the alarm is played
97 */ 117 */
98 void startAlarm(int count = 10); 118 void startAlarm( int count = 10 );
99 void killAlarm(); 119 void killAlarm();
100 void timerEvent( QTimerEvent* ); 120 void timerEvent( QTimerEvent* );
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
102private slots: 131private slots:
103 void appMessage( const QCString&, const QByteArray& ); 132 void appMessage( const QCString&, const QByteArray& );
104 void setDocument( const QString& ); 133 void setDocument( const QString& );
105 134
106 135 /** UI-related slots */
136 void slotViewCategory( QAction *category );
137
107private: 138private:
108 class Private; 139 class Private;
109 Private* d; 140 Private* d;
110 141
111 int m_rtti; 142 int m_rtti;
112 QCopChannel* m_channel; 143 QCopChannel* m_channel;
113 QString m_service; 144 QString m_service;
114 QCString m_str; 145 QCString m_str;
115 OPimRecord* m_fallBack; 146 OPimRecord* m_fallBack;
116 int m_alarmCount; 147 int m_alarmCount;
117 int m_playedCount; 148 int m_playedCount;
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
120 * but can't think of a right way 169 * but can't think of a right way
121 * because I need signal and slots -zecke 170 * because I need signal and slots -zecke
122 */ 171 */
123 virtual OPimRecord* record( int rtti, const QByteArray& ) ; 172 virtual OPimRecord* record( int rtti, const QByteArray& ) ;
124 int service(); 173 int service();
174
175 /** UI-related functions */
176 void initBars( const QString &itemName = tr( "Item" ) );
177
178signals:
179 void categorySelected( const QString &cat );
125}; 180};
126 181
127} 182}
128 183
129#endif 184#endif