Show loading indicators in the library model and the status bar when asynchronously loading songs during initialisation.

This commit is contained in:
David Sansome 2011-02-26 14:27:57 +00:00
parent 62b6d052de
commit 2b08d27a88
10 changed files with 38 additions and 9 deletions

View File

@ -54,7 +54,7 @@ ConnectedDevice::ConnectedDevice(const QUrl& url, DeviceLister* lister,
QString("device_%1_fts").arg(database_id));
// Create the model
model_ = new LibraryModel(backend_, this);
model_ = new LibraryModel(backend_, manager->task_manager(), this);
}
ConnectedDevice::~ConnectedDevice() {

View File

@ -48,7 +48,7 @@ Library::Library(BackgroundThread<Database>* db_thread, TaskManager* task_manage
using smart_playlists::Search;
using smart_playlists::SearchTerm;
model_ = new LibraryModel(backend_, this);
model_ = new LibraryModel(backend_, task_manager_, this);
model_->set_show_smart_playlists(true);
model_->set_default_smart_playlists(LibraryModel::DefaultGenerators()
<< (LibraryModel::GeneratorList()

View File

@ -33,6 +33,7 @@ class LibraryItem : public SimpleTreeItem<LibraryItem> {
Type_Song,
Type_PlaylistContainer,
Type_SmartPlaylist,
Type_LoadingIndicator,
};
LibraryItem(SimpleTreeModel<LibraryItem>* model)

View File

@ -23,6 +23,7 @@
#include "sqlrow.h"
#include "core/albumcoverloader.h"
#include "core/database.h"
#include "core/taskmanager.h"
#include "playlist/songmimedata.h"
#include "smartplaylists/generator.h"
#include "smartplaylists/generatormimedata.h"
@ -51,9 +52,11 @@ const int LibraryModel::kSmartPlaylistsVersion = 3;
typedef QFuture<SqlRowList> RootQueryFuture;
typedef QFutureWatcher<SqlRowList> RootQueryWatcher;
LibraryModel::LibraryModel(LibraryBackend* backend, QObject* parent)
LibraryModel::LibraryModel(LibraryBackend* backend, TaskManager* task_manager,
QObject* parent)
: SimpleTreeModel<LibraryItem>(new LibraryItem(this), parent),
backend_(backend),
task_manager_(task_manager),
dir_model_(new LibraryDirectoryModel(backend, this)),
show_smart_playlists_(false),
show_various_artists_(true),
@ -63,6 +66,7 @@ LibraryModel::LibraryModel(LibraryBackend* backend, QObject* parent)
no_cover_icon_(":nocover.png"),
playlists_dir_icon_(IconLoader::Load("folder-sound")),
playlist_icon_(":/icons/22x22/x-clementine-albums.png"),
init_task_id_(-1),
pretty_cover_size_(32, 32),
use_pretty_covers_(false)
{
@ -99,6 +103,15 @@ void LibraryModel::Init(bool async) {
backend_->UpdateTotalSongCountAsync();
if (async) {
// Show a loading indicator in the model.
LibraryItem* loading = new LibraryItem(LibraryItem::Type_LoadingIndicator, root_);
loading->display_text = tr("Loading...");
loading->lazy_loaded = true;
reset();
// Show a loading indicator in the status bar too.
init_task_id_ = task_manager_->StartTask(tr("Loading songs"));
ResetAsync();
} else {
Reset();
@ -590,6 +603,11 @@ void LibraryModel::ResetAsyncQueryFinished() {
container_nodes_[0][item->key] = item;
}
if (init_task_id_ != -1) {
task_manager_->SetTaskFinished(init_task_id_);
init_task_id_ = -1;
}
reset();
}
@ -914,6 +932,7 @@ Qt::ItemFlags LibraryModel::flags(const QModelIndex& index) const {
Qt::ItemIsDragEnabled;
case LibraryItem::Type_Divider:
case LibraryItem::Type_Root:
case LibraryItem::Type_LoadingIndicator:
default:
return Qt::ItemIsEnabled;
}

View File

@ -44,7 +44,8 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
Q_ENUMS(GroupBy);
public:
LibraryModel(LibraryBackend* backend, QObject* parent = 0);
LibraryModel(LibraryBackend* backend, TaskManager* task_manager,
QObject* parent = 0);
~LibraryModel();
static const char* kSmartPlaylistsMimeType;
@ -219,6 +220,7 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
private:
LibraryBackend* backend_;
TaskManager* task_manager_;
LibraryDirectoryModel* dir_model_;
bool show_smart_playlists_;
DefaultGenerators default_smart_playlists_;
@ -252,6 +254,8 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
QIcon no_cover_icon_;
QIcon playlists_dir_icon_;
QIcon playlist_icon_;
int init_task_id_;
QSize pretty_cover_size_;
bool use_pretty_covers_;

View File

@ -566,6 +566,10 @@ void LibraryView::EditSmartPlaylistFinished() {
}
QString LibraryView::GetNameForNewPlaylist(const SongList& songs) {
if (songs.isEmpty()) {
return tr("Playlist");
}
QSet<QString> artists;
QSet<QString> albums;

View File

@ -38,11 +38,12 @@ namespace smart_playlists { class Wizard; }
class LibraryItemDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
public:
LibraryItemDelegate(QObject* parent);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
public slots:
public slots:
bool helpEvent(QHelpEvent *event, QAbstractItemView *view,
const QStyleOptionViewItem &option, const QModelIndex &index);
};

View File

@ -87,7 +87,7 @@ JamendoService::JamendoService(RadioModel* parent)
using smart_playlists::Search;
using smart_playlists::SearchTerm;
library_model_ = new LibraryModel(library_backend_, this);
library_model_ = new LibraryModel(library_backend_, parent->task_manager(), this);
library_model_->set_show_various_artists(false);
library_model_->set_show_smart_playlists(true);
library_model_->set_default_smart_playlists(LibraryModel::DefaultGenerators()

View File

@ -79,7 +79,7 @@ MagnatuneService::MagnatuneService(RadioModel* parent)
library_backend_->moveToThread(parent->db_thread());
library_backend_->Init(parent->db_thread()->Worker(), kSongsTable,
QString::null, QString::null, kFtsTable);
library_model_ = new LibraryModel(library_backend_, this);
library_model_ = new LibraryModel(library_backend_, parent->task_manager(), this);
connect(library_backend_, SIGNAL(TotalSongCountUpdated(int)),
SLOT(UpdateTotalSongCount(int)));

View File

@ -37,7 +37,7 @@ class LibraryModelTest : public ::testing::Test {
backend_.reset(new LibraryBackend);
backend_->Init(database_, Library::kSongsTable,
Library::kDirsTable, Library::kSubdirsTable, Library::kFtsTable);
model_.reset(new LibraryModel(backend_.get()));
model_.reset(new LibraryModel(backend_.get(), NULL));
added_dir_ = false;