diff options
author | Chris Robinson <[email protected]> | 2014-08-05 04:56:51 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-08-05 04:56:51 -0700 |
commit | bda39c5038e67bdad0c39a3c311136167aad3d15 (patch) | |
tree | 14aa4e420d52990bc4d3f671ab449a53be958252 /utils/alsoft-config/mainwindow.cpp | |
parent | 066a48c5fb8cee4b32bd7145dd78147ba709f067 (diff) |
Filter for relative HRTF data paths and add Add/Remove label texts
Diffstat (limited to 'utils/alsoft-config/mainwindow.cpp')
-rw-r--r-- | utils/alsoft-config/mainwindow.cpp | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index f009208a..c58000d9 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -52,6 +52,48 @@ static QString getDefaultConfigName() return base +'/'+ fname; return fname; } + +static QString getBaseDataPath() +{ +#ifdef Q_OS_WIN32 + QByteArray base = qgetenv("AppData"); +#else + QByteArray base = qgetenv("XDG_DATA_HOME"); + if(base.isEmpty()) + { + base = qgetenv("HOME"); + if(!base.isEmpty()) + base += "/.local/share"; + } +#endif + return base; +} + +static QStringList getAllDataPaths(QString append=QString()) +{ + QStringList list; + list.append(getBaseDataPath()); +#ifdef Q_OS_WIN32 + // TODO: Common AppData path +#else + QString paths = qgetenv("XDG_DATA_DIRS"); + if(paths.isEmpty()) + paths = "/usr/local/share/:/usr/share/"; + list += paths.split(QChar(':'), QString::SkipEmptyParts); +#endif + QStringList::iterator iter = list.begin(); + while(iter != list.end()) + { + if(iter->isEmpty()) + iter = list.erase(iter); + else + { + iter->append(append); + iter++; + } + } + return list; +} } MainWindow::MainWindow(QWidget *parent) : @@ -490,10 +532,36 @@ void MainWindow::updatePeriodCountSlider() void MainWindow::addHrtfFile() { - QStringList fnames = QFileDialog::getOpenFileNames(this, tr("Select Files"), QString(), + const QStringList datapaths = getAllDataPaths("/openal/hrtf"); + QStringList fnames = QFileDialog::getOpenFileNames(this, tr("Select Files"), + datapaths.empty() ? QString() : datapaths[0], "HRTF Datasets(*.mhr);;All Files(*.*)"); if(fnames.isEmpty() == false) - ui->hrtfFileList->addItems(fnames); + { + for(QStringList::iterator iter = fnames.begin();iter != fnames.end();iter++) + { + QStringList::const_iterator path = datapaths.constBegin(); + for(;path != datapaths.constEnd();path++) + { + QDir hrtfdir(*path); + if(!hrtfdir.isAbsolute()) + continue; + + const QString relname = hrtfdir.relativeFilePath(*iter); + if(!relname.startsWith("..")) + { + // If filename is within this path, use the relative pathname + ui->hrtfFileList->addItem(relname); + break; + } + } + if(path == datapaths.constEnd()) + { + // Filename is not within any data path, use the absolute pathname + ui->hrtfFileList->addItem(*iter); + } + } + } } void MainWindow::removeHrtfFile() |