summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp56
1 files changed, 44 insertions, 12 deletions
diff --git a/main.cpp b/main.cpp
index 4943f2f0..7d5d6103 100644
--- a/main.cpp
+++ b/main.cpp
@@ -82,12 +82,12 @@ namespace
}
catch (std::exception const& e)
{
- MessageBox::critical_message (nullptr, translate ("main", "Fatal error"), e.what ());
+ MessageBox::critical_message (nullptr, "Fatal error", e.what ());
throw;
}
catch (...)
{
- MessageBox::critical_message (nullptr, translate ("main", "Unexpected fatal error"));
+ MessageBox::critical_message (nullptr, "Unexpected fatal error");
throw;
}
}
@@ -97,7 +97,7 @@ namespace
int main(int argc, char *argv[])
{
// ### Add timestamps to all debug messages
-// qSetMessagePattern ("[%{time yyyyMMdd HH:mm:ss.zzz t} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{message}");
+ // qSetMessagePattern ("[%{time yyyyMMdd HH:mm:ss.zzz t} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{message}");
init_random_seed ();
@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
// Multiple instances communicate with jt9 via this
QSharedMemory mem_jt9;
- ExceptionCatchingApplication a(argc, argv);
+ QApplication a(argc, argv);
try
{
// qDebug () << "+++++++++++++++++++++++++++ Resources ++++++++++++++++++++++++++++";
@@ -323,6 +323,7 @@ int main(int argc, char *argv[])
db.exec ("PRAGMA locking_mode=EXCLUSIVE");
int result;
+ auto const& original_style_sheet = a.styleSheet ();
do
{
#if WSJT_QDEBUG_TO_FILE
@@ -352,14 +353,42 @@ int main(int argc, char *argv[])
// Multiple instances: use rig_name as shared memory key
mem_jt9.setKey(a.applicationName ());
- if(!mem_jt9.attach()) {
- if (!mem_jt9.create(sizeof(struct dec_data))) {
+ // try and shut down any orphaned jt9 process
+ for (int i = 3; i; --i) // three tries to close old jt9
+ {
+ if (mem_jt9.attach ()) // shared memory presence implies
+ // orphaned jt9 sub-process
+ {
+ dec_data_t * dd = reinterpret_cast<dec_data_t *> (mem_jt9.data());
+ mem_jt9.lock ();
+ dd->ipc[1] = 999; // tell jt9 to shut down
+ mem_jt9.unlock ();
+ mem_jt9.detach (); // start again
+ }
+ else
+ {
+ break; // good to go
+ }
+ QThread::sleep (1); // wait for jt9 to end
+ }
+ if (!mem_jt9.attach ())
+ {
+ if (!mem_jt9.create (sizeof (dec_data)))
+ {
+ splash.hide ();
+ MessageBox::critical_message (nullptr, a.translate ("main", "Shared memory error"),
+ a.translate ("main", "Unable to create shared memory segment"));
+ throw std::runtime_error {"Shared memory error"};
+ }
+ qDebug () << "shmem size:" << mem_jt9.size ();
+ }
+ else
+ {
splash.hide ();
- MessageBox::critical_message (nullptr, a.translate ("main", "Shared memory error"),
- a.translate ("main", "Unable to create shared memory segment"));
- throw std::runtime_error {"Shared memory error"};
+ MessageBox::critical_message (nullptr, a.translate ("main", "Sub-process error"),
+ a.translate ("main", "Failed to close orphaned jt9 process"));
+ throw std::runtime_error {"Sub-process error"};
}
- }
mem_jt9.lock ();
memset(mem_jt9.data(),0,sizeof(struct dec_data)); //Zero all decoding params in shared memory
mem_jt9.unlock ();
@@ -387,6 +416,9 @@ int main(int argc, char *argv[])
splash.raise ();
QObject::connect (&a, SIGNAL (lastWindowClosed()), &a, SLOT (quit()));
result = a.exec();
+
+ // ensure config switches start with the right style sheet
+ a.setStyleSheet (original_style_sheet);
}
while (!result && !multi_settings.exit ());
@@ -407,12 +439,12 @@ int main(int argc, char *argv[])
}
catch (std::exception const& e)
{
- MessageBox::critical_message (nullptr, QApplication::translate ("main", "Fatal error"), e.what ());
+ MessageBox::critical_message (nullptr, "Fatal error", e.what ());
std::cerr << "Error: " << e.what () << '\n';
}
catch (...)
{
- MessageBox::critical_message (nullptr, QApplication::translate ("main", "Unexpected fatal error"));
+ MessageBox::critical_message (nullptr, "Unexpected fatal error");
std::cerr << "Unexpected fatal error\n";
throw; // hoping the runtime might tell us more about the exception
}