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 main.cpp
2009-09-03 08:53:55 +02:00
/// @brief Main loop
2009-09-26 11:38:17 +02:00
/// @ingroup base
2009-09-03 08:53:55 +02:00
# ifndef R_PRECOMP
2009-09-21 06:53:51 +02:00
# include <locale.h>
2009-09-03 08:53:55 +02:00
# include <wx/app.h>
2011-01-08 20:14:02 +01:00
# include <wx/button.h>
2009-09-03 08:53:55 +02:00
# include <wx/cmdline.h>
2011-01-08 20:14:02 +01:00
# include <wx/filename.h>
# include <wx/panel.h>
2009-09-03 08:53:55 +02:00
# include <wx/sizer.h>
# include <wx/stattext.h>
# include <wx/textctrl.h>
2011-01-08 20:14:02 +01:00
# include <wx/window.h>
2009-09-03 08:53:55 +02:00
# endif
2011-01-08 20:14:02 +01:00
# include <libaegisub/log.h>
2009-09-03 08:53:55 +02:00
# include "main.h"
# include "upload.h"
2011-01-08 20:14:02 +01:00
# include "util.h"
2009-09-03 08:53:55 +02:00
/// @brief Init the reporter.
2011-01-08 20:14:02 +01:00
bool Reporter : : OnInit ( ) {
2011-01-08 20:16:11 +01:00
const std : : string path_log ( util : : config_path ( ) + " log/ " ) ;
2011-01-08 20:14:02 +01:00
wxFileName : : Mkdir ( path_log , 0777 , wxPATH_MKDIR_FULL ) ;
agi : : log : : log = new agi : : log : : LogSink ( path_log ) ;
2009-09-27 13:30:29 +02:00
// if ( !wxApp::OnInit() )
// return false;
2009-09-03 08:53:55 +02:00
2011-07-16 05:36:42 +02:00
wxApp : : CheckBuildOptions ( WX_BUILD_OPTIONS_SIGNATURE , _ ( " Reporter " ) . c_str ( ) ) ;
2009-09-03 08:53:55 +02:00
2009-09-27 13:30:29 +02:00
2009-09-03 08:53:55 +02:00
static const wxCmdLineEntryDesc cmdLineDesc [ ] = {
2011-01-16 08:18:06 +01:00
{ wxCMD_LINE_SWITCH , " c " , " crash " , " Launch in crash mode. " , wxCMD_LINE_VAL_NONE , 0 } ,
{ wxCMD_LINE_SWITCH , " r " , " report " , " Launch in Report mode. " , wxCMD_LINE_VAL_NONE , 0 } ,
{ wxCMD_LINE_SWITCH , " j " , " json " , " Dump JSON file " , wxCMD_LINE_VAL_NONE , 0 } ,
2009-09-27 13:30:29 +02:00
{ wxCMD_LINE_SWITCH , " h " , " help " , " This help message " , wxCMD_LINE_VAL_NONE , wxCMD_LINE_OPTION_HELP } ,
2011-01-16 08:18:06 +01:00
{ wxCMD_LINE_NONE , NULL , NULL , NULL , wxCMD_LINE_VAL_NONE , 0 }
2009-09-03 08:53:55 +02:00
} ;
2009-09-27 13:30:29 +02:00
2009-09-03 08:53:55 +02:00
wxCmdLineParser parser ( cmdLineDesc , argc , argv ) ;
2009-09-27 13:30:29 +02:00
parser . SetLogo ( " Aegisub Reporter version x.x " ) ;
parser . SetCmdLine ( argc , argv ) ;
2009-09-03 08:53:55 +02:00
switch ( parser . Parse ( ) ) {
case - 1 :
2009-09-27 13:30:29 +02:00
return false ;
2009-09-03 08:53:55 +02:00
break ; // Help
case 0 :
break ; // OK
default :
wxLogMessage ( _T ( " Syntax error. " ) ) ;
2009-09-27 13:30:29 +02:00
return false ;
2009-09-03 08:53:55 +02:00
break ;
}
setlocale ( LC_NUMERIC , " C " ) ;
setlocale ( LC_CTYPE , " C " ) ;
wxLocale * locale = new wxLocale ( ) ;
locale - > Init ( wxLANGUAGE_ENGLISH ) ;
# ifdef __WINDOWS__
2009-10-03 19:37:09 +02:00
wxStandardPathsBase & paths = wxStandardPaths : : Get ( ) ;
locale - > AddCatalogLookupPathPrefix ( wxString : : Format ( " %s/locale " , paths . GetDataDir ( ) ) ) ;
2009-09-03 08:53:55 +02:00
locale - > AddCatalog ( _T ( " reporter " ) ) ;
# else
locale - > AddCatalog ( " reporter " ) ;
# endif
locale - > AddCatalog ( _T ( " wxstd " ) ) ;
setlocale ( LC_NUMERIC , " C " ) ;
setlocale ( LC_CTYPE , " C " ) ;
2011-01-03 15:11:53 +01:00
2009-09-03 08:53:55 +02:00
mFrame * frame = new mFrame ( _ ( " Aegisub Reporter " ) ) ;
2009-09-27 13:30:29 +02:00
2011-01-03 15:28:24 +01:00
if ( parser . Found ( " j " ) ) {
r - > Save ( " report.json " ) ;
std : : cout < < " Report saved to report.json " < < std : : endl ;
2009-09-27 13:30:29 +02:00
return false ;
}
2009-09-03 08:53:55 +02:00
SetTopWindow ( frame ) ;
2011-01-03 16:46:21 +01:00
r = new Report ;
frame - > SetReport ( r ) ;
2009-09-03 08:53:55 +02:00
return true ;
}
/// Main frame.
/// @param window_title Window title.
mFrame : : mFrame ( const wxString & window_title )
: wxFrame ( NULL , wxID_ANY , window_title , wxDefaultPosition , wxSize ( 300 , - 1 ) ) {
wxBoxSizer * topSizer = new wxBoxSizer ( wxVERTICAL ) ;
2011-01-03 15:11:53 +01:00
wxBoxSizer * msgSizer = new wxBoxSizer ( wxVERTICAL ) ;
topSizer - > Add ( msgSizer , 0 , wxALL , 5 ) ;
2009-09-03 08:53:55 +02:00
2011-01-03 15:11:53 +01:00
wxStaticText * title = new wxStaticText ( this , - 1 , _ ( " Welcome to the Aegisub reporter! " ) ) ;
msgSizer - > Add ( title , 0 , wxALL , 5 ) ;
2009-09-03 08:53:55 +02:00
title - > SetFont ( wxFont ( 11 , wxFONTFAMILY_SWISS , wxFONTSTYLE_NORMAL , wxFONTWEIGHT_BOLD ) ) ;
2011-01-03 15:11:53 +01:00
wxStaticText * msg = new wxStaticText ( this , - 1 , _ ( " In order to better help us target development, and improve Aegisub we would like you to submit some information about your system and setup. " ) ) ;
2009-09-03 08:53:55 +02:00
msg - > Wrap ( 325 ) ;
msgSizer - > Add ( msg , 1 , wxALL , 5 ) ;
2011-01-03 15:11:53 +01:00
wxStaticText * notice = new wxStaticText ( this , - 1 , _ ( " This information is completely anonymous, no personal information is sent along it is strictly used for targeting new features and the future direction of Aegisub. " ) ) ;
2009-09-03 08:53:55 +02:00
msgSizer - > Add ( notice , 1 , wxALL , 5 ) ;
notice - > SetFont ( wxFont ( 11 , wxFONTFAMILY_SWISS , wxFONTSTYLE_ITALIC , wxFONTWEIGHT_NORMAL ) ) ;
2009-09-29 13:56:43 +02:00
notice - > Wrap ( 325 ) ;
2011-01-03 15:11:53 +01:00
msgSizer - > Add ( new wxButton ( this , 42 , " View Report " ) , 0 , wxTOP , 5 ) ;
2009-09-03 08:53:55 +02:00
wxStdDialogButtonSizer * stdButton = new wxStdDialogButtonSizer ( ) ;
stdButton - > AddButton ( new wxButton ( this , wxID_OK , _ ( " Submit " ) ) ) ;
stdButton - > AddButton ( new wxButton ( this , wxID_CANCEL , _ ( " Cancel " ) ) ) ;
stdButton - > Realize ( ) ;
2011-01-03 15:11:53 +01:00
topSizer - > Add ( stdButton , 0 , wxALL , 5 ) ;
2009-09-03 08:53:55 +02:00
this - > SetSizerAndFit ( topSizer ) ;
2011-01-03 15:11:53 +01:00
msgSizer - > Layout ( ) ;
2009-09-03 08:53:55 +02:00
// Is there a better way to do this?
this - > SetMaxSize ( this - > GetEffectiveMinSize ( ) ) ;
this - > SetMinSize ( this - > GetEffectiveMinSize ( ) ) ;
this - > Show ( true ) ;
}
/// @brief View report.
void mFrame : : ReportView ( wxCommandEvent & WXUNUSED ( event ) ) {
View View ( this , r ) ;
View . ShowModal ( ) ;
}
/// @brief Cancel reporter.
void mFrame : : Cancel ( wxCommandEvent & WXUNUSED ( event ) ) {
Close ( true ) ;
}
/// @brief Submit report
void mFrame : : Submit ( wxCommandEvent & WXUNUSED ( event ) ) {
2009-10-03 19:16:52 +02:00
Progress * progress = new Progress ( this ) ;
Upload * upload = new Upload ( progress ) ;
2011-01-04 01:22:55 +01:00
upload - > Report ( " ./test.json " ) ;
2009-09-03 08:53:55 +02:00
}