import QtQuick Item { // CalDav double: setup drafts, save and refresh counters, the registry's // open gate, one synthetic // appointment today on updateEvents(), a long one on addLongEvent(), and // sync states on setSync(); no network, keyring, or settings file. property string status: "needs-setup" property bool stale: false property double lastSyncMs: 0 property var events: [] property string setupUrlDraft: "" property string setupUsernameDraft: "" property string setupPasswordDraft: "" property string secretError: "" property int refreshes: 0 property bool popupOpen: false property int saves: 0 property bool savedDrafts: false property bool setupBusy: false property bool failSave: true // The suite's view of the service; never the password draft. function fixtureState() { return { status: status, stale: stale, lastSyncMs: lastSyncMs, refreshes: refreshes, popupOpen: popupOpen, saves: saves, savedDrafts: savedDrafts, setupBusy: setupBusy, secretError: secretError, eventCount: events.length }; } // A retry of offline data keeps its stale mark while it runs, as production. function refresh() { refreshes++; if (status === "offline") status = "loading"; } function setSync(nextStatus, nextStale, syncedMs) { status = nextStatus; stale = nextStale; lastSyncMs = syncedMs; } function addLongEvent() { events = events.concat([ { date: isoDay(new Date()), allDay: true, color: "#b59ae4", summary: "fixture review of the quarterly planning notes with the whole team before the long weekend starts", kind: "event" } ]); } function editSetupUrl(value) { if (!setupBusy) setupUrlDraft = value; } function editSetupUsername(value) { if (!setupBusy) setupUsernameDraft = value; } function editSetupPassword(value) { if (!setupBusy) setupPasswordDraft = value; } function saveSetup(url, user, secret) { if (setupBusy) return; secretError = ""; if (!url.startsWith("https://") || !user || !secret) { secretError = "fill in url, username and password"; return; } saves++; savedDrafts = url === "https://fixture.invalid/dav" && user === "fixture-user" && secret === "fixture-only"; setupBusy = true; } function finishSave() { if (!setupBusy) return; setupBusy = false; if (failSave) { secretError = "unlock keyring and save again"; failSave = false; } else if (savedDrafts) { secretError = ""; setupPasswordDraft = ""; status = "ready"; } } function isoDay(date) { return date.getFullYear() + "-" + String(date.getMonth() + 1).padStart(2, "0") + "-" + String(date.getDate()).padStart(2, "0"); } function updateEvents() { events = [ { date: isoDay(new Date()), allDay: true, color: "#3ec5e3", summary: "fixture appointment", kind: "event" } ]; } }