<commit_before>#include "tarsnapaccount.h"
#include "debug.h"
#include "utils.h"

#include <QMessageBox>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QSettings>
#include <QTableWidget>

#define URL_ACTIVITY                                                           \
    "https://www.tarsnap.com/"                                                 \
    "manage.cgi?address=%1&password=%2&action=activity&format=csv"
#define URL_MACHINE_ACTIVITY                                                   \
    "https://www.tarsnap.com/"                                                 \
    "manage.cgi?address=%1&password=%2&action=subactivity&mid=%3&format=csv"

TarsnapAccount::TarsnapAccount(QWidget *parent) : QDialog(parent), _nam(this)
{
    _ui.setupUi(this);
    setWindowFlags((windowFlags() | Qt::CustomizeWindowHint) &
                   ~Qt::WindowMaximizeButtonHint);
    connect(_ui.passwordLineEdit, &QLineEdit::textEdited, this, [&]() {
        _ui.loginButton->setEnabled(!_ui.passwordLineEdit->text().isEmpty());
    });
}

TarsnapAccount::~TarsnapAccount()
{
}

void TarsnapAccount::getAccountInfo(bool displayActivity,
                                    bool displayMachineActivity)
{
    QSettings settings;
    _user    = settings.value("tarsnap/user", "").toString();
    _machine = settings.value("tarsnap/machine", "").toString();
    if(Utils::tarsnapVersionMinimum("1.0.37"))
    {
        emit getKeyId(settings.value("tarsnap/key", "").toString());
    }
    else
    {
        QMessageBox::warning(
            this, tr("Warning"),
            tr("You need Tarsnap CLI utils version 1.0.37 to "
               "be able to fetch machine activity. "
               "You have version %1.")
                .arg(settings.value("tarsnap/version", "").toString()));
    }
    if(_user.isEmpty() || _machine.isEmpty())
    {
        QMessageBox::warning(this, tr("Warning"),
                             tr("Tarsnap user and machine name must be set."));
        return;
    }
    _ui.textLabel->setText(tr("Type password for account %1:").arg(_user));
    _ui.loginButton->setEnabled(false);
    if(exec() == QDialog::Rejected)
        return;
    QString getActivity(URL_ACTIVITY);
    getActivity = getActivity.arg(QString(QUrl::toPercentEncoding(_user)),
                                  QString(QUrl::toPercentEncoding(
                                      _ui.passwordLineEdit->text())));
    QNetworkReply *activityReply = tarsnapRequest(getActivity);
    connect(activityReply, &QNetworkReply::finished, [=]() {<commit_msg>Fix issue with warning messages popup placement.<commit_after>#include "tarsnapaccount.h"
#include "debug.h"
#include "utils.h"

#include <QMessageBox>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QSettings>
#include <QTableWidget>

#define URL_ACTIVITY                                                           \
    "https://www.tarsnap.com/"                                                 \
    "manage.cgi?address=%1&password=%2&action=activity&format=csv"
#define URL_MACHINE_ACTIVITY                                                   \
    "https://www.tarsnap.com/"                                                 \
    "manage.cgi?address=%1&password=%2&action=subactivity&mid=%3&format=csv"

TarsnapAccount::TarsnapAccount(QWidget *parent) : QDialog(parent), _nam(this)
{
    _ui.setupUi(this);
    setWindowFlags((windowFlags() | Qt::CustomizeWindowHint) &
                   ~Qt::WindowMaximizeButtonHint);
    connect(_ui.passwordLineEdit, &QLineEdit::textEdited, this, [&]() {
        _ui.loginButton->setEnabled(!_ui.passwordLineEdit->text().isEmpty());
    });
}

TarsnapAccount::~TarsnapAccount()
{
}

void TarsnapAccount::getAccountInfo(bool displayActivity,
                                    bool displayMachineActivity)
{
    QSettings settings;
    _user    = settings.value("tarsnap/user", "").toString();
    _machine = settings.value("tarsnap/machine", "").toString();
    if(Utils::tarsnapVersionMinimum("1.0.37"))
    {
        emit getKeyId(settings.value("tarsnap/key", "").toString());
    }
    else
    {
        QMessageBox::warning(this->parentWidget(), tr("Warning"),
                             tr("You need Tarsnap CLI utils version 1.0.37 to "
                                "be able to fetch machine activity. "
                                "You have version %1.")
                             .arg(settings.value("tarsnap/version", "")
                                  .toString()));
    }
    if(_user.isEmpty() || _machine.isEmpty())
    {
        QMessageBox::warning(this->parentWidget(), tr("Warning"),
                             tr("Tarsnap user and machine name must be set."));
        return;
    }
    _ui.textLabel->setText(tr("Type password for account %1:").arg(_user));
    _ui.loginButton->setEnabled(false);
    if(exec() == QDialog::Rejected)
        return;
    QString getActivity(URL_ACTIVITY);
    getActivity = getActivity.arg(QString(QUrl::toPercentEncoding(_user)),
                                  QString(QUrl::toPercentEncoding(
                                      _ui.passwordLineEdit->text())));
    QNetworkReply *activityReply = tarsnapRequest(getActivity);
    connect(activityReply, &QNetworkReply::finished, [=]() {
{'fraction_non_alphanumeric': 0.13647548741245505, 'fraction_numerical': 0.0056785917092561046, 'mean_word_length': 2.1489868891537545, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4475386', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1459, 'n_words': 227}