File indexing completed on 2024-05-12 16:37:08
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007-2010 Thomas Zander <zander@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KWApplicationConfig.h" 0021 #include "KWDocument.h" 0022 0023 #include <KoUnit.h> 0024 #include <KoGlobal.h> 0025 0026 #include <kconfiggroup.h> 0027 #include <KSharedConfig> 0028 0029 KWApplicationConfig::KWApplicationConfig() 0030 : m_viewFrameBorders(true), 0031 m_viewRulers(false), 0032 m_showFormattingChars(false), 0033 m_showTableBorders(true), 0034 m_showSectionBounds(false), 0035 m_createBackupFile(true), 0036 m_statusBarShowPage(true), 0037 m_statusBarShowPageStyle(true), 0038 m_statusBarShowPageSize(false), 0039 m_statusBarShowLineNumber(true), 0040 m_statusBarShowModified(true), 0041 m_statusBarShowMouse(false), 0042 m_statusBarShowZoom(true), 0043 m_statusBarShowWordCount(false), 0044 m_showInlineObjectVisualization(true), 0045 m_zoom(100), 0046 m_zoomMode(KoZoomMode::ZOOM_WIDTH), 0047 m_autoSaveSeconds(KoDocument::defaultAutoSave()), 0048 m_defaultColumnSpacing(MM_TO_POINT(6)) 0049 { 0050 } 0051 0052 void KWApplicationConfig::load(KWDocument *document) 0053 { 0054 KSharedConfigPtr config = KSharedConfig::openConfig(); 0055 KConfigGroup interface = config->group("Interface"); 0056 // setCursorInProtectedArea(interface.readEntry("cursorInProtectArea", true)); 0057 // Config-file value in mm, default 10 pt 0058 m_viewRulers = interface.readEntry("Rulers", m_viewRulers); 0059 m_autoSaveSeconds = interface.readEntry("AutoSave", m_autoSaveSeconds); 0060 document->setAutoSave(m_autoSaveSeconds); 0061 0062 m_createBackupFile = interface.readEntry("BackupFile", m_createBackupFile); 0063 document->setBackupFile(m_createBackupFile); 0064 0065 // setNbPagePerRow(interface.readEntry("nbPagePerRow",4)); 0066 // m_maxRecentFiles = interface.readEntry("NbRecentFile", 10); 0067 0068 m_showFormattingChars = interface.readEntry("ViewFormattingChars", m_showFormattingChars); 0069 m_showInlineObjectVisualization = interface.readEntry("ViewFieldShadings", m_showInlineObjectVisualization); 0070 m_showTableBorders = interface.readEntry("ViewTableBorders", m_showTableBorders); 0071 m_showSectionBounds = interface.readEntry("ViewSectionBounds", m_showSectionBounds); 0072 0073 m_viewFrameBorders = interface.readEntry("ViewFrameBorders", m_viewFrameBorders); 0074 0075 m_zoom = interface.readEntry("Zoom", m_zoom); 0076 m_zoomMode = static_cast<KoZoomMode::Mode>(interface.readEntry("ZoomMode", (int) m_zoomMode)); 0077 0078 m_statusBarShowPage = interface.readEntry("StatusBarShowPage", m_statusBarShowPage); 0079 m_statusBarShowPageStyle = interface.readEntry("StatusBarShowPageStyle", m_statusBarShowPageStyle); 0080 m_statusBarShowPageSize = interface.readEntry("StatusBarShowPageSize", m_statusBarShowPageSize); 0081 m_statusBarShowLineNumber = interface.readEntry("StatusBarShowLineNumber", m_statusBarShowLineNumber); 0082 m_statusBarShowModified = interface.readEntry("StatusBarShowModified", m_statusBarShowModified); 0083 m_statusBarShowMouse = interface.readEntry("StatusBarShowMouse", m_statusBarShowMouse); 0084 m_statusBarShowZoom = interface.readEntry("StatusBarShowZoom", m_statusBarShowZoom); 0085 m_statusBarShowWordCount = interface.readEntry("StatusBarShowWordCount", m_statusBarShowWordCount); 0086 0087 // m_bShowDocStruct = interface.readEntry("showDocStruct", true); 0088 // m_viewModeType = interface.readEntry("viewmode", "ModeNormal"); 0089 // setShowStatusBarShow(interface.readEntry("ShowStatusBarShow" , true)); 0090 // setAllowAutoFormat(interface.readEntry("AllowAutoFormat" , true)); 0091 // setShowScrollBar(interface.readEntry("ShowScrollBar", true)); 0092 // if (isEmbedded()) 0093 // m_bShowDocStruct = false; // off by default for embedded docs, but still toggleable 0094 // m_pgUpDownMovesCaret = interface.readEntry("PgUpDownMovesCaret", true); 0095 // m_bInsertDirectCursor= interface.readEntry("InsertDirectCursor", false); 0096 // m_globalLanguage=interface.readEntry("language", KGlobal::locale()->language()); 0097 // m_bGlobalHyphenation=interface.readEntry("hyphenation", false); 0098 0099 // setShowGrid(interface.readEntry("ShowGrid" , false)); 0100 // setSnapToGrid(interface.readEntry("SnapToGrid", false)); 0101 0102 KConfigGroup misc = config->group("Misc"); 0103 if (misc.exists()) { 0104 0105 //load default unit setting - this is only used for new files (from templates) or empty files 0106 if (document && misc.hasKey("Units")) 0107 document->setUnit(KoUnit::fromSymbol(misc.readEntry("Units"))); 0108 m_defaultColumnSpacing = misc.readEntry("ColumnSpacing", m_defaultColumnSpacing); 0109 } 0110 0111 // if(undo!=-1) 0112 // setUndoRedoLimit(undo); 0113 0114 //text mode view is not a good default for a readonly document... 0115 // if (!isReadWrite() && m_viewModeType =="ModeText") 0116 // m_viewModeType= "ModeNormal"; 0117 0118 // m_layoutViewMode = KWViewMode::create(m_viewModeType, this, 0 /*no canvas*/); 0119 0120 KConfigGroup path = config->group("Words Path"); 0121 if (path.exists()) { 0122 // if (path.hasKey("expression path")) 0123 // m_personalExpressionPath = path.readPathEntry("expression path", QStringList()); 0124 if (document) 0125 document->setBackupPath(path.readPathEntry("backup path", QString())); 0126 } 0127 0128 // Load personal dict 0129 KConfigGroup spelling = KoGlobal::calligraConfig()->group("Spelling"); 0130 // m_spellCheckPersonalDict = spelling.readListEntry("PersonalDict"); 0131 0132 } 0133 0134 void KWApplicationConfig::save() 0135 { 0136 KSharedConfigPtr config = KSharedConfig::openConfig(); 0137 KConfigGroup interface = config->group("Interface"); 0138 interface.writeEntry("ViewFormattingChars", m_showFormattingChars); 0139 interface.writeEntry("ViewFieldShadings", m_showInlineObjectVisualization); 0140 interface.writeEntry("ViewTableBorders", m_showTableBorders); 0141 interface.writeEntry("ViewSectionBounds", m_showSectionBounds); 0142 interface.writeEntry("ViewFrameBorders", m_viewFrameBorders); 0143 interface.writeEntry("Zoom", m_zoom); 0144 interface.writeEntry("ZoomMode", (int)m_zoomMode); 0145 // interface.writeEntry("showDocStruct", m_bShowDocStruct); 0146 interface.writeEntry("Rulers", m_viewRulers); 0147 // interface.writeEntry("viewmode", m_viewModeType) ; 0148 // interface.writeEntry("AllowAutoFormat", m_bAllowAutoFormat); 0149 // interface.writeEntry("ShowGrid" , m_bShowGrid); 0150 // interface.writeEntry("SnapToGrid" , m_bSnapToGrid); 0151 interface.writeEntry("StatusBarShowPage", m_statusBarShowPage); 0152 interface.writeEntry("StatusBarShowPageStyle", m_statusBarShowPageStyle); 0153 interface.writeEntry("StatusBarShowPageSize", m_statusBarShowPageSize); 0154 interface.writeEntry("StatusBarShowLineNumber", m_statusBarShowLineNumber); 0155 interface.writeEntry("StatusBarShowModified", m_statusBarShowModified); 0156 interface.writeEntry("StatusBarShowMouse", m_statusBarShowMouse); 0157 interface.writeEntry("StatusBarShowZoom", m_statusBarShowZoom); 0158 interface.writeEntry("StatusBarShowWordCount", m_statusBarShowWordCount); 0159 interface.sync(); 0160 } 0161 0162 void KWApplicationConfig::setUnit(const KoUnit &unit) 0163 { 0164 KSharedConfigPtr config = KSharedConfig::openConfig(); 0165 KConfigGroup misc = config->group("Misc"); 0166 misc.writeEntry("Units", unit.symbol()); 0167 misc.sync(); 0168 }