Release 1.07
This commit is contained in:
parent
d97541e72e
commit
c5adeca556
|
@ -1,9 +1,13 @@
|
|||
AmiTimeKeeper Change Log
|
||||
|
||||
v1.07 15.02.2019
|
||||
- Support commodity hotkey and popup options
|
||||
- Hide advanced setting with new expert option
|
||||
|
||||
v1.06 08.02.2019
|
||||
- Adjust layout in settings window
|
||||
|
||||
v1.05 06.08.2018
|
||||
v1.05 06.08.2018 LTS
|
||||
- Preferences can now be saved from settings window
|
||||
- Time zone is shown as UTC offset in settings window
|
||||
- Running multiple instances no longer creates zombie processes
|
||||
|
|
144
broker.c
144
broker.c
|
@ -29,7 +29,11 @@
|
|||
#include "mem.h"
|
||||
#include "win.h"
|
||||
|
||||
#define EVT_HOTKEY 1L
|
||||
|
||||
static void ProcessMsg(void);
|
||||
static void InitBroker(void);
|
||||
static void CleanupBroker(void);
|
||||
|
||||
static struct NewBroker newBroker = {
|
||||
NB_VERSION,
|
||||
|
@ -44,6 +48,9 @@ void StartBroker(void)
|
|||
{
|
||||
LONG error;
|
||||
struct Message *msg;
|
||||
CxObj *filter, *sender, *translate;
|
||||
|
||||
InitBroker();
|
||||
|
||||
Globals->Broker->BrokerPort = CreateMsgPort();
|
||||
if (Globals->Broker->BrokerPort == NULL)
|
||||
|
@ -56,8 +63,7 @@ void StartBroker(void)
|
|||
if (Globals->Broker->UserPort == NULL)
|
||||
{
|
||||
LogError("Could not allocate broker user port");
|
||||
DeleteMsgPort(Globals->Broker->BrokerPort);
|
||||
Globals->Broker->BrokerPort = NULL;
|
||||
CleanupBroker();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -65,10 +71,7 @@ void StartBroker(void)
|
|||
if (Globals->Broker->ReplyPort == NULL)
|
||||
{
|
||||
LogError("Could not allocate broker reply port");
|
||||
DeleteMsgPort(Globals->Broker->BrokerPort);
|
||||
DeleteMsgPort(Globals->Broker->UserPort);
|
||||
Globals->Broker->BrokerPort = NULL;
|
||||
Globals->Broker->UserPort = NULL;
|
||||
CleanupBroker();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -76,12 +79,7 @@ void StartBroker(void)
|
|||
if (Globals->Broker->ShutdownSigBit == -1)
|
||||
{
|
||||
SendErrorMessage("Could not allocate signal for broker");
|
||||
DeleteMsgPort(Globals->Broker->BrokerPort);
|
||||
DeleteMsgPort(Globals->Broker->UserPort);
|
||||
DeleteMsgPort(Globals->Broker->ReplyPort);
|
||||
Globals->Broker->BrokerPort = NULL;
|
||||
Globals->Broker->UserPort = NULL;
|
||||
Globals->Broker->ReplyPort = NULL;
|
||||
CleanupBroker();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -97,23 +95,64 @@ void StartBroker(void)
|
|||
LogError("System problems (CBERR_SYSERR). Could not allocate broker object");
|
||||
break;
|
||||
case CBERR_DUP:
|
||||
LogWarning(APP_SHORT_NAME " already running");
|
||||
LogWarning(APP_SHORT_NAME " is already running");
|
||||
break;
|
||||
default:
|
||||
LogError("Could not allocate broker object (error code: %ld)", error);
|
||||
break;
|
||||
}
|
||||
|
||||
DeleteMsgPort(Globals->Broker->BrokerPort);
|
||||
DeleteMsgPort(Globals->Broker->UserPort);
|
||||
DeleteMsgPort(Globals->Broker->ReplyPort);
|
||||
Globals->Broker->BrokerPort = NULL;
|
||||
Globals->Broker->UserPort = NULL;
|
||||
Globals->Broker->ReplyPort = NULL;
|
||||
Globals->Broker->Object = NULL;
|
||||
CleanupBroker();
|
||||
return;
|
||||
}
|
||||
|
||||
filter = CxFilter(Globals->Settings->PopKey);
|
||||
if (filter == NULL)
|
||||
{
|
||||
LogError("Could not allocate broker filter object");
|
||||
CleanupBroker();
|
||||
return;
|
||||
}
|
||||
|
||||
AttachCxObj(Globals->Broker->Object, filter);
|
||||
|
||||
sender = CxSender(Globals->Broker->BrokerPort, EVT_HOTKEY);
|
||||
if (sender == NULL)
|
||||
{
|
||||
LogError("Could not allocate broker sender object");
|
||||
CleanupBroker();
|
||||
return;
|
||||
}
|
||||
|
||||
AttachCxObj(filter, sender);
|
||||
|
||||
translate = CxTranslate(NULL);
|
||||
if (translate == NULL)
|
||||
{
|
||||
LogError("Could not allocate broker translate object");
|
||||
CleanupBroker();
|
||||
return;
|
||||
}
|
||||
|
||||
AttachCxObj(filter, translate);
|
||||
|
||||
error = CxObjError(filter);
|
||||
if (error != 0)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case CBERR_SYSERR:
|
||||
LogWarning("Commodity filter problems (CBERR_SYSERR)");
|
||||
break;
|
||||
case COERR_BADFILTER:
|
||||
LogWarning("Commodity HOTKEY error");
|
||||
break;
|
||||
default:
|
||||
LogWarning("Commodity filter error (error code: %ld)", error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Globals->Broker->Task = FindTask(NULL);
|
||||
|
||||
StartCom();
|
||||
|
@ -128,15 +167,7 @@ void StartBroker(void)
|
|||
while ((msg = GetMsg(Globals->Broker->ReplyPort)))
|
||||
ReplyMsg(msg);
|
||||
|
||||
DeleteCxObj(Globals->Broker->Object);
|
||||
FreeSignal(Globals->Broker->ShutdownSigBit);
|
||||
DeleteMsgPort(Globals->Broker->BrokerPort);
|
||||
DeleteMsgPort(Globals->Broker->UserPort);
|
||||
DeleteMsgPort(Globals->Broker->ReplyPort);
|
||||
Globals->Broker->BrokerPort = NULL;
|
||||
Globals->Broker->UserPort = NULL;
|
||||
Globals->Broker->ReplyPort = NULL;
|
||||
Globals->Broker->Object = NULL;
|
||||
CleanupBroker();
|
||||
}
|
||||
|
||||
void ShutdownBroker(void)
|
||||
|
@ -195,6 +226,11 @@ static void ProcessMsg(void)
|
|||
ActivateCxObj(Globals->Broker->Object, 1);
|
||||
Globals->Active = true;
|
||||
|
||||
if (Globals->Settings->Popup)
|
||||
{
|
||||
ShowSettingWindow();
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
ULONG sigrcvd = Wait(sigmask);
|
||||
|
@ -211,6 +247,13 @@ static void ProcessMsg(void)
|
|||
switch (msgtype)
|
||||
{
|
||||
case CXM_IEVENT:
|
||||
switch (msgid)
|
||||
{
|
||||
case EVT_HOTKEY:
|
||||
LogTrace("Show window");
|
||||
ShowSettingWindow();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CXM_COMMAND:
|
||||
switch (msgid)
|
||||
|
@ -329,3 +372,46 @@ static void ProcessMsg(void)
|
|||
}
|
||||
} while (run);
|
||||
}
|
||||
|
||||
static void InitBroker(void)
|
||||
{
|
||||
Globals->Broker->Object = NULL;
|
||||
Globals->Broker->ShutdownSigBit = -1;
|
||||
Globals->Broker->Task = NULL;
|
||||
Globals->Broker->BrokerPort = NULL;
|
||||
Globals->Broker->UserPort = NULL;
|
||||
Globals->Broker->ReplyPort = NULL;
|
||||
}
|
||||
|
||||
static void CleanupBroker(void)
|
||||
{
|
||||
if (Globals->Broker->Object != NULL)
|
||||
{
|
||||
DeleteCxObjAll(Globals->Broker->Object);
|
||||
Globals->Broker->Object = NULL;
|
||||
}
|
||||
|
||||
if (Globals->Broker->ShutdownSigBit != -1)
|
||||
{
|
||||
FreeSignal(Globals->Broker->ShutdownSigBit);
|
||||
Globals->Broker->ShutdownSigBit = -1;
|
||||
}
|
||||
|
||||
if (Globals->Broker->BrokerPort != NULL)
|
||||
{
|
||||
DeleteMsgPort(Globals->Broker->BrokerPort);
|
||||
Globals->Broker->BrokerPort = NULL;
|
||||
}
|
||||
|
||||
if (Globals->Broker->UserPort != NULL)
|
||||
{
|
||||
DeleteMsgPort(Globals->Broker->UserPort);
|
||||
Globals->Broker->UserPort = NULL;
|
||||
}
|
||||
|
||||
if (Globals->Broker->ReplyPort != NULL)
|
||||
{
|
||||
DeleteMsgPort(Globals->Broker->ReplyPort);
|
||||
Globals->Broker->ReplyPort = NULL;
|
||||
}
|
||||
}
|
||||
|
|
25
config.h
25
config.h
|
@ -141,10 +141,16 @@ int poll(struct pollfd *, nfds_t, int);
|
|||
#define LIB_ERROR -1
|
||||
#define COM_ERROR -1
|
||||
|
||||
#ifdef AROS
|
||||
#define APP_SHORT_NAME "ArosTimeKeeper"
|
||||
#define APP_LONG_NAME "AROS Time Keeper"
|
||||
#else
|
||||
#define APP_SHORT_NAME "AmiTimeKeeper"
|
||||
#define APP_LONG_NAME "Amiga Time Keeper"
|
||||
#define APP_VERSION "1.06"
|
||||
#define APP_DATE_VERSION "1.06 (08.02.2019)"
|
||||
#endif
|
||||
|
||||
#define APP_VERSION "1.07"
|
||||
#define APP_DATE_VERSION "1.07 (15.02.2019)"
|
||||
#define APP_ID APP_SHORT_NAME " " APP_DATE_VERSION
|
||||
#define APP_TITLE APP_LONG_NAME " " APP_DATE_VERSION
|
||||
#define APP_TITLE_VERSION APP_LONG_NAME " " APP_VERSION
|
||||
|
@ -153,13 +159,16 @@ int poll(struct pollfd *, nfds_t, int);
|
|||
#include "state.h"
|
||||
#include "string.h"
|
||||
|
||||
#define KEYWORD_COUNT 9
|
||||
#define KEYWORD_COUNT 12
|
||||
#define KEYWORD_SERVER "SERVER"
|
||||
#define KEYWORD_PORT "PORT"
|
||||
#define KEYWORD_THRESHOLD "THRESHOLD"
|
||||
#define KEYWORD_INTERVAL "INTERVAL"
|
||||
#define KEYWORD_PRIORITY "CX_PRIORITY"
|
||||
#define KEYWORD_POPKEY "CX_POPKEY"
|
||||
#define KEYWORD_POPUP "CX_POPUP"
|
||||
#define KEYWORD_READONLY "READONLY"
|
||||
#define KEYWORD_EXPERT "EXPERT"
|
||||
#define KEYWORD_TIMEOUT "TIMEOUT"
|
||||
#define KEYWORD_VERBOSE "VERBOSE"
|
||||
#define KEYWORD_LOGFILE "LOGFILE"
|
||||
|
@ -174,6 +183,7 @@ int poll(struct pollfd *, nfds_t, int);
|
|||
#define PRIORITY_DEF 25
|
||||
#define PRIORITY_MAX 127
|
||||
#define READONLY_DEF 0
|
||||
#define EXPERT_DEF 1
|
||||
#define TIMEOUT_MIN 100
|
||||
#define TIMEOUT_DEF 5000
|
||||
#define TIMEOUT_MAX 30000
|
||||
|
@ -181,10 +191,13 @@ int poll(struct pollfd *, nfds_t, int);
|
|||
#define VERBOSE_DEF 0
|
||||
#define VERBOSE_MAX 3
|
||||
#define LOGFILE_DEF NULL
|
||||
#define POPKEY_DEF "lshift control t"
|
||||
#define POPUP_DEF 0
|
||||
|
||||
#define KEYWORD_TEMPLATE_1 KEYWORD_READONLY "/S," KEYWORD_SERVER "/K," KEYWORD_PORT "/K," KEYWORD_TIMEOUT "/N/K," KEYWORD_THRESHOLD "/K,"
|
||||
#define KEYWORD_TEMPLATE_2 KEYWORD_INTERVAL "/N/K," KEYWORD_VERBOSE "/N/K," KEYWORD_PRIORITY "/N/K," KEYWORD_LOGFILE "/K"
|
||||
#define KEYWORD_TEMPLATE KEYWORD_TEMPLATE_1 KEYWORD_TEMPLATE_2
|
||||
#define KEYWORD_TEMPLATE_1 KEYWORD_READONLY "/S," KEYWORD_EXPERT "/S," KEYWORD_SERVER "/K," KEYWORD_PORT "/K," KEYWORD_TIMEOUT "/N/K,"
|
||||
#define KEYWORD_TEMPLATE_2 KEYWORD_THRESHOLD "/K," KEYWORD_INTERVAL "/N/K," KEYWORD_VERBOSE "/N/K,"
|
||||
#define KEYWORD_TEMPLATE_3 KEYWORD_PRIORITY "/N/K," KEYWORD_POPKEY "/K," KEYWORD_POPUP "/K," KEYWORD_LOGFILE "/K"
|
||||
#define KEYWORD_TEMPLATE KEYWORD_TEMPLATE_1 KEYWORD_TEMPLATE_2 KEYWORD_TEMPLATE_3
|
||||
|
||||
/* broker.c */
|
||||
void StartBroker(void);
|
||||
|
|
|
@ -130,6 +130,8 @@ static void ClosingResource(const char *name)
|
|||
|
||||
int OpenLibraries(void)
|
||||
{
|
||||
LogInfo("Starting up");
|
||||
|
||||
// DOS Library
|
||||
if (!(DOSBase = (struct DosLibrary *)OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV)))
|
||||
{
|
||||
|
@ -265,6 +267,8 @@ int OpenLibraries(void)
|
|||
|
||||
void CloseLibraries(void)
|
||||
{
|
||||
LogInfo("Shutting down");
|
||||
|
||||
if (TimerDevice != NULL)
|
||||
{
|
||||
ClosingResource((const char *)TIMERNAME);
|
||||
|
|
2
mem.c
2
mem.c
|
@ -1,5 +1,5 @@
|
|||
/*-
|
||||
* Copyright (c) 2014-2018 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* Copyright (c) 2014-2019 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
471
state.c
471
state.c
|
@ -36,7 +36,10 @@ static const struct AppSettingKeys SettingKeyStruct = {
|
|||
.Threshold = KEYWORD_THRESHOLD,
|
||||
.Interval = KEYWORD_INTERVAL,
|
||||
.Priority = KEYWORD_PRIORITY,
|
||||
.PopKey = KEYWORD_POPKEY,
|
||||
.Popup = KEYWORD_POPUP,
|
||||
.Readonly = KEYWORD_READONLY,
|
||||
.Expert = KEYWORD_EXPERT,
|
||||
.Timeout = KEYWORD_TIMEOUT,
|
||||
.Verbose = KEYWORD_VERBOSE,
|
||||
.LogFile = KEYWORD_LOGFILE};
|
||||
|
@ -47,8 +50,11 @@ const struct AppSettings DefaultSettings = {
|
|||
.DestinationPort = (char *)PORT_DEF,
|
||||
.Timeout = TIMEOUT_DEF,
|
||||
.Interval = INTERVAL_DEF,
|
||||
.PopKey = POPKEY_DEF,
|
||||
.Popup = POPUP_DEF,
|
||||
.Verbose = VERBOSE_DEF,
|
||||
.Readonly = READONLY_DEF,
|
||||
.Expert = EXPERT_DEF,
|
||||
.Priority = PRIORITY_DEF,
|
||||
.Threshold = THRESHOLD_DEF,
|
||||
.LogFile = (char *)LOGFILE_DEF,
|
||||
|
@ -62,11 +68,15 @@ static void SetThresholdSetting(struct AppSettings *, void *);
|
|||
static void SetDestinationAddressSetting(struct AppSettings *, void *);
|
||||
static void SetDestinationPortSetting(struct AppSettings *, void *);
|
||||
static void SetReadOnlySetting(struct AppSettings *, void *);
|
||||
static void SetExpertSetting(struct AppSettings *, void *);
|
||||
static void SetLogFileSetting(struct AppSettings *, void *);
|
||||
static void SetPopupSetting(struct AppSettings *, void *);
|
||||
static void SetPopKeySetting(struct AppSettings *, void *);
|
||||
|
||||
// Keyword order in settingFunctions needs to match order in keyword template
|
||||
const struct SettingFunc settingFunctions[] = {
|
||||
{KEYWORD_READONLY, SetReadOnlySetting},
|
||||
{KEYWORD_EXPERT, SetExpertSetting},
|
||||
{KEYWORD_SERVER, SetDestinationAddressSetting},
|
||||
{KEYWORD_PORT, SetDestinationPortSetting},
|
||||
{KEYWORD_TIMEOUT, SetTimeoutSetting},
|
||||
|
@ -74,6 +84,8 @@ const struct SettingFunc settingFunctions[] = {
|
|||
{KEYWORD_INTERVAL, SetIntervalSetting},
|
||||
{KEYWORD_VERBOSE, SetVerboseSetting},
|
||||
{KEYWORD_PRIORITY, SetPrioritySetting},
|
||||
{KEYWORD_POPKEY, SetPopKeySetting},
|
||||
{KEYWORD_POPUP, SetPopupSetting},
|
||||
{KEYWORD_LOGFILE, SetLogFileSetting}};
|
||||
|
||||
static const char *prefsFile = "ENV:timekeeper.prefs";
|
||||
|
@ -91,12 +103,12 @@ static const char *foundSetting = "Found %s in preference file";
|
|||
static const char *foundWbSetting = "Found tooltype from icon: %s";
|
||||
static const char *foundCliSetting = "Got %s from CLI";
|
||||
static const char *integerError = "Value should be an integer: %s";
|
||||
static const char *yesNoError = "Value should be YES or NO: %s";
|
||||
static const char *applyDefaultSettings = "Applying default values";
|
||||
static const char *applyFileSettings = "Applying values from preference file";
|
||||
static const char *applyCliSettings = "Applying values from CLI";
|
||||
static const char *applyWbSettings = "Applying values from tooltypes";
|
||||
static const char *effectiveSettings = "Listing runtime values";
|
||||
static const char *noLogFile = "(none)";
|
||||
static const char *settingTooLow = "%s < %ld (too low)";
|
||||
static const char *settingTooHigh = "%s > %ld (too high)";
|
||||
static const char *settingGreaterThan = "%s > %s";
|
||||
|
@ -109,6 +121,10 @@ static const char *settingValueString = "%s=%s";
|
|||
static const char *saveValueLong = "%s=%ld\n";
|
||||
static const char *saveValueString = "%s=%s\n";
|
||||
|
||||
static const char *noLogFile = "(none)";
|
||||
static const char *noValueString = "NO";
|
||||
static const char *yesValueString = "YES";
|
||||
|
||||
#define MAXSETTINGLINELEN 256
|
||||
|
||||
static struct AppSettings *fileSettings;
|
||||
|
@ -139,11 +155,18 @@ void DestroyState(void)
|
|||
FreeMemSafe((void *)Globals);
|
||||
}
|
||||
|
||||
static char *BooleanAsText(bool value)
|
||||
{
|
||||
return (char *)(value ? yesValueString : noValueString);
|
||||
}
|
||||
|
||||
void ShowAppSettings(struct AppSettings *settings)
|
||||
{
|
||||
char low[MAXLONGLONGCHARSIZE];
|
||||
|
||||
LongLongToStr(settings->Threshold, low);
|
||||
LogTrace(settingValueString, SettingKeys->Popup, BooleanAsText(settings->Popup));
|
||||
LogTrace(settingValueString, SettingKeys->PopKey, settings->PopKey);
|
||||
LogTrace(settingValueLong, SettingKeys->Priority, settings->Priority);
|
||||
LogTrace(settingValueString, SettingKeys->Threshold, low);
|
||||
LogTrace(settingValueString, SettingKeys->DestinationAddress, settings->DestinationAddress);
|
||||
|
@ -151,7 +174,8 @@ void ShowAppSettings(struct AppSettings *settings)
|
|||
LogTrace(settingValueLong, SettingKeys->Timeout, settings->Timeout);
|
||||
LogTrace(settingValueLong, SettingKeys->Interval, settings->Interval);
|
||||
LogTrace(settingValueLong, SettingKeys->Verbose, settings->Verbose);
|
||||
LogTrace(settingValueLong, SettingKeys->Readonly, settings->Readonly);
|
||||
LogTrace(settingValueString, SettingKeys->Readonly, BooleanAsText(settings->Readonly));
|
||||
LogTrace(settingValueString, SettingKeys->Expert, BooleanAsText(settings->Expert));
|
||||
LogTrace(settingValueString, SettingKeys->LogFile,
|
||||
settings->LogFile ? settings->LogFile : noLogFile);
|
||||
}
|
||||
|
@ -166,7 +190,7 @@ void LogFoundSetting(long type, const char *name)
|
|||
{
|
||||
switch (type)
|
||||
{
|
||||
case FileSettingType:
|
||||
case PrefsSettingType:
|
||||
LogTrace(foundSetting, name);
|
||||
break;
|
||||
case CliSettingType:
|
||||
|
@ -180,144 +204,161 @@ void LogFoundSetting(long type, const char *name)
|
|||
}
|
||||
}
|
||||
|
||||
static void SetPrioritySetting(struct AppSettings *setting, void *value)
|
||||
static void ParseLongSetting(
|
||||
struct AppSettings *settings,
|
||||
long flag,
|
||||
const char *keyword,
|
||||
long *valueField,
|
||||
void *value)
|
||||
{
|
||||
LogFoundSetting(setting->Type, SettingKeys->Priority);
|
||||
if (setting->Type == CliSettingType)
|
||||
LogFoundSetting(settings->Type, keyword);
|
||||
if (settings->Type == CliSettingType)
|
||||
{
|
||||
setting->Priority = *(long *)value;
|
||||
setting->Values |= PrioritySet;
|
||||
*valueField = *(long *)value;
|
||||
settings->Values |= flag;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryParseLong((char *)value, &setting->Priority))
|
||||
if (TryParseLong((char *)value, valueField))
|
||||
{
|
||||
setting->Values |= PrioritySet;
|
||||
settings->Values |= flag;
|
||||
return;
|
||||
}
|
||||
|
||||
LogWarning(integerError, value);
|
||||
}
|
||||
|
||||
static void SetVerboseSetting(struct AppSettings *setting, void *value)
|
||||
static void ParseBooleanSetting(
|
||||
struct AppSettings *settings,
|
||||
long flag,
|
||||
const char *keyword,
|
||||
long *valueField,
|
||||
void *value,
|
||||
bool yesNo)
|
||||
{
|
||||
LogFoundSetting(setting->Type, SettingKeys->Verbose);
|
||||
if (setting->Type == CliSettingType)
|
||||
LogFoundSetting(settings->Type, SettingKeys->Popup);
|
||||
|
||||
// CLI switch is always a long value
|
||||
if (settings->Type == CliSettingType && !yesNo)
|
||||
{
|
||||
setting->Verbose = *(long *)value;
|
||||
setting->Values |= VerboseSet;
|
||||
*valueField = (*valueField != 0 ? true : false);
|
||||
settings->Values |= flag;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryParseLong((char *)value, &setting->Verbose))
|
||||
if (value == NULL || *((const char *)value) == '\0')
|
||||
{
|
||||
setting->Values |= VerboseSet;
|
||||
LogWarning(yesNoError, '\0');
|
||||
return;
|
||||
}
|
||||
|
||||
if (Stricmp((STRPTR)noValueString, (STRPTR)value) == 0 || Stricmp("0", (STRPTR)value) == 0)
|
||||
{
|
||||
*valueField = false;
|
||||
settings->Values |= flag;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Stricmp((STRPTR)yesValueString, (STRPTR)value) == 0 || Stricmp("1", (STRPTR)value) == 0)
|
||||
{
|
||||
*valueField = true;
|
||||
settings->Values |= flag;
|
||||
return;
|
||||
}
|
||||
|
||||
LogWarning(yesNoError, value);
|
||||
}
|
||||
|
||||
static void SetPrioritySetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
ParseLongSetting(settings, PrioritySet, SettingKeys->Priority,
|
||||
&settings->Priority, value);
|
||||
}
|
||||
|
||||
static void SetVerboseSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
ParseLongSetting(settings, VerboseSet, SettingKeys->Verbose,
|
||||
&settings->Verbose, value);
|
||||
}
|
||||
|
||||
static void SetIntervalSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
ParseLongSetting(settings, IntervalSet, SettingKeys->Interval,
|
||||
&settings->Interval, value);
|
||||
}
|
||||
|
||||
static void SetTimeoutSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
ParseLongSetting(settings, TimeoutSet, SettingKeys->Timeout,
|
||||
&settings->Timeout, value);
|
||||
}
|
||||
|
||||
static void SetThresholdSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
LogFoundSetting(settings->Type, SettingKeys->Threshold);
|
||||
if (TryParseLongLong((char *)value, &settings->Threshold))
|
||||
{
|
||||
settings->Values |= ThresholdSet;
|
||||
return;
|
||||
}
|
||||
|
||||
LogWarning(integerError, value);
|
||||
}
|
||||
|
||||
static void SetIntervalSetting(struct AppSettings *setting, void *value)
|
||||
static void SetDestinationAddressSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
LogFoundSetting(setting->Type, SettingKeys->Interval);
|
||||
if (setting->Type == CliSettingType)
|
||||
{
|
||||
setting->Interval = *(long *)value;
|
||||
setting->Values |= IntervalSet;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryParseLong((char *)value, &setting->Interval))
|
||||
{
|
||||
setting->Values |= IntervalSet;
|
||||
return;
|
||||
}
|
||||
|
||||
LogWarning(integerError, value);
|
||||
LogFoundSetting(settings->Type, SettingKeys->DestinationAddress);
|
||||
settings->DestinationAddress = StrDupSafe((const char *)value);
|
||||
settings->Values |= DestinationAddressSet;
|
||||
}
|
||||
|
||||
static void SetTimeoutSetting(struct AppSettings *setting, void *value)
|
||||
static void SetPopKeySetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
LogFoundSetting(setting->Type, SettingKeys->Timeout);
|
||||
if (setting->Type == CliSettingType)
|
||||
{
|
||||
setting->Timeout = *(long *)value;
|
||||
setting->Values |= TimeoutSet;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryParseLong((char *)value, &setting->Timeout))
|
||||
{
|
||||
setting->Values |= TimeoutSet;
|
||||
return;
|
||||
}
|
||||
|
||||
LogWarning(integerError, value);
|
||||
LogFoundSetting(settings->Type, SettingKeys->PopKey);
|
||||
settings->PopKey = StrDupSafe((const char *)value);
|
||||
settings->Values |= PopKeySet;
|
||||
}
|
||||
|
||||
static void SetThresholdSetting(struct AppSettings *setting, void *value)
|
||||
static void SetDestinationPortSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
LogFoundSetting(setting->Type, SettingKeys->Threshold);
|
||||
if (TryParseLongLong((char *)value, &setting->Threshold))
|
||||
{
|
||||
setting->Values |= ThresholdSet;
|
||||
return;
|
||||
}
|
||||
|
||||
LogWarning(integerError, value);
|
||||
LogFoundSetting(settings->Type, SettingKeys->DestinationPort);
|
||||
settings->DestinationPort = StrDupSafe((const char *)value);
|
||||
settings->Values |= DestinationPortSet;
|
||||
}
|
||||
|
||||
static void SetDestinationAddressSetting(struct AppSettings *setting, void *value)
|
||||
static void SetReadOnlySetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
LogFoundSetting(setting->Type, SettingKeys->DestinationAddress);
|
||||
setting->DestinationAddress = StrDupSafe((const char *)value);
|
||||
setting->Values |= DestinationAddressSet;
|
||||
ParseBooleanSetting(settings, ReadonlySet, SettingKeys->Readonly,
|
||||
&settings->Readonly, value, true);
|
||||
}
|
||||
|
||||
static void SetDestinationPortSetting(struct AppSettings *setting, void *value)
|
||||
static void SetExpertSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
LogFoundSetting(setting->Type, SettingKeys->DestinationPort);
|
||||
setting->DestinationPort = StrDupSafe((const char *)value);
|
||||
setting->Values |= DestinationPortSet;
|
||||
ParseBooleanSetting(settings, ExpertSet, SettingKeys->Expert,
|
||||
&settings->Expert, value, true);
|
||||
}
|
||||
|
||||
static void SetReadOnlySetting(struct AppSettings *setting, void *value)
|
||||
static void SetPopupSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
LogFoundSetting(setting->Type, SettingKeys->Readonly);
|
||||
if (setting->Type == CliSettingType)
|
||||
{
|
||||
setting->Readonly = value != 0 ? true : false;
|
||||
setting->Values |= ReadonlySet;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryParseLong((char *)value, &setting->Readonly))
|
||||
{
|
||||
setting->Readonly = setting->Readonly != 0 ? true : false;
|
||||
setting->Values |= ReadonlySet;
|
||||
return;
|
||||
}
|
||||
|
||||
LogWarning(integerError, value);
|
||||
ParseBooleanSetting(settings, PopUpSet, SettingKeys->Popup,
|
||||
&settings->Popup, value, false);
|
||||
}
|
||||
|
||||
static void SetLogFileSetting(struct AppSettings *setting, void *value)
|
||||
static void SetLogFileSetting(struct AppSettings *settings, void *value)
|
||||
{
|
||||
static const char *no = "no";
|
||||
LogFoundSetting(setting->Type, SettingKeys->LogFile);
|
||||
LogFoundSetting(settings->Type, SettingKeys->LogFile);
|
||||
|
||||
if (value == NULL || *((const char *)value) == '\0' ||
|
||||
Stricmp((STRPTR)no, (STRPTR)value) == 0 ||
|
||||
Stricmp((STRPTR)noValueString, (STRPTR)value) == 0 ||
|
||||
Stricmp((STRPTR)noLogFile, (STRPTR)value) == 0)
|
||||
{
|
||||
setting->LogFile = NULL;
|
||||
settings->LogFile = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
setting->LogFile = StrDupSafe((const char *)value);
|
||||
settings->LogFile = StrDupSafe((const char *)value);
|
||||
}
|
||||
setting->Values |= LogFileSet;
|
||||
settings->Values |= LogFileSet;
|
||||
}
|
||||
|
||||
static void ParseSetting(struct AppSettings *settings, char *line)
|
||||
|
@ -386,7 +427,7 @@ void LoadSettings(void)
|
|||
|
||||
LogInfo(prefsFileFound);
|
||||
|
||||
settings = CreateSettings(FileSettingType);
|
||||
settings = CreateSettings(PrefsSettingType);
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -449,6 +490,8 @@ void SaveSettings(bool persist)
|
|||
LogInfo(prefsFileSave, fileName);
|
||||
|
||||
LongLongToStr(Globals->Settings->Threshold, low);
|
||||
WriteSetting(file, saveValueString, SettingKeys->Popup, BooleanAsText(Globals->Settings->Popup));
|
||||
WriteSetting(file, saveValueString, SettingKeys->PopKey, Globals->Settings->PopKey);
|
||||
WriteSetting(file, saveValueLong, SettingKeys->Priority, Globals->Settings->Priority);
|
||||
WriteSetting(file, saveValueString, SettingKeys->Threshold, low);
|
||||
WriteSetting(file, saveValueString, SettingKeys->DestinationAddress, Globals->Settings->DestinationAddress);
|
||||
|
@ -456,7 +499,8 @@ void SaveSettings(bool persist)
|
|||
WriteSetting(file, saveValueLong, SettingKeys->Timeout, Globals->Settings->Timeout);
|
||||
WriteSetting(file, saveValueLong, SettingKeys->Interval, Globals->Settings->Interval);
|
||||
WriteSetting(file, saveValueLong, SettingKeys->Verbose, Globals->Settings->Verbose);
|
||||
WriteSetting(file, saveValueLong, SettingKeys->Readonly, Globals->Settings->Readonly);
|
||||
WriteSetting(file, saveValueString, SettingKeys->Readonly, BooleanAsText(Globals->Settings->Readonly));
|
||||
WriteSetting(file, saveValueString, SettingKeys->Expert, BooleanAsText(Globals->Settings->Expert));
|
||||
WriteSetting(file, saveValueString, SettingKeys->LogFile, Globals->Settings->LogFile);
|
||||
|
||||
Close(file);
|
||||
|
@ -476,6 +520,7 @@ struct AppSettings *CopySettings(const struct AppSettings *settings)
|
|||
CopyMem((void *)settings, s, sizeof(struct AppSettings));
|
||||
s->DestinationAddress = StrDupSafe(settings->DestinationAddress);
|
||||
s->DestinationPort = StrDupSafe(settings->DestinationPort);
|
||||
s->PopKey = StrDupSafe(settings->PopKey);
|
||||
if (s->LogFile != NULL)
|
||||
{
|
||||
s->LogFile = StrDupSafe(settings->LogFile);
|
||||
|
@ -496,6 +541,11 @@ void FreeSettings(struct AppSettings *settings)
|
|||
FreeMemSafe(settings->DestinationPort);
|
||||
}
|
||||
|
||||
if (settings->PopKey != NULL)
|
||||
{
|
||||
FreeMemSafe(settings->PopKey);
|
||||
}
|
||||
|
||||
if (settings->LogFile != NULL)
|
||||
{
|
||||
FreeMemSafe(settings->LogFile);
|
||||
|
@ -504,6 +554,89 @@ void FreeSettings(struct AppSettings *settings)
|
|||
FreeMemSafe(settings);
|
||||
}
|
||||
|
||||
static void ApplyLongSetting(
|
||||
struct AppSettings *settings,
|
||||
long flag,
|
||||
const char *keyword,
|
||||
long *curValue,
|
||||
long *newValue,
|
||||
bool quiet)
|
||||
{
|
||||
if ((settings->Values & flag) == flag)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueLong, keyword, *newValue);
|
||||
}
|
||||
else if (*curValue != *newValue)
|
||||
{
|
||||
LogInfo(settingChangedLong, keyword, *curValue, *newValue);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetLong, keyword, *newValue);
|
||||
}
|
||||
*curValue = *newValue;
|
||||
}
|
||||
}
|
||||
|
||||
static void ApplyBooleanSetting(
|
||||
struct AppSettings *settings,
|
||||
long flag,
|
||||
const char *keyword,
|
||||
long *curValue,
|
||||
long *newValue,
|
||||
bool quiet)
|
||||
{
|
||||
if ((settings->Values & flag) == flag)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueString, keyword, BooleanAsText(*newValue));
|
||||
}
|
||||
else if (*curValue != *newValue)
|
||||
{
|
||||
LogInfo(settingChangedString, keyword, BooleanAsText(*curValue), BooleanAsText(*newValue));
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingValueString, keyword, BooleanAsText(*newValue));
|
||||
}
|
||||
*curValue = *newValue;
|
||||
}
|
||||
}
|
||||
|
||||
static void ApplyStringSetting(
|
||||
struct AppSettings *settings,
|
||||
long flag,
|
||||
const char *keyword,
|
||||
char **curValue,
|
||||
char *newValue,
|
||||
bool quiet)
|
||||
{
|
||||
if ((settings->Values & flag) == flag)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueString, keyword, newValue);
|
||||
}
|
||||
else if (Stricmp((STRPTR)*curValue, (STRPTR)newValue) != 0)
|
||||
{
|
||||
LogInfo(settingChangedString, keyword, *curValue, newValue);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetString, keyword, newValue);
|
||||
}
|
||||
|
||||
if (*curValue != NULL)
|
||||
{
|
||||
FreeMemSafe(*curValue);
|
||||
}
|
||||
*curValue = StrDupSafe(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyAppSettings(struct AppSettings *settings, bool quiet)
|
||||
{
|
||||
switch (settings->Type)
|
||||
|
@ -511,7 +644,7 @@ void ApplyAppSettings(struct AppSettings *settings, bool quiet)
|
|||
case DefaultSettingType:
|
||||
LogInfo(applyDefaultSettings);
|
||||
break;
|
||||
case FileSettingType:
|
||||
case PrefsSettingType:
|
||||
LogInfo(applyFileSettings);
|
||||
break;
|
||||
case CliSettingType:
|
||||
|
@ -524,145 +657,35 @@ void ApplyAppSettings(struct AppSettings *settings, bool quiet)
|
|||
break;
|
||||
}
|
||||
|
||||
if ((settings->Values & PrioritySet) == PrioritySet)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueLong, SettingKeys->Priority, settings->Priority);
|
||||
}
|
||||
else if (Globals->Settings->Priority != settings->Priority)
|
||||
{
|
||||
LogInfo(settingChangedLong, SettingKeys->Priority, Globals->Settings->Priority,
|
||||
settings->Priority);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetLong, SettingKeys->Priority, settings->Priority);
|
||||
}
|
||||
Globals->Settings->Priority = settings->Priority;
|
||||
}
|
||||
ApplyBooleanSetting(settings, PopUpSet, SettingKeys->Popup,
|
||||
&Globals->Settings->Popup, &settings->Popup, quiet);
|
||||
|
||||
if ((settings->Values & VerboseSet) == VerboseSet)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueLong, SettingKeys->Verbose, settings->Verbose);
|
||||
}
|
||||
else if (Globals->Settings->Verbose != settings->Verbose)
|
||||
{
|
||||
LogInfo(settingChangedLong, SettingKeys->Verbose, Globals->Settings->Verbose,
|
||||
settings->Verbose);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetLong, SettingKeys->Verbose, settings->Verbose);
|
||||
}
|
||||
Globals->Settings->Verbose = settings->Verbose;
|
||||
}
|
||||
ApplyStringSetting(settings, PopKeySet, SettingKeys->PopKey,
|
||||
&Globals->Settings->PopKey, settings->PopKey, quiet);
|
||||
|
||||
if ((settings->Values & TimeoutSet) == TimeoutSet)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueLong, SettingKeys->Timeout, settings->Timeout);
|
||||
}
|
||||
else if (Globals->Settings->Timeout != settings->Timeout)
|
||||
{
|
||||
LogInfo(settingChangedLong, SettingKeys->Timeout, Globals->Settings->Timeout,
|
||||
settings->Timeout);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetLong, SettingKeys->Timeout, settings->Timeout);
|
||||
}
|
||||
Globals->Settings->Timeout = settings->Timeout;
|
||||
}
|
||||
ApplyLongSetting(settings, PrioritySet, SettingKeys->Priority,
|
||||
&Globals->Settings->Priority, &settings->Priority, quiet);
|
||||
|
||||
if ((settings->Values & IntervalSet) == IntervalSet)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueLong, SettingKeys->Interval, settings->Interval);
|
||||
}
|
||||
else if (Globals->Settings->Interval != settings->Interval)
|
||||
{
|
||||
LogInfo(settingChangedLong, SettingKeys->Interval, Globals->Settings->Interval,
|
||||
settings->Interval);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetLong, SettingKeys->Interval, settings->Interval);
|
||||
}
|
||||
Globals->Settings->Interval = settings->Interval;
|
||||
}
|
||||
ApplyLongSetting(settings, VerboseSet, SettingKeys->Verbose,
|
||||
&Globals->Settings->Verbose, &settings->Verbose, quiet);
|
||||
|
||||
if ((settings->Values & ReadonlySet) == ReadonlySet)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueLong, SettingKeys->Readonly, settings->Readonly);
|
||||
}
|
||||
else if (Globals->Settings->Readonly != settings->Readonly)
|
||||
{
|
||||
LogInfo(settingChangedLong, SettingKeys->Readonly, Globals->Settings->Readonly,
|
||||
settings->Readonly);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetLong, SettingKeys->Readonly, settings->Readonly);
|
||||
}
|
||||
Globals->Settings->Readonly = settings->Readonly;
|
||||
}
|
||||
ApplyLongSetting(settings, TimeoutSet, SettingKeys->Timeout,
|
||||
&Globals->Settings->Timeout, &settings->Timeout, quiet);
|
||||
|
||||
if ((settings->Values & DestinationAddressSet) == DestinationAddressSet)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueString, SettingKeys->DestinationAddress,
|
||||
settings->DestinationAddress);
|
||||
}
|
||||
else if (Stricmp((STRPTR)Globals->Settings->DestinationAddress,
|
||||
(STRPTR)settings->DestinationAddress) != 0)
|
||||
{
|
||||
LogInfo(settingChangedString, SettingKeys->DestinationAddress,
|
||||
Globals->Settings->DestinationAddress, settings->DestinationAddress);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetString, SettingKeys->DestinationAddress, settings->DestinationAddress);
|
||||
}
|
||||
ApplyLongSetting(settings, IntervalSet, SettingKeys->Interval,
|
||||
&Globals->Settings->Interval, &settings->Interval, quiet);
|
||||
|
||||
if (Globals->Settings->DestinationAddress != NULL)
|
||||
{
|
||||
FreeMemSafe(Globals->Settings->DestinationAddress);
|
||||
}
|
||||
Globals->Settings->DestinationAddress = StrDupSafe(settings->DestinationAddress);
|
||||
}
|
||||
ApplyBooleanSetting(settings, ReadonlySet, SettingKeys->Readonly,
|
||||
&Globals->Settings->Readonly, &settings->Readonly, quiet);
|
||||
|
||||
if ((settings->Values & DestinationPortSet) == DestinationPortSet)
|
||||
{
|
||||
if (settings->Type == DefaultSettingType)
|
||||
{
|
||||
LogTrace(settingValueString, SettingKeys->DestinationPort,
|
||||
settings->DestinationPort);
|
||||
}
|
||||
else if (Stricmp((STRPTR)Globals->Settings->DestinationPort,
|
||||
(STRPTR)settings->DestinationPort) != 0)
|
||||
{
|
||||
LogInfo(settingChangedString, SettingKeys->DestinationPort,
|
||||
Globals->Settings->DestinationPort, settings->DestinationPort);
|
||||
}
|
||||
else if (!quiet)
|
||||
{
|
||||
LogTrace(settingSetString, SettingKeys->DestinationPort, settings->DestinationPort);
|
||||
}
|
||||
ApplyBooleanSetting(settings, ExpertSet, SettingKeys->Expert,
|
||||
&Globals->Settings->Expert, &settings->Expert, quiet);
|
||||
|
||||
if (Globals->Settings->DestinationPort != NULL)
|
||||
{
|
||||
FreeMemSafe(Globals->Settings->DestinationPort);
|
||||
}
|
||||
Globals->Settings->DestinationPort = StrDupSafe(settings->DestinationPort);
|
||||
}
|
||||
ApplyStringSetting(settings, DestinationAddressSet, SettingKeys->DestinationAddress,
|
||||
&Globals->Settings->DestinationAddress, settings->DestinationAddress, quiet);
|
||||
|
||||
ApplyStringSetting(settings, DestinationPortSet, SettingKeys->DestinationPort,
|
||||
&Globals->Settings->DestinationPort, settings->DestinationPort, quiet);
|
||||
|
||||
if ((settings->Values & ThresholdSet) == ThresholdSet)
|
||||
{
|
||||
|
|
19
state.h
19
state.h
|
@ -34,13 +34,16 @@
|
|||
#define TimeoutSet 0x004
|
||||
#define IntervalSet 0x008
|
||||
#define ReadonlySet 0x010
|
||||
#define DestinationAddressSet 0x020
|
||||
#define DestinationPortSet 0x040
|
||||
#define ThresholdSet 0x080
|
||||
#define LogFileSet 0x200
|
||||
#define ExpertSet 0x020
|
||||
#define DestinationAddressSet 0x040
|
||||
#define DestinationPortSet 0x080
|
||||
#define ThresholdSet 0x100
|
||||
#define PopKeySet 0x200
|
||||
#define PopUpSet 0x400
|
||||
#define LogFileSet 0x800
|
||||
|
||||
#define DefaultSettingType 0x01
|
||||
#define FileSettingType 0x02
|
||||
#define PrefsSettingType 0x02
|
||||
#define CliSettingType 0x03
|
||||
#define WbSettingType 0x04
|
||||
#define GlobalSettingType 0x10
|
||||
|
@ -82,10 +85,13 @@ struct AppSettings
|
|||
long Timeout;
|
||||
long Interval;
|
||||
long Readonly;
|
||||
long Expert;
|
||||
long long Threshold;
|
||||
char *DestinationAddress;
|
||||
char *DestinationPort;
|
||||
char *LogFile;
|
||||
char *PopKey;
|
||||
long Popup;
|
||||
long Values;
|
||||
long Type;
|
||||
};
|
||||
|
@ -110,10 +116,13 @@ struct AppSettingKeys
|
|||
const char *Timeout;
|
||||
const char *Interval;
|
||||
const char *Readonly;
|
||||
const char *Expert;
|
||||
const char *DestinationAddress;
|
||||
const char *DestinationPort;
|
||||
const char *Threshold;
|
||||
const char *LogFile;
|
||||
const char *PopKey;
|
||||
const char *Popup;
|
||||
};
|
||||
|
||||
typedef void (*ParseSettingFunction)(struct AppSettings *, void *);
|
||||
|
|
3
string.c
3
string.c
|
@ -346,6 +346,8 @@ int SNPrintf(char *str, size_t size, const char *format, ...)
|
|||
|
||||
#endif
|
||||
|
||||
// Not curretly in used
|
||||
#if 0
|
||||
/*
|
||||
* Split filename in path and filename.
|
||||
*/
|
||||
|
@ -389,3 +391,4 @@ void SplitFileName(const char *s, char *path, char *name)
|
|||
CopyMem((char *)s, path, x);
|
||||
CopyMem(++c, name, y);
|
||||
}
|
||||
#endif
|
||||
|
|
344
win_gad.c
344
win_gad.c
|
@ -163,159 +163,163 @@ bool CreateGadgets(void)
|
|||
|
||||
Globals->Window->Gadgets->ServerGadget = gadget;
|
||||
|
||||
// Port
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)portLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_PORT;
|
||||
gadget = CreateGadget(
|
||||
STRING_KIND, gadget, ng,
|
||||
GTST_String, (IPTR)Globals->Settings->DestinationPort,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
if (Globals->Settings->Expert)
|
||||
{
|
||||
// Port
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)portLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
Globals->Window->Gadgets->PortGadget = gadget;
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_PORT;
|
||||
gadget = CreateGadget(
|
||||
STRING_KIND, gadget, ng,
|
||||
GTST_String, (IPTR)Globals->Settings->DestinationPort,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
// Interval
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTNM_MaxNumberLen, 8,
|
||||
GTTX_Text, (IPTR)intervalLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
Globals->Window->Gadgets->PortGadget = gadget;
|
||||
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_INTERVAL;
|
||||
gadget = CreateGadget(
|
||||
INTEGER_KIND, gadget, ng,
|
||||
GTNM_MaxNumberLen, 8,
|
||||
GTIN_Number, Globals->Settings->Interval,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
// Interval
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTNM_MaxNumberLen, 8,
|
||||
GTTX_Text, (IPTR)intervalLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->IntervalGadget = gadget;
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_INTERVAL;
|
||||
gadget = CreateGadget(
|
||||
INTEGER_KIND, gadget, ng,
|
||||
GTNM_MaxNumberLen, 8,
|
||||
GTIN_Number, Globals->Settings->Interval,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
// Timeout
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)timeoutLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->IntervalGadget = gadget;
|
||||
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_TIMEOUT;
|
||||
gadget = CreateGadget(
|
||||
INTEGER_KIND, gadget, ng,
|
||||
GTNM_MaxNumberLen, 8,
|
||||
GTIN_Number, Globals->Settings->Timeout,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
// Timeout
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)timeoutLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->TimeoutGadget = gadget;
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_TIMEOUT;
|
||||
gadget = CreateGadget(
|
||||
INTEGER_KIND, gadget, ng,
|
||||
GTNM_MaxNumberLen, 8,
|
||||
GTIN_Number, Globals->Settings->Timeout,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
// Threshold
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)thresholdLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->TimeoutGadget = gadget;
|
||||
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_THRESHOLD;
|
||||
gadget = CreateGadget(
|
||||
STRING_KIND, gadget, ng,
|
||||
GTST_String, (IPTR)Globals->Window->ThresholdText,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
// Threshold
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)thresholdLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->ThresholdGadget = gadget;
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_THRESHOLD;
|
||||
gadget = CreateGadget(
|
||||
STRING_KIND, gadget, ng,
|
||||
GTST_String, (IPTR)Globals->Window->ThresholdText,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
// Verbose
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)verboseLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->ThresholdGadget = gadget;
|
||||
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_VERBOSE;
|
||||
gadget = CreateGadget(
|
||||
CYCLE_KIND, gadget, ng,
|
||||
GTCY_Labels, (IPTR)verboseLevel,
|
||||
GTCY_Active, Globals->Settings->Verbose,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
// Verbose
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)verboseLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->VerboseGadget = gadget;
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = boxWidth + 20;
|
||||
ng->ng_GadgetID = GID_VERBOSE;
|
||||
gadget = CreateGadget(
|
||||
CYCLE_KIND, gadget, ng,
|
||||
GTCY_Labels, (IPTR)verboseLevel,
|
||||
GTCY_Active, Globals->Settings->Verbose,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
// Priority
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)priorityLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->VerboseGadget = gadget;
|
||||
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = (boxWidth + 20) / 2;
|
||||
ng->ng_GadgetID = GID_PRIORITY;
|
||||
// Priority
|
||||
ng->ng_LeftEdge = col1;
|
||||
ng->ng_TopEdge += ng->ng_Height + 4;
|
||||
ng->ng_Width = textWidth;
|
||||
ng->ng_GadgetID = labelId++;
|
||||
gadget = CreateGadget(
|
||||
TEXT_KIND, gadget, ng,
|
||||
GTTX_Text, (IPTR)priorityLabel,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
gadget = CreateGadget(
|
||||
STRING_KIND, gadget, ng,
|
||||
GTST_String, (IPTR)Globals->Window->PriorityText,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
ng->ng_LeftEdge = col2;
|
||||
ng->ng_Width = (boxWidth + 20) / 2;
|
||||
ng->ng_GadgetID = GID_PRIORITY;
|
||||
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->PriorityGadget = gadget;
|
||||
gadget = CreateGadget(
|
||||
STRING_KIND, gadget, ng,
|
||||
GTST_String, (IPTR)Globals->Window->PriorityText,
|
||||
TAG_END);
|
||||
if (!gadget)
|
||||
return false;
|
||||
|
||||
gadget->Flags |= GFLG_TABCYCLE;
|
||||
Globals->Window->Gadgets->PriorityGadget = gadget;
|
||||
}
|
||||
|
||||
// Time zone
|
||||
ng->ng_LeftEdge = col1;
|
||||
|
@ -449,6 +453,9 @@ void SetPort(void)
|
|||
{
|
||||
char *port, *text;
|
||||
|
||||
if (Globals->Window->Gadgets->PortGadget == NULL)
|
||||
return;
|
||||
|
||||
GT_GetGadgetAttrs(
|
||||
Globals->Window->Gadgets->PortGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
|
@ -471,6 +478,9 @@ void SetInterval(void)
|
|||
{
|
||||
unsigned long value;
|
||||
|
||||
if (Globals->Window->Gadgets->IntervalGadget == NULL)
|
||||
return;
|
||||
|
||||
GT_GetGadgetAttrs(
|
||||
Globals->Window->Gadgets->IntervalGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
|
@ -497,6 +507,10 @@ void SetInterval(void)
|
|||
void SetTimeout(void)
|
||||
{
|
||||
unsigned long value;
|
||||
|
||||
if (Globals->Window->Gadgets->TimeoutGadget == NULL)
|
||||
return;
|
||||
|
||||
GT_GetGadgetAttrs(
|
||||
Globals->Window->Gadgets->TimeoutGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
|
@ -528,6 +542,9 @@ void SetThreshold(void)
|
|||
char *tempString;
|
||||
int result;
|
||||
|
||||
if (Globals->Window->Gadgets->ThresholdGadget == NULL)
|
||||
return;
|
||||
|
||||
GT_GetGadgetAttrs(
|
||||
Globals->Window->Gadgets->ThresholdGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
|
@ -553,6 +570,10 @@ void SetThreshold(void)
|
|||
void SetVerbose(void)
|
||||
{
|
||||
long value;
|
||||
|
||||
if (Globals->Window->Gadgets->VerboseGadget == NULL)
|
||||
return;
|
||||
|
||||
GT_GetGadgetAttrs(
|
||||
Globals->Window->Gadgets->VerboseGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
|
@ -584,6 +605,9 @@ void SetCxPriority(void)
|
|||
char *tempString;
|
||||
int result;
|
||||
|
||||
if (Globals->Window->Gadgets->PriorityGadget == NULL)
|
||||
return;
|
||||
|
||||
GT_GetGadgetAttrs(
|
||||
Globals->Window->Gadgets->PriorityGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
|
@ -668,53 +692,3 @@ void ShowLastSync(void)
|
|||
GTTX_Text, (IPTR)label,
|
||||
TAG_END);
|
||||
}
|
||||
|
||||
void SetDefaultSettings(void)
|
||||
{
|
||||
static char priorityText[MAXLONGCHARSIZE];
|
||||
static char thresholdText[MAXLONGLONGCHARSIZE];
|
||||
|
||||
GT_SetGadgetAttrs(
|
||||
Globals->Window->Gadgets->ServerGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
GTST_String, (IPTR)DefaultSettings.DestinationAddress,
|
||||
TAG_END);
|
||||
|
||||
GT_SetGadgetAttrs(
|
||||
Globals->Window->Gadgets->PortGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
GTST_String, (IPTR)DefaultSettings.DestinationPort,
|
||||
TAG_END);
|
||||
|
||||
GT_SetGadgetAttrs(
|
||||
Globals->Window->Gadgets->TimeoutGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
GTIN_Number, DefaultSettings.Timeout,
|
||||
TAG_END);
|
||||
|
||||
GT_SetGadgetAttrs(
|
||||
Globals->Window->Gadgets->IntervalGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
GTIN_Number, DefaultSettings.Interval,
|
||||
TAG_END);
|
||||
|
||||
LongLongToStr(DefaultSettings.Threshold, thresholdText);
|
||||
GT_SetGadgetAttrs(
|
||||
Globals->Window->Gadgets->ThresholdGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
GTST_String, (IPTR)thresholdText,
|
||||
TAG_END);
|
||||
|
||||
GT_SetGadgetAttrs(
|
||||
Globals->Window->Gadgets->VerboseGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
GTCY_Active, DefaultSettings.Verbose,
|
||||
TAG_END);
|
||||
|
||||
LongToStr(DefaultSettings.Priority, priorityText);
|
||||
GT_SetGadgetAttrs(
|
||||
Globals->Window->Gadgets->PriorityGadget,
|
||||
Globals->Window->SettingWindow, NULL,
|
||||
GTST_String, (IPTR)priorityText,
|
||||
TAG_END);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue