home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kcalendarsystem.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  10.4 KB  |  358 lines

  1. /*
  2.    Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
  3.    Copyright (c) 2002-2003 Hans Petter Bieker <bieker@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.    Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KCALENDARSYSTEM_H
  22. #define KCALENDARSYSTEM_H
  23.  
  24. #include <qdatetime.h>
  25. #include <qstring.h>
  26. #include "kdelibs_export.h"
  27.  
  28. class KLocale;
  29.  
  30. class KCalendarSystemPrivate;
  31.  
  32. /**
  33.  * CalendarSystem abstract class, default derived kde gregorian class and
  34.  * factory class. Provides support for different calendar types for kde
  35.  * calendar widget and related stuff.
  36.  *
  37.  * Derived classes must be created through KCalendarFactory class
  38.  *
  39.  * @author Carlos Moro <cfmoro@correo.uniovi.es>
  40.  * @since 3.2
  41.  */
  42. class KDECORE_EXPORT KCalendarSystem
  43. {
  44. public:
  45.   /**
  46.    * Constructor of abstract calendar class. This will be called by the derived classes.
  47.    *
  48.    * @param locale It will use this locale for translations, 0 means global.
  49.    */
  50.   KCalendarSystem(const KLocale * locale = 0);
  51.  
  52.   /**
  53.    * Descructor.
  54.    */
  55.   virtual ~KCalendarSystem();
  56.  
  57.   /**
  58.    * Gets specific calendar type year for a given gregorian date
  59.    *
  60.    * @param date gregorian date
  61.    * @return year
  62.    */
  63.   virtual int year (const QDate & date) const = 0;
  64.  
  65.   /**
  66.    * Converts a date into a year literal
  67.    *
  68.    * @param pDate The date to convert
  69.    * @param bShort If the short version of should be used
  70.    * @return The year literal of the date
  71.    */
  72.   virtual QString yearString(const QDate & pDate, bool bShort) const;
  73.  
  74.   /**
  75.    * Converts a year literal of a part of a string into a integer starting at the beginning of the string
  76.    *
  77.    * @param sNum The string to parse
  78.    * @param iLength The number of QChars used, and 0 if no valid symbols was found in the string
  79.    * @return An integer corresponding to the year
  80.    */
  81.   virtual int yearStringToInteger(const QString & sNum, int & iLength) const;
  82.  
  83.   /**
  84.    * Gets specific calendar type month for a given gregorian date
  85.    *
  86.    * @param date gregorian date
  87.    * @return month number
  88.    */
  89.   virtual int month (const QDate & date) const = 0;
  90.  
  91.   /**
  92.    * Converts a date into a month literal
  93.    *
  94.    * @param pDate The date to convert
  95.    * @param bShort If the short version of should be used
  96.    * @return The month literal of the date
  97.    */
  98.   virtual QString monthString(const QDate & pDate, bool bShort) const;
  99.  
  100.   /**
  101.    * Converts a month literal of a part of a string into a integer starting at the beginning of the string
  102.    *
  103.    * @param sNum The string to parse
  104.    * @param iLength The number of QChars used, and 0 if no valid symbols was found in the string
  105.    * @return An integer corresponding to the month
  106.    */
  107.   virtual int monthStringToInteger(const QString & sNum, int & iLength) const;
  108.  
  109.   /**
  110.    * Gets specific calendar type day number of month for a given date
  111.    *
  112.    * @param date gregorian date equivalent to the specific one
  113.    * @return day of the month
  114.    */
  115.   virtual int day (const QDate & date) const = 0;
  116.  
  117.   /**
  118.    * Converts a date into a day literal
  119.    *
  120.    * @param pDate The date to convert
  121.    * @param bShort If the short version of should be used
  122.    * @return The day literal of the date
  123.    */
  124.   virtual QString dayString(const QDate & pDate, bool bShort) const;
  125.  
  126.   /**
  127.    * Converts a day literal of a part of a string into a integer starting at the beginning of the string
  128.    *
  129.    * @param sNum The string to parse
  130.    * @param iLength The number of QChars used, and 0 if no valid symbols was found in the string
  131.    * @return An integer corresponding to the day
  132.    */
  133.   virtual int dayStringToInteger(const QString & sNum, int & iLength) const;
  134.  
  135.   /**
  136.    * Gets specific calendar type number of day of week number for a given
  137.    * date
  138.    *
  139.    * @param date gregorian date
  140.    * @return day of week
  141.    */
  142.   virtual int dayOfWeek (const QDate & date) const = 0;
  143.  
  144.   /**
  145.    * Gets specific calendar type day number of year for a given date
  146.    *
  147.    * @param date gregorian date equivalent to the specific one
  148.    * @return day number
  149.    */
  150.   virtual int dayOfYear (const QDate & date) const = 0;
  151.  
  152.   /**
  153.    * Changes the date's year, month and day. The range of the year, month
  154.    * and day depends on which calendar is being used.
  155.    *
  156.    * @param date Date to change
  157.    * @param y Year
  158.    * @param m Month number
  159.    * @param d Day of month
  160.    * @return true if the date is valid; otherwise returns false.
  161.    */
  162.   virtual bool setYMD(QDate & date, int y, int m, int d) const = 0;
  163.  
  164.   /**
  165.    * Returns a QDate object containing a date nyears later.
  166.    *
  167.    * @param date The old date
  168.    * @param nyears The number of years to add
  169.    * @return The new date
  170.    */
  171.   virtual QDate addYears(const QDate & date, int nyears) const = 0;
  172.  
  173.   /**
  174.    * Returns a QDate object containing a date nmonths later.
  175.    *
  176.    * @param date The old date
  177.    * @param nmonths The number of months to add
  178.    * @return The new date
  179.    */
  180.   virtual QDate addMonths(const QDate & date, int nmonths) const = 0;
  181.  
  182.   /**
  183.    * Returns a QDate object containing a date ndays later.
  184.    *
  185.    * @param date The old date
  186.    * @param ndays The number of days to add
  187.    * @return The new date
  188.    */
  189.   virtual QDate addDays(const QDate & date, int ndays) const = 0;
  190.  
  191.   /**
  192.    * Gets specific calendar type number of month for a given year
  193.    *
  194.    * @param date The date whose year to use
  195.    * @return The number of months in that year
  196.    */
  197.   virtual int monthsInYear (const QDate & date) const = 0;
  198.  
  199.   /**
  200.    * Gets the number of days in date whose years specified.
  201.    *
  202.    * @param date Gregorian date equivalent to the specific one
  203.    * @return The number of days in year
  204.    */
  205.   virtual int daysInYear (const QDate & date) const = 0;
  206.  
  207.   /**
  208.    * Gets specific calendar type number of days in month for a given date
  209.    *
  210.    * @param date gregorian date
  211.    * @return number of days for month in date
  212.    */
  213.   virtual int daysInMonth (const QDate & date) const = 0;
  214.  
  215.   /**
  216.    * Gets the number of weeks in a specified year
  217.    *
  218.    * @param year the year
  219.    * @return number of weeks in year
  220.    */
  221.   virtual int weeksInYear(int year) const = 0;
  222.  
  223.   /**
  224.    * Gets specific calendar type week number for a given date
  225.    *
  226.    * @param date gregorian date
  227.    * @param yearNum The year the date belongs to
  228.    * @return week number
  229.    */
  230.   virtual int weekNumber(const QDate& date, int * yearNum = 0) const = 0;
  231.  
  232.   /**
  233.    * Gets specific calendar type month name for a given month number
  234.    * If an invalid month is specified, QString::null is returned.
  235.    *
  236.    * @param month The month number
  237.    * @param year The year the month belongs to
  238.    * @param shortName Specifies if the short month name should be used
  239.    * @return The name of the month
  240.    */
  241.   virtual QString monthName (int month, int year, bool shortName = false) const = 0;
  242.  
  243.   /**
  244.    * Gets specific calendar type month name for a given gregorian date
  245.    *
  246.    * @param date Gregorian date
  247.    * @param shortName Specifies if the short month name should be used
  248.    * @return The name of the month
  249.    */
  250.   virtual QString monthName (const QDate & date, bool shortName = false ) const = 0;
  251.  
  252.   /**
  253.    * Returns a string containing the possessive form of the month name.
  254.    * ("of January", "of February", etc.)
  255.    * It's needed in long format dates in some languages.
  256.    * If an invalid month is specified, QString::null is returned.
  257.    *
  258.    * @param month The month number
  259.    * @param year The year the month belongs to
  260.    * @param shortName Specifies if the short month name should be used
  261.    *
  262.    * @return The possessive form of the name of the month
  263.    */
  264.   virtual QString monthNamePossessive(int month, int year, bool shortName = false) const = 0;
  265.  
  266.   /**
  267.    * Returns a string containing the possessive form of the month name.
  268.    * ("of January", "of February", etc.)
  269.    * It's needed in long format dates in some languages.
  270.    *
  271.    * @param date Gregorian date
  272.    * @param shortName Specifies if the short month name should be used
  273.    *
  274.    * @return The possessive form of the name of the month
  275.    */
  276.   virtual QString monthNamePossessive(const QDate & date, bool shortName = false) const = 0;
  277.  
  278.   /**
  279.    * Gets specific calendar type week day name
  280.    * If an invalid week day is specified, QString::null is returned.
  281.    *
  282.    * @param weekDay number of day in week (1 -> Monday)
  283.    * @param shortName short or complete day name
  284.    * @return day name
  285.    */
  286.   virtual QString weekDayName (int weekDay, bool shortName = false) const = 0;
  287.  
  288.   /**
  289.    * Gets specific calendar type week day name
  290.    *
  291.    * @param date the date
  292.    * @param shortName short or complete day name
  293.    * @return day name
  294.    */
  295.   virtual QString weekDayName (const QDate & date, bool shortName = false) const = 0;
  296.  
  297.   /**
  298.    * Gets the first year value supported by specific calendar type
  299.    * algorithms.
  300.    *
  301.    * @return first year supported
  302.    */
  303.   virtual int minValidYear () const = 0;
  304.  
  305.   /**
  306.    * Gets the maximum year value supported by specific calendar type
  307.    * algorithms (QDate, 8000)
  308.    *
  309.    * @return maximum year supported
  310.    */
  311.   virtual int maxValidYear () const = 0;
  312.  
  313.   /**
  314.    * Gets the day of the week traditionaly associated with pray
  315.    *
  316.    * @return day number
  317.    */
  318.   virtual int weekDayOfPray () const = 0;
  319.  
  320.   /**
  321.    * Gets the string representing the calendar
  322.    */
  323.   virtual QString calendarName() const = 0;
  324.  
  325.   /**
  326.    * Gets if the calendar is lunar based
  327.    *
  328.    * @return if the calendar is lunar based
  329.    */
  330.   virtual bool isLunar() const = 0;
  331.  
  332.   /**
  333.    * Gets if the calendar is lunisolar based
  334.    *
  335.    * @return if the calendar is lunisolar based
  336.    */
  337.   virtual bool isLunisolar() const = 0;
  338.  
  339.   /**
  340.    * Gets if the calendar is solar based
  341.    *
  342.    * @return if the calendar is solar based
  343.    */
  344.   virtual bool isSolar() const = 0;
  345.  
  346. protected:
  347.   /**
  348.    * Gets the locale the calendar uses for translations. Set in
  349.    * the constructor.
  350.    */
  351.   const KLocale * locale() const;
  352.  
  353. private:
  354.   KCalendarSystemPrivate * d;
  355. };
  356.  
  357. #endif
  358.