1 //////////////////////////////////////////////////////////////////////
2 //
3 // BeeBEEP Copyright (C) 2010-2021 Marco Mastroddi
4 //
5 // BeeBEEP is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published
7 // by the Free Software Foundation, either version 3 of the License,
8 // or (at your option) any later version.
9 //
10 // BeeBEEP is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with BeeBEEP. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Author: Marco Mastroddi <marco.mastroddi(AT)gmail.com>
19 //
20 // $Id: FileInfo.h 1455 2020-12-23 10:17:53Z mastroddi $
21 //
22 //////////////////////////////////////////////////////////////////////
23 
24 #ifndef BEEBEEP_FILEINFO_H
25 #define BEEBEEP_FILEINFO_H
26 
27 #include "NetworkAddress.h"
28 
29 
30 class FileInfo
31 {
32 public:
33   enum TransferType { Upload, Download };
34   enum ContentType { File, VoiceMessage, NumContentTypes };
35 
urlSchemeShowFileInFolder()36   static QString urlSchemeShowFileInFolder() { return QLatin1String( "beeshowfileinfolder" ); }
urlSchemeVoiceMessage()37   static QString urlSchemeVoiceMessage() { return QLatin1String( "beevoicemessage" ); }
38 
39   FileInfo();
40   FileInfo( VNumber, FileInfo::TransferType );
41   inline FileInfo( const FileInfo& );
42 
43   FileInfo& operator=( const FileInfo& );
44   inline bool operator==( const FileInfo& );
45   bool operator<( const FileInfo& ) const;
46 
47   inline bool isValid() const;
48   inline bool isDownload() const;
49   inline TransferType transferType() const;
50   inline void setTransferType( TransferType );
51   inline const QString& name() const;
52   inline void setName( const QString& );
53   void setNameAndSuffix( const QString& file_name );
54   inline const QString& path() const;
55   inline void setPath( const QString& );
56   inline const QString& suffix() const;
57   inline void setSuffix( const QString& );
58   inline FileSizeType size() const;
59   inline void setSize( FileSizeType );
60   inline const QString& shareFolder() const;
61   inline void setShareFolder( const QString& );
62   inline bool isFolder() const;
63   inline void setIsFolder( bool );
64   inline void setNetworkAddress( const NetworkAddress& );
65   inline void setHostAddress( const QHostAddress& );
66   inline void setHostPort( quint16 );
67   inline const NetworkAddress& networkAddress() const;
68   inline const QByteArray& password() const;
69   inline void setPassword( const QByteArray& );
70   inline VNumber id() const;
71   inline void setId( VNumber );
72   inline const QString& fileHash() const;
73   inline void setFileHash( const QString& );
74   inline const QDateTime& lastModified() const;
75   inline void setLastModified( const QDateTime& );
76   inline bool isInShareBox() const;
77   inline void setIsInShareBox( bool );
78   inline const QString& chatPrivateId() const;
79   inline void setChatPrivateId( const QString& );
80   inline const QString& mimeType() const;
81   inline void setMimeType( const QString& );
82   inline ContentType contentType() const;
83   inline void setContentType( ContentType );
84   inline bool isVoiceMessage() const;
85   inline void setStartingPosition( FileSizeType );
86   inline FileSizeType startingPosition() const;
87   inline void setDuration( qint64 );
88   inline qint64 duration() const;
89 
90 private:
91   TransferType m_transferType;
92   QString m_name;
93   QString m_path;
94   QString m_suffix;
95   FileSizeType m_size;
96   QString m_shareFolder;
97   bool m_isFolder;
98   NetworkAddress m_networkAddress;
99   QByteArray m_password;
100   VNumber m_id;
101   QString m_fileHash;
102   QDateTime m_lastModified;
103   bool m_isInShareBox;
104   QString m_chatPrivateId;
105   QString m_mimeType;
106   ContentType m_contentType;
107   FileSizeType m_startingPosition;
108   qint64 m_duration;
109 
110 };
111 
112 typedef QPair<VNumber, FileInfo> SharedFileInfo;
113 
114 // Inline Functions
FileInfo(const FileInfo & fi)115 inline FileInfo::FileInfo( const FileInfo& fi ) { (void)operator=( fi ); }
116 inline bool FileInfo::operator==( const FileInfo& fi ) { return m_id == fi.m_id; }
117 inline bool operator==( const FileInfo& fi1, const FileInfo& fi2 ) { return fi1.id() == fi2.id(); }
isValid()118 inline bool FileInfo::isValid() const { return m_id != ID_INVALID && m_name.size() > 0; }
isDownload()119 inline bool FileInfo::isDownload() const { return m_transferType == FileInfo::Download; }
transferType()120 inline FileInfo::TransferType FileInfo::transferType() const { return m_transferType; }
setTransferType(FileInfo::TransferType new_value)121 inline void FileInfo::setTransferType( FileInfo::TransferType new_value ) { m_transferType = new_value; }
name()122 inline const QString& FileInfo::name() const { return m_name; }
setName(const QString & new_value)123 inline void FileInfo::setName( const QString& new_value ) { m_name = new_value; }
path()124 inline const QString& FileInfo::path() const { return m_path; }
setPath(const QString & new_value)125 inline void FileInfo::setPath( const QString& new_value ) { m_path = new_value; }
suffix()126 inline const QString& FileInfo::suffix() const { return m_suffix; }
setSuffix(const QString & new_value)127 inline void FileInfo::setSuffix( const QString& new_value ) { m_suffix = new_value.toLower(); }
size()128 inline FileSizeType FileInfo::size() const { return m_size; }
setSize(FileSizeType new_value)129 inline void FileInfo::setSize( FileSizeType new_value ) { m_size = new_value > 0 ? new_value : 0; }
shareFolder()130 inline const QString& FileInfo::shareFolder() const { return m_shareFolder; }
setShareFolder(const QString & new_value)131 inline void FileInfo::setShareFolder( const QString& new_value ) { m_shareFolder = new_value; }
isFolder()132 inline bool FileInfo::isFolder() const { return m_isFolder; }
setIsFolder(bool new_value)133 inline void FileInfo::setIsFolder( bool new_value ) { m_isFolder = new_value; }
setNetworkAddress(const NetworkAddress & new_value)134 inline void FileInfo::setNetworkAddress( const NetworkAddress& new_value ) { m_networkAddress = new_value; }
networkAddress()135 inline const NetworkAddress& FileInfo::networkAddress() const { return m_networkAddress; }
setHostAddress(const QHostAddress & new_value)136 inline void FileInfo::setHostAddress( const QHostAddress& new_value ) { m_networkAddress.setHostAddress( new_value ); }
setHostPort(quint16 new_value)137 inline void FileInfo::setHostPort( quint16 new_value ) { m_networkAddress.setHostPort( new_value ); }
password()138 inline const QByteArray& FileInfo::password() const { return m_password; }
setPassword(const QByteArray & new_value)139 inline void FileInfo::setPassword( const QByteArray& new_value ) { m_password = new_value; }
id()140 inline VNumber FileInfo::id() const { return m_id; }
setId(VNumber new_value)141 inline void FileInfo::setId( VNumber new_value ) { m_id = new_value; }
fileHash()142 inline const QString& FileInfo::fileHash() const { return m_fileHash; }
setFileHash(const QString & new_value)143 inline void FileInfo::setFileHash( const QString& new_value ) { m_fileHash = new_value; }
lastModified()144 inline const QDateTime& FileInfo::lastModified() const { return m_lastModified; }
setLastModified(const QDateTime & new_value)145 inline void FileInfo::setLastModified( const QDateTime& new_value ) { m_lastModified = new_value; }
isInShareBox()146 inline bool FileInfo::isInShareBox() const { return m_isInShareBox; }
setIsInShareBox(bool new_value)147 inline void FileInfo::setIsInShareBox( bool new_value ) { m_isInShareBox = new_value; }
chatPrivateId()148 inline const QString& FileInfo::chatPrivateId() const { return m_chatPrivateId; }
setChatPrivateId(const QString & new_value)149 inline void FileInfo::setChatPrivateId( const QString& new_value ) { m_chatPrivateId = new_value; }
mimeType()150 inline const QString& FileInfo::mimeType() const { return m_mimeType; }
setMimeType(const QString & new_value)151 inline void FileInfo::setMimeType( const QString& new_value ) { m_mimeType = new_value; }
contentType()152 inline FileInfo::ContentType FileInfo::contentType() const { return m_contentType; }
setContentType(ContentType new_value)153 inline void FileInfo::setContentType( ContentType new_value ) { m_contentType = new_value; }
isVoiceMessage()154 inline bool FileInfo::isVoiceMessage() const { return m_contentType == VoiceMessage; }
setStartingPosition(FileSizeType new_value)155 inline void FileInfo::setStartingPosition( FileSizeType new_value ) { m_startingPosition = new_value > 0 ? new_value : 0; }
startingPosition()156 inline FileSizeType FileInfo::startingPosition() const { return m_startingPosition; }
setDuration(qint64 new_value)157 inline void FileInfo::setDuration( qint64 new_value ) { m_duration = new_value; }
duration()158 inline qint64 FileInfo::duration() const { return m_duration; }
159 
160 #endif // BEEBEEP_FILEINFO_H
161