Hello,

I created a dataengine for the German "Shit Happens!" comic situated at www.ruth.de and got the permission by the author to publish the code.

Though there is one problem left I can't solve and need your help with.

He wrote that over every comic there should be this banner [1] so that everyone allways knows the comic's name. Similar to the way it looks like on his main page [2].


Yet I have no clue how to combine two pictures in one QImage -- if that is even possible -- especially if one is wider than the other.

Can you help me please?

If none knows a way how to do it I'll ask him if I can also do it without that banner, though I won't do it before trying -- it's not my comic after all.

Cheers!


[1] http://ruthe.de/bilder/shit_happens_header.gif
[2] http://ruthe.de/
Index: shithappensprovider.cpp
===================================================================
--- shithappensprovider.cpp     (Revision 0)
+++ shithappensprovider.cpp     (Revision 0)
@@ -0,0 +1,183 @@
+/*
+*   Copyright (C) 2008 Matthias Fuchs <[EMAIL PROTECTED]>
+*
+*   This program 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, 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 Library 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 <QtCore/QRegExp>
+#include <QtGui/QImage>
+#include <QtNetwork/QHttp>
+
+#include <KUrl>
+#include <KDebug>
+
+#include "shithappensprovider.h"
+
+COMICPROVIDER_EXPORT_PLUGIN( ShitHappensProvider, "ShitHappensProvider", "" )
+
+class ShitHappensProvider::Private
+{
+    public:
+        Private( ShitHappensProvider *parent )
+        : mParent( parent ), mGotMaxId ( false )
+        {
+            mHttp = new QHttp( "ruthe.com", 80, mParent );
+            connect( mHttp, SIGNAL( done( bool ) ), mParent, SLOT( 
pageRequestFinished( bool ) ) );
+        }
+        
+        void pageRequestFinished( bool );
+        void imageRequestFinished( bool );
+        
+        ShitHappensProvider *mParent;
+        QImage mImage;
+        int mRequestedId;
+        int mMaxId;
+        int mModifiedId;
+        bool mGotMaxId;
+        
+        QHttp *mHttp;
+        QHttp *mImageHttp;
+};
+
+void ShitHappensProvider::Private::pageRequestFinished( bool err )
+{
+    if ( err ) {
+        emit mParent->error( mParent );
+        return;
+    }
+    
+    const QString data = QString::fromUtf8( mHttp->readAll() );
+    
+    KUrl url;
+    
+    if (!mGotMaxId) {
+        QRegExp expMaxId( "\\b\\w+\\b (\\d+)/(\\d+)" );
+        const int pos = expMaxId.indexIn( data );
+        
+        if (pos > -1) {
+            mMaxId = expMaxId.cap( 2 ).toInt();
+            mGotMaxId = true;
+            mParent->setWebsiteHttp();
+            return;
+        } else {
+            emit mParent->error( mParent );
+            return;
+        }
+    } else {
+        QRegExp exp( "<img 
src=\"albums/userpics/(\\d+)/normal_strip_(\\d+)(\\S*\\d*)\\.jpg\"" );
+        const int pos = exp.indexIn( data );
+        
+        if (pos > -1) {
+            url = KUrl( QString( 
"http://ruthe.de/gallery/cpg1410/albums/userpics/%1/strip_%2%3.jpg"; )
+            .arg( exp.cap( 1 ) ).arg( exp.cap( 2 ) ).arg( exp.cap( 3 ) ) );
+        } else {
+            url = KUrl( QString( 
"http://ruthe.de/bilder/shit_happens_header.gif"; ) );
+        }
+    }
+    
+    mImageHttp = new QHttp( "ruthe.de", 80, mParent );
+    mImageHttp->setHost( url.host() );
+    mImageHttp->get( url.path() );
+    
+    mParent->connect( mImageHttp, SIGNAL( done( bool ) ), mParent, SLOT( 
imageRequestFinished( bool ) ) );
+    
+}
+
+void ShitHappensProvider::Private::imageRequestFinished( bool error )
+{
+    if ( error ) {
+        emit mParent->error( mParent );
+        return;
+    }
+    
+    mImage = QImage::fromData( mImageHttp->readAll() );
+    emit mParent->finished( mParent );
+}
+
+ShitHappensProvider::ShitHappensProvider( QObject *parent, const QVariantList 
&args )
+: ComicProvider( parent, args ), d( new Private( this ) )
+{
+    d->mRequestedId = requestedNumber();
+    
+    setWebsiteHttp();
+}
+
+void ShitHappensProvider::setWebsiteHttp()
+{
+    KUrl url ( QString( "http://ruthe.de/"; ) );
+
+    if ( d->mGotMaxId ) {
+        if ( ( d->mRequestedId < 1 ) || ( d->mRequestedId > d->mMaxId ) ) {
+            d->mRequestedId = d->mMaxId;
+        }
+        
+        d->mModifiedId = d->mMaxId - d->mRequestedId;
+        
+        url.setPath( QString( 
"/gallery/cpg1410/displayimage.php?album=4&pos=%1" )
+        .arg( d->mModifiedId ) );
+    } else {
+        url.setPath( QString( 
"/gallery/cpg1410/displayimage.php?album=4&pos=0" ) );
+    }
+    
+    d->mHttp->setHost( url.host() );
+    d->mHttp->get( url.path() );
+}
+
+ShitHappensProvider::~ShitHappensProvider()
+{
+    delete d;
+}
+
+ComicProvider::IdentifierType ShitHappensProvider::identifierType() const
+{
+    return NumberIdentifier;
+}
+
+QImage ShitHappensProvider::image() const
+{
+    return d->mImage;
+}
+
+QString ShitHappensProvider::identifier() const
+{
+    return QString( "shithappens:%1" ).arg( d->mRequestedId );
+}
+
+KUrl ShitHappensProvider::websiteUrl() const
+{
+    //allways pointing to the homepage because the modified ID changes 
constantly
+    return QString( "http://www.ruthe.de/"; );
+}
+
+QString ShitHappensProvider::nextIdentifier() const
+{
+    if ( d->mRequestedId < d->mMaxId ) {
+        return QString::number( d->mRequestedId + 1 );
+    } else {
+        return QString();
+    }
+}
+
+QString ShitHappensProvider::previousIdentifier() const
+{
+    if ( d->mRequestedId > 1 ) {
+        return QString::number( d->mRequestedId - 1 );
+    } else {
+        return QString();
+    }
+}
+
+#include "shithappensprovider.moc"
Index: pics/plasma_comic_shithappens.png
===================================================================
Kann nicht anzeigen: Dateityp ist als binär angegeben.
svn:mime-type = application/octet-stream

Eigenschaftsänderungen: pics/plasma_comic_shithappens.png
___________________________________________________________________
Hinzugefügt: svn:mime-type
   + application/octet-stream

Index: shithappensprovider.desktop
===================================================================
--- shithappensprovider.desktop (Revision 0)
+++ shithappensprovider.desktop (Revision 0)
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Type=Service
+X-KDE-ServiceTypes=PlasmaComic/Plugin
+X-KDE-Library=plasma_comic_shithappensprovider
+X-KDE-PlasmaComicProvider-SuffixType=Number
+X-KDE-PlasmaComicProvider-Identifier=shithappens
+Icon=plasma_comic_shithappens
+
+Name=Shit Happens!
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt      (Revision 849897)
+++ CMakeLists.txt      (Arbeitskopie)
@@ -108,3 +108,15 @@
 install( TARGETS plasma_comic_phdprovider DESTINATION ${PLUGIN_INSTALL_DIR} )
 install( FILES phdprovider.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
 install( FILES pics/plasma_comic_phd.png DESTINATION 
${DATA_INSTALL_DIR}/plasma-comic )
+
+### next ####
+
+set( comic_shithappens_provider_SRCS
+shithappensprovider.cpp
+)
+
+kde4_add_plugin( plasma_comic_shithappensprovider 
${comic_shithappens_provider_SRCS} )
+target_link_libraries( plasma_comic_shithappensprovider 
plasmacomicprovidercore ${KDE4_SYNDICATION_LIBS} )
+install( TARGETS plasma_comic_shithappensprovider DESTINATION 
${PLUGIN_INSTALL_DIR} )
+install( FILES shithappensprovider.desktop DESTINATION ${SERVICES_INSTALL_DIR} 
)
+install( FILES pics/plasma_comic_shithappens.png DESTINATION 
${DATA_INSTALL_DIR}/plasma-comic )
Index: shithappensprovider.h
===================================================================
--- shithappensprovider.h       (Revision 0)
+++ shithappensprovider.h       (Revision 0)
@@ -0,0 +1,94 @@
+/*
+*   Copyright (C) 2008 Matthias Fuchs <[EMAIL PROTECTED]>
+*
+*   This program 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, 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 Library 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 SHITHAPPENSPROVIDER_H
+#define SHITHAPPENSPROVIDER_H
+
+#include "comicprovider.h"
+
+/**
+* This class provides the comic strip image for http://ruthe.de.
+*/
+class ShitHappensProvider : public ComicProvider
+{
+    Q_OBJECT
+    
+    public:
+        
+        /**
+        * Creates a new ShitHappens provider.
+        *
+        * @param parent The parent object.
+        */
+        ShitHappensProvider( QObject *parent, const QVariantList& );
+        
+        /**
+        * Destroys the ctrl+alt+del provider.
+        */
+        ~ShitHappensProvider();
+        
+        /**
+        * Sets the Http to the Website of the comic (either a concrete
+        * date exluding the currentDate or a generic Url)
+        */
+        void setWebsiteHttp();
+        
+        /**
+        * Returns the identifier type.
+        */
+        IdentifierType identifierType() const;
+        
+        /**
+        * Returns the requested image.
+        *
+        * Note: This method returns only a valid image after the
+        *       finished() signal has been emitted.
+        */
+        virtual QImage image() const;
+        
+        /**
+        * Returns the identifier of the comic request (name + date).
+        */
+        virtual QString identifier() const;
+        
+        /**
+        * Returns the website of the comic.
+        */
+        virtual KUrl websiteUrl() const;
+        
+        /**
+        * Returns the identifier of the next comic.
+        */
+        virtual QString nextIdentifier() const;
+        
+        /**
+        * Returns the identifier of the previous comic.
+        */
+        virtual QString previousIdentifier() const;
+        
+        
+    private:
+        class Private;
+        Private* const d;
+        
+        Q_PRIVATE_SLOT( d, void pageRequestFinished( bool ) )
+        Q_PRIVATE_SLOT( d, void imageRequestFinished( bool ) )
+};
+
+#endif
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to