Recursive lambda functions

Today i found out how to use lambda functions in a recursive manner. Documentation from std::function states:

Instances of std::function can store, copy, and invoke any callable target — functions, lambda expressions, bind expressions, or other function objects.

It can’t get easier than that!
So here’s an example taken from some code I had to do which uses lambda functions recursivly to delete contents on a device.

#include <functional>

void MtpDevice::deleteSelectedFiles()
{
    QStringList objectsToDelete;

    std::function<void(ContentObject*)> addChildren;
    addChildren = [&addChildren, &objectsToDelete] (ContentObject *obj) -> void {
        if (obj->type() == ContentObject::FOLDER) {
            for (ContentObject *child : obj->children()) {
                if (child->type() == ContentObject::FOLDER) {
                    addChildren(child);
                    objectsToDelete.append(child->id());
                } else {
                    if (!objectsToDelete.contains(child->id())) {
                        objectsToDelete.append(child->id());
                    }
                }
            }
        } else {
            objectsToDelete.append(obj->id());
        }
    };


    for (ContentObject *contentObj : d->contentObjects.values()) {
        if (contentObj->isSelected()) {
            addChildren(contentObj);
            objectsToDelete.append(contentObj->id());
        }
    }

    for (const QString &objId : objectsToDelete) {
        deleteContent(objId);
    }
}
Tagged ,

Error Loading Kernel Modules – aka “check your config files!!!1!1!!ONE”

This one’s a simple post to remind all of you out there to always check your
config/settings files and be sure you don’t add junk to them.

So, to my (solved) problem.

I started noticing one day, after a few kernel updates, that my laptop wasn’t
detecting acpi events anymore (battery, leds on keyboard, screen luminosity). I
immediatly blamed it on the kernel as I’ve already had similar problems like this in the past with my old Acer 5930g.

So I said to myself: “ok, let’s just wait for an update”.
Many updates passed and still I was having the same issues until tonight.
Bored, I decided to investigate the problem and get down to the bottom of it.

I started off with checking out all errors in the logs when I came across

Feb 2 22:32:09 localhost systemd-modules-load[159]: Failed to

insert ‘vboxguest’: No such device
Feb 2 22:32:09 localhost systemd-modules-load[159]: Failed to insert
‘vboxsf’: No such device
Feb 2 22:32:11 localhost [ 2.313395] systemd[1]: Failed to start Load Kernel
Modules.

Hmm, strange. I didn’t remember adding those there. A check on the file “/etc/modules-load.d/virtualbox.conf” showed that they were actually there, so I just simply removed them from the file leaving only the “vboxdrv” module to be loaded.

I rebooted, et voilà: problem solved!

So yeah, failing to load 1 kernel module make all others fail too.

Now my

systemctl status systemd-modules-load.service

ouputs:

systemd-modules-load.service – Load Kernel Modules
Loaded: loaded (/usr/lib/systemd/system/systemd-modules-load.service;
static)
Active: active (exited) since Sat 2013-02-02 23:10:21 CET; 3min 35s
ago
Docs: man:systemd-modules-load.service(8)
man:modules-load.d(5)
Process: 173 ExecStart=/usr/lib/systemd/systemd-modules-load
(code=exited, status=0/SUCCESS)

Hell yeah! \o/

Remember, DON’T ADD JUNK TO YOUR CONFIG FILES!!

Tagged , , , , ,

Multitouch fix for Alps touchpad

This summer I bought a new laptop, a Dell Vostro 3460. First thing I did was install arch linux.
Nothing wrong with it except one little annoying thing: multitouch was not correctly detected and the synaptics driver was not correctly loaded.
Luckily via the Arch linux forums a solution was found.

I’ll quote the procedure:

  • download latest alps source code from here (in case the page goes in 404 i have a stashed copy here)
  • unpack it and substitute the “alps.c” with this one (stashed version here)
  • copy the psmouse-alps-dst-0.x folder to your /usr/src directory
  • (as root) dkms add psmouse/alps-dst-0.x
  • (as root) dkms autoinstall
  • (as root) rmmod psmouse && modprobe psmouse

and multitouch should start working out of the box! Have fun!

(Thanks to user “post-factum” for the solution)

Tagged , , , , , , ,

Getting my swap back

Lately my pc was slowing down when using KDevelop and Chromium together and completely froze when I launched amarok as well.
Something was up but I couldn’t quite figure what it was. I kept on thinking that it was my laptop (an acer 5930g – yes, the one that still suffers from the acpi bug from kernel 2.3 2.6.3   ) until I noticed in my htop that my swap was 0/0MB.
Quite odd indeed..
I don’t know what caused it to be like that but in the end I solved the problem with
a few lines from my konsole.
Here’s the solution:


swapoff -a
mkswap /dev/your-swap-partition
swapon -a

et voilà! your swap partition will be restored! Plus, no more slow downs on my pc when developing! \o/

A little update

Hi folks!
Just wanted to give you lot a quick update on how things are going with KDE-Telepathy.
One word: GREAT!
Today I finished implementing the global presence setting for the presence applet and a patch is in review for the contactlist.
We’ve also decided to switch to haze msn instead of butterfly. The main reason for this change is that butterfly does not support the SASLChannel, which means it cannot use kwallet (plus it was a bit buggy).
As David said in his previous blog post we’ve also got a cool drag ‘n’ drop feature from the contact list to the kde-plasma desktop! \o/
We’ve entered the hard feature freeze and now we’ll be polishing things up.
So help us do a good job by testing our software and reporting bugs so that we can assure you a good user experience!

Tagged ,

Woshibon spot the difference

Hi all!
A quick post to let you guys have a bit of fun. Let’s play spot the difference!
Can you find the differences between these two photo’s shown below? They differ by a year.
The subjects to look for are: grundelborg, d_ed, drdanz, drf_ and andrunko. You should be able to spot them quite easily ;)

kde-tp sprint 1

kde-tp Woshibon sprint 2

Tagged , , ,

Woshibo (Telepathy sprint) audio call

My aim for the woshibo sprint (kde-telepathy sprint) is to get something going for audio/video calls in kde-telepathy.
The sprint started off well. We discussed a lot about how the project is to evolve and sorted out the problems we currently have

woshibo whiteboard

This afternoon I was depressed because I was having problems on my pc that NOBODY else was but in the end I managed to sort things out after bugging a Collabora guy and George K. (which I thank for not having killed
me for asking him 1.000.000 questions).
So in the end I managed to call George K on his n900 with my pc and listen to him speak :)
So that’s a +1 for kde-tp!

Just to let you guys know what’s currently going on:

mck182 – currently working on the “now playing” plugin
shocklaterboy92 – currently working on a new plugin system for kde-tp-chat
domme – telepathy kde logging
d_ed – furious bug fixing and kwallet integration
drdanz – auth handler + file transfer awesomeness
gkiaga – mental farsight fixing
grundelborg & drf – talking about stuff out of my league that I can’t comprehend. So it’s gonna be awesome ;)
me – telepathy-kde-call-ui

So as you see, we’re all quite busy here.
Stay tuned for more news on the Woshibo sprint!

Tagged , , , ,

Telepathy Contact Applet Goes Public!

Yay!
As promised, I bring you KDE-Telepathy-Contacts!
The KDE sysadmins have kindly accepted my kde repo request and now my plasmoid is in the Telepathy playground.

Before I release version 0.1 I need to wait for reviewboard to be set up and do some final checks on my code with the help of my kde-telepathy colleagues.

If you can’t wait for the release (should be in just a few daysthis will be discussed at our sprint) you can checkout the git repo git clone http://anongit.kde.org/telepathy-contact-applet and build from source.

Have fun! :)

Tagged , , , ,

I bring you KDE-Telepathy contacts!

Hello all!
Cool thing happened today, I finished the Contact plasmoid for KDE-Telepathy! Yaaaaay!
This plasmoid is a simple 128×128 plasmoid that sits on your desktop and let’s you keep your favorite contact (or contacts if you have many friends) always at hand.
The contact presence status is displayed by a coloured frame on the outside. If you click on the plasmoid you’ll get a drop down menu with the possible/available actions you can use with that contact according
to your kde-telepathy capabilities and the ones of the selected contact.
I started off using the ktelepathy library nepomuk model for this plasmoid but ran into some problems halfway through so I had to fallback to the telepathy model (model we use in our contactlist component).
But no worries, we kde-telepathy devs have a sprint coming soon (September) where we will discuss problems and the future of the project and solve annoying issues.
I really believe in the integration of KDE apps data into nepomuk so don’t worry, we’ll get there.
Until my plasmoid goes public you can take a look at this nice video I hope you all will appreciate.

Enjoy!

Tagged , , ,

How to: Nepomuk QML plugin

Hello all!

Today I’ll be talking about something useful (apparently) for all those wanting to use
data stored in Nepomuk via a QML plasmoid.

So, let’s start!

First of all you need a C++ class able to extract info from nepomuk and store it in a class (don’t ask me how to do that. It’s black magic for me at the moment).
In our case (KDE-Telepathy) we have contacts stored in nepomuk and the info we need are the usual im infos one would want to know about a contact: mail, nickname, online presence, presence message and all that kind of stuff.

So, once you’ve got this sorted out it’s time to create your “QML export plugin” or whatever you want to call it.

Your plugin class will have to inherit “QDeclarativeExtensionPlugin”.
Here is a header file so you can see what’s to be done (taken from my plugin in the ktelepathy library)

declarativeplugins.h

#include

/**
* @class DeclarativePlugins
* @brief Class to enable access via QML
* This class permits QML plasmoids to access data stored by the library
* @author Francesco Nwokeka
*/

class DeclarativePlugins : public QDeclarativeExtensionPlugin
{
Q_OBJECT

public:
void registerTypes(const char *uri);
};

Q_EXPORT_PLUGIN2(declarativeplugins, DeclarativePlugins)

The QDeclarativeExtensionPlugin::registerTypes is a virtual funtion so it’s to be re-implemented.
“What is that function supposed to do?” you’re probably thinking.

Well as documentation says:

“Registers the QML types in the given uri. Subclasses should implement this to call qmlRegisterType() for all types which are provided by the extension plugin. The uri is an identifier for the plugin generated by the QML engine based on the name and path of the extension’s plugin library.”

so, let’s see how we’re supposed to re-implement this function.

declarativeplugins.cpp

#include "declarativeplugins.h"
#include "everyone-person-set-model.h"

#include

void DeclarativePlugins::registerTypes(const char* uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.telepathy.declarative"));

qmlRegisterType(uri, 0, 1, "ContactListModel");
}

#include "declarativeplugins.moc"

As you can see, the “uri” (identifier for the plugin) is the string to be used in your qml file to actually “import” the QML plugin.

Once you’ve defined how you want to import your plugin, you’ll have to define the C++ type in the QML system so that you can access it via import that in this case will be something like this:


import org.kde.telepathy.declarativeplugins 0.1 as TelepathyDeclarative

and the C++ class will be defined in QML like this:


qmlRegisterType(uri, 0, 1, "ContactListModel");

To access the class from your QML file you’ll have to write a line like the following:


TelepathyDeclarative.ContactListModel{}

So once you’ve defined these few things you’re ready to go! Hope this helped!

Tagged ,
Follow

Get every new post delivered to your Inbox.