stdcalendar.cpp
00001 /* 00002 This file is part of libkcal. 00003 00004 Copyright (c) 2004 Cornelius Schumacher <schumacher@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 "stdcalendar.h" 00023 00024 #include <libkcal/resourcecalendar.h> 00025 #include <libkdepim/kpimprefs.h> 00026 00027 #include <kstaticdeleter.h> 00028 #include <kconfig.h> 00029 #include <kstandarddirs.h> 00030 #include <klocale.h> 00031 #include <kurl.h> 00032 00033 using namespace KOrg; 00034 00035 static KStaticDeleter<StdCalendar> selfDeleter; 00036 00037 StdCalendar *StdCalendar::mSelf = 0; 00038 00039 StdCalendar *StdCalendar::self() 00040 { 00041 if ( !mSelf ) { 00042 selfDeleter.setObject( mSelf, new StdCalendar() ); 00043 } 00044 return mSelf; 00045 } 00046 00047 StdCalendar::StdCalendar() 00048 : CalendarResources( KPimPrefs::timezone() ) 00049 { 00050 readConfig(); 00051 00052 KCal::CalendarResourceManager *manager = resourceManager(); 00053 if ( manager->isEmpty() ) { 00054 KConfig config( "korganizerrc" ); 00055 config.setGroup( "General" ); 00056 TQString fileName = config.readPathEntry( "Active Calendar" ); 00057 00058 TQString resourceName; 00059 TQString resoruceType; 00060 KCal::ResourceCalendar *defaultResource = 0; 00061 if ( !fileName.isEmpty() ) { 00062 KURL url( fileName ); 00063 if ( url.isLocalFile() ) { 00064 kdDebug(5850) << "Local resource at " << url << endl; 00065 defaultResource = manager->createResource( "file" ); 00066 if ( defaultResource ) 00067 defaultResource->setValue( "File", url.path() ); 00068 } else { 00069 kdDebug(5850) << "Remote Resource at " << url << endl; 00070 defaultResource = manager->createResource( "remote" ); 00071 if ( defaultResource ) 00072 defaultResource->setValue( "URL", url.url() ); 00073 } 00074 resourceName = i18n( "Active Calendar" ); 00075 } 00076 // No resource created, i.e. no path found in config => use default path 00077 if ( !defaultResource ) { 00078 fileName = locateLocal( "data", "korganizer/std.ics" ); 00079 kdDebug(5850) << "Creating new default local resource at " << fileName << endl; 00080 defaultResource = manager->createResource( "file" ); 00081 if ( defaultResource ) 00082 defaultResource->setValue( "File", fileName ); 00083 resourceName = i18n( "Default Calendar" ); 00084 } 00085 00086 if ( defaultResource ) { 00087 defaultResource->setTimeZoneId( KPimPrefs::timezone() ); 00088 defaultResource->setResourceName( resourceName ); 00089 manager->add( defaultResource ); 00090 manager->setStandardResource( defaultResource ); 00091 } 00092 00093 // By default, also create a birthday resource 00094 KCal::ResourceCalendar *bdayResource = manager->createResource( "birthdays" ); 00095 if ( bdayResource ) { 00096 kdDebug(5850) << "Adding Birthdays resource" << endl; 00097 bdayResource->setTimeZoneId( KPimPrefs::timezone() ); 00098 bdayResource->setResourceName( i18n("Birthdays") ); 00099 manager->add( bdayResource ); 00100 } else { 00101 kdDebug(5850) << "Unable to add a Birthdays resource" << endl; 00102 } 00103 } 00104 } 00105 00106 StdCalendar::~StdCalendar() 00107 { 00108 mSelf = 0; 00109 }