Disable folders model when page hidden

This commit is contained in:
craig
2012-01-18 21:01:18 +00:00
committed by craig
parent 1578eb648a
commit 450bbcf917
3 changed files with 30 additions and 5 deletions

View File

@@ -35,6 +35,7 @@
FolderPage::FolderPage(MainWindow *p)
: QWidget(p)
, enabled(false)
{
setupUi(this);
addToPlaylist->setDefaultAction(p->addToPlaylistAction);
@@ -59,9 +60,6 @@ FolderPage::FolderPage(MainWindow *p)
proxy.setSourceModel(&model);
view->setModel(&proxy);
view->init(p->replacePlaylistAction, p->addToPlaylistAction);
connect(MPDConnection::self(), SIGNAL(dirViewUpdated(DirViewItemRoot *)), &model, SLOT(updateDirView(DirViewItemRoot *)));
connect(MPDConnection::self(), SIGNAL(updatingFileList()), view, SLOT(showSpinner()));
connect(MPDConnection::self(), SIGNAL(updatedFileList()), view, SLOT(hideSpinner()));
connect(this, SIGNAL(listAll()), MPDConnection::self(), SLOT(listAll()));
connect(this, SIGNAL(add(const QStringList &)), MPDConnection::self(), SLOT(add(const QStringList &)));
connect(this, SIGNAL(addSongsToPlaylist(const QString &, const QStringList &)), MPDConnection::self(), SLOT(addToPlaylist(const QString &, const QStringList &)));
@@ -75,10 +73,31 @@ FolderPage::~FolderPage()
{
}
void FolderPage::setEnabled(bool e)
{
if (e==enabled) {
return;
}
enabled=e;
if (enabled) {
connect(MPDConnection::self(), SIGNAL(dirViewUpdated(DirViewItemRoot *)), &model, SLOT(updateDirView(DirViewItemRoot *)));
connect(MPDConnection::self(), SIGNAL(updatingFileList()), view, SLOT(showSpinner()));
connect(MPDConnection::self(), SIGNAL(updatedFileList()), view, SLOT(hideSpinner()));
refresh();
} else {
disconnect(MPDConnection::self(), SIGNAL(dirViewUpdated(DirViewItemRoot *)), &model, SLOT(updateDirView(DirViewItemRoot *)));
disconnect(MPDConnection::self(), SIGNAL(updatingFileList()), view, SLOT(showSpinner()));
disconnect(MPDConnection::self(), SIGNAL(updatedFileList()), view, SLOT(hideSpinner()));
}
}
void FolderPage::refresh()
{
view->showSpinner();
emit listAll();
if (enabled) {
view->showSpinner();
emit listAll();
}
}
void FolderPage::clear()

View File

@@ -36,6 +36,8 @@ public:
FolderPage(MainWindow *p);
virtual ~FolderPage();
void setEnabled(bool e);
bool isEnabled() const { return enabled; }
void refresh();
void clear();
void addSelectionToPlaylist(const QString &name=QString());
@@ -55,6 +57,7 @@ private:
QStringList walk(QModelIndex rootItem);
private:
bool enabled;
DirViewModel model;
DirViewProxyModel proxy;
};

View File

@@ -549,6 +549,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
tabWidget->AddTab(devicesPage, devicesTabAction->icon(), devicesTabAction->text(), !hiddenPages.contains(devicesPage->metaObject()->className()));
#endif
AlbumsModel::self()->setEnabled(!hiddenPages.contains(albumsPage->metaObject()->className()));
folderPage->setEnabled(!hiddenPages.contains(folderPage->metaObject()->className()));
tabWidget->SetMode(FancyTabWidget::Mode_LargeSidebar);
connect(tabWidget, SIGNAL(CurrentChanged(int)), this, SLOT(currentTabChanged(int)));
@@ -1836,6 +1837,8 @@ void MainWindow::tabToggled(int index)
{
if(PAGE_ALBUMS==index) {
AlbumsModel::self()->setEnabled(!AlbumsModel::self()->isEnabled());
} else if(PAGE_FOLDERS==index) {
folderPage->setEnabled(!folderPage->isEnabled());
}
}