/**
   * Removes the specified account from the list of accounts that this provider factory is handling.
   * If the specified accountID is unknown to the ProtocolProviderFactory, the call has no effect
   * and false is returned. This method is persistent in nature and once called the account
   * corresponding to the specified ID will not be loaded during future runs of the project.
   *
   * @param accountID the ID of the account to remove.
   * @return true if an account with the specified ID existed and was removed and false otherwise.
   */
  public boolean uninstallAccount(AccountID accountID) {
    // unregister the protocol provider
    ServiceReference serRef = getProviderForAccount(accountID);

    if (serRef == null) return false;

    ProtocolProviderService protocolProvider =
        (ProtocolProviderService) SipActivator.getBundleContext().getService(serRef);

    try {
      protocolProvider.unregister();
    } catch (OperationFailedException e) {
      logger.error(
          "Failed to unregister protocol provider for account : "
              + accountID
              + " caused by : "
              + e);
    }

    ServiceRegistration registration = (ServiceRegistration) registeredAccounts.remove(accountID);

    if (registration == null) return false;

    // kill the service
    registration.unregister();

    return removeStoredAccount(SipActivator.getBundleContext(), accountID);
  }
  /**
   * Sends a typing notification state.
   *
   * @param typingState the typing notification state to send
   * @return the result of this operation. One of the TYPING_NOTIFICATION_XXX constants defined in
   *     this class
   */
  public int sendTypingNotification(int typingState) {
    // If this chat transport does not support sms messaging we do
    // nothing here.
    if (!allowsTypingNotifications()) return -1;

    ProtocolProviderService protocolProvider = contact.getProtocolProvider();
    OperationSetTypingNotifications tnOperationSet =
        protocolProvider.getOperationSet(OperationSetTypingNotifications.class);

    // if protocol is not registered or contact is offline don't
    // try to send typing notifications
    if (protocolProvider.isRegistered()
        && contact.getPresenceStatus().getStatus() >= PresenceStatus.ONLINE_THRESHOLD) {
      try {
        tnOperationSet.sendTypingNotification(contact, typingState);

        return ChatPanel.TYPING_NOTIFICATION_SUCCESSFULLY_SENT;
      } catch (Exception ex) {
        logger.error("Failed to send typing notifications.", ex);

        return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED;
      }
    }

    return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED;
  }
  /**
   * Returns existing chat rooms for the given <tt>chatRoomProvider</tt>.
   *
   * @param chatRoomProvider the <tt>ChatRoomProviderWrapper</tt>, which chat rooms we're looking
   *     for
   * @return existing chat rooms for the given <tt>chatRoomProvider</tt>
   */
  public List<String> getExistingChatRooms(ChatRoomProviderWrapper chatRoomProvider) {
    if (chatRoomProvider == null) return null;

    ProtocolProviderService protocolProvider = chatRoomProvider.getProtocolProvider();

    if (protocolProvider == null) return null;

    OperationSetMultiUserChat groupChatOpSet =
        protocolProvider.getOperationSet(OperationSetMultiUserChat.class);

    if (groupChatOpSet == null) return null;

    List<String> chatRooms = null;
    try {
      chatRooms = groupChatOpSet.getExistingChatRooms();
    } catch (OperationFailedException e) {
      if (logger.isTraceEnabled())
        logger.trace(
            "Failed to obtain existing chat rooms for server: "
                + protocolProvider.getAccountID().getService(),
            e);
    } catch (OperationNotSupportedException e) {
      if (logger.isTraceEnabled())
        logger.trace(
            "Failed to obtain existing chat rooms for server: "
                + protocolProvider.getAccountID().getService(),
            e);
    }

    return chatRooms;
  }
Beispiel #4
0
  /**
   * Returns list of <tt>ChatTransport</tt> (i.e. contact) that supports the specified
   * <tt>OperationSet</tt>.
   *
   * @param transports list of <tt>ChatTransport</tt>
   * @param opSetClass <tt>OperationSet</tt> to find
   * @return list of <tt>ChatTransport</tt> (i.e. contact) that supports the specified
   *     <tt>OperationSet</tt>.
   */
  private List<ChatTransport> getOperationSetForCapabilities(
      List<ChatTransport> transports, Class<? extends OperationSet> opSetClass) {
    List<ChatTransport> list = new ArrayList<ChatTransport>();

    for (ChatTransport transport : transports) {
      ProtocolProviderService protocolProvider = transport.getProtocolProvider();
      OperationSetContactCapabilities capOpSet =
          protocolProvider.getOperationSet(OperationSetContactCapabilities.class);
      OperationSetPersistentPresence presOpSet =
          protocolProvider.getOperationSet(OperationSetPersistentPresence.class);

      if (capOpSet == null) {
        list.add(transport);
      } else if (presOpSet != null) {
        Contact contact = presOpSet.findContactByID(transport.getName());

        if ((contact != null) && (capOpSet.getOperationSet(contact, opSetClass) != null)) {
          // It supports OpSet for at least one of its
          // ChatTransports
          list.add(transport);
        }
      }
    }

    return list;
  }
