[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: removing some of a KParts' GUI
From:       Thomas Friedrichsmeier <thomas.friedrichsmeier () ruhr-uni-bochum ! de>
Date:       2005-10-17 19:01:28
Message-ID: 200510172101.28435.thomas.friedrichsmeier () ruhr-uni-bochum ! de
[Download RAW message or body]

Hi again,

> Probably an easy question, but I just couldn't figure it out, yet: How can
> you remove some portions of a KPart GUI?
> For instance, I'm using a khtmlpart (among others), but in the context of
> my application, the entire Tools-Menu, and a number of other menus/toolbar
> items are entirely meaningless, and just constitute GUI bloat.
> Could somebody point me to the relevant documentation, please?

since nobody answered this question, I concluded, there is no easy way to do 
so, currently. After hours of experimentation with various approaches, I came 
up with the two helper functions listed below. Call these before the GUI is 
created, with a list of names of actions/menus/toolbars you want discarded. 
E.g.:

removeContainers (khtmlpart, QStringList::split (',', 
"tools,security,extraToolBar,saveBackground,saveDocument,saveFrame,kget_menu"), 
true);

Maybe a more efficient analogon to this could/should be added to the 
KXMLGUIClient?

/** A helper function to removeContainers: remove QDomElements with attribute 
'name="..."' from QDomNode parent, where "..." is any of the strings in 
names. */
	void removeNamedElementsRecursive (const QStringList &names, QDomNode 
&parent) {
		QDomNode nchild;

		for (QDomNode child = parent.firstChild (); !child.isNull (); child = 
nchild) {
			removeNamedElementsRecursive (names, child);

			nchild = child.nextSibling ();		// need to fetch next sibling here, as we 
might remove the child below
			if (child.isElement ()) {
				QDomElement e = child.toElement ();
				if (names.contains (e.attribute ("name"))) {
					parent.removeChild (child);
				}
			}
		}
	}


/** remove containers (actions, menus, etc.) with attribute 'name="..."' from 
KXMLGUIClient from s XML gui, where "..." is any of the strings in names. If 
recursive, also removes those containers from child clients. */
	void removeContainers (KXMLGUIClient *from, const QStringList &names, bool 
recursive) {
		QDomDocument doc = from->xmlguiBuildDocument ();
		if  (doc.documentElement ().isNull ()) doc = from->domDocument ();
	
		QDomElement e = doc.documentElement ();
		removeNamedElementsRecursive (names, e);
		from->setXMLGUIBuildDocument (doc);
	
		if (recursive) {
			QPtrList <KXMLGUIClient> *children = const_cast<QPtrList <KXMLGUIClient> *> 
(from->childClients ());
			if (children) {
				for (KXMLGUIClient *child = children->first (); child; child = 
children->next ()) {
					removeContainers (child, names, true);
				}
			}
		}
	}
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic