1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-30 11:04:57 +01:00

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)); QString("device_%1_fts").arg(database_id));
// Create the model // Create the model
model_ = new LibraryModel(backend_, this); model_ = new LibraryModel(backend_, manager->task_manager(), this);
} }
ConnectedDevice::~ConnectedDevice() { ConnectedDevice::~ConnectedDevice() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -87,7 +87,7 @@ JamendoService::JamendoService(RadioModel* parent)
using smart_playlists::Search; using smart_playlists::Search;
using smart_playlists::SearchTerm; 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_various_artists(false);
library_model_->set_show_smart_playlists(true); library_model_->set_show_smart_playlists(true);
library_model_->set_default_smart_playlists(LibraryModel::DefaultGenerators() 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_->moveToThread(parent->db_thread());
library_backend_->Init(parent->db_thread()->Worker(), kSongsTable, library_backend_->Init(parent->db_thread()->Worker(), kSongsTable,
QString::null, QString::null, kFtsTable); 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)), connect(library_backend_, SIGNAL(TotalSongCountUpdated(int)),
SLOT(UpdateTotalSongCount(int))); SLOT(UpdateTotalSongCount(int)));

View File

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