FileDialog : Adding mounted volumes on Linux (#6834)

* FileDialog : Adding mounted volumes on Linux

* Adding some file systems types and collapsing 2 'if' statements in one

* Removing the foreach

* Correcting PREPROCESSOR directive
This commit is contained in:
MrTopom
2023-09-12 23:30:31 +02:00
committed by GitHub
parent b64912cd57
commit 89baab6b87

View File

@@ -26,11 +26,12 @@
#include <QUrl>
#include <QListView>
#include <QStandardPaths>
#include <QStorageInfo>
#include <QStringList>
#include "ConfigManager.h"
#include "FileDialog.h"
namespace lmms::gui
{
@@ -45,19 +46,38 @@ FileDialog::FileDialog( QWidget *parent, const QString &caption,
setOption( QFileDialog::DontUseNativeDialog );
// Add additional locations to the sidebar
#ifdef LMMS_BUILD_LINUX
QList<QUrl> urls;
#else
QList<QUrl> urls = sidebarUrls();
urls << QUrl::fromLocalFile( QStandardPaths::writableLocation( QStandardPaths::DesktopLocation ) );
// Find downloads directory
QDir downloadDir( QDir::homePath() + "/Downloads" );
if ( ! downloadDir.exists() )
downloadDir.setPath(QStandardPaths::writableLocation( QStandardPaths::DownloadLocation ));
if ( downloadDir.exists() )
urls << QUrl::fromLocalFile( downloadDir.absolutePath() );
#endif
urls << QUrl::fromLocalFile( QStandardPaths::writableLocation( QStandardPaths::MusicLocation ) );
urls << QUrl::fromLocalFile( ConfigManager::inst()->workingDir() );
QDir desktopDir;
desktopDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
if (desktopDir.exists())
{
urls << QUrl::fromLocalFile(desktopDir.absolutePath());
}
QDir downloadDir(QDir::homePath() + "/Downloads");
if (!downloadDir.exists())
{
downloadDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
}
if (downloadDir.exists())
{
urls << QUrl::fromLocalFile(downloadDir.absolutePath());
}
QDir musicDir;
musicDir.setPath(QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
if (musicDir.exists())
{
urls << QUrl::fromLocalFile(musicDir.absolutePath());
}
urls << QUrl::fromLocalFile(ConfigManager::inst()->workingDir());
// Add `/Volumes` directory on OS X systems, this allows the user to browse
// external disk drives.
#ifdef LMMS_BUILD_APPLE
@@ -66,6 +86,22 @@ FileDialog::FileDialog( QWidget *parent, const QString &caption,
urls << QUrl::fromLocalFile( volumesDir.absolutePath() );
#endif
#ifdef LMMS_BUILD_LINUX
// FileSystem types : https://www.javatpoint.com/linux-file-system
QStringList usableFileSystems = {"ext", "ext2", "ext3", "ext4", "jfs", "reiserfs", "ntfs3", "fuse.sshfs", "fuseblk"};
for(QStorageInfo storage : QStorageInfo::mountedVolumes())
{
storage.refresh();
if (usableFileSystems.contains(QString(storage.fileSystemType()), Qt::CaseInsensitive) && storage.isValid() && storage.isReady())
{
urls << QUrl::fromLocalFile(storage.rootPath());
}
}
#endif
setSidebarUrls(urls);
}