Revision 1853 trunk/client/gui_qt/DownloadQueueModel.cpp
| DownloadQueueModel.cpp (revision 1853) | ||
|---|---|---|
| 8 | 8 | 
                  loadDownloadQueue(glue);  | 
              
| 9 | 9 | 
                   | 
              
| 10 | 10 | 
                  connect(glue, SIGNAL(fileDownloadStateUpdate(QString,QString,int,int,int,quint64,quint64,quint64,quint64)), SLOT(onFileDownloadStateUpdate(QString,QString,int,int,int,quint64,quint64,quint64,quint64)), Qt::QueuedConnection);  | 
              
| 11 | 
                  connect(glue, SIGNAL(fileStateChanged(QString,QString,QString,QNNTPGrabGlue::TaskState,QNNTPGrabGlue::TaskState)), SLOT(onFileStateChanged(QString,QString,QString,QNNTPGrabGlue::TaskState,QNNTPGrabGlue::TaskState)), Qt::QueuedConnection);  | 
              |
| 11 | 
                  connect(glue, SIGNAL(fileStateChanged(QString,QString,QString,QNNTPGrabGlue::TaskState,QNNTPGrabGlue::TaskState,quint64,quint64,quint64)), SLOT(onFileStateChanged(QString,QString,QString,QNNTPGrabGlue::TaskState,QNNTPGrabGlue::TaskState,quint64,quint64,quint64)), Qt::QueuedConnection);  | 
              |
| 12 | 12 | 
                   | 
              