Beispiel #5
0
  /**
   * Shows "call via" menu allowing user to selected from multiple providers.
   *
   * @param context the android context
   * @param v the View that will contain the popup menu.
   * @param destination target callee name.
   */
  private static void showCallViaMenu(final Context context, View v, final String destination) {
    PopupMenu popup = new PopupMenu(context, v);

    Menu menu = popup.getMenu();

    Iterator<ProtocolProviderService> registeredProviders =
        AccountUtils.getRegisteredProviders().iterator();

    while (registeredProviders.hasNext()) {
      final ProtocolProviderService provider = registeredProviders.next();
      String accountAddress = provider.getAccountID().getAccountAddress();

      MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, accountAddress);

      menuItem.setOnMenuItemClickListener(
          new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
              createCall(context, destination, provider);

              return false;
            }
          });
    }

    popup.show();
  }
  /**
   * Publish present status. We search for the highest value in the given interval.
   *
   * @param protocolProvider the protocol provider to which we change the status.
   * @param status the status tu publish.
   */
  public void publishStatus(
      ProtocolProviderService protocolProvider, PresenceStatus status, boolean rememberStatus) {
    OperationSetPresence presence = protocolProvider.getOperationSet(OperationSetPresence.class);

    LoginManager loginManager = GuiActivator.getUIService().getLoginManager();
    RegistrationState registrationState = protocolProvider.getRegistrationState();

    if (registrationState == RegistrationState.REGISTERED
        && presence != null
        && !presence.getPresenceStatus().equals(status)) {
      if (status.isOnline()) {
        new PublishPresenceStatusThread(protocolProvider, presence, status).start();
      } else {
        loginManager.setManuallyDisconnected(true);
        GuiActivator.getUIService().getLoginManager().logoff(protocolProvider);
      }
    } else if (registrationState != RegistrationState.REGISTERED
        && registrationState != RegistrationState.REGISTERING
        && registrationState != RegistrationState.AUTHENTICATING
        && status.isOnline()) {
      GuiActivator.getUIService().getLoginManager().login(protocolProvider);
    } else if (!status.isOnline() && !(registrationState == RegistrationState.UNREGISTERING)) {
      loginManager.setManuallyDisconnected(true);
      GuiActivator.getUIService().getLoginManager().logoff(protocolProvider);
    }

    if (rememberStatus) saveStatusInformation(protocolProvider, status.getStatusName());
  }
  /**
   * Saves the last status for all accounts. This information is used on loging. Each time user logs
   * in he's logged with the same status as he was the last time before closing the application.
   *
   * @param protocolProvider the protocol provider to save status information for
   * @param statusName the name of the status to save
   */
  private void saveStatusInformation(ProtocolProviderService protocolProvider, String statusName) {
    ConfigurationService configService = GuiActivator.getConfigurationService();

    String prefix = "net.java.sip.communicator.impl.gui.accounts";

    List<String> accounts = configService.getPropertyNamesByPrefix(prefix, true);

    boolean savedAccount = false;

    for (String accountRootPropName : accounts) {
      String accountUID = configService.getString(accountRootPropName);

      if (accountUID.equals(protocolProvider.getAccountID().getAccountUniqueID())) {

        configService.setProperty(accountRootPropName + ".lastAccountStatus", statusName);

        savedAccount = true;
      }
    }

    if (!savedAccount) {
      String accNodeName = "acc" + Long.toString(System.currentTimeMillis());

      String accountPackage = "net.java.sip.communicator.impl.gui.accounts." + accNodeName;

      configService.setProperty(
          accountPackage, protocolProvider.getAccountID().getAccountUniqueID());

      configService.setProperty(accountPackage + ".lastAccountStatus", statusName);
    }
  }
