• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
  • plugins
  • datenums
datenums.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (c) 2007 Loïc Corbasson <loic.corbasson@gmail.com>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
22 #include "datenums.h"
23 #include "configdialog.h"
24 #include "koglobals.h"
25 
26 #include <KCalendarSystem>
27 
28 class DatenumsFactory : public DecorationFactory
29 {
30  public:
31  Decoration *createPluginFactory() { return new Datenums; }
32 };
33 
34 K_EXPORT_PLUGIN( DatenumsFactory )
35 
36 Datenums::Datenums()
37  : mDisplayedInfo( DayOfYear | DaysRemaining )
38 {
39  KConfig _config( QLatin1String("korganizerrc"), KConfig::NoGlobals );
40  KConfigGroup config( &_config, "Calendar/Datenums Plugin" );
41  mDisplayedInfo = (DayNumbers)config.readEntry(
42  "DayNumbers", int( DayOfYear | DaysRemaining ) );
43 }
44 
45 void Datenums::configure( QWidget *parent )
46 {
47  ConfigDialog dlg( parent );
48  dlg.exec();
49 }
50 
51 QString Datenums::info() const
52 {
53  return i18n( "This plugin shows information on a day's position in the year." );
54 }
55 
56 Element::List Datenums::createDayElements( const QDate &date )
57 {
58  Element::List result;
59 
60  const KCalendarSystem *calsys = KOGlobals::self()->calendarSystem();
61  int dayOfYear = calsys->dayOfYear( date );
62  int remainingDays = calsys->daysInYear( date ) - dayOfYear;
63 
64  StoredElement *e;
65  switch ( mDisplayedInfo ) {
66  case DayOfYear: // only day of year
67  e = new StoredElement( QLatin1String("main element"), QString::number( dayOfYear ) );
68  break;
69  case DaysRemaining: // only days until end of year
70  e = new StoredElement( QLatin1String("main element"), QString::number( remainingDays ),
71  i18np( "1 day before the end of the year",
72  "%1 days before the end of the year",
73  remainingDays ) );
74  break;
75  case DayOfYear + DaysRemaining: // both day of year and days till end of year
76  default:
77  e = new StoredElement( QLatin1String("main element"), QString::number( dayOfYear ),
78  i18nc( "dayOfYear / daysTillEndOfYear", "%1 / %2",
79  dayOfYear, remainingDays ),
80  i18np( "1 day since the beginning of the year,\n",
81  "%1 days since the beginning of the year,\n",
82  dayOfYear ) +
83  i18np( "1 day until the end of the year",
84  "%1 days until the end of the year",
85  remainingDays ) );
86  break;
87  }
88  result.append( e );
89 
90  return result;
91 }
92 
93 Element::List Datenums::createWeekElements( const QDate &date )
94 {
95  Element::List result;
96 
97  const KCalendarSystem *calsys = KOGlobals::self()->calendarSystem();
98  int *yearOfTheWeek;
99  yearOfTheWeek = 0;
100  int remainingWeeks;
101  const int weekOfYear = calsys->week( date, yearOfTheWeek );
102 
103  QString weekOfYearShort;
104  QString weekOfYearLong;
105  QString weekOfYearExtensive;
106  QString remainingWeeksShort;
107  QString remainingWeeksLong;
108  QString remainingWeeksExtensive;
109  QString weekOfYearAndRemainingWeeksShort;
110 
111  // Usual case: the week belongs to this year
112  remainingWeeks = calsys->weeksInYear( date.year() ) - weekOfYear;
113 
114  weekOfYearShort = QString::number( weekOfYear );
115  weekOfYearLong = i18nc( "Week weekOfYear", "Week %1", weekOfYear );
116  weekOfYearExtensive = i18np( "1 week since the beginning of the year",
117  "%1 weeks since the beginning of the year",
118  weekOfYear );
119 
120  if ( yearOfTheWeek ) { // The week does not belong to this year
121 
122  weekOfYearShort = i18nc( "weekOfYear (year)",
123  "%1 (%2)", weekOfYear, *yearOfTheWeek );
124  weekOfYearLong = i18nc( "Week weekOfYear (year)",
125  "Week %1 (%2)", weekOfYear, *yearOfTheWeek );
126 
127  if ( *yearOfTheWeek == date.year() + 1 ) {
128  // The week belongs to next year
129  remainingWeeks = 0;
130 
131  weekOfYearExtensive = i18np( "1 week since the beginning of the year",
132  "%1 weeks since the beginning of the year",
133  weekOfYear );
134 
135  } else {
136  // The week belongs to last year
137  remainingWeeks = calsys->weeksInYear( date.year() );
138 
139  weekOfYearExtensive = i18np( "1 week since the beginning of the year",
140  "%1 weeks since the beginning of the year",
141  0 );
142  }
143  }
144 
145  remainingWeeksShort = QString::number( remainingWeeks );
146  remainingWeeksShort = i18np( "1 week remaining",
147  "%1 weeks remaining",
148  remainingWeeks );
149  remainingWeeksExtensive = i18np( "1 week until the end of the year",
150  "%1 weeks until the end of the year",
151  remainingWeeks );
152  weekOfYearAndRemainingWeeksShort = i18nc( "weekOfYear / weeksTillEndOfYear",
153  "%1 / %2", weekOfYear,
154  remainingWeeks );
155 
156  StoredElement *e;
157  switch ( mDisplayedInfo ) {
158  case DayOfYear: // only week of year
159  e = new StoredElement( QLatin1String("main element"), weekOfYearShort, weekOfYearLong,
160  weekOfYearExtensive );
161  break;
162  case DaysRemaining: // only weeks until end of year
163  e = new StoredElement( QLatin1String("main element"), remainingWeeksShort,
164  remainingWeeksLong, remainingWeeksExtensive );
165  break;
166  case DayOfYear + DaysRemaining: // both week of year and weeks till end of year
167  default:
168  e = new StoredElement( QLatin1String("main element"), weekOfYearShort,
169  weekOfYearAndRemainingWeeksShort,
170  i18nc( "n weeks since the beginning of the year\n"
171  "n weeks until the end of the year",
172  "%1\n%2", weekOfYearExtensive,
173  remainingWeeksExtensive ) );
174  break;
175  }
176  result.append( e );
177 
178  return result;
179 }
180 
koglobals.h
Datenums::DaysRemaining
Definition: datenums.h:41
Datenums::createDayElements
Element::List createDayElements(const QDate &)
Definition: datenums.cpp:56
QWidget
Datenums::createWeekElements
Element::List createWeekElements(const QDate &)
Definition: datenums.cpp:93
StoredElement
Datenums::DayOfYear
Definition: datenums.h:40
ConfigDialog
Definition: datenums/configdialog.h:28
Datenums::info
QString info() const
Definition: datenums.cpp:51
KOGlobals::calendarSystem
const KCalendarSystem * calendarSystem() const
Definition: koglobals.cpp:65
Decoration
KOGlobals::self
static KOGlobals * self()
Definition: koglobals.cpp:43
K_EXPORT_PLUGIN
K_EXPORT_PLUGIN(KOrganizerFactory(createAboutData())) KOrganizerPart
Definition: korganizer_part.cpp:49
Datenums
Definition: datenums.h:28
configdialog.h
Datenums::configure
void configure(QWidget *parent)
Definition: datenums.cpp:45
datenums.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal