/***************************************************************************
 *   Copyright (C) 2003 by liuspider                                       *
 *   liuspider@users.sourceforge.net                                       *
 *                                                                         *
 *   This program 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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 **************************************************************************/
#ifndef SCIMGLOBALACTIONS_H
#define SCIMGLOBALACTIONS_H

#include "skimpluginmanager.h"

#include <kactioncollection.h>
#include <kaboutapplication.h>
#include <kaboutdata.h>

#include "scimhelpdialog.h"

class SkimPluginManager;
class ScimAction;
class ScimComboAction;

namespace scim_kde{
  union ClientObject{
  class ScimAction *action;
  class ScimComboAction *comboaction;
  class QPopupMenu *popup;
  };
  enum ClientObjectType {Unknown, Action, ComboAction, Popup};
}

struct ClientPropertyInfo {
    scim::Property   property;
    int client;
    int id;    //the index in PropertyRepository
    scim_kde::ClientObject parentObject;
    scim_kde::ClientObjectType objectType;
};

typedef QMap <int, ClientPropertyInfo>               PropertyRepository;

class SkimGlobalActions : public KActionCollection
{
Q_OBJECT
public:
    SkimGlobalActions(QObject *parent = 0, const char *name = 0);
    ~SkimGlobalActions();

    KActionCollection* externalActionCollection () {return externalActions;};
    KActionPtrList propertyActions() {return _propertyActions;};
signals:
    void propertiesRegistered();
    void propertyChanged();
public slots:
    void registerProperties(const scim::PropertyList & properties, int client);
    void updateProperty(const scim::Property &property, int client);
protected slots:
    void propertyActivated(int);
    void deleteProperties(int client);
    void aboutApp();
    void showHelp( const QString & );
    
    void SetFactoryInfo( const QString &, const QString &);
    void changeFactory(const QString & path);
    void receiveFactoryMenu(std::vector <scim::String> &, std::vector <scim::String> &, 
    std::vector <scim::String> &, std::vector <scim::String> &);

    void requestReloadAllModules();

protected:
    void updateProperty(PropertyRepository::iterator &it, const scim::Property &property, int client);
    void create_properties(QWidget * parent, PropertyRepository &repository,
                                          const scim::PropertyList &properties, 
                                          scim::PropertyList::const_iterator  begin,
                                          scim::PropertyList::const_iterator  end,
                                          int client);
    PropertyRepository::iterator find_saved_property(PropertyRepository::iterator,
                                                     PropertyRepository::iterator,
                                                     const scim::Property &property);

    SkimPluginManager* mc;

    KActionCollection* externalActions;

    ScimComboAction* ServerAction;
    
    KIconLoader *kil;
    
    KAboutApplication* mAboutApp;
    ScimHelpDialog* helpDialog;
    
private:
    std::vector<scim::String> uuids;

    scim::SocketServerThread* InputServer;
    class KHelpMenu* mHelpMenu;
    
    PropertyRepository _property_repository;
    KActionPtrList _propertyActions;
};

#endif
