X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=infodialog.cpp;h=904eb79f9f4281501ff7df2ea378d569673569e1;hb=HEAD;hp=c76828fd5b53658abaf7a1de30d4c049a8f159e8;hpb=76446a14739779702a024d207be9fb52da36bd24;p=dorian diff --git a/infodialog.cpp b/infodialog.cpp index c76828f..904eb79 100644 --- a/infodialog.cpp +++ b/infodialog.cpp @@ -1,48 +1,87 @@ #include #include "infodialog.h" -#include "info.h" #include "book.h" #include "library.h" +#include "trace.h" -InfoDialog::InfoDialog(Book *book_, QWidget *parent): - QDialog(parent, Qt::Dialog | Qt::WindowTitleHint | - Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint), - book(book_) +InfoDialog::InfoDialog(Book *b, QWidget *parent, bool showButtons): + Dyalog(parent, showButtons), book(b) { - setWindowTitle(tr("Book Details")); - Info *info = new Info(book); - QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical, this); - QPushButton *read = new QPushButton(tr("Read"), this); - QPushButton *remove = new QPushButton(tr("Delete"), this); - connect(read, SIGNAL(clicked()), this, SLOT(onReadBook())); - connect(remove, SIGNAL(clicked()), this, SLOT(onRemoveBook())); - buttonBox->addButton(read, QDialogButtonBox::ActionRole); - buttonBox->addButton(remove, QDialogButtonBox::ActionRole); + TRACE; - QHBoxLayout *horizontalLayout = new QHBoxLayout(this); - horizontalLayout->addWidget(info); - horizontalLayout->addWidget(buttonBox); - setLayout(horizontalLayout); + setWindowTitle(tr("Book details")); + + if (book) { + QLabel *title = new QLabel(book->title, this); + title->setWordWrap(true); + addWidget(title); + if (book->subject != "") { + QLabel *subject = new QLabel(book->subject, this); + subject->setWordWrap(true); + addWidget(subject); + } + if (book->creators.size()) { + QLabel *creators = new QLabel(this); + creators->setWordWrap(true); + creators->setText(book->creators.join(", ")); + addWidget(creators); + } + QLabel *path = new QLabel("File: " + book->path(), this); + path->setWordWrap(true); + addWidget(path); + if (book->publisher != "") { + QLabel *publisher = + new QLabel("Published by " + book->publisher, this); + publisher->setWordWrap(true); + addWidget(publisher); + } + if (book->source != "") { + QLabel *source = new QLabel("Source: " + book->source, this); + source->setWordWrap(true); + addWidget(source); + } + if (book->rights != "") { + QLabel *rights = new QLabel(book->rights, this); + rights->setWordWrap(true); + addWidget(rights); + } + if (book->dateAdded.isValid()) { + QLabel *added = new QLabel("Added to library: " + + book->dateAdded.toLocalTime().toString(Qt::SystemLocaleShortDate), + this); + added->setWordWrap(true); + addWidget(added); + } + if (book->dateOpened.isValid()) { + QLabel *opened = new QLabel("Last read: " + + book->dateOpened.toLocalTime().toString(Qt::SystemLocaleShortDate), + this); + opened->setWordWrap(true); + addWidget(opened); + } + addStretch(); + } + + addButton(tr("Read"), this, SLOT(onReadBook()), + QDialogButtonBox::ActionRole); +#ifndef Q_OS_SYMBIAN + addButton(tr("Delete"), this, SLOT(onRemoveBook()), + QDialogButtonBox::DestructiveRole); +#endif } void InfoDialog::onReadBook() { - Library::instance()->setCurrent(Library::instance()->find(book)); - close(); + done(InfoDialog::Read); } void InfoDialog::onRemoveBook() { - QString title = book->title; if (QMessageBox::Yes == - QMessageBox::question(this, "Delete book", "Delete book " + title, - QMessageBox::Yes -#ifndef Q_WS_MAEMO_5 - , QMessageBox::No -#endif - )) { - Library::instance()->remove(Library::instance()->find(book)); - close(); + QMessageBox::question(this, tr("Delete book"), + tr("Delete book \"%1\" from library?").arg(book->shortName()), + QMessageBox::Yes | QMessageBox::No)) { + done(InfoDialog::Delete); } }