Beispiel #8
0
  /**
   * We fill the protocolProviderTable with all running protocol providers at the start of the
   * bundle.
   */
  private void init() {
    SystrayActivator.bundleContext.addServiceListener(new ProtocolProviderServiceListener());

    ServiceReference[] protocolProviderRefs = null;
    try {
      protocolProviderRefs =
          SystrayActivator.bundleContext.getServiceReferences(
              ProtocolProviderService.class.getName(), null);
    } catch (InvalidSyntaxException ex) {
      // this shouldn't happen since we're providing no parameter string
      // but let's log just in case.
      logger.error("Error while retrieving service refs", ex);
      return;
    }

    // in case we found any
    if (protocolProviderRefs != null) {

      for (int i = 0; i < protocolProviderRefs.length; i++) {
        ProtocolProviderService provider =
            (ProtocolProviderService)
                SystrayActivator.bundleContext.getService(protocolProviderRefs[i]);

        boolean isHidden =
            provider.getAccountID().getAccountProperties().get("HIDDEN_PROTOCOL") != null;

        if (!isHidden) this.addAccount(provider);
      }
    }
  }
Beispiel #9
0
    /** Fired when an account has changed its status. We update the icon in the menu. */
    public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt) {
      ProtocolProviderService pps = evt.getProvider();

      StatusSelector selectorBox = (StatusSelector) accountSelectors.get(pps.getAccountID());

      if (selectorBox == null) return;

      selectorBox.updateStatus(evt.getNewStatus());
    }
  /**
   * Adds the user interface related to the given protocol provider.
   *
   * @param protocolProvider the protocol provider for which we add the user interface
   */
  public void addProtocolProviderUI(ProtocolProviderService protocolProvider) {
    OperationSetBasicTelephony<?> telOpSet =
        protocolProvider.getOperationSet(OperationSetBasicTelephony.class);

    if (telOpSet != null) {
      telOpSet.addCallListener(androidCallListener);
    }

    OperationSetPresence presenceOpSet =
        protocolProvider.getOperationSet(OperationSetPresence.class);

    if (presenceOpSet != null) {
      presenceOpSet.addProviderPresenceStatusListener(androidPresenceListener);
    }
  }
  /**
   * Creates an instance of <tt>NewStatusMessageDialog</tt>.
   *
   * @param protocolProvider the <tt>ProtocolProviderService</tt>.
   */
  public NewStatusMessageDialog(ProtocolProviderService protocolProvider) {
    presenceOpSet =
        (OperationSetPersistentPresence)
            protocolProvider.getOperationSet(OperationSetPresence.class);

    this.init();
    pack();
  }
  /**
   * Removes the user interface related to the given protocol provider.
   *
   * @param protocolProvider the protocol provider to remove
   */
  public void removeProtocolProviderUI(ProtocolProviderService protocolProvider) {
    OperationSetBasicTelephony<?> telOpSet =
        protocolProvider.getOperationSet(OperationSetBasicTelephony.class);

    if (telOpSet != null) {
      telOpSet.removeCallListener(androidCallListener);
    }

    OperationSetPresence presenceOpSet =
        protocolProvider.getOperationSet(OperationSetPresence.class);

    if (presenceOpSet != null) {
      presenceOpSet.removeProviderPresenceStatusListener(androidPresenceListener);
    }

    // Removes all chat session for unregistered provider
    ChatSessionManager.removeAllChatsForProvider(protocolProvider);
  }
Beispiel #13
0
  /**
   * Adds the account corresponding to the given protocol provider to this menu.
   *
   * @param protocolProvider the protocol provider corresponding to the account to add
   */
  private void addAccount(ProtocolProviderService protocolProvider) {
    OperationSetPresence presence =
        (OperationSetPresence) protocolProvider.getOperationSet(OperationSetPresence.class);

    if (presence == null) {
      StatusSimpleSelector simpleSelector =
          new StatusSimpleSelector(parentSystray, protocolProvider);

      this.accountSelectors.put(protocolProvider.getAccountID(), simpleSelector);
      this.add(simpleSelector);
    } else {
      StatusSelector statusSelector = new StatusSelector(parentSystray, protocolProvider, presence);

      this.accountSelectors.put(protocolProvider.getAccountID(), statusSelector);
      this.add(statusSelector);

      presence.addProviderPresenceStatusListener(new SystrayProviderPresenceStatusListener());
    }
  }
  /**
   * Removes the specified account from the list of accounts that this provider factory is handling.
   * If the specified accountID is unknown to the ProtocolProviderFactory, the call has no effect
   * and false is returned. This method is persistent in nature and once called the account
   * corresponding to the specified ID will not be loaded during future runs of the project.
   *
   * @param accountID the ID of the account to remove.
   * @return true if an account with the specified ID existed and was removed and false otherwise.
   */
  public boolean uninstallAccount(AccountID accountID) {
    // Unregister the protocol provider.
    ServiceReference serRef = getProviderForAccount(accountID);

    boolean wasAccountExisting = false;

    // If the protocol provider service is registered, first unregister the
    // service.
    if (serRef != null) {
      BundleContext bundleContext = getBundleContext();
      ProtocolProviderService protocolProvider =
          (ProtocolProviderService) bundleContext.getService(serRef);

      try {
        protocolProvider.unregister();
      } catch (OperationFailedException ex) {
        logger.error(
            "Failed to unregister protocol provider for account: "
                + accountID
                + " caused by: "
                + ex);
      }
    }

    ServiceRegistration registration;

    synchronized (registeredAccounts) {
      registration = registeredAccounts.remove(accountID);
    }

    // first remove the stored account so when PP is unregistered we can
    // distinguish between deleted or just disabled account
    wasAccountExisting = removeStoredAccount(accountID);

    if (registration != null) {
      // Kill the service.
      registration.unregister();
    }

    return wasAccountExisting;
  }
Beispiel #15
0
    /**
     * Creates an instance of <tt>MetaContactDetail</tt> by specifying the underlying protocol
     * <tt>Contact</tt>.
     *
     * @param contact the protocol contact, on which this implementation is based
     */
    public MetaContactDetail(Contact contact) {
      super(
          contact.getAddress(),
          contact.getDisplayName(),
          new ImageIcon(contact.getPresenceStatus().getStatusIcon()),
          contact);

      this.contact = contact;

      ProtocolProviderService parentProvider = contact.getProtocolProvider();

      Iterator<Class<? extends OperationSet>> opSetClasses =
          parentProvider.getSupportedOperationSetClasses().iterator();

      while (opSetClasses.hasNext()) {
        Class<? extends OperationSet> opSetClass = opSetClasses.next();

        addPreferredProtocolProvider(opSetClass, parentProvider);
        addPreferredProtocol(opSetClass, parentProvider.getProtocolName());
      }
    }
  /**
   * Returns default nickname for chat room based on the given provider.
   *
   * @param pps the given protocol provider service
   * @return default nickname for chat room based on the given provider.
   */
  public String getDefaultNickname(ProtocolProviderService pps) {
    final OperationSetServerStoredAccountInfo accountInfoOpSet =
        pps.getOperationSet(OperationSetServerStoredAccountInfo.class);

    String displayName = "";
    if (accountInfoOpSet != null) {
      displayName = AccountInfoUtils.getDisplayName(accountInfoOpSet);
    }

    if (displayName == null || displayName.length() == 0) {
      displayName = MUCActivator.getGlobalDisplayDetailsService().getGlobalDisplayName();
      if (displayName == null || displayName.length() == 0) {
        displayName = pps.getAccountID().getUserID();
        if (displayName != null) {
          int atIndex = displayName.lastIndexOf("@");
          if (atIndex > 0) displayName = displayName.substring(0, atIndex);
        }
      }
    }

    return displayName;
  }
  /**
   * Unloads the account corresponding to the given <tt>accountID</tt>. Unregisters the
   * corresponding protocol provider, but keeps the account in contrast to the uninstallAccount
   * method.
   *
   * @param accountID the account identifier
   * @return true if an account with the specified ID existed and was unloaded and false otherwise.
   */
  public boolean unloadAccount(AccountID accountID) {
    // Unregister the protocol provider.
    ServiceReference serRef = getProviderForAccount(accountID);

    if (serRef == null) {
      return false;
    }

    BundleContext bundleContext = getBundleContext();
    ProtocolProviderService protocolProvider =
        (ProtocolProviderService) bundleContext.getService(serRef);

    try {
      protocolProvider.unregister();
    } catch (OperationFailedException ex) {
      logger.error(
          "Failed to unregister protocol provider for account : "
              + accountID
              + " caused by: "
              + ex);
    }

    ServiceRegistration registration;

    synchronized (registeredAccounts) {
      registration = registeredAccounts.remove(accountID);
    }
    if (registration == null) {
      return false;
    }

    // Kill the service.
    registration.unregister();

    return true;
  }
  /** Initializes "select account" spinner with existing accounts. */
  private void initAccountSpinner() {
    Spinner accountsSpiner = (Spinner) findViewById(R.id.selectAccountSpinner);

    Iterator<ProtocolProviderService> providers = AccountUtils.getRegisteredProviders().iterator();

    List<AccountID> accounts = new ArrayList<AccountID>();

    int selectedIdx = -1;
    int idx = 0;

    while (providers.hasNext()) {
      ProtocolProviderService provider = providers.next();

      OperationSet opSet = provider.getOperationSet(OperationSetPresence.class);

      if (opSet == null) continue;

      AccountID account = provider.getAccountID();
      accounts.add(account);
      idx++;

      if (account.isPreferredProvider()) {
        selectedIdx = idx;
      }
    }

    AccountsListAdapter accountsAdapter =
        new AccountsListAdapter(
            this, R.layout.select_account_row, R.layout.select_account_dropdown, accounts, true);
    accountsSpiner.setAdapter(accountsAdapter);

    // if we have only select account option and only one account
    // select the available account
    if (accounts.size() == 1) accountsSpiner.setSelection(0);
    else accountsSpiner.setSelection(selectedIdx);
  }
  /**
   * Publish present status. We search for the highest value in the given interval.
   *
   * @param protocolProvider the protocol provider to which we change the status.
   * @param floorStatusValue the min status value.
   * @param ceilStatusValue the max status value.
   */
  private void publishStatus(
      ProtocolProviderService protocolProvider, int floorStatusValue, int ceilStatusValue) {
    if (!protocolProvider.isRegistered()) return;

    OperationSetPresence presence = protocolProvider.getOperationSet(OperationSetPresence.class);

    if (presence == null) return;

    Iterator<PresenceStatus> statusSet = presence.getSupportedStatusSet();

    PresenceStatus status = null;

    while (statusSet.hasNext()) {
      PresenceStatus currentStatus = statusSet.next();

      if (status == null
          && currentStatus.getStatus() < ceilStatusValue
          && currentStatus.getStatus() >= floorStatusValue) {
        status = currentStatus;
      }

      if (status != null) {
        if (currentStatus.getStatus() < ceilStatusValue
            && currentStatus.getStatus() >= floorStatusValue
            && currentStatus.getStatus() > status.getStatus()) {
          status = currentStatus;
        }
      }
    }

    if (status != null) {
      new PublishPresenceStatusThread(protocolProvider, presence, status).start();

      this.saveStatusInformation(protocolProvider, status.getStatusName());
    }
  }
  /**
   * Returns the last status that was stored in the configuration for the given protocol provider.
   *
   * @param protocolProvider the protocol provider
   * @return the last status that was stored in the configuration for the given protocol provider
   */
  public PresenceStatus getLastPresenceStatus(ProtocolProviderService protocolProvider) {
    String lastStatus = getLastStatusString(protocolProvider);

    if (lastStatus != null) {
      OperationSetPresence presence = protocolProvider.getOperationSet(OperationSetPresence.class);

      if (presence == null) return null;

      Iterator<PresenceStatus> i = presence.getSupportedStatusSet();
      PresenceStatus status;

      while (i.hasNext()) {
        status = i.next();
        if (status.getStatusName().equals(lastStatus)) return status;
      }
    }
    return null;
  }
  /**
   * Indicates that a protocol provider connection has failed.
   *
   * @param protocolProvider the <tt>ProtocolProviderService</tt>, which connection failed
   * @param loginManagerCallback the <tt>LoginManager</tt> implementation, which is managing the
   *     process
   */
  public void protocolProviderConnectionFailed(
      final ProtocolProviderService protocolProvider, final LoginManager loginManagerCallback) {
    AccountID accountID = protocolProvider.getAccountID();

    AndroidUtils.showAlertConfirmDialog(
        JitsiApplication.getGlobalContext(),
        JitsiApplication.getResString(R.string.service_gui_ERROR),
        JitsiApplication.getResString(
            R.string.service_gui_CONNECTION_FAILED_MSG,
            accountID.getUserID(),
            accountID.getService()),
        JitsiApplication.getResString(R.string.service_gui_RETRY),
        new DialogActivity.DialogListener() {
          public boolean onConfirmClicked(DialogActivity dialog) {
            loginManagerCallback.login(protocolProvider);
            return true;
          }

          public void onDialogCancelled(DialogActivity dialog) {}
        });
  }
  /**
   * Returns the last contact status saved in the configuration.
   *
   * @param protocolProvider the protocol provider to which the status corresponds
   * @return the last contact status saved in the configuration.
   */
  public String getLastStatusString(ProtocolProviderService protocolProvider) {
    // find the last contact status saved in the configuration.
    String lastStatus = null;

    ConfigurationService configService = GuiActivator.getConfigurationService();
    String prefix = "net.java.sip.communicator.impl.gui.accounts";
    List<String> accounts = configService.getPropertyNamesByPrefix(prefix, true);
    String protocolProviderAccountUID = protocolProvider.getAccountID().getAccountUniqueID();

    for (String accountRootPropName : accounts) {
      String accountUID = configService.getString(accountRootPropName);

      if (accountUID.equals(protocolProviderAccountUID)) {
        lastStatus = configService.getString(accountRootPropName + ".lastAccountStatus");

        if (lastStatus != null) break;
      }
    }

    return lastStatus;
  }
  /**
   * Creates an account for the given user and password.
   *
   * @param providerFactory the ProtocolProviderFactory which will create the account
   * @param user the user identifier
   * @return the <tt>ProtocolProviderService</tt> for the new account.
   */
  public ProtocolProviderService installAccount(
      ProtocolProviderFactory providerFactory, String user) throws OperationFailedException {
    Hashtable<String, String> accountProperties = new Hashtable<String, String>();

    accountProperties.put(
        ProtocolProviderFactory.ACCOUNT_ICON_PATH,
        "resources/images/protocol/gibberish/gibberish32x32.png");

    if (registration.isRememberPassword()) {
      accountProperties.put(ProtocolProviderFactory.PASSWORD, registration.getPassword());
    }

    if (isModification()) {
      providerFactory.uninstallAccount(protocolProvider.getAccountID());
      this.protocolProvider = null;
      setModification(false);
    }

    try {
      AccountID accountID = providerFactory.installAccount(user, accountProperties);

      ServiceReference serRef = providerFactory.getProviderForAccount(accountID);

      protocolProvider =
          (ProtocolProviderService) GibberishAccRegWizzActivator.bundleContext.getService(serRef);
    } catch (IllegalStateException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT);
    } catch (Exception exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Failed to add account", OperationFailedException.GENERAL_ERROR);
    }

    return protocolProvider;
  }
