• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KHolidays Library

holidayparserdriver.cpp

00001 /*
00002   This file is part of the kholidays library.
00003 
00004   Copyright 2010 John Layt <john@layt.net>
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010 
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014   GNU Library General Public License for more details.
00015 
00016   You should have received a copy of the GNU Library General Public License
00017   along with this library; see the file COPYING.LIB.  If not, write to the
00018   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019   Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "holidayparserdriver_p.h"
00023 
00024 #include <KCalendarSystem>
00025 #include <KDebug>
00026 
00027 using namespace KHolidays;
00028 
00029 HolidayParserDriver::HolidayParserDriver( const QString &filePath )
00030 {
00031   m_filePath = filePath;
00032   m_parseCalendar = 0;
00033 }
00034 
00035 HolidayParserDriver::~HolidayParserDriver()
00036 {
00037   delete m_parseCalendar;
00038 }
00039 
00040 QString HolidayParserDriver::fileCountryCode() const
00041 {
00042   return m_fileCountryCode;
00043 }
00044 
00045 QString HolidayParserDriver::fileLanguageCode() const
00046 {
00047   return m_fileLanguageCode;
00048 }
00049 
00050 QString HolidayParserDriver::fileName() const
00051 {
00052   return m_fileName;
00053 }
00054 
00055 QString HolidayParserDriver::fileDescription() const
00056 {
00057   return m_fileDescription;
00058 }
00059 
00060 Holiday::List HolidayParserDriver::parseHolidays( const QDate &startDate, const QDate &endDate )
00061 {
00062   m_resultList.clear();
00063   if ( startDate.isNull() || endDate.isNull() ) {
00064     return m_resultList;
00065   }
00066   m_requestStart = startDate;
00067   m_requestEnd = endDate;
00068   parse();
00069   qSort( m_resultList );
00070   return m_resultList;
00071 }
00072 
00073 Holiday::List HolidayParserDriver::parseHolidays( const QDate &requestDate )
00074 {
00075   return parseHolidays( requestDate, requestDate );
00076 }
00077 
00078 Holiday::List HolidayParserDriver::parseHolidays( int calendarYear, const QString &calendarType )
00079 {
00080   m_resultList.clear();
00081   setParseCalendar( calendarType );
00082   if ( !m_parseCalendar->isValid( calendarYear, 1, 1 ) ) {
00083     return m_resultList;
00084   }
00085 
00086   QDate startDate, endDate;
00087   m_parseCalendar->setDate( startDate, calendarYear, 1, 1 );
00088   endDate = startDate.addDays( m_parseCalendar->daysInYear( startDate ) - 1 );
00089 
00090   return parseHolidays( startDate, endDate );
00091 }
00092 
00093 void HolidayParserDriver::error( const QString &errorMessage )
00094 {
00095   kDebug() << errorMessage;
00096 }
00097 
00098 void HolidayParserDriver::parse()
00099 {
00100 }
00101 
00102 void HolidayParserDriver::parseMetadata()
00103 {
00104 }
00105 
00106 void HolidayParserDriver::setParseCalendar( const QString &calendarType )
00107 {
00108   delete m_parseCalendar;
00109   m_parseCalendar = KCalendarSystem::create( calendarType );
00110 }
00111 
00112 void HolidayParserDriver::setParseStartEnd()
00113 {
00114   // Set start year and end year to generate holidays for
00115   // TODO Maybe make +/- 1 more year to allow spanned holidays from previous/following years
00116   // Make sure requested date range falls within valid date range for current calendar system
00117   if ( m_requestStart > m_parseCalendar->latestValidDate() ||
00118        m_requestEnd < m_parseCalendar->earliestValidDate() ) {
00119     // Completely out of range, don't parse
00120     m_parseStartYear = 0;
00121     m_parseEndYear = m_parseStartYear - 1;
00122   } else {
00123     if ( m_requestStart < m_parseCalendar->earliestValidDate() ) {
00124       m_parseStartYear = m_parseCalendar->year( m_parseCalendar->earliestValidDate() );
00125     } else {
00126       m_parseStartYear = m_parseCalendar->year( m_requestStart );
00127     }
00128 
00129     if ( m_requestEnd > m_parseCalendar->latestValidDate() ) {
00130       m_parseEndYear = m_parseCalendar->year( m_parseCalendar->latestValidDate() );
00131     } else {
00132       m_parseEndYear = m_parseCalendar->year( m_requestEnd );
00133     }
00134   }
00135 }

KHolidays Library

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal