2019-04-01 10:43:36 +02:00
|
|
|
#include "localimportpage.h"
|
2019-04-07 20:14:10 +02:00
|
|
|
#include "ui_localimportpage.h"
|
2019-04-01 10:43:36 +02:00
|
|
|
|
|
|
|
|
#include <QHostInfo>
|
2019-04-07 20:14:10 +02:00
|
|
|
#include <QDate>
|
2019-04-01 10:43:36 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QStringBuilder>
|
|
|
|
|
|
|
|
|
|
#include "importwizard.h"
|
|
|
|
|
|
|
|
|
|
LocalImportPage::LocalImportPage(QWidget *parent) :
|
2019-04-07 20:14:10 +02:00
|
|
|
QWizardPage(parent),
|
|
|
|
|
m_ui(std::make_unique<Ui::LocalImportPage>())
|
2019-04-01 10:43:36 +02:00
|
|
|
{
|
2019-04-07 20:14:10 +02:00
|
|
|
m_ui->setupUi(this);
|
2019-04-01 10:43:36 +02:00
|
|
|
|
2019-04-07 20:14:10 +02:00
|
|
|
setCommitPage(true);
|
2019-04-01 10:43:36 +02:00
|
|
|
|
2019-04-07 20:14:10 +02:00
|
|
|
m_ui->lineEditHost->setText(QHostInfo::localHostName());
|
|
|
|
|
m_ui->dateEdit->setDate(QDate::currentDate());
|
|
|
|
|
m_ui->comboBoxTimestamp->addItem(tr("Without milliseconds"), "HH:mm:ss");
|
|
|
|
|
m_ui->comboBoxTimestamp->addItem(tr("With milliseconds"), "HH:mm:ss.zzz");
|
2019-04-01 10:43:36 +02:00
|
|
|
|
2019-04-07 20:14:10 +02:00
|
|
|
m_ui->listView->setModel(&m_model);
|
2019-04-01 10:43:36 +02:00
|
|
|
|
2019-04-07 20:14:10 +02:00
|
|
|
connect(&m_model, &ChecklistModel::dataChanged, this, &LocalImportPage::updateSummary);
|
2019-04-01 10:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-07 20:14:10 +02:00
|
|
|
LocalImportPage::~LocalImportPage() = default;
|
|
|
|
|
|
2019-04-01 10:43:36 +02:00
|
|
|
int LocalImportPage::nextId() const
|
|
|
|
|
{
|
|
|
|
|
return int(ImportWizard::Pages::ImportProgress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalImportPage::initializePage()
|
|
|
|
|
{
|
|
|
|
|
m_result = wizard()->property("result").value<ScanResult>();
|
|
|
|
|
|
|
|
|
|
Q_ASSERT(m_result.count() == 1);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto processes = m_result.values().first().keys();
|
|
|
|
|
processes.sort();
|
|
|
|
|
m_model.setItems(processes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateSummary();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LocalImportPage::validatePage()
|
|
|
|
|
{
|
|
|
|
|
auto result = filterResult(m_result);
|
|
|
|
|
|
|
|
|
|
if (scanResultEmpty(result))
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("No files to import!"), tr("No files to import!"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_ASSERT(result.count() == 1);
|
|
|
|
|
|
|
|
|
|
auto host = result.values().first();
|
|
|
|
|
for (auto iter = host.begin(); iter != host.end(); iter++)
|
|
|
|
|
{
|
|
|
|
|
auto &dates = iter.value();
|
|
|
|
|
Q_ASSERT(dates.count() == 1);
|
|
|
|
|
|
|
|
|
|
const auto logfile = dates.values().first();
|
|
|
|
|
dates.clear();
|
2019-04-07 20:14:10 +02:00
|
|
|
dates.insert(m_ui->dateEdit->date(), logfile);
|
2019-04-01 10:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.clear();
|
2019-04-07 20:14:10 +02:00
|
|
|
result.insert(m_ui->lineEditHost->text(), host);
|
2019-04-01 10:43:36 +02:00
|
|
|
|
|
|
|
|
wizard()->setProperty("result", QVariant::fromValue(result));
|
2019-04-07 20:14:10 +02:00
|
|
|
wizard()->setProperty("timeFormat", m_ui->comboBoxTimestamp->currentData().toString());
|
2019-04-01 10:43:36 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalImportPage::updateSummary()
|
|
|
|
|
{
|
|
|
|
|
if (m_result.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const auto result = filterResult(m_result);
|
|
|
|
|
|
|
|
|
|
int logFiles { 0 };
|
|
|
|
|
qint64 totalSize { 0 };
|
|
|
|
|
|
|
|
|
|
for (auto hostsIter = result.constBegin(); hostsIter != result.constEnd(); hostsIter++)
|
|
|
|
|
for (auto processesIter = hostsIter.value().constBegin(); processesIter != hostsIter.value().constEnd(); processesIter++)
|
|
|
|
|
for (auto datesIter = processesIter.value().constBegin(); datesIter != processesIter.value().constEnd(); datesIter++)
|
|
|
|
|
{
|
|
|
|
|
logFiles++;
|
|
|
|
|
totalSize += datesIter.value().filesize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString sizeStr;
|
|
|
|
|
for (const QString prefix : { "K", "M", "G", "T" })
|
|
|
|
|
{
|
|
|
|
|
if (totalSize > 1024)
|
|
|
|
|
{
|
|
|
|
|
totalSize /= 1024;
|
|
|
|
|
sizeStr = QString::number(totalSize) % prefix;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-07 20:14:10 +02:00
|
|
|
m_ui->labelSummary->setText(tr("Filters match %0 files (%1B)").arg(logFiles).arg(sizeStr));
|
2019-04-01 10:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScanResult LocalImportPage::filterResult(ScanResult result) const
|
|
|
|
|
{
|
2019-04-07 18:20:01 +02:00
|
|
|
const auto processes = m_model.enabledTexts().toSet();
|
2019-04-01 10:43:36 +02:00
|
|
|
|
|
|
|
|
for (auto hostsIter = result.begin(); hostsIter != result.end(); hostsIter++)
|
|
|
|
|
{
|
|
|
|
|
for (auto processesIter = hostsIter.value().begin(); processesIter != hostsIter.value().end(); )
|
|
|
|
|
{
|
|
|
|
|
if (processes.contains(processesIter.key()))
|
|
|
|
|
processesIter++;
|
|
|
|
|
else
|
|
|
|
|
processesIter = hostsIter.value().erase(processesIter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|