source: filezilla/trunk/fuentes/src/interface/state.h @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 3 years ago

Update new version: 3.15.02

File size: 7.4 KB
Line 
1#ifndef __STATE_H__
2#define __STATE_H__
3
4#include "local_path.h"
5
6#include <memory>
7
8enum t_statechange_notifications
9{
10        STATECHANGE_NONE, // Used to unregister all notifications
11
12        STATECHANGE_REMOTE_DIR,
13        STATECHANGE_REMOTE_DIR_OTHER,
14        STATECHANGE_REMOTE_RECV,
15        STATECHANGE_REMOTE_SEND,
16        STATECHANGE_REMOTE_LINKNOTDIR,
17        STATECHANGE_LOCAL_DIR,
18
19        // data contains name (excluding path) of file to refresh
20        STATECHANGE_LOCAL_REFRESH_FILE,
21
22        STATECHANGE_APPLYFILTER,
23
24        STATECHANGE_REMOTE_IDLE,
25        STATECHANGE_SERVER,
26        STATECHANGE_ENCRYPTION,
27
28        STATECHANGE_SYNC_BROWSE,
29        STATECHANGE_COMPARISON,
30
31        STATECHANGE_RECURSION_STATUS,
32
33        /* Global notifications */
34        STATECHANGE_QUEUEPROCESSING,
35        STATECHANGE_NEWCONTEXT, /* New context created */
36        STATECHANGE_CHANGEDCONTEXT, /* Currently active context changed */
37        STATECHANGE_REMOVECONTEXT, /* Right before deleting a context */
38
39        STATECHANGE_MAX
40};
41
42class CDirectoryListing;
43class CFileZillaEngine;
44class CCommandQueue;
45class CMainFrame;
46class CStateEventHandler;
47class CRemoteDataObject;
48class CRecursiveOperation;
49class CComparisonManager;
50
51class CState;
52class CContextManager final
53{
54        friend class CState;
55public:
56        // If current_only is set, only notifications from the current (at the time
57        // of notification emission) context is dispatched to the handler.
58        void RegisterHandler(CStateEventHandler* pHandler, enum t_statechange_notifications notification, bool current_only);
59        void UnregisterHandler(CStateEventHandler* pHandler, enum t_statechange_notifications notification);
60
61        size_t HandlerCount(enum t_statechange_notifications notification) const;
62
63        CState* CreateState(CMainFrame &mainFrame);
64        void DestroyState(CState* pState);
65        void DestroyAllStates();
66
67        CState* GetCurrentContext();
68        const std::vector<CState*>* GetAllStates() { return &m_contexts; }
69
70        static CContextManager* Get();
71
72        void NotifyAllHandlers(enum t_statechange_notifications notification, const wxString& data = _T(""), const void* data2 = 0);
73        void NotifyGlobalHandlers(enum t_statechange_notifications notification, const wxString& data = _T(""), const void* data2 = 0);
74
75        void SetCurrentContext(CState* pState);
76
77protected:
78        CContextManager();
79
80        std::vector<CState*> m_contexts;
81        int m_current_context;
82
83        struct t_handler
84        {
85                CStateEventHandler* pHandler;
86                bool current_only;
87        };
88        std::vector<t_handler> m_handlers[STATECHANGE_MAX];
89
90        void NotifyHandlers(CState* pState, enum t_statechange_notifications notification, const wxString& data, const void* data2);
91
92        static CContextManager m_the_context_manager;
93};
94
95class CState final
96{
97        friend class CCommandQueue;
98public:
99        CState(CMainFrame& mainFrame);
100        ~CState();
101
102        CState(CState const&) = delete;
103        CState& operator=(CState const&) = delete;
104
105        bool CreateEngine();
106        void DestroyEngine();
107
108        CLocalPath GetLocalDir() const;
109        bool SetLocalDir(CLocalPath const& dir, wxString *error = 0, bool rememberPreviousSubdir = true);
110        bool SetLocalDir(const wxString& dir, wxString *error = 0, bool rememberPreviousSubdir = true);
111
112        bool Connect(const CServer& server, const CServerPath& path = CServerPath());
113        bool Disconnect();
114
115        bool ChangeRemoteDir(const CServerPath& path, const wxString& subdir = _T(""), int flags = 0, bool ignore_busy = false);
116        bool SetRemoteDir(std::shared_ptr<CDirectoryListing> const& pDirectoryListing, bool modified = false);
117        std::shared_ptr<CDirectoryListing> GetRemoteDir() const;
118        const CServerPath GetRemotePath() const;
119
120        const CServer* GetServer() const;
121        wxString GetTitle() const;
122
123        void RefreshLocal();
124        void RefreshLocalFile(wxString file);
125        void LocalDirCreated(const CLocalPath& path);
126
127        bool RefreshRemote();
128
129        void RegisterHandler(CStateEventHandler* pHandler, enum t_statechange_notifications notification, CStateEventHandler* insertBefore = 0);
130        void UnregisterHandler(CStateEventHandler* pHandler, enum t_statechange_notifications notification);
131
132        CFileZillaEngine* m_pEngine{};
133        CCommandQueue* m_pCommandQueue{};
134        CComparisonManager* GetComparisonManager() { return m_pComparisonManager; }
135
136        void UploadDroppedFiles(const wxFileDataObject* pFileDataObject, const wxString& subdir, bool queueOnly);
137        void UploadDroppedFiles(const wxFileDataObject* pFileDataObject, const CServerPath& path, bool queueOnly);
138        void HandleDroppedFiles(const wxFileDataObject* pFileDataObject, const CLocalPath& path, bool copy);
139        bool DownloadDroppedFiles(const CRemoteDataObject* pRemoteDataObject, const CLocalPath& path, bool queueOnly = false);
140
141        static bool RecursiveCopy(CLocalPath source, const CLocalPath& targte);
142
143        bool IsRemoteConnected() const;
144        bool IsRemoteIdle(bool ignore_recursive = false) const;
145
146        CRecursiveOperation* GetRecursiveOperationHandler() { return m_pRecursiveOperation; }
147
148        void NotifyHandlers(enum t_statechange_notifications notification, wxString const& data = wxString(), const void* data2 = 0);
149
150        bool SuccessfulConnect() const { return m_successful_connect; }
151        void SetSuccessfulConnect() { m_successful_connect = true; }
152
153        void ListingFailed(int error);
154        void LinkIsNotDir(const CServerPath& path, const wxString& subdir);
155
156        bool SetSyncBrowse(bool enable, const CServerPath& assumed_remote_root = CServerPath());
157        bool GetSyncBrowse() const { return !m_sync_browse.local_root.empty(); }
158
159        CServer GetLastServer() const { return m_last_server; }
160        CServerPath GetLastServerPath() const { return m_last_path; }
161        void SetLastServer(const CServer& server, const CServerPath& path)
162        { m_last_server = server; m_last_path = path; }
163
164        bool GetSecurityInfo(CCertificateNotification *& pInfo);
165        bool GetSecurityInfo(CSftpEncryptionNotification *& pInfo);
166        void SetSecurityInfo(CCertificateNotification const& info);
167        void SetSecurityInfo(CSftpEncryptionNotification const& info);
168
169        // If the previously selected directory was a direct child of the current directory, this
170        // returns the relative name of the subdirectory.
171        wxString GetPreviouslyVisitedLocalSubdir() const { return m_previouslyVisitedLocalSubdir; }
172        wxString GetPreviouslyVisitedRemoteSubdir() const { return m_previouslyVisitedRemoteSubdir; }
173        void ClearPreviouslyVisitedLocalSubdir() { m_previouslyVisitedLocalSubdir = _T(""); }
174        void ClearPreviouslyVisitedRemoteSubdir() { m_previouslyVisitedRemoteSubdir = _T(""); }
175
176protected:
177        void SetServer(const CServer* server, CServerPath const& path = CServerPath());
178
179        CLocalPath m_localDir;
180        std::shared_ptr<CDirectoryListing> m_pDirectoryListing;
181
182        CServer* m_pServer{};
183        wxString m_title;
184        bool m_successful_connect{};
185
186        CServer m_last_server;
187        CServerPath m_last_path;
188
189        CMainFrame& m_mainFrame;
190
191        CRecursiveOperation* m_pRecursiveOperation;
192
193        CComparisonManager* m_pComparisonManager;
194
195        struct t_handler
196        {
197                CStateEventHandler* pHandler;
198        };
199        std::vector<t_handler> m_handlers[STATECHANGE_MAX];
200
201        CLocalPath GetSynchronizedDirectory(CServerPath remote_path);
202        CServerPath GetSynchronizedDirectory(CLocalPath local_path);
203
204        struct _sync_browse
205        {
206                CLocalPath local_root;
207                CServerPath remote_root;
208                bool is_changing;
209                bool compare;
210
211                // The target path when changing remote directory
212                CServerPath target_path;
213        } m_sync_browse;
214
215        std::unique_ptr<CCertificateNotification> m_pCertificate;
216        std::unique_ptr<CSftpEncryptionNotification> m_pSftpEncryptionInfo;
217
218        wxString m_previouslyVisitedLocalSubdir;
219        wxString m_previouslyVisitedRemoteSubdir;
220};
221
222class CStateEventHandler
223{
224public:
225        CStateEventHandler(CState* pState);
226        virtual ~CStateEventHandler();
227
228        CState* m_pState;
229
230        virtual void OnStateChange(CState* pState, enum t_statechange_notifications notification, const wxString& data, const void* data2) = 0;
231};
232
233#endif
Note: See TracBrowser for help on using the repository browser.