/* * * 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 #include #include #include #include "RunShare.hpp" #include "RepositoryCommand.hpp" #include "DataRef.hpp" #include "Limits.hpp" extern BiAppnPtr biAppnPtr; extern BiErrorReturnPtr biErrorReturnPtr; extern GtkWidget *activeScreen; /* Command : ERROR */ /* Syntax : ERROR data_ref [ data_ref ... ] [ SEVERITY severity_ref ] */ /* ERROR NAME error_name */ void CmdError(const char **argList, int argHits, bool isMainThread, GtkWidget *outputScreen, bool idleEvent) { xmlDocPtr docRes; xmlXPathContextPtr ctxRes; xmlXPathObjectPtr resRes; char errorString[LM_ERROR_MESSAGE_LENGTH], returnRef[LM_ERROR_MESSAGE_LENGTH], *severity; char tmpRef[255], *errorClass = NULL; GtkWidget *dialog; gint result; int i; if (outputScreen == NULL) outputScreen = activeScreen; /* Check for predefined error */ if (strcmp(argList[1], "NAME") == 0) { /* Get Error from repository */ docRes = RC_Get(biAppnPtr->getAppn(), "ErrorDialog", argList[2]); /* Create XPath environment */ ctxRes = xmlXPathNewContext(docRes); /* Get Error Text */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/ErrorDialog/ErrorText", ctxRes); strcpy(errorString, (char *)xmlXPathCastToString(resRes)); /* Get Severity */ resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/ErrorDialog/Severity", ctxRes); severity = (char *)xmlXPathCastToString(resRes); } else { /* Get all data refs and concatenate to one string */ for (i = 1; i <= argHits; i++) { if (strcmp(argList[i], "SEVERITY") == 0) break; getDataRefRaw(argList[i], isMainThread, returnRef, false); if (i == 1) strcpy(errorString, returnRef); else strcat(errorString, returnRef); } /* Get Severity Code */ if ( (i < argHits) && (strcmp(argList[i], "SEVERITY") == 0) ) severity = getDataRef(argList[(i+1)], isMainThread, tmpRef, false); else { errorClass = new char[6]; strncpy(errorClass,"ERROR\0",6); severity = errorClass; } } /* Display error according severity code */ /* get GTK thread lock */ if ((isMainThread == false) || (idleEvent == true)) gdk_threads_enter(); /* QUESTION */ if (severity[0] == 'Q') { dialog = gtk_message_dialog_new (GTK_WINDOW(outputScreen), \ GTK_DIALOG_DESTROY_WITH_PARENT, \ GTK_MESSAGE_QUESTION, \ GTK_BUTTONS_OK_CANCEL, \ errorString); result = gtk_dialog_run (GTK_DIALOG (dialog)); if (result == GTK_RESPONSE_OK) biErrorReturnPtr->setErrorReturn(0); else biErrorReturnPtr->setErrorReturn(1); gtk_widget_destroy (dialog); } /* INFO */ else if (severity[0] == 'I') { dialog = gtk_message_dialog_new (GTK_WINDOW(outputScreen), \ GTK_DIALOG_DESTROY_WITH_PARENT, \ GTK_MESSAGE_INFO, \ GTK_BUTTONS_CLOSE, \ errorString); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); biErrorReturnPtr->setErrorReturn(1); } /* WARNING */ else if (severity[0] == 'W') { dialog = gtk_message_dialog_new (GTK_WINDOW(outputScreen), \ GTK_DIALOG_DESTROY_WITH_PARENT, \ GTK_MESSAGE_WARNING, \ GTK_BUTTONS_CLOSE, \ errorString); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); biErrorReturnPtr->setErrorReturn(1); } /* ERROR */ else { dialog = gtk_message_dialog_new (GTK_WINDOW(outputScreen), \ GTK_DIALOG_DESTROY_WITH_PARENT, \ GTK_MESSAGE_ERROR, \ GTK_BUTTONS_CLOSE, \ errorString); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); biErrorReturnPtr->setErrorReturn(1); } if (errorClass != NULL) delete errorClass; if ((isMainThread == false) || (idleEvent == true)) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } }