summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/ui/opimmainwindow.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/ui/opimmainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.cpp251
1 files changed, 244 insertions, 7 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
@@ -33,21 +33,31 @@
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
@@ -64,16 +74,24 @@ OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent,
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 /*
@@ -133,10 +151,12 @@ void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array )
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
@@ -154,6 +174,7 @@ OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) {
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 */
@@ -163,18 +184,22 @@ int OPimMainWindow::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++;
@@ -184,4 +209,216 @@ void OPimMainWindow::timerEvent( QTimerEvent* e) {
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 }
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 }
187} 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