Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add new interface action to enable/disable debug mode. #1226

Merged
merged 1 commit into from

3 participants

@orewagundam

During development and usage of XBMC I needed many times to enable/disable debug mode, and it was really annoying to have to go to the settings window every time.
So I added a new interface action called "toggledebug", that can be assigned to a key combination in the keyboard.xml file.
Example:

<keymap>
  <global>
    <keyboard>
      ....
      <l>toggledebug</l>
      ....
    </keyboard>
  </global>
</keymap>

In this example pushing "l" enables/disables debug mode on the fly, from anywhere in XBMC.

@jmarshallnz
Owner

A builtin would probably touch less code as well (just add to Builtins.cpp).

Also, you need to cleanup the whitespace indenting - compare the diff on github.

@orewagundam

Hello, sorry for the wait.
Anyway, as requested I moved the debug code to the Builtins.cpp file, and also fixed some wrong indentation.
I hope everything is allright.

Bye

@garbear
Collaborator

Almost :)

The key is to have CBuiltins::HasCommand("toggledebug") here return true (action id is then ACTION_BUILT_IN_FUNCTION). This is done by making "toggledebug" a builtin function (listed in the BUILT_IN commands[] table instead of the ActionMapping actions[] table). Instead of static functions, your code will be below a statement like this: else if (execute.Equals("toggledebug"))

When this is done, <l>toggledebug</l> will still work plus skins and scripts can now also make use of your work.

@orewagundam

Ok, I made the action a builtin action. I only have a doubt about what to do with the SetDebugMode() static function I left in the CBuiltins class: the reason i made this function is because this code is called in two places (the interface action and the debug change option in GuiWindowSettingsCategory.cpp, and I wanted to keep the code in a single place.
I tried looking for some already existing class related somewhat to debug, but I could'nt find any, so I wanted to create a CDebug class somewhere (maybe in /utils/ ?)..

@garbear
Collaborator

SetDebugMode() needs a good home. I nominate (non-static) CAdvancedSettings::SetDebugMode(int) because we are already accessing its member variables, and this has the added benefit that you can factor out these two lines into your new function.

Alternatively, ditch the new function and just c/p the code. Thoughts jmarshallnz?

@jmarshallnz
Owner

AdvancedSettings seems reasonable - everything you need is there already as you suggest.

@orewagundam orewagundam Added interface action to toggle debug mode
Moved debug functions to Builtins.cpp

Fixed indentation

Made toggledebug a builtin action

Moved SetDebugMode to CAdvancedSettings
245e8ef
@orewagundam

I moved SetDebugMode() to the CAdvancedSettings class.
For now I didn't change the other line in AdvancedSettings.cpp, because I feel it's doing something different from what I'm doing in the new function (it's setting the loglevel to the max between logLevel and logLevelHint, while SetDebugMode switches between two different values).

@garbear garbear merged commit ff1b9a8 into xbmc:master
@garbear
Collaborator

Thanks for making XBMC even better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 2, 2012
  1. @orewagundam

    Added interface action to toggle debug mode

    orewagundam authored
    Moved debug functions to Builtins.cpp
    
    Fixed indentation
    
    Made toggledebug a builtin action
    
    Moved SetDebugMode to CAdvancedSettings
This page is out of date. Refresh to see the latest.
View
11 xbmc/interfaces/Builtins.cpp
@@ -88,6 +88,7 @@
#endif
#include <vector>
+#include "xbmc/settings/AdvancedSettings.h"
using namespace std;
using namespace XFILE;
@@ -208,6 +209,7 @@ const BUILT_IN commands[] = {
{ "LCD.Resume", false, "Resumes LCDproc" },
#endif
{ "VideoLibrary.Search", false, "Brings up a search dialog which will search the library" },
+ { "toggledebug", false, "Enables/disables debug mode" },
};
bool CBuiltins::HasCommand(const CStdString& execString)
@@ -1555,8 +1557,13 @@ int CBuiltins::Execute(const CStdString& execString)
CGUIMessage msg(GUI_MSG_SEARCH, 0, 0, 0);
g_windowManager.SendMessage(msg, WINDOW_VIDEO_NAV);
}
+ else if (execute.Equals("toggledebug"))
+ {
+ bool debug = g_guiSettings.GetBool("debug.showloginfo");
+ g_guiSettings.SetBool("debug.showloginfo", !debug);
+ g_advancedSettings.SetDebugMode(!debug);
+ }
else
return -1;
return 0;
-}
-
+}
View
18 xbmc/settings/AdvancedSettings.cpp
@@ -1128,3 +1128,21 @@ float CAdvancedSettings::GetDisplayLatency(float refreshrate)
return delay; // in seconds
}
+
+void CAdvancedSettings::SetDebugMode(bool debug)
+{
+ if (debug)
+ {
+ int level = std::max(m_logLevelHint, LOG_LEVEL_DEBUG_FREEMEM);
+ m_logLevel = level;
+ CLog::SetLogLevel(level);
+ CLog::Log(LOGNOTICE, "Enabled debug logging due to GUI setting. Level %d.", level);
+ }
+ else
+ {
+ int level = std::min(m_logLevelHint, LOG_LEVEL_DEBUG/*LOG_LEVEL_NORMAL*/);
+ CLog::Log(LOGNOTICE, "Disabled debug logging due to GUI setting. Level %d.", level);
+ m_logLevel = level;
+ CLog::SetLogLevel(level);
+ }
+}
View
2  xbmc/settings/AdvancedSettings.h
@@ -342,6 +342,8 @@ class CAdvancedSettings
float GetDisplayLatency(float refreshrate);
bool m_initialized;
+
+ void SetDebugMode(bool debug);
};
XBMC_GLOBAL(CAdvancedSettings,g_advancedSettings);
View
2  xbmc/settings/GUISettings.cpp
@@ -1462,4 +1462,4 @@ bool CGUISettings::SetLanguage(const CStdString &strLanguage)
}
return true;
-}
+}
View
15 xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -1063,20 +1063,7 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
}
else if (strSetting.Equals("debug.showloginfo"))
{
- if (g_guiSettings.GetBool("debug.showloginfo"))
- {
- int level = std::max(g_advancedSettings.m_logLevelHint, LOG_LEVEL_DEBUG_FREEMEM);
- g_advancedSettings.m_logLevel = level;
- CLog::SetLogLevel(level);
- CLog::Log(LOGNOTICE, "Enabled debug logging due to GUI setting. Level %d.", level);
- }
- else
- {
- int level = std::min(g_advancedSettings.m_logLevelHint, LOG_LEVEL_DEBUG/*LOG_LEVEL_NORMAL*/);
- CLog::Log(LOGNOTICE, "Disabled debug logging due to GUI setting. Level %d.", level);
- g_advancedSettings.m_logLevel = level;
- CLog::SetLogLevel(level);
- }
+ g_advancedSettings.SetDebugMode(g_guiSettings.GetBool("debug.showloginfo"));
}
/*else if (strSetting.Equals("musicfiles.repeat"))
{
Something went wrong with that request. Please try again.