00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "holidayparserdriverplanold_p.h"
00023
00024 #include <QStringList>
00025 #include <QFileInfo>
00026
00027 #include <KCalendarSystem>
00028 #include <kdebug.h>
00029
00030 #include "holiday_p.h"
00031
00032
00033 extern "C" {
00034 #ifdef Q_OS_WIN32
00035 KHOLIDAYS_EXPORT char *parse_holidays( const char *, int year, short force );
00036 #else
00037 char *parse_holidays( const char *, int year, short force );
00038 #endif
00039
00040 struct holiday {
00041 char *string;
00042 int color;
00043 unsigned short dup;
00044 holiday *next;
00045 };
00046
00047 #ifdef Q_OS_WIN32
00048 KHOLIDAYS_EXPORT extern struct holiday holidays[366];
00049 #else
00050 extern struct holiday holidays[366];
00051 #endif
00052 }
00053
00054 using namespace KHolidays;
00055
00056 HolidayParserDriverPlanOld::HolidayParserDriverPlanOld( const QString &planFilePath )
00057 :HolidayParserDriver( planFilePath )
00058 {
00059 parseMetadata();
00060 }
00061
00062 HolidayParserDriverPlanOld::~HolidayParserDriverPlanOld()
00063 {
00064 }
00065
00066 void HolidayParserDriverPlanOld::error( const QString &errorMessage )
00067 {
00068 kDebug() << errorMessage;
00069 }
00070
00071 void HolidayParserDriverPlanOld::parse()
00072 {
00073
00074 setParseCalendar( "gregorian" );
00075
00076 setParseStartEnd();
00077
00078 QDate thisDate;
00079
00080
00081 for ( m_parseYear = m_parseStartYear; m_parseYear <= m_parseEndYear; ++m_parseYear ) {
00082
00083 QDate parseYearStart;
00084 m_parseCalendar->setDate( parseYearStart, m_parseYear, 1, 1 );
00085
00086
00087 parse_holidays( QFile::encodeName( m_filePath ), m_parseYear - 1900, 1 );
00088
00089
00090 for ( int i = 0; i < 366; ++i ) {
00091 struct holiday *hd = &::holidays[i];
00092 thisDate = parseYearStart.addDays(i);
00093
00094 if ( thisDate >= m_requestStart && thisDate <= m_requestEnd ) {
00095 while ( hd ) {
00096 if ( hd->string ) {
00097 Holiday holiday;
00098 holiday.d->mObservedDate = thisDate;
00099 holiday.d->mText = QString::fromUtf8( hd->string );
00100 holiday.d->mShortText = holiday.d->mText;
00101 if ( hd->color == 2 || hd->color == 9 ) {
00102 holiday.d->mDayType = Holiday::NonWorkday;
00103 } else {
00104 holiday.d->mDayType = Holiday::Workday;
00105 }
00106 m_resultList.append( holiday );
00107 }
00108 hd = hd->next;
00109 }
00110 }
00111 }
00112 }
00113 }
00114
00115 void HolidayParserDriverPlanOld::parseMetadata()
00116 {
00117
00118
00119 m_fileCountryCode.clear();
00120 m_fileLanguageCode.clear();
00121 m_fileName.clear();
00122 m_fileDescription.clear();
00123
00124 QFileInfo file( m_filePath );
00125 if ( file.exists() ) {
00126 QStringList metadata = file.fileName().split('_');
00127 if ( metadata[0] == "holiday" && metadata.count() > 2 ) {
00128 m_fileCountryCode = metadata[1].toUpper();
00129 QStringList language = metadata[2].split('-');
00130 m_fileLanguageCode = language[0];
00131 if ( language.count() > 1 ) {
00132 m_fileLanguageCode.append( '_' ).append( language[1].toUpper() );
00133 }
00134 if ( metadata.count() > 3 ) {
00135 m_fileName = metadata[3];
00136 }
00137 }
00138 }
00139 }