File: nsAlertsIconListener.h

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (107 lines) | stat: -rw-r--r-- 4,112 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsAlertsIconListener_h__
#define nsAlertsIconListener_h__

#include "nsCOMPtr.h"
#include "nsIAlertsService.h"
#include "nsString.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"

#include <gdk-pixbuf/gdk-pixbuf.h>

class nsIAlertNotification;
class nsICancelable;
class nsSystemAlertsService;

struct NotifyNotification;

class nsAlertsIconListener : public nsIAlertNotificationImageListener {
 public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIALERTNOTIFICATIONIMAGELISTENER

  nsAlertsIconListener(nsSystemAlertsService* aBackend,
                       nsIAlertNotification* aAlertNotification,
                       const nsAString& aAlertName);

  nsresult InitAlertAsync(nsIAlertNotification* aAlert,
                          nsIObserver* aAlertListener);
  nsresult Close();

  void SendCallback();
  void SendActionCallback(const nsAString& aActionName);
  void SendClosed();
  void Disconnect();

 protected:
  virtual ~nsAlertsIconListener();

  /**
   * The only difference between libnotify.so.4 and libnotify.so.1 for these
   * symbols is that notify_notification_new takes three arguments in
   * libnotify.so.4 and four in libnotify.so.1. Passing the fourth argument as
   * NULL is binary compatible.
   */
  using NotifyActionCallback = void (*)(NotifyNotification*, char*, gpointer);
  using notify_is_initted_t = bool (*)();
  using notify_init_t = bool (*)(const char*);
  using notify_get_server_caps_t = GList* (*)();
  using notify_notification_new_t = NotifyNotification* (*)(const char*,
                                                            const char*,
                                                            const char*,
                                                            const char*);
  using notify_notification_show_t = bool (*)(void*, GError**);
  using notify_notification_set_icon_from_pixbuf_t = void (*)(void*,
                                                              GdkPixbuf*);
  using notify_notification_add_action_t = void (*)(void*, const char*,
                                                    const char*,
                                                    NotifyActionCallback,
                                                    gpointer, GFreeFunc);
  using notify_notification_close_t = bool (*)(void*, GError**);
  using notify_notification_set_hint_t = void (*)(NotifyNotification*,
                                                  const char*, GVariant*);
  using notify_notification_set_timeout_t = void (*)(NotifyNotification*, gint);

  nsCOMPtr<nsICancelable> mIconRequest;
  nsCString mAlertTitle;
  nsCString mAlertText;

  nsCOMPtr<nsIObserver> mAlertListener;
  nsString mAlertCookie;
  nsString mAlertName;

  RefPtr<nsSystemAlertsService> mBackend;
  nsCOMPtr<nsIAlertNotification> mAlertNotification;

  bool mAlertHasAction = false;
  bool mAlertIsSilent = false;
  bool mAlertRequiresInteraction = false;
  nsTArray<RefPtr<nsIAlertAction>> mActions;

  static void* libNotifyHandle;
  static bool libNotifyNotAvail;
  static notify_is_initted_t notify_is_initted;
  static notify_init_t notify_init;
  static notify_get_server_caps_t notify_get_server_caps;
  static notify_notification_new_t notify_notification_new;
  static notify_notification_show_t notify_notification_show;
  static notify_notification_set_icon_from_pixbuf_t
      notify_notification_set_icon_from_pixbuf;
  static notify_notification_add_action_t notify_notification_add_action;
  static notify_notification_close_t notify_notification_close;
  static notify_notification_set_hint_t notify_notification_set_hint;
  static notify_notification_set_timeout_t notify_notification_set_timeout;
  NotifyNotification* mNotification = nullptr;
  gulong mClosureHandler = 0;

  nsresult ShowAlert(GdkPixbuf* aPixbuf);

  void NotifyFinished();
};

#endif