/*!
 * A helper method to ensure that a settings binary object is uptodate.
 * The "uptodateness" is determined by the \a settingsBinaryUptodate parameter.
 * If the binary needs updating, it is updated by reading the settings file determined
 * by the \a settingsFileName parameter.
 * \param settingsBinaryUptodate determines if the settings binary is uptodate or not.
 *        This parameter will be \c true after this method returns.
 * \param settingsBinaryObjectPointer a pointer to the pointer variable of the binary to be manipulated.
 * \param settingsFileName the file name of the settings file.
 */
static void ensureSettingsBinaryObjectUptodate(bool &settingsBinaryUptodate,
					       MSettingsLanguageBinary **settingsBinaryObjectPointer,
					       const QString &settingsFileName)
{
    if (!settingsBinaryUptodate) {
        // Delete any previous object
        delete *settingsBinaryObjectPointer;
        *settingsBinaryObjectPointer = NULL;

        // Convert the settings XML to a settings binary
        QFile xmlFile(settingsFileName);
        MSettingsLanguageParser parser;
        if (parser.readFrom(xmlFile)) {
            *settingsBinaryObjectPointer = parser.createSettingsBinary();
        }
        settingsBinaryUptodate = true;
    }
}
DcpDeclWidget::DcpDeclWidget(const QString& xmlPath)
{
    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(
                                      Qt::Vertical, this);

    QString filePath = xmlPath.startsWith('/') ? xmlPath
                                               : defaultPath + xmlPath;
    QFile file(filePath);
    if (!file.open(QIODevice::ReadOnly)) {
        createErrorLabel(
            QString("Cannot find applet xml file %1").arg(filePath)
            );
        return;
    }

    MSettingsLanguageParser parser;
    if (!parser.readFrom(file)) {
        createErrorLabel(QString("Error parsing the ui description %1")
                         .arg(filePath));
        return;
    }

    MSettingsLanguageBinary* binary = parser.createSettingsBinary();
    if (!binary) {
        createErrorLabel(QString("Error parsing the ui description %1")
                         .arg(filePath));
        return;
    }

    MDataStore* datastore = new DynamicGConfDataStore (this);

    MSettingsLanguageWidget* widget =
        MSettingsLanguageWidgetFactory::createWidget(*binary, datastore );
    dcp_failfunc_unless(widget);
    layout->addItem(widget);
}