diff options
-rw-r--r-- | mainwindow.cc | 13 | ||||
-rw-r--r-- | mainwindow.ui | 290 | ||||
-rw-r--r-- | notebookmodel.cc | 95 | ||||
-rw-r--r-- | notebookmodel.h | 14 | ||||
-rw-r--r-- | paperreplay.h | 1 | ||||
-rw-r--r-- | 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 @@ <string>...</string> </property> <property name="icon"> - <iconset theme="document-save-as"> + <iconset theme="document-send"> <normaloff>.</normaloff>.</iconset> </property> </widget> @@ -200,53 +200,36 @@ </layout> </item> <item> - <layout class="QHBoxLayout" name="pane2Mid"> - <property name="spacing"> + <widget class="QStackedWidget" name="pane2Stack"> + <property name="currentIndex"> <number>0</number> </property> - <item> - <widget class="NotebookView" name="notebookView"> - <property name="verticalScrollBarPolicy"> - <enum>Qt::ScrollBarAlwaysOn</enum> - </property> - <property name="horizontalScrollBarPolicy"> - <enum>Qt::ScrollBarAlwaysOn</enum> - </property> - </widget> - </item> - <item> - <widget class="QTableView" name="paperReplayView"> - <property name="selectionMode"> - <enum>QAbstractItemView::SingleSelection</enum> - </property> - <property name="selectionBehavior"> - <enum>QAbstractItemView::SelectRows</enum> - </property> - <property name="showGrid"> - <bool>false</bool> - </property> - <attribute name="horizontalHeaderHighlightSections"> - <bool>false</bool> - </attribute> - <attribute name="verticalHeaderVisible"> - <bool>false</bool> - </attribute> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - </layout> + <widget class="NotebookView" name="notebookView"> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOn</enum> + </property> + <property name="horizontalScrollBarPolicy"> + <enum>Qt::ScrollBarAsNeeded</enum> + </property> + </widget> + <widget class="QTableView" name="paperReplayView"> + <property name="selectionMode"> + <enum>QAbstractItemView::SingleSelection</enum> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> + <property name="showGrid"> + <bool>false</bool> + </property> + <attribute name="horizontalHeaderHighlightSections"> + <bool>false</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + </widget> + </widget> </item> <item> <layout class="QHBoxLayout" name="paperReplayTools"> @@ -340,12 +323,15 @@ </action> <action name="actionExport"> <property name="icon"> - <iconset theme="document-save-as"> + <iconset theme="document-send"> <normaloff>.</normaloff>.</iconset> </property> <property name="text"> <string>&Export...</string> </property> + <property name="toolTip"> + <string>Export</string> + </property> </action> <action name="actionAbout"> <property name="icon"> @@ -388,12 +374,12 @@ <slot>handleNotebookSelected(QModelIndex)</slot> <hints> <hint type="sourcelabel"> - <x>159</x> - <y>193</y> + <x>131</x> + <y>204</y> </hint> <hint type="destinationlabel"> - <x>358</x> - <y>192</y> + <x>356</x> + <y>218</y> </hint> </hints> </connection> @@ -414,78 +400,46 @@ </hints> </connection> <connection> - <sender>zoomSlider</sender> - <signal>valueChanged(int)</signal> - <receiver>notebookView</receiver> - <slot>setZoom(int)</slot> - <hints> - <hint type="sourcelabel"> - <x>671</x> - <y>42</y> - </hint> - <hint type="destinationlabel"> - <x>479</x> - <y>272</y> - </hint> - </hints> - </connection> - <connection> - <sender>notebookView</sender> - <signal>curPageChanged()</signal> - <receiver>MainWindow</receiver> - <slot>handleCurPageChanged()</slot> - <hints> - <hint type="sourcelabel"> - <x>479</x> - <y>272</y> - </hint> - <hint type="destinationlabel"> - <x>358</x> - <y>192</y> - </hint> - </hints> - </connection> - <connection> - <sender>prevButton</sender> + <sender>playButton</sender> <signal>clicked()</signal> - <receiver>notebookView</receiver> - <slot>prevPage()</slot> + <receiver>MainWindow</receiver> + <slot>handlePaperReplayPlay()</slot> <hints> <hint type="sourcelabel"> - <x>273</x> - <y>57</y> + <x>357</x> + <y>356</y> </hint> <hint type="destinationlabel"> - <x>479</x> - <y>272</y> + <x>332</x> + <y>267</y> </hint> </hints> </connection> <connection> - <sender>nextButton</sender> + <sender>pauseButton</sender> <signal>clicked()</signal> - <receiver>notebookView</receiver> - <slot>nextPage()</slot> + <receiver>MainWindow</receiver> + <slot>handlePaperReplayPause()</slot> <hints> <hint type="sourcelabel"> - <x>365</x> - <y>57</y> + <x>391</x> + <y>356</y> </hint> <hint type="destinationlabel"> - <x>479</x> - <y>272</y> + <x>373</x> + <y>294</y> </hint> </hints> </connection> <connection> - <sender>notebookView</sender> - <signal>paperReplayRequested(QString,qint64)</signal> + <sender>actionQuit</sender> + <signal>triggered()</signal> <receiver>MainWindow</receiver> - <slot>handlePaperReplayRequested(QString,qint64)</slot> + <slot>deleteLater()</slot> <hints> <hint type="sourcelabel"> - <x>479</x> - <y>255</y> + <x>-1</x> + <y>-1</y> </hint> <hint type="destinationlabel"> <x>358</x> @@ -494,14 +448,14 @@ </hints> </connection> <connection> - <sender>playButton</sender> - <signal>clicked()</signal> + <sender>actionExport</sender> + <signal>triggered()</signal> <receiver>MainWindow</receiver> - <slot>handlePaperReplayPlay()</slot> + <slot>handleExport()</slot> <hints> <hint type="sourcelabel"> - <x>273</x> - <y>358</y> + <x>-1</x> + <y>-1</y> </hint> <hint type="destinationlabel"> <x>358</x> @@ -510,14 +464,14 @@ </hints> </connection> <connection> - <sender>pauseButton</sender> - <signal>clicked()</signal> + <sender>actionAbout</sender> + <signal>triggered()</signal> <receiver>MainWindow</receiver> - <slot>handlePaperReplayPause()</slot> + <slot>handleAbout()</slot> <hints> <hint type="sourcelabel"> - <x>309</x> - <y>358</y> + <x>-1</x> + <y>-1</y> </hint> <hint type="destinationlabel"> <x>358</x> @@ -526,98 +480,98 @@ </hints> </connection> <connection> - <sender>paperReplayView</sender> - <signal>activated(QModelIndex)</signal> - <receiver>MainWindow</receiver> - <slot>handlePaperReplaySelected(QModelIndex)</slot> + <sender>zoomSlider</sender> + <signal>valueChanged(int)</signal> + <receiver>notebookView</receiver> + <slot>setZoom(int)</slot> <hints> <hint type="sourcelabel"> - <x>597</x> - <y>193</y> + <x>663</x> + <y>46</y> </hint> <hint type="destinationlabel"> - <x>358</x> - <y>192</y> + <x>550</x> + <y>132</y> </hint> </hints> </connection> <connection> - <sender>paperReplayView</sender> - <signal>doubleClicked(QModelIndex)</signal> - <receiver>MainWindow</receiver> - <slot>handlePaperReplaySelected(QModelIndex)</slot> + <sender>prevButton</sender> + <signal>clicked()</signal> + <receiver>notebookView</receiver> + <slot>prevPage()</slot> <hints> <hint type="sourcelabel"> - <x>597</x> - <y>193</y> + <x>347</x> + <y>46</y> </hint> <hint type="destinationlabel"> - <x>358</x> - <y>192</y> + <x>441</x> + <y>141</y> </hint> </hints> </connection> <connection> - <sender>exportButton</sender> + <sender>nextButton</sender> <signal>clicked()</signal> - <receiver>MainWindow</receiver> - <slot>handleExport()</slot> + <receiver>notebookView</receiver> + <slot>nextPage()</slot> <hints> <hint type="sourcelabel"> - <x>402</x> - <y>42</y> + <x>436</x> + <y>38</y> </hint> <hint type="destinationlabel"> - <x>358</x> - <y>192</y> + <x>473</x> + <y>87</y> </hint> </hints> </connection> <connection> - <sender>actionQuit</sender> - <signal>triggered()</signal> + <sender>notebookView</sender> + <signal>curPageChanged()</signal> <receiver>MainWindow</receiver> - <slot>deleteLater()</slot> + <slot>handleCurPageChanged()</slot> <hints> <hint type="sourcelabel"> - <x>-1</x> - <y>-1</y> + <x>368</x> + <y>161</y> </hint> <hint type="destinationlabel"> - <x>358</x> - <y>192</y> + <x>486</x> + <y>27</y> </hint> </hints> </connection> <connection> - <sender>actionExport</sender> - <signal>triggered()</signal> + <sender>notebookView</sender> + <signal>paperReplayRequested(QString,qint64)</signal> <receiver>MainWindow</receiver> - <slot>handleExport()</slot> + <slot>handlePaperReplayRequested(QString,qint64)</slot> <hints> <hint type="sourcelabel"> - <x>-1</x> - <y>-1</y> + <x>349</x> + <y>86</y> </hint> <hint type="destinationlabel"> - <x>358</x> - <y>192</y> + <x>387</x> + <y>165</y> </hint> </hints> </connection> <connection> - <sender>actionAbout</sender> - <signal>triggered()</signal> + <sender>paperReplayView</sender> + <signal>activated(QModelIndex)</signal> <receiver>MainWindow</receiver> - <slot>handleAbout()</slot> + <slot>handlePaperReplaySelected(QModelIndex)</slot> <hints> <hint type="sourcelabel"> - <x>-1</x> - <y>-1</y> + <x>367</x> + <y>117</y> </hint> <hint type="destinationlabel"> - <x>358</x> - <y>192</y> + <x>778</x> + <y>310</y> </hint> </hints> </connection> @@ -628,12 +582,28 @@ <slot>setValue(int)</slot> <hints> <hint type="sourcelabel"> - <x>361</x> - <y>193</y> + <x>576</x> + <y>116</y> + </hint> + <hint type="destinationlabel"> + <x>613</x> + <y>62</y> + </hint> + </hints> + </connection> + <connection> + <sender>exportButton</sender> + <signal>clicked()</signal> + <receiver>MainWindow</receiver> + <slot>handleExport()</slot> + <hints> + <hint type="sourcelabel"> + <x>457</x> + <y>46</y> </hint> <hint type="destinationlabel"> - <x>671</x> - <y>42</y> + <x>358</x> + <y>192</y> </hint> </hints> </connection> 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 <QtCore/QFileSystemWatcher> #include <QtGui/QIcon> +#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 <QtCore/QMap> #include <QtCore/QVector> +/** 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(); |