NvDialog 0.10.1
A cross-platform modal dialogs library for C/C++ that uses the native OS theme.
Loading...
Searching...
No Matches
nvdialog_notification.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2025 Aggelos Tselios
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25#pragma once
26
27#ifndef __nvdialog_notification_h__
28#define __nvdialog_notification_h__ 1
29
30#include "nvdialog_platform.h"
31
32/**
33 * @brief Possible types of NvDialog notifications. Each field will create a
34 * slightly different dialog matching the requested type.
35 * @note Some systems may not provide compatible icons "out-of-the-box", usually minimalist Linux distros.
36 * @ingroup Notification
37 * @since v0.5.0
38 * @sa NvdNotification
39 */
40typedef enum {
41 NVD_NOTIFICATION_SIMPLE, /**< A simple notification eg. to notify of
42 something new in the app. */
43 NVD_NOTIFICATION_WARNING, /**< A warning notification. */
44 NVD_NOTIFICATION_ERROR /**< An error notification, preferably used
45 before crashing. */
47
48/**
49 * @brief The base notification type used by NvDialog.
50 *
51 * @details NvDialog offers since v0.5.0 support for basic notifications that
52 * add an extra cross-platform solution. The notification API is cross-platform
53 * and should reduce the required setup to send a simple notification. On GNU/Linux and other Unix-like platforms,
54 * the DBus interface for notifications is used, making it desktop-agnostic and only requiring libdbus and related daemons
55 * to be available.
56 *
57 * @ingroup Notification
58 * @sa nvd_notification_new
59 * @since v0.5.0
60 */
61typedef struct _NvdNotification NvdNotification;
62
63/**
64 * @brief Creates a new notification object and returns it.
65 * @param title The title of the notification, can be NULL if no title is
66 desired.
67 * @param msg The message to show (Required, can't be NULL).
68 * @param type The type of the notification, see @ref NvdNotifyType.
69 * <b>Example:</b>
70 * @code
71 #include <nvdialog/nvdialog.h>
72 int main(int argc, char** argv) {
73 nvd_init(argv[0]);
74 NvdNotification *notif = nvd_notification_new("Notification",
75 "A notification for your
76 app.", NVD_NOTIFICATION_SIMPLE); if (!notif) return -1;
77 nvd_send_notification(notif);
78 nvd_delete_notification(notif);
79 return 0;
80 }
81 * @endcode
82 * @ingroup Notification
83 * @return An empty notification object.
84 */
86 const char* msg,
87 NvdNotifyType type);
88
89/**
90 * @brief Sends the notification to the system.
91 * It's safe to assume that the same notification can be sent multiple times.
92 * Just make sure the notification is still valid (Not freed yet).
93 *
94 * @param notification The notification object to use.
95 * @ingroup Notification
96 * @since v0.5.0
97 */
99
100/**
101 * @brief Deletes a notification object from NvDialog.
102 * @note You should only use this to free notifications. <b>Do not use @ref
103 * nvd_free_object please.</b>
104 * @param notification The notification object to delete.
105 * @ingroup Notification
106 */
108
109/**
110 * @brief Adds another button with a specified action to do when it is clicked.
111 * @deprecated This function no longer works since v0.10.0. It was only limited to some platforms before so it has become a no-op.
112 * @param notification The notification to add the said action to.
113 * @param action A string defining the action as well as the label of the button
114 * for the action.
115 * @param value_to_set The value to set when the action is triggered.
116 * @param value_to_return A pointer to an integer to save the value passed to
117 * @ref value_to_set .
118 * @ingroup Notification
119 */
121 const char* action, int value_to_set,
122 int* value_to_return);
123#endif /* __nvdialog_notification_h__ */
#define NVD_API
Definition nvdialog.h:113
struct _NvdNotification NvdNotification
The base notification type used by NvDialog.
Definition nvdialog_notification.h:61
NVD_API void nvd_delete_notification(NvdNotification *notification)
Deletes a notification object from NvDialog.
NvdNotifyType
Possible types of NvDialog notifications. Each field will create a slightly different dialog matching...
Definition nvdialog_notification.h:40
@ NVD_NOTIFICATION_SIMPLE
Definition nvdialog_notification.h:41
@ NVD_NOTIFICATION_ERROR
Definition nvdialog_notification.h:44
@ NVD_NOTIFICATION_WARNING
Definition nvdialog_notification.h:43
NVD_API NvdNotification * nvd_notification_new(const char *title, const char *msg, NvdNotifyType type)
Creates a new notification object and returns it.
NVD_API void nvd_add_notification_action(NvdNotification *notification, const char *action, int value_to_set, int *value_to_return)
Adds another button with a specified action to do when it is clicked.
NVD_API void nvd_send_notification(NvdNotification *notification)
Sends the notification to the system. It's safe to assume that the same notification can be sent mult...