2 This file is part of KOrganizer.
4 Copyright (c) 2002,2003 Cornelius Schumacher <schumacher@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
25 #include "koglobals.h"
26 #include "prefs/koprefs.h"
28 #include <KHolidays/HolidayRegion>
30 #include <KIconLoader>
32 #include <QApplication>
34 class KOGlobalsSingletonPrivate
40 Q_GLOBAL_STATIC(KOGlobalsSingletonPrivate
, sKOGlobalsSingletonPrivate
)
42 KOGlobals
*KOGlobals::self()
44 return &sKOGlobalsSingletonPrivate
->instance
;
47 KOGlobals::KOGlobals() : mHolidays(Q_NULLPTR
)
51 KOGlobals::~KOGlobals()
56 bool KOGlobals::reverseLayout()
58 return QApplication::isRightToLeft();
61 QPixmap
KOGlobals::smallIcon(const QString
&name
) const
63 return SmallIcon(name
);
66 QMap
<QDate
, QStringList
> KOGlobals::holiday(const QDate
&start
, const QDate
&end
) const
68 QMap
<QDate
, QStringList
> holidaysByDate
;
71 return holidaysByDate
;
74 const KHolidays::Holiday::List list
= mHolidays
->holidays(start
, end
);
75 for (int i
= 0; i
< list
.count(); ++i
) {
76 const KHolidays::Holiday
&h
= list
.at(i
);
77 holidaysByDate
[h
.observedStartDate()].append(h
.name());
79 return holidaysByDate
;
82 QList
<QDate
> KOGlobals::workDays(const QDate
&startDate
,
83 const QDate
&endDate
) const
87 const int mask(~(KOPrefs::instance()->mWorkWeekMask
));
88 const int numDays
= startDate
.daysTo(endDate
) + 1;
90 for (int i
= 0; i
< numDays
; ++i
) {
91 const QDate date
= startDate
.addDays(i
);
92 if (!(mask
& (1 << (date
.dayOfWeek() - 1)))) {
97 if (mHolidays
&& KOPrefs::instance()->mExcludeHolidays
) {
98 const KHolidays::Holiday::List list
= mHolidays
->holidays(startDate
, endDate
);
99 for (int i
= 0; i
< list
.count(); ++i
) {
100 const KHolidays::Holiday
&h
= list
.at(i
);
101 const QString dateString
= h
.observedStartDate().toString();
102 if (h
.dayType() == KHolidays::Holiday::NonWorkday
) {
103 result
.removeAll(h
.observedStartDate());
111 int KOGlobals::getWorkWeekMask()
113 return KOPrefs::instance()->mWorkWeekMask
;
116 void KOGlobals::setHolidays(KHolidays::HolidayRegion
*h
)
122 KHolidays::HolidayRegion
*KOGlobals::holidays() const