2015-04-22 6 views
6

का उपयोग करके मैं https://crates.io/crates/dbus का उपयोग कर डी-बस के माध्यम से डेस्कटॉप नोटिफिकेशन भेजना चाहता हूं।डी-बस डेस्कटॉप अधिसूचना dbus-rs

मेरे वर्तमान दृष्टिकोण है:

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 

]); 

मैं Notify विधि के इंटरफेस को पूरा करने के एक सार्थक तरीके से नहीं सोच सकते हैं। डी-पैर के अनुसार, यह इस तरह दिखता है:

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

विशेष रूप से Array of [String], Dict of {String, Variant} पहेली मुझे।

+0

मुझे लगता है कि 'स्ट्रिंग] का ऐरे' संदेश Item :: Array' enum संस्करण द्वारा कवर किया गया है, लेकिन मुझे 'डिक्ट' के बारे में निश्चित नहीं है। 'MessageItem :: DictEntry' है, लेकिन मैं नहीं कह सकता कि इसका उपयोग कैसे किया जाना चाहिए। –

+0

एक ['from_dict'] है (http://diwic.github.io/dbus-rs-docs/dbus/enum.MessageItem.html#method.from_dict) ... शायद 'डिक्ट' को सरणी के रूप में दर्शाया गया है कुंजी/मूल्य tuples के, और 'DictEntry' सिर्फ एक ही है ... – Shepmaster

उत्तर

1

थोड़ी देर के बाद मैं @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 
       ]); 

मेरे little fun project जहाँ मैं इस का उपयोग के साथ बाहर इस लगा।

संबंधित मुद्दे