Skip to content

Commit

Permalink
gui option added for enabling/disabling of shutdownHookCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
svenburkard committed Sep 13, 2014
1 parent 89b93f2 commit f0e5f80
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 19 deletions.
29 changes: 25 additions & 4 deletions language/English/strings.po
Expand Up @@ -5047,7 +5047,12 @@ msgctxt "#13036"
msgid "Failed for %s"
msgstr ""

#empty strings from id 13037 to 13049
#: system/settings/settings.xml
msgctxt "#13037"
msgid "Enable shutdownHookCheck"
msgstr ""

#empty strings from id 13038 to 13049

#: xbmc\powermanagement\PowerManager.cpp
msgctxt "#13050"
Expand Down Expand Up @@ -6694,7 +6699,12 @@ msgctxt "#14101"
msgid "Acceleration"
msgstr ""

#empty strings from id 14102 to 15011
#: system/settings/settings.xml
msgctxt "#14102"
msgid "ShutdownHookCheck"
msgstr ""

#empty strings from id 14103 to 15011

#: xbmc/video/VideoDatabase.cpp
msgctxt "#15012"
Expand Down Expand Up @@ -15107,7 +15117,12 @@ msgctxt "#36419"
msgid "Define locations used for retrieving weather information."
msgstr ""

#empty string with id 36420
#. Description of setting "System -> Power saving -> enable shutdownHookCheck" with label #13037
#: system/settings/settings.xml
msgctxt "#36420"
msgid "Custom scripts will be executed automatic right before shutdown/exit/hibernate/...\nand if one of the scripts exits with an exit-code not 0, the shutdown/exit/hibernate/...\nprocess will be stopped."
msgstr ""


#. Description of setting "Videos -> Playback -> Prefer VDPAU Video Mixer" with label #13437
#: system/settings/settings.xml
Expand Down Expand Up @@ -15170,7 +15185,13 @@ msgctxt "#36431"
msgid "Defines whether video decoding should be performed in software (requires more CPU) or with hardware acceleration where possible."
msgstr ""

#empty strings from id 36432 to 36499
#. Description of settings category "System -> ShutdownHookCheck" with label #14102
#: system/settings/settings.xml
msgctxt "#36432"
msgid "Category containing settings for shutdownHookCheck."
msgstr ""

#empty strings from id 36433 to 36499
#end reservation

#: system/settings/settings.xml
Expand Down
9 changes: 9 additions & 0 deletions system/settings/settings.xml
Expand Up @@ -2761,6 +2761,15 @@
</setting>
</group>
</category>
<category id="ShutdownHookCheck" label="14102" help="36432"> <!-- shutdownHookCheck -->
<group id="1">
<setting id="shutdownHookCheck.enabled" type="boolean" label="13037" help="36420">
<level>1</level>
<default>false</default>
<control type="toggle" />
</setting>
</group>
</category>
<category id="debug" label="14092" help="36391">
<group id="1">
<setting id="debug.showloginfo" type="boolean" label="20191" help="36392">
Expand Down
20 changes: 10 additions & 10 deletions xbmc/ApplicationMessenger.cpp
Expand Up @@ -236,35 +236,35 @@ void CApplicationMessenger::ProcessMessage(ThreadMessage *pMsg)
switch (CSettings::Get().GetInt("powermanagement.shutdownstate"))
{
case POWERSTATE_SHUTDOWN:
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
Powerdown();
break;
}

case POWERSTATE_SUSPEND:
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
Suspend();
break;
}

case POWERSTATE_HIBERNATE:
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
Hibernate();
break;
}

case POWERSTATE_QUIT:
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
Quit();
break;
}

case POWERSTATE_MINIMIZE:
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
Minimize();
break;
Expand All @@ -279,7 +279,7 @@ void CApplicationMessenger::ProcessMessage(ThreadMessage *pMsg)

