summaryrefslogtreecommitdiffabout
path: root/korganizer/calendarview.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/calendarview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 9571f16..8d024c1 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,31 +1,31 @@
/*
This file is part of KOrganizer.
Requires the Qt and KDE widget libraries, available at no cost at
http://www.troll.no and http://www.kde.org respectively
- Copyright (c) 1997, 1998, 1999
+ Copyright (c) savecale1997, 1998, 1999
Preston Brown (preton.brown@yale.edu)
Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
Ian Dawes (iadawes@globalserve.net)
Laszlo Boloni (boloni@cs.purdue.edu)
Copyright (c) 2000, 2001, 2002
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.
*/
#include <stdlib.h>
@@ -758,74 +758,78 @@ void CalendarView::nextConflict( bool all, bool allday )
void CalendarView::conflictAll()
{
nextConflict ( true, true );
}
void CalendarView::conflictAllday()
{
nextConflict ( false, true );
}
void CalendarView::conflictNotAll()
{
nextConflict ( false, false );
}
void CalendarView::setCalReadOnly( int id, bool readO )
{
if ( readO ) {
emit save();
}
mCalendar->setReadOnly( id, readO );
}
void CalendarView::setScrollBarStep(int val )
{
#ifdef DESKTOP_VERSION
mDateScrollBar->setLineStep ( val );
+#else
+ Q_UNUSED( val );
#endif
}
void CalendarView::scrollBarValue(int val )
{
#ifdef DESKTOP_VERSION
if ( QApplication::desktop()->width() < 800 ) return;
if ( flag_blockScrollBar ) return;
flag_blockScrollBar = true;
int count = mNavigator->selectedDates().count();
int day = mNavigator->selectedDates().first().dayOfYear();
int stepdays = val;
if ( mDateScrollBar->lineStep () <= count ) {
//val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
//qDebug("VAL %d ",val );
stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
stepdays = day+stepdays;
if ( stepdays < 0 ) stepdays = 0;
}
if ( stepdays == day ) {
flag_blockScrollBar = false;
return;
}
int year = mNavigator->selectedDates().first().year();
QDate d ( year,1,1 );
mNavigator->selectDates( d.addDays( stepdays-1) , count );
flag_blockScrollBar = false;
+#else
+ Q_UNUSED( val );
#endif
}
void CalendarView::updateView(const QDate &start, const QDate &end)
{
#ifdef DESKTOP_VERSION
if ( ! mDateScrollBar->draggingSlider () ) {
int dof = start.dayOfYear();
//qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() );
if ( dof != mDateScrollBar->value() ) {
mDateScrollBar->blockSignals( true );
mDateScrollBar->setValue( start.dayOfYear());
mDateScrollBar->blockSignals( false );
}
}
#endif
mTodoList->updateView();
mViewManager->updateView(start, end);
//mDateNavigator->updateView();
}
void CalendarView::checkFiles()
@@ -1581,48 +1585,49 @@ void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* t
QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
if ( !id.isEmpty() ) {
QString des = eve->description();
QString pref = "e";
if ( toDelete->typeID() == todoID )
pref = "t";
des += pref+ id + ",";
eve->setReadOnly( false );
eve->setDescription( des );
//qDebug("setdes %s ", des.latin1());
eve->setReadOnly( true );
}
eve = lastSync.next();
}
}
void CalendarView::checkExternalId( Incidence * inc )
{
QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
checkExternSyncEvent( lastSync, inc );
}
bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
{
+
bool syncOK = true;
int addedEvent = 0;
int addedEventR = 0;
int deletedEventR = 0;
int deletedEventL = 0;
int changedLocal = 0;
int changedRemote = 0;
int filteredIN = 0;
int filteredOUT = 0;
//QPtrList<Event> el = local->rawEvents();
Event* eventR;
QString uid;
int take;
Event* eventRSync;
Event* eventLSync;
clearAllViews();
QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
bool fullDateRange = false;
local->resetTempSyncStat();
mLastCalendarSync = QDateTime::currentDateTime();
if ( mSyncManager->syncWithDesktop() ) {
remote->resetPilotStat(1);
if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
@@ -1711,105 +1716,105 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
if ( incCounter % modulo == 0 )
bar.setProgress( incCounter );
++incCounter;
uid = inR->uid();
bool skipIncidence = false;
if ( uid.left(15) == QString("last-syncEvent-") )
skipIncidence = true;
QString idS;
qApp->processEvents();
if ( !skipIncidence ) {
inL = local->incidenceForUid( uid , false , true );
if ( inL ) { // maybe conflict - same uid in both calendars
if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
//qDebug("take %d %s ", take, inL->summary().latin1());
if ( take == 3 )
return false;
if ( take == 1 ) {// take local **********************
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
else
idS = inR->IDStr();
int calID = inR->calID();
remote->deleteIncidence( inR );
inR = inL->clone();
- inR->setCalID( calID );
+ inR->setCalID_block( calID );
inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
inR->setIDStr( idS );
remote->addIncidence( inR );
if ( mSyncManager->syncWithDesktop() )
inR->setPilotId( 2 );
++changedRemote;
} else {// take remote **********************
if ( !inL->isReadOnly() ) {
idS = inL->IDStr();
int pid = inL->pilotId();
int calID = inL->calID();
local->deleteIncidence( inL );
inL = inR->clone();
- inL->setCalID( calID );
+ inL->setCalID_block( calID );
if ( mSyncManager->syncWithDesktop() )
inL->setPilotId( pid );
inL->setIDStr( idS );
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
}
local->addIncidence( inL );
++changedLocal;
}
}
}
} else { // no conflict ********** add or delete remote
if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
QString des = eventLSync->description();
QString pref = "e";
if ( inR->typeID() == todoID )
pref = "t";
if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
//remote->deleteIncidence( inR );
++deletedEventR;
} else {
inR->setLastModified( modifiedCalendar );
inL = inR->clone();
inL->setIDStr( ":" );
inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
- inL->setCalID( 0 );// add to default cal
+ inL->setCalID_block( 0 );// add to default cal
local->addIncidence( inL );
++addedEvent;
}
} else {
if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
inR->setLastModified( modifiedCalendar );
inL = inR->clone();
inL->setIDStr( ":" );
- inL->setCalID( 0 );// add to default cal
+ inL->setCalID_block( 0 );// add to default cal
local->addIncidence( inL );
++addedEvent;
} else {
checkExternSyncEvent(eventRSyncSharp, inR);
remote->deleteIncidence( inR );
++deletedEventR;
}
}
} else {
++filteredIN;
}
}
}
inR = er.next();
}
QPtrList<Incidence> el = local->rawIncidences();
inL = el.first();
modulo = (el.count()/10)+1;
bar.setCaption (i18n("Add / remove events") );
bar.setTotalSteps ( el.count() ) ;
bar.show();
incCounter = 0;
@@ -1825,64 +1830,64 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
bool skipIncidence = false;
if ( uid.left(15) == QString("last-syncEvent-") )
skipIncidence = true;
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
skipIncidence = true;
if ( !skipIncidence ) {
inR = remote->incidenceForUid( uid , true, true );
if ( ! inR ) {
if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
// no conflict ********** add or delete local
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
checkExternSyncEvent(eventLSyncSharp, inL);
local->deleteIncidence( inL );
++deletedEventL;
} else {
if ( ! mSyncManager->mWriteBackExistingOnly ) {
inL->removeID(mCurrentSyncDevice );
++addedEventR;
//qDebug("remote added Incidence %s ", inL->summary().latin1());
inL->setLastModified( modifiedCalendar );
inR = inL->clone();
inR->setIDStr( ":" );
inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
- inR->setCalID( 0 );// add to default cal
+ inR->setCalID_block( 0 );// add to default cal
remote->addIncidence( inR );
}
}
} else {
if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
checkExternSyncEvent(eventLSyncSharp, inL);
local->deleteIncidence( inL );
++deletedEventL;
} else {
if ( ! mSyncManager->mWriteBackExistingOnly ) {
++addedEventR;
inL->setLastModified( modifiedCalendar );
inR = inL->clone();
inR->setIDStr( ":" );
- inR->setCalID( 0 );// add to default cal
+ inR->setCalID_block( 0 );// add to default cal
remote->addIncidence( inR );
}
}
}
} else {
++filteredOUT;
}
}
}
inL = el.next();
}
int delFut = 0;
int remRem = 0;
if ( mSyncManager->mWriteBackInFuture ) {
er = remote->rawIncidences();
remRem = er.count();
inR = er.first();
QDateTime dt;
QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
while ( inR ) {
if ( inR->typeID() == todoID ) {
Todo * t = (Todo*)inR;
if ( t->hasDueDate() )
@@ -2428,49 +2433,51 @@ bool CalendarView::openCalendar(QString filename, bool merge)
//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::mergeFile( QString fn )
{
clearAllViews();
mCalendar->mergeCalendarFile( fn );
mCalendar->reInitAlarmSettings();
setSyncEventsReadOnly();
updateUnmanagedViews();
updateView();
}
void CalendarView::mergeFileResource( QString fn ,QString resource )
{
if ( resource == "ALL" ) {
+ mCalendar->setAllCalendarEnabled( true );
mergeFile( fn );
+ restoreCalendarSettings();
return;
}
int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource );
if ( !exclusiveResource ) {
qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() );
return;
}
clearAllViews();
mCalendar->setCalendarRemove( exclusiveResource );
int def = mCalendar->defaultCalendar();
mCalendar->setDefaultCalendar(exclusiveResource);
if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) {
qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() );
}
mCalendar->setDefaultCalendar( def );
mCalendar->reInitAlarmSettings();
setSyncEventsReadOnly();
updateUnmanagedViews();
updateView();
}
void CalendarView::showOpenError()
{
KMessageBox::error(this,i18n("Couldn't load calendar\n."));
@@ -2576,50 +2583,54 @@ bool CalendarView::saveCalendars()
saveError = cal->mName +"\n";
cal = calendars.next();
while ( cal ) {
if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
mCalendar->setDefaultCalendar( cal->mCalNumber );
mCalendar->setDefaultCalendarEnabledOnly();
if ( saveCalendar( cal->mFileName ) )
cal->mLoadDt = QDateTime::currentDateTime();
else
saveError += cal->mName + "\n";
}
cal = calendars.next();
}
restoreCalendarSettings();
//saveError = "test error";
if ( !saveError.isEmpty() ) {
saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError;
KMessageBox::error(this, saveError, i18n("Error saving data"));
return false;
}
return true;
}
bool CalendarView::saveCalendarResource(QString filename, QString resource)
{
- if ( resource == "ALL" )
- return saveCalendar( filename );
+ if ( resource == "ALL" ) {
+ mCalendar->setAllCalendarEnabled( true );
+ bool retval = saveCalendar( filename );
+ restoreCalendarSettings();
+ return retval;
+ }
int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource );
if ( !exclusiveResource ) {
qDebug("KO: CalendarView::saveCalendarResource: resource not found %s", resource.latin1() );
return false;
}
mCalendar->setDefaultCalendar( exclusiveResource );
mCalendar->setDefaultCalendarEnabledOnly();
mCalendar->setSyncEventsEnabled();
bool res = saveCalendar( filename );
restoreCalendarSettings();
return res;
}
bool CalendarView::saveCalendar( QString filename )
{
// Store back all unsaved data into calendar object
// qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
if ( mViewManager->currentView() )
mViewManager->currentView()->flushView();
QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
mStorage->setSaveFormat( new ICalFormat() );