bool CQueueViewFailed::RequeueFileItem(CFileItem* pFileItem, CServerItem* pServerItem) { CQueueView* pQueueView = m_pQueue->GetQueueView(); pFileItem->m_errorCount = 0; pFileItem->SetStatusMessage(CFileItem::none); if (!pFileItem->Download() && pFileItem->GetType() != QueueItemType::Folder && !wxFileName::FileExists(pFileItem->GetLocalPath().GetPath() + pFileItem->GetLocalFile())) { delete pFileItem; return false; } if (pFileItem->m_edit == CEditHandler::remote) { CEditHandler* pEditHandler = CEditHandler::Get(); if (!pEditHandler) { delete pFileItem; return false; } 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())) { delete pFileItem; return false; } pFileItem->SetTargetFile(file); } else if (state == CEditHandler::upload_and_remove_failed) { wxASSERT(!pFileItem->Download()); bool ret = true; if (!pEditHandler->UploadFile(pFileItem->GetRemoteFile(), pFileItem->GetRemotePath(), pServerItem->GetServer(), true)) ret = false; delete pFileItem; return ret; } else { delete pFileItem; return false; } } pFileItem->SetParent(pServerItem); pQueueView->InsertItem(pServerItem, pFileItem); return true; }
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); }
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.")); }
void CLocalListView::OnMenuEdit(wxCommandEvent& event) { CServer server; CServerPath path; if (!m_pState->GetServer()) { if (COptions::Get()->GetOptionVal(OPTION_EDIT_TRACK_LOCAL)) { wxMessageBoxEx(_("Cannot edit file, not connected to any server."), _("Editing failed"), wxICON_EXCLAMATION); return; } } else { server = *m_pState->GetServer(); path = m_pState->GetRemotePath(); if (path.IsEmpty()) { wxMessageBoxEx(_("Cannot edit file, remote path unknown."), _("Editing failed"), wxICON_EXCLAMATION); return; } } std::list<CLocalFileData> selected_item_list; long item = -1; while ((item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1) { if (!item && m_hasParent) { wxBell(); return; } const CLocalFileData *data = GetData(item); if (!data) continue; if (data->dir) { wxBell(); return; } if (data->flags == fill) continue; selected_item_list.push_back(*data); } CEditHandler* pEditHandler = CEditHandler::Get(); if (selected_item_list.empty()) { wxBell(); return; } if (selected_item_list.size() > 10) { CConditionalDialog dlg(this, CConditionalDialog::many_selected_for_edit, CConditionalDialog::yesno); dlg.SetTitle(_("Confirmation needed")); dlg.AddText(_("You have selected more than 10 files for editing, do you really want to continue?")); if (!dlg.Run()) return; } for (std::list<CLocalFileData>::const_iterator data = selected_item_list.begin(); data != selected_item_list.end(); ++data) { wxFileName fn(m_dir, data->name); bool dangerous = false; bool program_exists = false; wxString cmd = pEditHandler->CanOpen(CEditHandler::local, fn.GetFullPath(), dangerous, program_exists); if (cmd.empty()) { CNewAssociationDialog dlg(this); if (!dlg.Show(fn.GetFullName())) continue; cmd = pEditHandler->CanOpen(CEditHandler::local, fn.GetFullPath(), dangerous, program_exists); if (cmd.empty()) { wxMessageBoxEx(wxString::Format(_("The file '%s' could not be opened:\nNo program has been associated on your system with this file type."), fn.GetFullPath().c_str()), _("Opening failed"), wxICON_EXCLAMATION); continue; } } if (!program_exists) { wxString msg = wxString::Format(_("The file '%s' cannot be opened:\nThe associated program (%s) could not be found.\nPlease check your filetype associations."), fn.GetFullPath().c_str(), cmd.c_str()); wxMessageBoxEx(msg, _("Cannot edit file"), wxICON_EXCLAMATION); continue; } if (dangerous) { int res = wxMessageBoxEx(_("The selected file would be executed directly.\nThis can be dangerous and damage your system.\nDo you really want to continue?"), _("Dangerous filetype"), wxICON_EXCLAMATION | wxYES_NO); if (res != wxYES) { wxBell(); continue; } } CEditHandler::fileState state = pEditHandler->GetFileState(fn.GetFullPath()); switch (state) { case CEditHandler::upload: case CEditHandler::upload_and_remove: wxMessageBoxEx(_("A file with that name is already being transferred."), _("Cannot view/edit selected file"), wxICON_EXCLAMATION); continue; case CEditHandler::edit: { int res = wxMessageBoxEx(wxString::Format(_("A file with that name is already being edited. Do you want to reopen '%s'?"), fn.GetFullPath().c_str()), _("Selected file already being edited"), wxICON_QUESTION | wxYES_NO); if (res != wxYES) { wxBell(); continue; } pEditHandler->StartEditing(fn.GetFullPath()); continue; } default: break; } wxString file = fn.GetFullPath(); if (!pEditHandler->AddFile(CEditHandler::local, file, path, server)) { wxMessageBoxEx(wxString::Format(_("The file '%s' could not be opened:\nThe associated command failed"), fn.GetFullPath().c_str()), _("Opening failed"), wxICON_EXCLAMATION); continue; } } }