summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-05-18 11:32:35 -0700
committerThiago Macieira <thiago.macieira@intel.com>2013-05-23 16:50:43 +0200
commitbef5655db43a56d717c7b15599489e327ec36dee (patch)
treeaabcfea6b5ea2222bf2e2c08cda61b241e8d7781
parentea7cb4feed549e9566eb5704ed6ff71e83aa1524 (diff)
downloadqtchooser-bef5655db43a56d717c7b15599489e327ec36dee.tar.gz
qtchooser-bef5655db43a56d717c7b15599489e327ec36dee.tar.bz2
qtchooser-bef5655db43a56d717c7b15599489e327ec36dee.zip
Print a sorted list of Qt versions
Right now, we're getting a directory order, which is arbitrary. Change-Id: Ia40c62ba9704fcc22504b1282f430e1fb18255d9 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
-rw-r--r--src/qtchooser/main.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/qtchooser/main.cpp b/src/qtchooser/main.cpp
index 22af289..ed1ee8f 100644
--- a/src/qtchooser/main.cpp
+++ b/src/qtchooser/main.cpp
@@ -50,6 +50,7 @@
#define _CRT_SECURE_NO_WARNINGS
#define _POSIX_C_SOURCE 200809L
+#include <algorithm>
#include <set>
#include <string>
#include <vector>
@@ -109,10 +110,11 @@ private:
vector<string> searchPaths() const;
typedef bool (*VisitFunction)(const string &targetSdk, Sdk &item);
- Sdk iterateSdks(const string &targetSdk, VisitFunction visit);
+ typedef void (*FinishFunction)(const set<string> &seenSdks);
+ Sdk iterateSdks(const string &targetSdk, VisitFunction visit, FinishFunction finish = 0);
Sdk selectSdk(const string &targetSdk);
- static bool printSdk(const string &, Sdk &sdk);
+ static void printSdks(const set<string> &seenNames);
static bool matchSdk(const string &targetSdk, Sdk &sdk);
};
@@ -131,7 +133,7 @@ int ToolWrapper::printHelp()
int ToolWrapper::listVersions()
{
- iterateSdks(string(), &ToolWrapper::printSdk);
+ iterateSdks(string(), 0, &ToolWrapper::printSdks);
return 0;
}
@@ -292,7 +294,7 @@ vector<string> ToolWrapper::searchPaths() const
return paths;
}
-Sdk ToolWrapper::iterateSdks(const string &targetSdk, VisitFunction visit)
+Sdk ToolWrapper::iterateSdks(const string &targetSdk, VisitFunction visit, FinishFunction finish)
{
vector<string> paths = searchPaths();
set<string> seenNames;
@@ -325,13 +327,16 @@ Sdk ToolWrapper::iterateSdks(const string &targetSdk, VisitFunction visit)
sdk.name = d->d_name;
sdk.name.resize(fnamelen + 1 - sizeof wantedSuffix);
sdk.configFile = path + PATH_SEP + d->d_name;
- if (visit(targetSdk, sdk))
+ if (visit && visit(targetSdk, sdk))
return sdk;
}
closedir(dir);
}
+ if (finish)
+ finish(seenNames);
+
return Sdk();
}
@@ -344,10 +349,14 @@ Sdk ToolWrapper::selectSdk(const string &targetSdk)
return matchedSdk;
}
-bool ToolWrapper::printSdk(const string &, Sdk &sdk)
+void ToolWrapper::printSdks(const set<string> &seenNames)
{
- printf("%s\n", sdk.name.c_str());
- return false; // continue
+ vector<string> sorted;
+ copy(seenNames.begin(), seenNames.end(), back_inserter(sorted));
+ sort(sorted.begin(), sorted.end());
+ vector<string>::const_iterator it = sorted.begin();
+ for ( ; it != sorted.end(); ++it)
+ printf("%s\n", it->c_str());
}
bool ToolWrapper::matchSdk(const string &targetSdk, Sdk &sdk)