QFile::FileError App::slotFileSave() { QFile::FileError error; /* Attempt to save with the existing name. Fall back to Save As. */ if (m_doc->fileName().isEmpty() == true) error = slotFileSaveAs(); else error = m_doc->saveXML(m_doc->fileName()); handleFileError(error); return error; }
QFile::FileError App::slotFileSaveAs() { QString fn; /* Create a file save dialog */ QFileDialog dialog(this); dialog.setWindowTitle(tr("Save Workspace As")); dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.selectFile(fileName()); /* Append file filters to the dialog */ QStringList filters; filters << tr("Workspaces (*%1)").arg(KExtWorkspace); #ifdef WIN32 filters << tr("All Files (*.*)"); #else filters << tr("All Files (*)"); #endif dialog.setNameFilters(filters); /* Append useful URLs to the dialog */ QList <QUrl> sidebar; sidebar.append(QUrl::fromLocalFile(QDir::homePath())); sidebar.append(QUrl::fromLocalFile(QDir::rootPath())); dialog.setSidebarUrls(sidebar); /* Get file name */ if (dialog.exec() != QDialog::Accepted) return QFile::NoError; fn = dialog.selectedFiles().first(); if (fn.isEmpty() == true) return QFile::NoError; /* Always use the workspace suffix */ if (fn.right(4) != KExtWorkspace) fn += KExtWorkspace; /* Set the workspace path before saving the new XML. In this way local files can be loaded even if the workspace file will be moved */ m_doc->setWorkspacePath(QFileInfo(fn).absolutePath()); /* Save the document and set workspace name */ QFile::FileError error = saveXML(fn); handleFileError(error); return error; }
QFile::FileError App::slotFileSaveAs() { QString fileName; /* Create a file save dialog */ #ifdef __APPLE__ // Don't create it above the screen... QFileDialog dialog(NULL); #else QFileDialog dialog(this); #endif dialog.setWindowTitle(tr("Save Workspace As")); dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.selectFile(m_doc->fileName()); /* Append file filters to the dialog */ QStringList filters; filters << QString("Workspaces (*%1)").arg(KExtWorkspace); filters << QString("All Files (*)"); dialog.setNameFilters(filters); /* Append useful URLs to the dialog */ QList <QUrl> sidebar; sidebar.append(QUrl::fromLocalFile(QDir::homePath())); sidebar.append(QUrl::fromLocalFile(QDir::rootPath())); dialog.setSidebarUrls(sidebar); /* Get file name */ if (dialog.exec() != QDialog::Accepted) return QFile::NoError; fileName = dialog.selectedFiles().first(); if (fileName.isEmpty() == true) return QFile::NoError; /* Always use the workspace suffix */ if (fileName.right(4) != KExtWorkspace) fileName += KExtWorkspace; /* Save the document and set workspace name */ QFile::FileError error = m_doc->saveXML(fileName); handleFileError(error); return error; }
QFile::FileError App::slotFileOpen() { QString fileName; /* Check that the user is aware of losing previous changes */ if (doc()->isModified() == true) { QString msg = tr("Do you wish to save the current workspace?\n" "Otherwise you will lose changes."); int result = QMessageBox::warning(this, "Open Workspace", msg, QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); if (result == QMessageBox::Yes) { /* Save first, but don't proceed unless it succeeded. */ QFile::FileError error = slotFileSaveAs(); if (handleFileError(error) == false) return error; } else if (result == QMessageBox::Cancel) { /* Second thoughts... Cancel loading. */ return QFile::NoError; } } /* Create a file open dialog */ QFileDialog dialog(this); dialog.setWindowTitle(tr("Open Workspace")); dialog.setAcceptMode(QFileDialog::AcceptOpen); dialog.selectFile(m_doc->fileName()); /* Append file filters to the dialog */ QStringList filters; filters << QString("Workspaces (*%1)").arg(KExtWorkspace); filters << QString("All Files (*)"); dialog.setNameFilters(filters); /* Append useful URLs to the dialog */ QList <QUrl> sidebar; sidebar.append(QUrl::fromLocalFile(QDir::homePath())); sidebar.append(QUrl::fromLocalFile(QDir::rootPath())); dialog.setSidebarUrls(sidebar); /* Get file name */ if (dialog.exec() != QDialog::Accepted) return QFile::NoError; fileName = dialog.selectedFiles().first(); if (fileName.isEmpty() == true) return QFile::NoError; /* Clear existing document data */ newDocument(); /* Load the file */ QFile::FileError error = doc()->loadXML(fileName, m_fixtureDefCache); if (handleFileError(error) == true) doc()->resetModified(); /* Update these in any case, since they are at least emptied now as a result of calling newDocument() a few lines ago. */ if (FunctionManager::instance() != NULL) FunctionManager::instance()->updateTree(); if (OutputManager::instance() != NULL) InputManager::instance()->updateTree(); if (InputManager::instance() != NULL) InputManager::instance()->updateTree(); return error; }
QFile::FileError App::slotFileOpen() { QString fn; /* Check that the user is aware of losing previous changes */ if (m_doc->isModified() == true) { QString msg(tr("Do you wish to save the current workspace?\n" \ "Changes will be lost if you don't save them.")); int result = QMessageBox::warning(this, tr("Open Workspace"), msg, QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); if (result == QMessageBox::Yes) { /* Save first, but don't proceed unless it succeeded. */ QFile::FileError error = slotFileSaveAs(); if (handleFileError(error) == false) return error; } else if (result == QMessageBox::Cancel) { /* Second thoughts... Cancel loading. */ return QFile::NoError; } } /* Create a file open dialog */ QFileDialog dialog(this); dialog.setWindowTitle(tr("Open Workspace")); dialog.setAcceptMode(QFileDialog::AcceptOpen); dialog.selectFile(fileName()); /* Append file filters to the dialog */ QStringList filters; filters << tr("Workspaces (*%1)").arg(KExtWorkspace); #ifdef WIN32 filters << tr("All Files (*.*)"); #else filters << tr("All Files (*)"); #endif dialog.setNameFilters(filters); /* Append useful URLs to the dialog */ QList <QUrl> sidebar; sidebar.append(QUrl::fromLocalFile(QDir::homePath())); sidebar.append(QUrl::fromLocalFile(QDir::rootPath())); dialog.setSidebarUrls(sidebar); /* Get file name */ if (dialog.exec() != QDialog::Accepted) return QFile::NoError; fn = dialog.selectedFiles().first(); if (fn.isEmpty() == true) return QFile::NoError; /* Clear existing document data */ clearDocument(); /* Set the workspace path before loading the new XML. In this way local files can be loaded even if the workspace file has been moved */ m_doc->setWorkspacePath(QFileInfo(fn).absolutePath()); /* Load the file */ QFile::FileError error = loadXML(fn); if (handleFileError(error) == true) m_doc->resetModified(); /* Update these in any case, since they are at least emptied now as a result of calling clearDocument() a few lines ago. */ if (FunctionManager::instance() != NULL) FunctionManager::instance()->updateTree(); if (FixtureManager::instance() != NULL) FixtureManager::instance()->updateView(); if (InputOutputManager::instance() != NULL) InputOutputManager::instance()->updateTree(); return error; }
int edwFileFetch(struct sqlConnection *conn, struct edwFile *ef, int fd, char *submitFileName, unsigned submitId, unsigned submitDirId, unsigned hostId) /* Fetch file and if successful update a bunch of the fields in ef with the result. * Returns fileId. */ { ef->id = makeNewEmptyFileRecord(conn, submitId, submitDirId, ef->submitFileName, ef->size); /* Update edwSubmit with file in transit info */ char query[256]; sqlSafef(query, sizeof(query), "update edwSubmit set fileIdInTransit=%lld where id=%u", (long long)ef->id, submitId); sqlUpdate(conn, query); sqlSafef(query, sizeof(query), "select paraFetchStreams from edwHost where id=%u", hostId); int paraFetchStreams = sqlQuickNum(conn, query); struct paraFetchInterruptContext interruptContext = {.conn=conn, .submitId=submitId}; /* Wrap getting the file, the actual data transfer, with an error catcher that * will remove partly uploaded files. Perhaps some day we'll attempt to rescue * ones that are just truncated by downloading the rest, but not now. */ struct errCatch *errCatch = errCatchNew(); char tempName[PATH_LEN] = ""; char edwFile[PATH_LEN] = "", edwPath[PATH_LEN]; if (errCatchStart(errCatch)) { /* Now make temp file name and open temp file in an atomic operation */ char *tempDir = edwTempDir(); safef(tempName, PATH_LEN, "%sedwSubmitXXXXXX", tempDir); int localFd = mustMkstemp(tempName); /* Update file name in database with temp file name so web app can track us. */ char query[PATH_LEN+128]; sqlSafef(query, sizeof(query), "update edwFile set edwFileName='%s' where id=%lld", tempName + strlen(edwRootDir), (long long)ef->id); sqlUpdate(conn, query); /* Do actual upload tracking how long it takes. */ ef->startUploadTime = edwNow(); mustCloseFd(&localFd); if (!parallelFetchInterruptable(submitFileName, tempName, paraFetchStreams, 4, FALSE, FALSE, paraFetchInterruptFunction, &interruptContext)) { if (interruptContext.isInterrupted) errAbort("Submission stopped by user."); else errAbort("parallel fetch of %s failed", submitFileName); } ef->endUploadTime = edwNow(); /* Rename file both in file system and (via ef) database. */ edwMakeFileNameAndPath(ef->id, submitFileName, edwFile, edwPath); mustRename(tempName, edwPath); if (endsWith(edwPath, ".gz") && !encode3IsGzipped(edwPath)) errAbort("%s has .gz suffix, but is not gzipped", submitFileName); ef->edwFileName = cloneString(edwFile); } errCatchEnd(errCatch); if (errCatch->gotError) { /* Attempt to remove any partial file. */ if (tempName[0] != 0) { verbose(1, "Removing partial %s\n", tempName); parallelFetchRemovePartial(tempName); remove(tempName); } handleSubmitError(conn, submitId, errCatch->message->string); // Throws further assert(FALSE); // We never get here } errCatchFree(&errCatch); /* Now we got the file. We'll go ahead and save the file name and stuff. */ sqlSafef(query, sizeof(query), "update edwFile set" " edwFileName='%s', startUploadTime=%lld, endUploadTime=%lld" " where id = %d" , ef->edwFileName, ef->startUploadTime, ef->endUploadTime, ef->id); sqlUpdate(conn, query); /* Wrap the validations in an error catcher that will save error to file table in database */ errCatch = errCatchNew(); boolean success = FALSE; if (errCatchStart(errCatch)) { /* Check MD5 sum here. */ unsigned char md5bin[16]; md5ForFile(edwPath, md5bin); char md5[33]; hexBinaryString(md5bin, sizeof(md5bin), md5, sizeof(md5)); if (!sameWord(md5, ef->md5)) errAbort("%s has md5 mismatch: %s != %s. File may be corrupted in upload, or file may have " "been changed since validateManifest was run. Please check that md5 of file " "before upload is really %s. If it is then try submitting again, otherwise " "rerun validateManifest and then try submitting again. \n", ef->submitFileName, ef->md5, md5, ef->md5); /* Finish updating a bunch more of edwFile record. Note there is a requirement in * the validFile section that ef->updateTime be updated last. A nonzero ef->updateTime * is used as a sign of record complete. */ struct dyString *dy = dyStringNew(0); /* Includes tag so query may be long */ sqlDyStringPrintf(dy, "update edwFile set md5='%s',size=%lld,updateTime=%lld", md5, ef->size, ef->updateTime); dyStringAppend(dy, ", tags='"); dyStringAppend(dy, ef->tags); dyStringPrintf(dy, "' where id=%d", ef->id); sqlUpdate(conn, dy->string); dyStringFree(&dy); /* Update edwSubmit so file no longer shown as in transit */ sqlSafef(query, sizeof(query), "update edwSubmit set fileIdInTransit=0 where id=%u", submitId); sqlUpdate(conn, query); success = TRUE; } errCatchEnd(errCatch); if (errCatch->gotError) { handleFileError(conn, submitId, ef->id, errCatch->message->string); } return ef->id; }