void gm_enable_menu_item(DBusMessageIter * list,FXint id,FXbool enabled) {
  DBusMessageIter dict;
  DBusMessageIter item;
  dbus_message_iter_open_container(list,DBUS_TYPE_STRUCT,NULL,&item);
    dbus_message_iter_append_basic(&item,DBUS_TYPE_INT32,&id);
    dbus_message_iter_open_container(&item,DBUS_TYPE_ARRAY,"{sv}",&dict);
      gm_dbus_dict_append_bool(&dict,"enabled",enabled);
    dbus_message_iter_close_container(&item,&dict);
  dbus_message_iter_close_container(list,&item);
  }
void gm_begin_menu(DBusMessageIter * root,DBusMessageIter * item,FXint id,const FXchar * label,const FXchar * icon=NULL,FXbool enabled=true) {
  DBusMessageIter dict;
  dbus_message_iter_open_container(root,DBUS_TYPE_STRUCT,NULL,item);
    dbus_message_iter_append_basic(item,DBUS_TYPE_INT32,&id);
      dbus_message_iter_open_container(item,DBUS_TYPE_ARRAY,"{sv}",&dict);
        gm_dbus_dict_append_string(&dict,"label",label);
        gm_dbus_dict_append_string(&dict,"icon-name",icon);
        if (!enabled)
          gm_dbus_dict_append_bool(&dict,"enabled",false);
      dbus_message_iter_close_container(item,&dict);
  }
void GMNotifyDaemon::notify(const FXchar * summary,const FXchar * body,FXint timeout,FXImage* image){
  FXint iw,ih,is,ibps,ichannels,isize;
  dbus_bool_t ialpha;

  const FXchar * idata=NULL;

  DBusMessage * msg = method("Notify");
  if (msg){
      DBusMessageIter iter;
      DBusMessageIter array;
      DBusMessageIter dict;
      DBusMessageIter value;
      DBusMessageIter variant;
      DBusMessageIter data;

      dbus_message_iter_init_append(msg,&iter);

        gm_dbus_append_string(&iter,appname);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_UINT32,&msgid);

        if (image && (flags&IMAGE_WITHOUT_APPICON)) {
          FXString empty;
          gm_dbus_append_string(&iter,empty);
          }
        else {
          gm_dbus_append_string(&iter,appicon);
          }

        dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&summary);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&body);

        dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,DBUS_TYPE_STRING_AS_STRING,&array);
        if (persistent) {
          if (GMPlayerManager::instance()->can_prev())
            gm_dbus_append_string_pair(&array,"media-skip-backward","Previous");
          if (GMPlayerManager::instance()->can_pause())
            gm_dbus_append_string_pair(&array,"media-playback-pause","Pause");
          else if (GMPlayerManager::instance()->can_play())
            gm_dbus_append_string_pair(&array,"media-playback-start","Play");
          if (GMPlayerManager::instance()->can_stop())
            gm_dbus_append_string_pair(&array,"media-playback-stop","Stop");
          if (GMPlayerManager::instance()->can_next())
            gm_dbus_append_string_pair(&array,"media-skip-forward","Next");
          }
        dbus_message_iter_close_container(&iter,&array);


        dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,"{sv}",&array);
        if (image && image->getData()) {
//          const FXchar * icon_data="icon_data"; /// spec 0.9 says "image_data". some use "icon_data" though..
//          const FXchar * icon_data="image-data"; /// spec 0.9 says "image_data". some use "icon_data" though..

          ialpha    = true;
          iw        = image->getWidth();
          ih        = image->getHeight();
          is        = iw*4;
          ibps      = 8;
          ichannels = 4;
          isize     = iw*ih*4;

          FXColor * bgra = NULL;
          allocElms(bgra,(iw*ih));
          gm_bgra_to_rgba(image->getData(),bgra,(iw*ih));

          idata     = (const FXchar*)bgra;

          dbus_message_iter_open_container(&array,DBUS_TYPE_DICT_ENTRY,0,&dict);
            gm_dbus_append_string(&dict,icondata);
            dbus_message_iter_open_container(&dict,DBUS_TYPE_VARIANT,"(iiibiiay)",&variant);
              dbus_message_iter_open_container(&variant,DBUS_TYPE_STRUCT,NULL,&value);
                dbus_message_iter_append_basic(&value,DBUS_TYPE_INT32,&iw);
                dbus_message_iter_append_basic(&value,DBUS_TYPE_INT32,&ih);
                dbus_message_iter_append_basic(&value,DBUS_TYPE_INT32,&is);
                dbus_message_iter_append_basic(&value,DBUS_TYPE_BOOLEAN,&ialpha);
                dbus_message_iter_append_basic(&value,DBUS_TYPE_INT32,&ibps);
                dbus_message_iter_append_basic(&value,DBUS_TYPE_INT32,&ichannels);
                dbus_message_iter_open_container(&value,DBUS_TYPE_ARRAY,DBUS_TYPE_BYTE_AS_STRING,&data);
                  dbus_message_iter_append_fixed_array(&data,DBUS_TYPE_BYTE,&idata,isize);
                dbus_message_iter_close_container(&value,&data);
              dbus_message_iter_close_container(&variant,&value);
            dbus_message_iter_close_container(&dict,&variant);
          dbus_message_iter_close_container(&array,&dict);

          freeElms(bgra);
          }

            //gm_dbus_dict_append_bool(&array,"transient",true);

        if (persistent) {
//          if (GMPlayerManager::instance()->playing())
            gm_dbus_dict_append_bool(&array,"resident",true);
//          else
//            gm_dbus_dict_append_bool(&array,"transient",true);
          gm_dbus_dict_append_bool(&array,"action-icons",true);
          }
        dbus_message_iter_close_container(&iter,&array);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_INT32,&timeout);

      send(msg,this,ID_NOTIFY_REPLY);
      }
    }