コード例 #1
0
    bool startElement(const QString &namespaceURI,
                      const QString &localName,
                      const QString &qName,
                      const QXmlAttributes &attributes)
    {
        // add to elements stack:
        m_elementStack.append(new ElementData(qName.utf8()));

        // First we need a node.
        if (DBUS("node"))
        {
            CONDITION(!m_currentNode.isEmpty(), "Node inside a node.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QCString("Anonymous node found."));

            m_currentNode = attributes.value(idx).utf8();
            // A node is actually of little interest, so do nothing here.
            return true;
        }

        // Then we need an interface.
        if (DBUS("interface"))
        {
            // We need a nodeName for interfaces:
            CONDITION(m_currentNode.isEmpty(), "Interface without a node.");
            CONDITION(m_currentInterface, "Interface within another interface.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Interface without a name found."));

            // A interface is roughly equivalent to a class:
            m_currentInterface = createEntry();

            m_currentInterface->section = Entry::CLASS_SEC;
            m_currentInterface->spec |= Entry::Interface;
            m_currentInterface->type = "Interface";
            m_currentInterface->name = substitute(attributes.value(idx).utf8(), ".", "::");

            openScopes(m_currentInterface);

            return true;
        }

        if (DBUS("method") || DBUS("signal"))
        {
            // We need a interfaceName for methods and signals:
            CONDITION(!m_currentInterface, "Method or signal found outside a interface.");
            CONDITION(m_currentMethod, "Method or signal found inside another method or signal.");
            CONDITION(m_currentProperty, "Methor or signal found inside a property.");
            CONDITION(!m_structStack.isEmpty(), "Method or signal found inside a struct.");
            CONDITION(m_currentEnum, "Methor or signal found inside a enum.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Method or signal without a name found."));

            m_currentMethod = createEntry();

            m_currentMethod->section = Entry::FUNCTION_SEC;
            m_currentMethod->name = attributes.value(idx).utf8();
            m_currentMethod->mtype = Method;
            m_currentMethod->type = "void";

            if (DBUS("signal"))
            { m_currentMethod->mtype = Signal; }
        }

        if (DBUS("arg"))
        {
            // We need a method for arguments:
            CONDITION(!m_currentMethod, "Argument found outside a method or signal.");
            CONDITION(m_currentArgument, "Argument found inside another argument.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Argument without a name found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Argument without a type found."));

            const int direction_idx(indexOf(attributes, "direction"));

            if ((m_currentMethod->mtype == Signal &&
                 direction_idx >= 0 &&
                 attributes.value(direction_idx) != "in") ||
                (m_currentMethod->mtype == Method &&
                 direction_idx >= 0 &&
                 attributes.value(direction_idx) != "in" &&
                 attributes.value(direction_idx) != "out"))
            {
                m_errorString = "Invalid direction found.";
                return false;
            }

            m_currentArgument = new Argument;
            m_currentArgument->type = getType(attributes).utf8();
            m_currentArgument->name = attributes.value(name_idx).utf8();
            if (direction_idx >= 0)
            { m_currentArgument->attrib = attributes.value(direction_idx).utf8(); }
            else
            {
                if (m_currentMethod->mtype == Signal)
                { m_currentArgument->attrib = "in"; }
                else
                { m_currentArgument->attrib = "out"; }
            }
        }

        if (DBUS("property"))
        {
            CONDITION(m_currentMethod, "Property found inside a method or signal.");
            CONDITION(!m_currentInterface, "Property found outside an interface.");
            CONDITION(m_currentProperty, "Property found inside another property.");
            CONDITION(!m_structStack.isEmpty(), "Property found inside a struct.");
            CONDITION(m_currentEnum, "Property found inside a enum.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous property found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Property without a type found."));

            const int access_idx(indexOf(attributes, "access"));
            COND_DOC_ERROR(access_idx < 0, QString("Property without a access attribute found."));
            COND_DOC_ERROR(attributes.value(access_idx) != "read" &&
                           attributes.value(access_idx) != "write" &&
                           attributes.value(access_idx) != "readwrite",
                           QString("Property with invalid access attribute \"%1\" found.").
                           arg(attributes.value(access_idx)));

            m_currentProperty = createEntry();

            m_currentProperty->section = Entry::FUNCTION_SEC;

            if (attributes.value(access_idx) == "read" ||
                attributes.value(access_idx) == "readwrite")
            { m_currentProperty->spec |= Entry::Readable; }

            if (attributes.value(access_idx) == "write" ||
                attributes.value(access_idx) == "readwrite")
            { m_currentProperty->spec |= Entry::Writable; }

            m_currentProperty->name = attributes.value(name_idx).utf8();
            m_currentProperty->mtype = Property;
            m_currentProperty->type = getType(attributes).utf8();
        }

        if (EXTENSION("namespace"))
        {
            CONDITION(m_currentNode.isEmpty(), "Namespace found outside a node.");
            CONDITION(m_currentInterface, "Namespace found inside an interface.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Anonymous namespace found."));

            m_namespaceStack.append(openNamespace(attributes.value(idx)));
            openScopes(m_namespaceStack.last());
        }

        if (EXTENSION("struct"))
        {
            CONDITION(m_currentMethod, "Struct found inside a method or signal.");
            CONDITION(m_currentProperty, "Struct found inside a property.");
            CONDITION(m_currentEnum, "Struct found inside an enum.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Anonymous struct found."));

            Entry * current_struct = createEntry();
            current_struct->section = Entry::CLASS_SEC;
            current_struct->spec = Entry::Struct;
            current_struct->name = attributes.value(idx).utf8();

            openScopes(current_struct);

            current_struct->type = current_struct->name + " struct";

            m_structStack.append(new StructData(current_struct));
        }

        if (EXTENSION("member"))
        {
            CONDITION(m_structStack.isEmpty(), "Member found outside of struct.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous member found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Member without a type found."));

            createEntry();

            m_currentEntry->section = Entry::VARIABLE_SEC;
            m_currentEntry->name = attributes.value(name_idx).utf8();
            m_currentEntry->type = getType(attributes).utf8();

            QString type(getDBusType(m_currentEntry->type));
            m_structStack.last()->type.append(type.utf8());
        }

        if (EXTENSION("enum") || EXTENSION("flagset"))
        {
            CONDITION(m_currentMethod, "Enum found inside a method or signal.");
            CONDITION(m_currentProperty, "Enum found inside a property.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous enum found."));

            const int type_idx(indexOf(attributes, "type"));
            QString type = "u";
            if (type_idx >= 0)
            { type = attributes.value(type_idx); }
            if (type != "y" && type != "q" && type != "u" && type != "t")
            { DOC_ERROR(QString("Invalid enum type \"%1\" found.").arg(type)); }

            m_currentEnum = createEntry();
            m_currentEnum->section = Entry::ENUM_SEC;
            m_currentEnum->name = attributes.value(name_idx).utf8();

            openScopes(m_currentEnum);

            m_currentEnum->type = m_currentEntry->name + " enum";

            addNamedType(type.utf8());
        }

        if (EXTENSION("value"))
        {
            CONDITION(!m_currentEnum, "Value found outside an enum.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous value found."));

            const int value_idx(indexOf(attributes, "value"));

            createEntry();

            m_currentEntry->section = Entry::VARIABLE_SEC;
            m_currentEntry->name = attributes.value(name_idx).utf8();
            m_currentEntry->type = m_currentEnum->name; // "@"; // enum marker!
            if (value_idx >= 0)
            { m_currentEntry->initializer = attributes.value(value_idx).utf8(); }
        }

        return true;
    }
コード例 #2
0
    bool endElement(const QString &namespaceURI,
                    const QString &localName,
                    const QString &qName)
    {
        // Clean up elements stack:
        // Since we made sure to get the elements in the proper order when
        // adding we do not need to do so again here.
        COND_DOC_ERROR(m_elementStack.last()->element != qName.utf8(),
                       QString("Malformed XML: Unexpected closing element found.").
                       arg(m_elementStack.last()->element).utf8());
        m_elementStack.removeLast();

        // Interface:
        if (DBUS("interface"))
        {
            CONDITION(!m_currentInterface, "end of interface found without start.");
            m_currentInterface->endBodyLine = lineNumber();
            closeScopes();
            m_currentInterface = 0;
        }

        if (DBUS("method") || DBUS("signal"))
        {
            CONDITION(!m_currentMethod, "end of method found without start.");
            CONDITION(!m_currentInterface, "end of method found outside interface.");
            m_currentMethod->endBodyLine = lineNumber();
            m_currentInterface->addSubEntry(m_currentMethod);
            m_currentMethod = 0;
        }

        if (DBUS("property"))
        {
            CONDITION(!m_currentProperty, "end of property found without start.");
            CONDITION(!m_currentInterface, "end of property found outside interface.");
            m_currentProperty->endBodyLine = lineNumber();
            m_currentInterface->addSubEntry(m_currentProperty);
            m_currentProperty = 0;
        }

        if (DBUS("arg"))
        {
            CONDITION(!m_currentMethod, "end of arg found outside method.");
            m_currentMethod->argList->append(m_currentArgument);
            m_currentArgument = 0;
        }

        if (EXTENSION("namespace"))
        {
            Entry * current = m_namespaceStack.last();
            CONDITION(!current, "end of namespace without start.");
            m_namespaceStack.removeLast();

            current->endBodyLine = lineNumber();
            closeScopes();
        }

        if (EXTENSION("struct"))
        {
            StructData * data = m_structStack.last();
            CONDITION(!data, "end of struct without start.");

            data->entry->endBodyLine = lineNumber();

            QString current_type;
            current_type.append(QString("("));
            current_type.append(data->type);
            current_type.append(QString(")"));

            addNamedType(current_type.utf8());

            closeScopes();

            m_structStack.removeLast();
        }

        if (EXTENSION("member"))
        {
           StructData * data = m_structStack.last();
           CONDITION(!data, "end of member outside struct.");
           data->entry->addSubEntry(m_currentEntry);
        }

        if (EXTENSION("enum") || EXTENSION("flagset"))
        {
            CONDITION(!m_currentEnum, "end of enum without start.");
            m_currentEnum->endBodyLine = lineNumber();
            closeScopes();

            m_currentEnum = 0;
        }

        if (EXTENSION("value"))
        {
            CONDITION(!m_currentEntry, "end of value without start");
            m_currentEntry->endBodyLine = lineNumber();

            m_currentEnum->addSubEntry(m_currentEntry);
        }

        return true;
    }
