-
Notifications
You must be signed in to change notification settings - Fork 1
/
filedata.cpp
49 lines (44 loc) · 1.03 KB
/
filedata.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
#include "filedata.h"
#include <QDataStream>
FileData::FileData(QObject *parent) :
QObject(parent)
{
totalSize_ = 0;
port_ = 0;
}
FileData::FileData(QObject *parent, QString path, short port) : QObject(parent){
port_ = port;
path_ = path;
totalSize_ = 0;
}
FileData::FileData(QObject *parent, short port) : QObject(parent){
port_ = port;
totalSize_ = 0;
}
FileData::FileData(QObject *parent, QString path, QByteArray data, short port) : QObject(parent){
path_ = path;
data_ = data;
port_ = port;
totalSize_ = 0;
}
bool FileData::writeToFile() {
int n = path_.lastIndexOf('/');
int s = path_.size() - n - 1;
QString songTitle = path_.right(s);
QFile file(songTitle);
if(!file.open(QIODevice::WriteOnly)){
return false;
}
file.write(data_);
file.close();
return true;
}
bool FileData::readFromFile() {
QFile file(path_);
if(!file.open(QIODevice::ReadOnly)){
return false;
}
data_ = file.readAll();
file.close();
return true;
}