Commit bd8b4f7f authored by David Faure's avatar David Faure
Browse files

add_definitions(-DQT_NO_URL_CAST_FROM_STRING) + fix compilation

The code in kalarm was rethought and simplified, in particular.
parent 0039d740
......@@ -200,7 +200,7 @@ bool AlarmCalendar::open()
// Check for file's existence, assuming that it does exist when uncertain,
// to avoid overwriting it.
auto statJob = KIO::stat(mUrl.url(), KIO::StatJob::SourceSide, 2);
auto statJob = KIO::stat(mUrl, KIO::StatJob::SourceSide, 2);
KJobWidgets::setWindow(statJob, MainWindow::mainMainWindow());
if (!statJob->exec() || load() == 0)
{
......@@ -247,7 +247,7 @@ int AlarmCalendar::load()
QString filename;
qCDebug(KALARM_LOG) << mUrl.toDisplayString();
if (!mUrl.isLocalFile()) {
auto getJob = KIO::storedGet(mUrl.url());
auto getJob = KIO::storedGet(mUrl);
KJobWidgets::setWindow(getJob, MainWindow::mainMainWindow());
if (!getJob->exec())
{
......@@ -348,7 +348,7 @@ bool AlarmCalendar::saveCal(const QString& newFile)
{
QFile file(saveFilename);
file.open(QIODevice::ReadOnly);
auto putJob = KIO::storedPut(&file, mICalUrl.url(), -1);
auto putJob = KIO::storedPut(&file, mICalUrl, -1);
KJobWidgets::setWindow(putJob, MainWindow::mainMainWindow());
if (!putJob->exec())
{
......@@ -622,7 +622,7 @@ bool AlarmCalendar::importAlarms(QWidget* parent, Collection* collection)
}
else
{
auto getJob = KIO::storedGet(url.url());
auto getJob = KIO::storedGet(url);
KJobWidgets::setWindow(getJob, MainWindow::mainMainWindow());
if (!getJob->exec())
{
......@@ -744,7 +744,7 @@ bool AlarmCalendar::exportAlarms(const KAEvent::List& events, QWidget* parent)
if (append && !calStorage->load())
{
KIO::UDSEntry uds;
auto statJob = KIO::stat(url.url(), KIO::StatJob::SourceSide, 2);
auto statJob = KIO::stat(url, KIO::StatJob::SourceSide, 2);
KJobWidgets::setWindow(statJob, parent);
statJob->exec();
KFileItem fi(statJob->statResult(), url);
......@@ -799,7 +799,7 @@ bool AlarmCalendar::exportAlarms(const KAEvent::List& events, QWidget* parent)
{
QFile qFile(file);
qFile.open(QIODevice::ReadOnly);
auto uploadJob = KIO::storedPut(&qFile, url.url(), -1);
auto uploadJob = KIO::storedPut(&qFile, url, -1);
KJobWidgets::setWindow(uploadJob, parent);
if (!uploadJob->exec())
{
......
......@@ -1625,20 +1625,18 @@ FileType fileType(const QMimeType& mimetype)
*/
FileErr checkFileExists(QString& filename, QUrl& url)
{
url = QUrl();
FileErr err = FileErr_None;
QString file = filename;
QRegExp f(QStringLiteral("^file:/+"));
if (f.indexIn(file) >= 0)
file = file.mid(f.matchedLength() - 1);
// Convert any relative file path to absolute
// (using home directory as the default)
int i = file.indexOf(QLatin1Char('/'));
if (i > 0 && file[i - 1] == QLatin1Char(':'))
// This also supports absolute paths and absolute urls
url = QUrl::fromUserInput(filename, QDir::homePath());
FileErr err = FileErr_None;
if (filename.isEmpty())
{
err = FileErr_Blank; // blank file name
}
else if (!url.isLocalFile())
{
url = file;
const QString displayStr = url.toDisplayString();
filename = displayStr.mid(displayStr.lastIndexOf(QLatin1Char('/')) + 1);
filename = url.toDisplayString();
auto statJob = KIO::stat(url, KIO::StatJob::SourceSide, 2);
KJobWidgets::setWindow(statJob, MainWindow::mainMainWindow());
if (!statJob->exec())
......@@ -1650,15 +1648,11 @@ FileErr checkFileExists(QString& filename, QUrl& url)
else if (!fi.isReadable()) err = FileErr_Unreadable;
}
}
else if (file.isEmpty())
err = FileErr_Blank; // blank file name
else
{
// It's a local file - convert to absolute path & check validity
QFileInfo info(file);
QDir::setCurrent(QDir::homePath());
filename = info.absoluteFilePath();
url.setPath(filename);
// It's a local file
filename = url.toLocalFile();
QFileInfo info(filename);
if (info.isDir()) err = FileErr_Directory;
else if (!info.exists()) err = FileErr_Nonexistent;
else if (!info.isReadable()) err = FileErr_Unreadable;
......@@ -1740,7 +1734,7 @@ QString browseFile(const QString& caption, QString& defaultDir, const QString& i
// Use AutoQPointer to guard against crash on application exit while
// the dialogue is still open. It prevents double deletion (both on
// deletion of parent, and on return from this function).
AutoQPointer<KFileDialog> fileDlg = new KFileDialog(initialDir, filter, parent);
AutoQPointer<KFileDialog> fileDlg = new KFileDialog(QUrl::fromLocalFile(initialDir), filter, parent);
fileDlg->setOperationMode(mode & KFile::ExistingOnly ? KFileDialog::Opening : KFileDialog::Saving);
fileDlg->setMode(KFile::File | mode);
fileDlg->setWindowTitle(caption);
......
......@@ -420,7 +420,7 @@ QString KAMail::appendBodyAttachments(KMime::Message& message, JobData& data)
}
// Read the file contents
auto downloadJob = KIO::storedGet(url.url());
auto downloadJob = KIO::storedGet(url);
KJobWidgets::setWindow(downloadJob, MainWindow::mainMainWindow());
if (!downloadJob->exec())
{
......
......@@ -498,7 +498,6 @@ bool SoundWidget::validate(bool showErrorMessage) const
return true;
if (err == KAlarm::FileErr_Nonexistent)
{
mUrl = QUrl::fromUserInput(file, QString(), QUrl::AssumeLocalFile);
if (mUrl.isLocalFile() && !file.startsWith(QStringLiteral("/")))
{
// It's a relative path.
......@@ -513,8 +512,7 @@ bool SoundWidget::validate(bool showErrorMessage) const
dir = soundDirs[i];
if (dir.isReadable() && dir.count() > 2)
{
mUrl.setPath(soundDirs[i] + QDir::separator() + file);
QString f = mUrl.toLocalFile();
QString f = soundDirs[i] + QDir::separator() + file;
err = KAlarm::checkFileExists(f, mUrl);
if (err == KAlarm::FileErr_None)
return true;
......@@ -528,8 +526,7 @@ bool SoundWidget::validate(bool showErrorMessage) const
}
if (err == KAlarm::FileErr_Nonexistent)
{
mUrl.setPath(QDir::homePath() + QDir::separator() + file);
QString f = mUrl.toLocalFile();
QString f = QDir::homePath() + QDir::separator() + file;
err = KAlarm::checkFileExists(f, mUrl);
if (err == KAlarm::FileErr_None)
return true;
......
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