2015-04-22 12 views
6

Vorrei inviare notifiche desktop tramite D-BUS utilizzando https://crates.io/crates/dbus.Notifica desktop D-Bus utilizzando dbus-rs

Il mio approccio attuale è:

let c = Connection::get_private(BusType::Session).unwrap(); 
//let m = Message::new_method_call("org.freedesktop.DBus", "/", "org.freedesktop.DBus", "ListNames").unwrap(); 
let mut m = Message::new_method_call(
    "org.freedesktop.Notifications", 
    "/org/freedesktop/Notifications", 
    "org.freedesktop.Notifications", 
    "Notify" 
    ).unwrap(); 
m.append_items(&[ 
     MessageItem::Str("appname".to_string()),   // appname 
     MessageItem::UInt32(0),       // notification to update 
     MessageItem::Str("icon".to_string()),   // icon 
     MessageItem::Str("summary".to_string()),   // summary (title) 
     MessageItem::Str("body".to_string()),   // body 
     ???,            // actions 
     ???,            // hints 
     MessageItem::UInt32(9000),      // timeout 

]); 

non riesco a pensare a un modo significativo per soddisfare l'interfaccia del metodo Notify. Secondo D-Piedi, sembra che questo:

Notify(
    String app_name, 
    UInt32 replaces_id, 
    String app_icon, 
    String summary, 
    String body, 
    Array of [String] actions, 
    Dict of {String, Variant} hints, 
    Int32 
) 

Soprattutto il Array of [String], Dict of {String, Variant} mi lascia perplesso.

+0

Suppongo che 'Array of [String]' sia coperto dalla variante enum di MessageItem :: Array, ma non sono sicuro di 'Dict'. C'è 'MessageItem :: DictEntry', ma non posso dire come dovrebbe essere usato. –

+0

C'è un ['from_dict'] (http://diwic.github.io/dbus-rs-docs/dbus/enum.MessageItem.html#method.from_dict) ... forse' Dict' è rappresentato come una matrice di tuple chiave/valore e 'DictEntry' è solo uno ... – Shepmaster

risposta

1

Dopo un po 'ho capito questo con @payload

m.append_items(&[ 
        MessageItem::Str(appname.to_string()),   // appname 
        MessageItem::UInt32(0),      // notification to update 
        MessageItem::Str(icon.to_string()),   // icon 
        MessageItem::Str(summary.to_string()),   // summary (title) 
        MessageItem::Str(body.to_string()),   // body 
        MessageItem::new_array(      // actions 
         vec!(MessageItem::Str("".to_string()))), 
        MessageItem::new_array(      // hints 
         vec!(
          MessageItem::DictEntry(
           Box::new(MessageItem::Str("".to_string())), 
           Box::new(MessageItem::Variant(
             Box::new(MessageItem::Str("".to_string())) 
             )) 
          ), 
         ) 
        ), 
        MessageItem::Int32(9000),      // timeout 
       ]); 

mio little fun project dove io uso questo.

Problemi correlati