Beispiel #24
0
  /**
   * Gets the list of features supported by participant. If we fail to obtain it due to network
   * failure default feature list is returned.
   *
   * @param protocolProvider protocol provider service instance that will be used for discovery.
   * @param address XMPP address of the participant.
   */
  public static List<String> discoverParticipantFeatures(
      ProtocolProviderService protocolProvider, String address) {
    OperationSetSimpleCaps disco = protocolProvider.getOperationSet(OperationSetSimpleCaps.class);
    if (disco == null) {
      logger.error("Service discovery not supported by " + protocolProvider);
      return getDefaultParticipantFeatureSet();
    }

    // Discover participant feature set
    List<String> participantFeatures = disco.getFeatures(address);
    if (participantFeatures == null) {
      logger.error("Failed to discover features for " + address + " assuming default feature set.");

      return getDefaultParticipantFeatureSet();
    }

    logger.info(address + ", features: ");
    for (String feature : participantFeatures) {
      logger.info(feature);
    }

    return participantFeatures;
  }
  /**
   * Shuts down the <code>ProtocolProviderService</code> representing an account registered with
   * this factory.
   *
   * @param registeredAccount the <code>ServiceRegistration</code> of the <code>
   *     ProtocolProviderService</code> representing an account registered with this factory
   */
  protected void stop(ServiceRegistration registeredAccount) {
    ProtocolProviderService protocolProviderService =
        (ProtocolProviderService) getBundleContext().getService(registeredAccount.getReference());

    protocolProviderService.shutdown();
  }
Beispiel #26
0
  /**
   * Returns the multi user chat operation set for the given protocol provider.
   *
   * @param protocolProvider The protocol provider for which the multi user chat operation set is
   *     about.
   * @return OperationSetMultiUserChat The telephony operation set for the given protocol provider.
   */
  public static OperationSetMultiUserChat getMultiUserChatOpSet(
      ProtocolProviderService protocolProvider) {
    OperationSet opSet = protocolProvider.getOperationSet(OperationSetMultiUserChat.class);

    return (opSet instanceof OperationSetMultiUserChat) ? (OperationSetMultiUserChat) opSet : null;
  }
