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
Configuration()26bb02e0acSNicolas Bonnefon Configuration::Configuration()
27bb02e0acSNicolas Bonnefon {
28bb02e0acSNicolas Bonnefon // Should have some sensible default values.
29a9448ba0SNicolas 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
43*3b104697SAnton Filimonov loadLastSession_ = true;
44*3b104697SAnton Filimonov
45bb02e0acSNicolas Bonnefon overviewVisible_ = true;
46bb02e0acSNicolas Bonnefon lineNumbersVisibleInMain_ = false;
47bb02e0acSNicolas Bonnefon lineNumbersVisibleInFiltered_ = true;
48bb02e0acSNicolas Bonnefon
49bb02e0acSNicolas Bonnefon QFontInfo fi(mainFont_);
50bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Default font is " << fi.family().toStdString();
51f688be2eSNicolas Bonnefon
52f688be2eSNicolas Bonnefon searchAutoRefresh_ = false;
53f688be2eSNicolas Bonnefon searchIgnoreCase_ = false;
54bb02e0acSNicolas Bonnefon }
55bb02e0acSNicolas Bonnefon
56bb02e0acSNicolas Bonnefon // Accessor functions
mainFont() const57bb02e0acSNicolas Bonnefon QFont Configuration::mainFont() const
58bb02e0acSNicolas Bonnefon {
59bb02e0acSNicolas Bonnefon return mainFont_;
60bb02e0acSNicolas Bonnefon }
61bb02e0acSNicolas Bonnefon
setMainFont(QFont newFont)62bb02e0acSNicolas Bonnefon void Configuration::setMainFont( QFont newFont )
63bb02e0acSNicolas Bonnefon {
64bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Configuration::setMainFont";
65bb02e0acSNicolas Bonnefon
66bb02e0acSNicolas Bonnefon mainFont_ = newFont;
67bb02e0acSNicolas Bonnefon }
68bb02e0acSNicolas Bonnefon
retrieveFromStorage(QSettings & settings)69bb02e0acSNicolas Bonnefon void Configuration::retrieveFromStorage( QSettings& settings )
70bb02e0acSNicolas Bonnefon {
71bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Configuration::retrieveFromStorage";
72bb02e0acSNicolas Bonnefon
73bb02e0acSNicolas Bonnefon // Fonts
74bb02e0acSNicolas Bonnefon QString family = settings.value( "mainFont.family" ).toString();
75bb02e0acSNicolas Bonnefon int size = settings.value( "mainFont.size" ).toInt();
76bb02e0acSNicolas Bonnefon
77bb02e0acSNicolas Bonnefon // If no config read, keep the default
78bb02e0acSNicolas Bonnefon if ( !family.isNull() )
79bb02e0acSNicolas Bonnefon mainFont_ = QFont( family, size );
80bb02e0acSNicolas Bonnefon
81bb02e0acSNicolas Bonnefon // Regexp types
82bb02e0acSNicolas Bonnefon mainRegexpType_ = static_cast<SearchRegexpType>(
83bb02e0acSNicolas Bonnefon settings.value( "regexpType.main", mainRegexpType_ ).toInt() );
84bb02e0acSNicolas Bonnefon quickfindRegexpType_ = static_cast<SearchRegexpType>(
85bb02e0acSNicolas Bonnefon settings.value( "regexpType.quickfind", quickfindRegexpType_ ).toInt() );
86bb02e0acSNicolas Bonnefon if ( settings.contains( "quickfind.incremental" ) )
87bb02e0acSNicolas Bonnefon quickfindIncremental_ = settings.value( "quickfind.incremental" ).toBool();
88bb02e0acSNicolas Bonnefon
8980bca0a3SNicolas Bonnefon // "Advanced" settings
9080bca0a3SNicolas Bonnefon if ( settings.contains( "polling.enabled" ) )
9180bca0a3SNicolas Bonnefon pollingEnabled_ = settings.value( "polling.enabled" ).toBool();
9280bca0a3SNicolas Bonnefon if ( settings.contains( "polling.intervalMs" ) )
9380bca0a3SNicolas Bonnefon pollIntervalMs_ = settings.value( "polling.intervalMs" ).toInt();
9480bca0a3SNicolas Bonnefon
95*3b104697SAnton Filimonov if ( settings.contains( "session.loadLast" ) )
96*3b104697SAnton Filimonov loadLastSession_ = settings.value( "session.loadLast" ).toBool();
97*3b104697SAnton Filimonov
98bb02e0acSNicolas Bonnefon // View settings
99bb02e0acSNicolas Bonnefon if ( settings.contains( "view.overviewVisible" ) )
100bb02e0acSNicolas Bonnefon overviewVisible_ = settings.value( "view.overviewVisible" ).toBool();
101bb02e0acSNicolas Bonnefon if ( settings.contains( "view.lineNumbersVisibleInMain" ) )
102bb02e0acSNicolas Bonnefon lineNumbersVisibleInMain_ =
103bb02e0acSNicolas Bonnefon settings.value( "view.lineNumbersVisibleInMain" ).toBool();
104bb02e0acSNicolas Bonnefon if ( settings.contains( "view.lineNumbersVisibleInFiltered" ) )
105bb02e0acSNicolas Bonnefon lineNumbersVisibleInFiltered_ =
106bb02e0acSNicolas Bonnefon settings.value( "view.lineNumbersVisibleInFiltered" ).toBool();
107bb02e0acSNicolas Bonnefon
108bb02e0acSNicolas Bonnefon // Some sanity check (mainly for people upgrading)
109bb02e0acSNicolas Bonnefon if ( quickfindIncremental_ )
110bb02e0acSNicolas Bonnefon quickfindRegexpType_ = FixedString;
111f688be2eSNicolas Bonnefon
112f688be2eSNicolas Bonnefon // Default crawler settings
113f688be2eSNicolas Bonnefon if ( settings.contains( "defaultView.searchAutoRefresh" ) )
114f688be2eSNicolas Bonnefon searchAutoRefresh_ = settings.value( "defaultView.searchAutoRefresh" ).toBool();
115f688be2eSNicolas Bonnefon if ( settings.contains( "defaultView.searchIgnoreCase" ) )
116f688be2eSNicolas Bonnefon searchIgnoreCase_ = settings.value( "defaultView.searchIgnoreCase" ).toBool();
117bb02e0acSNicolas Bonnefon }
118bb02e0acSNicolas Bonnefon
saveToStorage(QSettings & settings) const119bb02e0acSNicolas Bonnefon void Configuration::saveToStorage( QSettings& settings ) const
120bb02e0acSNicolas Bonnefon {
121bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Configuration::saveToStorage";
122bb02e0acSNicolas Bonnefon
123bb02e0acSNicolas Bonnefon QFontInfo fi(mainFont_);
124bb02e0acSNicolas Bonnefon
125bb02e0acSNicolas Bonnefon settings.setValue( "mainFont.family", fi.family() );
126bb02e0acSNicolas Bonnefon settings.setValue( "mainFont.size", fi.pointSize() );
127bb02e0acSNicolas Bonnefon settings.setValue( "regexpType.main", static_cast<int>( mainRegexpType_ ) );
128bb02e0acSNicolas Bonnefon settings.setValue( "regexpType.quickfind", static_cast<int>( quickfindRegexpType_ ) );
129bb02e0acSNicolas Bonnefon settings.setValue( "quickfind.incremental", quickfindIncremental_ );
13080bca0a3SNicolas Bonnefon settings.setValue( "polling.enabled", pollingEnabled_ );
13180bca0a3SNicolas Bonnefon settings.setValue( "polling.intervalMs", pollIntervalMs_ );
132*3b104697SAnton Filimonov settings.setValue( "session.loadLast", loadLastSession_);
13380bca0a3SNicolas Bonnefon
134bb02e0acSNicolas Bonnefon settings.setValue( "view.overviewVisible", overviewVisible_ );
135bb02e0acSNicolas Bonnefon settings.setValue( "view.lineNumbersVisibleInMain", lineNumbersVisibleInMain_ );
136bb02e0acSNicolas Bonnefon settings.setValue( "view.lineNumbersVisibleInFiltered", lineNumbersVisibleInFiltered_ );
137f688be2eSNicolas Bonnefon settings.setValue( "defaultView.searchAutoRefresh", searchAutoRefresh_ );
138f688be2eSNicolas Bonnefon settings.setValue( "defaultView.searchIgnoreCase", searchIgnoreCase_ );
139bb02e0acSNicolas Bonnefon }
140