Today we will be engaged in the preparation of the plugin for qutIM, but not for the one that was recently released, but for the future, which is being actively developed now.
First I would like to say a few general words:
- In sdk03, we tried to take into account all the "mistakes of stormy youth"
- It is completely incompatible with the old skd02
- Most likely, there will not be more such abrupt API transitions between versions.
And that is why I recommend to anyone who has never written plug-ins for Kutima to orient themselves on sdk03
I want to note the important fact that now the development is carried out with the use of Qt 4.6, it provides huge additional features that are simply a sin to refuse.
If you are eager to realize something interesting, but do not know where to direct your energy, then this article is for you!
In the summer, we came to the conclusion that the current implementation of the plug-in system brought the program to a standstill:
It became very hard to increase the functionality, the program has long ceased to be lightweight and on weak machines, when loading a long contact sheet, it slowed down. It took a lot of time to fix bugs.
Therefore, the development of libqutim began, in which we tried to take into account all the mistakes of the old plug-in system, and to make the development of Kutima as simple and pleasant as possible.
The structure of the new qutIM:
- Microkernel - it contains the implementation of the module manager. It is responsible for loading and correct operation of all parts of qutIM. It has a choice of which modules to load and which not. Plus, it has the ability to track dependencies, which can be indispensable for modules that rely on other components in their work. In addition, active modules can be switched directly in runtime, which, for example, is actively used in configbackend
- libqutim - this library stores the interfaces of all modules, as well as a set of the most useful and frequently used functions
- corelayers - the set of modules that is compiled directly with the application, if desired, it can be easily changed, as will be discussed below
- plugins - traditional shared libraries that are currently easiest to place in the plugins folder next to the executable file, best suited for protocols
The first step is to install the Qt4.6 library, for Windows and Macos X they are on the
official site .
Ubunt users can use the kubuntu-experimental repository, you can add it with the command:
$ add-apt-repository ppa: kubuntu-experimental
Gentushnikami enough unmask the corresponding ebuild'y. For the rest, it will not be difficult to find the necessary packages or assemble them yourself.
The source code is taken from here:
www.qutim.org/svn/qutim/branches/sdk03After as usual we command in the terminal
$ mkdir build && cd build && cmake ..
As a result, cmake will create a Makefile for you, if it turns out that not all dependencies for the build are satisfied, then install the missing packages.
Please pay attention to the lines of the type
+ layer KINETICPOPUPS added to build
+ layer XSETTINGSDIALOG added to build
+ layer ADIUMCHAT added to build
To date, in the cmake script, autodetection of the layers used is implemented. You just need to put the source code of your plug-in in scr / corelayers / name_layer, so that it is recognized by the system. This opens up huge prospects for creating your own builds, and simplifies development.
In this article I will describe how to implement the settings dialog:
Create a subdirectory simplesettingsdialog in the src / corelayers directory.
Create a settingslayerimpl class and inherit it from libqutim's SettingsLayer class, as shown below:
settingslayeriml.h#include "libqutim/settingslayer.h"
class SettingsDialog;
using namespace qutim_sdk_0_3;
class SettingsLayerImpl : public SettingsLayer
{
Q_OBJECT
public :
SettingsLayerImpl();
virtual ~SettingsLayerImpl();
virtual void close();
virtual void show ( const SettingsItemList& settings );
private :
QPointer<SettingsDialog> m_dialog;
};
* This source code was highlighted with Source Code Highlighter .
settingslayeriml.cppAttention: if you compile the module directly into a binary file, then you need to include the header files as shown in the example. If you bring it into a plugin, then you need to
<libqutim/>
replace it with
<qutim/>
The operation of the layer is very simple: upon a show request, a list of settings that must be displayed is transmitted.
settingslayeriml.cpp#include "settingslayerimpl.h"
#include "settingsdialog.h"
#include "modulemanagerimpl.h"
#include <libqutim/icon.h>
static Core::CoreModuleHelper<SettingsLayerImpl> settings_layer_static( // ,
QT_TRANSLATE_NOOP( "Plugin" , "Simple Settings dialog" ), //, QT_TRANSLATE_NOOP
QT_TRANSLATE_NOOP( "Plugin" , "SDK03 example" )
);
void SettingsLayerImpl::show ( const SettingsItemList& settings )
{
if (m_dialog.isNull())
m_dialog = new SettingsDialog(settings); // ,
m_dialog->show();
}
* This source code was highlighted with Source Code Highlighter .
There is nothing tricky in the implementation of the settings dialog either, it is only important to remember that the SettingsItem only generates a settings widget on demand to minimize memory costs.
Next, create the dialog itself:
settingsdialog.cpp')
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include <libqutim/settingswidget.h>
SettingsDialog::SettingsDialog ( const qutim_sdk_0_3::SettingsItemList& settings)
: ui ( new Ui::SettingsDialog)
{
m_setting_list = settings;
ui->setupUi( this );
foreach (SettingsItem *settings_item, m_setting_list) //
{
QListWidgetItem *list_item = new QListWidgetItem (settings_item->icon(),
settings_item->text(),
ui->listWidget
);
}
connect(ui->listWidget,SIGNAL(currentRowChanged( int )),SLOT(currentRowChanged( int ))); //
ui->listWidget->setCurrentRow(0);
}
void SettingsDialog::currentRowChanged ( int index)
{
SettingsWidget *widget = m_setting_list.at(index)->widget(); // ,
if (widget == 0)
return ;
if (ui->stackedWidget->indexOf(widget) == -1) // ,
{
widget->load();
ui->stackedWidget->addWidget(widget);
}
ui->stackedWidget->setCurrentWidget(widget); //
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
* This source code was highlighted with Source Code Highlighter .
After adding files, do not forget to run the command again:
$ cmake ..
If the line below appears in the output, then you did everything right.
+ layer SIMPLESETTINGSDIALOG added to build
Now you need to add a call to the Settings: showWidget () function somewhere, I usually add it to the constructor of one of the layers.
When everything is ready, you can run the application. Eventually there will be such a pretty window.

I hope you made sure that writing plugins is now quite simple. As you can see, the settings are not yet thick, so go for it, fill in the gaps, and the best plug-ins will fall into the core!
I hope that this is not the last article about the development of the new Kutim, in the future I plan to talk about the work of the settings engine, how convenient the json format is for storing them, and about many other things.
Thank you all for your attention, the
source code can be downloaded here.