source: filezilla/trunk/fuentes/src/interface/QueueView.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: 9.2 KB
Line 
1#ifndef __QUEUEVIEW_H__
2#define __QUEUEVIEW_H__
3
4#include "dndobjects.h"
5#include "queue.h"
6
7#include <libfilezilla_engine.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        fz::datetime 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#elif defined(__WXGTK__) || defined(__WXMSW__)
114class wxNotificationMessage;
115#endif
116
117class CQueueView : public CQueueViewBase, public COptionChangeEventHandler
118{
119        friend class CFolderProcessingThread;
120        friend class CQueueViewDropTarget;
121        friend class CQueueViewFailed;
122public:
123        CQueueView(CQueue* parent, int index, CMainFrame* pMainFrame, CAsyncRequestQueue* pAsyncRequestQueue);
124        virtual ~CQueueView();
125
126        bool QueueFile(const bool queueOnly, const bool download,
127                const wxString& localFile, const wxString& remoteFile,
128                const CLocalPath& localPath, const CServerPath& remotePath,
129                const CServer& server, int64_t size, enum CEditHandler::fileType edit = CEditHandler::none,
130                QueuePriority priority = QueuePriority::normal);
131
132        void QueueFile_Finish(const bool start); // Need to be called after QueueFile
133        bool QueueFiles(const bool queueOnly, const CLocalPath& localPath, const CRemoteDataObject& dataObject);
134        int QueueFiles(const std::list<CFolderProcessingEntry*> &entryList, bool queueOnly, bool download, CServerItem* pServerItem, const CFileExistsNotification::OverwriteAction defaultFileExistsAction);
135        bool QueueFolder(bool queueOnly, bool download, const CLocalPath& localPath, const CServerPath& remotePath, const CServer& server);
136
137        bool empty() const;
138        int IsActive() const { return m_activeMode; }
139        bool SetActive(bool active = true);
140        bool Quit();
141
142        // This sets the default file exists action for all files currently in queue.
143        // This includes queued folders which are yet to be processed
144        void SetDefaultFileExistsAction(CFileExistsNotification::OverwriteAction action, const TransferDirection direction);
145
146        void UpdateItemSize(CFileItem* pItem, int64_t size);
147
148        void RemoveAll();
149
150        void LoadQueue();
151        void LoadQueueFromXML();
152        void ImportQueue(pugi::xml_node element, bool updateSelections);
153
154        virtual void InsertItem(CServerItem* pServerItem, CQueueItem* pItem);
155
156        virtual void CommitChanges();
157
158        void ProcessNotification(CFileZillaEngine* pEngine, std::unique_ptr<CNotification>&& pNotification);
159
160        void RenameFileInTransfer(CFileZillaEngine *pEngine, const wxString& newName, bool local);
161
162        static wxString ReplaceInvalidCharacters(const wxString& filename);
163
164        // Get the current download speed as the sum of all active downloads.
165        // Unit is byte/s.
166        wxFileOffset GetCurrentDownloadSpeed();
167
168        // Get the current upload speed as the sum of all active uploads.
169        // Unit is byte/s.
170        wxFileOffset GetCurrentUploadSpeed();
171
172protected:
173
174#ifdef __WXMSW__
175        WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
176#endif
177
178        virtual void OnOptionsChanged(changed_options_t const& options);
179
180        void AdvanceQueue(bool refresh = true);
181        bool TryStartNextTransfer();
182
183        // Called from TryStartNextTransfer(), checks
184        // whether it is allowed to start another transfer on that server item
185        bool CanStartTransfer(const CServerItem& server_item, struct t_EngineData *&pEngineData);
186
187        bool ProcessFolderItems(int type = -1);
188        void ProcessUploadFolderItems();
189
190        void ProcessReply(t_EngineData* pEngineData, COperationNotification const& notification);
191        void SendNextCommand(t_EngineData& engineData);
192
193        enum ResetReason
194        {
195                success,
196                failure,
197                reset,
198                retry,
199                remove
200        };
201
202        enum ActionAfterState GetActionAfterState() const;
203
204        void ResetEngine(t_EngineData& data, const enum ResetReason reason);
205        void DeleteEngines();
206
207        virtual bool RemoveItem(CQueueItem* item, bool destroy, bool updateItemCount = true, bool updateSelections = true, bool forward = true);
208
209        // Stops processing of given item
210        // Returns true on success, false if it would block
211        bool StopItem(CFileItem* item);
212        bool StopItem(CServerItem* pServerItem, bool updateSelections);
213
214        void CheckQueueState();
215        bool IncreaseErrorCount(t_EngineData& engineData);
216        void UpdateStatusLinePositions();
217        void CalculateQueueSize();
218        void DisplayQueueSize();
219        void SaveQueue();
220
221        bool IsActionAfter(enum ActionAfterState);
222        void ActionAfter(bool warned = false);
223#if defined(__WXMSW__) || defined(__WXMAC__)
224        void ActionAfterWarnUser(ActionAfterState s);
225#endif
226
227        void ProcessNotification(t_EngineData* pEngineData, std::unique_ptr<CNotification> && pNotification);
228
229        // Tries to refresh the current remote directory listing
230        // if there's an idle engine connected to the current server of
231        // the primary connection.
232        void TryRefreshListings();
233        CServer m_last_refresh_server;
234        CServerPath m_last_refresh_path;
235        fz::monotonic_clock m_last_refresh_listing_time;
236
237        // Called from Process Reply.
238        // After a disconnect, check if there's another idle engine that
239        // is already connected.
240        bool SwitchEngine(t_EngineData** ppEngineData);
241
242        bool IsOtherEngineConnected(t_EngineData* pEngineData);
243
244        t_EngineData* GetIdleEngine(const CServer* pServer = 0, bool allowTransient = false);
245        t_EngineData* GetEngineData(const CFileZillaEngine* pEngine);
246
247        std::vector<t_EngineData*> m_engineData;
248        std::list<CStatusLineCtrl*> m_statusLineList;
249
250        /*
251         * List of queued folders used to populate the queue.
252         * Index 0 for downloads, index 1 for uploads.
253         * For each type, only the first one can be active at any given time.
254         */
255        std::list<CFolderScanItem*> m_queuedFolders[2];
256
257        void RemoveQueuedFolderItem(CFolderScanItem* pFolder);
258
259        CFolderProcessingThread *m_pFolderProcessingThread{};
260
261        /*
262         * Don't update status line positions if m_waitStatusLineUpdate is true.
263         * This assures we are updating the status line positions only once,
264         * and not multiple times (for example inside a loop).
265         */
266        bool m_waitStatusLineUpdate;
267
268        // Remember last top item in UpdateStatusLinePositions()
269        int m_lastTopItem;
270
271        int m_activeCount;
272        int m_activeCountDown;
273        int m_activeCountUp;
274        int m_activeMode; // 0 inactive, 1 only immediate transfers, 2 all
275        int m_quit;
276
277        enum ActionAfterState m_actionAfterState;
278        wxString m_actionAfterRunCommand;
279#if defined(__WXMSW__) || defined(__WXMAC__)
280        wxTimer* m_actionAfterTimer{};
281        wxProgressDialog* m_actionAfterWarnDialog{};
282        int m_actionAfterTimerCount{};
283        int m_actionAfterTimerId{-1};
284#endif
285
286        int64_t m_totalQueueSize;
287        int m_filesWithUnknownSize;
288
289        CMainFrame* m_pMainFrame;
290        CAsyncRequestQueue* m_pAsyncRequestQueue;
291
292        std::list<CFileZillaEngine*> m_waitingForPassword;
293
294        virtual void OnPostScroll();
295
296        wxTimer m_folderscan_item_refresh_timer;
297
298        int GetLineHeight();
299        int m_line_height;
300#ifdef __WXMSW__
301        int m_header_height;
302#endif
303
304        wxTimer m_resize_timer;
305
306        void ReleaseExclusiveEngineLock(CFileZillaEngine* pEngine);
307
308#if WITH_LIBDBUS
309        std::unique_ptr<CDesktopNotification> m_desktop_notification;
310#elif defined(__WXGTK__) || defined(__WXMSW__)
311        std::unique_ptr<wxNotificationMessage> m_desktop_notification;
312#endif
313
314        CQueueStorage m_queue_storage;
315
316        // Get the current transfer speed.
317        // Unit is byte/s.
318        wxFileOffset GetCurrentSpeed(bool countDownload, bool countUpload);
319
320        DECLARE_EVENT_TABLE()
321        void OnEngineEvent(wxFzEvent &event);
322        void OnFolderThreadComplete(wxCommandEvent& event);
323        void OnFolderThreadFiles(wxCommandEvent& event);
324        void OnChar(wxKeyEvent& event);
325
326        // Context menu handlers
327        void OnContextMenu(wxContextMenuEvent& event);
328        void OnProcessQueue(wxCommandEvent& event);
329        void OnStopAndClear(wxCommandEvent& event);
330        void OnRemoveSelected(wxCommandEvent& event);
331        void OnSetDefaultFileExistsAction(wxCommandEvent& event);
332
333        void OnAskPassword(wxCommandEvent& event);
334        void OnTimer(wxTimerEvent& evnet);
335
336        void OnSetPriority(wxCommandEvent& event);
337
338        void OnExclusiveEngineRequestGranted(wxCommandEvent& event);
339
340        void OnActionAfter(wxCommandEvent& event);
341        void OnActionAfterTimerTick();
342
343        void OnSize(wxSizeEvent& event);
344};
345
346#endif
Note: See TracBrowser for help on using the repository browser.