/***************************************************************************
 *   Copyright (C) 2005 by the G System Team                               *
 *   http://www.g-system.at                                                *
 *                                                                         *
 *   Permission is hereby granted, free of charge, to any person obtaining *
 *   a copy of this software and associated documentation files (the       *
 *   "Software"), to deal in the Software without restriction, including   *
 *   without limitation the rights to use, copy, modify, merge, publish,   *
 *   distribute, sublicense, and/or sell copies of the Software, and to    *
 *   permit persons to whom the Software is furnished to do so, subject to *
 *   the following conditions:                                             *
 *                                                                         *
 *   The above copyright notice and this permission notice shall be        *
 *   included in all copies or substantial portions of the Software.       *
 *                                                                         *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
 ***************************************************************************/

#ifndef GCLIENTFACTORY_H
#define GCLIENTFACTORY_H

#include <qobject.h>
#include <qtimer.h>

class GCommunicationWidget;

namespace GWE
{
  class GweController;
}

namespace GCE
{
  class GOpenGLFrame;
  class GCamera;
}

class QFrame;

class KMainWindow;
class KTextEdit;
class KLineEdit;
class KListBox;

/**
 * \class GClientFactory GClientFactory.h
 * \brief Can be used to initialize a client on top of a world engine.
 *
 * Basically the init() method handles all GUI creation.
 * It is the main application's responsibility to create
 * a KApplication object, and initialize a GweController
 * before calling init()
 *
 * It is also the main applications responsibility to
 * connect signals to quit the application.
 * 
 * @todo split of a GClientInterface class (should basically inherit KMainWindow)
 */
class GClientFactory : public QObject
{
  Q_OBJECT

  protected:
    /**
     * The controller is set by init() it is used
     * for setting up a client user interface on top of it.
     */
    GWE::GweController* WorldEngineController;
    
    /**
     * The main frame of the client interface.
     */
    QFrame* MainFrame;

    /**
     * The OpenGL frame that displays everything.
     */
    GCE::GOpenGLFrame* Frame;

    /**
     * The Camera for moving around,...
     */
    GCE::GCamera* Camera;
    
    GCommunicationWidget* CommWidget;

    /**
     * This timer is used to periodically check
     * if the GWE is ready (IDs are available,...)
     * It uses the checkWorldEngineReady() slot.
     */
    QTimer CheckTimer;

  public:

    /**
     * Constructor.
     */
    GClientFactory(QObject* parent = NULL, const char* name = NULL);

    /**
     * Virtual destructor.
     */
    virtual ~GClientFactory();

  protected slots:
    
    /**
     * This slot is used before the world engine is initialized.
     * Basically just draws a string saying "Connecting to G Universe".
     * The slot itself is connected to afterRendering() from the
     * GOpenGLFrame.
     * As soon as checkWorldEngineReady() fully initializes the
     * world engine this slot is disconnected.
     * @see GCE::GOpenGLFrame::afterRendering()
     */
    void renderInitStatus();

    /**
     * Checks if the world engine is ready - then
     * a client element is created and connected to
     * the camera. The OpenGL frame starts to render...
     */
    void checkWorldEngineReady();
    
    /**
     * Reads the current server list from the GWE and
     * updates the server listbox accordingly.
     * This is periodically called by a timer.
     * @todo move into new client interface class.
     */
    void updateServerList();
    

  public slots:

    /**
     * Starts client initialization.
     */
    void init(GWE::GweController* controller);
    
  signals:
    
    /**
     * Emitted when the user wants to send a message.
     * @todo move into new client interface class.
     * @see prepareMessageForSending()
     */
    void sendMessage(QString message, QString destination);

};

#endif


syntax highlighted by Code2HTML, v. 0.9.1