Skip to content

Commit

Permalink
Refactor Mainwindow::init()
Browse files Browse the repository at this point in the history
  • Loading branch information
d authored and d committed Mar 24, 2024
1 parent defa2e5 commit 2839044
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 93 deletions.
198 changes: 108 additions & 90 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,28 +289,8 @@ void MainWindow::setWindowSize(const QSize &_size)
logEvent(Q_FUNC_INFO, "END", Debug);
}

void MainWindow::init()
void MainWindow::checkDebugFile()
{
//qDebug() << Q_FUNC_INFO << " - Start - " << (QTime::currentTime()).toString("HH:mm:ss") ;
logLevel = Debug;
logEvent(Q_FUNC_INFO, "Start", Debug);
if (!QDir::setCurrent ( util->getHomeDir () )){
QDir d1(util->getHomeDir ());
if (d1.mkdir(util->getHomeDir ()))
{
if (!QDir::setCurrent ( util->getHomeDir () ))
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setWindowTitle(tr("KLog - KLog folder not found"));
QString aux = tr("It was not possible to define the KLog folder. Some functions may not work properly!");
msgBox.setText(aux);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
}
}
QFile debugFile(util->getDebugLogFile());
if (!debugFile.open(QIODevice::WriteOnly | QIODevice::Text)) /* Flawfinder: ignore */
{
Expand All @@ -328,6 +308,38 @@ void MainWindow::init()
debugFile.close();
logEvent(Q_FUNC_INFO, "KLog started!", Debug);
}
}

void MainWindow::checkHomeDir()
{
if (!QDir::setCurrent ( util->getHomeDir () )){
QDir d1(util->getHomeDir ());
if (d1.mkdir(util->getHomeDir ()))
{
if (!QDir::setCurrent ( util->getHomeDir () ))
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setWindowTitle(tr("KLog - KLog folder not found"));
QString aux = tr("It was not possible to define the KLog folder. Some functions may not work properly!");
msgBox.setText(aux);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
}
}
}

void MainWindow::init()
{
//qDebug() << Q_FUNC_INFO << " - Start - " << (QTime::currentTime()).toString("HH:mm:ss") ;
logLevel = Debug;
logEvent(Q_FUNC_INFO, "Start", Debug);
checkHomeDir();


checkDebugFile();

//qDebug() << Q_FUNC_INFO << " - 00" ;
util->setLongPrefixes(dataProxy->getLongPrefixes());
Expand Down Expand Up @@ -453,7 +465,6 @@ void MainWindow::init()
selectedYear = (dateTime->currentDateTime()).date().year();
loggWinAct->setShortcut(Qt::CTRL | Qt::Key_L);


palRed.setColor(QPalette::Text, Qt::red);
palBlack.setColor(QPalette::Text, Qt::black);

Expand All @@ -472,65 +483,9 @@ void MainWindow::init()
newOneColor.setNamedColor("green");
#endif





//qDebug() << Q_FUNC_INFO << " - 60" << (QTime::currentTime()).toString("HH:mm:ss") ;
bool existingData = QFile::exists(util->getKLogDBFile());
//qDebug() << Q_FUNC_INFO << " - 60.1" ;
ctyDatFile = util->getCTYFile();
//qDebug() << Q_FUNC_INFO << " - 60.2" ;
if (!existingData)
{
//qDebug() << Q_FUNC_INFO << " - 61" ;
world->create(ctyDatFile);
//qDebug() << Q_FUNC_INFO << " - 62" ;
}
else if (!world->hasSpecialEntities())
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);

