#include "bookmarksdialog.h"
#include "settings.h"
+#ifdef DORIAN_TEST_MODEL
+#include "modeltest.h"
+#endif
+
#ifdef Q_WS_MAC
# define ICON_PREFIX ":/icons/mac/"
#else
const int WIN_BIG_TIMER = 3000;
MainWindow::MainWindow(QWidget *parent):
- QMainWindow(parent), view(0), book(0), isFullscreen(false)
+ QMainWindow(parent), view(0), isFullscreen(false)
{
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow, true);
"view-fullscreen");
// Handle model changes
- connect(Library::instance(), SIGNAL(currentBookChanged()),
+ connect(Library::instance(), SIGNAL(nowReadingChanged()),
this, SLOT(onCurrentBookChanged()));
normalFlags = windowFlags();
if (QCoreApplication::arguments().size() == 2) {
QString path = QCoreApplication::arguments()[1];
library->add(path);
- int index = library->find(path);
- if (index != -1) {
- library->setCurrent(index);
+ QModelIndex index = library->find(path);
+ if (index.isValid()) {
+ library->setNowReading(index);
}
}
else {
- Book *current = library->current();
- if (current) {
- setCurrentBook(current);
+ QModelIndex index = library->nowReading();
+ if (index.isValid()) {
+ library->setNowReading(index);
}
else {
- if (!library->size()) {
+ if (!library->rowCount()) {
library->add(":/books/2 B R 0 2 B.epub");
}
- library->setCurrent(0);
+ library->setNowReading(library->index(0));
}
}
// Handle loading chapters
connect(view, SIGNAL(chapterLoaded(int)), this, SLOT(onChapterLoaded(int)));
+
+#ifdef DORIAN_TEST_MODEL
+ (void)new ModelTest(Library::instance(), this);
+#endif
}
void MainWindow::onCurrentBookChanged()
{
- setCurrentBook(Library::instance()->current());
+ setCurrentBook(Library::instance()->nowReading());
}
void MainWindow::showNormal()
restoreButton->flash();
}
-void MainWindow::setCurrentBook(Book *current)
+void MainWindow::setCurrentBook(const QModelIndex ¤t)
{
- book = current;
- view->setBook(current);
- setWindowTitle(current? current->title: "Dorian");
+ mCurrent = current;
+ if (current.isValid()) {
+ Book *book = Library::instance()->book(current);
+ view->setBook(book);
+ setWindowTitle(book->name());
+ } else {
+ view->setBook(0);
+ setWindowTitle("Dorian");
+ }
}
-QAction *MainWindow::addToolBarAction(const QObject *receiver, const char *member,
+QAction *MainWindow::addToolBarAction(const QObject *receiver,
+ const char *member,
const QString &name)
{
return toolBar->
void MainWindow::showInfo()
{
- if (book) {
- InfoDialog *info = new InfoDialog(book, this);
+ if (mCurrent.isValid()) {
+ InfoDialog *info =
+ new InfoDialog(Library::instance()->book(mCurrent), this);
info->exec();
}
}
void MainWindow::showBookmarks()
{
+ Book *book = Library::instance()->book(mCurrent);
if (book) {
BookmarksDialog *bookmarks = new BookmarksDialog(book, this);
int ret = bookmarks->exec();
{
bool enablePrevious = false;
bool enableNext = false;
+ Book *book = Library::instance()->book(mCurrent);
if (book) {
if (index > 0) {
enablePrevious = true;