/** Initializes the core phone objects. */
  private void initializePhone() {
    // Load Preferences
    loadPreferences();

    if (preferences == null) {
      return;
    }

    guiManager = new GuiManager();
    guiManager.addUserActionListener(this);
    logManager = new LogManagerImpl(this);

    this.getLogManager().setRemoteLogging(true);

    try {
      EventQueue.invokeAndWait(
          new Runnable() {
            @Override
            public void run() {
              registerMenu = new JCheckBoxMenuItem(PhoneRes.getIString("phone.enabled"));
            }
          });
    } catch (Exception e) {
      Log.error(e);
    }

    registerMenu.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (getStatus() == SipRegisterStatus.Unregistered
                || getStatus() == SipRegisterStatus.RegistrationFailed) {

              register();
            } else {
              handleUnregisterRequest();
            }
          }
        });

    SIPConfig.setPreferredNetworkAddress(preferences.getPreferredAddress());
    NetworkAddressManager.start();

    try {
      EventQueue.invokeAndWait(
          new Runnable() {
            @Override
            public void run() {
              // Initialize Missed calls
              missedCalls = new MissedCalls();
            }
          });
    } catch (Exception e) {
      Log.error(e);
    }

    final JMenu actionsMenu =
        SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
    actionsMenu.add(registerMenu);
  }
  /**
   * Fired when softphone is register sucessfully
   *
   * @param evt RegistrationEvent
   */
  public void registered(RegistrationEvent evt) {
    status = SipRegisterStatus.Registered;

    preferences.setPreferredAddress(NetworkAddressManager.getLocalHost().getHostAddress());
    // preference.commit();

    registerStatusChanged(new RegisterEvent(this, SipRegisterStatus.Registered, evt.getReason()));

    if (callTo.length() > 2) {
      handleDialRequest(callTo);
    }
    registerMenu.setSelected(true);
  }
  /**
   * Fired when softphone is unregistered sucessfully
   *
   * @param evt RegistrationEvent
   */
  public void unregistered(RegistrationEvent evt) {
    try {
      status = SipRegisterStatus.Unregistered;

      registerStatusChanged(
          new RegisterEvent(this, SipRegisterStatus.Unregistered, evt.getReason()));

      // we could now exit
      synchronized (unregistrationLock) {
        unregistrationLock.notifyAll();
      }

      destroySoftPhone();
      registerMenu.setSelected(false);
    } catch (Exception e) {
      Log.error("unregistered", e);
    }
  }
 public void registrationFailed(RegistrationEvent evt) {
   status = SipRegisterStatus.RegistrationFailed;
   registerStatusChanged(
       new RegisterEvent(this, SipRegisterStatus.RegistrationFailed, evt.getReason()));
   registerMenu.setSelected(false);
 }