source: filezilla/trunk/fuentes/src/interface/QueueView.h @ 130

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

First release to xenial

File size: 9.0 KB
Line 
1#ifndef __QUEUEVIEW_H__
2#define __QUEUEVIEW_H__
3
4#include "dndobjects.h"
5#include "queue.h"
6
7#include <libfilezilla.h>
8#include <option_change_event_handler.h>
9
10#include <set>
11#include <wx/progdlg.h>
12
13#include "queue_storage.h"
14
15class CFolderProcessingEntry
16{
17public:
18        enum t_type
19        {
20                dir,
21                file
22        };
23        const enum t_type m_type;
24
25        CFolderProcessingEntry(enum t_type type) : m_type(type) {}
26        virtual ~CFolderProcessingEntry() {}
27};
28
29class t_newEntry : public CFolderProcessingEntry
30{
31public:
32        t_newEntry()
33                : CFolderProcessingEntry(CFolderProcessingEntry::file)
34        {}
35
36        wxString name;
37        int64_t size{};
38        CDateTime time;
39        int attributes{};
40        bool dir{};
41};
42
43enum ActionAfterState
44{
45        ActionAfterState_Disabled,
46        ActionAfterState_Close,
47        ActionAfterState_Disconnect,
48        ActionAfterState_RunCommand,
49        ActionAfterState_ShowMessage,
50        ActionAfterState_PlaySound
51// On Windows and OS X, wx can reboot or shutdown the system as well.
52#if defined(__WXMSW__) || defined(__WXMAC__)
53        ,
54        ActionAfterState_Reboot,
55        ActionAfterState_Shutdown,
56        ActionAfterState_Sleep
57#endif
58};
59
60class CStatusLineCtrl;
61class CFileItem;
62struct t_EngineData
63{
64        t_EngineData()
65                : pEngine()
66                , active()
67                , transient()
68                , state(t_EngineData::none)
69                , pItem()
70                , pStatusLineCtrl()
71                , m_idleDisconnectTimer()
72        {
73        }
74
75        ~t_EngineData()
76        {
77                wxASSERT(!active);
78                if (!transient)
79                        delete pEngine;
80                delete m_idleDisconnectTimer;
81        }
82
83        CFileZillaEngine* pEngine;
84        bool active;
85        bool transient;
86
87        enum EngineDataState
88        {
89                none,
90                cancel,
91                disconnect,
92                connect,
93                transfer,
94                list,
95                mkdir,
96                askpassword,
97                waitprimary
98        } state;
99
100        CFileItem* pItem;
101        CServer lastServer;
102        CStatusLineCtrl* pStatusLineCtrl;
103        wxTimer* m_idleDisconnectTimer;
104};
105
106class CMainFrame;
107class CStatusLineCtrl;
108class CFolderProcessingThread;
109class CAsyncRequestQueue;
110class CQueue;
111#if WITH_LIBDBUS
112class CDesktopNotification;
113#endif
114
115class CQueueView : public CQueueViewBase, public COptionChangeEventHandler
116{
117        friend class CFolderProcessingThread;
118        friend class CQueueViewDropTarget;
119        friend class CQueueViewFailed;
120public:
121        CQueueView(CQueue* parent, int index, CMainFrame* pMainFrame, CAsyncRequestQueue* pAsyncRequestQueue);
122        virtual ~CQueueView();
123
124        bool QueueFile(const bool queueOnly, const bool download,
125                const wxString& localFile, const wxString& remoteFile,
126                const CLocalPath& localPath, const CServerPath& remotePath,
127                const CServer& server, int64_t size, enum CEditHandler::fileType edit = CEditHandler::none,
128                QueuePriority priority = QueuePriority::normal);
129
130        void QueueFile_Finish(const bool start); // Need to be called after QueueFile
131        bool QueueFiles(const bool queueOnly, const CLocalPath& localPath, const CRemoteDataObject& dataObject);
132        int QueueFiles(const std::list<CFolderProcessingEntry*> &entryList, bool queueOnly, bool download, CServerItem* pServerItem, const CFileExistsNotification::OverwriteAction defaultFileExistsAction);
133        bool QueueFolder(bool queueOnly, bool download, const CLocalPath& localPath, const CServerPath& remotePath, const CServer& server);
134
135        bool empty() const;
136        int IsActive() const { return m_activeMode; }
137        bool SetActive(bool active = true);
138        bool Quit();
139
140        // This sets the default file exists action for all files currently in queue.
141        // This includes queued folders which are yet to be processed
142        void SetDefaultFileExistsAction(CFileExistsNotification::OverwriteAction action, const TransferDirection direction);
143
144        void UpdateItemSize(CFileItem* pItem, int64_t size);
145
146        void RemoveAll();
147
148        void LoadQueue();
149        void LoadQueueFromXML();
150        void ImportQueue(pugi::xml_node element, bool updateSelections);
151
152        virtual void InsertItem(CServerItem* pServerItem, CQueueItem* pItem);
153
154        virtual void CommitChanges();
155
156        void ProcessNotification(CFileZillaEngine* pEngine, std::unique_ptr<CNotification>&& pNotification);
157
158        void RenameFileInTransfer(CFileZillaEngine *pEngine, const wxString& newName, bool local);
159
160        static wxString ReplaceInvalidCharacters(const wxString& filename);
161
162        // Get the current download speed as the sum of all active downloads.
163        // Unit is byte/s.
164        wxFileOffset GetCurrentDownloadSpeed();
165
166        // Get the current upload speed as the sum of all active uploads.
167        // Unit is byte/s.
168        wxFileOffset GetCurrentUploadSpeed();
169
170protected:
171
172#ifdef __WXMSW__
173        WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
174#endif
175
176        virtual void OnOptionsChanged(changed_options_t const& options);
177
178        void AdvanceQueue(bool refresh = true);
179        bool TryStartNextTransfer();
180
181        // Called from TryStartNextTransfer(), checks
182        // whether it is allowed to start another transfer on that server item
183        bool CanStartTransfer(const CServerItem& server_item, struct t_EngineData *&pEngineData);
184
185        bool ProcessFolderItems(int type = -1);
186        void ProcessUploadFolderItems();
187
188        void ProcessReply(t_EngineData* pEngineData, COperationNotification const& notification);
189        void SendNextCommand(t_EngineData& engineData);
190
191        enum ResetReason
192        {
193                success,
194                failure,
195                reset,
196                retry,
197                remove
198        };
199
200        enum ActionAfterState GetActionAfterState() const;
201
202        void ResetEngine(t_EngineData& data, const enum ResetReason reason);
203        void DeleteEngines();
204
205        virtual bool RemoveItem(CQueueItem* item, bool destroy, bool updateItemCount = true, bool updateSelections = true, bool forward = true);
206
207        // Stops processing of given item
208        // Returns true on success, false if it would block
209        bool StopItem(CFileItem* item);
210        bool StopItem(CServerItem* pServerItem, bool updateSelections);
211
212        void CheckQueueState();
213        bool IncreaseErrorCount(t_EngineData& engineData);
214        void UpdateStatusLinePositions();
215        void CalculateQueueSize();
216        void DisplayQueueSize();
217        void SaveQueue();
218
219        bool IsActionAfter(enum ActionAfterState);
220        void ActionAfter(bool warned = false);
221#if defined(__WXMSW__) || defined(__WXMAC__)
222        void ActionAfterWarnUser(ActionAfterState s);
223#endif
224
225        void ProcessNotification(t_EngineData* pEngineData, std::unique_ptr<CNotification> && pNotification);
226
227        // Tries to refresh the current remote directory listing
228        // if there's an idle engine connected to the current server of
229        // the primary connection.
230        void TryRefreshListings();
231        CServer m_last_refresh_server;
232        CServerPath m_last_refresh_path;
233        CMonotonicClock m_last_refresh_listing_time;
234
235        // Called from Process Reply.
236        // After a disconnect, check if there's another idle engine that
237        // is already connected.
238        bool SwitchEngine(t_EngineData** ppEngineData);
239
240        bool IsOtherEngineConnected(t_EngineData* pEngineData);
241
242        t_EngineData* GetIdleEngine(const CServer* pServer = 0, bool allowTransient = false);
243        t_EngineData* GetEngineData(const CFileZillaEngine* pEngine);
244
245        std::vector<t_EngineData*> m_engineData;
246        std::list<CStatusLineCtrl*> m_statusLineList;
247
248        /*
249         * List of queued folders used to populate the queue.
250         * Index 0 for downloads, index 1 for uploads.
251         * For each type, only the first one can be active at any given time.
252         */
253        std::list<CFolderScanItem*> m_queuedFolders[2];
254
255        void RemoveQueuedFolderItem(CFolderScanItem* pFolder);
256
257        CFolderProcessingThread *m_pFolderProcessingThread;
258
259        /*
260         * Don't update status line positions if m_waitStatusLineUpdate is true.
261         * This assures we are updating the status line positions only once,
262         * and not multiple times (for example inside a loop).
263         */
264        bool m_waitStatusLineUpdate;
265
266        // Remember last top item in UpdateStatusLinePositions()
267        int m_lastTopItem;
268
269        int m_activeCount;
270        int m_activeCountDown;
271        int m_activeCountUp;
272        int m_activeMode; // 0 inactive, 1 only immediate transfers, 2 all
273        int m_quit;
274
275        enum ActionAfterState m_actionAfterState;
276        wxString m_actionAfterRunCommand;
277#if defined(__WXMSW__) || defined(__WXMAC__)
278        wxTimer* m_actionAfterTimer{};
279        wxProgressDialog* m_actionAfterWarnDialog{};
280        int m_actionAfterTimerCount{};
281        int m_actionAfterTimerId{-1};
282#endif
283
284        int64_t m_totalQueueSize;
285        int m_filesWithUnknownSize;
286
287        CMainFrame* m_pMainFrame;
288        CAsyncRequestQueue* m_pAsyncRequestQueue;
289
290        std::list<CFileZillaEngine*> m_waitingForPassword;
291
292        virtual void OnPostScroll();
293
294        wxTimer m_folderscan_item_refresh_timer;
295
296        int GetLineHeight();
297        int m_line_height;
298#ifdef __WXMSW__
299        int m_header_height;
300#endif
301
302        wxTimer m_resize_timer;
303
304        void ReleaseExclusiveEngineLock(CFileZillaEngine* pEngine);
305
306#if WITH_LIBDBUS
307        CDesktopNotification* m_desktop_notification;
308#endif
309
310        CQueueStorage m_queue_storage;
311
312        // Get the current transfer speed.
313        // Unit is byte/s.
314        wxFileOffset GetCurrentSpeed(bool countDownload, bool countUpload);
315
316        DECLARE_EVENT_TABLE()
317        void OnEngineEvent(wxFzEvent &event);
318        void OnFolderThreadComplete(wxCommandEvent& event);
319        void OnFolderThreadFiles(wxCommandEvent& event);
320        void OnChar(wxKeyEvent& event);
321
322        // Context menu handlers
323        void OnContextMenu(wxContextMenuEvent& event);
324        void OnProcessQueue(wxCommandEvent& event);
325        void OnStopAndClear(wxCommandEvent& event);
326        void OnRemoveSelected(wxCommandEvent& event);
327        void OnSetDefaultFileExistsAction(wxCommandEvent& event);
328
329        void OnAskPassword(wxCommandEvent& event);
330        void OnTimer(wxTimerEvent& evnet);
331
332        void OnSetPriority(wxCommandEvent& event);
333
334        void OnExclusiveEngineRequestGranted(wxCommandEvent& event);
335
336        void OnActionAfter(wxCommandEvent& event);
337        void OnActionAfterTimerTick();
338
339        void OnSize(wxSizeEvent& event);
340};
341
342#endif
Note: See TracBrowser for help on using the repository browser.