• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KHolidays Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kholidays
  • parsers
holidayparserdriver.cpp
1 /*
2  This file is part of the kholidays library.
3 
4  Copyright 2010 John Layt <john@layt.net>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library 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 Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "holidayparserdriver_p.h"
23 
24 #include <KCalendarSystem>
25 #include <KDebug>
26 
27 using namespace KHolidays;
28 
29 HolidayParserDriver::HolidayParserDriver( const QString &filePath )
30 {
31  m_filePath = filePath;
32  m_parseCalendar = 0;
33 }
34 
35 HolidayParserDriver::~HolidayParserDriver()
36 {
37  delete m_parseCalendar;
38 }
39 
40 QString HolidayParserDriver::fileCountryCode() const
41 {
42  return m_fileCountryCode;
43 }
44 
45 QString HolidayParserDriver::fileLanguageCode() const
46 {
47  return m_fileLanguageCode;
48 }
49 
50 QString HolidayParserDriver::fileName() const
51 {
52  return m_fileName;
53 }
54 
55 QString HolidayParserDriver::fileDescription() const
56 {
57  return m_fileDescription;
58 }
59 
60 Holiday::List HolidayParserDriver::parseHolidays( const QDate &startDate, const QDate &endDate,
61  Holiday::MultidayMode multidayMode )
62 {
63  m_multidayMode = multidayMode;
64  m_resultList.clear();
65  if ( startDate.isNull() || endDate.isNull() ) {
66  return m_resultList;
67  }
68  m_requestStart = startDate;
69  m_requestEnd = endDate;
70  parse();
71  qSort( m_resultList );
72  return m_resultList;
73 }
74 
75 Holiday::List HolidayParserDriver::parseHolidays( const QDate &requestDate,
76  Holiday::MultidayMode multidayMode )
77 {
78  return parseHolidays( requestDate, requestDate, multidayMode );
79 }
80 
81 Holiday::List HolidayParserDriver::parseHolidays( int calendarYear, const QString &calendarType,
82  Holiday::MultidayMode multidayMode )
83 {
84  m_resultList.clear();
85  setParseCalendar( calendarType );
86  if ( !m_parseCalendar->isValid( calendarYear, 1, 1 ) ) {
87  return m_resultList;
88  }
89 
90  QDate startDate, endDate;
91  m_parseCalendar->setDate( startDate, calendarYear, 1, 1 );
92  endDate = startDate.addDays( m_parseCalendar->daysInYear( startDate ) - 1 );
93 
94  return parseHolidays( startDate, endDate, multidayMode );
95 }
96 
97 void HolidayParserDriver::error( const QString &errorMessage )
98 {
99  kDebug() << errorMessage;
100 }
101 
102 void HolidayParserDriver::parse()
103 {
104 }
105 
106 void HolidayParserDriver::parseMetadata()
107 {
108 }
109 
110 void HolidayParserDriver::setParseCalendar( const QString &calendarType )
111 {
112  delete m_parseCalendar;
113  m_parseCalendar = KCalendarSystem::create( calendarType );
114 }
115 
116 void HolidayParserDriver::setParseStartEnd()
117 {
118  // Set start year and end year to generate holidays for
119  // TODO Maybe make +/- 1 more year to allow spanned holidays from previous/following years
120  // Make sure requested date range falls within valid date range for current calendar system
121  if ( m_requestStart > m_parseCalendar->latestValidDate() ||
122  m_requestEnd < m_parseCalendar->earliestValidDate() ) {
123  // Completely out of range, don't parse
124  m_parseStartYear = 0;
125  m_parseEndYear = m_parseStartYear - 1;
126  } else {
127  if ( m_requestStart < m_parseCalendar->earliestValidDate() ) {
128  m_parseStartYear = m_parseCalendar->year( m_parseCalendar->earliestValidDate() );
129  } else {
130  m_parseStartYear = m_parseCalendar->year( m_requestStart );
131  }
132 
133  if ( m_requestEnd > m_parseCalendar->latestValidDate() ) {
134  m_parseEndYear = m_parseCalendar->year( m_parseCalendar->latestValidDate() );
135  } else {
136  m_parseEndYear = m_parseCalendar->year( m_requestEnd );
137  }
138  }
139 }
KHolidays::HolidayParserDriver::setParseStartEnd
virtual void setParseStartEnd()
Initialise parse year variables for calendar system.
Definition: holidayparserdriver.cpp:116
KHolidays::HolidayParserDriver::parseMetadata
virtual void parseMetadata()
Parse the file for metadata only and populate the metadata variables.
Definition: holidayparserdriver.cpp:106
KHolidays::HolidayParserDriver::error
virtual void error(const QString &errorMessage)
Standard error message handling.
Definition: holidayparserdriver.cpp:97
KHolidays::HolidayParserDriver::fileName
virtual QString fileName() const
Return the untranslated name of the file.
Definition: holidayparserdriver.cpp:50
KHolidays::HolidayParserDriver::HolidayParserDriver
HolidayParserDriver(const QString &filePath)
Constructor of abstract holiday file parser driver class.
Definition: holidayparserdriver.cpp:29
KHolidays::HolidayParserDriver::fileCountryCode
virtual QString fileCountryCode() const
Return the ISO 3166 country/region code of the file.
Definition: holidayparserdriver.cpp:40
KHolidays::HolidayParserDriver::parse
virtual void parse()
Actually parse the file, must be re-implemented by derived classes.
Definition: holidayparserdriver.cpp:102
KHolidays::HolidayParserDriver::parseHolidays
virtual Holiday::List parseHolidays(const QDate &startDate, const QDate &endDate, Holiday::MultidayMode multidayMode)
Return a list of holidays falling between any two dates.
Definition: holidayparserdriver.cpp:60
KHolidays::HolidayParserDriver::fileLanguageCode
virtual QString fileLanguageCode() const
Return the ISO 639-1 language code of the file.
Definition: holidayparserdriver.cpp:45
KHolidays::HolidayParserDriver::setParseCalendar
virtual void setParseCalendar(const QString &calendarType)
Set the calendar system to use.
Definition: holidayparserdriver.cpp:110
KHolidays::HolidayParserDriver::fileDescription
virtual QString fileDescription() const
Return the untranslated description of the file if available.
Definition: holidayparserdriver.cpp:55
KHolidays::HolidayParserDriver::~HolidayParserDriver
virtual ~HolidayParserDriver()
Destructor.
Definition: holidayparserdriver.cpp:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHolidays Library

Skip menu "KHolidays Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal