Saturday, 24 January 2015

Injeqt 1.0.0

There is not much to say. I'm working with Injeqt (Qt dependency injection library) for some time now, preparing to release Kadu 2.0, and I've not encountered any problems at all. It is great to have only one feature and have full tests coverage for it. So here it is, 1.0.0 release!

I really enjoy using this small library, but I've also learned that I wish it have some more features:

Subinjectors

I would like to use main Kadu injector in plugins code in a normal way. I would like to have a class with following header file and setters invoked by injector:

class ChatNotifier : public Notifier
{
  Q_OBJECT
private slots:
  ...
  INJEQT_SETTER void setChatWidgetRepository(
    ChatWidgetRepository *chatWidgetRepository);
  INJEQT_SETTER void setFormattedStringFactory(
    FormattedStringFactory *formattedStringFactory);
};

auto plugin_injector = injeqt::injector(
  plugin_modules, main_injector);
auto notifier = plugin_injector.get<ChatNotifier>();

Currently it is not possible - list of classes supported by injector is immutable and set on injector creation. And class ChatNotifier need to be added later, as it is in dynamically loaded plugin. So this code must be used:

class ChatNotifier : public Notifier
{
  Q_OBJECT
public:
  ...
  void setChatWidgetRepository(
    ChatWidgetRepository *chatWidgetRepository);
  void setFormattedStringFactory(
    FormattedStringFactory *formattedStringFactory);
};

auto notifier = new ChatNotifier{this};
notifier->setChatWidgetRepository(injector
  .get<ChatWidgetRepository>());
notifier->setFormattedStringFactory(injector
  .get<FormattedStringFactory>()));

Subinjectors will solve this problem. Injectors will be able to have a parent injector and known all of its objects so it will be able to use them in an easy way.

As this is the feature that I miss most, it will be included in Injeqt 1.1 that will be released just before Kadu 3.0 (hopefully in about 3 or 4 months).

Autoconnections

Injeqt should have an option to recognize matching signals and slots in objects that it creates and connect them automatically. I'm not 100% about the semantics of it (should it create objects just to connect to them even if application does not use them yet or should it wait for application to ask for an object to create it and connect). This is much more complicated to implement than subinjectors, so it is postponed to some next release.

Wednesday, 7 January 2015

QtSingleApplication replacement for Qt5

Kadu uses QtSingleApplication to ensure that only one instance can run on one profile at a time.

Unfortunately this solution is not compatible with Qt 5, so I've decided to update it a bit. My solution is available at gitorious. It uses code from Nokia solution, so I hope I got the licencing and copyright right (it is LGPL - one of the licences from Nokia's original files).

It has different interface from original one - 3 lambdas are accepted as constructor parameters. One for running first instance, one for running second and one for accepting messages. Not very Qt-ish but possibly less error prone.