~ubuntu-branches/debian/sid/filezilla/sid

« back to all changes in this revision

Viewing changes to src/interface/state.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adrien Cunin
  • Date: 2009-11-15 17:15:41 UTC
  • mfrom: (1.3.5 upstream) (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091115171541-nvo6m3hl3iof0lnc
* New upstream release
* Updated previous changelog entry to mention desktop notifications as a new
  feature

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include "local_filesys.h"
12
12
#include "listingcomparison.h"
13
13
 
14
 
CContextManager the_context_manager;
 
14
CContextManager CContextManager::m_the_context_manager;
 
15
 
 
16
CContextManager::CContextManager()
 
17
{
 
18
        m_current_context = -1;
 
19
}
15
20
 
16
21
CContextManager* CContextManager::Get()
17
22
{
18
 
        return &the_context_manager;
 
23
        return &m_the_context_manager;
19
24
}
20
25
 
21
26
CState* CContextManager::CreateState(CMainFrame* pMainFrame)
26
31
 
27
32
        m_contexts.push_back(pState);
28
33
 
 
34
        NotifyHandlers(pState, STATECHANGE_NEWCONTEXT, _T(""), 0, false);
 
35
        if (m_current_context == -1)
 
36
        {
 
37
                m_current_context = 0;
 
38
                NotifyHandlers(pState, STATECHANGE_CHANGEDCONTEXT, _T(""), 0, false);
 
39
        }
 
40
 
29
41
        return pState;
30
42
}
31
43
 
41
53
                        m_current_context--;
42
54
                else if ((int)i == m_current_context)
43
55
                {
44
 
                        m_current_context--;
45
 
                        // TODO context change
 
56
                        if (i >= m_contexts.size())
 
57
                                m_current_context--;
 
58
                        NotifyHandlers(GetCurrentContext(), STATECHANGE_CHANGEDCONTEXT, _T(""), 0, false);
46
59
                }
47
60
 
48
61
                break;
49
62
        }
50
63
 
 
64
        NotifyHandlers(pState, STATECHANGE_REMOVECONTEXT, _T(""), 0, false);
51
65
        delete pState;
52
66
}
53
67
 
 
68
void CContextManager::SetCurrentContext(CState* pState)
 
69
{
 
70
        if (GetCurrentContext() == pState)
 
71
                return;
 
72
 
 
73
        for (unsigned int i = 0; i < m_contexts.size(); i++)
 
74
        {
 
75
                if (m_contexts[i] != pState)
 
76
                        continue;
 
77
 
 
78
                m_current_context = i;
 
79
                NotifyHandlers(GetCurrentContext(), STATECHANGE_CHANGEDCONTEXT, _T(""), 0, false);
 
80
        }
 
81
}
 
82
 
 
83
void CContextManager::DestroyAllStates()
 
84
{
 
85
        m_current_context = -1;
 
86
        NotifyHandlers(GetCurrentContext(), STATECHANGE_CHANGEDCONTEXT, _T(""), 0, false);
 
87
 
 
88
        while (!m_contexts.empty())
 
89
        {
 
90
                CState* pState = m_contexts.back();
 
91
                m_contexts.pop_back();
 
92
 
 
93
                NotifyHandlers(pState, STATECHANGE_REMOVECONTEXT, _T(""), 0, false);
 
94
                delete pState;
 
95
        }
 
96
}
 
97
 
54
98
void CContextManager::RegisterHandler(CStateEventHandler* pHandler, enum t_statechange_notifications notification, bool current_only, bool blockable)
55
99
{
56
100
        wxASSERT(pHandler);
115
159
                if (blocked && iter->blockable)
116
160
                        continue;
117
161
 
 
162
                if (iter->current_only && pState != GetCurrentContext())
 
163
                        continue;
 
164
 
118
165
                iter->pHandler->OnStateChange(pState, notification, data, data2);
119
166
        }
120
167
}
121
168
 
 
169
CState* CContextManager::GetCurrentContext()
 
170
{
 
171
        if (m_current_context == -1)
 
172
                return 0;
 
173
 
 
174
        return m_contexts[m_current_context];
 
175
}
 
176
 
 
177
void CContextManager::NotifyAllHandlers(enum t_statechange_notifications notification, const wxString& data /*=_T("")*/, const void* data2 /*=0*/)
 
178
{
 
179
        for (unsigned int i = 0; i < m_contexts.size(); i++)
 
180
                m_contexts[i]->NotifyHandlers(notification, data, data2);
 
181
}
 
182
 
 
183
void CContextManager::NotifyGlobalHandlers(enum t_statechange_notifications notification, const wxString& data /*=_T("")*/, const void* data2 /*=0*/)
 
184
{
 
185
        const std::list<t_handler> &handlers = m_handlers[notification];
 
186
        for (std::list<t_handler>::const_iterator iter = handlers.begin(); iter != handlers.end(); iter++)
 
187
                iter->pHandler->OnStateChange(0, notification, data, data2);
 
188
}
 
189
 
122
190
CState::CState(CMainFrame* pMainFrame)
123
191
{
124
192
        memset(m_blocked, 0, sizeof(m_blocked));
137
205
 
138
206
        m_sync_browse.is_changing = false;
139
207
        m_sync_browse.compare = false;
 
208
 
 
209
        m_localDir.SetPath(CLocalPath::path_separator);
140
210
}
141
211
 
142
212
CState::~CState()
266
336
                }
267
337
        }
268
338
        else
269
 
                COptions::Get()->SetOption(OPTION_LASTSERVERPATH, pDirectoryListing->path.GetSafePath());
 