コード例 #3
0
static void
caja_file_management_properties_dialog_setup_extension_page (GtkBuilder *builder)
{
    GtkCellRendererToggle *toggle;
    GtkListStore *store;
    GtkTreeView *view;
    GtkTreeSelection *selection;
    GtkTreeIter iter;
    GtkIconTheme *icon_theme;
    GdkPixbuf *ext_pixbuf_icon;
    GtkButton *about_button;
    gchar *ext_text_info;
    
    GList *extensions;
    int i;

    extensions = caja_extensions_get_list ();

    view = GTK_TREE_VIEW (
                    gtk_builder_get_object (builder, "extension_view"));
    store = GTK_LIST_STORE (
                    gtk_builder_get_object (builder, "extension_store"));
                    
    toggle = GTK_CELL_RENDERER_TOGGLE (
                    gtk_builder_get_object (builder, "extension_toggle"));
    g_object_set (toggle, "xpad", 6, NULL);
                    
    g_signal_connect (toggle, "toggled",
                      G_CALLBACK (extension_state_toggled), view);
    
    icon_theme = gtk_icon_theme_get_default();
    
    for (i = 0; i < g_list_length (extensions); i++)
    {
        Extension* ext = EXTENSION (g_list_nth_data (extensions, i));

        if (ext->icon != NULL)
        {
            ext_pixbuf_icon = gtk_icon_theme_load_icon (icon_theme, ext->icon,
                                                        24,
                                                        GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
        }
        else
        {
            ext_pixbuf_icon = gtk_icon_theme_load_icon (icon_theme, "system-run",
                                                        24,
                                                        GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
        }

        if (ext->description != NULL)
        {
            ext_text_info = g_markup_printf_escaped ("<b>%s</b>\n%s",
                                                     ext->name ? ext->name : ext->filename,
                                                     ext->description);
        }
        else
        {
            ext_text_info = g_markup_printf_escaped ("<b>%s</b>",
                                                     ext->name ? ext->name : ext->filename);
        }

        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter,
                            EXT_STATE_COLUMN, ext->state,
                            EXT_ICON_COLUMN, ext_pixbuf_icon, 
                            EXT_INFO_COLUMN, ext_text_info,
                            EXT_STRUCT_COLUMN, ext, -1);

        g_free (ext_text_info);
        if (ext_pixbuf_icon)
            g_object_unref (ext_pixbuf_icon);
    }

    about_button = GTK_BUTTON (gtk_builder_get_object (builder, "about_extension_button"));
    selection = gtk_tree_view_get_selection (view);
    gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
    g_signal_connect (selection, "changed",
                      G_CALLBACK (extension_list_selection_changed),
                      about_button);
}