msgBox.setWindowTitle(tr("KLog - CTY.dat update"));
msgBox.setText(tr("KLog needs to update the Entities database."));
msgBox.setDetailedText(tr("You can update the entities database in Tools->Update cty.csv"));
msgBox.setInformativeText(tr("Do you want to update now?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();

switch (ret)
{
case QMessageBox::Yes :
slotUpdateCTYDAT();
break;
default:
break;
}
//qDebug() << Q_FUNC_INFO << " - 69" << (QTime::currentTime()).toString("HH:mm:ss") ;
}

checkExistingData();
readSettingsFile();
//qDebug() << Q_FUNC_INFO << " - 70" << (QTime::currentTime()).toString("HH:mm:ss") ;

//qDebug() << Q_FUNC_INFO << " - Reading config file" ;
if (util->fileExists (util->getCfgFile ()))
{
UpdateSettings settingsUpdate;
if (settingsUpdate.updateFile ())
{
UpdateSettings settingsUpdate;
if (settingsUpdate.updateFile ())
{
//configured = loadSettings ();
}
configured = loadSettings ();
}
}

QSettings settings(util->getCfgFile (), QSettings::IniFormat);
settings.setValue ("Version", softwareVersion);

mapWindow->init();

//qDebug() << Q_FUNC_INFO << " - 71" << (QTime::currentTime()).toString("HH:mm:ss") ;
Expand All @@ -555,16 +510,8 @@ void MainWindow::init()
dxClusterWidget->setCurrentLog(currentLog);

//qDebug() << Q_FUNC_INFO << " - 80" << (QTime::currentTime()).toString("HH:mm:ss") ;
//qDebug() << "MainWindow::Init: calling Software update ..." << (QTime::currentTime()).toString("HH:mm:ss") ;

if (checkNewVersions)
{//reportInfo
if (reportInfo)
{
softUpdate->addCall(stationCallsign);
}
softUpdate->needToUpdate();
}
//qDebug() << Q_FUNC_INFO << ": calling Software update ..." << (QTime::currentTime()).toString("HH:mm:ss") ;
checkVersions();

//qDebug() << Q_FUNC_INFO << " - 90" << (QTime::currentTime()).toString("HH:mm:ss") ;
currentBandShown = dataProxy->getIdFromBandName(mainQSOEntryWidget->getBand());
Expand Down Expand Up @@ -596,6 +543,77 @@ void MainWindow::init()
logEvent(Q_FUNC_INFO, "END", Debug);
}

void MainWindow::checkExistingData()
{
//qDebug() << Q_FUNC_INFO << " - " << (QTime::currentTime()).toString("HH:mm:ss") ;
bool existingData = QFile::exists(util->getKLogDBFile());
//qDebug() << Q_FUNC_INFO << " - 1" ;
ctyDatFile = util->getCTYFile();
//qDebug() << Q_FUNC_INFO << " - 2" ;
if (!existingData)
{
//qDebug() << Q_FUNC_INFO << " - 3" ;
world->create(ctyDatFile);
//qDebug() << Q_FUNC_INFO << " - 4" ;
}
else if (!world->hasSpecialEntities())
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);

msgBox.setWindowTitle(tr("KLog - CTY.dat update"));
msgBox.setText(tr("KLog needs to update the Entities database."));
msgBox.setDetailedText(tr("You can update the entities database in Tools->Update cty.csv"));
msgBox.setInformativeText(tr("Do you want to update now?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();

switch (ret)
{
case QMessageBox::Yes :
slotUpdateCTYDAT();
break;
default:
break;
}
//qDebug() << Q_FUNC_INFO << " - 7" << (QTime::currentTime()).toString("HH:mm:ss") ;
}
}

void MainWindow::readSettingsFile()
{
//qDebug() << Q_FUNC_INFO << " - 70" << (QTime::currentTime()).toString("HH:mm:ss") ;

if (util->fileExists (util->getCfgFile ()))
{
UpdateSettings settingsUpdate;
if (settingsUpdate.updateFile ())
{
UpdateSettings settingsUpdate;
if (settingsUpdate.updateFile ())
{
//configured = loadSettings ();
}
configured = loadSettings ();
}
}

QSettings settings(util->getCfgFile (), QSettings::IniFormat);
settings.setValue ("Version", softwareVersion);
}

void MainWindow::checkVersions()
{
if (checkNewVersions)
{
if (reportInfo)
{
softUpdate->addCall(stationCallsign);
}
softUpdate->needToUpdate();
}
}

void MainWindow::createActionsCommon(){
// Functional widgets connections
Expand Down
6 changes: 5 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,11 @@ private slots:

private:
//void setWidgetsOrder();

void checkDebugFile(); // Refactored from init()
void checkExistingData(); // Refactored from init()
void readSettingsFile(); // Refactored from init()
void checkVersions(); // Refactored from init()
void checkHomeDir(); // Refactored from init()
void startServices();
void backupCurrentQSO();
void restoreCurrentQSO(const bool restoreConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/showerrordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void ShowErrorDialog::slotAcceptButtonClicked()

void ShowErrorDialog::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {

switch (event->key())
{
break;

default:
Expand Down

0 comments on commit 2839044

Please sign in to comment.