• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

Public Member Functions | Static Public Member Functions | List of all members
KSaveFile Class Reference

#include <ksavefile.h>

Public Member Functions

 KSaveFile (const TQString &filename, int mode=0666)
 
 ~KSaveFile ()
 
int status () const
 
TQString name () const
 
int handle () const
 
FILE * fstream ()
 
TQFile * file ()
 
TQTextStream * textStream ()
 
TQDataStream * dataStream ()
 
void abort ()
 
bool close ()
 

Static Public Member Functions

static bool backupFile (const TQString &filename, const TQString &backupDir=TQString::null, const TQString &backupExtension=TQString::fromLatin1("~"))
 

Detailed Description

The KSaveFile class has been made to write out changes to an existing file atomically.

This means that EITHER: a) All changes have been written successfully to the file.

b) Some error occurred, no changes have been written whatsoever and the old file is still in place.

Definition at line 41 of file ksavefile.h.

Constructor & Destructor Documentation

◆ KSaveFile()

KSaveFile::KSaveFile ( const TQString &  filename,
int  mode = 0666 
)

Creates a new KSaveFile with the given file name.

Parameters
filenamethe path of the file
modethe mode of the file (see chmod(1))

Definition at line 43 of file ksavefile.cpp.

◆ ~KSaveFile()

KSaveFile::~KSaveFile ( )

The destructor closes the file.

You might want to call close() explicitely though, to test whether it worked.

Definition at line 87 of file ksavefile.cpp.

Member Function Documentation

◆ abort()

void KSaveFile::abort ( )

Aborts the write operation and removes any intermediate files This implies a close.

Definition at line 100 of file ksavefile.cpp.

◆ backupFile()

bool KSaveFile::backupFile ( const TQString &  filename,
const TQString &  backupDir = TQString::null,
const TQString &  backupExtension = TQString::fromLatin1( "~" ) 
)
static

Static method to create a backup file before saving.

You can use this method even if you don't use KSaveFile.

Parameters
filenamethe file to backup
backupDiroptional directory where to save the backup file in. If empty (the default), the backup will be in the same directory as filename.
backupExtensionthe extension to append to filename, "~" by default.
Since
3.2

Definition at line 145 of file ksavefile.cpp.

◆ close()

bool KSaveFile::close ( )

Closes the file and makes the changes definitive.

Returns 'true' is successful, or 'false' if an error has occurred. See status() for details about errors.

Returns
true if successful, or false if an error has occurred.

Definition at line 107 of file ksavefile.cpp.

◆ dataStream()

TQDataStream * KSaveFile::dataStream ( )
inline

A TQDataStream* open for writing to the file.

Returns
A TQDataStream that is open for writing to the file, or 0 if opening the file failed

Definition at line 115 of file ksavefile.h.

◆ file()

TQFile * KSaveFile::file ( )
inline

A TQFile* open for writing to the file.

Returns
A TQFile open for writing to the file, or 0 if opening the temporary file failed.

Definition at line 99 of file ksavefile.h.

◆ fstream()

FILE * KSaveFile::fstream ( )
inline

A FILE* stream open for writing to the file.

Returns
FILE* stream open for writing to the file, or 0 if opening the temporary file failed

Definition at line 91 of file ksavefile.h.

◆ handle()

int KSaveFile::handle ( ) const
inline

An integer file descriptor open for writing to the file.

Returns
The file descriptor, or a negative number if opening the temporary file failed

Definition at line 83 of file ksavefile.h.

◆ name()

TQString KSaveFile::name ( ) const

The name of the file as passed to the constructor.

Returns
The name of the file, or TQString::null if opening the file has failed

Definition at line 94 of file ksavefile.cpp.

◆ status()

int KSaveFile::status ( ) const
inline

Returns the status of the file based on errno.

(see errno.h) 0 means OK.

You should check the status after object creation to check whether a file could be created in the first place.

You may check the status after closing the file to verify that the file has indeed been written correctly.

Returns
the errno status, 0 means ok

Definition at line 68 of file ksavefile.h.

◆ textStream()

TQTextStream * KSaveFile::textStream ( )
inline

A TQTextStream* open for writing to the file.

Returns
A TQTextStream that is open for writing to the file, or 0 if opening the temporary file failed

Definition at line 107 of file ksavefile.h.


The documentation for this class was generated from the following files:
  • ksavefile.h
  • ksavefile.cpp

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.