#include "infodialog.h"
#include "settings.h"
-LibraryDialog::LibraryDialog(QWidget *parent):
- QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
- Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint)
+LibraryDialog::LibraryDialog(QWidget *parent): QMainWindow(parent)
{
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5StackedWindow, true);
+#endif
setWindowTitle(tr("Library"));
+
+ QFrame *frame = new QFrame(this);
+ setCentralWidget(frame);
+ QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
+ frame->setLayout(horizontalLayout);
+
list = new QListView(this);
sortedLibrary = new SortedLibrary(this);
list->setModel(sortedLibrary);
list->setSelectionMode(QAbstractItemView::SingleSelection);
list->setUniformItemSizes(true);
-#ifndef Q_WS_MAEMO_5
- setSizeGripEnabled(true);
-#endif
Library *library = Library::instance();
QModelIndex current = library->nowReading();
setSelected(current);
-
- QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
horizontalLayout->addWidget(list);
- QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
#ifndef Q_WS_MAEMO_5
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
detailsButton = new QPushButton(tr("Details"), this);
readButton = new QPushButton(tr("Read"), this);
removeButton = new QPushButton(tr("Delete"), this);
-#endif // Q_WS_MAEMO_5
addButton = new QPushButton(tr("Add"), this);
-#ifndef Q_WS_MAEMO_5
buttonBox->addButton(detailsButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(readButton, QDialogButtonBox::AcceptRole);
buttonBox->addButton(removeButton, QDialogButtonBox::ActionRole);
-#endif // Q_WS_MAEMO_5
buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
-
horizontalLayout->addWidget(buttonBox);
+#else
+ QAction *addBookAction = menuBar()->addAction(tr("Add book"));
+#endif // Q_WS_MAEMO_5
connect(Library::instance(), SIGNAL(nowReadingChanged()),
this, SLOT(onCurrentBookChanged()));
SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this,
SLOT(onBookAdded()));
- connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
connect(list, SIGNAL(activated(const QModelIndex &)),
this, SLOT(onItemActivated(const QModelIndex &)));
#ifndef Q_WS_MAEMO_5
connect(list, SIGNAL(itemSelectionChanged()),
this, SLOT(onItemSelectionChanged()));
+ connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
connect(detailsButton, SIGNAL(clicked()), this, SLOT(onDetails()));
connect(readButton, SIGNAL(clicked()), this, SLOT(onRead()));
connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemove()));
const QItemSelection &)),
this, SLOT(onItemSelectionChanged()));
onItemSelectionChanged();
+#else
+ connect(addBookAction, SIGNAL(triggered()), this, SLOT(onAdd()));
#endif // !Q_WS_MAEMO_5
}
void LibraryDialog::onRemove()
{
- qDebug() << "LibraryDialog::onRemove";
QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
if (current.isValid()) {
Book *currentBook = Library::instance()->book(current);
if (QMessageBox::Yes ==
QMessageBox::question(this, "Delete book",
"Delete book \"" + title + "\"?",
- QMessageBox::Yes, QMessageBox::No)) {
+ QMessageBox::Yes | QMessageBox::No)) {
Library::instance()->remove(current);
}
}
void LibraryDialog::onItemSelectionChanged()
{
bool enable = selected().isValid();
- qDebug() << "LibraryDialog::onItemSelectionChanged" << enable;
readButton->setEnabled(enable);
- qDebug() << " readButton";
detailsButton->setEnabled(enable);
- qDebug() << " detailsButton";
removeButton->setEnabled(enable);
- qDebug() << " removeButton";
}
#endif // Q_WS_MAEMO_5
}
return QModelIndex();
}
+
+void LibraryDialog::closeEvent(QCloseEvent *event)
+{
+#ifdef Q_WS_MAEMO_5
+ menuBar()->clear();
+#endif
+ event->accept();
+}
Settings::instance()->value("orientation"));
// Handle loading chapters
- connect(view, SIGNAL(chapterLoaded(int)), this, SLOT(onChapterLoaded(int)));
+ connect(view, SIGNAL(chapterLoadStart(int)),
+ this, SLOT(onChapterLoadStart()));
+ connect(view, SIGNAL(chapterLoadEnd(int)),
+ this, SLOT(onChapterLoadEnd(int)));
#ifdef DORIAN_TEST_MODEL
(void)new ModelTest(Library::instance(), this);
void MainWindow::showLibrary()
{
- LibraryDialog *dialog = new LibraryDialog();
- dialog->exec();
+ LibraryDialog *dialog = new LibraryDialog(this);
+ dialog->show();
}
void MainWindow::showSettings()
#endif // Q_WS_MAEMO_5
}
-void MainWindow::onChapterLoaded(int index)
+void MainWindow::onChapterLoadStart()
+{
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+#endif
+}
+
+void MainWindow::onChapterLoadEnd(int index)
{
bool enablePrevious = false;
bool enableNext = false;
}
}
#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
previousAction->setIcon(QIcon(enablePrevious?
":/icons/previous.png" : ":/icons/previous-disabled.png"));
nextAction->setIcon(QIcon(enableNext?