author | zautrix <zautrix> | 2005-06-15 18:23:08 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-15 18:23:08 (UTC) |
commit | ccfe3f97afd65c75ee6c7c931cb3694919a4e29b (patch) (side-by-side diff) | |
tree | 117d3467ef1d9678f31dea1b506390707f88d94a | |
parent | cba0ac17d3d505805be6aa4b4fea6f63473a1e00 (diff) | |
download | kdepimpi-ccfe3f97afd65c75ee6c7c931cb3694919a4e29b.zip kdepimpi-ccfe3f97afd65c75ee6c7c931cb3694919a4e29b.tar.gz kdepimpi-ccfe3f97afd65c75ee6c7c931cb3694919a4e29b.tar.bz2 |
fixess
-rw-r--r-- | korganizer/calendarview.cpp | 9 | ||||
-rw-r--r-- | korganizer/koagendaview.cpp | 2 | ||||
-rw-r--r-- | korganizer/kolistview.cpp | 68 | ||||
-rw-r--r-- | korganizer/kolistview.h | 5 | ||||
-rw-r--r-- | korganizer/koprefs.cpp | 4 | ||||
-rw-r--r-- | korganizer/koprefs.h | 1 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 10 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 2 |
10 files changed, 87 insertions, 16 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 377a66f..2012e92 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -1644,392 +1644,385 @@ bool CalendarView::importBday() if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) ++addCount; } } updateView(); topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); #else //DESKTOP_VERSION ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); // the result should now arrive through method insertBirthdays #endif //DESKTOP_VERSION #endif //KORG_NOKABC return true; } // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, const QStringList& anniversaryList, const QStringList& realNameList, const QStringList& emailList, const QStringList& assembledNameList, const QStringList& uidList) { //qDebug("KO::CalendarView::insertBirthdays"); if (uid == this->name()) { int count = birthdayList.count(); int addCount = 0; KCal::Attendee* a = 0; //qDebug("CalView 1 %i", count); QProgressBar bar(count,0 ); int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); bar.setCaption (i18n("inserting birthdays - close to abort!") ); qApp->processEvents(); QDate birthday; QDate anniversary; QString realName; QString email; QString assembledName; QString uid; bool ok = true; for ( int i = 0; i < count; i++) { if ( ! bar.isVisible() ) return; bar.setProgress( i ); qApp->processEvents(); birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); if (!ok) { ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); } anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); if (!ok) { ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); } realName = realNameList[i]; email = emailList[i]; assembledName = assembledNameList[i]; uid = uidList[i]; //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); if ( birthday.isValid() ){ a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, KCal::Attendee::ReqParticipant,uid) ; if ( addAnniversary( birthday, assembledName, a, true ) ) ++addCount; } if ( anniversary.isValid() ){ a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, KCal::Attendee::ReqParticipant,uid) ; if ( addAnniversary( anniversary, assembledName, a, false ) ) ++addCount; } } updateView(); topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); } } bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) { //qDebug("addAnni "); Event * ev = new Event(); ev->setOrganizer(KOPrefs::instance()->email()); if ( a ) { ev->addAttendee( a ); } QString kind; if ( birthday ) { kind = i18n( "Birthday" ); ev->setSummary( name + " (" + QString::number(date.year()) +")"); } else { kind = i18n( "Anniversary" ); ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); } ev->setCategories( kind ); ev->setDtStart( QDateTime(date) ); ev->setDtEnd( QDateTime(date) ); ev->setFloats( true ); Recurrence * rec = ev->recurrence(); rec->setYearly(Recurrence::rYearlyMonth,1,-1); rec->addYearlyNum( date.month() ); if ( !mCalendar->addAnniversaryNoDup( ev ) ) { delete ev; return false; } return true; } bool CalendarView::importQtopia( const QString &categories, const QString &datebook, const QString &todolist ) { QtopiaFormat qtopiaFormat; qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); updateView(); return true; #if 0 mGlobalSyncMode = SYNC_MODE_QTOPIA; mCurrentSyncDevice = "qtopia-XML"; if ( mSyncManager->mAskForPreferences ) edit_sync_options(); qApp->processEvents(); CalendarLocal* calendar = new CalendarLocal(); calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); bool syncOK = false; QtopiaFormat qtopiaFormat; qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); bool loadOk = true; if ( !categories.isEmpty() ) loadOk = qtopiaFormat.load( calendar, categories ); if ( loadOk && !datebook.isEmpty() ) loadOk = qtopiaFormat.load( calendar, datebook ); if ( loadOk && !todolist.isEmpty() ) loadOk = qtopiaFormat.load( calendar, todolist ); if ( loadOk ) { getEventViewerDialog()->setSyncMode( true ); syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); getEventViewerDialog()->setSyncMode( false ); qApp->processEvents(); if ( syncOK ) { if ( mSyncManager->mWriteBackFile ) { // write back XML file } setModified( true ); } } else { QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), question, i18n("Ok")) ; } delete calendar; updateView(); return syncOK; #endif } void CalendarView::setSyncEventsReadOnly() { - Event * ev; - QPtrList<Event> eL = mCalendar->rawEvents(); - ev = eL.first(); - while ( ev ) { - if ( ev->uid().left(15) == QString("last-syncEvent-") ) - ev->setReadOnly( true ); - ev = eL.next(); - } + mCalendar->setSyncEventsReadOnly(); } bool CalendarView::loadCalendars() { QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); mCalendar->setDefaultCalendar( 1 ); openCalendar( MainWindow::defaultFileName(), false ); cal = calendars.next(); while ( cal ) { addCalendar( cal ); cal = calendars.next(); } restoreCalendarSettings(); return true; } bool CalendarView::restoreCalendarSettings() { QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); while ( cal ) { mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); if ( cal->isStandard ) mCalendar->setDefaultCalendar( cal->mCalNumber ); cal = calendars.next(); } setSyncEventsReadOnly(); mCalendar->reInitAlarmSettings(); updateUnmanagedViews(); updateView(); return true; } void CalendarView::addCalendarId( int id ) { KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); addCalendar( cal ); } bool CalendarView::addCalendar( KopiCalendarFile * cal ) { cal->mErrorOnLoad = false; if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { cal->mLoadDt = QDateTime::currentDateTime(); return true; } qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); cal->mErrorOnLoad = true; return false; } bool CalendarView::openCalendar(QString filename, bool merge) { if (filename.isEmpty()) { return false; } if (!QFile::exists(filename)) { KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); return false; } globalFlagBlockAgenda = 1; clearAllViews(); if (!merge) { mViewManager->setDocumentId( filename ); mCalendar->close(); } mStorage->setFileName( filename ); if ( mStorage->load() ) { if ( merge ) ;//setModified( true ); else { //setModified( true ); mViewManager->setDocumentId( filename ); mDialogManager->setDocumentId( filename ); mTodoList->setDocumentId( filename ); } globalFlagBlockAgenda = 2; // if ( getLastSyncEvent() ) // getLastSyncEvent()->setReadOnly( true ); mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); if ( filename != MainWindow::defaultFileName() ) { saveCalendar( MainWindow::defaultFileName() ); } else { QFileInfo finf ( MainWindow::defaultFileName()); if ( finf.exists() ) { setLoadedFileVersion( finf.lastModified () ); } } return true; } else { // while failing to load, the calendar object could // have become partially populated. Clear it out. if ( !merge ) { mCalendar->close(); mViewManager->setDocumentId( filename ); mDialogManager->setDocumentId( filename ); mTodoList->setDocumentId( filename ); } //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); globalFlagBlockAgenda = 2; mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); } return false; } void CalendarView::showOpenError() { KMessageBox::error(this,i18n("Couldn't load calendar\n.")); } void CalendarView::setLoadedFileVersion(QDateTime dt) { loadedFileVersion = dt; } bool CalendarView::checkFileChanged(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); if ( dt <= loadedFileVersion ) return false; return true; } void CalendarView::watchSavedFile() { QFileInfo finf ( MainWindow::defaultFileName()); if ( !finf.exists() ) return; QDateTime dt = finf.lastModified (); if ( dt < loadedFileVersion ) { //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); return; } loadedFileVersion = dt; } bool CalendarView::checkAllFileVersions() { QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); mCalendar->setDefaultCalendar( 1 ); mCalendar->setDefaultCalendarEnabledOnly(); if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { if ( !checkFileVersion(MainWindow::defaultFileName())) { restoreCalendarSettings(); return false; } } cal = calendars.next(); QDateTime storeTemp = loadedFileVersion; while ( cal ) { if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { mCalendar->setDefaultCalendar( cal->mCalNumber ); mCalendar->setDefaultCalendarEnabledOnly(); loadedFileVersion = cal->mLoadDt.addSecs( 15 ); if ( !checkFileVersion(cal->mFileName )) { loadedFileVersion = storeTemp; restoreCalendarSettings(); return false; } } cal = calendars.next(); } loadedFileVersion = storeTemp; return true; } bool CalendarView::checkFileVersion(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); if ( dt <= loadedFileVersion ) return true; int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , i18n("KO/Pi Warning"),i18n("Overwrite"), i18n("Sync+save")); diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index b2b136a..93ff55e 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp @@ -473,385 +473,385 @@ KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); mAgenda->setPopup( mAllAgendaPopup ); mAllDayAgenda->setPopup( mAllAgendaPopup ); // make connections between dependent widgets mTimeLabels->setAgenda(mAgenda); // Update widgets to reflect user preferences // updateConfig(); // createDayLabels(); // these blank widgets make the All Day Event box line up with the agenda dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); // Scrolling connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), mTimeLabels, SLOT(positionChanged())); connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), SLOT(setContentsPos(int))); connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); // Create/Show/Edit/Delete Event connect(mAgenda,SIGNAL(newEventSignal(int,int)), SLOT(newEvent(int,int))); connect(mAgenda,SIGNAL(newTodoSignal(int,int)), SLOT(newTodo(int,int))); connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), SLOT(newEvent(int,int,int,int))); connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), SLOT(newEventAllDay(int,int))); connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), SLOT(newTodoAllDay(int,int))); connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), SLOT(newEventAllDay(int,int))); connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), SLOT(newTimeSpanSelected(int,int,int,int))); connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), SIGNAL(editIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), SIGNAL(editIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), SIGNAL(deleteIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), SIGNAL(deleteIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), SLOT(updateEventDates(KOAgendaItem *, int ))); connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), SLOT(updateEventDates(KOAgendaItem *, int))); // event indicator update connect(mAgenda,SIGNAL(lowerYChanged(int)), SLOT(updateEventIndicatorTop(int))); connect(mAgenda,SIGNAL(upperYChanged(int)), SLOT(updateEventIndicatorBottom(int))); // drag signals /* connect(mAgenda,SIGNAL(startDragSignal(Event *)), SLOT(startDrag(Event *))); connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), SLOT(startDrag(Event *))); */ // synchronize selections connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), mAllDayAgenda, SLOT( deselectItem() ) ); connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), mAgenda, SLOT( deselectItem() ) ); connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), SIGNAL( incidenceSelected( Incidence * ) ) ); connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), SIGNAL( incidenceSelected( Incidence * ) ) ); connect( mAgenda, SIGNAL( resizedSignal() ), SLOT( updateConfig( ) ) ); connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), SLOT( addToCalSlot(Incidence * , Incidence *) ) ); // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); connect( mAllDayAgenda, SIGNAL( signalClearSelection() ),mAgenda, SLOT( slotClearSelection()) ); connect( mAgenda, SIGNAL( signalClearSelection() ),mAllDayAgenda, SLOT( slotClearSelection()) ); } void KOAgendaView::toggleAllDay() { if ( mSplitterAgenda->firstHandle() ) mSplitterAgenda->firstHandle()->toggle(); } void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) { calendar()->addIncidence( inc ); if ( incOld ) { if ( incOld->typeID() == todoID ) emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); else emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); } } KOAgendaView::~KOAgendaView() { delete mAllAgendaPopup; //delete mAllDayAgendaPopup; delete KOAgendaItem::paintPix(); delete KOAgendaItem::paintPixSel(); } void KOAgendaView::resizeEvent( QResizeEvent* e ) { //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); bool uc = false; int ow = e->oldSize().width(); int oh = e->oldSize().height(); int w = e->size().width(); int h = e->size().height(); if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) uc = true; //qDebug("view changed %d %d %d %d ", ow, oh , w , h); } mUpcomingWidth = e->size().width() ; if ( mBlockUpdating || uc ) { mBlockUpdating = false; //mAgenda->setMinimumSize(800 , 600 ); //qDebug("mAgenda->resize+++++++++++++++ "); updateConfig(); //qDebug("KOAgendaView::Updating now possible "); } else createDayLabels(); //qDebug("resizeEvent end "); } void KOAgendaView::slotDaylabelClicked( int num ) { QDate firstDate = mSelectedDates.first(); if ( num == -1 ) emit showDateView( 6, firstDate ); else if (num >= 0 ) { if ( mSelectedDates.count() == 1) emit showDateView( 9, firstDate.addDays( num ) ); else emit showDateView( 3, firstDate.addDays( num ) ); } else showDateView( 10, firstDate.addDays(1) ); } KOAgendaButton* KOAgendaView::getNewDaylabel() { KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); mDayLabelsList.append( dayLabel ); mLayoutDayLabels->addWidget(dayLabel); return dayLabel ; } void KOAgendaView::createDayLabels() { if ( mBlockUpdating || globalFlagBlockLabel == 1) { // qDebug(" KOAgendaView::createDayLabels() blocked "); return; } int newHight; if ( !mSelectedDates.count()) return; // ### Before deleting and recreating we could check if mSelectedDates changed... // It would remove some flickering and gain speed (since this is called by // each updateView() call) - + int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); if ( maxWid < 20 ) maxWid = 20; QFont dlf = KOPrefs::instance()->mTimeLabelsFont; QFontMetrics fm ( dlf ); int selCount = mSelectedDates.count(); int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1; QString dayTest = "Mon 20"; //QString dayTest = "Mon 20"; int wid = fm.width( dayTest ); //maxWid -= ( selCount * 3 ); //working for QLabels if ( QApplication::desktop()->width() <= 320 ) maxWid -= ( selCount * 3 ); //working for QPushButton else maxWid -= ( selCount * 3 ); //working for QPushButton if ( maxWid < 0 ) maxWid = 20; int needWid = wid * selCount; //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); //if ( needWid > maxWid ) // qDebug("DAYLABELS TOOOOOOO BIG "); while ( needWid > maxWid ) { dayTest = dayTest.left( dayTest.length() - 1 ); wid = fm.width( dayTest ); needWid = wid * selCount; } int maxLen = dayTest.length(); int fontPoint = dlf.pointSize(); if ( maxLen < 2 ) { int fontPoint = dlf.pointSize(); while ( fontPoint > 4 ) { --fontPoint; dlf.setPointSize( fontPoint ); QFontMetrics f( dlf ); wid = f.width( "30" ); needWid = wid * selCount; if ( needWid < maxWid ) break; } maxLen = 2; } //qDebug("Max len %d ", dayTest.length() ); QFontMetrics tempF( dlf ); newHight = tempF.height(); mDayLabels->setFont( dlf ); // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; // mLayoutDayLabels->addSpacing(mTimeLabels->width()); //mLayoutDayLabels->addSpacing( 2 ); // QFont lFont = dlf; bool appendLabels = false; KOAgendaButton *dayLabel; dayLabel = mDayLabelsList.first(); if ( !dayLabel ) { appendLabels = true; dayLabel = getNewDaylabel(); } dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); dayLabel->setFont( dlf ); dayLabel->setNum( -1 ); //dayLabel->setAlignment(QLabel::AlignHCenter); dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); dayLabel->show(); DateList::ConstIterator dit; bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); int counter = -1; for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { ++counter; QDate date = *dit; // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); if ( ! appendLabels ) { dayLabel = mDayLabelsList.next(); if ( !dayLabel ) appendLabels = true; } if ( appendLabels ) { dayLabel = getNewDaylabel(); } dayLabel->setMinimumWidth( 1 ); dayLabel->setMaximumWidth( 10240 ); dayLabel->setFont( dlf ); dayLabel->show(); dayLabel->setAutoRepeat( false ); dayLabel->setNum( counter ); QString str; int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); switch ( maxLen ) { case 2: str = QString::number( date.day() ); break; case 3: str = dayName.left( 1 ) +QString::number( date.day()); break; case 4: str = dayName.left( 1 ) + " " +QString::number( date.day()); break; case 5: str = dayName.left( 2 ) + " " +QString::number( date.day()); break; case 6: str = dayName.left( 3 ) + " " +QString::number( date.day()); break; default: break; } if ( oneday ) { QString addString; if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) addString = i18n("Today"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) addString = i18n("Tomorrow"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) addString = i18n("Yesterday"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) addString = i18n("Day before yesterday"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) addString = i18n("Day after tomorrow"); if ( !addString.isEmpty() ) { str = addString+", " + str; } else { str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); } } dayLabel->setText(str); //dayLabel->setAlignment(QLabel::AlignHCenter); if (date == QDate::currentDate()) { QFont bFont = dlf; bFont.setBold( true ); dayLabel->setFont(bFont); } //dayLayout->addWidget(dayLabel); #ifndef KORG_NOPLUGINS CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); CalendarDecoration *it; for(it = cds.first(); it; it = cds.next()) { QString text = it->shortText( date ); if ( !text.isEmpty() ) { QLabel *label = new QLabel(text,mDayLabels); label->setAlignment(AlignCenter); dayLayout->addWidget(label); } } for(it = cds.first(); it; it = cds.next()) { QWidget *wid = it->smallWidget(mDayLabels,date); if ( wid ) { // wid->setHeight(20); dayLayout->addWidget(wid); } } #endif } if ( ! appendLabels ) { dayLabel = mDayLabelsList.next(); if ( !dayLabel ) appendLabels = true; } if ( appendLabels ) { dayLabel = getNewDaylabel(); } //dayLabel->hide();//test only dayLabel->setText(">"); dayLabel->setFont( dlf ); dayLabel->setAutoRepeat( true ); dayLabel->show(); dayLabel->setNum( -2 ); dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo ); //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); if ( !appendLabels ) { dayLabel = mDayLabelsList.next(); while ( dayLabel ) { //qDebug("!dayLabel %d",dayLabel ); dayLabel->hide(); dayLabel = mDayLabelsList.next(); } } mDayLabelsFrame->setFixedHeight( newHight + 4 ); } diff --git a/korganizer/kolistview.cpp b/korganizer/kolistview.cpp index 1f3b4c6..c705c73 100644 --- a/korganizer/kolistview.cpp +++ b/korganizer/kolistview.cpp @@ -1,565 +1,621 @@ /* This file is part of KOrganizer. Copyright (c) 1999 Preston Brown Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qlistview.h> #include <qlayout.h> #include <qlabel.h> #include <qpopupmenu.h> #include <qprogressbar.h> #include <qfileinfo.h> #include <qmessagebox.h> #include <qdialog.h> #include <qtextstream.h> #include <qdir.h> #include <qwhatsthis.h> #include <qregexp.h> #include <qpainter.h> #include <qpaintdevicemetrics.h> #include <klocale.h> #include <kdebug.h> #include <kiconloader.h> #include <kglobal.h> #include <libkdepim/kpimglobalprefs.h> #include <libkcal/calendar.h> #include <libkcal/calendarlocal.h> #include <libkcal/icalformat.h> #include <libkcal/vcalformat.h> #include <libkcal/recurrence.h> #include <libkcal/filestorage.h> #include <libkdepim/categoryselectdialog.h> #include <libkcal/kincidenceformatter.h> #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #else #include <qapplication.h> #endif #ifndef KORG_NOPRINTER #include "calprinter.h" #endif #include "koglobals.h" #include "koprefs.h" #include "kfiledialog.h" #include "kolistview.h" #include "koeventviewer.h" - - - class KOListViewWhatsThis :public QWhatsThis { public: KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; protected: virtual QString text( const QPoint& p) { return _view->getWhatsThisText(p) ; } private: QWidget* _wid; KOListView * _view; }; ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date ) { mItem = item; mDate = date; } ListItemVisitor::~ListItemVisitor() { } bool ListItemVisitor::visit(Event *e) { bool ok = false; QString start, end; QDate ds, de; if ( e->doesRecur() ) { ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date(); if ( ok ) { int days = e->dtStart().date().daysTo(e->dtEnd().date() ); start = KGlobal::locale()->formatDate(ds,true); de = ds.addDays( days); end = KGlobal::locale()->formatDate(de,true); } } if ( ! ok ) { start =e->dtStartDateStr(); end = e->dtEndDateStr(); ds = e->dtStart().date(); de = e->dtEnd().date(); } mItem->setText(0,e->summary()); mItem->setText(1,start); if ( e->doesFloat() ) mItem->setText(2,"---"); else mItem->setText(2,e->dtStartTimeStr()); mItem->setText(3,end); if ( e->doesFloat() ) mItem->setText(4,"---"); else mItem->setText(4,e->dtEndTimeStr()); if ( e->isAlarmEnabled() ) { mItem->setText(5,e->alarms().first()->offsetText() ); } else { mItem->setText(5, i18n("No")); } mItem->setText(6, e->recurrence()->recurrenceText()); if( ! e->doesRecur() ) mItem->setSortKey( 6, "-" ); mItem->setText(7,"---"); mItem->setText(8,"---"); mItem->setText(9, e->cancelled() ? i18n("Yes") : i18n("No")); mItem->setText(10,e->categoriesStr()); + mItem->setText(11, KOPrefs::instance()->calName( e->calID() )); QString key; QTime t = e->doesFloat() ? QTime(0,0) : e->dtStart().time(); key.sprintf("%04d%02d%02d%02d%02d",ds.year(),ds.month(),ds.day(),t.hour(),t.minute()); mItem->setSortKey(1,key); t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time(); key.sprintf("%04d%02d%02d%02d%02d",de.year(),de.month(),de.day(),t.hour(),t.minute()); mItem->setSortKey(3,key); return true; } bool ListItemVisitor::visit(Todo *t) { mItem->setText(0,i18n("Todo: %1").arg(t->summary())); if (t->hasStartDate()) { mItem->setText(1,t->dtStartDateStr()); if (t->doesFloat()) { mItem->setText(2,"---"); } else { mItem->setText(2,t->dtStartTimeStr()); } } else { mItem->setText(1,"---"); mItem->setText(2,"---"); } mItem->setText(3,"---"); mItem->setText(4,"---"); if ( t->isAlarmEnabled() ) { mItem->setText(5,t->alarms().first()->offsetText() ); } else { mItem->setText(5, i18n("No")); } mItem->setText(6, t->recurrence()->recurrenceText()); if( ! t->doesRecur() ) mItem->setSortKey( 6, "-" ); if (t->hasDueDate()) { mItem->setText(7,t->dtDueDateStr()); if (t->doesFloat()) { mItem->setText(8,"---"); } else { mItem->setText(8,t->dtDueTimeStr()); } } else { mItem->setText(7,"---"); mItem->setText(8,"---"); } mItem->setText(9, t->cancelled() ? i18n("Yes") : i18n("No")); mItem->setText(10,t->categoriesStr()); + mItem->setText(11, KOPrefs::instance()->calName( t->calID() )); QString key; QDate d; if (t->hasDueDate()) { d = t->dtDue().date(); QTime tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time(); key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); mItem->setSortKey(7,key); } if ( t->hasStartDate() ) { d = t->dtStart().date(); QTime tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time(); key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); mItem->setSortKey(1,key); } return true; } bool ListItemVisitor::visit(Journal * j) { QString des = j->description().left(30); des = des.simplifyWhiteSpace (); des.replace (QRegExp ("\\n"),"" ); des.replace (QRegExp ("\\r"),"" ); mItem->setText(0,i18n("Journal: ")+des.left(25)); mItem->setText(1,j->dtStartDateStr()); mItem->setText(2,"---"); mItem->setText(3,"---"); mItem->setText(4,"---"); mItem->setText(5,"---"); mItem->setText(6,"---"); mItem->setText(7,j->dtStartDateStr()); mItem->setText(8,"---"); mItem->setText(9,"---"); mItem->setText(10,i18n("Last Modified: ")+ KGlobal::locale()->formatDateTime( j->lastModified() , true) ); + mItem->setText(11, KOPrefs::instance()->calName( j->calID() )); QString key; QDate d = j->dtStart().date(); key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); mItem->setSortKey(1,key); mItem->setSortKey(7,key); return true; } KOListView::KOListView(Calendar *calendar, QWidget *parent, const char *name) : KOEventView(calendar, parent, name) { mActiveItem = 0; mListView = new KOListViewListView(this); mListView->addColumn(i18n("Summary")); mListView->addColumn(i18n("Start Date")); mListView->addColumn(i18n("Start Time")); mListView->addColumn(i18n("End Date")); mListView->addColumn(i18n("End Time")); mListView->addColumn(i18n("Alarm")); // alarm set? mListView->addColumn(i18n("Recurs")); // recurs? mListView->addColumn(i18n("Due Date")); mListView->addColumn(i18n("Due Time")); mListView->addColumn(i18n("Cancelled")); mListView->addColumn(i18n("Categories")); + mListView->addColumn(i18n("Calendar")); mListView->setColumnAlignment(0,AlignLeft); mListView->setColumnAlignment(1,AlignLeft); mListView->setColumnAlignment(2,AlignHCenter); mListView->setColumnAlignment(3,AlignLeft); mListView->setColumnAlignment(4,AlignHCenter); mListView->setColumnAlignment(5,AlignLeft); mListView->setColumnAlignment(6,AlignLeft); mListView->setColumnAlignment(7,AlignLeft); mListView->setColumnAlignment(8,AlignLeft); mListView->setColumnAlignment(9,AlignLeft); mListView->setColumnAlignment(10,AlignLeft); - mListView->setColumnWidthMode(10, QListView::Manual); + mListView->setColumnAlignment(11,AlignLeft); mKOListViewWhatsThis = new KOListViewWhatsThis(mListView->viewport(),this); int iii = 0; - for ( iii = 0; iii< 10 ; ++iii ) + for ( iii = 0; iii< 12 ; ++iii ) mListView->setColumnWidthMode( iii, QListView::Manual ); QBoxLayout *layoutTop = new QVBoxLayout(this); layoutTop->addWidget(mListView); mListView->setFont ( KOPrefs::instance()->mListViewFont ); mPopupMenu = eventPopup(); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Select all"),this, SLOT(allSelection()),true); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Deselect all"),this, SLOT(clearSelection()),true); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Delete all selected"),this, SLOT(deleteAll()),true); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Hide all selected"),this, SLOT(hideAll()),true); mPopupMenu->insertSeparator(); #ifdef DESKTOP_VERSION mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Print complete list"),this, SLOT(printList()),true); mPopupMenu->insertSeparator(); #endif + mCalPopup = new QPopupMenu ( this ); + mPopupMenu->insertItem( i18n("Set Calendar"), mCalPopup ); + + QObject::connect(mCalPopup,SIGNAL(aboutToShow()),this, + SLOT( populateCalPopup() )); + QObject::connect(mCalPopup,SIGNAL(activated( int )),this, + SLOT( setCalendar( int ) )); QPopupMenu * exportPO = new QPopupMenu ( this ); mPopupMenu->insertItem( i18n("Export selected"), exportPO ); exportPO->insertItem( i18n("As iCal (ics) file..."),this, SLOT(saveToFile())); exportPO->insertItem( i18n("As vCal (vcs) file..."),this, SLOT(saveToFileVCS())); exportPO->insertItem( i18n("Journal/Details..."),this, SLOT(saveDescriptionToFile())); // mPopupMenu->insertSeparator(); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Add Categ. to selected..."),this, SLOT(addCat()),true); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Set Categ. for selected..."),this, SLOT(setCat()),true); //mPopupMenu->insertSeparator(); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Set alarm for selected..."),this, SLOT(setAlarm()),true); + #ifndef DESKTOP_VERSION mPopupMenu->insertSeparator(); mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), i18n("Beam selected via IR"),this, SLOT(beamSelected()),true); #endif /* mPopupMenu = new QPopupMenu; mPopupMenu->insertItem(i18n("Edit Event"), this, SLOT (editEvent())); mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this, SLOT (deleteEvent())); mPopupMenu->insertSeparator(); mPopupMenu->insertItem(i18n("Show Dates"), this, SLOT(showDates())); mPopupMenu->insertItem(i18n("Hide Dates"), this, SLOT(hideDates())); */ QObject::connect(mListView,SIGNAL( newEvent()), this,SIGNAL(signalNewEvent())); QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)), this,SLOT(defaultItemAction(QListViewItem *))); QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *, const QPoint &, int )), this,SLOT(popupMenu(QListViewItem *,const QPoint &,int))); QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)), SLOT(processSelectionChange(QListViewItem *))); QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *)) ); readSettings(KOGlobals::config(),"KOListView Layout"); } KOListView::~KOListView() { delete mPopupMenu; #if QT_VERSION >= 0x030000 #else delete mKOListViewWhatsThis; #endif } QString KOListView::getWhatsThisText(QPoint p) { KOListViewItem* item = ( KOListViewItem* ) mListView->itemAt( p ); if ( item ) return KIncidenceFormatter::instance()->getFormattedText( item->data(), KOPrefs::instance()->mWTshowDetails, KOPrefs::instance()->mWTshowCreated, KOPrefs::instance()->mWTshowChanged); return i18n("That is the list view" ); } +void KOListView::setCalendar( int c ) +{ + int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), + i18n("This adds the selected\nitems to the calendar\n%1\nand removes them from\ntheir current calendar!").arg( KOPrefs::instance()->calName( c ) ), + i18n("Continue"), i18n("Cancel"), 0, + 0, 1 ); + if ( result != 0 ) { + return; + } + + QPtrList<Incidence> delSel = getSelectedIncidences() ; + int icount = delSel.count(); + if ( icount ) { + Incidence *incidence = delSel.first(); + while ( incidence ) { + incidence->setCalID( c ); + KOListViewItem * item = getItemForEvent( incidence ); + if ( item ) { + ListItemVisitor v(item, mStartDate ); + incidence->accept(v); + } + incidence = delSel.next(); + } + } + QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; + KopiCalendarFile * cal = calendars.first(); + while ( cal ) { + mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); + mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); + mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); + if ( cal->isStandard ) + mCalendar->setDefaultCalendar( cal->mCalNumber ); + cal = calendars.next(); + } + mCalendar->setSyncEventsReadOnly(); + mCalendar->reInitAlarmSettings(); + +} +void KOListView::populateCalPopup() +{ + mCalPopup->clear(); + KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); + while ( kkf ) { + mCalPopup->insertItem( kkf->mName, kkf->mCalNumber); + kkf = KOPrefs::instance()->mCalendars.next(); + } +} void KOListView::updateList() { // qDebug(" KOListView::updateList() "); } void KOListView::clearList() { clear (); } void KOListView::addCat( ) { setCategories( false ); } void KOListView::setCat() { setCategories( true ); } void KOListView::setAlarm() { KOAlarmPrefs kap( this); if ( !kap.exec() ) return; QStringList itemList; QPtrList<KOListViewItem> sel ; QListViewItem *qitem = mListView->firstChild (); while ( qitem ) { if ( qitem->isSelected() ) { Incidence* inc = ((KOListViewItem *) qitem)->data(); if ( inc->typeID() != journalID ) { if ( inc->typeID() == todoID ) { if ( ((Todo*)inc)->hasDueDate() ) sel.append(((KOListViewItem *)qitem)); } else sel.append(((KOListViewItem *)qitem)); } } qitem = qitem->nextSibling(); } int count = 0; KOListViewItem * item, *temp; item = sel.first(); Incidence* inc; while ( item ) { inc = item->data(); ++count; if (kap.mAlarmButton->isChecked()) { if (inc->alarms().count() == 0) inc->newAlarm(); QPtrList<Alarm> alarms = inc->alarms(); Alarm *alarm; for (alarm = alarms.first(); alarm; alarm = alarms.next() ) { alarm->setEnabled(true); int j = kap.mAlarmTimeEdit->value()* -60; if (kap.mAlarmIncrCombo->currentItem() == 1) j = j * 60; else if (kap.mAlarmIncrCombo->currentItem() == 2) j = j * (60 * 24); alarm->setStartOffset( j ); if (!kap.mAlarmProgram.isEmpty() && kap.mAlarmProgramButton->isOn()) { alarm->setProcedureAlarm(kap.mAlarmProgram); } else if (!kap.mAlarmSound.isEmpty() && kap.mAlarmSoundButton->isOn()) alarm->setAudioAlarm(kap.mAlarmSound); else alarm->setType(Alarm::Invalid); //alarm->setAudioAlarm("default"); // TODO: Deal with multiple alarms break; // For now, stop after the first alarm } } else { Alarm* alarm = inc->alarms().first(); if ( alarm ) { alarm->setEnabled(false); alarm->setType(Alarm::Invalid); } } ListItemVisitor v(item, mStartDate ); inc->accept(v); item = sel.next(); } topLevelWidget()->setCaption( i18n("Changed alarm for %1 items").arg( count ) ); qDebug("KO: Set alarm for %d items", count); calendar()->reInitAlarmSettings(); QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); } void KOListView::setCategories( bool removeOld ) { KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 ); csd->setColorEnabled(); if (! csd->exec()) { delete csd; return; } QStringList catList = csd->selectedCategories(); delete csd; // if ( catList.count() == 0 ) // return; //catList.sort(); QString categoriesStr = catList.join(","); int i; QStringList itemList; QPtrList<KOListViewItem> sel ; QListViewItem *qitem = mListView->firstChild (); while ( qitem ) { if ( qitem->isSelected() ) { sel.append(((KOListViewItem *)qitem)); } qitem = qitem->nextSibling(); } KOListViewItem * item, *temp; item = sel.first(); if( item ) { Incidence* inc = item->data() ; bool setSub = false; if( inc->typeID() == todoID && sel.count() == 1 && inc->relations().count() > 0 ) { int result = KMessageBox::warningYesNoCancel(this, i18n("The todo\n%1\nhas subtodos!\nDo you want to set\nthe categories for\nall subtodos as well?").arg( inc->summary().left ( 25 ) ), i18n("Todo has subtodos"), i18n("Yes"), i18n("No")); if (result == KMessageBox::Cancel) item = 0; if (result == KMessageBox::Yes) setSub = true; } while ( item ) { inc = item->data(); if ( removeOld ) { inc->setCategories( catList, setSub ); } else { inc->addCategories( catList, setSub ); } ListItemVisitor v(item, mStartDate ); inc->accept(v); item = sel.next(); } } QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); } void KOListView::beamSelected() { QPtrList<Incidence> delSel = getSelectedIncidences() ; int icount = delSel.count(); if ( icount ) { emit beamIncidenceList( delSel ); return; QString fn ; fn = QDir::homeDirPath()+"/kopitempbeamfile.vcs"; QString mes; bool createbup = true; if ( createbup ) { QString description = "\n"; CalendarLocal* cal = new CalendarLocal(); cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); Incidence *incidence = delSel.first(); while ( incidence ) { Incidence *in = incidence->clone(); description += in->summary() + "\n"; cal->addIncidence( in ); incidence = delSel.next(); } FileStorage storage( cal, fn, new VCalFormat ); storage.save(); delete cal; mes = i18n("KO/Pi: Ready for beaming"); topLevelWidget()->setCaption(mes); #ifndef DESKTOP_VERSION Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); ir->send( fn, description, "text/x-vCalendar" ); #endif } } } void KOListView::beamDone( Ir *ir ) { #ifndef DESKTOP_VERSION delete ir; #endif topLevelWidget()->setCaption(i18n("KO/Pi:Beaming done")); } void KOListView::saveDescriptionToFile() { int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."), i18n("Continue"), i18n("Cancel"), 0, @@ -850,385 +906,385 @@ QPtrList<Incidence> KOListView::selectedIncidences() QPtrList<Incidence> eventList; QListViewItem *item = mListView->firstChild (); while ( item ) { if ( item->isSelected() ) { eventList.append(((KOListViewItem *)item)->data()); } item = item->nextSibling(); } // // QListViewItem *item = mListView->selectedItem(); //if (item) eventList.append(((KOListViewItem *)item)->data()); return eventList; } DateList KOListView::selectedDates() { DateList eventList; return eventList; } void KOListView::showDates(bool show) { // Shouldn't we set it to a value greater 0? When showDates is called with // show == true at first, then the columnwidths are set to zero. static int oldColWidth1 = 0; static int oldColWidth3 = 0; if (!show) { oldColWidth1 = mListView->columnWidth(1); oldColWidth3 = mListView->columnWidth(3); mListView->setColumnWidth(1, 0); mListView->setColumnWidth(3, 0); } else { mListView->setColumnWidth(1, oldColWidth1); mListView->setColumnWidth(3, oldColWidth3); } mListView->repaint(); } void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td) { #ifndef KORG_NOPRINTER calPrinter->preview(CalPrinter::Day, fd, td); #endif } void KOListView::showDates() { showDates(true); } void KOListView::hideDates() { showDates(false); } void KOListView::resetFocus() { topLevelWidget()->setActiveWindow(); topLevelWidget()->raise(); mListView->setFocus(); } void KOListView::updateView() { mListView->setFocus(); if ( mListView->firstChild () ) mListView->setCurrentItem( mListView->firstChild () ); } void KOListView::updateConfig() { mListView->setFont ( KOPrefs::instance()->mListViewFont ); updateView(); } void KOListView::setStartDate(const QDate &start) { mStartDate = start; } void KOListView::showDates(const QDate &start, const QDate &end) { clear(); mStartDate = start; QDate date = start; QPtrList<Journal> j_list; while( date <= end ) { addEvents(calendar()->events(date)); addTodos(calendar()->todos(date)); Journal* jo = calendar()->journal(date); if ( jo ) j_list.append( jo ); date = date.addDays( 1 ); } addJournals(j_list); emit incidenceSelected( 0 ); updateView(); } void KOListView::addEvents(QPtrList<Event> eventList) { Event *ev; for(ev = eventList.first(); ev; ev = eventList.next()) { addIncidence(ev); } if ( !mListView->currentItem() ){ updateView(); } } void KOListView::addTodos(QPtrList<Todo> eventList) { Todo *ev; for(ev = eventList.first(); ev; ev = eventList.next()) { addIncidence(ev); } if ( !mListView->currentItem() ){ updateView(); } } void KOListView::addJournals(QPtrList<Journal> eventList) { Journal *ev; for(ev = eventList.first(); ev; ev = eventList.next()) { addIncidence(ev); } if ( !mListView->currentItem() ){ updateView(); } } void KOListView::addIncidence(Incidence *incidence) { if ( mUidDict.find( incidence->uid() ) ) return; // mListView->setFont ( KOPrefs::instance()->mListViewFont ); mUidDict.insert( incidence->uid(), incidence ); KOListViewItem *item = new KOListViewItem( incidence, mListView ); ListItemVisitor v(item, mStartDate ); if (incidence->accept(v)) { return; } else delete item; } void KOListView::showEvents(QPtrList<Event> eventList) { clear(); addEvents(eventList); // After new creation of list view no events are selected. emit incidenceSelected( 0 ); } int KOListView::count() { return mListView->childCount(); } void KOListView::changeEventDisplay(Event *event, int action) { KOListViewItem *item; switch(action) { case KOGlobals::EVENTADDED: addIncidence( event ); break; case KOGlobals::EVENTEDITED: item = getItemForEvent(event); if (item) { mUidDict.remove( event->uid() ); delete item; addIncidence( event ); } break; case KOGlobals::EVENTDELETED: item = getItemForEvent(event); if (item) { mUidDict.remove( event->uid() ); delete item; } break; default: ; } } -KOListViewItem *KOListView::getItemForEvent(Event *event) +KOListViewItem *KOListView::getItemForEvent(Incidence *event) { KOListViewItem *item = (KOListViewItem *)mListView->firstChild(); while (item) { if (item->data() == event) return item; item = (KOListViewItem *)item->nextSibling(); } return 0; } void KOListView::defaultItemAction(QListViewItem *i) { KOListViewItem *item = static_cast<KOListViewItem *>( i ); if ( item ) defaultAction( item->data() ); } void KOListView::popupMenu(QListViewItem *item,const QPoint &,int) { mActiveItem = (KOListViewItem *)item; if (mActiveItem) { Incidence *incidence = mActiveItem->data(); mPopupMenu->enableDefault( !mListView->hasMultiSelection( item ) ); mPopupMenu->showIncidencePopup(incidence); /* if ( incidence && incidence->type() == "Event" ) { Event *event = static_cast<Event *>( incidence ); mPopupMenu->showEventPopup(event); } */ } } void KOListView::readSettings(KConfig *config, QString setting) { // qDebug("KOListView::readSettings "); mListView->restoreLayout(config,setting); } void KOListView::writeSettings(KConfig *config, QString setting) { // qDebug("KOListView::writeSettings "); mListView->saveLayout(config, setting); } void KOListView::processSelectionChange(QListViewItem *) { KOListViewItem *item = static_cast<KOListViewItem *>( mListView->currentItem() ); if ( !item ) { emit incidenceSelected( 0 ); } else { emit incidenceSelected( item->data() ); } } void KOListView::clearSelection() { mListView->selectAll( false ); } void KOListView::allSelection() { mListView->selectAll( true ); } void KOListView::clear() { mListView->clear(); mUidDict.clear(); } Incidence* KOListView::currentItem() { if ( mListView->currentItem() ) return ((KOListViewItem*) mListView->currentItem())->data(); return 0; } void KOListView::keyPressEvent ( QKeyEvent *e) { if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) { deleteAll(); return; } e->ignore(); } void KOListViewListView::keyPressEvent ( QKeyEvent *e) { switch ( e->key() ) { case Qt::Key_Down: if ( e->state() == ShiftButton ) { QListViewItem* cn = currentItem(); if ( !cn ) cn = firstChild(); if ( !cn ) return; while ( cn->nextSibling() ) cn = cn->nextSibling(); setCurrentItem ( cn ); ensureItemVisible ( cn ); e->accept(); return; } if ( e->state() == ControlButton ) { int count = childCount (); int jump = count / 5; QListViewItem* cn; cn = currentItem(); if ( ! cn ) return; if ( jump == 0 ) jump = 1; while ( jump && cn->nextSibling() ) { cn = cn->nextSibling(); --jump; } setCurrentItem ( cn ); ensureItemVisible ( cn ); } else QListView::keyPressEvent ( e ) ; e->accept(); break; case Qt::Key_Up: if ( e->state() == ShiftButton ) { QListViewItem* cn = firstChild(); if ( cn ) { setCurrentItem ( cn ); ensureItemVisible ( cn ); } e->accept(); return; } if ( e->state() == ControlButton ) { int count = childCount (); int jump = count / 5; QListViewItem* cn; cn = currentItem(); if ( ! cn ) return; if ( jump == 0 ) jump = 1; while ( jump && cn->itemAbove ()) { cn = cn->itemAbove (); --jump; } setCurrentItem ( cn ); ensureItemVisible ( cn ); } else QListView::keyPressEvent ( e ) ; e->accept(); break; case Qt::Key_I: { QListViewItem* cn; cn = currentItem(); if ( cn ) { KOListViewItem* ci = (KOListViewItem*)( cn ); if ( ci ){ //emit showIncidence( ci->data()); cn = cn->nextSibling(); if ( cn ) { setCurrentItem ( cn ); ensureItemVisible ( cn ); } emit showIncidence( ci->data()); } } e->accept(); } break; case Qt::Key_Return: case Qt::Key_Enter: { QListViewItem* cn; cn = currentItem(); if ( cn ) { KOListViewItem* ci = (KOListViewItem*)( cn ); if ( ci ){ if ( e->state() == ShiftButton ) ci->setSelected( false ); else ci->setSelected( true ); cn = cn->nextSibling(); if ( cn ) { setCurrentItem ( cn ); ensureItemVisible ( cn ); diff --git a/korganizer/kolistview.h b/korganizer/kolistview.h index 9da5497..d384af0 100644 --- a/korganizer/kolistview.h +++ b/korganizer/kolistview.h @@ -106,213 +106,216 @@ class KOAlarmPrefs : public QDialog } QString mAlarmSound, mAlarmProgram ; QCheckBox* mAlarmButton; QSpinBox* mAlarmTimeEdit; QLabel* mAlarmLabel; QComboBox* mAlarmIncrCombo ; QPushButton* mAlarmSoundButton ,*mAlarmProgramButton; private slots: void pickAlarmSound() { //QString prefix = mAlarmSound; if (!mAlarmSoundButton->isOn()) { //mAlarmSound = ""; QToolTip::remove(mAlarmSoundButton); QToolTip::add(mAlarmSoundButton, i18n("No sound set")); mAlarmProgramButton->setOn(true); mAlarmSoundButton->setOn(false); } else { QString fileName(KFileDialog::getOpenFileName(mAlarmSound, i18n("*.wav|Wav Files"), 0)); if (!fileName.isEmpty()) { mAlarmSound = fileName; mAlarmLabel->setText( "..."+fileName.right( 30 ) ); QToolTip::remove(mAlarmSoundButton); QString dispStr = i18n("Playing '%1'").arg(fileName); QToolTip::add(mAlarmSoundButton, dispStr); mAlarmProgramButton->setOn(false); mAlarmSoundButton->setOn(true); } else { mAlarmProgramButton->setOn(true); mAlarmSoundButton->setOn(false); } } }; void pickAlarmProgram() { if (!mAlarmProgramButton->isOn()) { //mAlarmProgram = ""; QToolTip::remove(mAlarmProgramButton); QToolTip::add(mAlarmProgramButton, i18n("No program set")); mAlarmProgramButton->setOn(false); mAlarmSoundButton->setOn(true); } else { QString fileName(KFileDialog::getOpenFileName(mAlarmProgram,i18n("Procedure Alarm.: ") , 0)); if (!fileName.isEmpty()) { mAlarmProgram = fileName; mAlarmLabel->setText( "..."+fileName.right( 30 ) ); QToolTip::remove(mAlarmProgramButton); QString dispStr = i18n("Running '%1'").arg(fileName); QToolTip::add(mAlarmProgramButton, dispStr); mAlarmSoundButton->setOn(false); mAlarmProgramButton->setOn(true); } else { mAlarmProgramButton->setOn(false); mAlarmSoundButton->setOn(true); } } }; }; typedef CustomListViewItem<Incidence *> KOListViewItem; /** This class provides the initialisation of a KOListViewItem for calendar components using the Incidence::Visitor. */ class ListItemVisitor : public Incidence::Visitor { public: ListItemVisitor(KOListViewItem *, QDate d); ~ListItemVisitor(); bool visit(Event *); bool visit(Todo *); bool visit(Journal *); private: KOListViewItem *mItem; QDate mDate; }; /** This class provides a multi-column list view of events. It can display events from one particular day or several days, it doesn't matter. To use a view that only handles one day at a time, use KODayListView. @short multi-column list view of various events. @author Preston Brown <pbrown@kde.org> @see KOBaseView, KODayListView */ class KOListView; class KOListViewListView : public KListView { Q_OBJECT public: KOListViewListView(KOListView * lv ); bool hasMultiSelection(QListViewItem*); void printList(); signals: void newEvent(); void showIncidence( Incidence* ); public slots: void popupMenu(); private: QPoint mEventPos; QPoint mEventGlobalPos; QTimer* mPopupTimer; int mYMousePos; void keyPressEvent ( QKeyEvent * ) ; void contentsMouseDoubleClickEvent(QMouseEvent *e); void contentsMousePressEvent(QMouseEvent *e); void contentsMouseReleaseEvent(QMouseEvent *e); void contentsMouseMoveEvent(QMouseEvent *e); bool mMouseDown; }; class KOListView : public KOEventView { Q_OBJECT public: KOListView(Calendar *calendar, QWidget *parent = 0, const char *name = 0); ~KOListView(); virtual int maxDatesHint(); virtual int currentDateCount(); virtual QPtrList<Incidence> selectedIncidences(); virtual DateList selectedDates(); void showDates(bool show); Incidence* currentItem(); void addTodos(QPtrList<Todo> eventList); void addJournals(QPtrList<Journal> eventList); virtual void printPreview(CalPrinter *calPrinter, const QDate &, const QDate &); void readSettings(KConfig *config, QString setting = "KOListView Layout"); void writeSettings(KConfig *config, QString setting = "KOListView Layout"); void updateList(); void clearList(); void setStartDate(const QDate &start); int count(); QString getWhatsThisText(QPoint p); QPtrList<Incidence> KOListView::getSelectedIncidences( bool includeEvents = true, bool includeTodos = true , bool includeJournals = true, bool onlyDueTodos = false ); signals: void signalNewEvent(); void beamIncidenceList(QPtrList<Incidence>); public slots: void hideAll(); void printList(); void resetFocus(); virtual void updateView(); virtual void showDates(const QDate &start, const QDate &end); virtual void showEvents(QPtrList<Event> eventList); void clearSelection(); void allSelection(); void clear(); void beamDone( Ir *ir ); void showDates(); void hideDates(); void deleteAll(); void saveToFile(); void saveToFileVCS(); void saveDescriptionToFile(); void beamSelected(); void updateConfig(); void addCat(); void setCat(); void setAlarm(); void setCategories( bool removeOld ); void changeEventDisplay(Event *, int); void defaultItemAction(QListViewItem *item); void popupMenu(QListViewItem *item,const QPoint &,int); + void setCalendar( int c ); + void populateCalPopup(); protected slots: void processSelectionChange(QListViewItem *); protected: void writeToFile( bool iCal ); void addEvents(QPtrList<Event> eventList); void addIncidence(Incidence *); - KOListViewItem *getItemForEvent(Event *event); + KOListViewItem *getItemForEvent(Incidence *event); private: + QPopupMenu* mCalPopup; KOListViewWhatsThis *mKOListViewWhatsThis; KOListViewListView *mListView; KOEventPopupMenu *mPopupMenu; KOListViewItem *mActiveItem; QDict<Incidence> mUidDict; QDate mStartDate; void keyPressEvent ( QKeyEvent * ) ; }; #endif diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp index 65f0342..a4ea3d3 100644 --- a/korganizer/koprefs.cpp +++ b/korganizer/koprefs.cpp @@ -306,290 +306,294 @@ KOPrefs::KOPrefs() : KPrefs::setCurrentGroup( "Editors" ); addItemStringList( "EventTemplates", &mEventTemplates ); addItemStringList( "TodoTemplates", &mTodoTemplates ); addItemInt("DestinationPolicy",&mDestination,standardDestination); KPrefs::setCurrentGroup( "ViewOptions" ); addItemBool("EVshowDetails",&mEVshowDetails,true); addItemBool("EVshowCreated",&mEVshowCreated,true); addItemBool("EVshowChanged",&mEVshowChanged,true); addItemBool("WTshowDetails",&mWTshowDetails,false); addItemBool("WTshowCreated",&mWTshowCreated,false); addItemBool("WTshowChanged",&mWTshowChanged,false); mCalendars.setAutoDelete( true ); } KOPrefs::~KOPrefs() { if (mInstance == this) mInstance = insd.setObject(0); mCalendars.setAutoDelete( true ); mCalendars.clear(); //qDebug("KOPrefs::~KOPrefs() "); } KOPrefs *KOPrefs::instance() { if (!mInstance) { mInstance = insd.setObject(new KOPrefs()); mInstance->readConfig(); } return mInstance; } void KOPrefs::usrSetDefaults() { } void KOPrefs::fillMailDefaults() { if (mName.isEmpty()) mName = i18n("Anonymous"); if (mEmail.isEmpty()) mEmail = i18n("nobody@nowhere"); } void KOPrefs::setTimeZoneIdDefault() { ; } void KOPrefs::setAllDefaults() { setCategoryDefaults(); mEventSummaryUser = getDefaultList() ; mTodoSummaryUser = getDefaultList() ; mLocationDefaults = getLocationDefaultList(); } void KOPrefs::setCategoryDefaults() { mCustomCategories.clear(); mCustomCategories = getDefaultList(); QStringList::Iterator it; for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { setCategoryColor(*it,mDefaultCategoryColor); } } QStringList KOPrefs::getLocationDefaultList() { QStringList retval ; retval << i18n("Home") << i18n("Office") << i18n("Library") << i18n("School") << i18n("Doctor") << i18n("Beach") << i18n("University") << i18n("Restaurant") << i18n("Bar") << i18n("Conference room") << i18n("Cinema") << i18n("Lake") << i18n("Kindergarten") << i18n("Germany") << i18n("Sweden") << i18n("Forest") << i18n("Desert") << i18n("Kitchen") ; // << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") retval.sort(); return retval; } QStringList KOPrefs::getDefaultList() { QStringList retval ; retval << i18n("Anniversary") << i18n("Appointment") << i18n("Birthday") << i18n("Business") << i18n("Business Travel") << i18n("Cinema") << i18n("Customer") << i18n("Break")<< i18n("Breakfast")<< i18n("Competition")<< i18n("Dinner") << i18n("Education")<< i18n("Family") << i18n("Favorites") << i18n("Festival")<< i18n("Fishing")<< i18n("Flight") << i18n("Gifts") << i18n("Holiday") << i18n("Holiday Cards")<< i18n("Hot Contacts") << i18n("Hiking") << i18n("Hunting") << i18n("Key Customer") << i18n("Kids") << i18n("Lunch") << i18n("Meeting") << i18n("Miscellaneous") << i18n("Partner")<< i18n("Party") << i18n("Personal") << i18n("Personal Travel") << i18n("PHB") << i18n("Phone Calls") << i18n("Projects") << i18n("Recurring") << i18n("School") << i18n("Shopping") << i18n("Speach") << i18n("Special Occasion") << i18n("Sports") << i18n("Talk") << i18n("Travel") << i18n("TV")<< i18n("University") << i18n("Vacation") << i18n("VIP") << i18n("SyncEvent") ; retval.sort(); //qDebug("cat %s ", retval.join("-").latin1()); return retval; } void KOPrefs::usrReadConfig() { config()->setGroup("General"); //qDebug("KOPrefs::usrReadConfig() "); mCustomCategories = config()->readListEntry("Custom Categories"); mOldLoadedLanguage = mOldLanguage ; mOldLanguage = KPimGlobalPrefs::instance()->mPreferredLanguage; if (mLocationDefaults.isEmpty()) { mLocationDefaults = getLocationDefaultList(); } if (mEventSummaryUser.isEmpty()) { mEventSummaryUser = getDefaultList() ; } if (mTodoSummaryUser.isEmpty()) { mTodoSummaryUser = getDefaultList() ; } if (mCustomCategories.isEmpty()) setCategoryDefaults(); config()->setGroup("Personal Settings"); mName = config()->readEntry("user_name",""); mEmail = config()->readEntry("user_email",""); fillMailDefaults(); config()->setGroup("Category Colors"); QStringList::Iterator it; for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { setCategoryColor(*it,config()->readColorEntry(*it,&mDefaultCategoryColor)); } KConfig fc (locateLocal("config","kopicalendarrc")); fc.setGroup("CC"); int numCals = fc.readNumEntry("NumberCalendars",0 ); mNextAvailableCalendar = 1; if ( numCals == 0 ) { KopiCalendarFile *kkf = getNewCalendar(); kkf->isStandard = true; kkf->mName = i18n("Standard"); kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" ); } while ( mNextAvailableCalendar <= numCals ) { //qDebug("Read cal #%d ", mNextAvailableCalendar ); QString prefix = "Cal_" +QString::number( mNextAvailableCalendar ); KopiCalendarFile *kkf = getNewCalendar(); kkf->isStandard = fc.readBoolEntry( prefix+"_isStandard", false ); kkf->isEnabled = fc.readBoolEntry( prefix+"_isEnabled", true); kkf->isAlarmEnabled = fc.readBoolEntry( prefix+"_isAlarmEnabled", true); kkf->isReadOnly = fc.readBoolEntry( prefix+"_isReadOnly", false); kkf->mName = fc.readEntry( prefix+"_Name", "Calendar"); kkf->mFileName = fc.readEntry( prefix+"_FileName", kkf->mFileName); kkf->mDefaultColor = fc.readColorEntry( prefix+"_Color",&mEventColor); if ( kkf->mCalNumber == 1 ) { kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" ); } } KPimPrefs::usrReadConfig(); } KopiCalendarFile * KOPrefs::getCalendar( int num ) { return mDefCalColors[num-1]; } KopiCalendarFile * KOPrefs::getNewCalendar() { KopiCalendarFile * kkf = new KopiCalendarFile(); kkf->mCalNumber = mNextAvailableCalendar; mDefCalColors.resize( mNextAvailableCalendar ); mDefCalColors[mNextAvailableCalendar-1] = kkf; ++mNextAvailableCalendar; kkf->mDefaultColor = mEventColor; kkf->mName = i18n("New Calendar"); mCalendars.append( kkf ); return kkf; } void KOPrefs::deleteCalendar( int num ) { KopiCalendarFile * kkf = mCalendars.first(); while ( kkf ) { if ( kkf->mCalNumber == num ) { qDebug("KOPrefs::deleteCalendar %d ", num ); mCalendars.remove( kkf ); delete kkf; return; } kkf = mCalendars.next(); } } +QString KOPrefs::calName( int calNum) const +{ + return (mDefCalColors[calNum-1])->mName; +} QColor KOPrefs::defaultColor( int calNum ) const { if ( calNum == 1 ) return mEventColor; return (mDefCalColors[calNum-1])->mDefaultColor; } void KOPrefs::usrWriteConfig() { config()->setGroup("General"); config()->writeEntry("Custom Categories",mCustomCategories); config()->setGroup("Personal Settings"); config()->writeEntry("user_name",mName); config()->writeEntry("user_email",mEmail); config()->setGroup("Category Colors"); QDictIterator<QColor> it(mCategoryColors); while (it.current()) { config()->writeEntry(it.currentKey(),*(it.current())); ++it; } KConfig fc (locateLocal("config","kopicalendarrc")); fc.setGroup("CC"); fc.writeEntry("NumberCalendars",mCalendars.count()); int numCal = 1; int writeCal = 0; while ( numCal < mNextAvailableCalendar ) { KopiCalendarFile * kkf = mCalendars.first(); while ( kkf ) { //qDebug("cal num %d %d ", kkf->mCalNumber, numCal); if ( kkf->mCalNumber == numCal ) { ++writeCal; //qDebug("Write calendar %d %d ", numCal , writeCal); QString prefix = "Cal_" + QString::number( writeCal ); fc.writeEntry( prefix+"_isStandard", kkf->isStandard ); fc.writeEntry( prefix+"_isEnabled", kkf->isEnabled ); fc.writeEntry( prefix+"_isAlarmEnabled", kkf->isAlarmEnabled ); fc.writeEntry( prefix+"_isReadOnly", kkf->isReadOnly ); fc.writeEntry( prefix+"_Name", kkf->mName); fc.writeEntry( prefix+"_FileName", kkf->mFileName); fc.writeEntry( prefix+"_Color",kkf->mDefaultColor); } kkf = mCalendars.next(); } ++numCal; } fc.sync(); KPimPrefs::usrWriteConfig(); } void KOPrefs::setCategoryColor(QString cat,const QColor & color) { mCategoryColors.replace(cat,new QColor(color)); } QColor *KOPrefs::categoryColor(QString cat) { QColor *color = 0; if (!cat.isEmpty()) color = mCategoryColors[cat]; if (color) return color; else return &mDefaultCategoryColor; } void KOPrefs::setFullName(const QString &name) { mName = name; } void KOPrefs::setEmail(const QString &email) { //qDebug(" KOPrefs::setEmai*********** %s",email.latin1() ); mEmail = email; } QString KOPrefs::fullName() { if (mEmailControlCenter) { KEMailSettings settings; return settings.getSetting(KEMailSettings::RealName); } else { return mName; } } QString KOPrefs::email() { if (mEmailControlCenter) { KEMailSettings settings; return settings.getSetting(KEMailSettings::EmailAddress); } else { return mEmail; } } KConfig* KOPrefs::getConfig() { return config(); } diff --git a/korganizer/koprefs.h b/korganizer/koprefs.h index 463fc33..5cc9bfa 100644 --- a/korganizer/koprefs.h +++ b/korganizer/koprefs.h @@ -1,293 +1,294 @@ /* This file is part of KOrganizer. Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KOPREFS_H #define KOPREFS_H #include <libkdepim/kpimprefs.h> #include <qdict.h> #include <qdir.h> #include <qobject.h> class KConfig; class QFont; class QColor; class QStringList; #define VIEW_WN_VIEW 1 #define VIEW_NX_VIEW 2 #define VIEW_J_VIEW 3 #define VIEW_A_VIEW 4 #define VIEW_ML_VIEW 5 #define VIEW_M_VIEW 6 #define VIEW_L_VIEW 7 #define VIEW_T_VIEW 8 class KopiCalendarFile : public QObject { public: KopiCalendarFile( ) : QObject( ) { isStandard = false; isEnabled = true; isAlarmEnabled = true; isReadOnly = false; mName = "Calendar"; mFileName = QDir::homeDirPath() + "/icalfile.ics"; mCalNumber = 0; mDefaultColor = Qt::red; mErrorOnLoad = false; } bool isStandard; bool isEnabled; bool isAlarmEnabled; bool isReadOnly; bool mErrorOnLoad; QString mName; QString mFileName; int mCalNumber; QColor mDefaultColor; QDateTime mLoadDt; }; class KOPrefs : public KPimPrefs { public: enum { FormatVCalendar, FormatICalendar }; enum { MailClientKMail, MailClientSendmail }; enum { IMIPDummy, IMIPKMail }; enum { IMIPOutbox, IMIPdirectsend }; enum { neverAuto, addressbookAuto, selectedAuto }; enum { standardDestination, askDestination }; virtual ~KOPrefs(); /** Get instance of KOPrefs. It is made sure that there is only one instance. */ static KOPrefs *instance(); /** Set preferences to default values */ void usrSetDefaults(); /** Read preferences from config file */ void usrReadConfig(); /** Write preferences to config file */ void usrWriteConfig(); void setCategoryDefaults(); void setAllDefaults(); KopiCalendarFile * getNewCalendar(); KopiCalendarFile * getCalendar( int ); void deleteCalendar( int ); QColor defaultColor( int ) const; + QString calName( int ) const; protected: void setTimeZoneIdDefault(); /** Fill empty mail fields with default values. */ void fillMailDefaults(); private: /** Constructor disabled for public. Use instance() to create a KOPrefs object. */ KOPrefs(); static KOPrefs *mInstance; QStringList getDefaultList(); QStringList getLocationDefaultList(); public: // preferences data KConfig* getConfig(); void setFullName(const QString &); QString fullName(); void setEmail(const QString &); QString email(); QString mAdditional; bool mEmailControlCenter; bool mBcc; bool mAutoSave; int mAutoSaveInterval; bool mConfirm; bool mEnableGroupScheduling; bool mEnableProjectView; int mDefaultFormat; int mMailClient; int mStartTime; int mDefaultDuration; int mAlarmTime; int mWorkingHoursStart; int mWorkingHoursEnd; bool mExcludeHolidays; bool mExcludeSaturdays; bool mMarcusBainsShowSeconds; QFont mTimeBarFont; QFont mMonthViewFont; QFont mAgendaViewFont; QFont mMarcusBainsFont; QFont mTimeLabelsFont; QFont mTodoViewFont; QFont mListViewFont; QFont mDateNavigatorFont; QFont mEditBoxFont; QFont mJornalViewFont; QFont mWhatsNextFont; QFont mEventViewFont; QColor mHolidayColor; QColor mHighlightColor; QColor mEventColor; QColor mTodoDoneColor; QColor mAgendaBgColor; QColor mWorkingHoursColor; QColor mTodoDueTodayColor; QColor mTodoOverdueColor; QColor mTodoRunColor; QColor mMonthViewEvenColor; QColor mMonthViewOddColor; QColor mMonthViewHolidayColor; bool mMonthViewUsesDayColors; bool mMonthViewSatSunTog; bool mMonthViewWeek; QColor mAppColor1; QColor mAppColor2; bool mUseAppColors; int mDayBegins; int mHourSize; int mAllDaySize; bool mShowFullMenu; bool mDailyRecur; bool mWeeklyRecur; bool mMonthDailyRecur; bool mMonthWeeklyRecur; bool mMonthShowIcons; bool mMonthShowTimes; bool mMonthShowShort; bool mEnableToolTips; bool mEnableMonthScroll; bool mFullViewMonth; bool mMonthViewUsesCategoryColor; bool mFullViewTodo; bool mShowCompletedTodo; bool mMarcusBainsEnabled; int mNextXDays; int mWhatsNextDays; int mWhatsNextPrios; bool mEnableQuickTodo; bool mCompactDialogs; bool mVerticalScreen; bool mShowIconNewTodo; bool mShowIconNewEvent; bool mShowIconSearch; bool mShowIconList; bool mShowIconDay1; bool mShowIconDay5; bool mShowIconDay6; bool mShowIconDay7; bool mShowIconMonth; bool mShowIconTodoview; bool mShowIconBackFast; bool mShowIconBack; bool mShowIconToday; bool mShowIconForward; bool mShowIconForwardFast; bool mShowIconWhatsThis; bool mShowIconWeekNum; bool mShowIconNextDays; bool mShowIconNext; bool mShowIconJournal; bool mShowIconFilter; bool mShowIconOnetoolbar; bool mShowIconNavigator; bool mShowIconAllday; bool mShowIconFilterview; bool mShowIconToggleFull; bool mShowIconStretch; bool mToolBarHor; bool mToolBarUp; bool mToolBarHorV; bool mToolBarUpV; bool mToolBarHorN; bool mToolBarUpN; bool mToolBarHorF; bool mToolBarUpF; bool mToolBarMiniIcons; bool mAskForQuit; bool mUsePassWd; bool mShowSyncEvents; bool mShowTodoInAgenda; bool mShowCompletedTodoInAgenda; bool mShowTimeInAgenda; bool mHideNonStartedTodos; bool mBlockPopupMenu; int mLastSyncTime; void setCategoryColor(QString cat,const QColor & color); QColor *categoryColor(QString cat); QString mArchiveFile; QString mHtmlExportFile; bool mHtmlWithSave; QStringList mSelectedPlugins; QString mLastImportFile; QString mLastVcalFile; QString mLastSaveFile; QString mLastLoadFile; QString mDefaultAlarmFile; int mIMIPScheduler; int mIMIPSend; QStringList mAdditionalMails; int mIMIPAutoRefresh; int mIMIPAutoInsertReply; int mIMIPAutoInsertRequest; int mIMIPAutoFreeBusy; int mIMIPAutoFreeBusyReply; QStringList mTodoTemplates; QStringList mEventTemplates; int mDestination; bool mEditOnDoubleClick; bool mViewChangeHoldFullscreen; bool mViewChangeHoldNonFullscreen; diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 2243e28..3b7b183 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -1,270 +1,271 @@ /* This file is part of libkcal. Copyright (c) 1998 Preston Brown Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef CALENDAR_H #define CALENDAR_H #include <qobject.h> #include <qstring.h> #include <qdatetime.h> #include <qptrlist.h> #include <qdict.h> #include "customproperties.h" #include "event.h" #include "todo.h" #include "journal.h" #include "calfilter.h" //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ class KConfig; namespace KCal { /** This is the main "calendar" object class for KOrganizer. It holds information like all appointments/events, user information, etc. etc. one calendar is associated with each CalendarView (@see calendarview.h). This is an abstract base class defining the interface to a calendar. It is implemented by subclasses like @see CalendarLocal, which use different methods to store and access the data. Ownership of events etc. is handled by the following policy: As soon as an event (or any other subclass of IncidenceBase) object is added to the Calendar by addEvent() it is owned by the Calendar object. The Calendar takes care of deleting it. All Events returned by the query functions are returned as pointers, that means all changes to the returned events are immediately visible in the Calendar. You shouldn't delete any Event object you get from Calendar. */ class Calendar : public QObject, public CustomProperties, public IncidenceBase::Observer { Q_OBJECT public: Calendar(); Calendar(const QString &timeZoneId); virtual ~Calendar(); Incidence * undoIncidence() { return mUndoIncidence; }; bool undoDeleteIncidence(); void deleteIncidence(Incidence *in); void resetTempSyncStat(); void resetPilotStat(int id); /** Clears out the current calendar, freeing all used memory etc. */ virtual void close() = 0; virtual void addCalendar( Calendar* ) = 0; virtual bool addCalendarFile( QString name, int id ) = 0; + virtual void setSyncEventsReadOnly() = 0; /** Sync changes in memory to persistant storage. */ virtual void save() = 0; virtual QPtrList<Event> getExternLastSyncEvents() = 0; virtual void removeSyncInfo( QString syncProfile) = 0; virtual bool isSaving() { return false; } /** Return the owner of the calendar's full name. */ const QString &getOwner() const; /** Set the owner of the calendar. Should be owner's full name. */ void setOwner( const QString &os ); /** Return the email address of the calendar owner. */ const QString &getEmail(); /** Set the email address of the calendar owner. */ void setEmail( const QString & ); /** Set time zone from a timezone string (e.g. -2:00) */ void setTimeZone( const QString &tz ); /** Set time zone from a minutes value (e.g. -60) */ void setTimeZone( int tz ); /** Return time zone as offest in minutes. */ int getTimeZone() const; /** Compute an ISO 8601 format string from the time zone. */ QString getTimeZoneStr() const; /** Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal values). */ void setTimeZoneId( const QString & ); /** Return time zone id. */ QString timeZoneId() const; /** Use local time, not UTC or a time zone. */ void setLocalTime(); /** Return whether local time is being used. */ bool isLocalTime() const; /** Add an incidence to calendar. @return true on success, false on error. */ virtual bool addIncidence( Incidence * ); // Adds an incidence and all relatedto incidences to the cal void addIncidenceBranch( Incidence * ); /** Return filtered list of all incidences of this calendar. */ virtual QPtrList<Incidence> incidences(); /** Return unfiltered list of all incidences of this calendar. */ virtual QPtrList<Incidence> rawIncidences(); /** Adds a Event to this calendar object. @param anEvent a pointer to the event to add @return true on success, false on error. */ virtual bool addEventNoDup( Event *event ) = 0; virtual bool addAnniversaryNoDup( Event *event ) = 0; virtual bool addEvent( Event *anEvent ) = 0; /** Delete event from calendar. */ virtual void deleteEvent( Event * ) = 0; /** Retrieves an event on the basis of the unique string ID. */ virtual Event *event( const QString &UniqueStr ) = 0; virtual Event *event( QString, QString ) = 0; /** Builds and then returns a list of all events that match for the date specified. useful for dayView, etc. etc. The calendar filter is applied. */ QPtrList<Event> events( const QDate &date, bool sorted = false); /** Get events, which occur on the given date. The calendar filter is applied. */ QPtrList<Event> events( const QDateTime &qdt ); /** Get events in a range of dates. If inclusive is set to true, only events are returned, which are completely included in the range. The calendar filter is applied. */ QPtrList<Event> events( const QDate &start, const QDate &end, bool inclusive = false); /** Return filtered list of all events in calendar. */ virtual QPtrList<Event> events(); /** Return unfiltered list of all events in calendar. */ virtual QPtrList<Event> rawEvents() = 0; /** Add a todo to the todolist. @return true on success, false on error. */ virtual bool addTodo( Todo *todo ) = 0; virtual bool addTodoNoDup( Todo *todo ) = 0; /** Remove a todo from the todolist. */ virtual void deleteTodo( Todo * ) = 0; virtual void deleteJournal( Journal * ) = 0; /** Return filterd list of todos. */ virtual QPtrList<Todo> todos(); /** Searches todolist for an event with this unique string identifier, returns a pointer or null. */ virtual Todo *todo( const QString &uid ) = 0; virtual Todo *todo( QString, QString ) = 0; /** Returns list of todos due on the specified date. */ virtual QPtrList<Todo> todos( const QDate &date ) = 0; /** Return unfiltered list of todos. */ virtual QPtrList<Todo> rawTodos() = 0; /** Add a Journal entry to calendar. @return true on success, false on error. */ virtual bool addJournal( Journal * ) = 0; /** Return Journal for given date. */ virtual Journal *journal( const QDate & ) = 0; /** Return Journal with given UID. */ virtual Journal *journal( const QString &UID ) = 0; /** Return list of all Journal entries. */ virtual QPtrList<Journal> journals() = 0; /** Searches all incidence types for an incidence with this unique string identifier, returns a pointer or null. */ Incidence* incidence( const QString&UID ); /** Setup relations for an incidence. */ virtual void setupRelations( Incidence * ); /** Remove all relations to an incidence */ virtual void removeRelations( Incidence * ); /** Set calendar filter, which filters events for the events() functions. The Filter object is owned by the caller. diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 336c3e8..8c4dde1 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -1,272 +1,282 @@ /* This file is part of libkcal. Copyright (c) 1998 Preston Brown Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qdatetime.h> #include <qstring.h> #include <qptrlist.h> #include <kdebug.h> #include <kconfig.h> #include <kglobal.h> #include <klocale.h> #include "vcaldrag.h" #include "vcalformat.h" #include "icalformat.h" #include "exceptions.h" #include "incidence.h" #include "journal.h" #include "filestorage.h" #include "calfilter.h" #include "calendarlocal.h" // #ifndef DESKTOP_VERSION // #include <qtopia/alarmserver.h> // #endif using namespace KCal; CalendarLocal::CalendarLocal() : Calendar() { init(); } CalendarLocal::CalendarLocal(const QString &timeZoneId) : Calendar(timeZoneId) { init(); } void CalendarLocal::init() { mNextAlarmIncidence = 0; } CalendarLocal::~CalendarLocal() { if ( mDeleteIncidencesOnClose ) close(); } bool CalendarLocal::addCalendarFile( QString name, int id ) { CalendarLocal calendar( timeZoneId() ); calendar.setDefaultCalendar( id ); if ( calendar.load( name ) ) { addCalendar( &calendar ); return true; } return false; } +void CalendarLocal::setSyncEventsReadOnly() +{ + Event * ev; + ev = mEventList.first(); + while ( ev ) { + if ( ev->uid().left(15) == QString("last-syncEvent-") ) + ev->setReadOnly( true ); + ev = mEventList.next(); + } +} void CalendarLocal::addCalendar( Calendar* cal ) { cal->setDontDeleteIncidencesOnClose(); { QPtrList<Event> EventList = cal->rawEvents(); Event * ev = EventList.first(); while ( ev ) { ev->unRegisterObserver( cal ); ev->registerObserver( this ); mEventList.append( ev ); ev = EventList.next(); } } { QPtrList<Todo> TodoList = cal->rawTodos(); Todo * ev = TodoList.first(); while ( ev ) { QString rel = ev->relatedToUid(); if ( !rel.isEmpty() ){ ev->setRelatedTo ( 0 ); ev->setRelatedToUid( rel ); } ev = TodoList.next(); } //TodoList = cal->rawTodos(); ev = TodoList.first(); while ( ev ) { ev->unRegisterObserver( cal ); ev->registerObserver( this ); mTodoList.append( ev ); setupRelations( ev ); ev = TodoList.next(); } } { QPtrList<Journal> JournalList = cal->journals(); Journal * ev = JournalList.first(); while ( ev ) { ev->unRegisterObserver( cal ); ev->registerObserver( this ); mJournalList.append( ev ); ev = JournalList.next(); } } setModified( true ); } bool CalendarLocal::load( const QString &fileName ) { FileStorage storage( this, fileName ); return storage.load(); } bool CalendarLocal::save( const QString &fileName, CalFormat *format ) { FileStorage storage( this, fileName, format ); return storage.save(); } void CalendarLocal::close() { Todo * i; for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); mEventList.setAutoDelete( true ); mTodoList.setAutoDelete( true ); mJournalList.setAutoDelete( false ); mEventList.clear(); mTodoList.clear(); mJournalList.clear(); mEventList.setAutoDelete( false ); mTodoList.setAutoDelete( false ); mJournalList.setAutoDelete( false ); setModified( false ); } bool CalendarLocal::addAnniversaryNoDup( Event *event ) { QString cat; bool isBirthday = true; if( event->categoriesStr() == i18n( "Anniversary" ) ) { isBirthday = false; cat = i18n( "Anniversary" ); } else if( event->categoriesStr() == i18n( "Birthday" ) ) { isBirthday = true; cat = i18n( "Birthday" ); } else { qDebug("addAnniversaryNoDup called without fitting category! "); return false; } Event * eve; for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { if ( !(eve->categories().contains( cat ) )) continue; // now we have an event with fitting category if ( eve->dtStart().date() != event->dtStart().date() ) continue; // now we have an event with fitting category+date if ( eve->summary() != event->summary() ) continue; // now we have an event with fitting category+date+summary return false; } return addEvent( event ); } bool CalendarLocal::addEventNoDup( Event *event ) { Event * eve; for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { if ( *eve == *event ) { //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); return false; } } return addEvent( event ); } bool CalendarLocal::addEvent( Event *event ) { insertEvent( event ); event->registerObserver( this ); setModified( true ); event->setCalID( mDefaultCalendar ); event->setCalEnabled( true ); return true; } void CalendarLocal::deleteEvent( Event *event ) { if ( mUndoIncidence ) delete mUndoIncidence; mUndoIncidence = event->clone(); if ( mEventList.removeRef( event ) ) { setModified( true ); } } Event *CalendarLocal::event( const QString &uid ) { Event *event; Event *retVal = 0; for ( event = mEventList.first(); event; event = mEventList.next() ) { if ( event->calEnabled() && event->uid() == uid ) { if ( retVal ) { if ( retVal->calID() > event->calID() ) { retVal = event; } } else { retVal = event; } } } return retVal; } bool CalendarLocal::addTodoNoDup( Todo *todo ) { Todo * eve; for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { if ( *eve == *todo ) { //qDebug("duplicate todo found! not inserted! "); return false; } } return addTodo( todo ); } bool CalendarLocal::addTodo( Todo *todo ) { mTodoList.append( todo ); todo->registerObserver( this ); // Set up subtask relations setupRelations( todo ); setModified( true ); todo->setCalID( mDefaultCalendar ); todo->setCalEnabled( true ); return true; } void CalendarLocal::deleteTodo( Todo *todo ) { // Handle orphaned children if ( mUndoIncidence ) delete mUndoIncidence; diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 5bbe55f..0286b48 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -1,224 +1,225 @@ /* This file is part of libkcal. Copyright (c) 1998 Preston Brown Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef KCAL_CALENDARLOCAL_H #define KCAL_CALENDARLOCAL_H #include "calendar.h" namespace KCal { class CalFormat; /** This class provides a calendar stored as a local file. */ class CalendarLocal : public Calendar { public: /** Constructs a new calendar, with variables initialized to sane values. */ CalendarLocal(); /** Constructs a new calendar, with variables initialized to sane values. */ CalendarLocal( const QString &timeZoneId ); ~CalendarLocal(); void addCalendar( Calendar* ); bool addCalendarFile( QString name, int id ); + void setSyncEventsReadOnly(); /** Loads a calendar on disk in vCalendar or iCalendar format into the current calendar. Any information already present is lost. @return true, if successfull, false on error. @param fileName the name of the calendar on disk. */ bool load( const QString &fileName ); /** Writes out the calendar to disk in the specified \a format. CalendarLocal takes ownership of the CalFormat object. @return true, if successfull, false on error. @param fileName the name of the file */ bool save( const QString &fileName, CalFormat *format = 0 ); /** Clears out the current calendar, freeing all used memory etc. etc. */ void close(); void save() {} /** Add Event to calendar. */ void removeSyncInfo( QString syncProfile); bool addAnniversaryNoDup( Event *event ); bool addEventNoDup( Event *event ); bool addEvent( Event *event ); /** Deletes an event from this calendar. */ void deleteEvent( Event *event ); /** Retrieves an event on the basis of the unique string ID. */ Event *event( const QString &uid ); /** Return unfiltered list of all events in calendar. */ QPtrList<Event> rawEvents(); QPtrList<Event> getExternLastSyncEvents(); /** Add a todo to the todolist. */ bool addTodo( Todo *todo ); bool addTodoNoDup( Todo *todo ); /** Remove a todo from the todolist. */ void deleteTodo( Todo * ); /** Searches todolist for an event with this unique string identifier, returns a pointer or null. */ Todo *todo( const QString &uid ); /** Return list of all todos. */ QPtrList<Todo> rawTodos(); /** Returns list of todos due on the specified date. */ QPtrList<Todo> todos( const QDate &date ); /** Return list of all todos. Workaround because compiler does not recognize function of base class. */ QPtrList<Todo> todos() { return Calendar::todos(); } /** Add a Journal entry to calendar. */ bool addJournal( Journal * ); /** Remove a Journal from the calendar. */ void deleteJournal( Journal * ); /** Return Journal for given date. */ Journal *journal( const QDate & ); /** Return Journal with given UID. */ Journal *journal( const QString &uid ); /** Return list of all Journals stored in calendar. */ QPtrList<Journal> journals(); /** Return all alarms, which ocur in the given time interval. */ Alarm::List alarms( const QDateTime &from, const QDateTime &to ); /** Return all alarms, which ocur before given date. */ Alarm::List alarmsTo( const QDateTime &to ); QDateTime nextAlarm( int daysTo ) ; QDateTime nextAlarmEventDateTime() const; void checkAlarmForIncidence( Incidence *, bool deleted ) ; void registerAlarm(); void deRegisterAlarm(); QString getAlarmNotification(); QString nextSummary() const ; /** This method should be called whenever a Event is modified directly via it's pointer. It makes sure that the calendar is internally consistent. */ void update( IncidenceBase *incidence ); /** Builds and then returns a list of all events that match for the date specified. useful for dayView, etc. etc. */ QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); /** Get unfiltered events for date \a qdt. */ QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); /** Get unfiltered events in a range of dates. If inclusive is set to true, only events are returned, which are completely included in the range. */ QPtrList<Event> rawEvents( const QDate &start, const QDate &end, bool inclusive = false ); Todo *todo( QString, QString ); Event *event( QString, QString ); public slots: void setCalendarEnabled( int id, bool enable ); void setAlarmEnabled( int id, bool enable ); void setReadOnly( int id, bool enable ); void setDefaultCalendarEnabledOnly(); void setCalendarRemove( int id ); protected: // Event* mNextAlarmEvent; QString mNextSummary; QString mNextAlarmEventDateTimeString; QString mLastAlarmNotificationString; QDateTime mNextAlarmEventDateTime; QDateTime mNextAlarmDateTime; void reInitAlarmSettings(); /** Notification function of IncidenceBase::Observer. */ void incidenceUpdated( IncidenceBase *i ) { update( i ); } /** inserts an event into its "proper place" in the calendar. */ void insertEvent( Event *event ); /** Append alarms of incidence in interval to list of alarms. */ void appendAlarms( Alarm::List &alarms, Incidence *incidence, const QDateTime &from, const QDateTime &to ); /** Append alarms of recurring events in interval to list of alarms. */ void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, const QDateTime &from, const QDateTime &to ); private: void init(); QPtrList<Event> mEventList; QPtrList<Todo> mTodoList; QPtrList<Journal> mJournalList; }; } #endif diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index 2ddbb01..96039df 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp @@ -1,335 +1,337 @@ /* This file is part of libkcal. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <kglobal.h> #include <klocale.h> #include <kdebug.h> #include <kidmanager.h> #include "calformat.h" #include "syncdefines.h" #include "incidencebase.h" using namespace KCal; IncidenceBase::IncidenceBase() : mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), mPilotId(0), mSyncStatus(SYNCMOD) { setUid(CalFormat::createUniqueId()); mOrganizer = ""; mFloats = false; mDuration = 0; mHasDuration = false; mPilotId = 0; mExternalId = ":"; mTempSyncStat = SYNC_TEMPSTATE_INITIAL; mSyncStatus = 0; mAttendees.setAutoDelete( true ); mCalEnabled = true; mAlarmEnabled = true; mCalID = 0; } IncidenceBase::IncidenceBase(const IncidenceBase &i) : CustomProperties( i ) { mReadOnly = i.mReadOnly; mDtStart = i.mDtStart; mDuration = i.mDuration; mHasDuration = i.mHasDuration; mOrganizer = i.mOrganizer; mUid = i.mUid; mCalEnabled = i.mCalEnabled; mAlarmEnabled = i.mAlarmEnabled; mCalID = i.mCalID; QPtrList<Attendee> attendees = i.attendees(); for( Attendee *a = attendees.first(); a; a = attendees.next() ) { mAttendees.append( new Attendee( *a ) ); } mFloats = i.mFloats; mLastModified = i.mLastModified; mPilotId = i.mPilotId; mTempSyncStat = i.mTempSyncStat; mSyncStatus = i.mSyncStatus; mExternalId = i.mExternalId; // The copied object is a new one, so it isn't observed by the observer // of the original object. mObservers.clear(); mAttendees.setAutoDelete( true ); } IncidenceBase::~IncidenceBase() { } bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) { // do not compare mSyncStatus and mExternalId if( i1.attendees().count() != i2.attendees().count() ) { return false; // no need to check further } if ( i1.attendees().count() > 0 ) { Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; while ( a1 ) { if ( !( (*a1) == (*a2)) ) { //qDebug("Attendee not equal "); return false; } a1 = i1.attendees().next(); a2 = i2.attendees().next(); } } //if ( i1.dtStart() != i2.dtStart() ) // return false; #if 0 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); qDebug("1 %d ",i1.duration() == i2.duration() ); qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); qDebug("6 %d ",i1.organizer() == i2.organizer() ); #endif if ( i1.hasDuration() == i2.hasDuration() ) { if ( i1.hasDuration() ) { if ( i1.duration() != i2.duration() ) return false; } } else { return false; } return ( i1.organizer() == i2.organizer() && // i1.uid() == i2.uid() && // Don't compare lastModified, otherwise the operator is not // of much use. We are not comparing for identity, after all. i1.doesFloat() == i2.doesFloat() && i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); // no need to compare mObserver } QDateTime IncidenceBase::getEvenTime( QDateTime dt ) { QTime t = dt.time(); dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); return dt; } void IncidenceBase::setCalID( int id ) { + if ( mCalID > 0 ) + updated(); mCalID = id; } int IncidenceBase::calID() const { return mCalID; } void IncidenceBase::setCalEnabled( bool b ) { mCalEnabled = b; } bool IncidenceBase::calEnabled() const { return mCalEnabled; } void IncidenceBase::setAlarmEnabled( bool b ) { mAlarmEnabled = b; } bool IncidenceBase::alarmEnabled() const { return mAlarmEnabled; } void IncidenceBase::setUid(const QString &uid) { mUid = uid; updated(); } QString IncidenceBase::uid() const { return mUid; } void IncidenceBase::setLastModified(const QDateTime &lm) { // DON'T! updated() because we call this from // Calendar::updateEvent(). mLastModified = getEvenTime(lm); //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); } QDateTime IncidenceBase::lastModified() const { return mLastModified; } void IncidenceBase::setOrganizer(const QString &o) { // we don't check for readonly here, because it is // possible that by setting the organizer we are changing // the event's readonly status... mOrganizer = o; if (mOrganizer.left(7).upper() == "MAILTO:") mOrganizer = mOrganizer.remove(0,7); updated(); } QString IncidenceBase::organizer() const { return mOrganizer; } void IncidenceBase::setReadOnly( bool readOnly ) { mReadOnly = readOnly; } void IncidenceBase::setDtStart(const QDateTime &dtStart) { // if (mReadOnly) return; mDtStart = getEvenTime(dtStart); updated(); } QDateTime IncidenceBase::dtStart() const { return mDtStart; } QString IncidenceBase::dtStartTimeStr() const { return KGlobal::locale()->formatTime(dtStart().time()); } QString IncidenceBase::dtStartDateStr(bool shortfmt) const { return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); } QString IncidenceBase::dtStartStr(bool shortfmt) const { if ( doesFloat() ) return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); } bool IncidenceBase::doesFloat() const { return mFloats; } void IncidenceBase::setFloats(bool f) { if (mReadOnly) return; mFloats = f; updated(); } bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) { if (mReadOnly) return false; if (a->name().left(7).upper() == "MAILTO:") a->setName(a->name().remove(0,7)); QPtrListIterator<Attendee> qli(mAttendees); qli.toFirst(); while (qli) { if (*qli.current() == *a) return false; ++qli; } mAttendees.append(a); if (doupdate) updated(); return true; } #if 0 void IncidenceBase::removeAttendee(Attendee *a) { if (mReadOnly) return; mAttendees.removeRef(a); updated(); } void IncidenceBase::removeAttendee(const char *n) { Attendee *a; if (mReadOnly) return; for (a = mAttendees.first(); a; a = mAttendees.next()) if (a->getName() == n) { mAttendees.remove(); break; } } #endif void IncidenceBase::clearAttendees() { if (mReadOnly) return; mAttendees.clear(); } #if 0 Attendee *IncidenceBase::getAttendee(const char *n) const { QPtrListIterator<Attendee> qli(mAttendees); qli.toFirst(); while (qli) { if (qli.current()->getName() == n) return qli.current(); ++qli; } return 0L; } #endif Attendee *IncidenceBase::attendeeByMail(const QString &email) { QPtrListIterator<Attendee> qli(mAttendees); qli.toFirst(); while (qli) { if (qli.current()->email().lower() == email.lower()) return qli.current(); ++qli; } return 0L; } Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) { QPtrListIterator<Attendee> qli(mAttendees); |