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
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
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 }
|