#include "trace.h"
#include "bookfinder.h"
#include "progress.h"
+#include "dyalog.h"
#ifdef DORIAN_TEST_MODEL
#include "modeltest.h"
#endif
const int PROGRESS_HEIGHT = 17;
+const char *DORIAN_VERSION =
+#include "pkg/version.txt"
+;
MainWindow::MainWindow(QWidget *parent):
- QMainWindow(parent), view(0), preventBlankingTimer(-1)
+ BookWindow(parent), view(0), preventBlankingTimer(-1)
{
Trace t("MainWindow::MainWindow");
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow, true);
- grabZoomKeys();
#endif
setWindowTitle("Dorian");
connect(settingsAction, SIGNAL(triggered()), this, SLOT(showSettings()));
devToolsAction = menuBar()->addAction(tr("Developer"));
connect(devToolsAction, SIGNAL(triggered()), this, SLOT(showDevTools()));
+ QAction *aboutAction = menuBar()->addAction(tr("About"));
+ connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
#else
infoAction = addToolBarAction(this, SLOT(showInfo()), "document-properties");
libraryAction = addToolBarAction(this, SLOT(showLibrary()),
settingsAction = addToolBarAction(this, SLOT(showSettings()),
"preferences-system");
devToolsAction = addToolBarAction(this, SLOT(showDevTools()), "developer");
+ addToolBarAction(this, SLOT(about()), "about");
#endif // Q_WS_MAEMO_5
QFrame *frame = new QFrame(toolBar);
}
}
- // Handle settings changes
- Settings *settings = Settings::instance();
- connect(settings, SIGNAL(valueChanged(const QString &)),
- this, SLOT(onSettingsChanged(const QString &)));
- settings->setValue("orientation", settings->value("orientation"));
- settings->setValue("lightson", settings->value("lightson"));
-
- // Handle loading chapters
- connect(view, SIGNAL(chapterLoadStart(int)),
- this, SLOT(onChapterLoadStart()));
- connect(view, SIGNAL(chapterLoadEnd(int)),
- this, SLOT(onChapterLoadEnd(int)));
+ // Handle loading book parts
+ connect(view, SIGNAL(partLoadStart(int)), this, SLOT(onPartLoadStart()));
+ connect(view, SIGNAL(partLoadEnd(int)), this, SLOT(onPartLoadEnd(int)));
// Handle progress
connect(view, SIGNAL(progress(qreal)), progress, SLOT(setProgress(qreal)));
fullScreenWindow = new FullScreenWindow(this);
connect(fullScreenWindow, SIGNAL(restore()), this, SLOT(showRegular()));
- // Create thread for finding books in directories
- bookFinder = new BookFinder();
- connect(bookFinder, SIGNAL(add(const QString &)),
- library, SLOT(add(const QString &)));
- connect(bookFinder, SIGNAL(remove(const QString &)),
- library, SLOT(remove(const QString &)));
- bookFinder->moveToThread(&bookFinderThread);
- bookFinderThread.start();
+ // Handle settings changes
+ Settings *settings = Settings::instance();
+ connect(settings, SIGNAL(valueChanged(const QString &)),
+ this, SLOT(onSettingsChanged(const QString &)));
+ settings->setValue("orientation", settings->value("orientation"));
+ settings->setValue("lightson", settings->value("lightson"));
+ settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
#ifdef DORIAN_TEST_MODEL
(void)new ModelTest(Library::instance(), this);
MainWindow::~MainWindow()
{
- bookFinderThread.quit();
- bookFinderThread.wait();
- delete bookFinder;
}
void MainWindow::onCurrentBookChanged()
{
Trace t("MainWindow::showRegular");
fullScreenWindow->hide();
- fullScreenWindow->leaveChild();
- view->setParent(centralWidget());
- progress->setParent(centralWidget());
+ fullScreenWindow->leaveChildren();
progress->setGeometry(0, 0, geometry().width(), PROGRESS_HEIGHT);
- centralWidget()->layout()->addWidget(view);
+ QList<QWidget *> otherChildren;
+ otherChildren.append(progress);
+ takeChildren(view, otherChildren);
progress->flash();
}
void MainWindow::showBig()
{
Trace t("MainWindow::showBig");
- centralWidget()->layout()->removeWidget(view);
- progress->setParent(fullScreenWindow);
+ leaveChildren();
+ QList<QWidget *> otherChildren;
+ otherChildren.append(progress);
progress->setGeometry(0, 0, QApplication::desktop()->screenGeometry().width(),
PROGRESS_HEIGHT);
- fullScreenWindow->takeChild(view);
+ fullScreenWindow->takeChildren(view, otherChildren);
fullScreenWindow->showFullScreen();
progress->flash();
}
#ifdef Q_WS_MAEMO_5
if (key == "orientation") {
QString value = Settings::instance()->value(key).toString();
- Trace::trace(QString("MainWindow::onSettingsChanged: orientation %1").
- arg(value));
+ qDebug() << "MainWindow::onSettingsChanged: orientation" << value;
if (value == "portrait") {
setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
}
} else if (key == "lightson") {
bool enable = Settings::instance()->value(key, false).toBool();
- Trace::trace(QString("MainWindow::onSettingsChanged: lightson: %1").
- arg(enable));
+ qDebug() << "MainWindow::onSettingsChanged: lightson:" << enable;
killTimer(preventBlankingTimer);
if (enable) {
preventBlankingTimer = startTimer(29 * 1000);
}
+ } else if (key == "usevolumekeys") {
+ bool value = Settings::instance()->value(key).toBool();
+ qDebug() << "MainWindow::onSettingsChanged: usevolumekeys" << value;
+ grabZoomKeys(value);
+ fullScreenWindow->grabZoomKeys(value);
}
#else
Q_UNUSED(key);
MCE_REQUEST_IF, QDBusConnection::systemBus());
mce.call(MCE_PREVENT_BLANK_REQ);
#endif // Q_WS_MAEMO_5
- Trace::trace("MainWindow::timerEvent: Prevent display blanking");
+ qDebug() << "MainWindow::timerEvent: Prevent display blanking";
}
}
QMainWindow::resizeEvent(e);
}
-void MainWindow::grabZoomKeys()
+void MainWindow::about()
{
-#ifdef Q_WS_MAEMO_5
- if (!winId()) {
- qCritical() << "Can't grab keys unless we have a window id";
- return;
- }
- unsigned long val = 1;
- Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
- if (!atom) {
- qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
- return;
- }
- XChangeProperty(QX11Info::display(),
- winId(),
- atom,
- XA_INTEGER,
- 32,
- PropModeReplace,
- reinterpret_cast<unsigned char *>(&val),
- 1);
-#endif // Q_WS_MAEMO_5
+ Dyalog *aboutDialog = new Dyalog(this);
+ aboutDialog->setWindowTitle(tr("About Dorian"));
+ QLabel *label = new QLabel(aboutDialog);
+ label->setTextFormat(Qt::RichText);
+ label->setOpenExternalLinks(true);
+ label->setText(tr("<b>Dorian %1</b><br><br>Copyright © 2010 by "
+ "Akos Polster <akos@pipacs.com><br>"
+ "Licensed under GNU General Public License, Version 3<br>"
+ "Source code: <a href='https://garage.maemo.org/projects/dorian/'>"
+ "garage.maemo.org/projects/dorian</a>").arg(DORIAN_VERSION));
+ aboutDialog->addWidget(label);
+ aboutDialog->show();
}