Files
GDevelop/IDE/BugReport.cpp
T
Florian 2d5f4ff831 Improved bug report dialog.
Updated copyright.

git-svn-id: svn://localhost@1238 8062f311-0dae-4547-b526-b8ab9ac864a5
2014-01-04 12:50:39 +00:00

287 lines
15 KiB
C++

/** \file
* Game Develop
* 2008-2014 Florian Rival (Florian.Rival@gmail.com)
*/
#include "BugReport.h"
//(*InternalHeaders(BugReport)
#include <wx/artprov.h>
#include <wx/bitmap.h>
#include <wx/intl.h>
#include <wx/image.h>
#include <wx/string.h>
//*)
#include <wx/textfile.h>
#include "GDCore/CommonTools.h"
#include "GDCore/Tools/VersionWrapper.h"
#include <string>
#include <vector>
#include <iostream>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#include <SFML/Network.hpp>
#include <wx/uri.h>
#include <wx/log.h>
using namespace std;
//(*IdInit(BugReport)
const long BugReport::ID_STATICBITMAP3 = wxNewId();
const long BugReport::ID_STATICTEXT2 = wxNewId();
const long BugReport::ID_STATICBITMAP4 = wxNewId();
const long BugReport::ID_STATICTEXT8 = wxNewId();
const long BugReport::ID_HYPERLINKCTRL1 = wxNewId();
const long BugReport::ID_BUTTON4 = wxNewId();
const long BugReport::ID_PANEL2 = wxNewId();
const long BugReport::ID_STATICTEXT3 = wxNewId();
const long BugReport::ID_TEXTCTRL1 = wxNewId();
const long BugReport::ID_STATICTEXT1 = wxNewId();
const long BugReport::ID_TEXTCTRL3 = wxNewId();
const long BugReport::ID_STATICTEXT6 = wxNewId();
const long BugReport::ID_BUTTON1 = wxNewId();
const long BugReport::ID_BUTTON5 = wxNewId();
const long BugReport::ID_PANEL3 = wxNewId();
const long BugReport::ID_STATICTEXT7 = wxNewId();
const long BugReport::ID_TEXTCTRL2 = wxNewId();
const long BugReport::ID_STATICTEXT4 = wxNewId();
const long BugReport::ID_BUTTON3 = wxNewId();
const long BugReport::ID_BUTTON2 = wxNewId();
const long BugReport::ID_PANEL4 = wxNewId();
const long BugReport::ID_NOTEBOOK1 = wxNewId();
//*)
BEGIN_EVENT_TABLE( BugReport, wxDialog )
//(*EventTable(BugReport)
//*)
END_EVENT_TABLE()
BugReport::BugReport( wxWindow* parent, const std::vector<std::string> & openedFiles_ ) :
openedFiles(openedFiles_)
{
//(*Initialize(BugReport)
wxStaticBoxSizer* StaticBoxSizer2;
wxFlexGridSizer* FlexGridSizer4;
wxFlexGridSizer* FlexGridSizer10;
wxFlexGridSizer* FlexGridSizer3;
wxFlexGridSizer* FlexGridSizer5;
wxFlexGridSizer* FlexGridSizer9;
wxFlexGridSizer* FlexGridSizer2;
wxFlexGridSizer* FlexGridSizer7;
wxFlexGridSizer* FlexGridSizer8;
wxFlexGridSizer* FlexGridSizer12;
wxFlexGridSizer* FlexGridSizer1;
wxFlexGridSizer* FlexGridSizer11;
Create(parent, wxID_ANY, _("Something bad happened!"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
FlexGridSizer1 = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizer1->AddGrowableCol(0);
FlexGridSizer1->AddGrowableRow(0);
Notebook1 = new wxNotebook(this, ID_NOTEBOOK1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_NOTEBOOK1"));
Panel2 = new wxPanel(Notebook1, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL2"));
FlexGridSizer3 = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizer3->AddGrowableCol(0);
FlexGridSizer3->AddGrowableRow(0);
FlexGridSizer9 = new wxFlexGridSizer(0, 3, 0, 0);
StaticBitmap3 = new wxStaticBitmap(Panel2, ID_STATICBITMAP3, wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_INFORMATION")),wxART_OTHER), wxDefaultPosition, wxDefaultSize, wxNO_BORDER, _T("ID_STATICBITMAP3"));
FlexGridSizer9->Add(StaticBitmap3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText2 = new wxStaticText(Panel2, ID_STATICTEXT2, _("It seems that Game Develop has closed abruptly after an\nerror. Game Develop should never freeze or crash whatever \nthe user make. You can help us correct the problem by filling\nthe error report."), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
FlexGridSizer9->Add(StaticText2, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer3->Add(FlexGridSizer9, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticBoxSizer2 = new wxStaticBoxSizer(wxHORIZONTAL, Panel2, _("Known bugs for this version of Game Develop"));
FlexGridSizer11 = new wxFlexGridSizer(0, 3, 0, 0);
FlexGridSizer11->AddGrowableCol(1);
FlexGridSizer11->AddGrowableRow(0);
StaticBitmap4 = new wxStaticBitmap(Panel2, ID_STATICBITMAP4, wxBitmap(wxImage(_T("res/internet32.png"))), wxDefaultPosition, wxDefaultSize, wxNO_BORDER, _T("ID_STATICBITMAP4"));
FlexGridSizer11->Add(StaticBitmap4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer12 = new wxFlexGridSizer(0, 1, 0, 0);
StaticText8 = new wxStaticText(Panel2, ID_STATICTEXT8, _("You can visit a page on our website which can\ncontain known bugs for this version of Game Develop:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT8"));
FlexGridSizer12->Add(StaticText8, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
bugListBt = new wxHyperlinkCtrl(Panel2, ID_HYPERLINKCTRL1, _("View the known bugs for this version"), wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHL_CONTEXTMENU|wxHL_ALIGN_CENTRE|wxNO_BORDER, _T("ID_HYPERLINKCTRL1"));
FlexGridSizer12->Add(bugListBt, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer11->Add(FlexGridSizer12, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
StaticBoxSizer2->Add(FlexGridSizer11, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
FlexGridSizer3->Add(StaticBoxSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button1 = new wxButton(Panel2, ID_BUTTON4, _("Next"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
FlexGridSizer3->Add(Button1, 1, wxALL|wxALIGN_RIGHT|wxALIGN_BOTTOM, 5);
Panel2->SetSizer(FlexGridSizer3);
FlexGridSizer3->Fit(Panel2);
FlexGridSizer3->SetSizeHints(Panel2);
Panel3 = new wxPanel(Notebook1, ID_PANEL3, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL3"));
FlexGridSizer4 = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizer4->AddGrowableCol(0);
FlexGridSizer4->AddGrowableRow(3);
StaticText3 = new wxStaticText(Panel3, ID_STATICTEXT3, _("To help us solve the problem, try to describe the error as precisely as\nyou can. Indicate if possible:\n-How did the error happened (Click on a button ...)\n-In which part of program (Scene editor, events editor...)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
FlexGridSizer4->Add(StaticText3, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
UserReportEdit = new wxTextCtrl(Panel3, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxSize(408,100), wxTE_AUTO_SCROLL|wxTE_MULTILINE, wxDefaultValidator, _T("ID_TEXTCTRL1"));
FlexGridSizer4->Add(UserReportEdit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer2 = new wxFlexGridSizer(0, 1, 0, 0);
StaticText1 = new wxStaticText(Panel3, ID_STATICTEXT1, _("You can enter your email: (optional, so as to contact you if we need more information)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
FlexGridSizer2->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
mailEdit = new wxTextCtrl(Panel3, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
FlexGridSizer2->Add(mailEdit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer4->Add(FlexGridSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
FlexGridSizer7 = new wxFlexGridSizer(0, 3, 0, 0);
FlexGridSizer7->AddGrowableCol(1);
FlexGridSizer7->AddGrowableRow(0);
StaticText6 = new wxStaticText(Panel3, ID_STATICTEXT6, _("When you\'ve described the error, click on the button\nto automatically send the report.\n\nThanks!"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
FlexGridSizer7->Add(StaticText6, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
CreateRapportBt = new wxButton(Panel3, ID_BUTTON1, _("Send my report!"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
FlexGridSizer7->Add(CreateRapportBt, 1, wxALL|wxALIGN_TOP|wxALIGN_CENTER_HORIZONTAL, 5);
FlexGridSizer4->Add(FlexGridSizer7, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
Button2 = new wxButton(Panel3, ID_BUTTON5, _("Next"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON5"));
FlexGridSizer4->Add(Button2, 1, wxALL|wxALIGN_RIGHT|wxALIGN_BOTTOM, 5);
Panel3->SetSizer(FlexGridSizer4);
FlexGridSizer4->Fit(Panel3);
FlexGridSizer4->SetSizeHints(Panel3);
Panel4 = new wxPanel(Notebook1, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL4"));
FlexGridSizer5 = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizer5->AddGrowableCol(0);
FlexGridSizer5->AddGrowableRow(0);
FlexGridSizer10 = new wxFlexGridSizer(0, 1, 0, 0);
FlexGridSizer10->AddGrowableCol(0);
FlexGridSizer10->AddGrowableRow(1);
StaticText7 = new wxStaticText(Panel4, ID_STATICTEXT7, _("Here is a list of the projects opened during the last session:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT7"));
FlexGridSizer10->Add(StaticText7, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
openedFilesEdit = new wxTextCtrl(Panel4, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_AUTO_SCROLL|wxTE_MULTILINE|wxTE_READONLY, wxDefaultValidator, _T("ID_TEXTCTRL2"));
FlexGridSizer10->Add(openedFilesEdit, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer5->Add(FlexGridSizer10, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
StaticText4 = new wxStaticText(Panel4, ID_STATICTEXT4, _("Game Develop may have made automatic backups of these projects. When you\'ll\nclose this window, the backups will be opened. If these backup are not corrupted,\nyou can save them over the original project files."), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
FlexGridSizer5->Add(StaticText4, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer8 = new wxFlexGridSizer(0, 3, 0, 0);
CloseNoOpenBt = new wxButton(Panel4, ID_BUTTON3, _("Close but don\'t open the autosave(s)"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
FlexGridSizer8->Add(CloseNoOpenBt, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
CloseBt = new wxButton(Panel4, ID_BUTTON2, _("Close"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
FlexGridSizer8->Add(CloseBt, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer5->Add(FlexGridSizer8, 1, wxALL|wxALIGN_RIGHT|wxALIGN_BOTTOM, 0);
Panel4->SetSizer(FlexGridSizer5);
FlexGridSizer5->Fit(Panel4);
FlexGridSizer5->SetSizeHints(Panel4);
Notebook1->AddPage(Panel2, _("Oops..."), false);
Notebook1->AddPage(Panel3, _("Report the error"), false);
Notebook1->AddPage(Panel4, _("Load autosaves"), false);
FlexGridSizer1->Add(Notebook1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(FlexGridSizer1);
FlexGridSizer1->Fit(this);
FlexGridSizer1->SetSizeHints(this);
Center();
Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BugReport::OnButton1Click);
Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&BugReport::OnUserReportEditText);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BugReport::OnCreateRapportBtClick);
Connect(ID_BUTTON5,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BugReport::OnButton2Click);
Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BugReport::OnCloseNoOpenBtClick);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BugReport::OnCloseBtClick);
//*)
for (unsigned int i = 0; i < openedFiles.size(); ++i)
{
std::string file = openedFiles[i];
if (!wxFileExists(file+".autosave"))
file += _(" (Autosave not found!)");
openedFilesEdit->AppendText(file+"\n");
}
if (openedFiles.empty()) {
Notebook1->RemovePage(2);
Button2->SetLabel(_("Close"));
}
CreateRapportBt->Disable();
bugListBt->SetURL(_("http://www.wiki.compilgames.net/doku.php/en/game_develop/knownbugs/gd")+gd::ToString(gd::VersionWrapper::Major())+gd::ToString(gd::VersionWrapper::Minor())+gd::ToString(gd::VersionWrapper::Build()));
}
BugReport::~BugReport()
{
//(*Destroy(BugReport)
//*)
}
void BugReport::OnCreateRapportBtClick( wxCommandEvent& event )
{
if (UserReportEdit->GetValue().Trim().IsEmpty() || UserReportEdit->GetValue().length() < 7)
return;
//On recherche le rapport d'erreur de Game Develop
string rapport;
if ( wxFileExists( "errordata.txt" ) )
{
wxFileInputStream input( "errordata.txt" );
if ( input.Ok() )
{
wxTextInputStream text( input );
while ( !input.Eof() )
{
rapport += text.ReadLine()+"\n";
}
}
}
if ( rapport == "" )
rapport = "Pas de rapport d'erreur de Game Develop";
wxString report;
report += "GD Error report:\n\n";
report += "V: " + gd::VersionWrapper::FullString()+"\n";
report += "OS: " + wxGetOsDescription()+"\n";
report += "Trace:\n";
report += rapport;
report += "(End)\n";
report += "User desc.:\n";
report += UserReportEdit->GetValue();
report += "(End)\n";
report += "User mail: "+mailEdit->GetValue()+"\n";
report.Replace("&", "%26");
wxString encodedReportURI = wxURI("www.compilgames.net/bugs/report.php?report="+report).BuildURI();
wxURI requestURI(encodedReportURI);
std::cout << "Sending report with these data:" << requestURI.GetQuery() << std::endl;
// Create request
sf::Http Http;
Http.setHost("http://www.compilgames.net");
sf::Http::Request request;
request.setMethod(sf::Http::Request::Post);
request.setField("Content-Type", "application/x-www-form-urlencoded");
request.setUri("/bugs/report.php");
request.setBody(gd::ToString(requestURI.GetQuery()));
// Send the request
sf::Http::Response response = Http.sendRequest(request, sf::seconds(5));
if (response.getStatus() != sf::Http::Response::Ok)
std::cout << "Unable to connect to the server for sending the report!" << std::endl;
else {
wxLogMessage(_("Thanks for reporting the error!"));
CreateRapportBt->Disable();
}
}
void BugReport::OnCloseNoOpenBtClick(wxCommandEvent& event)
{
EndModal(0);
}
void BugReport::OnCloseBtClick(wxCommandEvent& event)
{
EndModal(1);
}
void BugReport::OnButton1Click(wxCommandEvent& event)
{
Notebook1->SetSelection(1);
}
void BugReport::OnButton2Click(wxCommandEvent& event)
{
if (openedFiles.empty())
EndModal(0);
else
Notebook1->SetSelection(2);
}
void BugReport::OnUserReportEditText(wxCommandEvent& event)
{
CreateRapportBt->Enable();
}