summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archivemodel.cpp52
-rw-r--r--archivemodel.h8
-rw-r--r--archiveview.cpp37
-rw-r--r--archiveview.h10
-rw-r--r--shemov.cpp5
-rw-r--r--shemov.h5
-rw-r--r--smtreeview.cpp17
-rw-r--r--smtreeview.h3
8 files changed, 130 insertions, 7 deletions
diff --git a/archivemodel.cpp b/archivemodel.cpp
index de95328..0c16c21 100644
--- a/archivemodel.cpp
+++ b/archivemodel.cpp
@@ -5,6 +5,7 @@
2 of the License, or (at your option) any later version.
*/
+#include <QSqlError>
#include <QSqlQuery>
#include "smtreeitem.h"
@@ -54,9 +55,54 @@ QVariant ArchiveModel::data(const QModelIndex &index, int role) const{
return QColor(Qt::darkGreen);
}
}
+ if(role == NameRole){
+ return item->data(Name);
+ }
+ if(role == TypeRole){
+ return item->data(Type);
+ }
return SmTreeModel::data(index, role);
}
+bool ArchiveModel::setData(const QModelIndex &idx, const QVariant &value, int role){
+ if(role != Qt::EditRole){
+ return false;
+ }
+ SmTreeItem *item = itemAt(idx);
+ int nodeType = item->data(Type).toInt();
+ QSqlQuery updateQuery(mDb);
+ if(nodeType == GenreNode){
+ updateQuery.prepare("UPDATE genres SET tgenrename = :value WHERE igenres_id = :id");
+ }else if(nodeType == ActorNode){
+ updateQuery.prepare("UPDATE actors SET tactorname = :value WHERE iactors_id = :id");
+ }else if(nodeType == SeriesNode){
+ updateQuery.prepare("UPDATE series SET tseries_name = :value WHERE iseries_id = :id");
+ }else{
+ return false;
+ }
+ QVariant id = item->data(GenericId);
+ updateQuery.bindValue(":value", value);
+ updateQuery.bindValue(":id", id);
+ if(updateQuery.exec()){
+ if(nodeType == GenreNode || nodeType == ActorNode){
+ item->setData(Name, value);
+ emit dataChanged(idx, idx);
+ return true;
+ }else if(nodeType == SeriesNode){
+ item->setData(Name, value);
+ emit needRefresh();
+ return true;
+ }
+ }else{
+ QSqlError e = updateQuery.lastError();
+ QString databaseText = e.databaseText().isEmpty() ? tr("(none)") : e.databaseText();
+ QString driverText = e.driverText().isEmpty() ? tr("(none)") : e.driverText();
+ QString errormsg = QString(tr("<b>Database errors:</b><br/><ul><li>driverText(): %1</li><li>databaseText(): %2</li></ul>")).arg(driverText).arg(databaseText);
+ emit databaseError(errormsg);
+ }
+ return false;
+}
+
QStringList ArchiveModel::indexToPath(const QModelIndex &idx) const {
QStringList retval;
SmTreeItem *item = itemAt(idx);
@@ -96,6 +142,10 @@ void ArchiveModel::setOrder(const QString &order){
setOrder(orderNum);
}
+void ArchiveModel::refresh(){
+ setOrder(mOrder);
+}
+
void ArchiveModel::collectorFinished(){
SmTreeItem *item = mCollector->rootItem();
setRoot(item);
@@ -151,7 +201,7 @@ void ArchiveCollector::populateByActor(){
QSqlQuery actorIdQuery = QSqlQuery("SELECT iactors_id, tactorname FROM actors ORDER BY tactorname", mDb);
while(actorIdQuery.next()){
QList<QVariant> actorIdData;
- actorIdData << actorIdQuery.value(1) << actorIdQuery.value(0) << QVariant() << QVariant() << ArchiveModel::GenreNode << false << QVariant() << QVariant() << QVariant();
+ actorIdData << actorIdQuery.value(1) << actorIdQuery.value(0) << QVariant() << QVariant() << ArchiveModel::ActorNode << false << QVariant() << QVariant() << QVariant();
SmTreeItem *actorIdItem = new SmTreeItem(actorIdData, mRootItem);
mRootItem->appendChild(actorIdItem);
}
diff --git a/archivemodel.h b/archivemodel.h
index 0f2eea7..946bb3c 100644
--- a/archivemodel.h
+++ b/archivemodel.h
@@ -19,7 +19,7 @@ class ArchiveCollector;
class ArchiveModel : public SmTreeModel {
Q_OBJECT
public:
- enum CustomRoles { NameRole = Qt::UserRole + 1, SeriesIdRole = Qt::UserRole + 2, SeriesPartIdRole = Qt::UserRole + 3, SeriesPartRole = Qt::UserRole + 4, TypeRole = Qt::UserRole + 5, FavoriteRole = Qt::UserRole + 6, SubtitleRole = Qt::UserRole + 7, CountRole = Qt::UserRole + 8 };
+ enum CustomRoles { NameRole = Qt::UserRole + 1, GenericIdRole = Qt::UserRole + 2, SeriesPartIdRole = Qt::UserRole + 3, SeriesPartRole = Qt::UserRole + 4, TypeRole = Qt::UserRole + 5, FavoriteRole = Qt::UserRole + 6, SubtitleRole = Qt::UserRole + 7, CountRole = Qt::UserRole + 8 };
enum Fields { Name = 0, GenericId = 1, SeriesPartId = 2, SeriesPart = 3, Type = 4, Favorite = 5, Subtitle = 6, Count = 7 };
enum Order { SeriesName, Actor, Genre, NoOrder };
enum { NumFields = 8 };
@@ -29,12 +29,18 @@ class ArchiveModel : public SmTreeModel {
const QHash<QString, int> availableOrdersHash() const { return mAvailableOrders; }
ArchiveCollector *collector() { return mCollector; }
virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual bool setData(const QModelIndex &idx, const QVariant &value, int role);
QStringList indexToPath(const QModelIndex &idx) const;
QModelIndexList pathToIndex(const QStringList &path) const;
+ signals:
+ void needRefresh();
+ void databaseError(const QString &error);
+
public slots:
void setOrder(int order);
void setOrder(const QString &order);
+ void refresh();
private slots:
void collectorFinished();
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){
diff --git a/archiveview.h b/archiveview.h
index 33969d9..850794c 100644
--- a/archiveview.h
+++ b/archiveview.h
@@ -36,9 +36,11 @@ class ArchiveView : public QWidget {
// center of the main window...
void setConstructingDone() { mConstructing = false; }
ArchiveModel *archiveModel() { return mArchiveModel; }
+ ArchiveTree *archiveTree() { return mTree; }
QWidget *progressDialog();
public slots:
+ void refreshArchive();
void setExpanded();
private slots:
@@ -46,6 +48,7 @@ class ArchiveView : public QWidget {
void clearFilter();
void collectorStarted();
void collectorFinished();
+ void showDatabaseError(const QString &errorMsg);
void expandItem(const QModelIndex &idx);
void collapseItem(const QModelIndex &idx);
@@ -62,11 +65,16 @@ class ArchiveView : public QWidget {
};
class ArchiveTree : public SmTreeView {
+ Q_OBJECT
public:
explicit ArchiveTree(QWidget *parent = 0);
+ virtual void setModel(ArchiveProxy *model);
+
+ public slots:
+ void rename();
private:
- QSortFilterProxyModel *mProxy;
+ ArchiveProxy *mProxy;
ArchiveModel *mModel;
};
diff --git a/shemov.cpp b/shemov.cpp
index 0144a7d..e0425fb 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -737,6 +737,11 @@ void SheMov::createActions(){
/* picView(er) END Actions! */
+ // ArchiveView actions
+ mArchiveViewRenameA = new QAction(tr("Rename..."), this);
+ connect(mArchiveViewRenameA, SIGNAL(triggered()), mArchive->archiveTree(), SLOT(rename()));
+ mArchive->archiveTree()->addAction(mArchiveViewRenameA);
+
//don't add actions with checkable(true) unless you know what you're doing!
mPicActionGroup = new QActionGroup(this);
mPicActionGroup->addAction(mPWDeletePicFromA);
diff --git a/shemov.h b/shemov.h
index 9bb2e4d..a18e0b1 100644
--- a/shemov.h
+++ b/shemov.h
@@ -184,7 +184,10 @@ class SheMov : public QMainWindow {
QAction *mPVAddToNPA;
QActionGroup *mPicActionGroup;
//EndActions
-
+
+ //ArchiveView actions
+ QAction *mArchiveViewRenameA;
+
QSignalMapper *mOpenWithMapperFS;
QSignalMapper *mOpenWithMapperAV;
QSignalMapper *mFilterMapper;
diff --git a/smtreeview.cpp b/smtreeview.cpp
index 405f6a0..d4faab8 100644
--- a/smtreeview.cpp
+++ b/smtreeview.cpp
@@ -5,10 +5,12 @@
2 of the License, or (at your option) any later version.
*/
-#include <QSettings>
-#include <QHeaderView>
#include <QAction>
#include <QActionGroup>
+#include <QHeaderView>
+#include <QMenu>
+#include <QContextMenuEvent>
+#include <QSettings>
#include "smtreeview.h"
#include "smglobals.h"
@@ -58,3 +60,14 @@ void SmTreeView::toggleHeader(QObject *action){
QHeaderView *hv = header();
hv->setSectionHidden(logicalIndex, !a->isChecked());
}
+
+void SmTreeView::contextMenuEvent(QContextMenuEvent *e){
+ if(actions().isEmpty()){
+ return;
+ }
+ QMenu contextMenu(this);
+ foreach(QAction *a, actions()){
+ contextMenu.addAction(a);
+ }
+ contextMenu.exec(e->globalPos());
+}
diff --git a/smtreeview.h b/smtreeview.h
index 67ba844..6d30917 100644
--- a/smtreeview.h
+++ b/smtreeview.h
@@ -24,6 +24,9 @@ class SmTreeView : public QTreeView {
void writeHeaderConfig();
void toggleHeader(QObject *action);
+ protected:
+ virtual void contextMenuEvent(QContextMenuEvent *e);
+
private:
const QString mHeaderSetting;
QActionGroup *mHeaderGroup;