• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

downloader.cpp
Go to the documentation of this file.
00001 /*
00002    Copyright (c) 2003 Malte Starostik <malte@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "downloader.h"
00021 
00022 #include <cstdlib>
00023 #include <cstring>
00024 
00025 #include <QtCore/QTextCodec>
00026 
00027 #include <kcharsets.h>
00028 #include <kglobal.h>
00029 #include <klocale.h>
00030 #include <kio/job.h>
00031 
00032 namespace KPAC
00033 {
00034     Downloader::Downloader( QObject* parent )
00035         : QObject( parent )
00036     {
00037     }
00038 
00039     void Downloader::download( const KUrl& url )
00040     {
00041         m_data.resize( 0 );
00042         m_script.clear();
00043         m_scriptURL = url;
00044 
00045         KIO::TransferJob* job = KIO::get( url, KIO::NoReload, KIO::HideProgressInfo );
00046         connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
00047                  SLOT( data( KIO::Job*, const QByteArray& ) ) );
00048         connect( job, SIGNAL ( redirection( KIO::Job*, const KUrl& ) ),
00049                  SLOT( redirection( KIO::Job*, const KUrl& ) ) );
00050         connect( job, SIGNAL( result( KJob* ) ), SLOT( result( KJob* ) ) );
00051     }
00052 
00053     void Downloader::failed()
00054     {
00055         emit result( false );
00056     }
00057 
00058     void Downloader::setError( const QString& error )
00059     {
00060         m_error = error;
00061     }
00062 
00063     void Downloader::redirection( KIO::Job* , const KUrl& url )
00064     {
00065         m_scriptURL = url;
00066     }
00067 
00068     void Downloader::data( KIO::Job*, const QByteArray& data )
00069     {
00070         unsigned offset = m_data.size();
00071         m_data.resize( offset + data.size() );
00072         std::memcpy( m_data.data() + offset, data.data(), data.size() );
00073     }
00074 
00075     void Downloader::result( KJob* job )
00076     {
00077         if ( !job->error() && !static_cast< KIO::TransferJob* >( job )->isErrorPage() )
00078         {
00079             bool dummy;
00080             m_script = KGlobal::charsets()->codecForName(
00081                 static_cast<KIO::Job*>( job )->queryMetaData( "charset" ), dummy )->toUnicode( m_data );
00082             emit result( true );
00083         }
00084         else
00085         {
00086             if ( job->error() )
00087                 setError( i18n( "Could not download the proxy configuration script:\n%1" ,
00088                                 job->errorString() ) );
00089             else setError( i18n( "Could not download the proxy configuration script" ) ); // error page
00090             failed();
00091         }
00092     }
00093 }
00094 
00095 // vim: ts=4 sw=4 et
00096 #include "downloader.moc"
00097 

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal