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

kontact

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

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