2
Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company
4
Author: Tobias Koenig <tokoe@kde.org>
6
This library is free software; you can redistribute it and/or modify it
7
under the terms of the GNU Library General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This library is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14
License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
#include "incidenceviewer.h"
25
#include "libkdepimdbusinterfaces/urihandler.h"
26
#include "incidenceattachmentmodel.h"
28
#include <Akonadi/CollectionFetchJob>
29
#include <Akonadi/ItemFetchScope>
31
#include <KCalUtils/IncidenceFormatter>
34
#include <KSystemTimeZone>
35
#include <KTextBrowser>
37
#include <QVBoxLayout>
39
using namespace CalendarSupport;
41
class TextBrowser : public KTextBrowser
44
TextBrowser( QWidget *parent = 0 )
45
: KTextBrowser( parent )
47
#ifdef KDEPIM_MOBILE_UI
48
setFrameStyle( QFrame::NoFrame );
52
void setSource( const QUrl &name )
54
QString uri = name.toString();
55
// QTextBrowser for some reason insists on putting // or / in links,
56
// this is a crude workaround
57
if ( uri.startsWith( QLatin1String( "uid:" ) ) ||
58
uri.startsWith( QLatin1String( "kmail:" ) ) ||
59
uri.startsWith( QString( "urn:x-ical" ).section( ':', 0, 0 ) ) ||
60
uri.startsWith( QLatin1String( "news:" ) ) ||
61
uri.startsWith( QLatin1String( "mailto:" ) ) ) {
62
uri.replace( QRegExp( "^([^:]+:)/+" ), "\\1" );
65
UriHandler::process( uri );
69
class IncidenceViewer::Private
72
Private( IncidenceViewer *parent )
73
: mParent( parent ), mDelayedClear( false ), mParentCollectionFetchJob( 0 ),
76
mBrowser = new TextBrowser;
83
if ( mCurrentItem.isValid() ) {
84
text = KCalUtils::IncidenceFormatter::extensiveDisplayStr(
85
CalendarSupport::displayName( mParentCollection ),
86
CalendarSupport::incidence( mCurrentItem ),
87
mDate, KSystemTimeZones::local() );
88
text.prepend( mHeaderText );
89
mBrowser->setHtml( text );
92
if ( !mDelayedClear ) {
93
mBrowser->setHtml( text );
99
void slotParentCollectionFetched( KJob *job )
101
mParentCollectionFetchJob = 0;
102
mParentCollection = Akonadi::Collection();
104
if ( !job->error() ) {
105
Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob*>( job );
106
if ( !fetchJob->collections().isEmpty() ) {
107
mParentCollection = fetchJob->collections().first();
114
IncidenceViewer *mParent;
115
TextBrowser *mBrowser;
116
Akonadi::Item mCurrentItem;
119
QString mDefaultText;
121
Akonadi::Collection mParentCollection;
122
Akonadi::CollectionFetchJob *mParentCollectionFetchJob;
123
IncidenceAttachmentModel *mAttachmentModel;
126
IncidenceViewer::IncidenceViewer( QWidget *parent )
127
: QWidget( parent ), d( new Private( this ) )
129
QVBoxLayout *layout = new QVBoxLayout( this );
130
layout->setMargin( 0 );
132
d->mBrowser->setNotifyClick( true );
133
d->mBrowser->setMinimumHeight( 1 );
135
layout->addWidget( d->mBrowser );
137
// always fetch full payload for incidences
138
fetchScope().fetchFullPayload();
139
fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
144
IncidenceViewer::~IncidenceViewer()
149
Akonadi::Item IncidenceViewer::incidence() const
151
return ItemMonitor::item();
154
QDate IncidenceViewer::activeDate() const
159
QAbstractItemModel *IncidenceViewer::attachmentModel() const
161
if ( !d->mAttachmentModel ) {
162
d->mAttachmentModel =
163
new IncidenceAttachmentModel( const_cast<IncidenceViewer*>( this ) );
165
return d->mAttachmentModel;
168
void IncidenceViewer::setDelayedClear( bool delayed )
170
d->mDelayedClear = delayed;
173
void IncidenceViewer::setDefaultMessage( const QString &message )
175
d->mDefaultText = message;
178
void IncidenceViewer::setHeaderText( const QString &text )
180
d->mHeaderText = text;
183
void IncidenceViewer::setIncidence( const Akonadi::Item &incidence, const QDate &date )
186
ItemMonitor::setItem( incidence );
191
void IncidenceViewer::itemChanged( const Akonadi::Item &item )
193
if ( !item.hasPayload<KCalCore::Incidence::Ptr>() ) {
194
d->mBrowser->clear();
198
d->mCurrentItem = item;
200
if ( d->mAttachmentModel ) {
201
d->mAttachmentModel->setItem( d->mCurrentItem );
204
if ( d->mParentCollectionFetchJob ) {
205
disconnect( d->mParentCollectionFetchJob, SIGNAL(result(KJob *)),
206
this, SLOT(slotParentCollectionFetched(KJob *)) );
207
delete d->mParentCollectionFetchJob;
210
d->mParentCollectionFetchJob =
211
new Akonadi::CollectionFetchJob( d->mCurrentItem.parentCollection(),
212
Akonadi::CollectionFetchJob::Base, this );
214
connect( d->mParentCollectionFetchJob, SIGNAL(result(KJob *)),
215
this, SLOT(slotParentCollectionFetched(KJob *)) );
218
void IncidenceViewer::itemRemoved()
220
d->mBrowser->clear();
223
#include "incidenceviewer.moc"