139 lines
3.9 KiB
C
139 lines
3.9 KiB
C
/*-
|
|
* Copyright (c) 2020-2021 Carsten Sonne Larsen <cs@innolan.net>
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
#include "config.h"
|
|
#include "message.h"
|
|
#include "global.h"
|
|
#include "locale.h"
|
|
#include "text.h"
|
|
#include "sync.h"
|
|
#include "win.h"
|
|
#include "mem.h"
|
|
|
|
#include "logmod.h"
|
|
#define MODULENAME "Control"
|
|
|
|
static bool HandleControlMessage(struct ControlMesage *msg)
|
|
{
|
|
msg->Code = ATK_CTRL_UNKNOWN;
|
|
|
|
switch (msg->AppMsg.MsgId)
|
|
{
|
|
case ATK_ID:
|
|
LogDebug("Identifier request");
|
|
StrCopy(msg->Result, APP_TITLE);
|
|
msg->Code = ATK_CTRL_OK;
|
|
break;
|
|
case ATK_VERSION:
|
|
LogDebug("Version request");
|
|
StrCopy(msg->Result, APP_VERSION);
|
|
msg->Code = ATK_CTRL_OK;
|
|
break;
|
|
case ATK_TIME:
|
|
LogDebug("Time request");
|
|
char *time = GetTimeText(LOCAL_TIME_NOW);
|
|
StrCopy(msg->Result, time);
|
|
FreeMemSafe(time);
|
|
msg->Code = ATK_CTRL_OK;
|
|
break;
|
|
case ATK_TIMEZONE:
|
|
LogDebug("Timezone request");
|
|
{
|
|
char buf[TIMEZONE_TEXT_LEN];
|
|
GetTimezoneText(buf, TZD_SECONDS_AHEAD);
|
|
StrCopy(msg->Result, buf);
|
|
}
|
|
msg->Code = ATK_CTRL_OK;
|
|
break;
|
|
case ATK_STATUS:
|
|
LogDebug("Status request");
|
|
if (SynchronizerRunning)
|
|
StrCopy(msg->Result, TextSyncOn);
|
|
else
|
|
StrCopy(msg->Result, TextSyncOff);
|
|
msg->Code = ATK_CTRL_OK;
|
|
break;
|
|
case ATK_SHOW:
|
|
LogInfo("Show window");
|
|
ShowSettingWindow();
|
|
msg->Code = ATK_CTRL_OK;
|
|
break;
|
|
case ATK_HIDE:
|
|
LogInfo("Hide window");
|
|
SendWindowMessage(ATK_SHUTDOWN);
|
|
msg->Code = ATK_CTRL_OK;
|
|
break;
|
|
case ATK_ENABLE:
|
|
LogNotice("Start");
|
|
if (!SynchronizerRunning)
|
|
{
|
|
Activate();
|
|
msg->Code = ATK_CTRL_OK;
|
|
}
|
|
else
|
|
{
|
|
StrCopy(msg->Result, TextSyncAlreadyOn);
|
|
msg->Code = ATK_CTRL_ERROR;
|
|
}
|
|
break;
|
|
case ATK_DISABLE:
|
|
LogNotice("Stop");
|
|
if (SynchronizerRunning)
|
|
{
|
|
Deactivate();
|
|
msg->Code = ATK_CTRL_OK;
|
|
}
|
|
else
|
|
{
|
|
StrCopy(msg->Result, TextSyncAlreadyOff);
|
|
msg->Code = ATK_CTRL_ERROR;
|
|
}
|
|
break;
|
|
case ATK_SHUTDOWN:
|
|
LogNotice("Shutdown");
|
|
msg->Code = ATK_CTRL_OK;
|
|
return false;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool HandleControlMessages(void)
|
|
{
|
|
bool cont = true;
|
|
struct ControlMesage *msg;
|
|
|
|
while ((msg = (struct ControlMesage *)GetNewMessage(MSGPORT_CONTROL)))
|
|
{
|
|
cont &= HandleControlMessage(msg);
|
|
ReplyMsg((struct Message *)msg);
|
|
}
|
|
return cont;
|
|
}
|