1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
xmunipack - main
Copyright © 2009-2015, 2019-22 F.Hroch (hroch@physics.muni.cz)
This file is part of Munipack.
Munipack is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Munipack is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Munipack. If not, see <http://www.gnu.org/licenses/>.
*/
#include "xmunipack.h"
#include <wx/wx.h>
#include <wx/app.h>
#include <wx/cmdline.h>
#include <wx/utils.h>
wxIMPLEMENT_APP(XMunipack);
bool XMunipack::OnInit()
{
config = 0;
view = 0;
browser = 0;
// switch-off timestamps in log
wxLog::DisableTimestamp();
// default log level prints errors only
wxLog::SetLogLevel(wxLOG_Error);
// command line parameters
wxCmdLineParser cmd(argc,argv);
OnInitCmdLine(cmd);
cmd.AddSwitch("","version","print version and license");
cmd.AddParam("filename",wxCMD_LINE_VAL_STRING,wxCMD_LINE_PARAM_OPTIONAL);
if( cmd.Parse() == 0 ) {
if( cmd.Found("verbose") )
wxLog::SetLogLevel(wxLOG_Debug);
else
wxSetAssertHandler(NULL);
if( cmd.Found("version") ) {
wxPrintf("%s %s, %s\n",PACKAGE_NAME,PACKAGE_VERSION,PACKAGE_COPYLEFT);
wxPrintf("%s\n\n",PACKAGE_DESCRIPTION);
wxPrintf("This program comes with ABSOLUTELY NO WARRANTY;\nfor details, see the GNU General Public License, version 3 or later.\n");
return false;
}
}
else
return false;
// look for passed file
wxString file;
if( cmd.GetParamCount() > 0 )
file = cmd.GetParam();
// initialisation
wxHandleFatalExceptions();
wxInitAllImageHandlers();
/*
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
"$XDG_CONFIG_HOME defines the base directory relative to which user-specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.
"
*/
wxString config_file;
wxString xdg_config_home;
if( wxGetEnv("XDG_CONFIG_HOME",&xdg_config_home) && xdg_config_home != "" ) {
wxFileName filename(xdg_config_home,"xmunipack.conf");
config_file = filename.GetFullPath();
}
else {
wxString home;
if( wxGetEnv("HOME",&home) && home != "" ) {
wxFileName filename(home,"xmunipack.conf");
filename.AppendDir(".config");
config_file = filename.GetFullPath();
}
}
config = new MuniConfig(config_file);
#ifdef __WXMAC__
// all main windows?
SetExitOnFrameDelete(true);
wxMenuBar *menubar = new wxMenuBar;
wxMenuBar::MacSetCommonMenuBar(menubar);
#endif
if( ! file.IsEmpty() ) {
view = new MuniView(NULL,config);
view->Show();
view->LoadFile(file);
SetTopWindow(view);
}
else {
browser = new MuniBrowser(NULL,config);
browser->Show(true);
}
return true;
}
int XMunipack::OnExit()
{
delete config;
return 0;
}
void XMunipack::OnEventLoopEnter(wxEventLoopBase* WXUNUSED(loop))
{
//wxLogDebug("XMunipack::OnEventLoopEnter");
if( view )
view->CreateFSWatch();
}
|