Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
#
# $Id$
# $HeadURL$
# $Author$
# Created by Malte Schroeder, SLSE, 2016-03-03
#
SET(lt_SRCS
licenceedit.cpp
licenceedit.h
mainwindow.cpp
mainwindow.h
main.cpp
sortfilter.cpp
sortfilter.h
)
NGL_WRAP_UI(lt_SRCS ui/mainwindow.ui ui/licenceedit.ui)
NGL_ADD_EXECUTABLE(WS NO_TRANSLATION LicenceEditor ${lt_SRCS})
NGL_TARGET_LINK_LIBRARIES(LicenceEditor
Qt5::Widgets
Qt5::Core
Qt5::Xml
nglapplication
nglwidgets
LtsLicence
NGLLogger
)
NGL_INSTALL_TARGET_DEVEL(LicenceEditor)
+108
View File
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<licences>
<licence>
<name>AreaEffectSimulation</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>AssetManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>ExerciseManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>24.06.2016 15:06:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>InfrastructureManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>MarkerManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>NotificationManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>OperatorManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>ProjectDataManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>PlayerManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>RecordingManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>ServiceManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>SituationReplay</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>SituationReplayManagement</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>TetraRadio</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
<licence>
<name>TrainingAreaBase</name>
<ignoreMaxCount>1</ignoreMaxCount> <!-- 1=ignore 0=consider maxCount -->
<ignoreExpiration>1</ignoreExpiration> <!-- 1=ignore 0=consider expiration -->
<maxCount>2</maxCount>
<expiration>31.12.2016 00:00:00</expiration> <!-- dd.MM.yyyy hh:mm:ss -->
</licence>
</licences>
+123
View File
@@ -0,0 +1,123 @@
/*
* @RDE_HEADER@
* <short description>
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Schröder, SLSE, 2016-06-08
*/
#include "licenceedit.h"
#include "ui_licenceedit.h"
#include <LtsLicence/lts_licence.h>
LicenceEdit::LicenceEdit(QWidget *parent)
: NGLDialog(parent)
, m_ui(new Ui::LicenceEdit)
{
m_ui->setupUi(this);
clear();
connect(m_ui->nglDialogButtonBox, &NGLDialogButtonBox::onOk,
this, &LicenceEdit::onOk);
connect(m_ui->nglDialogButtonBox, &NGLDialogButtonBox::onCancel,
this, &LicenceEdit::onCancel);
connect(m_ui->chbIgnoreCount, &QCheckBox::stateChanged,
this, &LicenceEdit::enableIgnoreCount);
connect(m_ui->chbIgnoreExpiration, &QCheckBox::stateChanged,
this, &LicenceEdit::enableIgnoreExpiration);
connect(m_ui->leName, &QLineEdit::textChanged,
this, &LicenceEdit::onNameChanged);
}
LicenceEdit::~LicenceEdit()
{
delete m_ui;
}
/**
* @brief enables QCheckBox "Ignore Count"
* @param checkState
*
* The function enables or disables the QCheckBox "sbCount"
* The parameter @checkState represents the CheckState of the QCheckBox.
*
* @return void
*/
void LicenceEdit::enableIgnoreCount(int checkState)
{
m_ui->lbxCount->setEnabled(checkState == Qt::Unchecked);
m_ui->sbMaxCount->setEnabled(checkState == Qt::Unchecked);
}
/**
* @brief enables QCheckBox "Ignore Expiration"
* @param i
*
* The function enables or disables the QCheckBox "sbExpiration"
* The parameter "i" represents the CheckState of the QCheckBox.
*
* @return void
*/
void LicenceEdit::enableIgnoreExpiration(int checkState)
{
m_ui->lbxExpiry->setEnabled(checkState == Qt::Unchecked);
m_ui->dateEdit->setEnabled(checkState == Qt::Unchecked);
m_ui->timeEdit->setEnabled(checkState == Qt::Unchecked);
}
void LicenceEdit::onNameChanged(const QString &name)
{
setWindowTitle(name.isEmpty() ? tr("Add Licence") : name);
m_ui->nglDialogButtonBox->setEnabled(NGLStandardButton::Ok, !name.isEmpty());
}
void LicenceEdit::setLicence(const LtsLicence::Licence &licence)
{
m_ui->leName->setText(licence.name);
m_ui->dateEdit->setDate(licence.expiration.date());
m_ui->timeEdit->setTime(licence.expiration.time());
m_ui->sbMaxCount->setValue(licence.maxCount);
m_ui->chbIgnoreCount->setChecked(licence.ignoreMaxCount);
m_ui->chbIgnoreExpiration->setChecked(licence.ignoreExpiration);
m_ui->leName->setEnabled(false);
}
void LicenceEdit::clear()
{
m_ui->leName->clear();
m_ui->chbIgnoreCount->setChecked(false);
m_ui->chbIgnoreExpiration->setChecked(false);
m_ui->dateEdit->setMinimumDate(QDate::currentDate());
m_ui->dateEdit->setDate(QDateTime::currentDateTime().date());
m_ui->timeEdit->setTime(QDateTime::currentDateTime().time());
m_ui->sbMaxCount->setValue(1);
m_ui->leName->setEnabled(true);
m_ui->leName->setFocus();
}
void LicenceEdit::onOk()
{
QDateTime dateTime(m_ui->dateEdit->date(), m_ui->timeEdit->time());
LtsLicence::Licence li;
li.name = m_ui->leName->text();
li.expiration = dateTime;
li.maxCount = m_ui->sbMaxCount->text().toInt();
li.ignoreMaxCount = m_ui->chbIgnoreCount->isChecked();
li.ignoreExpiration = m_ui->chbIgnoreExpiration->isChecked();
emit newLicence(li);
accept();
}
void LicenceEdit::onCancel()
{
reject();
}
+46
View File
@@ -0,0 +1,46 @@
/*
* @RDE_HEADER@
* <short description>
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Schröder, SLSE, 2016-06-08
*/
#pragma once
#include <nglwidgets/ngldialog.h>
namespace Ui
{
class LicenceEdit;
}
namespace LtsLicence
{
struct Licence;
}
class LicenceEdit : public NGLDialog
{
Q_OBJECT
public:
explicit LicenceEdit(QWidget *parent = nullptr);
~LicenceEdit();
void setLicence(const LtsLicence::Licence &licence);
void clear();
signals:
void newLicence(const LtsLicence::Licence &li);
private slots:
void onOk();
void onCancel();
void enableIgnoreCount(int checkState);
void enableIgnoreExpiration(int checkState);
void onNameChanged(const QString &name);
private:
Ui::LicenceEdit *m_ui;
};
+36
View File
@@ -0,0 +1,36 @@
/*
* @RDE_HEADER@
* <short description>
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Schröder, SLSE, 2016-06-08
*/
#include "mainwindow.h"
#include <NGLLogger/INGLLogger.h>
#include <nglapplication/nglapplication.h>
int main(int argc, char *argv[])
{
NGLApplication app(argc, argv);
QCoreApplication::setApplicationName(QLatin1String("Licence Editor"));
QCoreApplication::setOrganizationName(QLatin1String("RME"));
app.createLogger("LicenceEdit", "log4cxx_licenceedit.props");
NGL::INGLLogger &logger = app.baseLogger();
STARTUP_LOG(logger);
MainWindow w;
w.init();
w.show();
app.setQuitOnLastWindowClosed(true);
int retval = app.exec();
SHUTDOWN_LOG(logger);
return retval;
}
+424
View File
@@ -0,0 +1,424 @@
/*
* @RDE_HEADER@
* <short description>
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Schröder, SLSE, 2016-06-08
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "sortfilter.h"
#include <QCloseEvent>
#include <QFileDialog>
#include <QMessageBox>
#include <QModelIndex>
#include <LtsLicence/aes_crypt.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, m_ui(new Ui::MainWindow)
, m_licenceEdit(new LicenceEdit(this))
, m_licencesModel(new QStandardItemModel(this))
, m_cryptState(CryptState::Unknown)
{
m_ui->setupUi(this);
m_licenceEdit->setModal(true);
enableDisableButtons();
setTVHeaders();
m_filterProxyModel = new SortFilter(this);
m_filterProxyModel->setSourceModel(m_licencesModel);
m_ui->tvContent->setModel(m_filterProxyModel);
m_ui->tvContent->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_ui->leEncKey->setText(LtsLicence::passPhrase());
connect(m_ui->pbResetKey, &QPushButton::clicked, this, [this]() {m_ui->leEncKey->setText(LtsLicence::passPhrase());});
setWindowTitle(tr("Licence Editor"));
}
MainWindow::~MainWindow()
{
delete m_ui;
}
bool MainWindow::init()
{
connect(m_ui->actionOpen, &QAction::triggered, this, &MainWindow::onActionOpen);
connect(m_ui->actionSave, &QAction::triggered, this, &MainWindow::onActionSave);
connect(m_ui->actionSave_As, &QAction::triggered, this, &MainWindow::onActionSaveAs);
connect(m_ui->actionExit, &QAction::triggered, this, &MainWindow::close);
connect(m_ui->tvContent, &QTableView::doubleClicked, this, &MainWindow::onActionEdit);
connect(m_ui->nglDialogButtonBox, &NGLDialogButtonBox::onReset, this, &MainWindow::onActionReset);
connect(m_ui->nglDialogButtonBox, &NGLDialogButtonBox::onRemove, this, &MainWindow::onActionRemove);
connect(m_ui->nglDialogButtonBox, &NGLDialogButtonBox::onEdit, this, &MainWindow::onActionEdit);
connect(m_ui->nglDialogButtonBox, &NGLDialogButtonBox::onAdd, this, &MainWindow::onActionAdd);
connect(m_licenceEdit, &LicenceEdit::newLicence, this, &MainWindow::onNewLicence);
QPushButton *pb = m_ui->nglDialogButtonBox->button(NGLStandardButton::Add);
if (pb)
{
pb->setShortcut(tr("+"));
pb->setToolTip(tr("+"));
}
pb = m_ui->nglDialogButtonBox->button(NGLStandardButton::Remove);
if (pb)
{
pb->setShortcut(tr("-"));
pb->setToolTip(tr("-"));
}
pb = m_ui->nglDialogButtonBox->button(NGLStandardButton::Edit);
if (pb)
{
pb->setShortcut(tr("F2"));
pb->setToolTip(tr("F2"));
}
pb = m_ui->nglDialogButtonBox->button(NGLStandardButton::Reset);
if (pb)
{
pb->setShortcut(tr("Del"));
pb->setToolTip(tr("Del"));
}
return true;
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if (!isWindowModified())
{
QMainWindow::closeEvent(event);
return;
}
int ret = QMessageBox::warning(this, tr("Warning"),
tr("Do you want to save the changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save);
switch (ret)
{
case QMessageBox::Save:
m_fileName.isEmpty() ? onActionSaveAs() : onActionSave();
break;
case QMessageBox::Discard:
event->accept();
break;
case QMessageBox::Cancel:
return;
}
QMainWindow::closeEvent(event);
}
void MainWindow::insertRow(const LtsLicence::Licence &licence, int currentRowLicModel)
{
if (currentRowLicModel >= m_licencesModel->rowCount())
{
m_licencesModel->setRowCount(m_licencesModel->rowCount() + 1);
currentRowLicModel = m_licencesModel->rowCount() - 1;
}
// -----APPEND NAME-----
QStandardItem *name = new QStandardItem(licence.name);
m_licencesModel->setItem(currentRowLicModel, 0, name);
// -----APPEND MAXCOUNT-----
QStandardItem *maxCount = new QStandardItem();
maxCount->setData(licence.maxCount);
if (licence.ignoreMaxCount)
maxCount->setText(tr("(%1 unused)").arg(QString::number(licence.maxCount)));
else
maxCount->setText(QString::number(licence.maxCount));
m_licencesModel->setItem(currentRowLicModel, 1, maxCount);
// -----APPEND EXPIRY-----
QStandardItem *expiry = new QStandardItem();
expiry->setData(licence.expiration);
if (licence.ignoreExpiration)
expiry->setText(tr("(%1 unused)").arg(licence.expiration.toString(tr("ddd dd.MM.yyyy HH:mm"))));
else
expiry->setText(licence.expiration.toString(tr("ddd dd.MM.yyyy HH:mm")));
m_licencesModel->setItem(currentRowLicModel, 2, expiry);
setTVHeaders();
enableDisableButtons();
}
void MainWindow::onNewLicence(const LtsLicence::Licence &licence)
{
if (m_licences.contains(licence.name))
{
m_licences[licence.name] = licence;
for (int i = 0; i < m_licencesModel->rowCount(); ++i)
{
if (m_licencesModel->item(i, 0)->text() == licence.name)
{
insertRow(licence, i);
setWindowModified(true);
return;
}
}
}
m_licences.insert(licence.name, licence);
insertRow(licence, m_licences.count());
setWindowModified(true);
m_ui->tvContent->setFocus();
}
void MainWindow::enableDisableButtons()
{
bool enable = m_licencesModel->rowCount() > 0;
m_ui->actionSave_As->setEnabled(enable);
m_ui->nglDialogButtonBox->setEnabled(NGLStandardButton::Remove, enable);
m_ui->nglDialogButtonBox->setEnabled(NGLStandardButton::Reset, enable);
m_ui->nglDialogButtonBox->setEnabled(NGLStandardButton::Edit, enable);
}
void MainWindow::setCurrentIndex()
{
QModelIndex index = m_ui->tvContent->currentIndex();
m_ui->tvContent->selectRow(index.row() + 1);
}
void MainWindow::setTVHeaders()
{
m_licencesModel->setHorizontalHeaderItem(0, new QStandardItem(tr("Name")));
m_licencesModel->setHorizontalHeaderItem(1, new QStandardItem(tr("Count")));
m_licencesModel->setHorizontalHeaderItem(2, new QStandardItem(tr("Expiry")));
m_ui->tvContent->resizeColumnsToContents();
m_ui->tvContent->horizontalHeader()->setStretchLastSection(true);
}
/**
* @brief this method is called by clicking the item "Open" in the Main-Menu
*
* The function opens a XML-file and loads each element of it into the QListWidget "lwContent".
* Furthermore, all items are going to append to the QVector<Licence> "m_licences"
*
* @return void
*/
void MainWindow::onActionOpen()
{
if (!onActionReset())
return;
const QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Licence File"),
QString(),
tr("Encrypted Licence Files (*.dat *.crl) (*.dat *.crl);;Unencrypted Licence Files (*.xml *.lic) (*.xml *.lic);;"));
if (fileName.isEmpty())
return;
m_fileName = fileName;
m_ui->actionSave->setEnabled(true);
QFile file(fileName);
if (!file.exists() ||
!file.open(QIODevice::ReadOnly))
{
file.close();
return;
}
QByteArray ba = file.readAll();
file.close();
if (ba.isEmpty())
return;
m_cryptState = CryptState::Decrypted;
QVector<LtsLicence::Licence> licVec = LtsLicence::readLicences(ba);
if (licVec.isEmpty())
{
ba = LtsLicence::decryptData(ba, m_ui->leEncKey->text());
licVec = LtsLicence::readLicences(ba);
if (licVec.isEmpty())
{
m_cryptState = CryptState::Unknown;
m_fileName.clear();
return;
}
m_cryptState = CryptState::Encrypted;
}
for (const LtsLicence::Licence &lic : qAsConst(licVec))
{
m_licences.insert(lic.name, lic);
insertRow(lic, m_licencesModel->rowCount());
}
QFileInfo fi(fileName);
setWindowTitle(fi.fileName() + QLatin1String("[*] - Licence Editor"));
m_ui->tvContent->resizeColumnsToContents();
m_ui->tvContent->sortByColumn(0, Qt::AscendingOrder);
setCurrentIndex();
}
/**
* @brief function adds an entry to the QListWidget
*
* The function onActionAddEntry() adds a new QListWidgetItem to lwContent.
* It will append to the QVector<Licence> "m_licences" in a smiliar way.
*
* @return void
*/
void MainWindow::onActionAdd()
{
m_licenceEdit->clear();
m_licenceEdit->show();
}
/**
* @brief writes the content of the QListWidget to a file
*
* This function writes all content of the QVector<Licence> "m_licences" which represents the content of the QListWidget to a XML-file
*
* @return void
*/
void MainWindow::onActionSaveAs()
{
if (m_licences.isEmpty())
{
QMessageBox::warning(this, tr("Error"), tr("There are no elements to save!"), QMessageBox::Ok);
return;
}
QString selectedFilter;
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Licence file"), QString()
, tr("Encrypted Licence Files (*.crl) (*.crl);;Decrypted Licence Files (*.lic) (*.lic)")
, &selectedFilter);
if (fileName.isEmpty())
return;
if (selectedFilter.contains(QLatin1String("lic")))
{
m_cryptState = CryptState::Decrypted;
m_ui->actionSave->setEnabled(true);
}
else if (selectedFilter.contains(QLatin1String("crl")))
{
m_cryptState = CryptState::Encrypted;
m_ui->actionSave->setEnabled(true);
}
else
{
m_cryptState = CryptState::Unknown;
m_ui->actionSave->setEnabled(false);
}
QFileInfo fi(fileName);
setWindowTitle(fi.fileName() + QLatin1String("[*] - Licence Editor"));
m_fileName = fileName;
onActionSave();
}
void MainWindow::onActionSave()
{
if (m_fileName.isEmpty())
return;
QVector<LtsLicence::Licence> licVec;
licVec.reserve(m_licences.size());
for (const LtsLicence::Licence &lic : qAsConst(m_licences))
licVec += lic;
QByteArray licenceBa = LtsLicence::writeUnencryptedLicences(licVec);
if (m_cryptState == CryptState::Encrypted)
licenceBa = LtsLicence::encryptData(licenceBa, m_ui->leEncKey->text());
QFile file(m_fileName);
if (!file.open(QIODevice::WriteOnly))
return;
file.write(licenceBa);
file.close();
setWindowModified(false);
}
void MainWindow::onActionEdit()
{
const QModelIndex mi = m_filterProxyModel->mapToSource(m_ui->tvContent->currentIndex());
if (!mi.isValid())
return;
QStandardItem *si = m_licencesModel->item(mi.row(), 0);
if (!si)
return;
QString licenceName = si->text();
m_licenceEdit->setLicence(m_licences[licenceName]);
m_licenceEdit->show();
}
/**
* @brief slot for Button pbClear clears both the QListWidget and the QVector<Licence> m_licences
*
* This functions resets the Application to its intial state. In doing so, the QListWidget m_lwContent and
* the QVector<Licence> "m_licences" gets resetted.
*
* @return void
*/
bool MainWindow::onActionReset()
{
if (!m_licences.isEmpty())
{
int ret = QMessageBox::warning(this, tr("Reset"), tr("You sure to reset the current list?"), QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::No)
return false;
}
m_licencesModel->clear();
m_licencesModel->setRowCount(0);
setTVHeaders();
m_licences.clear();
m_fileName.clear();
m_ui->actionSave->setEnabled(false);
enableDisableButtons();
return true;
}
/**
* @brief function will be called by the Button pbDelete
*
* The function deletes the current QListWidgetItem of the QListWidget "lwContent"
*
* @return void
*/
void MainWindow::onActionRemove()
{
int ret = QMessageBox::question(this, tr("Remove"), tr("You sure to remove the selected item from the list?"), QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::No)
return;
const QModelIndex mi = m_filterProxyModel->mapToSource(m_ui->tvContent->currentIndex());
if (!mi.isValid())
return;
int currentRow = mi.row();
QStandardItem *si = m_licencesModel->item(currentRow, 0);
if (!si)
return;
QString licenceName = si->text();
m_licencesModel->removeRow(currentRow);
m_licences.remove(licenceName);
enableDisableButtons();
setCurrentIndex();
}
+69
View File
@@ -0,0 +1,69 @@
/*
* @RDE_HEADER@
* <short description>
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Schröder, SLSE, 2016-06-08
*/
#pragma once
#include <QMainWindow>
#include <QMap>
#include <QStandardItemModel>
#include <LtsLicence/lts_licence.h>
#include "licenceedit.h"
namespace Ui
{
class MainWindow;
}
class QSortFilterProxyModel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
bool init();
void closeEvent(QCloseEvent *event) override;
private slots:
void onNewLicence(const LtsLicence::Licence &licence);
void onActionOpen();
void onActionSave();
void onActionSaveAs();
void onActionAdd();
void onActionEdit();
void onActionRemove();
bool onActionReset();
private:
enum class CryptState
{
Unknown = 0,
Decrypted,
Encrypted
} ;
void insertRow(const LtsLicence::Licence &licence, int currentRowLicModel);
void enableDisableButtons();
void setCurrentIndex();
void setTVHeaders();
private:
Ui::MainWindow *m_ui;
QMap<QString, LtsLicence::Licence> m_licences;
QString m_fileName;
LicenceEdit *m_licenceEdit;
QStandardItemModel *m_licencesModel;
QSortFilterProxyModel *m_filterProxyModel;
CryptState m_cryptState;
};
+48
View File
@@ -0,0 +1,48 @@
/*
* @RDE_HEADER@
* <short description>
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Schröder, SLSE, 2016-07-01
*/
#include "sortfilter.h"
#include <QDateTime>
#include <QStandardItemModel>
SortFilter::SortFilter(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
bool SortFilter::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{
if (source_left.column() != source_right.column())
return QSortFilterProxyModel::lessThan(source_left, source_right);
// Uns interessiert nur column 1 (Zahl, teilweise mit '()') und column 2 (Datum als String)
if (source_left.column() != 1 && source_left.column() != 2)
return QSortFilterProxyModel::lessThan(source_left, source_right);
// die beiden zu vergleichenden QStandardItems holen
QStandardItemModel *srcModel = static_cast<QStandardItemModel *>(sourceModel());
QStandardItem *left = srcModel->item(source_left.row(), source_left.column());
QStandardItem *right = srcModel->item(source_right.row(), source_right.column());
// # an maximalen Lizenzen
if (source_left.column() == 1)
{
int maxCountLeft = left->data().toInt();
int maxCountRight = right->data().toInt();
return maxCountLeft < maxCountRight;
}
// Datum
if (source_left.column() == 2)
{
QDateTime dtLeft = left->data().toDateTime();
QDateTime dtRight = right->data().toDateTime();
return dtLeft < dtRight;
}
return QSortFilterProxyModel::lessThan(source_left, source_right);
}
+23
View File
@@ -0,0 +1,23 @@
/*
* @RDE_HEADER@
* <short description>
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Schröder, SLSE, 2016-07-01
*/
#pragma once
#include <QSortFilterProxyModel>
class SortFilter : public QSortFilterProxyModel
{
Q_OBJECT
public:
SortFilter(QObject *parent = nullptr);
protected:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override final;
};
+126
View File
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LicenceEdit</class>
<widget class="NGLDialog" name="LicenceEdit">
<property name="windowTitle">
<string>Licence Data</string>
</property>
<property name="title" stdset="0">
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="8" column="0" colspan="3">
<widget class="NGLDialogButtonBox" name="nglDialogButtonBox">
<property name="standardButtons">
<set>NGLStandardButton::Cancel|NGLStandardButton::Ok</set>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QSpinBox" name="sbMaxCount">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QTimeEdit" name="timeEdit">
<property name="dateTime">
<datetime>
<hour>0</hour>
<minute>0</minute>
<second>0</second>
<year>2000</year>
<month>1</month>
<day>1</day>
</datetime>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<widget class="QCheckBox" name="chbIgnoreExpiration">
<property name="text">
<string>Ignore Expiration</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbxName">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbxExpiry">
<property name="text">
<string>Expiry:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbxCount">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>Count:</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QCheckBox" name="chbIgnoreCount">
<property name="text">
<string>Ignore Count</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDateEdit" name="dateEdit">
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="leName"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>NGLDialogButtonBox</class>
<extends>QWidget</extends>
<header>nglwidgets/ngldialogbuttonbox.h</header>
</customwidget>
<customwidget>
<class>NGLDialog</class>
<extends>QDialog</extends>
<header>nglwidgets/ngldialog.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>leName</tabstop>
<tabstop>sbMaxCount</tabstop>
<tabstop>chbIgnoreCount</tabstop>
<tabstop>dateEdit</tabstop>
<tabstop>timeEdit</tabstop>
<tabstop>chbIgnoreExpiration</tabstop>
<tabstop>nglDialogButtonBox</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
+145
View File
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>816</width>
<height>543</height>
</rect>
</property>
<property name="windowTitle">
<string>Licence Editor</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonIconOnly</enum>
</property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Encryption key:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leEncKey"/>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pbResetKey">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QTableView" name="tvContent">
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>true</bool>
</attribute>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="NGLDialogButtonBox" name="nglDialogButtonBox" native="true">
<property name="standardButtons">
<set>NGLStandardButton::Add|NGLStandardButton::Edit|NGLStandardButton::Remove|NGLStandardButton::Reset</set>
</property>
<property name="m_bLineVisible" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>816</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>Fi&amp;le</string>
</property>
<addaction name="actionOpen"/>
<addaction name="separator"/>
<addaction name="actionSave"/>
<addaction name="actionSave_As"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<addaction name="menuFile"/>
</widget>
<action name="actionExit">
<property name="text">
<string>&amp;Exit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionOpen">
<property name="text">
<string>&amp;Open</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="actionSave">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Save</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionSave_As">
<property name="text">
<string>Sa&amp;ve As ...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+S</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>NGLDialogButtonBox</class>
<extends>QWidget</extends>
<header>nglwidgets/ngldialogbuttonbox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>leEncKey</tabstop>
<tabstop>pbResetKey</tabstop>
<tabstop>tvContent</tabstop>
</tabstops>
<resources/>
<connections/>
<slots>
<slot>oeffnenClicked()</slot>
</slots>
</ui>