コード例 #1
0
ファイル: szapp.cpp プロジェクト: marta09/szarp
void szAppImpl::InitializeLocale(wxArrayString &catalogs, wxLocale &locale) {

	wxString lang = wxConfig::Get()->Read(_T("LANGUAGE"), AUTO_LANGUAGE);
	if (lang == AUTO_LANGUAGE)
		lang = DEFAULT_LANGUAGE;

	const wxLanguageInfo *info = wxLocale::FindLanguageInfo(lang);

	int l;

	if (info)
	{
		l = info->Language;
	} else
		l = wxLANGUAGE_ENGLISH;

	locale.Init(l);

	if (!locale.IsOk()) {
		if(locale.IsAvailable(locale.GetSystemLanguage())) {
			l = locale.GetSystemLanguage();
			locale.Init(l);
			if(!locale.IsOk()) {
				wxMessageBox(_("Default locale cannot be loaded. Exiting"), _("Information."), wxICON_ERROR);
				exit(1);
			}
			wxString Ls = L"Locale " + lang + L" not available.\nDefault system locale loaded.";
			wxMessageBox(_(s), _("Information."), wxICON_INFORMATION);
		}
		else {
			wxLogWarning(_("No locale for this system`s language."));
		}
	}

	locale.AddCatalogLookupPathPrefix(GetSzarpDir() + _T("resources/locales"));

	for(size_t i = 0; i < catalogs.Count(); i++)
		locale.AddCatalog(catalogs[i]);

#ifdef __WXGTK__
	if (!locale.IsOk()) {
		wxLogInfo(_("Setting locale to \"C\""));
		setenv("LC_ALL", "C", 1);
	} else if( locale.GetSystemEncodingName() == _("") ) { // this probably doesn't happen on unix machines 
		wxLogInfo(_("wx: Setting locale to \"") + locale.GetCanonicalName() + _("\""));
		setenv("LC_ALL", SC::S2A(locale.GetCanonicalName()).c_str(), 1);
	} else {
		wxString localename = locale.GetCanonicalName() + _(".") + locale.GetSystemEncodingName();
		wxLogInfo(_("wx: Setting locale to \"") + localename + _("\""));
		setenv("LC_ALL", SC::S2A(localename).c_str(), 1);
	}
#endif

}
コード例 #2
0
ファイル: szapp.cpp プロジェクト: marta09/szarp
void szAppImpl::InitSzarpDataDir()
{
	wxConfig* cfg = new wxConfig(_T("SZARPDATADIR"));
	if (cfg->Exists(_T("SZARPDATADIR"))) {
		m_szarp_data_dir = cfg->Read(_T("SZARPDATADIR"), _T(""));
		const wxChar *slash =
#ifndef __WXMSW__
						_T("/");
#else
						_T("\\");
#endif

		if (!m_szarp_data_dir.EndsWith(slash))
			m_szarp_data_dir = m_szarp_data_dir + slash;

		delete cfg;
		return;
	}
	delete cfg;

#ifndef __WXMSW__
	m_szarp_data_dir = GetSzarpDir();
#else
	OSVERSIONINFOEXW vi;	
	ZeroMemory((void*)&vi, sizeof(vi));
	vi.dwOSVersionInfoSize = sizeof(vi);

	if (GetVersionEx((OSVERSIONINFOW*) &vi)) {
		if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT
				&& vi.dwMajorVersion == 6)
			//VISTA
			m_szarp_data_dir = wxGetHomeDir() + _T("\\.szarp\\");
		else
			m_szarp_data_dir = GetSzarpDir();
	} else {
		wxLogError(_T("Failed to get windows version info"));
		m_szarp_data_dir = GetSzarpDir();
	}
#endif
}
コード例 #3
0
ファイル: szapp.cpp プロジェクト: marta09/szarp
void szAppImpl::ShowAbout(wxWindow *parent) {
	wxBitmap bitmap;
	wxString logoimage = GetSzarpDir();

#ifndef MINGW32
	logoimage += _T("resources/wx/images/szarp-logo.png");
#else
	logoimage += _T("resources\\wx\\images\\szarp-logo.png");
#endif

#if wxUSE_LIBPNG
	/* Activate PNG image handler. */
	wxImage::AddHandler( new wxPNGHandler );
#endif

	wxBitmap* bitmapptr = NULL;
	if(bitmap.LoadFile(logoimage, wxBITMAP_TYPE_PNG)) {
		bitmapptr = &bitmap;
	}

	wxArrayString authors;
	/* About dialog data */
	authors.Add(L"Marcin Anderson");
	authors.Add(L"Micha\u0142 Blajerski");
	authors.Add(L"Piotr Branecki");
	authors.Add(L"S\u0142awomir Chy\u0142ek");
	authors.Add(L"Krzysztof Ga\u0142\u0105zka");
	authors.Add(L"Krzysztof Goli\u0144ski");
	authors.Add(L"Marcin Goliszewski");
	authors.Add(L"Jaros\u0142aw Janik");
	authors.Add(L"Stanis\u0142aw K\u0142osi\u0144ski");
	authors.Add(L"Pawe\u0142 Kolega");
	authors.Add(L"Jakub Kotur");
	authors.Add(L"Daniel Majewski");
	authors.Add(L"Dariusz Marcinkiewicz");
	authors.Add(L"Maciej Mochol");
	authors.Add(L"Jaros\u0142aw Nowisz");
	authors.Add(L"Krzysztof O\u0142owski");
	authors.Add(L"Pawe\u0142 Pa\u0142ucha");
	authors.Add(L"Lucjan Przykorski");
	authors.Add(L"Micha\u0142 R\u00F3j");
	authors.Add(L"Stanis\u0142aw Sawa");
	authors.Add(L"Adam Smyk");
	authors.Add(L"Tomasz \u015Awiatowiec");
	authors.Add(L"Maciej Zbi\u0144kowski");
	authors.Add(wxString(L"Witold Kowalewski") + _(" (Ideas)"));
	authors.Add(wxString(L"Jadwiga Ma\u0107kow") + _(" (French translations)"));
	authors.Add(wxString(L"Violetta Rowicka") + _(" (French translations)"));
	authors.Add(wxString(L"Marcin Zalewski") + _(" (logo)"));


	wxDialog* dlg = new szAboutDlg(bitmapptr, m_progname, m_version, m_releasedate, authors, parent);
	if (szFrame::default_icon.IsOk()) {
		dlg->SetIcon(szFrame::default_icon);
	}

	dlg->Centre();
	dlg->ShowModal();

	delete dlg;

	return;
}
コード例 #4
0
ファイル: drawapp.cpp プロジェクト: Strongc/szarp
bool DrawApp::OnInit() {


	/* Read params from szarp.cfg. */
#if wxUSE_UNICODE
	libpar_read_cmdline_w(&argc, argv);
#else
	libpar_read_cmdline(&argc, argv);
#endif

#if BOOST_FILESYSTEM_VERSION == 3
	boost::filesystem::wpath::imbue(std::locale("C")); 	
#else
	boost::filesystem::wpath_traits::imbue(std::locale("C")); 	
#endif

	if (!DrawGLApp::OnInit())
		return false;


	SetProgName(_T("Draw 3"));
	//signal(SIGINT, INThandler);

	if (m_just_print_version) {
		std::cout << SZARP_VERSION << std::endl;
		return false;
	}
	m_server = NULL;
	m_db_queue = NULL;
	m_executor = NULL;
	m_remarks_handler = NULL;

#ifdef __WXGTK__
	libpar_init();

	char *base = NULL;
	if (m_base == wxEmptyString) {
		base = libpar_getpar("", "config_prefix", 1);
		m_base = SC::L2S(base);
		free(base);
	}

	{

		if (m_base_type != IKS_BASE) {
			char *iks_server = libpar_getpar("draw3", "iks_server", 0);
			if (iks_server) {
				m_iks_server = SC::L2S(iks_server);
				m_base_type = IKS_BASE;
				free(iks_server);
			}

			char *iks_port = libpar_getpar("draw3", "iks_server_port", 0);
			if (iks_port) {
				m_iks_port = SC::L2S(iks_port);
				free(iks_port);
			}
		}
	}

	m_probers_from_szarp_cfg = get_probers_addresses();
#endif

#ifdef MINGW32
	WORD wVersionRequested = MAKEWORD(2, 2);
	WSADATA wsaData;
	WSAStartup(wVersionRequested, &wsaData);
#endif
	/* Set logging to stderr. */
	wxLog *logger = new wxLogStderr();
	//wxLog *logger = new wxLogGui();
	wxLog::SetActiveTarget(logger);


	m_instance = new szSingleInstanceChecker(_T(".szarp_m_instance_lock"), wxEmptyString, 
			_T("draw3"));
	if (m_instance->IsAnotherRunning()) {
		if (!m_url.IsEmpty()) {
			if (m_url_open_in_existing)
				SendToRunningInstance(_T("START_URL"), m_url.c_str());
			else
				SendToRunningInstance(_T("START_URL_EXISTING"), m_url.c_str());
		} else if (!m_base.IsEmpty()) {		
			SendToRunningInstance(_T("START_BASE"), m_base.c_str());
		} else {
			wxLogError(_T("base not given"));
			return false;
		}
		return false;
	}
        

	InitGL();

	SplashScreen *splash = NULL;
	wxBitmap bitmap;

	// this loads draw64_xpm under Linux, or draw64 icon resource under Windows
	szFrame::setDefaultIcon(wxICON(draw64));

	wxString splashimage = GetSzarpDir();

#ifndef MINGW32
	splashimage += _T("resources/wx/images/szarp-logo.png");
#else
	splashimage += _T("resources\\wx\\images\\szarp-logo.png");
#endif

#if wxUSE_LIBPNG
	/* Activate PNG image handler. */
	wxImage::AddHandler( new wxPNGHandler );
#endif

	if (bitmap.LoadFile(splashimage, wxBITMAP_TYPE_PNG))
		splash = new SplashScreen(&bitmap);
	else
		splash = new SplashScreen();
	splash->Show(true);

	splash->PushStatusText(_("Setting locale..."));
	
	/* Set locale. */
	this->InitializeLocale(_T("draw3"), locale);

	splash->PushStatusText(_("Reading params from szarp.cfg..."));

	wxString _lang = wxConfig::Get()->Read(_T("LANGUAGE"), AUTO_LANGUAGE);
	if (_lang == AUTO_LANGUAGE)
		_lang = DEFAULT_LANGUAGE;

	splash->PushStatusText(_("Initializing IPKContainer..."));
	IPKContainer::Init(GetSzarpDataDir().c_str(), 
			GetSzarpDir().c_str(), 
			_lang.c_str());
	m_cfg_mgr = new ConfigManager(GetSzarpDataDir(), IPKContainer::GetObject());

	m_cfg_mgr->SetSplashScreen(splash);

	splash->PushStatusText(_("Initializing szbase..."));

	splash->PushStatusText(_("Initializing XML Resources..."));
    
	InitXmlResource();

	splash->PushStatusText(_("Starting database query mechanism..."));

	m_db_queue = new DatabaseQueryQueue();
	m_dbmgr = new DatabaseManager(m_db_queue, m_cfg_mgr);
	m_db_queue->SetDatabaseManager(m_dbmgr);
	m_dbmgr->SetProbersAddresses(GetProbersAddresses());

	Draw3Base* draw_base;
	switch (m_base_type) {
		case SZBASE_BASE:
			draw_base = new SzbaseBase(m_dbmgr, GetSzarpDataDir().c_str(),
				&ConfigurationFileChangeHandler::handle,
				wxConfig::Get()->Read(_T("SZBUFER_IN_MEMORY_CACHE"), 0L));
			break;
		case SZ4_BASE:
			draw_base = new Sz4Base(m_dbmgr, GetSzarpDataDir().c_str(),
				IPKContainer::GetObject());
			break;
		case IKS_BASE:
			draw_base = new Sz4ApiBase(m_dbmgr, m_iks_server.c_str(), m_iks_port.c_str(),
				IPKContainer::GetObject());
			break;
	}

	m_executor = new QueryExecutor(m_db_queue, m_dbmgr, draw_base);
	m_executor->Create();
	m_executor->SetPriority((WXTHREAD_MAX_PRIORITY + WXTHREAD_DEFAULT_PRIORITY) / 2);
	m_executor->Run();

	m_cfg_mgr->SetDatabaseManager(m_dbmgr);

	ConfigurationFileChangeHandler::database_manager = m_dbmgr;

	/* default config */
	wxString defid;

	DrawsSets *config = NULL;

	splash->PushStatusText(_("Loading configuration..."));

	/* init activity logger with base name as server name. This assumes that 
	 * server has written basename to /etc/hosts on linux machines and probably
	 * doesn't work on windows.
	 */
	UDPLogger::SetAppName( "draw3" );
	UDPLogger::SetAddress( (const char*)m_base.mb_str(wxConvUTF8) );
	UDPLogger::SetPort   ( "7777" );
	UDPLogger::LogEvent  ( "drawapp:start" );



	wxString prefix, window;
	PeriodType pt = PERIOD_T_YEAR;
	time_t time = -1;
	int selected_draw = 0;

	if (!m_url.IsEmpty()) {
		if (!decode_url(m_url, prefix, window, pt, time, selected_draw)) {
			wxLogError(_T("Invalid URL"));
			StopThreads();
			return FALSE;
		}
	} else if (!m_base.IsEmpty()) {
		if ((config = m_cfg_mgr->LoadConfig(m_base,std::wstring(),m_show_logparams)) == NULL) {
			wxLogError(_("Error occurred while loading default configuration. Check your szarp.cfg file."));
			StopThreads();
			return FALSE;
		}
		prefix = m_base;
	} else {
		wxLogError(_("Missing starting base specification."));
		StopThreads();
		return FALSE;
	}


#ifndef MINGW32
	libpar_done();
#endif

	m_help = new szHelpController;
#ifndef MINGW32
	m_help->AddBook(wxGetApp().GetSzarpDir() + L"/resources/documentation/new/draw3/html/draw3.hhp");
#else
	m_help->AddBook(wxGetApp().GetSzarpDir() + L"\\resources\\documentation\\new\\draw3\\html\\draw3.hhp");
#endif
	szHelpControllerHelpProvider* provider = new szHelpControllerHelpProvider;
	wxHelpProvider::Set(provider);
	provider->SetHelpController(m_help);

	splash->PushStatusText(_("Initizalizing remarks..."));
	
	m_remarks_handler = new RemarksHandler(m_cfg_mgr);
	m_remarks_handler->Start();
	
	splash->PushStatusText(_("Creating Frame Manager..."));

	VersionChecker* version_checker = new VersionChecker(argv[0]);
	version_checker->Start();

	FrameManager *fm = new FrameManager(m_dbmgr, m_cfg_mgr, m_remarks_handler);

	/*@michal  */
	if (!fm->CreateFrame(prefix, window, pt, time, wxSize(width, height), wxPoint(x, y), selected_draw, m_url.IsEmpty(), m_full_screen)) {
		StopThreads();
		wxLogError(_T("Unable to load base: %s"), prefix.c_str());
		return FALSE;
	}

	StartInstanceServer(fm, m_cfg_mgr);

	wxToolTip::SetDelay(1000);
    
	SetAppName(_T("SZARPDRAW3"));

	splash->Destroy();

	m_cfg_mgr->ResetSplashScreen();

#ifndef NO_GSTREAMER
	if (!gst_init_check(NULL, NULL, NULL)) 
		return 1;
#endif

	return TRUE;
}
コード例 #5
0
ファイル: ekstraktor3.cpp プロジェクト: Strongc/szarp
bool EkstrApp::OnInit()
{
	//  READ PARAMS FROM CMD LINE
#if wxUSE_UNICODE
	libpar_read_cmdline_w(&argc, argv);
#else
	libpar_read_cmdline(&argc, argv);
#endif
	if (!szApp<>::OnInit())
		return false;

#if BOOST_FILESYSTEM_VERSION == 3
	boost::filesystem::wpath::imbue(std::locale("C")); 	
#else
	boost::filesystem::wpath_traits::imbue(std::locale("C")); 	
#endif

	SetProgName(_("Ekstraktor 3"));

	// SET LOCALE
	wxArrayString catalogs;
	catalogs.Add(_T("ekstraktor3"));
	catalogs.Add(_T("common"));
	catalogs.Add(_T("wx"));
	InitializeLocale(catalogs, locale);

	// GET LIBPAR STUFF
#ifndef MINGW32
	libpar_init();
#else
	wxString config_str =
	    GetSzarpDir() + wxFileName::GetPathSeparator() + _T("resources") +
	    wxFileName::GetPathSeparator() + _T("szarp.cfg");
	libpar_init_with_filename(SC::S2A(config_str).c_str(), 1);
#endif
	std::wstring ipk_prefix;
	char *_ipk_prefix = libpar_getpar("", "config_prefix", 0);
	if (_ipk_prefix) {
		ipk_prefix = SC::L2S(_ipk_prefix);
		free(_ipk_prefix);
	}
	std::map<wxString, std::pair<wxString, wxString> > m_probers_addresses;
#ifndef MINGW32
	m_probers_addresses = get_probers_addresses();
#endif
	szFrame::setDefaultIcon(wxICON(extr64));

	if (!base.IsEmpty()) {
		ipk_prefix = base.c_str();
	} else {
		if (ipk_prefix.empty()) {
			wxArrayString hidden_databases;
			wxString tmp;
			wxConfigBase *config = wxConfigBase::Get(true);
			if (config->Read(_T("HIDDEN_DATABASES"), &tmp)) {
				wxStringTokenizer tkz(tmp, _T(","), wxTOKEN_STRTOK);
				while (tkz.HasMoreTokens()) {
					wxString token = tkz.GetNextToken();
					token.Trim();
					if (!token.IsEmpty())
						hidden_databases.Add(token);
				}
			}
			if (ConfigDialog::SelectDatabase(base, &hidden_databases)) {
				ipk_prefix = base;
			} else
				return false;
		}
	}

	libpar_done();

#ifdef MINGW32
	WORD wVersionRequested = MAKEWORD(2, 2);
	WSADATA wsaData;
	WSAStartup(wVersionRequested, &wsaData);
#endif

	xmlInitParser();
	LIBXML_TEST_VERSION xmlSubstituteEntitiesDefault(1);

	// .. AND START THE MAIN WIDGET
	std::pair<wxString, wxString> prober_address;
	if (m_probers_addresses.find(ipk_prefix) != m_probers_addresses.end())
		prober_address = m_probers_addresses[ipk_prefix];
	EkstraktorWidget *ew = new EkstraktorWidget(ipk_prefix, geometry.IsEmpty() ? NULL : &geometry, prober_address, sz4);

	if (ew->IsConfigLoaded() == false) {
		delete ew;
		exit(1);
	}
	return true;

} // onInit()
コード例 #6
0
ファイル: testapp.cpp プロジェクト: cyclefusion/szarp
bool TestApp::OnInit() {
	/* Read params from szarp.cfg. */
#if wxUSE_UNICODE
	libpar_read_cmdline_w(&argc, argv);
#else
	libpar_read_cmdline(&argc, argv);
#endif

	SetProgName(_T("Test app"));

	m_db_queue = NULL;
	m_executor = NULL;
	m_remarks_handler = NULL;

#ifdef __WXGTK__
	libpar_init();
#endif

#ifdef MINGW32
	WORD wVersionRequested = MAKEWORD(2, 2);
	WSADATA wsaData;
	WSAStartup(wVersionRequested, &wsaData);
#endif

#if 0
	wxPendingEventsLocker = new wxCriticalSection;
#endif

	/* Set logging to stderr. */
	wxLog *logger = new wxLogStderr();
	wxLog::SetActiveTarget(logger);

	wxString _lang = wxConfig::Get()->Read(_T("LANGUAGE"), AUTO_LANGUAGE);
	if (_lang == AUTO_LANGUAGE)
		_lang = DEFAULT_LANGUAGE;

	IPKContainer::Init(GetSzarpDataDir().c_str(), 
			GetSzarpDir().c_str(), 
			_lang.c_str(),
			new szMutex());
	m_cfg_mgr = new ConfigManager(GetSzarpDataDir().c_str(), IPKContainer::GetObject());

	m_db_queue = new DatabaseQueryQueue();
	m_dbmgr = new DatabaseManager(m_db_queue, m_cfg_mgr);
	m_db_queue->SetDatabaseManager(m_dbmgr);
	//m_dbmgr->SetProbersAddresses(GetProbersAddresses());

	Szbase::Init(GetSzarpDataDir().c_str(),
			NULL,
			true,
			wxConfig::Get()->Read(_T("SZBUFER_IN_MEMORY_CACHE"), 0L));
	Szbase* szbase = Szbase::GetObject();

	m_executor = new QueryExecutor(m_db_queue, m_dbmgr, szbase);
	m_executor->Create();
	m_executor->SetPriority((WXTHREAD_MAX_PRIORITY + WXTHREAD_DEFAULT_PRIORITY) / 2);
	m_executor->Run();

	m_cfg_mgr->SetDatabaseManager(m_dbmgr);

#ifndef MINGW32
	libpar_done();
#endif

	m_remarks_handler = new RemarksHandler(m_cfg_mgr);
	m_remarks_handler->Start();

	SetAppName(_T("SZARPTESTAPP"));

	m_runner = new TestRunner(m_dbmgr, m_cfg_mgr);
	m_runner->Run();

	return TRUE;
}