Differenze tra le versioni di "Far mostrare sulla Scrivania i messaggi della specifica Desktop Notifications mediante le funzioni esterne del API di Libnotify"

Da Gambas-it.org - Wikipedia.
 
(5 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
 
La libreria ''Libnotify'' è un'implementazione della specifica ''Desktop Notifications''. Essa permette di mostrare le classiche piccole finestre popup passive sul desktop che informano l'utente di particolari eventi.
 
La libreria ''Libnotify'' è un'implementazione della specifica ''Desktop Notifications''. Essa permette di mostrare le classiche piccole finestre popup passive sul desktop che informano l'utente di particolari eventi.
  
Per poter fruire in Gambas delle sue risorse, è necessario installare ed utilizzare la libreria dinamica condivisa: "''libnotify.so.4.0.0''"
+
Per poter fruire in Gambas delle sue risorse, è necessario installare ed utilizzare la libreria condivisa: "''libnotify.so.4.0.0'' ".
  
 
+
Mostriamo un semplice esempio dimostrativo di base:
Mostriamo un semplice esempio dimostrativo:
 
 
  Library "libnotify:4.0.0"
 
  Library "libnotify:4.0.0"
 
   
 
   
Riga 30: Riga 29:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
   
 
   
 
   Dim nome As String
 
   Dim nome As String
 
   Dim notify As Pointer
 
   Dim notify As Pointer
 
    
 
    
    nome = "Notifica"
+
  nome = "Notifica"
 
    
 
    
    notify_init(nome)
+
  notify_init(nome)
 
      
 
      
    notify = notify_notification_new(nome, "Testo della notifica", Null)
+
  notify = notify_notification_new(nome, "Testo della notifica", Null)
 +
  If notify == 0 Then Error.Raise("Errore !")
 
      
 
      
 
  <FONT Color=gray>' ''Imposta il livello di urgenza della notifica:''</font>
 
  <FONT Color=gray>' ''Imposta il livello di urgenza della notifica:''</font>
    notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL)
+
  notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL)
 +
  notify_notification_show(notify, 0)
 
      
 
      
     notify_notification_show(notify, 0)
+
  g_object_unref(notify)
 +
 +
End
 +
Da rilevare che riguardo al <u>2° argomento</u> della funzione esterna "notify_notification_new()":
 +
<BR>- il testo, in esso contenuto, può essere manipolato con i seguenti tag html:
 +
&lt;b>....</b>
 +
&lt;i>....</i>
 +
&lt;u>....</u>
 +
- esso può contenere anche un collegamento web, cliccando sul quale sarà aperta nel webbrowser di sistema la pagina ivi indicata:
 +
notify = notify_notification_new(..., "https&#058;//www.gambas-it.org", ...)
 +
 
 +
====Mostrare un'icona====
 +
E' possibile anche mostrare un'icona all'interno della finestra della notifica.
 +
 
 +
Sono possibili due modalità.
 +
 
 +
'''1<SUP>a</sup>''' modalità:
 +
Library "libnotify:4.0.0"
 +
 +
Private Enum NOTIFY_URGENCY_LOW = 0, NOTIFY_URGENCY_NORMAL, NOTIFY_URGENCY_CRITICAL
 +
 +
<FONT Color=gray>' ''gboolean notify_init (const char *app_name)''
 +
' ''Initialized libnotify.''</font>
 +
Private Extern notify_init(app_name As String) As Boolean
 +
 +
<FONT Color=gray>' ''NotifyNotification * notify_notification_new (const char *summary, const char *body, const char *icon)''
 +
' ''Creates a new NotifyNotification.''</font>
 +
Private Extern notify_notification_new(summary As String, body As String, icon As String) As Pointer
 +
 +
<FONT Color=gray>' ''void notify_notification_set_urgency (NotifyNotification *notification, NotifyUrgency urgency)''
 +
' ''Sets the urgency level of this notification.''</font>
 +
Private Extern notify_notification_set_urgency(notification As Pointer, urgency As Integer)
 +
 +
<FONT Color=gray>' ''gboolean notify_notification_show (NotifyNotification *notification, GError **error)''
 +
' ''Tells the notification server to display the notification on the screen.''</font>
 +
Private Extern notify_notification_show(notification As Pointer, gerror As Pointer)
 +
 +
<FONT Color=gray>' ''void g_object_unref (gpointer object)''
 +
' ''Decreases the reference count of object.''</font>
 +
Private Extern g_object_unref(gobject As Pointer)
 +
 +
 +
Public Sub Main()
 +
 +
  Dim nome As String
 +
  Dim notify As Pointer
 +
 +
  nome = "Notifica"
 +
 +
  notify_init(nome)
 +
 +
<FONT Color=gray>' ''Nel 3° argomento della seguente funzione esterna si inserirà il percorso del file dell'immagine da mostrare:''</font>
 +
  notify = notify_notification_new(nome, "Testo della notifica", "<FONT Color=red>''/percorso/del/file/immagine''</font>")
 +
  If notify == 0 Then Error.Raise("Errore !")
 +
      
 +
