Filter for relative HRTF data paths and add Add/Remove label texts

This commit is contained in:
Chris Robinson 2014-08-05 04:56:51 -07:00
parent 066a48c5fb
commit bda39c5038
2 changed files with 79 additions and 12 deletions

View File

@ -52,6 +52,48 @@ static QString getDefaultConfigName()
return base +'/'+ fname; return base +'/'+ fname;
return 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) : MainWindow::MainWindow(QWidget *parent) :
@ -490,10 +532,36 @@ void MainWindow::updatePeriodCountSlider()
void MainWindow::addHrtfFile() 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(*.*)"); "HRTF Datasets(*.mhr);;All Files(*.*)");
if(fnames.isEmpty() == false) 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() void MainWindow::removeHrtfFile()

View File

@ -348,15 +348,14 @@ sample rate.</string>
<rect> <rect>
<x>110</x> <x>110</x>
<y>30</y> <y>30</y>
<width>361</width> <width>301</width>
<height>121</height> <height>121</height>
</rect> </rect>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>A list of files containing HRTF data sets. The listed data sets <string>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 are used in place of the default sets. The filenames may
filenames may contain these markers, which will be replaced contain these markers, which will be replaced as needed:
as needed:
%r - Device sampling rate %r - Device sampling rate
%% - Percent sign (%)</string> %% - Percent sign (%)</string>
</property> </property>
@ -379,14 +378,14 @@ as needed:
<widget class="QPushButton" name="hrtfAddButton"> <widget class="QPushButton" name="hrtfAddButton">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>475</x> <x>419</x>
<y>30</y> <y>30</y>
<width>25</width> <width>81</width>
<height>25</height> <height>25</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string/> <string>Add...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="list-add"> <iconset theme="list-add">
@ -400,14 +399,14 @@ as needed:
<widget class="QPushButton" name="hrtfRemoveButton"> <widget class="QPushButton" name="hrtfRemoveButton">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>475</x> <x>419</x>
<y>60</y> <y>60</y>
<width>25</width> <width>81</width>
<height>25</height> <height>25</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string/> <string>Remove</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="list-remove"> <iconset theme="list-remove">