<commit_before>///////////////////////////////////////////////////////////////////////////////
//
// CoinVault
//
// txactions.h
//
// Copyright (c) 2013-2014 <NAME>
//
// All Rights Reserved.

#include "txactions.h"

#include "txmodel.h"
#include "txview.h"
#include "accountmodel.h"

#include "rawtxdialog.h"
#include "signaturedialog.h"

#include "docdir.h"

#include <CoinDB/SynchedVault.h>

#include <QAction>
#include <QMenu>
#include <QUrl>
#include <QDesktopServices>
#include <QMessageBox>
#include <QApplication>
#include <QClipboard>
#include <QFileDialog>

#include <logger/logger.h>

#include <fstream>

TxActions::TxActions(TxModel* txModel, TxView* txView, AccountModel* accountModel, CoinDB::SynchedVault* synchedVault)
    : m_txModel(txModel), m_txView(txView), m_accountModel(accountModel), m_synchedVault(synchedVault), currentRow(-1)
{
    createActions();
    createMenus();
    connect(m_txView->selectionModel(), &QItemSelectionModel::currentChanged, this, &TxActions::updateCurrentTx);
}

void TxActions::updateCurrentTx(const QModelIndex& current, const QModelIndex& /*previous*/)
{
    currentRow = current.row();
    if (m_txModel && currentRow != -1)
    {
        QStandardItem* typeItem = m_txModel->item(currentRow, 2);
        signaturesAction->setEnabled(typeItem->text() == tr("Send"));

        typeItem = m_txModel->item(currentRow, 6);
        int type = typeItem->data(Qt::UserRole).toInt();
        if (type == CoinDB::Tx::UNSIGNED) {
            signTxAction->setEnabled(true);
        }
        else {
            signTxAction->setEnabled(false);
        }

        if (type == CoinDB::Tx::UNSENT) {
            sendTxAction->setText(tr("Send Transaction"));
            sendTxAction->setEnabled(m_synchedVault && m_synchedVault->isConnected());
        }
        else {
            sendTxAction->setText(tr("Resend Transaction"));
            sendTxAction->setEnabled(m_synchedVault && m_synchedVault->isConnected() && typeItem->text() == "0");
        }

        if (type == CoinDB::Tx::PROPAGATED || type == CoinDB::Tx::CONFIRMED) {
            viewTxOnWebAction->setEnabled(true);
        }
        else {
            viewTxOnWebAction->setEnabled(false);
        }

        exportTxToFileAction->setEnabled(true);
        copyTxHashToClipboardAction->setEnabled(true);
        copyRawTxToClipboardAction->setEnabled(true);
        saveRawTxToFileAction->setEnabled(true);
        viewRawTxAction->setEnabled(true);
        deleteTxAction->setEnabled(true);
    }
    else {
        signTxAction->setEnabled(false);
        sendTxAction->setEnabled(false);<commit_msg>Only allow deleting transactions that are not confirmed.<commit_after>///////////////////////////////////////////////////////////////////////////////
//
// CoinVault
//
// txactions.h
//
// Copyright (c) 2013-2014 <NAME>
//
// All Rights Reserved.

#include "txactions.h"

#include "txmodel.h"
#include "txview.h"
#include "accountmodel.h"

#include "rawtxdialog.h"
#include "signaturedialog.h"

#include "docdir.h"

#include <CoinDB/SynchedVault.h>

#include <QAction>
#include <QMenu>
#include <QUrl>
#include <QDesktopServices>
#include <QMessageBox>
#include <QApplication>
#include <QClipboard>
#include <QFileDialog>

#include <logger/logger.h>

#include <fstream>

TxActions::TxActions(TxModel* txModel, TxView* txView, AccountModel* accountModel, CoinDB::SynchedVault* synchedVault)
    : m_txModel(txModel), m_txView(txView), m_accountModel(accountModel), m_synchedVault(synchedVault), currentRow(-1)
{
    createActions();
    createMenus();
    connect(m_txView->selectionModel(), &QItemSelectionModel::currentChanged, this, &TxActions::updateCurrentTx);
}

void TxActions::updateCurrentTx(const QModelIndex& current, const QModelIndex& /*previous*/)
{
    currentRow = current.row();
    if (m_txModel && currentRow != -1)
    {
        QStandardItem* typeItem = m_txModel->item(currentRow, 2);
        signaturesAction->setEnabled(typeItem->text() == tr("Send"));

        typeItem = m_txModel->item(currentRow, 6);
        int type = typeItem->data(Qt::UserRole).toInt();
        if (type == CoinDB::Tx::UNSIGNED) {
            signTxAction->setEnabled(true);
        }
        else {
            signTxAction->setEnabled(false);
        }

        if (type == CoinDB::Tx::UNSENT) {
            sendTxAction->setText(tr("Send Transaction"));
            sendTxAction->setEnabled(m_synchedVault && m_synchedVault->isConnected());
        }
        else {
            sendTxAction->setText(tr("Resend Transaction"));
            sendTxAction->setEnabled(m_synchedVault && m_synchedVault->isConnected() && typeItem->text() == "0");
        }

        exportTxToFileAction->setEnabled(true);
        copyTxHashToClipboardAction->setEnabled(true);
        copyRawTxToClipboardAction->setEnabled(true);
        saveRawTxToFileAction->setEnabled(true);
        viewRawTxAction->setEnabled(true);
        viewTxOnWebAction->setEnabled(type == CoinDB::Tx::PROPAGATED || type == CoinDB::Tx::CONFIRMED);
        deleteTxAction->setEnabled(type != CoinDB::Tx::CONFIRMED);
    }
    else {
        signTxAction->setEnabled(false);
        sendTxAction->setEnabled(false);
{'fraction_non_alphanumeric': 0.17084458156575397, 'fraction_numerical': 0.005013497878904744, 'mean_word_length': 3.1595829991980753, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5478276', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1602, 'n_words': 257}