QString Application::ParseWildCardFilename(const QString& input) { // Parse all the special symbols from the log filename. QString filename = input.trimmed().replace("$(CWD)", CurrentWorkingDirectory(), Qt::CaseInsensitive); filename = filename.replace("$(INSTDIR)", InstallationDirectory(), Qt::CaseInsensitive); filename = filename.replace("$(USERDATA)", UserDataDirectory(), Qt::CaseInsensitive); filename = filename.replace("$(USERDOCS)", UserDocumentsDirectory(), Qt::CaseInsensitive); QRegExp rx("\\$\\(DATE:(.*)\\)"); // Qt Regexes don't support non-greedy matching. The above regex should be "\\$\\(DATE:(.*?)\\)". Instead Qt supports // only setting the matching to be non-greedy globally. rx.setMinimal(true); // This is to avoid e.g. $(DATE:yyyyMMdd)_aaa).txt to be incorrectly captured as "yyyyMMdd)_aaa". for(;;) // Loop and find all instances of $(DATE:someformat). { int pos = rx.indexIn(filename); if (pos > -1) { QString dateFormat = rx.cap(1); QString date = QDateTime::currentDateTime().toString(dateFormat); filename = filename.replace(rx.pos(0), rx.cap(0).length(), date); } else break; } return filename; }
QString Application::UserDocumentsDirectory() { QString qstr; #ifdef _WINDOWS LPITEMIDLIST pidl; if (SHGetFolderLocation(0, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, &pidl) != S_OK) return ""; WCHAR str[MAX_PATH+1] = {}; SHGetPathFromIDListW(pidl, str); CoTaskMemFree(pidl); qstr = WStringToQString(str) + '\\' + ApplicationName(); #else ///\todo Review. Is this desirable? qstr = UserDataDirectory(); #endif // Apply trailing slash if (!qstr.endsWith(QDir::separator())) qstr += QDir::separator(); return qstr; }
Application::Application(int &argc, char **argv) : QApplication(argc, argv), framework(0), appActivated(true), nativeTranslator(new QTranslator), appTranslator(new QTranslator), targetFpsLimit(60.0), splashScreen(0) { targetFpsLimitWhenInactive = targetFpsLimit / 2.f; // Reflect our versioning information to Qt internals, if something tries to obtain it straight from there. QApplication::setOrganizationName(organizationName); QApplication::setApplicationName(applicationName); QApplication::setApplicationVersion(version); // Parse version number parts. QStringList numberList = QString(version).split('.'); if (numberList.size() > 4) LogWarning("[Application]: More than 4 numbers given for application version. Ignoring extra numbers."); int i = 0; for(; i < numberList.size() && i < 4; ++i) { bool ok = false; uint versionNumber = numberList[i].trimmed().toUInt(&ok); if (!ok) { // Conversion failed. Is this the last number in the string? Maybe some kind of // postfix is used, "-RC1" or " RC1" or similar f.ex., so handle that. if (i == numberList.size() - 1) { QStringList lastNumber = numberList[i].split(QRegExp("[^0-9]")); if (!lastNumber.isEmpty()) versionNumber = lastNumber.first().trimmed().toUInt(&ok); } } // If conversion still not ok, default to 0. versionNumbers[i] = (ok ? versionNumber : 0); } // Guarantee trailing zeros. while(i < 4) versionNumbers[i++] = 0; #ifdef Q_WS_MAC QDir::setCurrent(QCoreApplication::applicationDirPath()); #endif // Make sure that the required Tundra data directories exist. QDir path = UserDataDirectory(); if (!path.exists()) path.mkpath("."); path = UserDocumentsDirectory(); if (!path.exists()) path.mkpath("."); // Add <install_dir>/qtplugins for qt to search plugins QString runDirectory = QDir::fromNativeSeparators(InstallationDirectory() + "/qtplugins"); addLibraryPath(runDirectory); // In headless mode, we create windows that are never shown. // Also, the user can open up debugging windows like the profiler or kNet network stats from the console, // so disable the whole application from closing when these are shut down. // For headful mode, we depend on explicitly checking on the closing of the main window, so we don't need // this flag in any case. setQuitOnLastWindowClosed(false); /// @todo This seems a bit odd here. Would there be a better place and could this be configurable at startup-/run-time? #ifndef ANDROID QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true); //enable flash #endif }
CelestialNavigationDialog::CelestialNavigationDialog(wxWindow *parent) : CelestialNavigationDialogBase(parent), m_FixDialog(this), m_ClockCorrectionDialog(this) { wxFileConfig *pConf = GetOCPNConfigObject(); pConf->SetPath( _T("/PlugIns/CelestialNavigation") ); //#ifdef __WXGTK__ // Move(0, 0); // workaround for gtk autocentre dialog behavior //#endif // Move(pConf->Read ( _T ( "DialogPosX" ), 20L ), pConf->Read ( _T ( "DialogPosY" ), 20L )); wxPoint p = GetPosition(); pConf->Read ( _T ( "DialogX" ), &p.x, p.x); pConf->Read ( _T ( "DialogY" ), &p.y, p.y); SetPosition(p); wxSize s = GetSize(); pConf->Read ( _T ( "DialogWidth" ), &s.x, s.x); pConf->Read ( _T ( "DialogHeight" ), &s.y, s.y); SetSize(s); // create a image list for the list with just the eye icon wxImageList *imglist = new wxImageList(20, 20, true, 1); imglist->Add(wxBitmap(eye)); m_lSights->AssignImageList(imglist, wxIMAGE_LIST_SMALL); m_lSights->InsertColumn(rmVISIBLE, wxT("")); m_lSights->SetColumnWidth(0, 28); m_lSights->InsertColumn(rmTYPE, _("Type")); m_lSights->InsertColumn(rmBODY, _("Body")); m_lSights->InsertColumn(rmTIME, _("Time (UT)")); m_lSights->InsertColumn(rmMEASUREMENT, _("Measurement")); m_lSights->InsertColumn(rmCOLOR, _("Color")); m_sights_path = celestial_navigation_pi::StandardPath() + _T("Sights.xml"); if(!OpenXML(m_sights_path, false)) { /* create directory for plugin files if it doesn't already exist */ wxFileName fn(m_sights_path); wxFileName fn2 = fn.GetPath(); if(!fn.DirExists()) { fn2.Mkdir(); fn.Mkdir(); } } wxString filename = DataDirectory() + "vsop87d.txt"; wxFileName fn(filename); if(!fn.Exists()) filename = UserDataDirectory() + "vsop87d.txt"; astrolabe::globals::vsop87d_text_path = (const char *)filename.mb_str(); #ifndef WIN32 // never hit because data is distribued easier to not compile compression support wxMessageDialog mdlg(this, _("Astrolab data unavailable.\n") + _("\nWould you like to download?"), _("Failure Alert"), wxYES | wxNO | wxICON_ERROR); if(mdlg.ShowModal() == wxID_YES) { wxString url = "https://cfhcable.dl.sourceforge.net/project/opencpnplugins/celestial_navigation_pi/"; wxString path = UserDataDirectory(); wxString fn = "vsop87d.txt.gz"; _OCPN_DLStatus status = OCPN_downloadFile( url+fn, path+fn, _("downloading celestial navigation data file"), "downloading...", *_img_celestial_navigation, this, OCPN_DLDS_CAN_ABORT|OCPN_DLDS_ELAPSED_TIME|OCPN_DLDS_ESTIMATED_TIME|OCPN_DLDS_REMAINING_TIME|OCPN_DLDS_SPEED|OCPN_DLDS_SIZE|OCPN_DLDS_URL|OCPN_DLDS_AUTO_CLOSE, 20); if(status == OCPN_DL_NO_ERROR) { // now decompress downloaded file ZUFILE *f = zu_open(path+fn.mb_str(), "rb", ZU_COMPRESS_AUTO); if(f) { FILE *out = fopen(path+"vsop87d.txt", "w"); if(out) { char buf[1024]; for(;;) { size_t size = zu_read(f, buf, sizeof buf); fwrite(buf, size, 1, out); if(size != sizeof buf) break; } fclose(out); } zu_close(f); } } } #endif #ifdef __OCPN__ANDROID__ GetHandle()->setStyleSheet( qtStyleSheet); Move(0, 0); #endif }