Merge lp:~vikoadi/audience/add-playlist-notification into lp:~audience-members/audience/trunk

Proposed by Viko Adi Rahmawan
Status: Merged
Merged at revision: 408
Proposed branch: lp:~vikoadi/audience/add-playlist-notification
Merge into: lp:~audience-members/audience/trunk
Diff against target: 139 lines (+77/-2)
3 files modified
src/Audience.vala (+14/-2)
src/CMakeLists.txt (+21/-0)
src/Utils.vala (+42/-0)
To merge this branch: bzr merge lp:~vikoadi/audience/add-playlist-notification
Reviewer Review Type Date Requested Status
Audience Members Pending
Review via email: mp+230570@code.launchpad.net

Description of the change

Show notification when adding playlist from file manager

To post a comment you must log in.
Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

depend on "libnotify"

Revision history for this message
Cody Garver (codygarver) wrote :

Can you make it combine current and future notifications into 1 notification, as seen with lp:noise when you queue tracks. Opening multiple videos would not spam the screen with multiple notifications.

368. By Viko Adi Rahmawan

merge trunk

369. By Viko Adi Rahmawan

use notification update

370. By Viko Adi Rahmawan

fix

371. By Viko Adi Rahmawan

fix plural

372. By Viko Adi Rahmawan

fix style

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

done

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Audience.vala'
2--- src/Audience.vala 2014-09-03 00:07:10 +0000
3+++ src/Audience.vala 2014-09-03 17:50:21 +0000
4@@ -68,6 +68,7 @@
5
6 public bool fullscreened { get; set; }
7
8+ private static App app; // global App instance
9 private Audience.Widgets.VideoPlayer video_player;
10 private Audience.Widgets.BottomBar bottom_bar;
11 private Clutter.Stage stage;
12@@ -95,6 +96,12 @@
13 this.flags |= GLib.ApplicationFlags.HANDLES_OPEN;
14 }
15
16+ public static App get_instance () {
17+ if (app == null)
18+ app = new App ();
19+ return app;
20+ }
21+
22 void build () {
23 playlist = new Widgets.Playlist ();
24 settings = new Settings ();
25@@ -745,7 +752,12 @@
26 playlist.add_item (file);
27 }
28
29- if (video_player.uri == null)
30+ if (video_player.uri != null) { // we already play some file
31+ if (files.length == 1)
32+ show_notification (_("File added to playlist"), files[0].get_basename ());
33+ else
34+ show_notification (_("%i files added to playlist").printf (files.length), "");
35+ } else
36 open_file(files[0].get_uri ());
37 }
38 }
39@@ -761,7 +773,7 @@
40
41 Gst.init (ref args);
42
43- var app = new Audience.App ();
44+ var app = Audience.App.get_instance ();
45
46 app.run (args);
47 }
48\ No newline at end of file
49
50=== modified file 'src/CMakeLists.txt'
51--- src/CMakeLists.txt 2014-06-30 14:54:30 +0000
52+++ src/CMakeLists.txt 2014-09-03 17:50:21 +0000
53@@ -22,6 +22,26 @@
54 )
55
56 pkg_check_modules (DEPS REQUIRED ${PKG_DEPS})
57+
58+#
59+# Libnotify
60+#
61+pkg_check_modules (LIBNOTIFY QUIET libnotify)
62+if (LIBNOTIFY_FOUND)
63+ message ("-- libnotify enabled")
64+
65+ set (GLOBAL_VALAC_OPTIONS ${GLOBAL_VALAC_OPTIONS} --define=HAVE_LIBNOTIFY)
66+
67+ set (PKG_DEPS ${PKG_DEPS} libnotify)
68+ set (VALA_DEPS ${VALA_DEPS} libnotify)
69+
70+ set (DEPS_CFLAGS ${DEPS_CFLAGS} ${LIBNOTIFY_CFLAGS})
71+ set (DEPS_LIBRARIES ${DEPS_LIBRARIES} ${LIBNOTIFY_LIBRARIES})
72+ set (DEPS_LIBRARY_DIRS ${DEPS_LIBRARY_DIRS} ${LIBNOTIFY_LIBRARY_DIRS})
73+else ()
74+ message ("-- libnotify disabled")
75+endif ()
76+
77 set (CFLAGS ${DEPS_CFLAGS} ${DEPS_CFLAGS_OTHER})
78 link_directories (${DEPS_LIBRARY_DIRS})
79 add_definitions (${CFLAGS})
80@@ -46,6 +66,7 @@
81 PACKAGES
82 ${VALA_DEPS}
83 OPTIONS
84+ ${GLOBAL_VALAC_OPTIONS}
85 --enable-experimental
86 --target-glib=2.32 # Remember to keep this updated.
87 --thread
88
89=== modified file 'src/Utils.vala'
90--- src/Utils.vala 2014-08-09 01:13:20 +0000
91+++ src/Utils.vala 2014-09-03 17:50:21 +0000
92@@ -111,4 +111,46 @@
93 var file = File.new_for_uri (uri);
94 return file.query_exists ();
95 }
96+
97+ /**
98+ * Notifications
99+ */
100+#if HAVE_LIBNOTIFY
101+ private Notify.Notification? notification = null;
102+#endif
103+
104+ public static void show_notification (string primary_text, string secondary_text, Gdk.Pixbuf? pixbuf = null, int urgency = -1) {
105+#if HAVE_LIBNOTIFY
106+ if (urgency == -1)
107+ urgency = Notify.Urgency.NORMAL;
108+
109+ if (!Notify.is_initted ()) {
110+ if (!Notify.init (App.get_instance ().application_id)) {
111+ warning ("Could not init libnotify");
112+ return;
113+ }
114+ }
115+
116+ if (notification == null) {
117+ notification = new Notify.Notification (primary_text, secondary_text, "");
118+ } else {
119+ notification.clear_hints ();
120+ notification.clear_actions ();
121+ notification.update (primary_text, secondary_text, "");
122+ }
123+
124+ if (pixbuf != null)
125+ notification.set_image_from_pixbuf (pixbuf);
126+ else
127+ notification.icon_name = App.get_instance ().app_icon;
128+
129+ notification.set_urgency ((Notify.Urgency) urgency);
130+
131+ try {
132+ notification.show ();
133+ } catch (GLib.Error err) {
134+ warning ("Could not show notification: %s", err.message);
135+ }
136+#endif
137+ }
138 }
139\ No newline at end of file

Subscribers

People subscribed via source and target branches