stdcalendar.cpp
00001 /* 00002 This file was originally from libkcal, then moved into korganizer. 00003 This version has been hacked for use by konsolekalendar. 00004 00005 Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> 00006 Copyright (c) 2005 Allen Winter <winter@kde.org> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License as published by the Free Software Foundation; either 00011 version 2 of the License, or (at your option) any later version. 00012 00013 This library 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 GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #include "stdcalendar.h" 00025 00026 #include <libkcal/resourcecalendar.h> 00027 #include <libtdepim/kpimprefs.h> 00028 00029 #include <tdeconfig.h> 00030 #include <kstandarddirs.h> 00031 #include <tdelocale.h> 00032 #include <kurl.h> 00033 00034 using namespace KCal; 00035 00036 StdCalendar::StdCalendar( const TQString &fileName, const TQString &resName ) 00037 : CalendarResources( KPimPrefs::timezone() ) 00038 { 00039 mManager = resourceManager(); 00040 if ( mManager->isEmpty() ) { 00041 addFileResource( fileName, resName ); 00042 } else { 00043 CalendarResourceManager::ActiveIterator it; 00044 for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) { 00045 (*it)->load(); 00046 } 00047 } 00048 } 00049 00050 StdCalendar::StdCalendar() 00051 : CalendarResources( KPimPrefs::timezone() ) 00052 { 00053 readConfig(); 00054 00055 mManager = resourceManager(); 00056 if ( mManager->isEmpty() ) { 00057 TDEConfig config( "korganizerrc" ); 00058 config.setGroup( "General" ); 00059 TQString fileName = config.readPathEntry( "Active Calendar" ); 00060 00061 if ( !fileName.isEmpty() ) { 00062 addFileResource( fileName, i18n( "Active Calendar" ) ); 00063 00064 } else { 00065 // No resource created, i.e. no path found in config => use default path 00066 addFileResource( locateLocal( "data", "korganizer/std.ics" ), 00067 i18n( "Default Calendar" ) ); 00068 } 00069 } 00070 } 00071 00072 void StdCalendar::addFileResource( const TQString &fileName, 00073 const TQString &resName ) 00074 { 00075 KCal::ResourceCalendar *resource = 0; 00076 00077 if ( !fileName.isEmpty() ) { 00078 KURL url( fileName ); 00079 if ( url.isLocalFile() ) { 00080 kdDebug() << "Local resource at " << url << endl; 00081 resource = mManager->createResource( "file" ); 00082 if ( resource ) 00083 resource->setValue( "File", url.path() ); 00084 } else { 00085 kdDebug() << "Remote Resource at " << url << endl; 00086 resource = mManager->createResource( "remote" ); 00087 if ( resource ) 00088 resource->setValue( "URL", url.url() ); 00089 } 00090 00091 if ( resource ) { 00092 resource->setTimeZoneId( KPimPrefs::timezone() ); 00093 resource->setResourceName( resName ); 00094 mManager->add( resource ); 00095 mManager->setStandardResource( resource ); 00096 } 00097 } 00098 } 00099 00100 StdCalendar::~StdCalendar() 00101 { 00102 }