Debian Codegraph @

libqnapi/src/engines/subtitledownloadengine.cpp

raw symbols SCIP
1 /*****************************************************************************
2 ** QNapi
3 ** Copyright (C) 2008-2017 Piotr KrzemiƄski <[email protected]>
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 *****************************************************************************/
14
15 #include "engines/subtitledownloadengine.h"
16 #include <QDir>
17 #include <QFlags>
18 #include "subconvert/subtitleformatsregistry.h"
19
20 SubtitleDownloadEngine::SubtitleDownloadEngine(const QString& tmpPath)
21 : tmpPath(tmpPath) {}
22
23 void SubtitleDownloadEngine::setMoviePath(const QString& path) { movie = path; }
24
25 QString SubtitleDownloadEngine::moviePath() { return movie; }
26
27 void SubtitleDownloadEngine::clearSubtitlesList() {
28 foreach (SubtitleInfo s, subtitlesList) {
29 if (QFile::exists(s.sourceLocation)) QFile::remove(s.sourceLocation);
30 }
31 subtitlesList.clear();
32 }
33
34 Maybe<SubtitleInfo> SubtitleDownloadEngine::resolveById(QUuid id) {
35 foreach (SubtitleInfo s, subtitlesList) {
36 if (s.id == id) return just(s);
37 }
38 return nothing();
39 }
40
41 void SubtitleDownloadEngine::updateSubtitleInfo(const SubtitleInfo& si) {
42 for (int i = 0; i < subtitlesList.size(); ++i) {
43 if (subtitlesList[i].id == si.id) {
44 subtitlesList[i] = si;
45 break;
46 }
47 }
48 }
49
50 QString SubtitleDownloadEngine::generateTmpFileName() const {
51 static bool gen_inited;
52 if (!gen_inited) {
53 qsrand(time(0));
54 gen_inited = true;
55 }
56 return QString("QNapi.%1.tmp").arg(qrand());
57 }
58
59 QString SubtitleDownloadEngine::generateTmpPath() const {
60 QString newTmpFilePath =
61 QString("%1/%2").arg(tmpPath).arg(generateTmpFileName());
62 return QDir::toNativeSeparators(newTmpFilePath);
63 }