summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-06-10 20:13:31 (UTC)
committer zautrix <zautrix>2005-06-10 20:13:31 (UTC)
commitcdc55afb3d2c3ebd970843b7dce02acb1e6a189b (patch) (side-by-side diff)
tree45f3bfa69a72de4e8b53bbcb2414478ec65cd183
parent31fed261955dcb25d06052a8154ac4cc630b0f7d (diff)
downloadkdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.zip
kdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.tar.gz
kdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.tar.bz2
many preparations for multiple calendars
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendar.cpp14
-rw-r--r--libkcal/calendar.h9
-rw-r--r--libkcal/calendarlocal.cpp78
-rw-r--r--libkcal/calendarlocal.h3
-rw-r--r--libkcal/calfilter.cpp9
-rw-r--r--libkcal/calfilter.h1
-rw-r--r--libkcal/event.cpp4
-rw-r--r--libkcal/incidencebase.cpp33
-rw-r--r--libkcal/incidencebase.h9
-rw-r--r--libkcal/todo.cpp2
10 files changed, 145 insertions, 17 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 7e8e2c5..f4350d9 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -33,49 +33,49 @@
#include "syncdefines.h"
using namespace KCal;
Calendar::Calendar()
{
init();
setTimeZoneId( " 00:00 Europe/London(UTC)" );
}
Calendar::Calendar( const QString &timeZoneId )
{
init();
setTimeZoneId(timeZoneId);
}
void Calendar::init()
{
mObserver = 0;
mNewObserver = false;
mUndoIncidence = 0;
mModified = false;
-
+ mDefaultCalendar = 1;
// Setup default filter, which does nothing
mDefaultFilter = new CalFilter;
mFilter = mDefaultFilter;
mFilter->setEnabled(false);
// initialize random numbers. This is a hack, and not
// even that good of one at that.
// srandom(time(0));
// user information...
setOwner(i18n("Unknown Name"));
setEmail(i18n("unknown@nowhere"));
#if 0
tmpStr = KOPrefs::instance()->mTimeZone;
// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
int dstSetting = KOPrefs::instance()->mDaylightSavings;
extern long int timezone;
struct tm *now;
time_t curtime;
curtime = time(0);
now = localtime(&curtime);
int hourOff = - ((timezone / 60) / 60);
if (now->tm_isdst)
@@ -91,49 +91,56 @@ void Calendar::init()
} else {
tzStr = tmpStr;
}
// if daylight savings has changed since last load time, we need
// to rewrite these settings to the config file.
if ((now->tm_isdst && !dstSetting) ||
(!now->tm_isdst && dstSetting)) {
KOPrefs::instance()->mTimeZone = tzStr;
KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
}
setTimeZone(tzStr);
#endif
// KOPrefs::instance()->writeConfig();
}
Calendar::~Calendar()
{
delete mDefaultFilter;
if ( mUndoIncidence )
delete mUndoIncidence;
}
-
+void Calendar::setDefaultCalendar( int d )
+{
+ mDefaultCalendar = d;
+}
+int Calendar::defaultCalendar()
+{
+ return mDefaultCalendar;
+}
const QString &Calendar::getOwner() const
{
return mOwner;
}
bool Calendar::undoDeleteIncidence()
{
if (!mUndoIncidence)
return false;
addIncidence(mUndoIncidence);
mUndoIncidence = 0;
return true;
}
void Calendar::setOwner(const QString &os)
{
int i;
mOwner = os;
i = mOwner.find(',');
if (i != -1)
mOwner = mOwner.left(i);
setModified( true );
}
@@ -327,49 +334,50 @@ QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
QPtrList<Event> el = rawEvents(start,end,inclusive);
mFilter->apply(&el);
return el;
}
QPtrList<Event> Calendar::events()
{
QPtrList<Event> el = rawEvents();
mFilter->apply(&el);
return el;
}
void Calendar::addIncidenceBranch(Incidence *i)
{
addIncidence( i );
Incidence * inc;
QPtrList<Incidence> Relations = i->relations();
for (inc=Relations.first();inc;inc=Relations.next()) {
addIncidenceBranch( inc );
}
}
bool Calendar::addIncidence(Incidence *i)
{
Incidence::AddVisitor<Calendar> v(this);
-
+ i->setCalID( mDefaultCalendar );
+ i->setCalEnabled( true );
return i->accept(v);
}
void Calendar::deleteIncidence(Incidence *in)
{
if ( in->typeID() == eventID )
deleteEvent( (Event*) in );
else if ( in->typeID() == todoID )
deleteTodo( (Todo*) in);
else if ( in->typeID() == journalID )
deleteJournal( (Journal*) in );
}
Incidence* Calendar::incidence( const QString& uid )
{
Incidence* i;
if( (i = todo( uid )) != 0 )
return i;
if( (i = event( uid )) != 0 )
return i;
if( (i = journal( uid )) != 0 )
return i;
return 0;
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index ab40970..4c6760f 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -281,79 +281,86 @@ public:
Return all alarms, which ocur in the given time interval.
*/
virtual Alarm::List alarms( const QDateTime &from,
const QDateTime &to ) = 0;
class Observer {
public:
virtual void calendarModified( bool, Calendar * ) = 0;
};
void registerObserver( Observer * );
void setModified( bool );
/**
Set product id returned by loadedProductId(). This function is only
useful for the calendar loading code.
*/
void setLoadedProductId( const QString & );
/**
Return product id taken from file that has been loaded. Returns
QString::null, if no calendar has been loaded.
*/
QString loadedProductId();
-
+ void setDefaultCalendar( int );
+ int defaultCalendar();
+ virtual void setCalendarEnabled( int id, bool enable ) = 0;
+ virtual void setAlarmEnabled( int id, bool enable ) = 0;
+ virtual void setDefaultCalendarEnabledOnly() = 0;
signals:
void calendarChanged();
void calendarSaved();
void calendarLoaded();
void addAlarm(const QDateTime &qdt, const QString &noti );
void removeAlarm(const QDateTime &qdt, const QString &noti );
protected:
/**
Get unfiltered events, which occur on the given date.
*/
virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
/**
Get unfiltered events, which occur on the given date.
*/
virtual QPtrList<Event> rawEventsForDate( const QDate &date,
bool sorted = false ) = 0;
/**
Get events in a range of dates. If inclusive is set to true, only events
are returned, which are completely included in the range.
*/
virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
bool inclusive = false ) = 0;
+
Incidence *mNextAlarmIncidence;
Incidence *mUndoIncidence;
+ int mDefaultCalendar;
private:
void init();
QString mOwner; // who the calendar belongs to
QString mOwnerEmail; // email address of the owner
int mTimeZone; // timezone OFFSET from GMT (MINUTES)
bool mLocalTime; // use local time, not UTC or a time zone
CalFilter *mFilter;
CalFilter *mDefaultFilter;
+
QString mTimeZoneId;
Observer *mObserver;
bool mNewObserver;
bool mModified;
QString mLoadedProductId;
// This list is used to put together related todos
QDict<Incidence> mOrphans;
QDict<Incidence> mOrphanUids;
};
}
#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index fe74052..c5500bf 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -129,175 +129,181 @@ bool CalendarLocal::addAnniversaryNoDup( Event *event )
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;
for ( event = mEventList.first(); event; event = mEventList.next() ) {
- if ( event->uid() == uid ) {
+ if ( event->uid() == uid && event->calEnabled() ) {
return event;
}
}
return 0;
}
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;
removeRelations( todo );
mUndoIncidence = todo->clone();
if ( mTodoList.removeRef( todo ) ) {
setModified( true );
}
}
QPtrList<Todo> CalendarLocal::rawTodos()
{
- return mTodoList;
+ QPtrList<Todo> el;
+ for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
+ if ( it->calEnabled() ) el.append( it );
+ return el;
}
Todo *CalendarLocal::todo( QString syncProf, QString id )
{
Todo *todo;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
- if ( todo->getID( syncProf ) == id ) return todo;
+ if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
}
return 0;
}
void CalendarLocal::removeSyncInfo( QString syncProfile)
{
QPtrList<Incidence> all = rawIncidences() ;
Incidence *inc;
for ( inc = all.first(); inc; inc = all.next() ) {
inc->removeID( syncProfile );
}
if ( syncProfile.isEmpty() ) {
QPtrList<Event> el;
Event *todo;
for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
el.append( todo );
}
for ( todo = el.first(); todo; todo = el.next() ) {
deleteIncidence ( todo );
}
} else {
Event *lse = event( "last-syncEvent-"+ syncProfile);
if ( lse )
deleteIncidence ( lse );
}
}
QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
{
QPtrList<Event> el;
Event *todo;
for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
if ( todo->summary().left(3) == "E: " )
el.append( todo );
}
return el;
}
Event *CalendarLocal::event( QString syncProf, QString id )
{
Event *todo;
for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
- if ( todo->getID( syncProf ) == id ) return todo;
+ if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
}
return 0;
}
Todo *CalendarLocal::todo( const QString &uid )
{
Todo *todo;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
- if ( todo->uid() == uid ) return todo;
+ if ( todo->calEnabled() && todo->uid() == uid ) return todo;
}
return 0;
}
QString CalendarLocal::nextSummary() const
{
return mNextSummary;
}
QDateTime CalendarLocal::nextAlarmEventDateTime() const
{
return mNextAlarmEventDateTime;
}
void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
{
//mNextAlarmIncidence
//mNextAlarmDateTime
//return mNextSummary;
//return mNextAlarmEventDateTime;
bool newNextAlarm = false;
bool computeNextAlarm = false;
bool ok;
int offset;
QDateTime nextA;
// QString nextSum;
@@ -368,129 +374,134 @@ void CalendarLocal::registerAlarm()
emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
// #ifndef DESKTOP_VERSION
// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
// #endif
}
void CalendarLocal::deRegisterAlarm()
{
if ( mLastAlarmNotificationString.isNull() )
return;
//qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
mNextAlarmEventDateTime = QDateTime();
// #ifndef DESKTOP_VERSION
// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
// #endif
}
QPtrList<Todo> CalendarLocal::todos( const QDate &date )
{
QPtrList<Todo> todos;
Todo *todo;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
+ if ( !todo->calEnabled() ) continue;
if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
todos.append( todo );
}
}
filter()->apply( &todos );
return todos;
}
void CalendarLocal::reInitAlarmSettings()
{
if ( !mNextAlarmIncidence ) {
nextAlarm( 1000 );
}
deRegisterAlarm();
mNextAlarmIncidence = 0;
checkAlarmForIncidence( 0, false );
}
QDateTime CalendarLocal::nextAlarm( int daysTo )
{
QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
QDateTime next;
Event *e;
bool ok;
bool found = false;
int offset;
mNextAlarmIncidence = 0;
for( e = mEventList.first(); e; e = mEventList.next() ) {
+ if ( !e->calEnabled() ) continue;
next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
if ( ok ) {
if ( next < nextA ) {
nextA = next;
found = true;
mNextSummary = e->summary();
mNextAlarmEventDateTime = next.addSecs(offset ) ;
mNextAlarmIncidence = (Incidence *) e;
}
}
}
Todo *t;
for( t = mTodoList.first(); t; t = mTodoList.next() ) {
+ if ( !t->calEnabled() ) continue;
next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
if ( ok ) {
if ( next < nextA ) {
nextA = next;
found = true;
mNextSummary = t->summary();
mNextAlarmEventDateTime = next.addSecs(offset );
mNextAlarmIncidence = (Incidence *) t;
}
}
}
if ( mNextAlarmIncidence ) {
mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
mNextAlarmDateTime = nextA;
}
return nextA;
}
Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
{
return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
}
Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
{
Alarm::List alarms;
Event *e;
for( e = mEventList.first(); e; e = mEventList.next() ) {
+ if ( !e->calEnabled() ) continue;
if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
else appendAlarms( alarms, e, from, to );
}
Todo *t;
for( t = mTodoList.first(); t; t = mTodoList.next() ) {
+ if ( !t->calEnabled() ) continue;
appendAlarms( alarms, t, from, to );
}
return alarms;
}
void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
const QDateTime &from, const QDateTime &to )
{
QPtrList<Alarm> alarmList = incidence->alarms();
Alarm *alarm;
for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
if ( alarm->enabled() ) {
if ( alarm->time() >= from && alarm->time() <= to ) {
alarms.append( alarm );
}
}
}
}
void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
Incidence *incidence,
@@ -522,48 +533,49 @@ void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
// after changes are made to an event, this should be called.
void CalendarLocal::update( IncidenceBase *incidence )
{
incidence->setSyncStatus( Event::SYNCMOD );
incidence->setLastModified( QDateTime::currentDateTime() );
// we should probably update the revision number here,
// or internally in the Event itself when certain things change.
// need to verify with ical documentation.
setModified( true );
}
void CalendarLocal::insertEvent( Event *event )
{
if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
}
QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
{
QPtrList<Event> eventList;
Event *event;
for( event = mEventList.first(); event; event = mEventList.next() ) {
+ if ( !event->calEnabled() ) continue;
if ( event->doesRecur() ) {
if ( event->isMultiDay() ) {
int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
int i;
for ( i = 0; i <= extraDays; i++ ) {
if ( event->recursOn( qd.addDays( -i ) ) ) {
eventList.append( event );
break;
}
}
} else {
if ( event->recursOn( qd ) )
eventList.append( event );
}
} else {
if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
eventList.append( event );
}
}
}
if ( !sorted ) {
return eventList;
}
@@ -574,48 +586,49 @@ QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
Event *sortEvent;
for ( event = eventList.first(); event; event = eventList.next() ) {
sortEvent = eventListSorted.first();
int i = 0;
while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
{
i++;
sortEvent = eventListSorted.next();
}
eventListSorted.insert( i, event );
}
return eventListSorted;
}
QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
bool inclusive )
{
Event *event = 0;
QPtrList<Event> eventList;
// Get non-recurring events
for( event = mEventList.first(); event; event = mEventList.next() ) {
+ if ( !event->calEnabled() ) continue;
if ( event->doesRecur() ) {
QDate rStart = event->dtStart().date();
bool found = false;
if ( inclusive ) {
if ( rStart >= start && rStart <= end ) {
// Start date of event is in range. Now check for end date.
// if duration is negative, event recurs forever, so do not include it.
if ( event->recurrence()->duration() == 0 ) { // End date set
QDate rEnd = event->recurrence()->endDate();
if ( rEnd >= start && rEnd <= end ) { // End date within range
found = true;
}
} else if ( event->recurrence()->duration() > 0 ) { // Duration set
// TODO: Calculate end date from duration. Should be done in Event
// For now exclude all events with a duration.
}
}
} else {
bool founOne;
QDate next = event->getNextOccurence( start, &founOne ).date();
if ( founOne ) {
if ( next <= end ) {
found = true;
}
@@ -649,78 +662,121 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
QDate e = event->dtEnd().date();
if ( inclusive ) {
if ( s >= start && e <= end ) {
eventList.append( event );
}
} else {
if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) {
eventList.append( event );
}
}
}
}
return eventList;
}
QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
{
return rawEventsForDate( qdt.date() );
}
QPtrList<Event> CalendarLocal::rawEvents()
{
- return mEventList;
+ QPtrList<Event> el;
+ for ( Event *it = mEventList.first(); it; it = mEventList.next() )
+ if ( it->calEnabled() ) el.append( it );
+ return el;
}
bool CalendarLocal::addJournal(Journal *journal)
{
if ( journal->dtStart().isValid())
kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl;
else
kdDebug(5800) << "Adding Journal without a DTSTART" << endl;
mJournalList.append(journal);
journal->registerObserver( this );
setModified( true );
-
+ journal->setCalID( mDefaultCalendar );
+ journal->setCalEnabled( true );
return true;
}
void CalendarLocal::deleteJournal( Journal *journal )
{
if ( mUndoIncidence ) delete mUndoIncidence;
mUndoIncidence = journal->clone();
mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
if ( mJournalList.removeRef(journal) ) {
setModified( true );
}
}
Journal *CalendarLocal::journal( const QDate &date )
{
// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
- if ( it->dtStart().date() == date )
+ if ( it->calEnabled() && it->dtStart().date() == date )
return it;
return 0;
}
Journal *CalendarLocal::journal( const QString &uid )
{
for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
- if ( it->uid() == uid )
+ if ( it->calEnabled() && it->uid() == uid )
return it;
return 0;
}
QPtrList<Journal> CalendarLocal::journals()
{
- return mJournalList;
+ QPtrList<Journal> el;
+ for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
+ if ( it->calEnabled() ) el.append( it );
+ return el;
}
+void CalendarLocal::setCalendarEnabled( int id, bool enable )
+{
+ for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
+ if ( it->calID() == id ) it->setCalEnabled( enable );
+
+ for ( Event *it = mEventList.first(); it; it = mEventList.next() )
+ if ( it->calID() == id ) it->setCalEnabled( enable );
+
+ for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
+ if ( it->calID() == id ) it->setCalEnabled( enable );
+
+}
+void CalendarLocal::setAlarmEnabled( int id, bool enable )
+{
+ for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
+ if ( it->calID() == id ) it->setAlarmEnabled( enable );
+
+ for ( Event *it = mEventList.first(); it; it = mEventList.next() )
+ if ( it->calID() == id ) it->setAlarmEnabled( enable );
+
+ for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
+ if ( it->calID() == id ) it->setAlarmEnabled( enable );
+
+}
+void CalendarLocal::setDefaultCalendarEnabledOnly()
+{
+ for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
+ it->setCalEnabled( it->calID() == mDefaultCalendar );
+
+ for ( Event *it = mEventList.first(); it; it = mEventList.next() )
+ it->setCalEnabled( it->calID() == mDefaultCalendar);
+
+ for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
+ it->setCalEnabled( it->calID() == mDefaultCalendar);
+
+}
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 98ec710..b25fcbe 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -159,48 +159,51 @@ class CalendarLocal : public Calendar
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 );
+ void setCalendarEnabled( int id, bool enable );
+ void setAlarmEnabled( int id, bool enable );
+ void setDefaultCalendarEnabledOnly();
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 );
diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp
index 20078a7..3510c7d 100644
--- a/libkcal/calfilter.cpp
+++ b/libkcal/calfilter.cpp
@@ -57,74 +57,83 @@ void CalFilter::apply(QPtrList<Event> *eventlist)
}
}
// kdDebug(5800) << "CalFilter::apply() done" << endl;
}
// TODO: avoid duplicating apply() code
void CalFilter::apply(QPtrList<Todo> *eventlist)
{
if (!mEnabled) return;
Todo *event = eventlist->first();
while(event) {
if (!filterTodo(event)) {
eventlist->remove();
event = eventlist->current();
} else {
event = eventlist->next();
}
}
// kdDebug(5800) << "CalFilter::apply() done" << endl;
}
bool CalFilter::filterCalendarItem(Incidence *in)
{
+ if ( !in->calEnabled() )
+ return false;
if ( in->typeID() == eventID )
return filterEvent( (Event*) in );
else if ( in->typeID() == todoID )
return filterTodo( (Todo*) in);
else if ( in->typeID () == journalID )
return filterJournal( (Journal*) in );
return false;
}
bool CalFilter::filterEvent(Event *event)
{
+
+ if ( !event->calEnabled() )
+ return false;
if (mCriteria & HideEvents)
return false;
if (mCriteria & HideRecurring) {
if (event->recurrence()->doesRecur()) return false;
}
return filterIncidence(event);
}
bool CalFilter::filterJournal(Journal *j)
{
+ if ( !j->calEnabled() )
+ return false;
if (mCriteria & HideJournals)
return false;
return true;
}
bool CalFilter::filterTodo(Todo *todo)
{
+ if ( !todo->calEnabled() )
+ return false;
if (mCriteria & HideTodos)
return false;
if (mCriteria & HideCompleted) {
if (todo->isCompleted()) return false;
}
return filterIncidence(todo);
}
bool CalFilter::showCategories()
{
return mCriteria & ShowCategories;
}
int CalFilter::getSecrecy()
{
if ( (mCriteria & ShowPublic ))
return Incidence::SecrecyPublic;
if ( (mCriteria & ShowPrivate ))
return Incidence::SecrecyPrivate;
if ( (mCriteria & ShowConfidential ))
return Incidence::SecrecyConfidential;
return Incidence::SecrecyPublic;
}
bool CalFilter::filterIncidence(Incidence *incidence)
{
diff --git a/libkcal/calfilter.h b/libkcal/calfilter.h
index 29db441..e349770 100644
--- a/libkcal/calfilter.h
+++ b/libkcal/calfilter.h
@@ -5,48 +5,49 @@
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 _CALFILTER_H
#define _CALFILTER_H
#include <qstring.h>
#include <qptrlist.h>
#include "event.h"
#include "todo.h"
+#include "journal.h"
namespace KCal {
/**
Filter for calendar objects.
*/
class CalFilter {
public:
/** Construct filter. */
CalFilter();
/** Construct filter with name */
CalFilter(const QString &name);
/** Destruct filter. */
~CalFilter();
/**
Set name of filter.
*/
void setName(const QString &name) { mName = name; }
/**
Return name of filter.
*/
QString name() const { return mName; }
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 9b99855..7cd81fa 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -152,49 +152,51 @@ bool Event::isMultiDay() const
{
bool multi = !(dtStart().date() == dtEnd().date());
return multi;
}
void Event::setTransparency(Event::Transparency transparency)
{
if (mReadOnly) return;
mTransparency = transparency;
updated();
}
Event::Transparency Event::transparency() const
{
return mTransparency;
}
void Event::setDuration(int seconds)
{
setHasEndDate(false);
Incidence::setDuration(seconds);
}
QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
{
-
+ *ok = false;
+ if ( !alarmEnabled() )
+ return QDateTime ();
bool yes;
QDateTime incidenceStart = getNextOccurence( start_dt, &yes );
if ( ! yes || cancelled() ) {
*ok = false;
return QDateTime ();
}
bool enabled = false;
Alarm* alarm;
int off = 0;
QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
// if ( QDateTime::currentDateTime() > incidenceStart ){
// *ok = false;
// return incidenceStart;
// }
for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
if (alarm->enabled()) {
if ( alarm->hasTime () ) {
if ( alarm->time() < alarmStart ) {
alarmStart = alarm->time();
enabled = true;
off = alarmStart.secsTo( incidenceStart );
}
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index b5fe2e6..2ddbb01 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -23,59 +23,66 @@
#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 )
{
@@ -111,48 +118,74 @@ bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
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 )
+{
+ 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;
}
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index 05209e0..dc6024a 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -120,55 +120,64 @@ class IncidenceBase : public CustomProperties
enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
/** Set synchronisation satus. */
void setSyncStatus(int stat);
/** Return synchronisation status. */
int syncStatus() const;
/** Set Pilot Id. */
void setPilotId(int id);
/** Return Pilot Id. */
int pilotId() const;
void setTempSyncStat(int id);
int tempSyncStat() const;
void setIDStr( const QString & );
QString IDStr() const;
void setID( const QString &, const QString & );
QString getID( const QString & );
void setCsum( const QString &, const QString & );
QString getCsum( const QString & );
void removeID(const QString &);
void registerObserver( Observer * );
void unRegisterObserver( Observer * );
void updated();
+ void setCalID( int id );
+ int calID() const;
+ void setCalEnabled( bool );
+ bool calEnabled() const;
+ void setAlarmEnabled( bool );
+ bool alarmEnabled() const;
protected:
QDateTime mDtStart;
bool mReadOnly;
QDateTime getEvenTime( QDateTime );
private:
// base components
QString mOrganizer;
QString mUid;
+ int mCalID;
+ bool mCalEnabled;
+ bool mAlarmEnabled;
QDateTime mLastModified;
QPtrList<Attendee> mAttendees;
bool mFloats;
int mDuration;
bool mHasDuration;
QString mExternalId;
int mTempSyncStat;
// PILOT SYNCHRONIZATION STUFF
int mPilotId; // unique id for pilot sync
int mSyncStatus; // status (for sync)
QPtrList<Observer> mObservers;
};
bool operator==( const IncidenceBase&, const IncidenceBase& );
}
#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index c97a61e..42274ff 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -496,49 +496,49 @@ bool Todo::setRecurDates()
mRecurrenceID = next;
mDtStart = next;
setDtDue( next.addSecs( secs ) );
if ( QDateTime::currentDateTime() > next)
return false;
} else {
setHasRecurrenceID( false );
recurrence()->unsetRecurs();
}
return true;
}
void Todo::setPercentComplete(int v)
{
if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
if ( !setRecurDates() )
v = 0;
}
mPercentComplete = v;
if ( v != 100 )
mHasCompletedDate = false;
updated();
}
QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
{
- if ( isCompleted() || ! hasDueDate() || cancelled() ) {
+ if ( isCompleted() || ! hasDueDate() || cancelled() || !alarmEnabled() ) {
*ok = false;
return QDateTime ();
}
QDateTime incidenceStart;
incidenceStart = dtDue();
bool enabled = false;
Alarm* alarm;
int off = 0;
QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
// if ( QDateTime::currentDateTime() > incidenceStart ){
// *ok = false;
// return incidenceStart;
// }
for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
if (alarm->enabled()) {
if ( alarm->hasTime () ) {
if ( alarm->time() < alarmStart ) {
alarmStart = alarm->time();
enabled = true;
off = alarmStart.secsTo( incidenceStart );
}
} else {
int secs = alarm->startOffset().asSeconds();