22 #include <tdeapplication.h>
23 #include <kstandarddirs.h>
26 #include "kholidays.h"
27 #include "kholidays_version.h"
30 char *parse_holidays(
const char *,
int year,
short force );
38 extern struct holiday holidays[366];
41 TQStringList KHolidays::locations()
44 TDEGlobal::dirs()->findAllResources(
"data",
"libkholidays/" + generateFileName(
"*" ),
48 TQStringList::ConstIterator it;
49 for ( it = files.begin(); it != files.end(); ++it )
50 locs.append( (*it).mid((*it).findRev(
'_') + 1) );
55 TQString KHolidays::fileForLocation(
const TQString &location )
57 return locate(
"data",
"libkholidays/" + generateFileName( location ) );
60 TQString KHolidays::userPath(
bool create )
62 return TDEGlobal::dirs()->saveLocation(
"data",
"libkholidays/", create );
65 TQString KHolidays::generateFileName(
const TQString &location )
67 return "holiday_" + location;
73 KHolidays::KHolidays(
const TQString& location )
74 : mLocation( location )
76 mHolidayFile = fileForLocation( location );
81 KHolidays::~KHolidays()
85 TQString KHolidays::location()
const
90 TQString KHolidays::shortText(
const TQDate &date )
92 TQValueList<KHoliday> lst = getHolidays( date );
94 return lst.first().text;
95 else return TQString();
98 bool KHolidays::parseFile(
const TQDate &date )
103 if ( mHolidayFile.isNull() || mHolidayFile.isEmpty() || date.isNull() || !date.isValid() )
106 if ( ( date.year() != mYearLast ) || ( mYearLast == 0 ) ) {
108 mYearLast = date.year();
109 lastYear = date.year() - 1900;
110 parse_holidays( TQFile::encodeName( mHolidayFile ), lastYear, 1 );
116 TQString KHolidays::getHoliday(
const TQDate &date )
118 TQValueList<KHoliday> lst = getHolidays( date );
119 if ( !lst.isEmpty() )
120 return lst.first().text;
121 else return TQString();
124 TQValueList<KHoliday> KHolidays::getHolidays(
const TQDate &date )
126 TQValueList<KHoliday> list;
127 if ( !date.isValid() ) {
131 if ( !parseFile( date ) )
return list;
132 struct holiday *hd = &holidays[date.dayOfYear()-1];
136 holiday.text = TQString::fromUtf8( hd->string );
137 holiday.shortText = holiday.text;
138 holiday.Category = (hd->color == 2) || (hd->color == 9) ? HOLIDAY : WORKDAY;
139 list.append( holiday );
146 int KHolidays::category(
const TQDate &date )
148 if ( !parseFile(date) )
return WORKDAY;
150 return (holidays[date.dayOfYear()-1].color == 2) ||
151 (holidays[date.dayOfYear()-1].color == 9) ? HOLIDAY : WORKDAY;