Пример #1
0
bool CServerItem::TryRemoveAll()
{
    wxASSERT(!GetParent());

    const int oldVisibleOffspring = m_visibleOffspring;
    std::vector<CQueueItem*>::iterator iter;
    std::vector<CQueueItem*> keepChildren;
    m_visibleOffspring = 0;
    for (iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); ++iter) {
        CQueueItem* pItem = *iter;
        if (pItem->TryRemoveAll()) {
            if (pItem->GetType() == QueueItemType::File || pItem->GetType() == QueueItemType::Folder) {
                CFileItem* pFileItem = static_cast<CFileItem*>(pItem);
                RemoveFileItemFromList(pFileItem, true);
            }
            delete pItem;
        }
        else {
            keepChildren.push_back(pItem);
            m_visibleOffspring++;
            m_visibleOffspring += pItem->GetChildrenCount(true);
        }
    }
    std::swap(m_children, keepChildren);
    m_removed_at_front = 0;

    m_maxCachedIndex = -1;

    wxASSERT(oldVisibleOffspring >= m_visibleOffspring);
    wxASSERT(m_visibleOffspring >= static_cast<int>(m_children.size()));
    (void)oldVisibleOffspring;

    return m_children.empty();
}
Пример #2
0
void CServerItem::SetDefaultFileExistsAction(CFileExistsNotification::OverwriteAction action, const TransferDirection direction)
{
	for (auto iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); ++iter) {
		CQueueItem *pItem = *iter;
		if (pItem->GetType() == QueueItemType::File) {
			CFileItem* pFileItem = ((CFileItem *)pItem);
			if (direction == TransferDirection::upload && pFileItem->Download())
				continue;
			else if (direction == TransferDirection::download && !pFileItem->Download())
				continue;
			pFileItem->m_defaultFileExistsAction = action;
		}
		else if (pItem->GetType() == QueueItemType::FolderScan) {
			if (direction == TransferDirection::download)
				continue;
			((CFolderScanItem *)pItem)->m_defaultFileExistsAction = action;
		}
	}
}
Пример #3
0
void CServerItem::SetDefaultFileExistsAction(enum CFileExistsNotification::OverwriteAction action, const enum TransferDirection direction)
{
	for (std::vector<CQueueItem*>::iterator iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); iter++)
	{
		CQueueItem *pItem = *iter;
		if (pItem->GetType() == QueueItemType_File)
		{
			CFileItem* pFileItem = ((CFileItem *)pItem);
			if (direction == upload && pFileItem->Download())
				continue;
			else if (direction == download && !pFileItem->Download())
				continue;
			pFileItem->m_defaultFileExistsAction = action;
		}
		else if (pItem->GetType() == QueueItemType_FolderScan)
		{
			if (direction == download)
				continue;
			((CFolderScanItem *)pItem)->m_defaultFileExistsAction = action;
		}
	}
}
Пример #4
0
bool CServerItem::TryRemoveAll()
{
	const int oldVisibleOffspring = m_visibleOffspring;
	std::vector<CQueueItem*>::iterator iter;
	std::vector<CQueueItem*> keepChildren;
	m_visibleOffspring = 0;
	for (iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); iter++)
	{
		CQueueItem* pItem = *iter;
		if (pItem->TryRemoveAll())
		{
			if (pItem->GetType() == QueueItemType_File || pItem->GetType() == QueueItemType_Folder)
			{
				CFileItem* pFileItem = reinterpret_cast<CFileItem*>(pItem);
				RemoveFileItemFromList(pFileItem);
			}
			delete pItem;
		}
		else
		{
			keepChildren.push_back(pItem);
			m_visibleOffspring++;
			m_visibleOffspring += pItem->GetChildrenCount(true);
		}
	}
	m_children = keepChildren;
	m_removed_at_front = 0;

	CQueueItem* parent = GetParent();
	while (parent)
	{
		parent->m_visibleOffspring -= oldVisibleOffspring - m_visibleOffspring;
		parent = parent->GetParent();
	}

	return m_children.empty();
}
Пример #5
0
void CQueueItem::AddChild(CQueueItem* item)
{
    wxASSERT(GetType() != QueueItemType::Folder);
    wxASSERT(GetType() != QueueItemType::Status);

    if (m_removed_at_front) {
        m_children.erase(m_children.begin(), m_children.begin() + m_removed_at_front);
        m_removed_at_front = 0;
    }
    m_children.push_back(item);

    CQueueItem* parent = GetParent();
    while (parent) {
        if (parent->GetType() == QueueItemType::Server) {
            static_cast<CServerItem*>(parent)->m_visibleOffspring += 1 + item->GetChildrenCount(true);
            static_cast<CServerItem*>(parent)->m_maxCachedIndex = -1;
        }
        parent = parent->GetParent();
    }
}
Пример #6
0
int CQueueViewBase::OnGetItemImage(long item) const
{
    CQueueViewBase* pThis = const_cast<CQueueViewBase*>(this);

    CQueueItem* pItem = pThis->GetQueueItem(item);
    if (!pItem)
        return -1;

    switch (pItem->GetType())
    {
    case QueueItemType::Server:
        return 0;
    case QueueItemType::File:
        return 1;
    case QueueItemType::Folder:
        return 2;
    default:
        return -1;
    }

    return -1;
}
Пример #7
0
void CQueueViewFailed::OnRemoveSelected(wxCommandEvent& event)
{
#ifndef __WXMSW__
	// GetNextItem is O(n) if nothing is selected, GetSelectedItemCount() is O(1)
	if (!GetSelectedItemCount())
		return;
#endif

	std::list<CQueueItem*> selectedItems;
	long item = -1;
	while (true)
	{
		item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
		if (item == -1)
			break;

		selectedItems.push_front(GetQueueItem(item));
		SetItemState(item, 0, wxLIST_STATE_SELECTED);
	}

	CEditHandler* pEditHandler = CEditHandler::Get();

	while (!selectedItems.empty())
	{
		CQueueItem* pItem = selectedItems.front();
		selectedItems.pop_front();

		CQueueItem* pTopLevelItem = pItem->GetTopLevelItem();

		if (pItem->GetType() == QueueItemType_Server)
		{
			CServerItem* pServerItem = (CServerItem*)pItem;
			if (pEditHandler && pEditHandler->GetFileCount(CEditHandler::remote, CEditHandler::upload_and_remove_failed, &pServerItem->GetServer()))
				pEditHandler->RemoveAll(CEditHandler::upload_and_remove_failed, &pServerItem->GetServer());
		}
		else if (pItem->GetType() == QueueItemType_File)
		{
			CFileItem* pFileItem = (CFileItem*)pItem;
			if (pFileItem->m_edit == CEditHandler::remote && pEditHandler)
			{
				wxFileName fn(pFileItem->GetLocalFile());
				if (pFileItem->m_edit == CEditHandler::local)
				{
					enum CEditHandler::fileState state = pEditHandler->GetFileState(pFileItem->GetLocalFile());
					if (state == CEditHandler::upload_and_remove_failed)
						pEditHandler->Remove(pFileItem->GetLocalFile());
				}
				else
				{
					CServerItem* pServerItem = (CServerItem*)pFileItem->GetTopLevelItem();
					enum CEditHandler::fileState state = pEditHandler->GetFileState(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer());
					if (state == CEditHandler::upload_and_remove_failed)
						pEditHandler->Remove(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer());
				}
			}
		}

		if (!pTopLevelItem->GetChild(1))
		{
			// Parent will get deleted
			// If next selected item is parent, remove it from list
			if (!selectedItems.empty() && selectedItems.front() == pTopLevelItem)
				selectedItems.pop_front();
		}
		RemoveItem(pItem, true, false, false);
	}
	DisplayNumberQueuedFiles();
	SaveSetItemCount(m_itemCount);
	RefreshListOnly();

	if (!m_itemCount && m_pQueue->GetQueueView()->GetItemCount())
		m_pQueue->SetSelection(0);
}
Пример #8
0
void CQueueViewFailed::OnRequeueSelected(wxCommandEvent& event)
{
#ifndef __WXMSW__
	// GetNextItem is O(n) if nothing is selected, GetSelectedItemCount() is O(1)
	if (!GetSelectedItemCount())
		return;
#endif

	bool failedToRequeueAll = false;
	std::list<CQueueItem*> selectedItems;
	long item = -1;
	long skipTo = -1;
	while (true)
	{
		item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
		if (item == -1)
			break;
		SetItemState(item, 0, wxLIST_STATE_SELECTED);
		if (item < skipTo)
			continue;

		CQueueItem* pItem = GetQueueItem(item);
		if (pItem->GetType() == QueueItemType_Server)
			skipTo = item + pItem->GetChildrenCount(true) + 1;
		selectedItems.push_back(GetQueueItem(item));
	}

	if (selectedItems.empty())
		return;

	CQueueView* pQueueView = m_pQueue->GetQueueView();

	while (!selectedItems.empty())
	{
		CQueueItem* pItem = selectedItems.front();
		selectedItems.pop_front();

		if (pItem->GetType() == QueueItemType_Server)
		{
			CServerItem* pOldServerItem = (CServerItem*)pItem;
			CServerItem* pServerItem = pQueueView->CreateServerItem(pOldServerItem->GetServer());

			unsigned int childrenCount = pOldServerItem->GetChildrenCount(false);
			for (unsigned int i = 0; i < childrenCount; i++)
			{
				CFileItem* pFileItem = (CFileItem*)pItem->GetChild(i, false);
				pFileItem->m_errorCount = 0;
				pFileItem->m_statusMessage.Clear();

				if (!pFileItem->Download() && !wxFileName::FileExists(pFileItem->GetLocalFile()))
				{
					failedToRequeueAll = true;
					RemoveItem(pItem, true, false, false);
					continue;
				}

				if (pFileItem->m_edit == CEditHandler::remote)
				{
					CEditHandler* pEditHandler = CEditHandler::Get();
					if (!pEditHandler)
					{
						failedToRequeueAll = true;
						delete pFileItem;
						continue;
					}
					enum CEditHandler::fileState state = pEditHandler->GetFileState(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer());
					if (state == CEditHandler::unknown)
					{
						wxASSERT(pFileItem->Download());
						wxString file = pFileItem->GetRemoteFile();
						if (!pEditHandler->AddFile(CEditHandler::remote, file, pFileItem->GetRemotePath(), pServerItem->GetServer()))
						{
							failedToRequeueAll = true;
							delete pFileItem;
							continue;
						}
						pFileItem->SetLocalFile(file);
					}
					else if (state == CEditHandler::upload_and_remove_failed)
					{
						wxASSERT(!pFileItem->Download());
						if (!pEditHandler->UploadFile(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer(), true))
							failedToRequeueAll = true;
						delete pFileItem;
						continue;
					}
					else
					{
						failedToRequeueAll = true;
						delete pFileItem;
						continue;
					}
				}

				pFileItem->SetParent(pServerItem);
				pQueueView->InsertItem(pServerItem, pFileItem);
			}

			m_fileCount -= childrenCount;
			m_itemCount -= childrenCount + 1;
			pOldServerItem->DetachChildren();
			delete pOldServerItem;

			std::vector<CServerItem*>::iterator iter;
			for (iter = m_serverList.begin(); iter != m_serverList.end(); iter++)
			{
				if (*iter == pOldServerItem)
					break;
			}
			if (iter != m_serverList.end())
				m_serverList.erase(iter);

			if (!pServerItem->GetChildrenCount(false))
			{
				pQueueView->CommitChanges();
				pQueueView->RemoveItem(pServerItem, true, true, true);
			}
		}
		else
		{
			CFileItem* pFileItem = (CFileItem*)pItem;
			pFileItem->m_errorCount = 0;
			pFileItem->m_statusMessage.Clear();

			if (!pFileItem->Download() && !wxFileName::FileExists(pFileItem->GetLocalFile()))
			{
				failedToRequeueAll = true;
				RemoveItem(pItem, true, false, false);
				continue;
			}

			CServerItem* pOldServerItem = (CServerItem*)pItem->GetTopLevelItem();
			CServerItem* pServerItem = pQueueView->CreateServerItem(pOldServerItem->GetServer());
			RemoveItem(pItem, false, false, false);

			if (pFileItem->m_edit == CEditHandler::remote)
			{
				CEditHandler* pEditHandler = CEditHandler::Get();
				if (!pEditHandler)
				{
					if (!pServerItem->GetChildrenCount(false))
					{
						pQueueView->CommitChanges();
						pQueueView->RemoveItem(pServerItem, true, true, true);
					}

					failedToRequeueAll = true;
					delete pItem;
					continue;
				}
				enum CEditHandler::fileState state = pEditHandler->GetFileState(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer());
				if (state == CEditHandler::unknown)
				{
					wxASSERT(pFileItem->Download());
					wxString file = pFileItem->GetRemoteFile();
					if (!pEditHandler->AddFile(CEditHandler::remote, file, pFileItem->GetRemotePath(), pServerItem->GetServer()))
					{
						if (!pServerItem->GetChildrenCount(false))
						{
							pQueueView->CommitChanges();
							pQueueView->RemoveItem(pServerItem, true, true, true);
						}

						failedToRequeueAll = true;
						delete pItem;
						continue;
					}
					pFileItem->SetLocalFile(file);
				}
				else if (state == CEditHandler::upload_and_remove_failed)
				{
					wxASSERT(!pFileItem->Download());
					if (!pEditHandler->UploadFile(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer(), true))
						failedToRequeueAll = true;

					if (!pServerItem->GetChildrenCount(false))
					{
						pQueueView->CommitChanges();
						pQueueView->RemoveItem(pServerItem, true, true, true);
					}

					delete pItem;
					continue;
				}
				else
				{
					if (!pServerItem->GetChildrenCount(false))
					{
						pQueueView->CommitChanges();
						pQueueView->RemoveItem(pServerItem, true, true, true);
					}

					failedToRequeueAll = true;
					delete pItem;
					continue;
				}
			}

			pItem->SetParent(pServerItem);
			pQueueView->InsertItem(pServerItem, pItem);
		}
	}
	m_fileCountChanged = true;

	pQueueView->CommitChanges();

	if (pQueueView->IsActive())
		pQueueView->AdvanceQueue(false);
	
	DisplayNumberQueuedFiles();
	SaveSetItemCount(m_itemCount);
	RefreshListOnly();

	if (!m_itemCount && m_pQueue->GetQueueView()->GetItemCount())
		m_pQueue->SetSelection(0);

	if (failedToRequeueAll)
		wxMessageBox(_("Not all items could be requeued for viewing/editing."));
}
Пример #9
0
wxString CQueueViewBase::OnGetItemText(long item, long column) const
{
	CQueueViewBase* pThis = const_cast<CQueueViewBase*>(this);

	CQueueItem* pItem = pThis->GetQueueItem(item);
	if (!pItem)
		return _T("");

	switch (pItem->GetType())
	{
	case QueueItemType_Server:
		{
			CServerItem* pServerItem = reinterpret_cast<CServerItem*>(pItem);
			if (!column)
				return pServerItem->GetName();
		}
		break;
	case QueueItemType_File:
		{
			CFileItem* pFileItem = reinterpret_cast<CFileItem*>(pItem);
			switch (column)
			{
			case 0:
				return pFileItem->GetIndent() + pFileItem->GetLocalFile();
			case 1:
				if (pFileItem->Download())
					if (pFileItem->Queued())
						return _T("<--");
					else
						return _T("<<--");
				else
					if (pFileItem->Queued())
						return _T("-->");
					else
						return _T("-->>");
				break;
			case 2:
				return pFileItem->GetRemotePath().FormatFilename(pFileItem->GetRemoteFile());
			case 3:
				{
					const wxLongLong& size = pFileItem->GetSize();
					if (size >= 0)
						return FormatSize(size);
					else
						return _T("?");
				}
			case 4:
				switch (pFileItem->GetPriority())
				{
				case 0:
					return _("Lowest");
				case 1:
					return _("Low");
				default:
				case 2:
					return _("Normal");
				case 3:
					return _("High");
				case 4:
					return _("Highest");
				}
				break;
			case 5:
				return pFileItem->m_statusMessage;
			default:
				break;
			}
		}
		break;
	case QueueItemType_FolderScan:
		{
			CFolderScanItem* pFolderItem = reinterpret_cast<CFolderScanItem*>(pItem);
			switch (column)
			{
			case 0:
				return _T("  ") + pFolderItem->GetLocalPath();
			case 1:
				if (pFolderItem->Download())
					if (pFolderItem->Queued())
						return _T("<--");
					else
						return _T("<<--");
				else
					if (pFolderItem->Queued())
						return _T("-->");
					else
						return _T("-->>");
				break;
			case 2:
				return pFolderItem->GetRemotePath().GetPath();
			case 5:
				return pFolderItem->m_statusMessage;
			default:
				break;
			}
		}
		break;
	case QueueItemType_Folder:
		{
			CFileItem* pFolderItem = reinterpret_cast<CFolderItem*>(pItem);
			switch (column)
			{
			case 0:
				if (pFolderItem->Download())
					return pFolderItem->GetIndent() + pFolderItem->GetLocalFile();
				break;
			case 1:
				if (pFolderItem->Download())
					if (pFolderItem->Queued())
						return _T("<--");
					else
						return _T("<<--");
				else
					if (pFolderItem->Queued())
						return _T("-->");
					else
						return _T("-->>");
				break;
			case 2:
				if (!pFolderItem->Download())
				{
					if (pFolderItem->GetRemoteFile() == _T(""))
						return pFolderItem->GetRemotePath().GetPath();
					else
						return pFolderItem->GetRemotePath().FormatFilename(pFolderItem->GetRemoteFile());
				}
				break;
			case 4:
				switch (pFolderItem->GetPriority())
				{
				case 0:
					return _("Lowest");
				case 1:
					return _("Low");
				default:
				case 2:
					return _("Normal");
				case 3:
					return _("High");
				case 4:
					return _("Highest");
				}
				break;
			case 5:
				return pFolderItem->m_statusMessage;
			default:
				break;
			}
		}
		break;
	default:
		break;
	}

	return _T("");
}
Пример #10
0
void CQueueViewFailed::OnRequeueSelected(wxCommandEvent&)
{
#ifndef __WXMSW__
	// GetNextItem is O(n) if nothing is selected, GetSelectedItemCount() is O(1)
	if (!GetSelectedItemCount())
		return;
#endif

	bool failedToRequeueAll = false;
	std::list<CQueueItem*> selectedItems;
	long item = -1;
	long skipTo = -1;
	for (;;) {
		item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
		if (item == -1)
			break;
		SetItemState(item, 0, wxLIST_STATE_SELECTED);
		if (item < skipTo)
			continue;

		CQueueItem* pItem = GetQueueItem(item);
		if (pItem->GetType() == QueueItemType::Server)
			skipTo = item + pItem->GetChildrenCount(true) + 1;
		selectedItems.push_back(GetQueueItem(item));
	}

	if (selectedItems.empty())
		return;

	CQueueView* pQueueView = m_pQueue->GetQueueView();

	while (!selectedItems.empty()) {
		CQueueItem* pItem = selectedItems.front();
		selectedItems.pop_front();

		if (pItem->GetType() == QueueItemType::Server) {
			CServerItem* pServerItem = (CServerItem*)pItem;
			failedToRequeueAll |= !RequeueServerItem(pServerItem);
		}
		else {
			CFileItem* pFileItem = (CFileItem*)pItem;

			CServerItem* pOldServerItem = (CServerItem*)pItem->GetTopLevelItem();
			CServerItem* pServerItem = pQueueView->CreateServerItem(pOldServerItem->GetServer());
			RemoveItem(pItem, false, false, false);

			failedToRequeueAll |= !RequeueFileItem(pFileItem, pServerItem);

			if (!pServerItem->GetChildrenCount(false)) {
				pQueueView->CommitChanges();
				pQueueView->RemoveItem(pServerItem, true, true, true);
			}
		}
	}
	m_fileCountChanged = true;

	pQueueView->CommitChanges();

	if (pQueueView->IsActive())
		pQueueView->AdvanceQueue(false);

	DisplayNumberQueuedFiles();
	SaveSetItemCount(m_itemCount);
	RefreshListOnly();

	if (!m_itemCount && m_pQueue->GetQueueView()->GetItemCount())
		m_pQueue->SetSelection(0);

	if (failedToRequeueAll)
		wxMessageBoxEx(_("Not all items could be requeued for transfer."));
}
Пример #11
0
bool CQueueItem::RemoveChild(CQueueItem* pItem, bool destroy, bool forward)
{
    int const oldVisibleOffspring = GetChildrenCount(true);
    int visibleOffspring = oldVisibleOffspring;

    bool deleted = false;

    auto doRemove = [&](std::vector<CQueueItem*>::iterator iter) {
        if (*iter == pItem) {
            visibleOffspring -= 1;
            visibleOffspring -= pItem->GetChildrenCount(true);
            if (destroy)
                delete pItem;

            if (iter - m_children.begin() - m_removed_at_front <= 10) {
                ++m_removed_at_front;
                unsigned int end = iter - m_children.begin();
                int c = 0;
                for (int i = end; i >= m_removed_at_front; i--, c++)
                    m_children[i] = m_children[i - 1];
            }
            else
                m_children.erase(iter);

            deleted = true;
            return;
        }

        int childVisibleOffspring = (*iter)->GetChildrenCount(true);
        if ((*iter)->RemoveChild(pItem, destroy)) {
            visibleOffspring -= childVisibleOffspring - (*iter)->GetChildrenCount(true);
            if (!((*iter)->m_children.size() - (*iter)->m_removed_at_front)) {
                visibleOffspring -= 1;
                delete *iter;

                if (iter - m_children.begin() - m_removed_at_front <= 10) {
                    ++m_removed_at_front;
                    unsigned int end = iter - m_children.begin();
                    for (int i = end; i >= m_removed_at_front; i--)
                        m_children[i] = m_children[i - 1];
                }
                else
                    m_children.erase(iter);
            }

            deleted = true;
        }
    };

    if (forward) {
        for (auto iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); ++iter ) {
            doRemove(iter);
            if (deleted) {
                break;
            }
        }
    }
    else {
        for (auto iter = m_children.rbegin(); iter != m_children.rend() - m_removed_at_front; ++iter ) {
            doRemove(iter.base() - 1);
            if (deleted) {
                break;
            }
        }
    }

    if (!deleted)
        return false;

    if (GetType() == QueueItemType::Server) {
        static_cast<CServerItem*>(this)->m_visibleOffspring = visibleOffspring;
    }

    // Propagate new children count to parent
    CQueueItem* parent = GetParent();
    while (parent) {
        if (parent->GetType() == QueueItemType::Server) {
            static_cast<CServerItem*>(parent)->m_maxCachedIndex = -1;
            static_cast<CServerItem*>(parent)->m_visibleOffspring -= oldVisibleOffspring - visibleOffspring;
        }
        parent = parent->GetParent();
    }

    return true;
}