mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kdecore: new KTemporaryFile::urlPath() method
based on the bits in kparts/part.cpp Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
75eeefb652
commit
7f261aca95
5 changed files with 27 additions and 26 deletions
|
@ -90,3 +90,17 @@ QString KTemporaryFile::filePath(const QString &pathtemplate)
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString KTemporaryFile::urlPath(const KUrl &url)
|
||||
{
|
||||
// use same extension as remote file, this is important for MIME type determination
|
||||
QFileInfo fileinfo(url.fileName());
|
||||
const QString filesuffix = fileinfo.completeSuffix();
|
||||
QString urltemplate = QLatin1String("XXXXXXXXXX");
|
||||
// but not if the extension is empty or the URL has a query
|
||||
if (!filesuffix.isEmpty() && url.query().isEmpty()) {
|
||||
urltemplate.append(QLatin1Char('.'));
|
||||
urltemplate.append(filesuffix);
|
||||
}
|
||||
return KTemporaryFile::filePath(urltemplate);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
#include <kglobal.h>
|
||||
|
||||
#include <qtemporaryfile.h>
|
||||
|
||||
class KTemporaryFilePrivate;
|
||||
#include <kurl.h>
|
||||
|
||||
/**
|
||||
* \class KTemporaryFile ktemporaryfile.h <KTemporaryFile>
|
||||
|
@ -139,6 +138,11 @@ public:
|
|||
* @param pathtemplate The template to use when generating filepath.
|
||||
*/
|
||||
static QString filePath(const QString &pathtemplate = QString());
|
||||
|
||||
/**
|
||||
* @brief Generates a filepath to be used as temporary file for the given URL.
|
||||
*/
|
||||
static QString urlPath(const KUrl &url);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -82,8 +82,8 @@ static QStringList tmpfiles;
|
|||
static QString lastErrorMsg;
|
||||
static int lastErrorCode = 0;
|
||||
|
||||
NetAccess::NetAccess() :
|
||||
d( new NetAccessPrivate )
|
||||
NetAccess::NetAccess()
|
||||
: d(new NetAccessPrivate())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ NetAccess::~NetAccess()
|
|||
delete d;
|
||||
}
|
||||
|
||||
bool NetAccess::download(const KUrl& u, QString & target, QWidget* window)
|
||||
bool NetAccess::download(const KUrl &u, QString &target, QWidget *window)
|
||||
{
|
||||
if (u.isLocalFile()) {
|
||||
// file protocol, do not need the network
|
||||
|
@ -106,15 +106,7 @@ bool NetAccess::download(const KUrl& u, QString & target, QWidget* window)
|
|||
}
|
||||
|
||||
if (target.isEmpty()) {
|
||||
// same bits as in kparts/part.cpp
|
||||
QFileInfo fileInfo(u.fileName());
|
||||
QString ext = fileInfo.completeSuffix();
|
||||
QString extension;
|
||||
if (!ext.isEmpty() && u.query().isEmpty()) {
|
||||
// not if the URL has a query
|
||||
extension = '.' + ext;
|
||||
}
|
||||
target = KTemporaryFile::filePath(QString::fromLatin1("XXXXXXXXXX%1").arg(extension));
|
||||
target = KTemporaryFile::urlPath(u);
|
||||
tmpfiles.append(target);
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ public:
|
|||
*
|
||||
* @return true if successful, false for failure
|
||||
*/
|
||||
static bool file_copy(const KUrl &src, const KUrl &target, QWidget* window = nullptr);
|
||||
static bool file_copy(const KUrl &src, const KUrl &target, QWidget *window = nullptr);
|
||||
|
||||
/**
|
||||
* Alternative method for copying over the network.
|
||||
|
@ -280,7 +280,7 @@ public:
|
|||
* again be prompted for passwords as needed.
|
||||
* @return true on success, false on failure.
|
||||
*/
|
||||
static bool del(const KUrl &url, QWidget* window);
|
||||
static bool del(const KUrl &url, QWidget *window);
|
||||
|
||||
/**
|
||||
* Creates a directory in a synchronous way.
|
||||
|
|
|
@ -471,16 +471,7 @@ void ReadOnlyPartPrivate::openRemoteFile()
|
|||
{
|
||||
Q_Q(ReadOnlyPart);
|
||||
m_bTemp = true;
|
||||
// Use same extension as remote file. This is important for mimetype-determination
|
||||
QString fileName = m_url.fileName();
|
||||
QFileInfo fileInfo(fileName);
|
||||
QString ext = fileInfo.completeSuffix();
|
||||
QString extension;
|
||||
if (!ext.isEmpty() && m_url.query().isNull()) {
|
||||
// not if the URL has a query, e.g. cgi.pl?something. keep the '.'
|
||||
extension = '.' + ext;
|
||||
}
|
||||
m_file = KTemporaryFile::filePath(QString::fromLatin1("XXXXXXXXXX%1").arg(extension));
|
||||
m_file = KTemporaryFile::urlPath(m_url);
|
||||
|
||||
KUrl destURL;
|
||||
destURL.setPath(m_file);
|
||||
|
|
Loading…
Add table
Reference in a new issue