Author: dmacvicar
Date: Wed Jul 30 18:39:03 2008
New Revision: 49530
URL: http://svn.opensuse.org/viewcvs/yast?rev=49530&view=rev
Log:
fork reader to support a 1:1 xml representation
Added:
branches/tmp/dmacvicar/yast-xmlui/libyui/examples/XMLLoad.cc
branches/tmp/dmacvicar/yast-xmlui/libyui/examples/yuixml/
branches/tmp/dmacvicar/yast-xmlui/libyui/examples/yuixml/example-1.xml
branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.cc
branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.h
Modified:
branches/tmp/dmacvicar/yast-xmlui/libyui/examples/Makefile.am
branches/tmp/dmacvicar/yast-xmlui/libyui/src/Makefile.am
Modified: branches/tmp/dmacvicar/yast-xmlui/libyui/examples/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/yast-xmlui/libyui/examples/Makefile.am?rev=49530&r1=49529&r2=49530&view=diff
==============================================================================
--- branches/tmp/dmacvicar/yast-xmlui/libyui/examples/Makefile.am (original)
+++ branches/tmp/dmacvicar/yast-xmlui/libyui/examples/Makefile.am Wed Jul 30 18:39:03 2008
@@ -7,6 +7,7 @@
noinst_PROGRAMS = \
HelloWorld \
XULLoad \
+ XMLLoad \
ComboBox1 \
ComboBox1-editable \
SelectionBox1 \
@@ -20,6 +21,9 @@
XULLoad_SOURCES = XULLoad.cc
XULLoad_LDADD = -L$(top_srcdir)/src -lyui
+XMLLoad_SOURCES = XMLLoad.cc
+XMLLoad_LDADD = -L$(top_srcdir)/src -lyui
+
ComboBox1_SOURCES = ComboBox1.cc
ComboBox1_LDADD = -L$(top_srcdir)/src -lyui
Added: branches/tmp/dmacvicar/yast-xmlui/libyui/examples/XMLLoad.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/yast-xmlui/libyui/examples/XMLLoad.cc?rev=49530&view=auto
==============================================================================
--- branches/tmp/dmacvicar/yast-xmlui/libyui/examples/XMLLoad.cc (added)
+++ branches/tmp/dmacvicar/yast-xmlui/libyui/examples/XMLLoad.cc Wed Jul 30 18:39:03 2008
@@ -0,0 +1,20 @@
+// Trivial libyui example.
+//
+// Compile with:
+//
+// g++ -I/usr/include/YaST2/yui -lyui HelloWorld.cc -o HelloWorld
+
+#include "YUI.h"
+#include "YUIXMLReader.h"
+
+#include "YWidgetFactory.h"
+#include "YDialog.h"
+#include "YLayoutBox.h"
+#include "YEvent.h"
+
+int main( int argc, char **argv )
+{
+ YDialog *dialog = YUIXMLReader::readDialogFromFile( argv[1] );
+ dialog->waitForEvent();
+ dialog->destroy();
+}
Added: branches/tmp/dmacvicar/yast-xmlui/libyui/examples/yuixml/example-1.xml
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/yast-xmlui/libyui/examples/yuixml/example-1.xml?rev=49530&view=auto
==============================================================================
--- branches/tmp/dmacvicar/yast-xmlui/libyui/examples/yuixml/example-1.xml (added)
+++ branches/tmp/dmacvicar/yast-xmlui/libyui/examples/yuixml/example-1.xml Wed Jul 30 18:39:03 2008
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<dialog id="example" xmlns="http://www.opensuse.org/YaST/YUIXML">
+ <hbox>
+ <pushbutton id="hello" label="Hello"/>
+ <pushbutton id="bye" label="Bye"/>
+ </hbox>
+</dialog>
+
+
+
Modified: branches/tmp/dmacvicar/yast-xmlui/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/yast-xmlui/libyui/src/Makefile.am?rev=49530&r1=49529&r2=49530&view=diff
==============================================================================
--- branches/tmp/dmacvicar/yast-xmlui/libyui/src/Makefile.am (original)
+++ branches/tmp/dmacvicar/yast-xmlui/libyui/src/Makefile.am Wed Jul 30 18:39:03 2008
@@ -90,7 +90,7 @@
YStringTree.cc \
YRpmGroupsTree.cc \
\
- YUIXULReader.cc \
+ YUIXMLReader.cc \
xmlsp/xmlsp.cpp \
xmlsp/xmlsp_dom.cpp
@@ -182,7 +182,7 @@
YRpmGroupsTree.h \
YStringTree.h \
YTransText.h \
- YUIXULReader.h
+ YUIXMLReader.h
CLEANFILES = libyui.kdoc $(BUILT_SOURCES)
Added: branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.cc?rev=49530&view=auto
==============================================================================
--- branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.cc (added)
+++ branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.cc Wed Jul 30 18:39:03 2008
@@ -0,0 +1,785 @@
+
+#include <cstring>
+#include <sstream>
+#include <fstream>
+#include <iostream>
+#include "xmlsp/xmlsp_dom.h"
+
+#include "YUI.h"
+
+#define YUILogComponent "YUIXULReader"
+#include "YUILog.h"
+
+#include "YUISymbols.h"
+
+#include "YWidgetFactory.h"
+#include "YItem.h"
+#include "YWidgetID.h"
+#include "YImage.h"
+#include "YDialog.h"
+#include "YLayoutBox.h"
+#include "YFrame.h"
+#include "YCheckBox.h"
+#include "YIntField.h"
+#include "YInputField.h"
+#include "YMultiLineEdit.h"
+#include "YPushButton.h"
+#include "YRadioButton.h"
+#include "YRadioButtonGroup.h"
+#include "YSelectionBox.h"
+#include "YMultiSelectionBox.h"
+#include "YLabel.h"
+#include "YProgressBar.h"
+#include "YComboBox.h"
+
+#include "YUIXMLReader.h"
+
+using namespace std;
+using namespace XMLSP;
+
+inline bool namecmp( const std::string &s1,
+ const std::string &s2 )
+{
+ return ::strcasecmp(s1.c_str(), s2.c_str()) == 0;
+}
+
+
+
+/**
+ * Widget ID class based on string.
+ **/
+class StringWidgetID: public YWidgetID
+{
+public:
+ /**
+ * Constructor.
+ **/
+ StringWidgetID( const string &value )
+ : _value(value)
+ {}
+
+ /**
+ * Check if this ID is equal to another.
+ *
+ * Reimplemented from YWidgetID.
+ **/
+ virtual bool isEqual( YWidgetID * otherID ) const
+ { return otherID->toString() == _value; }
+
+ /**
+ * Convert the ID value to string.
+ * Used for logging and debugging.
+ *
+ * Reimplemented from YWidgetID.
+ **/
+ virtual string toString() const
+ { return _value; }
+private:
+ string _value;
+};
+
+
+string dumpAttributes(XMLSP::DOMElement* e)
+{
+ stringstream s;
+ XMLSP::DOMStringList list = e->getAttributeList();
+ XMLSP::DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++) {
+ s<<" "<<*i<<"=\""<<e->getAttribute(*i)<<"\"";
+ }
+ return s.str();
+}
+
+
+void dumpElement(XMLSP::DOMElement* e, int depth)
+{
+ string p1, p2;
+ XMLSP::DOMElements els;
+ XMLSP::DOMElements::iterator i;
+
+
+ p1.assign((depth-1)*4, ' ');
+ p2.assign(depth*4, ' ');
+
+ cout<attributeCount())
+ cout<hasChilds()) {
+ cout<getChilds();
+ for(i = els.begin(); i != els.end(); i++) {
+ dumpElement(*i, depth+1);
+ }
+ } else if (e->getCData().size()) {
+ cout<> x))
+ YUI_THROW(YUIException("can't convert string \"" + s + "\" to integer"));
+ return x;
+}
+
+inline bool convertToBool(const std::string& s)
+{
+ if ( s == "true" )
+ return true;
+ else if (s == "false" )
+ return false;
+ else
+ YUI_THROW(YUIException("can't convert string \"" + s + "\" to boolean"));
+}
+
+
+// forward declarations
+static YWidget * parseCheckbox( YWidget *parent, DOMElement *root );
+static YWidget * parseComboBox( YWidget *parent, DOMElement *root );
+static YWidget * parseLabel( YWidget *parent, DOMElement *root );
+static YWidget * parseMultiSelectionBox( YWidget *parent, DOMElement *root );
+static YWidget * parseProgressBar( YWidget *parent, DOMElement *root );
+static YWidget * parseRadioButtonGroup( YWidget *parent, DOMElement *root );
+static YWidget * parseRadioButton( YWidget *parent, DOMElement *root );
+static YWidget * parseSelectionBox( YWidget *parent, DOMElement *root );
+static YWidget * parseCaption( YWidget *parent, DOMElement *root );
+static YWidget * parseFrame( YWidget *parent, DOMElement *root );
+static YWidget * parseTextbox( YWidget *parent, DOMElement *root );
+static YWidget * parseImage( YWidget *parent, DOMElement *root );
+static YWidget * parsePushButton( YWidget *parent, DOMElement *root );
+static YWidget * parseHBox( YWidget *parent, DOMElement *root );
+static YWidget * parseVBox( YWidget *parent, DOMElement *root );
+static YWidget * parseDialog( YWidget *parent, DOMElement *root );
+static YWidget * parseNode( YWidget *parent, DOMElement *root );
+static void parseChildren( YWidget *parent, DOMElement *root );
+static YItemCollection parseItemList( const string &tagname, YWidget *parent, DOMElement *root );
+static YItem parseItem( const string &tagname, YWidget *parent, DOMElement *root );
+
+static YWidget *
+parseProgressBar( YWidget *parent, DOMElement *root )
+{
+ int value = 0;
+ int maxValue = 100;
+ string mode = "determined";
+ string label;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "mode" )
+ mode = root->getAttribute(*i);
+ else if ( *i == "value" )
+ value = convertToInt(root->getAttribute(*i));
+ }
+
+ YProgressBar * progressBar = YUI::widgetFactory()->createProgressBar( parent, label, maxValue );
+ if ( value > 0 )
+ progressBar->setValue( value );
+ return progressBar;
+}
+
+
+static YItem
+parseItem( const string &tagname, YWidget *parent, DOMElement *root )
+{
+ if ( root->getElementName() != tagname )
+ {
+ YUI_THROW(YUIException("Invalid item '" + root->getElementName() + "'"));
+ }
+
+ string label;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "label" )
+ label = root->getAttribute(*i);
+ }
+
+ YItem item(label);
+ return item;
+}
+
+
+static YItemCollection
+parseItemList( const string &tagname, YWidget *parent, DOMElement *root )
+{
+ YItemCollection itemCollection;
+ itemCollection.reserve( root->childCount() );
+
+ try
+ {
+ DOMElements els;
+ DOMElements::iterator i;
+
+ if (root->hasChilds())
+ {
+ els = root->getChilds();
+ for(i = els.begin(); i != els.end(); i++)
+ {
+ // FIXME, lbyui does not support this
+ if ( (*i)->getElementName() == "menuseparator" )
+ continue;
+
+ YItem item = parseItem( tagname, parent, *i );
+ }
+ }
+ }
+ catch ( YUIException & exception )
+ {
+ // Delete all items created so far
+ YItemIterator it = itemCollection.begin();
+
+ while ( it != itemCollection.end() )
+ {
+ YItem * item = *it;
+ ++it;
+ delete item;
+ }
+ throw;
+ }
+ return itemCollection;
+}
+
+static YWidget *
+parseLabel( YWidget *parent, DOMElement *root )
+{
+ string value;
+ bool isOutputField = false;
+ bool isHeading = false;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "value" )
+ value = root->getAttribute(*i);
+ }
+ YLabel * label = YUI::widgetFactory()->createLabel( parent, value, isHeading, isOutputField );
+ return label;
+}
+
+static YWidget *
+parseComboBox( YWidget *parent, DOMElement *root )
+{
+ // FIXME XUL has no label here
+ string label;
+ bool editable = false;
+
+ // get the attributes
+ {
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "label" )
+ label = root->getAttribute(*i);
+ else if ( *i == "editable" )
+ editable = ( root->getAttribute(*i) == "true" );
+ }
+ }
+
+ YComboBox * comboBox = YUI::widgetFactory()->createComboBox( parent, label, editable );
+
+ // sadly the menulist element has a menupopup element
+ // which contains the menutem elements
+ {
+
+ DOMElements els;
+ DOMElements::iterator i;
+
+ if (root->hasChilds())
+ {
+ els = root->getChilds();
+ for(i = els.begin(); i != els.end(); i++)
+ {
+ if ( (*i)->getElementName() == "menupopup" )
+ {
+ comboBox->addItems( parseItemList( "menuitem", comboBox, *i ) );
+ }
+ }
+ }
+ }
+ return comboBox;
+}
+
+
+static YWidget *
+parseSelectionBox( YWidget *parent, DOMElement *root )
+{
+ string seltype = "single";
+
+ // FIXME XUL has no label here
+ string label;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "seltype" )
+ seltype = root->getAttribute(*i);
+ }
+
+ YSelectionBox *selBox = YUI::widgetFactory()->createSelectionBox( parent, label );
+ selBox->addItems( parseItemList( "listitem", selBox, root ) );
+ return selBox;
+}
+
+static YWidget *
+parseMultiSelectionBox( YWidget *parent, DOMElement *root )
+{
+ string seltype = "single";
+
+ // FIXME XUL has no label here
+ string label;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "seltype" )
+ seltype = root->getAttribute(*i);
+ }
+
+ YMultiSelectionBox * mselBox = YUI::widgetFactory()->createMultiSelectionBox( parent, label );
+ mselBox->addItems( parseItemList( "listitem", mselBox, root ) );
+ return mselBox;
+}
+
+
+static YWidget *
+parseRadioButtonGroup( YWidget *parent, DOMElement *root )
+{
+ // vertical by default
+ string orient = "vertical";
+
+ YRadioButtonGroup * radioButtonGroup = YUI::widgetFactory()->createRadioButtonGroup( parent );
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "orient" )
+ orient = root->getAttribute(*i);
+ }
+
+ YLayoutBox *box;
+
+ if ( orient == "horizontal" )
+ box = YUI::widgetFactory()->createHBox(radioButtonGroup);
+ else
+ box = YUI::widgetFactory()->createVBox(radioButtonGroup);
+
+ parseChildren( box, root );
+
+ return radioButtonGroup;
+}
+
+static YWidget *
+parseRadioButton( YWidget *parent, DOMElement *root )
+{
+ string label;
+ string value;
+ bool selected = false;
+ bool disabled = false;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "selected" )
+ selected = ( root->getAttribute(*i) == "true" );
+ if ( *i == "label" )
+ label = root->getAttribute(*i);
+ if ( *i == "disabled" )
+ disabled = ( root->getAttribute(*i) == "true" );
+ }
+
+ YRadioButton * radioButton = YUI::widgetFactory()->createRadioButton( parent, label, selected );
+ return radioButton;
+}
+
+
+
+/**
+ * Sets the caption of a groupbox
+ * <caption label="..."/>
+ */
+static YWidget * parseCaption( YWidget *parent, DOMElement *root )
+{
+ return 0L;
+}
+
+/**
+ * parses a YFrame from XUL
+ * <groupbox>
+ * <caption label="Network"/>
+ * </groupbox>
+ */
+static YWidget *
+parseFrame( YWidget *parent, DOMElement *root )
+{
+ // FIXME children <caption> sets the label
+ string label;
+
+ // vertical by default
+ string orient = "vertical";
+
+ YFrame * frame = YUI::widgetFactory()->createFrame( parent, label );
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "orient" )
+ orient = root->getAttribute(*i);
+ }
+
+ YLayoutBox *box;
+
+ if ( orient == "horizontal" )
+ box = YUI::widgetFactory()->createHBox(frame);
+ else
+ box = YUI::widgetFactory()->createVBox(frame);
+
+ parseChildren( box, root );
+
+ return frame;
+}
+
+/**
+ * parses a YIntField from XUL
+ * <textbox type="..."/>
+ */
+static YWidget *
+parseTextbox( YWidget *parent, DOMElement *root )
+{
+ // type of textbox
+ string type = "normal";
+
+ // for type number
+ int min = 0;
+ int max = 0;
+ int int_value = 0;
+
+ // for normal type
+ bool multiline = false;
+ string value;
+
+ // FIXME
+ string label;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "type" )
+ type = root->getAttribute(*i);
+ if ( *i == "multiline" )
+ multiline = ( root->getAttribute(*i) == "true" );
+ if ( *i == "max" )
+ max = convertToInt(root->getAttribute(*i));
+ if ( *i == "min" )
+ min = convertToInt(root->getAttribute(*i));
+ }
+
+ if ( type == "number" )
+ {
+ if ( !value.empty() )
+ int_value = convertToInt(value);
+ return YUI::widgetFactory()->createIntField( parent, label, min, max, int_value );
+ }
+ else if ( type == "password" )
+ {
+ return YUI::widgetFactory()->createInputField( parent, label, true );
+ }
+ else
+ {
+ if ( multiline )
+ {
+ YMultiLineEdit *edit = YUI::widgetFactory()->createMultiLineEdit( parent, label );
+ if ( ! value.empty() )
+ edit->setValue( value );
+ return edit;
+ }
+
+ return YUI::widgetFactory()->createInputField( parent, label, false );
+ }
+
+ return 0L;
+}
+
+/**
+ * parses a YImage from XUL
+ * <image src="start.png"/>
+ */
+static YWidget *
+parseImage( YWidget *parent, DOMElement *root )
+{
+ string imageFileName;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "src" )
+ imageFileName = root->getAttribute(*i);
+ }
+
+ YImage *image = YUI::widgetFactory()->createImage( parent, imageFileName, false);
+ return image;
+}
+
+
+/**
+ * parses a YPushCheckBox from XUL
+ * <checkbox>
+ */
+static YWidget *
+parseCheckbox( YWidget *parent, DOMElement *root )
+{
+ bool checked = false;
+ string label;
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "checked" )
+ checked = ( root->getAttribute(*i) == "true" );
+ if ( *i == "label" )
+ label = root->getAttribute(*i);
+ }
+
+ YCheckBox *checkbox = YUI::widgetFactory()->createCheckBox( parent, label, checked );
+ return checkbox;
+}
+
+/**
+ * parses a YPushButton from XUL
+ * <button>
+ */
+static YWidget *
+parsePushButton( YWidget *parent, DOMElement *root )
+{
+ string label;
+ string iconname;
+
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "label" )
+ label = root->getAttribute(*i);
+ }
+
+ YPushButton *button = YUI::widgetFactory()->createPushButton( parent, label );
+ return button;
+}
+
+/**
+ * parses a YLayoutBox from XUL
+ * <hbox>
+ */
+static YWidget *
+parseHBox( YWidget *parent, DOMElement *root )
+{
+ YLayoutBox *hbox = YUI::widgetFactory()->createHBox(parent);
+
+ parseChildren( hbox, root );
+
+ return hbox;
+}
+
+/**
+ * parses a YLayoutBox from XUL
+ * <vbox>
+ */
+static YWidget *
+parseVBox( YWidget *parent, DOMElement *root )
+{
+ YLayoutBox *vbox = YUI::widgetFactory()->createVBox(parent);
+
+ parseChildren( vbox, root );
+
+ return vbox;
+}
+
+/**
+ * parses a YDialog from XUL
+ * <window>
+ */
+static YWidget *
+parseDialog( YWidget *parent, DOMElement *root )
+{
+ YDialog *dialog = YUI::widgetFactory()->createPopupDialog();
+
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ //if ( *i == "orient" )
+ // orient = root->getAttribute(*i);
+ }
+
+ parseChildren( dialog, root );
+
+ return dialog;
+}
+
+/**
+ * iterates over all children and parses them
+ */
+static void
+parseChildren( YWidget *parent, DOMElement *root )
+{
+ DOMElements els;
+ DOMElements::iterator i;
+
+ if (root->hasChilds())
+ {
+ els = root->getChilds();
+ for(i = els.begin(); i != els.end(); i++)
+ {
+ parseNode( parent, *i );
+ }
+ }
+}
+
+/**
+ * Find out which parser function to call
+ * given the element
+ *
+ * also sets the widget basic properties
+ * like id.
+ */
+static YWidget *
+parseNode( YWidget *parent, DOMElement *root )
+{
+ string name = root->getElementName();
+ YWidget *w = 0L;
+
+ if ( namecmp( name, "dialog" ) )
+ w = parseDialog( parent, root );
+ else if ( namecmp( name, YUIWidget_CheckBox ) )
+ w = parseCheckbox( parent, root );
+ else if ( namecmp( name, YUIWidget_ComboBox ) )
+ w = parseComboBox( parent, root );
+ else if ( namecmp( name, YUIWidget_HBox ) )
+ w = parseHBox( parent, root );
+ else if ( namecmp( name, YUIWidget_Label ) )
+ w = parseLabel( parent, root );
+ else if ( namecmp( name, YUIWidget_ProgressBar ) )
+ w = parseProgressBar( parent, root );
+ else if ( namecmp( name, YUIWidget_PushButton ) )
+ w = parsePushButton( parent, root );
+ else if ( namecmp( name, YUIWidget_SelectionBox ) )
+ w = parseSelectionBox( parent, root );
+ else if ( namecmp( name, YUIWidget_MultiSelectionBox ) )
+ w = parseMultiSelectionBox( parent, root );
+ else if ( namecmp( name, YUIWidget_RadioButton ) )
+ w = parseRadioButton( parent, root );
+ else if ( namecmp( name, YUIWidget_RadioButtonGroup ) )
+ w = parseRadioButtonGroup( parent, root );
+ else if ( namecmp( name, YUIWidget_Frame ) )
+ w = parseFrame( parent, root );
+ else if ( name == "textbox" )
+ w = parseTextbox( parent, root );
+ else if ( name == "image" )
+ w = parseImage( parent, root );
+ else if ( namecmp( name, YUIWidget_VBox ) )
+ w = parseVBox( parent, root );
+
+ if ( ! w )
+ {
+ yuiError() << "widget `" << name << "' not supported" << endl;
+// YUI_THROW(YUIException("widget '" + name + "' not supported"));
+ }
+ else
+ {
+
+ // set the id of the widget
+ DOMStringList list = root->getAttributeList();
+ DOMStringList::iterator i;
+ for (i = list.begin(); i != list.end(); i++)
+ {
+ if ( *i == "id" )
+ w->setId( new StringWidgetID(root->getAttribute(*i)) );
+ }
+ }
+
+ return w;
+}
+
+
+YDialog *
+YUIXMLReader::readDialogFromFile( const string &filename )
+{
+ FILE * pFile;
+ long lSize;
+ char * buffer;
+ size_t result;
+
+ pFile = fopen ( filename.c_str() , "rb" );
+ if (pFile==NULL)
+ YUI_THROW(YUIException("File error"));
+
+ // obtain file size:
+ fseek (pFile , 0 , SEEK_END);
+ lSize = ftell (pFile);
+ rewind (pFile);
+
+ // allocate memory to contain the whole file:
+ buffer = (char*) malloc (sizeof(char)*lSize);
+ if (buffer == NULL)
+ YUI_THROW(YUIException("Memory error"));
+
+ // copy the file into the buffer:
+ result = fread (buffer,1,lSize,pFile);
+ if (result != (size_t) lSize)
+ YUI_THROW(YUIException("Reading error"));
+
+ /* the whole file is now loaded in the memory buffer. */
+
+ DOMElement* root;
+ root = DOMElement::loadXML(buffer);
+ if (root == NULL)
+ {
+
+ YUI_THROW(YUIException("Failed to parse dialog from xml file" + DOMElement::getLastError()));
+
+ }
+ else
+ {
+ yuiMilestone() << filename << " xml parsed correctly" << endl;
+ YWidget *w = parseNode( 0L, root );
+
+ YDialog *dialog = dynamic_cast(w);
+ if ( ! dialog )
+ {
+ YUI_THROW(YUINoDialogException());
+ }
+ yuiMilestone() << "built dialog from " << filename << " correctly" << endl;
+ delete root;
+ return dialog;
+ }
+
+ // terminate
+ fclose (pFile);
+ free (buffer);
+
+ return 0L;
+}
Added: branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.h?rev=49530&view=auto
==============================================================================
--- branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.h (added)
+++ branches/tmp/dmacvicar/yast-xmlui/libyui/src/YUIXMLReader.h Wed Jul 30 18:39:03 2008
@@ -0,0 +1,30 @@
+
+#ifndef YUIXMLReader_h
+#define YUIXMLReader_h
+
+#include <string>
+
+class YDialog;
+
+/**
+ * Build YUI dialogs from XUL (http://www.mozilla.org/projects/xul/)
+ * descriptions.
+ *
+ *
+ */
+class YUIXMLReader
+{
+ public:
+ /**
+ * Reads a YUI dialog from a XUL file
+ *
+ * 'filename' : the .xul file to read
+ *
+ * throws YUINoDialogException if the file does not
+ * contain a dialog.
+ */
+ static YDialog * readDialogFromFile( const std::string &filename );
+};
+
+
+#endif
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org