[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 size: BusyIndicatorSize.Large
running: _loading running: _loading
} }
BooksFitLabel { BooksFitLabel {
anchors { anchors.fill: busyIndicator
fill: busyIndicator
margins: Theme.paddingMedium
}
maxFontSize: Theme.fontSizeMedium
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
color: Theme.highlightColor
text: bookModel.progress > 0 ? bookModel.progress : "" text: bookModel.progress > 0 ? bookModel.progress : ""
visible: opacity > 0 opacity: (_loading && bookModel.progress > 0) ? 1 : 0
opacity: (_loading && bookModel.progress) > 0 ? 1 : 0
Behavior on opacity { FadeAnimation {} }
} }
Label { Label {
anchors { anchors {
top: busyIndicator.bottom top: busyIndicator.bottom

View file

@ -34,9 +34,16 @@ import Sailfish.Silica 1.0
Label { Label {
property int minFontSize: Theme.fontSizeTiny property int minFontSize: Theme.fontSizeTiny
property int maxFontSize: Theme.fontSizeHuge property int maxFontSize: Theme.fontSizeMedium
smooth: true 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() Component.onCompleted: refitText()

View file

@ -95,12 +95,19 @@ Dialog {
} }
BusyIndicator { BusyIndicator {
id: busyIndicator
visible: opacity > 0 visible: opacity > 0
anchors.centerIn: parent anchors.centerIn: parent
size: BusyIndicatorSize.Large size: BusyIndicatorSize.Large
running: _loading && !importModel.count 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 // Give the dialog 1 second to initialize and finish the transition
// then ask the model to actually examine the downloads // then ask the model to actually examine the downloads
Timer { Timer {

View file

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

View file

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

View file

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