Beispiel #27
0
  /**
   * Removes the account corresponding to the given protocol provider from this menu.
   *
   * @param protocolProvider the protocol provider corresponding to the account to remove.
   */
  private void removeAccount(ProtocolProviderService protocolProvider) {
    Component c = (Component) this.accountSelectors.get(protocolProvider.getAccountID());

    this.remove(c);
  }
  /**
   * Publish present status. We search for the highest value in the given interval.
   *
   * <p>change the status.
   *
   * @param globalStatus
   */
  public void publishStatus(GlobalStatusEnum globalStatus) {
    String itemName = globalStatus.getStatusName();

    Iterator<ProtocolProviderService> pProviders =
        GuiActivator.getUIService().getMainFrame().getProtocolProviders();

    while (pProviders.hasNext()) {
      ProtocolProviderService protocolProvider = pProviders.next();

      if (itemName.equals(GlobalStatusEnum.ONLINE_STATUS)) {
        if (!protocolProvider.isRegistered()) {
          saveStatusInformation(protocolProvider, itemName);

          GuiActivator.getUIService().getLoginManager().login(protocolProvider);
        } else {
          OperationSetPresence presence =
              protocolProvider.getOperationSet(OperationSetPresence.class);

          if (presence == null) {
            saveStatusInformation(protocolProvider, itemName);

            continue;
          }

          Iterator<PresenceStatus> statusSet = presence.getSupportedStatusSet();

          while (statusSet.hasNext()) {
            PresenceStatus status = statusSet.next();

            if (status.getStatus() < PresenceStatus.EAGER_TO_COMMUNICATE_THRESHOLD
                && status.getStatus() >= PresenceStatus.AVAILABLE_THRESHOLD) {
              new PublishPresenceStatusThread(protocolProvider, presence, status).start();

              this.saveStatusInformation(protocolProvider, status.getStatusName());

              break;
            }
          }
        }
      } else if (itemName.equals(GlobalStatusEnum.OFFLINE_STATUS)) {
        if (!protocolProvider.getRegistrationState().equals(RegistrationState.UNREGISTERED)
            && !protocolProvider.getRegistrationState().equals(RegistrationState.UNREGISTERING)) {
          OperationSetPresence presence =
              protocolProvider.getOperationSet(OperationSetPresence.class);

          if (presence == null) {
            saveStatusInformation(protocolProvider, itemName);

            GuiActivator.getUIService().getLoginManager().logoff(protocolProvider);

            continue;
          }

          Iterator<PresenceStatus> statusSet = presence.getSupportedStatusSet();

          while (statusSet.hasNext()) {
            PresenceStatus status = statusSet.next();

            if (status.getStatus() < PresenceStatus.ONLINE_THRESHOLD) {
              this.saveStatusInformation(protocolProvider, status.getStatusName());

              break;
            }
          }

          try {
            protocolProvider.unregister();
          } catch (OperationFailedException e1) {
            logger.error(
                "Unable to unregister the protocol provider: "
                    + protocolProvider
                    + " due to the following exception: "
                    + e1);
          }
        }
      } else if (itemName.equals(GlobalStatusEnum.FREE_FOR_CHAT_STATUS)) {
        // we search for highest available status here
        publishStatus(
            protocolProvider, PresenceStatus.AVAILABLE_THRESHOLD, PresenceStatus.MAX_STATUS_VALUE);
      } else if (itemName.equals(GlobalStatusEnum.DO_NOT_DISTURB_STATUS)) {
        // status between online and away is DND
        publishStatus(
            protocolProvider, PresenceStatus.ONLINE_THRESHOLD, PresenceStatus.AWAY_THRESHOLD);
      } else if (itemName.equals(GlobalStatusEnum.AWAY_STATUS)) {
        // a status in the away interval
        publishStatus(
            protocolProvider, PresenceStatus.AWAY_THRESHOLD, PresenceStatus.AVAILABLE_THRESHOLD);
      }
    }
  }
    @Override
    public void run() {
      try {
        presence.publishPresenceStatus(status, "");
      } catch (IllegalArgumentException e1) {

        logger.error("Error - changing status", e1);
      } catch (IllegalStateException e1) {

        logger.error("Error - changing status", e1);
      } catch (OperationFailedException e1) {
        if (e1.getErrorCode() == OperationFailedException.GENERAL_ERROR) {
          String msgText =
              GuiActivator.getResources()
                  .getI18NString(
                      "service.gui.STATUS_CHANGE_GENERAL_ERROR",
                      new String[] {
                        protocolProvider.getAccountID().getUserID(),
                        protocolProvider.getAccountID().getService()
                      });

          new ErrorDialog(
                  null,
                  GuiActivator.getResources().getI18NString("service.gui.GENERAL_ERROR"),
                  msgText,
                  e1)
              .showDialog();
        } else if (e1.getErrorCode() == OperationFailedException.NETWORK_FAILURE) {
          String msgText =
              GuiActivator.getResources()
                  .getI18NString(
                      "service.gui.STATUS_CHANGE_NETWORK_FAILURE",
                      new String[] {
                        protocolProvider.getAccountID().getUserID(),
                        protocolProvider.getAccountID().getService()
                      });

          new ErrorDialog(
                  null,
                  msgText,
                  GuiActivator.getResources().getI18NString("service.gui.NETWORK_FAILURE"),
                  e1)
              .showDialog();
        } else if (e1.getErrorCode() == OperationFailedException.PROVIDER_NOT_REGISTERED) {
          String msgText =
              GuiActivator.getResources()
                  .getI18NString(
                      "service.gui.STATUS_CHANGE_NETWORK_FAILURE",
                      new String[] {
                        protocolProvider.getAccountID().getUserID(),
                        protocolProvider.getAccountID().getService()
                      });

          new ErrorDialog(
                  null,
                  GuiActivator.getResources().getI18NString("service.gui.NETWORK_FAILURE"),
                  msgText,
                  e1)
              .showDialog();
        }
        logger.error("Error - changing status", e1);
      }
    }
  /**
   * Creates a chat room, by specifying the chat room name, the parent protocol provider and
   * eventually, the contacts invited to participate in this chat room.
   *
   * @param roomName the name of the room
   * @param protocolProvider the parent protocol provider.
   * @param contacts the contacts invited when creating the chat room.
   * @param reason
   * @param join whether we should join the room after creating it.
   * @param persistent whether the newly created room will be persistent.
   * @param isPrivate whether the room will be private or public.
   * @return the <tt>ChatRoomWrapper</tt> corresponding to the created room
   */
  public ChatRoomWrapper createChatRoom(
      String roomName,
      ProtocolProviderService protocolProvider,
      Collection<String> contacts,
      String reason,
      boolean join,
      boolean persistent,
      boolean isPrivate) {
    ChatRoomWrapper chatRoomWrapper = null;
    OperationSetMultiUserChat groupChatOpSet =
        protocolProvider.getOperationSet(OperationSetMultiUserChat.class);

    // If there's no group chat operation set we have nothing to do here.
    if (groupChatOpSet == null) return null;

    ChatRoom chatRoom = null;
    try {

      HashMap<String, Object> roomProperties = new HashMap<String, Object>();
      roomProperties.put("isPrivate", isPrivate);
      chatRoom = groupChatOpSet.createChatRoom(roomName, roomProperties);

      if (join) {
        chatRoom.join();

        for (String contact : contacts) chatRoom.invite(contact, reason);
      }
    } catch (OperationFailedException ex) {
      logger.error("Failed to create chat room.", ex);

      MUCActivator.getAlertUIService()
          .showAlertDialog(
              MUCActivator.getResources().getI18NString("service.gui.ERROR"),
              MUCActivator.getResources()
                  .getI18NString(
                      "service.gui.CREATE_CHAT_ROOM_ERROR",
                      new String[] {protocolProvider.getProtocolDisplayName()}),
              ex);
    } catch (OperationNotSupportedException ex) {
      logger.error("Failed to create chat room.", ex);

      MUCActivator.getAlertUIService()
          .showAlertDialog(
              MUCActivator.getResources().getI18NString("service.gui.ERROR"),
              MUCActivator.getResources()
                  .getI18NString(
                      "service.gui.CREATE_CHAT_ROOM_ERROR",
                      new String[] {protocolProvider.getProtocolDisplayName()}),
              ex);
    }

    if (chatRoom != null) {
      ChatRoomProviderWrapper parentProvider =
          chatRoomList.findServerWrapperFromProvider(protocolProvider);

      // if there is the same room ids don't add new wrapper as old one
      // maybe already created
      chatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom);

      if (chatRoomWrapper == null) {
        chatRoomWrapper = new ChatRoomWrapperImpl(parentProvider, chatRoom);
        chatRoomWrapper.setPersistent(persistent);
        chatRoomList.addChatRoom(chatRoomWrapper);
      }
    }

    return chatRoomWrapper;
  }