qt: add Open URI dialog
This commit is contained in:
@@ -278,6 +278,41 @@ QString getSaveFileName(QWidget *parent, const QString &caption, const QString &
|
||||
return result;
|
||||
}
|
||||
|
||||
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,
|
||||
const QString &filter,
|
||||
QString *selectedSuffixOut)
|
||||
{
|
||||
QString selectedFilter;
|
||||
QString myDir;
|
||||
if(dir.isEmpty()) // Default to user documents location
|
||||
{
|
||||
#if QT_VERSION < 0x050000
|
||||
myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
|
||||
#else
|
||||
myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
myDir = dir;
|
||||
}
|
||||
/* Directly convert path to native OS path separators */
|
||||
QString result = QDir::toNativeSeparators(QFileDialog::getOpenFileName(parent, caption, myDir, filter, &selectedFilter));
|
||||
|
||||
if(selectedSuffixOut)
|
||||
{
|
||||
/* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */
|
||||
QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]");
|
||||
QString selectedSuffix;
|
||||
if(filter_re.exactMatch(selectedFilter))
|
||||
{
|
||||
selectedSuffix = filter_re.cap(1);
|
||||
}
|
||||
*selectedSuffixOut = selectedSuffix;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Qt::ConnectionType blockingGUIThreadConnection()
|
||||
{
|
||||
if(QThread::currentThread() != qApp->thread())
|
||||
|
||||
Reference in New Issue
Block a user