#include "mylistview.h"
+#include "mylist.h"
#include "mylistmodel.h"
#include <QMenu>
{
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showCustomContextMenu(QPoint)));
+
+ openAction = new QAction(tr("Open"), this);
+ connect(openAction, SIGNAL(triggered()), this, SLOT(requestOpenFile()));
+ openNextAction = new QAction(tr("Open next"), this);
+ connect(openNextAction, SIGNAL(triggered()), this, SLOT(requestOpenFile()));
+ markWatchedAction = new QAction(tr("Marked Watched"), this);
+ connect(markWatchedAction, SIGNAL(triggered()), this, SLOT(markWatched()));
}
LocalMyList::MyListModel *MyListView::myListModel() const
if (!idx.isValid())
return;
- QAction a(tr("Dummyaction r=%1, c=%2").arg(idx.row()).arg(idx.column()), this);
- MyListModel::NodeType t = myListModel()->type(idx);
- QAction b(tr("%1 = %2").arg(t == MyListModel::Anime ? "aid" : t == MyListModel::Episode ? "eid" : t == MyListModel::File ? "fid" : "none").arg(myListModel()->id(idx)), this);
+ MyListModel::NodeType type = myListModel()->type(idx);
+
+ //QAction a(tr("Dummyaction r=%1, c=%2").arg(idx.row()).arg(idx.column()), this);
+
+ //QAction b(tr("%1 = %2").arg(type == MyListModel::Anime ? "aid" : type == MyListModel::Episode ? "eid" : type == MyListModel::File ? "fid" : "none").arg(myListModel()->id(idx)), this);
QList<QAction *> actions;
- actions << &a << &b;
+
+ if (type == MyListModel::Anime)
+ actions << openNextAction;
+ else
+ actions << openAction;
+ if (type == MyListModel::File)
+ actions << markWatchedAction;
+
+ if(actions.isEmpty())
+ return;
+
+ customContextMenuIndex = idx;
QMenu::exec(actions, viewport()->mapToGlobal(pos));
+ customContextMenuIndex = QModelIndex();
+}
+
+void MyListView::requestOpenFile()
+{
+ emit openFileRequested(customContextMenuIndex);
+}
+
+void MyListView::markWatched()
+{
+ int id = myListModel()->id(customContextMenuIndex);
+
+ LocalMyList::instance()->markWatched(id);
}
#define MYLISTVIEW_H
#include <QTreeView>
+#include <QModelIndex>
namespace LocalMyList {
class MyListModel;
public:
explicit MyListView(QWidget *parent = 0);
+signals:
+ void openFileRequested(const QModelIndex &index);
+
private slots:
LocalMyList::MyListModel *myListModel() const;
void showCustomContextMenu(const QPoint &pos);
-
+ void requestOpenFile();
+ void markWatched();
+private:
+ QModelIndex customContextMenuIndex;
+
+
+ QAction *openAction;
+ QAction *openNextAction;
+ QAction *markWatchedAction;
};
#endif // MYLISTVIEW_H