本文整理汇总了C++中FileManager::saveFile方法的典型用法代码示例。如果您正苦于以下问题:C++ FileManager::saveFile方法的具体用法?C++ FileManager::saveFile怎么用?C++ FileManager::saveFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::saveFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotSaveScript
void MainWindow::slotSaveScript() {
if (currentSession() && currentSession()->emulationHandler()->isRecording()) {
QMap<QString, QStringList> map;
QStringList text;
text << "text/plain";
map.insert(tr("Script"), text );
QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
if (!filename.isEmpty()) {
QFileInfo info(filename);
if (info.extension(FALSE) != "script")
filename += ".script";
DocLnk nf;
nf.setType("text/plain");
nf.setFile(filename);
nf.setName(info.fileName());
FileManager fm;
fm.saveFile(nf, currentSession()->emulationHandler()->script()->script());
currentSession()->emulationHandler()->clearScript();
m_saveScript->setEnabled(false);
m_recordScript->setEnabled(true);
populateScripts();
}
}
}
示例2: saveAs
/*!
prompted save */
bool TextEdit::saveAs()
{
odebug << "saveAsFile " + currentFileName << oendl;
QString rt = editor->text();
odebug << currentFileName << oendl;
QString docname;
if( currentFileName.isEmpty()
|| currentFileName == tr("Unnamed")
|| currentFileName == tr("Text Editor"))
{
odebug << "do silly TT filename thing" << oendl;
QString pt = rt.simplifyWhiteSpace();
int i = pt.find( ' ' );
docname = pt;
if ( i > 0 )
docname = pt.left( i );
while( docname.startsWith( "." ) )
docname = docname.mid( 1 );
docname.replace( QRegExp("/"), "_" );
// Cut the length. Filenames longer than 40 are not helpful
// and something goes wrong when they get too long.
if ( docname.length() > 40 ) docname = docname.left(40);
if ( docname.isEmpty() ) docname = tr("Unnamed");
}
QMap<QString, QStringList> map;
map.insert(tr("All"), QStringList() );
QStringList text;
text << "text/*";
map.insert(tr("Text"), text );
text << "*";
map.insert(tr("All"), text );
QFileInfo cuFi( docname);
QString filee = cuFi.fileName();
QString dire = cuFi.dirPath();
if(dire==".")
dire = QPEApplication::documentDir();
QString str;
if( !featureAutoSave) {
str = OFileDialog::getSaveFileName( 2, dire, filee, map);
if(!str.isEmpty() && QFile::exists(str)) {
switch ( QMessageBox::warning(this,tr("Text Editor"),tr("<p>The selected file already exists. Overwrite it?</p>"),tr("Overwrite"),tr("Cancel"),0,1) ) {
case 0: //Overwrite
break;
case 1: //Cancel
return false;
break;
}
}
}
else
str = docname;
if(!str.isEmpty()) {
QString fileNm=str;
odebug << "saving filename "+fileNm << oendl;
QFileInfo fi(fileNm);
currentFileName=fi.fileName();
if(doc)
delete doc;
DocLnk nf;
nf.setType("text/plain");
nf.setFile( fileNm);
doc = new DocLnk(nf);
odebug << "Saving file as " << currentFileName << oendl;
doc->setName( fi.baseName() );
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
return false;
}
if( filePerms ) {
filePermissions *filePerm;
filePerm = new filePermissions(this, tr("Permissions"),true, 0,
(const QString &)fileNm);
QPEApplication::execDialog( filePerm );
delete filePerm;
}
updateCaption();
resetEditStatus();
if(caption().left(1)=="*")
setCaption(caption().right(caption().length()-1));
checkEnableDelete();
return true;
}
odebug << "returning false" << oendl;
//.........这里部分代码省略.........
示例3: save
/*!
unprompted save */
bool TextEdit::save()
{
QString name, file;
odebug << "saveAsFile " + currentFileName << oendl;
if(currentFileName.isEmpty()) {
return saveAs();
}
if(doc) {
file = doc->file();
odebug << "saver file "+file << oendl;
name = doc->name();
odebug << "File named "+name << oendl;
} else {
file = currentFileName;
name = QFileInfo(currentFileName).baseName();
}
QString rt = editor->text();
if( !rt.isEmpty() ) {
if(name.isEmpty())
saveAs();
else {
currentFileName = name;
odebug << "saveFile "+currentFileName << oendl;
if(doc) {
int docFd;
// Save file permissions
struct stat buf;
mode_t mode;
bool setmode = true;
if((docFd = open(file, 0)) < 0)
setmode = false;
if(setmode) {
if (fstat(docFd, &buf)) {
::close(docFd);
setmode = false;
}
else
mode = buf.st_mode;
}
doc->setName(name);
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
return false;
}
// Restore file permissions
if(setmode) {
fchmod(docFd, mode);
::close(docFd);
}
} else {
odebug << "regular save file" << oendl;
QFile f(file);
if( f.open(IO_WriteOnly)) {
QCString crt = rt.utf8();
f.writeBlock(crt,crt.length());
} else {
QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
return false;
}
}
resetEditStatus();
if(caption().left(1)=="*")
setCaption(caption().right(caption().length()-1));
}
return true;
}
return false;
}