339
                m_last_path = pDirectoryListing->path;
270
340
 
271
341
        if (m_pDirectoryListing && m_pDirectoryListing->path == pDirectoryListing->path &&
272
342
        pDirectoryListing->m_failed)
283
353
        else
284
354
                NotifyHandlers(STATECHANGE_REMOTE_DIR_MODIFIED);
285
355
 
286
 
        if (m_sync_browse.is_changing)
 
356
        if (m_sync_browse.is_changing && !modified)
287
357
        {
288
358
                m_sync_browse.is_changing = false;
289
359
                if (m_pDirectoryListing->path != m_sync_browse.remote_root && !m_pDirectoryListing->path.IsSubdirOf(m_sync_browse.remote_root, false))
391
461
{
392
462
        if (m_pServer)
393
463
        {
394
 
                if (server && *server == *m_pServer)
 
464
                if (server && *server == *m_pServer &&
 
465
                        server->GetName() == m_pServer->GetName() &&
 
466
                        server->MaximumMultipleConnections() == m_pServer->MaximumMultipleConnections())
395
467
                {
396
468
                        // Nothing changes
397
469
                        return;
401
473
                delete m_pServer;
402
474
        }
403
475
        if (server)
 
476
        {
 
477
                if (m_last_server != *server)
 
478
                        m_last_path.Clear();
 
479
                m_last_server = *server;
 
480
 
404
481
                m_pServer = new CServer(*server);
 
482
        }
405
483
        else
406
484
                m_pServer = 0;
407
485
 
415
493
        return m_pServer;
416
494
}
417
495
 
418
 
bool CState::Connect(const CServer& server, bool askBreak, const CServerPath& path /*=CServerPath()*/)
 
496
bool CState::Connect(const CServer& server, const CServerPath& path /*=CServerPath()*/)
419
497
{
420
498
        if (!m_pEngine)
421
499
                return false;
422
500
        if (m_pEngine->IsConnected() || m_pEngine->IsBusy() || !m_pCommandQueue->Idle())
423
 
        {
424
 
                if (askBreak)
425
 
                        if (wxMessageBox(_("Break current connection?"), _T("FileZilla"), wxYES_NO | wxICON_QUESTION) != wxYES)
426
 
                                return false;
427
501
                m_pCommandQueue->Cancel();
428
 
        }
 
502
        m_pRecursiveOperation->StopRecursiveOperation();
 
503
        SetSyncBrowse(false);
429
504
 
430
505
        m_pCommandQueue->ProcessCommand(new CConnectCommand(server));
431
506
        m_pCommandQueue->ProcessCommand(new CListCommand(path, _T(""), LIST_FLAG_FALLBACK_CURRENT));
432
507
 
433
 
        COptions::Get()->SetLastServer(server);
434
 
        COptions::Get()->SetOption(OPTION_LASTSERVERPATH, path.GetSafePath());
435
 
 
436
 
        const wxString& name = server.GetName();
437
 
        if (!name.IsEmpty())
438
 
                m_pMainFrame->SetTitle(name + _T(" - ") + server.FormatServer() + _T(" - FileZilla"));
439
 
        else
440
 
                m_pMainFrame->SetTitle(server.FormatServer() + _T(" - FileZilla"));
 
508
        SetServer(&server);
 
509
 
 
510
        return true;
 
511
}
 
512
 
 
513
bool CState::Disconnect()
 
514
{
 
515
        if (!m_pEngine)
 
516
                return false;
 
517
 
 
518
        if (!IsRemoteConnected())
 
519
                return true;
 
520
        
 
521
        if (!IsRemoteIdle())
 
522
                return false;
 
523
 
 
524
        SetServer(0);
 
525
        m_pCommandQueue->ProcessCommand(new CDisconnectCommand());
441
526
 
442
527
        return true;
443
528
}
451
536
        m_pEngine = new CFileZillaEngine();
452
537
        m_pEngine->Init(m_pMainFrame, COptions::Get());
453
538
 
454
 
        m_pCommandQueue = new CCommandQueue(m_pEngine, m_pMainFrame);
 
539
        m_pCommandQueue = new CCommandQueue(m_pEngine, m_pMainFrame, this);
455
540
 
456
541
        return true;
457
542
}
468
553
{
469
554
        wxASSERT(pHandler);
470
555
        wxASSERT(pHandler->m_pState == this);
 
556
        if (pHandler->m_pState != this)
 
557
                return;
471
558
        wxASSERT(notification != STATECHANGE_MAX && notification != STATECHANGE_NONE);
472
559
 
473
560
        std::list<t_handler> &handlers = m_handlers[notification];
562
649
}
563
650
 
564
651
CStateEventHandler::CStateEventHandler(CState* pState)
 
652
        : m_pState(pState)
565
653
{
566
 
        if (!pState)
567
 
                return;
568
 
 
569
 
        m_pState = pState;
570
654
}
571
655
 
572
656
CStateEventHandler::~CStateEventHandler()
783
867
                if (!iter->dir)
784
868
                        continue;
785
869
 
786
 
                m_pRecursiveOperation->AddDirectoryToVisit(pRemoteDataObject->GetServerPath(), iter->name, path.GetPath() + iter->name, iter->link);
 
870
                m_pRecursiveOperation->AddDirectoryToVisit(pRemoteDataObject->GetServerPath(), iter->name, path.GetPath() + CQueueView::ReplaceInvalidCharacters(iter->name), iter->link);
787
871
        }
788
872
 
789
873
        if (m_pComparisonManager->IsComparing())