24 #include <QTextDocument>
28 #include <akonadi/changerecorder.h>
29 #include <akonadi/entitydisplayattribute.h>
31 #include <Akonadi/Notes/NoteUtils>
34 #include <KMime/KMimeMessage>
36 #include <kpimtextedit/textutils.h>
38 #include <grantlee/markupdirector.h>
39 #include <grantlee/texthtmlbuilder.h>
40 #include <grantlee/plaintextmarkupbuilder.h>
41 #include "noteshared/attributes/notelockattribute.h"
66 Grantlee::TextHTMLBuilder builder;
67 Grantlee::MarkupDirector director(&builder);
69 director.processDocument(document);
70 QString result = builder.getResult();
81 Grantlee::PlainTextMarkupBuilder builder;
82 Grantlee::MarkupDirector director(&builder);
84 director.processDocument(document);
85 QString result = builder.getResult();
92 Item item = m_index.
data(EntityTreeModel::ItemRole).
value<Item>();
95 Collection col = m_index.
data(EntityTreeModel::CollectionRole).
value<Collection>();
105 Collection col = m_index.
data(EntityTreeModel::CollectionRole).
value<Collection>();
109 return col.contentMimeTypes().contains( Akonadi::NoteUtils::noteMimeType() );
116 Item item = m_index.
data(EntityTreeModel::ItemRole).
value<Item>();
119 return item.hasPayload<KMime::Message::Ptr>();
128 const int column = 0;
134 childIndex = m_index.
child(row++, column);
143 const int column = 0;
163 qDeleteAll( m_documents );
168 if ( role == Qt::EditRole )
170 Item item = index.
data( ItemRole ).
value<Item>();
172 if ( !item.isValid() )
174 Collection col = index.
data( CollectionRole ).
value<Collection>();
176 if (col.hasAttribute<EntityDisplayAttribute>())
178 EntityDisplayAttribute *eda = col.attribute<EntityDisplayAttribute>();
179 eda->setDisplayName(value.
toString());
183 KMime::Message::Ptr m = item.payload<KMime::Message::Ptr>();
185 m->subject(
true )->fromUnicodeString( value.
toString(),
"utf-8" );
187 item.setPayload<KMime::Message::Ptr>( m );
189 if ( item.hasAttribute<EntityDisplayAttribute>() ) {
190 EntityDisplayAttribute *displayAttribute = item.attribute<EntityDisplayAttribute>();
191 displayAttribute->setDisplayName( value.
toString() );
193 return EntityTreeModel::setData(index, QVariant::fromValue<Item>( item ), ItemRole);
198 Item item = EntityTreeModel::data( index, ItemRole ).value<Item>();
199 if ( !item.hasPayload<KMime::Message::Ptr>() )
201 KMime::Message::Ptr note = item.payload<KMime::Message::Ptr>();
204 bool isRichText = KPIMTextEdit::TextUtils::containsFormatting( document );
206 note->contentType()->setMimeType( isRichText ?
"text/html" :
"text/plain" );
207 note->contentType()->setCharset(
"utf-8");
208 note->contentTransferEncoding(
true)->setEncoding(KMime::Headers::CEquPr);
209 note->mainBodyPart()->fromUnicodeString( isRichText ? document->toHtml() : document->toPlainText() );
211 item.setPayload<KMime::Message::Ptr>( note );
212 return EntityTreeModel::setData(index, QVariant::fromValue<Item>( item ), ItemRole );
217 Item item = index.
data( ItemRole ).
value<Item>();
218 m_cursorPositions.
insert( item.id(), value.
toInt() );
222 return EntityTreeModel::setData(index, value, role);
236 const Item item = index.
data( ItemRole ).
value<Item>();
237 Entity::Id itemId = item.id();
238 if ( m_documents.
contains( itemId ) )
240 if ( !item.hasPayload<KMime::Message::Ptr>() )
243 KMime::Message::Ptr note = item.payload<KMime::Message::Ptr>();
245 if ( note->contentType()->isHTMLText() )
246 document->
setHtml( note->mainBodyPart()->decodedText() );
248 document->setPlainText( note->mainBodyPart()->decodedText() );
250 m_documents.
insert( itemId, document );
256 const Item item = index.
data( ItemRole ).
value<Item>();
260 if ( m_cursorPositions.
contains( item.id() ) )
261 return m_cursorPositions.
value( item.id() );
266 if ( role == Qt::DecorationRole )
268 const Item item = index.
data( ItemRole ).
value<Item>();
269 if ( item.isValid() && item.hasAttribute<NoteShared::NoteLockAttribute>() ) {
272 const Collection col = index.
data( CollectionRole ).
value<Collection>();
273 if ( col.isValid() && col.hasAttribute<NoteShared::NoteLockAttribute>() ) {
279 return EntityTreeModel::data(index, role);
284 if ( ( role == Qt::EditRole || role == Qt::DisplayRole ) && item.hasPayload<KMime::Message::Ptr>() )
286 KMime::Message::Ptr page = item.payload<KMime::Message::Ptr>();
287 return page->subject()->asUnicodeString();
289 return EntityTreeModel::entityData( item, column, role );
QVariant data(const QModelIndex &index, int role) const
iterator insert(const Key &key, const T &value)
A wrapper QObject making some book and page properties available to Grantlee.
QVariantList entities() const
QVariantList breadcrumbs() const
QModelIndex child(int row, int column) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
int toInt(bool *ok) const
void setIndex(const QModelIndex &index)
virtual QVariant entityData(const Akonadi::Item &item, int column, int role=Qt::DisplayRole) const
QVariant data(int role) const
QModelIndex parent() const
const T value(const Key &key) const
QString plainContent() const
QVariant fromValue(const T &value)
QVariant data(int role) const
void setHtml(const QString &html)
bool contains(const Key &key) const
KJotsEntity(const QModelIndex &index, QObject *parent=0)
QModelIndex parent() const
KJotsModel(ChangeRecorder *monitor, QObject *parent=0)