Dev Week -- libmessagingmenu -- larsu -- Wed, Aug 29th, 2012
1 [18:01] <larsu> hi everyone 2 [18:01] <larsu> I'm Lars, I'll talk a bit about the changes we've made to the messaging menu this cycle 3 [18:02] <larsu> most importantly: libmessaging-menu, the new API for applications to integrate with the messaging menu 4 [18:02] <larsu> please don't hesitate to ask questions anytime 5 [18:03] <larsu> all the changes we've made have just landed in quantal a couple of days ago 6 [18:03] <larsu> for those of you already running quantal: that's the reason some apps show up in the menu right now ;) 7 [18:04] <larsu> let me just give a very short overview of the messaging menu 8 [18:05] <larsu> I assume most people here will be familiar with it 9 [18:05] <larsu> it's this little icon that sits in your panel, notifying you about incoming messages from various applications 10 [18:05] <larsu> also, it let's you set a global chat status for all apps at once 11 [18:06] <larsu> and it provides a way to launch messaging-related applications 12 [18:06] <larsu> up until now, three apps were always shown in the menu (Chat, Mail, and Broadcast) 13 [18:07] <larsu> starting from quantal, this will not be the case anymore: if no application is configured to show up in the menu, the menu will simply disappear 14 [18:07] <larsu> also, all applications will be referred to by their "real" name and icon, so Chat --> Empathy, Mail --> Thunderbird and Broadcast --> Gwibber 15 [18:08] <larsu> and ubuntu1 is gone from the messaging menu. It's not a messaging app anyway 16 [18:09] <larsu> if you're interested in why the menu works the way it is, there is a design specification with all the rationale at https://wiki.ubuntu.com/MessagingMenu 17 [18:10] <larsu> of course, we encourage application authors to integrate their apps with the menu 18 [18:10] <larsu> (where it makes sense of course ;) ) 19 [18:11] <larsu> !Q 20 [18:11] <ClassBot> ironhalik asked: With the new messaging menu, what's the situation with backward compatibility with Precise and older releases? Should I develop with Quantal or Precise in mind for largest userbase? 21 [18:12] <larsu> good question: the messaging menu in quantal is not backward compatible with the one in precise 22 [18:12] <larsu> we pondered keeping that, but it was more work than it was worth 23 [18:13] <larsu> to reach the biggest audience, you probably want to develop for precise, since that is the current release and it is an lts 24 [18:14] <larsu> if you think you have cutting edge users that will mostly be on the new version of ubuntu, I recommend going with the new API 25 [18:14] <larsu> it's much easier to use I am told ;) 26 [18:14] <larsu> ironhalik, does that answer your question? 27 [18:16] <larsu> so, each application gets a section in the messaging menu, which contains 3 types of items 28 [18:16] <larsu> (1) the application launcher itself, with a litte triangle next to it if the application is running 29 [18:17] <larsu> (2) shortcuts to commonly used actions (for example thunderbird has "Compose New Message" and "Contacts") 30 [18:17] <larsu> (3) the most important one: message source (for example, Thunderbird will add a menu entry for each mailbox that has new messages) 31 [18:18] <larsu> (1) and (2) are completely controlled by the applications .desktop file and cannot be changed while the application is running 32 [18:19] <larsu> to make the shortcut actions (2) that you have defined in the .desktop file appear in the messaging menu, the "TargetEnvironment" or "OnlyShowIn" keys must contain "Messaging Menu" 33 [18:19] <larsu> this is exactly the same way quicklists are handled for the launcher 34 [18:20] <larsu> so, let's go ahead with a concrete example of how to use libmessaging-menu 35 [18:21] <larsu> I'll paste a small python program line-by-line and explain what each line is doing 36 [18:22] <larsu> first: you need the gir1.2-messagingmenu-1.0 package, which is installed by default in quantal 37 [18:22] <larsu> as usual with gobject introspection, the first line of python is: 38 [18:22] <larsu> >>> from gi.repository import MessagingMenu, GLib 39 [18:23] <larsu> we'll need GLib later for the mainloop 40 [18:23] <larsu> as an aside: nothing will get send to the messaging menu until you run the main loop 41 [18:24] <larsu> next, you need to create a MessagingMenuApp object, which represents one application section in the menu 42 [18:25] <larsu> >>> mmapp = MessagingMenuApp(desktop_id="thunderbird.desktop") 43 [18:25] <larsu> you pass a desktop file id into the constructor, from which the items (1) and (2) I talked about earlier will be created 44 [18:25] <larsu> in this case, we're pretending to be thunderbird 45 [18:26] <larsu> to notify the messaging menu that our application is running, we call 46 [18:26] <larsu> >>> mmapp.register() 47 [18:26] <larsu> this does two things: if the application has never been in the menu before, a section will be created for it 48 [18:27] <larsu> and secondly, the application will be marked as "running" (with the little triangle next to it) 49 [18:28] <larsu> okay, now let's add a message source to the section: 50 [18:29] <larsu> >>> mmapp.append_source_with_count("inbox", None, "Inbox", 3) 51 [18:29] <larsu> this will append a new item with the label "Inbox" with a count of 3, which is shown on the right side of the menu item 52 [18:30] <larsu> the first parameter of this call is a unique identifier, the second one an optional icon (or None if you don't need one) 53 [18:30] <larsu> the third one is the label, and the fourth a count 54 [18:30] <larsu> analogous, there's also append_source_with_time, which you can pass a time stamp 55 [18:31] <larsu> the messaging menu will display the amount of time passed since that timestamp for these items 56 [18:31] <larsu> (for example, empathy uses that for incoming instant messages) 57 [18:32] <larsu> if you want the messaging menu envelope in the panel to turn blue, because the received notification is an important one: 58 [18:32] <larsu> >>> mmapp.draw_attention("inbox") 59 [18:32] <larsu> you just pass that function the id that we used to create the item 60 [18:34] <larsu> now, we want to get notified when the user selects the source and - for the sake of this example - simply print which source was activated 61 [18:34] <larsu> so we first need a small function 62 [18:34] <larsu> >>> def source_activated(mmapp, source_id): print id 63 [18:34] <larsu> sorry, that's "print source_id" of course 64 [18:34] <larsu> now, we can connect to the mmapp's "activate-source" signal 65 [18:35] <larsu> >>> mmapp.connect("activate-source", source_activated) 66 [18:35] <larsu> the source will be automatically removed when the user clicks on it 67 [18:36] <larsu> to try this out, let's spin up a main loop: 68 [18:36] <larsu> >>> GLib.MainLoop().run() 69 [18:37] <larsu> the messaging menu will automatically mark your application as "not running" when it stops running, no need to do anything 70 [18:38] <larsu> however, if you want to completly remove the application from the menu, call 71 [18:38] <larsu> >>> mmapp.unregister() 72 [18:39] <larsu> your application should remove any sources from the menu when the user gets to them in some other way 73 [18:40] <larsu> for example, when thunderbird is opened from the launcher and the user reads all messages that way 74 [18:40] <larsu> call mmapp.remove_source("inbox") to do this 75 [18:40] <larsu> there's not much more to it :) 76 [18:41] <larsu> unfortunately, I didn't manage to upload the API documentation in time for this talk, but it will appear on developer.ubuntu.com soon 77 [18:41] <larsu> and since it's a gobject-based library, your favorite programming language is most likely supported 78 [18:41] <larsu> hm, I've been talking all this time: are there any questions? 79 [18:43] <larsu> I've pasted our little example here: http://pastebin.ubuntu.com/1174375/ 80 [18:50] <ClassBot> There are 10 minutes remaining in the current session. 81 [18:55] <ClassBot> There are 5 minutes remaining in the current session. 82 [18:55] <ClassBot> marcosb asked: can i implement this example in ruby? 83 [18:56] <larsu> marcosb, to be honest, I'm not sure if there is gobject-introspection for ruby (ruby doesn't seem to be very popular amongst linux desktop programmers) 84 [18:57] <larsu> if there is, then you can implement this example in ruby 85 [18:57] <larsu> a quick google search seems to suggest that they exist 86 [18:58] <larsu> well, not many questions: hope you enjoyed it anyway. Bye!