khtml Library API Documentation

kjavadownloader.cpp

00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2000 Richard Moore <rich@kde.org>
00004  *               2000 Wynn Wilkes <wynnw@caldera.com>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #include "kjavadownloader.h"
00023 #include "kjavaappletserver.h"
00024 
00025 #include <kurl.h>
00026 #include <kio/job.h>
00027 #include <kdebug.h>
00028 #include <qfile.h>
00029 
00030 class KJavaDownloaderPrivate
00031 {
00032 friend class KJavaDownloader;
00033 public:
00034     ~KJavaDownloaderPrivate()
00035     {
00036         if( url )
00037         delete url;
00038     }
00039 private:
00040     QString           loaderID;
00041     KURL*             url;
00042     QByteArray        file;
00043     KIO::TransferJob* job;
00044 };
00045 
00046 
00047 KJavaDownloader::KJavaDownloader( QString& ID, QString& url )
00048 {
00049     kdDebug(6100) << "KJavaDownloader for ID = " << ID << " and url = " << url << endl;
00050 
00051     d = new KJavaDownloaderPrivate;
00052 
00053     d->loaderID = ID;
00054     d->url = new KURL( url );
00055 
00056     d->job = KIO::get( url, false, false );
00057     connect( d->job,  SIGNAL(data( KIO::Job*, const QByteArray& )),
00058              this,    SLOT(slotData( KIO::Job*, const QByteArray& )) );
00059     connect( d->job, SIGNAL(result(KIO::Job*)),
00060              this,   SLOT(slotResult(KIO::Job*)) );
00061 }
00062 
00063 KJavaDownloader::~KJavaDownloader()
00064 {
00065     delete d;
00066 }
00067 
00068 void KJavaDownloader::slotData( KIO::Job*, const QByteArray& qb )
00069 {
00070     kdDebug(6100) << "slotData for url = " << d->url->url() << endl;
00071 
00072     int cur_size = d->file.size();
00073     int qb_size = qb.size();
00074     d->file.resize( cur_size + qb_size );
00075     memcpy( d->file.data() + cur_size, qb.data(), qb_size );
00076 
00077 
00078 }
00079 
00080 void KJavaDownloader::slotResult( KIO::Job* )
00081 {
00082     kdDebug(6100) << "slotResult for url = " << d->url->url() << endl;
00083 
00084     if( d->job->error() )
00085     {
00086         kdDebug(6100) << "slave had an error = " << d->job->errorString() << endl;
00087         KJavaAppletServer* server = KJavaAppletServer::allocateJavaServer();
00088         d->file.resize(0);
00089         server->sendURLData( d->loaderID, d->url->url(), d->file );
00090         KJavaAppletServer::freeJavaServer();
00091     }
00092     else
00093     {
00094         kdDebug(6100) << "slave got all its data, sending to KJAS" << endl;
00095         kdDebug(6100) << "size of data = " << d->file.size() << endl;
00096         KJavaAppletServer* server = KJavaAppletServer::allocateJavaServer();
00097         server->sendURLData( d->loaderID, d->url->url(), d->file );
00098         KJavaAppletServer::freeJavaServer();
00099     }
00100 
00101     delete this;
00102 }
00103 
00104 #include "kjavadownloader.moc"
00105 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:40 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001