2009-09-03 08:53:55 +02:00
|
|
|
// Copyright (c) 2009, Amar Takhar <verm@aegisub.org>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
2009-09-26 11:22:54 +02:00
|
|
|
/// @file report.cpp
|
2009-09-03 08:53:55 +02:00
|
|
|
/// @brief Generation and manipulation of reports.
|
2009-09-26 11:38:17 +02:00
|
|
|
/// @ingroup base
|
2009-09-03 08:53:55 +02:00
|
|
|
|
|
|
|
#ifndef R_PRECOMP
|
|
|
|
#include <wx/intl.h>
|
2009-09-26 16:53:27 +02:00
|
|
|
#include <wx/log.h>
|
2009-09-03 08:53:55 +02:00
|
|
|
#endif
|
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
#include <libaegisub/cajun/elements.h>
|
|
|
|
#include <libaegisub/cajun/writer.h>
|
|
|
|
|
|
|
|
|
2009-09-03 08:53:55 +02:00
|
|
|
#include "report.h"
|
2009-10-03 19:16:52 +02:00
|
|
|
#include "include/platform.h"
|
2009-09-03 08:53:55 +02:00
|
|
|
#include "aegisub.h"
|
|
|
|
|
|
|
|
/// @brief Contstructor
|
|
|
|
Report::Report() {
|
|
|
|
ReportCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Create report layout and add contents.
|
|
|
|
/// @return Document.
|
|
|
|
Report::XMLReport Report::ReportCreate() {
|
|
|
|
|
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
json::Object root;
|
2009-09-03 08:53:55 +02:00
|
|
|
|
2009-10-03 19:16:52 +02:00
|
|
|
Platform *p = Platform::GetPlatform();
|
2009-09-03 08:53:55 +02:00
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
json::Object general;
|
|
|
|
general["Signature"] = json::String(p->Signature());
|
|
|
|
general["Date"] = json::String(p->Date());
|
|
|
|
general["Architecture"] = json::String(p->ArchName());
|
|
|
|
general["OS Family"] = json::String(p->OSFamily());
|
|
|
|
general["OS Name"] = json::String(p->OSName());
|
|
|
|
general["Endian"] = json::String(p->Endian());
|
|
|
|
general["OS Version"] = json::String(p->OSVersion());
|
|
|
|
general["wx Version"] = json::String(p->wxVersion());
|
|
|
|
general["Locale"] = json::String(p->Locale());
|
|
|
|
general["Language"] = json::String(p->Language());
|
|
|
|
general["System Language"] = json::String(p->SystemLanguage());
|
|
|
|
|
|
|
|
/*
|
|
|
|
doc.aegisub = new wxXmlNode(wxXML_ELEMENT_NODE, Aegisub);
|
2009-09-03 08:53:55 +02:00
|
|
|
doc.report->AddChild(doc.aegisub);
|
|
|
|
|
2009-10-03 19:16:52 +02:00
|
|
|
Aegisub *config = new Aegisub();
|
2011-01-03 13:00:12 +01:00
|
|
|
Add(doc.aegisub, Last Version, config->Read("Config/last version"));
|
|
|
|
Add(doc.aegisub, Spelling Language, config->Read("Config/spell checker language"));
|
|
|
|
Add(doc.aegisub, Thesaurus Language, config->Read("Config/thesaurus language"));
|
|
|
|
Add(doc.aegisub, Audio Player, config->Read("Config/audio player"));
|
|
|
|
Add(doc.aegisub, Audio Provider, config->Read("Config/audio provider"));
|
|
|
|
Add(doc.aegisub, Video Provider, config->Read("Config/video provider"));
|
|
|
|
Add(doc.aegisub, Subtitles Provider, config->Read("Config/subtitles provider"));
|
|
|
|
Add(doc.aegisub, Save Charset, config->Read("Config/save charset"));
|
|
|
|
Add(doc.aegisub, Grid Font Size, config->Read("Config/grid font size"));
|
|
|
|
Add(doc.aegisub, Edit Font Size, config->Read("Config/edit font size"));
|
|
|
|
Add(doc.aegisub, Spectrum Enabled, config->Read("Config/audio spectrum"));
|
|
|
|
Add(doc.aegisub, Spectrum Quality, config->Read("Config/audio spectrum quality"));
|
|
|
|
Add(doc.aegisub, Call Tips Enabled, config->Read("Config/call tips enabled"));
|
|
|
|
Add(doc.aegisub, Medusa Hotkeys Enabled, config->Read("Config/audio medusa timing hotkeys"));
|
|
|
|
|
|
|
|
doc.hardware = new wxXmlNode(wxXML_ELEMENT_NODE, Hardware);
|
2009-09-03 08:53:55 +02:00
|
|
|
doc.report->AddChild(doc.hardware);
|
2011-01-03 13:00:12 +01:00
|
|
|
Add(doc.hardware, Memory, p->Memory());
|
2009-09-03 08:53:55 +02:00
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
wxXmlNode *cpu = new wxXmlNode(wxXML_ELEMENT_NODE, CPU);
|
2009-10-03 19:16:52 +02:00
|
|
|
doc.hardware->AddChild(cpu);
|
2011-01-03 13:00:12 +01:00
|
|
|
Add(cpu, Id, p->CPUId());
|
|
|
|
Add(cpu, Speed, p->CPUSpeed());
|
|
|
|
Add(cpu, Count, p->CPUCount());
|
|
|
|
Add(cpu, Cores, p->CPUCores());
|
|
|
|
Add(cpu, Features, p->CPUFeatures());
|
|
|
|
Add(cpu, Features2, p->CPUFeatures2());
|
|
|
|
|
|
|
|
wxXmlNode *display = new wxXmlNode(wxXML_ELEMENT_NODE, Display);
|
2009-10-03 19:16:52 +02:00
|
|
|
doc.hardware->AddChild(display);
|
2011-01-03 13:00:12 +01:00
|
|
|
Add(display, Depth, p->DisplayDepth());
|
|
|
|
Add(display, Colour Screen, p->DisplayColour());
|
|
|
|
Add(display, Size, p->DisplaySize());
|
|
|
|
Add(display, Pixels Per Inch, p->DisplayPPI());
|
2009-10-03 19:16:52 +02:00
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
wxXmlNode *display_gl = new wxXmlNode(wxXML_ELEMENT_NODE, OpenGL);
|
2009-10-03 19:16:52 +02:00
|
|
|
display->AddChild(display_gl);
|
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
Add(display_gl, Vendor, p->OpenGLVendor());
|
|
|
|
Add(display_gl, Renderer, p->OpenGLRenderer());
|
|
|
|
Add(display_gl, Version, p->OpenGLVersion());
|
|
|
|
Add(display_gl, Extensions, p->OpenGLExt());
|
2009-09-28 10:08:16 +02:00
|
|
|
|
2009-09-03 08:53:55 +02:00
|
|
|
#ifdef __WINDOWS__
|
2011-01-03 13:00:12 +01:00
|
|
|
doc.windows = new wxXmlNode(wxXML_ELEMENT_NODE, Windows);
|
2009-09-03 08:53:55 +02:00
|
|
|
doc.report->AddChild(doc.windows);
|
2011-01-03 13:00:12 +01:00
|
|
|
Add(doc.windows, Service Pack, p->ServicePack());
|
|
|
|
Add(doc.windows, Graphics Driver Version, p->DriverGraphicsVersion());
|
|
|
|
Add(doc.windows, DirectShow Filters, p->DirectShowFilters());
|
|
|
|
Add(doc.windows, AntiVirus Installed, p->AntiVirus());
|
|
|
|
Add(doc.windows, Firewall Installed, p->Firewall());
|
|
|
|
Add(doc.windows, DLL, p->DLLVersions());
|
2009-09-03 08:53:55 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __UNIX__
|
2011-01-03 13:00:12 +01:00
|
|
|
doc.unixx = new wxXmlNode(wxXML_ELEMENT_NODE, Unix);
|
2009-09-03 08:53:55 +02:00
|
|
|
doc.report->AddChild(doc.unixx);
|
2011-01-03 13:00:12 +01:00
|
|
|
Add(doc.unixx, Desktop Environment, p->DesktopEnvironment());
|
|
|
|
Add(doc.unixx, Libraries, p->UnixLibraries());
|
2009-09-03 08:53:55 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
2011-01-03 13:00:12 +01:00
|
|
|
doc.osx = new wxXmlNode(wxXML_ELEMENT_NODE, OS X);
|
2009-09-03 08:53:55 +02:00
|
|
|
doc.report->AddChild(doc.osx);
|
2011-01-03 13:00:12 +01:00
|
|
|
Add(doc.osx, Patch, p->PatchLevel());
|
|
|
|
Add(doc.osx, QuickTime Extensions, p->QuickTimeExt());
|
|
|
|
Add(doc.osx, Model, p->HardwareModel());
|
2009-09-03 08:53:55 +02:00
|
|
|
|
|
|
|
#endif
|
2011-01-03 13:00:12 +01:00
|
|
|
*/
|
2009-09-03 08:53:55 +02:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Add a new XML node.
|
|
|
|
/// @param parent Parent nodee
|
|
|
|
/// @param node Name of the new node
|
|
|
|
/// @param text Contents
|
|
|
|
void Report::Add(wxXmlNode *parent, wxString node, wxString text) {
|
|
|
|
// Using AddChild() keeps the nodes in their natural order. It's slower but our
|
|
|
|
// document is pretty small. Doing it the faster way results in reverse-ordered nodes.
|
|
|
|
wxXmlNode *tmp = new wxXmlNode(wxXML_ELEMENT_NODE, node);
|
2009-10-03 19:16:52 +02:00
|
|
|
tmp->AddChild(new wxXmlNode(wxXML_TEXT_NODE, node, text));
|
2009-09-03 08:53:55 +02:00
|
|
|
parent->AddChild(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Recursive function to populate listView and text-based for Clipboard.
|
|
|
|
/// @param node Node to parse.
|
|
|
|
/// @param listView wxListView to populate.
|
|
|
|
void Report::ProcessNode(wxXmlNode *node, wxString *text, wxListView *listView) {
|
|
|
|
wxString node_name;
|
|
|
|
nameMap::iterator names;
|
|
|
|
nameMap nMap = HumanNames();
|
|
|
|
|
|
|
|
wxXmlNode *child = node->GetChildren();
|
|
|
|
|
|
|
|
while (child) {
|
|
|
|
wxString name = child->GetName();
|
|
|
|
|
2009-09-26 23:12:15 +02:00
|
|
|
if ((names = nMap.find(name)) != nMap.end()) {
|
2009-09-03 08:53:55 +02:00
|
|
|
node_name = locale->GetString(names->second);
|
|
|
|
} else {
|
|
|
|
wxLogDebug("Report::ProcessNode Unknown node found: \"%s\" (add it to nMap)\n", name);
|
|
|
|
node_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxListItem column;
|
|
|
|
int row = listView->GetItemCount();
|
|
|
|
int depth = child->GetDepth();
|
|
|
|
|
|
|
|
if (child->GetChildren()->GetType() == wxXML_ELEMENT_NODE) {
|
2009-10-03 19:16:52 +02:00
|
|
|
int font_size = 15 - floor(depth * 2 + 0.5);
|
2009-09-28 10:08:16 +02:00
|
|
|
int bgcolour = 155 + (depth * 20);
|
2009-09-03 08:53:55 +02:00
|
|
|
listView->InsertItem(row,node_name);
|
|
|
|
listView->SetItemFont(row, wxFont(font_size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
|
|
|
|
listView->SetItemBackgroundColour(row, wxColour(bgcolour,bgcolour,bgcolour, wxALPHA_OPAQUE));
|
|
|
|
if (depth == 1) text->Append("\n");
|
|
|
|
text->Append(wxString::Format("%s\n", node_name.Pad((depth*2)-2, ' ', 0)));
|
|
|
|
ProcessNode(child, text, listView);
|
|
|
|
} else {
|
|
|
|
wxString content = child->GetNodeContent();
|
|
|
|
listView->InsertItem(row,node_name);
|
|
|
|
listView->SetItem(row,1, content);
|
|
|
|
text->Append(wxString::Format("%-22s: %s\n", node_name.Pad((depth*2)-2, ' ', 0), content));
|
|
|
|
}
|
|
|
|
|
|
|
|
child = child->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-27 13:30:29 +02:00
|
|
|
|
2009-09-03 08:53:55 +02:00
|
|
|
void Report::Fill(wxString *text, wxListView *listView) {
|
|
|
|
|
|
|
|
listView->InsertColumn(0, _("Entry"), wxLIST_FORMAT_RIGHT);
|
2009-10-03 19:16:52 +02:00
|
|
|
listView->InsertColumn(1, _("Text"), wxLIST_FORMAT_LEFT, 100);
|
2009-09-03 08:53:55 +02:00
|
|
|
|
|
|
|
ProcessNode(doc.report, text, listView);
|
|
|
|
|
|
|
|
listView->SetColumnWidth(0, wxLIST_AUTOSIZE);
|
|
|
|
listView->SetColumnWidth(1, wxLIST_AUTOSIZE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Return Report as Text for the Clipboard.
|
2009-09-27 13:30:29 +02:00
|
|
|
void Report::Save(wxString file) {
|
|
|
|
doc.doc->Save(file);
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|