[app] Show number of scanned files to entertain the user

This commit is contained in:
Slava Monich 2015-07-16 23:51:57 +03:00
parent 1750361a7b
commit 135f196868
6 changed files with 53 additions and 15 deletions

View file

@ -213,20 +213,13 @@ SilicaFlickable {
size: BusyIndicatorSize.Large
running: _loading
}
BooksFitLabel {
anchors {
fill: busyIndicator
margins: Theme.paddingMedium
}
maxFontSize: Theme.fontSizeMedium
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
color: Theme.highlightColor
anchors.fill: busyIndicator
text: bookModel.progress > 0 ? bookModel.progress : ""
visible: opacity > 0
opacity: (_loading && bookModel.progress) > 0 ? 1 : 0
Behavior on opacity { FadeAnimation {} }
opacity: (_loading && bookModel.progress > 0) ? 1 : 0
}
Label {
anchors {
top: busyIndicator.bottom

View file

@ -34,9 +34,16 @@ import Sailfish.Silica 1.0
Label {
property int minFontSize: Theme.fontSizeTiny
property int maxFontSize: Theme.fontSizeHuge
property int maxFontSize: Theme.fontSizeMedium
smooth: true
visible: opacity > 0
color: Theme.highlightColor
anchors.margins: Theme.paddingMedium
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
Behavior on opacity { FadeAnimation {} }
Component.onCompleted: refitText()

View file

@ -95,12 +95,19 @@ Dialog {
}
BusyIndicator {
id: busyIndicator
visible: opacity > 0
anchors.centerIn: parent
size: BusyIndicatorSize.Large
running: _loading && !importModel.count
}
BooksFitLabel {
anchors.fill: busyIndicator
text: importModel.progress > 0 ? importModel.progress : ""
opacity: (busyIndicator.running && importModel.progress > 0) ? 1 : 0
}
// Give the dialog 1 second to initialize and finish the transition
// then ask the model to actually examine the downloads
Timer {

View file

@ -93,6 +93,7 @@ BackgroundItem {
}
BusyIndicator {
id: busyIndicator
anchors.centerIn: parent
visible: !root.enabled
running: visible

View file

@ -97,7 +97,7 @@ class BooksImportModel::Task : public BooksTask
Q_OBJECT
public:
Task(QString aDest) : iDestDir(aDest), iBufSize(0x1000), iBuf(NULL) {}
Task(QString aDest);
~Task();
void performTask();
@ -107,7 +107,8 @@ public:
QByteArray getFileHash(QString aPath);
Q_SIGNALS:
void bookFound(BooksBook* aBook) const;
void bookFound(BooksBook* aBook);
void progress(int aCount);
public:
QList<BooksBook*> iBooks;
@ -118,8 +119,14 @@ public:
QString iDestDir;
qint64 iBufSize;
char* iBuf;
int iProgress;
};
BooksImportModel::Task::Task(QString aDest) :
iDestDir(aDest), iBufSize(0x1000), iBuf(NULL), iProgress(0)
{
}
BooksImportModel::Task::~Task()
{
const int n = iBooks.count();
@ -241,6 +248,8 @@ void BooksImportModel::Task::scanDir(QDir aDir)
} else {
HDEBUG("not a book:" << path.c_str());
}
iProgress++;
Q_EMIT progress(iProgress);
}
}
@ -265,6 +274,7 @@ void BooksImportModel::Task::scanDir(QDir aDir)
BooksImportModel::BooksImportModel(QObject* aParent) :
QAbstractListModel(aParent),
iProgress(0),
iSelectedCount(0),
iAutoRefresh(false),
iTaskQueue(BooksTaskQueue::instance()),
@ -314,10 +324,17 @@ void BooksImportModel::refresh()
Q_EMIT countChanged();
}
if (iProgress) {
iProgress = 0;
Q_EMIT progressChanged();
}
iTask = new Task(iDestination);
connect(iTask, SIGNAL(bookFound(BooksBook*)),
SLOT(onBookFound(BooksBook*)), Qt::QueuedConnection);
connect(iTask, SIGNAL(done()), SLOT(onTaskDone()));
connect(iTask, SIGNAL(progress(int)), SLOT(onScanProgress(int)),
Qt::QueuedConnection);
iTaskQueue->submit(iTask);
Q_EMIT busyChanged();
}
@ -355,9 +372,17 @@ QObject* BooksImportModel::selectedBook(int aIndex)
return NULL;
}
void BooksImportModel::onScanProgress(int aProgress)
{
if (iTask && iTask == sender()) {
iProgress = aProgress;
Q_EMIT progressChanged();
}
}
void BooksImportModel::onBookFound(BooksBook* aBook)
{
if (iTask) {
if (iTask && iTask == sender()) {
// When we find the first book, we add two items. The second item
// is the "virtual" that will stay at the end of the list and will
// be removed by onTaskDone() after scanning is finished. The idea

View file

@ -48,6 +48,7 @@ class BooksImportModel: public QAbstractListModel
Q_OBJECT
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
Q_PROPERTY(int selectedCount READ selectedCount NOTIFY selectedCountChanged)
Q_PROPERTY(QString destination READ destination WRITE setDestination NOTIFY destinationChanged)
@ -57,6 +58,7 @@ public:
bool busy() const { return iTask != NULL; }
int count() const { return iList.count(); }
int progress() const { return iProgress; }
int selectedCount() const { return iSelectedCount; }
QString destination() const { return iDestination; }
void setDestination(QString aDestination);
@ -73,10 +75,12 @@ public:
Q_SIGNALS:
void countChanged();
void busyChanged();
void progressChanged();
void selectedCountChanged();
void destinationChanged();
private Q_SLOTS:
void onScanProgress(int aProgress);
void onBookFound(BooksBook* aBook);
void onTaskDone();
@ -89,6 +93,7 @@ private:
QString iDestination;
QList<Data*> iList;
QVector<int> iSelectedRole;
int iProgress;
int iSelectedCount;
bool iAutoRefresh;
shared_ptr<BooksTaskQueue> iTaskQueue;