Commit a4cf7ac2 authored by Thomas Eschenbacher's avatar Thomas Eschenbacher
Browse files

introduced Kwave::URLfromUserInput to work around problems with QUrl

misinterpreting file names in cmdline parameters as http:// URLs
parent c6213fa5
21.11.70 [2021-07-13]
* introduced Kwave::URLfromUserInput to work around problems with QUrl
misinterpreting file names in cmdline parameters as http:// URLs
20.08.01 [2020-08-31]
* adapted make targets (scripts) for "update-translations" and "msgstats"
......
......@@ -161,7 +161,7 @@ int Kwave::App::newInstance(const QStringList &args, const QString &dir)
// open a window for each file specified in the
// command line an load it
foreach (const QString &name, params) {
retval = newWindow(QUrl::fromUserInput(name));
retval = newWindow(Kwave::URLfromUserInput(name));
}
}
return retval;
......
......@@ -941,7 +941,7 @@ int Kwave::MainWidget::loadLabels(const QString &filename)
delete dlg;
}
} else {
url = QUrl::fromUserInput(filename);
url = Kwave::URLfromUserInput(filename);
}
// create an own undo transaction
......@@ -1000,7 +1000,7 @@ int Kwave::MainWidget::saveLabels(const QString &filename)
}
}
} else {
url = QUrl::fromUserInput(filename);
url = Kwave::URLfromUserInput(filename);
}
// now we have a file name -> save all labels...
......
......@@ -747,7 +747,7 @@ int Kwave::TopWidget::executeCommand(const QString &line)
QString filename = parser.nextParam();
if (!filename.isEmpty()) {
// open the selected file
result = loadFile(QUrl::fromUserInput(filename));
result = loadFile(Kwave::URLfromUserInput(filename));
} else {
// show file open dialog
result = openFile();
......@@ -1085,7 +1085,7 @@ int Kwave::TopWidget::loadFile(const QUrl &url)
int Kwave::TopWidget::openRecent(const QString &str)
{
Kwave::Parser parser(str);
return loadFile(QUrl::fromUserInput(parser.firstParam()));
return loadFile(Kwave::URLfromUserInput(parser.firstParam()));
}
//***************************************************************************
......
......@@ -34,6 +34,7 @@
#include "libkwave/CodecManager.h"
#include "libkwave/String.h"
#include "libkwave/Utils.h"
#include "libgui/FileDialog.h"
......@@ -48,7 +49,7 @@ Kwave::FileDialog::FileDialog(
)
:QDialog(parent),
m_layout(this),
m_file_widget(QUrl::fromUserInput(startDir), this),
m_file_widget(Kwave::URLfromUserInput(startDir), this),
m_config_group(),
m_last_url(last_url),
m_last_ext(last_ext)
......@@ -177,10 +178,10 @@ void Kwave::FileDialog::loadConfig(const QString &section)
// take last path, but user defined file name
QString file_name = m_last_url.fileName();
last_path = last_path.adjusted(QUrl::RemoveFilename);
m_last_url = QUrl::fromUserInput(last_path.path() + file_name);
m_last_url = Kwave::URLfromUserInput(last_path.path() + file_name);
}
} else {
m_last_url = QUrl::fromUserInput(cfg.readEntry("last_url",
m_last_url = Kwave::URLfromUserInput(cfg.readEntry("last_url",
m_last_url.toDisplayString()));
}
if (!m_last_ext.length())
......@@ -264,7 +265,7 @@ QUrl Kwave::FileDialog::baseUrl() const
//***************************************************************************
void Kwave::FileDialog::setDirectory(const QString &directory)
{
m_file_widget.setStartDir(QUrl::fromUserInput(directory));
m_file_widget.setStartDir(Kwave::URLfromUserInput(directory));
}
//***************************************************************************
......
......@@ -23,6 +23,7 @@
#include <QDate>
#include <QDateTime>
#include <QDir>
#include <QLatin1Char>
#include <QLocale>
#include <QString>
......@@ -175,6 +176,13 @@ QString Kwave::string2date(const QString &str)
return QString();
}
//***************************************************************************
QUrl Kwave::URLfromUserInput(const QString &path)
{
return QUrl::fromUserInput(path, QDir::currentPath(),
QUrl::AssumeLocalFile);
}
//***************************************************************************
QString Kwave::urlScheme()
{
......
......@@ -24,6 +24,7 @@
#include <QString>
#include <QtGlobal>
#include <QUrl>
#include "libkwave/Sample.h" // for sample_index_t
......@@ -137,8 +138,16 @@ namespace Kwave
return static_cast<int>(x);
}
/**
* Wrapper around Kwave::URLfromUserInput that handles relative paths and
* prefers local file names
* @param path a file name, path, or other kind of string encoded URL
* @return a QUrl object
*/
QUrl URLfromUserInput(const QString &path) Q_DECL_EXPORT;
/** returns the URL scheme for encoding/decoding kwave:<*> URLs */
QString Q_DECL_EXPORT urlScheme();
QString urlScheme() Q_DECL_EXPORT;
/**
* Returns the limit of memory that can be used for undo/redo
......
......@@ -99,7 +99,7 @@ int Kwave::K3BExportPlugin::interpreteParameters(QStringList &params)
return -EINVAL;
// the selected URL
m_url = QUrl::fromUserInput(Kwave::Parser::unescape(params[0]));
m_url = Kwave::URLfromUserInput(Kwave::Parser::unescape(params[0]));
if (!m_url.isValid()) return -EINVAL;
// label pattern
......@@ -308,7 +308,7 @@ QStringList *Kwave::K3BExportPlugin::setup(QStringList &params)
"K3b project file (*.k3b)"
),
parentWidget(),
QUrl::fromUserInput(signalName()),
Kwave::URLfromUserInput(signalName()),
_("*.k3b"),
m_pattern,
m_selection_only,
......
......@@ -38,6 +38,7 @@
#include "libkwave/Parser.h"
#include "libkwave/SignalManager.h"
#include "libkwave/String.h"
#include "libkwave/Utils.h"
#include "SaveBlocksDialog.h"
#include "SaveBlocksPlugin.h"
......@@ -85,7 +86,7 @@ QStringList *Kwave::SaveBlocksPlugin::setup(QStringList &previous_params)
_("kfiledialog:///kwave_save_blocks"),
Kwave::CodecManager::encodingFilter(),
parentWidget(),
QUrl::fromUserInput(signalName()),
Kwave::URLfromUserInput(signalName()),
_("*.wav"),
m_pattern,
m_numbering_mode,
......@@ -418,7 +419,7 @@ int Kwave::SaveBlocksPlugin::interpreteParameters(QStringList &params)
}
// the selected URL
m_url = QUrl::fromUserInput(Kwave::Parser::unescape(params[0]));
m_url = Kwave::URLfromUserInput(Kwave::Parser::unescape(params[0]));
if (!m_url.isValid()) return -EINVAL;
// filename pattern
......
Supports Markdown
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