diff --git a/app/qml/BooksBookView.qml b/app/qml/BooksBookView.qml index 01592ae..0ebf09b 100644 --- a/app/qml/BooksBookView.qml +++ b/app/qml/BooksBookView.qml @@ -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 diff --git a/app/qml/BooksFitLabel.qml b/app/qml/BooksFitLabel.qml index 8f6d6ab..0d652df 100644 --- a/app/qml/BooksFitLabel.qml +++ b/app/qml/BooksFitLabel.qml @@ -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() diff --git a/app/qml/BooksImport.qml b/app/qml/BooksImport.qml index d40b5eb..2c430ad 100644 --- a/app/qml/BooksImport.qml +++ b/app/qml/BooksImport.qml @@ -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 { diff --git a/app/qml/BooksImportItem.qml b/app/qml/BooksImportItem.qml index 8a76e0d..1e72880 100644 --- a/app/qml/BooksImportItem.qml +++ b/app/qml/BooksImportItem.qml @@ -93,6 +93,7 @@ BackgroundItem { } BusyIndicator { + id: busyIndicator anchors.centerIn: parent visible: !root.enabled running: visible diff --git a/app/src/BooksImportModel.cpp b/app/src/BooksImportModel.cpp index 46277af..17a7f7e 100644 --- a/app/src/BooksImportModel.cpp +++ b/app/src/BooksImportModel.cpp @@ -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 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 diff --git a/app/src/BooksImportModel.h b/app/src/BooksImportModel.h index 95f2d2e..704988e 100644 --- a/app/src/BooksImportModel.h +++ b/app/src/BooksImportModel.h @@ -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 iList; QVector iSelectedRole; + int iProgress; int iSelectedCount; bool iAutoRefresh; shared_ptr iTaskQueue;