diff options
-rw-r--r-- | src/CMakeLists.txt | 13 | ||||
-rw-r--r-- | src/bookmarks/bookmarkowner.cpp | 24 | ||||
-rw-r--r-- | src/bookmarks/bookmarkowner.h | 2 | ||||
-rw-r--r-- | src/bookmarks/bookmarkscontextmenu.cpp | 1 | ||||
-rw-r--r-- | src/urlbar/bookmarkwidget.cpp | 161 | ||||
-rw-r--r-- | src/urlbar/bookmarkwidget.h | 24 | ||||
-rw-r--r-- | src/urlbar/newresourcedialog.cpp | 108 | ||||
-rw-r--r-- | src/urlbar/newresourcedialog.h | 50 | ||||
-rw-r--r-- | src/urlbar/resourcelinkdialog.cpp | 347 | ||||
-rw-r--r-- | src/urlbar/resourcelinkdialog.h | 66 |
10 files changed, 778 insertions, 18 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7fd1cfc5..afdb9ec9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,6 +84,8 @@ SET( rekonq_KDEINIT_SRCS urlbar/bookmarkwidget.cpp urlbar/webshortcutwidget.cpp urlbar/favoritewidget.cpp + urlbar/resourcelinkdialog.cpp + urlbar/newresourcedialog.cpp #---------------------------------------- analyzer/analyzerpanel.cpp analyzer/networkanalyzer.cpp @@ -138,7 +140,10 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS ) KDE4_ADD_KCFG_FILES( rekonq_KDEINIT_SRCS rekonq.kcfgc ) - +find_package(KDE4 REQUIRED) +find_package(Nepomuk REQUIRED) +include(SopranoAddOntology) +include (KDE4Defaults) ### ------------- INCLUDING DIRECTORIES... @@ -155,6 +160,9 @@ INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDES} ${QT4_INCLUDES} + ${SOPRANO_INCLUDE_DIR} + ${CMAKE_SOURCE_DIR} + ${NEPOMUK_INCLUDE_DIR} ) @@ -182,6 +190,9 @@ TARGET_LINK_LIBRARIES ( kdeinit_rekonq ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KPARTS_LIBS} + ${NEPOMUK_LIBRARIES} + ${NEPOMUK_QUERY_LIBRARIES} + ${SOPRANO_LIBRARIES} ) diff --git a/src/bookmarks/bookmarkowner.cpp b/src/bookmarks/bookmarkowner.cpp index 141807ca..74683874 100644 --- a/src/bookmarks/bookmarkowner.cpp +++ b/src/bookmarks/bookmarkowner.cpp @@ -37,11 +37,15 @@ #include "mainview.h" #include "mainwindow.h" #include "webtab.h" +#include "resourcelinkdialog.h" // KDE Includes #include <KBookmarkDialog> #include <KLocalizedString> #include <KMessageBox> +#include <Nepomuk/Resource> +#include <Nepomuk/Vocabulary/NFO> + // Qt Includes #include <QClipboard> @@ -86,6 +90,9 @@ KAction* BookmarkOwner::createAction(const KBookmark &bookmark, const BookmarkAc case EDIT: return createAction(i18n("Edit"), "configure", i18n("Edit the bookmark"), SLOT(editBookmark(KBookmark)), bookmark); + case FANCYBOOKMARK: + return createAction(i18n("Fancy Bookmark"), "nepomuk", + i18n("Link Nepomuk resources"), SLOT(fancyBookmark(KBookmark)), bookmark); case DELETE: return createAction(i18n("Delete"), "edit-delete", i18n("Delete the bookmark"), SLOT(deleteBookmark(KBookmark)), bookmark); @@ -205,13 +212,19 @@ KBookmark BookmarkOwner::bookmarkCurrentPage(const KBookmark &bookmark) else { parent = rApp->bookmarkManager()->rootGroup(); + Nepomuk::Resource nfoResource; + nfoResource = ((QUrl)currentUrl()); + nfoResource.addType( Nepomuk::Vocabulary::NFO::Website() ); + nfoResource.setLabel( currentTitle() ); + qDebug()<<nfoResource.uri(); + } KBookmark newBk = parent.addBookmark(currentTitle(), KUrl(currentUrl())); if (!bookmark.isNull()) parent.moveBookmark(newBk, bookmark); - m_manager->emitChanged(parent); + m_manager->emitChanged(parent); return newBk; } @@ -297,6 +310,13 @@ void BookmarkOwner::editBookmark(KBookmark bookmark) delete dialog; } +void BookmarkOwner::fancyBookmark(KBookmark bookmark) +{ + Nepomuk::Resource nfoResource = (KUrl)bookmark.url(); + Nepomuk::ResourceLinkDialog r( nfoResource ); + r.exec(); + +} bool BookmarkOwner::deleteBookmark(const KBookmark &bookmark) { @@ -334,6 +354,8 @@ bool BookmarkOwner::deleteBookmark(const KBookmark &bookmark) return false; bmg.deleteBookmark(bookmark); + Nepomuk::Resource nfoResource(bookmark.url()); + nfoResource.remove(); m_manager->emitChanged(bmg); return true; } diff --git a/src/bookmarks/bookmarkowner.h b/src/bookmarks/bookmarkowner.h index c362fe5e..a9712d55 100644 --- a/src/bookmarks/bookmarkowner.h +++ b/src/bookmarks/bookmarkowner.h @@ -60,6 +60,7 @@ public: NEW_SEPARATOR, COPY, EDIT, + FANCYBOOKMARK, DELETE, NUM_ACTIONS, SET_TOOLBAR_FOLDER, @@ -107,6 +108,7 @@ public Q_SLOTS: void copyLink(const KBookmark &bookmark); void editBookmark(KBookmark bookmark); + void fancyBookmark(KBookmark bookmark); bool deleteBookmark(const KBookmark &bookmark); void setToolBarFolder(KBookmark bookmark = KBookmark()); void unsetToolBarFolder(); diff --git a/src/bookmarks/bookmarkscontextmenu.cpp b/src/bookmarks/bookmarkscontextmenu.cpp index 355a6d7f..bc8f0e3a 100644 --- a/src/bookmarks/bookmarkscontextmenu.cpp +++ b/src/bookmarks/bookmarkscontextmenu.cpp @@ -67,6 +67,7 @@ void BookmarksContextMenu::addBookmarkActions() addSeparator(); addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::EDIT)); + addAction(m_bmOwner->createAction(bookmark(),BookmarkOwner::FANCYBOOKMARK)); addAction(m_bmOwner->createAction(bookmark(), BookmarkOwner::DELETE)); } diff --git a/src/urlbar/bookmarkwidget.cpp b/src/urlbar/bookmarkwidget.cpp index 536befb8..ea278218 100644 --- a/src/urlbar/bookmarkwidget.cpp +++ b/src/urlbar/bookmarkwidget.cpp @@ -33,18 +33,26 @@ #include "application.h" #include "bookmarkmanager.h" #include "bookmarkowner.h" +#include "resourcelinkdialog.h" // KDE Includes #include <KComboBox> #include <KLocalizedString> #include <KIcon> #include <KLineEdit> +#include <KRatingWidget> // Qt Includes -#include <QDialogButtonBox> -#include <QFormLayout> -#include <QLabel> -#include <QPushButton> +#include <QtGui/QDialogButtonBox> +#include <QtGui/QFormLayout> +#include <QtGui/QLabel> +#include <QtGui/QPushButton> +#include <QCompleter> +#include <QTextCursor> + +//Nepomuk Includes +#include <Soprano/Vocabulary/NAO> + BookmarkWidget::BookmarkWidget(const KBookmark &bookmark, QWidget *parent) @@ -52,30 +60,42 @@ BookmarkWidget::BookmarkWidget(const KBookmark &bookmark, QWidget *parent) , m_bookmark(new KBookmark(bookmark)) { setAttribute(Qt::WA_DeleteOnClose); - setFixedWidth(350); + setFixedWidth(320); - QFormLayout *layout = new QFormLayout(this); + m_nfoResource = (QUrl)m_bookmark->url(); + QFormLayout *layout = new QFormLayout(this); + layout->setHorizontalSpacing(20); // Bookmark icon - QLabel *bookmarkIcon = new QLabel(this); - bookmarkIcon->setPixmap(KIcon("bookmarks").pixmap(32, 32)); +// QLabel *bookmarkIcon = new QLabel(this); +// bookmarkIcon->setPixmap(KIcon("bookmarks").pixmap(32, 32)); // Title - QVBoxLayout *vLayout = new QVBoxLayout; + QHBoxLayout *hLayout = new QHBoxLayout; QLabel *bookmarkInfo = new QLabel(this); - bookmarkInfo->setText(i18n("Edit this Bookmark")); + bookmarkInfo->setText(i18n(" Bookmark")); QFont f = bookmarkInfo->font(); f.setBold(true); bookmarkInfo->setFont(f); - vLayout->addWidget(bookmarkInfo); + // Remove button + QLabel *removeLabel = new QLabel( this ); + removeLabel->setText( i18n( "<a href='Remove'>Remove</a>" ) ); + removeLabel->setAlignment( Qt::AlignRight ); + hLayout->addWidget(bookmarkInfo); + hLayout->addWidget(removeLabel); + layout->addRow(hLayout); + + connect(removeLabel, SIGNAL( linkActivated(QString) ), this, SLOT( removeBookmark() )); + + /* QPushButton *removeButton = new QPushButton(this); removeButton->setText(i18n("Remove this Bookmark")); connect(removeButton, SIGNAL(clicked()), this, SLOT(removeBookmark())); vLayout->addWidget(removeButton); - - layout->addRow(bookmarkIcon, vLayout); +*/ + //layout->addRow(bookmarkIcon, vLayout); //Bookmark Folder QLabel *folderLabel = new QLabel(this); @@ -100,6 +120,53 @@ BookmarkWidget::BookmarkWidget(const KBookmark &bookmark, QWidget *parent) } layout->addRow(nameLabel, m_name); + QLabel* rateLabel = new QLabel(this); + rateLabel->setText( i18n( "Rate:" ) ); + KRatingWidget *ratingWidget = new KRatingWidget( this ); + if( m_nfoResource.rating() != NULL ) { + ratingWidget->setRating( m_nfoResource.rating() ); + } + connect( ratingWidget, SIGNAL( ratingChanged( int ) ), this, SLOT( setRatingSlot( int ) ) ); + ratingWidget->setToolTip( i18n( "Rate this page" ) ); + layout->addRow( rateLabel,ratingWidget ); + + //Add comments + QLabel *commentLabel = new QLabel( this ); + commentLabel->setText( i18n( "Describe:" ) ); + commentLabel->setAlignment( Qt::AlignCenter ); + m_commentEdit = new QPlainTextEdit( this ); + if( !m_nfoResource.description().isEmpty() ) { + m_commentEdit->setPlainText( m_nfoResource.description() ); + } + connect( m_commentEdit, SIGNAL(textChanged()), this, SLOT(addCommentSlot()) ); + layout->addRow( commentLabel, m_commentEdit ); + + //Create tags + QLabel *tagLabel = new QLabel( this ); + tagLabel->setText( i18n( "Tags:" ) ); + tagLabel->setAlignment( Qt::AlignLeft ); + m_tagLine = new KLineEdit( this ); + m_tagLine->setPlaceholderText( i18n( "add tags(comma separated)" ) ); + + //m_tagList = new QGridLayout( this ); + + QList<Nepomuk::Tag> tagList = Nepomuk::Tag::allTags(); + Q_FOREACH(Nepomuk::Tag t,tagList) { + m_tList.append(t.label()); + } + QCompleter *completeTag = new QCompleter( m_tList ); + completeTag->setCompletionMode(QCompleter::PopupCompletion); + m_tagLine->setCompleter(completeTag); + loadTags(); + + // connect( m_tagLine,SIGNAL( textEdited(QString) ),this,SLOT( tagListSlot() ) ); + layout->addRow(tagLabel,m_tagLine); +// layout->addRow(m_tagList); + + QPushButton *linkToResource = new QPushButton( this ); + linkToResource->setText( i18n( "Link Resources" ) ); + connect(linkToResource, SIGNAL(clicked()), this, SLOT( linkToResourceSlot() ) ); + layout->addWidget(linkToResource); // Ok & Cancel buttons QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); @@ -131,7 +198,6 @@ void BookmarkWidget::accept() m_bookmark->setFullText(m_name->text()); rApp->bookmarkManager()->emitChanged(); } - QString folderAddress = m_folder->itemData(m_folder->currentIndex()).toString(); KBookmarkGroup a = rApp->bookmarkManager()->manager()->findByAddress(folderAddress).toGroup(); @@ -139,6 +205,7 @@ void BookmarkWidget::accept() parent.deleteBookmark(*m_bookmark); a.addBookmark(*m_bookmark); rApp->bookmarkManager()->manager()->emitChanged(a); + parseTags(); close(); } @@ -194,3 +261,69 @@ void BookmarkWidget::removeBookmark() emit updateIcon(); } + + + +void BookmarkWidget::addTags(QList<Nepomuk::Tag> tagList) +{ + foreach( const Nepomuk::Tag &tag,tagList) { + if(!m_nfoResource.tags().contains(tag)) { + m_nfoResource.addTag(tag); + } + } + foreach( Nepomuk::Tag tag,m_nfoResource.tags()) { + if(!tagList.contains(tag)) { + tag.remove(); + } + } +} + +void BookmarkWidget::parseTags() +{ + QList<Nepomuk::Tag> tagList; + if(m_tagLine->text().contains(',')) { + QString text = m_tagLine->text(); + QStringList tagStringList = text.split( QChar::fromAscii(',') ); + + foreach( const QString &tag, tagStringList ) { + QString trimmedTag = tag.trimmed(); + if( !trimmedTag.isEmpty() ) + tagList << trimmedTag; + } + } + else { + tagList<<m_tagLine->text().trimmed(); + } + addTags(tagList); +} + +void BookmarkWidget::loadTags() { + + QString list; + if(!m_nfoResource.tags().isEmpty()) { + foreach( const Nepomuk::Tag &tag, m_nfoResource.tags() ) { + list.append(tag.genericLabel()); + list.append(","); + } + m_tagLine->setText(list); + } + +} + +void BookmarkWidget::setRatingSlot( int rate ) +{ + m_nfoResource.setRating(rate); +} +void BookmarkWidget::addCommentSlot() +{ + m_nfoResource.setDescription(m_commentEdit->toPlainText()); +} + + +void BookmarkWidget::linkToResourceSlot() +{ + Nepomuk::ResourceLinkDialog r( m_nfoResource ); + r.exec(); +} + + diff --git a/src/urlbar/bookmarkwidget.h b/src/urlbar/bookmarkwidget.h index c2985759..01f672e9 100644 --- a/src/urlbar/bookmarkwidget.h +++ b/src/urlbar/bookmarkwidget.h @@ -29,7 +29,13 @@ #define BOOKMARKWIDGET_H // Qt Includes -#include <QMenu> +#include <QtGui/QMenu> +#include <QtGui/QGridLayout> +#include <QtGui/QPlainTextEdit> + +#include <Nepomuk/Resource> +#include <Nepomuk/Tag> +#include <Nepomuk/Vocabulary/NFO> // Forward Declarations class KBookmark; @@ -46,20 +52,34 @@ public: virtual ~BookmarkWidget(); void showAt(const QPoint &pos); + void addTags(QList<Nepomuk::Tag>); + void parseTags(); + void loadTags(); Q_SIGNALS: void updateIcon(); + private Q_SLOTS: void accept(); void removeBookmark(); + void setRatingSlot( int rate ); + void addCommentSlot(); + void linkToResourceSlot(); + //void tagListSlot(); private: KBookmark *m_bookmark; KLineEdit *m_name; KComboBox *m_folder; + KLineEdit *m_tagLine; + QPlainTextEdit *m_commentEdit; + //QGridLayout* m_tagList; + Nepomuk::Resource m_nfoResource; + QStringList m_tList; + void setupFolderComboBox(); }; -#endif // BOOKMARKWIDGET_H +#endif diff --git a/src/urlbar/newresourcedialog.cpp b/src/urlbar/newresourcedialog.cpp new file mode 100644 index 00000000..9e0ed223 --- /dev/null +++ b/src/urlbar/newresourcedialog.cpp @@ -0,0 +1,108 @@ +/* + This is a part of the GSoC project - Fancy Bookmarking + Copyright 2011 Phaneendra Hegde <pnh.pes@gmail.com> + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +//Local Includes +#include "newresourcedialog.h" + +//Nepomuk Includes +#include <Nepomuk/Vocabulary/NCO> +#include <Nepomuk/Vocabulary/PIMO> +#include <Nepomuk/Resource> +#include <Nepomuk/Tag> + +//Qt Includes +#include <QPlainTextEdit> +#include <QVBoxLayout> +#include <QLabel> + +class Nepomuk::NewResourceDialog::Private +{ +public: + KLineEdit *m_resourceName; + QPlainTextEdit *m_description; + QLabel *m_titleResource; + QLabel *m_desResource; + Nepomuk::NewResourceDialog *q; + Nepomuk::Resource m_nofResource; + int m_index; +}; + + +Nepomuk::NewResourceDialog::NewResourceDialog( int index, Nepomuk::Resource& nfoResource, QWidget* parent ): + KDialog( parent ), + d( new Private() ) +{ + d->q = this; + d->m_index = index; + d->m_nofResource =nfoResource; + setWindowTitle( i18n( "Link to new Resource" ) ); + setButtonText( Ok, i18n( "Link" ) ); + setMinimumSize( 200, 150 ); + + QVBoxLayout *layout = new QVBoxLayout( mainWidget() ); + d->m_resourceName = new KLineEdit( mainWidget() ); + d->m_titleResource = new QLabel( mainWidget() ); + d->m_titleResource->setText( i18n( "* Resource Name:" ) ); + layout->addWidget( d->m_titleResource ); + layout->addWidget( d->m_resourceName ); + d->m_description = new QPlainTextEdit( mainWidget() ); + d->m_desResource = new QLabel( mainWidget() ); + d->m_desResource->setText( i18n( "Description (Optional)" )); + layout->addWidget( d->m_desResource); + layout->addWidget( d->m_description ); + + connect( this, SIGNAL( okClicked() ), this, SLOT( newResourceSlot() ) ); +} + + +Nepomuk::NewResourceDialog::~NewResourceDialog() +{ + delete d; +} + + +void Nepomuk::NewResourceDialog::newResourceSlot() +{ + if( d->m_index == 1 ) { + Nepomuk::Resource newResource( d->m_resourceName->text(), Nepomuk::Vocabulary::PIMO::Person() ); + newResource.addSymbol( "user-identity" ); + d->m_nofResource.addIsRelated( newResource ); + } + else if( d->m_index == 2 ) { + Nepomuk::Resource newResource( d->m_resourceName->text(), Nepomuk::Vocabulary::PIMO::Project() ); + newResource.addSymbol( "project-development" ); + d->m_nofResource.addIsRelated( newResource ); + } + else if( d->m_index == 3 ) { + Nepomuk::Resource newResource( d->m_resourceName->text(), Nepomuk::Vocabulary::PIMO::Task() ); + newResource.addSymbol( "view-pim-tasks" ); + d->m_nofResource.addIsRelated( newResource ); + } + else if( d->m_index == 4 ) { + Nepomuk::Resource newResource( d->m_resourceName->text(), Nepomuk::Vocabulary::PIMO::Location() ); + newResource.addSymbol( "user-location" ); + d->m_nofResource.addIsRelated( newResource ); + } + else if( d->m_index == 5 ) { + Nepomuk::Resource newResource( d->m_resourceName->text(), Nepomuk::Vocabulary::PIMO::Note() ); + newResource.addSymbol( "knotes" ); + d->m_nofResource.addIsRelated( newResource ); + } +} diff --git a/src/urlbar/newresourcedialog.h b/src/urlbar/newresourcedialog.h new file mode 100644 index 00000000..0bfcd0ba --- /dev/null +++ b/src/urlbar/newresourcedialog.h @@ -0,0 +1,50 @@ +/* + This is a part of the GSoC project - Fancy Bookmarking + Copyright 2011 Phaneendra Hegde <pnh.pes@gmail.com> + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef NEWRESOURCEDIALOG_H +#define NEWRESOURCEDIALOG_H + +//kde includes +#include <KDialog> +#include <KLineEdit> + +#include <Nepomuk/Resource> + +namespace Nepomuk +{ + class NewResourceDialog : public KDialog + { + Q_OBJECT + + public: + explicit NewResourceDialog( int index,Nepomuk::Resource& nfoResource, QWidget* parent = 0 ); + virtual ~NewResourceDialog(); + + private Q_SLOTS: + void newResourceSlot(); + + private: + class Private; + Private* const d; + }; + +} + +#endif // NEWRESOURCEDIALOG_H diff --git a/src/urlbar/resourcelinkdialog.cpp b/src/urlbar/resourcelinkdialog.cpp new file mode 100644 index 00000000..9c2ab203 --- /dev/null +++ b/src/urlbar/resourcelinkdialog.cpp @@ -0,0 +1,347 @@ +/* + This is a part of the GSoC project - Fancy Bookmarking + Copyright 2011 Phaneendra Hegde <pnh.pes@gmail.com> + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +//Local Includes +#include "resourcelinkdialog.h" +#include "newresourcedialog.h" + +//Qt Includes +#include <QtGui/QGridLayout> +#include <QtGui/QHBoxLayout> +#include <QtGui/QComboBox> +#include <QtGui/QAbstractItemView> +#include <QLabel> +#include <QListView> +#include <QPushButton> +#include <QColumnView> +#include <QStringListModel> +#include <QStandardItem> +#include <QModelIndexList> +#include <QItemSelectionModel> +#include <QMenu> +#include <QListWidget> + +//KDE Includes +#include <KLocale> +#include <KDebug> +#include <KAction> +#include <KIcon> + +//Nepomuk Includes +#include <Nepomuk/Utils/SimpleResourceModel> +#include <Nepomuk/Query/Term> +#include <Nepomuk/Query/Result> +#include <Nepomuk/Query/ResourceTypeTerm> +#include <Nepomuk/Query/QueryServiceClient> +#include <Nepomuk/Vocabulary/PIMO> +#include <Nepomuk/Vocabulary/NCO> +#include <Nepomuk/Query/QueryParser> +#include <Nepomuk/Variant> + + +class Nepomuk::ResourceLinkDialog::Private +{ +public: + void _k_selectionChanged(); + + KLineEdit *m_searchBox; + QListView *m_resourceView; + QListView *m_linkedResources; + KAction *m_removeResourceAction; + QComboBox *m_resourceSelect; + QLabel *m_resourceLabel; + QLabel *m_linkedResourceLabel; + QColumnView *m_leftPanel; + QStringListModel *m_model; + QPushButton *m_newResourceButton; + Utils::SimpleResourceModel *m_resourceModel; + Utils::SimpleResourceModel *m_linkedResourceModel; + Nepomuk::ResourceLinkDialog *q; + + Nepomuk::Resource m_nfoResource; + +}; + +void Nepomuk::ResourceLinkDialog::Private::_k_selectionChanged() +{ + q->enableButton( KDialog::User1, !m_resourceView->selectionModel()->selectedRows().isEmpty() ); +} + + +Nepomuk::ResourceLinkDialog::ResourceLinkDialog( Nepomuk::Resource &nfoResource, QWidget* parent ): + KDialog( parent ), + d( new Private() ) +{ + d->m_nfoResource = nfoResource; + setWindowTitle( i18n( "Resource Linker" ) ); + setButtons( Ok | User1 | User2 | Cancel ); + enableButtonCancel( true ); + enableButtonOk( true ); + enableButton( User1, false ); + setButtonText( Ok, i18n( "Done" ) ); + setButtonText( User1, i18n( "Link" ) ); + setButtonText( User2, "Unlink" ); + setMinimumSize(400,350); +// d->m_resourceView->setSelectionMode(QAbstractItemView::ExtendedSelection); + QGridLayout *mainLayout = new QGridLayout ( mainWidget() ); + + d->q = this; + + d->m_linkedResources = new QListView ( mainWidget() ); + d->m_linkedResourceModel = new Utils::SimpleResourceModel( this ); + d->m_linkedResources->setModel( d->m_linkedResourceModel ); + setRelatedResources(); + + d->m_searchBox = new KLineEdit ( mainWidget() ); + d->m_searchBox->setPlaceholderText( i18n( "Search resources" ) ); + connect( d->m_searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( dynamicSearchingSlot() ) ); + + d->m_resourceView = new QListView ( mainWidget() ); + d->m_resourceView->setToolTip( i18n( " Double click to link resource ") ); + d->m_resourceModel = new Utils::SimpleResourceModel( this ); + d->m_resourceView->setModel( d->m_resourceModel ); + + d->m_resourceSelect = new QComboBox( mainWidget() ); + QStringList rlist; + rlist << i18n( "Any resource" ) << i18n( "Persons" ) << i18n( "Projects" ) << i18n( "Tasks" ) << i18n( "Places" ) << i18n( "Notes" ); + d->m_resourceSelect->addItems( rlist ); + d->m_resourceSelect->setItemIcon(1,KIcon("user-identity")); + d->m_resourceSelect->setItemIcon(2,KIcon("project-development")); + d->m_resourceSelect->setItemIcon(3,KIcon("view-pim-tasks")); + d->m_resourceSelect->setItemIcon(4,KIcon("user-location")); + d->m_resourceSelect->setItemIcon(5,KIcon("knotes")); + connect( d->m_resourceSelect, SIGNAL( currentIndexChanged( int ) ), this, SLOT( resourceSelectedSlot( int ) ) ); + + d->m_resourceLabel = new QLabel( i18n( "Matching resources:" ), mainWidget() ); + d->m_linkedResourceLabel = new QLabel( i18n( "Linked Resources:" ), mainWidget() ); + + + d->m_newResourceButton = new QPushButton( mainWidget() ); + d->m_newResourceButton->setText( i18n( "Create New Resource" ) ); + if( d->m_resourceSelect->currentIndex() == 0 ) { + d->m_newResourceButton->setEnabled( false ); + } + connect(d->m_newResourceButton, SIGNAL( clicked() ), this, SLOT( createNewResourceSlot() ) ); + + QVBoxLayout *vlayoutR = new QVBoxLayout; + QVBoxLayout *vlayoutL = new QVBoxLayout; + vlayoutL->addWidget( d->m_searchBox ); + vlayoutL->addWidget( d->m_resourceLabel ); + vlayoutL->addWidget( d->m_resourceView ); + vlayoutR->addWidget( d->m_resourceSelect ); + vlayoutR->addWidget( d->m_linkedResourceLabel ); + vlayoutR->addWidget( d->m_linkedResources ); + vlayoutR->addWidget( d->m_newResourceButton ); + mainLayout->addLayout( vlayoutL, 1 ,1 ); + mainLayout->addLayout(vlayoutR, 1, 2); + mainLayout->setColumnMinimumWidth(1,100); + +// d->m_linkedResources->setContextMenuPolicy(Qt::CustomContextMenu); + d->m_linkedResources->setContextMenuPolicy(Qt::CustomContextMenu); + + connect( d->m_resourceView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(_k_selectionChanged()) ); + connect ( d->m_linkedResources->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), + this, SLOT( _k_selectionChanged() ) ); + connect ( this, SIGNAL( user1Clicked() ), this, SLOT( linkResourceSlot() ) ); + connect ( this, SIGNAL( user2Clicked() ), this, SLOT( unlinkResourceSlot() ) ); + connect ( d->m_resourceView, SIGNAL( doubleClicked(QModelIndex) ), this, SLOT( linkResourceSlot() ) ); + connect (d->m_linkedResources, SIGNAL( customContextMenuRequested(QPoint) ), this, SLOT( showContextMenu(QPoint) ) ); + if( !d->m_linkedResources->selectionModel()->selectedRows().isEmpty() ) { + enableButton( User2, true ); + } +} + +Nepomuk::ResourceLinkDialog::~ResourceLinkDialog() +{ + delete d; +} + +void Nepomuk::ResourceLinkDialog::setRelatedResources() +{ + QList<Nepomuk::Resource> relatedResourceList = d->m_nfoResource.isRelateds(); + d->m_linkedResourceModel->setResources(relatedResourceList); + +} + +void Nepomuk::ResourceLinkDialog::linkResourceSlot() +{ + QModelIndexList selectedResourceList; + selectedResourceList << d->m_resourceView->selectionModel()->selectedIndexes(); + Q_FOREACH(const QModelIndex& i, selectedResourceList) { + d->m_resourceView->selectionModel()->setCurrentIndex( i, QItemSelectionModel::NoUpdate ); + d->m_nfoResource.addIsRelated( d->m_resourceModel->resourceForIndex(d->m_resourceView->selectionModel()->currentIndex() ) ); + } + setRelatedResources(); +} + +void Nepomuk::ResourceLinkDialog::unlinkResourceSlot() +{ + d->m_nfoResource.removeProperty( Nepomuk::Resource::isRelatedUri(), + d->m_linkedResourceModel->resourceForIndex( + d->m_linkedResources->selectionModel()->currentIndex() ) ); + setRelatedResources(); +} + +void Nepomuk::ResourceLinkDialog::showContextMenu(const QPoint &pos) +{ + d->m_removeResourceAction = new KAction(this); + d->m_removeResourceAction->setText(i18n("&Unlink ")); + d->m_removeResourceAction->setIcon(KIcon("edit-delete")); + connect (d->m_removeResourceAction, SIGNAL( triggered(bool) ), this, SLOT( unlinkResourceSlot() ) ); + + QMenu myMenu; + QPoint globalPos = d->m_linkedResources->mapToGlobal(pos); + myMenu.addAction(d->m_removeResourceAction); + myMenu.exec(globalPos); +} +void Nepomuk::ResourceLinkDialog::createNewResourceSlot() +{ + Nepomuk::NewResourceDialog newResource( d->m_resourceSelect->currentIndex(), d->m_nfoResource ); + //close(); + newResource.exec(); + setRelatedResources(); +} +void Nepomuk::ResourceLinkDialog::dynamicSearchingSlot() +{ + Nepomuk::Query::Query query; + Nepomuk::Query::QueryServiceClient *test; + switch( d->m_resourceSelect->currentIndex() ) { + case 1: + query = Nepomuk::Query::QueryParser::parseQuery( d->m_searchBox->text() ); + query = query && Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Person() ); + test = new Nepomuk::Query::QueryServiceClient( this ); + test->query( query ); + d->m_resourceModel->clear(); + connect(test,SIGNAL( newEntries( QList<Nepomuk::Query::Result> ) ), + d->m_resourceModel,SLOT( addResults(QList<Nepomuk::Query::Result>)) ); + break; + case 2: + query = Nepomuk::Query::QueryParser::parseQuery( d->m_searchBox->text() ); + query = query && Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Project() ); + test = new Nepomuk::Query::QueryServiceClient( this ); + test->query( query ); + d->m_resourceModel->clear(); + connect(test,SIGNAL( newEntries( QList<Nepomuk::Query::Result> ) ), + d->m_resourceModel,SLOT( addResults(QList<Nepomuk::Query::Result>)) ); + break; + case 3: + query = Nepomuk::Query::QueryParser::parseQuery( d->m_searchBox->text() ); + query = query && Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Task() ); + test = new Nepomuk::Query::QueryServiceClient( this ); + test->query( query ); + d->m_resourceModel->clear(); + connect(test,SIGNAL( newEntries( QList<Nepomuk::Query::Result> ) ), + d->m_resourceModel,SLOT( addResults(QList<Nepomuk::Query::Result>)) ); + break; + case 4: + query = Nepomuk::Query::QueryParser::parseQuery( d->m_searchBox->text() ); + query = query && Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Location() ); + test = new Nepomuk::Query::QueryServiceClient( this ); + test->query( query ); + d->m_resourceModel->clear(); + connect(test,SIGNAL( newEntries( QList<Nepomuk::Query::Result> ) ), + d->m_resourceModel,SLOT( addResults(QList<Nepomuk::Query::Result>)) ); + break; + case 5: + query = Nepomuk::Query::QueryParser::parseQuery( d->m_searchBox->text() ); + query = query && Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Note() ); + test = new Nepomuk::Query::QueryServiceClient( this ); + test->query( query ); + d->m_resourceModel->clear(); + connect(test,SIGNAL( newEntries( QList<Nepomuk::Query::Result> ) ), + d->m_resourceModel,SLOT( addResults(QList<Nepomuk::Query::Result>)) ); + break; + default: + break; + } +} + + +void Nepomuk::ResourceLinkDialog::resourceSelectedSlot( int index ) +{ + enableButton( User1, true ); + d->m_newResourceButton->setEnabled( true ); + if( index == 0 ) { + d->m_resourceModel->clear(); + d->m_newResourceButton->setEnabled( false ); + } + //List Personal Contacts + if( index == 1 ) { + Nepomuk::Query::Term term = Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Person() ); + Nepomuk::Query::Query query( term ); + query.setLimit( 20 ); + QList<Nepomuk::Query::Result>results = Nepomuk::Query::QueryServiceClient::syncQuery( query ); + QList <Nepomuk::Resource> resource; + Q_FOREACH( const Nepomuk::Query::Result& result, results ) { + resource.append( result.resource() ); + } + d->m_resourceModel->setResources( resource ); + } + //List Projects + else if( index == 2 ) { + Nepomuk::Query::Term term = Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Project() ); + Nepomuk::Query::Query query( term ); + query.setLimit(20); + QList<Nepomuk::Query::Result>results = Nepomuk::Query::QueryServiceClient::syncQuery( query ); + QList <Nepomuk::Resource> resource; + Q_FOREACH( const Nepomuk::Query::Result& result, results ) { + resource.append( result.resource() ); + } + d->m_resourceModel->setResources( resource ); + } + //List Tasks + else if( index == 3 ) { + Nepomuk::Query::Term term = Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Task() ); + Nepomuk::Query::Query query( term ); + query.setLimit(20); + QList<Nepomuk::Query::Result>results = Nepomuk::Query::QueryServiceClient::syncQuery( query ); + QList <Nepomuk::Resource> resource; + Q_FOREACH( const Nepomuk::Query::Result& result, results ) { + resource.append( result.resource() ); + } + d->m_resourceModel->setResources( resource ); + } + //List Places + else if( index == 4 ) { + Nepomuk::Query::Term term = Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Location() ); + Nepomuk::Query::Query query( term ); + query.setLimit(20); + QList<Nepomuk::Query::Result>results = Nepomuk::Query::QueryServiceClient::syncQuery( query ); + QList <Nepomuk::Resource> resource; + Q_FOREACH( const Nepomuk::Query::Result& result, results ) { + resource.append( result.resource() ); + } + d->m_resourceModel->setResources( resource ); + } + //List Notes + else if( index == 5 ) { + Nepomuk::Query::Term term = Nepomuk::Query::ResourceTypeTerm( Nepomuk::Vocabulary::PIMO::Note() ); + Nepomuk::Query::Query query( term ); + query.setLimit(20); + QList<Nepomuk::Query::Result>results = Nepomuk::Query::QueryServiceClient::syncQuery( query ); + QList <Nepomuk::Resource> resource; + Q_FOREACH( const Nepomuk::Query::Result& result, results ) { + resource.append( result.resource() ); + } + d->m_resourceModel->setResources( resource ); + } +} + diff --git a/src/urlbar/resourcelinkdialog.h b/src/urlbar/resourcelinkdialog.h new file mode 100644 index 00000000..7e623778 --- /dev/null +++ b/src/urlbar/resourcelinkdialog.h @@ -0,0 +1,66 @@ +/* + This is a part of the GSoC project - Fancy Bookmarking + Copyright 2011 Phaneendra Hegde <pnh.pes@gmail.com> + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + + +#ifndef RESOURCELINKDIALOG_H +#define RESOURCELINKDIALOG_H + +//Qt includes +#include <QListView> + +//kde includes +#include <KDialog> +#include <KLineEdit> +#include <KConfigDialog> + +namespace Nepomuk +{ + class Resource; + namespace Query { + class Query; + } + + class ResourceLinkDialog : public KDialog + { + Q_OBJECT + + public: + explicit ResourceLinkDialog( Nepomuk::Resource& nfoResource, QWidget* parent = 0 ); + virtual ~ResourceLinkDialog(); + void setRelatedResources(); + + private Q_SLOTS: + void dynamicSearchingSlot(); + void resourceSelectedSlot(int); + void linkResourceSlot(); + void unlinkResourceSlot(); + void createNewResourceSlot(); + void showContextMenu(const QPoint&); + + + private: + class Private; + Private* const d; + + }; + +} + +#endif // RESOURCELINKDIALOG_H |