[rkward-cvs] rkward/rkward/plugin rkcomponentmap.cpp,NONE,1.1 rkcomponentmap.h,NONE,1.1 Makefile.am,1.3,1.4 rkpluginhandle.cpp,1.2,1.3 rkpluginhandle.h,1.2,1.3

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Sep 9 13:02:59 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/plugin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12794/rkward/plugin

Modified Files:
	Makefile.am rkpluginhandle.cpp rkpluginhandle.h 
Added Files:
	rkcomponentmap.cpp rkcomponentmap.h 
Log Message:
Changed the way plugin-handles and corresponding menu-entries are created. Added some first building blocks for component infrastructure. Some polishing still needed.

Index: Makefile.am
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Makefile.am	26 Mar 2005 11:27:26 -0000	1.3
--- Makefile.am	9 Sep 2005 13:02:57 -0000	1.4
***************
*** 3,11 ****
  noinst_LIBRARIES =  libplugin.a
  libplugin_a_SOURCES = rkcheckbox.cpp rkformula.cpp rkplugin.cpp \
! 		rkpluginhandle.cpp rkpluginspinbox.cpp rkpluginwidget.cpp rkradio.cpp rktext.cpp \
! 		rkvarselector.cpp rkvarslot.cpp rkinput.cpp rkinput.h rknote.cpp rknote.h \
! 	rkpluginbrowser.cpp rkpluginbrowser.h
  noinst_HEADERS = rkcheckbox.h rkformula.h rkplugin.h rkpluginhandle.h \
! 	rkpluginspinbox.h rkpluginwidget.h rkradio.h rktext.h rkvarselector.h rkvarslot.h
  
  
--- 3,12 ----
  noinst_LIBRARIES =  libplugin.a
  libplugin_a_SOURCES = rkcheckbox.cpp rkformula.cpp rkplugin.cpp \
! 			rkpluginhandle.cpp rkpluginspinbox.cpp rkpluginwidget.cpp rkradio.cpp rktext.cpp \
! 			rkvarselector.cpp rkvarslot.cpp rkinput.cpp rkinput.h rknote.cpp rknote.h \
! 		rkpluginbrowser.cpp rkpluginbrowser.h rkcomponentmap.cpp
  noinst_HEADERS = rkcheckbox.h rkformula.h rkplugin.h rkpluginhandle.h \
! 		rkpluginspinbox.h rkpluginwidget.h rkradio.h rktext.h rkvarselector.h rkvarslot.h \
! 	rkcomponentmap.h
  
  

Index: rkpluginhandle.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkpluginhandle.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** rkpluginhandle.h	19 Aug 2004 12:21:11 -0000	1.2
--- rkpluginhandle.h	9 Sep 2005 13:02:57 -0000	1.3
***************
*** 22,25 ****
--- 22,27 ----
  #include <qstring.h>
  
+ #include "rkcomponentmap.h"
+ 
  class RKwardApp;
  
***************
*** 27,34 ****
  @author Thomas Friedrichsmeier
  */
