More qstrings.

svn path=/trunk/kdenetwork/kmail/; revision=41815
wilder-work
Hans Petter Bieker 26 years ago
parent 583ced227d
commit 5d0397dd9f
  1. 68
      kfileio.cpp
  2. 8
      kfileio.h
  3. 21
      kmaddrbook.cpp
  4. 8
      kmaddrbook.h
  5. 7
      kmfldsearch.cpp

@ -15,19 +15,14 @@
//-----------------------------------------------------------------------------
static void msgDialog(const char* msg, const char* arg=NULL)
static void msgDialog(const QString &msg)
{
QString str;
if (arg) str.sprintf(msg, arg);
else str = msg;
KMessageBox::sorry(0, str, i18n("File I/O Error"));
KMessageBox::sorry(0, msg, i18n("File I/O Error"));
}
//-----------------------------------------------------------------------------
QString kFileToString(const char* aFileName, bool aEnsureNL, bool aVerbose)
QString kFileToString(const QString &aFileName, bool aEnsureNL, bool aVerbose)
{
QCString result;
QFileInfo info(aFileName);
@ -42,22 +37,20 @@ QString kFileToString(const char* aFileName, bool aEnsureNL, bool aVerbose)
if (!info.exists())
{
if (aVerbose)
msgDialog(i18n("The specified file does not exist:\n%s"),
aFileName);
msgDialog(i18n("The specified file does not exist:\n%1").arg(aFileName));
return QString::null;
}
if (info.isDir())
{
if (aVerbose)
msgDialog(i18n("This is a directory and not a file:\n%s"),
aFileName);
msgDialog(i18n("This is a directory and not a file:\n%1").arg(aFileName));
return QString::null;
}
if (!info.isReadable())
{
if (aVerbose)
msgDialog(i18n("You do not have read permissions "
"to the file:\n%s"), aFileName);
"to the file:\n%1").arg(aFileName));
return QString::null;
}
if (len <= 0) return QString::null;
@ -67,13 +60,13 @@ QString kFileToString(const char* aFileName, bool aEnsureNL, bool aVerbose)
if (aVerbose) switch(file.status())
{
case IO_ReadError:
msgDialog(i18n("Could not read file:\n%s"), aFileName);
msgDialog(i18n("Could not read file:\n%1").arg(aFileName));
break;
case IO_OpenError:
msgDialog(i18n("Could not open file:\n%s"), aFileName);
msgDialog(i18n("Could not open file:\n%1").arg(aFileName));
break;
default:
msgDialog(i18n("Error while reading file:\n%s"),aFileName);
msgDialog(i18n("Error while reading file:\n%1").arg(aFileName));
}
return QString::null;
}
@ -89,8 +82,7 @@ QString kFileToString(const char* aFileName, bool aEnsureNL, bool aVerbose)
if (readLen < len)
{
QString msg;
msg = i18n("Could only read %1 bytes of %2.")
QString msg = i18n("Could only read %1 bytes of %2.")
.arg(readLen).arg(len);
msgDialog(msg);
return QString::null;
@ -100,7 +92,7 @@ QString kFileToString(const char* aFileName, bool aEnsureNL, bool aVerbose)
}
//-----------------------------------------------------------------------------
QByteArray kFileToBytes(const char* aFileName, bool aVerbose)
QByteArray kFileToBytes(const QString &aFileName, bool aVerbose)
{
QByteArray result;
QFileInfo info(aFileName);
@ -115,22 +107,22 @@ QByteArray kFileToBytes(const char* aFileName, bool aVerbose)
if (!info.exists())
{
if (aVerbose)
msgDialog(i18n("The specified file does not exist:\n%s"),
aFileName);
msgDialog(i18n("The specified file does not exist:\n%1")
.arg(aFileName));
return result;
}
if (info.isDir())
{
if (aVerbose)
msgDialog(i18n("This is a directory and not a file:\n%s"),
aFileName);
msgDialog(i18n("This is a directory and not a file:\n%1")
.arg(aFileName));
return result;
}
if (!info.isReadable())
{
if (aVerbose)
msgDialog(i18n("You do not have read permissions "
"to the file:\n%s"), aFileName);
"to the file:\n%1").arg(aFileName));
return result;
}
if (len <= 0) return result;
@ -140,13 +132,13 @@ QByteArray kFileToBytes(const char* aFileName, bool aVerbose)
if (aVerbose) switch(file.status())
{
case IO_ReadError:
msgDialog(i18n("Could not read file:\n%s"), aFileName);
msgDialog(i18n("Could not read file:\n%1").arg(aFileName));
break;
case IO_OpenError:
msgDialog(i18n("Could not open file:\n%s"), aFileName);
msgDialog(i18n("Could not open file:\n%1").arg(aFileName));
break;
default:
msgDialog(i18n("Error while reading file:\n%s"),aFileName);
msgDialog(i18n("Error while reading file:\n%1").arg(aFileName));
}
return result;
}
@ -174,7 +166,7 @@ QByteArray kFileToBytes(const char* aFileName, bool aVerbose)
//-----------------------------------------------------------------------------
static
bool kBytesToFile(const char* aBuffer, int len,
const char* aFileName,
const QString &aFileName,
bool aAskIfExists, bool aBackup, bool aVerbose)
{
QFile file(aFileName);
@ -208,7 +200,8 @@ bool kBytesToFile(const char* aBuffer, int len,
// failed to rename file
if (!aVerbose) return FALSE;
rc = KMessageBox::warningContinueCancel(0,
i18n("Failed to make a backup copy of %s.\nContinue anyway ?"),
i18n("Failed to make a backup copy of %1.\nContinue anyway ?")
.arg(aFileName),
i18n("Save to file"), i18n("&Save"));
if (rc != KMessageBox::Continue) return FALSE;
}
@ -220,14 +213,14 @@ bool kBytesToFile(const char* aBuffer, int len,
if (aVerbose) switch(file.status())
{
case IO_WriteError:
msgDialog(i18n("Could not write to file:\n%s"), aFileName);
msgDialog(i18n("Could not write to file:\n%1").arg(aFileName));
break;
case IO_OpenError:
msgDialog(i18n("Could not open file for writing:\n%s"),
aFileName);
msgDialog(i18n("Could not open file for writing:\n%1")
.arg(aFileName));
break;
default:
msgDialog(i18n("Error while writing file:\n%s"),aFileName);
msgDialog(i18n("Error while writing file:\n%1").arg(aFileName));
}
return FALSE;
}
@ -236,13 +229,12 @@ bool kBytesToFile(const char* aBuffer, int len,
if (writeLen < 0)
{
msgDialog(i18n("Could not write to file:\n%s"), aFileName);
msgDialog(i18n("Could not write to file:\n%1").arg(aFileName));
return FALSE;
}
else if (writeLen < len)
{
QString msg;
msg = i18n("Could only write %1 bytes of %2.")
QString msg = i18n("Could only write %1 bytes of %2.")
.arg(writeLen).arg(len);
msgDialog(msg);
return FALSE;
@ -251,14 +243,14 @@ bool kBytesToFile(const char* aBuffer, int len,
return TRUE;
}
bool kCStringToFile(const QCString& aBuffer, const char* aFileName,
bool kCStringToFile(const QCString& aBuffer, const QString &aFileName,
bool aAskIfExists, bool aBackup, bool aVerbose)
{
return kBytesToFile(aBuffer, aBuffer.length(), aFileName, aAskIfExists,
aBackup, aVerbose);
}
bool kByteArrayToFile(const QByteArray& aBuffer, const char* aFileName,
bool kByteArrayToFile(const QByteArray& aBuffer, const QString &aFileName,
bool aAskIfExists, bool aBackup, bool aVerbose)
{
return kBytesToFile(aBuffer, aBuffer.size(), aFileName, aAskIfExists,

@ -16,10 +16,10 @@
* byte longer than the file itself.
* If ensureNewline is TRUE the string will always have a trailing newline.
*/
QString kFileToString(const char* fileName, bool ensureNewline=TRUE,
QString kFileToString(const QString &fileName, bool ensureNewline=TRUE,
bool withDialogs=TRUE);
QByteArray kFileToBytes(const char* fileName, bool withDialogs=TRUE);
QByteArray kFileToBytes(const QString &fileName, bool withDialogs=TRUE);
/** Save a file. If withDialogs is FALSE no warning dialogs are opened if
@ -27,11 +27,11 @@ QByteArray kFileToBytes(const char* fileName, bool withDialogs=TRUE);
* Replaces existing files without warning if askIfExists==FALSE.
* Makes a copy if the file exists to filename~ if createBackup==TRUE.
*/
bool kCStringToFile(const QCString& buffer, const char* fileName,
bool kCStringToFile(const QCString& buffer, const QString &fileName,
bool askIfExists=FALSE, bool createBackup=TRUE,
bool withDialogs=TRUE);
// Does not stop at NUL
bool kByteArrayToFile(const QByteArray& buffer, const char* fileName,
bool kByteArrayToFile(const QByteArray& buffer, const QString &fileName,
bool askIfExists=FALSE, bool createBackup=TRUE,
bool withDialogs=TRUE);

@ -84,10 +84,10 @@ void KMAddrBook::readConfig(void)
//-----------------------------------------------------------------------------
int KMAddrBook::load(const char* aFileName)
int KMAddrBook::load(const QString &aFileName)
{
char line[256];
const char* fname = (aFileName ? aFileName : (const char*)mDefaultFileName);
QString fname = aFileName.isNull() ? mDefaultFileName : aFileName;
QFile file(fname);
int rc;
@ -115,15 +115,14 @@ int KMAddrBook::load(const char* aFileName)
//-----------------------------------------------------------------------------
int KMAddrBook::store(const char* aFileName)
int KMAddrBook::store(const QString &aFileName)
{
const char* addr;
const char* fname = (aFileName ? aFileName : (const char*)mDefaultFileName);
QString fname = aFileName.isNull() ? mDefaultFileName : aFileName;
QFile file(fname);
//assert(fname != NULL);
if(!fname)
if(fname.isNull())
return IO_FatalError;
if (!file.open(IO_ReadWrite|IO_Truncate)) return fileError(file.status());
@ -146,21 +145,21 @@ int KMAddrBook::store(const char* aFileName)
//-----------------------------------------------------------------------------
int KMAddrBook::fileError(int status) const
{
QString msg, str;
QString msg;
switch(status)
{
case IO_ReadError:
msg = i18n("Could not read file:\n%s");
msg = i18n("Could not read file:\n%1");
break;
case IO_OpenError:
msg = i18n("Could not open file:\n%s");
msg = i18n("Could not open file:\n%1");
break;
default:
msg = i18n("Error while writing file:\n%s");
msg = i18n("Error while writing file:\n%1");
}
str.sprintf(msg, mDefaultFileName.data());
QString str = msg.arg(mDefaultFileName);
KMessageBox::sorry(0, str, i18n("File I/O Error"));
return status;

@ -22,10 +22,10 @@ public:
virtual void remove(const QString address);
/** Returns first address in addressbook or NULL if addressbook is empty. */
virtual const char* first(void) { return KMAddrBookInherited::first(); }
virtual QString first(void) { return KMAddrBookInherited::first(); }
/** Returns next address in addressbook or NULL. */
virtual const char* next(void) { return KMAddrBookInherited::next(); }
virtual QString next(void) { return KMAddrBookInherited::next(); }
/** Clear addressbook (remove the contents). */
virtual void clear(void);
@ -34,12 +34,12 @@ public:
file is used if no filename is given.
Returns IO_Ok on success and an IO device status on failure -- see
QIODevice::status(). */
virtual int load(const char* fileName=NULL);
virtual int load(const QString &fileName=QString::null);
/** Store addressbook in file or in same file of last load() call
if no filename is given. Returns IO_Ok on success and an IO device
status on failure -- see QIODevice::status(). */
virtual int store(const char* fileName=NULL);
virtual int store(const QString &fileName=QString::null);
/** Read/write configuration options. Uses the group "Addressbook"
in the app's config file. */

@ -138,10 +138,11 @@ void KMFldSearch::updStatus(void)
QString str;
if (!mSearching)
str.sprintf(i18n("Done, %d matches"), mNumMatches);
str = i18n("Done, %1 matches").arg(mNumMatches);
else
str.sprintf(i18n("%d matches, searching in %s"), mNumMatches,
(const char*)mSearchFolder);
str = i18n("%1 matches, searching in %2")
.arg(mNumMatches)
.arg(mSearchFolder);
mLblStatus->setText(str);
}

Loading…
Cancel
Save