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

KHolidays Library

  • 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 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:25:09 by doxygen 1.8.3.1 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-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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