target_link_libraries(dolphinprivate ${KDE4_KFILE_LIBS} konq ${KDE4_KNEWSTUFF3_LIBS} ${QIMAGEBLITZ_LIBRARIES})
if (Nepomuk_FOUND)
- target_link_libraries(dolphinprivate ${NEPOMUK_LIBRARIES} ${NEPOMUK_QUERY_LIBRARIES} ${SOPRANO_LIBRARIES})
+ target_link_libraries(dolphinprivate ${NEPOMUK_LIBRARIES} ${NEPOMUK_QUERY_LIBRARIES} nepomukutils ${SOPRANO_LIBRARIES})
endif (Nepomuk_FOUND)
dolphincontextmenu.cpp
filterbar/filterbar.cpp
main.cpp
+ panels/facets/facetpanel.cpp
panels/information/informationpanel.cpp
panels/information/informationpanelcontent.cpp
panels/information/pixmapviewer.cpp
${NEPOMUK_LIBRARIES}
${SOPRANO_LIBRARIES}
${NEPOMUK_QUERY_LIBRARIES}
+ nepomukutils
)
endif (Nepomuk_FOUND)
#include "dolphinnewfilemenu.h"
#include "dolphinviewcontainer.h"
#include "mainwindowadaptor.h"
+#include "panels/facets/facetpanel.h"
#include "panels/folders/folderspanel.h"
#include "panels/places/placespanel.h"
#include "panels/information/informationpanel.h"
connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
+ // setup "Facets"
+ QDockWidget* facetDock = new QDockWidget(i18nc("@title:window", "Filter"));
+ facetDock->setObjectName("facetDock");
+ facetDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+ Panel* facetPanel = new FacetPanel(facetDock);
+ connect(facetPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
+ facetDock->setWidget(facetPanel);
+
+ QAction* facetAction = facetDock->toggleViewAction();
+ facetAction->setIcon(KIcon("dialog-facet"));
+ addDockWidget(Qt::RightDockWidgetArea, facetDock);
+ connect(this, SIGNAL(urlChanged(KUrl)),
+ facetPanel, SLOT(setUrl(KUrl)));
+
// setup "Terminal"
#ifndef Q_OS_WIN
QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
panelsMenu->addAction(placesAction);
panelsMenu->addAction(infoAction);
panelsMenu->addAction(foldersAction);
+ panelsMenu->addAction(facetAction);
#ifndef Q_OS_WIN
panelsMenu->addAction(terminalAction);
#endif
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2010 by 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 "facetpanel.h"
+
+#include <nepomuk/filequery.h>
+#include <nepomuk/facetwidget.h>
+#include <Nepomuk/Query/FileQuery>
+#include <Nepomuk/Query/Term>
+
+#include <kfileitem.h>
+#include <kio/jobclasses.h>
+#include <kio/job.h>
+
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QTreeView>
+#include <QtGui/QPushButton>
+#include <kdebug.h>
+
+
+FacetPanel::FacetPanel(QWidget* parent)
+ : Panel(parent)
+{
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ m_buttonRemoveFolderRestriction = new QPushButton( i18n( "Remove folder restriction" ), this );
+ connect( m_buttonRemoveFolderRestriction, SIGNAL( clicked() ), SLOT( slotRemoveFolderRestrictionClicked() ) );
+
+ layout->addWidget(m_buttonRemoveFolderRestriction);
+
+ m_facetWidget = new Nepomuk::Utils::FacetWidget( this );
+ layout->addWidget( m_facetWidget, 1 );
+ connect(m_facetWidget, SIGNAL(facetsChanged()), this, SLOT(slotFacetsChanged()) );
+
+ // init to empty panel
+ setQuery(Nepomuk::Query::Query());
+}
+
+
+FacetPanel::~FacetPanel()
+{
+}
+
+void FacetPanel::setUrl(const KUrl& url)
+{
+ kDebug() << url;
+ Panel::setUrl(url);
+
+ // disable us
+ setQuery(Nepomuk::Query::Query());
+
+ // get the query from the item
+ m_lastSetUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
+ connect(m_lastSetUrlStatJob, SIGNAL(result(KJob*)),
+ this, SLOT(slotSetUrlStatFinished(KJob*)));
+}
+
+
+void FacetPanel::setQuery(const Nepomuk::Query::Query& query)
+{
+ kDebug() << query << query.isValid() << query.toSparqlQuery();
+
+ if (query.isValid()) {
+ m_buttonRemoveFolderRestriction->setVisible( query.isFileQuery() && !query.toFileQuery().includeFolders().isEmpty() );
+ m_unfacetedRestQuery = query;
+ m_unfacetedRestQuery.setTerm( m_facetWidget->extractFacetsFromTerm( query.term() ) );
+ m_facetWidget->setClientQuery( query );
+ kDebug() << "Rest query after facets:" << m_unfacetedRestQuery;
+ setEnabled(true);
+ }
+ else {
+ m_unfacetedRestQuery = Nepomuk::Query::Query();
+ setEnabled(false);
+ }
+}
+
+
+void FacetPanel::slotSetUrlStatFinished(KJob* job)
+{
+ m_lastSetUrlStatJob = 0;
+ kDebug() << url();
+ const KIO::UDSEntry uds = static_cast<KIO::StatJob*>(job)->statResult();
+ const QString nepomukQueryStr = uds.stringValue( KIO::UDSEntry::UDS_NEPOMUK_QUERY );
+ kDebug() << nepomukQueryStr;
+ Nepomuk::Query::FileQuery nepomukQuery;
+ if ( !nepomukQueryStr.isEmpty() ) {
+ nepomukQuery = Nepomuk::Query::Query::fromString( nepomukQueryStr );
+ }
+ else if ( url().isLocalFile() ) {
+ // fallback query for local file URLs
+ nepomukQuery.addIncludeFolder(url(), false);
+ }
+ kDebug() << nepomukQuery;
+ setQuery(nepomukQuery);
+}
+
+
+void FacetPanel::slotFacetsChanged()
+{
+ Nepomuk::Query::Query query( m_unfacetedRestQuery && m_facetWidget->queryTerm() );
+ kDebug() << query;
+ emit urlActivated( query.toSearchUrl() );
+}
+
+
+void FacetPanel::slotRemoveFolderRestrictionClicked()
+{
+ Nepomuk::Query::FileQuery query( m_unfacetedRestQuery && m_facetWidget->queryTerm() );
+ query.setIncludeFolders( KUrl::List() );
+ query.setExcludeFolders( KUrl::List() );
+ m_facetWidget->setClientQuery( query );
+ emit urlActivated( query.toSearchUrl() );
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2010 by 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 FACETPANEL_H
+#define FACETPANEL_H
+
+#include "../panel.h"
+#include <nepomuk/query.h>
+
+class KJob;
+class QPushButton;
+
+namespace Nepomuk {
+ namespace Utils {
+ class FacetWidget;
+ }
+}
+
+class FacetPanel : public Panel
+{
+ Q_OBJECT
+
+public:
+ FacetPanel(QWidget* parent = 0);
+ ~FacetPanel();
+
+public slots:
+ void setUrl(const KUrl& url);
+ void setQuery(const Nepomuk::Query::Query& query);
+
+signals:
+ void urlActivated( const KUrl& url );
+
+private slots:
+ void slotSetUrlStatFinished(KJob*);
+ void slotFacetsChanged();
+ void slotRemoveFolderRestrictionClicked();
+
+private:
+ bool urlChanged() {
+ return true;
+ }
+
+ KJob* m_lastSetUrlStatJob;
+
+ QPushButton* m_buttonRemoveFolderRestriction;
+ Nepomuk::Utils::FacetWidget* m_facetWidget;
+ Nepomuk::Query::Query m_unfacetedRestQuery;
+};
+
+#endif // FACETPANEL_H
#include <nepomuk/queryparser.h>
#include <nepomuk/resourcemanager.h>
#include <nepomuk/resourcetypeterm.h>
+ #include <nepomuk/comparisonterm.h>
#include "nfo.h"
#include "filters/datesearchfilterwidget.h"
KUrl DolphinSearchBox::urlForSearching() const
{
KUrl url;
- if (isSearchPathIndexed() && !m_fileNameButton->isChecked()) {
- // TODO: Currently Nepomuk is not used for searching filenames. Nepomuk
- // is capable to provide this, but further investigations are necessary to
- // also support regular expressions.
+ if (isSearchPathIndexed()) {
url = nepomukUrlForSearching();
} else {
url = m_searchPath;
bool DolphinSearchBox::isSearchPathIndexed() const
{
+ return true;
#ifdef HAVE_NEPOMUK
const QString path = m_searchPath.path();
// excluded folder is part of the search path.
const QStringList excludedFolders = strigiConfig.group("General").readPathEntry("exclude folders", QStringList());
foreach (const QString& excludedFolder, excludedFolders) {
- if (excludedFolder.startsWith(path)) {
+ // trueg: this is still not correct since there might be an include folder in the exclude folder
+ if (path.startsWith(excludedFolder)) {
isIndexed = false;
break;
}
// Add input from search filter
const QString text = m_searchInput->text();
if (!text.isEmpty()) {
- const Nepomuk::Query::Query customQuery = Nepomuk::Query::QueryParser::parseQuery(text);
- if (customQuery.isValid()) {
- andTerm.addSubTerm(customQuery.term());
+ if ( m_fileNameButton->isChecked() ) {
+ QString regex = QRegExp::escape(text);
+ regex.replace("\\*", QLatin1String( ".*" ));
+ regex.replace("\\?", QLatin1String( "." ));
+ regex.replace("\\", "\\\\");
+ regex.prepend('^');
+ regex.append('$');
+ andTerm.addSubTerm( Nepomuk::Query::ComparisonTerm(
+ Nepomuk::Vocabulary::NFO::fileName(),
+ Nepomuk::Query::LiteralTerm( regex ),
+ Nepomuk::Query::ComparisonTerm::Regexp ) );
+ }
+ else {
+ const Nepomuk::Query::Query customQuery = Nepomuk::Query::QueryParser::parseQuery(text, Nepomuk::Query::QueryParser::DetectFilenamePattern);
+ if (customQuery.isValid()) {
+ andTerm.addSubTerm(customQuery.term());
+ }
}
}
fileQuery.setFileMode(Nepomuk::Query::FileQuery::QueryFiles);
fileQuery.setTerm(andTerm);
- if (fileQuery.isValid()) {
- return fileQuery.toSearchUrl(i18nc("@title UDS_DISPLAY_NAME for a KIO directory listing. %1 is the query the user entered.",
- "Query Results from '%1'",
- text));
- }
-#endif
+ return fileQuery.toSearchUrl(i18nc("@title UDS_DISPLAY_NAME for a KIO directory listing. %1 is the query the user entered.",
+ "Query Results from '%1'",
+ text));
+#else
return KUrl();
+#endif
}
#include "dolphinsearchbox.moc"