kitchensync

metacalendar.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002,2003 Holger Freyther <freyther@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <kdebug.h>
00023 
00024 #include "metacalendar.h"
00025 
00026 
00027 using namespace OpieHelper;
00028 
00029 MetaCalendar::MetaCalendar( KSync::CalendarSyncee* sync, const QString& file )
00030   : MD5Template<KSync::CalendarSyncee, KSync::CalendarSyncEntry>( sync, file )
00031 {}
00032 
00033 MetaCalendar::~MetaCalendar()
00034 {}
00035 
00036 QString MetaCalendar::entryToString( KSync::CalendarSyncEntry* entry )
00037 {
00038   KCal::Incidence *inc = entry->incidence();
00039 
00040   QString str;
00041 
00042   if ( dynamic_cast<KCal::Todo*>( inc ) )
00043     str = todoToString( dynamic_cast<KCal::Todo*>( inc ) );
00044   else if ( dynamic_cast<KCal::Event*>( inc ) )
00045     str =  eventToString( dynamic_cast<KCal::Event*>( inc ) );
00046   else{
00047     str = QString::null;
00048   }
00049 
00050   return str;
00051 }
00052 
00053 QString MetaCalendar::todoToString( KCal::Todo *todo )
00054 {
00055   if ( !todo )
00056     return QString::null;
00057 
00058 
00059 
00060   QString str = todo->categories().join(";");
00061   str += QString::number( todo->isCompleted() );
00062   str += QString::number( todo->percentComplete() );
00063   str += todo->summary();
00064   if ( todo->hasDueDate() )
00065     str += todo->dtDue().toString("dd.MM.yyyy");
00066 
00067   if ( todo->hasStartDate() )
00068     str += todo->dtStart().toString( "dd.MM.yyyy" );
00069 
00070   if ( todo->isCompleted() && todo->hasCompletedDate() )
00071     str += todo->completed().toString( "dd.MM.yyyy" );
00072 
00073 
00074   str += QString::number( todo->priority() );
00075   str += todo->description();
00076 
00077   kdDebug(5227) << "Meta String is " << str << "Todo is " << todo->isCompleted()
00078                 << QString::number( todo->isCompleted() ) << endl;
00079 
00080   return str;
00081 }
00082 
00083 QString MetaCalendar::eventToString( KCal::Event* event)
00084 {
00085   if ( !event )
00086     return QString::null;
00087 
00088 
00089   QString string  = event->categories().join(";");
00090   string += event->summary();
00091   string += event->description();
00092   string += event->location();
00093   string += event->dtStart().toString("dd.MM.yyyy hh:mm:ss");
00094   string += event->dtEnd().toString("dd.MM.yyyy hh:mm:ss");
00095   string += QString::number( event->doesFloat() );
00096 
00097   /* Recurrance */
00098   KCal::Recurrence* rec = event->recurrence();
00099   if ( rec->doesRecur() ) {
00100     switch( rec->recurrenceType() ) {
00101     case KCal::Recurrence::rDaily:
00102       string += "Daily";
00103       break;
00104     case KCal::Recurrence::rWeekly:{
00105       string += "Weekly";
00106       string += days( rec->days() );
00107       break;
00108     }
00109     case KCal::Recurrence::rMonthlyPos:
00110       string += "MonthlyDay";
00111       break;
00112     case KCal::Recurrence::rMonthlyDay:
00113       string += "MonthlyDate";
00114       break;
00115     case KCal::Recurrence::rYearlyDay: // see datebook.cpp
00116     case KCal::Recurrence::rYearlyMonth:
00117     case KCal::Recurrence::rYearlyPos:
00118       string += "Yearly";
00119       break;
00120     case KCal::Recurrence::rNone:
00121     default:
00122       break;
00123     }
00124     string += QString::number( rec->frequency() );
00125 
00126     /* test duration */
00127     string += QString::number( rec->duration() );
00128     if ( rec->duration() == 0 ) {
00129       string += rec->endDate().toString("dd.MM.yyyy");
00130     }
00131     string += rec->startDateTime().toString("dd.MM.yyyy hh:mm:ss");
00132   }
00133   /* Alarms here */
00134   /*
00135     KCal::Alarm* al = event->alarms().first();
00136     if ( al != 0 ) {
00137     int sec = al->offset().asSeconds();
00138     string += QString::number( sec );
00139     string += al->audioFile();
00140     }
00141   */
00142 
00143   return string;
00144 }
00145 
00146 
00147 QString MetaCalendar::days( const QBitArray& ar )
00148 {
00149   QString str;
00150   if ( ar.testBit(0 ) ) str += "Mo";
00151   if ( ar.testBit(1 ) ) str += "Di";
00152   if ( ar.testBit(2 ) ) str += "Mi";
00153   if ( ar.testBit(3 ) ) str += "Do";
00154   if ( ar.testBit(4 ) ) str += "Fr";
00155   if ( ar.testBit(5 ) ) str += "Sa";
00156   if ( ar.testBit(6 ) ) str += "So";
00157 
00158   return str;
00159 }
KDE Home | KDE Accessibility Home | Description of Access Keys