datenums.cpp
00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "datenums.h" 00021 #include "koglobals.h" 00022 #include <tdeconfig.h> 00023 #include <kstandarddirs.h> 00024 00025 #include "configdialog.h" 00026 #include <kcalendarsystem.h> 00027 00028 class DatenumsFactory : public CalendarDecorationFactory { 00029 public: 00030 CalendarDecoration *create() { return new Datenums; } 00031 }; 00032 00033 K_EXPORT_COMPONENT_FACTORY( libkorg_datenums, DatenumsFactory ) 00034 00035 00036 Datenums::Datenums() 00037 { 00038 TDEConfig config( "korganizerrc", true, false); // Open read-only, no kdeglobals 00039 config.setGroup("Calendar/DateNum Plugin"); 00040 mDateNum = config.readNumEntry( "ShowDayNumbers", 0 ); 00041 } 00042 00043 void Datenums::configure(TQWidget *parent) 00044 { 00045 ConfigDialog *dlg = new ConfigDialog(parent); 00046 dlg->exec(); 00047 delete dlg; 00048 } 00049 00050 00051 TQString Datenums::shortText(const TQDate &date) 00052 { 00053 int doy = KOGlobals::self()->calendarSystem()->dayOfYear(date); 00054 switch (mDateNum) { 00055 case 1: // only days until end of year 00056 return TQString::number( KOGlobals::self()->calendarSystem()->daysInYear(date) - doy ); 00057 break; 00058 case 2: // both day of year and days till end of year 00059 return i18n("dayOfYear / daysTillEndOfYear", "%1 / %2").arg( doy ) 00060 .arg(KOGlobals::self()->calendarSystem()->daysInYear(date) - doy); 00061 break; 00062 case 0: // only day of year 00063 default: 00064 return TQString::number( doy ); 00065 } 00066 return TQString::number( doy ); 00067 } 00068 00069 TQString Datenums::info() 00070 { 00071 return i18n("This plugin provides numbers of days and weeks."); 00072 }