! class RKPluginHandle : public QObject {
  	Q_OBJECT
  public:
!     RKPluginHandle(RKwardApp *parent, const QString &filename);
  
      ~RKPluginHandle();
--- 29,36 ----
  @author Thomas Friedrichsmeier
  */
! class RKPluginHandle : public QObject, public RKComponentHandle {
  	Q_OBJECT
  public:
!     RKPluginHandle(const QString &filename, RKComponentType type);
  
      ~RKPluginHandle();
***************
*** 37,42 ****
  	for creating the GUI. */
  	void activated ();
- private:
- 	QString _filename;
  };
  
--- 39,42 ----

Index: rkpluginhandle.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkpluginhandle.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** rkpluginhandle.cpp	19 Aug 2004 12:21:11 -0000	1.2
--- rkpluginhandle.cpp	9 Sep 2005 13:02:57 -0000	1.3
***************
*** 19,25 ****
  #include "rkplugin.h"
  #include "../rkward.h"
  
! RKPluginHandle::RKPluginHandle (RKwardApp *parent, const QString &filename) : QObject (parent) {
! 	_filename = filename;
  }
  
--- 19,25 ----
  #include "rkplugin.h"
  #include "../rkward.h"
+ #include "../rkglobals.h"
  
! RKPluginHandle::RKPluginHandle (const QString &filename, RKComponentType type) : QObject (RKGlobals::rkApp ()), RKComponentHandle (filename, type) {
  }
  
***************
*** 29,33 ****
  
  void RKPluginHandle::activated () {
! 	new RKPlugin (_filename);
  }
  
--- 29,33 ----
  
  void RKPluginHandle::activated () {
! 	new RKPlugin (getFilename ());
  }
  

--- NEW FILE: rkcomponentmap.h ---
/***************************************************************************
                          rkcomponentmap.h  -  description
                             -------------------
    begin                : Thu May 12 2005
    copyright            : (C) 2005 by Thomas Friedrichsmeier
    email                : tfry at 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 RKCOMPONENTMAP_H
#define RKCOMPONENTMAP_H

/** enum of different types of RKComponent */
enum RKComponentType {
	Standard=0		/// the only type available so far. Classifies a component that can be used standalone, and is not special in any way. Of course, as long as there is only one category of component, this is fairly meaningless. It's meant for future features.
};

#include <qstring.h>

/** This simple class keeps the most basic information about a component in RKWard. Most work is done in RKComponentMap.
Note that standard components (i.e. components which can act as regular top-level dialogs) have an additional counterpart in RKPluginHandle

TODO: no! RKPluginHandle should inherit from RKComponentHandle!


@author Thomas Friedrichsmeier
*/

class RKComponentHandle {
public:
	RKComponentHandle (const QString &filename, RKComponentType type);

	~RKComponentHandle ();

	QString getFilename () { return filename; };
	RKComponentType getType () { return type; };
	bool isPlugin ();

	static RKComponentHandle* createComponentHandle (const QString &filename, RKComponentType type);
private:
/** The filename of the description file for this comonent */
	QString filename;
	RKComponentType type;
};

#include <qmap.h>

class QDomElement;
class RKMenu;

/** This class (only a single instance should ever be needed) keeps a list of named components, which can be made accessible via the menu-structure
or included in other plugins. What this class does is rather simple: It basically maps a two piece name (namespace, component name) to a short description of the component (RKComponentHandle). The most important part of that description is the filename where a more elaborate definition of
the component can be retrieved.

The RKComponentMap provides convenience functions for adding or removing a .pluginmap-file to/from the list of components, and looking up RKComponentHandle for a given component name.

@author Thomas Friedrichsmeier
*/
class RKComponentMap {
public:
	RKComponentMap ();

	~RKComponentMap ();

/** adds all Plugins / components in a .pluginmap-file. Also takes care of creating the menu-items, etc. */
	void addPluginMap (const QString& plugin_map_file);
/** clears out (and deletes) all components / plugins */
	void clear ();

/** returns the component identified by id */
	RKComponentHandle* getComponentHandle (const QString &id);
private:
/** recurse into a lower menu-level 
@param parent the parent menu
@param element the QDomElement containing the description for the new submenu */
	void addSubMenu (RKMenu* parent, const QDomElement& element, const QString& cnamespace);

/** typedef for easy reference to iterator */
	typedef QMap<QString, RKComponentHandle*> ComponentMap;
/** the actual map of components */
	ComponentMap components;
};

#endif

--- NEW FILE: rkcomponentmap.cpp ---
/***************************************************************************
                          rkcomponentmap.cpp  -  description
                             -------------------
    begin                : Thu May 12 2005
    copyright            : (C) 2005 by Thomas Friedrichsmeier
    email                : tfry at 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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "rkcomponentmap.h"

#include <qfileinfo.h>

#include <klocale.h>

#include "../misc/xmlhelper.h"
#include "../misc/rkmenu.h"
#include "../misc/rkmenulist.h"
#include "../debug.h"
#include "../rkglobals.h"
#include "../rkward.h"
#include "rkpluginhandle.h"

RKComponentMap::RKComponentMap () {
	RK_TRACE (PLUGIN);
}

RKComponentMap::~RKComponentMap () {
	RK_TRACE (PLUGIN);
}

void RKComponentMap::addPluginMap (const QString& plugin_map_file) {
	RK_TRACE (PLUGIN);

	XMLHelper* xml = XMLHelper::getStaticHelper ();

	QDomElement document_element = xml->openXMLFile (plugin_map_file, DL_ERROR);
	if (xml->highestError () >= DL_ERROR) return;

	QString prefix = QFileInfo (plugin_map_file).dirPath (true) + "/" + xml->getStringAttribute(document_element, "base_prefix", "", DL_WARNING);
	QString cnamespace = xml->getStringAttribute(document_element, "namespace", "rkward", DL_WARNING) + "::";

	// step 1: create list of components
	QDomElement element = xml->getChildElement (document_element, "components", DL_ERROR);
	XMLChildList list = xml->getChildElements (element, "component", DL_ERROR);

	for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
		QString filename = prefix + xml->getStringAttribute((*it), "file", "", DL_WARNING);
		QString id = cnamespace + xml->getStringAttribute((*it), "id", "", DL_WARNING);
		int type = xml->getMultiChoiceAttribute ((*it), "type", "standard", 0, DL_WARNING);

		if (components.contains (id)) {
			RK_DO (qDebug ("RKComponentMap already contains a component with id \"%s\". Ignoring second entry.", id.latin1 ()), PLUGIN, DL_WARNING);
		} else if (!QFileInfo (filename).isReadable ()) {
			RK_DO (qDebug ("Specified file '%s' for component id \"%s\" does not exist or is not readable. Ignoring.", filename.latin1 (), id.latin1 ()), PLUGIN, DL_ERROR);
		} else {
			components.insert (id, RKComponentHandle::createComponentHandle (filename, (RKComponentType) type));
		}
	}

	// step 2: create / insert into menus
	element = xml->getChildElement (document_element, "hierarchy", DL_ERROR);
	list = xml->getChildElements (element, "menu", DL_ERROR);

	for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
		addSubMenu (0, (*it), cnamespace);
	}
}

void RKComponentMap::clear () {
	RK_TRACE (PLUGIN);

	RKGlobals::rkApp ()->getMenuList ()->clear ();
	for (ComponentMap::iterator it = components.begin (); it != components.end (); ++it) {
		delete it.data ();
	}
}

RKComponentHandle* RKComponentMap::getComponentHandle (const QString &id) {
	RK_TRACE (PLUGIN);

	return (components[id]);
}

void RKComponentMap::addSubMenu (RKMenu* parent, const QDomElement& element, const QString& cnamespace) {
	RK_TRACE (PLUGIN);

	XMLHelper* xml = XMLHelper::getStaticHelper ();

	// 1: create new menu
	RKMenu* menu = 0;
	if (!parent) {
		menu = RKGlobals::rkApp ()->getMenuList ()->createMenu (xml->getStringAttribute (element, "id", "none", DL_WARNING), xml->getStringAttribute (element, "label", i18n ("(no label)"), DL_WARNING), xml->getIntAttribute (element, "index", 4, DL_WARNING));
	} else {
		menu = parent->addSubMenu (xml->getStringAttribute (element, "id", "none", DL_WARNING), xml->getStringAttribute (element, "label", i18n ("(no label)"), DL_WARNING), xml->getIntAttribute (element, "index", -1, DL_INFO));
	}

	// 2: recurse into submenus
	XMLChildList list = xml->getChildElements (element, "menu", DL_INFO);

	for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
		addSubMenu (menu, (*it), cnamespace);
	}

	// 3: add entries
	list = xml->getChildElements (element, "entry", DL_INFO);
	for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
		QString id = cnamespace + xml->getStringAttribute ((*it), "component", "#invalid#", DL_ERROR);

		RKComponentHandle* handle = components[id];

		if ((!handle) || (!handle->isPlugin ())) {
			RK_DO (qDebug ("No such component found while creating menu-entries or component is not a standalone plugin: \"%s\". No entry created.", id.latin1 ()), PLUGIN, DL_ERROR);
		} else {
			menu->addEntry (id, static_cast<RKPluginHandle*> (handle), xml->getStringAttribute ((*it), "label", i18n ("(no label)"), DL_WARNING));
		}
	}
}

///########################### END RKComponentMap ###############################
///########################### BEGIN RKComponentHandle ############################

RKComponentHandle::RKComponentHandle (const QString &filename, RKComponentType type) {
	RK_TRACE (PLUGIN);

	RKComponentHandle::type = type;
	RKComponentHandle::filename = filename;
}

RKComponentHandle::~RKComponentHandle () {
	RK_TRACE (PLUGIN);
}

//static 
RKComponentHandle* RKComponentHandle::createComponentHandle (const QString &filename, RKComponentType type) {
	if (type == (int) Standard) {
		return (new RKPluginHandle (filename, type));
	}
	// TODO: create an RKPluginHandle instead!

	// TODO: more ifs, special handling for sepcial components

	RK_ASSERT (false);
	return 0;
}

bool RKComponentHandle::isPlugin () {
	if (type != Standard) {
		return false;
	}
	return true;
}





More information about the rkward-tracker mailing list