186 lines
5.6 KiB
C++
186 lines
5.6 KiB
C++
|
/***************************************************************************
|
||
|
|
||
|
miniCash
|
||
|
Copyright © 2013-2022 christoph holzheuer
|
||
|
c.holzheuer@sourceworx.org
|
||
|
|
||
|
This program is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation; either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
***************************************************************************/
|
||
|
|
||
|
|
||
|
#include <QMessageBox>
|
||
|
#include <QPushButton>
|
||
|
#include <QFileDialog>
|
||
|
#include <QFileInfo>
|
||
|
#include <QStandardPaths>
|
||
|
|
||
|
#include <libMiniCash.h>
|
||
|
#include <mcsetupdialog.h>
|
||
|
#include <mcvendorsdialog.h>
|
||
|
|
||
|
#include <ui_mcsetupdialog.h>
|
||
|
|
||
|
/**
|
||
|
* @brief Der Setup-Dialog: Hier werden die Vorgabewerte gesetzt.
|
||
|
*/
|
||
|
|
||
|
MCSetupDialog::MCSetupDialog( QWidget* parent, QSettings* settings )
|
||
|
: QDialog{ parent }, _ui{new Ui::MCSetupDialog}, _settings{ settings }
|
||
|
|
||
|
{
|
||
|
|
||
|
_ui->setupUi( this );
|
||
|
setupDefaults();
|
||
|
|
||
|
// Murx, FIX! das sollte über den Translator gehen
|
||
|
_ui->_buttonBox->button( QDialogButtonBox::Ok )->setText( "Speichern" );
|
||
|
_ui->_buttonBox->button( QDialogButtonBox::Cancel )->setText( "Abbrechen" );
|
||
|
|
||
|
connect( _ui->_buttonReset, SIGNAL( clicked() ), this, SLOT( onReset() ) );
|
||
|
connect( _ui->_buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
|
||
|
connect( _ui->_buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
|
||
|
connect( _ui->_buttonFile, SIGNAL( clicked() ), this, SLOT( onChooseVendorsFile() ) );
|
||
|
connect( _ui->_buttonViewFile, SIGNAL( clicked() ), this, SLOT( onViewVendorsFile() ) );
|
||
|
|
||
|
_ui->_tabWidget->setCurrentIndex( 0 );
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @brief Destruktor.
|
||
|
*/
|
||
|
|
||
|
MCSetupDialog::~MCSetupDialog()
|
||
|
{
|
||
|
delete _ui;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @brief Vorgabewerte ins Form laden
|
||
|
*/
|
||
|
|
||
|
void MCSetupDialog::setupDefaults()
|
||
|
{
|
||
|
// Vorgabewerte setzen
|
||
|
QString driveLetter = _settings->value( miniCash::keyMobileDrive, miniCash::mobileDrive ).toString();
|
||
|
_ui->_driveMobile->addItem( driveLetter );
|
||
|
_ui->_driveMobile->setCurrentText( driveLetter );
|
||
|
_ui->_trProfit->setValue( _settings->value( miniCash::keyProfit, miniCash::profit ).toInt() );
|
||
|
_ui->_selfID->setValue( _settings->value( miniCash::keySelfID, miniCash::selfID ).toInt() );
|
||
|
_ui->_trFooterText->setText( _settings->value( miniCash::keyFooterText ).toString() );
|
||
|
|
||
|
_ui->_buttonViewFile->setEnabled( false );
|
||
|
QString filePath = _settings->value( miniCash::keyAddressFile ).toString();
|
||
|
if( !filePath.isEmpty() )
|
||
|
{
|
||
|
QFileInfo addressFile( filePath );
|
||
|
if( addressFile.exists() )
|
||
|
{
|
||
|
_ui->_addressFile->setText( addressFile.fileName() );
|
||
|
_ui->_buttonViewFile->setEnabled( true );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @brief Setzt alle voreinstellungen zurück auf den jeweiligen Default-Wert.
|
||
|
*/
|
||
|
|
||
|
void MCSetupDialog::onReset()
|
||
|
{
|
||
|
int ret = QMessageBox::warning(this, "miniCash Setup",
|
||
|
tr("Sollen die Voreinstellugen\n"
|
||
|
"neu geladen werden?"),
|
||
|
QMessageBox::Ok | QMessageBox::Cancel,
|
||
|
QMessageBox::Cancel);
|
||
|
|
||
|
if( ret == QMessageBox::Cancel )
|
||
|
return;
|
||
|
|
||
|
_settings->clear();
|
||
|
setupDefaults();
|
||
|
|
||
|
/// neu: wir setzen hier auch schon die network-defaults, weil der dialog
|
||
|
/// jetzt auch von minicash.connect verwendet wird.
|
||
|
|
||
|
_settings->setValue( miniCash::keyIsTcpSender, miniCash::isTcpSender );
|
||
|
_settings->setValue( miniCash::keyReceiverHost, "" );
|
||
|
_settings->setValue( miniCash::keyReceiverPort, miniCash::receiverPort );
|
||
|
_settings->setValue( miniCash::keyIsTcpReceiver, miniCash::isTcpReceiver );
|
||
|
_settings->setValue( miniCash::keyAddressFile, "" );
|
||
|
/// gefährlich
|
||
|
_settings->setValue( miniCash::keyTransCount, "1" );
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
void MCSetupDialog::onChooseVendorsFile()
|
||
|
{
|
||
|
|
||
|
_ui->_buttonViewFile->setEnabled( false );
|
||
|
QString docDir = QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation );
|
||
|
QString filePath = QFileDialog::getOpenFileName( this, tr("Adressdatei"), docDir, tr("CSV Datei (*.csv *.txt)") );
|
||
|
|
||
|
if( !filePath.isEmpty() )
|
||
|
{
|
||
|
_ui->_buttonViewFile->setEnabled( true );
|
||
|
QFileInfo addressFile( filePath );
|
||
|
_settings->setValue( miniCash::keyAddressFile, addressFile.absoluteFilePath() );
|
||
|
_ui->_addressFile->setText( addressFile.fileName() );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void MCSetupDialog::onViewVendorsFile()
|
||
|
{
|
||
|
QString filePath = _settings->value( miniCash::keyAddressFile ).toString();
|
||
|
if( filePath.isEmpty() || !QFileInfo::exists( filePath ) )
|
||
|
return;
|
||
|
|
||
|
MCVendorsDialog( this, filePath ).exec();
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @brief ok gedrückt: geänderte Daten übernehmen
|
||
|
*/
|
||
|
|
||
|
void MCSetupDialog::accept()
|
||
|
{
|
||
|
|
||
|
const QString& mDrive = _ui->_driveMobile->currentText();
|
||
|
const QString& profit = _ui->_trProfit->cleanText();
|
||
|
const QString& prefix = _ui->_selfID->cleanText();
|
||
|
|
||
|
// Murx, FIX! das sollte über den Translator gehen
|
||
|
if( profit.isEmpty() || prefix.isEmpty() )
|
||
|
{
|
||
|
QMessageBox::warning
|
||
|
(
|
||
|
this,
|
||
|
"Eingabefehler",
|
||
|
"Die Felder\n - lokales Laufwerk', 'KassenNr.'\n "
|
||
|
"sowie 'Anteil Kindergarten' müssen belegt sein."
|
||
|
);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
_settings->setValue( miniCash::keyMobileDrive, mDrive );
|
||
|
_settings->setValue( miniCash::keyProfit, profit );
|
||
|
_settings->setValue( miniCash::keySelfID, prefix );
|
||
|
_settings->setValue( miniCash::keyFooterText, _ui->_trFooterText->document()->toPlainText() );
|
||
|
|
||
|
return QDialog::accept();
|
||
|
|
||
|
}
|