diff options
Diffstat (limited to 'archiveview.cpp')
-rw-r--r-- | archiveview.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/archiveview.cpp b/archiveview.cpp index 9edfd0b..2e649f1 100644 --- a/archiveview.cpp +++ b/archiveview.cpp @@ -8,8 +8,10 @@ #include <QComboBox> #include <QDialog> #include <QHBoxLayout> +#include <QInputDialog> #include <QLabel> #include <QLineEdit> +#include <QMessageBox> #include <QPushButton> #include <QSettings> #include <QSplitter> @@ -23,6 +25,8 @@ ArchiveView::ArchiveView(QWidget *parent) : QWidget(parent), mConstructing(true) mArchiveModel = static_cast<ArchiveModel*>(SmGlobals::instance()->model("ArchiveModel")); connect(mArchiveModel->collector(), SIGNAL(started()), this, SLOT(collectorStarted())); connect(mArchiveModel->collector(), SIGNAL(finished()), this, SLOT(collectorFinished())); + connect(mArchiveModel, SIGNAL(needRefresh()), this, SLOT(refreshArchive())); + connect(mArchiveModel, SIGNAL(databaseError(QString)), this, SLOT(showDatabaseError(QString))); mProgress = new ArchiveProgressDialog(this); mProgress->setHidden(true); connect(mArchiveModel->collector(), SIGNAL(message(QString)), mProgress, SLOT(setMessage(QString))); @@ -39,6 +43,7 @@ ArchiveView::ArchiveView(QWidget *parent) : QWidget(parent), mConstructing(true) mTree->setColumnHidden(ArchiveModel::Subtitle, true); mTree->setColumnHidden(ArchiveModel::Count, true); mTree->resizeColumnToContents(ArchiveModel::Name); + mTree->setEditTriggers(QAbstractItemView::NoEditTriggers); connect(mTree, SIGNAL(expanded(QModelIndex)), this, SLOT(expandItem(QModelIndex))); connect(mTree, SIGNAL(collapsed(QModelIndex)), this, SLOT(collapseItem(QModelIndex))); @@ -103,6 +108,11 @@ QWidget *ArchiveView::progressDialog(){ return qobject_cast<QWidget *>(mProgress); } +void ArchiveView::refreshArchive(){ + writeSettings(); + mArchiveModel->refresh(); +} + void ArchiveView::setExpanded(){ QSettings s; QVariantList expanded = s.value("archivemodel/expandeditems").toList(); @@ -139,6 +149,10 @@ void ArchiveView::collectorFinished(){ setExpanded(); } +void ArchiveView::showDatabaseError(const QString &errorMsg){ + QMessageBox::critical(this, tr("Database Error"), errorMsg); +} + void ArchiveView::expandItem(const QModelIndex &idx){ mExpandedItems << QPersistentModelIndex(idx); } @@ -147,7 +161,28 @@ void ArchiveView::collapseItem(const QModelIndex &idx){ mExpandedItems.removeAll(QPersistentModelIndex(idx)); } -ArchiveTree::ArchiveTree(QWidget *parent) : SmTreeView(parent) { +ArchiveTree::ArchiveTree(QWidget *parent) : SmTreeView(parent) {} + +void ArchiveTree::setModel(ArchiveProxy *model){ + mProxy = model; + mModel = qobject_cast<ArchiveModel*>(mProxy->sourceModel()); + QTreeView::setModel(model); +} + +void ArchiveTree::rename(){ + QModelIndex idx = currentIndex(); + int nodeType = idx.data(ArchiveModel::TypeRole).toInt(); + if(nodeType == ArchiveModel::SeriesPartNode){ + QMessageBox::critical(this, tr("Error"), tr("This function is not possible. Rename the Series instead!")); + return; + } + QString currentName = idx.data(ArchiveModel::NameRole).toString(); + QString question = QString(tr("Rename %1 to:")).arg(currentName); + QString newName = QInputDialog::getText(this, tr("Rename"), question, QLineEdit::Normal, currentName); + if(!newName.isEmpty()){ + QModelIndex realIdx = mProxy->mapToSource(idx); + mModel->setData(realIdx, newName, Qt::EditRole); + } } ArchiveProgressDialog::ArchiveProgressDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ |