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) 2022 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#ifdef __cplusplus
33extern "C" {
34#endif /* __cplusplus */
35
36/**
37 * @brief Possible types of NvDialog notifications. Each field will create a
38 * slightly different dialog matching the requested type.
39 * @note Some systems may not provide compatible icons "out-of-the-box", usually minimalist Linux distros.
40 * @ingroup Notification
41 * @since v0.5.0
42 * @sa NvdNotification
43 */
44typedef enum {
45 NVD_NOTIFICATION_SIMPLE, /**< A simple notification eg. to notify of
46 something new in the app. */
47 NVD_NOTIFICATION_WARNING, /**< A warning notification. */
48 NVD_NOTIFICATION_ERROR /**< An error notification, preferably used
49 before crashing. */
51
52/**
53 * @brief The base notification type used by NvDialog.
54 *
55 * @details NvDialog offers since v0.5.0 support for basic notifications that
56 * add an extra cross-platform solution. The notification API is cross-platform
57 * and should reduce the required setup to send a simple notification. On GNU/Linux and other Unix-like platforms,
58 * the DBus interface for notifications is used, making it desktop-agnostic and only requiring libdbus and related daemons
59 * to be available.
60 *
61 * @ingroup Notification
62 * @sa nvd_notification_new
63 * @since v0.5.0
64 */
65typedef struct _NvdNotification NvdNotification;
66
67/**
68 * @brief Creates a new notification object and returns it.
69 * @param title The title of the notification, can be NULL if no title is
70 desired.
71 * @param msg The message to show (Required, can't be NULL).
72 * @param type The type of the notification, see @ref NvdNotifyType.
73 * <b>Example:</b>
74 * @code
75 #include <nvdialog/nvdialog.h>
76 int main(int argc, char** argv) {
77 nvd_init(argv[0]);
78 NvdNotification *notif = nvd_notification_new("Notification",
79 "A notification for your
80 app.", NVD_NOTIFICATION_SIMPLE); if (!notif) return -1;
81 nvd_send_notification(notif);
82 nvd_delete_notification(notif);
83 return 0;
84 }
85 * @endcode
86 * @ingroup Notification
87 * @return An empty notification object.
88 */
90 const char* msg,
91 NvdNotifyType type);
92
93/**
94 * @brief Sends the notification to the system.
95 * It's safe to assume that the same notification can be sent multiple times.
96 * Just make sure the notification is still valid (Not freed yet).
97 *
98 * @param notification The notification object to use.
99 * @ingroup Notification
100 * @since v0.5.0
101 */
103
104/**
105 * @brief Deletes a notification object from NvDialog.
106 * @note You should only use this to free notifications. <b>Do not use @ref
107 * nvd_free_object please.</b>
108 * @param notification The notification object to delete.
109 * @ingroup Notification
110 */
112
113/**
114 * @brief Adds another button with a specified action to do when it is clicked.
115 * @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.
116 * @param notification The notification to add the said action to.
117 * @param action A string defining the action as well as the label of the button
118 * for the action.
119 * @param value_to_set The value to set when the action is triggered.
120 * @param value_to_return A pointer to an integer to save the value passed to
121 * @ref value_to_set .
122 * @ingroup Notification
123 */
125 const char* action, int value_to_set,
126 int* value_to_return);
127
128#ifdef __cplusplus
129}
130#endif /* __cplusplus */
131
132#endif /* __nvdialog_notification_h__ */
struct _NvdNotification NvdNotification
The base notification type used by NvDialog.
Definition: nvdialog_notification.h:65
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:44
@ NVD_NOTIFICATION_SIMPLE
Definition: nvdialog_notification.h:45
@ NVD_NOTIFICATION_ERROR
Definition: nvdialog_notification.h:48
@ NVD_NOTIFICATION_WARNING
Definition: nvdialog_notification.h:47
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...
#define NVD_API
Definition: nvdialog_platform.h:57