void ManualRideDialog::enterClicked() { if (!(BSentry->hasAcceptableInput() && DPentry->hasAcceptableInput() && distanceentry->hasAcceptableInput() ) ) { QMessageBox::warning( this, tr("Values out of range"), tr("The values you've entered in:\n ") +(!BSentry->hasAcceptableInput() ? "\t BikeScore\n " : "") +(!DPentry->hasAcceptableInput() ? "\t Daniels Points\n " : "") +(!distanceentry->hasAcceptableInput() ? "\t Distance\n " : "") + tr("are invalid, please fix.") ); return; } // write data to manual entry file // use user's time for file: QDateTime lt = dateTimeEdit->dateTime().toLocalTime(); if (filename == "") { char tmp[32]; sprintf(tmp, "%04d_%02d_%02d_%02d_%02d_%02d.gc", lt.date().year(), lt.date().month(), lt.date().day(), lt.time().hour(), lt.time().minute(), lt.time().second()); filename = tmp; filepath = home.absolutePath() + "/" + filename; FILE *out = fopen(filepath.toAscii().constData(), "r"); if (out) { fclose(out); if (QMessageBox::warning( this, tr("Ride Already Downloaded"), tr("This ride appears to have already ") + tr("been downloaded. Do you want to ") + tr("download it again and overwrite ") + tr("the previous download?"), tr("&Overwrite"), tr("&Cancel"), QString(), 1, 1) == 1) { reject(); return ; } } } QString tmpname; { // QTemporaryFile doesn't actually close the file on .close(); it // closes the file when in its destructor. On Windows, we can't // rename an open file. So let tmp go out of scope before calling // rename. QString tmpl = home.absoluteFilePath(".ptdl.XXXXXX"); QTemporaryFile tmp(tmpl); tmp.setAutoRemove(false); if (!tmp.open()) { QMessageBox::critical(this, tr("Error"), tr("Failed to create temporary file ") + tmpl + ": " + tmp.error()); reject(); return; } QTextStream out(&tmp); tmpname = tmp.fileName(); // after close(), tmp.fileName() is "" /* * File format: * <!DOCTYPE GoldenCheetah> * <ride> * <attributes> * <attribute key="Start time" value="2010/03/18 21:29:43 UTC"/> * <attribute key="Device type" value="Manual CSV"/> * </attributes> * <override> * <metric value="14" name="daniels_points"/> * <metric value="39" name="skiba_bike_score"/> * <metric value="3600" name="time_riding"/> * <metric value="200" name="total_distance"/> * <metric value="145" name="average_heartrate"/> * </override> * </ride> */ #define DATETIME_FORMAT "yyyy/MM/dd hh:mm:ss' UTC'" double secs = (hrsentry->text().toInt() * 3600) + (minsentry->text().toInt() * 60) + (secsentry->text().toInt()); out << "<!DOCTYPE GoldenCheetah>\n" << "<ride>\n" << "\t<attributes>\n" << "\t\t<attribute key=\"Start time\" value=\"" << lt.toUTC().toString(DATETIME_FORMAT) <<"\"/>\n" << "\t\t<attribute key=\"Device type\" value=\"Manual CSV\"/>\n" << "\t</attributes>\n" << "\t<override>\n" << "\t\t<metric value=\"" << QString("%1").arg(DPentry->text().toInt()) << "\" name=\"daniels_points\"/>\n" << "\t\t<metric value=\"" << QString("%1").arg(BSentry->text().toInt()) << "\" name=\"skiba_bike_score\"/>\n" << "\t\t<metric value=\"" << QString("%1").arg(secs) << "\" name=\"workout_time\"/>\n" << "\t\t<metric value=\"" << QString("%1").arg(secs) << "\" name=\"time_riding\"/>\n" << "\t\t<metric value=\"" << QString("%1").arg(useMetricUnits ? distanceentry->text().toFloat() : (1.00/MILES_PER_KM) * distanceentry->text().toFloat()) << "\" name=\"total_distance\"/>\n" << "\t\t<metric value=\"" << QString("%1").arg(HRentry->text().toInt()) << "\" name=\"average_hr\"/>\n" << "\t</override>\n" << "</ride>\n" ; tmp.close(); // QTemporaryFile initially has permissions set to 0600. // Make it readable by everyone. tmp.setPermissions(tmp.permissions() | QFile::ReadOwner | QFile::ReadUser | QFile::ReadGroup | QFile::ReadOther); } #ifdef __WIN32__ // Windows ::rename won't overwrite an existing file. if (QFile::exists(filepath)) { QFile old(filepath); if (!old.remove()) { QMessageBox::critical(this, tr("Error"), tr("Failed to remove existing file ") + filepath + ": " + old.error()); QFile::remove(tmpname); reject(); } } #endif // Use ::rename() instead of QFile::rename() to get forced overwrite. if (rename(QFile::encodeName(tmpname), QFile::encodeName(filepath)) < 0) { QMessageBox::critical(this, tr("Error"), tr("Failed to rename ") + tmpname + tr(" to ") + filepath + ": " + strerror(errno)); QFile::remove(tmpname); reject(); return; } mainWindow->addRide(filename); accept(); }
Date Date::operator++(int ) { Date old(*this); ++*this; // use the pre-increment return old; }
void DoComparison(TString newFileName, TString oldFileName, vector<TString> newHistName, vector<TString> oldHistName) { TFile newF(newFileName,"read"); TDirectory *newDir = newF.GetDirectory("Merged"); TFile old(oldFileName); TFile output("Comparison.root","update"); assert(newHistName.size() == oldHistName.size()); vector<TH1D*> newHists; vector<TH1D*> oldHists; for(UInt_t i = 0; i < newHistName.size(); i++) { TH1D *newH = (TH1D*)newDir->Get(newHistName[i]); if(!newH) { cout<<"Could not find "<<newHistName[i]<< " in "<<newDir->GetName()<<endl; return; } TH1D *oldH = (TH1D*)old.Get(oldHistName[i]); if(!oldH) { cout<<"Could not find "<<oldHistName[i]<< " in "<<old.GetName()<<endl; return; } newHists.push_back(newH); oldHists.push_back(oldH); } for(UInt_t i = 0; i < newHists.size(); i++) { // Make ratio TH1D *ratio = (TH1D*)newHists[i]->Clone(); ratio->Divide(oldHists[i]); ratio->SetDirectory(0); TString newName = newHists[i]->GetName(); newName += "Ratio"; ratio->SetName(newName); ratio->SetTitle(newName); ratio->SetMarkerStyle(20); output.cd(); ratio->Write(newName, TObject::kOverwrite); cout<<"Wrote "<<newName<<" to "<< output.GetName()<<endl; // Make difference TH1D *difference = (TH1D*)newHists[i]->Clone(); difference->Add(oldHists[i],-1.); difference->SetDirectory(0); newName = newHists[i]->GetName(); newName += "Difference"; difference->SetName(newName); difference->SetTitle(newName); difference->SetMarkerStyle(20); output.cd(); difference->Write(newName, TObject::kOverwrite); cout<<"Wrote "<<newName<<" to "<< output.GetName()<<endl; // Make side by side plot TString canName = "Canvas"; canName += newHists[i]->GetName(); canName += "Comparison"; TCanvas *can = new TCanvas(canName, canName); newHists[i]->SetLineColor(kBlack); newHists[i]->SetMarkerStyle(20); newHists[i]->SetMarkerColor(kBlack); oldHists[i]->SetLineColor(kRed); oldHists[i]->SetMarkerStyle(20); oldHists[i]->SetMarkerColor(kRed); oldHists[i]->Draw(); newHists[i]->Draw("same"); can->Write(canName, TObject::kOverwrite); delete can; can = NULL; } }
void SpawnMonitor::saveSpawnPoints() { // only save if modified if (!m_modified) return; if ( !m_zoneName.length() ) { fprintf( stderr, "Zone name not set in 'SpawnMonitor::saveSpawnPoints'!\n" ); return; } QString fileName; fileName = QString(LOGDIR "/") + m_zoneName + ".sp"; QString newName = fileName + ".new"; QFile spFile( newName ); if (!spFile.open(IO_WriteOnly)) { printf("Failed to open %s for writing", (const char*)newName); return; } QTextStream output(&spFile); QAsciiDictIterator<SpawnPoint> it( m_points ); SpawnPoint* sp; while ((sp = it.current())) { ++it; output << sp->x() << " " << sp->y() << " " << sp->z() << " " << (unsigned long)sp->diffTime() << " " << sp->count() << " " << sp->name() << '\n'; } spFile.close(); QFileInfo fi( spFile ); QFile old( fileName ); QDir dir( fi.dir() ); QString backupName = fileName + ".bak"; if (old.exists()) { if (dir.rename( fileName, backupName)) { if (!dir.rename( newName, fileName)) printf( "Failed to rename %s to %s\n", (const char*)newName, (const char*)fileName); } } else { if (!dir.rename(newName, fileName)) printf("Failed to rename %s to %s\n", (const char*)newName, (const char*)fileName); } m_modified = false; printf("Saved spawn points: %s\n", (const char*)fileName); }
/** Expand the space available for this RlistSet. * Rebuilds old value in new space. * @param size is the size of the resized object. */ void RlistSet::expand(int size) { if (size <= n()) return; RlistSet old(this->n()); old.copyFrom(*this); resize(size); this->copyFrom(old); }
Fixed Fixed::operator++(int) { Fixed old(*this); ++this->_fixe; return (old); }
// postfix operator date++ Date Date::operator++(int dummy) { Date old(*this); ++*this; return old; }
/** Expand the space available for this ojbect. * Rebuilds old value in new space. * @param n is the size of the expanded object. */ void PathSet::expand(int n) { if (n <= this->n()) return; PathSet old(this->n(),pvals); old.copyFrom(*this); resize(n); this->copyFrom(old); }
VolumePixelDataIterator VolumePixelDataIterator::operator --(int) { VolumePixelDataIterator old(*this); m_pointer = static_cast<char*>(m_pointer) - scalarSize(); return old; }
GiColor GiCanvasIos::setBkColor(const GiColor& color) { GiColor old(m_draw->_bkcolor); m_draw->_bkcolor = color; return old; }
const IMAPTag IMAPTag::operator++(int) { IMAPTag old(*this); operator++(); return (old); }
void qore_program_private::waitForTerminationAndClear(ExceptionSink* xsink) { // we only clear the internal data structures once bool clr = false; { ReferenceHolder<QoreListNode> l(xsink); { AutoLocker al(plock); // wait for all threads to terminate waitForAllThreadsToTerminateIntern(); if (!ptid) { l = new QoreListNode; qore_root_ns_private::clearConstants(*RootNS, **l); // mark the program so that only code from this thread can run during data destruction ptid = gettid(); clr = true; } } } if (clr) { //printd(5, "qore_program_private::waitForTerminationAndClear() this: %p clr: %d\n", this, clr); // delete all global variables, etc qore_root_ns_private::clearData(*RootNS, xsink); // clear thread init code reference if any { ReferenceHolder<ResolvedCallReferenceNode> old(xsink); { AutoLocker al(tlock); // clear thread init code reference old = thr_init; thr_init = 0; } } // clear thread data if base object if (base_object) clearThreadData(xsink); clearProgramThreadData(xsink); { AutoLocker al(plock); ptid = -1; } // now clear the original map { AutoLocker al(tlock); pgm_data_map.clear(); tclear = 0; if (twaiting) tcond.broadcast(); } #ifdef HAVE_SIGNAL_HANDLING { int_set_t ns = sigset; // clear all signal handlers managed by this program for (int_set_t::iterator i = ns.begin(), e = ns.end(); i != e; ++i) QSM.removeHandler(*i, xsink); } #endif // merge pending parse exceptions into the passed exception sink, if any if (pendingParseSink) { xsink->assimilate(pendingParseSink); pendingParseSink = 0; } // clear any exec-class return value discard(exec_class_rv, xsink); exec_class_rv = 0; // clear program location update_runtime_location(QoreProgramLocation()); } }
/** Expand the space available for this ojbect. * Rebuilds old value in new space. * @param n is the size of the expanded object. */ void Ssets2k::expand(int n) { if (n <= this->n()) return; Ssets2k old(this->n()); old.copyFrom(*this); resize(n); this->copyFrom(old); }
Date Date::operator--(int ) { Date old(*this); --*this; // use the pre-decrement return old; }
void UpdatingWindow::fileDownloaded(QNetworkReply* pReply) { //emit a signal pReply->deleteLater(); writeToFile->close(); this->ui->label->setText("Unpacking"); QDir dir; QStringList path = pathToDownload.split("/"); path.removeLast(); QString oldPath = path.join("/")+"_old/"; QString exeName = fileToDownload.replace(".zip", ""); qDebug() << exeName << AppData::Instance()->executablePath(pathToDownload+exeName) << AppData::Instance()->executablePath(pathToDownload+exeName).replace(exeName, "").replace(".app", exeName+".app"); QString resourcesPath = pathToDownload; if(osName() == "win") { resourcesPath = AppData::Instance()->executablePath(pathToDownload).replace(".exe", "")+ "/"; } QString program; QStringList arguments; if(osName() == "osx" || osName()=="linux") { program = "unzip"; arguments << "-o" << pathToDownload + fileToDownload << "-d " << pathToDownload; QProcess::execute("unzip -o " + pathToDownload + fileToDownload + " -d " + pathToDownload); } else if(osName()== "win") { program = "7za.exe"; QString test = QString("-o")+pathToDownload; arguments << "x" << pathToDownload + fileToDownload << "-aoa" <<test; } QProcess *myProcess = new QProcess(); qDebug() << program; myProcess->setProcessChannelMode(QProcess::MergedChannels); myProcess->start(program, arguments); //sleep(10); myProcess->waitForFinished(-1); //qDebug() << myProcess->program() << myProcess->arguments().at(3); qDebug() << myProcess->readAll(); if (QFile::exists(resourcesPath+"settings.json")) { if(QFile::remove(resourcesPath+"settings.json")){ qDebug() << "removed settings.json"; } } if (QFile::exists(resourcesPath+"list.json")) { QFile::remove(resourcesPath+"list.json"); } qDebug() << resourcesPath; qDebug() << oldPath; QFile file(oldPath+"settings.json"); if(!file.rename(resourcesPath+"settings.json")){ qWarning() << "Settings.json move failed!!!"; } QFile file2(oldPath+"list.json"); file2.rename(resourcesPath+"list.json"); QDir old(oldPath); old.removeRecursively(); if(writeToFile->remove()){ qDebug() << "Removed Zip File"; QDir macJunkDir(pathToDownload + "__MACOSX"); macJunkDir.removeRecursively(); writeToFile->close(); } else { qDebug() << "Failed to remove zip file"; } this->ui->label->setText("Done!"); this->ui->progressBar->setValue(120); QString execPath; if(osName()=="osx") { QProcess::execute(QString("chmod +x %1").arg(pathToDownload + fileToDownload.replace(".zip", "")+ + ".app/Contents/MacOS/" + fileToDownload.replace(".zip", ""))); QProcess::execute(QString("chmod +x %1").arg(pathToDownload + fileToDownload.replace(".zip", "")+ ".app")); execPath = QString("open %1").arg(pathToDownload + fileToDownload.replace(".zip", "")+ ".app"); system(execPath.toLatin1()); }else if(osName()=="win"){ execPath = AppData::Instance()->executablePath("start " +pathToDownload+fileToDownload.replace(".zip", ".exe")); system(execPath.toLatin1()); } QProcess::startDetached(execPath); qDebug() << execPath; //qDebug() << process->errorString(); this->close(); }
/** Expand the space available for this Graph. * Rebuilds old value in new space. * @param size is the size of the resized object. */ void Graph::expand(int numv, int maxe) { if (numv <= n() && maxe <= M()) return; Graph old(this->n(),this->M()); old.copyFrom(*this); resize(numv,maxe); this->copyFrom(old); }
IMAPTag IMAPTag::operator++(int) { IMAPTag old(*this); operator++(); return old; }
bool create(const QString &dir, CFontEngine &fe) { bool root(Misc::root()), added = false; QString fmapDir(Misc::dirSyntax(root ? KFI_ROOT_CFG_DIR : dir)); CFile old(fmapDir); QStringList entries; int i; FcPattern *pat = FcPatternCreate(); FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_SCALABLE, (void *)0); FcFontSet *fs = FcFontList(0, pat, os); FcPatternDestroy(pat); FcObjectSetDestroy(os); for(i = 0; i < fs->nfont; i++) { QString fName(Misc::fileSyntax(CFcEngine::getFcString(fs->fonts[i], FC_FILE))); FcBool scalable = FcFalse; if(!fName.isEmpty() && (root || dir.isEmpty() || 0 == fName.find(dir)) && FcResultMatch == FcPatternGetBool(fs->fonts[i], FC_SCALABLE, 0, &scalable) && scalable) { const QStringList *existing = old.getEntries(fName); if(existing && existing->count()) entries += (*existing); else { int face = 0, numFaces = 0; do { if(fe.openFont(fName, face)) { if(fe.hasPsInfo()) { if(0 == numFaces) numFaces = fe.getNumFaces(); // Only really for TTC files... // // Add real addEntry(entries, fe.getPsName(), fName, fmapDir); added = true; // // Add fake entries for X11 generated names switch(fe.getWeight()) { case CFontEngine::WEIGHT_MEDIUM: case CFontEngine::WEIGHT_REGULAR: { QString x11Ps(createX11PsName(fe.getFamilyName())); if(CFontEngine::ITALIC_ITALIC != fe.getItalic() && CFontEngine::ITALIC_OBLIQUE != fe.getItalic()) addAliasEntry(entries, createName(x11Ps, "Roman", getItalicStr(fe.getItalic())), fe.getPsName()); addAliasEntry(entries, createName(x11Ps, NULL, getItalicStr(fe.getItalic())), fe.getPsName()); break; } case CFontEngine::WEIGHT_UNKNOWN: break; default: addAliasEntry(entries, createName(createX11PsName(fe.getFamilyName()), CFontEngine::weightStr(fe.getWeight()), getItalicStr(fe.getItalic())), fe.getPsName()); } } fe.closeFont(); } } while(++face < numFaces); } } } bool status = true; if(added || entries.count() != old.getLineCount()) { KSaveFile out(fmapDir + FONTMAP); QTextStream *stream = out.textStream(); if(stream) { QStringList::Iterator it; for(it = entries.begin(); it != entries.end(); ++it) *stream << *it << endl; } else status = false; } // // Ensure GS's main Fontmap references our file... if(root && status) { static const char *constGhostscriptDirs[] = {"/usr/share/ghostscript/", "/usr/local/share/ghostscript/", "/usr/share/gs-esp/", NULL}; QString gsFile = locateFile(FONTMAP, constGhostscriptDirs); if(!gsFile.isEmpty()) { const int constMaxLineLen = 1024; const char *constRLF = ".runlibfile"; char line[constMaxLineLen]; ifstream in(QFile::encodeName(gsFile)); if(in) { QCString fmap(QFile::encodeName(fmapDir + FONTMAP)); int lineNum = 0, kfiLine = -1, gsLine = -1, ncLine = -1; do { in.getline(line, constMaxLineLen); if(in.good()) { line[constMaxLineLen - 1] = '\0'; if(strstr(line, fmap.data()) != NULL && strstr(line, constRLF) != NULL) kfiLine = lineNum; else if(strstr(line, FONTMAP ".GS") != NULL && strstr(line, constRLF) != NULL) gsLine = lineNum; if(-1 == ncLine && '%' != line[0]) ncLine = lineNum; lineNum++; } } while(!in.eof() && (-1 == kfiLine || -1 == gsLine)); // // If the file doesn't already say to use our Fontmap file, then tell it to! // Also, ensure ours is .runlibfile'd before the main GS one - else problems can occur if(-1 == kfiLine || kfiLine > gsLine) { in.clear(); in.seekg(0, ios::end); int size = (streamoff)in.tellg(); in.seekg(0, ios::beg); char *buffer = new char[size + strlen(fmap) + strlen(constRLF) + 5]; if(buffer) { bool added = false; buffer[0] = '\0'; lineNum = 0; do { in.getline(line, constMaxLineLen); if(in.good()) { line[constMaxLineLen - 1] = '\0'; if(lineNum >= ncLine && !added) { strcat(buffer, "("); strcat(buffer, fmap); strcat(buffer, ") "); strcat(buffer, constRLF); strcat(buffer, "\n"); added = true; } if(lineNum != kfiLine) { strcat(buffer, line); strcat(buffer, "\n"); } lineNum++; } } while(!in.eof()); in.close(); if(added) // Don't re-write GS's Fontmap unless we've actually added something... { KSaveFile out(gsFile); QTextStream *stream = out.textStream(); if(stream) *stream << buffer; } delete[] buffer; } } } } } return status; }
/** Expand the space available for this ojbect. * Rebuilds old value in new space. * @param n is the size of the expanded object. */ void Map_rbt::expand(int n) { if (n <= this->n()) return; Map_rbt old(this->n()); old.copyFrom(*this); resize(n); this->copyFrom(old); }