1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 /* 4 Rosegarden 5 A MIDI and audio sequencer and musical notation editor. 6 Copyright 2000-2021 the Rosegarden development team. 7 8 Other copyrights also apply to some parts of this work. Please 9 see the AUTHORS file and individual file headers for details. 10 11 This program is free software; you can redistribute it and/or 12 modify it under the terms of the GNU General Public License as 13 published by the Free Software Foundation; either version 2 of the 14 License, or (at your option) any later version. See the file 15 COPYING included with this distribution for more information. 16 */ 17 18 19 #include "UnusedAudioSelectionDialog.h" 20 21 22 #include <QDialog> 23 #include <QDialogButtonBox> 24 #include <QTableWidget> 25 #include <QFileInfo> 26 #include <QLabel> 27 #include <QTableWidget> 28 #include <QTableWidgetItem> 29 #include <QString> 30 #include <QWidget> 31 #include <QVBoxLayout> 32 #include <QDateTime> 33 #include <iostream> 34 35 36 namespace Rosegarden 37 { 38 39 40 UnusedAudioSelectionDialog::UnusedAudioSelectionDialog(QWidget *parent, 41 QString introductoryText, 42 std::vector<QString> fileNames 43 ) : ares_parse_a_reply(const unsigned char * abuf,int alen,struct hostent ** host,struct ares_addrttl * addrttls,int * naddrttls)44 QDialog(parent) 45 { 46 setModal(true); 47 setWindowTitle(tr("Select Unused Audio Files")); 48 49 QVBoxLayout *layout = new QVBoxLayout; 50 setLayout(layout); 51 52 layout->addWidget(new QLabel(introductoryText)); 53 54 m_listView = new QTableWidget; 55 layout->addWidget(m_listView); 56 57 m_listView->setColumnCount(3); 58 QStringList sl; 59 sl << tr("File name") << tr("File size") << tr("Last modified date"); 60 m_listView->setHorizontalHeaderLabels(sl); 61 62 QTableWidgetItem *item = nullptr; 63 unsigned int i; 64 unsigned int rc; 65 for (i = 0; i < fileNames.size(); i++) { 66 QString fileName = fileNames[i]; 67 QFileInfo info(fileName); 68 QString fileSize = tr(" (not found) "); 69 QString fileDate; 70 if (info.exists()) { 71 fileSize = QString(" %1 ").arg(info.size()); 72 fileDate = QString(" %1 ").arg((info.lastModified()).toString(Qt::ISODate)); 73 } 74 rc = m_listView->rowCount(); 75 m_listView->insertRow(rc); 76 77 item = new QTableWidgetItem(fileName); 78 m_listView->setItem(rc, 0, item); 79 item = new QTableWidgetItem(fileSize); 80 m_listView->setItem(rc, 1, item); 81 item = new QTableWidgetItem(fileDate); 82 m_listView->setItem(rc, 2, item); 83 84 } 85 86 m_listView->setSelectionMode(QAbstractItemView::MultiSelection); 87 m_listView->setSelectionBehavior(QAbstractItemView::SelectRows); 88 89 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 90 layout->addWidget(buttonBox); 91 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 92 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 93 }; 94 95 std::vector<QString> 96 UnusedAudioSelectionDialog::getSelectedAudioFileNames() const 97 { 98 std::vector<QString> selectedNames; 99 100 QList<QTableWidgetItem *> sItems = m_listView->selectedItems(); 101 QTableWidgetItem *item; 102 103 for (int i = 0; i < sItems.size(); i++) { 104 item = sItems.at(i); 105 // Only reutrn items from column 0, which contains the filename 106 // we're after: 107 if (item->column() == 0) selectedNames.push_back(item->text()); 108 } 109 110 return selectedNames; 111 }; 112 113 114 } 115