diff --git a/kabc/vcardparser/testread.cpp b/kabc/vcardparser/testread.cpp index 8babf3688..ff844694c 100644 --- a/kabc/vcardparser/testread.cpp +++ b/kabc/vcardparser/testread.cpp @@ -1,83 +1,83 @@ /* This file is part of libkabc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include -#include +#include #include #include #include #include #include #include "kabc/vcardconverter.h" #include "vcard.h" static const KCmdLineOptions options[] = { {"vcard21", I18N_NOOP("vCard 2.1"), 0}, {"+inputfile", I18N_NOOP("Input file"), 0}, KCmdLineLastOption }; int main( int argc, char **argv ) { KAboutData aboutData( "testread", "vCard test reader", "0.1" ); aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); KComponentData componentData( &aboutData ); // QCoreApp not needed KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if ( args->count() != 1 ) { std::cerr << "Missing argument" << std::endl; return 1; } QString inputFile( args->arg( 0 ) ); QFile file( inputFile ); if ( !file.open( QIODevice::ReadOnly ) ) { qDebug( "Unable to open file '%s' for reading!", qPrintable( file.fileName() ) ); return 1; } QByteArray text = file.readAll(); file.close(); KABC::VCardConverter converter; KABC::Addressee::List list = converter.parseVCards( text ); if ( args->isSet( "vcard21" ) ) { text = converter.createVCards( list, KABC::VCardConverter::v2_1 ); // uses version 2.1 } else { text = converter.createVCards( list ); // uses version 3.0 } std::cout << text.data(); return 0; } diff --git a/kpimidentities/identity.cpp b/kpimidentities/identity.cpp index 7325329dd..f0ad58399 100644 --- a/kpimidentities/identity.cpp +++ b/kpimidentities/identity.cpp @@ -1,687 +1,687 @@ // -*- mode: C++; c-file-style: "gnu" -*- // kmidentity.cpp // License: GPL #include "identity.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace KPIM; Signature::Signature() : mType( Disabled ) { } Signature::Signature( const QString & text ) : mText( text ), mType( Inlined ) { } Signature::Signature( const QString & url, bool isExecutable ) : mUrl( url ), mType( isExecutable ? FromCommand : FromFile ) { } bool Signature::operator==( const Signature & other ) const { if ( mType != other.mType ) return false; switch ( mType ) { case Inlined: return mText == other.mText; case FromFile: case FromCommand: return mUrl == other.mUrl; default: case Disabled: return true; } } QString Signature::rawText( bool * ok ) const { switch ( mType ) { case Disabled: if ( ok ) *ok = true; return QString(); case Inlined: if ( ok ) *ok = true; return mText; case FromFile: return textFromFile( ok ); case FromCommand: return textFromCommand( ok ); }; kFatal( 5006 ) << "Signature::type() returned unknown value!" << endl; return QString(); // make compiler happy } QString Signature::textFromCommand( bool * ok ) const { assert( mType == FromCommand ); // handle pathological cases: if ( mUrl.isEmpty() ) { if ( ok ) *ok = true; return QString(); } // create a shell process: CollectingProcess proc; proc.setUseShell(true); proc << mUrl; // run the process: int rc = 0; - if ( !proc.start( KProcess::Block, KProcess::Stdout ) ) + if ( !proc.start( K3Process::Block, K3Process::Stdout ) ) rc = -1; else rc = ( proc.normalExit() ) ? proc.exitStatus() : -1 ; // handle errors, if any: if ( rc != 0 ) { if ( ok ) *ok = false; QString wmsg = i18n("Failed to execute signature script
%1:
%2
", mUrl, strerror(rc) ); KMessageBox::error(0, wmsg); return QString(); } // no errors: if ( ok ) *ok = true; // get output: QByteArray output = proc.collectedStdout(); // ### hmm, should we allow other encodings, too? return QString::fromLocal8Bit( output.data(), output.size() ); } QString Signature::textFromFile( bool * ok ) const { assert( mType == FromFile ); // ### FIXME: Use KIO::NetAccess to download non-local files! if ( !KUrl(mUrl).isLocalFile() && !(QFileInfo(mUrl).isRelative() && QFileInfo(mUrl).exists()) ) { kDebug( 5006 ) << "Signature::textFromFile: non-local URLs are unsupported" << endl; if ( ok ) *ok = false; return QString(); } if ( ok ) *ok = true; // ### hmm, should we allow other encodings, too? const QByteArray ba = kFileToByteArray( mUrl, false ); return QString::fromLocal8Bit( ba.data(), ba.size() ); } QString Signature::withSeparator( bool * ok ) const { bool internalOK = false; QString signature = rawText( &internalOK ); if ( !internalOK ) { if ( ok ) *ok = false; return QString(); } if ( ok ) *ok = true; if ( signature.isEmpty() ) return signature; // don't add a separator in this case if ( signature.startsWith( QString::fromLatin1("-- \n") ) ) // already have signature separator at start of sig: return QString::fromLatin1("\n") += signature; else if ( signature.indexOf( QString::fromLatin1("\n-- \n") ) != -1 ) // already have signature separator inside sig; don't prepend '\n' // to improve abusing signatures as templates: return signature; else // need to prepend one: return QString::fromLatin1("\n-- \n") + signature; } void Signature::setUrl( const QString & url, bool isExecutable ) { mUrl = url; mType = isExecutable ? FromCommand : FromFile ; } // config keys and values: static const char sigTypeKey[] = "Signature Type"; static const char sigTypeInlineValue[] = "inline"; static const char sigTypeFileValue[] = "file"; static const char sigTypeCommandValue[] = "command"; static const char sigTypeDisabledValue[] = "disabled"; static const char sigTextKey[] = "Inline Signature"; static const char sigFileKey[] = "Signature File"; static const char sigCommandKey[] = "Signature Command"; void Signature::readConfig( const KConfigGroup &config ) { QString sigType = config.readEntry( sigTypeKey ); if ( sigType == sigTypeInlineValue ) { mType = Inlined; } else if ( sigType == sigTypeFileValue ) { mType = FromFile; mUrl = config.readPathEntry( sigFileKey ); } else if ( sigType == sigTypeCommandValue ) { mType = FromCommand; mUrl = config.readPathEntry( sigCommandKey ); } else { mType = Disabled; } mText = config.readEntry( sigTextKey ); } void Signature::writeConfig( KConfigGroup & config ) const { switch ( mType ) { case Inlined: config.writeEntry( sigTypeKey, sigTypeInlineValue ); break; case FromFile: config.writeEntry( sigTypeKey, sigTypeFileValue ); config.writePathEntry( sigFileKey, mUrl ); break; case FromCommand: config.writeEntry( sigTypeKey, sigTypeCommandValue ); config.writePathEntry( sigCommandKey, mUrl ); break; case Disabled: config.writeEntry( sigTypeKey, sigTypeDisabledValue ); default: ; } config.writeEntry( sigTextKey, mText ); } QDataStream & KPIM::operator<<( QDataStream & stream, const KPIM::Signature & sig ) { return stream << static_cast(sig.mType) << sig.mUrl << sig.mText; } QDataStream & KPIM::operator>>( QDataStream & stream, KPIM::Signature & sig ) { quint8 s; stream >> s >> sig.mUrl >> sig.mText; sig.mType = static_cast(s); return stream; } // ### should use a kstaticdeleter? static Identity* identityNull = 0; const Identity& Identity::null() { if ( !identityNull ) identityNull = new Identity; return *identityNull; } bool Identity::isNull() const { return mIdentity.isEmpty() && mFullName.isEmpty() && mEmailAddr.isEmpty() && mOrganization.isEmpty() && mReplyToAddr.isEmpty() && mBcc.isEmpty() && mVCardFile.isEmpty() && mFcc.isEmpty() && mDrafts.isEmpty() && mTemplates.isEmpty() && mPGPEncryptionKey.isEmpty() && mPGPSigningKey.isEmpty() && mSMIMEEncryptionKey.isEmpty() && mSMIMESigningKey.isEmpty() && mTransport.isEmpty() && mDictionary.isEmpty() && #ifdef HAVE_GPGME mPreferredCryptoMessageFormat == Kleo::AutoFormat && #endif mSignature.type() == Signature::Disabled && mXFace.isEmpty(); } bool Identity::operator==( const Identity & other ) const { bool same = mUoid == other.mUoid && mIdentity == other.mIdentity && mFullName == other.mFullName && mEmailAddr == other.mEmailAddr && mOrganization == other.mOrganization && mReplyToAddr == other.mReplyToAddr && mBcc == other.mBcc && mVCardFile == other.mVCardFile && mFcc == other.mFcc && mPGPEncryptionKey == other.mPGPEncryptionKey && mPGPSigningKey == other.mPGPSigningKey && mSMIMEEncryptionKey == other.mSMIMEEncryptionKey && mSMIMESigningKey == other.mSMIMESigningKey && #ifdef HAVE_GPGME mPreferredCryptoMessageFormat == other.mPreferredCryptoMessageFormat && #endif mDrafts == other.mDrafts && mTemplates == other.mTemplates && mTransport == other.mTransport && mDictionary == other.mDictionary && mSignature == other.mSignature && mXFace == other.mXFace && mXFaceEnabled == other.mXFaceEnabled; #if 0 if ( same ) return true; if ( mUoid != other.mUoid ) kDebug() << "mUoid differs : " << mUoid << " != " << other.mUoid << endl; if ( mIdentity != other.mIdentity ) kDebug() << "mIdentity differs : " << mIdentity << " != " << other.mIdentity << endl; if ( mFullName != other.mFullName ) kDebug() << "mFullName differs : " << mFullName << " != " << other.mFullName << endl; if ( mEmailAddr != other.mEmailAddr ) kDebug() << "mEmailAddr differs : " << mEmailAddr << " != " << other.mEmailAddr << endl; if ( mOrganization != other.mOrganization ) kDebug() << "mOrganization differs : " << mOrganization << " != " << other.mOrganization << endl; if ( mReplyToAddr != other.mReplyToAddr ) kDebug() << "mReplyToAddr differs : " << mReplyToAddr << " != " << other.mReplyToAddr << endl; if ( mBcc != other.mBcc ) kDebug() << "mBcc differs : " << mBcc << " != " << other.mBcc << endl; if ( mVCardFile != other.mVCardFile ) kDebug() << "mVCardFile differs : " << mVCardFile << " != " << other.mVCardFile << endl; if ( mFcc != other.mFcc ) kDebug() << "mFcc differs : " << mFcc << " != " << other.mFcc << endl; if ( mPGPEncryptionKey != other.mPGPEncryptionKey ) kDebug() << "mPGPEncryptionKey differs : " << mPGPEncryptionKey << " != " << other.mPGPEncryptionKey << endl; if ( mPGPSigningKey != other.mPGPSigningKey ) kDebug() << "mPGPSigningKey differs : " << mPGPSigningKey << " != " << other.mPGPSigningKey << endl; if ( mSMIMEEncryptionKey != other.mSMIMEEncryptionKey ) kDebug() << "mSMIMEEncryptionKey differs : '" << mSMIMEEncryptionKey << "' != '" << other.mSMIMEEncryptionKey << "'" << endl; if ( mSMIMESigningKey != other.mSMIMESigningKey ) kDebug() << "mSMIMESigningKey differs : " << mSMIMESigningKey << " != " << other.mSMIMESigningKey << endl; if ( mPreferredCryptoMessageFormat != other.mPreferredCryptoMessageFormat ) kDebug() << "mPreferredCryptoMessageFormat differs : " << mPreferredCryptoMessageFormat << " != " << other.mPreferredCryptoMessageFormat << endl; if ( mDrafts != other.mDrafts ) kDebug() << "mDrafts differs : " << mDrafts << " != " << other.mDrafts << endl; if ( mTemplates != other.mTemplates ) kDebug() << "mTemplates differs : " << mTemplates << " != " << other.mTemplates << endl; if ( mTransport != other.mTransport ) kDebug() << "mTransport differs : " << mTransport << " != " << other.mTransport << endl; if ( mDictionary != other.mDictionary ) kDebug() << "mDictionary differs : " << mDictionary << " != " << other.mDictionary << endl; if ( ! ( mSignature == other.mSignature ) ) kDebug() << "mSignature differs" << endl; #endif return same; } Identity::Identity( const QString & id, const QString & fullName, const QString & emailAddr, const QString & organization, const QString & replyToAddr ) : mUoid( 0 ), mIdentity( id ), mFullName( fullName ), mEmailAddr( emailAddr ), mOrganization( organization ), mReplyToAddr( replyToAddr ), // Using "" instead of null to make operator==() not fail // (readConfig returns "") mBcc( "" ), mVCardFile( "" ), mPGPEncryptionKey( "" ), mPGPSigningKey( "" ), mSMIMEEncryptionKey( "" ), mSMIMESigningKey( "" ), mFcc( "" ), mDrafts( "" ), mTemplates( "" ), mTransport( "" ), mDictionary( "" ), mXFace( "" ), mXFaceEnabled( false ), mIsDefault( false ) #ifdef HAVE_GPGME , mPreferredCryptoMessageFormat( Kleo::AutoFormat ) #endif { } Identity::~Identity() { } void Identity::readConfig( const KConfigGroup & config ) { mUoid = config.readEntry("uoid",QVariant(0)).toUInt(); mIdentity = config.readEntry("Identity"); mFullName = config.readEntry("Name"); mEmailAddr = config.readEntry("Email Address"); mVCardFile = config.readPathEntry("VCardFile"); mOrganization = config.readEntry("Organization"); mPGPSigningKey = config.readEntry("PGP Signing Key").toLatin1(); mPGPEncryptionKey = config.readEntry("PGP Encryption Key").toLatin1(); mSMIMESigningKey = config.readEntry("SMIME Signing Key").toLatin1(); mSMIMEEncryptionKey = config.readEntry("SMIME Encryption Key").toLatin1(); #ifdef HAVE_GPGME mPreferredCryptoMessageFormat = Kleo::stringToCryptoMessageFormat( config.readEntry("Preferred Crypto Message Format", "none" ) ); #endif mReplyToAddr = config.readEntry("Reply-To Address"); mBcc = config.readEntry("Bcc"); mFcc = config.readEntry("Fcc", "sent-mail"); if( mFcc.isEmpty() ) mFcc = "sent-mail"; mDrafts = config.readEntry("Drafts", "drafts"); if( mDrafts.isEmpty() ) mDrafts = "drafts"; mTemplates = config.readEntry("Templates", "templates"); if( mTemplates.isEmpty() ) mTemplates = "templates"; mTransport = config.readEntry("Transport"); mDictionary = config.readEntry( "Dictionary" ); mXFace = config.readEntry( "X-Face" ); mXFaceEnabled = config.readEntry( "X-FaceEnabled", QVariant(false) ).toBool(); mSignature.readConfig( config ); kDebug(5006) << "Identity::readConfig(): UOID = " << mUoid << " for identity named \"" << mIdentity << "\"" << endl; } void Identity::writeConfig( KConfigGroup & config ) const { config.writeEntry("uoid", mUoid); config.writeEntry("Identity", mIdentity); config.writeEntry("Name", mFullName); config.writeEntry("Organization", mOrganization); config.writeEntry("PGP Signing Key", mPGPSigningKey.data()); config.writeEntry("PGP Encryption Key", mPGPEncryptionKey.data()); config.writeEntry("SMIME Signing Key", mSMIMESigningKey.data()); config.writeEntry("SMIME Encryption Key", mSMIMEEncryptionKey.data()); #ifdef HAVE_GPGME config.writeEntry("Preferred Crypto Message Format", Kleo::cryptoMessageFormatToString( mPreferredCryptoMessageFormat ) ); #else config.writeEntry("Preferred Crypto Message Format", QString() ); #endif config.writeEntry("Email Address", mEmailAddr); config.writeEntry("Reply-To Address", mReplyToAddr); config.writeEntry("Bcc", mBcc); config.writePathEntry("VCardFile", mVCardFile); config.writeEntry("Transport", mTransport); config.writeEntry("Fcc", mFcc); config.writeEntry("Drafts", mDrafts); config.writeEntry("Templates", mTemplates); config.writeEntry( "Dictionary", mDictionary ); config.writeEntry( "X-Face", mXFace ); config.writeEntry( "X-FaceEnabled", mXFaceEnabled ); mSignature.writeConfig( config ); } QDataStream & KPIM::operator<<( QDataStream & stream, const KPIM::Identity & i ) { return stream << static_cast(i.uoid()) << i.identityName() << i.fullName() << i.organization() << i.pgpSigningKey() << i.pgpEncryptionKey() << i.smimeSigningKey() << i.smimeEncryptionKey() << i.emailAddr() << i.replyToAddr() << i.bcc() << i.vCardFile() << i.transport() << i.fcc() << i.drafts() << i.templates() << i.mSignature << i.dictionary() << i.xface() #ifdef HAVE_GPGME << QString( Kleo::cryptoMessageFormatToString( i.mPreferredCryptoMessageFormat ) ); #else << QString(); #endif } QDataStream & KPIM::operator>>( QDataStream & stream, KPIM::Identity & i ) { quint32 uoid; QString format; stream >> uoid >> i.mIdentity >> i.mFullName >> i.mOrganization >> i.mPGPSigningKey >> i.mPGPEncryptionKey >> i.mSMIMESigningKey >> i.mSMIMEEncryptionKey >> i.mEmailAddr >> i.mReplyToAddr >> i.mBcc >> i.mVCardFile >> i.mTransport >> i.mFcc >> i.mDrafts >> i.mTemplates >> i.mSignature >> i.mDictionary >> i.mXFace >> format; i.mUoid = uoid; #ifdef HAVE_GPGME i.mPreferredCryptoMessageFormat = Kleo::stringToCryptoMessageFormat( format.toLatin1() ); #endif return stream; } //----------------------------------------------------------------------------- bool Identity::mailingAllowed() const { return !mEmailAddr.isEmpty(); } void Identity::setIsDefault( bool flag ) { mIsDefault = flag; } void Identity::setIdentityName( const QString & name ) { mIdentity = name; } void Identity::setFullName(const QString &str) { mFullName = str; } //----------------------------------------------------------------------------- void Identity::setOrganization(const QString &str) { mOrganization = str; } void Identity::setPGPSigningKey(const QByteArray &str) { mPGPSigningKey = str; if ( mPGPSigningKey.isNull() ) mPGPSigningKey = ""; } void Identity::setPGPEncryptionKey(const QByteArray &str) { mPGPEncryptionKey = str; if ( mPGPEncryptionKey.isNull() ) mPGPEncryptionKey = ""; } void Identity::setSMIMESigningKey(const QByteArray &str) { mSMIMESigningKey = str; if ( mSMIMESigningKey.isNull() ) mSMIMESigningKey = ""; } void Identity::setSMIMEEncryptionKey(const QByteArray &str) { mSMIMEEncryptionKey = str; if ( mSMIMEEncryptionKey.isNull() ) mSMIMEEncryptionKey = ""; } //----------------------------------------------------------------------------- void Identity::setEmailAddr(const QString &str) { mEmailAddr = str; } //----------------------------------------------------------------------------- void Identity::setVCardFile(const QString &str) { mVCardFile = str; } //----------------------------------------------------------------------------- QString Identity::fullEmailAddr(void) const { if (mFullName.isEmpty()) return mEmailAddr; const QString specials("()<>@,.;:[]"); QString result; // add DQUOTE's if necessary: bool needsQuotes=false; for (int i=0; i < mFullName.length(); i++) { if ( specials.contains( mFullName[i] ) ) needsQuotes = true; else if ( mFullName[i] == '\\' || mFullName[i] == '"' ) { needsQuotes = true; result += '\\'; } result += mFullName[i]; } if (needsQuotes) { result.insert(0,'"'); result += '"'; } result += " <" + mEmailAddr + '>'; return result; } //----------------------------------------------------------------------------- void Identity::setReplyToAddr(const QString& str) { mReplyToAddr = str; } //----------------------------------------------------------------------------- void Identity::setSignatureFile(const QString &str) { mSignature.setUrl( str, signatureIsCommand() ); } //----------------------------------------------------------------------------- void Identity::setSignatureInlineText(const QString &str ) { mSignature.setText( str ); } //----------------------------------------------------------------------------- void Identity::setTransport(const QString &str) { mTransport = str; if ( mTransport.isNull() ) mTransport = ""; } //----------------------------------------------------------------------------- void Identity::setFcc(const QString &str) { mFcc = str; if ( mFcc.isNull() ) mFcc = ""; } //----------------------------------------------------------------------------- void Identity::setDrafts(const QString &str) { mDrafts = str; if ( mDrafts.isNull() ) mDrafts = ""; } //----------------------------------------------------------------------------- void Identity::setTemplates(const QString &str) { mTemplates = str; if ( mTemplates.isNull() ) mTemplates = ""; } //----------------------------------------------------------------------------- void Identity::setDictionary( const QString &str ) { mDictionary = str; if ( mDictionary.isNull() ) mDictionary = ""; } //----------------------------------------------------------------------------- void Identity::setXFace( const QString &str ) { mXFace = str; mXFace.remove( " " ); mXFace.remove( "\n" ); mXFace.remove( "\r" ); } //----------------------------------------------------------------------------- void Identity::setXFaceEnabled( const bool on ) { mXFaceEnabled = on; } //----------------------------------------------------------------------------- QString Identity::signatureText( bool * ok ) const { bool internalOK = false; QString signatureText = mSignature.withSeparator( &internalOK ); if ( internalOK ) { if ( ok ) *ok=true; return signatureText; } // OK, here comes the funny part. The call to // Signature::withSeparator() failed, so we should probably fix the // cause: if ( ok ) *ok = false; return QString(); #if 0 // ### FIXME: error handling if (mSignatureFile.endsWith("|")) { } else { } #endif return QString(); } QString Identity::mimeDataType() { return "application/x-kmail-identity-drag"; } bool Identity::canDecode( const QMimeData*md ) { return md->hasFormat( mimeDataType() ); } void Identity::populateMimeData( QMimeData*md ) { QByteArray a; { QDataStream s( &a, QIODevice::WriteOnly ); s << this; } md->setData( mimeDataType(), a ); } Identity Identity::fromMimeData( const QMimeData*md ) { Identity i; if ( canDecode( md ) ) { QByteArray ba = md->data( mimeDataType() ); QDataStream s( &ba, QIODevice::ReadOnly ); s >> i; } return i; } diff --git a/kpimidentities/identity.h b/kpimidentities/identity.h index a49020904..9b29b63c2 100644 --- a/kpimidentities/identity.h +++ b/kpimidentities/identity.h @@ -1,333 +1,333 @@ /* -*- mode: C++; c-file-style: "gnu" -*- * User identity information * * Author: Stefan Taferner * This code is under GPL */ #ifndef kpim_identity_h #define kpim_identity_h #include // HAVE_GPGME #ifdef HAVE_GPGME #include #endif #include #include #include #include -class KProcess; +class K3Process; namespace KPIM { class Identity; class Signature; } class KConfigGroup; class IdentityList; class QDataStream; class QMimeData; namespace KPIM { /** * @short abstraction of a signature (aka "footer"). * @author Marc Mutz */ class KDE_EXPORT Signature { friend class Identity; friend QDataStream & KPIM::operator<<( QDataStream & stream, const Signature & sig ); friend QDataStream & KPIM::operator>>( QDataStream & stream, Signature & sig ); public: /** Type of signature (ie. way to obtain the signature text) */ enum Type { Disabled = 0, Inlined = 1, FromFile = 2, FromCommand = 3 }; /** Used for comparison */ bool operator==( const Signature & other ) const; /** Constructor for disabled signature */ Signature(); /** Constructor for inline text */ Signature( const QString & text ); /** Constructor for text from a file or from output of a command */ Signature( const QString & url, bool isExecutable ); /** @return the raw signature text as entered resp. read from file. */ QString rawText( bool * ok=0 ) const; /** @return the signature text with a "-- " separator added, if necessary. */ QString withSeparator( bool * ok=0 ) const; /** Set the signature text and mark this signature as being of "inline text" type. */ void setText( const QString & text ) { mText = text; } QString text() const { return mText; } /** Set the signature URL and mark this signature as being of "from file" resp. "from output of command" type. */ void setUrl( const QString & url, bool isExecutable=false ); QString url() const { return mUrl; } /// @return the type of signature (ie. way to obtain the signature text) Type type() const { return mType; } void setType( Type type ) { mType = type; } protected: void writeConfig( KConfigGroup& config ) const; void readConfig( const KConfigGroup& config ); private: QString textFromFile( bool * ok ) const; QString textFromCommand( bool * ok ) const; private: QString mUrl; QString mText; Type mType; }; /** User identity information */ class KDE_EXPORT Identity { // only the identity manager should be able to construct and // destruct us, but then we get into problems with using // QValueList and especially qHeapSort(). friend class IdentityManager; friend QDataStream & operator<<( QDataStream & stream, const KPIM::Identity & ident ); friend QDataStream & operator>>( QDataStream & stream, KPIM::Identity & ident ); public: typedef QList List; /** used for comparison */ bool operator==( const Identity & other ) const; bool operator!=( const Identity & other ) const { return !operator==( other ); } /** used for sorting */ bool operator<( const Identity & other ) const { if ( isDefault() ) return true; if ( other.isDefault() ) return false; return identityName() < other.identityName(); } bool operator>( const Identity & other ) const { if ( isDefault() ) return false; if ( other.isDefault() ) return true; return identityName() > other.identityName(); } bool operator<=( const Identity & other ) const { return !operator>( other ); } bool operator>=( const Identity & other ) const { return !operator<( other ); } /** Constructor */ explicit Identity( const QString & id=QString(), const QString & realName=QString(), const QString & emailAddr=QString(), const QString & organization=QString(), const QString & replyToAddress=QString() ); /** Destructor */ ~Identity(); protected: /** Read configuration from config. Group must be preset (or use KConfigGroup). Called from IdentityManager. */ void readConfig( const KConfigGroup & ); /** Write configuration to config. Group must be preset (or use KConfigGroup). Called from IdentityManager. */ void writeConfig( KConfigGroup & ) const; public: /** Tests if there are enough values set to allow mailing */ bool mailingAllowed() const; /** Identity/nickname for this collection */ QString identityName() const { return mIdentity; } void setIdentityName( const QString & name ); /** @return whether this identity is the default identity */ bool isDefault() const { return mIsDefault; } /// Unique Object Identifier for this identity uint uoid() const { return mUoid; } protected: /** Set whether this identity is the default identity. Since this affects all other identites, too (most notably, the old default identity), only the IdentityManager can change this. You should use
       kmkernel->identityManager()->setAsDefault( name_of_default )
       
instead. **/ void setIsDefault( bool flag ); void setUoid( uint aUoid ) { mUoid = aUoid; } public: /** Full name of the user */ QString fullName() const { return mFullName; } void setFullName(const QString&); /** The user's organization (optional) */ QString organization() const { return mOrganization; } void setOrganization(const QString&); KDE_DEPRECATED QByteArray pgpIdentity() const { return pgpEncryptionKey(); } KDE_DEPRECATED void setPgpIdentity( const QByteArray & key ) { setPGPEncryptionKey( key ); setPGPSigningKey( key ); } /** The user's OpenPGP encryption key */ QByteArray pgpEncryptionKey() const { return mPGPEncryptionKey; } void setPGPEncryptionKey( const QByteArray & key ); /** The user's OpenPGP signing key */ QByteArray pgpSigningKey() const { return mPGPSigningKey; } void setPGPSigningKey( const QByteArray & key ); /** The user's S/MIME encryption key */ QByteArray smimeEncryptionKey() const { return mSMIMEEncryptionKey; } void setSMIMEEncryptionKey( const QByteArray & key ); /** The user's S/MIME signing key */ QByteArray smimeSigningKey() const { return mSMIMESigningKey; } void setSMIMESigningKey( const QByteArray & key ); #ifdef HAVE_GPGME Kleo::CryptoMessageFormat preferredCryptoMessageFormat() const { return mPreferredCryptoMessageFormat; } void setPreferredCryptoMessageFormat( Kleo::CryptoMessageFormat format ) { mPreferredCryptoMessageFormat = format; } #endif /** email address (without the user name - only name\@host) */ QString emailAddr() const { return mEmailAddr; } void setEmailAddr(const QString&); /** vCard to attach to outgoing emails */ QString vCardFile() const { return mVCardFile; } void setVCardFile(const QString&); /** email address in the format "username " suitable for the "From:" field of email messages. */ QString fullEmailAddr() const; /** email address for the ReplyTo: field */ QString replyToAddr() const { return mReplyToAddr; } void setReplyToAddr(const QString&); /** email addresses for the BCC: field */ QString bcc() const { return mBcc; } void setBcc(const QString& aBcc) { mBcc = aBcc; } void setSignature( const Signature & sig ) { mSignature = sig; } Signature & signature() /* _not_ const! */ { return mSignature; } protected: /** @return true if the signature is read from the output of a command */ bool signatureIsCommand() const { return mSignature.type() == Signature::FromCommand; } /** @return true if the signature is read from a text file */ bool signatureIsPlainFile() const { return mSignature.type() == Signature::FromFile; } /** @return true if the signature was specified directly */ bool signatureIsInline() const { return mSignature.type() == Signature::Inlined; } /** name of the signature file (with path) */ QString signatureFile() const { return mSignature.url(); } void setSignatureFile(const QString&); /** inline signature */ QString signatureInlineText() const { return mSignature.text();} void setSignatureInlineText(const QString&); /** Inline or signature from a file */ bool useSignatureFile() const { return signatureIsPlainFile() || signatureIsCommand(); } public: /** Returns the signature. This method also takes care of special signature files that are shell scripts and handles them correct. So use this method to rectreive the contents of the signature file. If @p prompt is false, no errors will be displayed (useful for retries). */ QString signatureText( bool * ok=0) const; /** The transport that is set for this identity. Used to link a transport with an identity. */ QString transport() const { return mTransport; } void setTransport(const QString&); /** The folder where sent messages from this identity will be stored by default. */ QString fcc() const { return mFcc; } void setFcc(const QString&); /** The folder where draft messages from this identity will be stored by default. */ QString drafts() const { return mDrafts; } void setDrafts(const QString&); /** The folder where template messages from this identity will be stored by default. */ QString templates() const { return mTemplates; } void setTemplates( const QString& ); /** dictionary which should be used for spell checking */ QString dictionary() const { return mDictionary; } void setDictionary( const QString& ); /** a X-Face header for this identity */ QString xface() const { return mXFace; } void setXFace( const QString& ); bool isXFaceEnabled() const { return mXFaceEnabled; } void setXFaceEnabled( const bool ); static const Identity& null(); bool isNull() const; static QString mimeDataType(); static bool canDecode( const QMimeData* ); void populateMimeData( QMimeData* ); static Identity fromMimeData( const QMimeData* ); protected: // if you add new members, make sure they have an operator= (or the // compiler can synthesize one) and amend Identity::operator==, // isNull(), readConfig() and writeConfig() as well as operator<< // and operator>> accordingly: uint mUoid; QString mIdentity, mFullName, mEmailAddr, mOrganization; QString mReplyToAddr; QString mBcc; QString mVCardFile; QByteArray mPGPEncryptionKey, mPGPSigningKey, mSMIMEEncryptionKey, mSMIMESigningKey; QString mFcc, mDrafts, mTemplates, mTransport; QString mDictionary; QString mXFace; bool mXFaceEnabled; Signature mSignature; bool mIsDefault; #ifdef HAVE_GPGME Kleo::CryptoMessageFormat mPreferredCryptoMessageFormat; #endif }; KDE_EXPORT QDataStream & operator<<( QDataStream & stream, const KPIM::Signature & sig ); KDE_EXPORT QDataStream & operator>>( QDataStream & stream, KPIM::Signature & sig ); KDE_EXPORT QDataStream & operator<<( QDataStream & stream, const KPIM::Identity & ident ); KDE_EXPORT QDataStream & operator>>( QDataStream & stream, KPIM::Identity & ident ); } // namespace KPIM #endif /*kpim_identity_h*/ diff --git a/mailtransport/precommandjob.cpp b/mailtransport/precommandjob.cpp index 19877cada..1f85f18b1 100644 --- a/mailtransport/precommandjob.cpp +++ b/mailtransport/precommandjob.cpp @@ -1,82 +1,82 @@ /* Copyright (c) 2007 Volker Krause Based on KMail code by: Copyright (c) 1996-1998 Stefan Taferner Copyright (c) 2000-2002 Michael Haeckel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "precommandjob.h" #include -#include +#include using namespace MailTransport; PrecommandJob::PrecommandJob(const QString & precommand, QObject * parent) : KJob( parent ), mProcess( 0 ), mPrecommand( precommand ) { - mProcess = new KProcess( this ); + mProcess = new K3Process( this ); mProcess->setUseShell( true ); *mProcess << precommand; - connect( mProcess, SIGNAL(processExited(KProcess*)), SLOT(processExited(KProcess*)) ); + connect( mProcess, SIGNAL(processExited(K3Process*)), SLOT(processExited(K3Process*)) ); } PrecommandJob::~ PrecommandJob() { delete mProcess; } void PrecommandJob::start() { - if ( !mProcess->start( KProcess::NotifyOnExit ) ) { + if ( !mProcess->start( K3Process::NotifyOnExit ) ) { setError( UserDefinedError ); setErrorText( i18n("Could not execute precommand '%1'.", mPrecommand ) ); emitResult(); } else { emit infoMessage( this, i18n("Executing precommand"), i18n("Executing precommand '%1'.", mPrecommand ) ); } } bool PrecommandJob::doKill() { delete mProcess; mProcess = 0; return true; } -void PrecommandJob::processExited(KProcess *process) +void PrecommandJob::processExited(K3Process *process) { Q_ASSERT( mProcess == process ); if ( mProcess->normalExit() ) { if ( mProcess->exitStatus() ) { setError( UserDefinedError ); setErrorText( i18n("The precommand exited with code %1.", mProcess->exitStatus()) ); } } if ( mProcess->signalled() ) { setError( UserDefinedError ); setErrorText( i18n("The precommand was terminated by signal %1", mProcess->exitSignal() ) ); } emitResult(); } #include "precommandjob.moc" diff --git a/mailtransport/precommandjob.h b/mailtransport/precommandjob.h index 5da29eae0..d539c9da7 100644 --- a/mailtransport/precommandjob.h +++ b/mailtransport/precommandjob.h @@ -1,67 +1,67 @@ /* Copyright (c) 2007 Volker Krause Based on KMail code by: Copyright (c) 1996-1998 Stefan Taferner Copyright (c) 2000-2002 Michael Haeckel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MAILTRANSPORT_PRECOMMANDJOB_H #define MAILTRANSPORT_PRECOMMANDJOB_H #include -class KProcess; +class K3Process; namespace MailTransport { /** Job to execute commands before connecting to an account. */ class PrecommandJob : public KJob { Q_OBJECT public: /** Creates a new precommand job. @param precommand The command to run. @param parent The parent object. */ explicit PrecommandJob( const QString &precommand, QObject *parent = 0 ); /** Destroys this job. */ virtual ~PrecommandJob(); virtual void start(); protected: virtual bool doKill(); private slots: - void processExited(KProcess *process); + void processExited(K3Process *process); private: - KProcess *mProcess; + K3Process *mProcess; QString mPrecommand; }; } #endif diff --git a/mailtransport/sendmailjob.cpp b/mailtransport/sendmailjob.cpp index ae2a4d9d8..a1fbc940c 100644 --- a/mailtransport/sendmailjob.cpp +++ b/mailtransport/sendmailjob.cpp @@ -1,92 +1,92 @@ /* Copyright (c) 2007 Volker Krause Based on KMail code by: Copyright (c) 1996-1998 Stefan Taferner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sendmailjob.h" #include "transport.h" #include -#include +#include #include using namespace MailTransport; SendmailJob::SendmailJob(Transport * transport, QObject * parent) : TransportJob( transport, parent ) { - mProcess = new KProcess( this ); - connect( mProcess, SIGNAL(processExited(KProcess*)), SLOT(sendmailExited()) ); - connect( mProcess, SIGNAL(wroteStdin(KProcess*)), SLOT(wroteStdin()) ); - connect( mProcess, SIGNAL(receivedStderr(KProcess*,char*,int)), - SLOT(receivedStdErr(KProcess*,char*,int)) ); + mProcess = new K3Process( this ); + connect( mProcess, SIGNAL(processExited(K3Process*)), SLOT(sendmailExited()) ); + connect( mProcess, SIGNAL(wroteStdin(K3Process*)), SLOT(wroteStdin()) ); + connect( mProcess, SIGNAL(receivedStderr(K3Process*,char*,int)), + SLOT(receivedStdErr(K3Process*,char*,int)) ); } SendmailJob::~ SendmailJob() { delete mProcess; } void SendmailJob::doStart() { *mProcess << transport()->host() << "-i" << "-f" << sender() << to() << cc() << bcc(); - if ( !mProcess->start( KProcess::NotifyOnExit, KProcess::All ) ) { + if ( !mProcess->start( K3Process::NotifyOnExit, K3Process::All ) ) { setError( UserDefinedError ); setErrorText( i18n("Failed to execute mailer program %1", transport()->host()) ); emitResult(); } setTotalAmount( KJob::Bytes, data().length() ); wroteStdin(); } void SendmailJob::sendmailExited() { if ( !mProcess->normalExit() || !mProcess->exitStatus() == 0 ) { setError( UserDefinedError ); setErrorText( i18n("Sendmail exited abnormally: %1", mLastError) ); } emitResult(); } void SendmailJob::wroteStdin() { setProcessedAmount( KJob::Bytes, buffer()->pos() ); if ( buffer()->atEnd() ) { mProcess->closeStdin(); } else { QByteArray data = buffer()->read( 1024 ); mProcess->writeStdin( data.constData(), data.length() ); } } -void SendmailJob::receivedStdErr(KProcess * proc, char * data, int len) +void SendmailJob::receivedStdErr(K3Process * proc, char * data, int len) { Q_ASSERT( proc == mProcess ); mLastError += QString::fromLocal8Bit( data, len ); } bool SendmailJob::doKill() { delete mProcess; mProcess = 0; return true; } #include "sendmailjob.moc" diff --git a/mailtransport/sendmailjob.h b/mailtransport/sendmailjob.h index 50513aa8c..c4e8db3ed 100644 --- a/mailtransport/sendmailjob.h +++ b/mailtransport/sendmailjob.h @@ -1,66 +1,66 @@ /* Copyright (c) 2007 Volker Krause Based on KMail code by: Copyright (c) 1996-1998 Stefan Taferner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MailTransport_SENDMAILJOB_H #define MailTransport_SENDMAILJOB_H #include -class KProcess; +class K3Process; namespace MailTransport { /** Mail transport job for sendmail. */ class MAILTRANSPORT_EXPORT SendmailJob : public TransportJob { Q_OBJECT public: /** Creates a SendmailJob. @param transport The transport settings. @param parent The parent object. */ explicit SendmailJob( Transport* transport, QObject* parent = 0 ); /** Destroys this job. */ virtual ~SendmailJob(); protected: virtual void doStart(); virtual bool doKill(); private slots: void sendmailExited(); void wroteStdin(); - void receivedStdErr( KProcess *proc, char* data, int len ); + void receivedStdErr( K3Process *proc, char* data, int len ); private: - KProcess* mProcess; + K3Process* mProcess; QString mLastError; }; } #endif diff --git a/syndication/dataretriever.cpp b/syndication/dataretriever.cpp index f68304aca..98aadd8ab 100644 --- a/syndication/dataretriever.cpp +++ b/syndication/dataretriever.cpp @@ -1,223 +1,223 @@ /* * dataretriever.cpp * * Copyright (c) 2001, 2002, 2003 Frerich Raabe * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. For licensing and distribution details, check the * accompanying file 'COPYING'. */ #include "dataretriever.h" #include "global.h" #include -#include +#include #include #include #include namespace Syndication { DataRetriever::DataRetriever() { } DataRetriever::~DataRetriever() { } struct FileRetriever::FileRetrieverPrivate { FileRetrieverPrivate() : buffer(NULL), lastError(0), job(NULL) { } ~FileRetrieverPrivate() { delete buffer; } QBuffer *buffer; int lastError; KIO::Job *job; }; FileRetriever::FileRetriever() : d(new FileRetrieverPrivate) { } FileRetriever::~FileRetriever() { delete d; } bool FileRetriever::m_useCache = true; QString FileRetriever::m_userAgent = QString("Syndication %1").arg(SYNDICATION_VERSION); void FileRetriever::setUserAgent(const QString& userAgent) { m_userAgent = userAgent; } void FileRetriever::setUseCache(bool enabled) { m_useCache = enabled; } void FileRetriever::retrieveData(const KUrl &url) { if (d->buffer) return; d->buffer = new QBuffer; d->buffer->open(QIODevice::WriteOnly); KUrl u = url; if (u.protocol() == "feed") u.setProtocol("http"); d->job = KIO::get(u, false, false); d->job->addMetaData("UserAgent", m_userAgent); d->job->addMetaData("cache", m_useCache ? "refresh" : "reload"); QTimer::singleShot(1000*90, this, SLOT(slotTimeout())); connect(d->job, SIGNAL(data(KIO::Job*, const QByteArray&)), SLOT(slotData(KIO::Job*, const QByteArray&))); connect(d->job, SIGNAL(result(KJob*)), SLOT(slotResult(KJob*))); connect(d->job, SIGNAL(permanentRedirection(KIO::Job*, const KUrl&, const KUrl&)), SLOT(slotPermanentRedirection(KIO::Job*, const KUrl&, const KUrl&))); } void FileRetriever::slotTimeout() { abort(); delete d->buffer; d->buffer = NULL; d->lastError = KIO::ERR_SERVER_TIMEOUT; emit dataRetrieved(QByteArray(), false); } int FileRetriever::errorCode() const { return d->lastError; } void FileRetriever::slotData(KIO::Job *, const QByteArray &data) { d->buffer->write(data.data(), data.size()); } void FileRetriever::slotResult(KJob *job) { QByteArray data = d->buffer->buffer(); data.detach(); delete d->buffer; d->buffer = NULL; d->lastError = job->error(); emit dataRetrieved(data, d->lastError == 0); } void FileRetriever::slotPermanentRedirection(KIO::Job*, const KUrl&, const KUrl& newUrl) { emit permanentRedirection(newUrl); } void FileRetriever::abort() { if (d->job) { d->job->kill(); d->job = NULL; } } struct OutputRetriever::OutputRetrieverPrivate { OutputRetrieverPrivate() : process(0L), buffer(0L), lastError(0) { } ~OutputRetrieverPrivate() { delete process; delete buffer; } - KShellProcess *process; + K3ShellProcess *process; QBuffer *buffer; int lastError; }; OutputRetriever::OutputRetriever() : d(new OutputRetrieverPrivate) { } OutputRetriever::~OutputRetriever() { delete d; } void OutputRetriever::retrieveData(const KUrl &url) { // Ignore subsequent calls if we didn't finish the previous job yet. if (d->buffer || d->process) return; d->buffer = new QBuffer; d->buffer->open(QIODevice::WriteOnly); - d->process = new KShellProcess(); - connect(d->process, SIGNAL(processExited(KProcess*)), - SLOT(slotExited(KProcess*))); - connect(d->process, SIGNAL(receivedStdout(KProcess*, char*, int)), - SLOT(slotOutput(KProcess*, char*, int))); + d->process = new K3ShellProcess(); + connect(d->process, SIGNAL(processExited(K3Process*)), + SLOT(slotExited(K3Process*))); + connect(d->process, SIGNAL(receivedStdout(K3Process*, char*, int)), + SLOT(slotOutput(K3Process*, char*, int))); *d->process << url.path(); - d->process->start(KProcess::NotifyOnExit, KProcess::Stdout); + d->process->start(K3Process::NotifyOnExit, K3Process::Stdout); } int OutputRetriever::errorCode() const { return d->lastError; } -void OutputRetriever::slotOutput(KProcess *, char *data, int length) +void OutputRetriever::slotOutput(K3Process *, char *data, int length) { d->buffer->write(data, length); } -void OutputRetriever::slotExited(KProcess *p) +void OutputRetriever::slotExited(K3Process *p) { if (!p->normalExit()) d->lastError = p->exitStatus(); QByteArray data = d->buffer->buffer(); data.detach(); delete d->buffer; d->buffer = NULL; delete d->process; d->process = NULL; emit dataRetrieved(data, p->normalExit() && p->exitStatus() == 0); } } // namespace Syndication #include "dataretriever.moc" diff --git a/syndication/dataretriever.h b/syndication/dataretriever.h index 099bdb72d..9a4a432b9 100644 --- a/syndication/dataretriever.h +++ b/syndication/dataretriever.h @@ -1,243 +1,243 @@ /* * Copyright (c) 2001, 2002, 2003 Frerich Raabe * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. For licensing and distribution details, check the * accompanying file 'COPYING'. */ #ifndef SYNDICATION_DATARETRIEVER_H #define SYNDICATION_DATARETRIEVER_H #include "ksyndication.h" #include #include namespace KIO { class Job; } class KJob; -class KProcess; +class K3Process; class KUrl; class QByteArray; namespace Syndication { /** * Abstract baseclass for all data retriever classes. Subclass this to add * a new retrieval algorithm which can then be plugged into the RSS loader. * @see Loader, FileRetriever, OutputRetriever */ class SYNDICATION_EXPORT DataRetriever : public QObject { Q_OBJECT public: /** * Default constructor. */ DataRetriever(); /** * Destructor. */ virtual ~DataRetriever(); /** * Retrieve data from the given URL. This method is supposed to get * reimplemented by subclasses. It will be called by the Loader * class in case it needs to retrieve the data. * * @param url the URL to retrieve data from * * @see Loader::loadFrom() */ virtual void retrieveData(const KUrl& url) = 0; /** * @return An error code which might give a more precise information * about what went wrong in case the 'success' flag returned with * the dataRetrieved() signal was 'false'. Note that the meaning of * the returned integer depends on the actual data retriever. */ virtual int errorCode() const = 0; /** * aborts the retrieval process. */ virtual void abort() = 0; Q_SIGNALS: /** * Emit this signal to tell the Loader class that the retrieval * process was finished. * @param data Should contain the retrieved data and will get * parsed by the Loader class. * @param success Indicates whether there were any problems during * the retrieval process. Pass 'true' to indicate that everything * went seamlessy, 'false' to tell the Loader that something went * wrong and that the data parameter might contain no or invalid * data. */ void dataRetrieved(const QByteArray& data, bool success); private: DataRetriever(const DataRetriever& other); DataRetriever& operator=(const DataRetriever& other); }; /** * Implements a data retriever which executes a program and stores returned * by the program on stdout. To be used with Loader::loadFrom(). * @see DataRetriever, Loader::loadFrom() */ class SYNDICATION_EXPORT OutputRetriever : public DataRetriever { Q_OBJECT public: /** * Default constructor. */ OutputRetriever(); /** * Destructor. */ virtual ~OutputRetriever(); /** * Executes the program referenced by the given URL and retrieves * the data which the program prints to stdout. * @param url An URL which is supposed to reference an executable * file. * @see Loader::loadFrom() */ virtual void retrieveData(const KUrl& url); /** * @return The error code for the last process of retrieving data. * 0 is returned in case there was no error, otherwise an error * code which depends on the particular program which was run is * returned. */ virtual int errorCode() const; virtual void abort() {} private Q_SLOTS: - void slotOutput(KProcess* process, char* data, int length); - void slotExited(KProcess* process); + void slotOutput(K3Process* process, char* data, int length); + void slotExited(K3Process* process); private: OutputRetriever(const OutputRetriever& other); OutputRetriever& operator=(const OutputRetriever& other); struct OutputRetrieverPrivate; OutputRetrieverPrivate* d; }; /** * Implements a file retriever, to be used with Loader::loadFrom(). * @see DataRetriever, Loader::loadFrom() */ class SYNDICATION_EXPORT FileRetriever : public DataRetriever { Q_OBJECT public: /** * Default constructor. */ FileRetriever(); /** * Destructor. */ virtual ~FileRetriever(); /** * Downloads the file referenced by the given URL and passes it's * contents on to the Loader. * @param url An URL referencing a file which is assumed to * reference valid XML. * @see Loader::loadFrom() */ virtual void retrieveData(const KUrl& url); /** * @return The error code for the last process of retrieving data. * The returned numbers correspond directly to the error codes * as * defined by KIO. */ virtual int errorCode() const; /** * aborts the retrieval process. */ virtual void abort(); /** * sets whether the retriever should use the KHTML cache or * always refetch the file. By default, the cache is used. * * @param enabled whether to use the HTML cache or not */ static void setUseCache(bool enabled); /** * sets the user agent string sent to the remote server * * @param userAgent user agent string */ static void setUserAgent(const QString& userAgent); Q_SIGNALS: /** * Signals a permanent redirection. The redirection itself is * handled internally, so you don't need to call Loader::loadFrom() * with the new URL. This signal is useful in case you want to * notify the user, or adjust a database entry. * * @param url the new URL after the redirection * * @see Loader::loadFrom() */ void permanentRedirection(const KUrl& url); protected Q_SLOTS: void slotTimeout(); private Q_SLOTS: void slotData(KIO::Job*job, const QByteArray& data); void slotResult(KJob* job); void slotPermanentRedirection(KIO::Job* job, const KUrl& fromUrl, const KUrl& toUrl); private: static bool m_useCache; static QString m_userAgent; FileRetriever(const FileRetriever& other); FileRetriever& operator=(const FileRetriever& other); struct FileRetrieverPrivate; FileRetrieverPrivate* d; }; } // namespace Syndication #endif // SYNDICATION_DATARETRIEVER_H diff --git a/syndication/loader.h b/syndication/loader.h index 308230b2f..c9c5ac97e 100644 --- a/syndication/loader.h +++ b/syndication/loader.h @@ -1,192 +1,192 @@ /* * loader.h * * Copyright (c) 2001, 2002, 2003 Frerich Raabe * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. For licensing and distribution details, check the * accompanying file 'COPYING'. */ #ifndef SYNDICATION_LOADER_H #define SYNDICATION_LOADER_H #include #include #include "ksyndication.h" #include -class KProcess; +class K3Process; class KUrl; namespace KIO { class Job; } namespace Syndication { class DataRetriever; class Feed; //@cond PRIVATE typedef SharedPtr FeedPtr; //@endcond /** * This class is the preferred way of loading feed sources. Usage is very * straightforward: * * \code * Loader *loader = Loader::create(); * connect(loader, SIGNAL(loadingComplete(Loader*, FeedPtr, ErrorCode)), * this, SLOT(slotLoadingComplete(Loader*, FeedPtr, ErrorCode))); * loader->loadFrom("http://www.blah.org/foobar.rdf"); * \endcode * * This creates a Loader object, connects it's loadingComplete() signal to * your custom slot and then makes it load the file * 'http://www.blah.org/foobar.rdf'. You could've * done something like this as well: * * \code * // create the Loader, connect it's signal... * loader->loadFrom("/home/myself/some-script.py", new OutputRetriever); * \endcode * * That'd make the Loader use a custom algorithm for retrieving the RSS data; * 'OutputRetriever' will make it execute the script * '/home/myself/some-script.py' and assume whatever that script prints to * stdout is RSS/Azom markup. This is e.g. handy for conversion scripts, which * download a HTML file and convert it's contents into RSS markup. * * No matter what kind of retrieval algorithm you employ, your * 'slotLoadingComplete' method might look like this: * * \code * void MyClass::slotLoadingComplete(Loader* loader, FeedPtr feed, ErrorCode status) * { * // Note that Loader::~Loader() is private, so you cannot delete Loader instances. * // You don't need to do that anyway since Loader instances delete themselves. * * if (status != Syndication::Success) * return; * * QString title = feed->title(); * // do whatever you want with the information. * } * \endcode */ class SYNDICATION_EXPORT Loader : public QObject { Q_OBJECT public: /** * Constructs a Loader instance. This is pretty much what the * default constructor would do, except that it ensures that all * Loader instances have been allocated on the heap (this is * required so that Loader's can delete themselves safely after they * emitted the loadingComplete() signal.). * @return A pointer to a new Loader instance. */ static Loader* create(); /** * Convenience method. Does the same as the above method except that * it also does the job of connecting the loadingComplete() signal * to the given slot for you. * @param object A QObject which features the specified slot * @param slot Which slot to connect to. */ static Loader* create(QObject* object, const char* slot); /** * Loads the feed source referenced by the given URL using the * specified retrieval algorithm. Make sure that you connected * to the loadingComplete() signal before calling this method so * that you're guaranteed to get notified when the loading finished. * \note A Loader object cannot load from multiple URLs simultaneously; * consequently, subsequent calls to loadFrom will be discarded * silently, only the first loadFrom request will be executed. * @param url A URL referencing the input file. * @param retriever A subclass of DataRetriever which implements a * specialized retrieval behaviour. Note that the ownership of the * retriever is transferred to the Loader, i.e. the Loader will * delete it when it doesn't need it anymore. * @see DataRetriever, Loader::loadingComplete() */ void loadFrom(const KUrl& url, DataRetriever* retriever); /** * Convenience method. Does the same as the above method, where * FileRetriever is used as retriever implementation. * * @param url A URL referencing the input file. */ void loadFrom(const KUrl& url); /** * Retrieves the error code of the last loading process (if any). */ ErrorCode errorCode() const; /** * the error code returned from the retriever. * Use this if you use your custom retriever implementation and * need the specific error, not covered by errorCode(). */ int retrieverError() const; /** * returns the URL of a feed discovered in the feed source */ const KUrl& discoveredFeedURL() const; /** * aborts the loading process */ void abort(); Q_SIGNALS: /** * This signal gets emitted when the loading process triggered by * calling loadFrom() finished. * @param loader A pointer pointing to the loader object which * emitted this signal; this is handy in case you connect multiple * loaders to a single slot. * @param feed In case errortus is Success, this parameter holds the * parsed feed. If fetching/parsing failed, feed is NULL. * @param error An error code telling whether there were any * problems while retrieving or parsing the data. * @see Feed, ErrorCode */ void loadingComplete(Syndication::Loader* loader, Syndication::FeedPtr feed, Syndication::ErrorCode error); private Q_SLOTS: void slotRetrieverDone(const QByteArray& data, bool success); private: Loader(); Loader(const Loader& other); Loader& operator=(const Loader& other); ~Loader(); void discoverFeeds(const QByteArray& data); struct LoaderPrivate; LoaderPrivate* d; }; } // namespace Syndication #endif // SYNDICATION_LOADER_H