Ask confirmation when trying to exit without saving the log
pull/2/head
Stelios Bounanos 2008-10-07 08:41:20 +01:00
rodzic 629014d985
commit 1c9f450f60
1 zmienionych plików z 90 dodań i 108 usunięć

Wyświetl plik

@ -183,6 +183,7 @@ int Hwfall = DEFAULT_HWFALL;
int HNOM = DEFAULT_HNOM;
int WNOM = DEFAULT_WNOM;
bool clean_exit(void);
void cb_init_mode(Fl_Widget *, void *arg);
@ -434,70 +435,6 @@ void cb_mnuSaveMacro(Fl_Menu_*, void*) {
restoreFocus();
}
//bool logging = false;
//void cb_mnuLogFile(Fl_Menu_ *, void *) {
// logging = !logging;
// restoreFocus();
//}
bool clean_exit() {
arq_close();
if (progdefaults.changed == true) {
switch (fl_choice("Save changed configuration before exiting?", "Cancel", "Save", "Don't save")) {
case 0:
return false;
case 1:
progdefaults.saveDefaults();
// fall through
case 2:
break;
}
}
if (macros.changed == true) {
switch (fl_choice("Save changed macros before exiting?", "Cancel", "Save", "Don't save")) {
case 0:
return false;
case 1:
macros.saveMacroFile();
// fall through
case 2:
break;
}
}
if (Maillogfile)
Maillogfile->log_to_file_stop();
if (logfile)
logfile->log_to_file_stop();
if (bSaveFreqList)
saveFreqList();
progStatus.saveLastState();
#if USE_HAMLIB
hamlib_close();
#endif
rigCAT_close();
rigMEM_close();
if (mixer)
mixer->closeMixer();
if (trx_state == STATE_RX || trx_state == STATE_TX || trx_state == STATE_TUNE)
trx_state = STATE_ABORT;
else {
LOG_ERROR("trx in unexpected state %d", trx_state);
exit(1);
}
while (trx_state != STATE_ENDED) {
REQ_FLUSH(GET_THREAD_ID());
MilliSleep(10);
}
return true;
}
void cb_E(Fl_Menu_*, void*) {
fl_digi_main->do_callback();
}
@ -1162,65 +1099,47 @@ void cb_sldrSquelch(Fl_Slider* o, void*) {
restoreFocus();
}
char *zuluTime()
const char *zuluTime()
{
struct tm *tm;
time_t t;
static char logtime[10];
time(&t);
tm = gmtime(&t);
strftime(logtime, sizeof(logtime), "%H%M", tm);
struct tm tm;
static char logtime[5];
if ((t = time(NULL)) != (time_t)-1 && gmtime_r(&t, &tm) &&
strftime(logtime, sizeof(logtime), "%H%M", &tm))
return logtime;
else
return NULL;
}
bool oktoclear = false;
bool oktoclear = true;
void qsoTime_cb(Fl_Widget *b, void *)
{
FL_LOCK_D();
inpTime->value(zuluTime());
FL_UNLOCK_D();
FL_AWAKE_D();
oktoclear = false;
restoreFocus();
}
void clearQSO()
{
FL_LOCK_D();
Fl_Input* in[] = { inpCall, inpName, inpRstIn, inpRstOut,
inpQth, inpNotes, inpLoc, inpAZ };
for (size_t i = 0; i < sizeof(in)/sizeof(*in); i++)
in[i]->value("");
inpTime->value(zuluTime());
inpCall->value("");
inpName->value("");
inpRstIn->value("");
inpRstOut->value("");
inpQth->value("");
inpLoc->value("");
inpAZ->value(""); // WA5ZNU
inpNotes->value("");
FL_UNLOCK_D();
}
void cb_log(Fl_Widget *b, void *)
void cb_log(Fl_Widget*, void*)
{
oktoclear = false;
}
void cb_callsign(Fl_Widget *b, void *)
{
oktoclear = false;
restoreFocus();
}
void qsoClear_cb(Fl_Widget *b, void *)
{
if (oktoclear) {
if (oktoclear || fl_choice("Clear log fields?", "Cancel", "OK", NULL) == 1) {
clearQSO();
FL_AWAKE_D();
} else if (fl_choice ("Clear log fields?", "Cancel", "OK", NULL) == 1) {
clearQSO();
FL_AWAKE_D();
}
oktoclear = true;
}
restoreFocus();
}
@ -1346,6 +1265,75 @@ int default_handler(int event)
return 0;
}
bool clean_exit(void) {
arq_close();
if (progdefaults.changed) {
switch (fl_choice("Save changed configuration before exiting?", "Cancel", "Save", "Don't save")) {
case 0:
return false;
case 1:
progdefaults.saveDefaults();
// fall through
case 2:
break;
}
}
if (!oktoclear) {
switch (fl_choice("Save log before exiting?", "Cancel", "Save", "Don't save")) {
case 0:
return false;
case 1:
qsoSave_cb(0, 0);
// fall through
case 2:
break;
}
}
if (macros.changed) {
switch (fl_choice("Save changed macros before exiting?", "Cancel", "Save", "Don't save")) {
case 0:
return false;
case 1:
macros.saveMacroFile();
// fall through
case 2:
break;
}
}
if (Maillogfile)
Maillogfile->log_to_file_stop();
if (logfile)
logfile->log_to_file_stop();
if (bSaveFreqList)
saveFreqList();
progStatus.saveLastState();
#if USE_HAMLIB
hamlib_close();
#endif
rigCAT_close();
rigMEM_close();
if (mixer)
mixer->closeMixer();
if (trx_state == STATE_RX || trx_state == STATE_TX || trx_state == STATE_TUNE)
trx_state = STATE_ABORT;
else {
LOG_ERROR("trx in unexpected state %d", trx_state);
exit(1);
}
while (trx_state != STATE_ENDED) {
REQ_FLUSH(GET_THREAD_ID());
MilliSleep(10);
}
return true;
}
// XPM Calendar Label
static const char *cal_16[] = {
// width height num_colors chars_per_pixel
@ -1720,11 +1708,9 @@ void create_fl_digi_main() {
Fl_Group *qsoFrame = new Fl_Group(0, Y, WNOM, Hqsoframe);
inpFreq = new Fl_Input(pad, Y + Hqsoframe/2 - pad, 85, Hqsoframe/2, "Frequency");
inpFreq->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
inpFreq->callback(cb_log, 0);
inpTime = new Fl_Input(rightof(inpFreq) + pad, Y + Hqsoframe/2 - pad, 45, Hqsoframe/2, "Time");
inpTime->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
inpTime->callback(cb_log, 0);
qsoTime = new Fl_Button(rightof(inpTime) + pad, Y + Hqsoframe/2 - pad, 24, Hqsoframe/2);
Fl_Image *pixmap = new Fl_Pixmap(cal_16);
@ -1733,20 +1719,15 @@ void create_fl_digi_main() {
inpCall = new Fl_Input(rightof(qsoTime) + pad, Y + Hqsoframe/2 - pad, 80, Hqsoframe/2, "Call");
inpCall->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
inpCall->callback(cb_callsign, 0);
inpCall->when(FL_WHEN_ENTER_KEY|FL_WHEN_NOT_CHANGED);
inpName = new Fl_Input(rightof(inpCall) + pad, Y + Hqsoframe/2 - pad, 100, Hqsoframe/2, "Name");
inpName->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
inpName->callback(cb_log, 0);
inpRstIn = new Fl_Input(rightof(inpName) + pad, Y + Hqsoframe/2 - pad, 35, Hqsoframe/2, "RST In ");
inpRstIn->align(FL_ALIGN_TOP | FL_ALIGN_RIGHT);
inpRstIn->callback(cb_log, 0);
inpRstOut = new Fl_Input(rightof(inpRstIn) + pad, Y + Hqsoframe/2 - pad, 35, Hqsoframe/2, "Out");
inpRstOut->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
inpRstOut->callback(cb_log, 0);
btnQRZ = new Fl_Button(WNOM - 40 - pad, Y + 1, 40, Hqsoframe/2 - pad, "QRZ");
btnQRZ->callback(cb_QRZ, 0);
@ -1754,7 +1735,6 @@ void create_fl_digi_main() {
inpQth = new Fl_Input(rightof(inpRstOut) + pad, Y + Hqsoframe/2 - pad,
leftof(btnQRZ) - rightof(inpRstOut) - 2*pad, Hqsoframe/2, "QTH");
inpQth->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);
inpQth->callback(cb_log, 0);
qsoFrame->resizable(inpQth);
qsoClear = new Fl_Button(WNOM - 40 - pad, Y + Hqsoframe/2 + 1, 40, Hqsoframe/2 - pad, "Clear");
@ -1769,17 +1749,14 @@ void create_fl_digi_main() {
inpAZ = new Fl_Input(leftof(qsoSave) - 40 - pad, Y, 40, Hnotes, "Az"); // WA5ZNU
inpAZ->align(FL_ALIGN_LEFT);
inpAZ->callback(cb_log, 0);
inpLoc = new Fl_Input(leftof(inpAZ) - pad - pad - 70, Y, 70, Hnotes, "Loc");
inpLoc->align(FL_ALIGN_LEFT);
inpLoc->callback(cb_log, 0);
// align this vertically with the Call field
inpNotes = new Fl_Input(leftof(inpLoc) - pad - (leftof(inpLoc) - leftof(inpCall)), Y,
leftof(inpLoc) - leftof(inpCall) - 2*pad, Hnotes, "Notes");
inpNotes->align(FL_ALIGN_LEFT);
inpNotes->callback(cb_log, 0);
qsoFrame2->resizable(inpNotes);
btnSideband = new Fl_Button(leftof(inpNotes) - 2*pad - (Hnotes-2), Y+1, Hnotes-2, Hnotes-2, "U");
@ -1790,6 +1767,11 @@ void create_fl_digi_main() {
qsoFrame2->end();
Y += Hnotes;
Fl_Widget* logfields[] = { inpFreq, inpTime, inpCall, inpName, inpRstIn,
inpRstOut, inpQth, inpAZ, inpLoc, inpNotes };
for (size_t i = 0; i < sizeof(logfields)/sizeof(*logfields); i++)
logfields[i]->callback(cb_log);
int sw = DEFAULT_SW;
MixerFrame = new Fl_Group(0,Y,sw, Hrcvtxt + Hxmttxt);
valRcvMixer = new Fl_Value_Slider(0, Y, sw, (Htext)/2, "");