[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: KIO question
From:       Malte.Starostik () t-online ! de (Malte Starostik)
Date:       2001-06-12 14:52:32
[Download RAW message or body]

On Dienstag, 12. Juni 2001 14:58, Mark W. Webb wrote:

> I am sure everyone is busy with the new release, but I am working on a
> program that will download a file via ftp every X minutes.  I would like to
> use the ftp slave, but I cannot find any information on it.  Right now I am
> using KIO::NetAccess.  It works fine, but I do not want to see the status
> download dialog every time the file is transferred as this is an automated
> thing.  Does anyone have any ideas or better ways to do this?

Say you have a member variable QFile *m_file that you want to write the 
downloaded data to:

bool MyClass::startDownload(const KURL &url)
{
	if (!m_file->open(IO_WriteOnly))
		return false;
	KIO::Job *job = KIO::get(url, false /* don't force reload */, false /* don't 
	show progress dialog */);
	connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)), 
SLOT(slotData(KIO::Job *, const QByteArray &)));
	connect(job, SIGNAL(result(KIO::Job *)), SLOT(slotResult(KIO::Job *)));
	return true;
}

void MyClass::slotData(KIO::Job *, const QByteArray &data)
{
	m_file->writeBlock(data.data(), data.size());
}

void MyClass::slotResult(KIO::Job *job)
{
	m_file->close();
	if (job->error())
	{
		m_file->remove();
		// Something went wrong, cleanup, inform user, whatever
	}
	else
	{
		// Alright, do something with it
	}
}

-Malte
-- 
Wars don't determine who's right, only who's left.
 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic