Esempio n. 1
0
int QueueWindow::PushQueueItem(QueueOperation * op) {
	QueueOperation::QueueType type = op->GetType();
	if (!ValidType(type))
		return -1;

	LVITEM lvi;
	lvi.mask = LVIF_TEXT | LVIF_PARAM;
	lvi.iItem = GetNrItems();
	lvi.iSubItem = 0;
	lvi.lParam = (LPARAM)op;
	lvi.pszText = (TCHAR*)(type==QueueOperation::QueueTypeDownload||type==QueueOperation::QueueTypeDownloadHandle?TEXT("Download"):TEXT("Upload"));

	int index = ListView_InsertItem(m_hwnd,  &lvi);
	if (index == -1)
		return -1;

	ListView_SetItemText(m_hwnd, index, 1, TEXT("0.0%") );

	TCHAR * path = NULL;
	if (type == QueueOperation::QueueTypeDownload) {
		QueueDownload * qdld = (QueueDownload*)op;
		path = SU::Utf8ToTChar(qdld->GetExternalPath());
	} else if (type == QueueOperation::QueueTypeDownloadHandle) {
		QueueDownloadHandle * qdld = (QueueDownloadHandle*)op;
		path = SU::Utf8ToTChar(qdld->GetExternalPath());
	} else if (type == QueueOperation::QueueTypeUpload) {
		QueueUpload * quld = (QueueUpload*)op;
		path = SU::Utf8ToTChar(quld->GetExternalPath());
	}

	ListView_SetItemText(m_hwnd, index, 2, path );
	SU::FreeTChar(path);

	return 0;
}
Esempio n. 2
0
int FTPWindow::OnEvent(QueueOperation * queueOp, int code, void * data, bool isStart) {
	int result = 0;
	void * queueData = queueOp->GetData();
	int queueResult = queueOp->GetResult();

	//Set busy parameter
	switch(queueOp->GetType()) {
		case QueueOperation::QueueTypeDownload:
		case QueueOperation::QueueTypeDownloadHandle:
		case QueueOperation::QueueTypeUpload: {
			m_busy = isStart;
			break; }
		case QueueOperation::QueueTypeConnect:
		case QueueOperation::QueueTypeDisconnect:
		case QueueOperation::QueueTypeDirectoryGet:
		case QueueOperation::QueueTypeDirectoryCreate:
		case QueueOperation::QueueTypeDirectoryRemove:
		case QueueOperation::QueueTypeFileCreate:
		case QueueOperation::QueueTypeFileDelete:
		case QueueOperation::QueueTypeFileRename:
		case QueueOperation::QueueTypeQuote:
		default: {
			//Other operations cannot be aborted
			break; }
	}

	//TODO: properly handle failures, like with getdir
	//Perform GUI operations
	switch(queueOp->GetType()) {
		case QueueOperation::QueueTypeConnect: {
			m_connecting = isStart;
			if (isStart) {
				SetInfo(TEXT("Connecting"));
				OutMsg("Connecting");
			} else {
				if (queueOp->GetResult() != -1) {
					OnConnect(code);
					OutMsg("Connected");
				} else {
					OutErr("Unable to connect");
					OnDisconnect(code);
					m_ftpSession->TerminateSession();
					result = 1;
				}
			}
			break; }
		case QueueOperation::QueueTypeDisconnect: {
			if (isStart) {
				break;
			}
			OutMsg("Disconnected");
			OnDisconnect(code);
			result = 1;
			break; }
		case QueueOperation::QueueTypeDirectoryGet: {
			QueueGetDir * dirop = (QueueGetDir*)queueOp;
			if (isStart) {
				break;
			}

            std::vector<FTPDir*> parentDirObjs = dirop->GetParentDirObjs();
            size_t i;

            for (i=0; i<parentDirObjs.size(); i++) {
                FTPDir* curFTPDir = parentDirObjs[i];

                FileObject* parent;
                parent = m_ftpSession->FindPathObject(curFTPDir->dirPath);
                if (parent)
                    OnDirectoryRefresh(parent, curFTPDir->files, curFTPDir->count);
            }

			if (queueResult == -1) {
				OutErr("Failure retrieving contents of directory %s", dirop->GetDirPath());
				//break commented: even if failed, update the treeview etc., count should result in 0 anyway
				//break;	//failure
			}
			FTPFile* files = (FTPFile*)queueData;
			int count = dirop->GetFileCount();
			FileObject* parent = m_ftpSession->FindPathObject(dirop->GetDirPath());
			if (parent)
				OnDirectoryRefresh(parent, files, count);
			break; }
		case QueueOperation::QueueTypeDownloadHandle:
		case QueueOperation::QueueTypeDownload: {
			QueueDownload * opdld = (QueueDownload*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Download of %s failed", opdld->GetExternalPath());
				OnError(queueOp, code, data, isStart);
				break;	//failure
			}

			if (queueOp->GetType() == QueueOperation::QueueTypeDownload) {
				if (code == 0) {
					//Download to cache: Open file
					OutMsg("Download of %s succeeded, opening file.", opdld->GetExternalPath());
					::SendMessage(m_hNpp, NPPM_DOOPEN, (WPARAM)0, (LPARAM)opdld->GetLocalPath());
					::SendMessage(m_hNpp, NPPM_RELOADFILE, (WPARAM)0, (LPARAM)opdld->GetLocalPath());
				} else {
					//Download to other location: Ask
					int ret = ::MessageBox(m_hNpp, TEXT("The download is complete. Do you wish to open the file?"), TEXT("Download complete"), MB_YESNO);
					if (ret == IDYES) {
						::SendMessage(m_hNpp, NPPM_DOOPEN, (WPARAM)0, (LPARAM)opdld->GetLocalPath());
						::SendMessage(m_hNpp, NPPM_RELOADFILE, (WPARAM)0, (LPARAM)opdld->GetLocalPath());
					}
				}
			} else {
				OutMsg("Download of %s succeeded.", opdld->GetExternalPath());
			}
			break; }
		case QueueOperation::QueueTypeUpload: {
			QueueUpload * opuld = (QueueUpload*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Upload of %S failed", opuld->GetLocalPath());
				OnError(queueOp, code, data, isStart);
				break;	//failure
			}

			OutMsg("Upload of %s succeeded.", opuld->GetExternalPath());

			char path[MAX_PATH];
			strcpy(path, opuld->GetExternalPath());
			char * name = (char*)PU::FindExternalFilename(path);
			if (!name)
				break;

			*name = 0;	//truncate path

			m_ftpSession->GetDirectory(path);
			break; }
		case QueueOperation::QueueTypeDirectoryCreate: {
			QueueCreateDir * opmkdir = (QueueCreateDir*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to create directory %s", opmkdir->GetDirPath());
				break;	//failure
			}
			OutMsg("Created directory %s", opmkdir->GetDirPath());
			break; }
		case QueueOperation::QueueTypeDirectoryRemove: {
			QueueRemoveDir * oprmdir = (QueueRemoveDir*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to remove directory %s", oprmdir->GetDirPath());
				break;	//failure
			}
			OutMsg("Removed directory %s", oprmdir->GetDirPath());
			break; }
		case QueueOperation::QueueTypeFileCreate: {
			QueueCreateFile * opmkfile = (QueueCreateFile*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to create file %s", opmkfile->GetFilePath());
				break;	//failure
			}
			OutMsg("Created file %s", opmkfile->GetFilePath());
			break; }
		case QueueOperation::QueueTypeFileDelete: {
			QueueDeleteFile * opdelfile = (QueueDeleteFile*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to delete file %s", opdelfile->GetFilePath());
				break;	//failure
			}
			OutMsg("Deleted file %s", opdelfile->GetFilePath());
			break; }
		case QueueOperation::QueueTypeFileRename: {
			QueueRenameFile * oprename = (QueueRenameFile*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to rename file %s", oprename->GetFilePath());
				break;	//failure
			}
			OutMsg("Renamed %s to %s", oprename->GetFilePath(), oprename->GetNewPath());
			break; }
		case QueueOperation::QueueTypeQuote: {
			QueueQuote * opquote = (QueueQuote*)queueOp;
			if (isStart)
				break;
			if (queueResult == -1) {
				OutErr("Unable to perform quote operation %s", opquote->GetQuote());
				break;	//failure
			}
			break; }
		default: {
			//Other operations do not require change in GUI atm (update tree for delete/rename/create later on)
			break; }
	}

	SetToolbarState();

	return result;
}