Results 1 to 13 of 13

Thread: QDBus and org.freedesktop.Notifications.Notify

  1. #1
    Join Date
    Nov 2009
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDBus and org.freedesktop.Notifications.Notify

    Hi I'm currently developing a small tcp based notification server using the "org.freedesktop.Notifications.Notify" dbus binding and everything works fine on my Kubuntu, I even got the callbacks working with qdbus(I don't want to use libnotify because there are too many gtk depenecys).
    The current problem is that I don't know how to sent the a notification image over qdbus.

    on http://www.galago-project.org/specs/.../0.9/x207.html
    the image is defined as
    The icon_data field should be a raw image data structure of signature (iiibiiay) which describes the width, height, rowstride, has alpha, bits per sample, channels and image data respectively.

    and here is an except from dbus-monitor of a working notification

    Qt Code:
    1. array [
    2. dict entry(
    3. string "icon_data"
    4. variant struct {
    5. int32 50
    6. int32 50
    7. int32 200
    8. boolean true
    9. int32 8
    10. int32 4
    11. array [
    12. byte 255
    13. byte 32
    14. byte 57
    15. byte 93
    16. byte 255
    17. byte 32
    18. byte 57
    19. byte 93
    20. byte 255
    21. byte 32
    22. .......
    23. ]
    24. }
    25. )
    26. ]
    To copy to clipboard, switch view to plain text mode 

    The image defined above should be part of a QVariantMap.

    Problematic is how to get bits per sample and channels and finally how to sent these data over dbus.


    Regards

    TheOneRing

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    Bits per sample is most probably 8 or 24 - this is just the depth of your image (the only thing to check out is that if the number should describe one pixel (24b for RGB) or one channel(8b for RGB)). Channels will be one for gray images, 3 for colour images and 4 for colour images with alpha channel. You can deduce all the values based on QImage::format().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    TheOneRing (22nd November 2009)

  4. #3
    Join Date
    Nov 2009
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    Great but how to send the data over dbus?
    Currently I'm getting this

    Qt Code:
    1. string "icon_data"
    2. int32 133
    3. int32 135
    4. int32 532
    5. boolean true
    6. int32 8
    7. int32 4
    8. array [
    9. byte 137
    10. byte 80
    11. byte 78
    12. byte 71
    13. .....
    14. ]
    To copy to clipboard, switch view to plain text mode 
    how to get the right form?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    I don't understand your question. What exactly do you have trouble with? From your post it seems an image 32bit deep (4 channels (RGBA) 8 bits each) with size of 133x135 is carried.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Nov 2009
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    The problem is not the data (thanks for help) the current problem is which datatype I have to use that QDBus sends it in the correct form.
    Currently I use a QVariantList and insert all the vaues, in the working notification it looks like I have to send a struct over QDBus but I don't know how.

    Here is what I get
    Qt Code:
    1. string "icon_data"
    2. int32 133
    3. int32 135
    4. int32 532
    5. boolean true
    6. int32 8
    7. int32 4
    8. array [
    9. byte 137
    10. byte 80
    11. byte 78
    12. byte 71
    13. .....
    14. ]
    To copy to clipboard, switch view to plain text mode 

    and this is what I need:
    Qt Code:
    1. array [
    2. dict entry(
    3. string "icon_data"
    4. variant struct {
    5. int32 50
    6. int32 50
    7. int32 200
    8. boolean true
    9. int32 8
    10. int32 4
    11. array [
    12. byte 255
    13. byte 32
    14. byte 57
    15. byte 93
    16. byte 255
    17. byte 32
    18. byte 57
    19. byte 93
    20. byte 255
    21. byte 32
    22. .......
    23. ]
    24. }
    25. )
    26. ]
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Nov 2009
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    Ok now I get that far

    Qt Code:
    1. array [
    2. dict entry(
    3. string "icon_data"
    4. variant array [
    5. variant int32 133
    6. variant int32 135
    7. variant int32 532
    8. variant boolean true
    9. variant int32 8
    10. variant int32 4
    11. variant array [
    12. byte 137
    13. byte 80
    14. byte 78
    15. byte 71
    16. byte 13
    17. byte 10
    18. .......
    To copy to clipboard, switch view to plain text mode 

    at least the beginning seams to be right
    but I have no idea how to get the entry struct.

    My current code is
    Qt Code:
    1. QVariantMap Notify::getImage(QString* path){
    2. QImage img(*path);
    3. QVariantMap out;
    4.  
    5. if(img.isNull())return out;
    6. int width=img.width();
    7. int height=img.height();
    8. int rowstride=img.bytesPerLine();
    9. bool hasAlpha=img.hasAlphaChannel();
    10. int channels;
    11. if(img.isGrayscale())
    12. channels=1;
    13. else{
    14. channels =3;
    15. if(hasAlpha)
    16. channels=4;
    17. }
    18. int bitsPerSample=img.depth()/channels;
    19. QByteArray image;
    20. QBuffer buffer(&image,NULL );
    21. buffer.open( QBuffer::WriteOnly);
    22. img.save( &buffer, "PNG" );
    23. QVariantList o2;
    24. o2<<width<<height<<rowstride<<hasAlpha<<bitsPerSample<<channels<<image;
    25. out.insert("icon_data",o2);
    26. return out;
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 
    but instead of QVariantList for the body i have to use something different, but what?

  8. #7
    Join Date
    Nov 2009
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    Hi I finally got it to send a image but the image is not displayed correct, so I think there is a bug in my mtheode so here is the code
    Qt Code:
    1. void Notify::getImage(QVariantMap *hints,QString* path){
    2. QImage img(*path);
    3. if(img.isNull())return;
    4. int id=qDBusRegisterMetaType<iiibiiay>();
    5. iiibiiay i;
    6. i.width=img.width();
    7. i.height=img.height();
    8. i.rowstride=img.bytesPerLine();
    9. i.hasAlpha=img.hasAlphaChannel();
    10. if(img.isGrayscale())
    11. i.channels=1;
    12. else{
    13. i.channels =3;
    14. if(i.hasAlpha)
    15. i.channels=4;
    16. }
    17. i.bitsPerSample=img.depth()/i.channels;
    18. QBuffer buffer(&i.image,NULL );
    19. buffer.open( QBuffer::WriteOnly);
    20. img.save( &buffer, "PNG" );
    21. hints->insert("icon_data",QVariant(id,&i));
    22. }
    23.  
    24. QDBusArgument &operator<<(QDBusArgument &a, const iiibiiay &i) {
    25. a.beginStructure();
    26. a << i.width<<i.height<<i.rowstride<<i.hasAlpha<<i.bitsPerSample<<i.channels<<i.image;
    27. a.endStructure();
    28. return a;
    29. }
    30.  
    31. const QDBusArgument & operator >>(const QDBusArgument &a, iiibiiay &i) {
    32. a.beginStructure();
    33. a >> i.width>> i.height>> i.rowstride>> i.hasAlpha>> i.bitsPerSample>> i.channels>> i.image;
    34. a.endStructure();
    35. return a;
    36. }
    To copy to clipboard, switch view to plain text mode 


    The image in the upper left corner and the big rectangel should be the same

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    Try only sending img.bits() as the image data. If you were to send PNG image will all headers and stuff, all the information about the image wouldn't be necessary because they could be taken from PNG headers.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #9
    Join Date
    Nov 2009
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    I'v got even one step closer to my ultimate goal



    Qt Code:
    1. for(int ii=0;ii<img.numBytes();++ii)
    2. i.image.append(img.pixel(ii%i.width,ii/i.width));
    To copy to clipboard, switch view to plain text mode 

    does anybody know how to get a pixbuff out of a QImage without using gdk?

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    pixbuff is a GDK concept. It's equivalent in Qt is either QImage::bits() or QImage itself. Based on your code I think you should really try QImage::bits()
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    TheOneRing (23rd November 2009)

  13. #11
    Join Date
    Nov 2009
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    Big thanks but I get the wrong color.


    Qt Code:
    1. iiibiiay::iiibiiay(QImage* img){
    2. width=img->width();
    3. height=img->height();
    4. rowstride=img->bytesPerLine();
    5. hasAlpha=img->hasAlphaChannel();
    6. channels =img->isGrayscale()?1:hasAlpha?4:3;
    7. bitsPerSample=img->depth()/channels;
    8. image.append((char*)img->bits(),img->numBytes());
    9. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by TheOneRing; 23rd November 2009 at 10:12.

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    You probably have to swap the order of channels. I would assume - from RGB to BGR, or something like that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #13
    Join Date
    Nov 2009
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDBus and org.freedesktop.Notifications.Notify

    And again big thanks QImage::rgbSwapped() solved the problem
    so finally every problem is solved, wysota you are my hero!
    Last edited by TheOneRing; 23rd November 2009 at 10:44.

Similar Threads

  1. QDBus on a network
    By TMan in forum Qt Programming
    Replies: 6
    Last Post: 7th August 2009, 15:15
  2. HAL & qdbus introspection & InvalidSignature error
    By juannm in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2009, 17:59
  3. qdbus signal
    By khcbabu in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2009, 13:17
  4. Using QDBus
    By Sandip in forum Qt Programming
    Replies: 3
    Last Post: 27th May 2008, 07:17
  5. qDBus in windows?
    By cxl2253 in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2008, 07:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.