2
This file is part of choqoK, the KDE Twitter client
4
Copyright (C) 2008 Mehrdad Momeny <mehrdad.momeny@gmail.com>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
2
This file is part of choqoK, the KDE mono-blogging client
4
Copyright (C) 2008-2009 Mehrdad Momeny <mehrdad.momeny@gmail.com>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License as
8
published by the Free Software Foundation; either version 2 of
9
the License or (at your option) version 3 or any later version
10
accepted by the membership of KDE e.V. (or its successor approved
11
by the membership of KDE e.V.), which shall act as a proxy
12
defined in Section 14 of version 3 of the license.
11
15
This program is distributed in the hope that it will be useful,
12
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
29
32
#include <kdebug.h>
30
33
#include <KDE/KLocale>
32
MediaManager::MediaManager(QObject* parent): QObject(parent)
35
MediaManager::MediaManager( QObject* parent ): QObject( parent )
35
mediaResource = new KConfig();
36
map = new KConfigGroup(mediaResource, "MediaMap");
38
mediaResource = new KConfig();
39
map = new KConfigGroup( mediaResource, "MediaMap" );
40
43
MediaManager::~MediaManager()
49
52
MediaManager * MediaManager::mSelf = 0L;
51
54
MediaManager * MediaManager::self()
54
57
mSelf = new MediaManager;
58
QString MediaManager::getImageLocalPathIfExist(const QString & remotePath)
61
QString MediaManager::getImageLocalPathIfExist( const QString & remotePath )
60
QString path = map->readEntry(remotePath, QString(' '));
63
QString path = map->readEntry( remotePath, QString( ' ' ) );
64
void MediaManager::getImageLocalPathDownloadAsyncIfNotExists(const QString & localName, const QString & remotePath)
67
void MediaManager::getImageLocalPathDownloadAsyncIfNotExists( const QString & localName, const QString & remotePath )
67
if(mMediaFilesMap.contains(remotePath)){
70
if ( mMediaFilesMap.contains( remotePath ) ) {
68
71
///The file is on the way, wait to download complete.
72
if(map->hasKey(remotePath)){
73
local = map->readEntry(remotePath, QString());
74
emit imageFetched(remotePath, local);
75
if ( map->hasKey( remotePath ) ) {
76
local = map->readEntry( remotePath, QString() );
77
emit imageFetched( remotePath, local );
76
local = MEDIA_DIR+'/'+localName;
79
local = MEDIA_DIR + '/' + localName;
77
80
mMediaFilesMap [ remotePath ] = local;
78
KUrl srcUrl(remotePath);
81
KUrl srcUrl( remotePath );
82
KUrl destUrl( local );
81
KIO::FileCopyJob *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::HideProgressInfo | KIO::Overwrite) ;
83
kDebug()<<"Cannot create a FileCopyJob!";
84
QString errMsg = i18n("Cannot download userimage for %1, please check your internet connection.", localName);
85
emit sigError(errMsg);
84
KIO::FileCopyJob *job = KIO::file_copy( srcUrl, destUrl, -1, KIO::HideProgressInfo | KIO::Overwrite ) ;
86
kDebug() << "Cannot create a FileCopyJob!";
87
QString errMsg = i18n( "Cannot download userimage for %1, please check your internet connection.",
89
emit sigError( errMsg );
88
connect( job, SIGNAL(result(KJob*)), this, SLOT(slotImageFetched(KJob *)));
92
connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotImageFetched( KJob * ) ) );
93
void MediaManager::slotImageFetched(KJob * job)
97
void MediaManager::slotImageFetched( KJob * job )
96
KIO::FileCopyJob *baseJob = qobject_cast<KIO::FileCopyJob *>(job);
98
kDebug()<<"Job error!"<<job->error()<<"\t"<<job->errorString();
99
QString errMsg = i18n("Cannot download user image from %1. The returned result is: %2",
100
job->errorString(), baseJob->srcUrl().pathOrUrl());
101
emit sigError(errMsg);
100
KIO::FileCopyJob *baseJob = qobject_cast<KIO::FileCopyJob *>( job );
101
if ( job->error() ) {
102
kDebug() << "Job error!" << job->error() << "\t" << job->errorString();
103
QString errMsg = i18n( "Cannot download user image from %1. The returned result is: %2",
104
job->errorString(), baseJob->srcUrl().pathOrUrl() );
105
emit sigError( errMsg );
103
107
QString local = baseJob->destUrl().pathOrUrl();
104
QString remote= baseJob->srcUrl().pathOrUrl();
105
mMediaFilesMap.remove(remote);
106
map->writeEntry(remote, local);
108
emit imageFetched(remote, local);
108
QString remote = baseJob->srcUrl().pathOrUrl();
109
mMediaFilesMap.remove( remote );
110
map->writeEntry( remote, local );
112
emit imageFetched( remote, local );
112
116
#include "mediamanager.moc"