korganizer

stdcalendar.cpp
1 /*
2  This file is part of libkcal.
3 
4  Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "stdcalendar.h"
23 
24 #include <libkcal/resourcecalendar.h>
25 #include <libtdepim/kpimprefs.h>
26 
27 #include <kstaticdeleter.h>
28 #include <tdeconfig.h>
29 #include <kstandarddirs.h>
30 #include <tdelocale.h>
31 #include <kurl.h>
32 
33 using namespace KOrg;
34 
35 static KStaticDeleter<StdCalendar> selfDeleter;
36 
37 StdCalendar *StdCalendar::mSelf = 0;
38 
39 StdCalendar *StdCalendar::self()
40 {
41  if ( !mSelf ) {
42  selfDeleter.setObject( mSelf, new StdCalendar() );
43  }
44  return mSelf;
45 }
46 
47 StdCalendar::StdCalendar()
48  : CalendarResources( KPimPrefs::timezone() )
49 {
50  readConfig();
51 
52  KCal::CalendarResourceManager *manager = resourceManager();
53  if ( manager->isEmpty() ) {
54  TDEConfig config( "korganizerrc" );
55  config.setGroup( "General" );
56  TQString fileName = config.readPathEntry( "Active Calendar" );
57 
58  TQString resourceName;
59  TQString resoruceType;
60  KCal::ResourceCalendar *defaultResource = 0;
61  if ( !fileName.isEmpty() ) {
62  KURL url( fileName );
63  if ( url.isLocalFile() ) {
64  kdDebug(5850) << "Local resource at " << url << endl;
65  defaultResource = manager->createResource( "file" );
66  if ( defaultResource )
67  defaultResource->setValue( "File", url.path() );
68  } else {
69  kdDebug(5850) << "Remote Resource at " << url << endl;
70  defaultResource = manager->createResource( "remote" );
71  if ( defaultResource )
72  defaultResource->setValue( "URL", url.url() );
73  }
74  resourceName = i18n( "Active Calendar" );
75  }
76  // No resource created, i.e. no path found in config => use default path
77  if ( !defaultResource ) {
78  fileName = locateLocal( "data", "korganizer/std.ics" );
79  kdDebug(5850) << "Creating new default local resource at " << fileName << endl;
80  defaultResource = manager->createResource( "file" );
81  if ( defaultResource )
82  defaultResource->setValue( "File", fileName );
83  resourceName = i18n( "Default Calendar" );
84  }
85 
86  if ( defaultResource ) {
87  defaultResource->setTimeZoneId( KPimPrefs::timezone() );
88  defaultResource->setResourceName( resourceName );
89  manager->add( defaultResource );
90  manager->setStandardResource( defaultResource );
91  }
92 
93  // By default, also create a birthday resource
94  KCal::ResourceCalendar *bdayResource = manager->createResource( "birthdays" );
95  if ( bdayResource ) {
96  kdDebug(5850) << "Adding Birthdays resource" << endl;
97  bdayResource->setTimeZoneId( KPimPrefs::timezone() );
98  bdayResource->setResourceName( i18n("Birthdays") );
99  manager->add( bdayResource );
100  } else {
101  kdDebug(5850) << "Unable to add a Birthdays resource" << endl;
102  }
103  }
104 }
105 
106 StdCalendar::~StdCalendar()
107 {
108  mSelf = 0;
109 }
virtual bool setValue(const TQString &key, const TQString &value)
virtual void setTimeZoneId(const TQString &timeZoneId)=0