Commit bf10ef80 authored by Wolfgang Bauer's avatar Wolfgang Bauer

Fix some more incorrect QUrl usage

- QUrl::toString() returns the full Url (including "file://"); to get a
  local path, QUrl::toLocalFile() needs to be used
- QUrl::setPath() sets the path only, so it should be passed a path and
  not a full Url

Fixes some more cases where "file://..." was displayed in the UI or a
"file:" folder was created.
parent e64c1cfc
......@@ -68,7 +68,7 @@ DataSourceFactory::DataSourceFactory(QObject *parent, const QUrl &dest, KIO::fil
m_verifier(nullptr),
m_signature(nullptr)
{
qCDebug(KGET_DEBUG) << "Initialize DataSourceFactory: Dest: " + m_dest.url() + "Size: " + QString::number(m_size) + "SegSize: " + QString::number(m_segSize);
qCDebug(KGET_DEBUG) << "Initialize DataSourceFactory: Dest: " + m_dest.toLocalFile() + "Size: " + QString::number(m_size) + "SegSize: " + QString::number(m_segSize);
m_prevDownloadedSizes.append(0);
}
......@@ -217,7 +217,7 @@ void DataSourceFactory::start()
//create all dirs needed
QDir dir;
dir.mkpath(m_dest.adjusted(QUrl::RemoveFilename).toString());
dir.mkpath(m_dest.adjusted(QUrl::RemoveFilename).toLocalFile());
if (checkLocalFile()) {
if (!m_putJob) {
m_putJob = KIO::open(m_dest, QIODevice::WriteOnly | QIODevice::ReadOnly);
......
......@@ -292,12 +292,12 @@ FileModel::~FileModel()
void FileModel::setupModelData(const QList<QUrl> &files)
{
QString destDirectory = m_destDirectory.toString();
QString destDirectory = m_destDirectory.toLocalFile();
foreach (const QUrl &file, files)
{
FileItem *parent = m_rootItem;
QStringList directories = file.toString().remove(destDirectory).split('/', QString::SkipEmptyParts);
QStringList directories = file.toLocalFile().remove(destDirectory).split('/', QString::SkipEmptyParts);
FileItem *child = nullptr;
while (directories.count())
{
......@@ -557,7 +557,7 @@ QUrl FileModel::getUrl(FileItem *item)
const QString path = getPath(item);
const QString name = item->data(FileItem::File, Qt::DisplayRole).toString();
QUrl url = m_destDirectory;
url.setPath(m_destDirectory.toString() + path + name);
url.setPath(m_destDirectory.path() + path + name);
return url;
}
......@@ -582,10 +582,10 @@ FileItem *FileModel::getItem(const QUrl &file)
return m_itemCache[file];
}
QString destDirectory = m_destDirectory.toString();
QString destDirectory = m_destDirectory.toLocalFile();
FileItem *item = m_rootItem;
QStringList directories = file.toString().remove(destDirectory).split('/', QString::SkipEmptyParts);
QStringList directories = file.toLocalFile().remove(destDirectory).split('/', QString::SkipEmptyParts);
while (directories.count())
{
QString part = directories.takeFirst();
......@@ -664,9 +664,9 @@ void FileModel::rename(const QModelIndex &file, const QString &newName)
QString path = getPath(item);
QUrl oldUrl = m_destDirectory;
oldUrl.setPath(m_destDirectory.toString() + path + oldName);
oldUrl.setPath(m_destDirectory.path() + path + oldName);
QUrl newUrl = m_destDirectory;
newUrl.setPath(m_destDirectory.toString() + path + newName);
newUrl.setPath(m_destDirectory.path() + path + newName);
m_itemCache.remove(oldUrl);
......
......@@ -992,7 +992,7 @@ QUrl KGet::destFileInputDialog(QString destDir, const QString& suggestedFileName
QUrl destUrl = KFileDialog::getSaveUrl(startLocation, QString(), m_mainWindow, i18n("Save As"));
if (!destUrl.isEmpty()) {
Settings::setLastDirectory(destUrl.adjusted(QUrl::RemoveFilename).toString());
Settings::setLastDirectory(destUrl.adjusted(QUrl::RemoveFilename).path());
}
return destUrl;
......
......@@ -180,13 +180,13 @@ UrlChecker::UrlError UrlChecker::checkDestination(const QUrl &destination, bool
if (error == NoError) {
//not supposed to be a folder
QFileInfo fileInfo(destination.toString());
QFileInfo fileInfo(destination.toLocalFile());
if (!destination.isValid() || fileInfo.isDir()) {
error = Invalid;
}
qDebug() << "Adjusted destination:" << destination.adjusted(QUrl::RemoveFilename).toString();
if ((error == NoError) && !QFileInfo(destination.adjusted(QUrl::RemoveFilename).toString().remove("file://")).isWritable()) {
qDebug() << "Adjusted destination:" << destination.adjusted(QUrl::RemoveFilename).path();
if ((error == NoError) && !QFileInfo(destination.adjusted(QUrl::RemoveFilename).path()).isWritable()) {
error = NotWriteable;
}
}
......@@ -205,7 +205,7 @@ UrlChecker::UrlError UrlChecker::checkFolder(const QUrl &folder, bool showNotifi
{
UrlError error = NoError;
const QString destDir = folder.toString();
const QString destDir = folder.toLocalFile();
if (folder.isEmpty() || destDir.isEmpty()) {
error = Empty;
}
......@@ -239,9 +239,9 @@ QUrl UrlChecker::destUrl(const QUrl &destOrFolder, const QUrl &source, const QSt
if (usedFileName.isEmpty()) {
usedFileName = QUrl::toPercentEncoding(source.toString(), "/");
}
dest = dest.adjusted(QUrl::RemoveFilename).toString() + usedFileName;
dest = dest.adjusted(QUrl::RemoveFilename).path() + usedFileName;
} else if (!fileName.isEmpty()) {
dest.setPath(dest.adjusted(QUrl::RemoveFilename).toString() + fileName);
dest.setPath(dest.adjusted(QUrl::RemoveFilename).path() + fileName);
}
return dest;
......
......@@ -126,7 +126,7 @@ bool MetalinkXml::metalinkInit(const QUrl &src, const QByteArray &data)
for (it = m_metalink.files.files.constBegin(); it != itEnd ; ++it)
{
dest = tempDest;
dest.setPath(tempDest.adjusted(QUrl::RemoveFilename | QUrl::RemoveScheme).toString() + "/" + (*it).name);
dest.setPath(tempDest.path() + "/" + (*it).name);
QList<KGetMetalink::Url> urlList = (*it).resources.urls;
//sort the urls according to their priority (highest first)
......
......@@ -124,7 +124,7 @@ bool TransferMultiSegKio::repair(const QUrl &file)
bool TransferMultiSegKio::setDirectory(const QUrl& newDirectory)
{
QUrl newDest = newDirectory;
newDest.setPath(newDest.toString() + "/" + m_dest.fileName());
newDest.setPath(newDest.path() + "/" + m_dest.fileName());
return setNewDestination(newDest);
}
......@@ -177,7 +177,7 @@ void TransferMultiSegKio::slotDataSourceFactoryChange(Transfer::ChangesFlags cha
return;
}
QUrl path = m_dest.adjusted(QUrl::RemoveFilename);
path.setPath(path.toString() + "/" + filename);
path.setPath(path.path() + "/" + filename);
setNewDestination(path);
}
if (change & Tc_Source) {
......
......@@ -55,7 +55,7 @@ void GroupSettingsDialog::save()
if (ui.defaultFolderRequester->text().isEmpty()) {
m_group->setDefaultFolder(QString());
} else {
m_group->setDefaultFolder(ui.defaultFolderRequester->url().toString());
m_group->setDefaultFolder(ui.defaultFolderRequester->url().toLocalFile());
}
m_group->setDownloadLimit(ui.downloadBox->value(), Transfer::VisibleSpeedLimit);
......
......@@ -1160,7 +1160,7 @@ QString KGetMetalink::Metalink_v3::dateConstructToString(const KGetMetalink::Dat
bool KGetMetalink::HandleMetalink::load(const QUrl &destination, KGetMetalink::Metalink *metalink)
{
QFile file(destination.toString());
QFile file(destination.toLocalFile());
if (!file.open(QIODevice::ReadOnly))
{
return false;
......@@ -1224,7 +1224,7 @@ bool KGetMetalink::HandleMetalink::load(const QByteArray &data, KGetMetalink::Me
bool KGetMetalink::HandleMetalink::save(const QUrl &destination, KGetMetalink::Metalink *metalink)
{
QFile file(destination.toString());
QFile file(destination.toLocalFile());
if (!file.open(QIODevice::WriteOnly)) {
return false;
}
......
......@@ -54,7 +54,7 @@ void RenameFile::updateButton()
{
const QString newName = ui.name->text();
QUrl dest = m_dest;
dest.setPath(m_dest.toString() + newName);
dest.setPath(m_dest.path() + newName);
const bool enabled = !newName.isEmpty() && !QFile::exists(dest.toString());
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enabled);
......
......@@ -33,7 +33,7 @@ TransferDetails::TransferDetails(TransferHandler * transfer)
setLayout(m_layout);
frm.sourceContentEdit->setText(m_transfer->source().toString());
frm.destContentEdit->setText(m_transfer->dest().toString());
frm.destContentEdit->setText(m_transfer->dest().toLocalFile());
//This updates the widget with the right values
slotTransferChanged(transfer, 0xFFFFFFFF);
......@@ -94,7 +94,7 @@ void TransferDetails::slotTransferChanged(TransferHandler * transfer, TransferHa
}
if(flags & Transfer::Tc_FileName) {
frm.destContentEdit->setText(m_transfer->dest().toString());
frm.destContentEdit->setText(m_transfer->dest().toLocalFile());
}
if (flags & Transfer::Tc_Source) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment