void MainWindow::updateProgressbar(qint64 completedBytes, qint64 totalBytes) { ui->progressBar->setMaximum(totalBytes); //最大值 ui->progressBar->setValue(completedBytes); //当前值 // calculate the download speed double speed = completedBytes * 1000.0 / m_downloadTime.elapsed(); QString unit; if (speed < 1024) { unit = "bytes/sec"; } else if (speed < 1024*1024) { speed = qMax(speed/1024, 1.0); unit = "KB/s"; } else { speed = qMax(speed/(1024*1024), 1.0); unit = "MB/s"; } ui->speedLabel->setText(QString::fromLatin1("%1 %2") .arg(speed, 3, 'f', 1).arg(unit) ); QString lessByte = QString("%1/%2") .arg(formatSize(completedBytes)) .arg(formatSize(totalBytes)); ui->sizeLabel->setText(lessByte); }
void CopyProgressDialog::update() { const int state = fileCopy->GetState(); if(state == FileCopy::Finished) { refreshTimer.stop(); accept(); } if(state != FileCopy::Running && state != FileCopy::ForcedRunning) return; updateSpeed(); ui.progressBar->setValue(fileCopy->GetProgress()); ui.totalSizeLabel->setText(tr("Total: ") + formatSize(fileCopy->GetTotalBytesCopied()) + '/' + formatSize(fileCopy->GetTotalSize())); if(const FileInfo *file = fileCopy->GetCurrentCopiedFile()) { ui.sourceLabel->setText(file->name); ui.currentFileBytesCopied->setText(formatSize(fileCopy->GetCurrentFileBytesCopied()) + '/' + formatSize(file->size)); } ui.progressBar_2->setValue(fileCopy->GetCurrentFileProgress()); }
void SpeedLimitWidget::refresh() { Queue* q = g_wndMain->getCurrentQueue(); if(q != 0) { int down,up; q->speedLimits(down,up); g_wndMain->doneQueue(q, true, false); if(down > 0) labelDown->setText(formatSize(down,true)); else labelDown->setText(QString::fromUtf8("∞ kB/s")); if(up > 0) labelUp->setText(formatSize(up,true)); else labelUp->setText(QString::fromUtf8("∞ kB/s")); labelDown->refresh(down); labelDown2->refresh(down); labelUp->refresh(up); labelUp2->refresh(up); } }
// ======================================================= void CSavingWindow::showStats(const time_t timeStart, QWORD qwBlockSize, QWORD qwBlocksDone, QWORD qwBlocksTotal, char *szFullyBatchMode) { BEGIN; char szTemp[1024]; char szTemp2[1024]; char szTemp3[1024]; time_t timeElapsed, timeRemaining; QWORD qwBytesPerMin; float fMinElapsed; QWORD qwPercent; // progress bar qwPercent = (100 * qwBlocksDone) / qwBlocksTotal; SNPRINTF(szTemp, "%d %%", (int)qwPercent); newtScaleSet(m_progressSaving, (int)qwPercent); newtLabelSetText(m_labelPercent, szTemp); // stats if (timeStart != 0) { QWORD qwDone = qwBlockSize * qwBlocksDone; QWORD qwTotal = qwBlockSize * qwBlocksTotal; timeElapsed = time(0) - timeStart; timeRemaining = (timeElapsed * (qwTotal - qwDone)) / qwDone; SNPRINTF(szTemp, i18n("Time elapsed:................%s"), formatTime((DWORD)timeElapsed, szTemp2)); newtLabelSetText(m_labelStatsTime, szTemp); SNPRINTF(szTemp, i18n("Estimated time remaining:....%s"), formatTime((DWORD)timeRemaining, szTemp2)); newtLabelSetText(m_labelStatsTimeRemaining, szTemp); fMinElapsed = ((float)timeElapsed) / 60.0; qwBytesPerMin = (QWORD) (((float)qwDone) / fMinElapsed); SNPRINTF(szTemp, i18n("Speed:.......................%s/min"), formatSize(qwBytesPerMin, szTemp2)); newtLabelSetText(m_labelStatsSpeed, szTemp); SNPRINTF(szTemp, i18n("Data copied:.................%s / %s"), formatSize(qwDone, szTemp2), formatSize(qwTotal, szTemp3)); newtLabelSetText(m_labelStatsSpace, szTemp); //option -B gui=no show stats if ((szFullyBatchMode) && (strlen(szFullyBatchMode)>0)) { SNPRINTF(szTemp, "stats: %3d%%", (int)qwPercent); fprintf(stderr,"%-s ",szTemp); SNPRINTF(szTemp, i18n("%-s %-s"), formatTimeNG((DWORD)timeElapsed, szTemp2), formatTimeNG((DWORD)timeRemaining, szTemp3)); fprintf(stderr,"%-s ",szTemp); SNPRINTF(szTemp, i18n("%s/min"), formatSizeNG(qwBytesPerMin, szTemp2)); fprintf(stderr,"%-s\n",szTemp); } } newtRefresh(); RETURN; }
// ======================================================= int CRestoringWindow::create(char *szDevice, char *szImageFile, QWORD qwCurPartSize, DWORD dwCompressionMode, char *szOriginalDevice, char *szFileSystem, tm dateCreate, QWORD qwOrigPartSize, COptions * options) { BEGIN; char szTemp[2048]; char szTemp2[2048]; if (options->bSimulateMode) SNPRINTF(szTemp, i18n("simulate partition restoration from image file")); else SNPRINTF(szTemp, i18n("restore partition from image file")); newtCenteredWindow(78, 20, szTemp); SNPRINTF(szTemp, i18n("Partition to restore:.............%s"), szDevice); m_labelPartition = newtLabel(1, 0, szTemp); SNPRINTF(szTemp, i18n("Size of partition to restore:.....%s = %llu bytes"), formatSize(qwCurPartSize, szTemp2), qwCurPartSize); m_labelPartitionSize = newtLabel(1, 1, szTemp); SNPRINTF(szTemp, i18n("Image file to use.................%s"), szImageFile); m_labelImageFile = newtLabel(1, 2, szTemp); SNPRINTF(szTemp, i18n("File system:......................%s"), szFileSystem); m_labelFS = newtLabel(1, 3, szTemp); m_labelCompression = newtLabel(1, 4, ""); SNPRINTF(szTemp, i18n("Partition was on device:..........%s\n"), szOriginalDevice); m_labelOldDevice = newtLabel(1, 5, szTemp); SNPRINTF(szTemp, i18n("Image created on:.................%s\n"), asctime(&dateCreate)); m_labelDate = newtLabel(1, 6, szTemp); SNPRINTF(szTemp, i18n("Size of the original partition:...%s = %llu bytes"), formatSize(qwOrigPartSize, szTemp2), qwOrigPartSize); m_labelOriginalPartitionSize = newtLabel(1, 7, szTemp); // stats m_labelStatsTime = newtLabel(1, 9, ""); m_labelStatsTimeRemaining = newtLabel(1, 10, ""); m_labelStatsSpeed = newtLabel(1, 11, ""); m_labelStatsSpace = newtLabel(1, 12, ""); m_progressRestoring = newtScale(1, 18, 70, 100); m_labelPercent = newtLabel(72, 18, ""); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelPartition, m_labelPartitionSize, m_labelImageFile, m_labelFS, m_labelCompression, NULL); newtFormAddComponents(m_formMain, m_labelOldDevice, m_labelDate, m_labelOriginalPartitionSize, NULL); newtFormAddComponents(m_formMain, m_labelStatsTime, m_labelStatsTimeRemaining, m_labelStatsSpeed, m_labelStatsSpace, NULL); newtFormAddComponents(m_formMain, m_progressRestoring, m_labelPercent, NULL); newtDrawForm(m_formMain); newtRefresh(); RETURN_int(0); }
/** * @brief creating instance of rowdata from transfer * * @param t transfer which will be inserted into data model */ RowData::RowData(Transfer* t) : m_state(t->state()),m_name(t->name()),m_message(t->message()), m_mode(t->mode()), m_primaryMode(t->primaryMode()) { const qint64 total = t->total(); m_fProgress = (total) ? 100.0/t->total()*t->done() : 0; if(t->total()){ m_progress = QString("%1 from %2 (%3%)").arg(formatSize(t->done(),false)).arg(formatSize(t->total(),false)).arg(100.0/t->total()*t->done(), 0, 'f', 1); m_size = formatSize(t->total(),false); } else{ m_progress = QString("%1, total size unknown").arg(formatSize(t->done(),false)); m_size = "?"; } if (t->mode() == (Transfer::Upload)){ m_destination = t->url(); m_source = t->dataPath(true); } else{ m_destination = t->dataPath(false); m_source = t->url(); } if(t->isActive()) { int down,up; t->speeds(down,up); if(down) { m_actSpeed = QString("%1 kB/s").arg(double(down)/1024.f, 0, 'f', 1); } if(up) { m_actSpeed += QString("%1 kB/s").arg(double(up)/1024.f, 0, 'f', 1); } if(t->total()) { qulonglong totransfer = t->total() - t->done(); if(t->primaryMode() == Transfer::Download) { if(down) m_timeLeft = formatTime(totransfer/down); } else if(up) m_timeLeft = formatTime(totransfer/up); } } else m_actSpeed==""; }
void StatusBarApplet::update() { if (TorrentInterface::selected()) { QString msg = QString("up: %1 K/s (%2), dn: %3 K/s (%4)") .arg(TorrentInterface::selected()->speedUp(), 2) .arg(formatSize(TorrentInterface::selected()->trafficUp())) .arg(TorrentInterface::selected()->speedDown(), 2) .arg(formatSize(TorrentInterface::selected()->trafficDown())); setText(msg); } else { setText(__tr2qs_ctx("No client selected!", "torrent")); } }
void SelectDestination::filenameEditLostFocus() { long long dummy; m_archiveDestination.freeSpace = getDiskSpace(m_filenameEdit->GetText(), dummy, dummy); // if we don't get a valid freespace value it probably means the file doesn't // exist yet so try looking up the freespace for the parent directory if (m_archiveDestination.freeSpace == -1) { QString dir = m_filenameEdit->GetText(); int pos = dir.lastIndexOf('/'); if (pos > 0) dir = dir.left(pos); else dir = "/"; m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy); } if (m_archiveDestination.freeSpace != -1) { m_freespaceText->SetText(formatSize(m_archiveDestination.freeSpace, 2)); m_freeSpace = m_archiveDestination.freeSpace; } else { m_freespaceText->SetText(tr("Unknown")); m_freeSpace = 0; } }
// ======================================================= char *processHardDrive(char *cPtr, newtComponent editPartition) { char *cOldPtr; int nMajor, nMinor, nBlocks; int nPartNum; char szDevice[128]; char szFullDevice[128]; char cFormat[1024]; char szTemp[1024]; char *szDeviceName; int nRes; QWORD qwSize; cOldPtr = cPtr; nPartNum = 1; showDebug(9, "decode HD\n"); while (*(cPtr) && *(cPtr+1) && *(cPtr+2) && nPartNum) { cPtr = decodePartitionEntry(cPtr, &nMajor, &nMinor, &nBlocks, &nPartNum, szDevice); if (nPartNum) { cOldPtr = cPtr; memset(cFormat, ' ', 50); memset(cFormat+50, 0, 50); memcpy(cFormat, szDevice, strlen(szDevice)); // Device SNPRINTF(szFullDevice, "/dev/%s", szDevice); checkInodeForDevice(szFullDevice); if (nBlocks > 1) // a standard device { nRes = detectFileSystem(szFullDevice, szTemp); memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system qwSize = getPartitionSize(szFullDevice); formatSize(qwSize, szTemp); memcpy(cFormat+50, szTemp, strlen(szTemp)); // Size } else if (nBlocks == 1) // an extended partition { SNPRINTF(szTemp, "-extended-"); memcpy(cFormat+37, szTemp, strlen(szTemp)); // File system } szDeviceName = strdup(szFullDevice); // TOTO: never freed newtListboxAppendEntry(editPartition, cFormat, (void*)szDeviceName); showDebug(9, "inserted[2]: %s\n", cFormat); //debugWin("add[%s] and *cPtr=%d and 1=%d and 2=%d and 3=%d and 4=%d", cFormat, *(cPtr), *(cPtr+1), *(cPtr+2), *(cPtr+3), *(cPtr+4)); } } return cOldPtr; }
void ApplyBucketsWork::advance(std::string const& bucketName, BucketApplicator& applicator) { assert(applicator); assert(mTotalSize != 0); auto sz = applicator.advance(mCounters); mAppliedEntries += sz; mCounters.logDebug(bucketName, mLevel, mApp.getClock().now()); auto log = false; if (applicator) { mAppliedSize += (applicator.pos() - mLastPos); mLastPos = applicator.pos(); } else { mAppliedSize += (applicator.size() - mLastPos); mAppliedBuckets++; mLastPos = 0; log = true; mCounters.logInfo(bucketName, mLevel, mApp.getClock().now()); mCounters.reset(mApp.getClock().now()); } auto appliedSizeMb = mAppliedSize / 1024 / 1024; if (appliedSizeMb > mLastAppliedSizeMb) { log = true; mLastAppliedSizeMb = appliedSizeMb; } if (log) { CLOG(INFO, "Bucket") << "Bucket-apply: " << mAppliedEntries << " entries in " << formatSize(mAppliedSize) << "/" << formatSize(mTotalSize) << " in " << mAppliedBuckets << "/" << mTotalBuckets << " files (" << (100 * mAppliedSize / mTotalSize) << "%)"; } }
void ApplyBucketsWork::advance(BucketApplicator& applicator) { if (!applicator) { return; } assert(mTotalSize != 0); mAppliedEntries += applicator.advance(); auto log = false; if (applicator) { mAppliedSize += (applicator.pos() - mLastPos); mLastPos = applicator.pos(); } else { mAppliedSize += (applicator.size() - mLastPos); mAppliedBuckets++; mLastPos = 0; log = true; } auto appliedSizeMb = mAppliedSize / 1024 / 1024; if (appliedSizeMb > mLastAppliedSizeMb) { log = true; mLastAppliedSizeMb = appliedSizeMb; } if (log) { CLOG(INFO, "Bucket") << "Bucket-apply: " << mAppliedEntries << " entries in " << formatSize(mAppliedSize) << "/" << formatSize(mTotalSize) << " in " << mAppliedBuckets << "/" << mTotalBuckets << " files (" << (100 * mAppliedSize / mTotalSize) << "%)"; } }
// ======================================================= void CSavingWindow::showImageFileInfo(char *szImageFile, QWORD qwFreeSpace, QWORD qwImageSize, char *szFullyBatchMode) { BEGIN; char szTemp[2048]; char szTemp2[2048]; SNPRINTF(szTemp, i18n("Current image file:..........%s"), szImageFile); newtLabelSetText(m_labelImageFile, szTemp); if (qwImageSize) { SNPRINTF(szTemp, i18n("Image file size:.............%s"), formatSize(qwImageSize, szTemp2)); newtLabelSetText(m_labelImageFileSize, szTemp); } SNPRINTF (szTemp, i18n("Available space for image:...%s = %llu bytes"), formatSize(qwFreeSpace, szTemp2), qwFreeSpace); newtLabelSetText(m_labelFreeSpace, szTemp); RETURN; }
void TrayToolTip::redraw() { QPixmap pixmap(WIDTH, HEIGHT); QPainter painter(&pixmap); int downt = QueueMgr::instance()->totalDown(); int upt = QueueMgr::instance()->totalUp(); pixmap.fill(Qt::white); QString text = QString("%1 down | %2 up").arg(formatSize(downt,true)).arg(formatSize(upt,true)); painter.setPen(Qt::black); painter.drawText(0, 0, WIDTH, OFFSET, Qt::AlignTop|Qt::AlignHCenter, text, 0); painter.setPen(Qt::gray); painter.setFont( QFont(QString(), 25) ); painter.drawText(0, 0, WIDTH, HEIGHT, Qt::AlignCenter, "FatRat", 0); drawGraph(&painter); setPixmap(pixmap); }
void RecordingSelector::titleChanged(MythUIButtonListItem *item) { ProgramInfo *p; p = qVariantValue<ProgramInfo *>(item->GetData()); if (!p) return; if (m_titleText) m_titleText->SetText(p->GetTitle()); if (m_datetimeText) m_datetimeText->SetText(p->GetScheduledStartTime() .toString("dd MMM yy (hh:mm)")); if (m_descriptionText) { m_descriptionText->SetText( ((!p->GetSubtitle().isEmpty()) ? p->GetSubtitle() + "\n" : "") + p->GetDescription()); } if (m_filesizeText) { m_filesizeText->SetText(formatSize(p->GetFilesize() / 1024)); } if (m_cutlistImage) { if (p->HasCutlist()) m_cutlistImage->Show(); else m_cutlistImage->Hide(); } if (m_previewImage) { // try to locate a preview image if (QFile::exists(p->GetPathname() + ".png")) { m_previewImage->SetFilename(p->GetPathname() + ".png"); m_previewImage->Load(); } else { m_previewImage->SetFilename("blank.png"); m_previewImage->Load(); } } }
void ExportNative::titleChanged(MythUIButtonListItem *item) { ArchiveItem *a = item->GetData().value<ArchiveItem *>(); if (!a) return; m_titleText->SetText(a->title); m_datetimeText->SetText(a->startDate + " " + a->startTime); m_descriptionText->SetText( (a->subtitle != "" ? a->subtitle + "\n" : "") + a->description); m_filesizeText->SetText(formatSize(a->size / 1024, 2)); }
QVariant TransferList::data (const QModelIndex & index, int role) const { if (role != Qt::DisplayRole) return QVariant(); int r = index.row (); if (r < 0 || (size_t)r >= mOpIds.size()) { sf::Log (LogWarning) << LOGID << "Strange row " << r << std::endl; return QVariant (); } AsyncOpId id = mOpIds[r]; assert (mTransfers.count(id) > 0); const TransferInfo & t = mTransfers.find(id)->second; int c = index.column (); switch (c) { case 0: return QVariant (qtString (sf::toString (t.uri))); break; case 1: return QVariant (qtString (t.filename)); break; case 2: if (mOutgoing) return QVariant (qtString (t.receiver)); else return QVariant (qtString (t.source)); break; case 3: return QVariant (formatSize (t.size)); break; case 4: return QVariant (((float)t.transferred / (float)t.size)); // [0 .. 1] break; case 5:{ return QVariant (formatSpeed (t.speed)); break; } case 6:{ int seconds = (int) (t.size / t.speed); return QVariant (formatInterval (seconds)); break; } case 7: if (t.state == sf::TransferInfo::ERROR){ return QVariant ("Error: " + QString (toString (t.error))); } return QVariant (tr(toString (t.state))); break; } return QVariant (); }
void CopyProgressDialog::updateSpeed() { // speed is calculated by averaging speed in last 10 update ticks qint64 totalCopied = fileCopy->GetTotalBytesCopied(); bytesCopiedBetweenTicks[ticksPassed %= ticksMeasured] = totalCopied - oldTotalCopied; ticksPassed++; oldTotalCopied = totalCopied; qint64 t = 0; for(int i = 0; i < ticksMeasured; i++) t += bytesCopiedBetweenTicks[i]; int speed = t; ui.speed->setText(tr("Speed: ") + formatSize(speed) + "/s"); }
// ======================================================= void CXfsPart::printfInformations() { char szFullText[8192]; char szText[8192]; char szTemp1[1024]; getStdInfos(szText, sizeof(szText), true); SNPRINTF(szFullText, i18n("%s" // standard infos "Allocation Group count:.......%u\n" "Blocks per Allocation Group:..%u\n" "Allocation Group size:........%s\n"), szText, m_info.dwAgCount, m_info.dwAgBlocksCount, formatSize(m_info.dwAgBlocksCount*m_header.qwBlockSize,szTemp1)); g_interface->msgBoxOk(i18n("XFS informations"), szFullText); }
// ======================================================= void CHfsPart::printfInformations() { char szFullText[8192]; char szText[8192]; char szTemp1[1024]; getStdInfos(szText, sizeof(szText), true); SNPRINTF(szFullText, i18n("%s" // standard infos "Allocation Group count:.......%"PRIu64"\n" "Blocks per Allocation Group:..%u\n" "Allocation Group size:........%s\n" "First allocation block:.......%"PRIu64"\n"), szText, m_info.qwAllocCount, m_info.dwBlocksPerAlloc, formatSize(m_info.dwAllocSize,szTemp1), m_info.qwFirstAllocBlock); g_interface->msgBoxOk(i18n("HFS informations"), szFullText); }
/*========================================================================= statusLineSummary =========================================================================*/ QString KFileInfo::statusLineSummary (void) const { QString s; if (info.isDir()) { s = info.fileName() + ": " + QWidget::tr("modified") + " " + formatModified (info.lastModified()) + ", " + formatPermissions (info.permissions()); } else { s = info.fileName() + ": " + formatSize (info.size()) + ", " + QWidget::tr("modified") + " " + formatModified (info.lastModified()) + ", " + formatPermissions (info.permissions()); } if (info.isSymLink()) s += ", link"; return s; }
void RightClickLabel::mousePressEvent(QMouseEvent* event) { if(event->button() == Qt::RightButton) { QMenu menu; QAction* action; QLineEdit* lineEdit = new QLineEdit(&menu); QWidgetAction* wa = new QWidgetAction(&menu); int speed = (m_nSpeed) ? (m_nSpeed/1024) : 200; lineEdit->setText(QString::number(m_nSpeed/1024)); //lineEdit->setInputMask("00000"); wa->setDefaultWidget(lineEdit); connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(customSpeedEntered())); connect(lineEdit, SIGNAL(returnPressed()), &menu, SLOT(close())); menu.setSeparatorsCollapsible(false); action = menu.addSeparator(); action->setText(m_bUpload ? tr("Upload") : tr("Download")); menu.addAction(wa); menu.addSeparator(); action = menu.addAction(QString::fromUtf8("∞ kB/s")); action->setData(0); connect(action, SIGNAL(triggered()), this, SLOT(setLimit())); menu.addSeparator(); int step = speed/4; speed *= 2; for(int i=0;i<8 && speed;i++) { action = menu.addAction(formatSize(speed*1024, true)); action->setData(speed); connect(action, SIGNAL(triggered()), this, SLOT(setLimit())); speed -= step; } menu.exec(QCursor::pos()); } }
void ImportFile::titleChanged(MythUIButtonListItem *item) { ImportItem *i; i = item->GetData().value<ImportItem *>(); if (!i) return; if (m_titleText) m_titleText->SetText(i->title); if (m_datetimeText) m_datetimeText->SetText(MythDate::toString(i->startTime, MythDate::kDateTimeFull + MythDate::kAutoYear)); if (m_descriptionText) m_descriptionText->SetText(i->description); if (m_filesizeText) { if (i->size > 0) m_filesizeText->SetText(formatSize(i->size / 1024)); else m_filesizeText->SetText(tr("N/A")); } if (m_durationText) { if (i->actualDuration > 0) m_durationText->SetText(formatTime(i->actualDuration)); else m_durationText->SetText(tr("N/A")); } if (m_filenameText) m_filenameText->SetText(i->filename); }
QVariant TorrentPeersModel::data ( const QModelIndex &index, int role ) const { if ( index.row() >= ( int ) m_peers.size() ) return QVariant(); const libtorrent::peer_info& info = m_peers[index.row() ]; if ( role == Qt::DisplayRole ) { switch ( index.column() ) { case 0: { std::string ip = info.ip.address().to_string(); return QString ( ip.c_str() ); } case 1: { const char* country = 0; std::string ip = info.ip.address().to_string(); if ( g_pGeoIP != 0 ) country = GeoIP_country_name_by_addr_imp ( g_pGeoIP, ip.c_str() ); if ( country != 0 ) return QString ( country ); else return QString(); } case 2: return QString::fromUtf8 ( info.client.c_str() ); case 3: if(info.flags & libtorrent::peer_info::rc4_encrypted) return "RC4"; else if(info.flags & libtorrent::peer_info::plaintext_encrypted) return "Plain"; else return QVariant(); case 4: switch(info.source) { case libtorrent::peer_info::tracker: return "Tracker"; case libtorrent::peer_info::dht: return "DHT"; case libtorrent::peer_info::pex: return "PEX"; case libtorrent::peer_info::lsd: return "LSD"; case libtorrent::peer_info::resume_data: return "Resume"; case libtorrent::peer_info::incoming: return "Incoming"; default: { if(info.flags & libtorrent::peer_info::local_connection) return QVariant(); else return "Incoming"; } } case 5: return formatSize ( info.down_speed, true ); case 6: return formatSize ( info.up_speed, true ); case 7: return formatSize ( info.total_download ); case 8: return formatSize ( info.total_upload ); case 9: if ( info.flags & libtorrent::peer_info::connecting ) return tr ( "Connecting" ); else if ( info.flags & libtorrent::peer_info::handshake ) return tr ( "Handshaking" ); else if ( info.flags & libtorrent::peer_info::queued ) return tr ( "Queued" ); else { QString text; if ( info.flags & libtorrent::peer_info::interesting ) text += "Interesting "; if ( info.flags & libtorrent::peer_info::choked ) text += "Choked "; if ( info.flags & libtorrent::peer_info::remote_interested ) text += "Remote_interested "; if ( info.flags & libtorrent::peer_info::remote_choked ) text += "Remote_choked "; if ( info.connection_type == libtorrent::peer_info::web_seed ) text += "WEB_SEED"; return text; } case 10: { int pcs = 0; for ( ssize_t i=0;i<info.pieces.size();i++ ) if ( info.pieces[i] ) pcs++; QString pct = QString ( "%1%" ).arg ( ( int ) ( 100.0/double ( info.pieces.size() ) *pcs ) ); if(info.flags & libtorrent::peer_info::seed) pct += " S"; return pct; } } } else if ( role == Qt::DecorationRole ) { if ( index.column() == 1 && g_pGeoIP != 0 ) { std::string ip = info.ip.address().to_string(); const char* country = GeoIP_country_code_by_addr_imp ( g_pGeoIP, ip.c_str() ); if ( country != 0 ) { char ct[3] = { (char) tolower ( country[0] ), (char) tolower ( country[1] ), 0 }; if ( !g_mapFlags.contains ( ct ) ) { char flag[] = ":/flags/xx.gif"; flag[8] = ct[0]; flag[9] = ct[1]; g_mapFlags[ct] = QIcon ( flag ); } return g_mapFlags[ct]; } } } return QVariant(); }
// ======================================================= void CXfsPart::readSuperBlock() { BEGIN; xfs_superblock sb; int nRes; char szTemp1[4096], szTemp2[4096], szTemp3[4096]; QWORD qwFreeSpace, qwUsedSpace; // init memset(&m_info, 0, sizeof(CInfoXfsHeader)); // 0. go to the beginning of the super block nRes = fseek(m_fDeviceFile, 0, SEEK_SET); if (nRes == -1) THROW(ERR_ERRNO, errno); // 1. read and print important informations nRes = fread(&sb, sizeof(xfs_superblock), 1, m_fDeviceFile); if (nRes != 1) { g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_READING, (DWORD)0, errno); } // 2. check it's an XFS file system if (BeToCpu(sb.sb_magicnum) != XFS_SUPER_MAGIC) { g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_READING, (DWORD)0, errno); } // ---- blocks m_header.qwBlockSize = (QWORD)BeToCpu(sb.sb_blocksize); showDebug(3, "SUPER: sb_blocksize=m_header.qwBlockSize=%llu\n", m_header.qwBlockSize); // check for block size if (m_header.qwBlockSize != ((QWORD)4096)) { showDebug(1, "Only 4096 bytes per block volumes are supported. Current one is %lu bytes/block", (DWORD)m_header.qwBlockSize); //g_interface -> msgBoxError(szTemp); THROW(ERR_BLOCKSIZE, "XFS", (DWORD)m_header.qwBlockSize); } m_header.qwBlocksCount = (QWORD)BeToCpu(sb.sb_dblocks); showDebug(3, "SUPER: sb_dblocks=m_header.qwBlocksCount=%llu\n", m_header.qwBlocksCount); m_header.qwUsedBlocks = m_header.qwBlocksCount - (QWORD)BeToCpu(sb.sb_fdblocks); //swapNb((QWORD)sb.sb_fdblocks); showDebug(3, "SUPER: m_header.qwUsedBlocks=%llu\n", m_header.qwUsedBlocks); m_info.dwAgCount = (DWORD)BeToCpu(sb.sb_agcount); showDebug(3, "SUPER: sb_agcount=m_info.dwAgCount=%lu\n", m_info.dwAgCount); m_info.dwAgBlocksCount = (DWORD)BeToCpu(sb.sb_agblocks); showDebug(3, "SUPER: m_info.dwAgBlocksCount=%lu\n", m_info.dwAgBlocksCount); showDebug(3, "SUPER: Allocation group size: %lu blocks = %s\n", m_info.dwAgBlocksCount, formatSize(m_info.dwAgBlocksCount*m_header.qwBlockSize,szTemp1)); // ---- space informations qwFreeSpace = (m_header.qwBlocksCount - m_header.qwUsedBlocks) * m_header.qwBlockSize; qwUsedSpace = m_header.qwUsedBlocks * m_header.qwBlockSize; showDebug(3, "SUPER: total: %s\nused: %s\nfree: %s\n", formatSize(m_header.qwBlockSize * m_header.qwBlocksCount, szTemp1), formatSize(qwUsedSpace, szTemp2), formatSize(qwFreeSpace, szTemp3)); showDebug(3, "SUPER: sb_rbmblocks=%lu\n",(DWORD)BeToCpu(sb.sb_rbmblocks)); // ---- calculate infos //m_header.qwBlockSize = (QWORD)m_info.dwBlockSize; //m_header.qwUsedBlocks = m_info.qwBlocksCount - m_info.qwFreeBlocksCount; //swapNb((QWORD)sb.sb_fdblocks); //m_header.qwBlocksCount = m_info.qwBlocksCount; m_header.qwBitmapSize = (m_header.qwBlocksCount+7)/8; //sb.s_bmap_nr * m_header.qwBlockSize; memset(m_header.szLabel, 0, 64); setSuperBlockInfos(true, true, qwUsedSpace, qwFreeSpace); RETURN; }
void SelectDestination::setDestination(MythUIButtonListItem* item) { if (!item) return; int itemNo = item->GetData().value<ARCHIVEDESTINATION>(); if (itemNo < 0 || itemNo > ArchiveDestinationsCount - 1) itemNo = 0; m_destinationText->SetText(tr(ArchiveDestinations[itemNo].description)); m_archiveDestination = ArchiveDestinations[itemNo]; switch(itemNo) { case AD_DVD_SL: case AD_DVD_DL: m_filenameEdit->Hide(); m_findButton->Hide(); m_eraseDvdRwCheck->Hide(); m_eraseDvdRwText->Hide(); m_doBurnCheck->Show(); m_doBurnText->Show(); break; case AD_DVD_RW: m_filenameEdit->Hide(); m_findButton->Hide(); m_eraseDvdRwCheck->Show(); m_eraseDvdRwText->Show(); m_doBurnCheck->Show(); m_doBurnText->Show(); break; case AD_FILE: long long dummy; ArchiveDestinations[itemNo].freeSpace = getDiskSpace(m_filenameEdit->GetText(), dummy, dummy); m_filenameEdit->Show(); m_findButton->Show(); m_eraseDvdRwCheck->Hide(); m_eraseDvdRwText->Hide(); m_doBurnCheck->Hide(); m_doBurnText->Hide(); break; } // update free space if (ArchiveDestinations[itemNo].freeSpace != -1) { m_freespaceText->SetText(formatSize(ArchiveDestinations[itemNo].freeSpace, 2)); m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024; } else { m_freespaceText->SetText(tr("Unknown")); m_freeSpace = 0; } BuildFocusList(); }
void wFileProps::createGUI() { QString mimeType = getMimeType( fileName ); QFontDatabase fdb = QFontDatabase(); fdb.addApplicationFont( ":/fonts/ArchitectsDaughter.ttf" ); setStyleSheet( "font-family: Architects Daughter; font-size: 10;" ); iconLbl = new QLabel(); iconLbl->setPixmap( getPixmap( fileName ).scaled( 64, 64, Qt::KeepAspectRatio ) ); nameLbl = new QLabel(); nameLbl->setText( "<b>" + QFileInfo( fileName ).fileName() + "</b>" ); nameLbl->setFont( QFont( "Architects Daughter", 15 ) ); linesLbl = new QLabel( lines ); wordsLbl = new QLabel( words ); charsLbl= new QLabel( chars ); if ( !noFileProps ) { typeLbl = new QLabel( mimeType ); sizeLbl = new QLabel( formatSize( getSize( fileName ) ) ); locLbl = new QLabel( QFileInfo( fileName ).absolutePath() ); time1Lbl = new QLabel( QFileInfo( fileName ).created().toString( "ddd MMM dd, yyyy hh:mm:ss" ) ); time2Lbl = new QLabel( QFileInfo( fileName ).lastRead().toString( "ddd MMM dd, yyyy hh:mm:ss" ) ); time3Lbl = new QLabel( QFileInfo( fileName ).lastModified().toString( "ddd MMM dd, yyyy hh:mm:ss" ) ); } QPushButton *closeBtn = new QPushButton(); closeBtn->setText( "&Close" ); connect( closeBtn, SIGNAL( clicked() ), this, SLOT( close() ) ); QVBoxLayout *baseLyt = new QVBoxLayout(); QHBoxLayout *nameLyt = new QHBoxLayout(); QFormLayout *textInfoLyt = new QFormLayout(); QFormLayout *fileInfoLyt = new QFormLayout(); QHBoxLayout *btnLyt = new QHBoxLayout(); nameLyt->setAlignment( Qt::AlignCenter ); nameLyt->addWidget( iconLbl ); nameLyt->addWidget( nameLbl ); textInfoLyt->addRow( new QLabel( "<b>Lines: </b>" ), linesLbl ); textInfoLyt->addRow( new QLabel( "<b>Words: </b>" ), wordsLbl ); textInfoLyt->addRow( new QLabel( "<b>Chars: </b>" ), charsLbl ); textInfoLyt->setFormAlignment( Qt::AlignHCenter | Qt::AlignTop ); if ( !noFileProps ) { fileInfoLyt->addRow( new QLabel( "<b>Type: </b>" ), typeLbl ); fileInfoLyt->addRow( new QLabel( "<b>Size: </b>" ), sizeLbl ); fileInfoLyt->addRow( new QLabel( "<b>Location: </b>" ), locLbl ); fileInfoLyt->addRow( new QLabel( "<b>Created: </b>" ), time1Lbl ); fileInfoLyt->addRow( new QLabel( "<b>Accessed: </b>" ), time2Lbl ); fileInfoLyt->addRow( new QLabel( "<b>Modified: </b>" ), time3Lbl ); } btnLyt->addStretch( 0 ); btnLyt->addWidget( closeBtn ); btnLyt->addStretch( 0 ); QFrame *textFrame = new QFrame(); textFrame->setFrameStyle( QFrame::StyledPanel | QFrame::Plain ); textFrame->setLayout( textInfoLyt ); QFrame *fileFrame = new QFrame(); fileFrame->setFrameStyle( QFrame::StyledPanel | QFrame::Plain ); fileFrame->setLayout( fileInfoLyt ); baseLyt->addLayout( nameLyt ); baseLyt->addStretch( 0 ); baseLyt->addWidget( textFrame ); if ( !noFileProps ) { baseLyt->addStretch( 0 ); baseLyt->addWidget( fileFrame ); } baseLyt->addStretch( 0 ); baseLyt->addLayout( btnLyt ); setLayout( baseLyt ); };
bool MythNews::getHttpFile(const QString &sFilename, const QString &cmdURL) { #if QT_VERSION < 0x050000 QMutexLocker locker(&m_lock); int redirectCount = 0; QByteArray data(0); bool res = false; m_httpGrabber = NULL; QString hostname; QString fileUrl = cmdURL; createProgress(tr("Downloading media...")); while (1) { QUrl qurl(fileUrl); if (hostname.isEmpty()) hostname = qurl.host(); // hold onto original host if (qurl.host().isEmpty()) // can occur on redirects to partial paths qurl.setHost(hostname); if (m_httpGrabber != NULL) delete m_httpGrabber; m_httpGrabber = new HttpComms; m_abortHttp = false; m_httpGrabber->request(qurl, -1, true); while ((!m_httpGrabber->isDone()) && (!m_abortHttp)) { int progress = m_httpGrabber->getProgress(); int total = m_httpGrabber->getTotal(); if ((progress > 0) && (total > 5120) && (progress < total)) // Ignore total less than 5kb as we're probably looking at a redirect page or similar { m_progressPopup->SetTotal(total); m_progressPopup->SetProgress(progress); float fProgress = (float)progress/total; QString text = tr("%1 of %2 (%3 percent)") .arg(formatSize(progress, 2)) .arg(formatSize(total, 2)) .arg(floor(fProgress*100)); if (m_updatedText) m_updatedText->SetText(text); } qApp->processEvents(); usleep(100000); } if (m_abortHttp) break; // Check for redirection if (!m_httpGrabber->getRedirectedURL().isEmpty()) { if (redirectCount++ < 3) fileUrl = m_httpGrabber->getRedirectedURL(); // Try again continue; } if (m_httpGrabber->getStatusCode() > 400) { // Error, request failed break; } data = m_httpGrabber->getRawData(); if (data.size() > 0) { QFile file(sFilename); if (file.open(QIODevice::WriteOnly)) { file.write(data); file.close(); res = true; } } break; } if (m_progressPopup) { m_progressPopup->Close(); m_progressPopup = NULL; } delete m_httpGrabber; m_httpGrabber = NULL; return res; #else #warning MythNews::getHttpFile() has not yet been ported to Qt5 (void) sFilename; (void) cmdURL; return false; #endif }
void benchmark(autoserial::ISerializable *object, int runs) { autoserial::OpaqueObject o; o.set(object); Size size = o.getSize(); std::cout << "Benching " << object->getTypeNameV() << " of " << formatSize(size) << std::endl; { // With alloaction + deallocation (closer to what happens in reality) double st = Timer::get(); for (int i=0; i < runs; ++i) { autoserial::OpaqueObject obj; obj.set(object); } double t = Timer::get()-st; std::cout << "Serialization in " << t/runs << " ms" << std::endl; std::cout << " Serialization including (de)allocation: " << formatRate(t, size, runs) << std::endl; } { // With alloaction + deallocation (closer to what happens in reality) double st = Timer::get(); for (int i=0; i < runs; ++i) { FLUSH(); autoserial::OpaqueObject obj; obj.set(object); } double t = Timer::get()-st - flushTime*runs; std::cout << "Serialization in " << t/runs << " ms" << std::endl; std::cout << " Serialization including (de)allocation: " << formatRate(t, size, runs) << std::endl; } { // Deserialization+deallocation double st = Timer::get(); for (int i=0; i < runs; ++i) { autoserial::ISerializable *obj = o.get(); delete obj; } double t = Timer::get()-st; std::cout << "DESerialization in " << t/runs << " ms" << std::endl; std::cout << " Deserialization including (de)allocation: " << formatRate(t, size, runs) << std::endl; } { // Deserialization+deallocation double st = Timer::get(); for (int i=0; i < runs; ++i) { FLUSH(); autoserial::ISerializable *obj = o.get(); delete obj; } double t = Timer::get()-st - flushTime*runs; std::cout << "DESerialization in " << t/runs << " ms" << std::endl; std::cout << " Deserialization including (de)allocation: " << formatRate(t, size, runs) << std::endl; } { // Comparison autoserial::ISerializable *obj = o.get(); int count = 0; double st = Timer::get(); for (int i=0; i < runs; ++i) { FLUSH(); if (!obj->equals(object)) count++; } double t = Timer::get()-st - flushTime*runs; std::cout << " " << count << " Comparison time: " << formatRate(t, size, runs) << std::endl; } }
static QString createDetailsForObject(GUPnPDIDLLiteObject *object) { QString result; if (GUPNP_IS_DIDL_LITE_CONTAINER(object)) { return result; } GList* resources = gupnp_didl_lite_object_get_resources(object); GList* it = resources; const char *author = gupnp_didl_lite_object_get_artist(object); const char *album = gupnp_didl_lite_object_get_album(object); if (author != 0) { result += QString::fromLatin1("%1").arg(QString::fromUtf8(author)); } if (album != 0) { if (not result.isEmpty()) { result += QLatin1String(" | "); } result += QString::fromLatin1("%1").arg(QString::fromUtf8(album)); } const QLatin1String empty = QLatin1String(" "); while (it) { GUPnPDIDLLiteResource *res = (GUPnPDIDLLiteResource*) it->data; GUPnPProtocolInfo *info = gupnp_didl_lite_resource_get_protocol_info(res); // use first non-transcoded uri; might be problematic if (gupnp_protocol_info_get_dlna_conversion (info) == GUPNP_DLNA_CONVERSION_NONE) { long duration = gupnp_didl_lite_resource_get_duration(res); if (duration > 0) { if (not result.isEmpty()) { result += empty; } result += formatTime(duration); } int width = gupnp_didl_lite_resource_get_width(res); int height = gupnp_didl_lite_resource_get_height(res); if (width > 0 && height > 0) { if (not result.isEmpty()) { result += empty; } result += QString::fromLatin1("%1x%2").arg(QString::number(width), QString::number(height)); } gint64 size = gupnp_didl_lite_resource_get_size64(res); if (size > 0) { if (not result.isEmpty()) { result += empty; } result += formatSize(size); } break; } it = it->next; } g_list_free_full(resources, g_object_unref); return result; }
void MythNews::updateInfoView(MythUIButtonListItem *selected) { QMutexLocker locker(&m_lock); if (!selected) return; NewsSite *site = NULL; NewsArticle article; if (GetFocusWidget() == m_articlesList) { article = m_articles[selected]; if (m_sitesList->GetItemCurrent()) site = qVariantValue<NewsSite*> (m_sitesList->GetItemCurrent()->GetData()); } else { site = qVariantValue<NewsSite*>(selected->GetData()); if (m_articlesList->GetItemCurrent()) article = m_articles[m_articlesList->GetItemCurrent()]; } if (GetFocusWidget() == m_articlesList) { if (!article.title().isEmpty()) { if (m_titleText) m_titleText->SetText(article.title()); if (m_descText) { QString artText = article.description(); // replace a few HTML characters artText.replace("
", ""); // LSEP artText.replace("
", ""); // PSEP artText.replace("£", "£"); // POUND artText.replace("­", ""); // ? artText.replace("–", "-"); // EN-DASH artText.replace("“", """"); // LEFT-DOUBLE-QUOTE artText.replace("”", """"); // RIGHT-DOUBLE-QUOTE artText.replace("‘", "'"); // LEFT-SINGLE-QUOTE artText.replace("’", "'"); // RIGHT-SINGLE-QUOTE // Replace paragraph and break HTML with newlines if( artText.indexOf(QRegExp("</(p|P)>")) ) { artText.replace( QRegExp("<(p|P)>"), ""); artText.replace( QRegExp("</(p|P)>"), "\n\n"); } else { artText.replace( QRegExp("<(p|P)>"), "\n\n"); artText.replace( QRegExp("</(p|P)>"), ""); } artText.replace( QRegExp("<(br|BR|)/>"), "\n"); artText.replace( QRegExp("<(br|BR|)>"), "\n"); // These are done instead of simplifyWhitespace // because that function also strips out newlines // Replace tab characters with nothing artText.replace( QRegExp("\t"), ""); // Replace double space with single artText.replace( QRegExp(" "), ""); // Replace whitespace at beginning of lines with newline artText.replace( QRegExp("\n "), "\n"); // Remove any remaining HTML tags QRegExp removeHTML(QRegExp("</?.+>")); removeHTML.setMinimal(true); artText.remove((const QRegExp&) removeHTML); artText = artText.trimmed(); m_descText->SetText(artText); } if (!article.thumbnail().isEmpty()) { QString fileprefix = GetConfDir(); QDir dir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); fileprefix += "/MythNews/tcache"; dir = QDir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); QString url = article.thumbnail(); QString sFilename = QString("%1/%2") .arg(fileprefix) .arg(qChecksum(url.toLocal8Bit().constData(), url.toLocal8Bit().size())); #if QT_VERSION < 0x050000 bool exists = QFile::exists(sFilename); if (!exists) HttpComms::getHttpFile(sFilename, url, 20000, 1, 2); #else #warning MythNews::updateInfoView() has not yet been ported to Qt5 #endif if (m_thumbnailImage) { m_thumbnailImage->SetFilename(sFilename); m_thumbnailImage->Load(); if (!m_thumbnailImage->IsVisible()) m_thumbnailImage->Show(); } } else { if (m_thumbnailImage) m_thumbnailImage->Hide(); if (site && !site->imageURL().isEmpty()) { QString fileprefix = GetConfDir(); QDir dir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); fileprefix += "/MythNews/scache"; dir = QDir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); QString url = site->imageURL(); QString extension = url.section('.', -1); QString sitename = site->name(); QString sFilename = QString("%1/%2.%3").arg(fileprefix) .arg(sitename) .arg(extension); #if QT_VERSION < 0x050000 bool exists = QFile::exists(sFilename); if (!exists) HttpComms::getHttpFile(sFilename, url, 20000, 1, 2); #else #warning MythNews::updateInfoView() has not yet been ported to Qt5 #endif if (m_thumbnailImage) { m_thumbnailImage->SetFilename(sFilename); m_thumbnailImage->Load(); if (!m_thumbnailImage->IsVisible()) m_thumbnailImage->Show(); } } } if (m_downloadImage) { if (!article.enclosure().isEmpty()) { if (!m_downloadImage->IsVisible()) m_downloadImage->Show(); } else m_downloadImage->Hide(); } if (m_enclosureImage) { if (!article.enclosure().isEmpty()) { if (!m_enclosureImage->IsVisible()) m_enclosureImage->Show(); } else m_enclosureImage->Hide(); } if (m_podcastImage) m_podcastImage->Hide(); } } else { if (m_downloadImage) m_downloadImage->Hide(); if (m_enclosureImage) m_enclosureImage->Hide(); if (m_podcastImage) m_podcastImage->Hide(); if (site) { if (m_titleText) m_titleText->SetText(site->name()); if (m_descText) m_descText->SetText(site->description()); if (m_thumbnailImage && m_thumbnailImage->IsVisible()) m_thumbnailImage->Hide(); if (m_podcastImage && site->podcast() == 1) m_podcastImage->Show(); if (!site->imageURL().isEmpty()) { QString fileprefix = GetConfDir(); QDir dir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); fileprefix += "/MythNews/scache"; dir = QDir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); QString url = site->imageURL(); QString extension = url.section('.', -1); QString sitename = site->name(); QString sFilename = QString("%1/%2.%3").arg(fileprefix) .arg(sitename) .arg(extension); #if QT_VERSION < 0x050000 bool exists = QFile::exists(sFilename); if (!exists) HttpComms::getHttpFile(sFilename, url, 20000, 1, 2); #else #warning MythNews::updateInfoView() has not yet been ported to Qt5 #endif if (m_thumbnailImage) { m_thumbnailImage->SetFilename(sFilename); m_thumbnailImage->Load(); if (!m_thumbnailImage->IsVisible()) m_thumbnailImage->Show(); } } } } if (m_updatedText) { if (site) { QString text(tr("Updated") + " - "); QDateTime updated(site->lastUpdated()); if (updated.toTime_t() != 0) { text += MythDate::toString(site->lastUpdated(), MythDate::kDateTimeFull | MythDate::kSimplify); } else text += tr("Unknown"); m_updatedText->SetText(text); } #if QT_VERSION < 0x050000 if (m_httpGrabber != NULL) { int progress = m_httpGrabber->getProgress(); int total = m_httpGrabber->getTotal(); if ((progress > 0) && (total > 0) && (progress < total)) { float fProgress = (float)progress/total; QString text = tr("%1 of %2 (%3 percent)") .arg(formatSize(progress, 2)) .arg(formatSize(total, 2)) .arg(floor(fProgress*100)); m_updatedText->SetText(text); } } #else #warning MythNews::updateInfoView() has not yet been ported to Qt5 #endif } }