Commit 647cd78f authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark
Browse files

show size of files scanned so far in progress box

parent 5af1bcb2
...@@ -189,13 +189,15 @@ LocalLister::scan(const QByteArray &path, const QByteArray &dirname) ...@@ -189,13 +189,15 @@ LocalLister::scan(const QByteArray &path, const QByteArray &dirname)
continue; continue;
} }
if (S_ISREG(statbuf.st_mode)) //file if (S_ISREG(statbuf.st_mode)) { //file
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
cwd->append(ent->d_name, (statbuf.st_blocks * S_BLKSIZE)); const size_t size = (statbuf.st_blocks * S_BLKSIZE);
#else #else
cwd->append(ent->d_name, statbuf.st_size); const size_t size = statbuf.st_size;
#endif #endif
cwd->append(ent->d_name, size);
m_parent->m_totalSize += size;
}
else if (S_ISDIR(statbuf.st_mode)) //folder else if (S_ISDIR(statbuf.st_mode)) //folder
{ {
Folder *d = nullptr; Folder *d = nullptr;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "mainWindow.h" #include "mainWindow.h"
#include <KColorScheme> #include <KColorScheme>
#include <KFormat>
#include <KIO/Job> #include <KIO/Job>
#include <KLocalizedString> #include <KLocalizedString>
...@@ -45,7 +46,7 @@ ProgressBox::ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Fil ...@@ -45,7 +46,7 @@ ProgressBox::ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Fil
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
setText(999999); setText(999999, 0);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setMinimumSize(300, 300); setMinimumSize(300, 300);
...@@ -66,7 +67,7 @@ ProgressBox::start() //slot ...@@ -66,7 +67,7 @@ ProgressBox::start() //slot
void void
ProgressBox::report() //slot ProgressBox::report() //slot
{ {
setText(m_manager->files()); setText(m_manager->files(), m_manager->totalSize());
update(); //repaint(); update(); //repaint();
} }
...@@ -85,9 +86,9 @@ ProgressBox::halt() ...@@ -85,9 +86,9 @@ ProgressBox::halt()
} }
void void
ProgressBox::setText(int files) ProgressBox::setText(int files, size_t totalSize)
{ {
m_text = i18np("%1 File", "%1 Files", files); m_text = i18ncp("Scanned number of files and size so far", "%1 File, %2", "%1 Files, %2", files, KFormat().formatByteSize(totalSize));
m_textWidth = fontMetrics().boundingRect(m_text).width(); m_textWidth = fontMetrics().boundingRect(m_text).width();
m_textHeight = fontMetrics().height(); m_textHeight = fontMetrics().height();
} }
......
...@@ -38,7 +38,7 @@ class ProgressBox : public QWidget ...@@ -38,7 +38,7 @@ class ProgressBox : public QWidget
public: public:
ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Filelight::ScanManager *scanManager); ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Filelight::ScanManager *scanManager);
void setText(int); void setText(int files, size_t totalSize);
public Q_SLOTS: public Q_SLOTS:
void start(); void start();
......
...@@ -112,10 +112,12 @@ void RemoteLister::onCompleted() ...@@ -112,10 +112,12 @@ void RemoteLister::onCompleted()
const KFileItemList items = KDirLister::items(); const KFileItemList items = KDirLister::items();
for (KFileItemList::ConstIterator it = items.begin(), end = items.end(); it != end; ++it) for (KFileItemList::ConstIterator it = items.begin(), end = items.end(); it != end; ++it)
{ {
if (it->isDir()) if (it->isDir()) {
m_store->stores += new Store(it->url(), it->name(), m_store); m_store->stores += new Store(it->url(), it->name(), m_store);
else } else {
m_store->folder->append(it->name().toUtf8().constData(), it->size()); m_store->folder->append(it->name().toUtf8().constData(), it->size());
m_manager->m_totalSize += it->size();
}
m_manager->m_files++; m_manager->m_files++;
} }
......
...@@ -47,8 +47,11 @@ public: ...@@ -47,8 +47,11 @@ public:
bool start(const QUrl& path); bool start(const QUrl& path);
bool running() const; bool running() const;
uint files() const { int files() const {
return m_files; return m_files.loadRelaxed();
}
size_t totalSize() const {
return m_totalSize.loadRelaxed();
} }
void invalidateCacheFor(const QUrl &url); void invalidateCacheFor(const QUrl &url);
...@@ -66,7 +69,8 @@ Q_SIGNALS: ...@@ -66,7 +69,8 @@ Q_SIGNALS:
private: private:
bool m_abort; bool m_abort;
uint m_files; QAtomicInt m_files;
QAtomicInteger<size_t> m_totalSize;
QMutex m_mutex; QMutex m_mutex;
LocalLister *m_thread; LocalLister *m_thread;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment