aboutsummaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2012-08-09 18:32:31 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2012-08-09 18:32:31 +0000
commit038a5b038f9613e11d4b375868cda27c965f4027 (patch)
tree0c80e4e5d1111885c839d3365c3ba1e94a2ae0ef /src/net
parentb283f6522be737522deade794b46d7d0ff0b5f3c (diff)
downloadjitsi-038a5b038f9613e11d4b375868cda27c965f4027.zip
jitsi-038a5b038f9613e11d4b375868cda27c965f4027.tar.gz
jitsi-038a5b038f9613e11d4b375868cda27c965f4027.tar.bz2
Removes the "welcome" Growl notification on Jitsi startup. Improves the memory consumption and the execution speed of the growlnotification bundle. Prevents a NullPointerException during its stop on non-Mac OS X operating systems.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationActivator.java89
-rw-r--r--src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationServiceImpl.java118
-rw-r--r--src/net/java/sip/communicator/service/systray/event/SystrayPopupMessageEvent.java2
3 files changed, 81 insertions, 128 deletions
diff --git a/src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationActivator.java b/src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationActivator.java
index 51acfc0..003dacf 100644
--- a/src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationActivator.java
+++ b/src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationActivator.java
@@ -10,9 +10,8 @@ import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.service.systray.*;
import net.java.sip.communicator.util.*;
-import org.jitsi.service.configuration.*;
import org.jitsi.service.resources.*;
-import org.jitsi.util.OSUtils; // Disambiguation
+import org.jitsi.util.OSUtils; // disambiguation
import org.osgi.framework.*;
/**
@@ -20,6 +19,7 @@ import org.osgi.framework.*;
*
* @author Romain Kuntz
* @author Egidijus Jankauskas
+ * @author Lyubomir Marinov
*/
public class GrowlNotificationActivator
implements BundleActivator
@@ -30,17 +30,11 @@ public class GrowlNotificationActivator
public static BundleContext bundleContext;
/**
- * The <tt>Logger</tt> instance used by the
- * <tt>GrowlNotificationActivator</tt> class and its instances for logging
- * output.
+ * The <tt>Logger</tt> used by the <tt>GrowlNotificationActivator</tt> class
+ * and its instances for logging output.
*/
- private static final Logger logger =
- Logger.getLogger(GrowlNotificationActivator.class);
-
- /**
- * A reference to the configuration service.
- */
- private static ConfigurationService configService;
+ private static final Logger logger
+ = Logger.getLogger(GrowlNotificationActivator.class);
/**
* A reference to the resource management service.
@@ -53,62 +47,53 @@ public class GrowlNotificationActivator
private static GrowlNotificationServiceImpl handler;
/**
- * Initialize and start Growl Notifications Service
+ * Initializes and starts a new <tt>GrowlNotificationService</tt>
+ * implementation on Mac OS X.
*
- * @param bc BundleContext
- * @throws Exception if initializing and starting this service fails
+ * @param bundleContext the <tt>BundleContext</tt> to register the new
+ * <tt>GrowlNotificationService</tt> implementation into
+ * @throws Exception if initializing and/or starting the new
+ * <tt>GrowlNotificationService</tt> implementation fails
*/
- public void start(BundleContext bc) throws Exception
+ public void start(BundleContext bundleContext)
+ throws Exception
{
- // This bundle is only available for Mac os.
- if(!OSUtils.IS_MAC)
+ // This bundle is available for Mac OS X only.
+ if (!OSUtils.IS_MAC)
return;
if (logger.isInfoEnabled())
- logger.info("Growl Notification ...[Starting]");
- bundleContext = bc;
+ logger.info("Growl Notification... [Starting]");
- getConfigurationService();
+ GrowlNotificationActivator.bundleContext = bundleContext;
handler = new GrowlNotificationServiceImpl();
-
- handler.start(bc);
- bc.registerService(PopupMessageHandler.class.getName(), handler, null);
+ handler.start(bundleContext);
+ bundleContext.registerService(
+ PopupMessageHandler.class.getName(),
+ handler,
+ null);
if (logger.isInfoEnabled())
- logger.info("Growl Notification ...[Started]");
+ logger.info("Growl Notification... [Started]");
}
/**
* Stops this bundle.
*
- * @param bContext the <tt>BundleContext</tt>
- * @throws Exception if the stop operation goes wrong
+ * @param bundleContext the <tt>BundleContext</tt> to stop this bundle into
+ * @throws Exception if stopping this bundle fails
*/
- public void stop(BundleContext bContext) throws Exception
+ public void stop(BundleContext bundleContext)
+ throws Exception
{
- handler.stop(bContext);
- if (logger.isInfoEnabled())
- logger.info("Growl Notification Service ...[Stopped]");
- }
-
- /**
- * Returns the <tt>ConfigurationService</tt> obtained from the bundle
- * context.
- * @return the <tt>ConfigurationService</tt> obtained from the bundle
- * context
- */
- public static ConfigurationService getConfigurationService()
- {
- if(configService == null) {
- ServiceReference configReference = bundleContext
- .getServiceReference(ConfigurationService.class.getName());
-
- configService = (ConfigurationService) bundleContext
- .getService(configReference);
- }
+ // This bundle is available for Mac OS X only.
+ if (!OSUtils.IS_MAC)
+ return;
- return configService;
+ handler.stop(bundleContext);
+ if (logger.isInfoEnabled())
+ logger.info("Growl Notification Service... [Stopped]");
}
/**
@@ -120,8 +105,10 @@ public class GrowlNotificationActivator
public static ResourceManagementService getResources()
{
if (resourcesService == null)
- resourcesService =
- ResourceManagementServiceUtils.getService(bundleContext);
+ {
+ resourcesService
+ = ResourceManagementServiceUtils.getService(bundleContext);
+ }
return resourcesService;
}
}
diff --git a/src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationServiceImpl.java b/src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationServiceImpl.java
index cd32529..099cb24 100644
--- a/src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/growlnotification/GrowlNotificationServiceImpl.java
@@ -6,45 +6,44 @@
*/
package net.java.sip.communicator.impl.growlnotification;
-import java.util.*;
-
import net.java.sip.communicator.service.systray.*;
import net.java.sip.communicator.service.systray.event.*;
import net.java.sip.communicator.util.*;
import org.growl4j.*;
+import org.jitsi.service.resources.*;
import org.osgi.framework.*;
-// TODO Use a better icon in registration.
-
/**
* The Growl Notification Service displays on-screen information such as
* messages or call received, etc.
*
* @author Romain Kuntz
* @author Egidijus Jankauskas
+ * @author Lyubomir Marinov
*/
public class GrowlNotificationServiceImpl
extends AbstractPopupMessageHandler
implements GrowlCallbacksListener
{
/**
- * The logger for this class.
+ * The <tt>Logger</tt> used by the <tt>GrowlNotificationServiceImpl</tt>
+ * class and its instance for logging output.
*/
- private static Logger logger =
- Logger.getLogger(GrowlNotificationServiceImpl.class);
+ private static final Logger logger
+ = Logger.getLogger(GrowlNotificationServiceImpl.class);
/**
- * A variable that acts as a buffer to temporarily keep all PopupMessages
- * that were sent to Growl Daemon.
+ * The notification type (in Growl terms) to be specified to
+ * {@link Growl#notifyGrowlOf(String, String, String, byte[], Object)}
+ * when called by {@link #showPopupMessage(PopupMessage)}.
*/
- private static final HashMap<Long, PopupMessage> shownPopups =
- new HashMap<Long, PopupMessage>(10);
+ private static final String SHOW_POPUP_MESSAGE_TYPE = "Default";
/**
* The <tt>Growl</tt> object.
*/
- private Growl growl = null;
+ private Growl growl;
/**
* Starts the service. Creates a Growl notifier, and check the current
@@ -58,26 +57,21 @@ public class GrowlNotificationServiceImpl
if (logger.isDebugEnabled())
logger.debug("Starting the Growl Notification implementation.");
- String[] dict = { "Default", "Welcome message" };
- byte[] sipIcon = GrowlNotificationActivator.getResources().
- getImageInBytes("service.gui.SIP_COMMUNICATOR_LOGO_45x45");
- growl = new Growl (
- GrowlNotificationActivator.getResources()
- .getSettingsString("service.gui.APPLICATION_NAME"),
- "net.sip-communicator",
- sipIcon,
- dict,
- dict);
+ ResourceManagementService resources
+ = GrowlNotificationActivator.getResources();
+ byte[] sipIcon
+ = resources.getImageInBytes(
+ "service.gui.SIP_COMMUNICATOR_LOGO_45x45");
+ String[] dict = { SHOW_POPUP_MESSAGE_TYPE };
+
+ growl
+ = new Growl(
+ resources.getSettingsString("service.gui.APPLICATION_NAME"),
+ "net.sip-communicator",
+ sipIcon,
+ dict,
+ dict);
growl.addClickedNotificationsListener(this);
-
- growl.notifyGrowlOf(
- GrowlNotificationActivator.getResources()
- .getSettingsString("service.gui.APPLICATION_NAME"),
- GrowlNotificationActivator.getResources()
- .getSettingsString("service.gui.APPLICATION_WEB_SITE"),
- "Welcome message",
- null,
- null);
}
/**
@@ -90,31 +84,17 @@ public class GrowlNotificationServiceImpl
if (growl != null)
{
growl.doFinalCleanUp();
+ growl = null;
}
}
/**
- * Checks if Growl is running
- *
- * @return <tt>true</tt> if Growl is running and <tt>false</tt> otherwise
- */
- public boolean isGrowlRunning()
- {
- return Growl.isGrowlRunning();
- }
-
- /**
* Implements <tt>PopupMessageHandler#showPopupMessage()</tt>
*
* @param popupMessage the message we will show
*/
public void showPopupMessage(PopupMessage popupMessage)
{
- long timestamp = System.currentTimeMillis();
- synchronized(shownPopups) {
- shownPopups.put(timestamp, popupMessage);
- }
-
String messageBody = popupMessage.getMessage();
String messageTitle = popupMessage.getMessageTitle();
@@ -122,50 +102,35 @@ public class GrowlNotificationServiceImpl
messageBody = messageBody.replaceAll("</?\\w++[^>]*+>", "");
messageTitle = messageTitle.replaceAll("</?\\w++[^>]*+>", "");
- growl.notifyGrowlOf(messageTitle,
- messageBody,
- "Default",
- popupMessage.getIcon(),
- timestamp);
+ growl.notifyGrowlOf(
+ messageTitle,
+ messageBody,
+ SHOW_POPUP_MESSAGE_TYPE,
+ popupMessage.getIcon(),
+ popupMessage.getTag());
}
/**
* This method is called by Growl when the Growl notification is not clicked
*
- * @param context is an object that is used to identify sent notification
+ * @param context an object identifying the notification
*/
public void growlNotificationTimedOut(Object context)
{
- PopupMessage m = shownPopups.get(context);
- if (m != null) {
- synchronized(shownPopups) {
- shownPopups.remove(context);
- }
- if (logger.isTraceEnabled())
- logger.trace("Growl notification timed-out :" +
- m.getMessageTitle() + ": " + m.getMessage());
- }
+ if (logger.isTraceEnabled())
+ logger.trace("Growl notification timed out: " + context);
}
/**
* This method is called by Growl when the Growl notification is clicked
*
- * @param context is an object that is used to identify sent notification
+ * @param context an object identifying the notification
*/
public void growlNotificationWasClicked(Object context)
{
- PopupMessage m = shownPopups.get(context);
- if (m != null) {
- synchronized(shownPopups) {
- shownPopups.remove(context);
- }
-
- firePopupMessageClicked(new SystrayPopupMessageEvent(this,
- m.getTag()));
- if (logger.isTraceEnabled())
- logger.trace("Growl message clicked :" +
- m.getMessageTitle() + ": " + m.getMessage());
- }
+ firePopupMessageClicked(new SystrayPopupMessageEvent(this, context));
+ if (logger.isTraceEnabled())
+ logger.trace("Growl notification clicked: " + context);
}
/**
@@ -176,8 +141,9 @@ public class GrowlNotificationServiceImpl
@Override
public String toString()
{
- return GrowlNotificationActivator.getResources()
- .getI18NString("impl.growlnotification.POPUP_MESSAGE_HANDLER");
+ return
+ GrowlNotificationActivator.getResources().getI18NString(
+ "impl.growlnotification.POPUP_MESSAGE_HANDLER");
}
/**
diff --git a/src/net/java/sip/communicator/service/systray/event/SystrayPopupMessageEvent.java b/src/net/java/sip/communicator/service/systray/event/SystrayPopupMessageEvent.java
index 1df0a64..a21b38e 100644
--- a/src/net/java/sip/communicator/service/systray/event/SystrayPopupMessageEvent.java
+++ b/src/net/java/sip/communicator/service/systray/event/SystrayPopupMessageEvent.java
@@ -32,7 +32,7 @@ public class SystrayPopupMessageEvent
*/
public SystrayPopupMessageEvent(Object source)
{
- super(source);
+ this(source, null);
}
/**