/* 系统初始化 */
void initVars(void){
	/*-- After load Panel, you can init args' value right here ---*/
	//Panel relative Vals
	GetPanelAttribute(panelHdl, ATTR_WIDTH, &pWidth);
	GetPanelAttribute(panelHdl, ATTR_HEIGHT, &pHeight);
	GetPanelAttribute(panelHdl, ATTR_MENU_HEIGHT, &mHeight);
	validMonNum = 6;
	averSpaceH = 8; averSpaceV = 20; extraRight = 150;
	pHeight = pHeight - mHeight;
	cWidth = (pWidth - extraRight - averSpaceH*3)/3;
	cHeight = (pHeight - averSpaceV*2)/2;
	plotBakgColor = MakeColor(200, 200, 200); //Set background color of graphs
	plotGridColor = MakeColor(10, 10, 10);
	plotLineColor = MakeColor(136, 0, 25);
	graphScaleMode = VAL_MANUAL; //or VAL_MANUAL VAL_AUTOSCALE
	//x,y坐标的标值范围
	xAxisRange[0] = 0.0, xAxisRange[1] = 9.0; //temp
	yAxisRange[0] =0.00, yAxisRange[1] = 3.00;
	
	popPanelIsPloting = 0;
	//Create a ThreadPool
	if(setupThreadPool()<0){
		MessagePopup("s", "Create thread pool error.");
	}
	//ChildPanel,TabPage、and Popup panel's Vals
	tabWidth = pWidth-extraRight-averSpaceH*3;
	tabHeight = pHeight - averSpaceV*3;
	
	dataSrc = 0;
	for(int i=0; i<validMonNum; i++)
		signalShowingStat[i] = 1;
	//init the necessary Directory this system needs
	initDirectorySets();
	refreshDimmedStat();
	isDataAcqRunning = 0;
}
Esempio n. 2
0
void Downloader::start() {
  // Fetch HEAD to find out the size but also if it exists.
  reply = getHead(url);
  if (!reply) {
    QCoreApplication::exit(-1);
    return;
  }
  url = reply->url();

  // Find "Content-Length". If not found then it keeps operating (with
  // a single connection) not knowing the total size but it will
  // eventually be known from the first chunk progress information.
  bool ok;
  if (reply->hasRawHeader("Content-Length")) {
    contentLen =
      QString::fromUtf8(reply->rawHeader("Content-Length")).toLongLong(&ok);
    if (!ok || contentLen == 0) {
      qCritical() << "ERROR Invalid content length:" << contentLen;
      contentLen = -1;
    }
  }

  // Check if the total is different than the Content-Length and, if
  // so, then change to that number.
  if (reply->hasRawHeader("Content-Range")) {
    single = false;
    QString range = QString::fromUtf8(reply->rawHeader("Content-Range"));
    QStringList elms = range.split("/", QString::SkipEmptyParts);
    if (elms.size() == 2) {
      qint64 tot = elms[1].toLongLong(&ok);
      if (ok && tot > 0 && tot != contentLen) {
        contentLen = tot;
      }
    }
  }

  QString type;
  if (reply->hasRawHeader("Content-Type")) {
    type = QString::fromUtf8(reply->rawHeader("Content-Type"));
    int pos;
    if ((pos = type.indexOf(";")) != -1) {
      type = type.mid(0, pos);
    }
  }

  // Check if filename is defined.
  if (reply->hasRawHeader("Content-Disposition")) {
    QString hdr = QString::fromUtf8(reply->rawHeader("Content-Disposition"));
    int pos = hdr.indexOf("; filename=");
    if (pos != -1) {
      hdr = hdr.mid(pos + 11).trimmed();
      if (hdr.startsWith("\"")) {
        hdr = hdr.mid(1);
      }
      if (hdr.endsWith("\"")) {
        hdr.chop(1);
      }
      if (!hdr.isEmpty()) {
        fileOverride = hdr;
      }
    }
  }

  QString fsize;
  if (contentLen == -1) {
    fsize = "Unknown";
  }
  else {
    fsize = Util::formatSize(contentLen, 1);
  }
  qDebug() << "File size" << qPrintable(fsize)
           << qPrintable(!type.isEmpty() ? "[" + type + "]" : "");

  // Check for header "Accept-Ranges" and whether it has "bytes"
  // supported.
  resumable = false;
  if (reply->hasRawHeader("Accept-Ranges")) {
    const QString ranges = QString::fromUtf8(reply->rawHeader("Accept-Ranges"));
    resumable = ranges.toLower().contains("bytes");
  }
  if (verbose) {
    qDebug() << qPrintable(QString("%1RESUMABLE").
                           arg(resumable ? "" : "NOT "));
  }

  if (!resumable && resume) {
    qCritical() << "ERROR Cannot resume because server doesn't support it!";
    QCoreApplication::exit(-1);
    return;
  }
  else if (resumable && resume && contentLen == -1) {
    qCritical() << "ERROR Cannot resume because the content length is unknown!";
    QCoreApplication::exit(-1);
    return;
  }

  // Clean reply.
  reply->close();
  reply = nullptr;

  // If performing a dry run then stop now.
  if (dryRun) {
    emit finished();
    return;
  }

  if (!setupFile()) {
    QCoreApplication::exit(-1);
    return;
  }

  createRanges();
  setupThreadPool();

  emit information(outputPath, contentLen, rangeCount, conns, offset);

  // Start actual download.
  download();
}