MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / addFile

Method addFile

player/NymphCastPlayer/mainwindow.cpp:815–855  ·  view source on GitHub ↗

--- ADD FILE ---

Source from the content-addressed store, hash-verified

813
814// --- ADD FILE ---
815void MainWindow::addFile() {
816 // Select file from filesystem, add to playlist.
817 // Use stored directory location, if any.
818 QSettings settings;
819 QString dir = settings.value("openFileDir").toString();
820 QStringList filenames = QFileDialog::getOpenFileNames(this, tr("Open media files"), dir);
821 if (filenames.isEmpty()) { return; }
822
823 // Update current folder.
824 settings.setValue("openFileDir", filenames[0]);
825
826
827 // Store path of added file to reload on restart. Append to file.
828 QFile playlist;
829 playlist.setFileName(appDataLocation + "/filepaths.conf");
830 playlist.open(QIODevice::WriteOnly | QIODevice::Append);
831
832 // Handle each file.
833 QTextStream textStream(&playlist);
834 textStream.setCodec("UTF-8");
835 for (int i = 0; i < filenames.size(); ++i) {
836 // Check file.
837 QFileInfo finf(filenames[i]);
838 if (!finf.isFile()) {
839 QMessageBox::warning(this, tr("Failed to open file"),
840 tr("%1 could not be opened.").arg(finf.fileName()));
841 return;
842 }
843
844 // Add to UI.
845 QListWidgetItem *newItem = new QListWidgetItem;
846 newItem->setText(finf.fileName());
847 newItem->setData(Qt::UserRole, QVariant(filenames[i]));
848 ui->mediaListWidget->addItem(newItem);
849
850 // Add to internal playlist.
851 textStream << filenames[i] << "\n";
852 }
853
854 playlist.close();
855}
856
857
858// --- REMOVE FILE ---

Callers

nothing calls this directly

Calls 8

valueMethod · 0.80
toStringMethod · 0.45
setValueMethod · 0.45
openMethod · 0.45
sizeMethod · 0.45
setTextMethod · 0.45
addItemMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected