/* private */
void DownloadManager::stopLoadingPrivate( const KURL& url )
{
- qDebug( "DownloadManager::stopLoadingPrivate");
-
FileLoader * loader = getLoader( url );
if ( !loader ) return ;
/* private */
FileLoader* DownloadManager::getLoader( const KURL& url )
{
- qDebug( "getLoader %d",m_loaderList.count());
-
if ( m_loaderList.count() == 0 ) return NULL;
FileLoader* loader;
/* private */
void DownloadManager::deleteLoader( FileLoader* loader )
{
- qDebug( "\nloader deleted: %s",loader->getData().url.prettyURL().ascii());
- qDebug( "file: %s",loader->getData().path.ascii());
- qDebug( "code: %d",loader->getData().code);
-
m_loaderList.remove( loader );
delete loader;
}
/* This slot is called when loading is done. */ /* private slot */
void DownloadManager::slotResult( const LoaderData& data )
{
- qDebug( "DownloadManager::slotResult");
FileLoader* loader = getLoader( data.url );
/* Deleting the FileLoader here may crush kita,
/*
url: url of target
-path: path of save file. It can be QString::null.
-option: user defined option.
+path: path of save file. It can be QString::null. Then data is not saved in HDD.
+option: user defined option. See also downloadmanager.h
Call get() to start. Call stopJob() to stop.
-While loading, SIGNAL data() is emitted.
+SIGNAL data() is emitted when data is received.
SIGNAL result() is emitted when done.
+The pointer of struct Kita::LoaderData is sent by SIGNAL data() and result().
+For example, to get result code:
+
+void TmpClass::slotResult( const Kita::LoaderData& data )
+{
+ int result_code = data.code;
+}
+
+See also ImgManager::slotResult() and ImgManager::slotData().
+
*/
FileLoader::FileLoader( const KURL& url, const QString& path, const LoaderOption& option )
{
/* start downloading */
-/* When done, signal loadFinished is emitted. */ /* public */
+/* When done, slotResult() will be called. */ /* public */
bool FileLoader::get()
{
- qDebug( "\nFileLoader::get: %s",m_data.url.prettyURL().ascii() );
-
/* now loading */
if ( m_currentJob ) return FALSE;
m_file = NULL;
m_ds = NULL;
- /* open file */
+ /* If path of file is not QString::null, open file here */
+ /* Note that data is saved as "m_data.tmppath".
+ This file will be renamed in FileLoader::slotResult(). */
if( m_data.tmppath != QString::null ){
m_file = new QFile( m_data.tmppath );
if ( m_file == NULL || ! m_file->open( IO_WriteOnly ) ) {
m_ds = NULL;
m_file = NULL;
- qDebug( "close file(%d)",m_data.code);
-
- /* remove file */
+ /* If loading failed, remove file */
if ( m_data.code != 200 && m_data.tmppath != QString::null && QFile::exists( m_data.tmppath ) ){
- qDebug( "remove %s",m_data.tmppath.ascii());
QFile::remove( m_data.tmppath );
}
}
void FileLoader::slotRedirection( KIO::Job*, const KURL& url )
{
- qDebug( "redirect %s", url.prettyURL().ascii() );
stopJob();
m_data.redirection = TRUE;
m_data.redirectURL = url;
/* rename */
if( m_data.code == 200 && m_data.tmppath != QString::null ){
- qDebug( "rename: %s\n-> %s",m_data.tmppath.ascii(),m_data.path.ascii() );
if ( QFile::exists( m_data.path ) ) QFile::remove( m_data.path );
QDir qdir;
qdir.rename( m_data.tmppath, m_data.path );