qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
toxfile.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "src/core/toxfile.h"
21 #include <QFile>
22 #include <QRegularExpression>
23 #include <tox/tox.h>
24 
25 #define TOX_HEX_ID_LENGTH 2 * TOX_ADDRESS_SIZE
26 
38  : fileKind(0)
39  , fileNum(0)
40  , friendId(0)
41  , status(INITIALIZING)
42  , direction(SENDING)
43  , progress(0)
44 {}
45 
49 ToxFile::ToxFile(uint32_t fileNum, uint32_t friendId, QString filename, QString filePath,
50  uint64_t filesize, FileDirection Direction)
51  : fileKind{TOX_FILE_KIND_DATA}
52  , fileNum(fileNum)
53  , friendId(friendId)
54  , fileName{filename}
55  , filePath{filePath}
56  , file{new QFile(filePath)}
57  , status{INITIALIZING}
58  , direction{Direction}
59  , progress(filesize)
60 {}
61 
62 bool ToxFile::operator==(const ToxFile& other) const
63 {
64  return (fileNum == other.fileNum) && (friendId == other.friendId)
65  && (direction == other.direction);
66 }
67 
68 bool ToxFile::operator!=(const ToxFile& other) const
69 {
70  return !(*this == other);
71 }
72 
73 void ToxFile::setFilePath(QString path)
74 {
75  filePath = path;
76  file->setFileName(path);
77 }
78 
79 bool ToxFile::open(bool write)
80 {
81  return write ? file->open(QIODevice::ReadWrite) : file->open(QIODevice::ReadOnly);
82 }
ToxFile::operator==
bool operator==(const ToxFile &other) const
Definition: toxfile.cpp:62
toxfile.h
ToxFile::file
std::shared_ptr< QFile > file
Definition: toxfile.h:69
ToxFile::fileNum
uint32_t fileNum
Definition: toxfile.h:65
HistMessageContentType::file
@ file
ToxFile::direction
FileDirection direction
Definition: toxfile.h:71
ToxFile::FileDirection
FileDirection
Definition: toxfile.h:48
FileTransferList::Column::progress
@ progress
ToxFile::setFilePath
void setFilePath(QString path)
Definition: toxfile.cpp:73
ToxFile::friendId
uint32_t friendId
Definition: toxfile.h:66
FileTransferList::Column::status
@ status
ToxFile
Definition: toxfile.h:32
ToxFile::operator!=
bool operator!=(const ToxFile &other) const
Definition: toxfile.cpp:68
ToxFile::filePath
QString filePath
Definition: toxfile.h:68
ToxFile::ToxFile
ToxFile()
Definition: toxfile.cpp:37
ToxFile::open
bool open(bool write)
Definition: toxfile.cpp:79