Kstars

fileutilitycameradatadialog.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Joseph McGee <joseph.mcgee@sbcglobal.net>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include <QLoggingCategory>
8#include <QDir>
9#include <QFile>
10#include "fileutilitycameradata.h"
11#include "./ui_fileutilitycameradatadialog.h"
12#include <ekos_capture_debug.h>
13
14FileUtilityCameraDataDialog::FileUtilityCameraDataDialog(
15 QWidget *parent,
16 const QString &aPreferredCameraId) :
17 QDialog(parent),
18 aPreferredCameraId(aPreferredCameraId),
19 ui(new Ui::FileUtilityCameraDataDialog)
20{
21 ui->setupUi(this);
22
23 OptimalExposure::FileUtilityCameraData::downloadRepositoryCameraDataFileList(this);
24
25 connect(ui->downloadB, &QPushButton::clicked, this, &FileUtilityCameraDataDialog::startCameraDownload);
26
27 // ui->buttonBox->
28 // ui->buttonBox->Cancel
29
30 ui->availableRemoteCameraList->clear();
31 ui->availableRemoteCameraList->setSelectionMode(QAbstractItemView::ExtendedSelection);
32
33}
34
35FileUtilityCameraDataDialog::~FileUtilityCameraDataDialog()
36{
37 delete ui;
38}
39
40void FileUtilityCameraDataDialog::refreshCameraList()
41{
42 // ui needs a list of remote files that can be selected
43 // This setup depends upon the downloadRepositoryCameraDataFileList
44
45 ui->availableRemoteCameraList->clear();
46 ui->availableRemoteCameraList->setSelectionMode(QAbstractItemView::ExtendedSelection);
47
48 // This probably needs to move to a method called when downloadRepositoryCameraDataFileList has completed
49 QVector<QString> availableCameraDataFiles = getAvailableCameraDataFiles();
50 foreach(QString availableCameraFile, availableCameraDataFiles)
51 {
52 // Make the camera list user friendly... to match the camera device id
53 QString availableCameraId = OptimalExposure::FileUtilityCameraData::cameraDataFileNameToCameraId(availableCameraFile);
54
55 ui->availableRemoteCameraList->addItem(availableCameraId);
56 }
57
58 // Pre-select the value for aPreferredCameraId, (which should be the active camera device id)
59 QList<QListWidgetItem *> items = ui->availableRemoteCameraList->findItems(aPreferredCameraId, Qt::MatchExactly);
60 if (items.size() > 0)
61 {
62 items[0]->setSelected(true);
63 }
64}
65
66
67void FileUtilityCameraDataDialog::startCameraDownload()
68{
69
70
71 QList<QListWidgetItem *> selectedItems = ui->availableRemoteCameraList->selectedItems();
72 if (selectedItems.size() > 0)
73 {
74 this->setDownloadFileCounter(selectedItems.size());
75 // qCInfo(KSTARS_EKOS_CAPTURE) << "Selected Cameras " << selectedItems.size();
76 foreach(QListWidgetItem *aSelectedCameraItem, selectedItems)
77 {
79 // qCInfo(KSTARS_EKOS_CAPTURE) << "attempt Download of " << aSelectedCameraId;
80 OptimalExposure::FileUtilityCameraData::downloadCameraDataFile(aSelectedCameraId, this);
81 }
82 }
83}
84
85int FileUtilityCameraDataDialog::getDownloadFileCounter() const
86{
87 return downloadFileCounter;
88}
89
90void FileUtilityCameraDataDialog::setDownloadFileCounter(int newDownloadFileCounter)
91{
92 downloadFileCounter = newDownloadFileCounter;
93 ui->counter->text() = QString::number(downloadFileCounter);
94 qCInfo(KSTARS_EKOS_CAPTURE) << "Camera Data download file counter set "
95 << QString::number(downloadFileCounter);
96}
97
98void FileUtilityCameraDataDialog::decrementDownloadFileCounter()
99{
100 downloadFileCounter--;
101 ui->counter->text() = QString::number(downloadFileCounter);
102 qCInfo(KSTARS_EKOS_CAPTURE) << "Camera Data download file counter decremented "
103 << QString::number(downloadFileCounter);
104 if(downloadFileCounter == 0)
105 {
106 // downloads should have completed, dialog can close
107 // FileUtilityCameraDataDialog::delay(1);
108 qCInfo(KSTARS_EKOS_CAPTURE) << "Camera Data download file counter reach 0. Forcing dialog to close.";
110 }
111}
112
113void FileUtilityCameraDataDialog::setAvailableCameraDataFiles(QVector<QString> newAvailableCameraDataFiles)
114{
115 availableCameraDataFiles = newAvailableCameraDataFiles;
116}
117
118
119QVector<QString> FileUtilityCameraDataDialog::getAvailableCameraDataFiles()
120{
121 return availableCameraDataFiles;
122}
123
124QNetworkRequest *FileUtilityCameraDataDialog::getRequest() const
125{
126 return request;
127}
128
129void FileUtilityCameraDataDialog::setRequest(QNetworkRequest *newRequest)
130{
131 request = newRequest;
132}
133
134QNetworkReply *FileUtilityCameraDataDialog::getReply() const
135{
136 return reply;
137}
138
139void FileUtilityCameraDataDialog::setReply(QNetworkReply *newResponse)
140{
141 reply = newResponse;
142}
143
144QNetworkAccessManager *FileUtilityCameraDataDialog::getANetworkAccessManager() const
145{
146 return aNetworkAccessManager;
147}
148
149void FileUtilityCameraDataDialog::setANetworkAccessManager(QNetworkAccessManager *newANetworkAccessManager)
150{
151 aNetworkAccessManager = newANetworkAccessManager;
152}
153
void clicked(bool checked)
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
QString number(double n, char format, int precision)
QueuedConnection
MatchExactly
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:25 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.