summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebook.cpp
Unidiff
Diffstat (limited to 'core/pim/datebook/datebook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp120
1 files changed, 39 insertions, 81 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 829f8f8..4fbcb10 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -67,18 +67,12 @@
67#include <sys/types.h> 67#include <sys/types.h>
68#include <fcntl.h> 68#include <fcntl.h>
69#include <unistd.h> 69#include <unistd.h>
70 70
71#include <stdlib.h> 71#include <stdlib.h>
72 72
73#define DAY 1
74#define WEEK 2
75#define WEEKLST 4
76#define MONTH 3
77
78
79DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 73DateBook::DateBook( QWidget *parent, const char *, WFlags f )
80 : QMainWindow( parent, "datebook", f ), 74 : QMainWindow( parent, "datebook", f ),
81 aPreset( FALSE ), 75 aPreset( FALSE ),
82 presetTime( -1 ), 76 presetTime( -1 ),
83 startTime( 8 ), // an acceptable default 77 startTime( 8 ), // an acceptable default
84 rowStyle( 0 ), 78 rowStyle( 0 ),
@@ -163,62 +157,35 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
163 monthAction = a; 157 monthAction = a;
164 158
165 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); 159 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 );
166 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 160 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
167 a->addTo( sub_bar ); 161 a->addTo( sub_bar );
168 162
169 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); 163 a = new QAction( tr( "Edit..." ), QString::null, 0, 0 );
170 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 164 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
171 a->addTo( settings ); 165 a->addTo( settings );
172 166
173 QPopupMenu *default_view = new QPopupMenu(this); 167 if(defaultView==DAY) viewDay();
174 settings->insertItem( tr( "Default View" ),default_view ); 168 if(defaultView==WEEK) needEvilHack=true;// viewWeek();
175 default_view->setCheckable(TRUE); 169 if(defaultView==WEEKLST) viewWeekLst();
170 if(defaultView==MONTH) viewMonth();
176 171
177 Config config("DateBook"); 172 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
178 config.setGroup("Main"); 173 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) );
179 int current=config.readNumEntry("defaultview", DAY);
180
181 QActionGroup *ag = new QActionGroup(this);
182 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true );
183 if (current==DAY) a->setOn(true), viewDay();
184 ag->insert(a);
185 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true );
186 if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true;
187 ag->insert(a);
188 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true );
189 if (current==WEEKLST) a->setOn(true), viewWeekLst();
190 ag->insert(a);
191 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true );
192 if (current==MONTH) a->setOn(true), viewMonth();
193 ag->insert(a);
194
195 ag->addTo(default_view);
196 connect(ag, SIGNAL( selected ( QAction * ) ),
197 this, SLOT( newDefaultView(QAction *) )
198 );
199
200 connect( qApp, SIGNAL(clockChanged(bool)),
201 this, SLOT(changeClock(bool)) );
202 connect( qApp, SIGNAL(weekChanged(bool)),
203 this, SLOT(changeWeek(bool)) );
204 174
205#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 175#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
206 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 176 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) );
207 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
208#endif 177#endif
209 178
210 // listen on QPE/System 179 // listen on QPE/System
211#if defined(Q_WS_QWS) 180#if defined(Q_WS_QWS)
212#if !defined(QT_NO_COP) 181#if !defined(QT_NO_COP)
213 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 182 QCopChannel *channel = new QCopChannel( "QPE/System", this );
214 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 183 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) );
215 this, SLOT(receive(const QCString&, const QByteArray&)) );
216 channel = new QCopChannel( "QPE/Datebook", this ); 184 channel = new QCopChannel( "QPE/Datebook", this );
217 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 185 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) );
218 this, SLOT(receive(const QCString&, const QByteArray&)) );
219 qDebug("olle\n"); 186 qDebug("olle\n");
220#endif 187#endif
221#endif 188#endif
222 189
223 qDebug("done t=%d", t.elapsed() ); 190 qDebug("done t=%d", t.elapsed() );
224 191
@@ -269,23 +236,28 @@ void DateBook::slotSettings()
269{ 236{
270 DateBookSettings frmSettings( ampm, this ); 237 DateBookSettings frmSettings( ampm, this );
271 frmSettings.setStartTime( startTime ); 238 frmSettings.setStartTime( startTime );
272 frmSettings.setAlarmPreset( aPreset, presetTime ); 239 frmSettings.setAlarmPreset( aPreset, presetTime );
273 frmSettings.setJumpToCurTime( bJumpToCurTime ); 240 frmSettings.setJumpToCurTime( bJumpToCurTime );
274 frmSettings.setRowStyle( rowStyle ); 241 frmSettings.setRowStyle( rowStyle );
242 frmSettings.comboDefaultView->setCurrentItem(defaultView-1);
243 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig);
244
275#if defined (Q_WS_QWS) || defined(_WS_QWS_) 245#if defined (Q_WS_QWS) || defined(_WS_QWS_)
276 frmSettings.showMaximized(); 246 frmSettings.showMaximized();
277#endif 247#endif
278 248
279 if ( frmSettings.exec() ) { 249 if ( frmSettings.exec() ) {
280 250
281 aPreset = frmSettings.alarmPreset(); 251 aPreset = frmSettings.alarmPreset();
282 presetTime = frmSettings.presetTime(); 252 presetTime = frmSettings.presetTime();
283 startTime = frmSettings.startTime(); 253 startTime = frmSettings.startTime();
284 bJumpToCurTime = frmSettings.jumpToCurTime(); 254 bJumpToCurTime = frmSettings.jumpToCurTime();
285 rowStyle = frmSettings.rowStyle(); 255 rowStyle = frmSettings.rowStyle();
256 defaultView=frmSettings.comboDefaultView->currentItem()+1;
257 weeklistviewconfig=frmSettings.comboWeekListView->currentItem();
286 258
287 if ( dayView ) { 259 if ( dayView ) {
288 dayView->setStartViewTime( startTime ); 260 dayView->setStartViewTime( startTime );
289 dayView->setJumpToCurTime( bJumpToCurTime ); 261 dayView->setJumpToCurTime( bJumpToCurTime );
290 dayView->setRowStyle( rowStyle ); 262 dayView->setRowStyle( rowStyle );
291 } 263 }
@@ -297,12 +269,14 @@ void DateBook::slotSettings()
297 // make the change obvious 269 // make the change obvious
298 if ( views->visibleWidget() ) { 270 if ( views->visibleWidget() ) {
299 if ( views->visibleWidget() == dayView ) 271 if ( views->visibleWidget() == dayView )
300 dayView->redraw(); 272 dayView->redraw();
301 else if ( views->visibleWidget() == weekView ) 273 else if ( views->visibleWidget() == weekView )
302 weekView->redraw(); 274 weekView->redraw();
275 else if ( views->visibleWidget() == weekLstView )
276 weekLstView->redraw();
303 } 277 }
304 } 278 }
305} 279}
306 280
307void DateBook::fileNew() 281void DateBook::fileNew()
308{ 282{
@@ -380,17 +354,20 @@ void DateBook::view(int v, const QDate &d) {
380 views->raiseWidget( monthView ); 354 views->raiseWidget( monthView );
381 monthView->redraw(); 355 monthView->redraw();
382 } 356 }
383} 357}
384 358
385void DateBook::viewDefault(const QDate &d) { 359void DateBook::viewDefault(const QDate &d) {
360/*
386 Config config("DateBook"); 361 Config config("DateBook");
387 config.setGroup("Main"); 362 config.setGroup("Main");
388 int current=config.readNumEntry("defaultview", DAY); 363 int current=config.readNumEntry("defaultview", DAY);
389 364
390 view(current,d); 365 view(current,d);
366*/
367 view(defaultView,d);
391} 368}
392 369
393void DateBook::viewDay() { 370void DateBook::viewDay() {
394 view(DAY,currentDate()); 371 view(DAY,currentDate());
395} 372}
396 373
@@ -605,52 +582,40 @@ void DateBook::initMonth()
605 qApp->processEvents(); 582 qApp->processEvents();
606 } 583 }
607} 584}
608 585
609void DateBook::loadSettings() 586void DateBook::loadSettings()
610{ 587{
611 { 588 Config qpeconfig( "qpe" );
612 Config config( "qpe" ); 589 qpeconfig.setGroup("Time");
613 config.setGroup("Time"); 590 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE );
614 ampm = config.readBoolEntry( "AMPM", TRUE ); 591 onMonday = qpeconfig.readBoolEntry( "MONDAY" );
615 onMonday = config.readBoolEntry( "MONDAY" );
616 }
617 592
618 {
619 Config config("DateBook"); 593 Config config("DateBook");
620 config.setGroup("Main"); 594 config.setGroup("Main");
621 startTime = config.readNumEntry("startviewtime", 8); 595 startTime = config.readNumEntry("startviewtime", 8);
622 aPreset = config.readBoolEntry("alarmpreset"); 596 aPreset = config.readBoolEntry("alarmpreset");
623 presetTime = config.readNumEntry("presettime"); 597 presetTime = config.readNumEntry("presettime");
624 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 598 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
625 rowStyle = config.readNumEntry("rowstyle"); 599 rowStyle = config.readNumEntry("rowstyle");
626 } 600 defaultView = config.readNumEntry("defaultview",DAY);
601 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL);
627} 602}
628 603
629void DateBook::saveSettings() 604void DateBook::saveSettings()
630{ 605{
631 Config config( "qpe" ); 606 Config config( "qpe" );
632 Config configDB( "DateBook" ); 607 Config configDB( "DateBook" );
633 configDB.setGroup( "Main" ); 608 configDB.setGroup( "Main" );
634 configDB.writeEntry("startviewtime",startTime); 609 configDB.writeEntry("startviewtime",startTime);
635 configDB.writeEntry("alarmpreset",aPreset); 610 configDB.writeEntry("alarmpreset",aPreset);
636 configDB.writeEntry("presettime",presetTime); 611 configDB.writeEntry("presettime",presetTime);
637 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 612 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
638 configDB.writeEntry("rowstyle", rowStyle); 613 configDB.writeEntry("rowstyle", rowStyle);
639} 614 configDB.writeEntry("defaultview",defaultView);
640 615 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig);
641void DateBook::newDefaultView(QAction *a) {
642 int val=DAY;
643 if (a->text() == "Day") val=DAY;
644 if (a->text() == "Week") val=WEEK;
645 if (a->text() == "WeekLst") val=WEEKLST;
646 if (a->text() == "Month") val=MONTH;
647
648 Config configDB( "DateBook" );
649 configDB.setGroup( "Main" );
650 configDB.writeEntry("defaultview",val);
651} 616}
652 617
653void DateBook::appMessage(const QCString& msg, const QByteArray& data) 618void DateBook::appMessage(const QCString& msg, const QByteArray& data)
654{ 619{
655 bool needShow = FALSE; 620 bool needShow = FALSE;
656 if ( msg == "alarm(QDateTime,int)" ) { 621 if ( msg == "alarm(QDateTime,int)" ) {
@@ -659,24 +624,22 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data)
659 ds >> when >> warn; 624 ds >> when >> warn;
660 625
661 // check to make it's okay to continue, 626 // check to make it's okay to continue,
662 // this is the case that the time was set ahead, and 627 // this is the case that the time was set ahead, and
663 // we are forced given a stale alarm... 628 // we are forced given a stale alarm...
664 QDateTime current = QDateTime::currentDateTime(); 629 QDateTime current = QDateTime::currentDateTime();
665 if ( current.time().hour() != when.time().hour() 630 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() )
666 && current.time().minute() != when.time().minute() )
667 return; 631 return;
668 632
669 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 633 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
670 if ( list.count() > 0 ) { 634 if ( list.count() > 0 ) {
671 QString msg; 635 QString msg;
672 bool bSound = FALSE; 636 bool bSound = FALSE;
673 int stopTimer = 0; 637 int stopTimer = 0;
674 bool found = FALSE; 638 bool found = FALSE;
675 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); 639 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) {
676 it!=list.end(); ++it ) {
677 if ( (*it).event().hasAlarm() ) { 640 if ( (*it).event().hasAlarm() ) {
678 found = TRUE; 641 found = TRUE;
679 msg += "<CENTER><B>" + (*it).description() + "</B>" 642 msg += "<CENTER><B>" + (*it).description() + "</B>"
680 + "<BR>" + (*it).location() + "<BR>" 643 + "<BR>" + (*it).location() + "<BR>"
681 + TimeString::dateString((*it).event().start(),ampm) 644 + TimeString::dateString((*it).event().start(),ampm)
682 + (warn 645 + (warn
@@ -693,13 +656,12 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data)
693 if ( found ) { 656 if ( found ) {
694 if ( bSound ) { 657 if ( bSound ) {
695 Sound::soundAlarm(); 658 Sound::soundAlarm();
696 alarmCounter = 0; 659 alarmCounter = 0;
697 stopTimer = startTimer( 5000 ); 660 stopTimer = startTimer( 5000 );
698 } 661 }
699
700 QDialog dlg( this, 0, TRUE ); 662 QDialog dlg( this, 0, TRUE );
701 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 663 QVBoxLayout *vb = new QVBoxLayout( &dlg );
702 QScrollView *view = new QScrollView( &dlg, "scrollView"); 664 QScrollView *view = new QScrollView( &dlg, "scrollView");
703 view->setResizePolicy( QScrollView::AutoOneFit ); 665 view->setResizePolicy( QScrollView::AutoOneFit );
704 vb->addWidget( view ); 666 vb->addWidget( view );
705 QLabel *lblMsg = new QLabel( msg, &dlg ); 667 QLabel *lblMsg = new QLabel( msg, &dlg );
@@ -717,14 +679,13 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data)
717 killTimer( stopTimer ); 679 killTimer( stopTimer );
718 } 680 }
719 } 681 }
720 } else if ( msg == "nextView()" ) { 682 } else if ( msg == "nextView()" ) {
721 if ( !qApp-> activeWindow ( )) { 683 if ( !qApp-> activeWindow ( )) {
722 needShow = TRUE; 684 needShow = TRUE;
723 } 685 } else {
724 else {
725 QWidget* cur = views->visibleWidget(); 686 QWidget* cur = views->visibleWidget();
726 if ( cur ) { 687 if ( cur ) {
727 if ( cur == dayView ) 688 if ( cur == dayView )
728 viewWeek(); 689 viewWeek();
729 else if ( cur == weekView ) 690 else if ( cur == weekView )
730 viewWeekLst(); 691 viewWeekLst();
@@ -748,18 +709,15 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data)
748 } 709 }
749} 710}
750 711
751void DateBook::reload() 712void DateBook::reload()
752{ 713{
753 db->reload(); 714 db->reload();
754 if ( dayAction->isOn() ) 715 if ( dayAction->isOn() ) viewDay();
755 viewDay(); 716 else if ( weekAction->isOn() ) viewWeek();
756 else if ( weekAction->isOn() ) 717 else if ( monthAction->isOn() ) viewMonth();
757 viewWeek();
758 else if ( monthAction->isOn() )
759 viewMonth();
760 syncing = FALSE; 718 syncing = FALSE;
761} 719}
762 720
763void DateBook::flush() 721void DateBook::flush()
764{ 722{
765 syncing = TRUE; 723 syncing = TRUE;
@@ -768,16 +726,16 @@ void DateBook::flush()
768 726
769void DateBook::timerEvent( QTimerEvent *e ) 727void DateBook::timerEvent( QTimerEvent *e )
770{ 728{
771 if ( alarmCounter < 10 ) { 729 if ( alarmCounter < 10 ) {
772 alarmCounter++; 730 alarmCounter++;
773 Sound::soundAlarm(); 731 Sound::soundAlarm();
774 } 732 } else {
775 else
776 killTimer( e->timerId() ); 733 killTimer( e->timerId() );
777} 734}
735}
778 736
779void DateBook::changeClock( bool newClock ) 737void DateBook::changeClock( bool newClock )
780{ 738{
781 ampm = newClock; 739 ampm = newClock;
782 // repaint the affected objects... 740 // repaint the affected objects...
783 if (dayView) dayView->redraw(); 741 if (dayView) dayView->redraw();
@@ -792,13 +750,13 @@ void DateBook::changeWeek( bool m )
792 onMonday = m; 750 onMonday = m;
793} 751}
794 752
795void DateBook::slotToday() 753void DateBook::slotToday()
796{ 754{
797 // we need to view today using default view 755 // we need to view today using default view
798 viewDefault(QDate::currentDate()); 756 view(defaultView,QDate::currentDate());
799} 757}
800 758
801void DateBook::closeEvent( QCloseEvent *e ) 759void DateBook::closeEvent( QCloseEvent *e )
802{ 760{
803 if(syncing) { 761 if(syncing) {
804 /* no need to save, did that at flush */ 762 /* no need to save, did that at flush */
@@ -806,15 +764,15 @@ void DateBook::closeEvent( QCloseEvent *e )
806 return; 764 return;
807 } 765 }
808 766
809 // save settings will generate it's own error messages, no 767 // save settings will generate it's own error messages, no
810 // need to do checking ourselves. 768 // need to do checking ourselves.
811 saveSettings(); 769 saveSettings();
812 if ( db->save() ) 770 if ( db->save() ) {
813 e->accept(); 771 e->accept();
814 else { 772 } else {
815 if ( QMessageBox::critical( this, tr( "Out of space" ), 773 if ( QMessageBox::critical( this, tr( "Out of space" ),
816 tr("Calendar was unable to save\n" 774 tr("Calendar was unable to save\n"
817 "your changes.\n" 775 "your changes.\n"
818 "Free up some space and try again.\n" 776 "Free up some space and try again.\n"
819 "\nQuit anyway?"), 777 "\nQuit anyway?"),
820 QMessageBox::Yes|QMessageBox::Escape, 778 QMessageBox::Yes|QMessageBox::Escape,