Pith - wedge_linux
wedge_linux/WedgeData.cpp [8.6 kb]
Modified: 22:03:58 118 026 (15 Jul 026)
10 Days Ago
#include "WedgeData.h"
#include <QDesktopServices>
#include <QFont>
#include <QFormLayout>
#include <QFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QSizePolicy>
#include <QSpacerItem>
#include <QUrl>
#include <QVBoxLayout>
#include <QWidget>

// wedge linux version

static const QString kVersionRemote = "118.026.1";

static QSpacerItem* makeSpacer(int height) {
    return new QSpacerItem(0, height, QSizePolicy::Minimum, QSizePolicy::Fixed);
 }

static QWidget* makeSectionHeader(const QString &title) {
    auto *w = new QWidget();
    auto *h = new QHBoxLayout(w);
    h->setContentsMargins(0, 0, 0, 0);
    h->setSpacing(8);

    auto *label = new QLabel(title);
    label->setStyleSheet("color: #999999; font-size: 8pt;");
    label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    h->addWidget(label);

    auto *hr = new QFrame();
    hr->setFrameShape(QFrame::HLine);
    hr->setFrameShadow(QFrame::Plain);
    hr->setStyleSheet("color: #cccccc; background-color: #cccccc;");
    hr->setFixedHeight(1);
    hr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    h->addWidget(hr, 1);

    return w;
}

