diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-05 06:00:29 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-05 06:00:29 +0000 |
commit | fecb0e67b23e8b83ba7fc881bb57bc48c0852d62 (patch) | |
tree | 6b8614802f0d01b353bc9ba78aff2090846c198e /libkgpgfile | |
parent | dadc34655c3ab961b0b0b94a10eaaba710f0b5e8 (diff) | |
download | kmymoney-fecb0e67b23e8b83ba7fc881bb57bc48c0852d62.tar.gz kmymoney-fecb0e67b23e8b83ba7fc881bb57bc48c0852d62.zip |
TQt4 port kmymoney
This enables compilation under both Qt3 and Qt4
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmymoney@1239855 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkgpgfile')
-rw-r--r-- | libkgpgfile/kgpgfile.cpp | 180 | ||||
-rw-r--r-- | libkgpgfile/kgpgfile.h | 79 |
2 files changed, 135 insertions, 124 deletions
diff --git a/libkgpgfile/kgpgfile.cpp b/libkgpgfile/kgpgfile.cpp index a7fc338..934c772 100644 --- a/libkgpgfile/kgpgfile.cpp +++ b/libkgpgfile/kgpgfile.cpp @@ -24,13 +24,11 @@ // ---------------------------------------------------------------------------- // QT Includes -#include <qfile.h> -#include <qdir.h> -#include <qstring.h> +#include <tqfile.h> +#include <tqdir.h> +#include <tqstring.h> -#if QT_IS_VERSION(3,3,0) -#include <qeventloop.h> -#endif +#include <tqeventloop.h> // ---------------------------------------------------------------------------- @@ -53,7 +51,7 @@ class KGPGFileFactory : public KLibFactory public: KGPGFileFactory() : KLibFactory() {} ~KGPGFileFactory(){} - QObject *createObject( QObject *, const char *, const char*, const QStringList & ) + TQObject *createObject( TQObject *, const char *, const char*, const TQStringList & ) { return new KGPGFile; } @@ -67,7 +65,7 @@ extern "C" { } #endif -KGPGFile::KGPGFile(const QString& fn, const QString& homedir, const QString& options) : +KGPGFile::KGPGFile(const TQString& fn, const TQString& homedir, const TQString& options) : m_options(options), m_homedir(homedir), m_readRemain(0), @@ -87,18 +85,18 @@ KGPGFile::~KGPGFile() void KGPGFile::init(void) { setFlags(IO_Sequential); - setStatus(IO_Ok); + setqStatus(IO_Ok); setState(0); } -void KGPGFile::setName(const QString& fn) +void KGPGFile::setName(const TQString& fn) { m_fn = fn; if(fn[0] == '~') { - m_fn = QDir::homeDirPath()+fn.mid(1); + m_fn = TQDir::homeDirPath()+fn.mid(1); - } else if(QDir::isRelativePath(m_fn)) { - QDir dir(fn); + } else if(TQDir::isRelativePath(m_fn)) { + TQDir dir(fn); m_fn = dir.absPath(); } // qDebug("setName: '%s'", m_fn.data()); @@ -109,17 +107,17 @@ void KGPGFile::flush(void) // no functionality } -void KGPGFile::addRecipient(const QCString& recipient) +void KGPGFile::addRecipient(const TQCString& recipient) { m_recipient << recipient; } bool KGPGFile::open(int mode) { - return open(mode, QString(), false); + return open(mode, TQString(), false); } -bool KGPGFile::open(int mode, const QString& cmdArgs, bool skipPasswd) +bool KGPGFile::open(int mode, const TQString& cmdArgs, bool skipPasswd) { bool useOwnPassphrase = (getenv("GPG_AGENT_INFO") == 0); @@ -151,46 +149,46 @@ bool KGPGFile::open(int mode, const QString& cmdArgs, bool skipPasswd) return false; } - QStringList args; + TQStringList args; if(cmdArgs.isEmpty()) { - args << "--homedir" << QString("\"%1\"").arg(m_homedir) + args << "--homedir" << TQString("\"%1\"").tqarg(m_homedir) << "-q" << "--batch"; if(isWritable()) { args << "-ea" << "-z" << "6" - << "--comment" << QString("\"%1\"").arg(m_comment) + << "--comment" << TQString("\"%1\"").tqarg(m_comment) << "--trust-model=always" - << "-o" << QString("\"%1\"").arg(m_fn); - QValueList<QCString>::Iterator it; + << "-o" << TQString("\"%1\"").tqarg(m_fn); + TQValueList<TQCString>::Iterator it; for(it = m_recipient.begin(); it != m_recipient.end(); ++it) - args << "-r" << QString("\"%1\"").arg(*it); + args << "-r" << TQString("\"%1\"").tqarg(TQString(*it)); // some versions of GPG had trouble to replace a file // so we delete it first - QFile::remove(m_fn); + TQFile::remove(m_fn); } else { args << "-da"; if(useOwnPassphrase) args << "--passphrase-fd" << "0"; else args << "--use-agent"; - args << "--no-default-recipient" << QString("\"%1\"").arg(m_fn); + args << "--no-default-recipient" << TQString("\"%1\"").tqarg(m_fn); } } else { - args = QStringList::split(" ", cmdArgs); + args = TQStringList::split(" ", cmdArgs); } - QCString pwd; + TQCString pwd; if(isReadable() && useOwnPassphrase && !skipPasswd) { KPasswordDialog dlg(KPasswordDialog::Password,false,0); dlg.setPrompt(i18n("Enter passphrase")); dlg.addLine(i18n("File"), m_fn); dlg.adjustSize(); - if (dlg.exec() == QDialog::Rejected) + if (dlg.exec() == TQDialog::Rejected) return false; - pwd = QCString(dlg.password()); + pwd = TQCString(dlg.password()); } // qDebug("starting GPG process"); @@ -220,32 +218,32 @@ bool KGPGFile::open(int mode, const QString& cmdArgs, bool skipPasswd) } setState( IO_Open ); - ioIndex = 0; + tqat( 0 ); // qDebug("File open"); return true; } -bool KGPGFile::startProcess(const QStringList& args) +bool KGPGFile::startProcess(const TQStringList& args) { // now start the KProcess with GPG m_process = new KShellProcess(); *m_process << "gpg"; *m_process << args; - // QString arglist = args.join(":"); + // TQString arglist = args.join(":"); // qDebug("gpg '%s'", arglist.data()); - connect(m_process, SIGNAL(processExited(KProcess *)), - this, SLOT(slotGPGExited(KProcess *))); + connect(m_process, TQT_SIGNAL(processExited(KProcess *)), + this, TQT_SLOT(slotGPGExited(KProcess *))); - connect(m_process, SIGNAL(receivedStdout(KProcess*, char*, int)), - this, SLOT(slotDataFromGPG(KProcess*, char*, int))); + connect(m_process, TQT_SIGNAL(receivedStdout(KProcess*, char*, int)), + this, TQT_SLOT(slotDataFromGPG(KProcess*, char*, int))); - connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int)), - this, SLOT(slotErrorFromGPG(KProcess*, char*, int))); + connect(m_process, TQT_SIGNAL(receivedStderr(KProcess*, char*, int)), + this, TQT_SLOT(slotErrorFromGPG(KProcess*, char*, int))); - connect(m_process, SIGNAL(wroteStdin(KProcess *)), - this, SLOT(slotSendDataToGPG(KProcess *))); + connect(m_process, TQT_SIGNAL(wroteStdin(KProcess *)), + this, TQT_SLOT(slotSendDataToGPG(KProcess *))); if(!m_process->start(KProcess::NotifyOnExit, (KProcess::Communication)(KProcess::Stdin|KProcess::Stdout|KProcess::Stderr))) { // qDebug("m_process->start failed"); @@ -255,7 +253,7 @@ bool KGPGFile::startProcess(const QStringList& args) } // let the process settle and see if it starts and survives ;-) - kapp->processEvents(100); + kapp->tqprocessEvents(100); return true; } @@ -275,7 +273,7 @@ void KGPGFile::close(void) m_process->closeStdin(); // now wait for GPG to finish m_needExitLoop = true; - qApp->enter_loop(); + tqApp->enter_loop(); } else m_process->kill(); @@ -285,12 +283,12 @@ void KGPGFile::close(void) m_process->closeStdout(); // now wait for GPG to finish m_needExitLoop = true; - qApp->enter_loop(); + tqApp->enter_loop(); } else m_process->kill(); } } - m_ungetchBuffer = QCString(); + m_ungetchBuffer = TQCString(); setState(0); m_recipient.clear(); // qDebug("File closed"); @@ -342,7 +340,7 @@ int KGPGFile::putch(int c) return EOF; } -Q_LONG KGPGFile::writeBlock(const char *data, Q_ULONG maxlen) +TQ_LONG KGPGFile::writeBlock(const char *data, TQ_ULONG maxlen) { if(!isOpen()) return EOF; @@ -352,7 +350,7 @@ Q_LONG KGPGFile::writeBlock(const char *data, Q_ULONG maxlen) return _writeBlock(data, maxlen); } -Q_LONG KGPGFile::_writeBlock(const char *data, Q_ULONG maxlen) +TQ_LONG KGPGFile::_writeBlock(const char *data, TQ_ULONG maxlen) { if(!m_process) return EOF; @@ -362,7 +360,7 @@ Q_LONG KGPGFile::_writeBlock(const char *data, Q_ULONG maxlen) if(m_process->writeStdin(data, maxlen)) { // wait until the data has been written m_needExitLoop = true; - qApp->enter_loop(); + tqApp->enter_loop(); if(!m_process) return EOF; return maxlen; @@ -371,7 +369,7 @@ Q_LONG KGPGFile::_writeBlock(const char *data, Q_ULONG maxlen) return EOF; } -Q_LONG KGPGFile::readBlock(char *data, Q_ULONG maxlen) +TQ_LONG KGPGFile::readBlock(char *data, TQ_ULONG maxlen) { // char *oridata = data; if(maxlen == 0) @@ -382,7 +380,7 @@ Q_LONG KGPGFile::readBlock(char *data, Q_ULONG maxlen) if(!isReadable()) return EOF; - Q_ULONG nread = 0; + TQ_ULONG nread = 0; if(!m_ungetchBuffer.isEmpty()) { unsigned l = m_ungetchBuffer.length(); if(maxlen < l) @@ -410,7 +408,7 @@ Q_LONG KGPGFile::readBlock(char *data, Q_ULONG maxlen) if(m_readRemain) { m_process->resume(); m_needExitLoop = true; - qApp->enter_loop(); + tqApp->enter_loop(); } // if nothing has been read (maxlen-m_readRemain == 0) then we assume EOF if((maxlen - m_readRemain) == 0) { @@ -422,17 +420,17 @@ Q_LONG KGPGFile::readBlock(char *data, Q_ULONG maxlen) return maxlen - m_readRemain; } -QByteArray KGPGFile::readAll(void) +TQByteArray KGPGFile::readAll(void) { - // use a larger blocksize than in the QIODevice version + // use a larger blocksize than in the TQIODevice version const int blocksize = 8192; int nread = 0; - QByteArray ba; + TQByteArray ba; while ( !atEnd() ) { ba.resize( nread + blocksize ); int r = readBlock( ba.data()+nread, blocksize ); if ( r < 0 ) - return QByteArray(); + return TQByteArray(); nread += r; } ba.resize( nread ); @@ -446,7 +444,7 @@ void KGPGFile::slotGPGExited(KProcess* ) if(m_process->normalExit()) { m_exitStatus = m_process->exitStatus(); if(m_exitStatus != 0) - setStatus(IO_UnspecifiedError); + setqStatus(IO_UnspecifiedError); } else { m_exitStatus = -1; } @@ -456,7 +454,7 @@ void KGPGFile::slotGPGExited(KProcess* ) if(m_needExitLoop) { m_needExitLoop = false; - qApp->exit_loop(); + tqApp->exit_loop(); } } @@ -486,7 +484,7 @@ void KGPGFile::slotDataFromGPG(KProcess* proc, char* buf, int len) // wake up the recipient if(m_needExitLoop) { m_needExitLoop = false; - qApp->exit_loop(); + tqApp->exit_loop(); } } // qDebug("end slotDataFromGPG"); @@ -495,7 +493,7 @@ void KGPGFile::slotDataFromGPG(KProcess* proc, char* buf, int len) void KGPGFile::slotErrorFromGPG(KProcess *, char *buf, int len) { // qDebug("Received %d bytes on stderr", len); - QCString msg; + TQCString msg; msg.setRawData(buf, len); m_errmsg += msg; msg.resetRawData(buf, len); @@ -506,49 +504,49 @@ void KGPGFile::slotSendDataToGPG(KProcess *) // qDebug("wrote stdin"); if(m_needExitLoop) { m_needExitLoop = false; - qApp->exit_loop(); + tqApp->exit_loop(); } } bool KGPGFile::GPGAvailable(void) { - QString output; + TQString output; char buffer[1024]; - Q_LONG len; + TQ_LONG len; KGPGFile file; file.open(IO_ReadOnly, "--version", true); while((len = file.readBlock(buffer, sizeof(buffer)-1)) != EOF) { buffer[len] = 0; - output += QString(buffer); + output += TQString(buffer); } file.close(); return !output.isEmpty(); } -bool KGPGFile::keyAvailable(const QString& name) +bool KGPGFile::keyAvailable(const TQString& name) { - QStringList list; + TQStringList list; publicKeyList(list, name); return !list.isEmpty(); } -void KGPGFile::publicKeyList(QStringList& list, const QString& pattern) +void KGPGFile::publicKeyList(TQStringList& list, const TQString& pattern) { - QMap<QString, QString> map; - QString output; + TQMap<TQString, TQString> map; + TQString output; char buffer[1024]; - Q_LONG len; + TQ_LONG len; list.clear(); KGPGFile file; - QString args("--list-keys --with-colons"); + TQString args("--list-keys --with-colons"); if(!pattern.isEmpty()) - args += QString(" %1").arg(pattern); + args += TQString(" %1").tqarg(pattern); file.open(IO_ReadOnly, args, true); while((len = file.readBlock(buffer, sizeof(buffer)-1)) != EOF) { buffer[len] = 0; - output += QString(buffer); + output += TQString(buffer); } file.close(); @@ -560,24 +558,24 @@ void KGPGFile::publicKeyList(QStringList& list, const QString& pattern) uid:u::::2001-11-29::00A393737BC120C98A6402B921599F6D72058DD8::Thomas Baumgart <ipwizard@users.sourceforge.net>: sub:u:1024:16:85968A70D1F83C2B:2001-06-23::::::e: */ - QStringList lines = QStringList::split("\n", output); - QStringList::iterator it; - QString currentKey; + TQStringList lines = TQStringList::split("\n", output); + TQStringList::iterator it; + TQString currentKey; for(it = lines.begin(); it != lines.end(); ++it) { // qDebug("Parsing: '%s'", (*it).data()); - QStringList fields = QStringList::split(":", (*it), true); - QString val; + TQStringList fields = TQStringList::split(":", (*it), true); + TQString val; if(fields[0] == "pub") { - QDate expiration = QDate::fromString(fields[6], Qt::ISODate); - if(expiration > QDate::currentDate()) { + TQDate expiration = TQDate::fromString(fields[6], Qt::ISODate); + if(expiration > TQDate::tqcurrentDate()) { currentKey = fields[4]; - val = QString("%1:%2").arg(currentKey).arg(fields[9]); + val = TQString("%1:%2").tqarg(currentKey).tqarg(fields[9]); map[val] = val; } else { qDebug("'%s' is expired", fields[9].data()); } } else if(fields[0] == "uid") { - val = QString("%1:%2").arg(currentKey).arg(fields[9]); + val = TQString("%1:%2").tqarg(currentKey).tqarg(fields[9]); map[val] = val; } } @@ -585,18 +583,18 @@ void KGPGFile::publicKeyList(QStringList& list, const QString& pattern) } -void KGPGFile::secretKeyList(QStringList& list) +void KGPGFile::secretKeyList(TQStringList& list) { - QString output; + TQString output; char buffer[1024]; - Q_LONG len; + TQ_LONG len; list.clear(); KGPGFile file; file.open(IO_ReadOnly, "--list-secret-keys --with-colons", true); while((len = file.readBlock(buffer, sizeof(buffer)-1)) != EOF) { buffer[len] = 0; - output += QString(buffer); + output += TQString(buffer); } file.close(); @@ -608,17 +606,17 @@ void KGPGFile::secretKeyList(QStringList& list) sec::1024:17:59B0F826D2B08440:2005-01-03:2010-01-02:::KMyMoney emergency data recovery <kmymoney-recover@users.sourceforge.net>::: ssb::2048:16:B3DABDC48C0FE2F3:2005-01-03::::::: */ - QStringList lines = QStringList::split("\n", output); - QStringList::iterator it; - QString currentKey; + TQStringList lines = TQStringList::split("\n", output); + TQStringList::iterator it; + TQString currentKey; for(it = lines.begin(); it != lines.end(); ++it) { // qDebug("Parsing: '%s'", (*it).data()); - QStringList fields = QStringList::split(":", (*it), true); + TQStringList fields = TQStringList::split(":", (*it), true); if(fields[0] == "sec") { currentKey = fields[4]; - list << QString("%1:%2").arg(currentKey).arg(fields[9]); + list << TQString("%1:%2").tqarg(currentKey).tqarg(fields[9]); } else if(fields[0] == "uid") { - list << QString("%1:%2").arg(currentKey).arg(fields[9]); + list << TQString("%1:%2").tqarg(currentKey).tqarg(fields[9]); } } } @@ -660,7 +658,7 @@ void KGPGFile::secretKeyList(QStringList& list) #if KMM_DEBUG void KGPGFile::dumpBuffer(char *s, int len) const { - QString data, tmp, chars; + TQString data, tmp, chars; unsigned long addr = 0x0; while(1) { @@ -671,7 +669,7 @@ void KGPGFile::dumpBuffer(char *s, int len) const } if(!(addr & 0x0f)) { data = tmp.sprintf("%08lX", addr); - chars = QString(); + chars = TQString(); } if(!(addr & 0x03)) { data += " "; diff --git a/libkgpgfile/kgpgfile.h b/libkgpgfile/kgpgfile.h index ba5c7d2..08b6853 100644 --- a/libkgpgfile/kgpgfile.h +++ b/libkgpgfile/kgpgfile.h @@ -18,10 +18,14 @@ #ifndef KGPGFILE_H #define KGPGFILE_H -#include <qfile.h> -#include <qobject.h> -#include <qstring.h> -#include <qstringlist.h> +#include <tqfile.h> +#include <tqobject.h> +#include <tqstring.h> +#include <tqstringlist.h> + +#ifdef Q_MOC_RUN +#define USE_QT4 +#endif // Q_MOC_RUN /** * @author Thomas Baumgart @@ -34,14 +38,14 @@ class KProcess; * A class for reading and writing data to/from an * encrypted e.g. file. * - * This class presents a QFile based object to the application + * This class presents a TQFile based object to the application * but reads/writes data from/to the file through an instance of GPG. * * @code * * +------------------+ write +-----------+ stdin +-------+ +--------+ * | |--------->|\ |---------->| |---->| | - * | Application code | read | QFile | stdout | GPG | | File | + * | Application code | read | TQFile | stdout | GPG | | File | * | |<---------|/ |<----------| |<----| | * +------------------+ | KGPGFile | +-------+ +--------+ * | control| | @@ -55,14 +59,19 @@ class KProcess; * GPGAvailable(). Other, more general methods such as open(), close() and flush() are * not shown in the above picture. */ -class KGPGFile : public QObject, public QFile +#ifdef USE_QT4 +class KGPGFile : public TQFile +#else // USE_QT4 +class KGPGFile : public TQObject, public TQFile +#endif // USE_QT4 { Q_OBJECT + TQ_OBJECT public: - KGPGFile(const QString& fname = "", - const QString& homedir = "~/.gnupg", - const QString& options = ""); + KGPGFile(const TQString& fname = "", + const TQString& homedir = "~/.gnupg", + const TQString& options = ""); ~KGPGFile(); @@ -70,11 +79,15 @@ public: virtual void close(void); virtual void flush(void); +#ifdef USE_QT4 + virtual qint64 size(void) const { return 0; }; +#else // USE_QT4 virtual Offset size(void) const { return 0; }; +#endif // USE_QT4 - virtual Q_LONG readBlock(char *data, Q_ULONG maxlen); - virtual Q_LONG writeBlock(const char *data, Q_ULONG maxlen); - virtual QByteArray readAll(void); + virtual TQ_LONG readBlock(char *data, TQ_ULONG maxlen); + virtual TQ_LONG writeBlock(const char *data, TQ_ULONG maxlen); + virtual TQByteArray readAll(void); virtual int getch(void); virtual int putch(int c); @@ -89,16 +102,16 @@ public: * * @param recipient recipients identification (e.g. e-mail address) */ - void addRecipient(const QCString& recipient); + void addRecipient(const TQCString& recipient); /** * sets the name of the file to @p fn. This method must be * called prior to open(). */ - void setName(const QString& fn); - void setComment(const QString& txt); + void setName(const TQString& fn); + void setComment(const TQString& txt); - const QCString errmsg(void) const { return m_errmsg; }; + const TQCString errmsg(void) const { return m_errmsg; }; int exitStatus(void) const { return m_exitStatus; }; /** @@ -118,7 +131,7 @@ public: * @retval true key for user-id @p name was found * @retval false key for user-id @p not available */ - static bool keyAvailable(const QString& name); + static bool keyAvailable(const TQString& name); /** * This function returns a list of the secret keys contained @@ -131,7 +144,7 @@ public: * * "9C59DB40B75DD3BA:Thomas Baumgart <ipwizard@users.sourceforge.net>" */ - static void secretKeyList(QStringList& list); + static void secretKeyList(TQStringList& list); /** * This function returns a list of the public keys contained @@ -144,7 +157,7 @@ public: * * "9C59DB40B75DD3BA:Thomas Baumgart <ipwizard@users.sourceforge.net>" */ - static void publicKeyList(QStringList& list, const QString& pattern = QString()); + static void publicKeyList(TQStringList& list, const TQString& pattern = TQString()); #ifdef KMM_DEBUG void dumpUngetBuffer(void); @@ -159,25 +172,25 @@ protected slots: private: void init(void); - bool startProcess(const QStringList& args); - Q_LONG _writeBlock(const char *data, Q_ULONG maxlen); - bool open(int mode, const QString&, bool skipPasswd); + bool startProcess(const TQStringList& args); + TQ_LONG _writeBlock(const char *data, TQ_ULONG maxlen); + bool open(int mode, const TQString&, bool skipPasswd); private: - QString m_fn; - QString m_pubring; - QString m_secring; - QString m_options; - QString m_comment; - QString m_homedir; + TQString m_fn; + TQString m_pubring; + TQString m_secring; + TQString m_options; + TQString m_comment; + TQString m_homedir; KShellProcess* m_process; - QValueList<QCString> m_recipient; - QCString m_ungetchBuffer; - QCString m_errmsg; + TQValueList<TQCString> m_recipient; + TQCString m_ungetchBuffer; + TQCString m_errmsg; int m_exitStatus; - Q_LONG m_readRemain; + TQ_LONG m_readRemain; char* m_ptrRemain; bool m_needExitLoop; }; |