--- SCAN FOR SHARES ---
| 1367 | |
| 1368 | // --- SCAN FOR SHARES --- |
| 1369 | void MainWindow::scanForShares() { |
| 1370 | // Scan for media server instances on the network. |
| 1371 | std::vector<NymphCastRemote> mediaservers = client.findShares(); |
| 1372 | if (mediaservers.empty()) { |
| 1373 | QMessageBox::warning(this, tr("No media servers found."), tr("No media servers found.")); |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | // For each media server, request the shared file list. |
| 1378 | sharesModel.clear(); |
| 1379 | mediaFiles.clear(); |
| 1380 | QStandardItem* parentItem = sharesModel.invisibleRootItem(); |
| 1381 | for (uint32_t i = 0; i < mediaservers.size(); ++i) { |
| 1382 | std::vector<NymphMediaFile> files = client.getShares(mediaservers[i]); |
| 1383 | if (files.empty()) { continue; } |
| 1384 | |
| 1385 | // Insert into model. Use the media server's host name as top folder, with the shared |
| 1386 | // files inserted underneath it in their respective media type categories. |
| 1387 | // TODO: Use the provided media item categories within the UI. |
| 1388 | QStandardItem* item = new QStandardItem(QString::fromStdString(mediaservers[i].name)); |
| 1389 | item->setSelectable(false); |
| 1390 | QStandardItem* audioRoot = new QStandardItem("audio"); |
| 1391 | QStandardItem* videoRoot = new QStandardItem("video"); |
| 1392 | //QStandardItem* imageRoot = new QStandardItem("image"); |
| 1393 | QStandardItem* playlistRoot = new QStandardItem("playlist"); |
| 1394 | audioRoot->setSelectable(false); |
| 1395 | videoRoot->setSelectable(false); |
| 1396 | playlistRoot->setSelectable(false); |
| 1397 | for (uint32_t j = 0; j < files.size(); ++j) { |
| 1398 | if (files[j].type == FILE_TYPE_IMAGE) { continue; } |
| 1399 | QStandardItem* fn = new QStandardItem(QString::fromStdString(files[j].name)); |
| 1400 | QList<QVariant> ids; |
| 1401 | ids.append(QVariant(i)); |
| 1402 | ids.append(QVariant(j)); |
| 1403 | ids.append(QVariant(files[j].id)); |
| 1404 | mediaFiles.push_back(files); |
| 1405 | ids.append(QVariant((uint32_t) mediaFiles.size())); |
| 1406 | |
| 1407 | fn->setData(QVariant(ids), Qt::UserRole); |
| 1408 | //item->appendRow(fn); |
| 1409 | if (files[j].type == FILE_TYPE_AUDIO) { audioRoot->appendRow(fn); } |
| 1410 | else if (files[j].type == FILE_TYPE_VIDEO) { videoRoot->appendRow(fn); } |
| 1411 | else if (files[j].type == FILE_TYPE_PLAYLIST) { playlistRoot->appendRow(fn); } |
| 1412 | } |
| 1413 | |
| 1414 | item->appendRow(audioRoot); |
| 1415 | item->appendRow(videoRoot); |
| 1416 | //item->appendRow(imageRoot); |
| 1417 | item->appendRow(playlistRoot); |
| 1418 | parentItem->appendRow(item); |
| 1419 | |
| 1420 | // Expand each root item. |
| 1421 | ui->sharesTreeView->setExpanded(sharesModel.indexFromItem(item), true); |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | |
| 1426 | // --- PLAY SELECTED SHARE -- |