| 13 | 13 | 
                  connect(glue, SIGNAL(fileAdded(QString,QString,QString,QDateTime,quint64,quint64,quint64,QNNTPGrabGlue::TaskState,int,QList  | 
              
| 14 | 14 | 
                  connect(glue, SIGNAL(fileRemoved(QString,QString,quint64,quint64)), SLOT(onFileRemoved(QString,QString,quint64,quint64)), Qt::QueuedConnection);  | 
              
| ... | ... | |
| 254 | 254 | 
                   | 
              
| 255 | 255 | 
                      if (ret < 0 || ret > 100) {
                 | 
              
| 256 | 256 | 
                          qDebug("Invalid progress detected, size = %lli, size_remaining = %lli", size, sizeRemaining);
                 | 
              
| 257 | 
                          if (ret < 0) {
                 | 
              |
| 258 | 
                  ret = 0;  | 
              |
| 259 | 
                  }  | 
              |
| 257 | 260 | 
                  }  | 
              
| 258 | 261 | 
                   | 
              
| 259 | 262 | 
                  return qMin(100, ret);  | 
              
| ... | ... | |
| 323 | 326 | 
                  emit dataChanged(idx, idx);  | 
              
| 324 | 327 | 
                  }  | 
              
| 325 | 328 | 
                   | 
              
| 326 | 
                  void DownloadQueueModel::onFileStateChanged(QString collection_name, QString subject, QString real_filename, QNNTPGrabGlue::TaskState old_state, QNNTPGrabGlue::TaskState new_state)  | 
              |
| 329 | 
                  void DownloadQueueModel::onFileStateChanged(QString collection_name, QString subject, QString real_filename, QNNTPGrabGlue::TaskState old_state, QNNTPGrabGlue::TaskState new_state, quint64 file_size_remaining, quint64 total_size, quint64 total_size_remaining)  | 
              |
| 327 | 330 | 
                  {
                 | 
              
| 328 | 331 | 
                  Q_UNUSED(old_state);  | 
              
| 329 | 332 | 
                   | 
              
| 333 | 
                  QModelIndex idx;  | 
              |
| 330 | 334 | 
                  DownloadQueueItem *collection_node;  | 
              
| 331 | 335 | 
                  DownloadQueueItem *subject_node;  | 
              
| 332 | 336 | 
                   | 
              
| ... | ... | |
| 338 | 342 | 
                  return;  | 
              
| 339 | 343 | 
                  }  | 
              
| 340 | 344 | 
                   | 
              
| 341 | 
                  quint64 file_size;  | 
              |
| 342 | 
                  quint64 file_size_remaining;  | 
              |
| 343 | 
                  QString size_remaining;  | 
              |
| 344 | 
                  quint64 total_size;  | 
              |
| 345 | 
                  quint64 total_size_remaining;  | 
              |
| 346 | 
                  QModelIndex idx;  | 
              |
| 347 | 
                   | 
              |
| 348 | 345 | 
                      switch(new_state) {
                 | 
              
| 349 | 346 | 
                  case QNNTPGrabGlue::TASK_STATE_WAITING_FOR_DOWNLOAD:  | 
              
| 350 | 347 | 
                  /* The task was restarted */  | 
              
| 351 | 348 | 
                   | 
              
| 352 | 349 | 
                  /* Update the row itself */  | 
              
| 353 | 
                  file_size = subject_node->size;  | 
              |
| 354 | 
                  file_size_remaining = subject_node->sizeRemaining;  | 
              |
| 355 | 
                   | 
              |
| 356 | 350 | 
                  subject_node->progress = 0;  | 
              
| 357 | 351 | 
                  subject_node->stateStr = "";  | 
              
| 358 | 
                  subject_node->sizeRemaining = file_size;  | 
              |
| 359 | 
                  subject_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(file_size);  | 
              |
| 352 | 
                  subject_node->sizeRemaining = file_size_remaining;  | 
              |
| 353 | 
                  subject_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(file_size_remaining);  | 
              |
| 360 | 354 | 
                   | 
              
| 361 | 355 | 
                  /* Update the parent */  | 
              
| 362 | 
                  total_size = collection_node->size;  | 
              |
| 363 | 
                  total_size_remaining = collection_node->sizeRemaining;  | 
              |
| 364 | 
                   | 
              |
| 365 | 
                  total_size_remaining += file_size - file_size_remaining;  | 
              |
| 366 | 
                   | 
              |
| 367 | 356 | 
                  collection_node->progress = calculateProgress(total_size, total_size_remaining);  | 
              
| 357 | 
                  collection_node->size = total_size;  | 
              |
| 358 | 
                  collection_node->sizeStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size);  | 
              |
| 368 | 359 | 
                  collection_node->sizeRemaining = total_size_remaining;  | 
              
| 369 | 360 | 
                  collection_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size_remaining);  | 
              
| 370 | 361 | 
                   | 
              
| ... | ... | |
| 380 | 371 | 
                  subject_node->stateStr = ""; /* The state message should be empty. In that case the value of the progress bar will be shown */  | 
              
| 381 | 372 | 
                  break;  | 
              
| 382 | 373 | 
                  case QNNTPGrabGlue::TASK_STATE_WAITING_FOR_DECODE:  | 
              
| 383 | 
                  size_remaining = QNNTPGrabGlue::utilsCalculateFileSize(0);  | 
              |
| 384 | 374 | 
                  subject_node->progress = 100;  | 
              
| 385 | 375 | 
                  subject_node->sizeRemaining = 0;  | 
              
| 386 | 
                  subject_node->sizeRemainingStr = size_remaining;  | 
              |
| 376 | 
                  subject_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(0);  | 
              |
| 387 | 377 | 
                              subject_node->stateStr = tr("Waiting");
                 | 
              
| 388 | 378 | 
                  break;  | 
              
| 389 | 379 | 
                  case QNNTPGrabGlue::TASK_STATE_DECODING:  | 
              
| ... | ... | |
| 406 | 396 | 
                              subject_node->stateStr = tr("Not available");
                 | 
              
| 407 | 397 | 
                  break;  | 
              
| 408 | 398 | 
                  case QNNTPGrabGlue::TASK_STATE_SKIPPED:  | 
              
| 409 | 
                  size_remaining = QNNTPGrabGlue::utilsCalculateFileSize(0);  | 
              |
| 410 | 399 | 
                              subject_node->stateStr = tr("Skipped");
                 | 
              
| 411 | 400 | 
                  subject_node->sizeRemaining = 0;  | 
              
| 412 | 
                  subject_node->sizeRemainingStr = size_remaining;  | 
              |
| 401 | 
                  subject_node->sizeRemainingStr = "";  | 
              |
| 402 | 
                   | 
              |
| 403 | 
                  /* Update the parent */  | 
              |
| 404 | 
                  collection_node->progress = calculateProgress(total_size, total_size_remaining);  | 
              |
| 405 | 
                  collection_node->size = total_size;  | 
              |
| 406 | 
                  collection_node->sizeStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size);  | 
              |
| 407 | 
                  collection_node->sizeRemaining = total_size_remaining;  | 
              |
| 408 | 
                  collection_node->sizeRemainingStr = QNNTPGrabGlue::utilsCalculateFileSize(total_size_remaining);  | 
              |
| 409 | 
                   | 
              |
| 410 | 
                  idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_STATE_STR, collection_node);  | 
              |
| 411 | 
                  emit dataChanged(idx, idx);  | 
              |
| 412 | 
                   | 
              |
| 413 | 
                  idx = createIndex(collection_node->row(), (int) DownloadQueueItem::FIELD_FILE_SIZE_REMAINING_STR, collection_node);  | 
              |
| 414 | 
                  emit dataChanged(idx, idx);  | 
              |
| 415 | 
                   | 
              |
| 413 | 416 | 
                  break;  | 
              
| 414 | 417 | 
                  }  | 
              
| 415 | 418 | 
                   | 
              
Also available in: Unified diff
NNTPGrab

