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>
# include <wx/window.h>
# include <wx/log.h>
# include <wx/cmdline.h>
# include <wx/wxchar.h>
# include <wx/sizer.h>
# include <wx/stattext.h>
# include <wx/panel.h>
# include <wx/font.h>
# include <wx/button.h>
# include <wx/textctrl.h>
# include <wx/intl.h>
# endif
# include "main.h"
# include "upload.h"
/// @brief Init the reporter.
bool Reporter : : OnInit ( )
{
2009-09-27 13:30:29 +02:00
// if ( !wxApp::OnInit() )
// return false;
2009-09-03 08:53:55 +02:00
wxApp : : CheckBuildOptions ( WX_BUILD_OPTIONS_SIGNATURE , _ ( " Reporter " ) ) ;
2009-09-27 13:30:29 +02:00
2009-09-03 08:53:55 +02:00
static const wxCmdLineEntryDesc cmdLineDesc [ ] = {
2009-09-27 13:30:29 +02:00
{ wxCMD_LINE_SWITCH , " c " , " crash " , " Launch in crash mode. " , wxCMD_LINE_VAL_NONE , NULL } ,
{ wxCMD_LINE_SWITCH , " r " , " report " , " Launch in Report mode. " , wxCMD_LINE_VAL_NONE , NULL } ,
{ wxCMD_LINE_SWITCH , " x " , " xml " , " Dump XML file " , wxCMD_LINE_VAL_NONE , NULL } ,
{ wxCMD_LINE_SWITCH , " h " , " help " , " This help message " , wxCMD_LINE_VAL_NONE , wxCMD_LINE_OPTION_HELP } ,
2009-09-03 08:53:55 +02:00
{ wxCMD_LINE_NONE , NULL , NULL , NULL , wxCMD_LINE_VAL_NONE , NULL }
} ;
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 " ) ) ;
2011-01-03 15:11:53 +01:00
// Report *r = new Report;
2009-09-27 13:30:29 +02:00
if ( parser . Found ( " x " ) ) {
r - > Save ( " report.xml " ) ;
wxPrintf ( " Report saved to report.xml \n " ) ;
return false ;
}
2009-09-03 08:53:55 +02:00
SetTopWindow ( frame ) ;
2011-01-03 15:11:53 +01:00
// 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 ) ;
2009-09-03 08:53:55 +02:00
upload - > Report ( _ ( " ./test.xml " ) ) ;
}