bool XSettingsModel::save_profile() { // get lastused profile name QString previous = getLastUsed(); // or default if none #ifdef USE_ALTERNATE_GETFILE QString filename = util_getFileName(0, "Save Profiles", previous, QStringList("*.ini")); #else // !#ifdef USE_ALTERNATE_GETFILE QString filename = QFileDialog::getSaveFileName(0, "Save Profiles", previous, "Profile files (*.ini)" ); #endif // #ifdef USE_ALTERNATE_GETFILE y/n if (filename.length() == 0) { outLog("*** Profile write abandoneed"); return false; } QSettings settings(filename,QSettings::IniFormat); // selected profile filename will be stored in settings set_option("profile", true, filename); setLastUsed(filename); //= loop rows and save each "option" as an [ini section] with enabled, value as values for(int row_idx=0; row_idx < rowCount(); row_idx++){ settings.beginGroup(item(row_idx, C_OPTION)->text()); settings.setValue( "enabled", item(row_idx, C_ENABLED)->text()); settings.setValue( "value", item(row_idx, C_VALUE)->text()); settings.endGroup(); } outLog("*** Profile written to disk: "+filename); return true; }
void TextureManager::deleteTexture(const std::string& textureID) { if (textureBank.count(textureID) != 0) { textureBank.erase(textureID); outLog("* Deleting texture: \"" + textureID + "\""); } else outLog("#WARNING Texture \"" + textureID + "\" doesn't exist! Unable to delete"); }
bool TextureManager::loadTexture(const std::string& textureID, const std::string& filePath) { if (textureBank.count(textureID) != 0) { outLog("#WARNING \"" + textureID + "\" already loaded! Overwriting texture.."); deleteTexture(textureID); } outLog("* Loading new texture: \"" + textureID + "\" from " + filePath ); Texture newTexture; if (!newTexture.load(filePath)) return false; textureBank[textureID] = newTexture; return true; }
void CyclicCoordinateDescent::logResults(const char* fileName, bool withASE) { ofstream outLog(fileName); if (!outLog) { std::ostringstream stream; stream << "Unable to open log file: " << fileName; error->throwError(stream); } string sep(","); // TODO Make option outLog << "label" << sep << "estimate" //<< sep << "score" ; if (withASE) { outLog << sep << "ASE"; } outLog << endl; for (int i = 0; i < J; i++) { outLog << hXI.getColumn(i).getLabel() // << sep << conditionId << sep << hBeta[i]; if (withASE) { double ASE = sqrt(getAsymptoticVariance(i,i)); outLog << sep << ASE; } outLog << endl; } outLog.flush(); outLog.close(); }
void TextureManager::useTexture(const std::string& textureID) { if (textureBank.count(textureID) == 0) { textureBank.erase(textureID); outLog("#WARNING Trying to bind unexisting textureID: \"" + textureID + "\""); } else textureBank[textureID].bind(); }
QString XSettingsModel::get_fgfs_command_string() { QString fgfs = fgfs_path(); QFile file(fgfs); if (file.exists()) { outLog("XSettingsModel::get_fgfs_command_string: Found valid file ["+fgfs+"]"); } else { outLog("XSettingsModel::get_fgfs_command_string: File ["+fgfs+"] NOT valid!"); } if (fgfs.indexOf((QChar(' ')) > 0)) { fgfs = "\""+fgfs+"\""; // quote it if it contains a SPACE } fgfs.append(" "); fgfs.append( get_fgfs_args().join(" ") ); return fgfs; }
void XSettingsModel::load_last_profile(QString profile) { _loading = true; QString filename = profile; QSettings settings(filename,QSettings::IniFormat); outLog("*** FGx loading last used profile:"+filename); bool ena; for(int row_idx=0; row_idx < rowCount(); row_idx++){ //= loop rows and load each "option" as an [ini section] with enabled, value as values settings.beginGroup(item(row_idx, C_OPTION)->text()); ena = settings.value("enabled").toBool() ; item(row_idx, C_ENABLED)->setText( ena ? "1" : "0"); QString val = settings.value("value").toString(); if(val == ""){ val = item(row_idx, C_DEFAULT)->text(); } item(row_idx, C_VALUE)->setText(val ); set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240)); //= Broadcast changes emit upx(item(row_idx, C_OPTION)->text(), item(row_idx, C_ENABLED)->text() == "1", item(row_idx, C_VALUE)->text() ); settings.endGroup(); } _loading = false; emit updated(get_fgfs_list()); }
//================================================== // == Set An Option void XSettingsModel::set_option(QString option, bool enabled, QString value) { //qDebug() << "set " << option << _loading; if(_loading){ return; } //= Find item matching the "option" QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION); //qDebug() << "opts" << items; //TODO handle error if not found if (items.size() == 0) { outLog("set_option:setx called with INVALID option ["+option+"]"); return; } //= Get/update the "enabled" item in the same row QStandardItem *eItem = item(items[0]->row(),C_ENABLED); eItem->setText(enabled ? "1" : "0"); //= Get/update the "value" item in the same row QStandardItem *vItem = item(items[0]->row(),C_VALUE); vItem->setText(value); set_row_bg(items[0]->row(), enabled ? QColor(200,255,200) : QColor(240,240,240)); //= Announce the change //emit upx(option, enabled, value); emit updated(get_fgfs_list()); }
/* ==================== acppet a new client fd ==================== */ void acceptNewClient (SOCKET listenfd) { SOCKET newDesc; struct sockaddr_in peer; #if defined (WIN32) int peersize; #else socklen_t peersize; #endif peersize = sizeof (peer); newDesc = accept (listenfd, (struct sockaddr*) &peer, &peersize); if (newDesc < 0) { outLog ((char*)"accept new client failed!\r\n"); return; } setNonblock (newDesc); struct sPacket* newClient = (struct sPacket*) malloc (sizeof (struct sPacket*)); if (!newClient) { CLOSESOCKET (newDesc); return; } newClient->m_sock = newDesc; (void*) strcpy (newClient->m_ip, (char*) inet_ntoa (peer.sin_addr)); *newClient->m_recvBuff = 0x00; newClient->m_recvSize = 0x00; newClient->m_recvPos = 0x00; *newClient->m_sendBuff = 0x00; newClient->m_sendSize = 0x00; *newClient->m_name = 0x00; newClient->m_lastRecvTime = getTime (); newClient->m_prev = NULL; newClient->m_next = NULL; INSERT_TO_LIST (g_ClientList, newClient, m_prev, m_next); g_TotalClient++; outLog ((char*)"accept new connection: %d [%s]\r\n", newDesc, newClient->m_ip); }
bool XSettingsModel::load_profile() { _loading = true; // get lastused profile name QString previous = getLastUsed(); // or default if none #ifdef USE_ALTERNATE_GETFILE QString filename = util_getFileName(0, "Load Profiles", previous, QStringList("*.ini") ); #else // !#ifdef USE_ALTERNATE_GETFILE QString filename = QFileDialog::getOpenFileName(0, "Load Profiles", previous, "Profile files (*.ini)" ); #endif // #ifdef USE_ALTERNATE_GETFILE y/n QFile file; if ((filename.length() == 0) || (!file.exists(filename))) { outLog("*** Profile load abandonned!"); _loading = false; return false; // NO LOAD POSSIBLE } QSettings settings(filename,QSettings::IniFormat); bool ena; for(int row_idx=0; row_idx < rowCount(); row_idx++){ //= loop rows and load each "option" as an [ini section] with enabled, value as values settings.beginGroup(item(row_idx, C_OPTION)->text()); ena = settings.value("enabled").toBool() ; item(row_idx, C_ENABLED)->setText( ena ? "1" : "0"); QString val = settings.value("value").toString(); if(val == ""){ val = item(row_idx, C_DEFAULT)->text(); } item(row_idx, C_VALUE)->setText(val ); set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240)); //= Broadcast changes emit upx(item(row_idx, C_OPTION)->text(), item(row_idx, C_ENABLED)->text() == "1", item(row_idx, C_VALUE)->text() ); settings.endGroup(); } emit updated(get_fgfs_list()); outLog("*** Profile loaded: "+filename); setLastUsed(filename); // store lastused profile name return true; }
/* ==================== set socket fd to nonblock ==================== */ void setNonblock (SOCKET fd) { int flags; flags = fcntl (fd, F_GETFL, 0); flags |= O_NONBLOCK; if (fcntl (fd, F_SETFL, flags) < 0) outLog ((char*)" * nonblock Error\r\n"); }
//**************************************************************************** //** Browser Map void MainObject::on_browsermap(){ QUrl mapUrl(X->getx("show_mpmap")); if (X->get_ena("show_mpmap")) { mapUrl.addQueryItem("follow", X->getx("--callsign=")); QDesktopServices::openUrl(mapUrl); outLog("Opening browser map: "+mapUrl.toString()); } }
/* ==================== initialize server socket ==================== */ SOCKET initServerSock (int port, int backLog) { struct sockaddr_in sa; SOCKET sock; sock = socket (PF_INET, SOCK_STREAM, 0); if (sock < 0) { outLog ((char*)"InitServerSock(), socket (..) failed [PORT: %d].. \r\n", port); return (-1); } int opt = 1; if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, \ (char*) &opt, sizeof (opt)) < 0) { outLog ((char*)"* Error: setsockopt REUSEADDR\r\n"); exit (1); } struct linger ld; ld.l_onoff = 0; ld.l_linger = 0; if (setsockopt (sock, SOL_SOCKET, SO_LINGER, \ (char*) &ld, sizeof (ld)) < 0) outLog ((char*)"* Error: setsockopt SO_LINGER ...\r\n"); (void) memset ((char*)&sa, 0x00, sizeof (sa)); sa.sin_family = PF_INET; sa.sin_port = htons (port); sa.sin_addr.s_addr = INADDR_ANY; if (bind (sock, (struct sockaddr*)&sa, sizeof (sa)) < 0) { outLog ((char*)"InitServerSock(), bind (..) failed [PORT: %d].. \r\n", port); CLOSESOCKET (sock); return (-1); } setNonblock (sock); listen (sock, backLog); return (sock); }
void AutoSearchCrossValidationDriver::logResults(const CCDArguments& allArguments) { const auto& arguments = allArguments.crossValidation; ofstream outLog(arguments.cvFileName.c_str()); if (!outLog) { std::ostringstream stream; stream << "Unable to open log file: " << arguments.cvFileName; error->throwError(stream); } outLog << std::scientific; for (int i = 0; i < maxPoint.size(); ++i) { outLog << maxPoint[i] << " "; } outLog << std::endl; outLog.close(); }
void XSettingsModel::read_default_ini() { QString defaultSettings(""); switch (mainObject->runningOs()) { case OS_MAC: defaultSettings = ":/default/osx_default.ini"; break; case OS_WINDOWS: defaultSettings = ":/default/win_default.ini"; break; case OS_LINUX: defaultSettings = ":/default/x_default.ini"; break; default: outLog("*** FGx shout: No default settings for this system"); break; } QSettings settings(defaultSettings,QSettings::IniFormat); bool ena; for(int row_idx=0; row_idx < rowCount(); row_idx++){ //= loop rows and load each "option" as an [ini section] with enabled, value as values settings.beginGroup(item(row_idx, C_OPTION)->text()); ena = settings.value("enabled").toBool() ; item(row_idx, C_ENABLED)->setText( ena ? "1" : "0"); QString val = settings.value("value").toString(); if(val == ""){ val = item(row_idx, C_DEFAULT)->text(); } item(row_idx, C_VALUE)->setText(val ); set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240)); //= Broadcast changes emit upx(item(row_idx, C_OPTION)->text(), item(row_idx, C_ENABLED)->text() == "1", item(row_idx, C_VALUE)->text() ); settings.endGroup(); } //qDebug() << "Read ini"; emit updated(get_fgfs_list()); }
void TcpConnector::logMessage(QString message) { emit outLog(mName + ": " + message); }
MainObject::~MainObject() { outLog(util_getDateTimestg()+" - Application close"); }
bool AirportsData::import(QProgressDialog &progress, MainObject *mainObject){ QHash<QString, QString> airports; QString msg; QTime tm; int ms; progress.setValue(0); progress.setWindowTitle("Scanning Airport Directories"); progress.setRange(0, 50000); int c = 0; int found = 0; int air_added = 0; ms = tm.restart(); // Removing cache file, if exists() if (QFile::exists(mainObject->data_file("airports.txt"))) { outLog("*** FGx airportsdata reload: cache file exists!"); QFile::remove(mainObject->data_file("airports.txt")); outLog("*** FGx airportsdata reload: REMOVED AIRPORTS CACHE FILE"); } //= Cache File QFile cacheFile( mainObject->data_file("airports.txt") ); if(!cacheFile.open(QIODevice::WriteOnly | QIODevice::Text)){ //qDebug() << "TODO Open error cachce file="; return true; } QTextStream out(&cacheFile); msg = "FGx airportsdata reload: Scanning apt.dat.gz in " + mainObject->X->fgroot() + "/Airports/apt.dat.gz"; outLog(msg); airports = getAirportNameMap(mainObject); //================================================ //* Lets Loop the directories //* Get out aiports path from setings and get the the subdir also QDirIterator loopAirportsFiles( mainObject->X->airports_path(), QDirIterator::Subdirectories ); QString xFileName; msg = "FGx airportsdata reload: Scanning XML files in "+mainObject->X->airports_path(); outLog(msg); progress.setWindowTitle(msg); progress.setRange(0, 50000); // Check the fgfs additional argument list, // and/or any additional scenery path inputs // *** take care NOT to duplicate *** QStringList fgfs_args = mainObject->X->get_fgfs_args(); int i, ind; QDir d; QString path; #ifdef Q_OS_WIN QChar psep(';'); #else QChar psep(':'); #endif // AIIIIII, found the doubler !, said yves very very loud - well done said pete ;-) for (i = 0; i < fgfs_args.size(); i++) { msg = fgfs_args.at(i); ind = msg.indexOf(QChar('"')); if (ind == 0) msg = msg.mid(1,msg.length()-2); if (msg.indexOf("--fg-scenery=") == 0) { // got a scenery folder to scan msg = msg.mid(13); ind = msg.indexOf(QChar('"')); if (ind == 0) msg = msg.mid(1,msg.length()-2); QStringList path_list = msg.split(psep); int pathnumber = 0; for( QStringList::ConstIterator entry = path_list.begin(); entry != path_list.end(); entry++) { path = *entry; pathnumber = pathnumber + 1; if (d.exists(path)) { // we have a PATH to check, but we are ONLY checking 'Airports' if ( !(path.indexOf(QChar('/')) == (path.size()-1)) && !(path.indexOf(QChar('\\')) == (path.size()-1)) ) path.append("/"); path.append("Airports"); // XML is only in here if (!d.exists(path)) continue; QDirIterator loopFiles( path, QDirIterator::Subdirectories ); while (loopFiles.hasNext()) { //= Get file handle if there is one xFileName = loopFiles.next(); //= Check if file entry is a *.threshold.xml - cos this is what we want if(xFileName.endsWith(".threshold.xml") ){ //= Split out "CODE.threshold.xml" with a "." QFileInfo fileInfoThreshold(xFileName); QString airport_code = fileInfoThreshold.fileName().split(".").at(0); //* Update progress if(c % 100 == 0){ progress.setValue(c); progress.setLabelText(xFileName); progress.repaint(); } QString airport_name(""); if(airports.contains(airport_code)){ airport_name = airports.value(airport_code); } QStringList cols; // missing in middle is description ?? cols << airport_code << airport_name << fileInfoThreshold.absoluteDir().absolutePath() << QString::number(pathnumber); out << cols.join("\t").append("\n"); air_added++; found++; } if(progress.wasCanceled()){ progress.hide(); return true; } c++; } } } } } cacheFile.close(); msg.sprintf("*** FGx airportsdata reload: Walked %d files, found %d threshold.xml, appended %d to cache", c, found, air_added); outLog(msg+", in "+getElapTimeStg(tm.elapsed())); progress.hide(); return false; }