1 module libnotify4d.notify; 2 import std.string; 3 import std.exception; 4 import glib.gtypes, 5 glib.glist; 6 7 extern (C) { 8 gboolean notify_init(const char* app_name); 9 void notify_uninit(); 10 gboolean notify_is_initted(); 11 12 char* notify_get_app_name(); 13 void notify_set_app_name(const char* app_name); 14 15 GList* notify_get_server_caps(); 16 17 gboolean notify_get_server_info(char** ret_name, 18 char** ret_vender, 19 char** ret_version, 20 char** ret_spec_version); 21 } 22 23 class Notify { 24 this (string name) { 25 auto ret = Notify.init(name); 26 enforce(ret, "Failed to initailize notify with notify_init"); 27 } 28 29 ~this () { 30 Notify.uninit; 31 } 32 33 static bool init(string app_name) { 34 return cast(bool)notify_init(app_name.toStringz); 35 } 36 37 static void uninit() { 38 notify_uninit; 39 } 40 41 static bool isInitted() { 42 return cast(bool)notify_is_initted; 43 } 44 45 static string getAppName() { 46 return cast(string)notify_get_app_name().fromStringz; 47 } 48 49 static string[] getServerCaps() { 50 string[] ret; 51 auto r = notify_get_server_caps; 52 53 while (r !is null) { 54 ret ~= cast(string)(cast(char*)r.data).fromStringz; 55 r = g_list_next(r); 56 } 57 58 return ret; 59 } 60 61 static string[string] getServerInfo() { 62 string[string] ret; 63 char* ret_name, 64 ret_vender, 65 ret_version, 66 ret_spec_version; 67 68 bool r = cast(bool)notify_get_server_info(&ret_name, 69 &ret_vender, 70 &ret_version, 71 &ret_spec_version); 72 73 if (r) { 74 ret["ret_name"] = cast(string)ret_name.fromStringz; 75 ret["ret_vender"] = cast(string)ret_vender.fromStringz; 76 ret["ret_version"] = cast(string)ret_version.fromStringz; 77 ret["ret_spec_version"] = cast(string)ret_spec_version.fromStringz; 78 } 79 80 return ret; 81 } 82 }