Kstars

downloadhelper.cpp
1 #include "downloadhelper.h"
2 
3 ActionReply DownloadHelper::saveindexfile(const QVariantMap &args)
4 {
5  ActionReply reply;
6  QString filename = args["filename"].toString();
7  QFile file(filename);
8 
9  if (!file.open(QIODevice::WriteOnly))
10  {
11  reply = ActionReply::HelperErrorReply();
12  reply.setErrorDescription(file.errorString());
13  return reply;
14  }
15 
16  QByteArray array = args["contents"].toByteArray();
17 
18  file.write(array.data(), array.size());
19  file.close();
20 
21  return reply;
22 }
23 
24 ActionReply DownloadHelper::removeindexfileset(const QVariantMap &args)
25 {
26  ActionReply reply;
27  QString indexSetName = args["indexSetName"].toString();
28  QString astrometryDataDir = args["astrometryDataDir"].toString();
29 
30  QStringList nameFilter("*.fits");
31  QDir directory(astrometryDataDir);
32  QStringList indexList = directory.entryList(nameFilter);
33  for (auto& fileName : indexList)
34  {
35  if (fileName.contains(indexSetName.left(10)))
36  {
37  if (!directory.remove(fileName))
38  {
39  reply = ActionReply::HelperErrorReply();
40  reply.setErrorDescription("File did not delete");
41  return reply;
42  }
43  }
44  }
45 
46  return reply;
47 }
48 
49 KAUTH_HELPER_MAIN("org.kde.kf5auth.kstars", DownloadHelper);
void setErrorDescription(const QString &error)
QString left(int n) const const
int size() const const
char * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.