summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
authorzautrix <zautrix>2005-06-13 10:51:47 (UTC)
committer zautrix <zautrix>2005-06-13 10:51:47 (UTC)
commit4f3ff02932b39bf16b9692c3cb69c101a28b4616 (patch) (unidiff)
treebae36a7e654c788a0994bb353f3997b495e2459c /libkcal/calendar.cpp
parent2be8214908c52298ba79c8058d340edca5a8b417 (diff)
downloadkdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.zip
kdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.tar.gz
kdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.tar.bz2
fixx
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index f4350d9..5092d1a 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,210 +1,215 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 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 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <stdlib.h> 22#include <stdlib.h>
23#include <time.h> 23#include <time.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "exceptions.h" 29#include "exceptions.h"
30#include "calfilter.h" 30#include "calfilter.h"
31 31
32#include "calendar.h" 32#include "calendar.h"
33#include "syncdefines.h" 33#include "syncdefines.h"
34 34
35using namespace KCal; 35using namespace KCal;
36 36
37Calendar::Calendar() 37Calendar::Calendar()
38{ 38{
39 39
40 init(); 40 init();
41 setTimeZoneId( " 00:00 Europe/London(UTC)" ); 41 setTimeZoneId( " 00:00 Europe/London(UTC)" );
42} 42}
43 43
44Calendar::Calendar( const QString &timeZoneId ) 44Calendar::Calendar( const QString &timeZoneId )
45{ 45{
46 46
47 init(); 47 init();
48 setTimeZoneId(timeZoneId); 48 setTimeZoneId(timeZoneId);
49} 49}
50 50
51void Calendar::init() 51void Calendar::init()
52{ 52{
53 mObserver = 0; 53 mObserver = 0;
54 mNewObserver = false; 54 mNewObserver = false;
55 mUndoIncidence = 0; 55 mUndoIncidence = 0;
56 mDeleteIncidencesOnClose = true;
56 mModified = false; 57 mModified = false;
57 mDefaultCalendar = 1; 58 mDefaultCalendar = 1;
58 // Setup default filter, which does nothing 59 // Setup default filter, which does nothing
59 mDefaultFilter = new CalFilter; 60 mDefaultFilter = new CalFilter;
60 mFilter = mDefaultFilter; 61 mFilter = mDefaultFilter;
61 mFilter->setEnabled(false); 62 mFilter->setEnabled(false);
62 63
63 // initialize random numbers. This is a hack, and not 64 // initialize random numbers. This is a hack, and not
64 // even that good of one at that. 65 // even that good of one at that.
65// srandom(time(0)); 66// srandom(time(0));
66 67
67 // user information... 68 // user information...
68 setOwner(i18n("Unknown Name")); 69 setOwner(i18n("Unknown Name"));
69 setEmail(i18n("unknown@nowhere")); 70 setEmail(i18n("unknown@nowhere"));
70 71
71#if 0 72#if 0
72 tmpStr = KOPrefs::instance()->mTimeZone; 73 tmpStr = KOPrefs::instance()->mTimeZone;
73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 74// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
74 int dstSetting = KOPrefs::instance()->mDaylightSavings; 75 int dstSetting = KOPrefs::instance()->mDaylightSavings;
75 extern long int timezone; 76 extern long int timezone;
76 struct tm *now; 77 struct tm *now;
77 time_t curtime; 78 time_t curtime;
78 curtime = time(0); 79 curtime = time(0);
79 now = localtime(&curtime); 80 now = localtime(&curtime);
80 int hourOff = - ((timezone / 60) / 60); 81 int hourOff = - ((timezone / 60) / 60);
81 if (now->tm_isdst) 82 if (now->tm_isdst)
82 hourOff += 1; 83 hourOff += 1;
83 QString tzStr; 84 QString tzStr;
84 tzStr.sprintf("%.2d%.2d", 85 tzStr.sprintf("%.2d%.2d",
85 hourOff, 86 hourOff,
86 abs((timezone / 60) % 60)); 87 abs((timezone / 60) % 60));
87 88
88 // if no time zone was in the config file, write what we just discovered. 89 // if no time zone was in the config file, write what we just discovered.
89 if (tmpStr.isEmpty()) { 90 if (tmpStr.isEmpty()) {
90// KOPrefs::instance()->mTimeZone = tzStr; 91// KOPrefs::instance()->mTimeZone = tzStr;
91 } else { 92 } else {
92 tzStr = tmpStr; 93 tzStr = tmpStr;
93 } 94 }
94 95
95 // if daylight savings has changed since last load time, we need 96 // if daylight savings has changed since last load time, we need
96 // to rewrite these settings to the config file. 97 // to rewrite these settings to the config file.
97 if ((now->tm_isdst && !dstSetting) || 98 if ((now->tm_isdst && !dstSetting) ||
98 (!now->tm_isdst && dstSetting)) { 99 (!now->tm_isdst && dstSetting)) {
99 KOPrefs::instance()->mTimeZone = tzStr; 100 KOPrefs::instance()->mTimeZone = tzStr;
100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 101 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
101 } 102 }
102 103
103 setTimeZone(tzStr); 104 setTimeZone(tzStr);
104#endif 105#endif
105 106
106// KOPrefs::instance()->writeConfig(); 107// KOPrefs::instance()->writeConfig();
107} 108}
108 109
109Calendar::~Calendar() 110Calendar::~Calendar()
110{ 111{
111 delete mDefaultFilter; 112 delete mDefaultFilter;
112 if ( mUndoIncidence ) 113 if ( mUndoIncidence )
113 delete mUndoIncidence; 114 delete mUndoIncidence;
114} 115}
116void Calendar::setDontDeleteIncidencesOnClose ()
117{
118 mDeleteIncidencesOnClose = false;
119}
115void Calendar::setDefaultCalendar( int d ) 120void Calendar::setDefaultCalendar( int d )
116{ 121{
117 mDefaultCalendar = d; 122 mDefaultCalendar = d;
118} 123}
119int Calendar::defaultCalendar() 124int Calendar::defaultCalendar()
120{ 125{
121 return mDefaultCalendar; 126 return mDefaultCalendar;
122} 127}
123const QString &Calendar::getOwner() const 128const QString &Calendar::getOwner() const
124{ 129{
125 return mOwner; 130 return mOwner;
126} 131}
127 132
128bool Calendar::undoDeleteIncidence() 133bool Calendar::undoDeleteIncidence()
129{ 134{
130 if (!mUndoIncidence) 135 if (!mUndoIncidence)
131 return false; 136 return false;
132 addIncidence(mUndoIncidence); 137 addIncidence(mUndoIncidence);
133 mUndoIncidence = 0; 138 mUndoIncidence = 0;
134 return true; 139 return true;
135} 140}
136void Calendar::setOwner(const QString &os) 141void Calendar::setOwner(const QString &os)
137{ 142{
138 int i; 143 int i;
139 mOwner = os; 144 mOwner = os;
140 i = mOwner.find(','); 145 i = mOwner.find(',');
141 if (i != -1) 146 if (i != -1)
142 mOwner = mOwner.left(i); 147 mOwner = mOwner.left(i);
143 148
144 setModified( true ); 149 setModified( true );
145} 150}
146 151
147void Calendar::setTimeZone(const QString & tz) 152void Calendar::setTimeZone(const QString & tz)
148{ 153{
149 bool neg = FALSE; 154 bool neg = FALSE;
150 int hours, minutes; 155 int hours, minutes;
151 QString tmpStr(tz); 156 QString tmpStr(tz);
152 157
153 if (tmpStr.left(1) == "-") 158 if (tmpStr.left(1) == "-")
154 neg = TRUE; 159 neg = TRUE;
155 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 160 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
156 tmpStr.remove(0, 1); 161 tmpStr.remove(0, 1);
157 hours = tmpStr.left(2).toInt(); 162 hours = tmpStr.left(2).toInt();
158 if (tmpStr.length() > 2) 163 if (tmpStr.length() > 2)
159 minutes = tmpStr.right(2).toInt(); 164 minutes = tmpStr.right(2).toInt();
160 else 165 else
161 minutes = 0; 166 minutes = 0;
162 mTimeZone = (60*hours+minutes); 167 mTimeZone = (60*hours+minutes);
163 if (neg) 168 if (neg)
164 mTimeZone = -mTimeZone; 169 mTimeZone = -mTimeZone;
165 mLocalTime = false; 170 mLocalTime = false;
166 171
167 setModified( true ); 172 setModified( true );
168} 173}
169 174
170QString Calendar::getTimeZoneStr() const 175QString Calendar::getTimeZoneStr() const
171{ 176{
172 if (mLocalTime) 177 if (mLocalTime)
173 return ""; 178 return "";
174 QString tmpStr; 179 QString tmpStr;
175 int hours = abs(mTimeZone / 60); 180 int hours = abs(mTimeZone / 60);
176 int minutes = abs(mTimeZone % 60); 181 int minutes = abs(mTimeZone % 60);
177 bool neg = mTimeZone < 0; 182 bool neg = mTimeZone < 0;
178 183
179 tmpStr.sprintf("%c%.2d%.2d", 184 tmpStr.sprintf("%c%.2d%.2d",
180 (neg ? '-' : '+'), 185 (neg ? '-' : '+'),
181 hours, minutes); 186 hours, minutes);
182 return tmpStr; 187 return tmpStr;
183} 188}
184 189
185void Calendar::setTimeZone(int tz) 190void Calendar::setTimeZone(int tz)
186{ 191{
187 mTimeZone = tz; 192 mTimeZone = tz;
188 mLocalTime = false; 193 mLocalTime = false;
189 194
190 setModified( true ); 195 setModified( true );
191} 196}
192 197
193int Calendar::getTimeZone() const 198int Calendar::getTimeZone() const
194{ 199{
195 return mTimeZone; 200 return mTimeZone;
196} 201}
197 202
198void Calendar::setTimeZoneId(const QString &id) 203void Calendar::setTimeZoneId(const QString &id)
199{ 204{
200 mTimeZoneId = id; 205 mTimeZoneId = id;
201 mLocalTime = false; 206 mLocalTime = false;
202 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 207 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
203 if ( mTimeZone > 1000) 208 if ( mTimeZone > 1000)
204 setLocalTime(); 209 setLocalTime();
205 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 210 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
206 setModified( true ); 211 setModified( true );
207} 212}
208 213
209QString Calendar::timeZoneId() const 214QString Calendar::timeZoneId() const
210{ 215{