e75128
# HG changeset patch
e75128
# Parent b17cad2d1e5e6bcb5a10096d51d07ea8a79b6921
e75128
# User Martin Stransky <stransky@redhat.com>
e75128
Bug 858919 - Add support for libnotify calls which was removed for new notification API. r=karlt
e75128
e75128
diff --git a/toolkit/system/gnome/moz.build b/toolkit/system/gnome/moz.build
e75128
--- a/toolkit/system/gnome/moz.build
e75128
+++ b/toolkit/system/gnome/moz.build
e75128
@@ -1,15 +1,17 @@
e75128
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
e75128
 # vim: set filetype=python:
e75128
 # This Source Code Form is subject to the terms of the Mozilla Public
e75128
 # License, v. 2.0. If a copy of the MPL was not distributed with this
e75128
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
e75128
 
e75128
 SOURCES += [
e75128
+    'nsAlertsIconListener.cpp',
e75128
+    'nsAlertsService.cpp',
e75128
     'nsGnomeModule.cpp',
e75128
 ]
e75128
 
e75128
 if CONFIG['MOZ_ENABLE_GCONF']:
e75128
     SOURCES += [
e75128
         'nsGConfService.cpp',
e75128
     ]
e75128
 
e75128
diff --git a/toolkit/system/gnome/nsAlertsIconListener.h b/toolkit/system/gnome/nsAlertsIconListener.h
e75128
new file mode 100644
e75128
--- /dev/null
e75128
+++ b/toolkit/system/gnome/nsAlertsIconListener.h
e75128
@@ -0,0 +1,89 @@
e75128
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
e75128
+/* This Source Code Form is subject to the terms of the Mozilla Public
e75128
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
e75128
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
e75128
+
e75128
+#ifndef nsAlertsIconListener_h__
e75128
+#define nsAlertsIconListener_h__
e75128
+
e75128
+#include "nsCOMPtr.h"
e75128
+#include "imgINotificationObserver.h"
e75128
+#include "nsStringAPI.h"
e75128
+#include "nsIObserver.h"
e75128
+#include "nsWeakReference.h"
e75128
+
e75128
+#include <gdk-pixbuf/gdk-pixbuf.h>
e75128
+
e75128
+class imgIRequest;
e75128
+
e75128
+struct NotifyNotification;
e75128
+
e75128
+class nsAlertsIconListener : public imgINotificationObserver,
e75128
+                             public nsIObserver,
e75128
+                             public nsSupportsWeakReference
e75128
+{
e75128
+public:
e75128
+  NS_DECL_ISUPPORTS
e75128
+  NS_DECL_IMGINOTIFICATIONOBSERVER
e75128
+  NS_DECL_NSIOBSERVER
e75128
+
e75128
+  nsAlertsIconListener();
e75128
+
e75128
+  nsresult InitAlertAsync(const nsAString & aImageUrl,
e75128
+                          const nsAString & aAlertTitle, 
e75128
+                          const nsAString & aAlertText,
e75128
+                          bool aAlertTextClickable,
e75128
+                          const nsAString & aAlertCookie,
e75128
+                          nsIObserver * aAlertListener);
e75128
+
e75128
+  void SendCallback();
e75128
+  void SendClosed();
e75128
+
e75128
+protected:
e75128
+  virtual ~nsAlertsIconListener();
e75128
+
e75128
+  nsresult OnStopRequest(imgIRequest* aRequest);
e75128
+  nsresult OnStopFrame(imgIRequest* aRequest);
e75128
+
e75128
+  /**
e75128
+   * The only difference between libnotify.so.4 and libnotify.so.1 for these symbols
e75128
+   * is that notify_notification_new takes three arguments in libnotify.so.4 and
e75128
+   * four in libnotify.so.1.
e75128
+   * Passing the fourth argument as NULL is binary compatible.
e75128
+   */
e75128
+  typedef void (*NotifyActionCallback)(NotifyNotification*, char*, gpointer);
e75128
+  typedef bool (*notify_is_initted_t)(void);
e75128
+  typedef bool (*notify_init_t)(const char*);
e75128
+  typedef GList* (*notify_get_server_caps_t)(void);
e75128
+  typedef NotifyNotification* (*notify_notification_new_t)(const char*, const char*, const char*, const char*);
e75128
+  typedef bool (*notify_notification_show_t)(void*, char*);
e75128
+  typedef void (*notify_notification_set_icon_from_pixbuf_t)(void*, GdkPixbuf*);
e75128
+  typedef void (*notify_notification_add_action_t)(void*, const char*, const char*, NotifyActionCallback, gpointer, GFreeFunc);
e75128
+
e75128
+  nsCOMPtr<imgIRequest> mIconRequest;
e75128
+  nsCString mAlertTitle;
e75128
+  nsCString mAlertText;
e75128
+
e75128
+  nsCOMPtr<nsIObserver> mAlertListener;
e75128
+  nsString mAlertCookie;
e75128
+
e75128
+  bool mLoadedFrame;
e75128
+  bool mAlertHasAction;
e75128
+
e75128
+  static void* libNotifyHandle;
e75128
+  static bool libNotifyNotAvail;
e75128
+  static notify_is_initted_t notify_is_initted;
e75128
+  static notify_init_t notify_init;
e75128
+  static notify_get_server_caps_t notify_get_server_caps;
e75128
+  static notify_notification_new_t notify_notification_new;
e75128
+  static notify_notification_show_t notify_notification_show;
e75128
+  static notify_notification_set_icon_from_pixbuf_t notify_notification_set_icon_from_pixbuf;
e75128
+  static notify_notification_add_action_t notify_notification_add_action;
e75128
+  NotifyNotification* mNotification;
e75128
+  gulong mClosureHandler;
e75128
+
e75128
+  nsresult StartRequest(const nsAString & aImageUrl);
e75128
+  nsresult ShowAlert(GdkPixbuf* aPixbuf);
e75128
+};
e75128
+
e75128
+#endif
e75128
diff --git a/toolkit/system/gnome/nsAlertsService.cpp b/toolkit/system/gnome/nsAlertsService.cpp
e75128
new file mode 100644
e75128
--- /dev/null
e75128
+++ b/toolkit/system/gnome/nsAlertsService.cpp
e75128
@@ -0,0 +1,53 @@
e75128
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode:nil; c-basic-offset: 2 -*- */
e75128
+/* This Source Code Form is subject to the terms of the Mozilla Public
e75128
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
e75128
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
e75128
+
e75128
+#include "nsXULAppAPI.h"
e75128
+#include "nsAlertsService.h"
e75128
+#include "nsAlertsIconListener.h"
e75128
+#include "nsAutoPtr.h"
e75128
+
e75128
+NS_IMPL_ADDREF(nsAlertsService)
e75128
+NS_IMPL_RELEASE(nsAlertsService)
e75128
+
e75128
+NS_INTERFACE_MAP_BEGIN(nsAlertsService)
e75128
+   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAlertsService)
e75128
+   NS_INTERFACE_MAP_ENTRY(nsIAlertsService)
e75128
+NS_INTERFACE_MAP_END_THREADSAFE
e75128
+
e75128
+nsAlertsService::nsAlertsService()
e75128
+{
e75128
+}
e75128
+
e75128
+nsAlertsService::~nsAlertsService()
e75128
+{}
e75128
+
e75128
+nsresult
e75128
+nsAlertsService::Init()
e75128
+{
e75128
+  return NS_OK;
e75128
+}
e75128
+
e75128
+NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl, const nsAString & aAlertTitle, 
e75128
+                                                     const nsAString & aAlertText, bool aAlertTextClickable,
e75128
+                                                     const nsAString & aAlertCookie,
e75128
+                                                     nsIObserver * aAlertListener,
e75128
+                                                     const nsAString & aAlertName,
e75128
+                                                     const nsAString & aBidi,
e75128
+                                                     const nsAString & aLang,
e75128
+                                                     nsIPrincipal * aPrincipal)
e75128
+{
e75128
+  nsRefPtr<nsAlertsIconListener> alertListener = new nsAlertsIconListener();
e75128
+  if (!alertListener)
e75128
+    return NS_ERROR_OUT_OF_MEMORY;
e75128
+
e75128
+  return alertListener->InitAlertAsync(aImageUrl, aAlertTitle, aAlertText, aAlertTextClickable,
e75128
+                                       aAlertCookie, aAlertListener);
e75128
+}
e75128
+
e75128
+NS_IMETHODIMP nsAlertsService::CloseAlert(const nsAString& aAlertName,
e75128
+                                          nsIPrincipal* aPrincipal)
e75128
+{
e75128
+  return NS_ERROR_NOT_IMPLEMENTED;
e75128
+}
e75128
diff --git a/toolkit/system/gnome/nsAlertsService.h b/toolkit/system/gnome/nsAlertsService.h
e75128
new file mode 100644
e75128
--- /dev/null
e75128
+++ b/toolkit/system/gnome/nsAlertsService.h
e75128
@@ -0,0 +1,27 @@
e75128
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
e75128
+/* This Source Code Form is subject to the terms of the Mozilla Public
e75128
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
e75128
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
e75128
+
e75128
+#ifndef nsAlertsService_h__
e75128
+#define nsAlertsService_h__
e75128
+
e75128
+#include "nsIAlertsService.h"
e75128
+#include "nsCOMPtr.h"
e75128
+
e75128
+class nsAlertsService : public nsIAlertsService
e75128
+{
e75128
+public:
e75128
+  NS_DECL_NSIALERTSSERVICE
e75128
+  NS_DECL_ISUPPORTS
e75128
+
e75128
+  nsAlertsService();
e75128
+
e75128
+  nsresult Init();
e75128
+
e75128
+protected:
e75128
+  virtual ~nsAlertsService();
e75128
+
e75128
+};
e75128
+
e75128
+#endif /* nsAlertsService_h__ */
e75128
diff --git a/toolkit/system/gnome/nsGnomeModule.cpp b/toolkit/system/gnome/nsGnomeModule.cpp
e75128
--- a/toolkit/system/gnome/nsGnomeModule.cpp
e75128
+++ b/toolkit/system/gnome/nsGnomeModule.cpp
e75128
@@ -17,53 +17,58 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGC
e75128
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGnomeVFSService, Init)
e75128
 #endif
e75128
 #ifdef MOZ_ENABLE_GIO
e75128
 #include "nsGIOService.h"
e75128
 #include "nsGSettingsService.h"
e75128
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsGIOService)
e75128
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGSettingsService, Init)
e75128
 #endif
e75128
+#include "nsAlertsService.h"
e75128
+NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAlertsService, Init)
e75128
 
e75128
 #ifdef MOZ_ENABLE_GCONF
e75128
 NS_DEFINE_NAMED_CID(NS_GCONFSERVICE_CID);
e75128
 #endif
e75128
 #ifdef MOZ_ENABLE_GNOMEVFS
e75128
 NS_DEFINE_NAMED_CID(NS_GNOMEVFSSERVICE_CID);
e75128
 #endif
e75128
 #ifdef MOZ_ENABLE_GIO
e75128
 NS_DEFINE_NAMED_CID(NS_GIOSERVICE_CID);
e75128
 NS_DEFINE_NAMED_CID(NS_GSETTINGSSERVICE_CID);
e75128
 #endif
e75128
+NS_DEFINE_NAMED_CID(NS_SYSTEMALERTSSERVICE_CID);
e75128
 
e75128
 static const mozilla::Module::CIDEntry kGnomeCIDs[] = {
e75128
 #ifdef MOZ_ENABLE_GCONF
e75128
   { &kNS_GCONFSERVICE_CID, false, nullptr, nsGConfServiceConstructor },
e75128
 #endif
e75128
 #ifdef MOZ_ENABLE_GNOMEVFS
e75128
   { &kNS_GNOMEVFSSERVICE_CID, false, nullptr, nsGnomeVFSServiceConstructor },
e75128
 #endif
e75128
 #ifdef MOZ_ENABLE_GIO
e75128
   { &kNS_GIOSERVICE_CID, false, nullptr, nsGIOServiceConstructor },
e75128
   { &kNS_GSETTINGSSERVICE_CID, false, nullptr, nsGSettingsServiceConstructor },
e75128
 #endif
e75128
+  { &kNS_SYSTEMALERTSSERVICE_CID, false, nullptr, nsAlertsServiceConstructor },
e75128
   { nullptr }
e75128
 };
e75128
 
e75128
 static const mozilla::Module::ContractIDEntry kGnomeContracts[] = {
e75128
 #ifdef MOZ_ENABLE_GCONF
e75128
   { NS_GCONFSERVICE_CONTRACTID, &kNS_GCONFSERVICE_CID },
e75128
 #endif
e75128
 #ifdef MOZ_ENABLE_GNOMEVFS
e75128
   { NS_GNOMEVFSSERVICE_CONTRACTID, &kNS_GNOMEVFSSERVICE_CID },
e75128
 #endif
e75128
 #ifdef MOZ_ENABLE_GIO
e75128
   { NS_GIOSERVICE_CONTRACTID, &kNS_GIOSERVICE_CID },
e75128
   { NS_GSETTINGSSERVICE_CONTRACTID, &kNS_GSETTINGSSERVICE_CID },
e75128
 #endif
e75128
+  { NS_SYSTEMALERTSERVICE_CONTRACTID, &kNS_SYSTEMALERTSSERVICE_CID },
e75128
   { nullptr }
e75128
 };
e75128
 
e75128
 static nsresult
e75128
 InitGType ()
e75128
 {
e75128
   g_type_init();
e75128
   return NS_OK;