Commit a429cdc3 authored by Mehrdad Momeny's avatar Mehrdad Momeny
Browse files

BUG:280679 Media Manager ported to KImageCache to fix this bug!

Thank you Christoph
parent bb57e139
......@@ -31,7 +31,7 @@
#include <QHash>
#include <KEmoticons>
#include <KEmoticonsTheme>
#include <KPixmapCache>
#include <KImageCache>
#include <choqokbehaviorsettings.h>
#include "uploader.h"
#include "pluginmanager.h"
......@@ -47,10 +47,10 @@ class MediaManager::Private
{
public:
Private()
:emoticons(KEmoticons().theme()),cache("choqok-userimages"), uploader(0)
:emoticons(KEmoticons().theme()),cache("choqok-userimages", 20000000), uploader(0)
{}
KEmoticonsTheme emoticons;
KPixmapCache cache;
KImageCache cache;
QHash<KJob*, QString> queue;
QPixmap defaultImage;
Uploader *uploader;
......@@ -61,7 +61,6 @@ MediaManager::MediaManager()
{
KIcon icon("image-loading");
d->defaultImage = icon.pixmap(48);
d->cache.setCacheLimit(20000);
}
MediaManager::~MediaManager()
......@@ -93,7 +92,7 @@ QString MediaManager::parseEmoticons(const QString& text)
QPixmap * MediaManager::fetchImage( const QString& remoteUrl, ReturnMode mode /*= Sync*/ )
{
QPixmap *p = new QPixmap();
if( d->cache.find(remoteUrl,*p) ) {
if( d->cache.findPixmap(remoteUrl,p) ) {
emit imageFetched(remoteUrl, *p);
return p;
} else if(mode == Async) {
......@@ -131,7 +130,7 @@ void MediaManager::slotImageFetched( KJob * job )
QPixmap p;
if( !baseJob->data().startsWith(QByteArray("<?xml version=\"")) &&
p.loadFromData( baseJob->data() ) ) {
d->cache.insert( remote, p );
d->cache.insertPixmap( remote, p );
emit imageFetched( remote, p );
} else {
kDebug()<<"Parse Error: \nBase Url:"<<baseJob->url()<<"\ndata:"<<baseJob->data();
......@@ -142,7 +141,7 @@ void MediaManager::slotImageFetched( KJob * job )
void MediaManager::clearImageCache()
{
d->cache.discard();
d->cache.clear();
}
QPixmap MediaManager::convertToGrayScale(const QPixmap& pic)
......
......@@ -5,11 +5,33 @@ ${CHOQOK_INCLUDES}
set( choqok_is_gd_SRCS
is_gd.cpp )
kde4_add_kcfg_files(choqok_is_gd_SRCS is_gd_settings.kcfgc )
kde4_add_plugin(choqok_is_gd ${choqok_is_gd_SRCS})
target_link_libraries(choqok_is_gd ${KDE4_KIO_LIBS} choqok)
target_link_libraries(choqok_is_gd ${KDE4_KIO_LIBS} ${QJSON_LIBRARY} choqok)
install(TARGETS choqok_is_gd DESTINATION ${PLUGIN_INSTALL_DIR})
install( FILES choqok_is_gd.desktop DESTINATION ${SERVICES_INSTALL_DIR})
########### next target ###############
set( kcm_choqok_is_gd_PART_SRCS
is_gd_config.cpp )
kde4_add_ui_files(kcm_choqok_is_gd_PART_SRCS is_gd_prefs.ui )
kde4_add_kcfg_files(kcm_choqok_is_gd_PART_SRCS is_gd_settings.kcfgc )
kde4_add_plugin(kcm_choqok_is_gd ${kcm_choqok_is_gd_PART_SRCS})
target_link_libraries(kcm_choqok_is_gd ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS}
choqok)
install( TARGETS kcm_choqok_is_gd DESTINATION ${PLUGIN_INSTALL_DIR})
install( FILES is_gd_settings.kcfg DESTINATION ${KCFG_INSTALL_DIR})
install( FILES choqok_is_gd_config.desktop
DESTINATION ${SERVICES_INSTALL_DIR})
......@@ -30,6 +30,9 @@
#include <KGenericFactory>
#include <kglobal.h>
#include <qeventloop.h>
#include <notifymanager.h>
#include <qjson/parser.h>
#include "is_gd_settings.h"
K_PLUGIN_FACTORY( MyPluginFactory, registerPlugin < Is_gd > (); )
K_EXPORT_PLUGIN( MyPluginFactory( "choqok_is_gd" ) )
......@@ -46,8 +49,15 @@ Is_gd::~Is_gd()
QString Is_gd::shorten( const QString& url )
{
kDebug() << "Using is.gd";
KUrl reqUrl( "http://is.gd/api.php" );
reqUrl.addQueryItem( "longurl", KUrl( url ).url() );
Is_gd_Settings::self()->readConfig();
KUrl reqUrl( "http://is.gd/create.php" );
reqUrl.addQueryItem( "format", "json" );
reqUrl.addQueryItem( "url", KUrl( url ).url() );
if (Is_gd_Settings::logstats()) {
reqUrl.addQueryItem( "logstats", "true");
}
QEventLoop loop;
KIO::StoredTransferJob* job = KIO::storedGet( reqUrl, KIO::Reload, KIO::HideProgressInfo );
......@@ -56,14 +66,25 @@ QString Is_gd::shorten( const QString& url )
loop.exec();
if( job->error() == KJob::NoError ) {
QString output(job->data());
kDebug() << "Short url is: " << output;
if( !output.isEmpty() ) {
return output;
QJson::Parser parser;
bool ok;
QVariantMap map = parser.parse( job->data() , &ok ).toMap();
if ( ok ) {
if ( !map[ "errorcode" ].toString().isEmpty() ) {
Choqok::NotifyManager::error( map[ "errormessage" ].toString(), i18n("is.gd error") );
return url;
}
QString shorturl = map[ "shorturl" ].toString();
if (!shorturl.isEmpty()) {
return shorturl;
}
} else {
Choqok::NotifyManager::error( i18n("Malformed response\n"), i18n("is.gd error") );
}
}
else {
kDebug() << "KJob ERROR" << job->errorString();
Choqok::NotifyManager::error( i18n("Cannot create a short url.\n%1", job->errorString()), i18n("is.gd error") );
}
return url;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment