[rkward-cvs] rkward/rkward/plugin rkcomponentmap.cpp,1.5,1.6 rkcomponentmap.h,1.3,1.4
Thomas Friedrichsmeier
tfry at users.sourceforge.net
Mon Oct 24 18:12:00 UTC 2005
Update of /cvsroot/rkward/rkward/rkward/plugin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1999/rkward/plugin
Modified Files:
rkcomponentmap.cpp rkcomponentmap.h
Log Message:
Finish converting RKComponentMap to use KXMLGUI. Some small fixes, many cleanups.
Index: rkcomponentmap.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkcomponentmap.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rkcomponentmap.h 23 Oct 2005 22:07:24 -0000 1.3
--- rkcomponentmap.h 24 Oct 2005 18:11:58 -0000 1.4
***************
*** 45,49 ****
bool isPlugin ();
! static RKComponentHandle* createComponentHandle (const QString &filename, RKComponentType type, const QString& id);
private:
/** The filename of the description file for this comonent */
--- 45,49 ----
bool isPlugin ();
! static RKComponentHandle* createComponentHandle (const QString &filename, RKComponentType type, const QString& id, const QString& label);
private:
/** The filename of the description file for this comonent */
***************
*** 64,69 ****
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.
- // TODO: maybe we do not need to keep a map at all, but only create the handles! Think about this one day!
-
@author Thomas Friedrichsmeier
*/
--- 64,67 ----
***************
*** 77,81 ****
@returns number of plugins (i.e. stand-alone components/menu-entries) added successfully */
int addPluginMap (const QString& plugin_map_file);
- // int addPluginMapNew (const QString& plugin_map_file);
/** clears out (and deletes) all components / plugins */
void clear ();
--- 75,78 ----
***************
*** 85,94 ****
private:
/** recurse into a lower menu-level
! @param parent the parent menu
! @param element the QDomElement containing the description for the new submenu
@returns number of plugins/menu-entries added successfully */
- // int addSubMenu (RKMenu* parent, const QDomElement& element, const QString& cnamespace);
int addSubMenu (QDomElement& parent, const QDomElement& description, const QString& cnamespace);
QDomElement findOrCreateElement (QDomElement& parent, const QString& tagname, const QString& name, const QString& label, int index);
--- 82,96 ----
private:
/** recurse into a lower menu-level
! @param parent the parent menu (in the KXMLGUI)
! @param description the QDomElement containing the description for the new submenu
@returns number of plugins/menu-entries added successfully */
int addSubMenu (QDomElement& parent, const QDomElement& description, const QString& cnamespace);
+ /** helper function: Find a specified element, and return it. If the element could not be found, it is created instead. The first three parameters are used as search parameters (all have to match). The additional two parameters only take effect, if a new element is created.
+ @param parent the QDomElement whose children to search through
+ @param tagname the tagname to look for
+ @param name value of the "name"-attribute to look for
+ @param label the label to assign to the new element (if no existing match could be found)
+ @param index the index position where to insert the new element in the list of children (if no existing match could be found). -1 means insert at the end of the list. */
QDomElement findOrCreateElement (QDomElement& parent, const QString& tagname, const QString& name, const QString& label, int index);
Index: rkcomponentmap.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/plugin/rkcomponentmap.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** rkcomponentmap.cpp 23 Oct 2005 22:07:24 -0000 1.5
--- rkcomponentmap.cpp 24 Oct 2005 18:11:58 -0000 1.6
***************
*** 36,89 ****
RKComponentMap::~RKComponentMap () {
RK_TRACE (PLUGIN);
- }
- /*
- int 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 (0);
!
! QString prefix = QFileInfo (plugin_map_file).dirPath (true) + "/" + xml->getStringAttribute(document_element, "base_prefix", QString::null, 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", QString::null, DL_WARNING);
! QString id = cnamespace + xml->getStringAttribute((*it), "id", QString::null, 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);
!
! int counter = 0;
! for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
! counter += addSubMenu (0, (*it), cnamespace);
! }
!
! addPluginMapNew (plugin_map_file);
! qDebug ("after %s", xmlguiBuildDocument ().toString ().latin1 ());
!
! return counter;
! } */
void RKComponentMap::clear () {
RK_TRACE (PLUGIN);
! RKGlobals::rkApp ()->getMenuList ()->clear ();
for (ComponentMap::iterator it = components.begin (); it != components.end (); ++it) {
delete (it.data ());
--- 36,47 ----
RKComponentMap::~RKComponentMap () {
RK_TRACE (PLUGIN);
! clear ();
! }
void RKComponentMap::clear () {
RK_TRACE (PLUGIN);
! actionCollection ()->clear ();
for (ComponentMap::iterator it = components.begin (); it != components.end (); ++it) {
delete (it.data ());
***************
*** 103,144 ****
return (components[id]);
}
- /*
- int RKComponentMap::addSubMenu (RKMenu* parent, const QDomElement& element, const QString& cnamespace) {
- RK_TRACE (PLUGIN);
-
- int counter = 0;
- 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_INFO));
- } 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) {
- counter += 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), xml->getIntAttribute ((*it), "index", -1, DL_INFO));
- counter++;
- }
- }
- return counter;
- } */
//static
--- 61,64 ----
***************
*** 147,158 ****
XMLHelper* xml = XMLHelper::getStaticHelper ();
! XMLChildList list = xml->getChildElements (parent, tagname, DL_INFO);
QDomElement insert_after_element;
for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
! if (name == xml->getStringAttribute ((*it), "name", "", DL_ERROR)) {
return (*it);
} else {
! if ((index >= 0) && insert_after_element.isNull ()) {
! if (index > xml->getIntAttribute ((*it), "index", 1000000, DL_INFO)) {
insert_after_element = *it;
}
--- 67,78 ----
XMLHelper* xml = XMLHelper::getStaticHelper ();
! XMLChildList list = xml->getChildElements (parent, QString::null, DL_INFO); // we need to look at all children, so we get the order right
QDomElement insert_after_element;
for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
! if ((tagname == (*it).tagName ()) && (name == xml->getStringAttribute ((*it), "name", "", DL_ERROR))) {
return (*it);
} else {
! if (index >= 0) {
! if (index > xml->getIntAttribute ((*it), "index", -1, DL_INFO)) {
insert_after_element = *it;
}
***************
*** 165,171 ****
ret.setAttribute ("name", name);
ret.setAttribute ("index", index);
! QDomElement text = xmlguiBuildDocument ().createElement ("text");
! text.appendChild (xmlguiBuildDocument ().createTextNode (label));
! ret.appendChild (text);
parent.insertAfter (ret, insert_after_element); // if index_after_element.isNull, this add the new element as the last child of parent!
--- 85,93 ----
ret.setAttribute ("name", name);
ret.setAttribute ("index", index);
! if (!label.isEmpty ()) {
! QDomElement text = xmlguiBuildDocument ().createElement ("text");
! text.appendChild (xmlguiBuildDocument ().createTextNode (label));
! ret.appendChild (text);
! }
parent.insertAfter (ret, insert_after_element); // if index_after_element.isNull, this add the new element as the last child of parent!
***************
*** 198,203 ****
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 {
! findOrCreateElement (menu_element, "Action", id, xml->getStringAttribute ((*it), "label", i18n ("(no label)"), DL_WARNING), xml->getIntAttribute ((*it), "index", -1, DL_INFO));
! action (id)->setText (xml->getStringAttribute ((*it), "label", i18n ("(no label)"), DL_WARNING));
counter++;
}
--- 120,124 ----
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 {
! findOrCreateElement (menu_element, "Action", id, QString::null, xml->getIntAttribute ((*it), "index", -1, DL_INFO));
counter++;
}
***************
*** 227,230 ****
--- 148,152 ----
QString id = cnamespace + xml->getStringAttribute((*it), "id", QString::null, DL_WARNING);
int type = xml->getMultiChoiceAttribute ((*it), "type", "standard", 0, DL_WARNING);
+ QString label = xml->getStringAttribute ((*it), "label", i18n ("(no label)"), DL_WARNING);
if (components.contains (id)) {
***************
*** 233,242 ****
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, id));
}
}
// step 2: create / insert into menus
- qDebug ("before %s", xmlguiBuildDocument ().toString ().latin1 ());
QDomElement xmlgui_menubar_elem = xml->getChildElement (xmlguiBuildDocument ().documentElement (), "MenuBar", DL_ERROR);
--- 155,163 ----
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, id, label));
}
}
// step 2: create / insert into menus
QDomElement xmlgui_menubar_elem = xml->getChildElement (xmlguiBuildDocument ().documentElement (), "MenuBar", DL_ERROR);
***************
*** 266,273 ****
//static
! RKComponentHandle* RKComponentHandle::createComponentHandle (const QString &filename, RKComponentType type, const QString& id) {
if (type == (int) Standard) {
RKPluginHandle *ret = new RKPluginHandle (filename, type);
! new KAction ("", 0, ret, SLOT (activated ()), RKGlobals::componentMap ()->actionCollection (), id);
return (ret);
}
--- 187,194 ----
//static
! RKComponentHandle* RKComponentHandle::createComponentHandle (const QString &filename, RKComponentType type, const QString& id, const QString& label) {
if (type == (int) Standard) {
RKPluginHandle *ret = new RKPluginHandle (filename, type);
! new KAction (label, 0, ret, SLOT (activated ()), RKGlobals::componentMap ()->actionCollection (), id);
return (ret);
}
More information about the rkward-tracker
mailing list