/******************************************************************************
 *
 *    Name: servicerecord.cpp
 *
 *    $Id$
 *
 *    Purpose: Example Service Record dialog using the UI Dialog Library from C++.
 *
 *    Copyright 2013 Citrix Systems, Inc. All rights reserved.
 *
 *****************************************************************************/

#include <iostream>
#include <string>
#include <stdlib.h>
#include "UIDialogLibCall.h"


/*
Service Record Dialog to be displayed:

Expanded:
#################################################################################################
#   ______                                                                                      #
#  |      |  Do you want to use "Store" provided by "Citrix Systems Inc."?                      #
#  |      |  You should only proceed if you trust Citrix Systems Inc.. Citrix Systems Inc. was  #
#  |______|  verified by GTE Corporation.                                                       #
#                                                                                               #
#  + Details                                                                                    #
#                                                                                               #
#     Store address:    https://example.citrix.com/Citrix/Store/discovery                       #
#     Default gateway:  Example-Citrix                                                          #
#     Other gateway:    -                                                                       #
#_______________________________________________________________________________________________#
#                                                                        ________    ________   #
#                                                                       |_Cancel_|  |_Agree__|  #
#                                                                                               #
#################################################################################################

Minimised:
#################################################################################################
#   ______                                                                                      #
#  |      |  Do you want to use "Store" provided by "Citrix Systems Inc."?                      #
#  |      |  You should only proceed if you trust Citrix Systems Inc.. Citrix Systems Inc. was  #
#  |______|  verified by GTE Corporation.                                                       #
#                                                                                               #
#  - Details                                                                                    #
#_______________________________________________________________________________________________#
#                                                                        ________    ________   #
#                                                                       |_Cancel_|  |_Agree__|  #
#                                                                                               #
#################################################################################################
*/


int main(int argc, char *argv[])
{
    const char *result;
    const char *icaroot;
    UIDIALOG *dialog;

    struct formsElement heading =   {
                                        {L_Heading, "Do you want to use \"Store\" provided by \"Citrix Systems Inc.\"?", NULL},
                                        {
                                            I_None,
                                            NULL,
                                            FALSE,
                                            {{ 0 }}
                                        }
                                    };

    struct formsElement body =  {
                                    {L_Plain, "You should only proceed if you trust Citrix Systems Inc.. Citrix Systems Inc. was verified by GTE Corporation.", NULL},
                                    {
                                        I_None,
                                        NULL,
                                        FALSE,
                                        {{ 0 }}
                                    }
                                };

    struct formsElement store = {
                                    {L_Plain, "Store address:", NULL},
                                    {
                                        I_Label,
                                        NULL,
                                        FALSE,
                                        {
                                            label: {L_Plain, "https://example.citrix.com/Citrix/Store/discovery", NULL}
                                        }
                                    }
                                };

    struct formsElement defgateway =    {
                                            {L_Plain, "Default gateway:", NULL},
                                            {
                                                I_Label,
                                                NULL,
                                                FALSE,
                                                {
                                                    label: {L_Plain, "Example-Citrix\nhttps://gateway-example.citrix.com", NULL}
                                                }
                                            }
                                        };


    struct formsElement othergateway =  {
                                            {L_Plain, "Other gateways:", NULL},
                                            {
                                                I_Label,
                                                NULL,
                                                FALSE,
                                                {
                                                    label: {L_Plain, "Example2-Citrix\nhttps://gateway-example2.citrix.com\nExample3-Citrix\nhttps://gateway-example3.citrix.com", NULL}
                                                }
                                            }
                                        };

    struct formsElement *subform[] =   {
                                        &store,
                                        &defgateway,
                                        &othergateway,
                                        NULL
                                    };

    struct formsElement details =   {
                                        {L_Plain, "Details", NULL},
                                        {
                                            I_Expander,
                                            "Click for more details",
                                            FALSE,
                                            {
                                                expander: subform
                                            }
                                        }
                                    };

    struct formsElement cancel =    {
                                        {L_Plain, NULL, NULL},
                                        {
                                            I_Button,
                                            NULL,
                                            FALSE,
                                            {
                                                button: {"CancelId", "Cancel", NULL}
                                            }
                                        }
                                    };

    struct formsElement accept =     {
                                        {L_Plain, NULL, NULL},
                                        {
                                            I_Button,
                                            NULL,
                                            TRUE,
                                            {
                                                button: {"acceptId", "Accept", NULL}
                                            }
                                        }
                                    };

    struct formsElement *form[] =   {
                                        &heading,
                                        &body,
                                        &details,
                                        &cancel,
                                        &accept,
                                        NULL
                                    };

    /* Add the mnemonics. */
    details.label.mnemonic = details.label.text;    
    accept.input.inputUnion.button.mnemonic = accept.input.inputUnion.button.text;
    cancel.input.inputUnion.button.mnemonic = cancel.input.inputUnion.button.text;

    /* Setup ICAROOT. */
    icaroot = getenv("ICAROOT");

    if (icaroot == NULL)
        icaroot = "/opt/Citrix/ICAClient";

    /* Load the UI Dialog Library. */ 
    UIDialogLibLoad(icaroot);    

    /* Initialise the UI Dialog Library */
    UI_DIALOG_INIT(icaroot);
    UI_DIALOG_LOOP_INIT(&argc, &argv);

    dialog = UI_DIALOG_ALLOCATE();

    /* Display UI */
    result = UI_DIALOG_DISPLAY(dialog, form, S_Security, NULL, CITRIX_BRANDNAME, "acceptId", 0, NULL);

    /* Close the dialog. */
    UI_DIALOG_CLOSE(dialog);

    free(dialog);

    std::cout << "Received the following id=" << result << "\n";
    return 0;
}
