Debian Codegraph @

CodeLite/cl_sftp_attribute.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2013 by Eran Ifrah
5 // file name : cl_sftp_attribute.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25 #ifndef SFTPATTRIBUTE_H
26 #define SFTPATTRIBUTE_H
27
28 #if USE_SFTP
29
30 #include "codelite_exports.h"
31 #include "smart_ptr.h"
32 #include <list>
33 #include <wx/clntdata.h>
34 #include <wx/filename.h>
35
36 // We do it this way to avoid exposing the include to <libssh/sftp.h> to files including this header
37 struct sftp_attributes_struct;
38 typedef struct sftp_attributes_struct* SFTPAttribute_t;
39
40 class WXDLLIMPEXP_CL SFTPAttribute : public wxClientData
41 {
42 wxString m_name;
43 size_t m_flags;
44 size_t m_size;
45 SFTPAttribute_t m_attributes = nullptr;
46 size_t m_permissions = 0;
47 wxString m_symlinkPath; // incase this file represents a symlink, this member will hold the target path
48
49 public:
50 typedef SmartPtr<SFTPAttribute> Ptr_t;
51 typedef std::list<SFTPAttribute::Ptr_t> List_t;
52
53 enum {
54 TYPE_FOLDER = 0x00000001,
55 TYPE_SYMBLINK = 0x00000002,
56 TYPE_REGULAR_FILE = 0x00000004,
57 TYPE_SEPCIAL = 0x00000008,
58 TYPE_UNKNOWN = 0x00000010,
59 };
60
61 protected:
62 void DoClear();
63 void DoConstruct();
64
65 public:
66 SFTPAttribute(SFTPAttribute_t attr);
67 virtual ~SFTPAttribute();
68
69 bool IsOk() const { return m_attributes != nullptr; }
70 static bool Compare(SFTPAttribute::Ptr_t one, SFTPAttribute::Ptr_t two);
71 /**
72 * @brief assign this object with attributes.
73 * This object takes ownership of the attributes and it will free it when done
74 * @param attr
75 */
76 void Assign(SFTPAttribute_t attr);
77
78 size_t GetSize() const { return m_size; }
79 wxString GetTypeAsString() const;
80 const wxString& GetName() const { return m_name; }
81
82 bool IsFolder() const { return m_flags & TYPE_FOLDER; }
83
84 bool IsFile() const { return m_flags & TYPE_REGULAR_FILE; }
85
86 bool IsSymlink() const { return m_flags & TYPE_SYMBLINK; }
87
88 bool IsSpecial() const { return m_flags & TYPE_SEPCIAL; }
89 void SetPermissions(size_t permissions) { this->m_permissions = permissions; }
90 size_t GetPermissions() const { return m_permissions; }
91
92 void SetSymlinkPath(const wxString& symlinkPath) { this->m_symlinkPath = symlinkPath; }
93 const wxString& GetSymlinkPath() const { return m_symlinkPath; }
94
95 void SetFile()
96 {
97 m_flags &= ~TYPE_FOLDER;
98 m_flags |= TYPE_REGULAR_FILE;
99 }
100 void SetFolder()
101 {
102 m_flags &= ~TYPE_REGULAR_FILE;
103 m_flags |= TYPE_FOLDER;
104 }
105 };
106 #endif
107 #endif // SFTPATTRIBUTE_H