konsolekalendar
stdcalendar.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "stdcalendar.h"
00025
00026 #include <libkcal/resourcecalendar.h>
00027 #include <libkdepim/kpimprefs.h>
00028
00029 #include <kconfig.h>
00030 #include <kstandarddirs.h>
00031 #include <klocale.h>
00032 #include <kurl.h>
00033
00034 using namespace KCal;
00035
00036 StdCalendar::StdCalendar( const QString &fileName, const QString &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 KConfig config( "korganizerrc" );
00058 config.setGroup( "General" );
00059 QString fileName = config.readPathEntry( "Active Calendar" );
00060
00061 if ( !fileName.isEmpty() ) {
00062 addFileResource( fileName, i18n( "Active Calendar" ) );
00063
00064 } else {
00065
00066 addFileResource( locateLocal( "data", "korganizer/std.ics" ),
00067 i18n( "Default Calendar" ) );
00068 }
00069 }
00070 }
00071
00072 void StdCalendar::addFileResource( const QString &fileName,
00073 const QString &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 }
|