[jitsi~svn:9878] Makes the "toggle video" button in the call window active only if we're r


#1

Nice! I've been bothered by this one for quite a while!!

Emil

···

---------- Forwarded message ----------

From: <bgrozev@java.net>

Date: Wed, Sep 26, 2012 at 11:29 AM
Subject: [jitsi~svn:9878] Makes the "toggle video" button in the call
window active only if we're r
To: commits@jitsi.java.net

Project: jitsi
Repository: svn
Revision: 9878
Author: bgrozev
Date: 2012-09-26 09:29:34 UTC
Link:

Log Message:
------------
Makes the "toggle video" button in the call window active only if
we're ready to send video, and shows an appropriate tooltip otherwise.
Same for the desktop sharing button.

Revisions:
----------
9878

Modified Paths:
---------------
trunk/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf
trunk/src/net/java/sip/communicator/impl/gui/main/call/LocalVideoButton.java
trunk/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java
trunk/lib/installer-exclude/libjitsi.jar
trunk/src/net/java/sip/communicator/impl/gui/main/call/DesktopSharingButton.java
libjitsi/src/org/jitsi/service/neomedia/codec/EncodingConfiguration.java
trunk/resources/languages/resources.properties
trunk/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java
trunk/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java

Diffs:
------
Index: trunk/lib/installer-exclude/libjitsi.jar

Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java

--- trunk/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java
       (revision 9877)
+++ trunk/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java
       (revision 9878)
@@ -8,12 +8,15 @@

import java.awt.*;
import java.beans.*;
-import java.util.List;
+import java.util.*;
+import java.util.List; /* disambiguation */

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.service.protocol.*;

import org.jitsi.service.configuration.*;
+import org.jitsi.service.neomedia.*;
+import org.jitsi.service.neomedia.codec.*;
import org.osgi.framework.*;

/**
@@ -2021,4 +2024,38 @@

         return className.substring(0, className.lastIndexOf('.'));
     }
+
+ /**
+ * Returns <tt>true</tt> if the account associated with
+ * <tt>protocolProvider</tt> has at least one video format enabled in it's
+ * configuration, <tt>false</tt> otherwise.
+ *
+ * @return <tt>true</tt> if the account associated with
+ * <tt>protocolProvider</tt> has at least one video format enabled in it's
+ * configuration, <tt>false</tt> otherwise.
+ */
+ public static boolean hasEnabledVideoFormat(
+ ProtocolProviderService protocolProvider)
+ {
+ Map<String, String> accountProperties
+ = protocolProvider.getAccountID().getAccountProperties();
+
+ EncodingConfiguration encodingConfiguration;
+ String overrideEncodings = accountProperties
+ .get(ProtocolProviderFactory.OVERRIDE_ENCODINGS);
+ if(Boolean.parseBoolean(overrideEncodings))
+ {
+ encodingConfiguration = GuiActivator.getMediaService().
+ createEmptyEncodingConfiguration();
+ encodingConfiguration.loadProperties(accountProperties,
+ ProtocolProviderFactory.ENCODING_PROP_PREFIX);
+ }
+ else
+ {
+ encodingConfiguration = GuiActivator.getMediaService().
+ getCurrentEncodingConfiguration();
+ }
+
+ return encodingConfiguration.hasEnabledFormat(MediaType.VIDEO);
+ }
}
Index: trunk/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java

--- trunk/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java
      (revision 9877)
+++ trunk/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java
      (revision 9878)
@@ -29,8 +29,6 @@
import net.java.sip.communicator.util.skin.*;
import net.java.sip.communicator.util.swing.*;

-import org.jitsi.service.neomedia.*;
-import org.jitsi.service.neomedia.device.*;
import org.jitsi.util.*;
import org.osgi.framework.*;

@@ -735,6 +733,8 @@
     {
         dialButton.setEnabled(!hold);

+ videoButton.setEnabled(!hold);
+
         ProtocolProviderService protocolProvider
         = call.getProtocolProvider();

@@ -742,41 +742,25 @@
             = protocolProvider.getOperationSet(
                     OperationSetVideoTelephony.class);

- MediaDevice videoDevice = GuiActivator.getMediaService()
- .getDefaultDevice(MediaType.VIDEO, MediaUseCase.CALL);
+ // If the video was already enabled (for example in the case of
+ // direct video call) make sure the video button is selected.
+ if (videoTelephony != null &&
+ videoTelephony.isLocalVideoAllowed(call) &&
+ !videoButton.isSelected())
+ setVideoButtonSelected(!hold);

- // If the video telephony is supported and the default video device
- // isn't null, i.e. there's an available camera to the video we
- // enable the video button.
- if (videoTelephony != null && videoDevice != null)
- {
- videoButton.setEnabled(!hold);
-
- // If the video was already enabled (for example in the case of
- // direct video call) make sure the video button is selected.
- if (videoTelephony.isLocalVideoAllowed(call)
- && !videoButton.isSelected())
- setVideoButtonSelected(!hold);
- }
- else if (videoDevice == null)
- videoButton.setToolTipText(GuiActivator.getResources()
- .getI18NString("service.gui.NO_CAMERA_AVAILABLE"));
-
         OperationSetDesktopSharingServer desktopSharing
             = protocolProvider.getOperationSet(
                 OperationSetDesktopSharingServer.class);

- if (desktopSharing != null)
- {
- desktopSharingButton.setEnabled(!hold);
-
- // If the video was already enabled (for example in the case of
- // direct desktop sharing call) make sure the video button is
- // selected.
- if (desktopSharing.isLocalVideoAllowed(call)
- && !desktopSharingButton.isSelected())
- setDesktopSharingButtonSelected(!hold);
- }
+ desktopSharingButton.setEnabled(!hold);
+ // If the video was already enabled (for example in the case of
+ // direct desktop sharing call) make sure the video button is
+ // selected.
+ if (desktopSharing != null &&
+ desktopSharing.isLocalVideoAllowed(call) &&
+ !desktopSharingButton.isSelected())
+ setDesktopSharingButtonSelected(!hold);
     }

     /**
@@ -807,12 +791,8 @@
             conferenceButton.setEnabled(enable);
         }

- if (protocolProvider.getOperationSet(OperationSetVideoTelephony.class)
- != null
- && videoButton != null)
- {
+ if (videoButton != null)
             videoButton.setEnabled(enable);
- }

         if (!isLastConference)
         {
Index: trunk/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java

--- trunk/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java
    (revision 9877)
+++ trunk/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java
    (revision 9878)
@@ -96,8 +96,10 @@
             }

             Call sourceCall = event.getSourceCall();
+ boolean isVideoCall = event.isVideoCall() && ConfigurationManager
+ .hasEnabledVideoFormat(sourceCall.getProtocolProvider());
             final ReceivedCallDialog receivedCallDialog
- = new ReceivedCallDialog(sourceCall, event.isVideoCall(),
+ = new ReceivedCallDialog(sourceCall, isVideoCall,
                     (CallManager.getActiveCalls().size() > 0));

             receivedCallDialog.setVisible(true);
Index: trunk/src/net/java/sip/communicator/impl/gui/main/call/LocalVideoButton.java

--- trunk/src/net/java/sip/communicator/impl/gui/main/call/LocalVideoButton.java
       (revision 9877)
+++ trunk/src/net/java/sip/communicator/impl/gui/main/call/LocalVideoButton.java
       (revision 9878)
@@ -29,6 +29,12 @@
     private static final long serialVersionUID = 0L;

     /**
+ * Whether video is enabled. If this is <tt>false</tt>, calls to
+ * <tt>setEnabled(true)</tt> will NOT enable the button.
+ */
+ private boolean videoAvailable;
+
+ /**
      * Creates a <tt>LocalVideoButton</tt> by specifying the corresponding
      * <tt>call</tt>.
      * @param call the corresponding to this button call
@@ -59,14 +65,43 @@
             ImageLoader.LOCAL_VIDEO_BUTTON_PRESSED,
             "service.gui.LOCAL_VIDEO_BUTTON_TOOL_TIP");

- MediaDevice videoDevice
- = GuiActivator.getMediaService().getDefaultDevice(MediaType.VIDEO,
- MediaUseCase.CALL);
- if (videoDevice == null
- || videoDevice.getDirection().equals(MediaDirection.RECVONLY))
+
+ OperationSetVideoTelephony videoTelephony
+ = call.getProtocolProvider().getOperationSet(
+ OperationSetVideoTelephony.class);
+
+ MediaDevice videoDevice = GuiActivator.getMediaService()
+ .getDefaultDevice(MediaType.VIDEO, MediaUseCase.CALL);
+
+ /* Check whether we can send video and set the appropriate tooltip */
+ if(videoDevice == null ||
+ videoDevice.getDirection().equals(MediaDirection.RECVONLY))
         {
- this.setEnabled(false);
+ setToolTipText(GuiActivator.getResources()
+ .getI18NString("service.gui.NO_CAMERA_AVAILABLE"));
+ videoAvailable = false;
         }
+ else if (videoTelephony == null)
+ {
+ setToolTipText(GuiActivator.getResources()
+ .getI18NString("service.gui.NO_VIDEO_FOR_PROTOCOL"));
+ videoAvailable = false;
+ }
+ else if(!ConfigurationManager.hasEnabledVideoFormat(
+ call.getProtocolProvider()))
+ {
+ setToolTipText(GuiActivator.getResources()
+ .getI18NString("service.gui.NO_VIDEO_ENCODINGS"));
+ videoAvailable = false;
+ }
+ else
+ {
+ setToolTipText(GuiActivator.getResources()
+ .getI18NString("service.gui.LOCAL_VIDEO_BUTTON_TOOL_TIP"));
+ videoAvailable = true;
+ }
+
+ super.setEnabled(videoAvailable);
     }

     /**
@@ -77,4 +112,18 @@
         CallManager.enableLocalVideo(call,
             !CallManager.isLocalVideoEnabled(call));
     }
+
+ /**
+ * Enables/disables the button. If <tt>this.videoAvailable</tt> is false,
+ * keeps the button as it is (i.e. disabled).
+ *
+ * @param enable <tt>true</tt> to enable the button, <tt>false</tt> to
+ * disable it.
+ */
+ @Override
+ public void setEnabled(boolean enable)
+ {
+ if(videoAvailable)
+ super.setEnabled(enable);
+ }
}
Index: trunk/src/net/java/sip/communicator/impl/gui/main/call/DesktopSharingButton.java

--- trunk/src/net/java/sip/communicator/impl/gui/main/call/DesktopSharingButton.java
   (revision 9877)
+++ trunk/src/net/java/sip/communicator/impl/gui/main/call/DesktopSharingButton.java
   (revision 9878)
@@ -25,6 +25,12 @@
     extends AbstractCallToggleButton
{
     /**
+ * Whether desktop sharing is enabled. If false, calls to
+ * <tt>setEnabled(true)</tt> will NOT enable the button.
+ */
+ private boolean desktopSharingAvailable;
+
+ /**
      * Initializes a new <tt>DesktopSharingButton</tt> instance which is meant
      * to be used to initiate a desktop sharing during a call.
      *
@@ -54,6 +60,31 @@
                 selected,
                 ImageLoader.CALL_DESKTOP_BUTTON,
                 "service.gui.SHARE_DESKTOP_WITH_CONTACT");
+
+ OperationSetDesktopSharingServer desktopSharing
+ = call.getProtocolProvider().getOperationSet(
+ OperationSetDesktopSharingServer.class);
+
+ if (desktopSharing == null)
+ {
+ setToolTipText(GuiActivator.getResources()
+ .getI18NString("NO_DESKTOP_SHARING_FOR_PROTOCOL"));
+ desktopSharingAvailable = false;
+ }
+ else if(!ConfigurationManager.hasEnabledVideoFormat(
+ call.getProtocolProvider()))
+ {
+ setToolTipText(GuiActivator.getResources()
+ .getI18NString("service.gui.NO_VIDEO_ENCODINGS"));
+ desktopSharingAvailable = false;
+ }
+ else
+ {
+ setToolTipText(GuiActivator.getResources()
+ .getI18NString("service.gui.SHARE_DESKTOP_WITH_CONTACT"));
+ desktopSharingAvailable = true;
+ }
+ super.setEnabled(desktopSharingAvailable);
     }

     /**
@@ -136,4 +167,18 @@

         return popupMenu;
     }
+
+ /**
+ * Enables/disables the button. If <tt>this.desktopSharingAvailable</tt> is
+ * false, keeps the button as it is (i.e. disabled).
+ *
+ * @param enable <tt>true</tt> to enable the button, <tt>false</tt> to
+ * disable it.
+ */
+ @Override
+ public void setEnabled(boolean enable)
+ {
+ if(desktopSharingAvailable)
+ super.setEnabled(enable);
+ }
}
Index: trunk/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf

--- trunk/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf
(revision 9877)
+++ trunk/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf
(revision 9878)
@@ -58,8 +58,9 @@
  org.jitsi.service.configuration,
  org.jitsi.service.fileaccess,
  org.jitsi.service.neomedia,
+ org.jitsi.service.neomedia.codec,
+ org.jitsi.service.neomedia.device,
  org.jitsi.service.neomedia.event,
- org.jitsi.service.neomedia.device,
  org.jitsi.service.neomedia.format,
  org.jitsi.service.protocol,
  org.jitsi.service.protocol.event,
Index: trunk/resources/languages/resources.properties

--- trunk/resources/languages/resources.properties (revision 9877)
+++ trunk/resources/languages/resources.properties (revision 9878)
@@ -325,6 +325,8 @@
service.gui.NO=No
service.gui.NONE=None
service.gui.NO_CAMERA_AVAILABLE=No camera available
+service.gui.NO_VIDEO_ENCODINGS=No video encodings are selected in configuration
+service.gui.NO_VIDEO_FOR_PROTOCOL=Video is not supported for this protocol
service.gui.NO_AVAILABLE_ROOMS=The list of rooms for this server is
currently not available.
service.gui.NO_CONTACTS_FOUND=No matching contacts found. Press
Ctrl+Enter to call {0} or use the buttons below.
service.gui.NO_CONTACTS_FOUND_SHORT=No matching contacts found.
Index: libjitsi/src/org/jitsi/service/neomedia/codec/EncodingConfiguration.java

--- libjitsi/src/org/jitsi/service/neomedia/codec/EncodingConfiguration.java
   (revision 9877)
+++ libjitsi/src/org/jitsi/service/neomedia/codec/EncodingConfiguration.java
   (revision 9878)
@@ -501,4 +501,17 @@
         encodingConfiguration.storeProperties(properties);
         loadProperties(properties);
     }
+
+ /**
+ * Returns <tt>true</tt> if there is at least one enabled format for media
+ * type <tt>type</tt>.
+ *
+ * @param mediaType The media type, MediaType.AUDIO or MediaType.VIDEO
+ * @return <tt>true</tt> if there is at least one enabled format for media
+ * type <tt>type</tt>.
+ */
+ public boolean hasEnabledFormat(MediaType mediaType)
+ {
+ return (getEnabledEncodings(mediaType).length > 0);
+ }
}

--
Emil Ivov, Ph.D. 67000 Strasbourg,
Project Lead France
Jitsi
emcho@jitsi.org PHONE: +33.1.77.62.43.30
http://jitsi.org FAX: +33.1.77.62.47.31