/*************************************************************************** * Copyright (C) 2006 by Bertjan Broeksema * * bbroeksema@bluebottle.com * * * * 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 "tododcop.h" #include #include #include #include #include #include #include #include TodoDCOP::TodoDCOP() : DCOPObject("TodoIface") { KConfig korgcfg( locate( "config", "korganizerrc" ) ); korgcfg.setGroup( "Time & Date" ); m_timezone = QString( korgcfg.readEntry( "TimeZoneId" ) ); KCal::CalendarResources *cal = new KCal::CalendarResources( m_timezone ); cal->readConfig(); cal->load(); m_calendar = cal; } TodoDCOP::~TodoDCOP() { kdDebug() << "Going away... " << endl; delete m_calendar; } QString TodoDCOP::todos() { KCal::ICalFormat format; KCal::CalendarLocal todos( m_timezone ); KCal::Todo::List list = m_calendar->todos(); KCal::Todo::List::iterator it; for ( it = list.begin(); it != list.end(); ++it ) { todos.addTodo( (*it) ); } return format.toString( &todos ); } void TodoDCOP::editTodo( const QString &todo ) { KCal::ICalFormat format; KCal::Incidence *i = format.fromString( todo ); if( i ) kdDebug() << "UID: " << i->uid() << endl; else kdDebug() << "UID: incidence is 0" << endl; if( !dynamic_cast( i ) ) { kdDebug() << "todo is not a valid string for a KCal::Todo item" << endl; kdDebug() << todo << endl; return; } else { KCal::Todo *skTodo = dynamic_cast( i ); KCal::Todo *calTodo = m_calendar->todo( skTodo->uid() ); if( !calTodo ) { kdDebug() << "There is no KCal::Todo item with uid: " << skTodo->uid() << endl; return; } else { if( skTodo->isCompleted() != calTodo->isCompleted() ) { if( skTodo->isCompleted() ) { kdDebug() << "Setting calTodo completed... " << endl; kdDebug() << "Completed on: " << skTodo->completed() << endl; kdDebug() << "calTodo: " << calTodo << endl; kdDebug() << "skTodo: " << skTodo << endl; calTodo->setCompleted( skTodo->completed() ); kdDebug() << "calTodo should have changed now." << endl; } else { kdDebug() << "Setting calTodo to not completed... " << endl; calTodo->setCompleted( false ); kdDebug() << "Value should have changed now." << endl; } } } } } void TodoDCOP::exit() { kapp->quit(); }