-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
739268b
commit f3a20d8
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2020 elementary, Inc. (https://elementary.io) | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA | ||
* | ||
* Authored by: Marius Meisenzahl <[email protected]> | ||
* | ||
*/ | ||
|
||
public class Application : Gtk.Application { | ||
private MainWindow window; | ||
|
||
public Application () { | ||
Object ( | ||
application_id: "io.elementary.notifications.demo", | ||
flags: ApplicationFlags.FLAGS_NONE | ||
); | ||
} | ||
|
||
protected override void activate () { | ||
var granite_settings = Granite.Settings.get_default (); | ||
var gtk_settings = Gtk.Settings.get_default (); | ||
|
||
gtk_settings.gtk_application_prefer_dark_theme = | ||
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; | ||
|
||
granite_settings.notify["prefers-color-scheme"].connect (() => { | ||
gtk_settings.gtk_application_prefer_dark_theme = | ||
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; | ||
}); | ||
|
||
window = new MainWindow (this); | ||
|
||
window.show_all (); | ||
} | ||
|
||
public static int main (string[] args) { | ||
var app = new Application (); | ||
return app.run (args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright 2020 elementary, Inc. (https://elementary.io) | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA | ||
* | ||
* Authored by: Marius Meisenzahl <[email protected]> | ||
* | ||
*/ | ||
|
||
public class MainWindow : Gtk.ApplicationWindow { | ||
private Gtk.Entry title_entry; | ||
private Gtk.Entry body_entry; | ||
private Gtk.Entry id_entry; | ||
private Gtk.ComboBoxText priority_combobox; | ||
|
||
public MainWindow (Gtk.Application application) { | ||
this.application = application; | ||
|
||
title = "Notifications Demo"; | ||
set_default_size (400, 400); | ||
|
||
var grid = new Gtk.Grid () { | ||
orientation = Gtk.Orientation.VERTICAL, | ||
halign = Gtk.Align.CENTER, | ||
valign = Gtk.Align.CENTER, | ||
row_spacing = 12 | ||
}; | ||
|
||
title_entry = new Gtk.Entry () { | ||
hexpand = true, | ||
placeholder_text = "Title", | ||
text = "Title" | ||
}; | ||
grid.add (title_entry); | ||
|
||
body_entry = new Gtk.Entry () { | ||
hexpand = true, | ||
placeholder_text = "Body", | ||
text = "Body" | ||
}; | ||
grid.add (body_entry); | ||
|
||
id_entry = new Gtk.Entry () { | ||
hexpand = true, | ||
placeholder_text = "Id" | ||
}; | ||
grid.add (id_entry); | ||
|
||
var priority_label = new Gtk.Label ("Priority:"); | ||
|
||
priority_combobox = new Gtk.ComboBoxText () { | ||
hexpand = true | ||
}; | ||
priority_combobox.append_text ("low"); | ||
priority_combobox.append_text ("normal"); | ||
priority_combobox.append_text ("high"); | ||
priority_combobox.append_text ("urgent"); | ||
priority_combobox.set_active (1); | ||
|
||
var priority_grid = new Gtk.Grid () { | ||
column_spacing = 6, | ||
margin = 6 | ||
}; | ||
priority_grid.add (priority_label); | ||
priority_grid.add (priority_combobox); | ||
grid.add (priority_grid); | ||
|
||
|
||
var send_button = new Gtk.Button.with_label ("Send notification"); | ||
send_button.clicked.connect (send_notification); | ||
grid.add (send_button); | ||
|
||
add (grid); | ||
} | ||
|
||
private void send_notification () { | ||
var notification = new Notification (title_entry.text); | ||
notification.set_body (body_entry.text); | ||
|
||
NotificationPriority priority; | ||
switch (priority_combobox.get_active_text ()) { | ||
case "urgent": | ||
priority = NotificationPriority.URGENT; | ||
break; | ||
case "high": | ||
priority = NotificationPriority.HIGH; | ||
break; | ||
case "low": | ||
priority = NotificationPriority.LOW; | ||
break; | ||
case "normal": | ||
default: | ||
priority = NotificationPriority.NORMAL; | ||
break; | ||
} | ||
notification.set_priority (priority); | ||
|
||
string? id = id_entry.text.length == 0 ? null : id_entry.text; | ||
|
||
application.send_notification (id, notification); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Desktop Entry] | ||
Name=Notifications Demo | ||
Comment=A demo to test the notification server | ||
Exec=io.elementary.notifications.demo | ||
Icon=preferences-system-notifications | ||
Type=Application | ||
NoDisplay=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
executable( | ||
'io.elementary.notifications.demo', | ||
'Application.vala', | ||
'MainWindow.vala', | ||
dependencies : [ | ||
dependency ('granite'), | ||
dependency ('gtk+-3.0'), | ||
], | ||
install : true | ||
) | ||
|
||
applications_dir = join_paths( | ||
get_option('prefix'), | ||
get_option('datadir'), | ||
'applications' | ||
) | ||
|
||
install_data( | ||
'io.elementary.notifications.demo.desktop', | ||
install_dir: applications_dir | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ executable( | |
) | ||
|
||
subdir('data') | ||
subdir('demo') | ||
subdir('po') | ||
|
||
meson.add_install_script('meson/post_install.py') |