本文整理汇总了C++中kio::TransferJob::url方法的典型用法代码示例。如果您正苦于以下问题:C++ TransferJob::url方法的具体用法?C++ TransferJob::url怎么用?C++ TransferJob::url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kio::TransferJob
的用法示例。
在下文中一共展示了TransferJob::url方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _k_contentTypeCheckFailed
void _k_contentTypeCheckFailed(KJob* job)
{
KIO::TransferJob* tJob = qobject_cast<KIO::TransferJob*>(job);
// On error simply call downloadResource which will probably fail as well.
if (tJob && tJob->error()) {
(void)downloadResource(tJob->url(), QString(), window, tJob->metaData());
}
}
示例2: slotData
void FavIconRequestJobPrivate::slotData(Job *job, const QByteArray &data)
{
KIO::TransferJob *tjob = static_cast<KIO::TransferJob *>(job);
unsigned int oldSize = m_iconData.size();
// Size limit. Stop downloading if the file is huge.
// Testcase (as of june 2008, at least): http://planet-soc.com/favicon.ico, 136K and strange format.
// Another case: sites which redirect from "/favicon.ico" to "/" and return the main page.
if (oldSize > 0x10000) { // 65K
qCDebug(FAVICONS_LOG) << "Favicon too big, aborting download of" << tjob->url();
const QUrl iconUrl = tjob->url();
KIO::FavIconsCache::instance()->addFailedDownload(iconUrl);
tjob->kill(KJob::EmitResult);
} else {
m_iconData.resize(oldSize + data.size());
memcpy(m_iconData.data() + oldSize, data.data(), data.size());
}
}
示例3: slotResult
void FavIconRequestJob::slotResult(KJob *job)
{
KIO::TransferJob *tjob = static_cast<KIO::TransferJob *>(job);
const QUrl iconUrl = tjob->url();
KIO::FavIconsCache *cache = KIO::FavIconsCache::instance();
if (!job->error()) {
QBuffer buffer(&d->m_iconData);
buffer.open(QIODevice::ReadOnly);
QImageReader ir(&buffer);
QSize desired(16, 16);
if (ir.canRead()) {
while (ir.imageCount() > 1
&& ir.currentImageRect() != QRect(0, 0, desired.width(), desired.height())) {
if (!ir.jumpToNextImage()) {
break;
}
}
ir.setScaledSize(desired);
const QImage img = ir.read();
if (!img.isNull()) {
cache->ensureCacheExists();
const QString localPath = cache->cachePathForIconUrl(iconUrl);
qCDebug(FAVICONS_LOG) << "Saving image to" << localPath;
QSaveFile saveFile(localPath);
if (saveFile.open(QIODevice::WriteOnly) &&
img.save(&saveFile, "PNG") && saveFile.commit()) {
d->m_iconFile = localPath;
} else {
setError(KIO::ERR_COULD_NOT_WRITE);
setErrorText(i18n("Error saving image to %1", localPath));
}
} else {
qCDebug(FAVICONS_LOG) << "QImageReader read() returned a null image";
}
} else {
qCDebug(FAVICONS_LOG) << "QImageReader canRead returned false";
}
} else if (job->error() == KJob::KilledJobError) { // we killed it in slotData
setError(KIO::ERR_SLAVE_DEFINED);
setErrorText(i18n("Icon file too big, download aborted"));
} else {
setError(job->error());
setErrorText(job->errorString()); // not errorText(), because "this" is a KJob, with no errorString building logic
}
d->m_iconData.clear(); // release memory
if (d->m_iconFile.isEmpty()) {
qCDebug(FAVICONS_LOG) << "adding" << iconUrl << "to failed downloads due to error:" << errorString();
cache->addFailedDownload(iconUrl);
} else {
cache->removeFailedDownload(iconUrl);
}
KCompositeJob::removeSubjob(job);
emitResult();
}
示例4: _k_receivedContentType
void _k_receivedContentType(KIO::Job* job, const QString& mimetype)
{
KIO::TransferJob* tJob = qobject_cast<KIO::TransferJob*>(job);
if (tJob && !tJob->error()) {
tJob->putOnHold();
KIO::Scheduler::publishSlaveOnHold();
// Get suggested file name...
mimeType = mimetype;
const QString suggestedFileName (tJob->queryMetaData(QL1S("content-disposition-filename")));
// kDebug(800) << "suggested filename:" << suggestedFileName << ", mimetype:" << mimetype;
(void) downloadResource(tJob->url(), suggestedFileName, window, tJob->metaData());
}
}
示例5: slotJobData
void KRun::slotJobData( KIO::Job *job, const QByteArray &data )
{
// Are we pumping data for an external program?
if ( m_fhandle != -1 )
{
// This should *REALLY* be implemented in another thread or process
if ( data.isEmpty() )
{
emit error();
delete this;
}
else
for ( uint d = 0; d < data.count(); )
{
int n = data.count() - d;
if ( n > 1024 )
n = 1024;
n = ::write( m_fhandle, data.data() + d, n );
if ( n >= 0 )
d += n;
else
{
if ( errno == EAGAIN )
usleep(5000);
else
{
delete this;
break;
}
}
}
return;
}
assert( job->inherits( "KIO::TransferJob" ) );
assert( job == m_job );
KIO::TransferJob *transferJob = static_cast<KIO::TransferJob *>( job );
QString referrer;
{
if ( transferJob->outgoingMetaData().contains( "referrer" ) )
referrer = transferJob->outgoingMetaData()["referrer"];
}
QString mtype = transferJob->mimetype();
// if no MIME type is available attempt to guess it
if ( mtype.isEmpty() )
{
const KIO::MimeHandler* guess = KIO::MimeHandler::Find( m_strURL );
if ( !guess )
guess = KIO::MimeHandler::Find( data );
if ( guess )
mtype = guess->Preferred();
else
mtype = QString::fromLatin1( "text/html" );
}
// If app wants us to pump it data don't detach from job
const KIO::MimeHandler* mime = KIO::MimeHandler::Find( mtype );
if ( mime && mime->isExtApp() && mime->isExtApp()->wantsData() )
{
m_fhandle = exec( ( static_cast<const KIO::MimeExtApp *>( mime ) )->getExtApp(), m_strURL.url(), referrer, true );
if ( m_fhandle >= 0 )
{
// Since we already got some data call itself once
slotJobData( job, data );
return;
}
}
transferJob->detach( data );
job->disconnect( this, 0 );
KURL url = transferJob->url();
m_strURL = url;
if ( mime && mime->isExtApp() )
{
job->kill();
exec( mime->isExtApp()->getExtApp(), m_strURL.url(), referrer );
emit error();
}
else if ( mime && mime->isUnknown() )
{
job->kill();
emit error();
}
else
foundMimeType( mtype );
QTimer::singleShot( 0, this, SLOT( slotSuicide() ) );
}