Hello App: HelloApp.cpp
Contents
HelloApp.cpp
/**
* HelloApp.cpp - class declaration for Hello app implementation
*
* Copyright (c) 2024 HanoverSoft
* Written by Anthony V. Edwards
* 820 Churchill Drive, Chapel Hill, NC 27517
* ave@hanoversoft.net
*
* We handle new session initialization, menu callbacks, and user input responses here.
*/
#include <User.h> // using the User class to access to MAE User database table
#include "hello.h"
/** Constructor for an instance of a user interacting with us.
* We are a simple program, so there's not much to initialize.
* @param id - user id
*/
{
this->id= id;
}
/** The first time the user connects to our app, this is called.
* @param param - inbound variables from UserDevice::run() (if any)
*/
{
// save the starting params for the instance, once launched
params= param;
// Create a tab/window and display our prompt there
drawPromptWindow();
}
/** Create a "Prompt" window and display our question in it.
* The layout of the question comes from /usr/mae/html/record/helloPrompt.html.
* @see UserDevice
*/
{
// Create a tab/window and display our prompt there
UserDevice promptwin= /* UserDevice:: */ setWindow("Prompt");
HashArray values;
promptwin.record("helloPrompt", values);
// Fill in the text box with a name
if (!defaultName.empty())
promptwin.settext(defaultName, "helloPrompt_name");
}
/** The user has typed something into the name box and we can now process it.
* @param name - the user text
*/
{
/* UserDevice:: */ setRegion("helloPrompt_greeting");
/* UserDevice:: */ writeln((string)"Hello, "+name+"!");
}
/** Menu Display->From DB selected. So, query the user's name from the DB, then say hello.
* @see User
*/
{
DbRecNum userId= /* UserDevice:: */ getUserId();
if (userId == 0)
// this should never happen! A user must be authorized before they can get through.
/* UserDevice:: */ attention("Who are you?");
else {
// Get the user record from the data store
User user(userId);
// Display the greeting to the user by name
inputName(user.getName());
}
}
/** The user selected the Display->Clear menu options.
* So, clear the display of anything output so far.
*/
{
// Clear the windows
/* UserDevice:: */ unsetWindow("Prompt");
/* UserDevice:: */ unsetWindow("Help");
// Redraw the prompt window
drawPromptWindow();
}
/** The user selected the Display->Help menu options.
* So, display some help (in a new tab).
*/
{
UserDevice helpwin= /* UserDevice:: */ setWindow("Help");
helpwin.clear();
helpwin.writeln("This is a simple MAE app that asks for a name.");
helpwin.writeln("Upon submitting the name, the program greets you with a Hello.");
helpwin.writeln("(Click on the Prompt tab to return to that prompt.)");
}
/** The user selected the Display->Quit menu options.
* So, quit.
*/
{
// If we have any user state to save, save it out
save();
// Exit out back to the starting app for this user
/* UserDevice:: */ quit();
}