summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Lancaster <[email protected]>2017-06-09 17:35:05 +0300
committerJasem Mutlaq <[email protected]>2017-06-09 17:35:05 +0300
commit5e540e68e5391d1729b6d5ff2f673cc69ccce820 (patch)
treeec47948fe3dd2d2897ddc3287c7bb8976ce15e67
parentb0936baa56951dad2b67931aad73c63ea153c31f (diff)
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.
-rw-r--r--CMakeLists.txt9
-rw-r--r--kstars/auxiliary/downloadhelper.cpp50
-rw-r--r--kstars/auxiliary/downloadhelper.h23
-rw-r--r--kstars/ekos/align/opsastrometryindexfiles.cpp105
-rw-r--r--kstars/ekos/align/opsastrometryindexfiles.h2
-rw-r--r--org.kde.kf5auth.kstars.actions11
6 files changed, 170 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 15ebae1..8ee5f2d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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/")
diff --git a/kstars/auxiliary/downloadhelper.cpp b/kstars/auxiliary/downloadhelper.cpp
new file mode 100644
index 0000000..237907c
--- /dev/null
+++ b/kstars/auxiliary/downloadhelper.cpp
@@ -0,0 +1,50 @@
+#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);
diff --git a/kstars/auxiliary/downloadhelper.h b/kstars/auxiliary/downloadhelper.h
new file mode 100644
index 0000000..81e79f1
--- /dev/null
+++ b/kstars/auxiliary/downloadhelper.h
@@ -0,0 +1,23 @@
+#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
diff --git a/kstars/ekos/align/opsastrometryindexfiles.cpp b/kstars/ekos/align/opsastrometryindexfiles.cpp
index 777d32b..e4591d7 100644
--- a/kstars/ekos/align/opsastrometryindexfiles.cpp
+++ b/kstars/ekos/align/opsastrometryindexfiles.cpp
@@ -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
}
}
diff --git a/kstars/ekos/align/opsastrometryindexfiles.h b/kstars/ekos/align/opsastrometryindexfiles.h
index d0fb6da..19e2032 100644
--- a/kstars/ekos/align/opsastrometryindexfiles.h
+++ b/kstars/ekos/align/opsastrometryindexfiles.h
@@ -5,6 +5,8 @@
#include "ui_opsastrometryindexfiles.h"
#include "QNetworkAccessManager"
+#include "kauth.h"
+
class KConfigDialog;
diff --git a/org.kde.kf5auth.kstars.actions b/org.kde.kf5auth.kstars.actions
new file mode 100644
index 0000000..6b12fa3
--- /dev/null
+++ b/org.kde.kf5auth.kstars.actions
@@ -0,0 +1,11 @@
+[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