DataWindow::DataWindow(const NoteData &data, QWidget *parent)
    : QDialog(parent), originalData(data) {

    setWindowTitle("");
    setFixedWidth(333);

    auto *layout = new QVBoxLayout(this);
    auto *form = new QFormLayout();

    form->setVerticalSpacing(7);
    form->setHorizontalSpacing(15);

    // excryption

    form->addRow(makeSectionHeader("Encryption"));
    form->addItem(makeSpacer(2));

    phraseEdit = new QLineEdit();
    phraseEdit->setEchoMode(QLineEdit::Password);

    encryptBtn = new QPushButton("Encrypt");
    decryptBtn = new QPushButton("Decrypt");
    encryptBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    decryptBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    QHBoxLayout *cryptoLayout = new QHBoxLayout();
    cryptoLayout->setSpacing(8);
    cryptoLayout->addWidget(encryptBtn);
    cryptoLayout->addWidget(decryptBtn);

    form->addRow("Phrase", phraseEdit);
    form->addRow("", cryptoLayout);

    connect(encryptBtn, &QPushButton::clicked, [this]() {
        if (!phraseEdit->text().isEmpty()) {
            emit encryptRequested(phraseEdit->text());
        }
    });

    connect(decryptBtn, &QPushButton::clicked, [this]() {
        if (!phraseEdit->text().isEmpty()) {
            emit decryptRequested(phraseEdit->text());
        }
    });

    form->addItem(makeSpacer(2));

    // sync

    form->addRow(makeSectionHeader("Sync"));
    form->addItem(makeSpacer(2));

    routeCombo = new QComboBox(this);
    routeCombo->addItems(QStringList() << "USB" << "WIFI");
    routeCombo->setCurrentIndex(data.networkRoute);

    roleCombo = new QComboBox(this);
    roleCombo->addItem("Client");
    roleCombo->setCurrentIndex(data.networkRole);

    QString modifiedStr = (data.lastModified > 0) ? ConfigManager::formatOtc(data.lastModified) : "Never";
    QString syncedStr = (data.lastSynced > 0) ? ConfigManager::formatOtc(data.lastSynced) : "Never";

    QLabel *modifiedLabel = new QLabel(modifiedStr, this);
    modifiedLabel->setStyleSheet("font-family: monospace; font-size: 8pt; padding-top: 4px; padding-bottom: 2px;");
    QLabel *syncedLabel = new QLabel(syncedStr, this);
    syncedLabel->setStyleSheet("font-family: monospace; font-size: 8pt; padding-top: 2px; padding-bottom: 2px;");

    netStatusValLabel = new QLabel("Disconnected", this);
    netStatusValLabel->setStyleSheet("font-family: monospace; font-size: 8pt; padding-top: 2px; padding-bottom: 4px;");

    connectBtn = new QPushButton("Connect", this);
    syncBtn = new QPushButton("Send", this);
    connectBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    syncBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    QHBoxLayout *netActionLayout = new QHBoxLayout();
    netActionLayout->setSpacing(8);
    netActionLayout->addWidget(connectBtn);
    netActionLayout->addWidget(syncBtn);

    passKeyEdit = new QLineEdit(this);
    passKeyEdit->setText(data.passKey.isEmpty() ? "wedge03569" : data.passKey);

    ipEdit = new QLineEdit(this);
    ipEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    ipEdit->setPlaceholderText("192.168.1.255");
    if (!data.ipAddress.isEmpty()) {
        ipEdit->setText(data.ipAddress);
    }

    form->addRow("Route", routeCombo);
    form->addRow("Role", roleCombo);
    form->addRow("Address", ipEdit);
    form->addRow("Pass Key", passKeyEdit);
    form->addRow("Modified", modifiedLabel);
    form->addRow("Synced", syncedLabel);
    form->addRow("Status", netStatusValLabel);
    form->addRow("", netActionLayout);

    form->addItem(makeSpacer(2));

    // calendar header

    form->addRow(makeSectionHeader("Calendar"));
    form->addItem(makeSpacer(2));

    headerEdit = new QLineEdit(this);
    headerEdit->setText(data.headerFormat.isEmpty() ? "otcDay EEE dd MMM*" : data.headerFormat);

    form->addRow("Header", headerEdit);

    layout->addLayout(form);

    form->addItem(makeSpacer(1));

    // data

    form->addRow(makeSectionHeader("Data"));
    form->addItem(makeSpacer(2));

    // int totalChars = data.content.length();
    // int totalLines = data.content.isEmpty() ? 0 : data.content.count('\n') + 1;
    // QLabel *charsLabel = new QLabel(QString::number(totalChars), this);
    // QLabel *linesLabel = new QLabel(QString::number(totalLines), this);
    // charsLabel->setStyleSheet("color: #000000; font-family: monospace; font-size: 8pt;");
    // linesLabel->setStyleSheet("color: #000000; font-family: monospace; font-size: 8pt;");

    qint64 backupTime = ConfigManager::lastBackupTime();
    QString archivedStr = (backupTime > 0) ? ConfigManager::formatOtc(backupTime) : "n/a";
    QLabel *archiveLabel = new QLabel(archivedStr, this);
    archiveLabel->setStyleSheet("font-family: monospace; font-size: 8pt; padding-top: 2px; padding-bottom: 2px;");

    QLabel *dataLabel = new QLabel("<a style='text-decoration: none; color: #000000; font-family: monospace; font-size: 8pt;' href='conf'>wedge.conf</a>", this);
    dataLabel->setOpenExternalLinks(false);
    dataLabel->setStyleSheet("padding-top: 2px; padding-bottom: 2px;");

    connect(dataLabel, &QLabel::linkActivated, this, [](const QString &link) {
        if (link == "conf") {
            QDesktopServices::openUrl(QUrl::fromLocalFile(ConfigManager::getConfigPath() + "/wedge.conf"));
        }
    });

    QLabel *versionLabel = new QLabel(
        QString("%1 <a style='text-decoration: none; color: #888888; font-family: monospace; font-size: 8pt;' href='https://vgmlr.com/?t=Wedge'>[update]</a>").arg(kVersionRemote),
        this);
    versionLabel->setStyleSheet("font-family: monospace; font-size: 8pt; padding-top: 2px; padding-bottom: 2px;");
    versionLabel->setOpenExternalLinks(true);
    versionLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);

    QLabel *sourceLabel = new QLabel("<a style='text-decoration: none; color: #000000; font-family: monospace; font-size: 8pt;' href='https://vgmlr.com/mlwrk'>vgmlr.com/mlwrk</a>", this);
    sourceLabel->setOpenExternalLinks(true);
    sourceLabel->setStyleSheet("padding-top: 2px; padding-bottom: 2px;");

    // form->addRow("Characters", charsLabel);
    // form->addRow("Lines", linesLabel);
    form->addRow("Storage", dataLabel);
    form->addRow("Archived", archiveLabel);
    form->addRow("Version", versionLabel);
    form->addRow("Source", sourceLabel);

    form->addItem(makeSpacer(7));

    connect(connectBtn, &QPushButton::clicked, this, [this]() {
        netStatusValLabel->setText("Connecting");
        emit connectRequested(routeCombo->currentIndex(), roleCombo->currentIndex());
    });
    connect(syncBtn, &QPushButton::clicked, this, &DataWindow::syncRequested);

    // save and cancel buttons

    auto *saveBtn = new QPushButton("Save");
    auto *cancelBtn = new QPushButton("Cancel");

    saveBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    cancelBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    auto *actionLayout = new QHBoxLayout();
    actionLayout->setContentsMargins(0, 0, 0, 0);
    actionLayout->setSpacing(8);
    actionLayout->addWidget(saveBtn);
    actionLayout->addWidget(cancelBtn);

    form->addRow("", actionLayout);

    connect(saveBtn, &QPushButton::clicked, this, &QDialog::accept);
    connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);

}

NoteData DataWindow::getUpdatedData() const {
    NoteData data = originalData;
    data.networkRole = roleCombo->currentIndex();
    data.networkRoute = routeCombo->currentIndex();
    data.passKey = passKeyEdit->text();
    data.ipAddress = ipEdit->text();
    data.headerFormat = headerEdit->text();
    return data;
}
Updates
Wedge - Android 126.026
Wedge - Linux 124.026
Shim - Android 117.026
Miter - 114.026
Kerf - Android 112.026
Dev
TVShow (227) 'CSA'
TVShow (228) 'APT'
TVProgram (83) 'BXT'
Miter Update(s)
Peen (Messaging)

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)