konsolekalendar

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