[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/jackcoolpython/ghostwriter/dev/src/AppSettings.cpp [Back]  [Original]

/***********************************************************************
 *
 * Copyright (C) 2014-2016 wereturtle
 * Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Graeme Gott 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 *
 ***********************************************************************/

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include "AppSettings.h"
#include "ExporterFactory.h"
#include "dictionary_manager.h"

#define GW_AUTOSAVE_KEY "Save/autoSave"
#define GW_BACKUP_FILE_KEY "Save/backupFile"
#define GW_REMEMBER_FILE_HISTORY_KEY "Save/rememberFileHistory"
#define GW_FONT_KEY "Style/font"
#define GW_LARGE_HEADINGS_KEY "Style/largeHeadings"
#define GW_HIGHLIGHT_LINE_BREAKS "Style/highlightLineBreaks"
#define GW_AUTO_MATCH_KEY "Typing/autoMatchEnabled"
#define GW_AUTO_MATCH_FILTER_KEY "Typing/autoMatchFilter"
#define GW_BULLET_CYCLING_KEY "Typing/bulletPointCyclingEnabled"
#define GW_UNDERLINE_ITALICS_KEY "Style/underlineInsteadOfItalics"
#define GW_FOCUS_MODE_KEY "Style/focusMode"
#define GW_HIDE_MENU_BAR_IN_FULL_SCREEN_KEY "Style/hideMenuBarInFullScreenEnabled"
#define GW_THEME_KEY "Style/theme"
#define GW_EDITOR_WIDTH_KEY "Style/editorWidth"
#define GW_INTERFACE_STYLE_KEY "Style/interfaceStyle"
#define GW_BLOCKQUOTE_STYLE_KEY "Style/blockquoteStyle"
#define GW_DISPLAY_TIME_IN_FULL_SCREEN_KEY "Style/displayTimeInFullScreen"
#define GW_HIDE_HUDS_WHEN_TYPING_KEY "Style/hideHudsWhenTypingEnabled"
#define GW_HIDE_HUDS_ON_PREVIEW_KEY "Style/hideHudsOnPreviewEnabled"
#define GW_TAB_WIDTH_KEY "Tabs/tabWidth"
#define GW_SPACES_FOR_TABS_KEY "Tabs/insertSpacesForTabs"
#define GW_DICTIONARY_KEY "Spelling/locale"
#define GW_LOCALE_KEY "Application/locale"
#define GW_LIVE_SPELL_CHECK_KEY "Spelling/liveSpellCheck"
#define GW_HUD_BUTTON_LAYOUT_KEY "HUD/windowButtonLayout"
#define GW_HUD_ROW_COLORS_KEY "HUD/alternateRowColors"
#define GW_DESKTOP_COMPOSITING_KEY "HUD/desktopCompositingEnabled"
#define GW_HUD_OPACITY_KEY "HUD/opacity"
#define GW_HTML_PREVIEW_OPEN_KEY "Preview/htmlPreviewOpen"
#define GW_CUSTOM_STYLE_SHEETS_KEY "Preview/customStyleSheets"
#define GW_LAST_USED_STYLE_SHEET_KEY "Preview/lastUsedStyleSheet"
#define GW_LAST_USED_EXPORTER_KEY "Preview/lastUsedExporter"

AppSettings* AppSettings::instance = NULL;

AppSettings* AppSettings::getInstance()
{
    if (NULL == instance)
    {
        instance = new AppSettings();
    }

    return instance;
}

AppSettings::~AppSettings()
{
    store();
}

void AppSettings::store()
{
    QSettings appSettings;
    appSettings.setValue(GW_AUTOSAVE_KEY, QVariant(autoSaveEnabled));
    appSettings.setValue(GW_BACKUP_FILE_KEY, QVariant(backupFileEnabled));
    appSettings.setValue(GW_FONT_KEY, QVariant(font.toString()));
    appSettings.setValue(GW_TAB_WIDTH_KEY, QVariant(tabWidth));
    appSettings.setValue(GW_SPACES_FOR_TABS_KEY, QVariant(insertSpacesForTabsEnabled));
    appSettings.setValue(GW_LARGE_HEADINGS_KEY, QVariant(largeHeadingSizesEnabled));
    appSettings.setValue(GW_HIGHLIGHT_LINE_BREAKS, QVariant(highlightLineBreaks));
    appSettings.setValue(GW_AUTO_MATCH_KEY, QVariant(autoMatchEnabled));
    appSettings.setValue(GW_AUTO_MATCH_FILTER_KEY, QVariant(autoMatchedCharFilter));
    appSettings.setValue(GW_BULLET_CYCLING_KEY, QVariant(bulletPointCyclingEnabled));

    appSettings.setValue(GW_UNDERLINE_ITALICS_KEY, QVariant(useUnderlineForEmphasis));
    appSettings.setValue(GW_FOCUS_MODE_KEY, QVariant(focusMode));
    appSettings.setValue(GW_HIDE_MENU_BAR_IN_FULL_SCREEN_KEY, QVariant(hideMenuBarInFullScreenEnabled));
    appSettings.setValue(GW_REMEMBER_FILE_HISTORY_KEY, QVariant(fileHistoryEnabled));
    appSettings.setValue(GW_DISPLAY_TIME_IN_FULL_SCREEN_KEY, QVariant(displayTimeInFullScreenEnabled));
    appSettings.setValue(GW_HIDE_HUDS_WHEN_TYPING_KEY, QVariant(hideHudsWhenTypingEnabled));
    appSettings.setValue(GW_HIDE_HUDS_ON_PREVIEW_KEY, QVariant(hideHudsOnPreviewEnabled));

    appSettings.setValue(GW_THEME_KEY, QVariant(themeName));
    appSettings.setValue(GW_DICTIONARY_KEY, QVariant(dictionaryLanguage));
    appSettings.setValue(GW_LOCALE_KEY, QVariant(locale));
    appSettings.setValue(GW_LIVE_SPELL_CHECK_KEY, QVariant(liveSpellCheckEnabled));
    appSettings.setValue(GW_EDITOR_WIDTH_KEY, QVariant(editorWidth));
    appSettings.setValue(GW_INTERFACE_STYLE_KEY, QVariant(interfaceStyle));
    appSettings.setValue(GW_BLOCKQUOTE_STYLE_KEY, QVariant(blockquoteStyle));
    appSettings.setValue(GW_HUD_BUTTON_LAYOUT_KEY, QVariant(hudButtonLayout));
    appSettings.setValue(GW_HUD_ROW_COLORS_KEY, QVariant(alternateHudRowColorsEnabled));
    appSettings.setValue(GW_DESKTOP_COMPOSITING_KEY, QVariant(desktopCompositingEnabled));
    appSettings.setValue(GW_HUD_OPACITY_KEY, QVariant(hudOpacity));

    appSettings.setValue(GW_HTML_PREVIEW_OPEN_KEY, QVariant(htmlPreviewVisible));
    appSettings.setValue(GW_CUSTOM_STYLE_SHEETS_KEY, QVariant(customCssFiles));
    appSettings.setValue(GW_LAST_USED_STYLE_SHEET_KEY, QVariant(currentCssFile));
    appSettings.setValue(GW_LAST_USED_EXPORTER_KEY, QVariant(currentHtmlExporter->getName()));

    appSettings.sync();
}

QString AppSettings::getThemeDirectoryPath() const
{
    return themeDirectoryPath;
}

QString AppSettings::getDictionaryPath() const
{
    return dictionaryPath;
}

QString AppSettings::getTranslationsPath() const
{
    return translationsPath;
}

bool AppSettings::getAutoSaveEnabled() const
{
    return autoSaveEnabled;
}

void AppSettings::setAutoSaveEnabled(bool enabled)
{
    autoSaveEnabled = enabled;
    emit autoSaveChanged(enabled);
}

bool AppSettings::getBackupFileEnabled() const
{
    return backupFileEnabled;
}

void AppSettings::setBackupFileEnabled(bool enabled)
{
    backupFileEnabled = enabled;
    emit backupFileChanged(enabled);
    qWarning("Backup file enabled = %d", backupFileEnabled);
}

QFont AppSettings::getFont() const
{
    return font;
}

void AppSettings::setFont(const QFont& font)
{
    this->font = font;
}

int AppSettings::getTabWidth() const
{
    return tabWidth;
}

void AppSettings::setTabWidth(int width)
{
    if ((tabWidth >= MIN_TAB_WIDTH) && (tabWidth 

Web Proxy Viewer  |  New URL  |  Original Page