Revision 1777 trunk/client/gui_qt/DownloadQueueModel.cpp
| DownloadQueueModel.cpp (revision 1777) | ||
|---|---|---|
| 155 | 155 |
for (int i = 0; i < collections.count(); i++) {
|
| 156 | 156 |
QNNTPGrabGlue::Collection collection = collections[i]; |
| 157 | 157 |
|
| 158 |
DownloadQueueItem *collection_item = new DownloadQueueItem(); |
|
| 158 |
DownloadQueueItem *collection_item = new DownloadQueueItem(rootItem); |
|
| 159 | 159 |
|
| 160 | 160 |
for (int j = 0; j < collection.files.count(); j++) {
|
| 161 | 161 |
QNNTPGrabGlue::File file = collection.files[j]; |
| ... | ... | |
| 165 | 165 |
file_item->subject = file.subject; |
| 166 | 166 |
file_item->poster = file.poster; |
| 167 | 167 |
file_item->size = file.file_size; |
| 168 |
file_item->sizeStr = QNNTPGrabGlue::utilsCalculateFileSize(file.file_size); |
|
| 168 | 169 |
file_item->sizeRemaining = file.file_size_remaining; |
| 170 |
file_item->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(file.file_size_remaining); |
|
| 169 | 171 |
file_item->stamp = file.stamp; |
| 170 |
file_item->state = file.status; |
|
| 171 | 172 |
file_item->realFilename = file.filename; |
| 172 | 173 |
|
| 173 | 174 |
for (int k = 0; k < file.groups.count(); k++) {
|
| ... | ... | |
| 226 | 227 |
collection_item->subject = collection.collection_name; |
| 227 | 228 |
collection_item->poster = collection.poster; |
| 228 | 229 |
collection_item->size = collection.total_size; |
| 230 |
collection_item->sizeStr = QNNTPGrabGlue::utilsCalculateFileSize(collection.total_size); |
|
| 229 | 231 |
collection_item->sizeRemaining = collection.total_size_remaining; |
| 232 |
collection_item->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(collection.total_size_remaining); |
|
| 230 | 233 |
|
| 231 |
|
|
| 232 | 234 |
rootItem->appendChild(collection_item); |
| 233 | 235 |
} |
| 234 | 236 |
} |
| ... | ... | |
| 248 | 250 |
return qMin(100, ret); |
| 249 | 251 |
} |
| 250 | 252 |
|
| 253 |
DownloadQueueItem *DownloadQueueModel::lookupCollectionItem(QString collection_name) |
|
| 254 |
{
|
|
| 255 |
if (!rootItem) {
|
|
| 256 |
return NULL; |
|
| 257 |
} |
|
| 258 |
|
|
| 259 |
return rootItem->lookupSubject(collection_name); |
|
| 260 |
} |
|
| 261 |
|
|
| 262 |
DownloadQueueItem *DownloadQueueModel::lookupSubjectItem(DownloadQueueItem *collection_item, QString subject) |
|
| 263 |
{
|
|
| 264 |
if (!collection_item) {
|
|
| 265 |
return NULL; |
|
| 266 |
} |
|
| 267 |
|
|
| 268 |
return collection_item->lookupSubject(subject); |
|
| 269 |
} |
|
| 270 |
|
|
| 251 | 271 |
void DownloadQueueModel::onFileDownloadStateUpdate(QString collection_name, QString subject, int num_parts_total, int num_parts_done, |
| 252 | 272 |
int num_parts_failed, quint64 file_size, quint64 file_size_remaining, |
| 253 | 273 |
quint64 total_size, quint64 total_size_remaining) |
| ... | ... | |
| 255 | 275 |
Q_UNUSED(num_parts_total); |
| 256 | 276 |
Q_UNUSED(num_parts_done); |
| 257 | 277 |
Q_UNUSED(num_parts_failed); |
| 258 |
#if 0 |
|
| 259 |
QTreeWidgetItem *collection_node; |
|
| 260 |
QTreeWidgetItem *subject_node; |
|
| 261 | 278 |
|
| 262 |
collection_node = getTreeWidgetByCollection(collection_name); |
|
| 263 |
subject_node = getTreeWidgetBySubject(collection_node, subject); |
|
| 279 |
DownloadQueueItem *collection_node; |
|
| 280 |
DownloadQueueItem *subject_node; |
|
| 281 |
|
|
| 282 |
collection_node = lookupCollectionItem(collection_name); |
|
| 283 |
subject_node = lookupSubjectItem(collection_node, subject); |
|
| 264 | 284 |
if (subject_node == NULL) {
|
| 265 | 285 |
qWarning("onFileDownloadStateUpdate: Subject '%s' from collection '%s' could not found", collection_name.toUtf8().data(), subject.toUtf8().data());
|
| 266 | 286 |
return; |
| 267 | 287 |
} |
| 268 | 288 |
|
| 269 |
collection_node->setText(FIELD_PROGRESS, QString("%1").arg(calculateProgress(total_size, total_size_remaining)));
|
|
| 270 |
collection_node->setText(FIELD_STATE_STR, collection_node->text(FIELD_STATE_STR)); /* Force redraw */ |
|
| 271 |
collection_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole, QVariant(total_size_remaining)); |
|
| 272 |
collection_node->setText(FIELD_FILE_SIZE_REMAINING_STR, glue->utilsCalculateFileSize(total_size_remaining)); |
|
| 289 |
/* Don't continue processing this event when the file just got skipped */ |
|
| 290 |
if (subject_node->stateStr == tr("Skipped")) {
|
|
| 291 |
return; |
|
| 292 |
} |
|
| 273 | 293 |
|
| 274 |
subject_node->setText(FIELD_PROGRESS, QString("%1").arg(calculateProgress(file_size, file_size_remaining)));
|
|
| 275 |
subject_node->setText(FIELD_STATE_STR, subject_node->text(FIELD_STATE_STR)); /* Force redraw */ |
|
| 276 |
subject_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole, QVariant(file_size_remaining)); |
|
| 277 |
subject_node->setText(FIELD_FILE_SIZE_REMAINING_STR, glue->utilsCalculateFileSize(file_size_remaining)); |
|
| 278 |
#endif |
|
| 294 |
QModelIndex idx; |
|
| 295 |
|
|
| 296 |
collection_node->progress = calculateProgress(total_size, total_size_remaining); |
|
| 297 |
collection_node->sizeRemaining = total_size_remaining; |
|
| 298 |
collection_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size_remaining); |
|
| 299 |
|
|
| 300 |
idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_STATE_STR, collection_node); |
|
| 301 |
emit dataChanged(idx, idx); |
|
| 302 |
|
|
| 303 |
idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_REMAINING_STR, collection_node); |
|
| 304 |
emit dataChanged(idx, idx); |
|
| 305 |
|
|
| 306 |
subject_node->progress = calculateProgress(file_size, file_size_remaining); |
|
| 307 |
subject_node->sizeRemaining = file_size_remaining; |
|
| 308 |
subject_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(file_size_remaining); |
|
| 309 |
|
|
| 310 |
idx = createIndex(subject_node->row(), (int) DownloadQueueItem::FIELD_STATE_STR, subject_node); |
|
| 311 |
emit dataChanged(idx, idx); |
|
| 312 |
|
|
| 313 |
idx = createIndex(subject_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_REMAINING_STR, subject_node); |
|
| 314 |
emit dataChanged(idx, idx); |
|
| 279 | 315 |
} |
| 280 | 316 |
|
| 281 | 317 |
void DownloadQueueModel::onFileStateChanged(QString collection_name, QString subject, QString real_filename, QNNTPGrabGlue::TaskState old_state, QNNTPGrabGlue::TaskState new_state) |
| 282 | 318 |
{
|
| 283 | 319 |
Q_UNUSED(old_state); |
| 284 | 320 |
|
| 285 |
#if 0 |
|
| 286 |
QTreeWidgetItem *collection_node; |
|
| 287 |
QTreeWidgetItem *subject_node; |
|
| 321 |
DownloadQueueItem *collection_node; |
|
| 322 |
DownloadQueueItem *subject_node; |
|
| 288 | 323 |
|
| 289 |
collection_node = getTreeWidgetByCollection(collection_name); |
|
| 290 |
subject_node = getTreeWidgetBySubject(collection_node, subject); |
|
| 324 |
collection_node = lookupCollectionItem(collection_name); |
|
| 325 |
subject_node = lookupSubjectItem(collection_node, subject); |
|
| 291 | 326 |
|
| 292 | 327 |
if (!subject_node) {
|
| 293 | 328 |
qWarning("onFileStateChanged: Subject '%s' from collection '%s' could not be found", subject.toUtf8().data(), collection_name.toUtf8().data());
|
| ... | ... | |
| 299 | 334 |
QString size_remaining; |
| 300 | 335 |
quint64 total_size; |
| 301 | 336 |
quint64 total_size_remaining; |
| 302 |
int progress; |
|
| 337 |
QModelIndex idx; |
|
| 303 | 338 |
|
| 304 | 339 |
switch(new_state) {
|
| 305 | 340 |
case QNNTPGrabGlue::TASK_STATE_WAITING_FOR_DOWNLOAD: |
| 306 | 341 |
/* The task was restarted */ |
| 307 | 342 |
|
| 308 | 343 |
/* Update the row itself */ |
| 309 |
file_size = subject_node->data(FIELD_FILE_SIZE, Qt::DisplayRole).toLongLong(); |
|
| 310 |
file_size_remaining = subject_node->data(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole).toLongLong(); |
|
| 344 |
file_size = subject_node->size; |
|
| 345 |
file_size_remaining = subject_node->sizeRemaining; |
|
| 311 | 346 |
|
| 312 |
size_remaining = glue->utilsCalculateFileSize(file_size); |
|
| 347 |
subject_node->progress = 0; |
|
| 348 |
subject_node->stateStr = ""; |
|
| 349 |
subject_node->sizeRemaining = file_size; |
|
| 350 |
subject_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(file_size); |
|
| 313 | 351 |
|
| 314 |
subject_node->setText(FIELD_PROGRESS, "0"); |
|
| 315 |
subject_node->setText(FIELD_STATE_STR, ""); |
|
| 316 |
subject_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole, QVariant(file_size)); |
|
| 317 |
subject_node->setText(FIELD_FILE_SIZE_REMAINING_STR, size_remaining); |
|
| 318 |
|
|
| 319 | 352 |
/* Update the parent */ |
| 320 |
total_size = collection_node->data(FIELD_FILE_SIZE, Qt::DisplayRole).toLongLong(); |
|
| 321 |
total_size_remaining = collection_node->data(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole).toLongLong(); |
|
| 353 |
total_size = collection_node->size; |
|
| 354 |
total_size_remaining = collection_node->sizeRemaining; |
|
| 322 | 355 |
|
| 323 | 356 |
total_size_remaining += file_size - file_size_remaining; |
| 324 | 357 |
|
| 325 |
progress = calculateProgress(total_size, total_size_remaining); |
|
| 326 |
size_remaining = glue->utilsCalculateFileSize(total_size_remaining); |
|
| 358 |
collection_node->progress = calculateProgress(total_size, total_size_remaining); |
|
| 359 |
collection_node->sizeRemaining = total_size_remaining; |
|
| 360 |
collection_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size_remaining); |
|
| 327 | 361 |
|
| 328 |
collection_node->setText(FIELD_PROGRESS, QString("%1").arg(progress));
|
|
| 329 |
collection_node->setText(FIELD_STATE_STR, collection_node->text(FIELD_STATE_STR)); /* Force redraw */ |
|
| 330 |
collection_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole, QVariant(total_size_remaining)); |
|
| 331 |
collection_node->setText(FIELD_FILE_SIZE_REMAINING_STR, size_remaining); |
|
| 362 |
idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_STATE_STR, collection_node); |
|
| 363 |
emit dataChanged(idx, idx); |
|
| 332 | 364 |
|
| 365 |
idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_REMAINING_STR, collection_node); |
|
| 366 |
emit dataChanged(idx, idx); |
|
| 367 |
|
|
| 333 | 368 |
break; |
| 334 | 369 |
case QNNTPGrabGlue::TASK_STATE_DOWNLOADING: |
| 335 |
subject_node->setText(FIELD_PROGRESS, "0"); |
|
| 336 |
subject_node->setText(FIELD_STATE_STR, ""); /* The state message should be empty. In that case the value of the progress bar will be shown */ |
|
| 370 |
subject_node->progress = 0; |
|
| 371 |
subject_node->stateStr = ""; /* The state message should be empty. In that case the value of the progress bar will be shown */ |
|
| 337 | 372 |
break; |
| 338 | 373 |
case QNNTPGrabGlue::TASK_STATE_WAITING_FOR_DECODE: |
| 339 |
size_remaining = glue->utilsCalculateFileSize(0); |
|
| 340 |
subject_node->setText(FIELD_PROGRESS, "100"); |
|
| 341 |
subject_node->setText(FIELD_FILE_SIZE_REMAINING_STR, size_remaining); |
|
| 342 |
subject_node->setText(FIELD_STATE_STR, tr("Waiting"));
|
|
| 374 |
size_remaining = QNNTPGrabGlue::utilsCalculateFileSize(0); |
|
| 375 |
subject_node->progress = 100; |
|
| 376 |
subject_node->sizeRemaining = 0; |
|
| 377 |
subject_node->sizeRemainingStr = size_remaining; |
|
| 378 |
subject_node->stateStr = tr("Waiting");
|
|
| 343 | 379 |
break; |
| 344 | 380 |
case QNNTPGrabGlue::TASK_STATE_DECODING: |
| 345 |
subject_node->setText(FIELD_PROGRESS, "100"); |
|
| 346 |
subject_node->setText(FIELD_STATE_STR, tr("Decoding"));
|
|
| 381 |
subject_node->progress = 100; |
|
| 382 |
subject_node->stateStr = tr("Decoding");
|
|
| 347 | 383 |
break; |
| 348 | 384 |
case QNNTPGrabGlue::TASK_STATE_FINISHED_COMPLETE: |
| 349 | 385 |
Q_ASSERT(real_filename != NULL); |
| 350 | 386 |
|
| 351 |
subject_node->setText(FIELD_STATE_STR, tr("Done"));
|
|
| 352 |
subject_node->setText(FIELD_REAL_FILENAME, real_filename); |
|
| 387 |
subject_node->stateStr = tr("Done");
|
|
| 388 |
subject_node->realFilename = real_filename; |
|
| 353 | 389 |
break; |
| 354 | 390 |
case QNNTPGrabGlue::TASK_STATE_FINISHED_INCOMPLETE: |
| 355 | 391 |
Q_ASSERT(real_filename != NULL); |
| 356 | 392 |
|
| 357 |
subject_node->setText(FIELD_STATE_STR, tr("Incomplete"));
|
|
| 358 |
subject_node->setText(FIELD_REAL_FILENAME, real_filename); |
|
| 393 |
subject_node->stateStr = tr("Incomplete");
|
|
| 394 |
subject_node->realFilename = real_filename; |
|
| 359 | 395 |
break; |
| 360 | 396 |
case QNNTPGrabGlue::TASK_STATE_FINISHED_NO_PARTS_AVAIL: |
| 361 |
subject_node->setText(FIELD_STATE_STR, tr("Not available"));
|
|
| 397 |
subject_node->stateStr = tr("Not available");
|
|
| 362 | 398 |
break; |
| 363 | 399 |
case QNNTPGrabGlue::TASK_STATE_SKIPPED: |
| 364 |
subject_node->setText(FIELD_STATE_STR, tr("Skipped"));
|
|
| 365 |
subject_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayPropertyRole, QVariant(0)); |
|
| 366 |
subject_node->setText(FIELD_FILE_SIZE_REMAINING_STR, ""); |
|
| 400 |
size_remaining = QNNTPGrabGlue::utilsCalculateFileSize(0); |
|
| 401 |
subject_node->stateStr = tr("Skipped");
|
|
| 402 |
subject_node->sizeRemaining = 0; |
|
| 403 |
subject_node->sizeRemainingStr = size_remaining; |
|
| 367 | 404 |
break; |
| 368 | 405 |
} |
| 369 | 406 |
|
| 370 |
ui->treeWidget->resizeColumnToContents(FIELD_PROGRESS); |
|
| 371 |
#endif |
|
| 407 |
idx = createIndex(subject_node->row(), (int) DownloadQueueItem::FIELD_STATE_STR, subject_node); |
|
| 408 |
emit dataChanged(idx, idx); |
|
| 409 |
|
|
| 410 |
idx = createIndex(subject_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_REMAINING_STR, subject_node); |
|
| 411 |
emit dataChanged(idx, idx); |
|
| 372 | 412 |
} |
| 373 | 413 |
|
| 374 | 414 |
void DownloadQueueModel::onFileAdded(QString collection_name, QString subject, QString poster, QDateTime stamp, quint64 file_size, quint64 total_size, quint64 total_size_remaining, QNNTPGrabGlue::TaskState state, int num_parts, QList |
| 375 | 415 |
{
|
| 376 | 416 |
Q_UNUSED(num_parts); |
| 377 | 417 |
|
| 378 |
#if 0 |
|
| 379 |
QTreeWidgetItem *collection_node = NULL; |
|
| 380 |
|
|
| 381 |
collection_node = getTreeWidgetByCollection(collection_name); |
|
| 418 |
DownloadQueueItem *collection_node = lookupCollectionItem(collection_name); |
|
| 382 | 419 |
if (collection_node == NULL) {
|
| 383 | 420 |
qWarning("file added: Collection %s could not be found", collection_name.toUtf8().data());
|
| 384 | 421 |
return; |
| 385 | 422 |
} |
| 386 | 423 |
|
| 387 |
QTreeWidgetItem *file_node = new QTreeWidgetItem(); |
|
| 388 |
file_node->setText(FIELD_SUBJECT, subject); |
|
| 389 |
file_node->setText(FIELD_POSTER, poster); |
|
| 390 |
file_node->setData(FIELD_FILE_SIZE, Qt::DisplayRole, QVariant(file_size)); |
|
| 391 |
file_node->setText(FIELD_FILE_SIZE_STR, glue->utilsCalculateFileSize(file_size)); |
|
| 392 |
file_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayPropertyRole, QVariant(file_size)); |
|
| 393 |
file_node->setText(FIELD_FILE_SIZE_REMAINING_STR, glue->utilsCalculateFileSize(file_size)); |
|
| 394 |
file_node->setText(FIELD_STAMP, stamp.toString()); |
|
| 424 |
DownloadQueueItem *file_node = new DownloadQueueItem(collection_node); |
|
| 425 |
file_node->subject = subject; |
|
| 426 |
file_node->poster = poster; |
|
| 427 |
file_node->size = file_size; |
|
| 428 |
file_node->sizeStr = QNNTPGrabGlue::utilsCalculateFileSize(file_size); |
|
| 429 |
file_node->sizeRemaining = file_size; |
|
| 430 |
file_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(file_size); |
|
| 431 |
file_node->stamp = stamp; |
|
| 395 | 432 |
|
| 396 | 433 |
int i; |
| 397 | 434 |
QString groups_str; |
| ... | ... | |
| 402 | 439 |
groups_str += QString(",") + groups[i];
|
| 403 | 440 |
} |
| 404 | 441 |
} |
| 405 |
file_node->setText(FIELD_GROUPS, groups_str); |
|
| 442 |
file_node->groups = groups_str; |
|
| 406 | 443 |
|
| 407 | 444 |
if (state == QNNTPGrabGlue::TASK_STATE_SKIPPED) {
|
| 408 |
file_node->setText(FIELD_STATE_STR, tr("Skipped"));
|
|
| 409 |
file_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole, QVariant(0)); |
|
| 410 |
file_node->setText(FIELD_FILE_SIZE_REMAINING_STR, ""); |
|
| 445 |
file_node->stateStr = tr("Skipped");
|
|
| 446 |
file_node->sizeRemaining = 0; |
|
| 447 |
file_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(0); |
|
| 411 | 448 |
} |
| 412 | 449 |
|
| 450 |
QModelIndex idx_start = createIndex(file_node->row(), 0, file_node); |
|
| 451 |
QModelIndex idx_end = createIndex(file_node->row(), DownloadQueueItem::NUM_FIELDS - 1, file_node); |
|
| 452 |
emit dataChanged(idx_start, idx_end); |
|
| 453 |
|
|
| 413 | 454 |
/* Update the parent */ |
| 414 |
collection_node->addChild(file_node); |
|
| 455 |
collection_node->appendChild(file_node); |
|
| 415 | 456 |
|
| 416 |
QString size = glue->utilsCalculateFileSize(total_size); |
|
| 417 |
QString size_remaining = glue->utilsCalculateFileSize(total_size_remaining); |
|
| 457 |
collection_node->size = total_size; |
|
| 458 |
collection_node->sizeStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size); |
|
| 459 |
collection_node->sizeRemaining = total_size_remaining; |
|
| 460 |
collection_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size_remaining); |
|
| 461 |
collection_node->progress = calculateProgress(total_size, total_size_remaining); |
|
| 418 | 462 |
|
| 419 |
int progress = calculateProgress(total_size, total_size_remaining); |
|
| 463 |
QModelIndex idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_STATE_STR, collection_node); |
|
| 464 |
emit dataChanged(idx, idx); |
|
| 420 | 465 |
|
| 421 |
collection_node->setData(FIELD_FILE_SIZE, Qt::DisplayRole, QVariant(total_size)); |
|
| 422 |
collection_node->setText(FIELD_FILE_SIZE_STR, size); |
|
| 423 |
collection_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole, QVariant(total_size_remaining)); |
|
| 424 |
collection_node->setText(FIELD_FILE_SIZE_REMAINING_STR, size_remaining); |
|
| 425 |
collection_node->setText(FIELD_PROGRESS, QString("%1").arg(progress));
|
|
| 426 |
collection_node->setText(FIELD_STATE_STR, collection_node->text(FIELD_STATE_STR)); /* Force redraw */ |
|
| 427 |
#endif |
|
| 466 |
idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_STR, collection_node); |
|
| 467 |
emit dataChanged(idx, idx); |
|
| 468 |
|
|
| 469 |
idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_REMAINING_STR, collection_node); |
|
| 470 |
emit dataChanged(idx, idx); |
|
| 428 | 471 |
} |
| 429 | 472 |
|
| 430 | 473 |
void DownloadQueueModel::onFileRemoved(QString collection_name, QString subject, quint64 total_size, quint64 total_size_remaining) |
| 431 | 474 |
{
|
| 432 |
#if 0 |
|
| 433 |
QTreeWidgetItem *collection_node; |
|
| 434 |
QTreeWidgetItem *subject_node; |
|
| 475 |
DownloadQueueItem *collection_node; |
|
| 476 |
DownloadQueueItem *subject_node; |
|
| 435 | 477 |
|
| 436 |
collection_node = getTreeWidgetByCollection(collection_name); |
|
| 437 |
subject_node = getTreeWidgetBySubject(collection_node, subject); |
|
| 478 |
collection_node = lookupCollectionItem(collection_name); |
|
| 479 |
subject_node = lookupSubjectItem(collection_node, subject); |
|
| 438 | 480 |
if (subject_node == NULL) {
|
| 439 | 481 |
qWarning("onFileRemoved: Subject '%s' in collection '%s' could not be found", subject.toUtf8().data(), collection_name.toUtf8().data());
|
| 440 | 482 |
return; |
| 441 | 483 |
} |
| 442 | 484 |
|
| 443 |
QString size = glue->utilsCalculateFileSize(total_size); |
|
| 444 |
QString size_remaining = glue->utilsCalculateFileSize(total_size_remaining); |
|
| 485 |
collection_node->size = total_size; |
|
| 486 |
collection_node->sizeStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size); |
|
| 487 |
collection_node->sizeRemaining = total_size_remaining; |
|
| 488 |
collection_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size_remaining); |
|
| 489 |
collection_node->progress = calculateProgress(total_size, total_size_remaining); |
|
| 445 | 490 |
|
| 446 |
collection_node->setData(FIELD_FILE_SIZE, Qt::DisplayRole, QVariant(total_size)); |
|
| 447 |
collection_node->setText(FIELD_FILE_SIZE_STR, size); |
|
| 448 |
collection_node->setData(FIELD_FILE_SIZE_REMAINING, Qt::DisplayRole, QVariant(total_size_remaining)); |
|
| 449 |
collection_node->setText(FIELD_FILE_SIZE_REMAINING_STR, size_remaining); |
|
| 450 |
collection_node->setText(FIELD_PROGRESS, QString("%1").arg(calculateProgress(total_size, total_size_remaining)));
|
|
| 451 |
collection_node->setText(FIELD_STATE_STR, collection_node->text(FIELD_STATE_STR)); /* Force redraw */ |
|
| 491 |
collection_node->removeChild(subject_node); |
|
| 452 | 492 |
|
| 493 |
QModelIndex idx_start = createIndex(subject_node->row(), 0, subject_node); |
|
| 494 |
QModelIndex idx_end = createIndex(subject_node->row(), DownloadQueueItem::NUM_FIELDS - 1, subject_node); |
|
| 495 |
emit dataChanged(idx_start, idx_end); |
|
| 496 |
|
|
| 453 | 497 |
delete subject_node; |
| 454 |
#endif |
|
| 498 |
|
|
| 499 |
QModelIndex idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_STATE_STR, collection_node); |
|
| 500 |
emit dataChanged(idx, idx); |
|
| 501 |
|
|
| 502 |
idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_STR, collection_node); |
|
| 503 |
emit dataChanged(idx, idx); |
|
| 504 |
|
|
| 505 |
idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_REMAINING_STR, collection_node); |
|
| 506 |
emit dataChanged(idx, idx); |
|
| 455 | 507 |
} |
| 456 | 508 |
|
| 457 | 509 |
void DownloadQueueModel::onFileMoved(QString orig_collection_name, QString subject, QString new_collection_name, int old_position, int new_position) |
| ... | ... | |
| 459 | 511 |
Q_UNUSED(subject); |
| 460 | 512 |
Q_UNUSED(new_collection_name); |
| 461 | 513 |
|
| 462 |
#if 0 |
|
| 463 | 514 |
bool was_selected; |
| 464 |
QTreeWidgetItem *subject_node; |
|
| 465 |
QTreeWidgetItem *collection_node = getTreeWidgetByCollection(orig_collection_name); |
|
| 515 |
DownloadQueueItem *collection_node = lookupCollectionItem(orig_collection_name); |
|
| 516 |
DownloadQueueItem *subject_node = lookupSubjectItem(collection_node, subject); |
|
| 466 | 517 |
|
| 467 | 518 |
qDebug("file moved: old_position: %i, new position: %i", old_position, new_position);
|
| 468 | 519 |
|
| ... | ... | |
| 471 | 522 |
return; |
| 472 | 523 |
} |
| 473 | 524 |
|
| 525 |
#if 0 |
|
| 474 | 526 |
was_selected = collection_node->child(old_position)->isSelected(); |
| 475 |
subject_node = collection_node->takeChild(old_position); |
|
| 527 |
#endif |
|
| 476 | 528 |
|
| 529 |
Q_ASSERT(collection_node->removeChild(subject_node)); |
|
| 530 |
|
|
| 531 |
QModelIndex idx_start = createIndex(subject_node->row(), 0, subject_node); |
|
| 532 |
QModelIndex idx_end = createIndex(subject_node->row(), DownloadQueueItem::NUM_FIELDS - 1, subject_node); |
|
| 533 |
emit dataChanged(idx_start, idx_end); |
|
| 534 |
|
|
| 477 | 535 |
if (new_position == -1) {
|
| 478 |
collection_node->addChild(subject_node); |
|
| 536 |
collection_node->appendChild(subject_node); |
|
| 479 | 537 |
} else {
|
| 480 | 538 |
collection_node->insertChild(new_position, subject_node); |
| 481 | 539 |
} |
| 482 | 540 |
|
| 541 |
idx_start = createIndex(subject_node->row(), 0, subject_node); |
|
| 542 |
idx_end = createIndex(subject_node->row(), DownloadQueueItem::NUM_FIELDS - 1, subject_node); |
|
| 543 |
emit dataChanged(idx_start, idx_end); |
|
| 544 |
|
|
| 545 |
#if 0 |
|
| 483 | 546 |
if (was_selected) {
|
| 484 | 547 |
subject_node->setSelected(true); |
| 485 | 548 |
} |
| ... | ... | |
| 488 | 551 |
|
| 489 | 552 |
void DownloadQueueModel::onCollectionAdded(QString collection_name, QString poster) |
| 490 | 553 |
{
|
| 491 |
#if 0 |
|
| 492 |
qDebug("Collection added");
|
|
| 493 |
QTreeWidgetItem *collection_node = new QTreeWidgetItem(); |
|
| 494 |
collection_node->setText(FIELD_SUBJECT, collection_name); |
|
| 495 |
collection_node->setText(FIELD_POSTER, poster); |
|
| 496 |
ui->treeWidget->addTopLevelItem(collection_node); |
|
| 497 |
#endif |
|
| 554 |
DownloadQueueItem *collection_node = new DownloadQueueItem(rootItem); |
|
| 555 |
collection_node->subject = collection_name; |
|
| 556 |
collection_node->poster = poster; |
|
| 557 |
rootItem->appendChild(collection_node); |
|
| 558 |
|
|
| 559 |
QModelIndex idx_start = createIndex(collection_node->row(), 0, collection_node); |
|
| 560 |
QModelIndex idx_end = createIndex(collection_node->row(), DownloadQueueItem::NUM_FIELDS - 1, collection_node); |
|
| 561 |
emit dataChanged(idx_start, idx_end); |
|
| 498 | 562 |
} |
| 499 | 563 |
|
| 500 | 564 |
void DownloadQueueModel::onCollectionRemoved(QString collection_name) |
| 501 | 565 |
{
|
| 502 |
#if 0 |
|
| 503 |
qDebug("collection removed: %s", collection_name.toUtf8().data());
|
|
| 504 |
QTreeWidgetItem *collection_node = NULL; |
|
| 505 |
collection_node = getTreeWidgetByCollection(collection_name); |
|
| 566 |
DownloadQueueItem *collection_node = lookupCollectionItem(collection_name); |
|
| 506 | 567 |
|
| 507 | 568 |
if (collection_node == NULL) {
|
| 508 | 569 |
qWarning("collectionmodified: Collection %s not found", collection_name.toUtf8().data());
|
| 509 | 570 |
return; |
| 510 | 571 |
} |
| 511 | 572 |
|
| 573 |
rootItem->removeChild(collection_node); |
|
| 574 |
|
|
| 575 |
QModelIndex idx_start = createIndex(collection_node->row(), 0, collection_node); |
|
| 576 |
QModelIndex idx_end = createIndex(collection_node->row(), DownloadQueueItem::NUM_FIELDS - 1, collection_node); |
|
| 577 |
emit dataChanged(idx_start, idx_end); |
|
| 578 |
|
|
| 512 | 579 |
delete collection_node; |
| 513 |
#endif |
|
| 514 | 580 |
} |
| 515 | 581 |
|
| 516 | 582 |
void DownloadQueueModel::onCollectionModified(QString collection_name, QString poster) |
| 517 | 583 |
{
|
| 518 |
#if 0 |
|
| 519 |
qDebug("Collection modified");
|
|
| 520 |
QTreeWidgetItem *collection_node = NULL; |
|
| 521 |
collection_node = getTreeWidgetByCollection(collection_name); |
|
| 584 |
DownloadQueueItem *collection_node = lookupCollectionItem(collection_name); |
|
| 522 | 585 |
|
| 523 | 586 |
if (collection_node == NULL) {
|
| 524 | 587 |
qWarning("collectionmodified: Collection %s not found", collection_name.toUtf8().data());
|
| 525 | 588 |
return; |
| 526 | 589 |
} |
| 527 | 590 |
|
| 528 |
collection_node->setText(FIELD_POSTER, poster); |
|
| 529 |
#endif |
|
| 591 |
collection_node->poster = poster; |
|
| 592 |
|
|
| 593 |
QModelIndex idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_POSTER, collection_node); |
|
| 594 |
emit dataChanged(idx, idx); |
|
| 530 | 595 |
} |
| 531 | 596 |
|
| 532 | 597 |
void DownloadQueueModel::onCollectionMoved(QString collection_name, int old_position, int new_position) |
| 533 | 598 |
{
|
| 534 |
#if 0 |
|
| 535 | 599 |
qDebug("collection moved: old_position: %i, new position: %i", old_position, new_position);
|
| 536 | 600 |
bool was_selected; |
| 537 | 601 |
bool was_expanded; |
| 538 |
QTreeWidgetItem *collection_node; |
|
| 602 |
DownloadQueueItem *collection_node; |
|
| 539 | 603 |
|
| 604 |
#if 0 |
|
| 540 | 605 |
was_selected = ui->treeWidget->topLevelItem(old_position)->isSelected(); |
| 541 | 606 |
was_expanded = ui->treeWidget->topLevelItem(old_position)->isExpanded(); |
| 542 |
collection_node = ui->treeWidget->takeTopLevelItem(old_position); |
|
| 607 |
#endif |
|
| 608 |
collection_node = lookupCollectionItem(collection_name); |
|
| 543 | 609 |
|
| 544 |
if (collection_node->text(FIELD_SUBJECT).compare(collection_name) != 0) {
|
|
| 545 |
qWarning("onCollectionMoved: %s != %s", collection_name.toUtf8().data(), collection_node->text(FIELD_SUBJECT).toUtf8().data());
|
|
| 546 |
return; |
|
| 547 |
} |
|
| 610 |
rootItem->removeChild(collection_node); |
|
| 611 |
QModelIndex idx_start = createIndex(collection_node->row(), 0, collection_node); |
|
| 612 |
QModelIndex idx_end = createIndex(collection_node->row(), DownloadQueueItem::NUM_FIELDS - 1, collection_node); |
|
| 613 |
emit dataChanged(idx_start, idx_end); |
|
| 548 | 614 |
|
| 549 | 615 |
if (new_position == -1) { // To bottom
|
| 550 |
ui->treeWidget->addTopLevelItem(collection_node); |
|
| 616 |
rootItem->appendChild(collection_node); |
|
| 551 | 617 |
} else {
|
| 552 |
ui->treeWidget->insertTopLevelItem(new_position, collection_node); |
|
| 618 |
rootItem->insertChild(new_position, collection_node); |
|
| 553 | 619 |
} |
| 554 | 620 |
|
| 621 |
idx_start = createIndex(collection_node->row(), 0, collection_node); |
|
| 622 |
idx_end = createIndex(collection_node->row(), DownloadQueueItem::NUM_FIELDS - 1, collection_node); |
|
| 623 |
emit dataChanged(idx_start, idx_end); |
|
| 624 |
|
|
| 625 |
#if 0 |
|
| 555 | 626 |
if (was_selected) {
|
| 556 | 627 |
collection_node->setSelected(true); |
| 557 | 628 |
} |
| ... | ... | |
| 567 | 638 |
Q_UNUSED(stamp); |
| 568 | 639 |
Q_UNUSED(average); |
| 569 | 640 |
|
| 570 |
#if 0 |
|
| 571 | 641 |
static int times_been_here = 10; |
| 572 | 642 |
bool no_data_received = FALSE; |
| 573 | 643 |
quint64 total_estimated_time_remaining; |
| 574 | 644 |
|
| 575 |
if (ui->treeWidget->children().count() == 0) {
|
|
| 576 |
return; |
|
| 577 |
} |
|
| 578 |
|
|
| 579 | 645 |
if (bytes_received1 == 0 && bytes_received2 == 0 && bytes_received3 == 0 && bytes_received4 == 0 && bytes_received5 == 0 && |
| 580 | 646 |
bytes_received6 == 0 && bytes_received7 == 0 && bytes_received8 == 0 && bytes_received9 == 0 && bytes_received10 == 0) {
|
| 581 | 647 |
no_data_received = TRUE; |
| ... | ... | |
| 595 | 661 |
|
| 596 | 662 |
total_estimated_time_remaining = 0; |
| 597 | 663 |
|
| 598 |
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) {
|
|
| 599 |
QTreeWidgetItem *collection_item; |
|
| 664 |
QModelIndex idx; |
|
| 665 |
int count = rootItem->childCount(); |
|
| 666 |
for (int i = 0; i < count; i++) {
|
|
| 667 |
DownloadQueueItem *collection_item; |
|
| 600 | 668 |
int estimated_time_remaining; |
| 601 | 669 |
quint64 file_size; |
| 602 | 670 |
|
| 603 |
collection_item = ui->treeWidget->topLevelItem(i); |
|
| 604 |
file_size = collection_item->data(FIELD_FILE_SIZE_REMAINING, Qt::UserRole).toULongLong(); |
|
| 605 |
estimated_time_remaining = glue->utilsCalculateEstimatedTimeRemaining(bytes_received1, bytes_received2, bytes_received3, bytes_received4, bytes_received5, |
|
| 606 |
bytes_received6, bytes_received7, bytes_received8, bytes_received9, bytes_received10, file_size); |
|
| 671 |
collection_item = rootItem->child(i); |
|
| 672 |
file_size = collection_item->sizeRemaining; |
|
| 673 |
estimated_time_remaining = QNNTPGrabGlue::utilsCalculateEstimatedTimeRemaining(bytes_received1, bytes_received2, bytes_received3, |
|
| 674 |
bytes_received4, bytes_received5, bytes_received6, |
|
| 675 |
bytes_received7, bytes_received8, bytes_received9, |
|
| 676 |
bytes_received10, file_size); |
|
| 607 | 677 |
|
| 608 | 678 |
if (estimated_time_remaining == -1) {
|
| 609 | 679 |
/* Not enough data received to make an estimation */ |
| ... | ... | |
| 612 | 682 |
|
| 613 | 683 |
if (estimated_time_remaining == 0) {
|
| 614 | 684 |
/* Collection is already downloaded */ |
| 615 |
collection_item->setText(FIELD_ESTIMATED_TIME_REMAINING_STR, ""); |
|
| 616 |
collection_item->setText(FIELD_ESTIMATED_TIME_TO_FINISH_STR, ""); |
|
| 685 |
if (!collection_item->estimatedTimeRemainingStr.isEmpty()) {
|
|
| 686 |
collection_item->estimatedTimeRemainingStr = ""; |
|
| 687 |
collection_item->estimatedTimeToFinishStr = ""; |
|
| 688 |
|
|
| 689 |
idx = createIndex(collection_item->row(), (int) DownloadQueueItem::FIELD_ESTIMATED_TIME_REMAINING_STR, collection_item); |
|
| 690 |
emit dataChanged(idx, idx); |
|
| 691 |
|
|
| 692 |
idx = createIndex(collection_item->row(), (int) DownloadQueueItem::FIELD_ESTIMATED_TIME_TO_FINISH_STR, collection_item); |
|
| 693 |
emit dataChanged(idx, idx); |
|
| 694 |
} |
|
| 617 | 695 |
} else {
|
| 618 |
collection_item->setText(FIELD_ESTIMATED_TIME_REMAINING_STR, glue->utilsGetReadableTimeRemaining(total_estimated_time_remaining + estimated_time_remaining)); |
|
| 619 |
collection_item->setText(FIELD_ESTIMATED_TIME_TO_FINISH_STR, glue->utilsGetReadableFinishedTime(total_estimated_time_remaining + estimated_time_remaining)); |
|
| 696 |
collection_item->estimatedTimeRemainingStr = QNNTPGrabGlue::utilsGetReadableTimeRemaining(total_estimated_time_remaining + estimated_time_remaining); |
|
| 697 |
collection_item->estimatedTimeToFinishStr = QNNTPGrabGlue::utilsGetReadableFinishedTime(total_estimated_time_remaining + estimated_time_remaining); |
|
| 698 |
|
|
| 699 |
idx = createIndex(collection_item->row(), (int) DownloadQueueItem::FIELD_ESTIMATED_TIME_REMAINING_STR, collection_item); |
|
| 700 |
emit dataChanged(idx, idx); |
|
| 701 |
|
|
| 702 |
idx = createIndex(collection_item->row(), (int) DownloadQueueItem::FIELD_ESTIMATED_TIME_TO_FINISH_STR, collection_item); |
|
| 703 |
emit dataChanged(idx, idx); |
|
| 620 | 704 |
} |
| 621 | 705 |
|
| 622 | 706 |
total_estimated_time_remaining += estimated_time_remaining; |
| 623 | 707 |
|
| 624 |
/* Disabled for now as it causes too much load */ |
|
| 625 |
#if 0 |
|
| 626 | 708 |
/* Walk through all the children */ |
| 627 |
for (int j = 0; j < collection_item->childCount(); j++) {
|
|
| 628 |
QTreeWidgetItem *subject_item = collection_item->child(j); |
|
| 709 |
int count2 = collection_item->childCount(); |
|
| 710 |
for (int j = 0; j < count2; j++) {
|
|
| 711 |
DownloadQueueItem *subject_item = collection_item->child(j); |
|
| 629 | 712 |
|
| 630 |
file_size = subject_item->data(FIELD_FILE_SIZE_REMAINING, Qt::UserRole).toLongLong(); |
|
| 713 |
file_size = subject_item->sizeRemaining; |
|
| 631 | 714 |
if (file_size == 0) {
|
| 632 | 715 |
/* File is already downloaded */ |
| 633 |
subject_item->setText(FIELD_ESTIMATED_TIME_REMAINING_STR, ""); |
|
| 634 |
subject_item->setText(FIELD_ESTIMATED_TIME_TO_FINISH_STR, ""); |
|
| 716 |
if (!subject_item->estimatedTimeRemainingStr.isEmpty()) {
|
|
| 717 |
subject_item->estimatedTimeRemainingStr = ""; |
|
| 718 |
subject_item->estimatedTimeToFinishStr = ""; |
|
| 719 |
|
|
| 720 |
idx = createIndex(subject_item->row(), (int) DownloadQueueItem::FIELD_ESTIMATED_TIME_REMAINING_STR, subject_item); |
|
| 721 |
emit dataChanged(idx, idx); |
|
| 722 |
|
|
| 723 |
idx = createIndex(subject_item->row(), (int) DownloadQueueItem::FIELD_ESTIMATED_TIME_TO_FINISH_STR, subject_item); |
|
| 724 |
emit dataChanged(idx, idx); |
|
| 725 |
} |
|
| 635 | 726 |
} else {
|
| 636 |
estimated_time_remaining = glue->utilsCalculateEstimatedTimeRemaining(bytes_received1, bytes_received2, bytes_received3, bytes_received4, bytes_received5, |
|
| 637 |
bytes_received6, bytes_received7, bytes_received8, bytes_received9, bytes_received10, file_size); |
|
| 727 |
estimated_time_remaining = QNNTPGrabGlue::utilsCalculateEstimatedTimeRemaining(bytes_received1, bytes_received2, bytes_received3, |
|
| 728 |
bytes_received4, bytes_received5, bytes_received6, |
|
| 729 |
bytes_received7, bytes_received8, bytes_received9, |
|
| 730 |
bytes_received10, file_size); |
|
| 638 | 731 |
|
| 639 |
subject_item->setText(FIELD_ESTIMATED_TIME_REMAINING_STR, glue->utilsGetReadableTimeRemaining(total_estimated_time_remaining)); |
|
| 640 |
subject_item->setText(FIELD_ESTIMATED_TIME_TO_FINISH_STR, glue->utilsGetReadableFinishedTime(total_estimated_time_remaining)); |
|
| 732 |
subject_item->estimatedTimeRemainingStr = QNNTPGrabGlue::utilsGetReadableTimeRemaining(total_estimated_time_remaining); |
|
| 733 |
subject_item->estimatedTimeToFinishStr = QNNTPGrabGlue::utilsGetReadableFinishedTime(total_estimated_time_remaining); |
|
| 734 |
|
|
| 735 |
idx = createIndex(subject_item->row(), (int) DownloadQueueItem::FIELD_ESTIMATED_TIME_REMAINING_STR, subject_item); |
|
| 736 |
emit dataChanged(idx, idx); |
|
| 737 |
|
|
| 738 |
idx = createIndex(collection_item->row(), (int) DownloadQueueItem::FIELD_ESTIMATED_TIME_TO_FINISH_STR, subject_item); |
|
| 739 |
emit dataChanged(idx, idx); |
|
| 641 | 740 |
} |
| 642 | 741 |
} |
| 643 |
#endif |
|
| 644 | 742 |
} |
| 645 |
|
|
| 646 |
ui->treeWidget->resizeColumnToContents(FIELD_ESTIMATED_TIME_REMAINING_STR); |
|
| 647 |
ui->treeWidget->resizeColumnToContents(FIELD_ESTIMATED_TIME_TO_FINISH_STR); |
|
| 648 |
#endif |
|
| 649 | 743 |
} |
Also available in: Unified diff
NNTPGrab

