datenums.cpp
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program 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
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include "datenums.h"
21 #include "koglobals.h"
22 #include <tdeconfig.h>
23 #include <kstandarddirs.h>
24 
25 #include "configdialog.h"
26 #include <kcalendarsystem.h>
27 
28 class DatenumsFactory : public CalendarDecorationFactory {
29  public:
30  CalendarDecoration *create() { return new Datenums; }
31 };
32 
33 K_EXPORT_COMPONENT_FACTORY( libkorg_datenums, DatenumsFactory )
34 
35 
36 Datenums::Datenums()
37 {
38  TDEConfig config( "korganizerrc", true, false); // Open read-only, no kdeglobals
39  config.setGroup("Calendar/DateNum Plugin");
40  mDateNum = config.readNumEntry( "ShowDayNumbers", 0 );
41 }
42 
43 void Datenums::configure(TQWidget *parent)
44 {
45  ConfigDialog *dlg = new ConfigDialog(parent);
46  dlg->exec();
47  delete dlg;
48 }
49 
50 
51 TQString Datenums::shortText(const TQDate &date)
52 {
53  int doy = KOGlobals::self()->calendarSystem()->dayOfYear(date);
54  switch (mDateNum) {
55  case 1: // only days until end of year
56  return TQString::number( KOGlobals::self()->calendarSystem()->daysInYear(date) - doy );
57  break;
58  case 2: // both day of year and days till end of year
59  return i18n("dayOfYear / daysTillEndOfYear", "%1 / %2").arg( doy )
60  .arg(KOGlobals::self()->calendarSystem()->daysInYear(date) - doy);
61  break;
62  case 0: // only day of year
63  default:
64  return TQString::number( doy );
65  }
66  return TQString::number( doy );
67 }
68 
69 TQString Datenums::info()
70 {
71  return i18n("This plugin provides numbers of days and weeks.");
72 }
This class provides the interface for a date dependent decoration.