<FONT Color=gray>' ''Imposta il livello di urgenza della notifica:''</font>
 +
  notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL)
 +
  notify_notification_show(notify, 0)
 
      
 
      
    g_object_unref(notify)
+
  g_object_unref(notify)
 
   
 
   
  '''End'''
+
  End
 
 
  
 +
'''2<SUP>a</sup>''' modalità:
 +
Library "libnotify:4.0.0"
 +
 +
Private Enum NOTIFY_URGENCY_LOW = 0, NOTIFY_URGENCY_NORMAL, NOTIFY_URGENCY_CRITICAL
 +
 +
<FONT Color=gray>' ''gboolean notify_init (const char *app_name)''
 +
' ''Initialized libnotify.''</font>
 +
Private Extern notify_init(app_name As String) As Boolean
 +
 +
<FONT Color=gray>' ''NotifyNotification * notify_notification_new (const char *summary, const char *body, const char *icon)''
 +
' ''Creates a new NotifyNotification.''</font>
 +
Private Extern notify_notification_new(summary As String, body As String, icon As String) As Pointer
 +
 +
<FONT Color=gray>' ''GVariant* g_variant_new_string (const gchar* string)''
 +
' ''Creates a string GVariant with the contents of string.''</font>
 +
Private Extern g_variant_new_string(_string As String) As Pointer
 +
 +
<FONT Color=gray>' ''void notify_notification_set_hint (NotifyNotification* notification, const char* key, GVariant* value)''
 +
' ''Sets a hint for key with value value.''</font>
 +
Private Extern notify_notification_set_hint(notification As Pointer, key As String, value As Pointer)
 +
 +
<FONT Color=gray>' ''void notify_notification_set_urgency (NotifyNotification *notification, NotifyUrgency urgency)''
 +
' ''Sets the urgency level of this notification.''</font>
 +
Private Extern notify_notification_set_urgency(notification As Pointer, urgency As Integer)
 +
 +
<FONT Color=gray>' ''gboolean notify_notification_show (NotifyNotification *notification, GError **error)''
 +
' ''Tells the notification server to display the notification on the screen.''</font>
 +
Private Extern notify_notification_show(notification As Pointer, gerror As Pointer)
 +
 +
<FONT Color=gray>' ''void g_object_unref (gpointer object)''
 +
' ''Decreases the reference count of object.''</font>
 +
Private Extern g_object_unref(gobject As Pointer)
 +
 +
 +
Public Sub Main()
 +
 +
  Dim nome As String
 +
  Dim notify As Pointer
 +
 
 +
  nome = "Notifica"
 +
 
 +
  notify_init(nome)
 +
   
 +
  notify = notify_notification_new(nome, "Testo della notifica", Null)
 +
  If notify == 0 Then Error.Raise("Errore !")
 +
 +
  gv = g_variant_new_string("<FONT Color=red>''/percorso/del/file/immagine''</font>")
 +
  notify_notification_set_hint(notify, "image-path", gv)
 +
   
 +
<FONT Color=gray>' ''Imposta il livello di urgenza della notifica:''</font>
 +
  notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL)
 +
  notify_notification_show(notify, 0)
 +
   
 +
  g_object_unref(notify)
 +
 +
End
  
  
 
=Riferimenti=
 
=Riferimenti=
* https://developer.gnome.org/libnotify/unstable/
+
* https://gnome.pages.gitlab.gnome.org/libnotify/
 +
* https://docs.gtk.org/gio/class.Notification.html
 +
* https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html

Versione attuale delle 04:30, 26 nov 2023

La libreria Libnotify è un'implementazione della specifica Desktop Notifications. Essa permette di mostrare le classiche piccole finestre popup passive sul desktop che informano l'utente di particolari eventi.

Per poter fruire in Gambas delle sue risorse, è necessario installare ed utilizzare la libreria condivisa: "libnotify.so.4.0.0 ".

Mostriamo un semplice esempio dimostrativo di base:

Library "libnotify:4.0.0"

Private Enum NOTIFY_URGENCY_LOW = 0, NOTIFY_URGENCY_NORMAL, NOTIFY_URGENCY_CRITICAL

' gboolean notify_init (const char *app_name)
' Initialized libnotify.
Private Extern notify_init(app_name As String) As Boolean

' NotifyNotification * notify_notification_new (const char *summary, const char *body, const char *icon)
' Creates a new NotifyNotification.
Private Extern notify_notification_new(summary As String, body As String, icon As String) As Pointer

' void notify_notification_set_urgency (NotifyNotification *notification, NotifyUrgency urgency)
' Sets the urgency level of this notification. 
Private Extern notify_notification_set_urgency(notification As Pointer, urgency As Integer)

