]> Some of my projects - localmylist.git/commitdiff
Add Open AniDB Page context menu option.
authorAPTX <marek321@gmail.com>
Mon, 11 Jun 2012 12:39:16 +0000 (14:39 +0200)
committerAPTX <marek321@gmail.com>
Mon, 11 Jun 2012 12:39:16 +0000 (14:39 +0200)
management-gui/mylistview.cpp
management-gui/mylistview.h

index ae3860e01981af0bfd7d5725fead3c0745615cc1..368cb9fa0802616896da8837c921e038d7c8fed2 100644 (file)
@@ -4,6 +4,8 @@
 #include "mylistmodel.h"
 
 #include <QMenu>
+#include <QDesktopServices>
+#include <QUrl>
 
 MyListView::MyListView(QWidget *parent) :
     QTreeView(parent)
@@ -13,10 +15,12 @@ MyListView::MyListView(QWidget *parent) :
 
        openAction = new QAction(tr("Open"), this);
        connect(openAction, SIGNAL(triggered()), this, SLOT(requestOpenFile()));
-       openNextAction = new QAction(tr("Open next"), this);
+       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()));
+       aniDBLinkAction = new QAction(tr("Open AniDB Page"), this);
+       connect(aniDBLinkAction, SIGNAL(triggered()), this, SLOT(openAnidbPage()));
 }
 
 LocalMyList::MyListModel *MyListView::myListModel() const
@@ -33,19 +37,29 @@ void MyListView::showCustomContextMenu(const QPoint &pos)
                return;
 
        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);
+       int id = myListModel()->id(idx);
 
        QList<QAction *> actions;
 
-       if (type == MyListModel::Anime)
-               actions << openNextAction;
-       else
-               actions << openAction;
-       if (type == MyListModel::File)
-               actions << markWatchedAction;
+       switch (type)
+       {
+               case MyListModel::Anime:
+                       aniDBLinkAction->setText(tr("Open AniDB Page (%1%2)").arg('a').arg(id));
+                       actions << aniDBLinkAction
+                                       << openNextAction;
+               break;
+               case MyListModel::Episode:
+                       aniDBLinkAction->setText(tr("Open AniDB Page (%1%2)").arg('e').arg(id));
+                       actions << aniDBLinkAction
+                                       << openAction;
+               break;
+               case MyListModel::File:
+                       aniDBLinkAction->setText(tr("Open AniDB Page (%1%2)").arg('f').arg(id));
+                       actions << aniDBLinkAction
+                                       << openAction
+                                       << markWatchedAction;
+               break;
+       }
 
        if(actions.isEmpty())
                return;
@@ -66,3 +80,25 @@ void MyListView::markWatched()
 
        LocalMyList::instance()->markWatched(id);
 }
+
+void MyListView::openAnidbPage()
+{
+       using namespace LocalMyList;
+
+       QString aniDBUrlBase = "http://anidb.net/%1%2";
+       int id = myListModel()->id(customContextMenuIndex);
+       MyListModel::NodeType type = myListModel()->type(customContextMenuIndex);
+
+       switch (type)
+       {
+               case MyListModel::Anime:
+                       QDesktopServices::openUrl(QUrl(aniDBUrlBase.arg('a').arg(id)));
+               break;
+               case MyListModel::Episode:
+                       QDesktopServices::openUrl(QUrl(aniDBUrlBase.arg('e').arg(id)));
+               break;
+               case MyListModel::File:
+                       QDesktopServices::openUrl(QUrl(aniDBUrlBase.arg('f').arg(id)));
+               break;
+       }
+}
index b4371b96e193ae4ae70a2c057a81aab7b9137e20..8f30ad08be8febff9b9c6478808c985df8d3c22d 100644 (file)
@@ -22,6 +22,7 @@ private slots:
        void showCustomContextMenu(const QPoint &pos);
        void requestOpenFile();
        void markWatched();
+       void openAnidbPage();
 private:
        QModelIndex customContextMenuIndex;
 
@@ -29,6 +30,7 @@ private:
        QAction *openAction;
        QAction *openNextAction;
        QAction *markWatchedAction;
+       QAction *aniDBLinkAction;
 };
 
 #endif // MYLISTVIEW_H