// This file is generated by kxml_compiler from kde-holidays.rng.
// All changes you do to this file will be lost.
/*
    This file is part of KDE.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
 */

#include "kde-holidays.h"

#include <kdebug.h>
#include <QTextStream>
#include <QFile>
#include <QTextStream>

QString indent( int n = 0 )
{
  static int i = 0;
  i += n;
  QString space;
  return space.fill( ' ', i );
}

void Description::setLanguage( const QString &v )
{
  mLanguage = v;
}

QString Description::language() const
{
  return mLanguage;
}

QString Description::writeElement()
{
  QString xml;
  xml += indent() + "<description language=\"" + language() + "\">\n";
  indent( 2 );
  indent( -2 );
  xml += indent() + "</description>\n";
  return xml;
}


void Name::setLanguage( const QString &v )
{
  mLanguage = v;
}

QString Name::language() const
{
  return mLanguage;
}

QString Name::writeElement()
{
  QString xml;
  xml += indent() + "<name language=\"" + language() + "\">\n";
  indent( 2 );
  indent( -2 );
  xml += indent() + "</name>\n";
  return xml;
}


void Holiday::setType( const QString &v )
{
  mType = v;
}

QString Holiday::type() const
{
  return mType;
}

void Holiday::setWorkDayOff( const QString &v )
{
  mWorkDayOff = v;
}

QString Holiday::workDayOff() const
{
  return mWorkDayOff;
}

void Holiday::setSchoolDayOff( const QString &v )
{
  mSchoolDayOff = v;
}

QString Holiday::schoolDayOff() const
{
  return mSchoolDayOff;
}

void Holiday::setBankClosed( const QString &v )
{
  mBankClosed = v;
}

QString Holiday::bankClosed() const
{
  return mBankClosed;
}

void Holiday::setLength( const QString &v )
{
  mLength = v;
}

QString Holiday::length() const
{
  return mLength;
}

void Holiday::setIcon( const QString &v )
{
  mIcon = v;
}

QString Holiday::icon() const
{
  return mIcon;
}

void Holiday::setName( const QString &v )
{
  mName = v;
}

QString Holiday::name() const
{
  return mName;
}

void Holiday::setDatespec( const QString &v )
{
  mDatespec = v;
}

QString Holiday::datespec() const
{
  return mDatespec;
}

void Holiday::setDescription( const QString &v )
{
  mDescription = v;
}

QString Holiday::description() const
{
  return mDescription;
}

QString Holiday::writeElement()
{
  QString xml;
  xml += indent() + "<holiday type=\"" + type() + "\" workDayOff=\"" + workDayOff() + "\" schoolDayOff=\"" + schoolDayOff() + "\" bankClosed=\"" + bankClosed() + "\" length=\"" + length() + "\" icon=\"" + icon() + "\">\n";
  indent( 2 );
  xml += indent() + "<name>" + name() + "</name>\n";
  xml += indent() + "<datespec>" + datespec() + "</datespec>\n";
  xml += indent() + "<description>" + description() + "</description>\n";
  indent( -2 );
  xml += indent() + "</holiday>\n";
  return xml;
}


void HolidayCalendar::setName( const QString &v )
{
  mName = v;
}

QString HolidayCalendar::name() const
{
  return mName;
}

void HolidayCalendar::setType( const QString &v )
{
  mType = v;
}

QString HolidayCalendar::type() const
{
  return mType;
}

void HolidayCalendar::setCalendar( const QString &v )
{
  mCalendar = v;
}

QString HolidayCalendar::calendar() const
{
  return mCalendar;
}

void HolidayCalendar::setHemisphere( const QString &v )
{
  mHemisphere = v;
}

QString HolidayCalendar::hemisphere() const
{
  return mHemisphere;
}

void HolidayCalendar::setIcon( const QString &v )
{
  mIcon = v;
}

QString HolidayCalendar::icon() const
{
  return mIcon;
}

void HolidayCalendar::setInclude( const QString &v )
{
  mInclude = v;
}

QString HolidayCalendar::include() const
{
  return mInclude;
}

void HolidayCalendar::addHoliday( const Holiday &v )
{
  mHolidayList.append( v );
}

void HolidayCalendar::setHolidayList( const Holiday::List &v )
{
  mHolidayList = v;
}

Holiday::List HolidayCalendar::holidayList() const
{
  return mHolidayList;
}

QString HolidayCalendar::writeElement()
{
  QString xml;
  xml += indent() + "<holidayCalendar name=\"" + name() + "\" type=\"" + type() + "\" calendar=\"" + calendar() + "\" hemisphere=\"" + hemisphere() + "\" icon=\"" + icon() + "\" include=\"" + include() + "\">\n";
  indent( 2 );
  foreach( Holiday e, holidayList() ) {
    xml += e.writeElement();
  }
  indent( -2 );
  xml += indent() + "</holidayCalendar>\n";
  return xml;
}

bool HolidayCalendar::writeFile( const QString &filename )
{
  QFile file( filename );
  if ( !file.open( QIODevice::WriteOnly ) ) {
    kError() << "Unable to open file '" << filename << "'";
    return false;
  }

  QTextStream ts( &file );
  ts << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  ts << writeElement();
  file.close();

  return true;
}


