WSL/SLF GitLab Repository

Commit d61f0196 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Trying to get nicer looking paths in the workflow panel, as shown above the...

Trying to get nicer looking paths in the workflow panel, as shown above the applications or simulations
parent f94eaab9
......@@ -378,10 +378,14 @@ void WorkflowPanel::readAppsFromDirs(bool &applications_found, bool &simulations
} //endfor filename
//display the directory's path as a list separator if it contains valid XMLs:
if (applications_->count() > count_before_applications)
applications_->addInfoSeparator(directory, count_before_applications);
if (simulations_->count() > count_before_simulations)
simulations_->addInfoSeparator(directory, count_before_simulations);
if (applications_->count() > count_before_applications) {
const QString path_title( os::prettyPath(directory) );
applications_->addInfoSeparator(path_title, count_before_applications);
}
if (simulations_->count() > count_before_simulations) {
const QString path_title( os::prettyPath(directory) );
simulations_->addInfoSeparator(path_title, count_before_simulations);
}
} //endfor directory_list
......
......@@ -27,6 +27,17 @@
#include <QStandardPaths>
#include <QtGlobal>
#include <iostream>
#if defined _WIN32 || defined __MINGW32__
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#else
#include <cstring>
#endif
namespace os {
/**
......@@ -68,6 +79,40 @@ void getSystemLocations(QStringList &locations)
#endif
}
/**
* @brief resolve and simplify a path. Unfortunatelly, there is no guarantee for a proper handling of UTF encodings,
* so only use this call to display nicer paths!
* @param[out] in_path path to cleanup
*/
QString prettyPath(const QString& in_path)
{
std::string in_path_str( in_path.toStdString() );
#if defined _WIN32 || defined __MINGW32__
//if this would not suffice, see http://pdh11.blogspot.ch/2009/05/pathcanonicalize-versus-what-it-says-on.html
char **ptr = nullptr;
char *out_buff = (char*)calloc(MAX_PATH, sizeof(char));
const DWORD status = GetFullPathName(in_path_str.c_str(), MAX_PATH, out_buff, ptr);
if (status!=0 && status<=MAX_PATH) in_path_str = out_buff;
free(out_buff);
std::replace(in_path_str.begin(), in_path_str.end(), '\\', '/');
return QString::fromStdString( in_path_str );
#else //POSIX
std::replace(in_path_str.begin(), in_path_str.end(), '\\', '/');
errno = 0;
char *real_path = realpath(in_path_str.c_str(), nullptr); //POSIX 2008
if (real_path!=nullptr) {
const QString tmp( real_path );
free(real_path);
return tmp;
} else {
std::cerr << "Path expansion of \'" << in_path_str << "\' failed. Reason:\t" << std::strerror(errno) << "\n";
return QString::fromStdString( in_path_str ); //something failed in realpath, keep it as it is
}
#endif
}
/**
* @brief Check if we're running on KDE Desktop environment.
* @details On a well-tuned KDE, things should be the smoothest.
......
......@@ -31,6 +31,7 @@
namespace os {
void getSystemLocations(QStringList &locations);
QString prettyPath(const QString& in_path);
bool isKde();
QString cleanKDETabStr(const QString &string);
bool isDarkTheme();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment