Plasma newbie questions and API fuzzyness (perhaps)

Dmitry Suzdalev dimsuzkde at gmail.com
Sat Mar 22 15:18:04 CET 2008


Another thing I just discovered - some usage path that ends up with unexpected 
behaviour :)

In short:
1. Applet wants to connect to sources dynamically - as they're added.
2. It does this by connecting to the newSource signal of data engine and then 
connects to that source in corresponding slot
3. Problem: applet receives *two* dataUpdated signals and one of them has 
uninitialized Data structure

What happens in detail:
1. Engine calls setData("source", myData). (where "source" doesn't exist yet, myData 
is well defined structure filled with data)
2. setData() calls d->source() which creates new source automatically
3. after creating new source d->source() emits 'newSource' signal
4. Applet receives this signal and calls connectSource(this)
5. connectSource(this) calls dataUpdated() with an empty data (!!!) as it hasn't been 
assigned yet
   (it emits because there's immediateCall flag in DataEngine::connectSource)
6. control returns to setData, where it sets actual source data to myData
7. dataUpdated is called again - this time with correct data.

Step 5 is unexpected and could cause some "WTF?!" from user space :)
Happenned here ;)

For now I protect agains this by using

if ( !data.isEmpty() )
{
// do stuff
}

in dataUpdated().

I'm not sure what the right solution to this problem would be.
Thoughts?

PS. I hope i described a problem cleanly enough.

Cheers,
Dmitry.

On Thursday 20 March 2008 21:34:30 Dmitry Suzdalev wrote:
> Hi, guys!
>
> A few notes as a new plasma API user :)
>
> 1. DataEngine::connectAllSources() - for some reason I thought that after
> in the applet I do:
>
> m_myEngine->connectAllSources(this)
>
> then I'll get dataUpdated slot called for every source that is changed or
> *added*. Nope. I figured out that to accomplish this I need to connect my
> applet to sourceAdded slot and then do
>
> void MyApplet::onSourceAdded(QString sourceName)
> {
>      m_myEngine->connectSource(sourceName, this);
>      kDebug() << "source" << sourceName << "added";
> }
>
> Ok, perhaps this need to be mentioned in docs - that connectAllSources
> connects all sources that *exist* at the moment when it called. Is it so
> btw? :) Didn't checked.
>
> 2. I wonder why the following code inside the data engine:
>
> void MyDataEngine::someFunction()
> {
>         Plasma::DataEngine::Data notificationData;
>         id = 1;
>         // fill data
>
>         setData( QString("notification %1").arg(id), notificationData );
>         kDebug() << "data was set";
> }
>
> produces the following output with applet set up as described in 1. (with
> additional similar sourceRemoved slot):
>
> NotifierApplet::sourceAdded: source "notification 1" added
> NotifierApplet::dataUpdated: source "notification 1" changed
> NotifierApplet::sourceRemoved: source "notification 1" removed
> NotificationsEngine::notify: data was set
> NotifierApplet::dataUpdated: source "notification 1" changed
>
> I.e. added,changed,*removed*,changed
> Why it was removed?
> I didn't ask to remove it.
>
> I guess I am doing something wrong?
> Anyway if I'm doing this, I wasn't told otherwise by docs/API, so I expect
> it to work the way I wrote it, so I guess something should be corrected :)
> Be it API docs or my brains ;)
>
> Cheers,
> Dmitry.




More information about the Panel-devel mailing list