Revision 1778 trunk/client/gui_qt/WidgetDownloadQueue.cpp
| WidgetDownloadQueue.cpp (revision 1778) | ||
|---|---|---|
| 31 | 31 |
connect(ui->actionMoveSelectedItemsDown, SIGNAL(triggered(void)), SLOT(btnQueueMoveDown_clicked(void))); |
| 32 | 32 |
connect(ui->actionMoveSelectedItemsToTheBottom, SIGNAL(triggered(void)), SLOT(btnQueueMoveToBottom_clicked(void))); |
| 33 | 33 |
|
| 34 |
connect(ui->treeView, SIGNAL(itemSelectionChanged(void)), SLOT(onItemSelectionChanged(void))); |
|
| 34 |
QItemSelectionModel *selectionModel = ui->treeView->selectionModel(); |
|
| 35 |
connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &))); |
|
| 35 | 36 |
|
| 36 | 37 |
connect(ui->actionMarkItemOptional, SIGNAL(triggered()), SLOT(actionMarkItemOptional_activated())); |
| 37 | 38 |
connect(ui->actionRestartSelectedItems, SIGNAL(triggered()), SLOT(actionRestartSelectedItems_activated())); |
| ... | ... | |
| 102 | 103 |
} |
| 103 | 104 |
|
| 104 | 105 |
typedef struct _move_item_data {
|
| 105 |
QTreeWidgetItem *item; |
|
| 106 |
DownloadQueueItem *item; |
|
| 106 | 107 |
int position; |
| 107 | 108 |
} MoveItemData; |
| 108 | 109 |
|
| 109 | 110 |
void WidgetDownloadQueue::processSelectionAndMoveItems(moveDirection direction) |
| 110 | 111 |
{
|
| 111 |
QTreeWidgetItem *collection_item; |
|
| 112 |
QTreeWidgetItem *subject_item; |
|
| 112 |
DownloadQueueItem *collection_item; |
|
| 113 |
DownloadQueueItem *subject_item; |
|
| 113 | 114 |
QList |
| 114 | 115 |
MoveItemData move_data; |
| 116 |
DownloadQueueModel *model = static_cast |
|
| 117 |
QItemSelectionModel *selectionModel = ui->treeView->selectionModel(); |
|
| 115 | 118 |
|
| 116 |
#if 0 |
|
| 117 |
for (int i = 0; i < ui->treeView->topLevelItemCount(); i++) {
|
|
| 118 |
collection_item = ui->treeView->topLevelItem(i); |
|
| 119 |
for (int i = 0; i < model->rowCount(); i++) {
|
|
| 120 |
QModelIndex idx_collection = model->index(i, 0); |
|
| 121 |
collection_item = static_cast |
|
| 119 | 122 |
|
| 120 |
if (collection_item->isSelected()) {
|
|
| 121 |
if (i == ui->treeWidget->topLevelItemCount() - 1 && direction == MOVE_DIRECTION_DOWN) {
|
|
| 123 |
Q_ASSERT(collection_item != NULL); |
|
| 124 |
|
|
| 125 |
if (selectionModel->isSelected(idx_collection)) {
|
|
| 126 |
if (i == model->rowCount() - 1 && direction == MOVE_DIRECTION_DOWN) {
|
|
| 122 | 127 |
/* We're already at the bottom, no need to move again */ |
| 123 | 128 |
continue; |
| 124 | 129 |
} |
| ... | ... | |
| 139 | 144 |
|
| 140 | 145 |
for (int j = 0; j < collection_item->childCount(); j++) {
|
| 141 | 146 |
subject_item = collection_item->child(j); |
| 147 |
QModelIndex idx_subject = model->index(i, 0, idx_collection); |
|
| 142 | 148 |
|
| 143 |
if (subject_item->isSelected()) {
|
|
| 149 |
if (selectionModel->isSelected(idx_subject)) {
|
|
| 144 | 150 |
if (j == collection_item->childCount() - 1 && direction == MOVE_DIRECTION_DOWN) {
|
| 145 | 151 |
/* We're already at the bottom, no need to move again */ |
| 146 | 152 |
continue; |
| ... | ... | |
| 161 | 167 |
|
| 162 | 168 |
if (list_subjects.count() > 0) {
|
| 163 | 169 |
Q_FOREACH(move_data, list_subjects) {
|
| 164 |
doMoveItem(collection_item->data(FIELD_SUBJECT, 0).toString(), move_data.item->data(FIELD_SUBJECT, 0).toString(), calculateNewPosition(move_data.position, direction)); |
|
| 170 |
doMoveItem(collection_item->subject, move_data.item->subject, calculateNewPosition(move_data.position, direction)); |
|
| 165 | 171 |
} |
| 166 | 172 |
} |
| 167 | 173 |
} |
| 168 |
#endif |
|
| 169 | 174 |
|
| 170 | 175 |
if (list_collections.count() > 0) {
|
| 171 | 176 |
Q_FOREACH(move_data, list_collections) {
|
| 172 |
doMoveItem(move_data.item->data(DownloadQueueItem::FIELD_SUBJECT, 0).toString(), NULL, calculateNewPosition(move_data.position, direction)); |
|
| 177 |
doMoveItem(move_data.item->subject, NULL, calculateNewPosition(move_data.position, direction)); |
|
| 173 | 178 |
} |
| 174 | 179 |
} |
| 175 | 180 |
} |
| ... | ... | |
| 194 | 199 |
processSelectionAndMoveItems(MOVE_DIRECTION_BOTTOM); |
| 195 | 200 |
} |
| 196 | 201 |
|
| 197 |
#if 0 |
|
| 198 |
QTreeWidgetItem *WidgetDownloadQueue::getTreeWidgetByCollection(QString collection_name) |
|
| 202 |
void WidgetDownloadQueue::onSelectionChanged(const QItemSelection &newSelection, const QItemSelection &oldSelection) |
|
| 199 | 203 |
{
|
| 200 |
QTreeWidgetItem *collection_node = NULL; |
|
| 201 |
int i; |
|
| 202 |
for(i = 0; i < ui->treeWidget->topLevelItemCount(); i++) {
|
|
| 203 |
if(collection_name.compare(ui->treeWidget->topLevelItem(i)->text(FIELD_SUBJECT)) == 0) {
|
|
| 204 |
collection_node = ui->treeWidget->topLevelItem(i); |
|
| 205 |
break; |
|
| 206 |
} |
|
| 207 |
} |
|
| 208 |
return collection_node; |
|
| 209 |
} |
|
| 204 |
Q_UNUSED(newSelection); |
|
| 205 |
Q_UNUSED(oldSelection); |
|
| 210 | 206 |
|
| 211 |
QTreeWidgetItem *WidgetDownloadQueue::getTreeWidgetBySubject(QTreeWidgetItem *collection_node, QString subject) |
|
| 212 |
{
|
|
| 213 |
QTreeWidgetItem *subject_node = NULL; |
|
| 214 |
int i; |
|
| 215 |
|
|
| 216 |
if (!collection_node) {
|
|
| 217 |
return NULL; |
|
| 218 |
} |
|
| 219 |
|
|
| 220 |
int count = collection_node->childCount(); |
|
| 221 |
for(i = 0; i < count; i++) {
|
|
| 222 |
if(subject.compare(collection_node->child(i)->text(FIELD_SUBJECT)) == 0) {
|
|
| 223 |
subject_node = collection_node->child(i); |
|
| 224 |
break; |
|
| 225 |
} |
|
| 226 |
} |
|
| 227 |
return subject_node; |
|
| 228 |
} |
|
| 229 |
#endif |
|
| 230 |
|
|
| 231 |
void WidgetDownloadQueue::onItemSelectionChanged(void) |
|
| 232 |
{
|
|
| 233 |
#if 0 |
|
| 234 |
if (ui->treeView->selectedItems().count() == 0) {
|
|
| 207 |
if (!ui->treeView->selectionModel()->hasSelection()) {
|
|
| 235 | 208 |
ui->btnQueueMoveToTop->setEnabled(false); |
| 236 | 209 |
ui->btnQueueMoveUp->setEnabled(false); |
| 237 | 210 |
ui->btnQueueMoveDown->setEnabled(false); |
| ... | ... | |
| 244 | 217 |
ui->btnQueueMoveToBottom->setEnabled(true); |
| 245 | 218 |
actionRemoveSelectedFiles->setEnabled(true); |
| 246 | 219 |
} |
| 247 |
#endif |
|
| 248 | 220 |
} |
| 249 | 221 |
|
| 250 | 222 |
void WidgetDownloadQueue::actionMarkItemOptional_activated(void) |
| 251 | 223 |
{
|
| 252 |
#if 0 |
|
| 224 |
QItemSelectionModel *selectionModel = ui->treeView->selectionModel(); |
|
| 225 |
|
|
| 253 | 226 |
bool flag_set = FALSE; |
| 254 | 227 |
bool is_optional = FALSE; |
| 255 | 228 |
|
| 256 |
for (int i = 0; i < ui->treeView->selectedItems().count(); i++) {
|
|
| 257 |
QString collection_name = ""; |
|
| 258 |
QString subject = ""; |
|
| 259 |
QString errmsg = ""; |
|
| 229 |
Q_FOREACH(QModelIndex idx, selectionModel->selectedRows()) {
|
|
| 230 |
DownloadQueueItem *item = static_cast |
|
| 260 | 231 |
|
| 261 |
QTreeWidgetItem *item = ui->treeView->selectedItems().at(i); |
|
| 262 |
|
|
| 263 | 232 |
if (item->childCount() != 0) {
|
| 264 | 233 |
/* This is a collection, ignore */ |
| 265 | 234 |
continue; |
| 266 | 235 |
} |
| 267 | 236 |
|
| 268 | 237 |
/* This is a subject */ |
| 269 |
subject = item->text(FIELD_SUBJECT); |
|
| 270 |
collection_name = item->parent()->text(FIELD_SUBJECT); |
|
| 271 |
|
|
| 272 | 238 |
if (!flag_set) {
|
| 273 |
if (item->text(FIELD_STATE_STR).compare(tr("Skipped")) == 0) {
|
|
| 239 |
if (item->stateStr == tr("Skipped")) {
|
|
| 274 | 240 |
is_optional = false; |
| 275 | 241 |
} else {
|
| 276 | 242 |
is_optional = true; |
| ... | ... | |
| 279 | 245 |
flag_set = true; |
| 280 | 246 |
} |
| 281 | 247 |
|
| 282 |
if (!glue->schedularMarkTaskOptional(collection_name, subject, is_optional)) {
|
|
| 248 |
if (!glue->schedularMarkTaskOptional(item->parent()->subject, item->subject, is_optional)) {
|
|
| 283 | 249 |
qWarning("%s", tr("Unable to change the status of the selected file(s)").toUtf8().data());
|
| 284 | 250 |
} |
| 285 | 251 |
} |
| 286 |
#endif |
|
| 287 | 252 |
} |
| 288 | 253 |
|
| 289 | 254 |
void WidgetDownloadQueue::actionRemoveSelectedFiles_activated(void) |
| 290 | 255 |
{
|
| 291 |
#if 0 |
|
| 292 |
for (int i = 0; i < ui->treeView->selectedItems().count(); i++) {
|
|
| 256 |
QItemSelectionModel *selectionModel = ui->treeView->selectionModel(); |
|
| 257 |
Q_FOREACH(QModelIndex idx, selectionModel->selectedRows()) {
|
|
| 258 |
DownloadQueueItem *item = static_cast |
|
| 293 | 259 |
QString collection_name = ""; |
| 294 | 260 |
QString subject = ""; |
| 295 | 261 |
QString errmsg = ""; |
| 296 | 262 |
|
| 297 |
QTreeWidgetItem *item = ui->treeView->selectedItems().at(i); |
|
| 298 |
|
|
| 299 | 263 |
if (item->childCount() == 0) {
|
| 300 | 264 |
/* This is a subject */ |
| 301 |
subject = item->text(FIELD_SUBJECT); |
|
| 302 |
collection_name = item->parent()->text(FIELD_SUBJECT); |
|
| 265 |
subject = item->subject; |
|
| 266 |
collection_name = item->parent()->subject; |
|
| 303 | 267 |
} else {
|
| 304 | 268 |
/* This is a collection */ |
| 305 |
collection_name = item->text(FIELD_SUBJECT); |
|
| 269 |
collection_name = item->subject; |
|
| 306 | 270 |
} |
| 307 | 271 |
|
| 308 | 272 |
if (!glue->schedularDelTaskFromQueue(collection_name, subject, errmsg)) {
|
| 309 | 273 |
qWarning(tr("Error occured while removing file(s):\n%s").toUtf8().data(), errmsg.toUtf8().data());
|
| 310 | 274 |
} |
| 311 | 275 |
} |
| 312 |
#endif |
|
| 313 | 276 |
} |
| 314 | 277 |
|
| 315 | 278 |
void WidgetDownloadQueue::actionRestartSelectedItems_activated(void) |
| 316 | 279 |
{
|
| 317 |
#if 0 |
|
| 318 |
for (int i = 0; i < ui->treeView->selectedItems().count(); i++) {
|
|
| 280 |
QItemSelectionModel *selectionModel = ui->treeView->selectionModel(); |
|
| 281 |
Q_FOREACH(QModelIndex idx, selectionModel->selectedRows()) {
|
|
| 282 |
DownloadQueueItem *item = static_cast |
|
| 319 | 283 |
QString collection_name = ""; |
| 320 | 284 |
QString subject = ""; |
| 321 | 285 |
QString errmsg = ""; |
| 322 | 286 |
|
| 323 |
QTreeWidgetItem *item = ui->treeView->selectedItems().at(i); |
|
| 324 |
|
|
| 325 | 287 |
if (item->childCount() == 0) {
|
| 326 | 288 |
/* This is a subject */ |
| 327 |
subject = item->text(FIELD_SUBJECT); |
|
| 328 |
collection_name = item->parent()->text(FIELD_SUBJECT); |
|
| 289 |
subject = item->subject; |
|
| 290 |
collection_name = item->parent()->subject; |
|
| 329 | 291 |
} else {
|
| 330 | 292 |
/* This is a collection */ |
| 331 |
collection_name = item->text(FIELD_SUBJECT); |
|
| 293 |
collection_name = item->subject; |
|
| 332 | 294 |
} |
| 333 | 295 |
|
| 334 | 296 |
if (!glue->schedularRestartTask(collection_name, subject, errmsg)) {
|
| 335 | 297 |
qWarning(tr("Error occured while restarting file(s):\n%s").toUtf8().data(), errmsg.toUtf8().data());
|
| 336 | 298 |
} |
| 337 | 299 |
} |
| 338 |
#endif |
|
| 339 | 300 |
} |
| 340 | 301 |
|
| 341 | 302 |
void WidgetDownloadQueue::actionOpenDownloadFolder_activated(void) |
| 342 | 303 |
{
|
| 343 |
#if 0 |
|
| 344 | 304 |
QString folder = ""; |
| 345 | 305 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
| 346 | 306 |
|
| 347 |
if (ui->treeView->selectedItems().count() == 1) {
|
|
| 307 |
if (ui->treeView->selectionModel()->selectedRows().count() == 1) {
|
|
| 348 | 308 |
QString collection_name; |
| 349 |
QTreeWidgetItem *item = ui->treeView->selectedItems().at(0); |
|
| 309 |
DownloadQueueItem *item = static_cast |
|
| 350 | 310 |
|
| 351 | 311 |
if (item->childCount() == 0) {
|
| 352 | 312 |
/* This is a subject */ |
| 353 |
collection_name = item->parent()->text(FIELD_SUBJECT); |
|
| 313 |
collection_name = item->parent()->subject; |
|
| 354 | 314 |
} else {
|
| 355 |
collection_name = item->text(FIELD_SUBJECT); |
|
| 315 |
collection_name = item->subject; |
|
| 356 | 316 |
} |
| 357 | 317 |
|
| 358 | 318 |
folder = opts.download_directory + QString("/") + collection_name;
|
| ... | ... | |
| 376 | 336 |
#else |
| 377 | 337 |
QDesktopServices::openUrl(QUrl(QString("file://") + location.absoluteFilePath()));
|
| 378 | 338 |
#endif |
| 379 |
#endif |
|
| 380 | 339 |
} |
| 381 | 340 |
|
| 382 | 341 |
void WidgetDownloadQueue::actionExecuteSelectedItem_activated(void) |
| 383 | 342 |
{
|
| 384 |
#if 0 |
|
| 385 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
|
| 386 |
|
|
| 387 |
if (ui->treeView->selectedItems().count() != 1) {
|
|
| 343 |
if (ui->treeView->selectionModel()->selectedRows().count() != 1) {
|
|
| 388 | 344 |
return; |
| 389 | 345 |
} |
| 390 | 346 |
|
| 391 |
QTreeWidgetItem *item = ui->treeView->selectedItems().at(0); |
|
| 347 |
DownloadQueueItem *item = static_cast |
|
| 392 | 348 |
|
| 393 | 349 |
if (item->childCount() != 0) {
|
| 394 | 350 |
return; |
| 395 | 351 |
} |
| 396 | 352 |
|
| 397 |
QString collection_name = item->parent()->text(FIELD_SUBJECT); |
|
| 398 |
QString real_filename = item->text(FIELD_REAL_FILENAME); |
|
| 353 |
QString collection_name = item->parent()->subject; |
|
| 354 |
QString real_filename = item->realFilename; |
|
| 399 | 355 |
|
| 400 | 356 |
if (real_filename.isEmpty()) {
|
| 401 | 357 |
qWarning("%s", tr("Unable to execute file as it isn't downloaded yet").toUtf8().data());
|
| 402 | 358 |
return; |
| 403 | 359 |
} |
| 404 | 360 |
|
| 361 |
QNNTPGrabGlue::ConfigOpts opts = glue->configGetOpts(); |
|
| 405 | 362 |
QFileInfo location(QString(opts.download_directory) + QString("/") + collection_name + QString("/") + real_filename);
|
| 406 | 363 |
|
| 407 | 364 |
if (!location.exists()) {
|
| ... | ... | |
| 414 | 371 |
#else |
| 415 | 372 |
QDesktopServices::openUrl(QUrl(QString("file://") + location.absoluteFilePath()));
|
| 416 | 373 |
#endif |
| 417 |
#endif |
|
| 418 | 374 |
} |
| 419 | 375 |
|
| 420 | 376 |
void WidgetDownloadQueue::showContextMenu(const QPoint &position) |
| 421 | 377 |
{
|
| 422 |
#if 0 |
|
| 423 | 378 |
QList |
| 424 | 379 |
QAction *a = new QAction(this); |
| 425 | 380 |
|
| ... | ... | |
| 427 | 382 |
return; |
| 428 | 383 |
} |
| 429 | 384 |
|
| 430 |
if (ui->treeView->selectedItems().count() == 0) {
|
|
| 385 |
if (!ui->treeView->selectionModel()->hasSelection()) {
|
|
| 431 | 386 |
return; |
| 432 | 387 |
} |
| 433 | 388 |
|
| ... | ... | |
| 450 | 405 |
ui->actionOpenDownloadFolder->setEnabled(true); |
| 451 | 406 |
} |
| 452 | 407 |
|
| 453 |
QTreeWidgetItem *item; |
|
| 454 |
|
|
| 455 | 408 |
/* Do we have exactly one selected item and is this item already downloaded? */ |
| 456 | 409 |
ui->actionExecuteSelectedItem->setEnabled(false); |
| 457 |
if (glue->getIsStandalone() && ui->treeView->selectedItems().count() == 1) {
|
|
| 458 |
item = ui->treeView->selectedItems().at(0); |
|
| 410 |
DownloadQueueItem *item = static_cast |
|
| 411 |
if (glue->getIsStandalone() && ui->treeView->selectionModel()->selectedRows().count() == 1) {
|
|
| 412 |
if (item->stateStr == tr("Done") ||
|
|
| 413 |
item->stateStr == tr("Incomplete")) {
|
|
| 459 | 414 |
|
| 460 |
if (item->text(FIELD_STATE_STR).compare(tr("Done")) == 0 ||
|
|
| 461 |
item->text(FIELD_STATE_STR).compare(tr("Incomplete")) == 0) {
|
|
| 462 |
|
|
| 463 | 415 |
ui->actionExecuteSelectedItem->setEnabled(true); |
| 464 | 416 |
} |
| 465 | 417 |
} |
| 466 | 418 |
|
| 467 | 419 |
/* Enable the forcefully download / skip option */ |
| 468 |
item = ui->treeView->selectedItems().at(0); |
|
| 469 |
if (item->text(FIELD_STATE_STR).compare(tr("Skipped")) == 0) {
|
|
| 420 |
if (item->stateStr == tr("Skipped")) {
|
|
| 470 | 421 |
ui->actionMarkItemOptional->setText(tr("Forcefully download file(s)"));
|
| 471 | 422 |
ui->actionMarkItemOptional->setEnabled(true); |
| 472 |
} else if (item->text(FIELD_STATE_STR).compare(tr("Done")) != 0 &&
|
|
| 473 |
item->text(FIELD_STATE_STR).compare(tr("Incomplete")) != 0 &&
|
|
| 474 |
item->text(FIELD_STATE_STR).compare(tr("Not available")) != 0) {
|
|
| 423 |
} else if (item->stateStr != tr("Done") &&
|
|
| 424 |
item->stateStr != tr("Incomplete") &&
|
|
| 425 |
item->stateStr != tr("Not available")) {
|
|
| 475 | 426 |
|
| 476 | 427 |
ui->actionMarkItemOptional->setText(tr("Don't download file(s)"));
|
| 477 | 428 |
ui->actionMarkItemOptional->setEnabled(true); |
| ... | ... | |
| 482 | 433 |
QMenu::exec(actions, ui->treeView->mapToGlobal(position)); |
| 483 | 434 |
|
| 484 | 435 |
delete a; |
| 485 |
#endif |
|
| 486 | 436 |
} |
| 487 | 437 |
|
| 488 | 438 |
void WidgetDownloadQueue::hideField(DownloadQueueItem::field f) |
Also available in: Unified diff
NNTPGrab

