palm-client: connection state in conversations' title too (the title is cut to make room); tapping "offline" or Options > Connect connects; a reconnect after wake that fails or is stopped is retried 2, 4 ... 256 s later (it often ran before the USB link was back and was never tried again)
This commit is contained in:
1 parent
87a6a7e1a1
commit
d2f992eafc
8 files changed
+206
-43
No files matched your search
@@ -11,7 +11,7 @@ APP = visormesh
|
||||
NAME = VisorMesh
|
||||
CREATOR = VMsh
|
||||
|
||||
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c src/db.c
|
||||
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/title.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c src/db.c
|
||||
OBJS = $(SRCS:src/%.c=build/%.o)
|
||||
|
||||
CC = m68k-palmos-gcc
|
||||
|
||||
@@ -31,6 +31,7 @@ BEGIN
|
||||
END
|
||||
PULLDOWN "Options"
|
||||
BEGIN
|
||||
MENUITEM "Connect" ID MainMenuConnect
|
||||
MENUITEM "Flood Scopes..." ID MainMenuScopes "O"
|
||||
MENUITEM "Preferences..." ID MainMenuSounds "R"
|
||||
MENUITEM "-" AUTOID
|
||||
@@ -65,6 +66,7 @@ BEGIN
|
||||
END
|
||||
PULLDOWN "Options"
|
||||
BEGIN
|
||||
MENUITEM "Connect" ID MainMenuConnect
|
||||
MENUITEM "Flood Scopes..." ID MainMenuScopes "O"
|
||||
MENUITEM "Preferences..." ID MainMenuSounds "R"
|
||||
MENUITEM "-" AUTOID
|
||||
@@ -108,6 +110,7 @@ BEGIN
|
||||
END
|
||||
PULLDOWN "Options"
|
||||
BEGIN
|
||||
MENUITEM "Connect" ID MainMenuConnect
|
||||
MENUITEM "Flood Scopes..." ID MainMenuScopes "O"
|
||||
MENUITEM "Preferences..." ID MainMenuSounds "R"
|
||||
MENUITEM "-" AUTOID
|
||||
@@ -150,6 +153,7 @@ BEGIN
|
||||
END
|
||||
PULLDOWN "Options"
|
||||
BEGIN
|
||||
MENUITEM "Connect" ID MainMenuConnect
|
||||
MENUITEM "Flood Scopes..." ID MainMenuScopes "O"
|
||||
MENUITEM "Preferences..." ID MainMenuSounds "R"
|
||||
MENUITEM "-" AUTOID
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "convos.h"
|
||||
#include "app.h"
|
||||
#include "ui/draw.h"
|
||||
#include "ui/title.h"
|
||||
#include "ui/text.h"
|
||||
#include "ui/rowlist.h"
|
||||
#include "ui/emoji.h"
|
||||
@@ -27,6 +28,7 @@ static void Build(void) VM_SECT2;
|
||||
static Int16 TextWithMentions(const Char *text, UInt16 len, Coord x, Coord y, Coord hitX) VM_SECT2;
|
||||
static void DrawLine(UInt16 row, const RectangleType *b, void *ctx) VM_SECT2;
|
||||
static void DrawCounter(void) VM_SECT2;
|
||||
static void DrawStatus(void) VM_SECT2;
|
||||
static UInt32 FirstUnread(void) VM_SECT2;
|
||||
static void ScrollToNew(void) VM_SECT2;
|
||||
static void Refresh(Boolean toEnd) VM_SECT2;
|
||||
@@ -65,6 +67,8 @@ static UInt16 gCount = 0;
|
||||
static UInt16 gShow = MAX_MSGS; /* messages shown (the newest) */
|
||||
static RowList gList;
|
||||
static Char gTitle[VM_NAME_SIZE + 2];
|
||||
static Coord gTitleEnd; /* where the title's tab ends */
|
||||
static Boolean gShownOnline;
|
||||
static UInt32 gNewFrom = NO_NEW; /* unique ID of the first message unread at open */
|
||||
|
||||
static const Char *kDays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
@@ -334,6 +338,17 @@ static void DrawCounter(void)
|
||||
FntSetFont(old);
|
||||
}
|
||||
|
||||
/* Online or offline at the right of the title; redraws the title if "Connecting..." covered its end. */
|
||||
static void DrawStatus(void)
|
||||
{
|
||||
Boolean over = TitleStatusLeft() < gTitleEnd;
|
||||
|
||||
gShownOnline = SessionIsConnected();
|
||||
TitleConnState("");
|
||||
if (over)
|
||||
FrmCopyTitle(FrmGetActiveForm(), gTitle);
|
||||
}
|
||||
|
||||
/* The oldest unread message of this conversation, or NO_NEW. */
|
||||
static UInt32 FirstUnread(void)
|
||||
{
|
||||
@@ -527,7 +542,9 @@ Boolean ConvoFormHandleEvent(EventType *event)
|
||||
if (!AllocLines())
|
||||
return false;
|
||||
ConvName(&gAppConv, gTitle, VM_NAME_SIZE);
|
||||
gTitleEnd = TitleFit(gTitle);
|
||||
FrmCopyTitle(form, gTitle);
|
||||
TitleStatusReset();
|
||||
RowListInit(&gList, ConvoGadget, ConvoScroll, LINE_H, DrawLine, NULL, NULL);
|
||||
gNewFrom = FirstUnread();
|
||||
Build();
|
||||
@@ -537,6 +554,7 @@ Boolean ConvoFormHandleEvent(EventType *event)
|
||||
FrmDrawForm(form);
|
||||
RowListDraw(&gList);
|
||||
DrawCounter();
|
||||
DrawStatus();
|
||||
FrmSetFocus(form, FrmGetObjectIndex(form, ConvoField));
|
||||
return true;
|
||||
|
||||
@@ -555,9 +573,12 @@ Boolean ConvoFormHandleEvent(EventType *event)
|
||||
FrmDrawForm(form);
|
||||
RowListDraw(&gList);
|
||||
DrawCounter();
|
||||
TitleStatusReset();
|
||||
DrawStatus();
|
||||
return true;
|
||||
}
|
||||
Refresh(gList.top + RowListVisibleRows(&gList) >= gCount); /* follow new messages if at the end */
|
||||
DrawStatus();
|
||||
return true;
|
||||
|
||||
case fldChangedEvent:
|
||||
@@ -575,6 +596,11 @@ Boolean ConvoFormHandleEvent(EventType *event)
|
||||
}
|
||||
break;
|
||||
|
||||
case penDownEvent:
|
||||
if (TitleStatusTapped(event))
|
||||
return true;
|
||||
break;
|
||||
|
||||
case keyDownEvent:
|
||||
if (event->data.keyDown.chr == linefeedChr) { /* Graffiti return sends */
|
||||
Send(form);
|
||||
@@ -596,6 +622,9 @@ Boolean ConvoFormHandleEvent(EventType *event)
|
||||
|
||||
void ConvoFormIdle(void)
|
||||
{
|
||||
if (gLines)
|
||||
if (gLines) {
|
||||
DrawCounter();
|
||||
if (SessionIsConnected() != gShownOnline)
|
||||
DrawStatus();
|
||||
}
|
||||
}
|
||||
+12
-37
@@ -13,6 +13,7 @@
|
||||
#include "ui/draw.h"
|
||||
#include "ui/text.h"
|
||||
#include "ui/rowlist.h"
|
||||
#include "ui/title.h"
|
||||
#include "home_form.h"
|
||||
#include "mutes.h"
|
||||
#include "scopes.h"
|
||||
@@ -26,8 +27,6 @@
|
||||
static void DrawRow(UInt16 row, const RectangleType *b, void *ctx) VM_SECT2;
|
||||
static Boolean Selectable(UInt16 row, void *ctx) VM_SECT2;
|
||||
static void DrawTitleStatus(void) VM_SECT2;
|
||||
static void ShowStatus(const Char *text) VM_SECT2;
|
||||
static void TitleRight(const Char *text) VM_SECT2;
|
||||
static void Rebuild(Boolean draw) VM_SECT2;
|
||||
static Int16 PopupActions(const RectangleType *b, Char **items, UInt16 n) VM_SECT2;
|
||||
static Boolean HoldChannel(const VmConvRow *r, const RectangleType *b) VM_SECT2;
|
||||
@@ -175,45 +174,15 @@ static Boolean Selectable(UInt16 row, void *ctx)
|
||||
return gRows[row].kind == VM_ROW_CONV;
|
||||
}
|
||||
|
||||
/* Right end of the title bar: unread total and connection state. */
|
||||
/*
|
||||
* Text at the right end of the title bar. Erases back to where the previous
|
||||
* text started, so a shorter one doesn't leave the start of a longer one
|
||||
* behind ("Connecting..." is 65 px in the large font). Rows 2-10: above the
|
||||
* title line, so the large font draws a row higher.
|
||||
*/
|
||||
static Coord gTitleLeft = 160;
|
||||
|
||||
static void TitleRight(const Char *text)
|
||||
{
|
||||
RectangleType r;
|
||||
FontID old = FntSetFont(vmSmallFont);
|
||||
Coord left = 158 - FntCharsWidth(text, StrLen(text));
|
||||
|
||||
if (left < gTitleLeft)
|
||||
gTitleLeft = left;
|
||||
RctSetRectangle(&r, gTitleLeft - 1, 2, 160 - (gTitleLeft - 1), 9);
|
||||
WinEraseRectangle(&r, 0);
|
||||
DrawRight(text, 158, gUiFontHeight > 6 ? 3 : 4);
|
||||
gTitleLeft = left;
|
||||
FntSetFont(old);
|
||||
}
|
||||
|
||||
static void DrawTitleStatus(void)
|
||||
{
|
||||
Char buf[24];
|
||||
Char buf[8];
|
||||
UInt16 unread = ConvosUnread(gRows, gCount);
|
||||
|
||||
buf[0] = 0;
|
||||
if (unread)
|
||||
StrPrintF(buf, "%c%u %s", GLYPH_COMPANION, unread, SessionIsConnected() ? "online" : "offline");
|
||||
else
|
||||
StrCopy(buf, SessionIsConnected() ? "online" : "offline");
|
||||
TitleRight(buf);
|
||||
}
|
||||
|
||||
static void ShowStatus(const Char *text)
|
||||
{
|
||||
TitleRight(text);
|
||||
StrPrintF(buf, "%c%u ", GLYPH_COMPANION, unread);
|
||||
TitleConnState(buf);
|
||||
}
|
||||
|
||||
static void Rebuild(Boolean draw)
|
||||
@@ -239,12 +208,13 @@ Boolean HomeFormHandleEvent(EventType *event)
|
||||
RowListInit(&gList, HomeGadget, HomeScroll, VM_ROW_H, DrawRow, Selectable, NULL);
|
||||
gList.hold = Hold;
|
||||
Rebuild(false);
|
||||
TitleStatusReset();
|
||||
FrmDrawForm(FrmGetActiveForm());
|
||||
RowListDraw(&gList);
|
||||
DrawTitleStatus();
|
||||
if (!gAppAutoConnectTried && !SessionIsConnected()) {
|
||||
gAppAutoConnectTried = true;
|
||||
AppConnect(ShowStatus, true);
|
||||
AppConnect(TitleStatus, true);
|
||||
Rebuild(true);
|
||||
}
|
||||
return true;
|
||||
@@ -279,6 +249,11 @@ Boolean HomeFormHandleEvent(EventType *event)
|
||||
}
|
||||
break;
|
||||
|
||||
case penDownEvent:
|
||||
if (TitleStatusTapped(event))
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
+50
-4
@@ -24,6 +24,7 @@
|
||||
#include "bgcheck.h"
|
||||
#include "shots.h"
|
||||
#include "ui/draw.h"
|
||||
#include "ui/title.h"
|
||||
|
||||
#define VM_MIN_ROM_VERSION sysMakeROMVersion(3, 5, 0, sysROMStageRelease, 0)
|
||||
#define VM_POLL_TICKS (SysTicksPerSecond() / 2)
|
||||
@@ -42,6 +43,8 @@ static Err RomVersionCompatible(UInt32 required, UInt16 launchFlags)
|
||||
return sysErrRomIncompatible;
|
||||
}
|
||||
|
||||
static void Connect(Boolean retry);
|
||||
|
||||
/* Go, Channel and Options commands, whichever screen's menu they're on; Edit is the form's. */
|
||||
static Boolean HandleMenu(UInt16 itemID)
|
||||
{
|
||||
@@ -61,6 +64,7 @@ static Boolean HandleMenu(UInt16 itemID)
|
||||
case MainMenuShot: ShotCapture(); return true; /* the menu has gone by now */
|
||||
case MainMenuShotLater: ShotLater(5); return true;
|
||||
case MainMenuAbout: AppAbout(); return true;
|
||||
case MainMenuConnect: Connect(false); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -111,6 +115,47 @@ static Boolean AppHandleEvent(EventType *event)
|
||||
static UInt32 gLastSecs = 0, gLastTicks = 0;
|
||||
static Boolean gWantConnection = false; /* we were connected when the Visor slept */
|
||||
|
||||
/*
|
||||
* After a wake the connect often fails (the USB link isn't back yet) or a tap
|
||||
* stops it, so it's tried again 2, 4, 8 ... 256 s later (8.5 min in all).
|
||||
*/
|
||||
#define VM_RETRIES 8
|
||||
static UInt32 gRetryAt = 0; /* ticks; 0: no retry due */
|
||||
static UInt16 gRetries = 0;
|
||||
|
||||
/* Shows progress in the title on Home and conversations; retry: quietly, again later if it fails. */
|
||||
static void Connect(Boolean retry)
|
||||
{
|
||||
UInt16 formId = FrmGetActiveFormID();
|
||||
Err err;
|
||||
|
||||
gRetryAt = 0;
|
||||
err = AppConnect(formId == HomeForm || formId == ConvoForm ? TitleStatus : NULL, retry);
|
||||
if (err == errNone) {
|
||||
gWantConnection = false;
|
||||
gRetries = 0;
|
||||
} else if (retry && gRetries < VM_RETRIES) {
|
||||
gRetries++;
|
||||
gRetryAt = TimGetTicks() + ((UInt32)SysTicksPerSecond() << gRetries);
|
||||
if (!gRetryAt)
|
||||
gRetryAt = 1;
|
||||
}
|
||||
FrmUpdateForm(formId, VM_UPDATE_DATA);
|
||||
}
|
||||
|
||||
/* How long to wait for an event: poll while connected, wake for a retry that's due. */
|
||||
static Int32 EventTimeout(void)
|
||||
{
|
||||
Int32 left;
|
||||
|
||||
if (SessionIsConnected())
|
||||
return VM_POLL_TICKS;
|
||||
if (!gRetryAt)
|
||||
return evtWaitForever;
|
||||
left = (Int32)(gRetryAt - TimGetTicks());
|
||||
return left > 1 ? left : 1;
|
||||
}
|
||||
|
||||
static void CheckWake(void)
|
||||
{
|
||||
UInt32 secs = TimGetSeconds(), ticks = TimGetTicks();
|
||||
@@ -122,9 +167,8 @@ static void CheckWake(void)
|
||||
if (wall - run > VM_SLEEP_GAP_SECS && (SessionIsConnected() || gWantConnection)) {
|
||||
gWantConnection = true;
|
||||
SessionDisconnect();
|
||||
if (AppConnect(NULL, true) == errNone)
|
||||
gWantConnection = false;
|
||||
FrmUpdateForm(FrmGetActiveFormID(), VM_UPDATE_DATA);
|
||||
gRetries = 0;
|
||||
Connect(true);
|
||||
secs = TimGetSeconds();
|
||||
ticks = TimGetTicks();
|
||||
}
|
||||
@@ -157,9 +201,11 @@ static void AppEventLoop(void)
|
||||
Err err;
|
||||
|
||||
do {
|
||||
EvtGetEvent(&event, SessionIsConnected() ? VM_POLL_TICKS : evtWaitForever);
|
||||
EvtGetEvent(&event, EventTimeout());
|
||||
CheckWake();
|
||||
if (event.eType == nilEvent) {
|
||||
if (gRetryAt && !SessionIsConnected() && (Int32)(TimGetTicks() - gRetryAt) >= 0)
|
||||
Connect(true);
|
||||
Poll();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define MainMenuShot 1015
|
||||
#define MainMenuShotLater 1016
|
||||
#define MainMenuAbout 1019
|
||||
#define MainMenuConnect 1021 /* also a tap on "offline" in the title */
|
||||
#define AboutAlert 1020
|
||||
#define ConvoChanMenuBar 1014 /* Go, Edit, Channel (Add, Leave, Mute, Scope), Options */
|
||||
#define ConvoMenuBar 1017 /* Go, Edit, Options: a DM, the console */
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#include <PalmOS.h>
|
||||
#include "resources.h"
|
||||
#include "session.h"
|
||||
#include "ui/draw.h"
|
||||
#include "ui/title.h"
|
||||
|
||||
#define TITLE_PAD 8 /* the tab's width past its text */
|
||||
#define ELLIPSIS ((Char)0x85) /* chrHorizontalEllipsis (3.1 and later ROMs) */
|
||||
|
||||
static Coord gLeft = 160;
|
||||
|
||||
void TitleStatusReset(void)
|
||||
{
|
||||
gLeft = 160;
|
||||
}
|
||||
|
||||
/*
|
||||
* Erases back to where the previous text started, so a shorter one doesn't
|
||||
* leave the start of a longer one behind ("Connecting..." is 65 px in the
|
||||
* large font). Rows 2-10: above the title line, so the large font draws a row
|
||||
* higher.
|
||||
*/
|
||||
void TitleStatus(const Char *text)
|
||||
{
|
||||
RectangleType r;
|
||||
FontID old = FntSetFont(vmSmallFont);
|
||||
Coord left = 158 - FntCharsWidth(text, StrLen(text));
|
||||
|
||||
if (left < gLeft)
|
||||
gLeft = left;
|
||||
RctSetRectangle(&r, gLeft - 1, 2, 160 - (gLeft - 1), 9);
|
||||
WinEraseRectangle(&r, 0);
|
||||
DrawRight(text, 158, gUiFontHeight > 6 ? 3 : 4);
|
||||
gLeft = left;
|
||||
FntSetFont(old);
|
||||
}
|
||||
|
||||
void TitleConnState(const Char *prefix)
|
||||
{
|
||||
Char buf[24];
|
||||
|
||||
StrCopy(buf, prefix);
|
||||
StrCat(buf, SessionIsConnected() ? "online" : "offline");
|
||||
TitleStatus(buf);
|
||||
}
|
||||
|
||||
Coord TitleStatusLeft(void)
|
||||
{
|
||||
return gLeft;
|
||||
}
|
||||
|
||||
Boolean TitleStatusTapped(const EventType *event)
|
||||
{
|
||||
EventType e;
|
||||
|
||||
if (event->eType != penDownEvent || SessionIsConnected() ||
|
||||
event->screenY > 12 || event->screenX < gLeft - 4)
|
||||
return false;
|
||||
MemSet(&e, sizeof(e), 0);
|
||||
e.eType = menuEvent;
|
||||
e.data.menu.itemID = MainMenuConnect;
|
||||
EvtAddEventToQueue(&e);
|
||||
return true;
|
||||
}
|
||||
|
||||
Coord TitleFit(Char *title)
|
||||
{
|
||||
FontID old = FntSetFont(vmSmallFont);
|
||||
Int16 maxW = 158 - FntCharsWidth("offline", 7) - 4 - TITLE_PAD;
|
||||
Int16 w = maxW, len = StrLen(title);
|
||||
Boolean fits;
|
||||
|
||||
FntSetFont(boldFont);
|
||||
if (FntCharsWidth(title, len) > maxW) {
|
||||
w = maxW - FntCharWidth(ELLIPSIS);
|
||||
FntCharsInWidth(title, &w, &len, &fits);
|
||||
title[len++] = ELLIPSIS;
|
||||
title[len] = 0;
|
||||
}
|
||||
w = FntCharsWidth(title, len) + TITLE_PAD;
|
||||
FntSetFont(old);
|
||||
return w;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* The right end of a form's title bar: the connection state ("online",
|
||||
* "offline", "Connecting..." while it connects), drawn in the UI font. Tapping
|
||||
* it while offline is the same as Options > Connect. Call TitleStatusReset
|
||||
* when the form opens.
|
||||
*/
|
||||
#ifndef VM_TITLE_H
|
||||
#define VM_TITLE_H
|
||||
|
||||
#include <PalmOS.h>
|
||||
#include "../sections.h"
|
||||
|
||||
void TitleStatusReset(void) VM_SECT3;
|
||||
/* Draws text there, erasing back to where the previous text started. */
|
||||
void TitleStatus(const Char *text) VM_SECT3;
|
||||
/* "online" or "offline", after prefix (may be empty). */
|
||||
void TitleConnState(const Char *prefix) VM_SECT3;
|
||||
/* The left edge of what's drawn there now (160: nothing). */
|
||||
Coord TitleStatusLeft(void) VM_SECT3;
|
||||
/* A tap on it while offline: queues Options > Connect. */
|
||||
Boolean TitleStatusTapped(const EventType *event) VM_SECT3;
|
||||
/* Cuts title with an ellipsis so its tab ends before "offline"; returns where the tab ends. */
|
||||
Coord TitleFit(Char *title) VM_SECT3;
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user