1bb02e0acSNicolas Bonnefon /* 280bca0a3SNicolas Bonnefon * Copyright (C) 2009, 2010, 2013, 2015 Nicolas Bonnefon and other contributors 3bb02e0acSNicolas Bonnefon * 4bb02e0acSNicolas Bonnefon * This file is part of glogg. 5bb02e0acSNicolas Bonnefon * 6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9bb02e0acSNicolas Bonnefon * (at your option) any later version. 10bb02e0acSNicolas Bonnefon * 11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15bb02e0acSNicolas Bonnefon * 16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18bb02e0acSNicolas Bonnefon */ 19bb02e0acSNicolas Bonnefon 20bb02e0acSNicolas Bonnefon #include <QFontInfo> 21bb02e0acSNicolas Bonnefon 22bb02e0acSNicolas Bonnefon #include "log.h" 23bb02e0acSNicolas Bonnefon 24bb02e0acSNicolas Bonnefon #include "configuration.h" 25bb02e0acSNicolas Bonnefon 26bb02e0acSNicolas Bonnefon Configuration::Configuration() 27bb02e0acSNicolas Bonnefon { 28bb02e0acSNicolas Bonnefon // Should have some sensible default values. 29*a9448ba0SNicolas Bonnefon mainFont_ = QFont("monaco", 10); 30bb02e0acSNicolas Bonnefon mainFont_.setStyleHint( QFont::Courier, QFont::PreferOutline ); 31bb02e0acSNicolas Bonnefon 32bb02e0acSNicolas Bonnefon mainRegexpType_ = ExtendedRegexp; 33bb02e0acSNicolas Bonnefon quickfindRegexpType_ = FixedString; 34bb02e0acSNicolas Bonnefon quickfindIncremental_ = true; 35bb02e0acSNicolas Bonnefon 3680bca0a3SNicolas Bonnefon #ifdef GLOGG_SUPPORTS_POLLING 3780bca0a3SNicolas Bonnefon pollingEnabled_ = true; 3880bca0a3SNicolas Bonnefon #else 3980bca0a3SNicolas Bonnefon pollingEnabled_ = false; 4080bca0a3SNicolas Bonnefon #endif 4180bca0a3SNicolas Bonnefon pollIntervalMs_ = 2000; 4280bca0a3SNicolas Bonnefon 43bb02e0acSNicolas Bonnefon overviewVisible_ = true; 44bb02e0acSNicolas Bonnefon lineNumbersVisibleInMain_ = false; 45bb02e0acSNicolas Bonnefon lineNumbersVisibleInFiltered_ = true; 46bb02e0acSNicolas Bonnefon 47bb02e0acSNicolas Bonnefon QFontInfo fi(mainFont_); 48bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Default font is " << fi.family().toStdString(); 49f688be2eSNicolas Bonnefon 50f688be2eSNicolas Bonnefon searchAutoRefresh_ = false; 51f688be2eSNicolas Bonnefon searchIgnoreCase_ = false; 52bb02e0acSNicolas Bonnefon } 53bb02e0acSNicolas Bonnefon 54bb02e0acSNicolas Bonnefon // Accessor functions 55bb02e0acSNicolas Bonnefon QFont Configuration::mainFont() const 56bb02e0acSNicolas Bonnefon { 57bb02e0acSNicolas Bonnefon return mainFont_; 58bb02e0acSNicolas Bonnefon } 59bb02e0acSNicolas Bonnefon 60bb02e0acSNicolas Bonnefon void Configuration::setMainFont( QFont newFont ) 61bb02e0acSNicolas Bonnefon { 62bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Configuration::setMainFont"; 63bb02e0acSNicolas Bonnefon 64bb02e0acSNicolas Bonnefon mainFont_ = newFont; 65bb02e0acSNicolas Bonnefon } 66bb02e0acSNicolas Bonnefon 67bb02e0acSNicolas Bonnefon void Configuration::retrieveFromStorage( QSettings& settings ) 68bb02e0acSNicolas Bonnefon { 69bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Configuration::retrieveFromStorage"; 70bb02e0acSNicolas Bonnefon 71bb02e0acSNicolas Bonnefon // Fonts 72bb02e0acSNicolas Bonnefon QString family = settings.value( "mainFont.family" ).toString(); 73bb02e0acSNicolas Bonnefon int size = settings.value( "mainFont.size" ).toInt(); 74bb02e0acSNicolas Bonnefon 75bb02e0acSNicolas Bonnefon // If no config read, keep the default 76bb02e0acSNicolas Bonnefon if ( !family.isNull() ) 77bb02e0acSNicolas Bonnefon mainFont_ = QFont( family, size ); 78bb02e0acSNicolas Bonnefon 79bb02e0acSNicolas Bonnefon // Regexp types 80bb02e0acSNicolas Bonnefon mainRegexpType_ = static_cast<SearchRegexpType>( 81bb02e0acSNicolas Bonnefon settings.value( "regexpType.main", mainRegexpType_ ).toInt() ); 82bb02e0acSNicolas Bonnefon quickfindRegexpType_ = static_cast<SearchRegexpType>( 83bb02e0acSNicolas Bonnefon settings.value( "regexpType.quickfind", quickfindRegexpType_ ).toInt() ); 84bb02e0acSNicolas Bonnefon if ( settings.contains( "quickfind.incremental" ) ) 85bb02e0acSNicolas Bonnefon quickfindIncremental_ = settings.value( "quickfind.incremental" ).toBool(); 86bb02e0acSNicolas Bonnefon 8780bca0a3SNicolas Bonnefon // "Advanced" settings 8880bca0a3SNicolas Bonnefon if ( settings.contains( "polling.enabled" ) ) 8980bca0a3SNicolas Bonnefon pollingEnabled_ = settings.value( "polling.enabled" ).toBool(); 9080bca0a3SNicolas Bonnefon if ( settings.contains( "polling.intervalMs" ) ) 9180bca0a3SNicolas Bonnefon pollIntervalMs_ = settings.value( "polling.intervalMs" ).toInt(); 9280bca0a3SNicolas Bonnefon 93bb02e0acSNicolas Bonnefon // View settings 94bb02e0acSNicolas Bonnefon if ( settings.contains( "view.overviewVisible" ) ) 95bb02e0acSNicolas Bonnefon overviewVisible_ = settings.value( "view.overviewVisible" ).toBool(); 96bb02e0acSNicolas Bonnefon if ( settings.contains( "view.lineNumbersVisibleInMain" ) ) 97bb02e0acSNicolas Bonnefon lineNumbersVisibleInMain_ = 98bb02e0acSNicolas Bonnefon settings.value( "view.lineNumbersVisibleInMain" ).toBool(); 99bb02e0acSNicolas Bonnefon if ( settings.contains( "view.lineNumbersVisibleInFiltered" ) ) 100bb02e0acSNicolas Bonnefon lineNumbersVisibleInFiltered_ = 101bb02e0acSNicolas Bonnefon settings.value( "view.lineNumbersVisibleInFiltered" ).toBool(); 102bb02e0acSNicolas Bonnefon 103bb02e0acSNicolas Bonnefon // Some sanity check (mainly for people upgrading) 104bb02e0acSNicolas Bonnefon if ( quickfindIncremental_ ) 105bb02e0acSNicolas Bonnefon quickfindRegexpType_ = FixedString; 106f688be2eSNicolas Bonnefon 107f688be2eSNicolas Bonnefon // Default crawler settings 108f688be2eSNicolas Bonnefon if ( settings.contains( "defaultView.searchAutoRefresh" ) ) 109f688be2eSNicolas Bonnefon searchAutoRefresh_ = settings.value( "defaultView.searchAutoRefresh" ).toBool(); 110f688be2eSNicolas Bonnefon if ( settings.contains( "defaultView.searchIgnoreCase" ) ) 111f688be2eSNicolas Bonnefon searchIgnoreCase_ = settings.value( "defaultView.searchIgnoreCase" ).toBool(); 112bb02e0acSNicolas Bonnefon } 113bb02e0acSNicolas Bonnefon 114bb02e0acSNicolas Bonnefon void Configuration::saveToStorage( QSettings& settings ) const 115bb02e0acSNicolas Bonnefon { 116bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Configuration::saveToStorage"; 117bb02e0acSNicolas Bonnefon 118bb02e0acSNicolas Bonnefon QFontInfo fi(mainFont_); 119bb02e0acSNicolas Bonnefon 120bb02e0acSNicolas Bonnefon settings.setValue( "mainFont.family", fi.family() ); 121bb02e0acSNicolas Bonnefon settings.setValue( "mainFont.size", fi.pointSize() ); 122bb02e0acSNicolas Bonnefon settings.setValue( "regexpType.main", static_cast<int>( mainRegexpType_ ) ); 123bb02e0acSNicolas Bonnefon settings.setValue( "regexpType.quickfind", static_cast<int>( quickfindRegexpType_ ) ); 124bb02e0acSNicolas Bonnefon settings.setValue( "quickfind.incremental", quickfindIncremental_ ); 12580bca0a3SNicolas Bonnefon settings.setValue( "polling.enabled", pollingEnabled_ ); 12680bca0a3SNicolas Bonnefon settings.setValue( "polling.intervalMs", pollIntervalMs_ ); 12780bca0a3SNicolas Bonnefon 128bb02e0acSNicolas Bonnefon settings.setValue( "view.overviewVisible", overviewVisible_ ); 129bb02e0acSNicolas Bonnefon settings.setValue( "view.lineNumbersVisibleInMain", lineNumbersVisibleInMain_ ); 130bb02e0acSNicolas Bonnefon settings.setValue( "view.lineNumbersVisibleInFiltered", lineNumbersVisibleInFiltered_ ); 131f688be2eSNicolas Bonnefon settings.setValue( "defaultView.searchAutoRefresh", searchAutoRefresh_ ); 132f688be2eSNicolas Bonnefon settings.setValue( "defaultView.searchIgnoreCase", searchIgnoreCase_ ); 133bb02e0acSNicolas Bonnefon } 134