korganizer

koglobals.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2002,2003 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program 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
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <tqapplication.h>
26 
27 #include <kdebug.h>
28 #include <tdeglobal.h>
29 #include <tdeconfig.h>
30 #include <kstandarddirs.h>
31 #include <tdeglobalsettings.h>
32 #include <tdelocale.h>
33 #include <kstaticdeleter.h>
34 #include <kiconloader.h>
35 
36 #include <kcalendarsystem.h>
37 #include <kholidays.h>
38 
39 #include "alarmclient.h"
40 
41 #include "koglobals.h"
42 #include "koprefs.h"
43 #include "korganizer_part.h"
44 
45 #if 0 // unused
46 class NopAlarmClient : public AlarmClient
47 {
48  public:
49  void startDaemon() {}
50  void stopDaemon() {}
51 };
52 #endif
53 
54 KOGlobals *KOGlobals::mSelf = 0;
55 
56 static KStaticDeleter<KOGlobals> koGlobalsDeleter;
57 
58 KOGlobals *KOGlobals::self()
59 {
60  if ( !mSelf ) {
61  koGlobalsDeleter.setObject( mSelf, new KOGlobals );
62  }
63 
64  return mSelf;
65 }
66 
67 KOGlobals::KOGlobals()
68  : mHolidays(0)
69 {
70  // Needed to distinguish from global TDEInstance
71  // in case we are a KPart
72  mOwnInstance = new TDEInstance( "korganizer" );
73  mOwnInstance->config()->setGroup( "General" );
74  mOwnInstance->iconLoader()->addAppDir( "tdepim" );
75  TDEGlobal::iconLoader()->addAppDir( "tdepim" );
76 
77  mAlarmClient = new AlarmClient;
78 }
79 
80 TDEConfig* KOGlobals::config() const
81 {
82  return mOwnInstance->config();
83 }
84 
85 KOGlobals::~KOGlobals()
86 {
87  delete mAlarmClient;
88  delete mOwnInstance;
89  delete mHolidays;
90 }
91 
92 const KCalendarSystem *KOGlobals::calendarSystem() const
93 {
94  return TDEGlobal::locale()->calendar();
95 }
96 
97 AlarmClient *KOGlobals::alarmClient() const
98 {
99  return mAlarmClient;
100 }
101 
102 void KOGlobals::fitDialogToScreen( TQWidget *wid, bool force )
103 {
104  bool resized = false;
105 
106  int w = wid->frameSize().width();
107  int h = wid->frameSize().height();
108 
109  TQRect desk = TDEGlobalSettings::desktopGeometry( wid );
110  if ( w > desk.width() ) {
111  w = desk.width();
112  resized = true;
113  }
114  // FIXME: ugly hack. Is the -30 really to circumvent the size of kicker?!
115  if ( h > desk.height() - 30 ) {
116  h = desk.height() - 30;
117  resized = true;
118  }
119 
120  if ( resized || force ) {
121  wid->resize( w, h );
122  wid->move( desk.x(), desk.y()+15 );
123  if ( force ) wid->setFixedSize( w, h );
124  }
125 }
126 
127 bool KOGlobals::reverseLayout()
128 {
129  return TQApplication::reverseLayout();
130 }
131 
132 TQPixmap KOGlobals::smallIcon( const TQString& name )
133 {
134  return SmallIcon( name, mOwnInstance );
135 }
136 
137 TQIconSet KOGlobals::smallIconSet( const TQString& name, int size )
138 {
139  return SmallIconSet( name, size, mOwnInstance );
140 }
141 
142 TQStringList KOGlobals::holiday( const TQDate &date )
143 {
144  TQStringList hdays;
145 
146  if ( !mHolidays ) return hdays;
147  TQValueList<KHoliday> list = mHolidays->getHolidays( date );
148  TQValueList<KHoliday>::ConstIterator it = list.begin();
149  for ( ; it != list.end(); ++it ) {
150  hdays.append( (*it).text );
151  }
152  return hdays;
153 }
154 
155 bool KOGlobals::isWorkDay( const TQDate &date )
156 {
157  int mask( ~( KOPrefs::instance()->mWorkWeekMask ) );
158 
159  bool nonWorkDay = ( mask & ( 1 << ( date.dayOfWeek() - 1 ) ) );
160  if ( KOPrefs::instance()->mExcludeHolidays && mHolidays ) {
161  TQValueList<KHoliday> list = mHolidays->getHolidays( date );
162  TQValueList<KHoliday>::ConstIterator it = list.begin();
163  for ( ; it != list.end(); ++it ) {
164  nonWorkDay = nonWorkDay
165  || ( (*it).Category == KHolidays::HOLIDAY );
166  }
167  }
168  return !nonWorkDay;
169 }
170 
171 int KOGlobals::getWorkWeekMask()
172 {
173  return KOPrefs::instance()->mWorkWeekMask;
174 }
175 
176 void KOGlobals::setHolidays( KHolidays *h )
177 {
178  delete mHolidays;
179  mHolidays = h;
180 }
181 
182 KHolidays *KOGlobals::holidays() const
183 {
184  return mHolidays;
185 }