Skip to content
This repository

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

Merged
merged 1 commit into from over 1 year ago

3 participants

orewagundam jmarshallnz Garrett Brown
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

Garrett Brown
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/ ?)..

Garrett Brown
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 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).

Garrett Brown garbear merged commit ff1b9a8 into from August 02, 2012
Garrett Brown garbear closed this August 02, 2012
Garrett Brown
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

Showing 1 unique commit by 1 author.

Aug 02, 2012
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
This page is out of date. Refresh to see the latest.
11  xbmc/interfaces/Builtins.cpp
@@ -88,6 +88,7 @@
88 88
 #endif
89 89
 
90 90
 #include <vector>
  91
+#include "xbmc/settings/AdvancedSettings.h"
91 92
 
92 93
 using namespace std;
93 94
 using namespace XFILE;
@@ -208,6 +209,7 @@ const BUILT_IN commands[] = {
208 209
   { "LCD.Resume",                 false,  "Resumes LCDproc" },
209 210
 #endif
210 211
   { "VideoLibrary.Search",        false,  "Brings up a search dialog which will search the library" },
  212
+  { "toggledebug",                false,  "Enables/disables debug mode" },
211 213
 };
212 214
 
213 215
 bool CBuiltins::HasCommand(const CStdString& execString)
@@ -1555,8 +1557,13 @@ int CBuiltins::Execute(const CStdString& execString)
1555 1557
     CGUIMessage msg(GUI_MSG_SEARCH, 0, 0, 0);
1556 1558
     g_windowManager.SendMessage(msg, WINDOW_VIDEO_NAV);
1557 1559
   }
  1560
+  else if (execute.Equals("toggledebug"))
  1561
+  {
  1562
+    bool debug = g_guiSettings.GetBool("debug.showloginfo");
  1563
+    g_guiSettings.SetBool("debug.showloginfo", !debug);
  1564
+    g_advancedSettings.SetDebugMode(!debug);
  1565
+  }
1558 1566
   else
1559 1567
     return -1;
1560 1568
   return 0;
1561  
-}
1562  
-
  1569
+}
18  xbmc/settings/AdvancedSettings.cpp
@@ -1128,3 +1128,21 @@ float CAdvancedSettings::GetDisplayLatency(float refreshrate)
1128 1128
 
1129 1129
   return delay; // in seconds
1130 1130
 }
  1131
+
  1132
+void CAdvancedSettings::SetDebugMode(bool debug)
  1133
+{
  1134
+  if (debug)
  1135
+  {
  1136
+    int level = std::max(m_logLevelHint, LOG_LEVEL_DEBUG_FREEMEM);
  1137
+    m_logLevel = level;
  1138
+    CLog::SetLogLevel(level);
  1139
+    CLog::Log(LOGNOTICE, "Enabled debug logging due to GUI setting. Level %d.", level);
  1140
+  }
  1141
+  else
  1142
+  {
  1143
+    int level = std::min(m_logLevelHint, LOG_LEVEL_DEBUG/*LOG_LEVEL_NORMAL*/);
  1144
+    CLog::Log(LOGNOTICE, "Disabled debug logging due to GUI setting. Level %d.", level);
  1145
+    m_logLevel = level;
  1146
+    CLog::SetLogLevel(level);
  1147
+  }	
  1148
+}
2  xbmc/settings/AdvancedSettings.h
@@ -342,6 +342,8 @@ class CAdvancedSettings
342 342
 
343 343
     float GetDisplayLatency(float refreshrate);
344 344
     bool m_initialized;
  345
+
  346
+    void SetDebugMode(bool debug);
345 347
 };
346 348
 
347 349
 XBMC_GLOBAL(CAdvancedSettings,g_advancedSettings);
2  xbmc/settings/GUISettings.cpp
@@ -1462,4 +1462,4 @@ bool CGUISettings::SetLanguage(const CStdString &strLanguage)
1462 1462
   }
1463 1463
 
1464 1464
   return true;
1465  
-}
  1465
+}
15  xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -1063,20 +1063,7 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
1063 1063
   }
1064 1064
   else if (strSetting.Equals("debug.showloginfo"))
1065 1065
   {
1066  
-    if (g_guiSettings.GetBool("debug.showloginfo"))
1067  
-    {
1068  
-      int level = std::max(g_advancedSettings.m_logLevelHint, LOG_LEVEL_DEBUG_FREEMEM);
1069  
-      g_advancedSettings.m_logLevel = level;
1070  
-      CLog::SetLogLevel(level);
1071  
-      CLog::Log(LOGNOTICE, "Enabled debug logging due to GUI setting. Level %d.", level);
1072  
-    }
1073  
-    else
1074  
-    {
1075  
-      int level = std::min(g_advancedSettings.m_logLevelHint, LOG_LEVEL_DEBUG/*LOG_LEVEL_NORMAL*/);
1076  
-      CLog::Log(LOGNOTICE, "Disabled debug logging due to GUI setting. Level %d.", level);
1077  
-      g_advancedSettings.m_logLevel = level;
1078  
-      CLog::SetLogLevel(level);
1079  
-    }
  1066
+    g_advancedSettings.SetDebugMode(g_guiSettings.GetBool("debug.showloginfo"));
1080 1067
   }
1081 1068
   /*else if (strSetting.Equals("musicfiles.repeat"))
1082 1069
   {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.