/* Copyright (c) 2013, 2014 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "knotesakonadiapp.h" #include "knotesakonaditray.h" #include "noteshared/akonadi/notesakonaditreemodel.h" #include "knoteakonadinote.h" #include "noteshared/akonadi/noteschangerecorder.h" #include "noteshared/attributes/notelockattribute.h" #include "noteshared/attributes/notedisplayattribute.h" #include "noteshared/attributes/notealarmattribute.h" #include #include #include #include #include #include #include #include #include #include KNotesAkonadiApp::KNotesAkonadiApp(QWidget *parent) : QWidget(parent) { Akonadi::Session *session = new Akonadi::Session( "KNotes Session", this ); Akonadi::Control::widgetNeedsAkonadi(this); mNoteRecorder = new NoteShared::NotesChangeRecorder(this); mNoteRecorder->changeRecorder()->setSession(session); mTray = new KNotesAkonadiTray(mNoteRecorder->changeRecorder(), 0); mNoteTreeModel = new NoteShared::NotesAkonadiTreeModel(mNoteRecorder->changeRecorder(), this); connect( mNoteTreeModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(slotRowInserted(QModelIndex,int,int))); connect( mNoteRecorder->changeRecorder(), SIGNAL(itemChanged(Akonadi::Item,QSet)), SLOT(slotItemChanged(Akonadi::Item,QSet))); connect( mNoteRecorder->changeRecorder(), SIGNAL(itemRemoved(Akonadi::Item)), SLOT(slotItemRemoved(Akonadi::Item)) ); } KNotesAkonadiApp::~KNotesAkonadiApp() { qDeleteAll(mHashNotes); } void KNotesAkonadiApp::slotItemRemoved(const Akonadi::Item &item) { qDebug()<<" note removed"< &set) { if (mHashNotes.contains(item.id())) { qDebug()<<" item changed "<setEnabled(!item.hasAttribute()); } if (set.contains("PLD:RFC822")) { KMime::Message::Ptr noteMessage = item.payload(); if (noteMessage) { const KMime::Headers::Subject * const subject = noteMessage->subject(false); note->title()->setText(subject ? subject->asUnicodeString() : QString()); if ( noteMessage->contentType()->isHTMLText() ) { note->editor()->setAcceptRichText(true); note->editor()->setHtml(noteMessage->mainBodyPart()->decodedText()); } else { note->editor()->setAcceptRichText(false); note->editor()->setPlainText(noteMessage->mainBodyPart()->decodedText()); } } } if (set.contains("ATR:NoteDisplayAttribute")) { //TODO } if (set.contains("ATR:NoteAlarmAttribute")) { //TODO } } } void KNotesAkonadiApp::slotRowInserted(const QModelIndex &parent, int start, int end) { for ( int i = start; i <= end; ++i) { if ( mNoteTreeModel->hasIndex( i, 0, parent ) ) { const QModelIndex child = mNoteTreeModel->index( i, 0, parent ); Akonadi::Item item = mNoteTreeModel->data( child, Akonadi::EntityTreeModel::ItemRole ).value(); if ( !item.hasPayload() ) continue; KMime::Message::Ptr noteMessage = item.payload(); KNoteAkonadiNote *note = new KNoteAkonadiNote(0); const KMime::Headers::Subject * const subject = noteMessage ? noteMessage->subject(false) : 0; note->title()->setText(subject ? subject->asUnicodeString() : QString()); if ( noteMessage->contentType()->isHTMLText() ) { note->editor()->setAcceptRichText(true); note->editor()->setHtml(noteMessage->mainBodyPart()->decodedText()); } else { note->editor()->setAcceptRichText(false); note->editor()->setPlainText(noteMessage->mainBodyPart()->decodedText()); } if ( item.hasAttribute() ) { note->setEnabled(false); } if ( item.hasAttribute()) { //TODO add display attribute NoteShared::NoteDisplayAttribute *attr = item.attribute(); if (attr->isHidden()) { note->hide(); } else { note->show(); } note->resize(attr->size()); } else { note->show(); } if ( item.hasAttribute()) { //TODO add alarm attribute } mHashNotes.insert(item.id(), note); } } }