diff --git a/providers/Paths.cpp b/providers/Paths.cpp index c72e692..cba0fee 100644 --- a/providers/Paths.cpp +++ b/providers/Paths.cpp @@ -1,109 +1,118 @@ /* * 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 +static QString subUser(QString path) +{ + QString homePath = QDir::homePath(); + if (path.startsWith(homePath)) + path = "~" + path.mid(homePath.length(), -1); + return path; +} + Paths::Paths() {} Paths::~Paths() {} QList Paths::getResults(QString query) { QList list = QList(); QString original = query; QDir dir; if (query.startsWith("/")) { dir = QDir::root(); query.remove(0, 1); } 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 = Application(); result.name = subUser(path.absoluteFilePath()); result.completion = result.name.left(result.name.lastIndexOf("/")) + "/" + path.fileName(); KFileItem info = KFileItem(KFileItem::Unknown, KFileItem::Unknown, path.absoluteFilePath()); 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(); } result.object = this; result.program = path.absoluteFilePath(); result.type = i18n("Open path"); list.append(result); } return list; } int Paths::launch(QVariant selected) { KFileItem info = KFileItem(KFileItem::Unknown, KFileItem::Unknown, selected.toString()); KRun run(info.targetUrl(), 0); return 0; } namespace { QString subUser(QString path) { QString homePath = QDir::homePath(); if (path.startsWith(homePath)) path = "~" + path.mid(homePath.length(), -1); return path; } }; #include "Paths.moc" // kate: indent-mode cstyle; space-indent on; indent-width 4; diff --git a/providers/Paths.h b/providers/Paths.h index 478352c..3590729 100644 --- a/providers/Paths.h +++ b/providers/Paths.h @@ -1,49 +1,44 @@ /* * 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" class Paths : public Provider { Q_OBJECT public: Paths(); ~Paths(); public slots: QList getResults(QString query); int launch(QVariant selected); }; -namespace -{ -QString subUser(QString); -}; - #endif //Paths_H // kate: indent-mode cstyle; space-indent on; indent-width 4;