Index: kmail/proxyobject.h =================================================================== --- kmail/proxyobject.h (revision 0) +++ kmail/proxyobject.h (revision 0) @@ -0,0 +1,21 @@ +#ifndef _PROXYOBJECT_H_ +#define _PROXYOBJECT_H_ + +#include <QObject> + +class proxyObject : public QObject +{ + Q_OBJECT + unsigned long msgSerNum; + +public: + proxyObject( unsigned long serNum, QObject* parent = 0 ) : + QObject( parent ), msgSerNum( serNum) + { + } + +public slots: + void Proxy(); +}; + +#endif Index: kmail/messageactions.h =================================================================== --- kmail/messageactions.h (revision 1129091) +++ kmail/messageactions.h (working copy) @@ -34,6 +34,9 @@ class KMMessage; class KXMLGUIClient; +namespace Nepomuk { +class AnnotationMenu; +} namespace KMail { /** @@ -44,6 +47,7 @@ Q_OBJECT public: MessageActions( KActionCollection* ac, QWidget *parent ); + ~MessageActions(); void setMessageView( KMReaderWin *msgView ); /** @@ -76,6 +80,8 @@ KActionMenu* mailingListActionMenu() const { return mMailingListActionMenu; } + KActionMenu* annotationActionMenu() const { return mAnnotationActionMenu; } + public slots: void editCurrentMessage(); @@ -126,6 +132,8 @@ KToggleAction *mToggleFlagAction, *mToggleToActAction; KAction *mEditAction; bool mKorganizerIsOnSystem; + Nepomuk::AnnotationMenu* mAnnotationMenu; + KActionMenu* mAnnotationActionMenu; }; } Index: kmail/messagelistview/widget.cpp =================================================================== --- kmail/messagelistview/widget.cpp (revision 1129091) +++ kmail/messagelistview/widget.cpp (working copy) @@ -688,6 +688,10 @@ menu.addAction( mMainWidget->messageActions()->createTodoAction() ); + menu.addSeparator(); + + menu.addAction( mMainWidget->messageActions()->annotationActionMenu() ); + KAcceleratorManager::manage( &menu ); kmkernel->setContextMenuShown( true ); menu.exec( globalPos ); Index: kmail/kmmessage.h =================================================================== --- kmail/kmmessage.h (revision 1129091) +++ kmail/kmmessage.h (working copy) @@ -51,7 +51,9 @@ namespace KMail { } - +namespace Nepomuk { + class Resource; +} // Real code starts here :) namespace KMail { @@ -841,6 +843,11 @@ DwBodyPart* findPart( int index ); + /** + * Create a Nepomuk resource representing the message. + */ + Nepomuk::Resource nepomukResource() const; + private: /** Initialization shared by the ctors. */ Index: kmail/kmreadermainwin.cpp =================================================================== --- kmail/kmreadermainwin.cpp (revision 1129091) +++ kmail/kmreadermainwin.cpp (working copy) @@ -56,6 +56,9 @@ #include <akonadi/contact/contactsearchjob.h> #include <kpimutils/email.h> +#include <nepomuk/resource.h> +#include <nepomuk/annotationmenu.h> + KMReaderMainWin::KMReaderMainWin( bool htmlOverride, bool htmlLoadExtOverride, char *name ) : KMail::SecondaryWindow( name ? name : "readerwindow#" ), @@ -459,6 +462,8 @@ menu->addAction( mSaveAtmAction ); menu->addSeparator(); menu->addAction( mMsgActions->createTodoAction() ); + menu->addSeparator(); + menu->addAction( mMsgActions->annotationActionMenu() ); } menu->exec( aPoint, 0 ); delete menu; Index: kmail/kmreaderwin.cpp =================================================================== --- kmail/kmreaderwin.cpp (revision 1129091) +++ kmail/kmreaderwin.cpp (working copy) @@ -161,6 +161,12 @@ #include <QTextDocument> #endif +#include "nepomukwidget.h" +#include "annotationwidget.h" +#include <nepomuk/resourcemanager.h> +#include <nepomuk/variant.h> +#include <QCheckBox> + using namespace KMail; // This function returns the complete data that were in this @@ -348,9 +354,9 @@ +#include <nepomuk/resourceeditor.h> +#include <nepomuk/thing.h> - - void KMReaderWin::createWidgets() { QVBoxLayout * vlay = new QVBoxLayout( this ); vlay->setMargin( 0 ); @@ -367,8 +373,22 @@ mColorBar->setObjectName( "mColorBar" ); connect( mColorBar, SIGNAL( clicked() ), this, SLOT( slotToggleHtmlMode() ) ); - mViewer = new KHTMLPart( mBox ); + KVBox* viewerBox = new KVBox(mBox); + QSplitter* viewerSplitter = new QSplitter(viewerBox); + mViewer = new KHTMLPart(viewerSplitter); mViewer->setObjectName( "mViewer" ); + m_annotationWidget = new AnnotationWidget; + viewerSplitter->addWidget(mViewer->widget()); + viewerSplitter->addWidget(m_annotationWidget); + viewerSplitter->setStretchFactor(0, 2); + + connect(m_annotationWidget, SIGNAL(newAnnotation(Nepomuk::Annotation*)), m_annotationWidget, SLOT(show())); + // m_annotationWidget->hide(); + m_nepomukWidget = new NepomukWidget( viewerBox ); + m_nepomukWidget->setKMReaderWin( this ); + viewerBox->setStretchFactor(viewerSplitter, 1); + connect(m_nepomukWidget, SIGNAL(changed()), this, SLOT(slotNepomukDataChanged())); + connect(m_annotationWidget, SIGNAL(annotationCreated()), this, SLOT(slotNepomukDataChanged())); // Remove the shortcut for the selectAll action from khtml part. It's redefined to // CTRL-SHIFT-A in kmail and clashes with kmails CTRL-A action. KAction *selectAll = qobject_cast<KAction*>( @@ -1210,6 +1230,7 @@ //----------------------------------------------------------------------------- void KMReaderWin::setMsg( KMMessage* aMsg, bool force ) { + kDebug() << aMsg << force; if ( aMsg ) { kDebug() << "(" << aMsg->getMsgSerNum() <<", last" << mLastSerNum <<")" << aMsg->subject() << aMsg->fromStrip() << ", readyToShow" << (aMsg->readyToShow()); @@ -1289,6 +1310,18 @@ } } + if ( GlobalSettings::self()->showAnnotationControls() && + Nepomuk::ResourceManager::instance()->initialized() && aMsg ) { + m_nepomukWidget->setResource( aMsg->nepomukResource().pimoThing() ); + m_annotationWidget->setResource( aMsg->nepomukResource().pimoThing(), aMsg->bodyToUnicode() ); + m_nepomukWidget->show(); + m_annotationWidget->show(); + } + else { + m_nepomukWidget->hide(); + m_annotationWidget->hide(); + } + if ( aMsg && (aMsg->status().isUnread() || aMsg->status().isNew()) && GlobalSettings::self()->delayedMarkAsRead() ) { if ( GlobalSettings::self()->delayedMarkTime() != 0 ) @@ -3137,6 +3170,19 @@ mShowFullCcAddressList = showFullCcAddressList; } +void KMReaderWin::slotNepomukDataChanged() +{ + Nepomuk::Resource res = message()->nepomukResource(); + if(res.label().isEmpty()) { + res.setLabel(message()->subject()); + res.setProperty(QUrl::fromEncoded("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent"), message()->bodyToUnicode()); + res.addType(QUrl::fromEncoded("http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#Email")); + res.addProperty(QUrl::fromEncoded("http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#messageId"), QString::number( message()->getMsgSerNum())); + } + // to update the tags + m_nepomukWidget->setResource(res.pimoThing()); +} + #include "kmreaderwin.moc" Index: kmail/kmmessage.cpp =================================================================== --- kmail/kmmessage.cpp (revision 1129091) +++ kmail/kmmessage.cpp (working copy) @@ -76,6 +76,21 @@ #include "util.h" #endif +#include <Nepomuk/Resource> +#include <Nepomuk/Variant> + +Nepomuk::Resource KMMessage::nepomukResource() const +{ + // This is an evil hack which should be fixed as soon as we are ported to Akonadi + //QString id = "nepomuk:/emails/" + parent()->prettyUrl() + '/' + fileName(); + + //This is a less-evil hack + QString msgSerNum = QString::number( getMsgSerNum()); + Nepomuk::Resource mail("XYkmail_msg_" + msgSerNum);//, QUrl( nmoEmail) ); + + return mail; +} + using namespace KMail; using namespace KMime; Index: kmail/configuredialog_p.h =================================================================== --- kmail/configuredialog_p.h (revision 1129091) +++ kmail/configuredialog_p.h (working copy) @@ -464,6 +464,7 @@ QCheckBox *mShrinkQuotesCheck; KComboBox *mCharsetCombo; KComboBox *mOverrideCharsetCombo; + QCheckBox *mShowAnnotations; }; Index: kmail/messageactions.cpp =================================================================== --- kmail/messageactions.cpp (revision 1129091) +++ kmail/messageactions.cpp (working copy) @@ -38,6 +38,9 @@ #include <QVariant> #include <qwidget.h> +#include <nepomuk/annotationmenu.h> +#include <nepomuk/resource.h> + using namespace KMail; MessageActions::MessageActions( KActionCollection *ac, QWidget* parent ) : @@ -185,9 +188,21 @@ this, SLOT(slotRunUrl(QAction *)) ); mActionCollection->addAction( "message_list", mMailingListActionMenu ); + mAnnotationMenu = new Nepomuk::AnnotationMenu(); + Nepomuk::AnnotationMenu::ConfigurationFlags flags = Nepomuk::AnnotationMenu::ShowAll|Nepomuk::AnnotationMenu::UseSubMenus; + mAnnotationMenu->setConfigurationFlags( flags ); + mAnnotationActionMenu = new KActionMenu(KIcon("nepomuk"), i18nc("@title:menu Annotate message using Nepomuk", "Annotate"), this); + mAnnotationActionMenu->setMenu( mAnnotationMenu ); + mActionCollection->addAction( "message_annotate", mAnnotationActionMenu ); + updateActions(); } +MessageActions::~MessageActions() +{ + delete mAnnotationMenu; +} + void MessageActions::setCurrentMessage(KMMessage * msg) { mCurrentMessage = msg; @@ -284,6 +299,7 @@ } else { mMailingListActionMenu->setEnabled( false ); } + mAnnotationMenu->setResource( mCurrentMessage->nepomukResource() ); } mEditAction->setEnabled( singleMsg ); Index: kmail/kmcommands.cpp =================================================================== --- kmail/kmcommands.cpp (revision 1129091) +++ kmail/kmcommands.cpp (working copy) @@ -141,7 +141,10 @@ #include <QList> #include <QTextCodec> #include <QProgressBar> +#include <QDBusInterface> +#include <Nepomuk/Resource> + #include <memory> #include "messagelistview/pane.h" @@ -258,8 +261,8 @@ if ( mMsgList.size() > 0 ) mb = *(mMsgList.begin()); - if ( ( mb ) && ( mMsgList.count() == 1 ) && ( mb->isMessage() ) && - ( mb->parent() == 0 ) ) + if ( ( mb ) && ( mMsgList.count() == 1 ) + && ( mb->isMessage() ) && ( mb->parent() == 0 ) ) { // Special case of operating on message that isn't in a folder mRetrievedMsgs.append((KMMessage*)mMsgList.takeFirst()); @@ -1018,6 +1021,16 @@ setDeletesItself( true ); } +KMOpenMsgCommand2::KMOpenMsgCommand2( QWidget *parent, KMMsgBase* message, + const QString & encoding ) + : KMCommand( parent, message ), + mMsgBase( message ), + mEncoding( encoding ) +{ + Q_ASSERT(message != NULL ); + setDeletesItself( false ); +} + KMCommand::Result KMOpenMsgCommand::execute() { if ( mUrl.isEmpty() ) { @@ -1038,6 +1051,20 @@ return OK; } +KMCommand::Result KMOpenMsgCommand2::execute() +{ + KMReaderMainWin *win = new KMReaderMainWin(); + KMMessage* msg = new KMMessage (*retrievedMessage() ); + msg->setReadyToShow( true ); + Q_ASSERT( msg != NULL ); + win->showMsg( mEncoding, msg); + + win->show(); + + setResult( OK ); + return OK; +} + void KMOpenMsgCommand::slotDataArrived( KIO::Job *, const QByteArray & data ) { if ( data.isEmpty() ) @@ -2192,6 +2219,9 @@ } bool undo = msg->enableUndo(); + // remember nepomuk resource for update later on + QUrl oldNepomukUri = msg->nepomukResource().resourceUri(); + if ( msg->transferInProgress() && srcFolder->folderType() == KMFolderTypeImap ) { @@ -2227,6 +2257,11 @@ undoId = kmkernel->undoStack()->newUndoAction( srcFolder, mDestFolder ); kmkernel->undoStack()->addMsgToAction( undoId, mb->getMsgSerNum() ); } + + // update Nepomuk data (we simply use the service to avoid code duplication) + QUrl newNepomukUri = mDestFolder->getMsg( mDestFolder->count() - 1 )->nepomukResource().resourceUri(); + QDBusInterface("org.kde.nepomuk.services.nepomukfilewatch", "/nepomukfilewatch", "org.kde.nepomuk.FileWatch") + .call("moveFileMetadata", QString::fromAscii(oldNepomukUri.toEncoded()), QString::fromAscii(newNepomukUri.toEncoded())); } else if (rc != 0) { // Something went wrong. Stop processing here, it is likely that the // other moves would fail as well. Index: kmail/kmkernel.cpp =================================================================== --- kmail/kmkernel.cpp (revision 1129091) +++ kmail/kmkernel.cpp (working copy) @@ -2,6 +2,8 @@ #include "kmkernel.h" +#include "proxyobject.h" + #include <config-kmail.h> #include "globalsettings.h" @@ -96,6 +98,8 @@ #include <kmailadaptor.h> #include "kmailinterface.h" +#include <Nepomuk/ResourceManager> + #include "folderadaptor.h" #include "groupware_types.h" static bool s_askingToGoOnline = false; @@ -182,6 +186,8 @@ connect( MailTransport::TransportManager::self(), SIGNAL(transportRenamed(int,QString,QString)), SLOT(transportRenamed(int,QString,QString)) ); + + Nepomuk::ResourceManager::instance()->init(); } KMKernel::~KMKernel () @@ -234,10 +240,12 @@ QString to, cc, bcc, subj, body; QStringList customHeaders; KUrl messageFile; + unsigned long msgSerNum = 0; KUrl::List attachURLs; bool mailto = false; bool checkMail = false; bool viewOnly = false; + bool viewOnlyId = false; bool calledWithSession = false; // for ignoring '-session foo' // process args: @@ -321,6 +329,15 @@ } } + if (args->isSet( "viewid" ) ) { + viewOnlyId = true; + const QString MsgSerNum = args->getOption( "viewid" ); + bool conv_ok; + msgSerNum = MsgSerNum.toInt(&conv_ok); + Q_ASSERT(conv_ok != false); + //kDebug() << "MESSAGE SERIAL NUM:" << MsgSerNum; + } + if ( !calledWithSession ) { // only read additional command line arguments if kmail/kontact is // not called with "-session foo" @@ -361,7 +378,9 @@ if ( !noArgsOpensReader && !mailto && !checkMail && !viewOnly ) return false; - if ( viewOnly ) + if ( viewOnlyId ) + viewMessage( msgSerNum ); + else if ( viewOnly ) viewMessage( messageFile ); else action( mailto, checkMail, to, cc, bcc, subj, body, messageFile, @@ -736,6 +755,14 @@ return 1; } +int KMKernel::viewMessage( unsigned long msgSerNum ) +{ + proxyObject* prox = new proxyObject(msgSerNum, this); + QTimer::singleShot(2000, prox, SLOT( Proxy() )); + + return 1; +} + int KMKernel::sendCertificate( const QString& to, const QByteArray& certData ) { KMMessage *msg = new KMMessage; Index: kmail/kmail_options.h =================================================================== --- kmail/kmail_options.h (revision 1129091) +++ kmail/kmail_options.h (working copy) @@ -22,6 +22,7 @@ options.add("check", ki18n("Only check for new mail")); options.add("composer", ki18n("Only open composer window")); options.add("view <url>", ki18n("View the given message file" )); + options.add("viewid <msg id>", ki18n("View the given message corresponding to the kmail id" )); options.add("+[address|URL]", ki18n("Send message to 'address' resp. " "attach the file the 'URL' points " "to")); Index: kmail/kmmainwidget.cpp =================================================================== --- kmail/kmmainwidget.cpp (revision 1129091) +++ kmail/kmmainwidget.cpp (working copy) @@ -3434,6 +3434,9 @@ menu->addSeparator(); menu->addAction( mMsgActions->createTodoAction() ); + + menu->addSeparator(); + menu->addAction( mMsgActions->annotationActionMenu() ); } KAcceleratorManager::manage(menu); menu->exec( aPoint, 0 ); Index: kmail/annotationwidget.h =================================================================== --- kmail/annotationwidget.h (revision 0) +++ kmail/annotationwidget.h (revision 0) @@ -0,0 +1,61 @@ +/* + This file is part of KMail, the KDE mail client. + Copyright (c) 2009 Sebastian Trueg <trueg@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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. +*/ + +#ifndef _KMAIL_ANNOTATION_WIDGET_H_ +#define _KMAIL_ANNOTATION_WIDGET_H_ + +#include <QtGui/QWidget> + +#include <Nepomuk/Resource> + +namespace Nepomuk { + class ResourceAnnotationModel; + class AnnotationRelevanceFilterModel; + class Annotation; +} +class QListView; +class QModelIndex; + +class AnnotationWidget : public QWidget +{ + Q_OBJECT + +public: + AnnotationWidget( QWidget* parent = 0 ); + ~AnnotationWidget(); + + void setResource( const Nepomuk::Resource& res, const QString& content ); + +protected: + //virtual QSize sizeHint() const { return QSize(200, 300); } + +Q_SIGNALS: + void newAnnotation( Nepomuk::Annotation* ); + void annotationCreated(); + +private Q_SLOTS: + void slotAnnotationExecuted( const QModelIndex& ); + +private: + Nepomuk::ResourceAnnotationModel* m_model; + Nepomuk::AnnotationRelevanceFilterModel* m_filterModel; + QListView* m_listView; +}; + +#endif Index: kmail/kmail.kcfg.cmake =================================================================== --- kmail/kmail.kcfg.cmake (revision 1129091) +++ kmail/kmail.kcfg.cmake (working copy) @@ -303,6 +303,10 @@ <label>Hide local inbox if unused</label> <default>true</default> </entry> + <entry name="ShowAnnotationControls" type="Bool"> + <label>Show Nepomuk annotations</label> + <default>true</default> + </entry> </group> <group name="Composer"> Index: kmail/kmcommands.h =================================================================== --- kmail/kmcommands.h (revision 1129091) +++ kmail/kmcommands.h (working copy) @@ -374,6 +374,23 @@ const QString mEncoding; }; +class KMAIL_EXPORT KMOpenMsgCommand2 : public KMCommand +{ + Q_OBJECT +public: + explicit KMOpenMsgCommand2( QWidget *parent, KMMsgBase* msgbase, + const QString & encoding = QString() ); +private: + virtual KMCommand::Result execute(); + + // private slots: + // void slotResult(); + + private: + KMMsgBase* mMsgBase; + const QString mEncoding; +}; + class KMAIL_EXPORT KMSaveAttachmentsCommand : public KMCommand { Q_OBJECT Index: kmail/kmreaderwin.h =================================================================== --- kmail/kmreaderwin.h (revision 1129091) +++ kmail/kmreaderwin.h (working copy) @@ -37,6 +37,9 @@ #include <map> +class NepomukWidget; +class AnnotationWidget; + class QSplitter; class KHBox; class QTreeWidgetItem; @@ -97,6 +100,7 @@ friend class KMail::ObjectTreeParser; friend class KMail::KHtmlPartHtmlWriter; + //friend class NepomukWidget; //MINE public: KMReaderWin( QWidget *parent, QWidget *mainWindow, @@ -557,6 +561,7 @@ private slots: void slotSetEncoding(); void injectAttachments(); + void slotNepomukDataChanged(); /** Show hide all fields specified inside this function */ void toggleFullAddressList(); @@ -653,6 +658,8 @@ bool mExternalWindow; bool mShowFullToAddressList; bool mShowFullCcAddressList; + NepomukWidget* m_nepomukWidget; + AnnotationWidget* m_annotationWidget; }; Index: kmail/configuredialog.cpp =================================================================== --- kmail/configuredialog.cpp (revision 1129091) +++ kmail/configuredialog.cpp (working copy) @@ -1922,6 +1922,12 @@ hlay2->addWidget( label ); hlay2->addWidget( mOverrideCharsetCombo ); + populateCheckBox( mShowAnnotations = new QCheckBox( this ), + GlobalSettings::self()->showAnnotationControlsItem() ); + vlay->addWidget( mShowAnnotations ); + connect( mShowAnnotations, SIGNAL ( stateChanged( int ) ), + this, SLOT( slotEmitChanged() ) ); + vlay->addStretch( 100 ); // spacer } @@ -1988,6 +1994,7 @@ mShrinkQuotesCheck->setChecked( GlobalSettings::self()->shrinkQuotes() ); mShowExpandQuotesMark->setChecked( GlobalSettings::self()->showExpandQuotesMark() ); mCollapseQuoteLevelSpin->setValue( GlobalSettings::self()->collapseQuoteLevelSpin() ); + mShowAnnotations->setChecked( GlobalSettings::self()->showAnnotationControls() ); readCurrentFallbackCodec(); readCurrentOverrideCodec(); } @@ -2014,6 +2021,7 @@ mOverrideCharsetCombo->currentIndex() == 0 ? QString() : KMMsgBase::encodingForName( mOverrideCharsetCombo->currentText() ) ); + GlobalSettings::self()->setShowAnnotationControls( mShowAnnotations->isChecked() ); } QString AppearancePage::SystemTrayTab::helpAnchor() const Index: kmail/proxyobject.cpp =================================================================== --- kmail/proxyobject.cpp (revision 0) +++ kmail/proxyobject.cpp (revision 0) @@ -0,0 +1,25 @@ +#include "proxyobject.h" +#include "kmmsgbase.h" +#include "kmmsgdict.h" +#include "kmcommands.h" +#include "kmfolder.h" + +void proxyObject::Proxy() +{ + KMFolder* folder; + KMMsgBase* msgbase; + int index; + + KMMsgDict::instance()->getLocation( msgSerNum, &folder, &index ); + if ( folder != NULL && index != -1 ) { + kFatal("msg serial number not found ; the serial number provided may incorrect"); + } + folder->open("viewid"); + msgbase = folder->getMsgBase( index ); + Q_ASSERT( msgbase != NULL ); + + KMOpenMsgCommand2 *openCommand = new KMOpenMsgCommand2( 0, msgbase ); + openCommand->start(); +} + +#include "proxyobject.moc" Index: kmail/kmkernel.h =================================================================== --- kmail/kmkernel.h (revision 1129091) +++ kmail/kmkernel.h (working copy) @@ -14,6 +14,7 @@ #include <kconfig.h> #include <kurl.h> +#include "kmmsgbase.h" #include "kmail_export.h" #include "kmmsgbase.h" #include "kmmessagetag.h" @@ -233,6 +234,7 @@ Q_SCRIPTABLE QString debugSernum( quint32 serialNumber ); Q_SCRIPTABLE int viewMessage( const KUrl & messageFile ); + Q_SCRIPTABLE int viewMessage( unsigned long msgSerNum ); Q_SIGNALS: Index: kmail/nepomukwidget.cpp =================================================================== --- kmail/nepomukwidget.cpp (revision 0) +++ kmail/nepomukwidget.cpp (revision 0) @@ -0,0 +1,102 @@ +/* + This file is part of KMail, the KDE mail client. + Copyright (c) 2009 Sebastian Trueg <trueg@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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 "nepomukwidget.h" + +#include "kmreaderwin.h" +#include "kmmessage.h" + +#include <nepomuk/annotationwidget.h> +#include <nepomuk/kmetadatatagwidget.h> +#include <nepomuk/kratingwidget.h> +#include <nepomuk/annotationmenu.h> + +#include <QHBoxLayout> +#include <QLabel> +#include <KIcon> +#include <KMessageBox> +#include <QPushButton> +#include <KLocale> + +#include <Nepomuk/Resource> +#include <Nepomuk/Variant> +#include <Nepomuk/Thing> + +#include <KDebug> + +NepomukWidget::NepomukWidget( QWidget* parent ) + : QWidget( parent ) +{ + QHBoxLayout* lay = new QHBoxLayout(this); + m_tagWidget = new Nepomuk::TagWidget(this); + m_ratingWidget = new KRatingWidget(this); + m_annotationWidget = new Nepomuk::AnnotationWidget(this); + m_tasksButton = new QPushButton( i18n("More..."), this ); + + lay->addWidget(m_tagWidget); + lay->addWidget(m_ratingWidget); + lay->addWidget(m_tasksButton); + lay->addWidget(m_annotationWidget); + + m_tagWidget->setModeFlags( Nepomuk::TagWidget::MiniMode|Nepomuk::TagWidget::DisableTagClicking ); + + connect( m_ratingWidget, SIGNAL( ratingChanged( int ) ), + this, SLOT( slotRatingChanged( int ) ) ); + connect( m_annotationWidget, SIGNAL(annotationAdded(Nepomuk::Resource)), + this, SIGNAL(changed())); + + connect( m_tasksButton, SIGNAL( clicked( bool )), + this, SLOT( associateToATask() )); +} + +NepomukWidget::~NepomukWidget() +{ +} + +void NepomukWidget::setKMReaderWin( KMReaderWin* kmreaderwin) +{ + m_kmreaderwin = kmreaderwin; +} + +void NepomukWidget::associateToATask() +{ + Nepomuk::AnnotationMenu menu; + Nepomuk::AnnotationMenu::ConfigurationFlags flags = Nepomuk::AnnotationMenu::ShowAll|Nepomuk::AnnotationMenu::UseSubMenus; + flags &= ~Nepomuk::AnnotationMenu::ShowRatingAction; + flags &= ~Nepomuk::AnnotationMenu::ShowTagActions; + menu.setConfigurationFlags( flags ); + menu.setResource( m_resource ); + menu.exec( QCursor::pos() ); +} + +void NepomukWidget::setResource( const Nepomuk::Resource& res ) +{ + m_resource = res; + m_tagWidget->setTaggedResource( res ); + m_annotationWidget->setResource( res ); + m_ratingWidget->setRating( res.rating() ); +} + +void NepomukWidget::slotRatingChanged(int rating) +{ + m_resource.setRating(rating); + emit changed(); +} + +#include "nepomukwidget.moc" Index: kmail/nepomukwidget.h =================================================================== --- kmail/nepomukwidget.h (revision 0) +++ kmail/nepomukwidget.h (revision 0) @@ -0,0 +1,66 @@ +/* + This file is part of KMail, the KDE mail client. + Copyright (c) 2009 Sebastian Trueg <trueg@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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. +*/ + +#ifndef _KMAIL_NEPOMUK_WIDGET_H_ +#define _KMAIL_NEPOMUK_WIDGET_H_ + +#include <QtGui/QWidget> + +#include <Nepomuk/Resource> + +namespace Nepomuk { + class AnnotationWidget; + class TagWidget; +} +class KRatingWidget; +class KMReaderWin; +class QPushButton; + +class NepomukWidget : public QWidget +{ + Q_OBJECT + +public: + NepomukWidget( QWidget* parent = 0 ); + ~NepomukWidget(); + + void setResource( const Nepomuk::Resource& res ); + void setKMReaderWin( KMReaderWin* ); + +Q_SIGNALS: + /** + * Emitted if an annotation has been added or a rating changed + * or whateever. + */ + void changed(); + +private Q_SLOTS: + void slotRatingChanged(int); + void associateToATask(); + +private: + Nepomuk::AnnotationWidget* m_annotationWidget; + Nepomuk::TagWidget* m_tagWidget; + KRatingWidget* m_ratingWidget; + Nepomuk::Resource m_resource; + KMReaderWin* m_kmreaderwin; + QPushButton* m_tasksButton; +}; + +#endif Index: kmail/CMakeLists.txt =================================================================== --- kmail/CMakeLists.txt (revision 1129091) +++ kmail/CMakeLists.txt (working copy) @@ -252,6 +252,9 @@ procmailparser.cpp stringutil.cpp iconnamecache.cpp + nepomukwidget.cpp + proxyobject.cpp + annotationwidget.cpp mdnadvicedialog.cpp htmlquotecolorer.cpp attachmentdialog.cpp @@ -370,6 +373,7 @@ ${KDE4_KIMAP_LIBRARY} ${KDE4_KPARTS_LIBRARY} ${KDE4_KRESOURCES_LIBRARY} + ${KDE4_KFILE_LIBS} kleo ${QGPGME_LIBRARIES} mimelib @@ -381,6 +385,11 @@ ${KDEPIMLIBS_KPIMUTILS_LIBS} ${KDEPIMLIBS_KPIMTEXTEDIT_LIBS} ${QT_QT3SUPPORT_LIBRARY} + ${NEPOMUK_LIBRARIES} + nepomukannotation + nepomuk + nepomukutils + nepomuktasks ) if(INDICATEQT_FOUND) Index: kmail/annotationwidget.cpp =================================================================== --- kmail/annotationwidget.cpp (revision 0) +++ kmail/annotationwidget.cpp (revision 0) @@ -0,0 +1,79 @@ +/* + This file is part of KMail, the KDE mail client. + Copyright (c) 2009 Sebastian Trueg <trueg@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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 "annotationwidget.h" + +#include <nepomuk/resourceannotationmodel.h> +#include <nepomuk/annotationrelevancefiltermodel.h> +#include <nepomuk/annotation.h> +#include <nepomuk/resourcemanager.h> + +#include <QHBoxLayout> +#include <QLabel> +#include <QListView> +#include <KDebug> + +#include <KLocale> + +Q_DECLARE_METATYPE(Nepomuk::Annotation*) + +AnnotationWidget::AnnotationWidget( QWidget* parent ) + : QWidget( parent ) +{ + QVBoxLayout* lay = new QVBoxLayout(this); + m_listView = new QListView(this); + lay->addWidget(new QLabel(i18n("Suggestions:"), this)); + lay->addWidget(m_listView); + + m_model = new Nepomuk::ResourceAnnotationModel(m_listView); + m_model->setAutoUpdate(false); + m_filterModel = new Nepomuk::AnnotationRelevanceFilterModel(m_model); + m_filterModel->setSourceModel(m_model); + m_filterModel->setSortRole(Nepomuk::AnnotationModel::RelevanceRole); + m_filterModel->setDynamicSortFilter(true); + m_listView->setModel(m_filterModel); + + connect(m_listView, SIGNAL(activated(QModelIndex)), + this, SLOT(slotAnnotationExecuted(QModelIndex))); +} + + +AnnotationWidget::~AnnotationWidget() +{ +} + + +void AnnotationWidget::setResource( const Nepomuk::Resource& res, const QString& content ) +{ + m_model->setResource(res); + m_model->setContent(content); + m_filterModel->setFilterResource(res); + m_model->updateAnnotations(); +} + + +void AnnotationWidget::slotAnnotationExecuted( const QModelIndex& index ) +{ + Nepomuk::Annotation* anno = index.data( Nepomuk::AnnotationModel::AnnotationRole ).value<Nepomuk::Annotation*>(); + connect(anno, SIGNAL(finished(Nepomuk::Annotation*)), this, SIGNAL(annotationCreated())); + connect(anno, SIGNAL(finished(Nepomuk::Annotation*)), anno, SLOT(deleteLater())); + anno->create(m_model->resource()); +} + +#include "annotationwidget.moc"