summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebook.cpp
Unidiff
Diffstat (limited to 'core/pim/datebook/datebook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp108
1 files changed, 73 insertions, 35 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 6dd8918..cf1eeca 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -221,61 +221,77 @@ void DateBook::receive( const QCString &msg, const QByteArray &data )
221 viewMonth(); 221 viewMonth();
222 } 222 }
223 else if (msg == "editEvent(int)") { 223 else if (msg == "editEvent(int)") {
224 int uid; 224 int uid;
225 stream >> uid; 225 stream >> uid;
226 Event e=db->eventByUID(uid); 226 Event e=db->eventByUID(uid);
227 editEvent(e); 227 editEvent(e);
228 } 228 }
229} 229}
230 230
231DateBook::~DateBook() 231DateBook::~DateBook()
232{ 232{
233} 233}
234 234
235void DateBook::slotSettings() 235void DateBook::slotSettings()
236{ 236{
237 DateBookSettings frmSettings( ampm, this ); 237 DateBookSettings frmSettings( ampm, this );
238 frmSettings.setStartTime( startTime ); 238 frmSettings.setStartTime( startTime );
239 frmSettings.setAlarmPreset( aPreset, presetTime ); 239 frmSettings.setAlarmPreset( aPreset, presetTime );
240 frmSettings.setJumpToCurTime( bJumpToCurTime ); 240 frmSettings.setJumpToCurTime( bJumpToCurTime );
241 frmSettings.setRowStyle( rowStyle ); 241 frmSettings.setRowStyle( rowStyle );
242 frmSettings.comboDefaultView->setCurrentItem(defaultView-1); 242 frmSettings.comboDefaultView->setCurrentItem(defaultView-1);
243 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); 243 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig);
244 244
245 bool found=false;
246 for (int i=0; i<(frmSettings.comboLocation->count()); i++) {
247 if ( frmSettings.comboLocation->text(i) == defaultLocation ) {
248 frmSettings.comboLocation->setCurrentItem(i);
249 found=true;
250 break;
251 }
252 }
253 if(!found) {
254 frmSettings.comboLocation->insertItem(defaultLocation);
255 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1);
256 }
257 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar"));
258
245#if defined (Q_WS_QWS) || defined(_WS_QWS_) 259#if defined (Q_WS_QWS) || defined(_WS_QWS_)
246 frmSettings.showMaximized(); 260 frmSettings.showMaximized();
247#endif 261#endif
248 262
249 if ( frmSettings.exec() ) { 263 if ( frmSettings.exec() ) {
250 264
251 aPreset = frmSettings.alarmPreset(); 265 aPreset = frmSettings.alarmPreset();
252 presetTime = frmSettings.presetTime(); 266 presetTime = frmSettings.presetTime();
253 startTime = frmSettings.startTime(); 267 startTime = frmSettings.startTime();
254 bJumpToCurTime = frmSettings.jumpToCurTime(); 268 bJumpToCurTime = frmSettings.jumpToCurTime();
255 rowStyle = frmSettings.rowStyle(); 269 rowStyle = frmSettings.rowStyle();
256 defaultView=frmSettings.comboDefaultView->currentItem()+1; 270 defaultView=frmSettings.comboDefaultView->currentItem()+1;
257 weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); 271 weeklistviewconfig=frmSettings.comboWeekListView->currentItem();
272 defaultLocation=frmSettings.comboLocation->currentText();
273 defaultCategories=frmSettings.comboCategory->currentCategories();
258 274
259 if ( dayView ) { 275 if ( dayView ) {
260 dayView->setStartViewTime( startTime ); 276 dayView->setStartViewTime( startTime );
261 dayView->setJumpToCurTime( bJumpToCurTime ); 277 dayView->setJumpToCurTime( bJumpToCurTime );
262 dayView->setRowStyle( rowStyle ); 278 dayView->setRowStyle( rowStyle );
263 } 279 }
264 if ( weekView ) { 280 if ( weekView ) {
265 weekView->setStartViewTime( startTime ); 281 weekView->setStartViewTime( startTime );
266 } 282 }
267 saveSettings(); 283 saveSettings();
268 284
269 // make the change obvious 285 // make the change obvious
270 if ( views->visibleWidget() ) { 286 if ( views->visibleWidget() ) {
271 if ( views->visibleWidget() == dayView ) 287 if ( views->visibleWidget() == dayView )
272 dayView->redraw(); 288 dayView->redraw();
273 else if ( views->visibleWidget() == weekView ) 289 else if ( views->visibleWidget() == weekView )
274 weekView->redraw(); 290 weekView->redraw();
275 else if ( views->visibleWidget() == weekLstView ) 291 else if ( views->visibleWidget() == weekLstView )
276 weekLstView->redraw(); 292 weekLstView->redraw();
277 } 293 }
278 } 294 }
279} 295}
280 296
281void DateBook::fileNew() 297void DateBook::fileNew()
@@ -364,50 +380,52 @@ void DateBook::viewDefault(const QDate &d) {
364 380
365 view(current,d); 381 view(current,d);
366*/ 382*/
367 view(defaultView,d); 383 view(defaultView,d);
368} 384}
369 385
370void DateBook::viewDay() { 386void DateBook::viewDay() {
371 view(DAY,currentDate()); 387 view(DAY,currentDate());
372} 388}
373 389
374void DateBook::viewWeek() { 390void DateBook::viewWeek() {
375 view(WEEK,currentDate()); 391 view(WEEK,currentDate());
376} 392}
377 393
378void DateBook::viewWeekLst() { 394void DateBook::viewWeekLst() {
379 view(WEEKLST,currentDate()); 395 view(WEEKLST,currentDate());
380} 396}
381 397
382void DateBook::viewMonth() { 398void DateBook::viewMonth() {
383 view(MONTH,currentDate()); 399 view(MONTH,currentDate());
384} 400}
385 401
386void DateBook::insertEvent( const Event &e ) 402void DateBook::insertEvent( const Event &e )
387{ 403{
388 qWarning("Adding Event!"); 404 Event dupEvent=e;
389 db->addEvent(e); 405 dupEvent.setLocation(defaultLocation);
406 dupEvent.setCategories(defaultCategories);
407 db->addEvent(dupEvent);
390 emit newEvent(); 408 emit newEvent();
391} 409}
392 410
393void DateBook::duplicateEvent( const Event &e ) 411void DateBook::duplicateEvent( const Event &e )
394{ 412{
395 qWarning("Hmmm..."); 413 qWarning("Hmmm...");
396 // Alot of code duplication, as this is almost like editEvent(); 414 // Alot of code duplication, as this is almost like editEvent();
397 if (syncing) { 415 if (syncing) {
398 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 416 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
399 return; 417 return;
400 } 418 }
401 419
402 Event dupevent(e);// Make a duplicate. 420 Event dupevent(e);// Make a duplicate.
403 421
404 // workaround added for text input. 422 // workaround added for text input.
405 QDialog editDlg( this, 0, TRUE ); 423 QDialog editDlg( this, 0, TRUE );
406 DateEntry *entry; 424 DateEntry *entry;
407 editDlg.setCaption( tr("Duplicate Event") ); 425 editDlg.setCaption( tr("Duplicate Event") );
408 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 426 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
409 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 427 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
410 sv->setResizePolicy( QScrollView::AutoOneFit ); 428 sv->setResizePolicy( QScrollView::AutoOneFit );
411 // KLUDGE!!! 429 // KLUDGE!!!
412 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 430 sv->setHScrollBarMode( QScrollView::AlwaysOff );
413 vb->addWidget( sv ); 431 vb->addWidget( sv );
@@ -585,62 +603,78 @@ void DateBook::initMonth()
585 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), 603 connect( monthView, SIGNAL( dateClicked( int, int, int ) ),
586 this, SLOT( showDay( int, int, int ) ) ); 604 this, SLOT( showDay( int, int, int ) ) );
587 connect( this, SIGNAL( newEvent() ), 605 connect( this, SIGNAL( newEvent() ),
588 monthView, SLOT( redraw() ) ); 606 monthView, SLOT( redraw() ) );
589 qApp->processEvents(); 607 qApp->processEvents();
590 } 608 }
591} 609}
592 610
593void DateBook::loadSettings() 611void DateBook::loadSettings()
594{ 612{
595 Config qpeconfig( "qpe" ); 613 Config qpeconfig( "qpe" );
596 qpeconfig.setGroup("Time"); 614 qpeconfig.setGroup("Time");
597 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); 615 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE );
598 onMonday = qpeconfig.readBoolEntry( "MONDAY" ); 616 onMonday = qpeconfig.readBoolEntry( "MONDAY" );
599 617
600 Config config("DateBook"); 618 Config config("DateBook");
601 config.setGroup("Main"); 619 config.setGroup("Main");
602 startTime = config.readNumEntry("startviewtime", 8); 620 startTime = config.readNumEntry("startviewtime", 8);
603 aPreset = config.readBoolEntry("alarmpreset"); 621 aPreset = config.readBoolEntry("alarmpreset");
604 presetTime = config.readNumEntry("presettime"); 622 presetTime = config.readNumEntry("presettime");
605 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 623 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
606 rowStyle = config.readNumEntry("rowstyle"); 624 rowStyle = config.readNumEntry("rowstyle");
607 defaultView = config.readNumEntry("defaultview",DAY); 625 defaultView = config.readNumEntry("defaultview",DAY);
608 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); 626 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL);
627
628 defaultLocation=config.readEntry("defaultLocation");
629 QString tmpString=config.readEntry("defaultCategories");
630 QStringList tmpStringList=QStringList::split(",",tmpString);
631 defaultCategories.truncate(0);
632 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) {
633 defaultCategories.resize(defaultCategories.count()+1);
634 defaultCategories[defaultCategories.count()-1]=(*i).toInt();
635 }
609} 636}
610 637
611void DateBook::saveSettings() 638void DateBook::saveSettings()
612{ 639{
613 Config config( "qpe" ); 640 Config config( "qpe" );
614 Config configDB( "DateBook" ); 641 Config configDB( "DateBook" );
615 configDB.setGroup( "Main" ); 642 configDB.setGroup( "Main" );
616 configDB.writeEntry("startviewtime",startTime); 643 configDB.writeEntry("startviewtime",startTime);
617 configDB.writeEntry("alarmpreset",aPreset); 644 configDB.writeEntry("alarmpreset",aPreset);
618 configDB.writeEntry("presettime",presetTime); 645 configDB.writeEntry("presettime",presetTime);
619 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 646 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
620 configDB.writeEntry("rowstyle", rowStyle); 647 configDB.writeEntry("rowstyle", rowStyle);
621 configDB.writeEntry("defaultview",defaultView); 648 configDB.writeEntry("defaultview",defaultView);
622 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); 649 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig);
650
651 configDB.writeEntry("defaultLocation",defaultLocation);
652 QStringList tmpStringList;
653 for( uint i=0; i<defaultCategories.count(); i++) {
654 tmpStringList << QString::number(defaultCategories[i]);
655 }
656 configDB.writeEntry("defaultCategories",tmpStringList.join(","));
623} 657}
624 658
625void DateBook::appMessage(const QCString& msg, const QByteArray& data) 659void DateBook::appMessage(const QCString& msg, const QByteArray& data)
626{ 660{
627 bool needShow = FALSE; 661 bool needShow = FALSE;
628 if ( msg == "alarm(QDateTime,int)" ) { 662 if ( msg == "alarm(QDateTime,int)" ) {
629 QDataStream ds(data,IO_ReadOnly); 663 QDataStream ds(data,IO_ReadOnly);
630 QDateTime when; int warn; 664 QDateTime when; int warn;
631 ds >> when >> warn; 665 ds >> when >> warn;
632 666
633 // check to make it's okay to continue, 667 // check to make it's okay to continue,
634 // this is the case that the time was set ahead, and 668 // this is the case that the time was set ahead, and
635 // we are forced given a stale alarm... 669 // we are forced given a stale alarm...
636 QDateTime current = QDateTime::currentDateTime(); 670 QDateTime current = QDateTime::currentDateTime();
637 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) 671 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() )
638 return; 672 return;
639 673
640 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 674 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
641 if ( list.count() > 0 ) { 675 if ( list.count() > 0 ) {
642 QString msg; 676 QString msg;
643 bool bSound = FALSE; 677 bool bSound = FALSE;
644 int stopTimer = 0; 678 int stopTimer = 0;
645 bool found = FALSE; 679 bool found = FALSE;
646 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { 680 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) {
@@ -804,90 +838,94 @@ void DateBook::slotNewEventFromKey( const QString &str )
804 // So we can assume some things. We want the string 838 // So we can assume some things. We want the string
805 // passed in to be part of the description. 839 // passed in to be part of the description.
806 QDateTime start, end; 840 QDateTime start, end;
807 if ( views->visibleWidget() == dayView ) { 841 if ( views->visibleWidget() == dayView ) {
808 dayView->selectedDates( start, end ); 842 dayView->selectedDates( start, end );
809 } else if ( views->visibleWidget() == monthView ) { 843 } else if ( views->visibleWidget() == monthView ) {
810 QDate d = monthView->selectedDate(); 844 QDate d = monthView->selectedDate();
811 start = end = d; 845 start = end = d;
812 start.setTime( QTime( 10, 0 ) ); 846 start.setTime( QTime( 10, 0 ) );
813 end.setTime( QTime( 12, 0 ) ); 847 end.setTime( QTime( 12, 0 ) );
814 } else if ( views->visibleWidget() == weekView ) { 848 } else if ( views->visibleWidget() == weekView ) {
815 QDate d = weekView->date(); 849 QDate d = weekView->date();
816 start = end = d; 850 start = end = d;
817 start.setTime( QTime( 10, 0 ) ); 851 start.setTime( QTime( 10, 0 ) );
818 end.setTime( QTime( 12, 0 ) ); 852 end.setTime( QTime( 12, 0 ) );
819 } else if ( views->visibleWidget() == weekLstView ) { 853 } else if ( views->visibleWidget() == weekLstView ) {
820 QDate d = weekLstView->date(); 854 QDate d = weekLstView->date();
821 start = end = d; 855 start = end = d;
822 start.setTime( QTime( 10, 0 ) ); 856 start.setTime( QTime( 10, 0 ) );
823 end.setTime( QTime( 12, 0 ) ); 857 end.setTime( QTime( 12, 0 ) );
824 } 858 }
825 slotNewEntry(start, end, str); 859 slotNewEntry(start, end, str);
826} 860}
827void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { 861void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) {
828 // argh! This really needs to be encapsulated in a class 862 // argh! This really needs to be encapsulated in a class
829 // or function. 863 // or function.
830 QDialog newDlg( this, 0, TRUE ); 864 QDialog newDlg( this, 0, TRUE );
831 newDlg.setCaption( DateEntryBase::tr("New Event") ); 865 newDlg.setCaption( DateEntryBase::tr("New Event") );
832 DateEntry *e; 866 DateEntry *e;
833 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 867 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
834 QScrollView *sv = new QScrollView( &newDlg ); 868 QScrollView *sv = new QScrollView( &newDlg );
835 sv->setResizePolicy( QScrollView::AutoOneFit ); 869 sv->setResizePolicy( QScrollView::AutoOneFit );
836 sv->setFrameStyle( QFrame::NoFrame ); 870 sv->setFrameStyle( QFrame::NoFrame );
837 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 871 sv->setHScrollBarMode( QScrollView::AlwaysOff );
838 vb->addWidget( sv ); 872 vb->addWidget( sv );
839 873
840 Event ev; 874 Event ev;
841 ev.setDescription( str ); 875 ev.setDescription( str );
842 // When the new gui comes in, change this... 876 // When the new gui comes in, change this...
843 if(location==0) { 877 if(location==0) {
844 ev.setLocation( tr("(Unknown)") ); 878 if(defaultLocation.isEmpty()) {
879 ev.setLocation(tr("(Unknown)"));
880 } else {
881 ev.setLocation( defaultLocation );
882 }
845 } else { 883 } else {
846 ev.setLocation(location); 884 ev.setLocation(location);
847 } 885 }
848 ev.setStart( start ); 886 ev.setCategories(defaultCategories);
849 ev.setEnd( end ); 887 ev.setStart( start );
888 ev.setEnd( end );
850 889
851 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 890 e = new DateEntry( onMonday, ev, ampm, &newDlg );
852 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 891 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
853 sv->addChild( e ); 892 sv->addChild( e );
854#if defined(Q_WS_QWS) || defined(_WS_QWS_) 893#if defined(Q_WS_QWS) || defined(_WS_QWS_)
855 newDlg.showMaximized(); 894 newDlg.showMaximized();
856#endif 895#endif
857 while (newDlg.exec()) { 896 while (newDlg.exec()) {
858 ev = e->event(); 897 ev = e->event();
859 ev.assignUid(); 898 ev.assignUid();
860 QString error = checkEvent( ev ); 899 QString error = checkEvent( ev );
861 if ( !error.isNull() ) { 900 if ( !error.isNull() ) {
862 if ( QMessageBox::warning( this, tr("Error!"), 901 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
863 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 902 continue;
864 continue; 903 }
904 db->addEvent( ev );
905 emit newEvent();
906 break;
865 } 907 }
866 db->addEvent( ev );
867 emit newEvent();
868 break;
869 }
870} 908}
871 909
872void DateBook::setDocument( const QString &filename ) 910void DateBook::setDocument( const QString &filename )
873{ 911{
874 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 912 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
875 913
876 QValueList<Event> tl = Event::readVCalendar( filename ); 914 QValueList<Event> tl = Event::readVCalendar( filename );
877 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 915 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
878 db->addEvent( *it ); 916 db->addEvent( *it );
879 } 917 }
880} 918}
881 919
882static const char * beamfile = "/tmp/obex/event.vcs"; 920static const char * beamfile = "/tmp/obex/event.vcs";
883 921
884void DateBook::beamEvent( const Event &e ) 922void DateBook::beamEvent( const Event &e )
885{ 923{
886 qDebug("trying to beamn"); 924 qDebug("trying to beamn");
887 unlink( beamfile ); // delete if exists 925 unlink( beamfile ); // delete if exists
888 mkdir("/tmp/obex/", 0755); 926 mkdir("/tmp/obex/", 0755);
889 Event::writeVCalendar( beamfile, e ); 927 Event::writeVCalendar( beamfile, e );
890 Ir *ir = new Ir( this ); 928 Ir *ir = new Ir( this );
891 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 929 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
892 QString description = e.description(); 930 QString description = e.description();
893 ir->send( beamfile, description, "text/x-vCalendar" ); 931 ir->send( beamfile, description, "text/x-vCalendar" );