Added confirmation dialog for file transfer operation.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@458 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/FTDialog.cxx b/vncviewer/FTDialog.cxx
index 5998a0f..b4c669d 100644
--- a/vncviewer/FTDialog.cxx
+++ b/vncviewer/FTDialog.cxx
@@ -492,20 +492,70 @@
FTDialog::onUpload()
{
FileInfo fi;
- if (m_pLocalLV->getSelectedItems(&fi) > 0) {
- m_pFileTransfer->addTransferQueue(m_szLocalPath, m_szRemotePath, &fi, FT_ATTR_COPY_UPLOAD);
+ char prefix[FT_FILENAME_SIZE];
+ prefix[0] = '\0';
+
+ if (m_pFileTransfer->isTransferEnable())
+ strcpy(prefix, "File Transfer is active.\nDo you want to add selected file(s)/folder(s) to transfer queue?\n\n");
+
+ int numSel = m_pLocalLV->getSelectedItems(&fi);
+ if (numSel > 0) {
+ char *pBuf = new char [(numSel + 4) * (MAX_PATH + 3) + strlen(prefix) + 1];
+ sprintf(pBuf, "%sFrom: Local Computer %s\\\n\n", prefix, m_szLocalPath);
+
+ for (unsigned int i = 0; i < fi.getNumEntries(); i++)
+ sprintf(pBuf, "%s%s, ", pBuf, fi.getNameAt(i));
+
+ sprintf(pBuf, "%s\n\nTo: Remote Computer %s\\", pBuf, m_szRemotePath);
+
+ if (strlen(pBuf) > 2048)
+ sprintf(pBuf, "%sFrom: Local Computer %s\\\n\nTo: Remote Computer %s\\\n\nTotal %d file(s)/folder(s)",
+ prefix, m_szLocalPath, m_szRemotePath, numSel);
+
+ if (MessageBox(m_hwndFTDialog, pBuf, "Copy Selected Files and Folders", MB_OKCANCEL) == IDOK)
+ m_pFileTransfer->addTransferQueue(m_szLocalPath, m_szRemotePath, &fi, FT_ATTR_COPY_UPLOAD);
+
+ delete [] pBuf;
+ return;
}
+
setButtonsState();
+ setStatusText("File Transfer Impossible. No file(s) selected for transfer");
}
void
FTDialog::onDownload()
{
FileInfo fi;
- if (m_pRemoteLV->getSelectedItems(&fi) > 0) {
- m_pFileTransfer->addTransferQueue(m_szLocalPath, m_szRemotePath, &fi, FT_ATTR_COPY_DOWNLOAD);
+ char prefix[FT_FILENAME_SIZE];
+ prefix[0] = '\0';
+
+ if (m_pFileTransfer->isTransferEnable())
+ strcpy(prefix, "File Transfer is active.\nDo you want to add selected file(s)/folder(s) to transfer queue?\n\n");
+
+ int numSel = m_pRemoteLV->getSelectedItems(&fi);
+ if (numSel > 0) {
+ char *pBuf = new char [(numSel + 4) * (MAX_PATH + 3) + strlen(prefix) + 1];
+ sprintf(pBuf, "%sFrom: Remote Computer %s\\\n\n", prefix, m_szRemotePath);
+
+ for (unsigned int i = 0; i < fi.getNumEntries(); i++)
+ sprintf(pBuf, "%s%s, ", pBuf, fi.getNameAt(i));
+
+ sprintf(pBuf, "%s\n\nTo: Local Computer %s\\", pBuf, m_szLocalPath);
+
+ if (strlen(pBuf) > 2048)
+ sprintf(pBuf, "%sFrom: Remote Computer %s\\\n\nTo: Local Computer %s\\\n\nTotal %d file(s)/folder(s)",
+ prefix, m_szRemotePath, m_szLocalPath, numSel);
+
+ if (MessageBox(m_hwndFTDialog, pBuf, "Copy Selected Files and Folders", MB_OKCANCEL) == IDOK)
+ m_pFileTransfer->addTransferQueue(m_szLocalPath, m_szRemotePath, &fi, FT_ATTR_COPY_DOWNLOAD);
+
+ delete [] pBuf;
+ return;
}
+
setButtonsState();
+ setStatusText("File Transfer Impossible. No file(s) selected for transfer");
}
void
diff --git a/vncviewer/FileTransfer.cxx b/vncviewer/FileTransfer.cxx
index bf7454e..32279d0 100644
--- a/vncviewer/FileTransfer.cxx
+++ b/vncviewer/FileTransfer.cxx
@@ -165,7 +165,10 @@
FileTransfer::addTransferQueue(char *pLocalPath, char *pRemotePath,
FileInfo *pFI, unsigned int flags)
{
- if ((m_bFTDlgShown) && (!isTransferEnable())) m_pFTDialog->setStatusText("Starting Copy Operation");
+ if (!isTransferEnable()) {
+ if (m_bFTDlgShown) m_pFTDialog->setStatusText("Starting Copy Operation");
+ m_bTransferSuccess = true;
+ }
m_TransferQueue.add(pLocalPath, pRemotePath, pFI, (flags | FT_ATTR_RESIZE_NEEDED));
@@ -221,7 +224,12 @@
m_pFTDialog->m_pProgress->clearAll();
m_dw64SizeSending = 0;
m_bResized = false;
- m_pFTDialog->setStatusText("File Transfer Operation Completed Successfully");
+
+ if (m_bTransferSuccess)
+ m_pFTDialog->setStatusText("File Transfer Operation Completed Successfully");
+ else
+ m_pFTDialog->setStatusText("File Transfer Operation Completed");
+
m_pFTDialog->afterCancelTransfer();
PostMessage(m_pFTDialog->getWndHandle(), WM_COMMAND, MAKEWPARAM(IDC_FTLOCALRELOAD, 0), 0);
PostMessage(m_pFTDialog->getWndHandle(), WM_COMMAND, MAKEWPARAM(IDC_FTREMOTERELOAD, 0), 0);
@@ -261,6 +269,7 @@
if (!fm.createDir(pLocPath)) {
if (m_bFTDlgShown) m_pFTDialog->setStatusText("Creating Local Folder Failed.");
+ m_bTransferSuccess = false;
m_TransferQueue.deleteAt(0);
m_pFTDialog->postCheckTransferQueueMsg();
return;
@@ -277,6 +286,7 @@
}
}
}
+ m_bTransferSuccess = false;
if (m_bFTDlgShown) m_pFTDialog->setStatusText("File Transfer Operation Failed. Unknown data in the transfer queue");
} // if (!isTransferEnable())
}
@@ -349,6 +359,7 @@
}
} else {
m_fileReader.close();
+ m_bTransferSuccess = false;
char reason[] = "Error While Reading File";
m_pWriter->writeFileUploadFailed(strlen(reason), reason);
if (m_bFTDlgShown) {
@@ -440,6 +451,7 @@
}
if ((!m_fileWriter.isCreated()) || (!isTransferEnable())) {
+ m_bTransferSuccess = false;
if (pFile != NULL) delete pFile;
return false;
}
@@ -449,6 +461,7 @@
m_fileWriter.write(pFile, bufSize, &bytesWritten);
delete pFile;
if (bytesWritten != bufSize) {
+ m_bTransferSuccess = false;
char reason[] = "Error File Writting to File";
m_pWriter->writeFileDownloadCancel(strlen(reason), reason);
if (m_bFTDlgShown) {
@@ -477,6 +490,7 @@
return true;
} else {
m_fileWriter.close();
+ m_bTransferSuccess = false;
char reason[] = "Error File Writting";
if (m_bFTDlgShown) {
m_pFTDialog->setStatusText("Download Failed");
@@ -546,6 +560,7 @@
} else {
if (flags & FT_ATTR_DIR) {
m_TransferQueue.deleteAt(0);
+ m_bTransferSuccess = false;
if (m_bFTDlgShown) m_pFTDialog->setStatusText("Create Remote Folder Failed.");
}
}
@@ -581,6 +596,7 @@
m_pFTDialog->postCheckTransferQueueMsg();
return true;
} else {
+ m_bTransferSuccess = false;
if (m_bFTDlgShown) m_pFTDialog->setStatusText("File Transfer Operation Failed: Unknown data from server.");
}
return false;
@@ -630,6 +646,7 @@
if (m_bFTDlgShown) m_pFTDialog->processDlgMsgs();
if (m_bCancel) {
endUndoneOperation();
+ m_bTransferSuccess = false;
if (m_bFTDlgShown) {
m_pFTDialog->setStatusText("All Operations Canceled");
}
diff --git a/vncviewer/FileTransfer.h b/vncviewer/FileTransfer.h
index 2c5d802..f62c2f9 100644
--- a/vncviewer/FileTransfer.h
+++ b/vncviewer/FileTransfer.h
@@ -73,6 +73,7 @@
bool m_bFTDlgShown;
bool m_bInitialized;
bool m_bResized;
+ bool m_bTransferSuccess;
FTDialog *m_pFTDialog;