koglobals.cpp
00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2002,2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include <tqapplication.h> 00026 00027 #include <kdebug.h> 00028 #include <kglobal.h> 00029 #include <kconfig.h> 00030 #include <kstandarddirs.h> 00031 #include <kglobalsettings.h> 00032 #include <klocale.h> 00033 #include <kstaticdeleter.h> 00034 #include <kiconloader.h> 00035 00036 #include <kcalendarsystem.h> 00037 #include <kholidays.h> 00038 00039 #include "alarmclient.h" 00040 00041 #include "koglobals.h" 00042 #include "koprefs.h" 00043 #include "korganizer_part.h" 00044 00045 #if 0 // unused 00046 class NopAlarmClient : public AlarmClient 00047 { 00048 public: 00049 void startDaemon() {} 00050 void stopDaemon() {} 00051 }; 00052 #endif 00053 00054 KOGlobals *KOGlobals::mSelf = 0; 00055 00056 static KStaticDeleter<KOGlobals> koGlobalsDeleter; 00057 00058 KOGlobals *KOGlobals::self() 00059 { 00060 if ( !mSelf ) { 00061 koGlobalsDeleter.setObject( mSelf, new KOGlobals ); 00062 } 00063 00064 return mSelf; 00065 } 00066 00067 KOGlobals::KOGlobals() 00068 : mHolidays(0) 00069 { 00070 // Needed to distinguish from global KInstance 00071 // in case we are a KPart 00072 mOwnInstance = new KInstance( "korganizer" ); 00073 mOwnInstance->config()->setGroup( "General" ); 00074 mOwnInstance->iconLoader()->addAppDir( "kdepim" ); 00075 KGlobal::iconLoader()->addAppDir( "kdepim" ); 00076 00077 mAlarmClient = new AlarmClient; 00078 } 00079 00080 KConfig* KOGlobals::config() const 00081 { 00082 return mOwnInstance->config(); 00083 } 00084 00085 KOGlobals::~KOGlobals() 00086 { 00087 delete mAlarmClient; 00088 delete mOwnInstance; 00089 delete mHolidays; 00090 } 00091 00092 const KCalendarSystem *KOGlobals::calendarSystem() const 00093 { 00094 return KGlobal::locale()->calendar(); 00095 } 00096 00097 AlarmClient *KOGlobals::alarmClient() const 00098 { 00099 return mAlarmClient; 00100 } 00101 00102 void KOGlobals::fitDialogToScreen( TQWidget *wid, bool force ) 00103 { 00104 bool resized = false; 00105 00106 int w = wid->frameSize().width(); 00107 int h = wid->frameSize().height(); 00108 00109 TQRect desk = KGlobalSettings::desktopGeometry( wid ); 00110 if ( w > desk.width() ) { 00111 w = desk.width(); 00112 resized = true; 00113 } 00114 // FIXME: ugly hack. Is the -30 really to circumvent the size of kicker?! 00115 if ( h > desk.height() - 30 ) { 00116 h = desk.height() - 30; 00117 resized = true; 00118 } 00119 00120 if ( resized || force ) { 00121 wid->resize( w, h ); 00122 wid->move( desk.x(), desk.y()+15 ); 00123 if ( force ) wid->setFixedSize( w, h ); 00124 } 00125 } 00126 00127 bool KOGlobals::reverseLayout() 00128 { 00129 return TQApplication::reverseLayout(); 00130 } 00131 00132 TQPixmap KOGlobals::smallIcon( const TQString& name ) 00133 { 00134 return SmallIcon( name, mOwnInstance ); 00135 } 00136 00137 TQIconSet KOGlobals::smallIconSet( const TQString& name, int size ) 00138 { 00139 return SmallIconSet( name, size, mOwnInstance ); 00140 } 00141 00142 TQStringList KOGlobals::holiday( const TQDate &date ) 00143 { 00144 TQStringList hdays; 00145 00146 if ( !mHolidays ) return hdays; 00147 TQValueList<KHoliday> list = mHolidays->getHolidays( date ); 00148 TQValueList<KHoliday>::ConstIterator it = list.begin(); 00149 for ( ; it != list.end(); ++it ) { 00150 hdays.append( (*it).text ); 00151 } 00152 return hdays; 00153 } 00154 00155 bool KOGlobals::isWorkDay( const TQDate &date ) 00156 { 00157 int mask( ~( KOPrefs::instance()->mWorkWeekMask ) ); 00158 00159 bool nonWorkDay = ( mask & ( 1 << ( date.dayOfWeek() - 1 ) ) ); 00160 if ( KOPrefs::instance()->mExcludeHolidays && mHolidays ) { 00161 TQValueList<KHoliday> list = mHolidays->getHolidays( date ); 00162 TQValueList<KHoliday>::ConstIterator it = list.begin(); 00163 for ( ; it != list.end(); ++it ) { 00164 nonWorkDay = nonWorkDay 00165 || ( (*it).Category == KHolidays::HOLIDAY ); 00166 } 00167 } 00168 return !nonWorkDay; 00169 } 00170 00171 int KOGlobals::getWorkWeekMask() 00172 { 00173 return KOPrefs::instance()->mWorkWeekMask; 00174 } 00175 00176 void KOGlobals::setHolidays( KHolidays *h ) 00177 { 00178 delete mHolidays; 00179 mHolidays = h; 00180 } 00181 00182 KHolidays *KOGlobals::holidays() const 00183 { 00184 return mHolidays; 00185 }