First stab at converting the reporter to use JSON and updating it to a saner design.

Originally committed to SVN as r5111.
This commit is contained in:
Amar Takhar 2011-01-03 12:00:12 +00:00
parent 85b577f25e
commit 5985c60ded
7 changed files with 105 additions and 103 deletions

View file

@ -11,8 +11,8 @@ PRECOMPILED_HEADER_NAME=r_pre.h
#nodist_reporter_3_0_SOURCES = r_prec.h.gch #nodist_reporter_3_0_SOURCES = r_prec.h.gch
#endif #endif
CXXFLAGS += -Iinclude $(CFLAGS_WX) CXXFLAGS += -Iinclude $(CFLAGS_WX) -I../libaegisub/include
LDFLAGS += $(LDFLAGS_WX) $(LDFLAGS_LIBCURL) LDFLAGS += $(LDFLAGS_WX) $(LDFLAGS_LIBCURL) -L../libaegisub -laegisub-3.0 $(LDFLAGS_UCHARDET) -rpath ../libaegisub
#if PRECOMPILED_HEADER #if PRECOMPILED_HEADER
## This doesn't depend on Makefile on purpose, you should already know what you're doing when using this. ## This doesn't depend on Makefile on purpose, you should already know what you're doing when using this.

View file

@ -48,29 +48,29 @@ public:
/// Architecture /// Architecture
/// @return Architecture name. /// @return Architecture name.
/// @retval 32 bit, 64 bit /// @retval 32 bit, 64 bit
wxString ArchName(); const char* ArchName();
/// OS Family /// OS Family
/// @return OS Family /// @return OS Family
/// @retval Unix, Windows, Mac /// @retval Unix, Windows, Mac
wxString OSFamily(); const char* OSFamily();
/// OS Name /// OS Name
/// @return OS Name /// @return OS Name
/// @retval FreeBSD, Windows, Mac /// @retval FreeBSD, Windows, Mac
wxString OSName(); const char* OSName();
/// Endian /// Endian
/// @return Endian /// @return Endian
/// @retval Little endian, Big endian /// @retval Little endian, Big endian
wxString Endian(); const char* Endian();
// From <wx/gdicmn.h> // From <wx/gdicmn.h>
/// Is the display colour /// Is the display colour
/// @return true/false /// @return true/false
/// @retval 1, 0 /// @retval 1, 0
wxString DisplayColour(); int DisplayColour();
/// Display depth /// Display depth
/// @return Depth /// @return Depth
@ -92,32 +92,32 @@ public:
/// Report signature /// Report signature
/// @return Signature /// @return Signature
/// @retval SHA256 hash /// @retval SHA256 hash
wxString Signature(); std::string Signature();
/// wxWidgets version /// wxWidgets version
/// @return Version /// @return Version
/// @retval Major.Minor.Micro.Patch: 2.9.0.0 /// @retval Major.Minor.Micro.Patch: 2.9.0.0
wxString wxVersion(); const char* wxVersion();
/// Locale /// Locale
/// @return Locale name /// @return Locale name
/// @retval C,POSIX,<code> /// @retval C,POSIX,<code>
wxString Locale(); const char* Locale();
/// Language currently in use /// Language currently in use
/// @return Language reporter is currently running in /// @return Language reporter is currently running in
/// @retval Language code: en_US, en_CA... /// @retval Language code: en_US, en_CA...
wxString Language(); const char* Language();
/// System language /// System language
/// @return Language operating system is currently running in /// @return Language operating system is currently running in
/// @retval Language code: en_US, en_CA... /// @retval Language code: en_US, en_CA...
wxString SystemLanguage(); const char* SystemLanguage();
/// Date /// Date
/// @return Date /// @return Date
/// @retval Date in YYYY-MM-DD /// @retval Date in YYYY-MM-DD
wxString Date(); std::string Date();
/// Time /// Time
/// @return Time /// @return Time
@ -138,7 +138,7 @@ public:
/// Operating System version /// Operating System version
/// @return OS Version /// @return OS Version
/// @retval Any /// @retval Any
virtual wxString OSVersion()=0; virtual const std::string OSVersion()=0;
// Hardware // Hardware

View file

