Makefile: remove spurious tab
[xcsoar.git] / src / Profile / PageProfile.cpp
blob841aa2c1ae051213714a2ae99d59a8a036aa718a
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Profile/PageProfile.hpp"
25 #include "Profile/Profile.hpp"
26 #include "PageSettings.hpp"
27 #include "InfoBoxes/InfoBoxSettings.hpp"
29 /**
30 * Old enum moved from PageSettings.
32 enum eTopLayout {
33 tlEmpty,
34 tlMap,
35 tlMapAndInfoBoxes,
38 static void
39 Load(PageLayout &_pl, const unsigned page)
41 char profileKey[32];
42 unsigned prefixLen = sprintf(profileKey, "Page%u", page);
43 if (prefixLen <= 0)
44 return;
46 PageLayout pl = PageLayout::Default();
47 strcpy(profileKey + prefixLen, "InfoBoxMode");
48 if (!Profile::Get(profileKey, pl.infobox_config.auto_switch))
49 return;
50 strcpy(profileKey + prefixLen, "InfoBoxPanel");
51 if (!Profile::Get(profileKey, pl.infobox_config.panel))
52 return;
54 strcpy(profileKey + prefixLen, "Layout");
55 unsigned temp = 0;
56 Profile::Get(profileKey, temp);
57 switch (temp) {
58 case tlEmpty:
59 pl.valid = false;
60 break;
62 case tlMap:
63 pl.infobox_config.enabled = false;
64 break;
67 if (pl.infobox_config.panel >= InfoBoxSettings::MAX_PANELS)
68 return;
69 if (page == 0 && !pl.IsDefined())
70 return;
72 strcpy(profileKey + prefixLen, "Bottom");
73 if (!Profile::GetEnum(profileKey, pl.bottom) ||
74 unsigned(pl.bottom) >= unsigned(PageLayout::Bottom::MAX))
75 pl.bottom = PageLayout::Bottom::NOTHING;
77 strcpy(profileKey + prefixLen, "Main");
78 if (!Profile::GetEnum(profileKey, pl.main) ||
79 unsigned(pl.main) >= unsigned(PageLayout::Main::MAX))
80 pl.main = PageLayout::Main::MAP;
82 _pl = pl;
85 void
86 Profile::Load(PageSettings &settings)
88 for (unsigned i = 0; i < PageSettings::MAX_PAGES; ++i)
89 ::Load(settings.pages[i], i);
91 settings.Compress();
93 Get(ProfileKeys::PagesDistinctZoom, settings.distinct_zoom);
96 void
97 Profile::Save(const PageLayout &page, const unsigned i)
99 char profileKey[32];
100 unsigned prefixLen = sprintf(profileKey, "Page%u", i);
101 if (prefixLen <= 0)
102 return;
103 strcpy(profileKey + prefixLen, "InfoBoxMode");
104 Profile::Set(profileKey, page.infobox_config.auto_switch);
105 strcpy(profileKey + prefixLen, "InfoBoxPanel");
106 Profile::Set(profileKey, page.infobox_config.panel);
108 strcpy(profileKey + prefixLen, "Layout");
109 Profile::Set(profileKey,
110 page.valid
111 ? (page.infobox_config.enabled
112 ? tlMapAndInfoBoxes
113 : tlMap)
114 : tlEmpty);
116 strcpy(profileKey + prefixLen, "Bottom");
117 Profile::Set(profileKey, (unsigned)page.bottom);
119 strcpy(profileKey + prefixLen, "Main");
120 Profile::Set(profileKey, (unsigned)page.main);
124 void
125 Profile::Save(const PageSettings &settings)
127 for (unsigned i = 0; i < PageSettings::MAX_PAGES; ++i)
128 Save(settings.pages[i], i);