/***************************************************************************
 *   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 GODGWEXMLCONFIGURATOR_H
#define GODGWEXMLCONFIGURATOR_H

// #include <GWorldEngineFactory.h>

#include "GweXmlConfiguratorBase.h"

#include <klineedit.h>
#include <klistview.h>

#include <qwidget.h>
#include <qpushbutton.h>
#include <qlistview.h>
#include <qstring.h>

namespace GWE
{
  class GWorldEngineFactory;
  class GweFactoryOption;
}


namespace GOD
{
  
/**
 * An option item in the graphical options tree.
 */
class GListViewOptionItem : public QObject, public QListViewItem
{
  Q_OBJECT
      
  protected:
    
    /**
     * The Option in the factory
     */
    GWE::GweFactoryOption* AssociatedOption;
    
  public:
    
    /**
     * Constructor for top-level items.
     */
    GListViewOptionItem(GWE::GweFactoryOption* option, QListView* parent);
    
    /**
     * Constructor with an item as parent.
     */
    GListViewOptionItem(GWE::GweFactoryOption* option, QListViewItem* parent);
    
    /**
     * Destructor
     */
    virtual ~GListViewOptionItem();
    
  protected:
    
    /**
     * Checks which value is renamed and emits a proper signal.
     */
    virtual void okRename(int col);
    
  signals:
    
    //note that the option name will (should!!) never change
    
    /**
     * Emitted when the value of the option is changed, this is the second column.
     */
    void valueChanged(GWE::GweFactoryOption* option, const QString& new_value);
    
    /**
     * Emitted when the description of an option has been changed.
     */
    void descriptionChanged(GWE::GweFactoryOption* option, const QString& new_desc);
};

/**
 * \class GweXmlConfigurator GweXmlConfigurator.h
 * \brief Configuration widget for GWE XML configuration files.
 * @author Raphael Langerhorst
 */

class GweXmlConfigurator : public GweXmlConfiguratorBase
{
  Q_OBJECT
    
  protected:

    /**
     * The factory that is used to modify the configuration.
     * The reason for using it is that the Factory automatically
     * extends option trees and thus we just need to stay in sync
     * with it to know which options should be available in the
     * ConfigTree.
     */
    GWE::GWorldEngineFactory* Factory;

  public:
    
    /**
     * Constructor.
     */
    GweXmlConfigurator(const QString& url = "/usr/local/etc/gsystem/gweconfig.xml", QWidget *parent = 0, const char *name = 0);

    /**
     * Virtual Desctructor.
     */
    virtual ~GweXmlConfigurator();

  public slots:
    
    /**
     * Loads the configuration from given URL, unsaved data is lost!
     */
    bool loadFromUrl(const QString&);
    
    /**
     * Saves the configuration to given URL
     */
    bool saveToUrl(const QString&);
    
    /**
     * Loads the configuration from the URL in the URL Requester,
     * unsaved data is lost!
     */
    bool loadConfiguration();
    
    /**
     * Saves the configuration to the URL in the URL Requester
     */
    bool saveConfiguration();
    
    /**
     * Updates the tree view content to the options actually inside the GWE Factory.
     * Currently this just clears the view and reloads all content from the factory.
     */
    void updateOptionsView();
    
  private:
    
    /**
     * Recursive view updates, used by updateOptionsView().
     */
    void updateSubOptions(GWE::GweFactoryOption* option, QListViewItem* parent);
    
};

}

#endif


syntax highlighted by Code2HTML, v. 0.9.1