/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.sip.communicator.util;

import java.awt.*;
import java.beans.*;
import java.io.*;
import java.util.*;
import java.util.List;

import javax.net.ssl.*;

import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.resources.*;

import org.jitsi.service.configuration.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.codec.*;
import org.jitsi.service.resources.*;
import org.jitsi.util.OSUtils;
import org.jitsi.utils.*;
import org.osgi.framework.*;

import org.apache.commons.lang3.StringUtils;

/**
 * Cares about all common configurations. Storing and retrieving configuration
 * values.
 *
 * @author Yana Stamcheva
 * @author Damian Minkov
 */
public class ConfigurationUtils
{
    /**
     * The logger for this class.
     */
    private static final Logger logger
        = Logger.getLogger(ConfigurationUtils.class);

    /**
     * The send message command defined by the Enter key.
     */
    public static final String ENTER_COMMAND = "Enter";

    /**
     * The send message command defined by the Ctrl-Enter key.
     */
    public static final String CTRL_ENTER_COMMAND = "Ctrl-Enter";

    /**
     * Indicates whether the message automatic pop-up is enabled.
     */
    private static boolean autoPopupNewMessage = false;

    /**
     * The send message command. ENTER or Ctrl-ENTER
     */
    private static String sendMessageCommand;

    /**
     * Indicates if the call panel is shown.
     */
    private static boolean isCallPanelShown = true;

    /**
     * Indicates if the offline contacts are shown.
     */
    private static boolean isShowOffline = true;

    /**
     * Indicates if the application main window is visible by default.
     */
    private static boolean isApplicationVisible = true;

    /**
     * Indicates if the quit warning should be shown.
     */
    private static boolean isQuitWarningShown = true;

    /**
     * Indicates if the main frame should be minimized instead of hidden.
     */
    private static boolean minimizeInsteadOfHide = false;

    /**
     * Indicates if typing notifications should be sent.
     */
    private static boolean isSendTypingNotifications;

    /**
     * Indicates if confirmation should be requested before really moving a
     * contact.
     */
    private static boolean isMoveContactConfirmationRequested = true;

    /**
     * Indicates if tabs in chat window are enabled.
     */
    private static boolean isMultiChatWindowEnabled;

    /**
     * Indicates whether we will leave chat room on window closing.
     */
    private static boolean isLeaveChatRoomOnWindowCloseEnabled;

    /**
     * Indicates if private messaging is enabled for chat rooms.
     */
    private static boolean isPrivateMessagingInChatRoomDisabled;

    /**
     * Indicates if the history should be shown in the chat window.
     */
    private static boolean isHistoryShown;

    /**
     * Indicates if the recent messages should be shown.
     */
    private static boolean isRecentMessagesShown = true;

    /**
     * The size of the chat history to show in chat window.
     */
    private static int chatHistorySize;

    /**
     * The size of the chat write area.
     */
    private static int chatWriteAreaSize;

    /**
     * The transparency of the window.
     */
    private static int windowTransparency;

    /**
     * Indicates if transparency is enabled.
     */
    private static boolean isTransparentWindowEnabled;

    /**
     * Indicates if the window is decorated.
     */
    private static boolean isWindowDecorated;

    /**
     * Indicates if the chat tool bar is visible.
     */
    private static boolean isChatToolbarVisible;

    /**
     * Indicates if the chat style bar is visible.
     */
    private static boolean isChatStylebarVisible;

    /**
     * Indicates if the smileys are shown.
     */
    private static boolean isShowSmileys;

    /**
     * Indicates if the chat simple theme is activated.
     */
    private static boolean isChatSimpleThemeEnabled;

    /**
     * Indicates if the add contact functionality is disabled.
     */
    private static boolean isAddContactDisabled;

    /**
     * Indicates if the merge contact functionality is disabled.
     */
    private static boolean isMergeContactDisabled;

    /**
     * Indicates if the go to chatroom functionality is disabled.
     */
    private static boolean isGoToChatroomDisabled;

    /**
     * Indicates if the create group functionality is disabled.
     */
    private static boolean isCreateGroupDisabled;

    /**
     * Indicates if the create group functionality is disabled.
     */
    private static boolean isFlattenGroupEnabled;

    /**
     * Indicates if the remove contact functionality is disabled.
     */
    private static boolean isRemoveContactDisabled;

    /**
     * Indicates if the move contact functionality is disabled.
     */
    private static boolean isContactMoveDisabled;

    /**
     * Indicates if the rename contact functionality is disabled.
     */
    private static boolean isContactRenameDisabled;

    /**
     * Indicates if the remove group functionality is disabled.
     */
    private static boolean isGroupRemoveDisabled;

    /**
     * Indicates if the rename group functionality is disabled.
     */
    private static boolean isGroupRenameDisabled;


    /**
     * Indicates if the pre set status messages are enabled.
     */
    private static boolean isPresetStatusMessagesEnabled;

    /**
     * The last directory used in file transfer.
     */
    private static String sendFileLastDir;

    /**
     * The configuration service.
     */
    private static ConfigurationService configService
        = UtilActivator.getConfigurationService();

    /**
     * The parent of the last contact.
     */
    private static String lastContactParent = null;

    /**
     * The last conference call provider.
     */
    private static ProtocolProviderService lastCallConferenceProvider = null;

    /**
     * Indicates if the "Advanced" configurations for an account should be
     * disabled for the user.
     */
    private static boolean isAdvancedAccountConfigDisabled;

    /**
     * The default font family used in chat windows.
     */
    private static String defaultFontFamily;

    /**
     * The default font size used in chat windows.
     */
    private static String defaultFontSize;

    /**
     * Indicates if the font is bold in chat windows.
     */
    private static boolean isDefaultFontBold = false;

    /**
     * Indicates if the font is italic in chat windows.
     */
    private static boolean isDefaultFontItalic = false;

    /**
     * Indicates if the font is underline in chat windows.
     */
    private static boolean isDefaultFontUnderline = false;

    /**
     * The default font color used in chat windows.
     */
    private static int defaultFontColor = -1;

    /**
     * whether to show the status changed message in chat history area.
     */
    private static boolean showStatusChangedInChat = false;

    /**
     * When enabled, allow to use the additional phone numbers
     * to route video calls and desktop sharing through it if possible.
     */
    private static boolean routeVideoAndDesktopUsingPhoneNumber = false;

    /**
     * Indicates that when we have a single account we can hide the select
     * account option when possible.
     */
    private static boolean hideAccountSelectionWhenPossible = false;

    /**
     * Hide accounts from accounts status list.
     */
    private static boolean hideAccountStatusSelectors = false;

    /**
     * Hide extended away status.
     */
    private static boolean hideExtendedAwayStatus = false;

    /**
     * Whether to disable creation of auto answer submenu.
     */
    private static boolean autoAnswerDisableSubmenu = false;

    /**
     * Whether the chat room user configuration functionality is disabled.
     */
    private static boolean isChatRoomConfigDisabled = false;

    /**
     * Indicates if the single window interface is enabled.
     */
    private static boolean isSingleWindowInterfaceEnabled = false;

    /**
     * Whether addresses will be shown in call history tooltips.
     */
    private static boolean isHideAddressInCallHistoryTooltipEnabled = false;

    /**
     * The name of the property, whether to show addresses in call history
     * tooltip.
     */
    private static final String HIDE_ADDR_IN_CALL_HISTORY_TOOLTIP_PROPERTY
        = "net.java.sip.communicator.impl.gui.contactlist" +
                ".HIDE_ADDRESS_IN_CALL_HISTORY_TOOLTIP_ENABLED";

    /**
     * Texts to notify that sms has been sent or sms has been received.
     */
    private static boolean isSmsNotifyTextDisabled = false;

    /**
     * To disable displaying sms delivered message or sms received.
     */
    private static final String SMS_MSG_NOTIFY_TEXT_DISABLED_PROP
        = "net.java.sip.communicator.impl.gui.main.contactlist."
        + "SMS_MSG_NOTIFY_TEXT_DISABLED_PROP";

