diff options
Diffstat (limited to 'notebookmodel.cc')
-rw-r--r-- | notebookmodel.cc | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/notebookmodel.cc b/notebookmodel.cc index 2b7c99f..2139ee7 100644 --- a/notebookmodel.cc +++ b/notebookmodel.cc @@ -4,6 +4,7 @@ #include <QtGui/QDesktopServices> #include <QtGui/QStyle> #include "paperreplay.h" +#include "afdnotebook.h" #include "notebookmodel.h" #define NUM_COLUMNS 3 @@ -66,6 +67,15 @@ QVariant NotebookModel::data(const QModelIndex &index, int role) const return _pens[penIndex]; } break; + case Qt::DecorationRole: + switch (index.column()) { + case 2: + if (isPenLocked(_pens[penIndex])) { + return QApplication::style()->standardIcon(QStyle::SP_BrowserReload); + } + break; + } + break; } } else { const QString &penName = _pens[id]; @@ -77,7 +87,10 @@ QVariant NotebookModel::data(const QModelIndex &index, int role) const case 0: return notebooks.at(index.row()); case 1: - return 0; + if (notebookName != PAPER_REPLAY) { + return estimatePagesOfNotebook(penName, notebookName); + } + break; } break; case Qt::DecorationRole: @@ -90,6 +103,7 @@ QVariant NotebookModel::data(const QModelIndex &index, int role) const if (isNotebookLocked(penName, notebookName)) { return QApplication::style()->standardIcon(QStyle::SP_BrowserReload); } + break; } case Qt::TextAlignmentRole: switch (index.column()) { @@ -240,6 +254,8 @@ void NotebookModel::refreshPen(const QString &name) QModelIndex penIndex = index(indexOfPen(name), 0, QModelIndex()); + emit dataChanged(penIndex, index(penIndex.row(), NUM_COLUMNS - 1, QModelIndex())); + int i = 0, j = 0; while (i < curNotebooks.size() && j < diskNotebooks.size()) { int comp = QString::compare(curNotebooks[i], diskNotebooks[j], Qt::CaseInsensitive); @@ -283,9 +299,14 @@ int NotebookModel::indexOfPen(const QString &name) } } +QDir NotebookModel::penDir(const QString &pen) const +{ + return QDir(penDirectory(pen)); +} + QDir NotebookModel::notebookDir(const QString &pen, const QString ¬ebook) const { - return QDir(_dataDir.filePath("%1.pen/%2.afd").arg(pen, notebook)); + return QDir(notebookDirectory(pen, notebook)); } QIcon NotebookModel::getNotebookIcon(const QString &pen, const QString ¬ebook) const @@ -311,6 +332,16 @@ QIcon NotebookModel::getNotebookIcon(const QString &pen, const QString ¬ebook return icon; } +bool NotebookModel::isPenLocked(const QString &pen) const +{ + QDir dir = penDir(pen); + if (dir.exists(".sync.lck")) { + return true; // TODO check if stale + } else { + return false; + } +} + bool NotebookModel::isNotebookLocked(const QString &pen, const QString ¬ebook) const { QDir dir = notebookDir(pen, notebook); @@ -321,6 +352,13 @@ bool NotebookModel::isNotebookLocked(const QString &pen, const QString ¬ebook } } +int NotebookModel::estimatePagesOfNotebook(const QString &pen, const QString ¬ebook) const +{ + QDir dataDir(notebookDirectory(pen, notebook) + "/data"); + QStringList pages = dataDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); + return pages.count(); +} + void NotebookModel::handleChangedDirectory(const QString &path) { qDebug() << "changed" << path; |