2 #include <QStringListModel>
6 #include <QtMaemo5/QMaemo5InformationBox>
9 #include "foldersdialog.h"
13 #include "bookfinder.h"
15 FoldersDialog::FoldersDialog(QWidget *parent): ListWindow(parent)
17 setWindowTitle(tr("Folders"));
18 model = new QStringListModel(Library::instance()->folders(), this);
19 QListView *list = new QListView(this);
20 list->setModel(model);
21 list->setEditTriggers(QAbstractItemView::NoEditTriggers);
22 list->setUniformItemSizes(true);
24 addAction(tr("Add folder"), this, SLOT(onAdd()));
26 addAction(tr("Delete folder"), this, SLOT(onDelete()));
28 addAction(tr("Re-scan folders"), this, SLOT(onRefresh()));
31 void FoldersDialog::onAdd()
33 Trace t("FoldersDialog::onAdd");
36 Settings *settings = Settings::instance();
37 QString last = settings->value("lastfolderadded", QDir::homePath()).toString();
38 QString path = QFileDialog::getExistingDirectory(this, tr("Add Folder"), last);
42 settings->setValue("lastfolderadded", QFileInfo(path).absolutePath());
45 // Add folder to model
46 if (Library::instance()->addFolder(path)) {
47 int rows = model->rowCount();
48 model->insertRows(rows, 1);
49 model->setData(model->index(rows), path);
53 QMaemo5InformationBox::information(this,
54 tr("This folder is already in the library"),
55 QMaemo5InformationBox::DefaultTimeout);
57 (void)QMessageBox::information(this, tr("Dorian"),
58 tr("This folder is already in the library"), QMessageBox::Ok);
59 #endif // Q_WS_MAEMO_5
63 void FoldersDialog::onRemove()
67 void FoldersDialog::onRefresh()
70 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
73 BookFinder *bookFinder = new BookFinder(this);
74 Library *library = Library::instance();
75 connect(bookFinder, SIGNAL(add(const QString &)),
76 library, SLOT(add(const QString &)));
77 connect(bookFinder, SIGNAL(remove(const QString &)),
78 library, SLOT(remove(const QString &)));
79 connect(bookFinder, SIGNAL(done(int,int)),
80 this, SLOT(onRefreshDone(int, int)));
81 // bookFinder->moveToThread(&bookFinderThread);
82 // bookFinderThread.start();
84 (void)QMetaObject::invokeMethod(
87 Q_ARG(QStringList, model->stringList()),
88 Q_ARG(QStringList, library->bookPaths()));
91 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
95 void FoldersDialog::onRefreshDone(int added, int removed)
101 case 0: addedMsg = tr("No books added"); break;
102 case 1: addedMsg = tr("%1 book added").arg(1); break;
103 default: addedMsg = tr("%1 books added").arg(added);
107 case 0: removedMsg = tr("no books removed"); break;
108 case 1: removedMsg = tr("%1 book removed").arg(1); break;
109 default: removedMsg = tr("%1 books removed").arg(removed);
112 QString msg(tr("Scanning folders complete\n\n%1, %2.").
113 arg(addedMsg).arg(removedMsg));
114 Trace::trace(QString("FoldersDialog::onRefreshDone: " + msg));
116 QMaemo5InformationBox::
117 information(this, msg, QMaemo5InformationBox::NoTimeout);