' gboolean notify_notification_show (NotifyNotification *notification, GError **error)
' Tells the notification server to display the notification on the screen.
Private Extern notify_notification_show(notification As Pointer, gerror As Pointer)

' void g_object_unref (gpointer object)
' Decreases the reference count of object.
Private Extern g_object_unref(gobject As Pointer)


Public Sub Main()

 Dim nome As String
 Dim notify As Pointer
 
 nome = "Notifica"
 
 notify_init(nome)
   
 notify = notify_notification_new(nome, "Testo della notifica", Null)
 If notify == 0 Then Error.Raise("Errore !")
   
' Imposta il livello di urgenza della notifica:
 notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL)
 notify_notification_show(notify, 0)
   
 g_object_unref(notify)

End

Da rilevare che riguardo al 2° argomento della funzione esterna "notify_notification_new()":
- il testo, in esso contenuto, può essere manipolato con i seguenti tag html:

<b>....</b>
<i>....</i>
<u>....</u>

- esso può contenere anche un collegamento web, cliccando sul quale sarà aperta nel webbrowser di sistema la pagina ivi indicata:

notify = notify_notification_new(..., "https://www.gambas-it.org", ...)

Mostrare un'icona

E' possibile anche mostrare un'icona all'interno della finestra della notifica.

Sono possibili due modalità.

1a modalità:

Library "libnotify:4.0.0"

Private Enum NOTIFY_URGENCY_LOW = 0, NOTIFY_URGENCY_NORMAL, NOTIFY_URGENCY_CRITICAL

' gboolean notify_init (const char *app_name)
' Initialized libnotify.
Private Extern notify_init(app_name As String) As Boolean

' NotifyNotification * notify_notification_new (const char *summary, const char *body, const char *icon)
' Creates a new NotifyNotification.
Private Extern notify_notification_new(summary As String, body As String, icon As String) As Pointer

' void notify_notification_set_urgency (NotifyNotification *notification, NotifyUrgency urgency)
' Sets the urgency level of this notification. 
Private Extern notify_notification_set_urgency(notification As Pointer, urgency As Integer)

' gboolean notify_notification_show (NotifyNotification *notification, GError **error)
' Tells the notification server to display the notification on the screen.
Private Extern notify_notification_show(notification As Pointer, gerror As Pointer)

' void g_object_unref (gpointer object)
' Decreases the reference count of object.
Private Extern g_object_unref(gobject As Pointer)


Public Sub Main()

 Dim nome As String
 Dim notify As Pointer

 nome = "Notifica"

 notify_init(nome)

' Nel 3° argomento della seguente funzione esterna si inserirà il percorso del file dell'immagine da mostrare:
 notify = notify_notification_new(nome, "Testo della notifica", "/percorso/del/file/immagine")
 If notify == 0 Then Error.Raise("Errore !")
   
' Imposta il livello di urgenza della notifica:
 notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL)
 notify_notification_show(notify, 0)
   
 g_object_unref(notify)

End

2a modalità:

Library "libnotify:4.0.0"

Private Enum NOTIFY_URGENCY_LOW = 0, NOTIFY_URGENCY_NORMAL, NOTIFY_URGENCY_CRITICAL

' gboolean notify_init (const char *app_name)
' Initialized libnotify.
Private Extern notify_init(app_name As String) As Boolean

' NotifyNotification * notify_notification_new (const char *summary, const char *body, const char *icon)
' Creates a new NotifyNotification.
Private Extern notify_notification_new(summary As String, body As String, icon As String) As Pointer

' GVariant* g_variant_new_string (const gchar* string)
' Creates a string GVariant with the contents of string.
Private Extern g_variant_new_string(_string As String) As Pointer

' void notify_notification_set_hint (NotifyNotification* notification, const char* key, GVariant* value)
' Sets a hint for key with value value.
Private Extern notify_notification_set_hint(notification As Pointer, key As String, value As Pointer)

' void notify_notification_set_urgency (NotifyNotification *notification, NotifyUrgency urgency)
' Sets the urgency level of this notification. 
Private Extern notify_notification_set_urgency(notification As Pointer, urgency As Integer)

' gboolean notify_notification_show (NotifyNotification *notification, GError **error)
' Tells the notification server to display the notification on the screen.
Private Extern notify_notification_show(notification As Pointer, gerror As Pointer)

' void g_object_unref (gpointer object)
' Decreases the reference count of object.
Private Extern g_object_unref(gobject As Pointer)


Public Sub Main()

 Dim nome As String
 Dim notify As Pointer
 
 nome = "Notifica"
 
 notify_init(nome)
   
 notify = notify_notification_new(nome, "Testo della notifica", Null)
 If notify == 0 Then Error.Raise("Errore !")

 gv = g_variant_new_string("/percorso/del/file/immagine")
 notify_notification_set_hint(notify, "image-path", gv)
   
' Imposta il livello di urgenza della notifica:
 notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL)
 notify_notification_show(notify, 0)
   
 g_object_unref(notify)

End


Riferimenti