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 
00076   mAlarmClient = new AlarmClient;
00077 }
00078 
00079 KConfig* KOGlobals::config() const
00080 {
00081   return mOwnInstance->config();
00082 }
00083 
00084 KOGlobals::~KOGlobals()
00085 {
00086   delete mAlarmClient;
00087   delete mOwnInstance;
00088   delete mHolidays;
00089 }
00090 
00091 const KCalendarSystem *KOGlobals::calendarSystem() const
00092 {
00093   return KGlobal::locale()->calendar();
00094 }
00095 
00096 AlarmClient *KOGlobals::alarmClient() const
00097 {
00098   return mAlarmClient;
00099 }
00100 
00101 void KOGlobals::fitDialogToScreen( QWidget *wid, bool force )
00102 {
00103   bool resized = false;
00104 
00105   int w = wid->frameSize().width();
00106   int h = wid->frameSize().height();
00107 
00108   QRect desk = KGlobalSettings::desktopGeometry( wid );
00109   if ( w > desk.width() ) {
00110     w = desk.width();
00111     resized = true;
00112   }
00113   // FIXME: ugly hack.  Is the -30 really to circumvent the size of kicker?!
00114   if ( h > desk.height() - 30 ) {
00115     h = desk.height() - 30;
00116     resized = true;
00117   }
00118 
00119   if ( resized || force ) {
00120     wid->resize( w, h );
00121     wid->move( desk.x(), desk.y()+15 );
00122     if ( force ) wid->setFixedSize( w, h );
00123   }
00124 }
00125 
00126 bool KOGlobals::reverseLayout()
00127 {
00128 #if QT_VERSION >= 0x030000
00129   return QApplication::reverseLayout();
00130 #else
00131   return false;
00132 #endif
00133 }
00134 
00135 QPixmap KOGlobals::smallIcon( const QString& name )
00136 {
00137   return SmallIcon( name, mOwnInstance );
00138 }
00139 
00140 QIconSet KOGlobals::smallIconSet( const QString& name, int size )
00141 {
00142   return SmallIconSet( name, size, mOwnInstance );
00143 }
00144 
00145 QStringList KOGlobals::holiday( const QDate &date )
00146 {
00147   QStringList hdays;
00148 
00149   if ( !mHolidays ) return hdays;
00150   QValueList<KHoliday> list = mHolidays->getHolidays( date );
00151   QValueList<KHoliday>::ConstIterator it = list.begin();
00152   for ( ; it != list.end(); ++it ) {
00153     hdays.append( (*it).text );
00154   }
00155   return hdays;
00156 }
00157 
00158 bool KOGlobals::isWorkDay( const QDate &date )
00159 {
00160   int mask( ~( KOPrefs::instance()->mWorkWeekMask ) );
00161 
00162   bool nonWorkDay = ( mask & ( 1 << ( date.dayOfWeek() - 1 ) ) );
00163   if ( KOPrefs::instance()->mExcludeHolidays && mHolidays ) {
00164     QValueList<KHoliday> list = mHolidays->getHolidays( date );
00165     QValueList<KHoliday>::ConstIterator it = list.begin();
00166     for ( ; it != list.end(); ++it ) {
00167       nonWorkDay = nonWorkDay
00168                || ( (*it).Category == KHolidays::HOLIDAY );
00169     }
00170   }
00171   return !nonWorkDay;
00172 }
00173 
00174 void KOGlobals::setHolidays( KHolidays *h )
00175 {
00176   delete mHolidays;
00177   mHolidays = h;
00178 }
00179 
00180 KHolidays *KOGlobals::holidays() const
00181 {
00182   return mHolidays;
00183 }
KDE Home | KDE Accessibility Home | Description of Access Keys