korganizer
koglobals.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00071
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
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 }
|