Dialog cleanup (#156)

* Cleaner: CreateOperation Dialog
* Cleaner: Credits Dialog
* Cleaner: EvidenceManager
* Cleaner: EvidenceFilterForm Dialog
* Cleaner: GetInfo Dialog
* Cleaner: Porting Dialog
* Cleaner: Settings Dialog

Co-authored-by: Chris Rizzitello <crizzitello@ics.com>
main
crizzitello 2022-05-02 14:20:42 -04:00 committed by GitHub
parent 688ba30b72
commit fe898a97a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 284 additions and 539 deletions

View File

@ -1,70 +1,52 @@
#include "createoperation.h"
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QNetworkReply>
#include <QRegularExpression>
#include "appsettings.h"
#include "dtos/ashirt_error.h"
#include "components/loading_button/loadingbutton.h"
#include "helpers/netman.h"
#include "helpers/stopreply.h"
#include "dtos/ashirt_error.h"
#include "appsettings.h"
CreateOperation::CreateOperation(QWidget* parent)
: AShirtDialog(parent, AShirtDialog::commonWindowFlags)
, submitButton(new LoadingButton(tr("Submit"), this))
, responseLabel(new QLabel(this))
, operationNameTextBox(new QLineEdit(this))
{
buildUi();
wireUi();
submitButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(submitButton, &QPushButton::clicked, this, &CreateOperation::submitButtonClicked);
// Layout
/* 0 1 2
+---------------+-------------+------------+
0 | Op Lbl | [Operation TB] |
+---------------+-------------+------------+
1 | Error Lbl |
+---------------+-------------+------------+
2 | <None> | <None> | Submit Btn |
+---------------+-------------+------------+
*/
auto gridLayout = new QGridLayout(this);
gridLayout->addWidget(new QLabel(tr("Operation Name"), this), 0, 0);
gridLayout->addWidget(operationNameTextBox, 0, 1, 1, 2);
gridLayout->addWidget(responseLabel, 1, 0, 1, 3);
gridLayout->addWidget(submitButton, 2, 2);
setLayout(gridLayout);
resize(400, 1);
setWindowTitle(tr("Create Operation"));
}
CreateOperation::~CreateOperation() {
delete submitButton;
delete _operationLabel;
delete responseLabel;
delete operationNameTextBox;
delete gridLayout;
stopReply(&createOpReply);
}
void CreateOperation::buildUi() {
gridLayout = new QGridLayout(this);
submitButton = new LoadingButton(tr("Submit"), this);
submitButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
_operationLabel = new QLabel(tr("Operation Name"), this);
_operationLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
responseLabel = new QLabel(this);
operationNameTextBox = new QLineEdit(this);
// Layout
/* 0 1 2
+---------------+-------------+------------+
0 | Op Lbl | [Operation TB] |
+---------------+-------------+------------+
1 | Error Lbl |
+---------------+-------------+------------+
2 | <None> | <None> | Submit Btn |
+---------------+-------------+------------+
*/
// row 0
gridLayout->addWidget(_operationLabel, 0, 0);
gridLayout->addWidget(operationNameTextBox, 0, 1, 1, 2);
// row 1
gridLayout->addWidget(responseLabel, 1, 0, 1, 3);
// row 2
gridLayout->addWidget(submitButton, 2, 2);
this->setLayout(gridLayout);
this->resize(400, 1);
this->setWindowTitle(tr("Create Operation"));
}
void CreateOperation::wireUi() {
connect(submitButton, &QPushButton::clicked, this, &CreateOperation::submitButtonClicked);
}
void CreateOperation::submitButtonClicked() {
responseLabel->clear();
auto name = operationNameTextBox->text().trimmed();
@ -99,7 +81,7 @@ void CreateOperation::onRequestComplete() {
dto::Operation op = dto::Operation::parseData(data);
AppSettings::getInstance().setOperationDetails(op.slug, op.name);
operationNameTextBox->clear();
this->close();
close();
}
else {
dto::AShirtError err = dto::AShirtError::parseData(data);

View File

@ -2,12 +2,10 @@
#include "ashirtdialog/ashirtdialog.h"
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QNetworkReply>
#include "components/loading_button/loadingbutton.h"
class QLabel;
class QLineEdit;
class QNetworkReply;
class LoadingButton;
class CreateOperation : public AShirtDialog {
Q_OBJECT
@ -17,26 +15,16 @@ class CreateOperation : public AShirtDialog {
~CreateOperation();
private:
void buildUi();
void wireUi();
void submitButtonClicked();
private slots:
void onRequestComplete();
QString makeSlugFromName(QString name);
// void showEvent(QShowEvent *evt) override;
private:
QNetworkReply* createOpReply = nullptr;
// ui elements
QGridLayout* gridLayout = nullptr;
LoadingButton* submitButton = nullptr;
QLabel* _operationLabel = nullptr;
QLabel* responseLabel = nullptr;
QLineEdit* operationNameTextBox = nullptr;
};

View File

@ -4,10 +4,13 @@
#include "credits.h"
#include <QDateTime>
#include <QKeySequence>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QLabel>
#include <QTextBrowser>
#include "helpers/netman.h"
#include "helpers/constants.h"
#include "helpers/netman.h"
struct Attribution {
std::string library;
@ -106,14 +109,14 @@ static std::string normalBodyMarkdown() {
}
Credits::Credits(QWidget* parent)
: AShirtDialog(parent, AShirtDialog::commonWindowFlags)
: AShirtDialog(parent, AShirtDialog::commonWindowFlags)
, updateLabel(new QLabel(this))
{
buildUi();
wireUi();
}
void Credits::updateRelease() {
static QString baseUpdateText = "A new update is available! Click <a href=\"%1\">here</a> for more details.";
if (updateDigest.hasUpgrade()) {
updateLabel->setText(baseUpdateText.arg(Constants::releasePageUrl()));
}
@ -123,21 +126,18 @@ void Credits::updateRelease() {
}
void Credits::buildUi() {
gridLayout = new QGridLayout(this);
updateLabel = new QLabel();
updateLabel->setOpenExternalLinks(true);
updateLabel->setTextFormat(Qt::RichText);
updateLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
creditsArea = new QTextBrowser(this);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::close);
auto creditsArea = new QTextBrowser(this);
creditsArea->setOpenExternalLinks(true);
creditsArea->setReadOnly(true);
creditsArea->setMarkdown(normalBodyMarkdown().c_str());
buttonBox = new QDialogButtonBox(this);
buttonBox->addButton(QDialogButtonBox::Close);
// Layout
/* 0
+------------------------------------+
@ -151,33 +151,20 @@ void Credits::buildUi() {
+------------------------------------+
*/
// row 0
auto gridLayout = new QGridLayout(this);
gridLayout->addWidget(updateLabel, 0, 0);
// row 1
gridLayout->addWidget(creditsArea, 1, 0);
// row 2
gridLayout->addWidget(buttonBox, 2, 0);
setLayout(gridLayout);
this->setLayout(gridLayout);
this->resize(640, 500);
this->setWindowTitle("About");
resize(450, 500);
setWindowTitle("About");
}
void Credits::wireUi() {
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::close);
connect(&NetMan::getInstance(), &NetMan::releasesChecked, this, &Credits::onReleasesUpdate);
}
Credits::~Credits() {
delete updateLabel;
delete creditsArea;
delete buttonBox;
delete gridLayout;
}
void Credits::onReleasesUpdate(bool success, std::vector<dto::GithubRelease> releases) {
if (!success) {
return; //doesn't matter if this fails

View File

@ -4,20 +4,16 @@
#pragma once
#include "ashirtdialog/ashirtdialog.h"
#include <QLabel>
#include <QTextBrowser>
#include <QDialogButtonBox>
#include <QGridLayout>
#include "dtos/github_release.h"
class QLabel;
class Credits : public AShirtDialog {
Q_OBJECT
public:
explicit Credits(QWidget *parent = nullptr);
~Credits();
~Credits() = default;
public slots:
void onReleasesUpdate(bool success, std::vector<dto::GithubRelease> releases);
@ -32,12 +28,7 @@ class Credits : public AShirtDialog {
void updateRelease();
private:
// UI Components
QGridLayout* gridLayout = nullptr;
QTextBrowser* creditsArea = nullptr;
QDialogButtonBox* buttonBox = nullptr;
QLabel* updateLabel = nullptr;
dto::ReleaseDigest updateDigest;
inline static const QString baseUpdateText = QStringLiteral("A new update is available! Click <a href=\"%1\">here</a> for more details.");
};

View File

@ -5,7 +5,6 @@
#include <QCheckBox>
#include <QHeaderView>
#include <QKeySequence>
#include <QMessageBox>
#include <QRandomGenerator>
#include <QStandardPaths>
@ -32,57 +31,35 @@ enum ColumnIndexes {
COL_ERROR_MSG
};
static QStringList columnNames() {
static QStringList names;
if (names.count() == 0) {
names.insert(COL_DATE_CAPTURED, QStringLiteral("Date Captured"));
names.insert(COL_OPERATION, QStringLiteral("Operation"));
names.insert(COL_PATH, QStringLiteral("Path"));
names.insert(COL_CONTENT_TYPE, QStringLiteral("Content Type"));
names.insert(COL_DESCRIPTION, QStringLiteral("Description"));
names.insert(COL_SUBMITTED, QStringLiteral("Submitted"));
names.insert(COL_DATE_SUBMITTED, QStringLiteral("Date Submitted"));
names.insert(COL_FAILED, QStringLiteral("Failed"));
names.insert(COL_ERROR_MSG, QStringLiteral("Error"));
}
return names;
}
EvidenceManager::EvidenceManager(DatabaseConnection* db, QWidget* parent)
: AShirtDialog(parent)
: AShirtDialog(parent)
, db(db)
, evidenceTable(new QTableWidget(this))
, filterForm(new EvidenceFilterForm(this))
, evidenceTableContextMenu(new QMenu(this))
, submitEvidenceAction(new QAction(tr("Submit Evidence"), evidenceTableContextMenu))
, copyPathToClipboardAction(new QAction(tr("Copy Path"), evidenceTableContextMenu))
, filterTextBox(new QLineEdit(this))
, editFiltersButton(new QPushButton(tr("Edit Filters"), this))
, applyFilterButton(new QPushButton(tr("Apply"), this))
, resetFilterButton(new QPushButton(tr("Reset"), this))
, editButton(new QPushButton(tr("Edit"), this))
, cancelEditButton(new QPushButton(tr("Cancel"), this))
, evidenceEditor(new EvidenceEditor(this->db, this))
, loadingAnimation(new QProgressIndicator(this))
{
this->db = db;
buildUi();
wireUi();
}
EvidenceManager::~EvidenceManager() {
delete submitEvidenceAction;
delete deleteEvidenceAction;
delete copyPathToClipboardAction;
delete deleteTableContentsAction;
delete evidenceTableContextMenu;
delete filterForm;
delete evidenceEditor;
delete editButton;
delete cancelEditButton;
delete editFiltersButton;
delete applyFilterButton;
delete resetFilterButton;
delete filterTextBox;
delete evidenceTable;
delete loadingAnimation;
delete gridLayout;
stopReply(&uploadAssetReply);
}
void EvidenceManager::buildEvidenceTableUi() {
evidenceTable = new QTableWidget(this);
evidenceTable->setContextMenuPolicy(Qt::CustomContextMenu);
QStringList colNames = columnNames();
evidenceTable->setColumnCount(colNames.length());
evidenceTable->setHorizontalHeaderLabels(colNames);
evidenceTable->setColumnCount(columnNames.length());
evidenceTable->setHorizontalHeaderLabels(columnNames);
evidenceTable->setSelectionMode(QAbstractItemView::SingleSelection);
evidenceTable->setSelectionBehavior(QAbstractItemView::SelectRows);
evidenceTable->setSortingEnabled(true);
@ -95,26 +72,13 @@ void EvidenceManager::buildEvidenceTableUi() {
}
void EvidenceManager::buildUi() {
gridLayout = new QGridLayout(this);
filterForm = new EvidenceFilterForm(this);
evidenceTableContextMenu = new QMenu(this);
submitEvidenceAction = new QAction(tr("Submit Evidence"), evidenceTableContextMenu);
evidenceTableContextMenu->addAction(submitEvidenceAction);
deleteEvidenceAction = new QAction(tr("Delete Evidence"), evidenceTableContextMenu);
evidenceTableContextMenu->addAction(deleteEvidenceAction);
copyPathToClipboardAction = new QAction(tr("Copy Path"), evidenceTableContextMenu);
evidenceTableContextMenu->addAction(tr("Delete Evidence"), this, &EvidenceManager::deleteEvidenceTriggered);
evidenceTableContextMenu->addAction(copyPathToClipboardAction);
evidenceTableContextMenu->addSeparator();
deleteTableContentsAction = new QAction(tr("Delete All from table"), evidenceTableContextMenu);
evidenceTableContextMenu->addAction(deleteTableContentsAction);
evidenceTableContextMenu->addAction(tr("Delete All from table"), this , &EvidenceManager::deleteAllTriggered);
filterTextBox = new QLineEdit(this);
editFiltersButton = new QPushButton(tr("Edit Filters"), this);
applyFilterButton = new QPushButton(tr("Apply"), this);
resetFilterButton = new QPushButton(tr("Reset"), this);
editButton = new QPushButton(tr("Edit"), this);
cancelEditButton = new QPushButton(tr("Cancel"), this);
cancelEditButton->setVisible(false);
// remove button defaults (i.e. enter-submits-form functionality)
@ -129,12 +93,8 @@ void EvidenceManager::buildUi() {
buildEvidenceTableUi();
evidenceEditor = new EvidenceEditor(db, this);
evidenceEditor->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
loadingAnimation = new QProgressIndicator(this);
spacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
setTabOrder(editFiltersButton, filterTextBox);
setTabOrder(filterTextBox, applyFilterButton);
setTabOrder(applyFilterButton, resetFilterButton);
@ -157,28 +117,26 @@ void EvidenceManager::buildUi() {
+---------------+-------------+------------+-------------+
*/
// row 0
auto gridLayout = new QGridLayout(this);
gridLayout->addWidget(editFiltersButton, 0, 0);
gridLayout->addWidget(filterTextBox, 0, 1);
gridLayout->addWidget(applyFilterButton, 0, 2);
gridLayout->addWidget(resetFilterButton, 0, 3);
// row 1
gridLayout->addWidget(evidenceTable, 1, 0, 1, gridLayout->columnCount());
// row 2
gridLayout->addWidget(evidenceEditor, 2, 0, 1, gridLayout->columnCount());
// row 3
gridLayout->addWidget(loadingAnimation, 3, 0);
gridLayout->addItem(spacer, 3, 1);
gridLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum), 3, 1);
gridLayout->addWidget(cancelEditButton, 3, 2);
gridLayout->addWidget(editButton, 3, 3);
setLayout(gridLayout);
this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
this->resize(800, 600);
this->setWindowTitle(tr("Evidence Manager"));
this->setLayout(gridLayout);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
resize(800, 600);
setWindowTitle(tr("Evidence Manager"));
}
void EvidenceManager::wireUi() {
@ -193,9 +151,7 @@ void EvidenceManager::wireUi() {
connect(cancelEditButton, btnClicked, this, &EvidenceManager::cancelEditEvidenceButtonClicked);
connect(submitEvidenceAction, actionTriggered, this, &EvidenceManager::submitEvidenceTriggered);
connect(deleteEvidenceAction, actionTriggered, this, &EvidenceManager::deleteEvidenceTriggered);
connect(copyPathToClipboardAction, actionTriggered, this, &EvidenceManager::copyPathTriggered);
connect(deleteTableContentsAction, actionTriggered, this, &EvidenceManager::deleteAllTriggered);
connect(filterForm, &EvidenceFilterForm::evidenceSet, this, &EvidenceManager::applyFilterForm);
@ -358,7 +314,6 @@ void EvidenceManager::openTableContextMenu(QPoint pos) {
copyPathToClipboardAction->setEnabled(singleItemSelected);
bool wasSubmitted = !evidenceEditor->encodeEvidence().uploadDate.isNull();
submitEvidenceAction->setEnabled(singleItemSelected && !wasSubmitted);
evidenceTableContextMenu->popup(evidenceTable->viewport()->mapToGlobal(pos));
}

View File

@ -17,6 +17,7 @@
#include "db/databaseconnection.h"
#include "forms/evidence_filter/evidencefilterform.h"
//class
/// EvidenceRow contains the necessary data for a full row in the evidence table.
/// QTableWidget should memory-manage this data.
struct EvidenceRow {
@ -93,9 +94,9 @@ class EvidenceManager : public AShirtDialog {
/// After saving, the edit/cancel button is reset. Note: this will change the name of the button to "Save"
void editEvidenceButtonClicked();
/// cancelEditEvidenceButtonClicked resets the edit/cancel buttons
/// cancelEditEvidenceButtonClicked resets the edit/cancel buttons
void cancelEditEvidenceButtonClicked();
/// deleteSet is a small helper to iterate through the provided list, delete the ids, and process
/// the result
void deleteSet(std::vector<qint64> ids);
@ -126,12 +127,10 @@ class EvidenceManager : public AShirtDialog {
QMenu* evidenceTableContextMenu = nullptr;
QAction* submitEvidenceAction = nullptr;
QAction* deleteEvidenceAction = nullptr;
QAction* copyPathToClipboardAction = nullptr;
QAction* deleteTableContentsAction = nullptr;
// UI Elements
QGridLayout* gridLayout = nullptr;
QPushButton* editFiltersButton = nullptr;
QPushButton* applyFilterButton = nullptr;
QPushButton* resetFilterButton = nullptr;
@ -141,5 +140,15 @@ class EvidenceManager : public AShirtDialog {
QTableWidget* evidenceTable = nullptr;
EvidenceEditor* evidenceEditor = nullptr;
QProgressIndicator* loadingAnimation = nullptr;
QSpacerItem* spacer = nullptr;
inline static const QStringList columnNames {
QStringLiteral("Date Captured")
, QStringLiteral("Operation")
, QStringLiteral("Path")
, QStringLiteral("Content Type")
, QStringLiteral("Description")
, QStringLiteral("Submitted")
, QStringLiteral("Date Submitted")
, QStringLiteral("Failed")
, QStringLiteral("Error")
};
};

View File

@ -3,93 +3,74 @@
#include "evidencefilterform.h"
#include <QKeySequence>
#include <QComboBox>
#include <QCheckBox>
#include <QDateEdit>
#include <QDialogButtonBox>
#include <QLabel>
#include "appsettings.h"
#include "helpers/netman.h"
#include "helpers/ui_helpers.h"
static void initializeTriCombobox(QComboBox *box) {
box->clear();
box->addItem(QT_TRANSLATE_NOOP("EvidenceFilter", "Any"));
box->addItem(QT_TRANSLATE_NOOP("EvidenceFilter", "Yes"));
box->addItem(QT_TRANSLATE_NOOP("EvidenceFilter", "No"));
void EvidenceFilterForm::initializeTriCombobox(QComboBox *box) {
box->clear();
box->addItem(tr("Any"));
box->addItem(tr("Yes"));
box->addItem(tr("No"));
}
static void initializeDateEdit(QDateEdit *dateEdit) {
void EvidenceFilterForm::initializeDateEdit(QDateEdit *dateEdit) {
dateEdit->setDate(QDateTime::currentDateTime().date());
dateEdit->setDisplayFormat(QStringLiteral("MMM dd, yyyy"));
dateEdit->setDateRange(QDate(2000, 01, 01), QDateTime::currentDateTime().date());
dateEdit->setEnabled(false);
}
void EvidenceFilterForm::dateNormalize(bool isCondition)
{
// swap dates so smaller date is always "from" / after
if (isCondition && fromDateEdit->date() > toDateEdit->date()) {
auto copy = fromDateEdit->date();
fromDateEdit->setDate(toDateEdit->date());
toDateEdit->setDate(copy);
}
}
EvidenceFilterForm::EvidenceFilterForm(QWidget *parent)
: AShirtDialog(parent) {
: AShirtDialog(parent)
, operationComboBox(new QComboBox(this))
, submittedComboBox(new QComboBox(this))
, erroredComboBox(new QComboBox(this))
, contentTypeComboBox(new QComboBox(this))
, fromDateEdit(new QDateEdit(this))
, toDateEdit(new QDateEdit(this))
, includeStartDateCheckBox(new QCheckBox(tr("From Date"), this))
, includeEndDateCheckBox(new QCheckBox(tr("To Date"), this))
, buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok, this))
{
buildUi();
wireUi();
}
EvidenceFilterForm::~EvidenceFilterForm() {
delete _operationLabel;
delete _contentTypeLabel;
delete _hadErrorLabel;
delete _wasSubmittedLabel;
delete _fromDateLabel;
delete _toDateLabel;
delete operationComboBox;
delete submittedComboBox;
delete erroredComboBox;
delete contentTypeComboBox;
delete fromDateEdit;
delete toDateEdit;
delete includeEndDateCheckBox;
delete includeStartDateCheckBox;
delete buttonBox;
delete gridLayout;
}
void EvidenceFilterForm::buildUi() {
gridLayout = new QGridLayout(this);
_operationLabel = new QLabel(tr("Operation"), this);
_contentTypeLabel = new QLabel(tr("Content Type"), this);
_hadErrorLabel = new QLabel(tr("Had Error"), this);
_wasSubmittedLabel = new QLabel(tr("Was Submitted"), this);
_fromDateLabel = new QLabel(tr("From Date"), this);
_toDateLabel = new QLabel(tr("To Date"), this);
operationComboBox = new QComboBox(this);
erroredComboBox->setEditable(false);
operationComboBox->setEditable(false);
operationComboBox->setEnabled(false);
operationComboBox->addItem(tr("Loading..."), QVariant());
operationComboBox->addItem(tr("Loading..."));
submittedComboBox = new QComboBox(this);
submittedComboBox->setEditable(false);
initializeTriCombobox(submittedComboBox);
erroredComboBox = new QComboBox(this);
erroredComboBox->setEditable(false);
initializeTriCombobox(erroredComboBox);
contentTypeComboBox = new QComboBox(this);
contentTypeComboBox->setEditable(false);
contentTypeComboBox->addItem(tr("<None>"), QVariant());
contentTypeComboBox->addItem(tr("<None>"));
contentTypeComboBox->addItem(tr("Image"), QStringLiteral("image"));
contentTypeComboBox->addItem(tr("Codeblock"), QStringLiteral("codeblock"));
fromDateEdit = new QDateEdit(this);
initializeDateEdit(fromDateEdit);
toDateEdit = new QDateEdit(this);
initializeDateEdit(toDateEdit);
includeEndDateCheckBox = new QCheckBox(tr("Include"), this);
includeStartDateCheckBox = new QCheckBox(tr("Include"), this);
buttonBox = new QDialogButtonBox(this);
buttonBox->addButton(QDialogButtonBox::Ok);
// Layout
/* 0 1 2
+---------------+-------------+--------------+
@ -109,38 +90,30 @@ void EvidenceFilterForm::buildUi() {
+---------------+-------------+--------------+
*/
// row 0
gridLayout->addWidget(_operationLabel, 0, 0);
auto gridLayout = new QGridLayout(this);
gridLayout->addWidget(new QLabel(tr("Operation"), this), 0, 0);
gridLayout->addWidget(operationComboBox, 0, 1, 1, 2);
// row 1
gridLayout->addWidget(_contentTypeLabel, 1, 0);
gridLayout->addWidget(new QLabel(tr("Content Type"), this), 1, 0);
gridLayout->addWidget(contentTypeComboBox, 1, 1, 1, 2);
// row 2
gridLayout->addWidget(_hadErrorLabel, 2, 0);
gridLayout->addWidget(new QLabel(tr("Had Error"), this), 2, 0);
gridLayout->addWidget(erroredComboBox, 2, 1, 1, 2);
// row 3
gridLayout->addWidget(_wasSubmittedLabel, 3, 0);
gridLayout->addWidget(new QLabel(tr("Was Submitted"), this), 3, 0);
gridLayout->addWidget(submittedComboBox, 3, 1, 1, 2);
// row 4
gridLayout->addWidget(_fromDateLabel, 4, 0);
gridLayout->addWidget(fromDateEdit, 4, 1);
gridLayout->addWidget(includeStartDateCheckBox, 4, 2);
gridLayout->addWidget(includeStartDateCheckBox, 4, 0, Qt::AlignLeft);
gridLayout->addWidget(fromDateEdit, 4, 1, 1, 2);
// row 5
gridLayout->addWidget(_toDateLabel, 5, 0);
gridLayout->addWidget(toDateEdit, 5, 1);
gridLayout->addWidget(includeEndDateCheckBox, 5, 2);
gridLayout->addWidget(includeEndDateCheckBox, 5, 0, Qt::AlignLeft);
gridLayout->addWidget(toDateEdit, 5, 1, 1, 2);
// row 6
gridLayout->addWidget(buttonBox, 6, 0, 1, gridLayout->columnCount());
this->setLayout(gridLayout);
this->setWindowTitle(tr("Evidence Filters"));
this->resize(320, 245);
setLayout(gridLayout);
setWindowTitle(tr("Evidence Filters"));
resize(320, 245);
}
void EvidenceFilterForm::wireUi() {
@ -153,10 +126,8 @@ void EvidenceFilterForm::wireUi() {
&EvidenceFilterForm::onOperationListUpdated);
connect(buttonBox, &QDialogButtonBox::accepted, this, &EvidenceFilterForm::writeAndClose);
connect(includeStartDateCheckBox, &QCheckBox::stateChanged, this,
[this](bool checked) { fromDateEdit->setEnabled(checked); });
connect(includeEndDateCheckBox, &QCheckBox::stateChanged, this,
[this](bool checked) { toDateEdit->setEnabled(checked); });
connect(includeStartDateCheckBox, &QCheckBox::stateChanged, fromDateEdit, &QDateEdit::setEnabled);
connect(includeEndDateCheckBox, &QCheckBox::stateChanged, toDateEdit, &QDateEdit::setEnabled);
}
void EvidenceFilterForm::writeAndClose() {
@ -177,13 +148,7 @@ EvidenceFilters EvidenceFilterForm::encodeForm() {
filter.operationSlug = operationComboBox->currentData().toString();
filter.contentType = contentTypeComboBox->currentData().toString();
// swap dates so smaller date is always "from" / after
if (fromDateEdit->isEnabled() && toDateEdit->isEnabled() &&
fromDateEdit->date() > toDateEdit->date()) {
auto copy = fromDateEdit->date();
fromDateEdit->setDate(toDateEdit->date());
toDateEdit->setDate(copy);
}
dateNormalize(fromDateEdit->isEnabled() && toDateEdit->isEnabled());
if (includeStartDateCheckBox->isChecked()) {
filter.startDate = fromDateEdit->date();
@ -209,13 +174,7 @@ void EvidenceFilterForm::setForm(const EvidenceFilters &model) {
toDateEdit->setDate(model.endDate.isValid() ? model.endDate
: QDateTime::currentDateTime().date());
// swap dates so smaller date is always "from" / after
if (model.startDate.isValid() && model.endDate.isValid() &&
fromDateEdit->date() > toDateEdit->date()) {
auto copy = fromDateEdit->date();
fromDateEdit->setDate(toDateEdit->date());
toDateEdit->setDate(copy);
}
dateNormalize(model.startDate.isValid() && model.endDate.isValid());
}
void EvidenceFilterForm::onOperationListUpdated(bool success,
@ -228,7 +187,7 @@ void EvidenceFilterForm::onOperationListUpdated(bool success,
}
operationComboBox->clear();
operationComboBox->addItem(tr("<None>"), QVariant());
operationComboBox->addItem(tr("<None>"));
for (const auto &op : operations) {
operationComboBox->addItem(op.name, op.slug);
}

View File

@ -5,22 +5,21 @@
#include "ashirtdialog/ashirtdialog.h"
#include <QGridLayout>
#include <QLabel>
#include <QComboBox>
#include <QDateEdit>
#include <QCheckBox>
#include <QDialogButtonBox>
#include "db/databaseconnection.h"
#include "dtos/operation.h"
#include "evidencefilter.h"
class QComboBox;
class QLabel;
class QDateEdit;
class QCheckBox;
class QDialogButtonBox;
class EvidenceFilterForm : public AShirtDialog {
Q_OBJECT
public:
explicit EvidenceFilterForm(QWidget *parent = nullptr);
~EvidenceFilterForm();
~EvidenceFilterForm() = default;
private:
/// buildUi creates the window structure.
@ -49,14 +48,6 @@ class EvidenceFilterForm : public AShirtDialog {
private:
// UI Components
QGridLayout* gridLayout = nullptr;
QLabel* _operationLabel = nullptr;
QLabel* _contentTypeLabel = nullptr;
QLabel* _hadErrorLabel = nullptr;
QLabel* _wasSubmittedLabel = nullptr;
QLabel* _fromDateLabel = nullptr;
QLabel* _toDateLabel = nullptr;
QComboBox* operationComboBox = nullptr;
QComboBox* submittedComboBox = nullptr;
QComboBox* erroredComboBox = nullptr;
@ -66,4 +57,7 @@ class EvidenceFilterForm : public AShirtDialog {
QCheckBox* includeEndDateCheckBox = nullptr;
QCheckBox* includeStartDateCheckBox = nullptr;
QDialogButtonBox* buttonBox = nullptr;
void initializeTriCombobox(QComboBox *box);
void initializeDateEdit(QDateEdit *dateEdit);
void dateNormalize(bool isCondition = false);
};

View File

@ -3,11 +3,12 @@
#include "getinfo.h"
#include <QKeySequence>
#include <QMessageBox>
#include "appsettings.h"
#include "components/evidence_editor/evidenceeditor.h"
#include "components/loading_button/loadingbutton.h"
#include "db/databaseconnection.h"
#include "helpers/netman.h"
#include "helpers/stopreply.h"
#include "helpers/ui_helpers.h"
@ -16,6 +17,8 @@ GetInfo::GetInfo(DatabaseConnection* db, qint64 evidenceID, QWidget* parent)
: AShirtDialog(parent, AShirtDialog::commonWindowFlags)
, db(db)
, evidenceID(evidenceID)
, submitButton(new LoadingButton(tr("Submit"), this))
, evidenceEditor(new EvidenceEditor(this->evidenceID, this->db, this))
{
buildUi();
wireUi();
@ -23,24 +26,21 @@ GetInfo::GetInfo(DatabaseConnection* db, qint64 evidenceID, QWidget* parent)
GetInfo::~GetInfo() {
delete evidenceEditor;
delete submitButton;
delete deleteButton;
delete gridLayout;
stopReply(&uploadAssetReply);
}
void GetInfo::buildUi() {
gridLayout = new QGridLayout(this);
submitButton = new LoadingButton(tr("Submit"), this);
submitButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
submitButton->setAutoDefault(false);
deleteButton = new QPushButton(tr("Delete"), this);
connect(submitButton, &QPushButton::clicked, this, &GetInfo::submitButtonClicked);
connect(this, &GetInfo::setActionButtonsEnabled, submitButton, &QPushButton::setEnabled);
auto deleteButton = new QPushButton(tr("Delete"), this);
deleteButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
deleteButton->setAutoDefault(false);
connect(deleteButton, &QPushButton::clicked, this, &GetInfo::deleteButtonClicked);
connect(this, &GetInfo::setActionButtonsEnabled, deleteButton, &QPushButton::setEnabled);
evidenceEditor = new EvidenceEditor(evidenceID, db, this);
evidenceEditor->setEnabled(true);
// Layout
@ -53,25 +53,19 @@ void GetInfo::buildUi() {
1 | Delete Btn | <None> | Submit Btn |
+---------------+-------------+------------+
*/
// row 0
auto gridLayout = new QGridLayout(this);
gridLayout->addWidget(evidenceEditor, 0, 0, 1, 3);
// row 1
gridLayout->addWidget(deleteButton, 1, 0);
gridLayout->addWidget(submitButton, 1, 2);
setLayout(gridLayout);
this->setLayout(gridLayout);
this->setAttribute(Qt::WA_DeleteOnClose);
this->resize(720, 480);
this->setWindowTitle(tr("Add Evidence Details"));
setAttribute(Qt::WA_DeleteOnClose);
resize(720, 480);
setWindowTitle(tr("Add Evidence Details"));
setFocus(); // ensure focus is not on the submit button
}
void GetInfo::wireUi() {
connect(submitButton, &QPushButton::clicked, this, &GetInfo::submitButtonClicked);
connect(deleteButton, &QPushButton::clicked, this, &GetInfo::deleteButtonClicked);
}
void GetInfo::showEvent(QShowEvent* evt) {
@ -93,7 +87,7 @@ bool GetInfo::saveData() {
void GetInfo::submitButtonClicked() {
submitButton->startAnimation();
setActionButtonsEnabled(false);
Q_EMIT setActionButtonsEnabled(false);
if (saveData()) {
try {
model::Evidence evi = db->getEvidenceDetails(evidenceID);
@ -113,7 +107,7 @@ void GetInfo::deleteButtonClicked() {
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (reply == QMessageBox::Yes) {
setActionButtonsEnabled(false);
Q_EMIT setActionButtonsEnabled(false);
bool shouldClose = true;
model::Evidence evi = evidenceEditor->encodeEvidence();
@ -132,24 +126,19 @@ void GetInfo::deleteButtonClicked() {
<< e.text().toStdString() << std::endl;
}
setActionButtonsEnabled(true);
Q_EMIT setActionButtonsEnabled(true);
if (shouldClose) {
this->close();
close();
}
}
}
void GetInfo::setActionButtonsEnabled(bool enabled) {
submitButton->setEnabled(enabled);
deleteButton->setEnabled(enabled);
}
void GetInfo::onUploadComplete() {
if (uploadAssetReply->error() != QNetworkReply::NoError) {
auto errMessage =
tr("Unable to upload evidence: Network error (%1)").arg(uploadAssetReply->errorString());
try {
db->updateEvidenceError(errMessage, this->evidenceID);
db->updateEvidenceError(errMessage, evidenceID);
}
catch (QSqlError& e) {
std::cout << "Upload failed. Could not update internal database. Error: "
@ -163,9 +152,9 @@ void GetInfo::onUploadComplete() {
}
else {
try {
db->updateEvidenceSubmitted(this->evidenceID);
Q_EMIT evidenceSubmitted(db->getEvidenceDetails(this->evidenceID));
this->close();
db->updateEvidenceSubmitted(evidenceID);
Q_EMIT evidenceSubmitted(db->getEvidenceDetails(evidenceID));
close();
}
catch (QSqlError& e) {
std::cout << "Upload successful. Could not update internal database. Error: "
@ -175,6 +164,6 @@ void GetInfo::onUploadComplete() {
// we don't actually need anything from the uploadAssets reply, so just clean it up.
// one thing we might want to record: evidence uuid... not sure why we'd need it though.
submitButton->stopAnimation();
setActionButtonsEnabled(true);
Q_EMIT setActionButtonsEnabled(true);
tidyReply(&uploadAssetReply);
}

View File

@ -5,18 +5,11 @@
#include "ashirtdialog/ashirtdialog.h"
#include <QGridLayout>
#include <QNetworkReply>
#include "components/evidence_editor/evidenceeditor.h"
#include "components/loading/qprogressindicator.h"
#include "components/loading_button/loadingbutton.h"
#include "db/databaseconnection.h"
#include "dtos/tag.h"
namespace Ui {
class GetInfo;
}
class DatabaseConnection;
class LoadingButton;
class GetInfo : public AShirtDialog {
Q_OBJECT
@ -29,14 +22,13 @@ class GetInfo : public AShirtDialog {
void buildUi();
void wireUi();
bool saveData();
void setActionButtonsEnabled(bool enabled);
void showEvent(QShowEvent *evt) override;
signals:
void setActionButtonsEnabled(bool enabled);
private slots:
void submitButtonClicked();
void deleteButtonClicked();
void onUploadComplete();
public:
@ -46,13 +38,9 @@ class GetInfo : public AShirtDialog {
private:
DatabaseConnection *db;
qint64 evidenceID;
QNetworkReply *uploadAssetReply = nullptr;
// Ui Components
QGridLayout* gridLayout;
QPushButton* deleteButton;
EvidenceEditor *evidenceEditor;
LoadingButton *submitButton;
EvidenceEditor *evidenceEditor = nullptr;
LoadingButton *submitButton = nullptr;
};

View File

@ -1,58 +1,35 @@
#include "porting_dialog.h"
#include <QFileDialog>
#include <QtConcurrent/QtConcurrent>
#include <QMessageBox>
#include <iostream>
#include <QCheckBox>
#include <QFileDialog>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QProgressBar>
#include <QPushButton>
#include <QtConcurrent/QtConcurrent>
#include "db/databaseconnection.h"
PortingDialog::PortingDialog(PortType dialogType, DatabaseConnection* db, QWidget *parent)
: AShirtDialog(parent) {
this->dialogType = dialogType;
this->db = db;
buildUi();
wireUi();
}
PortingDialog::~PortingDialog() {
delete _selectFileLabel;
delete portConfigCheckBox;
delete portEvidenceCheckBox;
delete submitButton;
delete pathTextBox;
delete progressBar;
delete portStatusLabel;
delete gridLayout;
}
void PortingDialog::buildUi() {
gridLayout = new QGridLayout(this);
_selectFileLabel = new QLabel(this);
portStatusLabel = new QLabel(this);
submitButton = new QPushButton(this);
browseButton = new QPushButton(tr("Browse"), this);
pathTextBox = new QLineEdit(this);
portConfigCheckBox = new QCheckBox(tr("Include Config"), this);
: AShirtDialog(parent)
, dialogType(dialogType)
, db(db)
, portStatusLabel(new QLabel(this))
, submitButton(new QPushButton(dialogType == Import ? tr("Import") : tr("Export"), this))
, pathTextBox(new QLineEdit(this))
, portConfigCheckBox(new QCheckBox(tr("Include Config"), this))
, portEvidenceCheckBox(new QCheckBox(tr("Include Evidence"), this))
, progressBar(new QProgressBar(this))
{
setWindowTitle(dialogType == Import ? tr("Import Data") : tr("Export Data"));
auto browseButton = new QPushButton(tr("Browse"), this);
connect(browseButton, &QPushButton::clicked, this, &PortingDialog::onBrowsePresed);
connect(submitButton, &QPushButton::clicked, this, &PortingDialog::onSubmitPressed);
portConfigCheckBox->setChecked(true);
portEvidenceCheckBox = new QCheckBox(tr("Include Evidence"), this);
portEvidenceCheckBox->setChecked(true);
progressBar = new QProgressBar(this);
if (dialogType == Import) {
submitButton->setText(tr("Import"));
_selectFileLabel->setText(tr("Select import file"));
this->setWindowTitle(tr("Import Data"));
}
else {
submitButton->setText(tr("Export"));
_selectFileLabel->setText(tr("Export Directory"));
this->setWindowTitle(tr("Export Data"));
}
// Layout
/* 0 1 2
@ -71,35 +48,23 @@ void PortingDialog::buildUi() {
+---------------+-------------+--------------+
*/
// row 0
gridLayout->addWidget(_selectFileLabel, 0, 0);
auto gridLayout = new QGridLayout(this);
gridLayout->addWidget(new QLabel(dialogType == Import ? tr("Select import file") : tr("Export Directory"), this), 0, 0);
gridLayout->addWidget(pathTextBox, 0, 1);
gridLayout->addWidget(browseButton, 0, 2);
// row 1
gridLayout->addWidget(portConfigCheckBox, 1, 0, 1, gridLayout->columnCount());
// row 2
gridLayout->addWidget(portEvidenceCheckBox, 2, 0, 1, gridLayout->columnCount());
// row 3
gridLayout->addWidget(progressBar, 3, 0, 1, gridLayout->columnCount());
// row 4
gridLayout->addWidget(portStatusLabel, 4, 0, 1, gridLayout->columnCount());
// row 5
gridLayout->addWidget(submitButton, 5, 2);
setLayout(gridLayout);
this->setLayout(gridLayout);
this->resize(500, 1);
}
void PortingDialog::wireUi() {
auto btnClicked = &QPushButton::clicked;
connect(submitButton, btnClicked, this, &PortingDialog::onSubmitPressed);
connect(browseButton, btnClicked, this, &PortingDialog::onBrowsePresed);
resize(500, 1);
}
void PortingDialog::onBrowsePresed() {
@ -132,7 +97,7 @@ void PortingDialog::resetForm() {
void PortingDialog::onSubmitPressed() {
if (portDone) {
this->close();
close();
resetForm();
}
auto portingPath = pathTextBox->text().trimmed();

View File

@ -1,18 +1,14 @@
#pragma once
#include "ashirtdialog/ashirtdialog.h"
#include <QCheckBox>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QProgressBar>
#include <QPushButton>
#include <QWidget>
#include "db/databaseconnection.h"
#include "porting/system_manifest.h"
class DatabaseConnection;
class QCheckBox;
class QLabel;
class QLineEdit;
class QProgressBar;
class QPushButton;
/**
* @brief The PortingDialog class renders a dialog window allowing a user to import or export content and settings.
* The UI presented is dependent on the underlying dialogType. Specifying Import will render an import window,
@ -39,7 +35,7 @@ class PortingDialog : public AShirtDialog {
* @param parent is used by the underlying QDialog constructor
*/
explicit PortingDialog(PortType dialogType, DatabaseConnection* db, QWidget *parent = nullptr);
~PortingDialog();
~PortingDialog() = default;
public:
/// getPortPath retrieves the path used to import or export (note: this is always directory, even
@ -52,11 +48,6 @@ class PortingDialog : public AShirtDialog {
void portCompleted(QString path);
private:
/// buildUi creates the window structure.
void buildUi();
/// wireUi connects the components to each other.
void wireUi();
/// onSubmitPressed preps an import/export and routes the action to doImport or doExport
void onSubmitPressed();
/// onBrowsePressed renders a QFileDialog window (for opening). The behavior is specific for
@ -95,12 +86,8 @@ class PortingDialog : public AShirtDialog {
porting::SystemManifest* executedManifest = nullptr;
// UI Components
QGridLayout* gridLayout = nullptr;
QLabel* _selectFileLabel = nullptr;
QLabel* portStatusLabel = nullptr;
QPushButton* submitButton = nullptr;
QPushButton* browseButton = nullptr;
QLineEdit* pathTextBox = nullptr;
QProgressBar* progressBar = nullptr;
QCheckBox* portConfigCheckBox = nullptr;

View File

@ -4,8 +4,16 @@
#include "settings.h"
#include <QDateTime>
#include <QDialogButtonBox>
#include <QErrorMessage>
#include <QFileDialog>
#include <QGridLayout>
#include <QKeySequence>
#include <QKeySequenceEdit>
#include <QLabel>
#include <QLineEdit>
#include <QNetworkReply>
#include <QPushButton>
#include <QString>
#include "appconfig.h"
@ -17,78 +25,42 @@
#include "helpers/ui_helpers.h"
#include "hotkeymanager.h"
#include "components/custom_keyseq_edit/singlestrokekeysequenceedit.h"
#include "components/loading_button/loadingbutton.h"
Settings::Settings(HotkeyManager *hotkeyManager, QWidget *parent)
: AShirtDialog(parent, AShirtDialog::commonWindowFlags)
: AShirtDialog(parent, AShirtDialog::commonWindowFlags)
, hotkeyManager(hotkeyManager)
, connStatusLabel(new QLabel(this))
, eviRepoTextBox(new QLineEdit(this))
, accessKeyTextBox(new QLineEdit(this))
, secretKeyTextBox(new QLineEdit(this))
, hostPathTextBox(new QLineEdit(this))
, captureAreaCmdTextBox(new QLineEdit(this))
, captureAreaShortcutTextBox(new SingleStrokeKeySequenceEdit(this))
, captureWindowCmdTextBox(new QLineEdit(this))
, captureWindowShortcutTextBox(new SingleStrokeKeySequenceEdit(this))
, recordCodeblockShortcutTextBox(new SingleStrokeKeySequenceEdit(this))
, testConnectionButton(new LoadingButton(tr("Test Connection"), this))
, couldNotSaveSettingsMsg(new QErrorMessage(this))
{
this->hotkeyManager = hotkeyManager;
buildUi();
wireUi();
}
Settings::~Settings() {
delete _eviRepoLabel;
delete _accessKeyLabel;
delete _secretKeyLabel;
delete _hostPathLabel;
delete _captureAreaCmdLabel;
delete _captureAreaShortcutLabel;
delete _captureWindowCmdLabel;
delete _captureWindowShortcutLabel;
delete _recordCodeblockShortcutLabel;
delete connStatusLabel;
delete eviRepoTextBox;
delete accessKeyTextBox;
delete secretKeyTextBox;
delete hostPathTextBox;
delete captureAreaCmdTextBox;
delete captureAreaShortcutTextBox;
delete captureWindowCmdTextBox;
delete captureWindowShortcutTextBox;
delete recordCodeblockShortcutTextBox;
delete testConnectionButton;
delete eviRepoBrowseButton;
delete buttonBox;
delete gridLayout;
delete couldNotSaveSettingsMsg;
stopReply(&currentTestReply);
}
void Settings::buildUi() {
gridLayout = new QGridLayout(this);
_eviRepoLabel = new QLabel(tr("Evidence Repository"), this);
_accessKeyLabel = new QLabel(tr("Access Key"), this);
_secretKeyLabel = new QLabel(tr("Secret Key"), this);
_hostPathLabel = new QLabel(tr("Host Path"), this);
_captureAreaCmdLabel = new QLabel(tr("Capture Area Command"), this);
_captureAreaShortcutLabel = new QLabel(tr("Shortcut"), this);
_captureWindowCmdLabel = new QLabel(tr("Capture Window Command"), this);
_captureWindowShortcutLabel = new QLabel(tr("Shortcut"), this);
_recordCodeblockShortcutLabel = new QLabel(tr("Record Codeblock Shortcut"), this);
connStatusLabel = new QLabel(QString(), this);
auto eviRepoBrowseButton = new QPushButton(tr("Browse"), this);
connect(eviRepoBrowseButton, &QPushButton::clicked, this, &Settings::onBrowseClicked);
eviRepoTextBox = new QLineEdit(this);
accessKeyTextBox = new QLineEdit(this);
secretKeyTextBox = new QLineEdit(this);
hostPathTextBox = new QLineEdit(this);
captureAreaCmdTextBox = new QLineEdit(this);
captureAreaShortcutTextBox = new SingleStrokeKeySequenceEdit(this);
captureWindowCmdTextBox = new QLineEdit(this);
captureWindowShortcutTextBox = new SingleStrokeKeySequenceEdit(this);
recordCodeblockShortcutTextBox = new SingleStrokeKeySequenceEdit(this);
eviRepoBrowseButton = new QPushButton(tr("Browse"), this);
testConnectionButton = new LoadingButton(tr("Test Connection"), this);
clearHotkeysButton = new QPushButton(tr("Clear Shortcuts"), this);
buttonBox = new QDialogButtonBox(this);
buttonBox->addButton(QDialogButtonBox::Save);
buttonBox->addButton(QDialogButtonBox::Cancel);
spacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding);
couldNotSaveSettingsMsg = new QErrorMessage(this);
auto clearHotkeysButton = new QPushButton(tr("Clear Shortcuts"), this);
connect(clearHotkeysButton, &QPushButton::clicked, this, &Settings::onClearShortcutsClicked);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel, this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &Settings::onSaveClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &Settings::onCancelClicked);
// Layout
/* 0 1 2 3
+---------------+-------------+------------+-------------+
@ -113,38 +85,38 @@ void Settings::buildUi() {
9 | Dialog button Box{save, cancel} |
+---------------+-------------+------------+-------------+
*/
auto gridLayout = new QGridLayout(this);
// row 0
gridLayout->addWidget(_eviRepoLabel, 0, 0);
gridLayout->addWidget(new QLabel(tr("Evidence Repository"), this), 0, 0);
gridLayout->addWidget(eviRepoTextBox, 0, 1, 1, 3);
gridLayout->addWidget(eviRepoBrowseButton, 0, 4);
// row 1
gridLayout->addWidget(_accessKeyLabel, 1, 0);
gridLayout->addWidget(new QLabel(tr("Access Key"), this), 1, 0);
gridLayout->addWidget(accessKeyTextBox, 1, 1, 1, 4);
// row 2
gridLayout->addWidget(_secretKeyLabel, 2, 0);
gridLayout->addWidget(new QLabel(tr("Secret Key"), this), 2, 0);
gridLayout->addWidget(secretKeyTextBox, 2, 1, 1, 4);
// row 3
gridLayout->addWidget(_hostPathLabel, 3, 0);
gridLayout->addWidget(new QLabel(tr("Host Path"), this), 3, 0);
gridLayout->addWidget(hostPathTextBox, 3, 1, 1, 4);
// row 4
gridLayout->addWidget(_captureAreaCmdLabel, 4, 0);
gridLayout->addWidget(new QLabel(tr("Capture Area Command"), this), 4, 0);
gridLayout->addWidget(captureAreaCmdTextBox, 4, 1);
gridLayout->addWidget(_captureAreaShortcutLabel, 4, 2);
gridLayout->addWidget(new QLabel(tr("Shortcut"), this), 4, 2);
gridLayout->addWidget(captureAreaShortcutTextBox, 4, 3, 1, 2);
// row 5
gridLayout->addWidget(_captureWindowCmdLabel, 5, 0);
gridLayout->addWidget(new QLabel(tr("Capture Window Command"), this), 5, 0);
gridLayout->addWidget(captureWindowCmdTextBox, 5, 1);
gridLayout->addWidget(_captureWindowShortcutLabel, 5, 2);
gridLayout->addWidget(new QLabel(tr("Shortcut"), this), 5, 2);
gridLayout->addWidget(captureWindowShortcutTextBox, 5, 3, 1, 2);
// row 6 (reserved for codeblocks)
gridLayout->addWidget(_recordCodeblockShortcutLabel, 6, 0);
gridLayout->addWidget(new QLabel(tr("Record Codeblock Shortcut"), this), 6, 0);
gridLayout->addWidget(recordCodeblockShortcutTextBox, 6, 1);
gridLayout->addWidget(clearHotkeysButton, 6, 2, 1, 3, Qt::AlignRight);
@ -153,24 +125,19 @@ void Settings::buildUi() {
gridLayout->addWidget(connStatusLabel, 7, 1, 1, 4);
// row 8
gridLayout->addItem(spacer, 8, 0, 1, gridLayout->columnCount());
gridLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding), 8, 0, 1, gridLayout->columnCount());
// row 9
gridLayout->addWidget(buttonBox, 9, 0, 1, gridLayout->columnCount());
this->setLayout(gridLayout);
this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
this->resize(760, 300);
this->setWindowTitle(tr("Settings"));
setLayout(gridLayout);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
resize(760, 300);
setWindowTitle(tr("Settings"));
}
void Settings::wireUi() {
connect(buttonBox, &QDialogButtonBox::accepted, this, &Settings::onSaveClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &Settings::onCancelClicked);
connect(testConnectionButton, &QPushButton::clicked, this, &Settings::onTestConnectionClicked);
connect(eviRepoBrowseButton, &QPushButton::clicked, this, &Settings::onBrowseClicked);
connect(clearHotkeysButton, &QPushButton::clicked, this, &Settings::onClearShortcutsClicked);
connect(captureAreaShortcutTextBox, &QKeySequenceEdit::keySequenceChanged, this, [this](const QKeySequence &keySequence){
checkForDuplicateShortcuts(keySequence, captureAreaShortcutTextBox);
});
@ -209,7 +176,7 @@ void Settings::checkForDuplicateShortcuts(const QKeySequence& keySequence, QKeyS
void Settings::showEvent(QShowEvent *evt) {
QDialog::showEvent(evt);
this->hotkeyManager->disableHotkeys();
hotkeyManager->disableHotkeys();
AppConfig &inst = AppConfig::getInstance();
eviRepoTextBox->setFocus(); //setting focus to prevent retaining focus for macs
@ -232,13 +199,13 @@ void Settings::showEvent(QShowEvent *evt) {
void Settings::closeEvent(QCloseEvent *event) {
onSaveClicked();
this->hotkeyManager->enableHotkeys();
hotkeyManager->enableHotkeys();
QDialog::closeEvent(event);
}
void Settings::onCancelClicked() {
stopReply(&currentTestReply);
this->hotkeyManager->enableHotkeys();
hotkeyManager->enableHotkeys();
reject();
}

View File

@ -6,18 +6,15 @@
#include "ashirtdialog/ashirtdialog.h"
#include <QCloseEvent>
#include <QDialogButtonBox>
#include <QErrorMessage>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QNetworkReply>
#include <QPushButton>
#include <QSpacerItem>
#include <QKeySequenceEdit>
#include "components/loading_button/loadingbutton.h"
#include "hotkeymanager.h"
class HotkeyManager;
class QErrorMessage;
class QKeySequenceEdit;
class QLabel;
class QLineEdit;
class LoadingButton;
class QNetworkReply;
class QPushButton;
/**
* @brief The Settings class represents the settings dialog that displays when
@ -70,16 +67,6 @@ class Settings : public AShirtDialog {
QNetworkReply* currentTestReply = nullptr;
// UI components
QGridLayout* gridLayout = nullptr;
QLabel* _eviRepoLabel = nullptr;
QLabel* _accessKeyLabel = nullptr;
QLabel* _secretKeyLabel = nullptr;
QLabel* _hostPathLabel = nullptr;
QLabel* _captureAreaCmdLabel = nullptr;
QLabel* _captureAreaShortcutLabel = nullptr;
QLabel* _captureWindowCmdLabel = nullptr;
QLabel* _captureWindowShortcutLabel = nullptr;
QLabel* _recordCodeblockShortcutLabel = nullptr;
QLabel* connStatusLabel = nullptr;
QLineEdit* eviRepoTextBox = nullptr;
@ -94,8 +81,5 @@ class Settings : public AShirtDialog {
LoadingButton* testConnectionButton = nullptr;
QPushButton* eviRepoBrowseButton = nullptr;
QPushButton* clearHotkeysButton = nullptr;
QDialogButtonBox* buttonBox = nullptr;
QErrorMessage* couldNotSaveSettingsMsg = nullptr;
QSpacerItem* spacer = nullptr;
};