1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
/*
* BRLTTY - A background process providing access to the console screen (when in
* text mode) for a blind person using a refreshable braille display.
*
* Copyright (C) 1995-2024 by The BRLTTY Developers.
*
* BRLTTY comes with ABSOLUTELY NO WARRANTY.
*
* This is free software, placed under the terms of the
* GNU Lesser General Public License, as published by the Free Software
* Foundation; either version 2.1 of the License, or (at your option) any
* later version. Please see the file LICENSE-LGPL for details.
*
* Web Page: http://brltty.app/
*
* This software is maintained by Dave Mielke <dave@mielke.cc>.
*/
#include "prologue.h"
#include <stdio.h>
#include "strfmt.h"
#include "cmd_queue.h"
#include "cmd_miscellaneous.h"
#include "cmd_utils.h"
#include "brl_cmds.h"
#include "prefs.h"
#include "scr_special.h"
#include "message.h"
#include "alert.h"
#include "core.h"
#ifdef ENABLE_SPEECH_SUPPORT
static
STR_BEGIN_FORMATTER(formatSpeechDate, const TimeFormattingData *fmt)
const char *yearFormat = "%u";
const char *monthFormat = "%s";
const char *dayFormat = "%u";
uint16_t year = fmt->components.year;
uint8_t day = fmt->components.day + 1;
char month[0X20];
size_t length = strftime(month, sizeof(month), "%B", &fmt->components.time);
month[length] = 0;
switch (prefs.dateFormat) {
default:
case dfYearMonthDay:
STR_PRINTF(yearFormat, year);
STR_PRINTF(" ");
STR_PRINTF(monthFormat, month);
STR_PRINTF(" ");
STR_PRINTF(dayFormat, day);
break;
case dfMonthDayYear:
STR_PRINTF(monthFormat, month);
STR_PRINTF(" ");
STR_PRINTF(dayFormat, day);
STR_PRINTF(", ");
STR_PRINTF(yearFormat, year);
break;
case dfDayMonthYear:
STR_PRINTF(dayFormat, day);
STR_PRINTF(" ");
STR_PRINTF(monthFormat, month);
STR_PRINTF(", ");
STR_PRINTF(yearFormat, year);
break;
}
STR_END_FORMATTER
static
STR_BEGIN_FORMATTER(formatSpeechTime, const TimeFormattingData *fmt)
unsigned int hours = fmt->components.hour;
unsigned int minutes = fmt->components.minute;
unsigned int seconds = fmt->components.second;
if (minutes > 0) {
STR_PRINTF("%u", hours);
if (minutes < 10) STR_PRINTF(" 0");
STR_PRINTF(" %u", minutes);
} else if (!fmt->meridian) {
// xgettext: This is how to say when the time is exactly on (i.e. zero minutes after) an hour.
// xgettext: (%u represents the number of hours)
STR_PRINTF(ngettext("%u o'clock", "%u o'clock", hours), hours);
}
if (fmt->meridian) {
const char *character = fmt->meridian;
while (*character) STR_PRINTF(" %c", *character++);
}
if (prefs.showSeconds) {
STR_PRINTF(", ");
if (seconds == 0) {
// xgettext: This is the term used when the time is exactly on (i.e. zero seconds after) a minute.
STR_PRINTF("%s", gettext("exactly"));
} else {
STR_PRINTF("%s", gettext("and"));
// xgettext: This is a number (%u) of seconds (time units).
STR_PRINTF(ngettext("%u second", "%u seconds", seconds), seconds);
}
}
STR_END_FORMATTER
static void
speakTime (const TimeFormattingData *fmt) {
char announcement[0X100];
char time[0X80];
STR_BEGIN(announcement, sizeof(announcement));
formatSpeechTime(time, sizeof(time), fmt);
if (prefs.datePosition == dpNone) {
STR_PRINTF("%s", time);
} else {
char date[0X40];
formatSpeechDate(date, sizeof(date), fmt);
switch (prefs.datePosition) {
case dpBeforeTime:
STR_PRINTF("%s, %s", date, time);
break;
case dpAfterTime:
STR_PRINTF("%s, %s", time, date);
break;
default:
STR_PRINTF("%s", date);
break;
}
}
STR_PRINTF(".");
STR_END;
sayString(&spk, announcement, SAY_OPT_MUTE_FIRST);
}
#endif /* ENABLE_SPEECH_SUPPORT */
static void
showTime (const TimeFormattingData *fmt) {
char buffer[0X80];
formatBrailleTime(buffer, sizeof(buffer), fmt);
message(NULL, buffer, MSG_SILENT);
}
static int
handleMiscellaneousCommands (int command, void *data) {
switch (command & BRL_MSK_CMD) {
case BRL_CMD_RESTARTBRL:
brl.hasFailed = 1;
break;
case BRL_CMD_BRL_STOP:
disableBrailleDriver(gettext("braille driver stopped"));
break;
case BRL_CMD_BRL_START:
enableBrailleDriver();
break;
case BRL_CMD_SCR_STOP:
disableScreenDriver(gettext("screen driver stopped"));
break;
case BRL_CMD_SCR_START:
enableScreenDriver();
break;
case BRL_CMD_HELP: {
int ok = 0;
unsigned int pageNumber;
if (isSpecialScreen(SCR_HELP)) {
pageNumber = getHelpPageNumber() + 1;
ok = 1;
} else {
pageNumber = haveSpecialScreen(SCR_HELP)? getHelpPageNumber(): 1;
if (!activateSpecialScreen(SCR_HELP)) pageNumber = 0;
}
if (pageNumber) {
unsigned int pageCount = getHelpPageCount();
while (pageNumber <= pageCount) {
if (setHelpPageNumber(pageNumber))
if (getHelpLineCount())
break;
pageNumber += 1;
}
if (pageNumber > pageCount) {
deactivateSpecialScreen(SCR_HELP);
} else {
ok = 1;
}
updateSessionAttributes();
}
if (ok) {
infoMode = 0;
} else {
message(NULL, gettext("help not available"), 0);
}
break;
}
case BRL_CMD_TIME: {
TimeFormattingData fmt;
getTimeFormattingData(&fmt);
#ifdef ENABLE_SPEECH_SUPPORT
if (isAutospeakActive()) speakTime(&fmt);
#endif /* ENABLE_SPEECH_SUPPORT */
showTime(&fmt);
break;
}
case BRL_CMD_REFRESH: {
if (canRefreshBrailleDisplay(&brl)) {
if (refreshBrailleDisplay(&brl)) {
break;
}
}
alert(ALERT_COMMAND_REJECTED);
break;
}
default: {
int arg = command & BRL_MSK_ARG;
switch (command & BRL_MSK_BLK) {
case BRL_CMD_BLK(DESCCHAR): {
int column, row;
if (getCharacterCoordinates(arg, &row, &column, NULL, 0)) {
char description[0X80];
STR_BEGIN(description, sizeof(description));
STR_FORMAT(formatCharacterDescription, column, row);
STR_END;
message(NULL, description, 0);
} else {
alert(ALERT_COMMAND_REJECTED);
}
break;
}
case BRL_CMD_BLK(REFRESH_LINE): {
if (canRefreshBrailleRow(&brl)) {
if (refreshBrailleRow(&brl, arg)) {
break;
}
}
alert(ALERT_COMMAND_REJECTED);
break;
}
case BRL_CMD_BLK(ALERT):
alert(arg);
break;
default:
return 0;
}
break;
}
}
return 1;
}
int
addMiscellaneousCommands (void) {
return pushCommandHandler("miscellaneous", KTB_CTX_DEFAULT,
handleMiscellaneousCommands, NULL, NULL);
}
|