QXRD  0.11.16
Public Slots | Public Member Functions | Private Attributes | List of all members
QxrdFileBrowserModelUpdater Class Reference

#include <qxrdfilebrowsermodelupdater.h>

Inheritance diagram for QxrdFileBrowserModelUpdater:
Inheritance graph
[legend]
Collaboration diagram for QxrdFileBrowserModelUpdater:
Collaboration graph
[legend]

Public Slots

void changeRoot (const QString &path)
 
void changeContents (const QString &path)
 
void updateTimeout ()
 
void needUpdate ()
 
void updateContents ()
 
void generateFileUpdates (int doIt)
 
- Public Slots inherited from QcepObject
virtual void printLine (QString line)
 
virtual void printMessage (QString msg, QDateTime dt=QDateTime::currentDateTime()) const
 
virtual void criticalMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
virtual void statusMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
virtual QString settingsScript ()
 
QString scriptValueLiteral (QVariant v)
 

Public Member Functions

 QxrdFileBrowserModelUpdater (QxrdFileBrowserModelWPtr browser, QcepObject *parent)
 
virtual ~QxrdFileBrowserModelUpdater ()
 
bool updateNeeded ()
 
- Public Member Functions inherited from QcepObject
 QcepObject (QString name, QcepObject *parent)
 
virtual ~QcepObject ()
 
virtual void writeSettings (QSettings *set, QString section)
 
virtual void readSettings (QSettings *set, QString section)
 
QString get_Name () const
 
void set_Name (QString name)
 

Private Attributes

QxrdFileBrowserModelWPtr m_BrowserModel
 
QString m_RootPath
 
QFileSystemWatcher * m_FileSystemWatcher
 
QAtomicInt m_UpdateNeeded
 
QTimer m_UpdateTimer
 
int m_UpdateInterval
 
QVector< QFileInfo > m_Directories
 
QVector< QFileInfo > m_Files
 
QDateTime m_PreviousUpdate
 
QAtomicInt m_GenerateUpdates
 

Additional Inherited Members

- Static Public Member Functions inherited from QcepObject
static int allocatedObjects ()
 
static int deletedObjects ()
 
static QSet< QcepObject * > allocatedObjectsSet ()
 
static QString addSlashes (QString str)
 
- Properties inherited from QcepObject
QString name
 

Detailed Description

Definition at line 13 of file qxrdfilebrowsermodelupdater.h.

Constructor & Destructor Documentation

QxrdFileBrowserModelUpdater::QxrdFileBrowserModelUpdater ( QxrdFileBrowserModelWPtr  browser,
QcepObject parent 
)
explicit

Definition at line 10 of file qxrdfilebrowsermodelupdater.cpp.

References changeContents(), changeRoot(), DEBUG_BROWSER, g_Application, m_BrowserModel, m_FileSystemWatcher, m_UpdateInterval, m_UpdateTimer, QcepApplication::printMessage(), qcepDebug(), QxrdFileBrowserModel::rootChanged(), and updateTimeout().

