Files
ProjektManagerC-BA/src/createupdaterdialog.cpp
Your Name 34a45a570e v1.13.4
2024-04-03 19:43:42 +02:00

180 lines
6.9 KiB
C++

#include "createupdaterdialog.h"
#include "mainsettingsdialog.h"
#include "ui_createupdaterdialog.h"
CreateUpdaterDialog::CreateUpdaterDialog(ProjektData *data, QWidget *parent)
: QDialog(parent)
, ui(new Ui::CreateUpdaterDialog)
, data(data)
{
qDebug() << " CreateUpdaterDialog()";
ui->setupUi(this);
ui->lineEditVersion->setText(data->getAppVersion());
ui->checkBox_githochladen->setChecked(data->shouldSetRemoteRepo());
ui->checkBox_githochladen->setEnabled(data->shouldSetRemoteRepo());
ui->checkBox_CommitAndPushUpdaterRepo->setChecked(data->shouldSetRemoteRepo());
ui->checkBox_CommitAndPushUpdaterRepo->setEnabled(data->shouldSetRemoteRepo());
ui->lineEditCommitMessage->setText("v" + data->getAppVersion());
}
CreateUpdaterDialog::~CreateUpdaterDialog()
{
delete ui;
qDebug() << " ~CreateUpdaterDialog()";
}
ThreadData CreateUpdaterDialog::values()
{
QString newVersion = ui->lineEditVersion->text();
bool copyRelease = ui->checkBoxCopyRelease->isChecked();
bool cleanUpProject = ui->checkBox_cleanprojekt->isChecked();
bool offline_installer = ui->checkBox->isChecked();
bool online_installer = ui->checkBox_2->isChecked();
bool add_git_tag = ui->checkBoxAddGitTag->isChecked();
bool update_updater_repo = ui->checkBox_6->isChecked();
bool commit_nad_push_u_repo = ui->checkBox_CommitAndPushUpdaterRepo->isChecked();
bool groupBoxGit = ui->groupBox_GIT->isChecked();
bool gitAddAll = ui->checkBox_addAll->isChecked();
bool gitHochladen = ui->checkBox_githochladen->isChecked();
QString commitMessage = ui->lineEditCommitMessage->text();
bool repoUpdate = ui->groupBoxRepoUpdate->isChecked();
bool updateVersionInFile = ui->checkBox_UpdateVersionInFile->isChecked();
bool updater = this->ui->updater->isChecked();
if(!updater) {
offline_installer = false;
online_installer = false;
copyRelease = false;
}
if(!repoUpdate) {
update_updater_repo = false;
commit_nad_push_u_repo = false;
}
return ThreadData(newVersion, copyRelease, cleanUpProject, offline_installer,
online_installer, add_git_tag, update_updater_repo,
commit_nad_push_u_repo, updater, groupBoxGit, gitAddAll,
gitHochladen, commitMessage, repoUpdate, updateVersionInFile);
}
ThreadData::ThreadData()
{
}
ThreadData::ThreadData(QString newVersion, bool copyRelease,
bool cleanUpProject, bool offline_installer,
bool online_installer, bool add_git_tag,
bool update_updater_repo, bool commit_nad_push_u_repo, bool updater, bool groupBoxGit, bool gitAddAll,
bool gitHochladen, QString commitMessage, bool repoUpdate, bool updateVersionInFile)
: newVersion(std::move(newVersion)), commitMessage(commitMessage),
copyRelease(copyRelease), cleanUpProject(cleanUpProject),
offline_installer(offline_installer), online_installer(online_installer),
add_git_tag(add_git_tag),
update_updater_repo(update_updater_repo),
commit_nad_push_u_repo(commit_nad_push_u_repo),
updater(updater),
groupBoxGit(groupBoxGit),
gitAddAll(gitAddAll),
gitHochladen(gitHochladen),
repoUpdate(repoUpdate),
updateVersionInFile(updateVersionInFile)
{
}
void ThreadData::appendToStoredTimes(int time)
{
QString path = MainSettingsDialog::appDataLocal() + "tasktimeslist.qt" ;
this->elapsedtime = time;
QList<ThreadData> keysToStore = getThreadDataListHistory();
keysToStore.append(*this);
// Store the list of structs to a file
QFile file(path);
if (file.open(QIODevice::WriteOnly)) {
QDataStream out(&file);
out << keysToStore;
file.close();
qDebug() << "List of structs stored successfully.";
} else {
qWarning() << "Failed to open file for writing.";
}
}
QList<ThreadData> ThreadData::getThreadDataListHistory()
{
QString path = MainSettingsDialog::appDataLocal() + "tasktimeslist.qt" ;
// Load the list of structs from the file
QList<ThreadData> loadedKeys;
QFile file(path);
if (file.open(QIODevice::ReadOnly)) {
QDataStream in(&file);
in >> loadedKeys;
file.close();
} else {
qWarning() << "Failed to open file for reading.";
}
return loadedKeys;
}
unsigned ThreadData::getAvgElapsedTimePrediction()
{
QString path = MainSettingsDialog::appDataLocal() + "tasktimeslist.qt" ;
QList<ThreadData> keysToStore = getThreadDataListHistory();
int time = 0;
int count = 0;
for(const auto & key : keysToStore) {
if(this->sameKey(key)) {
time += key.elapsedtime;
count++;
}
}
if(count) {
qDebug() << " summed time: " << time << " entries: " << count << " avg: " << time / count;
return time / count;
} else {
qDebug() << " no saved time for this task!";
}
/*create or update task ? -> fast! : slow*/
return this->newVersion.isEmpty() ? 10 : 400;
}
bool ThreadData::sameKey(const ThreadData &other) const
{
// Compare all values except for key.elapsedtime
bool same = (copyRelease == other.copyRelease &&
cleanUpProject == other.cleanUpProject &&
offline_installer == other.offline_installer &&
online_installer == other.online_installer &&
add_git_tag == other.add_git_tag &&
update_updater_repo == other.update_updater_repo &&
updateVersionInFile == other.updateVersionInFile &&
commit_nad_push_u_repo == other.commit_nad_push_u_repo &&
gitAddAll == other.gitAddAll &&
gitHochladen == other.gitHochladen);
// qDebug() << "Keys are" << (same ? "the same." : "different: copyRelease:" + QString::number(copyRelease) + "-" + QString::number(other.copyRelease) + " cleanUpProject:" + QString::number(cleanUpProject) + "-" + QString::number(other.cleanUpProject) + " offline_installer:" + QString::number(offline_installer) + "-" + QString::number(other.offline_installer) + " online_installer:" + QString::number(online_installer) + "-" + QString::number(other.online_installer) + " add_git_tag:" + QString::number(add_git_tag) + "-" + QString::number(other.add_git_tag) + " update_updater_repo:" + QString::number(update_updater_repo) + "-" + QString::number(other.update_updater_repo) + " updateVersionInFile:" + QString::number(updateVersionInFile) + "-" + QString::number(other.updateVersionInFile) + " commit_nad_push_u_repo:" + QString::number(commit_nad_push_u_repo) + "-" + QString::number(other.commit_nad_push_u_repo) + " gitAddAll:" + QString::number(gitAddAll) + "-" + QString::number(other.gitAddAll) + " gitHochladen:" + QString::number(gitHochladen) + "-" + QString::number(other.gitHochladen));
return same;
}
void CreateUpdaterDialog::on_lineEditVersion_textChanged(const QString &arg1)
{
ui->lineEditCommitMessage->setText("v" + arg1);
}