QString ImageDirectory()
 {
     #ifdef WIN32
     return DataDirectory()+QString("img\\");
     #else
     return DataDirectory()+QString("img/");
     #endif
 }
 QString XmlDirectory()
 {
     #ifdef WIN32
     return DataDirectory() + QString("xml\\");
     #else
     return DataDirectory() + QString("xml/");
     #endif
 }
 QString CookiesDirectory()
 {
     #ifdef WIN32
     return DataDirectory()+QString("cookies\\");
     #else
     return DataDirectory()+QString("cookies/");
     #endif
 }
 QString DumpDirectory()
 {
     #ifdef WIN32
     return DataDirectory()+QString("onlinedump\\");
     #else
     return DataDirectory()+QString("onlinedump/");
     #endif
 }
QString UnitSyncFileManager::UnitSyncFile() const
{
	if( _mode == UnitSync_MultiEngine )
		return SelectedEnginePath().append( "/" ).append( _unitSyncFile );
	else
		return DataDirectory().append( "/" ).append( _unitSyncFile );
}
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
}