AmiTimeKeeper/win_gad.c

627 lines
14 KiB
C
Raw Permalink Normal View History

2018-11-24 21:39:18 +00:00
/*-
2021-01-12 22:16:18 +00:00
* Copyright (c) 2017-2021 Carsten Sonne Larsen <cs@innolan.net>
2018-11-24 21:39:18 +00:00
* 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.
2021-01-12 22:00:49 +00:00
*
2018-11-24 21:39:18 +00:00
*/
#include "config.h"
2021-01-12 22:02:29 +00:00
#include "global.h"
2018-11-24 21:39:18 +00:00
#include "message.h"
2021-01-12 22:02:29 +00:00
#include "setting.h"
#include "timer.h"
2021-01-12 22:16:18 +00:00
#include "conv.h"
#include "text.h"
2018-11-24 21:39:18 +00:00
#include "mem.h"
#include "win.h"
2021-01-12 22:16:18 +00:00
#include "val.h"
2021-01-12 22:02:29 +00:00
#include "tz.h"
#include "logmod.h"
#define MODULENAME "Window"
2018-11-24 21:39:18 +00:00
struct AppSettingWindowGadgets
{
struct Gadget *ServerGadget;
struct Gadget *PortGadget;
struct Gadget *TimeoutGadget;
struct Gadget *IntervalGadget;
struct Gadget *ThresholdGadget;
struct Gadget *PriorityGadget;
2021-01-12 22:02:29 +00:00
struct Gadget *TimezoneGadget;
2018-11-24 21:39:18 +00:00
struct Gadget *LastSyncGadget;
};
static const char *serverLabel = "Server address";
static const char *portLabel = "Server port";
static const char *timeoutLabel = "Timeout (ms)";
static const char *intervalLabel = "Interval (ms)";
static const char *thresholdLabel = "Threshold (us)";
static const char *priorityLabel = "CX priority";
2021-01-12 22:02:29 +00:00
static const char *TimezoneLabel = "Time zone";
2018-11-24 21:39:18 +00:00
static const char *lastSyncLabel = "Last sync";
static const char *saveLabel = "Save";
static const char *useLabel = "Use";
static const char *cancelLabel = "Cancel";
2021-01-12 21:50:54 +00:00
static const char **textLabels[] = {
&serverLabel,
&portLabel,
&timeoutLabel,
&intervalLabel,
&thresholdLabel,
&priorityLabel,
2021-01-12 22:02:29 +00:00
&TimezoneLabel,
2021-01-12 21:50:54 +00:00
&lastSyncLabel,
NULL};
int GetLabelWidth(struct RastPort *rp)
{
int len, max = 0;
int c, i = 0;
const char **label = textLabels[0];
2021-01-12 22:16:18 +00:00
while (*label != NULL)
2021-01-12 21:50:54 +00:00
{
c = StrLen(*label);
2021-01-12 22:02:29 +00:00
len = TextLength(rp, (CONST_STRPTR)*label, c);
2021-01-12 21:50:54 +00:00
if (len > max)
{
max = len;
}
label = textLabels[++i];
}
return max;
}
2018-11-24 21:39:18 +00:00
bool CreateGadgets(void)
{
struct Gadget *gadget;
struct NewGadget *ng;
2021-01-12 21:50:54 +00:00
long x, y, h;
long labelWidth;
2018-11-24 21:39:18 +00:00
long textWidth, boxWidth;
long col1, col2;
long labelId;
2021-01-12 21:53:12 +00:00
long tmp1, tmp2;
2018-11-24 21:39:18 +00:00
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets = AllocStructSafe(struct AppSettingWindowGadgets);
ng = AllocStructSafe(struct NewGadget);
2018-11-24 21:39:18 +00:00
if (!ng)
return false;
2021-01-12 22:02:29 +00:00
gadget = CreateContext(&SettingWindow.GadgetList);
2018-11-24 21:39:18 +00:00
if (!gadget)
return false;
2021-01-12 22:02:29 +00:00
ng->ng_VisualInfo = SettingWindow.VisualInfo;
ng->ng_TextAttr = SettingWindow.Screen->Font;
2018-11-24 21:39:18 +00:00
ng->ng_Flags = 0;
2021-01-12 21:53:12 +00:00
2021-01-12 22:02:29 +00:00
h = SettingWindow.Screen->RastPort.TxHeight;
x = SettingWindow.Screen->WBorLeft + 8;
y = SettingWindow.Screen->WBorTop + h + 9;
2018-11-24 21:39:18 +00:00
2021-01-12 22:02:29 +00:00
labelWidth = GetLabelWidth(&SettingWindow.Screen->RastPort);
2021-01-12 21:53:12 +00:00
2018-11-24 21:39:18 +00:00
col1 = x;
2021-01-12 22:02:29 +00:00
textWidth = labelWidth + SettingWindow.Screen->RastPort.TxWidth / 2;
2018-11-24 21:39:18 +00:00
2021-01-12 21:50:54 +00:00
col2 = col1 + textWidth;
boxWidth = labelWidth;
2018-11-24 21:39:18 +00:00
ng->ng_TopEdge = y;
ng->ng_Height = h + 6;
labelId = 5000;
// Server
ng->ng_LeftEdge = col1;
2021-01-12 21:50:54 +00:00
ng->ng_Width = textWidth;
2018-11-24 21:39:18 +00:00
ng->ng_GadgetID = labelId++;
gadget = CreateGadget(
TEXT_KIND, gadget, ng,
GTTX_Text, (IPTR)serverLabel,
TAG_END);
if (!gadget)
return false;
ng->ng_LeftEdge = col2;
2021-01-12 21:50:54 +00:00
ng->ng_Width = boxWidth + 20;
2018-11-24 21:39:18 +00:00
ng->ng_GadgetID = GID_SERVER;
gadget = CreateGadget(
STRING_KIND, gadget, ng,
2021-01-12 22:02:29 +00:00
GTST_String, (IPTR)Settings->DestinationAddress,
2018-11-24 21:39:18 +00:00
TAG_END);
if (!gadget)
return false;
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->ServerGadget = gadget;
2018-11-24 21:39:18 +00:00
2021-01-12 22:02:29 +00:00
if (Settings->Expert)
2021-01-12 21:53:12 +00:00
{
// 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,
2021-01-12 22:02:29 +00:00
GTST_String, (IPTR)Settings->DestinationPort,
2021-01-12 21:53:12 +00:00
TAG_END);
if (!gadget)
return false;
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->PortGadget = gadget;
2021-01-12 21:53:12 +00:00
// 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;
ng->ng_LeftEdge = col2;
ng->ng_Width = boxWidth + 20;
ng->ng_GadgetID = GID_INTERVAL;
gadget = CreateGadget(
INTEGER_KIND, gadget, ng,
GTNM_MaxNumberLen, 8,
2021-01-12 22:02:29 +00:00
GTIN_Number, Settings->Interval,
2021-01-12 21:53:12 +00:00
TAG_END);
if (!gadget)
return false;
gadget->Flags |= GFLG_TABCYCLE;
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->IntervalGadget = gadget;
2021-01-12 21:53:12 +00:00
// 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;
ng->ng_LeftEdge = col2;
ng->ng_Width = boxWidth + 20;
ng->ng_GadgetID = GID_TIMEOUT;
gadget = CreateGadget(
INTEGER_KIND, gadget, ng,
GTNM_MaxNumberLen, 8,
2021-01-12 22:02:29 +00:00
GTIN_Number, Settings->Timeout,
2021-01-12 21:53:12 +00:00
TAG_END);
if (!gadget)
return false;
gadget->Flags |= GFLG_TABCYCLE;
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->TimeoutGadget = gadget;
2021-01-12 21:53:12 +00:00
// 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;
ng->ng_LeftEdge = col2;
ng->ng_Width = boxWidth + 20;
ng->ng_GadgetID = GID_THRESHOLD;
gadget = CreateGadget(
STRING_KIND, gadget, ng,
2021-01-12 22:02:29 +00:00
GTST_String, (IPTR)SettingWindow.ThresholdText,
2021-01-12 21:53:12 +00:00
TAG_END);
if (!gadget)
return false;
gadget->Flags |= GFLG_TABCYCLE;
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->ThresholdGadget = gadget;
2021-01-12 21:53:12 +00:00
// 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;
2018-11-24 21:39:18 +00:00
2021-01-12 21:53:12 +00:00
ng->ng_LeftEdge = col2;
ng->ng_Width = (boxWidth + 20) / 2;
ng->ng_GadgetID = GID_PRIORITY;
2018-11-24 21:39:18 +00:00
2021-01-12 21:53:12 +00:00
gadget = CreateGadget(
STRING_KIND, gadget, ng,
2021-01-12 22:02:29 +00:00
GTST_String, (IPTR)SettingWindow.PriorityText,
2021-01-12 21:53:12 +00:00
TAG_END);
if (!gadget)
return false;
2018-11-24 21:39:18 +00:00
2021-01-12 21:53:12 +00:00
gadget->Flags |= GFLG_TABCYCLE;
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->PriorityGadget = gadget;
2021-01-12 21:53:12 +00:00
}
2018-11-24 21:39:18 +00:00
// Time zone
ng->ng_LeftEdge = col1;
ng->ng_TopEdge += ng->ng_Height + 4;
2021-01-12 21:50:54 +00:00
ng->ng_Width = textWidth;
2018-11-24 21:39:18 +00:00
ng->ng_GadgetID = labelId++;
gadget = CreateGadget(
TEXT_KIND, gadget, ng,
2021-01-12 22:02:29 +00:00
GTTX_Text, (IPTR)TimezoneLabel,
2018-11-24 21:39:18 +00:00
TAG_END);
if (!gadget)
return false;
ng->ng_LeftEdge = col2;
2021-01-12 21:50:54 +00:00
ng->ng_Width = boxWidth + 20;
2018-11-24 21:39:18 +00:00
ng->ng_GadgetID = labelId++;
gadget = CreateGadget(
TEXT_KIND, gadget, ng,
2021-01-12 22:02:29 +00:00
GTTX_Text, (IPTR)SettingWindow.TimezoneText,
2018-11-24 21:39:18 +00:00
TAG_END);
if (!gadget)
return false;
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->TimezoneGadget = gadget;
2018-11-24 21:39:18 +00:00
// Last sync
ng->ng_LeftEdge = col1;
ng->ng_TopEdge += ng->ng_Height + 4;
2021-01-12 21:50:54 +00:00
ng->ng_Width = textWidth;
2018-11-24 21:39:18 +00:00
ng->ng_GadgetID = labelId++;
gadget = CreateGadget(
TEXT_KIND, gadget, ng,
GTTX_Text, (IPTR)lastSyncLabel,
TAG_END);
if (!gadget)
return false;
ng->ng_LeftEdge = col2;
2021-01-12 21:50:54 +00:00
ng->ng_Width = boxWidth + 20;
2018-11-24 21:39:18 +00:00
ng->ng_GadgetID = labelId++;
gadget = CreateGadget(
TEXT_KIND, gadget, ng,
TAG_END);
if (!gadget)
return false;
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->LastSyncGadget = gadget;
2018-11-24 21:39:18 +00:00
tmp1 = ng->ng_LeftEdge + ng->ng_Width - 18; // Why is this 18?
tmp2 = tmp1 / 3;
ng->ng_TopEdge += ng->ng_Height + 6;
ng->ng_Width = tmp2;
ng->ng_LeftEdge = col1;
ng->ng_GadgetText = (STRPTR)saveLabel;
ng->ng_GadgetID = GID_SAVE;
ng->ng_Flags = 0;
gadget = CreateGadget(BUTTON_KIND, gadget, ng, TAG_END);
if (!gadget)
return false;
ng->ng_LeftEdge += ng->ng_Width + 4;
ng->ng_GadgetText = (STRPTR)useLabel;
ng->ng_GadgetID = GID_USE;
gadget = CreateGadget(BUTTON_KIND, gadget, ng, TAG_END);
if (!gadget)
return false;
ng->ng_LeftEdge += ng->ng_Width + 4;
ng->ng_GadgetText = (STRPTR)cancelLabel;
ng->ng_GadgetID = GID_CANCEL;
gadget = CreateGadget(BUTTON_KIND, gadget, ng, TAG_END);
if (!gadget)
return false;
2021-01-12 22:02:29 +00:00
SettingWindow.Height = ng->ng_TopEdge + ng->ng_Height;
SettingWindow.Width = textWidth + boxWidth;
2018-11-24 21:39:18 +00:00
2021-01-12 22:02:29 +00:00
FreeMemSafe(ng);
2018-11-24 21:39:18 +00:00
return true;
}
2021-01-12 22:16:18 +00:00
void UseSettings(void)
2018-11-24 21:39:18 +00:00
{
2021-01-12 22:16:18 +00:00
LogNotice("Apply new settings");
ReadUiServer();
ReadUiPort();
ReadUiInterval();
ReadUiTimeout();
ReadUiThreshold();
ReadUiCxPriority();
2018-11-24 21:39:18 +00:00
}
2021-01-12 22:16:18 +00:00
void WriteUiServer(void)
2018-11-24 21:39:18 +00:00
{
2021-01-12 22:16:18 +00:00
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->ServerGadget == NULL)
return;
GT_SetGadgetAttrs(
SettingWindow.Gadgets->ServerGadget,
SettingWindow.Window, NULL,
GTST_String, (IPTR)Settings->DestinationAddress,
TAG_END);
2018-11-24 21:39:18 +00:00
}
2021-01-12 22:16:18 +00:00
void ReadUiServer(void)
2018-11-24 21:39:18 +00:00
{
2021-01-12 22:16:18 +00:00
char *valueString;
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->ServerGadget == NULL)
return;
2018-11-24 21:39:18 +00:00
GT_GetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->ServerGadget,
SettingWindow.Window, NULL,
2021-01-12 22:16:18 +00:00
GTST_String, (IPTR)&valueString,
2018-11-24 21:39:18 +00:00
TAG_END);
2021-01-12 22:16:18 +00:00
SetServer(valueString, APPLY_UI_FRONT | APPLY_RUNTIME);
}
void WriteUiPort(void)
{
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->PortGadget == NULL)
2018-11-24 21:39:18 +00:00
return;
2021-01-12 22:16:18 +00:00
GT_SetGadgetAttrs(
SettingWindow.Gadgets->PortGadget,
SettingWindow.Window, NULL,
GTST_String, (IPTR)Settings->DestinationPort,
TAG_END);
2018-11-24 21:39:18 +00:00
}
2021-01-12 22:16:18 +00:00
void ReadUiPort(void)
2018-11-24 21:39:18 +00:00
{
2021-01-12 22:16:18 +00:00
char *valueString;
2018-11-24 21:39:18 +00:00
2021-01-12 22:16:18 +00:00
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->PortGadget == NULL)
2021-01-12 21:53:12 +00:00
return;
2018-11-24 21:39:18 +00:00
GT_GetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->PortGadget,
SettingWindow.Window, NULL,
2021-01-12 22:16:18 +00:00
GTST_String, (IPTR)&valueString,
2018-11-24 21:39:18 +00:00
TAG_END);
2021-01-12 22:16:18 +00:00
SetPort(valueString, APPLY_UI_FRONT | APPLY_RUNTIME);
}
void WriteUiInterval(void)
{
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->IntervalGadget == NULL)
2018-11-24 21:39:18 +00:00
return;
2021-01-12 22:16:18 +00:00
GT_SetGadgetAttrs(
SettingWindow.Gadgets->IntervalGadget,
SettingWindow.Window, NULL,
GTIN_Number, (ULONG)Settings->Interval,
TAG_END);
2018-11-24 21:39:18 +00:00
}
2021-01-12 22:16:18 +00:00
void ReadUiInterval(void)
2018-11-24 21:39:18 +00:00
{
unsigned long value;
2021-01-12 22:16:18 +00:00
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->IntervalGadget == NULL)
2021-01-12 21:53:12 +00:00
return;
2018-11-24 21:39:18 +00:00
GT_GetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->IntervalGadget,
SettingWindow.Window, NULL,
2018-11-24 21:39:18 +00:00
GTIN_Number, (IPTR)&value,
TAG_END);
2021-01-12 22:16:18 +00:00
SetInterval(value, APPLY_UI_FRONT | APPLY_RUNTIME);
2018-11-24 21:39:18 +00:00
}
2021-01-12 22:16:18 +00:00
void WriteUiTimeout(void)
{
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->TimeoutGadget == NULL)
return;
GT_SetGadgetAttrs(
SettingWindow.Gadgets->TimeoutGadget,
SettingWindow.Window, NULL,
GTIN_Number, (ULONG)Settings->Timeout,
TAG_END);
}
void ReadUiTimeout(void)
2018-11-24 21:39:18 +00:00
{
unsigned long value;
2021-01-12 21:53:12 +00:00
2021-01-12 22:16:18 +00:00
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->TimeoutGadget == NULL)
2021-01-12 21:53:12 +00:00
return;
2018-11-24 21:39:18 +00:00
GT_GetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->TimeoutGadget,
SettingWindow.Window, NULL,
2018-11-24 21:39:18 +00:00
GTIN_Number, (IPTR)&value,
TAG_END);
2021-01-12 22:16:18 +00:00
SetTimeout(value, APPLY_UI_FRONT | APPLY_RUNTIME);
}
void WriteUiThreshold(void)
{
char value[MAXLONGLONGCHARSIZE];
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->ThresholdGadget == NULL)
return;
LongLongToStr(Settings->Threshold, value);
GT_SetGadgetAttrs(
SettingWindow.Gadgets->ThresholdGadget,
SettingWindow.Window, NULL,
GTST_String, (IPTR)value,
TAG_END);
2018-11-24 21:39:18 +00:00
}
2021-01-12 22:16:18 +00:00
void ReadUiThreshold(void)
2018-11-24 21:39:18 +00:00
{
2021-01-12 22:16:18 +00:00
char *valueString;
2018-11-24 21:39:18 +00:00
2021-01-12 22:16:18 +00:00
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->ThresholdGadget == NULL)
2021-01-12 21:53:12 +00:00
return;
2018-11-24 21:39:18 +00:00
GT_GetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->ThresholdGadget,
SettingWindow.Window, NULL,
2021-01-12 22:16:18 +00:00
GTST_String, (IPTR)&valueString,
2018-11-24 21:39:18 +00:00
TAG_END);
2021-01-12 22:16:18 +00:00
SetThreshold(valueString, APPLY_UI_FRONT | APPLY_RUNTIME);
2018-11-24 21:39:18 +00:00
}
2021-01-12 22:16:18 +00:00
void WriteUiCxPriority(void)
2018-11-24 21:39:18 +00:00
{
2021-01-12 22:16:18 +00:00
char value[MAXLONGCHARSIZE];
2018-11-24 21:39:18 +00:00
2021-01-12 22:16:18 +00:00
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->PriorityGadget == NULL)
2021-01-12 21:53:12 +00:00
return;
2021-01-12 22:16:18 +00:00
LongToStr(Settings->Priority, value);
GT_SetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->PriorityGadget,
SettingWindow.Window, NULL,
2021-01-12 22:16:18 +00:00
GTST_String, (IPTR)value,
2018-11-24 21:39:18 +00:00
TAG_END);
2021-01-12 22:16:18 +00:00
}
2018-11-24 21:39:18 +00:00
2021-01-12 22:16:18 +00:00
void ReadUiCxPriority(void)
{
char *valueString;
2018-11-24 21:39:18 +00:00
2021-01-12 22:16:18 +00:00
if (SettingWindow.Gadgets == NULL || SettingWindow.Gadgets->PriorityGadget == NULL)
return;
GT_GetGadgetAttrs(
SettingWindow.Gadgets->PriorityGadget,
SettingWindow.Window, NULL,
GTST_String, (IPTR)&valueString,
TAG_END);
SetPriority(valueString, APPLY_UI_FRONT | APPLY_RUNTIME);
2018-11-24 21:39:18 +00:00
}
2021-01-12 22:02:29 +00:00
void ShowLastSync(struct timeval *tv)
2018-11-24 21:39:18 +00:00
{
static char label[10];
2021-01-12 22:16:18 +00:00
struct timeval nowLocal, lastLocal;
2018-11-24 21:39:18 +00:00
struct ClockData clockdata;
struct DateTime dateTime = {
.dat_Stamp = {.ds_Days = 0},
.dat_Format = FORMAT_DOS,
.dat_Flags = 0,
.dat_StrDay = NULL,
.dat_StrDate = NULL,
.dat_StrTime = (STRPTR)label};
long seconds;
2021-01-12 22:02:29 +00:00
if (tv->tv_secs == 0)
2018-11-24 21:39:18 +00:00
{
static const char *never = "Not synced yet";
GT_SetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->LastSyncGadget,
SettingWindow.Window, NULL,
2018-11-24 21:39:18 +00:00
GTTX_Text, (IPTR)never,
TAG_END);
return;
}
GetLocalTimeOfDay(&nowLocal);
2021-01-31 19:10:59 +00:00
UnixUtc2AmigaLocal(tv, &lastLocal);
2018-11-24 21:39:18 +00:00
seconds = nowLocal.tv_secs - lastLocal.tv_secs;
if (seconds > 60 * 60 * 24)
{
static const char *tooOld = "> 24 hours";
GT_SetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->LastSyncGadget,
SettingWindow.Window, NULL,
2018-11-24 21:39:18 +00:00
GTTX_Text, (IPTR)tooOld,
TAG_END);
return;
}
Amiga2Date(lastLocal.tv_secs, &clockdata);
dateTime.dat_Stamp.ds_Minute = clockdata.hour * 60 + clockdata.min;
dateTime.dat_Stamp.ds_Tick = clockdata.sec * 50;
DateToStr(&dateTime);
GT_SetGadgetAttrs(
2021-01-12 22:02:29 +00:00
SettingWindow.Gadgets->LastSyncGadget,
SettingWindow.Window, NULL,
2018-11-24 21:39:18 +00:00
GTTX_Text, (IPTR)label,
TAG_END);
}
2021-01-12 22:02:29 +00:00
void ShowNewTimezone(void)
{
char *temp = SettingWindow.TimezoneText;
char *new = AllocStringSafe(TIMEZONE_TEXT_LEN);
2021-01-31 19:10:59 +00:00
GetTimezoneText(new, TZD_ZONE_IN_PARENS);
2021-01-12 22:02:29 +00:00
GT_SetGadgetAttrs(
SettingWindow.Gadgets->TimezoneGadget,
SettingWindow.Window, NULL,
GTTX_Text, (IPTR) new,
TAG_END);
SettingWindow.TimezoneText = new;
FreeMemSafe(temp);
}