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