kpilot
syncCalendar.cc
Go to the documentation of this file.00001 /* KPilot 00002 ** 00003 ** Copyright (C) 2005 by Adriaan de Groot <groot@kde.org> 00004 ** 00005 */ 00006 00007 /* 00008 ** This program is free software; you can redistribute it and/or modify 00009 ** it under the terms of the GNU General Public License as published by 00010 ** the Free Software Foundation; either version 2 of the License, or 00011 ** (at your option) any later version. 00012 ** 00013 ** This program is distributed in the hope that it will be useful, 00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 ** GNU General Public License for more details. 00017 ** 00018 ** You should have received a copy of the GNU General Public License 00019 ** along with this program in a file called COPYING; if not, write to 00020 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00021 ** MA 02110-1301, USA. 00022 */ 00023 00024 /* 00025 ** Bug reports and questions can be sent to kde-pim@kde.org. 00026 */ 00027 00028 #include "options.h" 00029 00030 #include <kpilotlink.h> 00031 #include <pilotDatabase.h> 00032 #include <pilotDateEntry.h> 00033 00034 #include <libkcal/calendarlocal.h> 00035 #include <libkcal/event.h> 00036 00037 00038 typedef DatabaseInterpreter<KCal::Event,PilotDateEntry,PilotDateEntry::Mapper> DatebookDB; 00039 00040 class CalendarDumper 00041 { 00042 public: 00043 CalendarDumper() {} 00044 00045 KCal::CalendarLocal *retrieve(int fd); 00046 KCal::CalendarLocal *retrieve(const QString &filename); 00047 00048 protected: 00049 KCal::CalendarLocal *retrieve(DatebookDB *db); 00050 } ; 00051 00052 00053 00054 KCal::CalendarLocal *CalendarDumper::retrieve(int fd) 00055 { 00056 PilotSerialDatabase sdb( fd, CSL1("DatebookDB") ); 00057 DatebookDB db(&sdb); 00058 return retrieve(db); 00059 } 00060 00061 KCal::CalendarLocal *CalendarDumped::retrieve(const QString &fn) 00062 { 00063 PilotLocalDatabase ldb( fn ); 00064 DatebookDB db(&ldb); 00065 return retrieve(db); 00066 } 00067 00068 KCal::CalendarLocal *retrieve(DatebookDB *db) 00069 { 00070 KCal::CalendarLocal *cal = new CalendarLocal( QString::null ); 00071 00072 int count = db->db()->recordCount(); 00073 00074 if (count < 1) 00075 { 00076 return cal; 00077 } 00078 00079 for (int i=0; i<count; i++) 00080 { 00081 KCal::Event *e = db->readRecordByIndex(i); 00082 if (!e) continue; 00083 cal->addEvent(e); 00084 } 00085 00086 return cal; 00087 }