• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • 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                                                   Holiday::MultidayMode multidayMode )
00062 {
00063   m_multidayMode = multidayMode;
00064   m_resultList.clear();
00065   if ( startDate.isNull() || endDate.isNull() ) {
00066     return m_resultList;
00067   }
00068   m_requestStart = startDate;
00069   m_requestEnd = endDate;
00070   parse();
00071   qSort( m_resultList );
00072   return m_resultList;
00073 }
00074 
00075 Holiday::List HolidayParserDriver::parseHolidays( const QDate &requestDate,
00076                                                   Holiday::MultidayMode multidayMode )
00077 {
00078   return parseHolidays( requestDate, requestDate, multidayMode );
00079 }
00080 
00081 Holiday::List HolidayParserDriver::parseHolidays( int calendarYear, const QString &calendarType,
00082                                                   Holiday::MultidayMode multidayMode )
00083 {
00084   m_resultList.clear();
00085   setParseCalendar( calendarType );
00086   if ( !m_parseCalendar->isValid( calendarYear, 1, 1 ) ) {
00087     return m_resultList;
00088   }
00089 
00090   QDate startDate, endDate;
00091   m_parseCalendar->setDate( startDate, calendarYear, 1, 1 );
00092   endDate = startDate.addDays( m_parseCalendar->daysInYear( startDate ) - 1 );
00093 
00094   return parseHolidays( startDate, endDate, multidayMode );
00095 }
00096 
00097 void HolidayParserDriver::error( const QString &errorMessage )
00098 {
00099   kDebug() << errorMessage;
00100 }
00101 
00102 void HolidayParserDriver::parse()
00103 {
00104 }
00105 
00106 void HolidayParserDriver::parseMetadata()
00107 {
00108 }
00109 
00110 void HolidayParserDriver::setParseCalendar( const QString &calendarType )
00111 {
00112   delete m_parseCalendar;
00113   m_parseCalendar = KCalendarSystem::create( calendarType );
00114 }
00115 
00116 void HolidayParserDriver::setParseStartEnd()
00117 {
00118   // Set start year and end year to generate holidays for
00119   // TODO Maybe make +/- 1 more year to allow spanned holidays from previous/following years
00120   // Make sure requested date range falls within valid date range for current calendar system
00121   if ( m_requestStart > m_parseCalendar->latestValidDate() ||
00122        m_requestEnd < m_parseCalendar->earliestValidDate() ) {
00123     // Completely out of range, don't parse
00124     m_parseStartYear = 0;
00125     m_parseEndYear = m_parseStartYear - 1;
00126   } else {
00127     if ( m_requestStart < m_parseCalendar->earliestValidDate() ) {
00128       m_parseStartYear = m_parseCalendar->year( m_parseCalendar->earliestValidDate() );
00129     } else {
00130       m_parseStartYear = m_parseCalendar->year( m_requestStart );
00131     }
00132 
00133     if ( m_requestEnd > m_parseCalendar->latestValidDate() ) {
00134       m_parseEndYear = m_parseCalendar->year( m_parseCalendar->latestValidDate() );
00135     } else {
00136       m_parseEndYear = m_parseCalendar->year( m_requestEnd );
00137     }
00138   }
00139 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 7 2012 23:54:54 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHolidays Library

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

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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