Hello App: HelloApp.cpp

Index Home Sample App > Hello App: HelloApp.cpp

Contents

HelloApp::HelloApp(DbRecNum id):
UserDevice("")
void HelloApp::userstart(XMLData & param)
void HelloApp::drawPromptWindow(const string & defaultName)
void HelloApp::inputName(const string & name)
void HelloApp::menu_Display_FromDB()
void HelloApp::menu_Display_Clear()
void HelloApp::menu_Display_Help()
void HelloApp::menu_Display_Quit()

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

 */

HelloApp::HelloApp(DbRecNum id):

UserDevice("")

{

    this->id= id;

}

/** The first time the user connects to our app, this is called.

 * @param param - inbound variables from UserDevice::run() (if any)

 */

void HelloApp::userstart(XMLData & param)

{

    // 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

 */

void HelloApp::drawPromptWindow(const string & defaultName)

{

    // 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

 */

void HelloApp::inputName(const string & name)

{

    /* 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

 */

void HelloApp::menu_Display_FromDB()

{

    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.

 */

void HelloApp::menu_Display_Clear()

{

    // 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).

 */

void HelloApp::menu_Display_Help()

{

    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.

 */

void HelloApp::menu_Display_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();

}