korganizer

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 Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qapplication.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( QWidget *wid, bool force )
00103 {
00104   bool resized = false;
00105 
00106   int w = wid->frameSize().width();
00107   int h = wid->frameSize().height();
00108 
00109   QRect 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 #if QT_VERSION >= 0x030000
00130   return QApplication::reverseLayout();
00131 #else
00132   return false;
00133 #endif
00134 }
00135 
00136 QPixmap KOGlobals::smallIcon( const QString& name )
00137 {
00138   return SmallIcon( name, mOwnInstance );
00139 }
00140 
00141 QIconSet KOGlobals::smallIconSet( const QString& name, int size )
00142 {
00143   return SmallIconSet( name, size, mOwnInstance );
00144 }
00145 
00146 QStringList KOGlobals::holiday( const QDate &date )
00147 {
00148   QStringList hdays;
00149 
00150   if ( !mHolidays ) return hdays;
00151   QValueList<KHoliday> list = mHolidays->getHolidays( date );
00152   QValueList<KHoliday>::ConstIterator it = list.begin();
00153   for ( ; it != list.end(); ++it ) {
00154     hdays.append( (*it).text );
00155   }
00156   return hdays;
00157 }
00158 
00159 bool KOGlobals::isWorkDay( const QDate &date )
00160 {
00161   int mask( ~( KOPrefs::instance()->mWorkWeekMask ) );
00162 
00163   bool nonWorkDay = ( mask & ( 1 << ( date.dayOfWeek() - 1 ) ) );
00164   if ( KOPrefs::instance()->mExcludeHolidays && mHolidays ) {
00165     QValueList<KHoliday> list = mHolidays->getHolidays( date );
00166     QValueList<KHoliday>::ConstIterator it = list.begin();
00167     for ( ; it != list.end(); ++it ) {
00168       nonWorkDay = nonWorkDay
00169                || ( (*it).Category == KHolidays::HOLIDAY );
00170     }
00171   }
00172   return !nonWorkDay;
00173 }
00174 
00175 void KOGlobals::setHolidays( KHolidays *h )
00176 {
00177   delete mHolidays;
00178   mHolidays = h;
00179 }
00180 
00181 KHolidays *KOGlobals::holidays() const
00182 {
00183   return mHolidays;
00184 }
KDE Home | KDE Accessibility Home | Description of Access Keys