Skip to content

Commit

Permalink
Merge remote-tracking branch 'khoidauminh/sidebar-url-adjust' into 08…
Browse files Browse the repository at this point in the history
…08-tests
  • Loading branch information
qnebra committed Aug 8, 2024
2 parents d667f93 + 305b99e commit 1eb402d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
7 changes: 7 additions & 0 deletions include/FileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define LMMS_GUI_FILE_DIALOG_H

#include <QFileDialog>
#include <QList>
#include <QUrl>

#include "lmms_export.h"

Expand All @@ -40,6 +42,8 @@ class LMMS_EXPORT FileDialog : public QFileDialog
explicit FileDialog( QWidget *parent = 0, const QString &caption = QString(),
const QString &directory = QString(),
const QString &filter = QString() );

~FileDialog();

static QString getExistingDirectory(QWidget *parent,
const QString &caption,
Expand All @@ -51,6 +55,9 @@ class LMMS_EXPORT FileDialog : public QFileDialog
const QString &filter = QString(),
QString *selectedFilter = 0);
void clearSelection();

private:
QList<QUrl> m_oldURLs;
};


Expand Down
40 changes: 26 additions & 14 deletions src/gui/modals/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,44 +46,51 @@ FileDialog::FileDialog( QWidget *parent, const QString &caption,

setOption( QFileDialog::DontUseNativeDialog );

#ifdef LMMS_BUILD_LINUX
QList<QUrl> urls;
#else
auto addIfUnavailable = [](QList<QUrl>& urls, const QString& path)
{
auto newUrl = QUrl::fromLocalFile(path);

if (!urls.contains(newUrl))
{
urls << newUrl;
}
};

m_oldURLs = sidebarUrls();
QList<QUrl> urls = sidebarUrls();
#endif

QDir desktopDir;
desktopDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
if (desktopDir.exists())
{
urls << QUrl::fromLocalFile(desktopDir.absolutePath());
addIfUnavailable(urls, desktopDir.absolutePath());
}

QDir downloadDir(QDir::homePath() + "/Downloads");
if (!downloadDir.exists())
{
downloadDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
}
if (downloadDir.exists())
{
urls << QUrl::fromLocalFile(downloadDir.absolutePath());
addIfUnavailable(urls, downloadDir.absolutePath());
}

QDir musicDir;
musicDir.setPath(QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
if (musicDir.exists())
{
urls << QUrl::fromLocalFile(musicDir.absolutePath());
addIfUnavailable(urls, musicDir.absolutePath());
}

urls << QUrl::fromLocalFile(ConfigManager::inst()->workingDir());
addIfUnavailable(urls, ConfigManager::inst()->workingDir());

// Add `/Volumes` directory on OS X systems, this allows the user to browse
// external disk drives.
#ifdef LMMS_BUILD_APPLE
QDir volumesDir( QDir("/Volumes") );
if ( volumesDir.exists() )
urls << QUrl::fromLocalFile( volumesDir.absolutePath() );
addIfUnavailable(urls, volumesDir.absolutePath());
#endif

#ifdef LMMS_BUILD_LINUX
Expand All @@ -96,15 +103,20 @@ FileDialog::FileDialog( QWidget *parent, const QString &caption,
storage.refresh();

if (usableFileSystems.contains(QString(storage.fileSystemType()), Qt::CaseInsensitive) && storage.isValid() && storage.isReady())
{
urls << QUrl::fromLocalFile(storage.rootPath());
{
addIfUnavailable(urls, storage.rootPath());
}
}
#endif

setSidebarUrls(urls);
}

FileDialog::~FileDialog()
{
setSidebarUrls(m_oldURLs);
}


QString FileDialog::getExistingDirectory(QWidget *parent,
const QString &caption,
Expand Down Expand Up @@ -146,4 +158,4 @@ void FileDialog::clearSelection()
}


} // namespace lmms::gui
} // namespace lmms::gui

0 comments on commit 1eb402d

Please sign in to comment.