/*
*
* ProLinga-UI
*
* Copyright (C) 2002-2008 Xobas Software.
* All rights reserved.
*
* This file is part of ProLinga-UI.
*
* ProLinga-UI 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-UI 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-UI. If not, see .
*
* More information is available at the following addresses:
*
* Website : http://www.prolinga.org
*
* Email : prolinga-list@prolinga.org
*
*
*/
#include "UICommon.h"
#include
#include
#include
#include
#include
#include
#include "UCUICommand.hpp"
#include "UIConfig.hpp"
#include "UIMain.hpp"
#include "UIShare.hpp"
/* Make sure global handles keep their value */
//static ConfigUIPtr confUIStaticPtr;
static int _argcStatic;
static char **_argvStatic;
/* Global handles */
//ConfigUIPtr confUIPtr = confUIStaticPtr;
int _argc = _argcStatic;
char **_argv = _argvStatic;
DesktopScreenPtr desktopScreenPtr = NULL;
void *RunGTKThread(void *args)
{
/* Start main Gtk+ loop */
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
/* Return */
return NULL;
}
xmlDocPtr ProcessError(char *errorString)
{
xmlDocPtr docUIResponse;
char *uiResponse;
/* Generate generic error */
uiResponse = new char[1024];
strcpy(uiResponse, "\n\t\n\t\t\n\t\t\t\n\t\t\t\tError\n\t\t\t\tCan not process UI Command\n\t\t\t\t");
strcat(uiResponse, errorString);
strcat(uiResponse, "\n\t\t\t\n\t\t\n\t\n");
/* Load response into xml doc */
docUIResponse = xmlParseMemory(uiResponse, strlen(uiResponse));
/* Clean up */
delete uiResponse;
/* Return */
return docUIResponse;
}
PlUI::PlUI()
{
/* Init */
isUIOpen = false;
}
PlUI::~PlUI()
{
/* free */
}
void PlUI::uiOpen(const char *configFileName, int argc, char **argv)
{
char *confName, *threadName;
pthread_t tid;
/* Return if already open */
if (isUIOpen == true)
return;
/* Get Config */
if (configFileName == NULL)
confName = DEF_CONFIG_FILE;
else
confName = (char *)configFileName;
/* Get Config */
// confRunPtr = new ConfigRun(DEF_CONFIG_FILE);
// confRunStaticPtr = confRunPtr;
/* Init Main Thread & GTK+ */
if (! g_thread_supported ())
g_thread_init(NULL);
gdk_threads_init();
gtk_init (&argc, &argv);
/* Set status */
isUIOpen = true;
/* Start main GTK loop */
pthread_create(&tid, NULL, RunGTKThread, NULL);
/* Free */
// delete confRunPtr;
}
void PlUI::uiClose(void)
{
/* Return if already closed */
if (isUIOpen == false)
return;
/* Clean up */
//delete confUIPtr;
/* Close GTK+ */
gtk_main_quit();
/* Set status */
isUIOpen = false;
}
xmlDocPtr PlUI::executeCommand(const xmlDocPtr uiRequest)
{
xmlDocPtr uiResponse;
/* Return if UI not open or process command */
if (isUIOpen == false)
uiResponse = ProcessError("UI not opened.");
else
uiResponse = UCUICommand(uiRequest);
/* Return */
return uiResponse;
}