Made replacement QAbstractFileEngine descendent to replace the QT3 Source Factory.
Matt (mattr) asked me to post it so it can get tested, Hope it works for everybody. Attached 3 files: diff.patch - Replaces kopetemimesourcefactory entries kopetefileengine.cpp - Place in libkopete kopetefileengine.j - Place in libkopete -- Guillermo A. Amaral, CSE # Free & Open Source Advocate & nick: guillermoamaral @ blog: http://blog.guillermoamaral.com/ @ site: http://www.guillermoamaral.com/ $ irc: [EMAIL PROTECTED] % gpg: http://downloads.guillermoamaral.com/public.asc
Index: kopete/kopeteapplication.h =================================================================== --- kopete/kopeteapplication.h (revision 678750) +++ kopete/kopeteapplication.h (working copy) @@ -26,7 +26,7 @@ class KopeteWindow; class QSessionManager; -class Q3MimeSourceFactory; +class QAbstractFileEngineHandler; namespace Kopete { @@ -78,7 +78,7 @@ QPointer<KopeteWindow> m_mainWindow; bool m_isShuttingDown; Kopete::MimeTypeHandler *m_emoticonHandler; - Q3MimeSourceFactory *m_mimeFactory; + QAbstractFileEngineHandler *m_fileEngineHandler; private: void handleURLArgs(); Index: kopete/kopeteapplication.cpp =================================================================== --- kopete/kopeteapplication.cpp (revision 678750) +++ kopete/kopeteapplication.cpp (working copy) @@ -38,7 +38,7 @@ #include "kopetecommandhandler.h" #include "kopetecontactlist.h" #include "kopeteglobal.h" -#include "kopetemimesourcefactory.h" +#include "kopetefileengine.h" #include "kopetemimetypehandler.h" #include "kopetepluginmanager.h" #include "kopeteprotocol.h" @@ -81,8 +81,7 @@ */ QTimer::singleShot( 0, this, SLOT( slotLoadPlugins() ) ); - m_mimeFactory = new Kopete::MimeSourceFactory; - Q3MimeSourceFactory::addFactory( m_mimeFactory ); + m_fileEngineHandler = new Kopete::KopeteFileEngineHandler; //Create the emoticon installer m_emoticonHandler = new Kopete::EmoticonMimeTypeHandler; @@ -94,7 +93,7 @@ delete m_mainWindow; delete m_emoticonHandler; - delete m_mimeFactory; + delete m_fileEngineHandler; //kDebug( 14000 ) << k_funcinfo << "Done" << endl; } Index: libkopete/CMakeLists.txt =================================================================== --- libkopete/CMakeLists.txt (revision 678750) +++ libkopete/CMakeLists.txt (working copy) @@ -75,7 +75,7 @@ kopetemessagehandlerchain.cpp kopetemessagehandler.cpp kopetemetacontact.cpp - kopetemimesourcefactory.cpp + kopetefileengine.cpp kopetemimetypehandler.cpp kopeteonlinestatus.cpp kopeteonlinestatusmanager.cpp @@ -103,7 +103,7 @@ ui/addressbooklinkwidget_base.ui ui/addressbookselectorwidget_base.ui ui/avatarselectorwidget.ui - ui/contactaddednotifywidget.ui + ui/contactaddednotifywidget.ui ui/fileconfirmbase.ui ui/kopeteawaydialogbase.ui ui/kopetepasswordwidgetbase.ui
/* kopetefileengine.h - Kopete file engine Copyright (c) 2007 by Guillermo A. Amaral B <[EMAIL PROTECTED]> Kopete (c) 2007 by the Kopete developers <kopete-devel@kde.org> Based on Kopete Mime Source Factory Copyright (c) 2004 by Richard Smith <[EMAIL PROTECTED]> ************************************************************************* * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * ************************************************************************* */ #include "kopetefileengine.h" #include "kopeteaccountmanager.h" #include "kopetecontactlist.h" #include "kopeteaccount.h" #include "kopetecontact.h" #include "kopetemetacontact.h" #include "kopetepicture.h" #include <kdebug.h> #include <kiconloader.h> #include <QPixmap> #include <qdiriterator.h> #include <qstring.h> #include <qstringlist.h> namespace Kopete { QAbstractFileEngine *KopeteFileEngineHandler::create(const QString &fileName) const { bool handle = false; handle |= fileName.startsWith("kopete-contact-icon", Qt::CaseInsensitive); handle |= fileName.startsWith("kopete-account-icon", Qt::CaseInsensitive); handle |= fileName.startsWith("kopete-metacontact-icon", Qt::CaseInsensitive); handle |= fileName.startsWith("kopete-metacontact-photo", Qt::CaseInsensitive); handle |= fileName.startsWith("kopete-onlinestatus-icon", Qt::CaseInsensitive); return handle ? new KopeteFileEngine(fileName) : 0; } KopeteFileEngine::KopeteFileEngine() : m_buffer(&m_data) { kDebug(14010) << k_funcinfo << endl; } KopeteFileEngine::KopeteFileEngine(const QString& fileName) : m_fileName(fileName), m_buffer(&m_data) { kDebug(14010) << k_funcinfo << fileName << endl; } KopeteFileEngine::~KopeteFileEngine() { kDebug(14010) << k_funcinfo << m_fileName << endl; } bool KopeteFileEngine::open(QIODevice::OpenMode openMode) { // flag used to signal something went wrong when creating a mimesource bool completed = false; bool isPhoto = false; QPixmap tmpImg; QImage tmpPhoto; // extract and decode arguments QStringList parts = m_fileName.split( QChar(':'), QString::SkipEmptyParts ); for ( QStringList::Iterator it = parts.begin(); it != parts.end(); ++it ) *it = QUrl::fromPercentEncoding( (*it).toUtf8() ); if ( parts[0] == QString::fromLatin1("kopete-contact-icon") ) { if ( parts.size() >= 4 ) { Account *account = AccountManager::self()->findAccount( parts[1], parts[2] ); if ( account ) { Contact *contact = account->contacts()[ parts[3] ]; if ( contact ) { tmpImg = contact->onlineStatus().iconFor( contact ); completed = true; } else kDebug( 14010 ) << k_funcinfo << "kopete-contact-icon: contact not found" << endl; } else kDebug( 14010 ) << k_funcinfo << "kopete-contact-icon: account not found" << endl; } else kDebug( 14010 ) << k_funcinfo << "kopete-contact-icon: insufficient information in m_fileName: " << parts << endl; } else if ( parts[0] == QString::fromLatin1("kopete-account-icon") ) { if ( parts.size() >= 3 ) { Account *account = AccountManager::self()->findAccount( parts[1], parts[2] ); if ( account ) { tmpImg = account->myself()->onlineStatus().iconFor( account->myself() ); completed = true; } else kDebug( 14010 ) << k_funcinfo << "kopete-account-icon: account not found" << endl; } else kDebug( 14010 ) << k_funcinfo << "kopete-account-icon: insufficient information in m_fileName: " << parts << endl; } else if ( parts[0] == QString::fromLatin1("kopete-metacontact-icon") ) { if ( parts.size() >= 2 ) { MetaContact *mc = ContactList::self()->metaContact( parts[1] ); if ( mc ) { tmpImg = SmallIcon( mc->statusIcon() ); completed = true; } } else kDebug( 14010 ) << k_funcinfo << "kopete-metacontact-icon: insufficient information in m_fileName: " << parts << endl; } else if ( parts[0] == QString::fromLatin1("kopete-metacontact-photo") ) { if ( parts.size() >= 2 ) { MetaContact *mc = ContactList::self()->metaContact( parts[1] ); if ( mc ) { tmpPhoto = (mc->picture().image()); isPhoto = true; completed = true; } } else kDebug( 14010 ) << k_funcinfo << "kopete-metacontact-photo: insufficient information in m_fileName: " << parts << endl; } else if ( parts[0] == QString::fromLatin1("kopete-onlinestatus-icon") ) { if ( parts.size() >= 2 ) { /* * We are using a dirty trick here: this mime source is supposed to return the * icon for an arbitrary KOS instance. To do this, the caller needs to ask * the KOS for the mime source key first, which also ensures the icon is * currently in the cache. The cache is global, so we just need to find any * existing KOS instance to return us the rendered icon from the cache. * To find a valid KOS, we ask Kopete's account manager to locate an existing * account. We'll use the myself() instance of that account to reference its * current KOS object, which in turn has access to the global KOS icon cache. * Note that if the cache has been invalidated in the meantime, we'll just * get an empty pixmap back. */ Account *account = AccountManager::self()->accounts().first(); if ( account ) { tmpImg = account->myself()->onlineStatus().iconFor( parts[1] ); completed = true; } else kDebug( 14010 ) << k_funcinfo << "kopete-onlinestatus-icon: no active account found" << endl; } else kDebug( 14010 ) << k_funcinfo << "kopete-onlinestatus-icon: insufficient information in m_fileName: " << parts << endl; } close(); if ( completed ) { m_buffer.open(QIODevice::WriteOnly); if (isPhoto) { tmpPhoto.save(&m_buffer, "JPEG"); } else { tmpImg.save(&m_buffer, "PNG"); } m_buffer.close(); m_buffer.open(openMode); m_buffer.seek(0); } kDebug(14010) << k_funcinfo << openMode << endl; return completed; } bool KopeteFileEngine::close() { kDebug(14010) << k_funcinfo << endl; if(m_buffer.isOpen()) m_buffer.close(); m_data.clear(); return true; } qint64 KopeteFileEngine::size() const { return m_buffer.size(); } qint64 KopeteFileEngine::pos() const { return m_buffer.pos(); } bool KopeteFileEngine::seek(qint64 newPos) { return m_buffer.seek(newPos); } bool KopeteFileEngine::isSequential() const { return m_buffer.isSequential(); } bool KopeteFileEngine::remove() { return false; } bool KopeteFileEngine::rename(const QString &newName) { Q_UNUSED(newName); return false; } bool KopeteFileEngine::mkdir(const QString &dirName, bool createParentDirectories) const { Q_UNUSED(dirName); Q_UNUSED(createParentDirectories); return false; } bool KopeteFileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const { Q_UNUSED(dirName); Q_UNUSED(recurseParentDirectories); return false; } bool KopeteFileEngine::setSize(qint64 size) { Q_UNUSED(size); return false; } bool KopeteFileEngine::caseSensitive() const { return false; } bool KopeteFileEngine::isRelativePath() const { return false; } QStringList KopeteFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const { QStringList ret; QDirIterator it(fileName(), filterNames, filters); while (it.hasNext()) { it.next(); ret << it.fileName(); } return ret; } KopeteFileEngine::FileFlags KopeteFileEngine::fileFlags(FileFlags type) const { Q_UNUSED(type); return 0; } bool KopeteFileEngine::setPermissions(uint perms) { Q_UNUSED(perms); return false; } QString KopeteFileEngine::fileName(FileName file) const { Q_UNUSED(file); return m_fileName; } uint KopeteFileEngine::ownerId(FileOwner owner) const { Q_UNUSED(owner); return 0; } QString KopeteFileEngine::owner(FileOwner owner) const { Q_UNUSED(owner); return QString(); } QDateTime KopeteFileEngine::fileTime(FileTime time) const { Q_UNUSED(time); return QDateTime(); } void KopeteFileEngine::setFileName(const QString &file) { m_fileName = file; } qint64 KopeteFileEngine::read(char *data, qint64 maxlen) { return m_buffer.read(data, maxlen);; } qint64 KopeteFileEngine::readLine(char *data, qint64 maxlen) { return m_buffer.readLine(data, maxlen); } qint64 KopeteFileEngine::write(const char *data, qint64 len) { return m_buffer.write(data, len); } bool KopeteFileEngine::atEnd() const { return m_buffer.atEnd(); } } // END namespace Kopete // vim: set noet ts=4 sts=4 sw=4:
/* kopetefileengine.h - Kopete file engine Copyright (c) 2007 by Guillermo A. Amaral B <[EMAIL PROTECTED]> Kopete (c) 2007 by the Kopete developers <kopete-devel@kde.org> Based on Kopete Mime Source Factory Copyright (c) 2004 by Richard Smith <[EMAIL PROTECTED]> ************************************************************************* * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * ************************************************************************* */ #ifndef KOPETEFILEENGINE_H #define KOPETEFILEENGINE_H #include <qabstractfileengine.h> #include <qstring.h> #include <QBuffer> #include "kopete_export.h" namespace Kopete { class KOPETE_EXPORT KopeteFileEngineHandler : public QAbstractFileEngineHandler { public: QAbstractFileEngine *create(const QString &fileName) const; }; class KOPETE_EXPORT KopeteFileEngine : public QAbstractFileEngine { public: KopeteFileEngine(); ~KopeteFileEngine(); explicit KopeteFileEngine(const QString&); bool open(QIODevice::OpenMode openMode); bool close(); qint64 size() const; qint64 pos() const; bool seek(qint64); bool isSequential() const; bool remove(); bool rename(const QString &newName); bool mkdir(const QString &dirName, bool createParentDirectories) const; bool rmdir(const QString &dirName, bool recurseParentDirectories) const; bool setSize(qint64 size); bool caseSensitive() const; bool isRelativePath() const; QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const; FileFlags fileFlags(FileFlags type) const; bool setPermissions(uint perms); QString fileName(FileName file=DefaultName) const; uint ownerId(FileOwner) const; QString owner(FileOwner) const; QDateTime fileTime(FileTime time) const; void setFileName(const QString &file); bool atEnd() const; qint64 read(char *data, qint64 maxlen); qint64 readLine(char *data, qint64 maxlen); qint64 write(const char *data, qint64 len); private: QString m_fileName; QByteArray m_data; QBuffer m_buffer; }; } // Kopete #endif // vim: set noet ts=4 sts=4 sw=4:
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ kopete-devel mailing list kopete-devel@kde.org https://mail.kde.org/mailman/listinfo/kopete-devel