From 55b5c88cf93d06629ba70eb7cddeb50a365b170a Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 12 Oct 2020 02:27:14 +0200 Subject: minor UI refactor; allow reading ".archive" directories Archives cannot be created from the UI yet. Just copy a .pen directory to an .archive directory for now. --- mainwindow.cc | 13 +-- mainwindow.ui | 290 ++++++++++++++++++++++++------------------------------ notebookmodel.cc | 95 ++++++++++++------ notebookmodel.h | 14 ++- paperreplay.h | 1 + smartpensyncer.cc | 2 +- 6 files changed, 215 insertions(+), 200 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index 5c27145..bba19cc 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -42,11 +42,9 @@ MainWindow::MainWindow(QWidget *parent) : ui->notebookTree->header()->setSectionResizeMode(1, QHeaderView::Fixed); ui->notebookTree->header()->setSectionResizeMode(2, QHeaderView::Fixed); ui->notebookTree->expandAll(); - ui->notebookView->setVisible(false); ui->paperReplayView->setModel(_replayModel); ui->paperReplayView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->paperReplayView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed); - ui->paperReplayView->setVisible(false); Phonon::createPath(_media, _mediaOutput); _media->setTickInterval(500); ui->replaySlider->setMediaObject(_media); @@ -85,9 +83,8 @@ void MainWindow::closeNotebook() _curPenName.clear(); _curNotebookName.clear(); _replay->close(); + ui->pane2Stack->setCurrentWidget(ui->notebookView); ui->notebookView->setNotebook(QString()); - ui->notebookView->setVisible(false); - ui->paperReplayView->setVisible(false); } void MainWindow::openNotebook(const QString &pen, const QString ¬ebook) @@ -105,7 +102,7 @@ void MainWindow::openNotebook(const QString &pen, const QString ¬ebook) _replay->open(replayDir, 0); _replayModel->refresh(); - ui->paperReplayView->setVisible(true); + ui->pane2Stack->setCurrentWidget(ui->paperReplayView); } else { QString nbDir = _notebooks->notebookDirectory(_curPenName, _curNotebookName); @@ -113,7 +110,7 @@ void MainWindow::openNotebook(const QString &pen, const QString ¬ebook) ui->notebookView->setPaperReplay(_notebooks->paperReplayDirectory(_curPenName)); ui->notebookView->setNotebook(nbDir); - ui->notebookView->setVisible(true); + ui->pane2Stack->setCurrentWidget(ui->notebookView); } } @@ -173,8 +170,8 @@ void MainWindow::handleNotebookSelected(const QModelIndex &index) // Get column 0, which corresponds to notebook name QModelIndex nb = _notebooks->index(index.row(), 0, parent); - openNotebook(_notebooks->data(parent, Qt::DisplayRole).toString(), - _notebooks->data(nb, Qt::DisplayRole).toString()); + openNotebook(_notebooks->data(parent, NotebookModel::FileNameRole).toString(), + _notebooks->data(nb, NotebookModel::FileNameRole).toString()); } void MainWindow::handleNotebookRowsInserted(const QModelIndex &index, int start, int end) diff --git a/mainwindow.ui b/mainwindow.ui index 5c1774c..a56ffba 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -129,7 +129,7 @@ ... - + .. @@ -200,53 +200,36 @@ - - + + 0 - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOn - - - - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - false - - - false - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAsNeeded + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + false + + + @@ -340,12 +323,15 @@ - + .. &Export... + + Export + @@ -388,12 +374,12 @@ handleNotebookSelected(QModelIndex) - 159 - 193 + 131 + 204 - 358 - 192 + 356 + 218 @@ -414,78 +400,46 @@ - zoomSlider - valueChanged(int) - notebookView - setZoom(int) - - - 671 - 42 - - - 479 - 272 - - - - - notebookView - curPageChanged() - MainWindow - handleCurPageChanged() - - - 479 - 272 - - - 358 - 192 - - - - - prevButton + playButton clicked() - notebookView - prevPage() + MainWindow + handlePaperReplayPlay() - 273 - 57 + 357 + 356 - 479 - 272 + 332 + 267 - nextButton + pauseButton clicked() - notebookView - nextPage() + MainWindow + handlePaperReplayPause() - 365 - 57 + 391 + 356 - 479 - 272 + 373 + 294 - notebookView - paperReplayRequested(QString,qint64) + actionQuit + triggered() MainWindow - handlePaperReplayRequested(QString,qint64) + deleteLater() - 479 - 255 + -1 + -1 358 @@ -494,14 +448,14 @@ - playButton - clicked() + actionExport + triggered() MainWindow - handlePaperReplayPlay() + handleExport() - 273 - 358 + -1 + -1 358 @@ -510,14 +464,14 @@ - pauseButton - clicked() + actionAbout + triggered() MainWindow - handlePaperReplayPause() + handleAbout() - 309 - 358 + -1 + -1 358 @@ -526,98 +480,98 @@ - paperReplayView - activated(QModelIndex) - MainWindow - handlePaperReplaySelected(QModelIndex) + zoomSlider + valueChanged(int) + notebookView + setZoom(int) - 597 - 193 + 663 + 46 - 358 - 192 + 550 + 132 - paperReplayView - doubleClicked(QModelIndex) - MainWindow - handlePaperReplaySelected(QModelIndex) + prevButton + clicked() + notebookView + prevPage() - 597 - 193 + 347 + 46 - 358 - 192 + 441 + 141 - exportButton + nextButton clicked() - MainWindow - handleExport() + notebookView + nextPage() - 402 - 42 + 436 + 38 - 358 - 192 + 473 + 87 - actionQuit - triggered() + notebookView + curPageChanged() MainWindow - deleteLater() + handleCurPageChanged() - -1 - -1 + 368 + 161 - 358 - 192 + 486 + 27 - actionExport - triggered() + notebookView + paperReplayRequested(QString,qint64) MainWindow - handleExport() + handlePaperReplayRequested(QString,qint64) - -1 - -1 + 349 + 86 - 358 - 192 + 387 + 165 - actionAbout - triggered() + paperReplayView + activated(QModelIndex) MainWindow - handleAbout() + handlePaperReplaySelected(QModelIndex) - -1 - -1 + 367 + 117 - 358 - 192 + 778 + 310 @@ -628,12 +582,28 @@ setValue(int) - 361 - 193 + 576 + 116 + + + 613 + 62 + + + + + exportButton + clicked() + MainWindow + handleExport() + + + 457 + 46 - 671 - 42 + 358 + 192 diff --git a/notebookmodel.cc b/notebookmodel.cc index bfe183b..3898df7 100644 --- a/notebookmodel.cc +++ b/notebookmodel.cc @@ -29,6 +29,9 @@ #define NUM_COLUMNS 3 #define PEN_INDEX_ID 0xFFFFFFFFU +#define PEN_EXTENSION "pen" +#define ARCHIVE_EXTENSION "archive" + NotebookModel::NotebookModel(QObject *parent) : QAbstractItemModel(parent), _dataDir(userDataDirectory()), @@ -66,12 +69,12 @@ QString NotebookModel::userDataDirectory() QString NotebookModel::penDirectory(const QString &name) const { - return _dataDir.filePath(name + ".pen"); + return _dataDir.filePath(name); } QString NotebookModel::notebookDirectory(const QString &penName, const QString &nbName) const { - return _dataDir.filePath(penName + ".pen" + "/" + nbName + ".afd"); + return _dataDir.filePath(penName + "/" + nbName); } QString NotebookModel::notebookDirectory(const QModelIndex &index) const @@ -89,7 +92,7 @@ QString NotebookModel::notebookDirectory(const QModelIndex &index) const QString NotebookModel::paperReplayDirectory(const QString &name) const { - return _dataDir.filePath(name + ".pen" + "/"+ PAPER_REPLAY); + return _dataDir.filePath(name + "/" + PAPER_REPLAY); } QVariant NotebookModel::data(const QModelIndex &index, int role) const @@ -99,22 +102,28 @@ QVariant NotebookModel::data(const QModelIndex &index, int role) const if (id == PEN_INDEX_ID) { int penIndex = index.row(); if (penIndex < 0 || penIndex >= _pens.size()) return QVariant(); + const QString &penName = _pens[penIndex]; switch (role) { case Qt::DisplayRole: switch (index.column()) { case 0: - return _pens[penIndex]; + return penDisplayName(penName); } break; case Qt::DecorationRole: switch (index.column()) { + case 0: + return penIcon(penName); case 2: - if (isPenLocked(_pens[penIndex])) { + if (isPenLocked(penName)) { return QApplication::style()->standardIcon(QStyle::SP_BrowserReload); } break; } break; + case FileNameRole: + return penName; + break; } } else { const QString &penName = _pens[id]; @@ -124,7 +133,7 @@ QVariant NotebookModel::data(const QModelIndex &index, int role) const case Qt::DisplayRole: switch (index.column()) { case 0: - return notebookName; + return notebookDisplayName(penName, notebookName); case 1: if (notebookName != PAPER_REPLAY) { return estimatePagesOfNotebook(penName, notebookName); @@ -135,18 +144,12 @@ QVariant NotebookModel::data(const QModelIndex &index, int role) const case Qt::DecorationRole: switch (index.column()) { case 0: - return getNotebookIcon(penName, notebookName); + return notebookIcon(penName, notebookName); case 1: return QVariant(); case 2: - if (notebookName != PAPER_REPLAY) { - if (isNotebookLocked(penName, notebookName)) { - return QApplication::style()->standardIcon(QStyle::SP_BrowserReload); - } - } else { - if (isPaperReplayLocked(penName)) { - return QApplication::style()->standardIcon(QStyle::SP_BrowserReload); - } + if (isNotebookLocked(penName, notebookName)) { + return QApplication::style()->standardIcon(QStyle::SP_BrowserReload); } break; } @@ -160,6 +163,8 @@ QVariant NotebookModel::data(const QModelIndex &index, int role) const return Qt::AlignCenter; } break; + case FileNameRole: + return notebookName; } } return QVariant(); @@ -239,10 +244,7 @@ int NotebookModel::columnCount(const QModelIndex &parent) const void NotebookModel::refresh() { - QStringList pens = _dataDir.entryList(QStringList("*.pen"), QDir::Dirs, QDir::Name); - for (int i = 0; i < pens.size(); i++) { - pens[i].chop(4); // Remove .pen extension - } + QStringList pens = _dataDir.entryList(QStringList{"*." PEN_EXTENSION, "*." ARCHIVE_EXTENSION}, QDir::Dirs, QDir::Name); // Insert/remove new/deleted pens int i = 0, j = 0; @@ -295,10 +297,7 @@ void NotebookModel::refreshPen(const QString &name) _watcher.addPath(penDir.canonicalPath()); QStringList &curNotebooks = _notebooks[name]; - QStringList diskNotebooks = penDir.entryList(QStringList("*.afd"), QDir::Dirs, QDir::Name); - for (int i = 0; i < diskNotebooks.size(); i++) { - diskNotebooks[i].chop(4); - } + QStringList diskNotebooks = penDir.entryList(QStringList("*." AFD_NOTEBOOK_EXTENSION), QDir::Dirs, QDir::Name); if (penDir.exists(PAPER_REPLAY)) diskNotebooks.append(PAPER_REPLAY); QModelIndex penIndex = index(indexOfPen(name), 0, QModelIndex()); @@ -358,8 +357,44 @@ QDir NotebookModel::notebookDir(const QString &pen, const QString ¬ebook) con return QDir(notebookDirectory(pen, notebook)); } -QIcon NotebookModel::getNotebookIcon(const QString &pen, const QString ¬ebook) const +QString NotebookModel::penDisplayName(const QString &pen) const +{ + if (pen.endsWith("." PEN_EXTENSION, Qt::CaseInsensitive)) { + return pen.chopped(strlen("." PEN_EXTENSION)); + } else if (pen.endsWith("." ARCHIVE_EXTENSION, Qt::CaseInsensitive)) { + return pen.chopped(strlen("." ARCHIVE_EXTENSION)); + } else { + return pen; + } +} + +QString NotebookModel::notebookDisplayName(const QString &pen, const QString ¬ebook) const +{ + Q_UNUSED(pen); + if (notebook.endsWith("." AFD_NOTEBOOK_EXTENSION, Qt::CaseInsensitive)) { + return notebook.chopped(strlen("." AFD_NOTEBOOK_EXTENSION)); + } else if (notebook == PAPER_REPLAY) { + return tr("Voice recordings"); + } else { + return notebook; + } +} + +QIcon NotebookModel::penIcon(const QString &pen) const +{ + if (isPenArchive(pen)) { + return QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon); + } else { + return QIcon::fromTheme("scribiu"); + } +} + +QIcon NotebookModel::notebookIcon(const QString &pen, const QString ¬ebook) const { + if (notebook == PAPER_REPLAY) { + return QApplication::style()->standardIcon(QStyle::SP_MediaVolume); + } + QDir dir = notebookDir(pen, notebook); QIcon icon = _iconCache.value(dir.path()); @@ -380,6 +415,11 @@ QIcon NotebookModel::getNotebookIcon(const QString &pen, const QString ¬ebook return icon; } +bool NotebookModel::isPenArchive(const QString &pen) const +{ + return pen.endsWith("." ARCHIVE_EXTENSION); +} + bool NotebookModel::isPenLocked(const QString &pen) const { QDir dir = penDir(pen); @@ -402,12 +442,7 @@ bool NotebookModel::isNotebookLocked(const QString &pen, const QString ¬ebook bool NotebookModel::isPaperReplayLocked(const QString &pen) const { - QDir dir(paperReplayDirectory(pen)); - if (dir.exists(".sync.lck")) { - return true; - } else { - return false; - } + return isNotebookLocked(pen, PAPER_REPLAY); } int NotebookModel::estimatePagesOfNotebook(const QString &pen, const QString ¬ebook) const diff --git a/notebookmodel.h b/notebookmodel.h index f847c77..51148e5 100644 --- a/notebookmodel.h +++ b/notebookmodel.h @@ -24,6 +24,10 @@ #include #include +#define PEN_EXTENSION "pen" +#define ARCHIVE_EXTENSION "archive" +#define AFD_NOTEBOOK_EXTENSION "afd" + class NotebookModel : public QAbstractItemModel { Q_OBJECT @@ -31,6 +35,10 @@ class NotebookModel : public QAbstractItemModel public: explicit NotebookModel(QObject *parent = 0); + enum Roles { + FileNameRole = Qt::UserRole + }; + static QString defaultDataDirectory(); static QString userDataDirectory(); @@ -58,7 +66,11 @@ private: int indexOfPen(const QString &name); QDir penDir(const QString &pen) const; QDir notebookDir(const QString &pen, const QString ¬ebook) const; - QIcon getNotebookIcon(const QString &pen, const QString ¬ebook) const; + QString penDisplayName(const QString &pen) const; + QString notebookDisplayName(const QString &pen, const QString ¬ebook) const; + QIcon penIcon(const QString &pen) const; + QIcon notebookIcon(const QString &pen, const QString ¬ebook) const; + bool isPenArchive(const QString &pen) const; bool isPenLocked(const QString &pen) const; bool isNotebookLocked(const QString &pen, const QString ¬ebook) const; bool isPaperReplayLocked(const QString &pen) const; diff --git a/paperreplay.h b/paperreplay.h index 328939c..9e61af7 100644 --- a/paperreplay.h +++ b/paperreplay.h @@ -24,6 +24,7 @@ #include #include +/** Name of the paper replay notebook */ #define PAPER_REPLAY "Paper Replay" class PaperReplay : public QObject diff --git a/smartpensyncer.cc b/smartpensyncer.cc index 8047f4e..acc32ac 100644 --- a/smartpensyncer.cc +++ b/smartpensyncer.cc @@ -262,7 +262,7 @@ bool SmartpenSyncer::syncPen() bool SmartpenSyncer::syncNotebook(Smartpen::PenTime lastSync, const Smartpen::ChangeReport &change) { - QDir notebookDir(_penDataDir.filePath(change.title + ".afd")); + QDir notebookDir(_penDataDir.filePath(change.title + "." AFD_NOTEBOOK_EXTENSION)); if (!notebookDir.exists()) { if (!notebookDir.mkpath(".")) { qWarning() << "Cannot create notebook data directory:" << notebookDir.absolutePath(); -- cgit v1.2.3