@ -104,24 +104,25 @@ wxString Platform::GetVideoInfo(enum Platform::VideoInfo which) {
return value; return value;
} }
wxString Platform::ArchName() { const char* Platform::ArchName() {
return plat.GetArchName(); return plat.GetArchName().c_str();
}; };
wxString Platform::OSFamily() { const char* Platform::OSFamily() {
return plat.GetOperatingSystemFamilyName(); return plat.GetOperatingSystemFamilyName().c_str();
}; };
wxString Platform::OSName() { const char* Platform::OSName() {
return plat.GetOperatingSystemIdName(); return plat.GetOperatingSystemIdName().c_str();
}; };
wxString Platform::Endian() { const char* Platform::Endian() {
return plat.GetEndiannessName(); return plat.GetEndiannessName().c_str();
}; };
wxString Platform::DisplayColour() { int Platform::DisplayColour() {
return wxString::Format(L"%d", wxColourDisplay()); return wxColourDisplay();
//wxString::Format(L"%d", wxColourDisplay());
} }
wxString Platform::DisplayDepth() { wxString Platform::DisplayDepth() {
@ -138,29 +139,29 @@ wxString Platform::DisplayPPI() {
return wxString::Format(L"%d %d", wxGetDisplayPPI().GetWidth(), wxGetDisplayPPI().GetHeight()); return wxString::Format(L"%d %d", wxGetDisplayPPI().GetWidth(), wxGetDisplayPPI().GetHeight());
} }
wxString Platform::wxVersion() { const char* Platform::wxVersion() {
return wxString::Format(L"%d.%d.%d.%d", wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, wxSUBRELEASE_NUMBER); return wxString::Format(L"%d.%d.%d.%d", wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, wxSUBRELEASE_NUMBER).c_str();
} }
wxString Platform::Locale() { const char* Platform::Locale() {
return wxLocale().GetSysName(); return wxLocale().GetSysName().c_str();
} }
wxString Platform::Language() { const char* Platform::Language() {
const wxLanguageInfo *info = locale->GetLanguageInfo(locale->GetLanguage()); const wxLanguageInfo *info = locale->GetLanguageInfo(locale->GetLanguage());
return info->CanonicalName; return info->CanonicalName.c_str();
} }
wxString Platform::SystemLanguage() { const char* Platform::SystemLanguage() {
const wxLanguageInfo *info = locale->GetLanguageInfo(locale->GetSystemLanguage()); const wxLanguageInfo *info = locale->GetLanguageInfo(locale->GetSystemLanguage());
return info->CanonicalName; return info->CanonicalName.c_str();
} }
wxString Platform::Date() { std::string Platform::Date() {
return ""; return "";
} }
wxString Platform::Signature() { std::string Platform::Signature() {
return ""; return "";
} }

View file

@ -32,7 +32,7 @@ extern "C" {
} }
wxString PlatformUnix::OSVersion() { const std::string PlatformUnix::OSVersion() {
struct utsname name; struct utsname name;
if (uname(&name) != -1) { if (uname(&name) != -1) {
return name.release; return name.release;

View file

@ -25,7 +25,7 @@ class PlatformUnix : public Platform {
public: public:
PlatformUnix() {}; PlatformUnix() {};
virtual ~PlatformUnix() {}; virtual ~PlatformUnix() {};
wxString OSVersion(); const std::string OSVersion();
wxString DesktopEnvironment(); wxString DesktopEnvironment();
// Hardware // Hardware

View file

@ -25,7 +25,7 @@ class PlatformWindows : public Platform {
public: public:
PlatformWindows() {}; PlatformWindows() {};
virtual ~PlatformWindows() {}; virtual ~PlatformWindows() {};
wxString OSVersion(); const std::string OSVersion();
wxString DesktopEnvironment(); wxString DesktopEnvironment();
// Hardware // Hardware

View file

@ -23,6 +23,10 @@
#include <wx/log.h> #include <wx/log.h>
#endif #endif
#include <libaegisub/cajun/elements.h>
#include <libaegisub/cajun/writer.h>
#include "report.h" #include "report.h"
#include "include/platform.h" #include "include/platform.h"
#include "aegisub.h" #include "aegisub.h"
@ -36,102 +40,99 @@ Report::Report() {
/// @return Document. /// @return Document.
Report::XMLReport Report::ReportCreate() { Report::XMLReport Report::ReportCreate() {
// So we can use GetString() below.
locale = new wxLocale();
doc.doc = new wxXmlDocument(); json::Object root;
doc.report = new wxXmlNode(wxXML_ELEMENT_NODE, "report");
doc.doc->SetRoot(doc.report);
Platform *p = Platform::GetPlatform(); Platform *p = Platform::GetPlatform();
doc.general = new wxXmlNode(doc.report, wxXML_ELEMENT_NODE, "general"); json::Object general;
Add(doc.general, "signature", p->Signature()); general["Signature"] = json::String(p->Signature());
Add(doc.general, "date", p->Date()); general["Date"] = json::String(p->Date());
Add(doc.general, "arch", p->ArchName()); general["Architecture"] = json::String(p->ArchName());
Add(doc.general, "osfamily", p->OSFamily()); general["OS Family"] = json::String(p->OSFamily());
Add(doc.general, "osname", p->OSName()); general["OS Name"] = json::String(p->OSName());
Add(doc.general, "osendian", p->Endian()); general["Endian"] = json::String(p->Endian());
Add(doc.general, "osversion", p->OSVersion()); general["OS Version"] = json::String(p->OSVersion());
Add(doc.general, "wxversion", p->wxVersion()); general["wx Version"] = json::String(p->wxVersion());
Add(doc.general, "locale", p->Locale()); general["Locale"] = json::String(p->Locale());
Add(doc.general, "lang", p->Language()); general["Language"] = json::String(p->Language());
Add(doc.general, "syslang", p->SystemLanguage()); general["System Language"] = json::String(p->SystemLanguage());
doc.aegisub = new wxXmlNode(wxXML_ELEMENT_NODE, "aegisub"); /*
doc.aegisub = new wxXmlNode(wxXML_ELEMENT_NODE, Aegisub);
doc.report->AddChild(doc.aegisub); doc.report->AddChild(doc.aegisub);
Aegisub *config = new Aegisub(); Aegisub *config = new Aegisub();
Add(doc.aegisub, "lastversion", config->Read("Config/last version")); Add(doc.aegisub, Last Version, config->Read("Config/last version"));
Add(doc.aegisub, "spelllang", config->Read("Config/spell checker language")); Add(doc.aegisub, Spelling Language, config->Read("Config/spell checker language"));
Add(doc.aegisub, "thesauruslang", config->Read("Config/thesaurus language")); Add(doc.aegisub, Thesaurus Language, config->Read("Config/thesaurus language"));
Add(doc.aegisub, "audioplayer", config->Read("Config/audio player")); Add(doc.aegisub, Audio Player, config->Read("Config/audio player"));
Add(doc.aegisub, "audioprovider", config->Read("Config/audio provider")); Add(doc.aegisub, Audio Provider, config->Read("Config/audio provider"));
Add(doc.aegisub, "videoprovider", config->Read("Config/video provider")); Add(doc.aegisub, Video Provider, config->Read("Config/video provider"));
Add(doc.aegisub, "subtitleprovider", config->Read("Config/subtitles provider")); Add(doc.aegisub, Subtitles Provider, config->Read("Config/subtitles provider"));
Add(doc.aegisub, "savecharset", config->Read("Config/save charset")); Add(doc.aegisub, Save Charset, config->Read("Config/save charset"));
Add(doc.aegisub, "gridfontsize", config->Read("Config/grid font size")); Add(doc.aegisub, Grid Font Size, config->Read("Config/grid font size"));
Add(doc.aegisub, "editfontsize", config->Read("Config/edit font size")); Add(doc.aegisub, Edit Font Size, config->Read("Config/edit font size"));
Add(doc.aegisub, "spectrum", config->Read("Config/audio spectrum")); Add(doc.aegisub, Spectrum Enabled, config->Read("Config/audio spectrum"));
Add(doc.aegisub, "spectrumqual", config->Read("Config/audio spectrum quality")); Add(doc.aegisub, Spectrum Quality, config->Read("Config/audio spectrum quality"));
Add(doc.aegisub, "calltips", config->Read("Config/call tips enabled")); Add(doc.aegisub, Call Tips Enabled, config->Read("Config/call tips enabled"));
Add(doc.aegisub, "medusakeys", config->Read("Config/audio medusa timing hotkeys")); Add(doc.aegisub, Medusa Hotkeys Enabled, config->Read("Config/audio medusa timing hotkeys"));
doc.hardware = new wxXmlNode(wxXML_ELEMENT_NODE, "hardware"); doc.hardware = new wxXmlNode(wxXML_ELEMENT_NODE, Hardware);
doc.report->AddChild(doc.hardware); doc.report->AddChild(doc.hardware);
Add(doc.hardware, "memory", p->Memory()); Add(doc.hardware, Memory, p->Memory());
wxXmlNode *cpu = new wxXmlNode(wxXML_ELEMENT_NODE, "cpu"); wxXmlNode *cpu = new wxXmlNode(wxXML_ELEMENT_NODE, CPU);
doc.hardware->AddChild(cpu); doc.hardware->AddChild(cpu);
Add(cpu, "id", p->CPUId()); Add(cpu, Id, p->CPUId());
Add(cpu, "speed", p->CPUSpeed()); Add(cpu, Speed, p->CPUSpeed());
Add(cpu, "count", p->CPUCount()); Add(cpu, Count, p->CPUCount());
Add(cpu, "cores", p->CPUCores()); Add(cpu, Cores, p->CPUCores());
Add(cpu, "features", p->CPUFeatures()); Add(cpu, Features, p->CPUFeatures());
Add(cpu, "features2", p->CPUFeatures2()); Add(cpu, Features2, p->CPUFeatures2());
wxXmlNode *display = new wxXmlNode(wxXML_ELEMENT_NODE, "display"); wxXmlNode *display = new wxXmlNode(wxXML_ELEMENT_NODE, Display);
doc.hardware->AddChild(display); doc.hardware->AddChild(display);
Add(display, "depth", p->DisplayDepth()); Add(display, Depth, p->DisplayDepth());
Add(display, "colour", p->DisplayColour()); Add(display, Colour Screen, p->DisplayColour());
Add(display, "size", p->DisplaySize()); Add(display, Size, p->DisplaySize());
Add(display, "ppi", p->DisplayPPI()); Add(display, Pixels Per Inch, p->DisplayPPI());
wxXmlNode *display_gl = new wxXmlNode(wxXML_ELEMENT_NODE, "opengl"); wxXmlNode *display_gl = new wxXmlNode(wxXML_ELEMENT_NODE, OpenGL);
display->AddChild(display_gl); display->AddChild(display_gl);
Add(display_gl, "vendor", p->OpenGLVendor()); Add(display_gl, Vendor, p->OpenGLVendor());
Add(display_gl, "renderer", p->OpenGLRenderer()); Add(display_gl, Renderer, p->OpenGLRenderer());
Add(display_gl, "version", p->OpenGLVersion()); Add(display_gl, Version, p->OpenGLVersion());
Add(display_gl, "extensions", p->OpenGLExt()); Add(display_gl, Extensions, p->OpenGLExt());
#ifdef __WINDOWS__ #ifdef __WINDOWS__
doc.windows = new wxXmlNode(wxXML_ELEMENT_NODE, "windows"); doc.windows = new wxXmlNode(wxXML_ELEMENT_NODE, Windows);
doc.report->AddChild(doc.windows); doc.report->AddChild(doc.windows);
Add(doc.windows, "sp", p->ServicePack()); Add(doc.windows, Service Pack, p->ServicePack());
Add(doc.windows, "graphicsver", p->DriverGraphicsVersion()); Add(doc.windows, Graphics Driver Version, p->DriverGraphicsVersion());
Add(doc.windows, "dshowfilter", p->DirectShowFilters()); Add(doc.windows, DirectShow Filters, p->DirectShowFilters());
Add(doc.windows, "antivirus", p->AntiVirus()); Add(doc.windows, AntiVirus Installed, p->AntiVirus());
Add(doc.windows, "firewall", p->Firewall()); Add(doc.windows, Firewall Installed, p->Firewall());
Add(doc.windows, "dll", p->DLLVersions()); Add(doc.windows, DLL, p->DLLVersions());
#endif #endif
#ifdef __UNIX__ #ifdef __UNIX__
doc.unixx = new wxXmlNode(wxXML_ELEMENT_NODE, "unix"); doc.unixx = new wxXmlNode(wxXML_ELEMENT_NODE, Unix);
doc.report->AddChild(doc.unixx); doc.report->AddChild(doc.unixx);
Add(doc.unixx, "desktopenv", p->DesktopEnvironment()); Add(doc.unixx, Desktop Environment, p->DesktopEnvironment());
Add(doc.unixx, "lib", p->UnixLibraries()); Add(doc.unixx, Libraries, p->UnixLibraries());
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
doc.osx = new wxXmlNode(wxXML_ELEMENT_NODE, "osx"); doc.osx = new wxXmlNode(wxXML_ELEMENT_NODE, OS X);
doc.report->AddChild(doc.osx); doc.report->AddChild(doc.osx);
Add(doc.osx, "patch", p->PatchLevel()); Add(doc.osx, Patch, p->PatchLevel());
Add(doc.osx, "quicktimeext", p->QuickTimeExt()); Add(doc.osx, QuickTime Extensions, p->QuickTimeExt());
Add(doc.osx, "model", p->HardwareModel()); Add(doc.osx, Model, p->HardwareModel());
#endif #endif
*/
return doc; return doc;
} }