/** Loads Preferences, either from server or locally. */
 private void loadPreferences() {
   boolean serverPluginInstalled =
       SipAccountPacket.isSoftPhonePluginInstalled(SparkManager.getConnection());
   if (serverPluginInstalled) {
     setupRemotePreferences(SparkManager.getConnection());
   }
 }
  /**
   * Setup the Preferences according to remote server
   *
   * @param con XMPPConnection connection
   */
  private void setupRemotePreferences(XMPPConnection con) {

    try {
      ProviderManager.addIQProvider(
          SipAccountPacket.ELEMENT_NAME,
          SipAccountPacket.NAMESPACE,
          new SipAccountPacket.Provider());

      ProviderManager.addIQProvider(
          LogPacket.ELEMENT_NAME, LogPacket.NAMESPACE, new LogPacket.Provider());

      SipAccountPacket sp = SipAccountPacket.getSipSettings(con);

      if (sp != null) {

        SipAccount sipAccount = sp.getSipAccount();

        if (sipAccount != null) {
          this.saccount = sipAccount;
          preference = new SipPreference();
          preference.setShowGUI(false);
          preference.setCommitSettings(false);

          preferences = new SipPreferences();

          preferences.setUserName(sipAccount.getSipUsername());
          preferences.setAuthUserName(sipAccount.getAuthUsername());
          preferences.setServer(sipAccount.getServer());
          preferences.setPassword(sipAccount.getPassword());
          preferences.setRegisterAtStart(true);

          preferences.setStunServer(sipAccount.getStunServer());
          preferences.setStunPort(sipAccount.getStunPort());
          preferences.setUseStun(sipAccount.isUseStun());
          preferences.setVoicemail(sipAccount.getVoiceMailNumber());
          preferences.setOutboundproxy(sipAccount.getOutboundproxy());
          preferences.setPromptCredentials(sipAccount.isPromptCredentials());

          SIPConfig.setUseStun(preferences.isUseStun());
          SIPConfig.setStunServer(preferences.getStunServer());
          SIPConfig.setStunPort(preferences.getStunPort());
          SIPConfig.setOutboundProxy(preferences.getOutboundproxy());

          preference.setData(preferences);
          SIPConfig.setPreferredNetworkAddress(
              NetworkAddressManager.getLocalHost(false).getHostAddress());

          if (preferences.isRegisterAtStart()) {
            register();
          }

          if (preferences.isPromptCredentials()) {
            loadLocalPreferences();
          }

        } else {

        }
      }

    } catch (Exception e) {
      Log.error("setupRemotePreferences", e);
    }
  }