diff --git a/providers/Paths.cpp b/providers/Paths.cpp index 54d85cb..68bed01 100644 --- a/providers/Paths.cpp +++ b/providers/Paths.cpp @@ -1,107 +1,104 @@ /* * Copyright 2010-2012 Bart Kroon * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "Paths.h" -#include -#include #include -#include + +#include #include +#include +#include static QString subUser(QString path) { QString homePath = QDir::homePath(); if (path.startsWith(homePath)) path = "~" + path.mid(homePath.length(), -1); return path; } Paths::Paths(QObject *parent) : Provider(parent) { } Paths::~Paths() {} QList Paths::getResults(QString query) { QList list; - QString original = query; + QDir dir; - if (query.startsWith("/")) - { + if (query.startsWith("/")) { dir = QDir::root(); query.remove(0, 1); - } - else + } else { dir = QDir::home(); + } + QStringList walk = query.split("/", QString::SkipEmptyParts); if (walk.isEmpty()) walk.append(""); QString part = walk.takeFirst(); while (walk.length() > 0) { dir.cd(part); part = walk.takeFirst(); } query = part + "*"; QFileInfoList paths = dir.entryInfoList(QStringList(query), QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files); foreach(QFileInfo path, paths) { Application *result = new Application(); result->name = subUser(path.absoluteFilePath()); result->completion = result->name.left(result->name.lastIndexOf("/")) + "/" + path.fileName(); - KFileItem info = KFileItem(path.absoluteFilePath()); - if (path.isDir()) - { + QFileInfo info(path.absoluteFilePath()); + result->priority = info.lastModified().toSecsSinceEpoch(); + if (path.isDir()) { result->completion += "/"; result->icon = "system-file-manager"; - result->priority = time(NULL) - info.time(KFileItem::ModificationTime).toTime_t(); - } - else - { - result->icon = info.iconName(); - result->priority = time(NULL) - info.time(KFileItem::ModificationTime).toTime_t(); + } else { + result->icon = m_mimeDb.mimeTypeForFile(path.absoluteFilePath()).iconName(); } result->object = this; result->program = path.absoluteFilePath(); result->type = i18n("Open path"); list.append(result); } return list; } int Paths::launch(QVariant selected) { QDesktopServices::openUrl(QUrl::fromLocalFile(selected.toString())); return 0; } // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Paths.h b/providers/Paths.h index f23dff4..f1e313c 100644 --- a/providers/Paths.h +++ b/providers/Paths.h @@ -1,45 +1,49 @@ /* * Copyright 2010-2012 Bart Kroon * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef Paths_H #define Paths_H #include "Provider.h" +#include class Paths : public Provider { Q_OBJECT public: Paths(QObject *parent); ~Paths(); public slots: QList getResults(QString query) override; int launch(QVariant selected) override; + +private: + QMimeDatabase m_mimeDb; }; #endif //Paths_H // kate: indent-mode cstyle; space-indent on; indent-width 4;