    /**
     * Whether domain will be shown in receive call dialog.
     */
    private static boolean isHideDomainInReceivedCallDialogEnabled = false;

    /**
     * The name of the property, whether to show addresses in call history
     * tooltip.
     */
    private static final String HIDE_DOMAIN_IN_RECEIEVE_CALL_DIALOG_PROPERTY
        = "net.java.sip.communicator.impl.gui.main.call." +
            "HIDE_DOMAIN_IN_RECEIVE_CALL_DIALOG_ENABLED";

    /**
     * The name of the show smileys property.
     */
    private static final String SHOW_SMILEYS_PROPERTY
            = "net.java.sip.communicator.service.replacement.SMILEY.enable";

    /**
     * The name of the simple theme property.
     */
    private static final String CHAT_SIMPLE_THEME_ENABLED_PROP
        = "net.java.sip.communicator.service.gui.CHAT_SIMPLE_THEME_ENABLED";

    /**
     * The name of the chat room configuration property.
     */
    private static final String CHAT_ROOM_CONFIG_DISABLED_PROP
        = "net.java.sip.communicator.service.gui.CHAT_ROOM_CONFIG_DISABLED";

    /**
     * The name of the single interface property.
     */
    private static final String SINGLE_WINDOW_INTERFACE_ENABLED
        = "net.java.sip.communicator.service.gui.SINGLE_WINDOW_INTERFACE_ENABLED";

    /**
     * Indicates if phone numbers should be normalized before dialed.
     */
    private static boolean isNormalizePhoneNumber;

    /**
     * Indicates if a string containing alphabetical characters might be
     * considered as a phone number.
     */
    private static boolean acceptPhoneNumberWithAlphaChars;

    /**
     * The name of the single interface property.
     */
    public static final String ALERTER_ENABLED_PROP
        = "plugin.chatalerter.ENABLED";

    /**
     * The name of the property which indicates whether the user should be
     * warned that master password is not set.
     */
    private static final String MASTER_PASS_WARNING_PROP
        = "net.java.sip.communicator.impl.gui.main"
            + ".SHOW_MASTER_PASSWORD_WARNING";

    /**
     * Indicates whether the user should be warned
     * that master password is not set.
     */
    private static boolean showMasterPasswordWarning;

    /**
     * Indicates if window (task bar or dock icon) alerter is enabled.
     */
    private static boolean alerterEnabled;

