Esempio n. 1
0
void CContextControl::CreateTab()
{
	wxGetApp().AddStartupProfileRecord(_T("CContextControl::CreateTab"));
	Freeze();

	CState* pState = 0;

	// See if we can reuse an existing context
	for (size_t i = 0; i < m_context_controls.size(); i++)
	{
		if (m_context_controls[i].tab_index != -1)
			continue;

		if (m_context_controls[i].pState->IsRemoteConnected() ||
			!m_context_controls[i].pState->IsRemoteIdle())
			continue;

		pState = m_context_controls[i].pState;
		m_context_controls.erase(m_context_controls.begin() + i);
		if (m_current_context_controls > (int)i)
			m_current_context_controls--;
		break;
	}
	if (!pState)
	{
		pState = CContextManager::Get()->CreateState(m_pMainFrame);
		if (!pState->CreateEngine())
		{
			wxMessageBoxEx(_("Failed to initialize FTP engine"));
		}
	}

	// Restore last server and path
	CServer last_server;
	CServerPath last_path;
	if (COptions::Get()->GetLastServer(last_server) && last_path.SetSafePath(COptions::Get()->GetOption(OPTION_LASTSERVERPATH)))
		pState->SetLastServer(last_server, last_path);

	CreateContextControls(pState);

	pState->GetRecursiveOperationHandler()->SetQueue(m_pMainFrame->GetQueue());

	wxString localDir = COptions::Get()->GetOption(OPTION_LASTLOCALDIR);
	if (!pState->SetLocalDir(localDir))
		pState->SetLocalDir(_T("/"));

	CContextManager::Get()->SetCurrentContext(pState);

	if (!m_pMainFrame->RestoreSplitterPositions())
		m_pMainFrame->SetDefaultSplitterPositions();

	if (m_tabs)
		m_tabs->SetSelection(m_tabs->GetPageCount() - 1);

	Thaw();
}
Esempio n. 2
0
bool CContextControl::CloseTab(int tab)
{
	if (!m_tabs)
		return false;
	if (tab < 0)
		return false;

	size_t i = 0;
	for (i = 0; i < m_context_controls.size(); i++)
	{
		if (m_context_controls[i].tab_index == tab)
			break;
	}
	if (i == m_context_controls.size())
		return false;

	CState* pState = m_context_controls[i].pState;

	if (!pState->m_pCommandQueue->Idle())
	{
		if (wxMessageBoxEx(_("Cannot close tab while busy.\nCancel current operation and close tab?"), _T("FileZilla"), wxYES_NO | wxICON_QUESTION) != wxYES)
			return false;
	}

#ifndef __WXMAC__
	// Some reparenting is being done when closing tabs. Reparenting of frozen windows isn't working
	// on OS X.
	wxWindowUpdateLocker lock(this);
#endif

	pState->m_pCommandQueue->Cancel();
	pState->GetRecursiveOperationHandler()->StopRecursiveOperation();

	pState->GetComparisonManager()->SetListings(0, 0);

	if (m_tabs->GetPageCount() == 2)
	{
		// Get rid again of tab bar
		m_tabs->Disconnect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(CContextControl::OnTabChanged), 0, this);

		int keep = tab ? 0 : 1;
		m_tabs->RemovePage(keep);

		size_t j;
		for (j = 0; j < m_context_controls.size(); j++)
		{
			if (m_context_controls[j].tab_index != keep)
				continue;

			break;
		}

		m_context_controls[j].pViewSplitter->Reparent(this);
		ReplaceWindow(m_tabs, m_context_controls[j].pViewSplitter);
		m_context_controls[j].pViewSplitter->Show();
		m_context_controls[j].tab_index = 0;

		wxAuiNotebookEx *tabs = m_tabs;
		m_tabs = 0;

		m_context_controls[i].tab_index = -1;
		m_context_controls[i].site_bookmarks.reset();

		CContextManager::Get()->SetCurrentContext(m_context_controls[j].pState);

		tabs->Destroy();
	}
	else
	{
		if (pState == CContextManager::Get()->GetCurrentContext())
		{
			int newsel = tab + 1;
			if (newsel >= (int)m_tabs->GetPageCount())
				newsel = m_tabs->GetPageCount() - 2;

			for (size_t j = 0; j < m_context_controls.size(); j++)
			{
				if (m_context_controls[j].tab_index != newsel)
					continue;
				m_tabs->SetSelection(newsel);
				CContextManager::Get()->SetCurrentContext(m_context_controls[j].pState);
			}
		}
		for (size_t j = 0; j < m_context_controls.size(); j++)
		{
			if (m_context_controls[j].tab_index > tab)
				m_context_controls[j].tab_index--;
		}
		m_context_controls[i].tab_index = -1;
		m_context_controls[i].site_bookmarks.reset();
		m_tabs->DeletePage(tab);
	}

	pState->Disconnect();

	return true;
}
Esempio n. 3
0
void CClearPrivateDataDialog::Show()
{
	if (!Load(m_pMainFrame, _T("ID_CLEARPRIVATEDATA")))
		return;

	if (ShowModal() != wxID_OK)
		return;

	wxCheckBox *pSitemanagerCheck = XRCCTRL(*this, "ID_CLEARSITEMANAGER", wxCheckBox);
	wxCheckBox *pQueueCheck = XRCCTRL(*this, "ID_CLEARQUEUE", wxCheckBox);
	if (pSitemanagerCheck->GetValue() && pQueueCheck->GetValue())
	{
		int res = wxMessageBox(_("Do you really want to delete all Site Manager entries and the transfer queue?"), _("Clear private data"), wxYES | wxNO | wxICON_QUESTION);
		if (res != wxYES)
			return;
	}
	else if (pQueueCheck->GetValue())
	{
		int res = wxMessageBox(_("Do you really want to delete the transfer queue?"), _("Clear private data"), wxYES | wxNO | wxICON_QUESTION);
		if (res != wxYES)
			return;
	}
	else if (pSitemanagerCheck->GetValue())
	{
		int res = wxMessageBox(_("Do you really want to delete all Site Manager entries?"), _("Clear private data"), wxYES | wxNO | wxICON_QUESTION);
		if (res != wxYES)
			return;
	}

	wxCheckBox *pCheck = XRCCTRL(*this, "ID_CLEARQUICKCONNECT", wxCheckBox);
	if (!pCheck)
		return;

	if (pCheck->GetValue())
	{
		CRecentServerList::Clear();
		if (m_pMainFrame->GetQuickconnectBar())
			m_pMainFrame->GetQuickconnectBar()->ClearFields();
	}

	pCheck = XRCCTRL(*this, "ID_CLEARRECONNECT", wxCheckBox);

	if (pCheck->GetValue())
	{
		bool asked = false;

		const std::vector<CState*> *states = CContextManager::Get()->GetAllStates();

		for (std::vector<CState*>::const_iterator iter = states->begin(); iter != states->end(); ++iter)
		{
			CState* pState = *iter;
			if (pState->IsRemoteConnected() || !pState->IsRemoteIdle())
			{
				if (!asked)
				{
					int res = wxMessageBox(_("Reconnect information cannot be cleared while connected to a server.\nIf you continue, your connection will be disconnected."), _("Clear private data"), wxOK | wxCANCEL);
					if (res != wxOK)
						return;
					asked = true;
				}

				pState->GetRecursiveOperationHandler()->StopRecursiveOperation();
				if (!pState->m_pCommandQueue->Cancel())
				{
					m_timer.SetOwner(this);
					m_timer.Start(250, true);
				}
				else
					pState->Disconnect();
			}
		}

		// Doesn't harm to do it now, but has to be repeated later just to be safe
		ClearReconnect();
	}

	if (pSitemanagerCheck->GetValue())
	{
		CInterProcessMutex sitemanagerMutex(MUTEX_SITEMANAGERGLOBAL, false);
		while (sitemanagerMutex.TryLock() == 0)
		{
			int res = wxMessageBox(_("The Site Manager is opened in another instance of FileZilla 3.\nPlease close it or the data cannot be deleted."), _("Clear private data"), wxOK | wxCANCEL);
			if (res != wxYES)
				return;
		}
		CInterProcessMutex mutex(MUTEX_SITEMANAGER);
		RemoveXmlFile(_T("sitemanager"));
	}

	if (pQueueCheck->GetValue())
	{
		m_pMainFrame->GetQueue()->SetActive(false);
		m_pMainFrame->GetQueue()->RemoveAll();

		CInterProcessMutex mutex(MUTEX_QUEUE);
		RemoveXmlFile(_T("queue"));
	}
}