list->setUniformItemSizes(true);
addList(list);
addAction(tr("Add folder"), this, SLOT(onAdd()));
- addItemAction(tr("Delete folder"), this, SLOT(onRemove()));
- addAction(tr("Re-scan folders"), this, SLOT(onRefresh()));
+ addItemAction(tr("Re-scan"), this, SLOT(onRefresh()));
+ addItemAction(tr("Remove"), this, SLOT(onRemove()));
+ addAction(tr("Re-scan all folders"), this, SLOT(onRefreshAll()));
}
void FoldersDialog::onAdd()
} else {
#ifdef Q_WS_MAEMO_5
QMaemo5InformationBox::information(this,
- tr("This folder is already in the library"),
- QMaemo5InformationBox::DefaultTimeout);
+ tr("This folder is already in the library"));
#else
(void)QMessageBox::information(this, tr("Dorian"),
tr("This folder is already in the library"), QMessageBox::Ok);
if (selection.size() != 1) {
return;
}
+
QModelIndex selected = selection[0];
QString path = list->model()->data(selected).toString();
t.trace(path);
- if (Library::instance()->removeFolder(path)) {
- model->removeRow(selected.row());
- onRefresh();
+
+ if (QMessageBox::Yes ==
+ QMessageBox::question(this, tr("Remove folder"),
+ tr("Remove folder \"%1\" from library?").arg(path),
+ QMessageBox::Yes | QMessageBox::No)) {
+ if (Library::instance()->removeFolder(path)) {
+ model->removeRow(selected.row());
+ }
}
}
void FoldersDialog::onRefresh()
{
+ Trace t("FoldersDialog::onRefresh");
+
+ QModelIndexList selection = list->selectionModel()->selectedIndexes();
+ if (selection.size() != 1) {
+ return;
+ }
+
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
#endif
-
+ QModelIndex selected = selection[0];
+ QString path = list->model()->data(selected).toString();
+ t.trace(path);
BookFinder *bookFinder = new BookFinder(this);
Library *library = Library::instance();
connect(bookFinder, SIGNAL(add(const QString &)),
library, SLOT(remove(const QString &)));
connect(bookFinder, SIGNAL(done(int,int)),
this, SLOT(onRefreshDone(int, int)));
- // bookFinder->moveToThread(&bookFinderThread);
- // bookFinderThread.start();
+ bookFinder->find(QStringList(path), library->bookPaths());
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+#endif
+}
+
+void FoldersDialog::onRefreshAll()
+{
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+#endif
- (void)QMetaObject::invokeMethod(
- bookFinder,
- "find",
- Q_ARG(QStringList, model->stringList()),
- Q_ARG(QStringList, library->bookPaths()));
+ BookFinder *bookFinder = new BookFinder(this);
+ Library *library = Library::instance();
+ connect(bookFinder, SIGNAL(add(const QString &)),
+ library, SLOT(add(const QString &)));
+ connect(bookFinder, SIGNAL(remove(const QString &)),
+ library, SLOT(remove(const QString &)));
+ connect(bookFinder, SIGNAL(done(int,int)),
+ this, SLOT(onRefreshDone(int, int)));
+ bookFinder->find(model->stringList(), library->bookPaths());
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
default: removedMsg = tr("%1 books removed").arg(removed);
}
- QString msg(tr("Scanning folders complete\n\n%1, %2.").
+ QString msg(tr("Scanning complete\n\n%1, %2.").
arg(addedMsg).arg(removedMsg));
Trace::trace(QString("FoldersDialog::onRefreshDone: " + msg));
#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::
- information(this, msg, QMaemo5InformationBox::NoTimeout);
+ QMaemo5InformationBox::information(this, msg);
#else
// FIXME
#endif
QFrame *frame = new QFrame(this);
setCentralWidget(frame);
- frameLayout = new QHBoxLayout(frame);
+ frameLayout = new QHBoxLayout();
frame->setLayout(frameLayout);
-#ifndef Q_WS_MAEMO_5
+#ifdef Q_WS_MAEMO_5
+ popup = new QMenu(this);
+#else
buttonBox = new QDialogButtonBox(Qt::Vertical, this);
frameLayout->addWidget(buttonBox);
#endif
void ListWindow::addList(QListView *listView)
{
list = listView;
+#ifdef Q_WS_MAEMO_5
+ list->installEventFilter(this);
+#endif
frameLayout->insertWidget(0, list);
connect(list->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
this,
- SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection&)));
+ SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
}
void ListWindow::addAction(const QString &title, QObject *receiver,
itemButtons.append(button);
activateItemButtons();
#else
- // FIXME
+ popup->addAction(title, receiver, slot);
#endif // ! Q_WS_MAEMO_5
}
}
#endif // ! Q_WS_MAEMO_5
+
+#ifdef Q_WS_MAEMO_5
+
+bool ListWindow::eventFilter(QObject *obj, QEvent *event)
+{
+ if (event->type() == QEvent::ContextMenu) {
+ Trace::trace("ListWindow::eventFiler: Received QEvent::ContextMenu");
+ if (popup->actions().size()) {
+ QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
+ QPoint pos = mouseEvent->globalPos();
+ pos.setX(pos.x() - 150);
+ if (pos.x() < 0) {
+ pos.setX(0);
+ }
+ popup->exec(pos);
+ }
+ return true;
+ } else {
+ Trace::trace("ListWindow::eventFilter");
+ return QObject::eventFilter(obj, event);
+ }
+}
+
+#endif // Q_WS_MAEMO_5