diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
commit | e38d2351b83fa65c66ccde443777647ef5cb6cff (patch) | |
tree | 1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/core/netaccess.cpp | |
download | tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip |
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/core/netaccess.cpp')
-rw-r--r-- | src/core/netaccess.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/core/netaccess.cpp b/src/core/netaccess.cpp new file mode 100644 index 0000000..77b6554 --- /dev/null +++ b/src/core/netaccess.cpp @@ -0,0 +1,100 @@ +/*************************************************************************** + copyright : (C) 2006 by Robby Stephenson + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of version 2 of the GNU General Public License as * + * published by the Free Software Foundation; * + * * + ***************************************************************************/ + +#include "netaccess.h" +#include "../tellico_kernel.h" +#include "../tellico_debug.h" + +#include <kdeversion.h> +#include <kio/job.h> +#include <kio/netaccess.h> +#include <kio/scheduler.h> +#include <kio/previewjob.h> +#include <ktempfile.h> + +#include <qapplication.h> +#include <qfile.h> + +#include <unistd.h> // for unlink() + +using Tellico::NetAccess; + +QStringList* NetAccess::s_tmpFiles = 0; + +bool NetAccess::download(const KURL& url_, QString& target_, QWidget* window_) { + if(url_.isLocalFile()) { + return KIO::NetAccess::download(url_, target_, window_); + } + +// if(!KIO::NetAccess::exists(url_, true, window_)) { +// myDebug() << "NetAccess::download() - does not exist: " << url_ << endl; +// return false; +// } + + if(target_.isEmpty()) { + KTempFile tmpFile; + target_ = tmpFile.name(); + if(!s_tmpFiles) { + s_tmpFiles = new QStringList; + } + s_tmpFiles->append(target_); + } + + KURL dest; + dest.setPath(target_); + + KIO::Job* job = KIO::file_copy(url_, dest, -1, true /*overwrite*/, false /*resume*/, false /*showProgress*/); + return KIO::NetAccess::synchronousRun(job, window_); +} + +void NetAccess::removeTempFile(const QString& name_) { + if(!s_tmpFiles) { + return; + } + if(s_tmpFiles->contains(name_)) { + ::unlink(QFile::encodeName(name_)); + s_tmpFiles->remove(name_); + } +} + +QPixmap NetAccess::filePreview(const KURL& url, int size) { + NetAccess netaccess; + + KURL::List list; + list.append(url); + KIO::Job* previewJob = KIO::filePreview(list, size, size); + connect(previewJob, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)), + &netaccess, SLOT(slotPreview(const KFileItem*, const QPixmap&))); + + KIO::NetAccess::synchronousRun(previewJob, Kernel::self()->widget()); + return netaccess.m_preview; +} + +QPixmap NetAccess::filePreview(KFileItem* item, int size) { + NetAccess netaccess; + + KFileItemList list; + list.append(item); + KIO::Job* previewJob = KIO::filePreview(list, size, size); + connect(previewJob, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)), + &netaccess, SLOT(slotPreview(const KFileItem*, const QPixmap&))); + + KIO::NetAccess::synchronousRun(previewJob, Kernel::self()->widget()); + return netaccess.m_preview; +} + +void NetAccess::slotPreview(const KFileItem*, const QPixmap& pix_) { + m_preview = pix_; +} + +#include "netaccess.moc" |