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

kontact

  • sources
  • kde-4.12
  • kdepim
  • kontact
  • plugins
  • korganizer
apptsummarywidget.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Kontact.
3 
4  Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
5  Copyright (c) 2005-2006,2008-2009 Allen Winter <winter@kde.org>
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  As a special exception, permission is given to link this program
22  with any edition of Qt, and distribute the resulting executable,
23  without including the source code for Qt in the source distribution.
24 */
25 
26 #include "apptsummarywidget.h"
27 #include "korganizerplugin.h"
28 #include "summaryeventinfo.h"
29 
30 #include "korganizer/korganizerinterface.h"
31 
32 #include <calendarsupport/utils.h>
33 #include <calendarsupport/calendarsingleton.h>
34 
35 #include <Akonadi/Collection>
36 #include <Akonadi/Calendar/IncidenceChanger>
37 
38 #include <KCalCore/Calendar>
39 #include <KCalCore/Event>
40 
41 #include <KontactInterface/Core>
42 
43 #include <KConfigGroup>
44 #include <KIconLoader>
45 #include <KLocale>
46 #include <KMenu>
47 #include <KSystemTimeZones>
48 #include <KUrlLabel>
49 
50 #include <QGridLayout>
51 #include <QLabel>
52 #include <QVBoxLayout>
53 
54 ApptSummaryWidget::ApptSummaryWidget( KOrganizerPlugin *plugin, QWidget *parent )
55  : KontactInterface::Summary( parent ), mPlugin( plugin )
56 {
57  QVBoxLayout *mainLayout = new QVBoxLayout( this );
58  mainLayout->setSpacing( 3 );
59  mainLayout->setMargin( 3 );
60 
61  QWidget *header = createHeader(
62  this, QLatin1String("view-calendar-upcoming-events"), i18n( "Upcoming Events" ) );
63  mainLayout->addWidget( header );
64 
65  mLayout = new QGridLayout();
66  mainLayout->addItem( mLayout );
67  mLayout->setSpacing( 3 );
68  mLayout->setRowStretch( 6, 1 );
69 
70  QStringList mimeTypes;
71  mimeTypes << KCalCore::Event::eventMimeType();
72  mCalendar = CalendarSupport::calendarSingleton();
73 
74  mChanger = new Akonadi::IncidenceChanger( parent );
75 
76  connect( mCalendar.data(), SIGNAL(calendarChanged()), this, SLOT(updateView()) );
77  connect( mPlugin->core(), SIGNAL(dayChanged(QDate)), this, SLOT(updateView()) );
78 
79  // Update Configuration
80  configUpdated();
81 }
82 
83 ApptSummaryWidget::~ApptSummaryWidget()
84 {
85 }
86 
87 void ApptSummaryWidget::configUpdated()
88 {
89  KConfig config( QLatin1String("kcmapptsummaryrc") );
90 
91  KConfigGroup group = config.group( "Days" );
92  mDaysAhead = group.readEntry( "DaysToShow", 7 );
93 
94  group = config.group( "Show" );
95  mShowBirthdaysFromCal = group.readEntry( "BirthdaysFromCalendar", true );
96  mShowAnniversariesFromCal = group.readEntry( "AnniversariesFromCalendar", true );
97 
98  group = config.group( "Groupware" );
99  mShowMineOnly = group.readEntry( "ShowMineOnly", false );
100 
101  updateView();
102 }
103 
104 void ApptSummaryWidget::updateView()
105 {
106  qDeleteAll( mLabels );
107  mLabels.clear();
108 
109  // The event print consists of the following fields:
110  // icon:start date:days-to-go:summary:time range
111  // where,
112  // the icon is the typical event icon
113  // the start date is the event start date
114  // the days-to-go is the #days until the event starts
115  // the summary is the event summary
116  // the time range is the start-end time (only for non-floating events)
117 
118  QLabel *label = 0;
119  int counter = 0;
120 
121  KIconLoader loader( QLatin1String("korganizer") );
122  QPixmap pm = loader.loadIcon( QLatin1String("view-calendar-day"), KIconLoader::Small );
123  QPixmap pmb = loader.loadIcon( QLatin1String("view-calendar-birthday"), KIconLoader::Small );
124  QPixmap pma = loader.loadIcon( QLatin1String("view-calendar-wedding-anniversary"), KIconLoader::Small );
125 
126  QStringList uidList;
127  SummaryEventInfo::setShowSpecialEvents( mShowBirthdaysFromCal,
128  mShowAnniversariesFromCal );
129  QDate currentDate = QDate::currentDate();
130 
131  SummaryEventInfo::List events = SummaryEventInfo::eventsForRange( currentDate, currentDate.addDays( mDaysAhead - 1 ), mCalendar );
132 
133  foreach ( SummaryEventInfo *event, events ) {
134 
135  // Optionally, show only my Events
136 /* if ( mShowMineOnly &&
137  !KCalCore::CalHelper::isMyCalendarIncidence( mCalendarAdaptor, event->ev ) ) {
138  continue;
139  }
140  TODO: CalHelper is deprecated, remove this?
141 */
142 
143  KCalCore::Event::Ptr ev = event->ev;
144  // print the first of the recurring event series only
145  if ( ev->recurs() ) {
146  if ( uidList.contains( ev->instanceIdentifier() ) ) {
147  continue;
148  }
149  uidList.append( ev->instanceIdentifier() );
150  }
151 
152  // Icon label
153  label = new QLabel( this );
154  if ( ev->categories().contains( QLatin1String("BIRTHDAY"), Qt::CaseInsensitive ) ) {
155  label->setPixmap( pmb );
156  } else if ( ev->categories().contains( QLatin1String("ANNIVERSARY"), Qt::CaseInsensitive ) ) {
157  label->setPixmap( pma );
158  } else {
159  label->setPixmap( pm );
160  }
161  label->setMaximumWidth( label->minimumSizeHint().width() );
162  mLayout->addWidget( label, counter, 0 );
163  mLabels.append( label );
164 
165  // Start date or date span label
166  QString dateToDisplay = event->startDate;
167  if ( !event->dateSpan.isEmpty() ) {
168  dateToDisplay = event->dateSpan;
169  }
170  label = new QLabel( dateToDisplay, this );
171  label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
172  mLayout->addWidget( label, counter, 1 );
173  mLabels.append( label );
174  if ( event->makeBold ) {
175  QFont font = label->font();
176  font.setBold( true );
177  label->setFont( font );
178  }
179 
180  // Days to go label
181  label = new QLabel( event->daysToGo, this );
182  label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
183  mLayout->addWidget( label, counter, 2 );
184  mLabels.append( label );
185 
186  // Summary label
187  KUrlLabel *urlLabel = new KUrlLabel( this );
188  urlLabel->setText( event->summaryText );
189  urlLabel->setUrl( event->summaryUrl );
190  urlLabel->installEventFilter( this );
191  urlLabel->setTextFormat( Qt::RichText );
192  urlLabel->setWordWrap( true );
193  mLayout->addWidget( urlLabel, counter, 3 );
194  mLabels.append( urlLabel );
195 
196  connect( urlLabel, SIGNAL(leftClickedUrl(QString)),
197  this, SLOT(viewEvent(QString)) );
198  connect( urlLabel, SIGNAL(rightClickedUrl(QString)),
199  this, SLOT(popupMenu(QString)) );
200  if ( !event->summaryTooltip.isEmpty() ) {
201  urlLabel->setToolTip( event->summaryTooltip );
202  }
203 
204  // Time range label (only for non-floating events)
205  if ( !event->timeRange.isEmpty() ) {
206  label = new QLabel( event->timeRange, this );
207  label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
208  mLayout->addWidget( label, counter, 4 );
209  mLabels.append( label );
210  }
211 
212  counter++;
213  }
214 
215  qDeleteAll( events );
216 
217  if ( !counter ) {
218  QLabel *noEvents = new QLabel(
219  i18np( "No upcoming events starting within the next day",
220  "No upcoming events starting within the next %1 days",
221  mDaysAhead ), this );
222  noEvents->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
223  mLayout->addWidget( noEvents, 0, 0 );
224  mLabels.append( noEvents );
225  }
226 
227  Q_FOREACH ( label, mLabels ) { //krazy:exclude=foreach as label is a pointer
228  label->show();
229  }
230 }
231 
232 void ApptSummaryWidget::viewEvent( const QString &uid )
233 {
234  Akonadi::Item::Id id = mCalendar->item( uid ).id();
235 
236  if ( id != -1 ) {
237  mPlugin->core()->selectPlugin( QLatin1String("kontact_korganizerplugin") ); //ensure loaded
238  OrgKdeKorganizerKorganizerInterface korganizer(
239  QLatin1String("org.kde.korganizer"), QLatin1String("/Korganizer"), QDBusConnection::sessionBus() );
240  korganizer.editIncidence( QString::number( id ) );
241  }
242 }
243 
244 void ApptSummaryWidget::removeEvent( const Akonadi::Item &item )
245 {
246  mChanger->deleteIncidence( item );
247 }
248 
249 void ApptSummaryWidget::popupMenu( const QString &uid )
250 {
251  KMenu popup( this );
252 
253  // FIXME: Should say "Show Appointment" if we don't have rights to edit
254  // Doesn't make sense to edit events from birthday resource for example
255  QAction *editIt = popup.addAction( i18n( "&Edit Appointment..." ) );
256 
257  QAction *delIt = popup.addAction( i18n( "&Delete Appointment" ) );
258  delIt->setIcon( KIconLoader::global()->
259  loadIcon( QLatin1String("edit-delete"), KIconLoader::Small ) );
260 
261  Akonadi::Item item = mCalendar->item( uid );
262  delIt->setEnabled( mCalendar->hasRight( item, Akonadi::Collection::CanDeleteItem ) );
263 
264  const QAction *selectedAction = popup.exec( QCursor::pos() );
265  if ( selectedAction == editIt ) {
266  viewEvent( uid );
267  } else if ( selectedAction == delIt ) {
268  removeEvent( item );
269  }
270 }
271 
272 bool ApptSummaryWidget::eventFilter( QObject *obj, QEvent *e )
273 {
274  if ( obj->inherits( "KUrlLabel" ) ) {
275  KUrlLabel *label = static_cast<KUrlLabel*>( obj );
276  if ( e->type() == QEvent::Enter ) {
277  emit message( i18n( "Edit Event: \"%1\"", label->text() ) );
278  }
279  if ( e->type() == QEvent::Leave ) {
280  emit message( QString::null ); //krazy:exclude=nullstrassign for old broken gcc
281  }
282  }
283 
284  return KontactInterface::Summary::eventFilter( obj, e );
285 }
286 
287 QStringList ApptSummaryWidget::configModules() const
288 {
289  return QStringList()<< QLatin1String("kcmapptsummary.desktop");
290 }
291 
292 #include "apptsummarywidget.moc"
SummaryEventInfo::summaryUrl
QString summaryUrl
Definition: summaryeventinfo.h:57
SummaryEventInfo
Definition: summaryeventinfo.h:37
ApptSummaryWidget::configUpdated
void configUpdated()
Definition: apptsummarywidget.cpp:87
SummaryEventInfo::setShowSpecialEvents
static void setShowSpecialEvents(bool skipBirthdays, bool skipAnniversaries)
Definition: summaryeventinfo.cpp:74
SummaryEventInfo::summaryText
QString summaryText
Definition: summaryeventinfo.h:56
QWidget
KOrganizerPlugin
Definition: korganizerplugin.h:36
QObject
SummaryEventInfo::summaryTooltip
QString summaryTooltip
Definition: summaryeventinfo.h:58
SummaryEventInfo::eventsForRange
static List eventsForRange(const QDate &start, const QDate &end, const KCalCore::Calendar::Ptr &calendar)
static
Definition: summaryeventinfo.cpp:134
ApptSummaryWidget::eventFilter
virtual bool eventFilter(QObject *obj, QEvent *e)
Definition: apptsummarywidget.cpp:272
ApptSummaryWidget::ApptSummaryWidget
ApptSummaryWidget(KOrganizerPlugin *plugin, QWidget *parent)
Definition: apptsummarywidget.cpp:54
ApptSummaryWidget::~ApptSummaryWidget
~ApptSummaryWidget()
Definition: apptsummarywidget.cpp:83
apptsummarywidget.h
korganizerplugin.h
SummaryEventInfo::dateSpan
QString dateSpan
Definition: summaryeventinfo.h:53
SummaryEventInfo::daysToGo
QString daysToGo
Definition: summaryeventinfo.h:54
summaryeventinfo.h
QLabel
SummaryEventInfo::makeBold
bool makeBold
Definition: summaryeventinfo.h:59
SummaryEventInfo::timeRange
QString timeRange
Definition: summaryeventinfo.h:55
ApptSummaryWidget::configModules
QStringList configModules() const
Definition: apptsummarywidget.cpp:287
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:30 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kontact

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

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