rainmeter-studio/Library/Section.cpp

88 lines
2.2 KiB
C++
Raw Normal View History

2013-01-14 19:30:10 +00:00
/*
Copyright (C) 2013 spx
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "Section.h"
2013-02-06 10:12:16 +00:00
#include "ConfigParser.h"
2013-01-14 19:30:10 +00:00
#include "Rainmeter.h"
/*
** The constructor
**
*/
2013-05-31 14:18:52 +00:00
Section::Section(MeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(meterWindow), m_Name(name),
2013-01-14 19:30:10 +00:00
m_DynamicVariables(false),
m_UpdateDivider(1),
m_UpdateCounter(1)
{
}
/*
** The destructor
**
*/
2013-05-31 14:18:52 +00:00
Section::~Section()
2013-01-14 19:30:10 +00:00
{
}
2013-02-06 10:12:16 +00:00
/*
** Read the common options specified in the ini file. The inherited classes must
** call this base implementation if they overwrite this method.
**
*/
2013-05-31 14:18:52 +00:00
void Section::ReadOptions(ConfigParser& parser, const WCHAR* section)
2013-02-06 10:12:16 +00:00
{
int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
if (updateDivider != m_UpdateDivider)
{
m_UpdateCounter = m_UpdateDivider = updateDivider;
}
m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
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
**
*/
2013-05-31 14:18:52 +00:00
bool Section::UpdateCounter()
2013-02-06 10:12:16 +00:00
{
++m_UpdateCounter;
if (m_UpdateCounter < m_UpdateDivider) return false;
m_UpdateCounter = 0;
return true;
}
2013-01-14 19:30:10 +00:00
/*
** Execute OnUpdateAction if action is set
**
*/
2013-05-31 14:18:52 +00:00
void Section::DoUpdateAction()
2013-01-14 19:30:10 +00:00
{
if (!m_OnUpdateAction.empty())
{
GetRainmeter().ExecuteCommand(m_OnUpdateAction.c_str(), m_MeterWindow);
2013-01-14 19:30:10 +00:00
}
}