case TMSG_POWERDOWN:
{
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
g_application.Stop(EXITCODE_POWERDOWN);
g_powerManager.Powerdown();
Expand All @@ -289,7 +289,7 @@ void CApplicationMessenger::ProcessMessage(ThreadMessage *pMsg)

case TMSG_QUIT:
{
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
g_application.Stop(EXITCODE_QUIT);
}
Expand All @@ -298,7 +298,7 @@ void CApplicationMessenger::ProcessMessage(ThreadMessage *pMsg)

case TMSG_HIBERNATE:
{
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
g_PVRManager.SetWakeupCommand();
g_powerManager.Hibernate();
Expand All @@ -308,7 +308,7 @@ void CApplicationMessenger::ProcessMessage(ThreadMessage *pMsg)

case TMSG_SUSPEND:
{
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
g_PVRManager.SetWakeupCommand();
g_powerManager.Suspend();
Expand All @@ -319,7 +319,7 @@ void CApplicationMessenger::ProcessMessage(ThreadMessage *pMsg)
case TMSG_RESTART:
case TMSG_RESET:
{
if(CshutdownHookCheck.shutdownHookCheck())
if(!(CshutdownHookCheck.isEnabled()) || CshutdownHookCheck.shutdownHookCheck())
{
g_application.Stop(EXITCODE_REBOOT);
g_powerManager.Reboot();
Expand Down
103 changes: 98 additions & 5 deletions xbmc/shutdownHookCheck.cpp
Expand Up @@ -7,11 +7,12 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// system includes
#include <cstdlib> // system / getenv
//#include <iostream> // cout
#include <dirent.h> // dir...
#include <string.h> // strcmp
#include <sys/stat.h> // stat
#include <cstdlib> // system / getenv
//#include <iostream> // cout
#include <dirent.h> // dir...
#include <string.h> // strcmp
#include <sys/stat.h> // stat
#include <libxml/parser.h>

// xbmc includes
#include "utils/log.h"
Expand Down Expand Up @@ -43,6 +44,98 @@ bool fileIsExecutable(const string file)
}


////////////////////////////////////////////////////////
bool parseSetting(xmlDocPtr doc, xmlNodePtr cur, string settingKey)
{
////////////////////////////////////////////////////////

xmlChar *settingValue;

cur = cur->xmlChildrenNode;

while(cur != NULL)
{
if((!xmlStrcmp(cur->name, (const xmlChar *)settingKey.c_str())))
{

settingValue = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);

if(strcmp((const char *)settingValue, "true") == 0)
{
xmlFree(settingValue);
return true;
}
else
{
xmlFree(settingValue);
return false;
}
}
cur = cur->next;
}

return false;
}


////////////////////////////////////////////////////////
bool CshutdownHookCheck::isEnabled()
{
////////////////////////////////////////////////////////

string dirHome = CSpecialProtocol::TranslatePath("special://home/").c_str();
string settingsFile = dirHome + "/userdata/guisettings.xml";
string settingCategory = "shutdownHookCheck";
string settingKey = "enabled";

xmlDocPtr doc;
xmlNodePtr cur;

CLog::Log(LOGDEBUG,"[shutdownHookCheck] settingsfile:>>%s<<", settingsFile.c_str());

doc = xmlParseFile(settingsFile.c_str());

if(doc == NULL)
{
CLog::Log(LOGERROR,"[shutdownHookCheck] parsing of the settingsfile failed (%s)!", settingsFile.c_str());
return false;
}

cur = xmlDocGetRootElement(doc);

if(cur == NULL)
{
xmlFreeDoc(doc);
CLog::Log(LOGERROR,"[shutdownHookCheck] settingsfile (%s) is empty!", settingsFile.c_str());
return false;
}

cur = cur->xmlChildrenNode;

while(cur != NULL)
{
if((!xmlStrcmp(cur->name, (const xmlChar *)settingCategory.c_str())))
{
if(parseSetting(doc, cur, settingKey.c_str()))
{
CLog::Log(LOGDEBUG,"[shutdownHookCheck] is enabled");
return true;
}
else
{
CLog::Log(LOGDEBUG,"[shutdownHookCheck] is disabled");
return false;
}
}
cur = cur->next;
}

xmlFreeDoc(doc);
CLog::Log(LOGWARNING,"[shutdownHookCheck] is disabled (because of an ERROR)");
return false;
}


////////////////////////////////////////////////////////
bool CshutdownHookCheck::shutdownHookCheck()
{
Expand Down
1 change: 1 addition & 0 deletions xbmc/shutdownHookCheck.h
Expand Up @@ -10,6 +10,7 @@
class CshutdownHookCheck
{
public:
bool isEnabled();
bool shutdownHookCheck();
};

0 comments on commit f0e5f80

Please sign in to comment.