bool KstIfaceImpl::saveAs(const QString& fileName) { bool rc = _doc->saveDocument(fileName); if (rc) { QFileInfo saveAsInfo(fileName); _doc->setTitle(saveAsInfo.fileName()); _doc->setAbsFilePath(saveAsInfo.absFilePath()); _app->setCaption(kapp->caption() + ": " + _doc->title()); } return rc; }
void KstApp::slotFileSaveAs() { slotUpdateStatusMsg(i18n("Saving file with a new filename...")); QString newName= KFileDialog::getSaveFileName(QDir::currentDirPath(), i18n("*.kst|Kst Plot File (*.kst)\n*|All Files"), this, i18n("Save As")); if(!newName.isEmpty()) { if (doc->saveDocument(newName)) { addRecentFile(newName); QFileInfo saveAsInfo(newName); doc->setTitle(saveAsInfo.fileName()); doc->setAbsFilePath(saveAsInfo.absFilePath()); setCaption(kapp->caption() + ": " + doc->getTitle()); } } slotUpdateStatusMsg(i18n("Ready")); }
void FileViewManager::SaveAs(const QString& filePathName, const QString& originalFileName, DatabaseManager* dbm, QWidget* dialogParent) { QFileInfo fi(filePathName); const QString documentsDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); QString lastSaveAsDir = dbm->sets.GetSetting("LastSaveAsDir", documentsDir); QString targetFilePath = lastSaveAsDir + "/" + originalFileName; QString saveAsFilePath = QFileDialog::getSaveFileName(dialogParent, "Save File As", targetFilePath, "All Files (*)"); if (saveAsFilePath.isEmpty()) return; QFileInfo saveAsInfo(saveAsFilePath); dbm->sets.SetSetting("LastSaveAsDir", saveAsInfo.absolutePath()); //Remove file if it exists (user has already pressed 'Yes' on replace dialog) if (QFile::exists(saveAsInfo.filePath())) { if (!QFile::remove(saveAsInfo.filePath())) { QString errorText = QString("Could not replace file!\nFile: %1") .arg(saveAsInfo.filePath()); QMessageBox::critical(dialogParent, "Error", errorText); return; } } //Copy it if (!QFile::copy(fi.absoluteFilePath(), saveAsFilePath)) { QString errorText = QString("Could not copy file!\nSource file: %1\nDestination file: %2") .arg(fi.absoluteFilePath(), saveAsFilePath); QMessageBox::critical(dialogParent, "Error", errorText); } }