File indexing completed on 2024-05-19 04:50:15
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2007 Casey Link <unnamedrambler@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #define DEBUG_PREFIX "AvatarDownloader" 0019 0020 #include "AvatarDownloader.h" 0021 #include "core/support/Debug.h" 0022 0023 #include <QUrl> 0024 0025 AvatarDownloader::AvatarDownloader() 0026 { 0027 } 0028 0029 AvatarDownloader::~AvatarDownloader() 0030 { 0031 } 0032 0033 void 0034 AvatarDownloader::downloadAvatar( const QString& username, const QUrl &url ) 0035 { 0036 if( !url.isValid() ) 0037 return; 0038 0039 m_userAvatarUrls.insert( url, username ); 0040 The::networkAccessManager()->getData( url, this, 0041 &AvatarDownloader::downloaded); 0042 0043 } 0044 0045 void 0046 AvatarDownloader::downloaded( const QUrl &url, QByteArray data, NetworkAccessManagerProxy::Error e ) 0047 { 0048 if( !m_userAvatarUrls.contains( url ) ) 0049 return; 0050 0051 const QString username = m_userAvatarUrls.take( url ); 0052 if( e.code == QNetworkReply::NoError ) 0053 { 0054 QPixmap avatar; 0055 if( avatar.loadFromData( data ) ) 0056 emit avatarDownloaded( username, avatar ); 0057 } 0058 else 0059 debug() << QString( "Error: failed to download %1'savatar: %2" ).arg( username, e.description ); 0060 } 0061