Commit 5e540e68 authored by Robert Lancaster's avatar Robert Lancaster Committed by Jasem Mutlaq

This patch should make astrometry downloads work on Linux just like they now...

This patch should make astrometry downloads work on Linux just like they now work on Mac.  It makes use of KAuth and a helper file to read and write to the write protected /usr/share/astrometry folder.
parent b0936baa
......@@ -290,6 +290,15 @@ install(FILES org.kde.kstars.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR})
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
#This generates the helper file for astrometry index file downloads.
add_executable(kauth_kstars_helper kstars/auxiliary/downloadhelper.cpp ${helper_mocs})
target_link_libraries(kauth_kstars_helper Qt5::Core)
target_link_libraries(kauth_kstars_helper Qt5::Widgets)
target_link_libraries(kauth_kstars_helper KF5::Auth)
install(TARGETS kauth_kstars_helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
kauth_install_helper_files(kauth_kstars_helper org.kde.kf5auth.kstars root)
kauth_install_actions(org.kde.kf5auth.kstars org.kde.kf5auth.kstars.actions)
# Final package generation
if (ANDROID)
set(EXPORT_DIR "${CMAKE_BINARY_DIR}/android/kstars_build_apk/")
......
#include "downloadhelper.h"
ActionReply DownloadHelper::saveindexfile(const QVariantMap &args)
{
ActionReply reply;
QString filename = args["filename"].toString();
QFile file(filename);
if (file.open(QIODevice::WriteOnly) == false)
{
reply = ActionReply::HelperErrorReply();
reply.setErrorDescription(file.errorString());
return reply;
}
QByteArray array = args["contents"].toByteArray();
file.write(array.data(),array.size());
file.close();
return reply;
}
ActionReply DownloadHelper::removeindexfileset(const QVariantMap &args)
{
ActionReply reply;
QString indexSetName = args["indexSetName"].toString();
QString astrometryDataDir = args["astrometryDataDir"].toString();
QStringList nameFilter("*.fits");
QDir directory(astrometryDataDir);
QStringList indexList = directory.entryList(nameFilter);
foreach(QString fileName, indexList)
{
if(fileName.contains(indexSetName.left(10)))
{
if(!directory.remove(fileName))
{
reply = ActionReply::HelperErrorReply();
reply.setErrorDescription("File did not delete");
return reply;
}
}
}
return reply;
}
KAUTH_HELPER_MAIN("org.kde.kf5auth.kstars" , DownloadHelper);
#ifndef DOWNLOADHELPER_H
#define DOWNLOADHELPER_H
#include <QObject>
#include <QFile>
#include <QDir>
#include <QMessageBox>
#include <kauth.h>
using namespace KAuth;
class DownloadHelper : public QObject
{
Q_OBJECT
public Q_SLOTS:
ActionReply saveindexfile(const QVariantMap &args);
ActionReply removeindexfileset(const QVariantMap &args);
};
#endif // DOWNLOADHELPER_H
......@@ -9,6 +9,9 @@
#include "align.h"
#include "Options.h"
#include <kauthaction.h>
#include <kauthexecutejob.h>
namespace Ekos
{
......@@ -48,12 +51,7 @@ OpsAstrometryIndexFiles::OpsAstrometryIndexFiles(Align * parent) : QDialog( KSt
foreach(QCheckBox * checkBox, checkboxes)
{
//This disables the downloader on Linux until a solution can be found to the read only astrometry folder
#ifdef Q_OS_OSX
connect(checkBox, SIGNAL(clicked(bool)), this, SLOT(downloadOrDeleteIndexFiles(bool)));
#else
checkBox->setEnabled(false);
#endif
connect(checkBox, SIGNAL(clicked(bool)), this, SLOT(downloadOrDeleteIndexFiles(bool)));
}
QList<QProgressBar *> progressBars = findChildren<QProgressBar *>();
......@@ -252,25 +250,46 @@ void OpsAstrometryIndexFiles::downloadIndexFile(QString URL, QString fileN, QChe
indexFileN.replace("*" , indexString);
QFile file(indexFileN);
if (file.open(QIODevice::WriteOnly) == false)
if(QFileInfo(QFileInfo(file).path()).isWritable())
{
qDebug()<<"Index file save error";
return;
if (!file.open(QIODevice::WriteOnly))
{
KMessageBox::error(0, i18n("File Write Error"));
slotUpdate();
return;
}
else
{
file.write(responseData.data(),responseData.size());
file.close();
}
}
else
{
file.write(responseData.data(),responseData.size());
file.close();
#ifdef Q_OS_OSX
KMessageBox::error(0, i18n("Astrometry Folder Permissions Error"));
#else
KAuth::Action action(QStringLiteral("org.kde.kf5auth.kstars.saveindexfile"));
action.setHelperId(QStringLiteral("org.kde.kf5auth.kstars"));
action.setArguments(QVariantMap({{"filename",indexFileN},{"contents", responseData}}));
KAuth::ExecuteJob *job = action.execute();
if (!job->exec())
{
QMessageBox::information(this, "Error", QString("KAuth returned an error code: %1 %2").arg(job->error()).arg(job->errorString()));
slotUpdate();
return;
}
#endif
}
if(currentIndex==maxIndex){
checkBox->setEnabled(true);
if(indexDownloadProgress)
indexDownloadProgress->setVisible(false);
slotUpdate();
}
else
downloadIndexFile(URL, fileN, checkBox, currentIndex + 1, maxIndex);
if(currentIndex==maxIndex){
checkBox->setEnabled(true);
if(indexDownloadProgress)
indexDownloadProgress->setVisible(false);
slotUpdate();
}
else
downloadIndexFile(URL, fileN, checkBox, currentIndex + 1, maxIndex);
});
}
......@@ -281,16 +300,18 @@ void OpsAstrometryIndexFiles::downloadOrDeleteIndexFiles(bool checked){
if (getAstrometryDataDir(astrometryDataDir) == false)
return;
if(checkBox){
if(checkBox)
{
QString indexSetName=checkBox->text().remove("&");
QString progressBarName=indexSetName;
progressBarName=progressBarName.replace("-","_").left(10)+"_progress";
QProgressBar * indexDownloadProgress=findChild<QProgressBar *>(progressBarName);
QString fileN = astrometryDataDir + "/" + indexSetName;
QString filePath = astrometryDataDir + "/" + indexSetName;
int indexFileNum=indexSetName.mid(8,2).toInt();
if(checked){
checkBox->setChecked(!checked);
if(astrometryIndicesAreAvailable()){
if(astrometryIndicesAreAvailable())
{
if(indexDownloadProgress)
indexDownloadProgress->setVisible(true);
checkBox->setEnabled(false);
......@@ -300,12 +321,13 @@ void OpsAstrometryIndexFiles::downloadOrDeleteIndexFiles(bool checked){
else if(indexSetName.startsWith("index-42"))
URL = "http://broiler.astrometry.net/~dstn/4200/" + indexSetName;
int maxIndex=0;
if(indexFileNum<8 && URL.contains("*")){
if(indexFileNum<8 && URL.contains("*"))
{
maxIndex=11;
if(indexFileNum<5)
maxIndex=47;
}
downloadIndexFile(URL, fileN, checkBox,0,maxIndex);
downloadIndexFile(URL, filePath, checkBox,0,maxIndex);
} else{
KMessageBox::sorry( 0, i18n( "Could not contact Astrometry Index Server: broiler.astrometry.net" ) );
}
......@@ -313,13 +335,36 @@ void OpsAstrometryIndexFiles::downloadOrDeleteIndexFiles(bool checked){
if(KMessageBox::Continue==KMessageBox::warningContinueCancel(NULL, "Are you sure you want to delete these index files? " + indexSetName,
i18n("Delete File(s)"), KStandardGuiItem::cont(), KStandardGuiItem::cancel(), "delete_index_files_warning"))
{
QStringList nameFilter("*.fits");
QDir directory(astrometryDataDir);
QStringList indexList = directory.entryList(nameFilter);
foreach(QString indexName, indexList)
if(QFileInfo(astrometryDataDir).isWritable())
{
QStringList nameFilter("*.fits");
QDir directory(astrometryDataDir);
QStringList indexList = directory.entryList(nameFilter);
foreach(QString fileName, indexList)
{
if(fileName.contains(indexSetName.left(10))){
if(!directory.remove(fileName))
{
KMessageBox::error(0, i18n("File Delete Error"));
slotUpdate();
return;
}
}
}
}
else
{
if(indexName.contains(indexSetName.left(10)))
directory.remove(indexName);
#ifdef Q_OS_OSX
KMessageBox::error(0, i18n("Astrometry Folder Permissions Error"));
slotUpdate();
#else
KAuth::Action action(QStringLiteral("org.kde.kf5auth.kstars.removeindexfileset"));
action.setHelperId(QStringLiteral("org.kde.kf5auth.kstars"));
action.setArguments(QVariantMap({{"indexSetName",indexSetName},{"astrometryDataDir", astrometryDataDir}}));
KAuth::ExecuteJob *job = action.execute();
if (!job->exec())
QMessageBox::information(this, "Error", QString("KAuth returned an error code: %1 %2").arg(job->error()).arg(job->errorString()));
#endif
}
}
......
......@@ -5,6 +5,8 @@
#include "ui_opsastrometryindexfiles.h"
#include "QNetworkAccessManager"
#include "kauth.h"
class KConfigDialog;
......
[org.kde.kf5auth.kstars.saveindexfile]
Name=Save Astrometry Index File to a write protected directory
Description=KStars is attempting to save an Astrometry Index File to a directory owned by root
Policy=auth_admin
Persistence=session
[org.kde.kf5auth.kstars.removeindexfileset]
Name=Remove an Astrometry Index File Set
Description=KStars is attempting to remove Astrometry Index Files owned by root
Policy=auth_admin
Persistence=session
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