Add view modes
This commit is contained in:
@@ -27,20 +27,28 @@
|
||||
#include "models/playqueuemodel.h"
|
||||
#include "widgets/menubutton.h"
|
||||
#include "support/monoicon.h"
|
||||
#include "support/configuration.h"
|
||||
#include <QDesktopServices>
|
||||
|
||||
LocalFolderBrowsePage::LocalFolderBrowsePage(bool isHome, QWidget *p)
|
||||
: SinglePageWidget(p)
|
||||
, isHomeFolder(isHome)
|
||||
{
|
||||
model = isHome ? new LocalBrowseModel(QLatin1String("localbrowsehome"), tr("Home"), tr("Browse files in your home folder"), ":home.svg", this)
|
||||
: new LocalBrowseModel(QLatin1String("localbrowseroot"), tr("Root"), tr("Browse files on your computer"), ":hdd.svg", this);
|
||||
proxy = new FileSystemProxyModel(model);
|
||||
view->setModel(proxy);
|
||||
browseAction = new Action(MonoIcon::icon(FontAwesome::folderopen, Utils::monoIconColor()), tr("Open In File Manager"), this);
|
||||
connect(view, SIGNAL(itemsSelected(bool)), this, SLOT(controlActions()));
|
||||
connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(itemDoubleClicked(const QModelIndex &)));
|
||||
connect(view, SIGNAL(headerClicked(int)), SLOT(headerClicked(int)));
|
||||
connect(browseAction, SIGNAL(triggered()), this, SLOT(openFileManager()));
|
||||
init(ReplacePlayQueue|AppendToPlayQueue);
|
||||
Configuration config(configGroup());
|
||||
view->load(config);
|
||||
MenuButton *menu=new MenuButton(this);
|
||||
menu->addActions(createViewActions(QList<ItemView::Mode>() << ItemView::Mode_BasicTree << ItemView::Mode_SimpleTree
|
||||
<< ItemView::Mode_DetailedTree << ItemView::Mode_List));
|
||||
init(ReplacePlayQueue|AppendToPlayQueue, QList<QWidget *>() << menu);
|
||||
|
||||
// view->addAction(CustomActions::self());
|
||||
// #ifdef TAGLIB_FOUND
|
||||
@@ -50,18 +58,30 @@ LocalFolderBrowsePage::LocalFolderBrowsePage(bool isHome, QWidget *p)
|
||||
// #endif
|
||||
// #endif // TAGLIB_FOUND
|
||||
view->addAction(browseAction);
|
||||
view->setModel(proxy);
|
||||
view->closeSearch();
|
||||
view->alwaysShowHeader();
|
||||
view->view()->setRootIndex(proxy->mapFromSource(model->setRootPath(isHome ? QDir::homePath() : "/")));
|
||||
setView(view->viewMode());
|
||||
}
|
||||
|
||||
LocalFolderBrowsePage::~LocalFolderBrowsePage()
|
||||
{
|
||||
Configuration config(configGroup());
|
||||
view->save(config);
|
||||
model->deleteLater();
|
||||
model=nullptr;
|
||||
}
|
||||
|
||||
QString LocalFolderBrowsePage::configGroup() const
|
||||
{
|
||||
return isHomeFolder ? QLatin1String("localbrowsehome") : QLatin1String("localbrowseroot");
|
||||
}
|
||||
|
||||
void LocalFolderBrowsePage::setView(int v)
|
||||
{
|
||||
SinglePageWidget::setView(v);
|
||||
view->view()->setRootIndex(proxy->mapFromSource(model->setRootPath(isHomeFolder ? QDir::homePath() : "/")));
|
||||
}
|
||||
|
||||
void LocalFolderBrowsePage::headerClicked(int level)
|
||||
{
|
||||
if (0==level) {
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
const Icon & icon() const { return model->icon(); }
|
||||
|
||||
private:
|
||||
QString configGroup() const;
|
||||
void setView(int v) override;
|
||||
void addSelectionToPlaylist(const QString &name=QString(), int action=MPDConnection::Append, quint8 priority=0, bool decreasePriority=false) override;
|
||||
void controlActions() override;
|
||||
|
||||
@@ -51,6 +53,7 @@ private Q_SLOTS:
|
||||
void openFileManager();
|
||||
|
||||
private:
|
||||
bool isHomeFolder;
|
||||
LocalBrowseModel *model;
|
||||
FileSystemProxyModel *proxy;
|
||||
Action *browseAction;
|
||||
|
||||
@@ -75,7 +75,7 @@ LocalBrowseModel::LocalBrowseModel(const QString &name, const QString &title, co
|
||||
|
||||
QVariant LocalBrowseModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
if (!index.isValid() || fileInfo(index).absoluteFilePath()==rootPath()) {
|
||||
switch (role) {
|
||||
case Cantata::Role_TitleText:
|
||||
return title();
|
||||
@@ -95,6 +95,12 @@ QVariant LocalBrowseModel::data(const QModelIndex &index, int role) const
|
||||
? Icons::self()->playlistListIcon
|
||||
: Icons::self()->audioListIcon;
|
||||
}
|
||||
case Cantata::Role_TitleText:
|
||||
return QFileSystemModel::data(index, Qt::DisplayRole);
|
||||
case Cantata::Role_SubText: {
|
||||
QFileInfo info = fileInfo(index);
|
||||
return info.isDir() ? QString() : Utils::formatByteSize(info.size());
|
||||
}
|
||||
case Cantata::Role_Actions: {
|
||||
QVariant v;
|
||||
v.setValue<QList<Action *> >(QList<Action *>() << StdActions::self()->replacePlayQueueAction << StdActions::self()->appendToPlayQueueAction);
|
||||
|
||||
Reference in New Issue
Block a user