    /**
     * Loads all user interface configurations.
     */
    public static void loadGuiConfigurations()
    {
        configService.addPropertyChangeListener(
            new ConfigurationChangeListener());

        // Load the "auPopupNewMessage" property.
        String autoPopupProperty =
            "service.gui.AUTO_POPUP_NEW_MESSAGE";

        String autoPopup = configService.getString(autoPopupProperty);

        if(autoPopup == null)
            autoPopup = UtilActivator.getResources().
                getSettingsString(autoPopupProperty);

        if(autoPopup != null && autoPopup.equalsIgnoreCase("yes"))
            autoPopupNewMessage = true;

        // Load the "sendMessageCommand" property.
        String messageCommandProperty = "service.gui.SEND_MESSAGE_COMMAND";
        sendMessageCommand = UtilActivator.getResources()
            .getSettingsString(messageCommandProperty);

        // Load the showCallPanel property.
        String callPanelShown = configService.getString(
            "net.java.sip.communicator.impl.gui.showCallPanel");

        if(callPanelShown != null && callPanelShown.length() > 0)
        {
            isCallPanelShown = Boolean.parseBoolean(callPanelShown);
        }

        // Load the "showOffline" property.
        String showOffline = configService.getString(
            "net.java.sip.communicator.impl.gui.showOffline");

        if(showOffline != null && showOffline.length() > 0)
        {
            isShowOffline = Boolean.parseBoolean(showOffline);
        }

        // Load the "showApplication" property.
        isApplicationVisible
            = configService.getBoolean(
                    "net.java.sip.communicator.impl.systray.showApplication",
                    isApplicationVisible);

        // Load the "showAppQuitWarning" property.
        String quitWarningShown = configService.getString(
            "net.java.sip.communicator.impl.gui.quitWarningShown");

        if(quitWarningShown != null && quitWarningShown.length() > 0)
        {
            isQuitWarningShown
                = Boolean.parseBoolean(quitWarningShown);
        }

        minimizeInsteadOfHide = configService.getBoolean(
            "net.java.sip.communicator.impl.gui.minimizeInsteadOfHide",
            isPinnedToTaskBar());

        // Load the "sendTypingNotifications" property.
        String isSendTypingNotifProperty =
            "service.gui.SEND_TYPING_NOTIFICATIONS_ENABLED";
        String isSendTypingNotif =
            configService.getString(isSendTypingNotifProperty);

        if(isSendTypingNotif == null)
            isSendTypingNotif =
                UtilActivator.getResources().
                    getSettingsString(isSendTypingNotifProperty);

        if(isSendTypingNotif != null && isSendTypingNotif.length() > 0)
        {
            isSendTypingNotifications
                = Boolean.parseBoolean(isSendTypingNotif);
        }

        // Load the "isMoveContactConfirmationRequested" property.
        String isMoveContactConfirmationRequestedString
            = configService.getString(
            "net.java.sip.communicator.impl.gui.isMoveContactConfirmationRequested");

        if(isMoveContactConfirmationRequestedString != null
            && isMoveContactConfirmationRequestedString.length() > 0)
        {
            isMoveContactConfirmationRequested
                = Boolean.parseBoolean(isMoveContactConfirmationRequestedString);
        }

        // Load the "isMultiChatWindowEnabled" property.
        String isMultiChatWindowEnabledStringProperty
            = "service.gui.IS_MULTI_CHAT_WINDOW_ENABLED";

        String isMultiChatWindowEnabledString
            = configService.getString(isMultiChatWindowEnabledStringProperty);

        if(isMultiChatWindowEnabledString == null)
            isMultiChatWindowEnabledString =
                UtilActivator.getResources().
                    getSettingsString(isMultiChatWindowEnabledStringProperty);

        if(isMultiChatWindowEnabledString != null
            && isMultiChatWindowEnabledString.length() > 0)
        {
            isMultiChatWindowEnabled
                = Boolean.parseBoolean(isMultiChatWindowEnabledString);
        }

        isPrivateMessagingInChatRoomDisabled
            = configService.getBoolean(
                "service.gui.IS_PRIVATE_CHAT_IN_CHATROOM_DISABLED", false);

        // Load the "isLeaveChatroomOnWindowCloseEnabled" property.
        String isLeaveChatRoomOnWindowCloseEnabledStringProperty
            = "service.gui.LEAVE_CHATROOM_ON_WINDOW_CLOSE";

        String isLeaveChatRoomOnWindowCloseEnabledString
            = configService.getString(
                    isLeaveChatRoomOnWindowCloseEnabledStringProperty);

        if(isLeaveChatRoomOnWindowCloseEnabledString == null)
        {
            isLeaveChatRoomOnWindowCloseEnabledString
                = UtilActivator.getResources().getSettingsString(
                        isLeaveChatRoomOnWindowCloseEnabledStringProperty);
        }

        if(isLeaveChatRoomOnWindowCloseEnabledString != null
            && isLeaveChatRoomOnWindowCloseEnabledString.length() > 0)
        {
            isLeaveChatRoomOnWindowCloseEnabled
                = Boolean.parseBoolean(
                        isLeaveChatRoomOnWindowCloseEnabledString);
        }


        // Load the "isHistoryShown" property.
        String isHistoryShownStringProperty =
            "service.gui.IS_MESSAGE_HISTORY_SHOWN";

        String isHistoryShownString
            = configService.getString(isHistoryShownStringProperty);

        if(isHistoryShownString == null)
            isHistoryShownString =
                UtilActivator.getResources().
                    getSettingsString(isHistoryShownStringProperty);

        if(isHistoryShownString != null
            && isHistoryShownString.length() > 0)
        {
            isHistoryShown
                = Boolean.parseBoolean(isHistoryShownString);
        }

        // Load the "isRecentMessagesShown" property.
        isRecentMessagesShown
            = !configService.getBoolean(
                    MessageHistoryService.PNAME_IS_RECENT_MESSAGES_DISABLED,
                    !isRecentMessagesShown);

        // Load the "chatHistorySize" property.
        String chatHistorySizeStringProperty =
            "service.gui.MESSAGE_HISTORY_SIZE";
        String chatHistorySizeString
            = configService.getString(chatHistorySizeStringProperty);

        if(chatHistorySizeString == null)
            chatHistorySizeString =
                UtilActivator.getResources().
                    getSettingsString(chatHistorySizeStringProperty);

        if(chatHistorySizeString != null
            && chatHistorySizeString.length() > 0)
        {
            chatHistorySize = Integer.parseInt(chatHistorySizeString);
        }

        // Load the "CHAT_WRITE_AREA_SIZE" property.
        String chatWriteAreaSizeStringProperty =
            "net.java.sip.communicator.impl.gui.CHAT_WRITE_AREA_SIZE";
        String chatWriteAreaSizeString
            = configService.getString(chatWriteAreaSizeStringProperty);

        if(chatWriteAreaSizeString == null)
            chatWriteAreaSizeString =
                UtilActivator.getResources().
                    getSettingsString(chatWriteAreaSizeStringProperty);

        if(chatWriteAreaSizeString != null
            && chatWriteAreaSizeString.length() > 0)
        {
            chatWriteAreaSize
                = Integer.parseInt(chatWriteAreaSizeString);
        }

        // Load the "isTransparentWindowEnabled" property.
        String isTransparentWindowEnabledProperty =
            "impl.gui.IS_TRANSPARENT_WINDOW_ENABLED";

        String isTransparentWindowEnabledString
            = configService.getString(isTransparentWindowEnabledProperty);

        if(isTransparentWindowEnabledString == null)
            isTransparentWindowEnabledString =
                UtilActivator.getResources().
                    getSettingsString(isTransparentWindowEnabledProperty);

        if(isTransparentWindowEnabledString != null
            && isTransparentWindowEnabledString.length() > 0)
        {
            isTransparentWindowEnabled
                = Boolean.parseBoolean(isTransparentWindowEnabledString);
        }

        // Load the "windowTransparency" property.
        String windowTransparencyProperty =
            "impl.gui.WINDOW_TRANSPARENCY";

        String windowTransparencyString
            = configService.getString(windowTransparencyProperty);

        if(windowTransparencyString == null)
            windowTransparencyString =
                UtilActivator.getResources().
                    getSettingsString(windowTransparencyProperty);

        if(windowTransparencyString != null
            && windowTransparencyString.length() > 0)
        {
            windowTransparency
                = Integer.parseInt(windowTransparencyString);
        }

        // Load the "isWindowDecorated" property.
        String isWindowDecoratedProperty
            = "impl.gui.IS_WINDOW_DECORATED";

        String isWindowDecoratedString
            = configService.getString(isWindowDecoratedProperty);

        if(isWindowDecoratedString == null)
            isWindowDecoratedString =
                UtilActivator.getResources().
                    getSettingsString(isWindowDecoratedProperty);

        if(isWindowDecoratedString != null
            && isWindowDecoratedString.length() > 0)
        {
            isWindowDecorated
                = Boolean.parseBoolean(isWindowDecoratedString);
        }

        // Load the "isChatToolbarVisible" property
        isChatToolbarVisible
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.chat.ChatWindow.showToolbar",
                true);
        // Load the "isChatToolbarVisible" property
        isChatStylebarVisible
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.chat.ChatWindow.showStylebar",
                true);

        // Load the "isShowSmileys" property
        isShowSmileys
            = configService.getBoolean(
                SHOW_SMILEYS_PROPERTY,
                true);

        // Load the "isChatSimpleThemeEnabled" property.
        isChatSimpleThemeEnabled
            = configService.getBoolean(
                CHAT_SIMPLE_THEME_ENABLED_PROP,
                true);

        // Load the "lastContactParent" property.
        lastContactParent = configService.getString(
            "net.java.sip.communicator.impl.gui.addcontact.lastContactParent");

        // Load the "sendFileLastDir" property.
        sendFileLastDir = configService.getString(
            "net.java.sip.communicator.impl.gui.chat.filetransfer." +
            "SEND_FILE_LAST_DIR");

        // Load the "ADD_CONTACT_DISABLED" property.
        isAddContactDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "CONTACT_ADD_DISABLED",
                false);

        // Load the "MERGE_CONTACT_DISABLED" property.
        isMergeContactDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "CONTACT_MERGE_DISABLED",
                false);

        // Load the "CREATE_GROUP_DISABLED" property.
        isCreateGroupDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "CREATE_GROUP_DISABLED",
                false);

        // Load the "FLATTEN_GROUP_ENABLED" property.
        isFlattenGroupEnabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "FLATTEN_GROUP_ENABLED",
                false);

        // Load the "GO_TO_CHATROOM_DISABLED" property.
        isGoToChatroomDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.chatroomslist." +
                "GO_TO_CHATROOM_DISABLED",
                false);

        // Load the "REMOVE_CONTACT_DISABLED" property.
        isRemoveContactDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "CONTACT_REMOVE_DISABLED",
                false);

        // Load the "CONTACT_MOVE_DISABLED" property.
        isContactMoveDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "CONTACT_MOVE_DISABLED",
                false);

        // Load the "CONTACT_RENAME_DISABLED" property.
        isContactRenameDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "CONTACT_RENAME_DISABLED",
                false);
        // Load the "GROUP_REMOVE_DISABLED" property.
        isGroupRemoveDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "GROUP_REMOVE_DISABLED",
                false);

        // Load the "GROUP_RENAME_DISABLED" property.
        isGroupRenameDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.contactlist." +
                "GROUP_RENAME_DISABLED",
                false);

        // Load the "PRESET_STATUS_MESSAGES" property.
        isPresetStatusMessagesEnabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.presence." +
                "PRESET_STATUS_MESSAGES",
                true);

        // Load the "net.java.sip.communicator.impl.gui.main.account
        // .ADVANCED_CONFIG_DISABLED" property.
        String advancedConfigDisabledDefaultProp
            = UtilActivator.getResources().getSettingsString(
                "impl.gui.main.account.ADVANCED_CONFIG_DISABLED");

        boolean isAdvancedConfigDisabled = false;

        if (advancedConfigDisabledDefaultProp != null)
            isAdvancedConfigDisabled
                = Boolean.parseBoolean(advancedConfigDisabledDefaultProp);

        // Load the advanced account configuration disabled.
        isAdvancedAccountConfigDisabled
            = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.main.account." +
                "ADVANCED_CONFIG_DISABLED",
                isAdvancedConfigDisabled);

        // Single interface enabled property.
        String singleInterfaceEnabledProp
            = UtilActivator.getResources().getSettingsString(
                SINGLE_WINDOW_INTERFACE_ENABLED);

        boolean isEnabled = false;

        if (singleInterfaceEnabledProp != null)
            isEnabled = Boolean.parseBoolean(singleInterfaceEnabledProp);
        else
            isEnabled = Boolean.parseBoolean(
                UtilActivator.getResources().getSettingsString(
                "impl.gui.SINGLE_WINDOW_INTERFACE"));

        // Load the advanced account configuration disabled.
        isSingleWindowInterfaceEnabled
            = configService.getBoolean( SINGLE_WINDOW_INTERFACE_ENABLED,
                                        isEnabled);

        if(isFontSupportEnabled())
        {
            // Load default font family string.
            defaultFontFamily = configService.getString(
                "net.java.sip.communicator.impl.gui.chat.DEFAULT_FONT_FAMILY");

            // Load default font size.
            defaultFontSize = configService.getString(
                "net.java.sip.communicator.impl.gui.chat.DEFAULT_FONT_SIZE");

            // Load isBold chat property.
            isDefaultFontBold = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.chat.DEFAULT_FONT_BOLD",
                isDefaultFontBold);

            // Load isItalic chat property.
            isDefaultFontItalic = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.chat.DEFAULT_FONT_ITALIC",
                isDefaultFontItalic);

            // Load isUnderline chat property.
            isDefaultFontUnderline = configService.getBoolean(
                "net.java.sip.communicator.impl.gui.chat.DEFAULT_FONT_UNDERLINE",
                isDefaultFontUnderline);

            // Load default font color property.
            int colorSetting = configService.getInt(
                "net.java.sip.communicator.impl.gui.chat.DEFAULT_FONT_COLOR",
                -1);

            if(colorSetting != -1)
                defaultFontColor = colorSetting;
        }

        String showStatusChangedInChatProperty
                = "impl.gui.SHOW_STATUS_CHANGED_IN_CHAT";
        String showStatusChangedInChatDefault = UtilActivator.getResources().
            getSettingsString(showStatusChangedInChatProperty);

        // if there is a default value use it
        if(showStatusChangedInChatDefault != null)
            showStatusChangedInChat = Boolean.parseBoolean(
                showStatusChangedInChatDefault);

        showStatusChangedInChat = configService.getBoolean(
            showStatusChangedInChatProperty,
            showStatusChangedInChat);

        String routeVideoAndDesktopUsingPhoneNumberProperty
            = "impl.gui.ROUTE_VIDEO_AND_DESKTOP_TO_PNONENUMBER";
        String routeVideoAndDesktopUsingPhoneNumberDefault =
            UtilActivator.getResources()
                .getSettingsString(routeVideoAndDesktopUsingPhoneNumberProperty);

        if(routeVideoAndDesktopUsingPhoneNumberDefault != null)
            routeVideoAndDesktopUsingPhoneNumber = Boolean.parseBoolean(
                routeVideoAndDesktopUsingPhoneNumberDefault);

        routeVideoAndDesktopUsingPhoneNumber = configService.getBoolean(
            routeVideoAndDesktopUsingPhoneNumberProperty,
            routeVideoAndDesktopUsingPhoneNumber);

        String hideAccountMenuProperty
            = "impl.gui.HIDE_SELECTION_ON_SINGLE_ACCOUNT";
        String hideAccountMenuDefaultValue = UtilActivator.getResources()
            .getSettingsString(hideAccountMenuProperty);

        if(hideAccountMenuDefaultValue != null)
            hideAccountSelectionWhenPossible = Boolean.parseBoolean(
                hideAccountMenuDefaultValue);

        hideAccountSelectionWhenPossible = configService.getBoolean(
            hideAccountMenuProperty,
            hideAccountSelectionWhenPossible);

        String hideAccountStatusSelectorsProperty
            = "impl.gui.HIDE_ACCOUNT_STATUS_SELECTORS";
        String hideAccountsStatusDefaultValue = UtilActivator.getResources()
            .getSettingsString(hideAccountStatusSelectorsProperty);

        if(hideAccountsStatusDefaultValue != null)
            hideAccountStatusSelectors = Boolean.parseBoolean(
                hideAccountsStatusDefaultValue);

        hideAccountStatusSelectors = configService.getBoolean(
            hideAccountStatusSelectorsProperty,
            hideAccountStatusSelectors);

        String autoAnswerDisableSubmenuProperty
            = "impl.gui.AUTO_ANSWER_DISABLE_SUBMENU";
        String autoAnswerDisableSubmenuDefaultValue =
            UtilActivator.getResources()
                .getSettingsString(autoAnswerDisableSubmenuProperty);

        if(autoAnswerDisableSubmenuDefaultValue != null)
            autoAnswerDisableSubmenu = Boolean.parseBoolean(
                autoAnswerDisableSubmenuDefaultValue);

        autoAnswerDisableSubmenu = configService.getBoolean(
            autoAnswerDisableSubmenuProperty,
            autoAnswerDisableSubmenu);

        isChatRoomConfigDisabled = configService.getBoolean(
            CHAT_ROOM_CONFIG_DISABLED_PROP,
            isChatRoomConfigDisabled);

        isNormalizePhoneNumber
            = configService.getBoolean("impl.gui.NORMALIZE_PHONE_NUMBER", true);

        alerterEnabled
            = configService.getBoolean(ALERTER_ENABLED_PROP, true);

        // Load the "ACCEPT_PHONE_NUMBER_WITH_ALPHA_CHARS" property.
        acceptPhoneNumberWithAlphaChars
            = configService.getBoolean(
                    "impl.gui.ACCEPT_PHONE_NUMBER_WITH_ALPHA_CHARS",
                    true);

        isHideAddressInCallHistoryTooltipEnabled = configService.getBoolean(
            HIDE_ADDR_IN_CALL_HISTORY_TOOLTIP_PROPERTY,
            isHideAddressInCallHistoryTooltipEnabled);

        isHideDomainInReceivedCallDialogEnabled = configService.getBoolean(
            HIDE_DOMAIN_IN_RECEIEVE_CALL_DIALOG_PROPERTY,
            isHideDomainInReceivedCallDialogEnabled);

        String hideExtendedAwayStatusProperty
            = "net.java.sip.communicator.service.protocol" +
                ".globalstatus.HIDE_EXTENDED_AWAY_STATUS";
        String hideExtendedAwayStatusDefaultValue = UtilActivator.getResources()
            .getSettingsString(hideExtendedAwayStatusProperty);

        if(hideExtendedAwayStatusDefaultValue != null)
            hideExtendedAwayStatus = Boolean.parseBoolean(
                hideExtendedAwayStatusDefaultValue);

        hideExtendedAwayStatus = configService.getBoolean(
            hideExtendedAwayStatusProperty,
            hideExtendedAwayStatus);

        isSmsNotifyTextDisabled = configService.getBoolean(
            SMS_MSG_NOTIFY_TEXT_DISABLED_PROP,
            isSmsNotifyTextDisabled
        );

        showMasterPasswordWarning
            = configService.getBoolean(MASTER_PASS_WARNING_PROP, true);
    }

    private static boolean isPinnedToTaskBar()
    {
        if (!OSUtils.IS_WINDOWS)
        {
            return false;
        }

        File taskbar = new File(System.getenv("appdata"),
            "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar");
        if (!taskbar.exists())
        {
            return false;
        }

        File[] pins = taskbar.listFiles(new FileFilter()
        {
            @Override
            public boolean accept(File f)
            {
                return f.getName().endsWith(".lnk");
            }
        });

        String title = UtilActivator.getResources()
            .getSettingsString("service.gui.APPLICATION_NAME");
        for (File pin : pins)
        {
            if (pin.getName().contains(title))
            {
                return true;
            }
        }

        return false;
    }

    /**
     * Checks whether font support is disabled, checking in default
     * settings for the default value.
     * @return is font support disabled.
     */
    public static boolean isFontSupportEnabled()
    {
        String fontDisabledProp =
            "net.java.sip.communicator.impl.gui.FONT_SUPPORT_ENABLED";

        boolean defaultValue = false;

        String defaultSettingStr =
            UtilActivator.getResources().getSettingsString(fontDisabledProp);

        if(defaultSettingStr != null)
            defaultValue = Boolean.parseBoolean(defaultSettingStr);

        return configService.getBoolean(
            fontDisabledProp, defaultValue);
    }

    /**
     * Return TRUE if "autoPopupNewMessage" property is true, otherwise - return
     * FALSE. Indicates to the user interface whether new messages should be
     * opened and bring to front.
     * @return TRUE if "autoPopupNewMessage" property is true, otherwise
     * - return FALSE.
     */
    public static boolean isAutoPopupNewMessage()
    {
        return autoPopupNewMessage;
    }

    /**
     * Updates the "autoPopupNewMessage" property.
     *
     * @param autoPopup indicates to the user interface whether new
     * messages should be opened and bring to front.
     **/
    public static void setAutoPopupNewMe