From bda39c5038e67bdad0c39a3c311136167aad3d15 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 5 Aug 2014 04:56:51 -0700 Subject: Filter for relative HRTF data paths and add Add/Remove label texts --- utils/alsoft-config/mainwindow.cpp | 72 ++++++++++++++++++++++++++++++++++++-- utils/alsoft-config/mainwindow.ui | 19 +++++----- 2 files changed, 79 insertions(+), 12 deletions(-) (limited to 'utils/alsoft-config') 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() diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 7a0276d8..b9e9acee 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -348,15 +348,14 @@ sample rate. 110 30 - 361 + 301 121 A list of files containing HRTF data sets. The listed data sets -are used in place of or in addition to the the default sets. The -filenames may contain these markers, which will be replaced -as needed: +are used in place of the default sets. The filenames may +contain these markers, which will be replaced as needed: %r - Device sampling rate %% - Percent sign (%) @@ -379,14 +378,14 @@ as needed: - 475 + 419 30 - 25 + 81 25 - + Add... @@ -400,14 +399,14 @@ as needed: - 475 + 419 60 - 25 + 81 25 - + Remove -- cgit v1.2.3