MCPcopy Create free account
hub / github.com/KikoPlayProject/KikoPlay / EpisodeEditor

Method EpisodeEditor

UI/episodeeditor.cpp:12–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "Play/Video/mpvplayer.h"
11#include "Common/network.h"
12EpisodeEditor::EpisodeEditor(Anime *anime, QWidget *parent) : CFramelessDialog(tr("Episodes"),parent)
13{
14 QTreeView *episodeView=new QTreeView(this);
15 episodeView->setRootIsDecorated(false);
16 episodeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
17 episodeView->setItemDelegate(new EpItemDelegate(&epNames,this));
18 episodeView->setFont(font());
19 epModel=new EpisodesModel(anime,this);
20 episodeView->setModel(epModel);
21 episodeView->setAlternatingRowColors(true);
22 QPushButton *add=new QPushButton(tr("Add Episode(s)"),this);
23 QObject::connect(add,&QPushButton::clicked,[this](){
24 QStringList files = QFileDialog::getOpenFileNames(this,tr("Select media files"),"",
25 QString("Video Files(%1);;All Files(*) ").arg(GlobalObjects::mpvplayer->videoFileFormats.join(" ")));
26 if (files.count())
27 {
28 QFileInfo fi;
29 for(auto &file:files)
30 {
31 fi.setFile(file);
32 epModel->addEpisode(fi.baseName(),file);
33 }
34 }
35 });
36 QPushButton *remove=new QPushButton(tr("Remove Episode(s)"),this);
37 QObject::connect(remove,&QPushButton::clicked,[episodeView,this](){
38 auto selection = episodeView->selectionModel()->selectedRows();
39 if (selection.size() == 0)return;
40 epModel->removeEpisodes(selection);
41 });
42 QPushButton *getEpNames=new QPushButton(tr("Get Epsoide Names"),this);
43 QObject::connect(getEpNames,&QPushButton::clicked,[this,anime,getEpNames](){
44 if(anime->bangumiID==-1)return;
45 QString epUrl(QString("https://api.bgm.tv/subject/%1/ep").arg(anime->bangumiID));
46 try
47 {
48 getEpNames->setText(tr("Getting..."));
49 getEpNames->setEnabled(false);
50 this->showBusyState(true);
51 QString str(Network::httpGet(epUrl,QUrlQuery(),QStringList()<<"Accept"<<"application/json"));
52 QJsonDocument document(Network::toJson(str));
53 QJsonObject obj = document.object();
54 QJsonArray epArray=obj.value("eps").toArray();
55 for(auto iter=epArray.begin();iter!=epArray.end();++iter)
56 {
57 QJsonObject epobj=(*iter).toObject();
58 epNames.append(QString("No.%0 %1(%2)").arg(epobj.value("sort").toInt()).arg(epobj.value("name").toString()).arg(epobj.value("name_cn").toString()));
59 }
60 getEpNames->setText(tr("Getting Done"));
61
62 }
63 catch(Network::NetworkError &error)
64 {
65 QMessageBox::information(this,tr("Error"),error.errorInfo);
66 getEpNames->setEnabled(true);
67 getEpNames->setText(tr("Get Epsoide Names"));
68 }
69 this->showBusyState(false);

Callers

nothing calls this directly

Calls 14

QStringClass · 0.85
setFontMethod · 0.80
countMethod · 0.80
setEnabledMethod · 0.80
valueMethod · 0.80
setContentsMarginsMethod · 0.80
headerMethod · 0.80
sizeMethod · 0.45
setTextMethod · 0.45
showBusyStateMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected