[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: Re: Making paths case insensitive in krunner
From: "Diaa Sami" <diaasami () gmail ! com>
Date: 2009-01-19 23:10:13
Message-ID: 1232406613.14932.1295653681 () webmail ! messagingengine ! com
[Download RAW message or body]
On Mon, 19 Jan 2009 11:08 -0700, "Aaron J. Seigo" <aseigo@kde.org> wrote:
>
> however, the code itself needs to be written following our coding style
> guidelines:
>
> http://techbase.kde.org/Policies/Kdelibs_Coding_Style
>
> qDebug should be kDebug; QString whatever = "" should be
> whatever.isEmpty();
> there's an assert Q_ASSERT(components.size() > 1) when it it is handled
> almost
> alright by the very next line of code (which should probably be "if
> (components.size() < 2), actually, to guard against the zero case); the
> QString *s in the two helper functions should be QString &s;
> CorrectPathCase
> should be correctPathCase (it's a function, not a method).
>
Find the new version attached
--
Diaa Sami
["krunner-caseinsensitive-paths2.patch" (krunner-caseinsensitive-paths2.patch)]
Index: kde/src/KDE/kdelibs/plasma/runnercontext.cpp
===================================================================
--- kde/src/KDE/kdelibs/plasma/runnercontext.cpp (revision 911086)
+++ kde/src/KDE/kdelibs/plasma/runnercontext.cpp (working copy)
@@ -47,6 +47,104 @@
namespace Plasma
{
+/*
+Corrects the case of the last component in a path (e.g. /usr/liB -> /usr/lib)
+path: The path to be processed.
+correctCasePath: The corrected-case path
+mustBeDir: Tells whether the last component is a folder or doesn't matter
+Returns true on success and false on error, in case of error, correctCasePath is not modified
+*/
+bool correctLastComponentCase(const QString &path, QString &correctCasePath, const bool mustBeDir)
+{
+ kDebug() << "Correcting " << path;
+
+ // If the file already exists then no need to search for it.
+ if (QFile::exists(path)) {
+ correctCasePath = path;
+ kDebug() << "Correct path is" << correctCasePath;
+ return true;
+ }
+
+ const QFileInfo pathInfo(path);
+
+ const QDir fileDir = pathInfo.dir();
+ kDebug() << "Directory is" << fileDir;
+
+ const QString filename = pathInfo.fileName();
+ kDebug() << "Filename is" << filename;
+
+ kDebug() << "searching for a" << (mustBeDir ? "directory" : "directory/file");
+
+ const QStringList matchingFilenames = fileDir.entryList(QStringList(filename),
+ mustBeDir ? QDir::Dirs : QDir::NoFilter);
+
+ if (matchingFilenames.empty()) {
+ kDebug() << "No matches found!!\n";
+ return false;
+ } else {
+ if (matchingFilenames.size() > 1) {
+ kDebug() << "Found multiple matches!!\n";
+ }
+
+ if (fileDir.path().endsWith(QDir::separator())) {
+ correctCasePath = fileDir.path() + matchingFilenames[0];
+ } else {
+ correctCasePath = fileDir.path() + QDir::separator() + matchingFilenames[0];
+ }
+
+ kDebug() << "Correct path is" << correctCasePath;
+ return true;
+ }
+}
+
+/*
+Corrects the case of a path (e.g. /uSr/loCAL/bIN -> /usr/local/bin)
+path: The path to be processed.
+corrected: The corrected-case path
+Returns true on success and false on error, in case of error, corrected is not modified
+*/
+bool correctPathCase(const QString path, QString &corrected)
+{
+ // early exit check
+ if (QFile::exists(path)) {
+ corrected = path;
+ return true;
+ }
+
+ // path components
+ QStringList components = QString(path).split(QDir::separator());
+
+ if (components.size() < 2) {
+ return false;
+ }
+
+ const bool mustBeDir = components.back().isEmpty();
+
+ kDebug() << "Components are" << components;
+
+ QString correctPath;
+
+ if (components.back().isEmpty()) {
+ components.pop_back();
+ }
+
+ const unsigned initialComponents = components.size();
+ for (unsigned i = 0; i < initialComponents - 1; i ++) {
+ const QString tmp = components[0] + QDir::separator() + components[1];
+
+ if (!correctLastComponentCase(tmp, correctPath, components.size() > 2 || mustBeDir)) {
+ kDebug() << "search was not successfull";
+ return false;
+ }
+
+ components.removeFirst();
+ components[0] = correctPath;
+ }
+
+ corrected = correctPath;
+ return true;
+}
+
class RunnerContextPrivate : public QSharedData
{
public:
@@ -88,9 +186,11 @@
RunnerContext::Executable;
} else {
KUrl url(term);
+ QString correctCasePath;
if (!url.protocol().isEmpty() && !url.isLocalFile()) {
type = RunnerContext::NetworkLocation;
- } else if (QFile::exists(path)) {
+ } else if (correctPathCase(path, correctCasePath)) {
+ path = correctCasePath;
QFileInfo info(path);
if (info.isSymLink()) {
path = info.canonicalFilePath();
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic