From d97541e72eb11c700c9f1eb5347cdb0bd2f145dd Mon Sep 17 00:00:00 2001 From: Carsten Larsen Date: Tue, 12 Jan 2021 22:50:54 +0100 Subject: [PATCH] Release 1.06 --- ChangeLog | 5 +- LICENSE | 2 +- Manual | 289 ++++++++++++++++++++++++++++++++++++++++++++++ broker.c | 2 +- com.c | 2 +- compiler.h | 2 +- config.h | 14 +-- library.c | 23 +++- log.c | 2 +- log.h | 2 +- main.c | 2 +- mem.h | 2 +- message.c | 2 +- message.h | 2 +- net.c | 2 +- net_getaddrinfo.c | 2 +- net_getaddrinfo.h | 2 +- net_poll.c | 2 +- sntp.c | 2 +- sntp.h | 2 +- state.c | 2 +- state.h | 2 +- string.c | 2 +- string.h | 2 +- time.c | 2 +- time.h | 2 +- win.h | 2 +- win_gad.c | 90 ++++++++++----- win_main.c | 2 +- 29 files changed, 407 insertions(+), 62 deletions(-) create mode 100644 Manual diff --git a/ChangeLog b/ChangeLog index 704f5fa..ae3d1d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ AmiTimeKeeper Change Log +v1.06 08.02.2019 + - Adjust layout in settings window + v1.05 06.08.2018 - Preferences can now be saved from settings window - Time zone is shown as UTC offset in settings window @@ -7,7 +10,7 @@ v1.05 06.08.2018 - Low water option renamed to threshold and high water option removed - New option for sending log messages to file instead of to screen - Some incorrect NTP log messages no longer appears - - Read-only options is now applied consistently + - Read-only option is now applied consistently - Potential race condition in memory allocation fixed - Other minor enhancements diff --git a/LICENSE b/LICENSE index 8841b7d..8031509 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ Copyright (c) 2001, 02 Motoyuki Kasahara Copyright (c) 2007 TANDBERG Telecom AS Copyright (c) 2008-2009 Dag-Erling Smørgrav -Copyright (c) 2017-2018 Carsten Sonne Larsen +Copyright (c) 2017-2019 Carsten Sonne Larsen All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/Manual b/Manual new file mode 100644 index 0000000..7dd8a6d --- /dev/null +++ b/Manual @@ -0,0 +1,289 @@ +@database TimeKeeper.guide +@$VER: TimeKeeper.guide 1.06 (2019-02-08) +@(c) 2017-2019 Carsten Sonne Larsen +@author Carsten Sonne Larsen + +@rem Copyright (c) 2017-2019 Carsten Sonne Larsen +@rem All rights reserved. +@rem +@rem Redistribution and use in source and binary forms, with or without +@rem modification, are permitted provided that the following conditions +@rem are met: +@rem 1. Redistributions of source code must retain the above copyright +@rem notice, this list of conditions and the following disclaimer. +@rem 2. Redistributions in binary form must reproduce the above copyright +@rem notice, this list of conditions and the following disclaimer in the +@rem documentation and/or other materials provided with the distribution. +@rem +@rem THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +@rem IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +@rem OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +@rem IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +@rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +@rem NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +@rem DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +@rem THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +@rem (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +@rem THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +@Width 74 + +@Node Main "TimeKeeper.guide" +@Next "Configuring the client" + +AmiTimeKeeper is a small program which keeps the time right on your +machine. No installation is required. + +AmiTimeKeeper is operated as a commodity and is controlled by AmigaOS. +An AmiTCP compatible TCP/IP stack is required for AmiTimeKeeper to work. + +AmiTimeKeeper can be configured through several settings. This can be +done either directly from the command line or by using the tooltypes +of an icon. Preferences can also be saved between reboots. + +@{"Configuring the client" Link "Configuring the client"} +@{"Using tooltypes of an icon" Link "Using tooltypes of an icon"} +@{"Saving preferences" Link "Saving preferences"} +@{"Change Log / Change History" Link "Change Log"} +@{"Software License" Link "Software License"} +@{"Contacting the author" Link "Contacting the author"} + +@EndNode + +@Node "Configuring the client" "TimeKeeper.guide/Configuring the client" +@Toc "Main" +@Prev "Main" +@Next "Using tooltypes of an icon" +@{b}Server Address@{ub} + +NTP servers are managed by several organizations. The pool.ntp.org +project and Network Time Foundation are probably the two most famous. +The pool.ntp.org project organize servers into pools whereas Network +Time Foundation maintains a list of valid NTP servers. The servers are +divided into two categories: Stratum 1 and Stratum 2. + +The NTP pool servers are divided into zones. If you want to use a server +in Europe you can use set the server address to europe.pool.ntp.org. +For North America the server address is north-america.pool.ntp.org. +Zones also exists for countries. To use a server in for example Germany +the server address should be set to de.pool.ntp.org. For Switzerland +the address should be ch.pool.ntp.org. + +Network Time Foundation has a website on http://support.ntp.org/ +The pool.ntp.org project website is located at https://www.ntppool.org/ + +@{b}Server Port@{ub} + +NTP servers use port 123 as default. Only under special circumstances +are the NTP server port different from 123. + +@{b}Interval between requests@{ub} + +The Amiga hardware clock will slowly drift away from true time. The +drift is determined by several factors and is small, but the drift is not +insignificant. Request are repeatedly sent to the NTP server in order to +keep the Amiga hardware clock as close to true time as possible. + +The requests are sent in certain intervals defined by the interval +parameter. The interval should be specified using milliseconds. One +thousand (1.000) milliseconds are equal to one second. + +@{b}Threshold@{ub} + +Due to the accuracy of NTP servers and the nature of Amiga CPUs it does +not make sense to adjust the Amiga clock on every response from the NTP +server. Processing the response could take longer time than anticipated. +The amount of accepted inaccuracy is set using the threshold parameter. +The threshold should be specified using microsecond. One million +microseconds (1.000.000) are equal to one second. + +@{b}Read Only@{ub} + +It is possible to send request to the NTP server without setting the +Amiga hardware clock. This option can be handy when debugging time zone +setup and other time related parameters. + +@{b}Connection Timeout@{ub} + +In some cases, a connection to the NTP server cannot be established or +the NTP server simply does respond. To avoid an infinitive wait for a +response the connection will instead make a time out. The timeout +interval should be specified using milliseconds. One thousand (1.000) +milliseconds are equal to one second. + +@{b}Verbosity@{ub} + +The level of logging can be adjusted from none to all. Expressed as a +numeric value verbose can be 0, 1, 2 or 3, where 0 is equal to none and +3 is equal to maximum verbosity. + +@{b}Log file@{ub} + +It is possible to send log messages to a file instead of sending them to +a console window. + +@EndNode + +@Node "Using tooltypes of an icon" "TimeKeeper.guide/Using tooltypes of an icon" +@Toc "Main" +@Prev "Configuring the client" +@Next "Saving preferences" + +Settings can be changes by setting tooltypes in the TimeKeeper icon. +Add the following line to the icon tooltypes in order to set the server +to an European pool server: +SERVER=europe.pool.ntp.org + +The available tooltypes are the same as the available command line +parameters. + +@{b}Parameter@{ub} | @{b}Short description@{ub} +----------------------------------------- +SERVER | Server Address +PORT | Server Port +THRESHOLD | Adjustment threshold +INTERVAL | Interval between requests +CX_PRIORITY | Commodity priority +READONLY | Read only option +TIMEOUT | Connection Timeout +VERBOSE | Log verbosity +LOGFILE | Log file location + +@{b}Caveats@{ub} + +Settings can be overridden and are set in the following order: +1. Preference file +2. Icon tooltypes +3. CLI parameters + +CLI parameters has highest precedence and will always override settings +from icon tooltypes and from the preference file. + +@EndNode + +@Node "Saving preferences" "TimeKeeper.guide/Saving preferences" +@Toc "Main" +@Prev "Using tooltypes of an icon" +@Next "Change Log" + +Preferences from the setting window are saved in the file +ENV:timekeeper.prefs + +Preferences are also persisted between reboots in the file +ENVARC:timekeeper.prefs + +Depending on the setup the content of timekeeper.prefs could be: + +CX_PRIORITY=25 +THRESHOLD=1000000 +SERVER=de.pool.ntp.org +PORT=123 +TIMEOUT=5000 +INTERVAL=17500 +VERBOSE=3 +READONLY=0 +LOGFILE=RAM:log + +The preference file should not be edited under normal circumstances. + +@{b}Caveats@{ub} + +If LOGFILE is set in the preference file, no messages will be emitted +to screen (unless overridden by CLI or Icon tooltype with LOGFILE=NO). + +@EndNode + +@Node "Change Log" "TimeKeeper.guide/Change Log" +@Toc "Main" +@Prev "Saving preferences" +@Next "Software License" + +@{b}v1.06 08.02.2019@{ub} + - Adjust layout in settings window + +@{b}v1.05 06.08.2018@{ub} + - Preferences can now be saved from settings window + - Time zone is shown as UTC offset in settings window + - Running multiple instances no longer create zombie processes + - Low water option renamed to threshold and high water option removed + - New option for sending log messages to file instead of to screen + - Some incorrect NTP log messages no longer appears + - Read-only option is now applied consistently + - Potential race condition in memory allocation fixed + - Other minor enhancements + +@{b}v1.04 15.12.2017@{ub} + - Default settings adjusted to comply better with AmigaOS + - Bugs in threshold settings (high/low water) fixed + - Bugs in opening and closing of libraries fixed + - New and more accurate error and log messages + +@{b}v1.03 09.12.2017@{ub} + - Settings window + +@{b}v1.02 29.11.2017@{ub} + - AROS code compliance + +@{b}v1.01 28.11.2017@{ub} + - Handle network disconnection + - Fix infinity timeout problem + - Support hardware clock + - Improved error messages + +@{b}v1.00 26.11.2017@{ub} + - First public release + +@EndNode + +@Node "Software License" "TimeKeeper.guide/Software License" +@Prev "Change Log" +@Next "Contacting the author" +@Toc "Main" + +@{b}Simplified BSD License / 2-clause BSD license@{ub} + +Copyright (c) 2001, 02 Motoyuki Kasahara +Copyright (c) 2007 TANDBERG Telecom AS +Copyright (c) 2008-2009 Dag-Erling Smørgrav +Copyright (c) 2017-2019 Carsten Sonne Larsen +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +@EndNode + +@Node "Contacting the author" "TimeKeeper.guide/Contacting the author" +@Toc "Main" +@Prev "Software License" + +The author of AmiTimeKeeper can be contacted using the following +email addresses: or . + +Please notice is a member of several high volume +mailing lists and should not be used under normal circumstances. + +Feel free to send suggestions, feature request and bug reports. +General comment and questions are also welcome. + +Carsten Sonne Larsen +February 2019 + +@EndNode diff --git a/broker.c b/broker.c index ebe4333..c2ce4d7 100644 --- a/broker.c +++ b/broker.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/com.c b/com.c index 590846c..cb1aa3f 100644 --- a/com.c +++ b/com.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/compiler.h b/compiler.h index 96a2dfe..826816d 100644 --- a/compiler.h +++ b/compiler.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014-2018 Carsten Sonne Larsen + * Copyright (c) 2014-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/config.h b/config.h index ed41d25..80c32a0 100644 --- a/config.h +++ b/config.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #include #include @@ -48,6 +50,7 @@ #include #include #include +#include #include #include @@ -127,11 +130,6 @@ int poll(struct pollfd *, nfds_t, int); #if AOS3 #define IPTR ULONG #endif -#if AOS3 -#define VARSIZE 0 -#else -#define VARSIZE 1 -#endif #ifdef AROS #define VSNPrintf(str, n, format, args) vsnprintf(str, n, format, args) @@ -145,8 +143,8 @@ int poll(struct pollfd *, nfds_t, int); #define APP_SHORT_NAME "AmiTimeKeeper" #define APP_LONG_NAME "Amiga Time Keeper" -#define APP_VERSION "1.05" -#define APP_DATE_VERSION "1.05 (06.08.2018)" +#define APP_VERSION "1.06" +#define APP_DATE_VERSION "1.06 (08.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 diff --git a/library.c b/library.c index 39264f8..dbaa286 100644 --- a/library.c +++ b/library.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,6 +31,7 @@ /* Library identifiers */ static const char *dosName = "dos.library"; static const char *aslName = "asl.library"; +static const char *gfxName = "graphics.library"; static const char *iconName = "icon.library"; static const char *commoditiesName = "commodities.library"; static const char *localeName = "locale.library"; @@ -46,6 +47,7 @@ static const char *mathName = "mathieeedoubbas.library"; #define UtilityBase __FX_UtilityBase #define IntuitionBase __FX_IntuitionBase #define CxBase __FX_CxBase +#define GfxBase __FX_GfxBase #define AslBase __FX_AslBase #define IconBase __FX_IconBase #define GadToolsBase __FX_GadToolsBase @@ -60,6 +62,7 @@ struct LocaleBase *LocaleBase = NULL; struct UtilityBase *UtilityBase = NULL; struct IntuitionBase *IntuitionBase = NULL; struct Library *CxBase = NULL; +struct Library *GfxBase = NULL; struct Library *AslBase = NULL; struct Library *IconBase = NULL; struct Library *GadToolsBase = NULL; @@ -70,6 +73,8 @@ struct UtilityBase *__UtilityBase = NULL; #define DOSLIB_REV 36L #define ASLLIB_NAME ((STRPTR)aslName) #define ASLLIB_REV 37L +#define GFXLIB_NAME ((STRPTR)gfxName) +#define GFXLIB_REV 37L #define ICONLIB_NAME ((STRPTR)iconName) #define ICONLIB_REV 36L #define COMMODLIB_NAME ((STRPTR)commoditiesName) @@ -217,6 +222,15 @@ int OpenLibraries(void) OpenLibrarySuccess(GadToolsBase->lib_IdString); + // Graphics Library + if (!(GfxBase = OpenLibrary((STRPTR)GFXLIB_NAME, GFXLIB_REV))) + { + OpenLibraryError(GFXLIB_NAME, GFXLIB_REV); + return LIB_ERROR; + } + + OpenLibrarySuccess(GfxBase->lib_IdString); + // Locale if (!(Globals->Locale = OpenLocale(NULL))) { @@ -308,6 +322,13 @@ void CloseLibraries(void) GadToolsBase = NULL; } + if (GfxBase != NULL) + { + ClosingLibrary(GfxBase->lib_IdString); + CloseLibrary(GfxBase); + GfxBase = NULL; + } + if (IntuitionBase != NULL) { ClosingLibrary(((struct Library *)IntuitionBase)->lib_IdString); diff --git a/log.c b/log.c index 51b63f5..4394ab4 100644 --- a/log.c +++ b/log.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/log.h b/log.h index a404c5e..5eb1a4f 100644 --- a/log.h +++ b/log.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/main.c b/main.c index 4a0bcdf..8d81259 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/mem.h b/mem.h index 3770d79..d942e7f 100644 --- a/mem.h +++ b/mem.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2014-2018 Carsten Sonne Larsen + * Copyright (c) 2014-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/message.c b/message.c index 9241437..8f70902 100644 --- a/message.c +++ b/message.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/message.h b/message.h index 3fa976e..4044809 100644 --- a/message.h +++ b/message.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/net.c b/net.c index a5970fc..79078fd 100644 --- a/net.c +++ b/net.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/net_getaddrinfo.c b/net_getaddrinfo.c index 147cc16..32fdf83 100644 --- a/net_getaddrinfo.c +++ b/net_getaddrinfo.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2001, 02 Motoyuki Kasahara - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/net_getaddrinfo.h b/net_getaddrinfo.h index 526f85e..b78bc7c 100644 --- a/net_getaddrinfo.h +++ b/net_getaddrinfo.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2001, 02 Motoyuki Kasahara - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/net_poll.c b/net_poll.c index 5b80bac..a297082 100644 --- a/net_poll.c +++ b/net_poll.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sntp.c b/sntp.c index 0b54c42..9b7036a 100644 --- a/sntp.c +++ b/sntp.c @@ -1,7 +1,7 @@ /*- * Copyright (c) 2007 TANDBERG Telecom AS * Copyright (c) 2008-2009 Dag-Erling Smørgrav - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sntp.h b/sntp.h index 41c6213..5356b5e 100644 --- a/sntp.h +++ b/sntp.h @@ -1,7 +1,7 @@ /*- * Copyright (c) 2007 TANDBERG Telecom AS * Copyright (c) 2008-2009 Dag-Erling Smørgrav - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/state.c b/state.c index 781790f..97a5efb 100644 --- a/state.c +++ b/state.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/state.h b/state.h index edba8fd..adb8b00 100644 --- a/state.h +++ b/state.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/string.c b/string.c index 22f795e..afd1893 100644 --- a/string.c +++ b/string.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/string.h b/string.h index 4feca53..5b1f977 100644 --- a/string.h +++ b/string.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/time.c b/time.c index bba0e21..6171217 100644 --- a/time.c +++ b/time.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/time.h b/time.h index e4eced5..dbea268 100644 --- a/time.h +++ b/time.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/win.h b/win.h index 725c966..10dea53 100644 --- a/win.h +++ b/win.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/win_gad.c b/win_gad.c index 329c60a..0244136 100644 --- a/win_gad.c +++ b/win_gad.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -57,6 +57,18 @@ static const char *saveLabel = "Save"; static const char *useLabel = "Use"; static const char *cancelLabel = "Cancel"; +static const char **textLabels[] = { + &serverLabel, + &portLabel, + &timeoutLabel, + &intervalLabel, + &thresholdLabel, + &verboseLabel, + &priorityLabel, + &timeZoneLabel, + &lastSyncLabel, + NULL}; + static char *verboseLevel[] = { "Show none (0)", "Show some (1)", @@ -64,15 +76,37 @@ static char *verboseLevel[] = { "Show all (3)", NULL}; +int GetLabelWidth(struct RastPort *rp) +{ + int len, max = 0; + int c, i = 0; + const char **label = textLabels[0]; + + while (**label != NULL) + { + c = StrLen(*label); + len = TextLength(rp, *label, c); + if (len > max) + { + max = len; + } + + label = textLabels[++i]; + } + + return max; +} + bool CreateGadgets(void) { struct Gadget *gadget; struct NewGadget *ng; - long x, y, w, h; + long x, y, h; + long labelWidth; long textWidth, boxWidth; long col1, col2; long labelId; - long tmp1, tmp2; + long tmp1, tmp2; Globals->Window->Gadgets = (struct AppSettingWindowGadgets *) AllocMemSafe(sizeof(struct AppSettingWindowGadgets)); @@ -88,18 +122,18 @@ bool CreateGadgets(void) ng->ng_VisualInfo = Globals->Window->VisualInfo; ng->ng_TextAttr = Globals->Window->Screen->Font; ng->ng_Flags = 0; - - w = Globals->Window->Screen->RastPort.TxWidth; + h = Globals->Window->Screen->RastPort.TxHeight; - x = Globals->Window->Screen->WBorLeft + 8; y = Globals->Window->Screen->WBorTop + h + 9; + labelWidth = GetLabelWidth(&Globals->Window->Screen->RastPort); + col1 = x; - textWidth = 13 + VARSIZE; + textWidth = labelWidth + Globals->Window->Screen->RastPort.TxWidth / 2; - col2 = col1 + w * textWidth; - boxWidth = 13 + VARSIZE * 2; + col2 = col1 + textWidth; + boxWidth = labelWidth; ng->ng_TopEdge = y; ng->ng_Height = h + 6; @@ -108,7 +142,7 @@ bool CreateGadgets(void) // Server ng->ng_LeftEdge = col1; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -118,7 +152,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = boxWidth * w + 20; + ng->ng_Width = boxWidth + 20; ng->ng_GadgetID = GID_SERVER; gadget = CreateGadget( STRING_KIND, gadget, ng, @@ -132,7 +166,7 @@ bool CreateGadgets(void) // Port ng->ng_LeftEdge = col1; ng->ng_TopEdge += ng->ng_Height + 4; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -142,7 +176,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = boxWidth * w + 20; + ng->ng_Width = boxWidth + 20; ng->ng_GadgetID = GID_PORT; gadget = CreateGadget( STRING_KIND, gadget, ng, @@ -156,7 +190,7 @@ bool CreateGadgets(void) // Interval ng->ng_LeftEdge = col1; ng->ng_TopEdge += ng->ng_Height + 4; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -167,7 +201,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = boxWidth * w + 20; + ng->ng_Width = boxWidth + 20; ng->ng_GadgetID = GID_INTERVAL; gadget = CreateGadget( INTEGER_KIND, gadget, ng, @@ -183,7 +217,7 @@ bool CreateGadgets(void) // Timeout ng->ng_LeftEdge = col1; ng->ng_TopEdge += ng->ng_Height + 4; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -193,7 +227,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = boxWidth * w + 20; + ng->ng_Width = boxWidth + 20; ng->ng_GadgetID = GID_TIMEOUT; gadget = CreateGadget( INTEGER_KIND, gadget, ng, @@ -209,7 +243,7 @@ bool CreateGadgets(void) // Threshold ng->ng_LeftEdge = col1; ng->ng_TopEdge += ng->ng_Height + 4; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -219,7 +253,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = boxWidth * w + 20; + ng->ng_Width = boxWidth + 20; ng->ng_GadgetID = GID_THRESHOLD; gadget = CreateGadget( STRING_KIND, gadget, ng, @@ -234,7 +268,7 @@ bool CreateGadgets(void) // Verbose ng->ng_LeftEdge = col1; ng->ng_TopEdge += ng->ng_Height + 4; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -244,7 +278,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = boxWidth * w + 20; + ng->ng_Width = boxWidth + 20; ng->ng_GadgetID = GID_VERBOSE; gadget = CreateGadget( CYCLE_KIND, gadget, ng, @@ -260,7 +294,7 @@ bool CreateGadgets(void) // Priority ng->ng_LeftEdge = col1; ng->ng_TopEdge += ng->ng_Height + 4; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -270,7 +304,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = (boxWidth * w + 20) / 2; + ng->ng_Width = (boxWidth + 20) / 2; ng->ng_GadgetID = GID_PRIORITY; gadget = CreateGadget( @@ -286,7 +320,7 @@ bool CreateGadgets(void) // Time zone ng->ng_LeftEdge = col1; ng->ng_TopEdge += ng->ng_Height + 4; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -296,7 +330,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = boxWidth * w + 20; + ng->ng_Width = boxWidth + 20; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -310,7 +344,7 @@ bool CreateGadgets(void) // Last sync ng->ng_LeftEdge = col1; ng->ng_TopEdge += ng->ng_Height + 4; - ng->ng_Width = textWidth * w + 20; + ng->ng_Width = textWidth; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -320,7 +354,7 @@ bool CreateGadgets(void) return false; ng->ng_LeftEdge = col2; - ng->ng_Width = boxWidth * w + 20; + ng->ng_Width = boxWidth + 20; ng->ng_GadgetID = labelId++; gadget = CreateGadget( TEXT_KIND, gadget, ng, @@ -358,7 +392,7 @@ bool CreateGadgets(void) return false; Globals->Window->Height = ng->ng_TopEdge + ng->ng_Height; - Globals->Window->Width = textWidth * w + boxWidth * w; + Globals->Window->Width = textWidth + boxWidth; FreeMemSafe(ng); return true; diff --git a/win_main.c b/win_main.c index 23c35d6..eb8eb0f 100644 --- a/win_main.c +++ b/win_main.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017-2018 Carsten Sonne Larsen + * Copyright (c) 2017-2019 Carsten Sonne Larsen * All rights reserved. * * Redistribution and use in source and binary forms, with or without