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

calendarsupport

  • sources
  • kde-4.12
  • kdepim
  • calendarsupport
  • next
incidenceviewer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3  Author: Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "incidenceviewer.h"
22 #include "incidenceviewer_p.h"
23 #include "attachmenthandler.h"
24 #include "utils.h"
25 
26 #include "libkdepimdbusinterfaces/urihandler.h"
27 #include "incidenceattachmentmodel.h"
28 
29 #include <Akonadi/CollectionFetchJob>
30 #include <Akonadi/ItemFetchScope>
31 #include <akonadi/calendar/calendarbase.h>
32 
33 #include <KCalUtils/IncidenceFormatter>
34 
35 #include <KJob>
36 #include <KSystemTimeZone>
37 #include <KTextBrowser>
38 
39 #include <QVBoxLayout>
40 
41 using namespace CalendarSupport;
42 
43 TextBrowser::TextBrowser( QWidget *parent )
44  : KTextBrowser( parent )
45 {
46 #ifdef KDEPIM_MOBILE_UI
47  setFrameStyle( QFrame::NoFrame );
48 #endif
49 }
50 
51 void TextBrowser::setSource( const QUrl &name )
52 {
53  QString uri = name.toString();
54  // QTextBrowser for some reason insists on putting // or / in links,
55  // this is a crude workaround
56  if ( uri.startsWith( QLatin1String( "uid:" ) ) ||
57  uri.startsWith( QLatin1String( "kmail:" ) ) ||
58  uri.startsWith( QString::fromLatin1( "urn:x-ical" ).section( QLatin1Char(':'), 0, 0 ) ) ||
59  uri.startsWith( QLatin1String( "news:" ) ) ||
60  uri.startsWith( QLatin1String( "mailto:" ) ) ) {
61  uri.replace( QRegExp( QLatin1String("^([^:]+:)/+") ), QLatin1String("\\1") );
62  }
63 
64  if ( uri.startsWith( QLatin1String( "ATTACH:" ) ) ) {
65  emit attachmentUrlClicked( uri );
66  } else {
67  UriHandler::process( uri );
68  }
69 }
70 
71 class IncidenceViewer::Private
72 {
73  public:
74  Private( IncidenceViewer *parent )
75  : mParent( parent ), mDelayedClear( false ), mParentCollectionFetchJob( 0 ),
76  mAttachmentModel( 0 )
77  {
78  mAttachmentHandler = new AttachmentHandler( parent );
79  mBrowser = new TextBrowser;
80  parent->connect( mBrowser, SIGNAL(attachmentUrlClicked(QString)),
81  parent, SLOT(slotAttachmentUrlClicked(QString)) );
82  }
83 
84  void updateView()
85  {
86  QString text;
87 
88  if ( mCurrentItem.isValid() ) {
89  text = KCalUtils::IncidenceFormatter::extensiveDisplayStr(
90  CalendarSupport::displayName( mCalendar, mParentCollection ),
91  CalendarSupport::incidence( mCurrentItem ),
92  mDate, KSystemTimeZones::local() );
93  text.prepend( mHeaderText );
94  mBrowser->setHtml( text );
95  } else {
96  text = mDefaultText;
97  if ( !mDelayedClear ) {
98  mBrowser->setHtml( text );
99  }
100  }
101 
102  }
103 
104  void slotParentCollectionFetched( KJob *job )
105  {
106  mParentCollectionFetchJob = 0;
107  mParentCollection = Akonadi::Collection();
108 
109  if ( !job->error() ) {
110  Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob*>( job );
111  if ( !fetchJob->collections().isEmpty() ) {
112  mParentCollection = fetchJob->collections().first();
113  }
114  }
115 
116  updateView();
117  }
118 
119  void slotAttachmentUrlClicked( const QString &uri )
120  {
121  const QString attachmentName =
122  QString::fromUtf8( QByteArray::fromBase64( uri.mid( 7 ).toUtf8() ) );
123  mAttachmentHandler->view( attachmentName, CalendarSupport::incidence( mCurrentItem ) );
124  }
125 
126  Akonadi::ETMCalendar *mCalendar;
127  IncidenceViewer *mParent;
128  TextBrowser *mBrowser;
129  Akonadi::Item mCurrentItem;
130  QDate mDate;
131  QString mHeaderText;
132  QString mDefaultText;
133  bool mDelayedClear;
134  Akonadi::Collection mParentCollection;
135  Akonadi::CollectionFetchJob *mParentCollectionFetchJob;
136  IncidenceAttachmentModel *mAttachmentModel;
137  AttachmentHandler *mAttachmentHandler;
138 };
139 
140 IncidenceViewer::IncidenceViewer( Akonadi::ETMCalendar *calendar, QWidget *parent )
141  : QWidget( parent ), d( new Private( this ) )
142 {
143  d->mCalendar = calendar;
144  init();
145 }
146 
147 IncidenceViewer::IncidenceViewer( QWidget *parent )
148  : QWidget( parent ), d( new Private( this ) )
149 {
150  d->mCalendar = 0;
151  init();
152 }
153 
154 void IncidenceViewer::init()
155 {
156  QVBoxLayout *layout = new QVBoxLayout( this );
157  layout->setMargin( 0 );
158 
159  d->mBrowser->setNotifyClick( true );
160  d->mBrowser->setMinimumHeight( 1 );
161 
162  layout->addWidget( d->mBrowser );
163 
164  // always fetch full payload for incidences
165  fetchScope().fetchFullPayload();
166  fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
167 
168  d->updateView();
169 }
170 
171 IncidenceViewer::~IncidenceViewer()
172 {
173  delete d;
174 }
175 
176 void IncidenceViewer::setCalendar( Akonadi::ETMCalendar *calendar )
177 {
178  d->mCalendar = calendar;
179 }
180 
181 Akonadi::Item IncidenceViewer::incidence() const
182 {
183  return ItemMonitor::item();
184 }
185 
186 QDate IncidenceViewer::activeDate() const
187 {
188  return d->mDate;
189 }
190 
191 QAbstractItemModel *IncidenceViewer::attachmentModel() const
192 {
193  if ( !d->mAttachmentModel ) {
194  d->mAttachmentModel =
195  new IncidenceAttachmentModel( const_cast<IncidenceViewer*>( this ) );
196  }
197  return d->mAttachmentModel;
198 }
199 
200 void IncidenceViewer::setDelayedClear( bool delayed )
201 {
202  d->mDelayedClear = delayed;
203 }
204 
205 void IncidenceViewer::setDefaultMessage( const QString &message )
206 {
207  d->mDefaultText = message;
208 }
209 
210 void IncidenceViewer::setHeaderText( const QString &text )
211 {
212  d->mHeaderText = text;
213 }
214 
215 void IncidenceViewer::setIncidence( const Akonadi::Item &incidence, const QDate &date )
216 {
217  d->mDate = date;
218  ItemMonitor::setItem( incidence );
219 
220  d->updateView();
221 }
222 
223 void IncidenceViewer::itemChanged( const Akonadi::Item &item )
224 {
225  if ( !item.hasPayload<KCalCore::Incidence::Ptr>() ) {
226  d->mBrowser->clear();
227  return;
228  }
229 
230  d->mCurrentItem = item;
231 
232  if ( d->mAttachmentModel ) {
233  d->mAttachmentModel->setItem( d->mCurrentItem );
234  }
235 
236  if ( d->mParentCollectionFetchJob ) {
237  disconnect( d->mParentCollectionFetchJob, SIGNAL(result(KJob*)),
238  this, SLOT(slotParentCollectionFetched(KJob*)) );
239  delete d->mParentCollectionFetchJob;
240  }
241 
242  d->mParentCollectionFetchJob =
243  new Akonadi::CollectionFetchJob( d->mCurrentItem.parentCollection(),
244  Akonadi::CollectionFetchJob::Base, this );
245 
246  connect( d->mParentCollectionFetchJob, SIGNAL(result(KJob*)),
247  this, SLOT(slotParentCollectionFetched(KJob*)) );
248 }
249 
250 void IncidenceViewer::itemRemoved()
251 {
252  d->mBrowser->clear();
253 }
254 
255 #include "incidenceviewer.moc"
256 #include "incidenceviewer_p.moc"
CalendarSupport::IncidenceViewer::attachmentModel
QAbstractItemModel * attachmentModel() const
Returns the attachment model for the currently displayed incidence.
Definition: incidenceviewer.cpp:191
CalendarSupport::TextBrowser
Definition: incidenceviewer_p.h:29
incidenceattachmentmodel.h
CalendarSupport::IncidenceViewer::IncidenceViewer
IncidenceViewer(Akonadi::ETMCalendar *calendar, QWidget *parent=0)
Creates a new incidence viewer.
Definition: incidenceviewer.cpp:140
QWidget
CalendarSupport::IncidenceViewer::setDefaultMessage
void setDefaultMessage(const QString &message)
Sets the default message that shall be shown if no incidence is set.
Definition: incidenceviewer.cpp:205
CalendarSupport::IncidenceViewer::~IncidenceViewer
~IncidenceViewer()
Destroys the incidence viewer.
Definition: incidenceviewer.cpp:171
CalendarSupport::IncidenceViewer::setDelayedClear
void setDelayedClear(bool delayed)
Sets whether the view shall be cleared as soon as an empty incidence is set (default) or delayed when...
Definition: incidenceviewer.cpp:200
CalendarSupport::incidence
CALENDARSUPPORT_EXPORT KCalCore::Incidence::Ptr incidence(const Akonadi::Item &item)
returns the incidence from an akonadi item, or a null pointer if the item has no such payload ...
Definition: utils.cpp:75
utils.h
incidenceviewer_p.h
CalendarSupport::IncidenceViewer
A viewer component for incidences in Akonadi.
Definition: incidenceviewer.h:62
CalendarSupport::IncidenceViewer::incidence
Akonadi::Item incidence() const
Returns the incidence that is currently displayed.
Definition: incidenceviewer.cpp:181
CalendarSupport::IncidenceAttachmentModel
Definition: incidenceattachmentmodel.h:41
CalendarSupport::IncidenceViewer::setIncidence
void setIncidence(const Akonadi::Item &incidence, const QDate &activeDate=QDate())
Sets the incidence that shall be displayed in the viewer.
Definition: incidenceviewer.cpp:215
CalendarSupport::TextBrowser::attachmentUrlClicked
void attachmentUrlClicked(const QString &uri)
attachmenthandler.h
This file is part of the API for handling calendar data and provides static functions for dealing wit...
KTextBrowser
CalendarSupport::displayName
CALENDARSUPPORT_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &coll)
Definition: utils.cpp:497
CalendarSupport::TextBrowser::TextBrowser
TextBrowser(QWidget *parent=0)
Definition: incidenceviewer.cpp:43
CalendarSupport::IncidenceViewer::setHeaderText
void setHeaderText(const QString &text)
Sets an additional text that is shown above the incidence.
Definition: incidenceviewer.cpp:210
incidenceviewer.h
CalendarSupport::IncidenceViewer::init
void init()
Initialize the widget settings.
Definition: incidenceviewer.cpp:154
CalendarSupport::IncidenceViewer::setCalendar
void setCalendar(Akonadi::ETMCalendar *calendar)
Sets the Calendar for this viewer.
Definition: incidenceviewer.cpp:176
CalendarSupport::TextBrowser::setSource
void setSource(const QUrl &name)
Definition: incidenceviewer.cpp:51
CalendarSupport::AttachmentHandler
Provides methods to handle incidence attachments.
Definition: attachmenthandler.h:48
CalendarSupport::IncidenceViewer::activeDate
QDate activeDate() const
Returns the active date used for the currently displayed incidence.
Definition: incidenceviewer.cpp:186
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

calendarsupport

Skip menu "calendarsupport"
  • Main Page
  • Namespace List
  • Namespace Members
  • 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