forked from rainmeter/rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSection.cpp
70 lines (60 loc) · 1.77 KB
/
Section.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Copyright (C) 2013 Rainmeter Project Developers
*
* This Source Code Form is subject to the terms of the GNU General Public
* License; either version 2 of the License, or (at your option) any later
* version. If a copy of the GPL was not distributed with this file, You can
* obtain one at <https://www.gnu.org/licenses/gpl-2.0.html>. */
#include "StdAfx.h"
#include "Section.h"
#include "ConfigParser.h"
#include "Rainmeter.h"
Section::Section(Skin* skin, const WCHAR* name) : m_Skin(skin), m_Name(name),
m_DynamicVariables(false),
m_UpdateDivider(1),
m_UpdateCounter(1)
{
}
Section::~Section()
{
}
/*
** Read the common options specified in the ini file. The inherited classes must
** call this base implementation if they overwrite this method.
**
*/
void Section::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
const int defaultUpdateDivider =
m_Skin ? m_Skin->GetDefaultUpdateDivider() : 1;
int updateDivider = parser.ReadInt(section, L"UpdateDivider", defaultUpdateDivider);
if (updateDivider != m_UpdateDivider)
{
m_UpdateCounter = m_UpdateDivider = updateDivider;
}
m_DynamicVariables = parser.ReadBool(section, L"DynamicVariables", false);
m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);
const std::wstring& group = parser.ReadString(section, L"Group", L"");
InitializeGroup(group);
}
/*
** Updates the counter value
**
*/
bool Section::UpdateCounter()
{
++m_UpdateCounter;
if (m_UpdateCounter < m_UpdateDivider) return false;
m_UpdateCounter = 0;
return true;
}
/*
** Execute OnUpdateAction if action is set
**
*/
void Section::DoUpdateAction()
{
if (!m_OnUpdateAction.empty())
{
GetRainmeter().ExecuteActionCommand(m_OnUpdateAction.c_str(), this);
}
}