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