diff --git a/applications/webbrowser/src/completionitem.cpp b/applications/webbrowser/src/completionitem.cpp index bf3d27b9..5703095e 100644 --- a/applications/webbrowser/src/completionitem.cpp +++ b/applications/webbrowser/src/completionitem.cpp @@ -1,116 +1,121 @@ /*************************************************************************** * * * Copyright 2011 Sebastian Kügler * * * * 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 "completionitem.h" #include "bookmark.h" #include #include class CompletionItemPrivate { public: QString name; QString url; QString iconName; QImage preview; + QUrl resourceUri; }; CompletionItem::CompletionItem(const QString &n, const QString &u, const QImage &i, QObject *parent) : QObject(parent) { d = new CompletionItemPrivate; d->name = n; d->url = u; d->preview = i; } CompletionItem::CompletionItem(QObject *parent) : QObject(parent) { d = new CompletionItemPrivate; d->name = QString(); d->url = QString(); d->preview = QImage(); } void CompletionItem::setResource(Nepomuk::Resource resource) { //d->url = resource. //kDebug() << "!!!!! res props: " << resource.properties().keys(); //kDebug() << "SET RESOURCE" << resource.resourceUri(); d->name = resource.genericDescription(); //d->url = resource.property(QUrl("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url")).toString(); //d->url = resource.property(Nepomuk::Bookmark::bookmarksUri()).toString(); d->url = resource.description(); d->name.remove("http://"); //kDebug() << "Bookmark: " << d->name << d->url; d->iconName = "bookmarks"; //d->url = resource.property(resour).toString(); - + d->resourceUri = resource.resourceUri(); } +QUrl CompletionItem::resourceUri() +{ + return d->resourceUri; +} CompletionItem::~CompletionItem() { delete d; } QString CompletionItem::name() { return d->name; } QString CompletionItem::url() { return d->url; } QString CompletionItem::iconName() { return d->iconName; } QImage CompletionItem::preview() { return d->preview; } void CompletionItem::setName(const QString &name) { d->name = name; } void CompletionItem::setIconName(const QString &iconName) { d->iconName = iconName; } void CompletionItem::setUrl(const QString &url) { d->url = url; } void CompletionItem::setPreview(const QImage &preview) { d->preview = preview; } #include "completionitem.moc" diff --git a/applications/webbrowser/src/completionitem.h b/applications/webbrowser/src/completionitem.h index c9fc70dc..a0770634 100644 --- a/applications/webbrowser/src/completionitem.h +++ b/applications/webbrowser/src/completionitem.h @@ -1,71 +1,72 @@ /*************************************************************************** * * * Copyright 2011 Sebastian Kügler * * * * 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 COMPLETIONITEM_H #define COMPLETIONITEM_H #include #include #include class CompletionItemPrivate; class CompletionItem : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged) Q_PROPERTY(QImage preview READ preview WRITE setPreview NOTIFY previewChanged) Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged) public: CompletionItem(const QString &name = QString(), const QString &url = QString(), const QImage &i = QImage(), QObject *parent = 0 ); CompletionItem(QObject *parent); //CompletionItem(Nepomuk::Resource resource, QObject *parent = 0); ~CompletionItem(); void setResource(Nepomuk::Resource resource); QString name(); QString iconName(); QString url(); QImage preview(); + QUrl resourceUri(); public Q_SLOTS: void setName(const QString &name); void setUrl(const QString &url); void setPreview(const QImage &image); void setIconName(const QString &iconName); Q_SIGNALS: void nameChanged(); void urlChanged(); void previewChanged(); void iconNameChanged(); private: CompletionItemPrivate* d; }; #endif // COMPLETIONITEM_H diff --git a/applications/webbrowser/src/completionmodel.cpp b/applications/webbrowser/src/completionmodel.cpp index cc5dbdcf..6c91e789 100644 --- a/applications/webbrowser/src/completionmodel.cpp +++ b/applications/webbrowser/src/completionmodel.cpp @@ -1,192 +1,207 @@ /*************************************************************************** * * * Copyright 2011 Sebastian Kügler * * * * 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 . * ***************************************************************************/ //#define KDE_DEPRECATED 1 #include "completionmodel.h" #include "completionitem.h" #include "history.h" // Nepomuk #include #include //#include #include #include "bookmark.h" #include //#include #include #include //#include #include #include #include #include #include #include "kdebug.h" class CompletionModelPrivate { public: QList items; QList filteredItems; Nepomuk::Query::Query query; Nepomuk::Query::QueryServiceClient* queryClient; History* history; QString filter; bool isPopulated; }; CompletionModel::CompletionModel(QObject *parent) : QObject(parent) { d = new CompletionModelPrivate; d->isPopulated = false; d->history = new History(this); connect(d->history, SIGNAL(dataChanged()), this, SIGNAL(dataChanged())); } CompletionModel::~CompletionModel() { delete d; } History* CompletionModel::history() { return d->history; } QList CompletionModel::items() { QList l; l.append(d->history->items()); l.append(d->items); return l; } QList CompletionModel::filteredBookmarks() { return filteredItems(d->items); } QList CompletionModel::filteredHistory() { return filteredItems(d->history->items()); } QList CompletionModel::filteredItems(const QList &l) { //QList l; //l.append(d->history->items()); //l.append(d->items); if (d->filter.isEmpty()) { return l; } d->filteredItems.clear(); QList filteredItems; foreach(QObject* it, l) { CompletionItem* ci = qobject_cast(it); if (ci) { // Matching, pretty basic right now if (ci->name().contains(d->filter, Qt::CaseInsensitive)) { filteredItems.append(ci); } else if (ci->url().contains(d->filter, Qt::CaseInsensitive)) { filteredItems.append(ci); } } } return filteredItems; } void CompletionModel::setFilter(const QString &filter) { d->filter = filter; //kDebug() << "OOO FIlter set to " << filter; emit dataChanged(); } void CompletionModel::populate() { //kDebug() << "populating model..."; if (!d->isPopulated) { d->isPopulated = true; d->history->loadHistory(); loadBookmarks(); } } void CompletionModel::loadBookmarks() { if (!Nepomuk::Query::QueryServiceClient::serviceAvailable()) { return; } kDebug() << "Loading bookmarks..."; Nepomuk::Types::Class bookmarkClass(Nepomuk::Bookmark::resourceTypeUri()); Nepomuk::Query::ResourceTypeTerm rtt(bookmarkClass); d->query.setTerm(rtt); d->queryClient = new Nepomuk::Query::QueryServiceClient(this); connect(d->queryClient, SIGNAL(finishedListing()), this, SLOT(finishedListing())); - connect(d->queryClient, SIGNAL(newEntries(const QList &)), - this, SLOT(newEntries(const QList &))); - connect(d->queryClient, SIGNAL(entriesRemoved(const QList &)), - this, SLOT(entriesRemoved(const QList &))); + connect(d->queryClient, SIGNAL(newEntries(QList)), + this, SLOT(newEntries(QList))); + connect(d->queryClient, SIGNAL(entriesRemoved(QList)), + this, SLOT(entriesRemoved(QList))); d->query.setLimit(64); d->queryClient->query(d->query); } void CompletionModel::finishedListing() { //kDebug() << "Done listing."; } void CompletionModel::newEntries(const QList< Nepomuk::Query::Result >& entries) { foreach (Nepomuk::Query::Result res, entries) { //kDebug() << "Result!!!" << res.resource().genericLabel() << res.resource().type(); CompletionItem* item = new CompletionItem(this); item->setResource(res.resource()); d->items.append(item); } emit dataChanged(); } void CompletionModel::entriesRemoved(const QList< QUrl >& urls) { - Q_UNUSED( urls ); - // TODO: implement me + // not efficient but I do think users will have thousands of bookmarks to make this cause any lag. + // Also in the common case urls.size() == 1, so there will be only one iteration through the + // bookmarks list. + QMutableListIterator i(d->items); + foreach (const QUrl &u, urls) { + while (i.hasNext()) { + CompletionItem * cItem = static_cast(i.next()); + if (cItem && cItem->resourceUri() == u) { + //kDebug() << "Removing" << u << cItem->url(); + i.remove(); + cItem->deleteLater(); + break; + } + } + i.toFront(); + } + emit dataChanged(); } #include "completionmodel.moc"