• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

calendarengine.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2009 Davide Bettio <davide.bettio@kdemail.net>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 
00021 #include "calendarengine.h"
00022 
00023 #include <QDate>
00024 
00025 #include <KCalendarSystem>
00026 #include <KHolidays/Holidays>
00027 
00028 CalendarEngine::CalendarEngine(QObject* parent, const QVariantList& args)
00029     : Plasma::DataEngine(parent)
00030 {
00031     Q_UNUSED(args);
00032 }
00033 
00034 CalendarEngine::~CalendarEngine()
00035 {
00036     qDeleteAll(m_regions);
00037 }
00038 
00039 bool CalendarEngine::sourceRequestEvent(const QString &name)
00040 {
00041     kDebug() << name << "\n";
00042     const QStringList tokens = name.split(':');
00043 
00044     if (tokens.count() < 3) {
00045         if (name == "holidaysRegions") {
00046             setData(name, KHolidays::HolidayRegion::locations());
00047             return true;
00048         } else {
00049             return false;
00050         }
00051     }
00052 
00053     kDebug() << tokens[0];
00054     kDebug() << tokens[2];
00055     const QString regionName = tokens[1];
00056     KHolidays::HolidayRegion *region = m_regions.value(regionName);
00057 
00058     if (!region) {
00059         region = new KHolidays::HolidayRegion(regionName);
00060         m_regions.insert(regionName, region);
00061     }
00062 
00063     QDate dateArg = QDate::fromString(tokens[2], Qt::ISODate);
00064 
00065     if (tokens[0] == "holidaysInMonth") {
00066         Plasma::DataEngine::Data data;
00067         const int days = KGlobal::locale()->calendar()->daysInMonth(dateArg);
00068         dateArg.setDate(dateArg.year(), dateArg.month(), 1);
00069 
00070         for (int i = 0; i < days; ++i) {
00071             KHolidays::Holiday::List holidays = region->holidays(dateArg);
00072 
00073             if (!holidays.isEmpty()) {
00074                 QString summary;
00075                 foreach (const KHolidays::Holiday &holiday, holidays) {
00076                     if (!summary.isEmpty()) {
00077                         summary.append("\n");
00078                     }
00079 
00080                     summary.append(holiday.text());
00081                 }
00082 
00083                 data.insert(dateArg.toString(Qt::ISODate), summary);
00084             }
00085 
00086             dateArg = dateArg.addDays(1);
00087         }
00088 
00089         setData(name, data);
00090     } else if (tokens[0] == "isHoliday") {
00091         setData(name, region->isHoliday(dateArg));
00092     } else if (tokens[0] == "description") {
00093         KHolidays::Holiday::List holidays = region->holidays(dateArg);
00094         QString summary;
00095         foreach (const KHolidays::Holiday &holiday, holidays) {
00096             if (!summary.isEmpty()) {
00097                 summary.append("\n");
00098             }
00099 
00100             summary.append(holiday.text());
00101         }
00102 
00103         setData(name, summary);
00104     }
00105 
00106 
00107     return true;
00108 }
00109 
00110 #include "calendarengine.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •     Animators
  •     Applets
  •     Engines
  • Solid Modules
  • System Settings
  •   SystemSettingsView
Generated for API Reference by doxygen 1.5.9-20090814
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