Commit d2ad5cc2 authored by Jasem Mutlaq's avatar Jasem Mutlaq

+ Using toLocalFile() instead of path() to avoid cross-platform file location issues.

+ ImageViewer save dialog will remember last location
+ Observing Session will not be saved if list is empty
parent fbd8f889
......@@ -37,6 +37,8 @@
#include <KLocalizedString>
#include <KMessageBox>
QUrl ImageViewer::lastURL = QUrl::fromLocalFile(QDir::homePath());
ImageLabel::ImageLabel( QWidget *parent ) : QFrame( parent )
{
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
......@@ -102,7 +104,7 @@ ImageViewer::ImageViewer (const QUrl &url, const QString &capText, QWidget *pare
if (m_ImageUrl.isLocalFile())
{
loadImage(m_ImageUrl.path());
loadImage(m_ImageUrl.toLocalFile());
return;
}
......@@ -285,12 +287,12 @@ bool ImageViewer::showImage()
void ImageViewer::saveFileToDisc()
{
QFileDialog dialog;
dialog.selectFile(m_ImageUrl.fileName().remove(m_ImageUrl.path()));
dialog.setFileMode(QFileDialog::AnyFile);
QUrl newURL = dialog.getSaveFileUrl(KStars::Instance(), i18n("Save Image")); // save-dialog with default filename
QUrl newURL = dialog.getSaveFileUrl(KStars::Instance(), i18n("Save Image"), lastURL); // save-dialog with default filename
if (!newURL.isEmpty())
{
QFile f (newURL.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path() + '/' + newURL.fileName());
//QFile f (newURL.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).toLocalFile() + '/' + newURL.fileName());
QFile f(newURL.toLocalFile());
if (f.exists())
{
int r=KMessageBox::warningContinueCancel(static_cast<QWidget *>(parent()),
......@@ -302,6 +304,9 @@ void ImageViewer::saveFileToDisc()
f.remove();
}
lastURL = QUrl(newURL.toString(QUrl::RemoveFilename));
saveFile (newURL);
}
}
......@@ -314,7 +319,7 @@ void ImageViewer::saveFile (QUrl &url)
//QUrl tmpURL((file.fileName()));
//tmpURL.setScheme("file");
if (file.copy(url.path()) == false)
if (file.copy(url.toLocalFile()) == false)
//if (KIO::file_copy(tmpURL, url)->exec() == false)
{
QString text = i18n ("Saving of the image %1 failed.", url.toString());
......
......@@ -105,13 +105,14 @@ private:
bool fileIsImage;
QString filename;
//KIO::Job *downloadJob; // download job of image -> 0 == no job is running
FileDownloader downloadJob;
ImageLabel *m_View;
QLabel *m_Caption;
// Share among image viewers
static QUrl lastURL;
private slots:
/** Initialize (common part of onstructors) */
void init(QString caption, QString capText);
......
......@@ -60,7 +60,7 @@ public:
/**
*@return the filename of the custom catalog.
*/
QString filename() const { return acd->CatalogURL->url().path(); }
QString filename() const { return acd->CatalogURL->url().toLocalFile(); }
private slots:
/**
......
......@@ -1870,7 +1870,7 @@ void Capture::syncTelescopeInfo()
void Capture::saveFITSDirectory()
{
QString dir = QFileDialog::getExistingDirectory(KStars::Instance(), i18n("FITS Save Directory"), dirPath.path());
QString dir = QFileDialog::getExistingDirectory(KStars::Instance(), i18n("FITS Save Directory"), dirPath.toLocalFile());
if (dir.isEmpty())
return;
......@@ -1887,14 +1887,14 @@ void Capture::loadSequenceQueue()
if (fileURL.isValid() == false)
{
QString message = i18n( "Invalid URL: %1", fileURL.path() );
QString message = i18n( "Invalid URL: %1", fileURL.toLocalFile() );
KMessageBox::sorry( 0, message, i18n( "Invalid URL" ) );
return;
}
dirPath = QUrl(fileURL.url(QUrl::RemoveFilename));
loadSequenceQueue(fileURL.path());
loadSequenceQueue(fileURL.toLocalFile());
}
......@@ -2169,7 +2169,7 @@ void Capture::saveSequenceQueue()
{
QUrl backupCurrent = sequenceURL;
if (sequenceURL.path().startsWith("/tmp/") || sequenceURL.path().contains("/Temp"))
if (sequenceURL.toLocalFile().startsWith("/tmp/") || sequenceURL.toLocalFile().contains("/Temp"))
sequenceURL.clear();
// If no changes made, return.
......@@ -2188,10 +2188,10 @@ void Capture::saveSequenceQueue()
dirPath = QUrl(sequenceURL.url(QUrl::RemoveFilename));
if (sequenceURL.path().contains('.') == 0)
sequenceURL.setPath(sequenceURL.path() + ".esq");
if (sequenceURL.toLocalFile().endsWith(".esq") == false)
sequenceURL.setPath(sequenceURL.toLocalFile() + ".esq");
if (QFile::exists(sequenceURL.path()))
if (QFile::exists(sequenceURL.toLocalFile()))
{
int r = KMessageBox::warningContinueCancel(0,
i18n( "A file named \"%1\" already exists. "
......@@ -2204,7 +2204,7 @@ void Capture::saveSequenceQueue()
if ( sequenceURL.isValid() )
{
if ( (saveSequenceQueue(sequenceURL.path())) == false)
if ( (saveSequenceQueue(sequenceURL.toLocalFile())) == false)
{
KMessageBox::error(KStars::Instance(), i18n("Failed to save sequence queue"), i18n("Save"));
return;
......
......@@ -200,7 +200,7 @@ void OnlineAstrometryParser::authenticate()
QUrl url(apiURL);
QString method = "login";
url.setPath(QString("%1%2").arg(url.path()).arg(method));
url.setPath(QString("%1%2").arg(url.toLocalFile()).arg(method));
request.setUrl(url);
QVariantMap apiReq;
......@@ -231,7 +231,7 @@ void OnlineAstrometryParser::uploadFile()
QUrl url(apiURL);
QString method = "upload/";
url.setPath(QString("%1%2").arg(url.path()).arg(method));
url.setPath(QString("%1%2").arg(url.toLocalFile()).arg(method));
request.setUrl(url);
QHttpMultiPart reqEntity(QHttpMultiPart::FormDataType);
......
......@@ -68,7 +68,7 @@ void OpsEkos::slotSelectPHD2Exec()
if (phd2URL.isEmpty())
return;
kcfg_PHD2Exec->setText(phd2URL.path());
kcfg_PHD2Exec->setText(phd2URL.toLocalFile());
}
void OpsEkos::slotCheckGuideModule()
......
......@@ -312,7 +312,7 @@ void Scheduler::selectFITS()
setDirty();
fitsEdit->setText(fitsURL.path());
fitsEdit->setText(fitsURL.toLocalFile());
//raBox->clear();
//decBox->clear();
......@@ -334,7 +334,7 @@ void Scheduler::selectSequence()
setDirty();
sequenceEdit->setText(sequenceURL.path());
sequenceEdit->setText(sequenceURL.toLocalFile());
// For object selection, all fields must be filled
if ( (raBox->isEmpty() == false && decBox->isEmpty() == false && nameEdit->text().isEmpty() == false)
......@@ -355,7 +355,7 @@ void Scheduler::selectStartupScript()
dirPath = QUrl(startupScriptURL.url(QUrl::RemoveFilename));
mDirty=true;
startupScript->setText(startupScriptURL.path());
startupScript->setText(startupScriptURL.toLocalFile());
}
void Scheduler::selectShutdownScript()
......@@ -367,7 +367,7 @@ void Scheduler::selectShutdownScript()
dirPath = QUrl(shutdownScriptURL.url(QUrl::RemoveFilename));
mDirty=true;
shutdownScript->setText(shutdownScriptURL.path());
shutdownScript->setText(shutdownScriptURL.toLocalFile());
}
void Scheduler::addJob()
......@@ -626,7 +626,7 @@ void Scheduler::loadJob(QModelIndex i)
if (job->getFITSFile().isEmpty() == false)
{
fitsEdit->setText(job->getFITSFile().path());
fitsEdit->setText(job->getFITSFile().toLocalFile());
fitsURL = job->getFITSFile();
}
else
......@@ -635,7 +635,7 @@ void Scheduler::loadJob(QModelIndex i)
fitsURL = QUrl();
}
sequenceEdit->setText(job->getSequenceFile().path());
sequenceEdit->setText(job->getSequenceFile().toLocalFile());
sequenceURL = job->getSequenceFile();
profileCombo->setCurrentText(job->getProfile());
......@@ -2929,14 +2929,14 @@ void Scheduler::load()
if (fileURL.isValid() == false)
{
QString message = i18n( "Invalid URL: %1", fileURL.path() );
QString message = i18n( "Invalid URL: %1", fileURL.toLocalFile() );
KMessageBox::sorry( 0, message, i18n( "Invalid URL" ) );
return;
}
dirPath = QUrl(fileURL.url(QUrl::RemoveFilename));
loadScheduler(fileURL.path());
loadScheduler(fileURL.toLocalFile());
}
bool Scheduler::loadScheduler(const QString &fileURL)
......@@ -3188,7 +3188,7 @@ void Scheduler::save()
{
QUrl backupCurrent = schedulerURL;
if (schedulerURL.path().startsWith("/tmp/") || schedulerURL.path().contains("/Temp"))
if (schedulerURL.toLocalFile().startsWith("/tmp/") || schedulerURL.toLocalFile().contains("/Temp"))
schedulerURL.clear();
// If no changes made, return.
......@@ -3207,10 +3207,10 @@ void Scheduler::save()
dirPath = QUrl(schedulerURL.url(QUrl::RemoveFilename));
if (schedulerURL.path().contains('.') == 0)
schedulerURL.setPath(schedulerURL.path() + ".esl");
if (schedulerURL.toLocalFile().contains('.') == 0)
schedulerURL.setPath(schedulerURL.toLocalFile() + ".esl");
if (QFile::exists(schedulerURL.path()))
if (QFile::exists(schedulerURL.toLocalFile()))
{
int r = KMessageBox::warningContinueCancel(0,
i18n( "A file named \"%1\" already exists. "
......@@ -3241,11 +3241,11 @@ void Scheduler::save()
bool Scheduler::saveScheduler(const QUrl &fileURL)
{
QFile file;
file.setFileName(fileURL.path());
file.setFileName(fileURL.toLocalFile());
if ( !file.open( QIODevice::WriteOnly))
{
QString message = i18n( "Unable to write to file %1", fileURL.path());
QString message = i18n( "Unable to write to file %1", fileURL.toLocalFile());
KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
return false;
}
......@@ -3267,9 +3267,9 @@ bool Scheduler::saveScheduler(const QUrl &fileURL)
outstream << "</Coordinates>" << endl;
if (job->getFITSFile().isValid() && job->getFITSFile().isEmpty() == false)
outstream << "<FITS>" << job->getFITSFile().path() << "</FITS>" << endl;
outstream << "<FITS>" << job->getFITSFile().toLocalFile() << "</FITS>" << endl;
outstream << "<Sequence>" << job->getSequenceFile().path() << "</Sequence>" << endl;
outstream << "<Sequence>" << job->getSequenceFile().toLocalFile() << "</Sequence>" << endl;
outstream << "<StartupCondition>" << endl;
if (job->getFileStartupCondition() == SchedulerJob::START_ASAP)
......@@ -3341,7 +3341,7 @@ bool Scheduler::saveScheduler(const QUrl &fileURL)
outstream << "</SchedulerList>" << endl;
appendLogText(i18n("Scheduler list saved to %1", fileURL.path()));
appendLogText(i18n("Scheduler list saved to %1", fileURL.toLocalFile()));
file.close();
return true;
}
......@@ -3576,7 +3576,7 @@ void Scheduler::startCapture()
{
captureInterface->call(QDBus::AutoDetect,"clearSequenceQueue");
QString url = currentJob->getSequenceFile().path();
QString url = currentJob->getSequenceFile().toLocalFile();
QList<QVariant> dbusargs;
dbusargs.append(url);
......@@ -3640,7 +3640,7 @@ void Scheduler::setDirty()
bool Scheduler::estimateJobTime(SchedulerJob *job)
{
QFile sFile;
sFile.setFileName(job->getSequenceFile().path());
sFile.setFileName(job->getSequenceFile().toLocalFile());
if ( !sFile.open( QIODevice::ReadOnly))
{
......@@ -4277,11 +4277,11 @@ void Scheduler::startMosaicTool()
if (saveScheduler(mosaicURL))
{
appendLogText(i18n("Mosaic file %1 saved successfully.", mosaicURL.path()));
appendLogText(i18n("Mosaic file %1 saved successfully.", mosaicURL.toLocalFile()));
}
else
{
appendLogText(i18n("Error saving mosaic file %1. Please reload job.", mosaicURL.path()));
appendLogText(i18n("Error saving mosaic file %1. Please reload job.", mosaicURL.toLocalFile()));
}
}
}
......@@ -4289,7 +4289,7 @@ void Scheduler::startMosaicTool()
XMLEle * Scheduler::getSequenceJobRoot()
{
QFile sFile;
sFile.setFileName(sequenceURL.path());
sFile.setFileName(sequenceURL.toLocalFile());
if ( !sFile.open( QIODevice::ReadOnly))
{
......@@ -4318,7 +4318,7 @@ XMLEle * Scheduler::getSequenceJobRoot()
bool Scheduler::createJobSequence(XMLEle *root, const QString &prefix, const QString &outputDir)
{
QFile sFile;
sFile.setFileName(sequenceURL.path());
sFile.setFileName(sequenceURL.toLocalFile());
if ( !sFile.open( QIODevice::ReadOnly))
{
......
......@@ -250,7 +250,7 @@ bool FITSTab::saveFile()
QUrl currentDir(Options::fitsDir());
currentDir.setScheme("file");
if (currentURL.path().startsWith("/tmp/") || currentURL.path().contains("/Temp"))
if (currentURL.toLocalFile().startsWith("/tmp/") || currentURL.toLocalFile().contains("/Temp"))
currentURL.clear();
// If no changes made, return.
......@@ -267,10 +267,10 @@ bool FITSTab::saveFile()
return false;
}
if (currentURL.path().contains('.') == 0)
currentURL.setPath(currentURL.path() + ".fits");
if (currentURL.toLocalFile().contains('.') == 0)
currentURL.setPath(currentURL.toLocalFile() + ".fits");
if (QFile::exists(currentURL.path()))
if (QFile::exists(currentURL.toLocalFile()))
{
int r = KMessageBox::warningContinueCancel(0,
i18n( "A file named \"%1\" already exists. "
......@@ -285,7 +285,7 @@ bool FITSTab::saveFile()
if ( currentURL.isValid() )
{
if ( (err_status = saveFITS('!' + currentURL.path())) != 0)
if ( (err_status = saveFITS('!' + currentURL.toLocalFile())) != 0)
{
// -1000 = user canceled
if (err_status == -1000)
......
......@@ -480,7 +480,7 @@ void FITSViewer::openFile()
return;
lastURL = QUrl(fileURL.url(QUrl::RemoveFilename));
QString fpath = fileURL.path();
QString fpath = fileURL.toLocalFile();
QString cpath;
......
......@@ -663,9 +663,9 @@ void INDI_E::browseBlob()
return;
if ( currentURL.isValid() )
write_w->setText(currentURL.path());
write_w->setText(currentURL.toLocalFile());
fp.setFileName(currentURL.path());
fp.setFileName(currentURL.toLocalFile());
if ( (pos = filename.lastIndexOf(".")) != -1)
format = filename.mid (pos, filename.length());
......
......@@ -159,7 +159,7 @@ void StreamWG::captureImage()
if ( currentFileURL.isValid() )
{
streamFrame->kPix.save(currentFileURL.path(), fmt.toLatin1());
streamFrame->kPix.save(currentFileURL.toLocalFile(), fmt.toLatin1());
}
else
{
......
......@@ -789,12 +789,12 @@ void KStars::slotOpenFITS()
// Reported as fixed in Qt 5.6
// Emerged Qt 5.5 with patch is not working
#ifdef Q_OS_WIN
if (fileURL.path().startsWith("/"))
fileURL.setPath(fileURL.path().right(fileURL.path().count()-1));
if (fileURL.toLocalFile().startsWith("/"))
fileURL.setPath(fileURL.toLocalFile().right(fileURL.toLocalFile().count()-1));
#endif
// Remember last directory
path.setUrl(fileURL.path());
path.setUrl(fileURL.toLocalFile());
FITSViewer * fv = new FITSViewer(this);
// Error opening file
......@@ -819,7 +819,7 @@ void KStars::slotExportImage() {
}
//Warn user if file exists!
if (QFile::exists(fileURL.path()))
if (QFile::exists(fileURL.toLocalFile()))
{
int r=KMessageBox::warningContinueCancel(parentWidget(),
i18n( "A file named \"%1\" already exists. Overwrite it?" , fileURL.fileName()),
......
......@@ -308,7 +308,7 @@ void Execute::slotEndSession() {
if( fileURL.isValid() ) {
QFile f( fileURL.path() );
QFile f( fileURL.toLocalFile() );
if( ! f.open( QIODevice::WriteOnly ) ) {
QString message = i18n( "Could not open file %1", f.fileName() );
KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
......
......@@ -82,7 +82,7 @@ void PWizPrintUI::slotExport()
}
//Warn user if file exists!
if(QFile::exists(url.path()))
if(QFile::exists(url.toLocalFile()))
{
int r=KMessageBox::warningContinueCancel(parentWidget(),
i18n( "A file named \"%1\" already exists. Overwrite it?" , url.fileName()),
......
......@@ -148,7 +148,7 @@ void SatellitesComponent::updateTLEs()
if (response->error() == QNetworkReply::NoError)
{
QFile file(group->tleFilename().path());
QFile file(group->tleFilename().toLocalFile());
if (file.open(QFile::WriteOnly))
{
file.write(response->readAll());
......
......@@ -750,7 +750,7 @@ void ObservingList::slotOpenList()
if ( fileURL.isValid() )
{
f.setFileName( fileURL.path() );
f.setFileName( fileURL.toLocalFile() );
//FIXME do we still need to do this?
/*
if ( ! fileURL.isLocalFile() ) {
......@@ -798,7 +798,7 @@ void ObservingList::slotOpenList()
//Newly-opened list should not trigger isModified flag
isModified = false;
f.close();
} else if ( ! fileURL.path().isEmpty() ) {
} else if ( ! fileURL.toLocalFile().isEmpty() ) {
KMessageBox::sorry( 0 , i18n( "The specified file is invalid" ) );
}
}
......@@ -817,9 +817,12 @@ void ObservingList::saveCurrentList() {
}
void ObservingList::slotSaveSessionAs(bool nativeSave) {
if (sessionList().isEmpty())
return;
QUrl fileURL = QFileDialog::getSaveFileUrl(KStars::Instance(), i18n("Save Observing List"), QUrl(), "KStars Observing List (*.obslist)" );
if ( fileURL.isValid() ) {
FileName = fileURL.path();
FileName = fileURL.toLocalFile();
slotSaveSession(nativeSave);
}
}
......@@ -886,6 +889,12 @@ void ObservingList::slotLoadWishList() {
}
void ObservingList::slotSaveSession(bool nativeSave) {
if (sessionList().isEmpty())
{
KMessageBox::error(0, i18n("Cannot save an empty session list!"));
return;
}
if ( FileName.isEmpty() ) {
slotSaveSessionAs(nativeSave);
return;
......
......@@ -756,7 +756,7 @@ void ScriptBuilder::slotOpen() {
if ( currentFileURL.isValid() )
{
currentDir = currentFileURL.path();
currentDir = currentFileURL.toLocalFile();
ScriptList.clear();
sb->ScriptListBox->clear();
......@@ -819,13 +819,13 @@ void ScriptBuilder::slotSave()
}
if ( currentFileURL.isValid() ) {
currentDir = currentFileURL.path();
currentDir = currentFileURL.toLocalFile();
if ( currentFileURL.isLocalFile() ) {
fname = currentFileURL.toLocalFile();
//Warn user if file exists
if (newFilename == true && QFile::exists(currentFileURL.path())) {
if (newFilename == true && QFile::exists(currentFileURL.toLocalFile())) {
int r=KMessageBox::warningContinueCancel(static_cast<QWidget *>(parent()),
i18n( "A file named \"%1\" already exists. "
"Overwrite it?" , currentFileURL.fileName()),
......
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