Communi strives for full QML support. The property-based APIs have been designed QML compatibility in mind. Almost all the types can be registered to QML and used as is.
A ready-made QML plugin is also provided for convenience. The plugin does QML type registration and is made available via the following import:
The following snippet illustrates how the Communi QML plugin does the type registration. The same can be done manually in application code to avoid the need of deploying the Communi QML plugin.
In order to connect to IRC in QML, declare an IrcConnection instance, set the desired properties, and call connection.open().
Even though the IrcCommand::createXxx() methods are static, QML does not provide a way to call them without an IrcCommand instance. Thus, in order to create and send commands, declare an instance of IrcCommand, call any createXxx() method to create a command, and finally send it via IrcCommand::sendCommand().
In order to keep track of channels and queries, declare an instance of IrcBufferModel. Notice that it can be used directly as a data model for QML types such as ListView and Repeater.
IrcBufferModel creates channel and query buffers automatically when the client joins channels and receives private messages, respectively.
A typical IRC client has a special server buffer for messages that are not targeted to any specific channel or query. This can be easily achieved by declaring an instance of IrcBuffer and forwarding the messages ignored by IrcBufferModel to it.
In order to keep track of channel users, create an instance of IrcUserModel. It can be also used directly as a data model for QML types such as ListView and Repeater.
IrcCommandParser helps with parsing commands from user input. In order to take it in use, declare an instance of IrcCommandParser and introduce the desired commands.
Notice that commands are often context sensitive. While some command may accept an optional parameter that is filled up with the current target (channel/query) name when absent, another command may always inject the current target name as a certain parameter. Therefore IrcCommandParser must be kept up-to-date with the current target and the list of channels.