-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoitem.cpp
77 lines (61 loc) · 1.79 KB
/
videoitem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <QFileInfo>
#include "videoitem.h"
#include "common.h"
VideoItem::VideoItem(QObject *parent) : QObject(parent)
{
m_videoName = "";
m_videoPath = "";
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
}
VideoItem::VideoItem(Parameters *parameters, VideoType type)
{
m_parameters = parameters;
m_videoType = type;
m_videoPath = "";
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
}
void VideoItem::serialize(PrettyWriter<StringBuffer> &writer)
{
writer.StartObject();
writer.Key("videoType");
writer.Int(m_videoType);
writer.Key("videoName");
writer.String(m_videoName.toStdString().c_str());
writer.Key("videoPath");
writer.String(m_videoPath.toStdString().c_str());
writer.EndObject();
}
void VideoItem::unserialize(const Value &value)
{
if (value.HasMember("videoName")) {
m_videoName = QString(value["videoName"].GetString());
}
if (value.HasMember("videoPath")) {
m_videoPath = QString(value["videoPath"].GetString());
}
}
QString VideoItem::videoName() const
{
return m_videoName;
}
void VideoItem::setVideoName(const QString &videoName)
{
QUrl tmp(videoName);
QFileInfo fileInfo(tmp.toLocalFile());
if (fileInfo.exists()) {
//Copy video to video path
QFile::copy(tmp.toLocalFile(), m_parameters->getApplicationDirPath().toString() + "/" + VIDEO_FOLDER + "/" + fileInfo.fileName());
m_videoName = fileInfo.fileName();
}
m_parameters->Serialize();
emit videoItemChanged();
}
QString VideoItem::videoPath() const
{
return m_parameters->getApplicationDirPath().toString() + "/" + VIDEO_FOLDER + "/" + m_videoName;
}
void VideoItem::setVideoPath(const QString &videoPath)
{
m_videoPath = videoPath;
emit videoItemChanged();
}