return e;
}
+Episode Database::getEpisode(int aid, int epno, const QString &type)
+{
+ Episode e;
+
+ QSqlQuery &q = prepare(
+ "SELECT eid, aid, entry_added, anidb_update, entry_update, my_update, epno, "
+ " title_english, title_romaji, title_kanji, length, airdate, state, "
+ " type, recap, rating, votes, my_vote, my_vote_date "
+ " FROM episode "
+ " WHERE aid = :aid "
+ " AND epno = :epno "
+ " AND type = :type ");
+
+ q.bindValue(":aid", aid);
+ q.bindValue(":epno", epno);
+ q.bindValue(":type", type.isNull() ? "" : type);
+
+ if (!exec(q))
+ return e;
+
+ if (q.next())
+ e = readEpisode(q);
+
+ q.finish();
+
+ return e;
+}
+
File Database::getFile(int fid)
{
File f;
LocalMyList::Anime getAnime(int aid);
QList<LocalMyList::Episode> getEpisodes(int aid);
LocalMyList::Episode getEpisode(int eid);
+ LocalMyList::Episode getEpisode(int aid, int epno, const QString &type = "");
LocalMyList::File getFile(int fid);
LocalMyList::File getFileByPath(const QString &path);
LocalMyList::File getFileByTitle(const QString &title, int epno = 1);
foreach (const PendingMyListUpdate &request, requests)
{
+ if (request.setVote)
+ {
+ VoteCommand cmd;
+
+ cmd.setVoteType(VoteCommand::AnimeVote);
+ cmd.setId(request.aid);
+ cmd.setEpno(request.epno);
+ cmd.setValue(int(request.vote * 100));
+
+ VoteReply *reply = Client::instance()->send(cmd);
+ connect(reply, SIGNAL(replyReady(bool)), this, SLOT(myListUpdateVoteReplyRecieved(bool)));
+ myListUpdateVoteIdMap.insert(reply, request.updateId);
+ continue;
+ }
+
MyListAddCommand cmd;
cmd.setEdit(true);
t.commit();
}
+void RequestHandler::myListUpdateVoteReplyRecieved(bool success)
+{
+ using namespace ::AniDBUdpClient;
+
+ VoteReply *reply = qobject_cast<VoteReply *>(sender());
+
+ Q_ASSERT(reply);
+ Q_ASSERT(myListUpdateVoteIdMap.contains(reply));
+ reply->deleteLater();
+
+ qint64 id = myListUpdateVoteIdMap.take(reply);
+
+ if (!success)
+ return;
+
+ RaiiTransaction t(db);
+
+ PendingMyListUpdate request = db->getPendingMyListUpdate(id);
+
+ if (!request.updateId)
+ {
+ qWarning("PendingMyListUpdate not in DB");
+ return;
+ }
+
+ if (request.epno == 0)
+ {
+ Anime anime = db->getAnime(request.aid);
+
+ anime.myVote = request.vote;
+ anime.myVoteDate = QDateTime::currentDateTime();
+
+ db->setAnime(anime);
+ return;
+ }
+
+ Episode episode = db->getEpisode(request.aid, request.epno);
+
+ episode.myVote = request.vote;
+ episode.myVoteDate = QDateTime::currentDateTime();
+
+ db->setEpisode(episode);
+}
+
} // namespace LocalMyList
void voteRequestComplete(bool);
void myListAddReplyRecieved(bool success);
void myListEditReplyRecieved(bool success);
-
+ void myListUpdateVoteReplyRecieved(bool success);
private:
Database *db;
QMap< ::AniDBUdpClient::VoteReply *, int> idMap;
QMap< ::AniDBUdpClient::MyListAddReply *, qint64> myListUpdateIdMap;
+ QMap< ::AniDBUdpClient::VoteReply *, qint64> myListUpdateVoteIdMap;
};
} // namespace LocalMyList