📜 ⬆️ ⬇️

Development of plugins for qutIM from under Windows - quick start

The traditional way to start development was to siphon all the sources and compile them, and even from a quick comparison of the size of the instructions for Windows and Ubuntu, it is clear that this task is very complicated. Fortunately, the method appeared easier and faster.

For this we need the usual qutIM Windows installer, QtSDK, and cmake .
Step One - Installing QtSDK and cmake


There are no subtleties here, just put your desktop Qt (minGW) in the forehead and set cmake, the only thing you need in qtvars.cmd is to add the path to cmake to the PATH variable

Step two - install qutIM

')
It is best to place it not in Program Files, but in another folder, for example C: \ develop \ qutim \ dist. The installer contains all the necessary header files and object files needed for linking, and in the share / doc directory there is html documentation, more precisely even its sketch, the full API documentation does not exist yet.

Step three - create CMakeLists.txt for our plugin


The approximate view of CMakeLists.txt will be as follows:

cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
if( COMMAND cmake_policy )
cmake_policy( SET CMP0003 NEW )
endif(COMMAND cmake_policy )
project( Plugins )
set(QT_MIN_VERSION "4.6.0")

set(QUTIM_PATH "" CACHE FILEPATH "Path to qutim distro")
set(CMAKE_INSTALL_PREFIX ${QUTIM_PATH})

LIST (APPEND CMAKE_MODULE_PATH "cmake")
LIST (APPEND CMAKE_MODULE_PATH "${QUTIM_PATH}/share/cmake/Modules")
LIST (APPEND CMAKE_PREFIX_PATH "${QUTIM_PATH}")

INCLUDE (MacroEnsureVersion)
find_package(Qt4 COMPONENTS QtCore QtGui)
find_package(QutIM REQUIRED)

include_directories(include)
add_subdirectory(src)


In the src directory, you need to put CMakeLists.txt with a description of the plugin to be collected.
find_library( SIMPLECONTACTLIST_LIBRARIES simplecontactlist PATHS ${QUTIM_PATH}/lib )
message (${SIMPLECONTACTLIST_LIBRARIES})

qutim_add_plugin(simplecontactlistwidget
EXTENSION
EXTENSION_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/sevenwidget.h
EXTENSION_CLASS Core::SimpleContactList::SimpleWidget
DISPLAY_NAME "Seven"
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
DESCRIPTION "Windows seven specific implementation with button's in caption"
LINK_LIBRARIES ${SIMPLECONTACTLIST_LIBRARIES}
)


The plugin we create will link to simplecontactlist.a, so you need to tell cmake that we need to find it. The plugin is an extension, so you need to specify the name of the class that will be used as a description of the extension and specify the path to the header file. In the case, if instead of EXTENSION we create SUBPLUGIN, it will be necessary to create a class inheriting from qutim_sdk_0_3 :: Plugin and export it via QUTIM_EXPORT_PLUGIN. The easiest way to spy on the implementation in other plugins.

Step Four - Writing the Plugin


We will write a plugin that will draw buttons in our contact list header. I want to note that simplecontactlist is not part of the public API, so its header files are not in the installer, so we simply copy the files we need into include. But we must remember that the API can change at any time.

To create a contact form, you need to inherit from the AbstractContactListWidget interface and implement the AddButton methods, which will add buttons to the window title, RemoveButton, which will remove them. In addition, you will need to get a pointer to the contact model and the delegate to draw, all this can be viewed in the archive with the source code or downloaded via git from the labs turnips.
m_model = ServiceManager::getByName<AbstractContactModel*>( "ContactModel" );
Q_ASSERT(m_model);
m_view = new TreeView(m_model, this );
layout->addWidget(m_view);
m_view->setItemDelegate(ServiceManager::getByName<QAbstractItemDelegate*>( "ContactDelegate" ));


* This source code was highlighted with Source Code Highlighter .
m_model = ServiceManager::getByName<AbstractContactModel*>( "ContactModel" );
Q_ASSERT(m_model);
m_view = new TreeView(m_model, this );
layout->addWidget(m_view);
m_view->setItemDelegate(ServiceManager::getByName<QAbstractItemDelegate*>( "ContactDelegate" ));


* This source code was highlighted with Source Code Highlighter .
m_model = ServiceManager::getByName<AbstractContactModel*>( "ContactModel" );
Q_ASSERT(m_model);
m_view = new TreeView(m_model, this );
layout->addWidget(m_view);
m_view->setItemDelegate(ServiceManager::getByName<QAbstractItemDelegate*>( "ContactDelegate" ));


* This source code was highlighted with Source Code Highlighter .



Step Five - Build


Create next to the directory containing the very first CMakeLists.txt build directory, start the Qt command prompt, go to it and command something like this:

H:\develop\windows\labs\build>cmake ..\sevenlist -DCMAKE_BUILD_TYPE=Release -DQUTIM_PATH=H:\develop\qutim\dist -G"MinGW Makefiles"


The result should be something like this:
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: H:/apps/QtCreator/mingw/bin/gcc.exe
-- Check for working C compiler: H:/apps/QtCreator/mingw/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: H:/apps/QtCreator/mingw/bin/g++.exe
-- Check for working CXX compiler: H:/apps/QtCreator/mingw/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - not found.
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - found
-- Looking for Q_WS_QWS
-- Looking for Q_WS_QWS - not found.
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found.
-- Found Qt-Version 4.7.2 (using H:/apps/Qt/4.7.2/bin/qmake.exe)
-- Found QutIM: H:/develop/qutim/dist/lib/liblibqutim.dll.a
H:/develop/qutim/dist/lib/libsimplecontactlist.dll.a
-- Configuring done
-- Generating done
-- Build files have been written to: H:/develop/windows/labs/build


Now we can just make make install and run qutIM. Just do not try to execute this command when running katime. The source of the plugin can be taken on the guitar (sevenlists folder).

The result should be such a beauty.



What is most needed now:


All questions on the API ask our conference talks@conference.qutim.org.

Source: https://habr.com/ru/post/117181/


All Articles