10  :
11  QcepObject("fileBrowserModelUpdater", parent),
12  m_BrowserModel(browser),
13  m_RootPath(""),
14  m_FileSystemWatcher(NULL),
15  m_UpdateNeeded(1),
16  m_UpdateTimer(),
17  m_UpdateInterval(1000),
18  m_PreviousUpdate(QDateTime::currentDateTime()),
19  m_GenerateUpdates(true)
20 {
22  g_Application->printMessage("Starting Browser Model Updater");
23  }
24 
25  m_FileSystemWatcher = new QFileSystemWatcher(this);
26 
28 
29  if (model) {
30  connect(model.data(), &QxrdFileBrowserModel::rootChanged,
32  }
33 
34  connect(m_FileSystemWatcher, &QFileSystemWatcher::directoryChanged,
35  this, &QxrdFileBrowserModelUpdater::changeContents, Qt::DirectConnection);
36  connect(&m_UpdateTimer, &QTimer::timeout,
38 
39  m_UpdateTimer.setSingleShot(true);
41 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void changeContents(const QString &path)
QxrdFileBrowserModelWPtr m_BrowserModel
QcepObject(QString name, QcepObject *parent)
Definition: qcepobject.cpp:16
void rootChanged(const QString &path)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
QSharedPointer< QxrdFileBrowserModel > QxrdFileBrowserModelPtr

Here is the call graph for this function:

QxrdFileBrowserModelUpdater::~QxrdFileBrowserModelUpdater ( )
virtual

Definition at line 43 of file qxrdfilebrowsermodelupdater.cpp.

References DEBUG_APP, DEBUG_CONSTRUCTORS, QcepObject::printMessage(), and qcepDebug().

44 {
45 #ifndef QT_NO_DEBUG
46  printf("Deleting file browser model updater\n");
47 #endif
48 
50  printf("QxrdFileBrowserModelUpdater::~QxrdFileBrowserModelUpdater(%p)\n", this);
51  }
52 
53  if (qcepDebug(DEBUG_APP)) {
54  printMessage("QxrdFileBrowserModelUpdater::~QxrdFileBrowserModelUpdater");
55  }
56 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime()) const
Definition: qcepobject.cpp:84

Here is the call graph for this function:

Member Function Documentation

void QxrdFileBrowserModelUpdater::changeContents ( const QString &  path)
slot

Definition at line 81 of file qxrdfilebrowsermodelupdater.cpp.

References DEBUG_BROWSER, g_Application, m_UpdateNeeded, QcepApplication::printMessage(), and qcepDebug().

Referenced by QxrdFileBrowserModelUpdater().

82 {
84  g_Application->printMessage(tr("QxrdFileBrowserModelUpdater::changeContents %1").arg(path));
85  }
86 
87  m_UpdateNeeded.fetchAndStoreOrdered(1);
88 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdFileBrowserModelUpdater::changeRoot ( const QString &  path)
slot

Definition at line 58 of file qxrdfilebrowsermodelupdater.cpp.

References DEBUG_BROWSER, g_Application, m_FileSystemWatcher, m_RootPath, QcepApplication::printMessage(), and qcepDebug().

Referenced by QxrdFileBrowserModelUpdater().

59 {
61  g_Application->printMessage(tr("QxrdFileBrowserModelUpdater::changeRoot %1").arg(path));
62  }
63 
64  QStringList dirs = m_FileSystemWatcher->directories();
65 
66  if (dirs.count() >= 1) {
67  m_FileSystemWatcher->removePaths(dirs);
68  }
69 
70  if (path != "") {
71  m_FileSystemWatcher->addPath(path);
72  m_RootPath = path;
73  }
74 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdFileBrowserModelUpdater::generateFileUpdates ( int  doIt)
slot

Definition at line 317 of file qxrdfilebrowsermodelupdater.cpp.

References m_GenerateUpdates, and m_PreviousUpdate.

318 {
319  if (doIt) {
320  m_PreviousUpdate = QDateTime::currentDateTime();
321  }
322 
323  m_GenerateUpdates = doIt;
324 }
void QxrdFileBrowserModelUpdater::needUpdate ( )
slot

Definition at line 76 of file qxrdfilebrowsermodelupdater.cpp.

References m_UpdateNeeded.

77 {
78  m_UpdateNeeded.fetchAndStoreOrdered(1);
79 }
void QxrdFileBrowserModelUpdater::updateContents ( )
slot

Definition at line 167 of file qxrdfilebrowsermodelupdater.cpp.

References DEBUG_BROWSER, fileDateGreaterThan(), fileDateLessThan(), fileNameGreaterThan(), fileNameLessThan(), fileSizeGreaterThan(), fileSizeLessThan(), g_Application, m_BrowserModel, m_Directories, m_Files, m_GenerateUpdates, m_PreviousUpdate, m_RootPath, m_UpdateNeeded, mod(), QcepApplication::printMessage(), and qcepDebug().

Referenced by updateTimeout().

168 {
169  QTime tic;
170  tic.start();
171 
172  m_UpdateNeeded.fetchAndStoreOrdered(0);
173 
175 
176  if (model) {
177  QDirIterator iterd(m_RootPath);
178  QDirIterator iter(m_RootPath, model->nameFilters());
179  QVector<QFileInfo> dirs;
180  QVector<QFileInfo> files;
181 
182  while (iterd.hasNext()) {
183  if (m_UpdateNeeded.fetchAndAddOrdered(0)) {
185  g_Application->printMessage("Directory list generation abandoned");
186  }
187 
188  return;
189  }
190 
191  QString filePath = iterd.next();
192  QFileInfo fileInfo(m_RootPath, filePath);
193 
194  if (fileInfo.isDir()) {
195  QString dirName = fileInfo.fileName();
196 
197  if ((dirName != ".") && (dirName != "..")) {
198  dirs.append(fileInfo);
199  }
200  }
201  }
202 
203  while (iter.hasNext()) {
204  if (m_UpdateNeeded.fetchAndAddOrdered(0)) {
206  g_Application->printMessage("File list generation abandoned");
207  }
208 
209  return;
210  }
211 
212  QString filePath = iter.next();
213  QFileInfo fileInfo(m_RootPath, filePath);
214 
215  if (fileInfo.isDir()) {
216  } else {
217  files.append(fileInfo);
218  }
219  }
220 
221  m_Directories = dirs;
222  m_Files = files;
223 
225  g_Application->printMessage(tr("Update file browser took %1 msec").arg(tic.restart()));
226  g_Application->printMessage(tr("File Path %1: %2 dirs, %3 files")
227  .arg(m_RootPath).arg(m_Directories.count()).arg(m_Files.count()));
228  }
229 
230  if (m_GenerateUpdates.fetchAndAddOrdered(0)) {
231  QDateTime latest = m_PreviousUpdate;
232 
233  foreach(QFileInfo file, files) {
234  QDateTime mod = file.lastModified();
235  if (mod > m_PreviousUpdate) {
236  model->updatedFile(file);
237  }
238 
239  if (mod > latest) {
240  latest = mod;
241  }
242  }
243 
244  m_PreviousUpdate = latest;
245  }
246 
247  int column = model->sortedColumn();
248  Qt::SortOrder order = model->sortOrder();
249 
250  try {
251  qStableSort(m_Directories.begin(), m_Directories.end(),
253 
254  switch(column) {
255  case 0:
256  if (order == Qt::AscendingOrder) {
257  qStableSort(m_Files.begin(), m_Files.end(),
259  } else {
260  qStableSort(m_Files.begin(), m_Files.end(),
262  }
263  break;
264 
265  case 1:
266  if (order == Qt::AscendingOrder) {
267  qStableSort(m_Files.begin(), m_Files.end(),
269  } else {
270  qStableSort(m_Files.begin(), m_Files.end(),
272  }
273  break;
274 
275  case 2:
276  if (order == Qt::AscendingOrder) {
277  qStableSort(m_Files.begin(), m_Files.end(),
279  } else {
280  qStableSort(m_Files.begin(), m_Files.end(),
282  }
283  break;
284  }
285  }
286 
287  catch (...) {
289  g_Application->printMessage("Sorting abandoned");
290  }
291 
292  return;
293  }
294 
296  g_Application->printMessage(tr("Sort file browser took %1 msec").arg(tic.elapsed()));
297  }
298 
299  int limit = 10000;
300 
301  QxrdApplication *app = qobject_cast<QxrdApplication*>(g_Application);
302 
303  if (app) {
304  limit = app->get_FileBrowserLimit();
305  }
306 
307  int trueSize = m_Files.count();
308 
309  if (limit && limit < trueSize) {
310  model->newDataAvailable(m_Directories, m_Files.mid(0,limit), limit, trueSize);
311  } else {
312  model->newDataAvailable(m_Directories, m_Files);
313  }
314  }
315 }
static bool fileDateLessThan(QFileInfo f1, QFileInfo f2)
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static bool fileSizeLessThan(QFileInfo f1, QFileInfo f2)
static bool fileNameGreaterThan(QFileInfo f1, QFileInfo f2)
static bool fileSizeGreaterThan(QFileInfo f1, QFileInfo f2)
QxrdFileBrowserModelWPtr m_BrowserModel
static bool fileNameLessThan(QFileInfo f1, QFileInfo f2)
static double mod(double a, double b)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
QSharedPointer< QxrdFileBrowserModel > QxrdFileBrowserModelPtr
static bool fileDateGreaterThan(QFileInfo f1, QFileInfo f2)

Here is the call graph for this function:

Here is the caller graph for this function:

bool QxrdFileBrowserModelUpdater::updateNeeded ( )

Definition at line 103 of file qxrdfilebrowsermodelupdater.cpp.

References m_UpdateNeeded.

104 {
105  return m_UpdateNeeded.fetchAndAddOrdered(0);
106 }
void QxrdFileBrowserModelUpdater::updateTimeout ( )
slot

Definition at line 90 of file qxrdfilebrowsermodelupdater.cpp.

References DEBUG_BROWSER, g_Application, m_RootPath, m_UpdateInterval, m_UpdateNeeded, m_UpdateTimer, QcepApplication::printMessage(), qcepDebug(), and updateContents().

Referenced by QxrdFileBrowserModelUpdater().

91 {
92  if (m_UpdateNeeded.fetchAndStoreOrdered(0)) {
94  g_Application->printMessage(tr("QxrdFileBrowserModelUpdater::updateTimeout update needed %1").arg(m_RootPath));
95  }
96 
98  }
99 
101 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

QxrdFileBrowserModelWPtr QxrdFileBrowserModelUpdater::m_BrowserModel
private

Definition at line 32 of file qxrdfilebrowsermodelupdater.h.

Referenced by QxrdFileBrowserModelUpdater(), and updateContents().

QVector<QFileInfo> QxrdFileBrowserModelUpdater::m_Directories
private

Definition at line 38 of file qxrdfilebrowsermodelupdater.h.

Referenced by updateContents().

QVector<QFileInfo> QxrdFileBrowserModelUpdater::m_Files
private

Definition at line 39 of file qxrdfilebrowsermodelupdater.h.

Referenced by updateContents().

QFileSystemWatcher* QxrdFileBrowserModelUpdater::m_FileSystemWatcher
private

Definition at line 34 of file qxrdfilebrowsermodelupdater.h.

Referenced by changeRoot(), and QxrdFileBrowserModelUpdater().

QAtomicInt QxrdFileBrowserModelUpdater::m_GenerateUpdates
private

Definition at line 41 of file qxrdfilebrowsermodelupdater.h.

Referenced by generateFileUpdates(), and updateContents().

QDateTime QxrdFileBrowserModelUpdater::m_PreviousUpdate
private

Definition at line 40 of file qxrdfilebrowsermodelupdater.h.

Referenced by generateFileUpdates(), and updateContents().

QString QxrdFileBrowserModelUpdater::m_RootPath
private

Definition at line 33 of file qxrdfilebrowsermodelupdater.h.

Referenced by changeRoot(), updateContents(), and updateTimeout().

int QxrdFileBrowserModelUpdater::m_UpdateInterval
private

Definition at line 37 of file qxrdfilebrowsermodelupdater.h.

Referenced by QxrdFileBrowserModelUpdater(), and updateTimeout().

QAtomicInt QxrdFileBrowserModelUpdater::m_UpdateNeeded
private
QTimer QxrdFileBrowserModelUpdater::m_UpdateTimer
private

Definition at line 36 of file qxrdfilebrowsermodelupdater.h.

Referenced by QxrdFileBrowserModelUpdater(), and updateTimeout().


The documentation for this class was generated from the following files: