void CInterval:: init() { bool integral = isIntegral(); timeType_ = TimeType::SECONDS; startTime_.year = 0; startTime_.month = 0; startTime_.day = 0; startTime_.hour = 0; startTime_.minute = 0; startTime_.second = 0; // Ensure min/max are in the correct order double min = std::min(data_.start, data_.end); double max = std::max(data_.start, data_.end); if (isIntegral()) { min = std::floor(min); max = std::ceil (max); } else if (isDate()) { int y = timeLengthToYears (min, max); int m = timeLengthToMonths (min, max); int d = timeLengthToDays (min, max); startTime_.year = timeToYear (min); startTime_.month = timeToMonths (min); startTime_.day = timeToDays (min); min = 0; if (y >= 5) { //std::cout << "years\n"; timeType_ = TimeType::YEARS; max = y; } else if (m >= 3) { //std::cout << "months\n"; timeType_ = TimeType::MONTHS; max = m; } else if (d >= 4) { //std::cout << "days\n"; timeType_ = TimeType::DAYS; max = d; } integral = true; } else if (isTime()) { int h = timeLengthToHours (min, max); int m = timeLengthToMinutes(min, max); int s = timeLengthToSeconds(min, max); startTime_.hour = timeToHours (min); startTime_.minute = timeToMinutes(min); startTime_.second = timeToSeconds(min); min = 0; if (h >= 12) { //std::cout << "hours\n"; timeType_ = TimeType::HOURS; max = h; } else if (m >= 10) { //std::cout << "minutes\n"; timeType_ = TimeType::MINUTES; max = m; } else { //std::cout << "seconds\n"; timeType_ = TimeType::SECONDS; max = s; } integral = true; } //--- // use fixed increment double majorIncrement = this->majorIncrement(); if (majorIncrement > 0.0 && (! isDate() && ! isTime())) { calcData_.start = min; calcData_.end = max; calcData_.increment = majorIncrement; calcData_.numMajor = CMathRound::RoundNearest((calcData_.end - calcData_.start)/calcData_.increment); calcData_.numMinor = 5; return; } //--- if (data_.numMajor > 0) { goodTicks_.opt = data_.numMajor; goodTicks_.min = std::max(goodTicks_.opt/10, 1); goodTicks_.max = goodTicks_.opt*10; } else { goodTicks_ = GoodTicks(); } //--- calcData_.numMajor = -1; calcData_.numMinor = 5; //--- calcData_.increment = data_.increment; if (calcData_.increment <= 0.0) { calcData_.increment = initIncrement(min, max, integral); //--- // Calculate other test increments for (int i = 0; i < numIncrementTests; i++) { // disable non-integral increments for integral if (integral && ! isInteger(incrementTests[i].factor)) { incrementTests[i].incFactor = 0.0; continue; } // disable non-log increments for log if (isLog() && ! incrementTests[i].isLog) { incrementTests[i].incFactor = 0.0; continue; } incrementTests[i].incFactor = calcData_.increment*incrementTests[i].factor; } //--- // Test each increment in turn (Set default start/end to force update) int tickIncrement = this->tickIncrement(); GapData axisGapData; for (int i = 0; i < numIncrementTests; i++) { // skip disable tests if (incrementTests[i].incFactor <= 0.0) continue; // if tick increment set then skip if not multiple of increment if (tickIncrement > 0) { if (! isInteger(incrementTests[i].incFactor)) continue; int incFactor1 = int(incrementTests[i].incFactor); if (incFactor1 % tickIncrement != 0) continue; } // test factor, ticks and update best if (testAxisGaps(min, max, incrementTests[i].incFactor, incrementTests[i].numTicks, axisGapData)) { //axisGapData.print(" Best) "); } } //--- calcData_.start = axisGapData.start; calcData_.end = axisGapData.end; calcData_.increment = axisGapData.increment; calcData_.numMinor = (! isLog() ? axisGapData.numMinor : 10); } else { calcData_.start = min; calcData_.end = max; calcData_.numMinor = 5; } calcData_.numMajor = CMathRound::RoundNearest((calcData_.end - calcData_.start)/calcData_.increment); if (isDate()) { if (timeType_ == TimeType::YEARS) { calcData_.numMinor = 12; } else if (timeType_ == TimeType::MONTHS) { calcData_.numMinor = 4; } else if (timeType_ == TimeType::DAYS) { calcData_.numMinor = 4; } } else if (isTime()) { if (timeType_ == TimeType::HOURS) { calcData_.numMinor = 6; } else if (timeType_ == TimeType::MINUTES) { calcData_.numMinor = 12; } else if (timeType_ == TimeType::SECONDS) { calcData_.numMinor = 12; } } }
bool KUserFiles::savesdw() { #ifdef HAVE_SHADOW bool addok = false; QString tmp; FILE *f; struct spwd *spwp; struct spwd s; KU::KUser *up; QString shadow_file = mCfg->shadowsrc(); QString new_shadow_file = shadow_file+QString::fromLatin1(KU_CREATE_EXT); if ( shadow_file.isEmpty() ) return TRUE; if (!s_backuped) { if (!backup(shadow_file)) return FALSE; s_backuped = TRUE; } if ((f = fopen(QFile::encodeName(new_shadow_file), "w")) == NULL) { KMessageBox::error( 0, i18n("Error opening %1 for writing.").arg(new_shadow_file) ); return FALSE; } s.sp_namp = (char *)malloc(200); s.sp_pwdp = (char *)malloc(200); QPtrListIterator<KU::KUser> it( mUsers ); up = (*it); while (true) { if ( up == 0 ) { if ( addok ) break; it = QPtrListIterator<KU::KUser> ( mAdd ); up = (*it); addok = true; if ( up == 0 ) break; }; if ( mDel.containsRef( up ) ) { ++it; up = (*it); continue; } if ( mMod.contains( up ) ) up = &( mMod[ up ] ); strncpy( s.sp_namp, up->getName().local8Bit(), 200 ); if ( up->getDisabled() ) strncpy( s.sp_pwdp, QString("!!" + up->getSPwd()).local8Bit(), 200 ); else strncpy( s.sp_pwdp, up->getSPwd().local8Bit(), 200 ); s.sp_lstchg = timeToDays( up->getLastChange() ); s.sp_min = up->getMin(); s.sp_max = up->getMax(); #ifndef _SCO_DS s.sp_warn = up->getWarn(); s.sp_inact = up->getInactive(); s.sp_expire = timeToDays( up->getExpire() ); s.sp_flag = up->getFlag(); #endif spwp = &s; putspent(spwp, f); ++it; up = (*it); } fclose(f); chmod(QFile::encodeName(new_shadow_file), sdw_mode); chown(QFile::encodeName(new_shadow_file), sdw_uid, sdw_gid); rename(QFile::encodeName(new_shadow_file), QFile::encodeName(shadow_file)); free(s.sp_namp); free(s.sp_pwdp); #endif // HAVE_SHADOW return TRUE; }