/* * * ProLinga-Run * * Copyright (C) 2002-2009 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Run. * * ProLinga-Run is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Run is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Run. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "RunCommon.h" #include "Main.hpp" #include #include #include #include #include "RunShare.hpp" #include "DataRef.hpp" #include "RepositoryCommand.hpp" #include "ValidateCommand.hpp" #include "LogicCommands.hpp" #include "DataManager.hpp" #include "Screen.hpp" #include "CmdList.hpp" #include "BuiltIn.hpp" #include "LogicCommandDef.hpp" #include "RunConfig.hpp" extern ConfigRunPtr confRunPtr; extern BiAppnPtr biAppnPtr; extern BiAppnDevPtr biAppnDevPtr; extern BiUserPtr biUserPtr; extern BiValidateStatusPtr biValidateStatusPtr; extern BiQuitLastScreenPtr biQuitLastScreenPtr; /* Screens open on Desktop Ptr */ extern DesktopScreenPtr desktopScreenPtr; //extern GtkWidget *activeScreen; /* Active Screen Dialog stack Ptr */ //extern ScreenStackPtr dialogStackPtr; //extern bool quit_appn; //static bool quit_appn = true; /* Command : CONTROL */ /* Syntax : control_function [argument...] */ void CmdControl(const char **argList, int argHits, bool isMainThread, GtkWidget *outputScreen) { char *tmpBigValue = NULL, tmpValue[255], tableName[255], fileName[255], fileName2[255], shellCmd[255], *screenType, *name, *screenPainter; char *startLogic, *logonScreen, *dataRefComponent; const char *dataRefComponentWork; int option, retStatus = 0; xmlDocPtr docPnt; xmlNodePtr curPnt; xmlBufferPtr bufPnt; // xmlXPathContextPtr ctxPnt; // xmlXPathObjectPtr resPnt; FILE *fp; const char *paramList[255]; char appnName[32], objectType[32], objectName[32]; if (strcmp(argList[1],"exit") == 0) { /* get GTK thread lock */ // if (isMainThread == false) // gdk_threads_enter(); gtk_main_quit(); // if (isMainThread == false) // { // /* Sync with X server */ // gdk_flush(); // // /* release GTK thread lock */ // gdk_threads_leave(); // } } else if (strcmp(argList[1],"cancel") == 0) { /* get GTK thread lock */ // if (isMainThread == false) // gdk_threads_enter(); /* Fall back */ // numDesktop = desktopScreenPtr->numberOnDesktop(desktopScreenPtr); // if (numDesktop <= 1) // { // //if (quit_appn == true) // if (biQuitLastScreenPtr->getQuitLastScreen() == 0) // { // gtk_main_quit(); // return; // } // } screenType = (char *)g_object_get_data(G_OBJECT(outputScreen), "screenType"); if (strcmp(screenType, "DIALOG") == 0) { gtk_dialog_response(GTK_DIALOG(outputScreen), GTK_RESPONSE_CLOSE); //dialogStackPtr->pop(&dialogStackPtr, &tempScreen); } else { // xml = glade_get_widget_tree(outputScreen); // g_object_unref(G_OBJECT(xml)); gtk_widget_destroy(outputScreen); gtk_widget_destroyed(outputScreen, &outputScreen); // if (tempScreen != NULL) // activeScreen = tempScreen; } // if (isMainThread == false) // { // /* Sync with X server */ // gdk_flush(); // // /* release GTK thread lock */ // gdk_threads_leave(); // } } else if (strcmp(argList[1],"commit") == 0) { /* get GTK thread lock */ // if (isMainThread == false) // gdk_threads_enter(); screenType = (char *)g_object_get_data(G_OBJECT(outputScreen), "screenType"); if (strcmp(screenType, "DIALOG") == 0) { gtk_dialog_response(GTK_DIALOG(outputScreen), GTK_RESPONSE_CLOSE); //dialogStackPtr->pop(&dialogStackPtr, &tempScreen); } else { gtk_widget_destroy(outputScreen); gtk_widget_destroyed(outputScreen, &outputScreen); } //if (tempScreen != NULL) // activeScreen = tempScreen; // if (isMainThread == false) // { // /* Sync with X server */ // gdk_flush(); // // /* release GTK thread lock */ // gdk_threads_leave(); // } } else if (strcmp(argList[1],"appndev") == 0) { /* Set application developer name */ biAppnDevPtr->setAppnDev(getDataRef(argList[2], isMainThread, tmpValue, false)); } else if (strcmp(argList[1],"user") == 0) { /* Set user name */ biUserPtr->setUser(getDataRef(argList[2], isMainThread, tmpValue, false)); } else if (strcmp(argList[1],"validate") == 0) { /* get GTK thread lock */ // if (isMainThread == false) // gdk_threads_enter(); /* Init */ biValidateStatusPtr->setValidateStatus(0); //if (strcmp(getDataRef(argList[3], isMainThread, tmpValue, false), "Logic") != 0) // { // printf("No Logic but : %s\n", argList[3]); // return; // } strcpy(appnName, getDataRef(argList[2], isMainThread, tmpValue, false)); strcpy(objectType, getDataRef(argList[3], isMainThread, tmpValue, false)); strcpy(objectName, getDataRef(argList[4], isMainThread, tmpValue, false)); /* Validate Component */ retStatus = valValObject(appnName, objectType, objectName, isMainThread); if ( retStatus != 0) { biValidateStatusPtr->setValidateStatus(retStatus); return; } // if (isMainThread == false) // { // /* Sync with X server */ // gdk_flush(); // // /* release GTK thread lock */ // gdk_threads_leave(); // } } else if (strcmp(argList[1],"logon") == 0) { /* Set application name */ strcpy(appnName, getDataRef(argList[2], isMainThread, tmpValue, false)); //biAppnPtr->setAppn(getDataRef(argList[2], isMainThread, tmpValue, false)); //printf("APP is nu %s\n", biAppnPtr->getAppn()); //biAppnPtr->setAppn(PL_APPN_DEV); /* Setting to overrule appn exit on close last screen */ biQuitLastScreenPtr->setQuitLastScreen(1); /* Close all screens on desktop */ CloseAllScreens(isMainThread); /* Setting to overrule appn exit on close last screen */ biQuitLastScreenPtr->setQuitLastScreen(0); /* Clear all buffers, lists and stacks */ ResetBuffers(); ResetStores(); ResetScreenStack(); /* Reset communication areas */ ResetBuiltIns(); /* Reset Logic Command buffers */ ResetLogicCommandBuffers(); /* Set application name */ if (strlen(appnName) == 0) biAppnPtr->setAppn(PL_APPN_DEV); else biAppnPtr->setAppn(appnName); /* Open start logic */ startLogic = new char[4]; strncpy(startLogic,"Main",4); //paramList[1] = "Main"; paramList[1] = startLogic; CmdCall(paramList, 1, isMainThread, false); delete startLogic; } else if (strcmp(argList[1],"logout") == 0) { /* Setting to overrule appn exit on close last screen */ biQuitLastScreenPtr->setQuitLastScreen(1); //quit_appn = false; /* Close all screens on desktop */ CloseAllScreens(isMainThread); /* Clear all buffers, lists and stacks */ ResetBuffers(); ResetStores(); ResetScreenStack(); /* Reset communication areas */ ResetBuiltIns(); // biAppnPtr->setAppn(PL_APPN_DEV); /* Reset Logic Command buffers */ ResetLogicCommandBuffers(); /* Call logon screen */ logonScreen = new char[6]; strncpy(logonScreen,"Runner",6); //paramList[1] = "Runner"; paramList[1] = logonScreen; CmdScreen(paramList, 1, isMainThread, outputScreen); delete logonScreen; /* Reset setting to overrule appn exit on close last screen */ biQuitLastScreenPtr->setQuitLastScreen(0); } else if (strcmp(argList[1],"datamanager") == 0) { /* Get Option */ option = atoi(getDataRef(argList[2], isMainThread, tmpValue, false)); /* Get Application Name */ strcpy(appnName, getDataRef(argList[3], isMainThread, tmpValue, false)); /* Get Table Name */ strcpy(tableName, getDataRef(argList[4], isMainThread, tmpValue, false)); /* If no appn/table loaded, exit */ if ((strcmp(appnName,"") == 0) || (strcmp(tableName, "") == 0) ) return; /* Get Interface Type */ dataRefComponent = new char[25]; strncpy(dataRefComponent,"F-DataInterfaceType.Table",25); dataRefComponentWork = dataRefComponent; getDataRef(dataRefComponentWork, isMainThread, tmpValue, false); dataRefComponentWork = NULL; delete dataRefComponent; if (strcmp(tmpValue, "GDA") == 0) BuildDataData(appnName, tableName, option, isMainThread); else printf("Invalid Interface Type: %s\n", tmpValue); } else if (strcmp(argList[1],"painter") == 0) { /* Get Screen */ name = getDataRef(argList[2], isMainThread, tmpValue, false); //docPnt = RC_Get(biAppnPtr->getAppn(), "Screen", name); //printf("%s\n", getDataRef("F-DisplayData.Screen", isMainThread, tmpBigValue, false)); /* Init Xpath */ //xmlXPathInit(); /* Create XPath environment */ //ctxPnt = xmlXPathNewContext(docPnt); /* Get glade section only */ //resPnt = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/Screen/DisplayData/glade-interface", ctxPnt); //curPnt = resPnt->nodesetval->nodeTab[0]; /* Dump Screen to File */ //bufPnt = xmlBufferCreate(); //curPnt = xmlDocGetRootElement(docPnt); //xmlNodeDump(bufPnt, docPnt, curPnt, 0, 1); //fprintf(fp,"%s\n", (char *)xmlBufferContent(bufPnt)); /* Create Dummy Project File */ sprintf(fileName, "/usr/tmp/%s.gladep", name); fp = fopen(fileName, "w"); fprintf(fp,"\n\t%s\n\t%s\n\tFALSE\n\t\n", name, name); fclose(fp); /* Create Glade file */ sprintf(fileName2, "/usr/tmp/%s.glade", name); fp = fopen(fileName2, "w"); //fprintf(fp,"%s\n", (char *)xmlBufferContent(bufPnt)); // fprintf(fp,"%s\n", getDataRef("F-DisplayData.Screen", isMainThread, tmpBigValue, false)); // dataRefComponent = new char[20]; strncpy(dataRefComponent,"F-DisplayData.Screen",20); //tmpBigValue = getDataRef("F-DisplayData.Screen", isMainThread, tmpBigValue, true); dataRefComponentWork = dataRefComponent; tmpBigValue = getDataRef(dataRefComponentWork, isMainThread, tmpBigValue, true); dataRefComponentWork = NULL; delete dataRefComponent; if (tmpBigValue == NULL) fprintf(fp,"\n"); else { fprintf(fp,"%s\n", tmpBigValue); delete tmpBigValue; } fclose(fp); //xmlBufferFree(bufPnt); /* Start external screen painter */ screenPainter = confRunPtr->getStringValue("ExternalScreenPainter", DEF_EXT_SCREEN_PAINTER); //sprintf(fileName, "/opt/builds/glade/glade-2.0.0/bin/glade-2 /usr/tmp/%s.glade", name); sprintf(fileName, "%s /usr/tmp/%s.glade", screenPainter, name); system(fileName); /* Get results */ docPnt = xmlParseFile(fileName2); if (docPnt == NULL) { fprintf(stderr, "Error parsing document. \n"); xmlFreeDoc(docPnt); return; } /* Set window id */ // ctxPnt = xmlXPathNewContext(docPnt); // resPnt = xmlXPathEval((const xmlChar *)"/glade-interface/widget", ctxPnt); // curPnt = resPnt->nodesetval->nodeTab[0]; // xmlSetProp(curPnt, (const xmlChar *)"id", (const xmlChar *)name); // xmlXPathFreeObject(resPnt); // xmlXPathFreeContext(ctxPnt); /* Dump Doc to FileBuffer */ bufPnt = xmlBufferCreate(); curPnt = xmlDocGetRootElement(docPnt); xmlNodeDump(bufPnt, docPnt, curPnt, 0, 1); dataRefComponent = new char[20]; strncpy(dataRefComponent,"F-DisplayData.Screen",20); //putDataRef("F-DisplayData.Screen", (char *)xmlBufferContent(bufPnt), 0, isMainThread); putDataRef(dataRefComponent, (char *)xmlBufferContent(bufPnt), 0, isMainThread); delete dataRefComponent; //printf("%s\n", (char *)xmlBufferContent(bufPnt)); xmlBufferFree(bufPnt); /* Clean up */ sprintf(shellCmd, "rm /usr/tmp/%s.glade", name); system(shellCmd); sprintf(shellCmd, "rm /usr/tmp/%s.gladep", name); system(shellCmd); // DisplayRefresh(GTK_OBJECT(activeScreen)); } }