File indexing completed on 2024-04-28 04:48:37
0001 /* 0002 SPDX-FileCopyrightText: 2008 Ian Monroe <ian@monroe.nu> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "discSelectionDialog.h" 0008 0009 #include "codeine.h" 0010 #include "mainWindow.h" 0011 #include "videoWindow.h" 0012 0013 #include <QDialogButtonBox> 0014 #include <QIcon> 0015 #include <QLabel> 0016 #include <QListWidget> 0017 #include <QListWidgetItem> 0018 #include <QVBoxLayout> 0019 0020 #include <KLocalizedString> 0021 #include <Solid/OpticalDisc> 0022 0023 class SolidListItem : public QListWidgetItem 0024 { 0025 public: 0026 SolidListItem(QListWidget *parent, const Solid::Device &device) 0027 : QListWidgetItem(parent) 0028 , m_device(device) 0029 { 0030 const Solid::OpticalDisc *disc = device.as<const Solid::OpticalDisc>(); 0031 if (disc) { 0032 const QString label = disc->label(); 0033 if (label.isEmpty()) { 0034 setText(contentTypesToString(disc->availableContent())); 0035 } else { 0036 setText(i18nc("%1 is the disc type, %2 is the name of the disc that the user can choose. Ex. 'DVD: OfficeSpace'", 0037 "%1: %2", 0038 contentTypesToString(disc->availableContent()), 0039 label)); 0040 } 0041 if (disc->availableContent() & Solid::OpticalDisc::Audio) 0042 setIcon(QIcon::fromTheme(QLatin1String("audio-x-generic"))); 0043 else 0044 setIcon(QIcon::fromTheme(QLatin1String("video-x-generic"))); 0045 } 0046 } 0047 0048 Solid::Device device() const 0049 { 0050 return m_device; 0051 } 0052 0053 static QString contentTypesToString(Solid::OpticalDisc::ContentTypes solidType) 0054 { 0055 if (solidType & Solid::OpticalDisc::VideoDvd) 0056 return i18nc("Digital Versatile Disc, but keep it short", "DVD"); 0057 else if (solidType & (Solid::OpticalDisc::VideoCd | Solid::OpticalDisc::SuperVideoCd)) 0058 return i18n("Video CD"); 0059 else if (solidType & Solid::OpticalDisc::Audio) 0060 return i18n("Audio CD"); 0061 else 0062 return i18n("Data CD"); 0063 } 0064 0065 private: 0066 const Solid::Device m_device; 0067 }; 0068 0069 DiscSelectionDialog::DiscSelectionDialog(QWidget *parent, const QList<Solid::Device> &deviceList) 0070 : QDialog(parent) 0071 , m_listWidget(new QListWidget()) 0072 { 0073 setWindowTitle(i18nc("@title:window", "Select a Disc")); 0074 0075 QLabel *questionLabel = new QLabel(i18n("Select a disc to play.")); 0076 for (const Solid::Device &device : deviceList) { 0077 new SolidListItem(m_listWidget, device); 0078 } 0079 0080 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0081 0082 QVBoxLayout *layout = new QVBoxLayout(); 0083 layout->addWidget(questionLabel); 0084 layout->addWidget(m_listWidget); 0085 layout->addWidget(bbox); 0086 setLayout(layout); 0087 0088 connect(m_listWidget, &QListWidget::itemDoubleClicked, this, &DiscSelectionDialog::discItemSelected); 0089 connect(bbox, &QDialogButtonBox::accepted, this, &DiscSelectionDialog::okClicked); 0090 connect(bbox, &QDialogButtonBox::rejected, this, &QDialog::deleteLater); 0091 // connect( bbox, &QDialogButtonBox::rejected, const_cast<QObject *>(Dragon::mainWindow()), &Dragon::MainWindow::playDisc ); // kf5 FIXME? this could have 0092 // never worked 0093 show(); 0094 } 0095 0096 void DiscSelectionDialog::discItemSelected(QListWidgetItem *item) 0097 { 0098 openItem(item); 0099 deleteLater(); 0100 } 0101 0102 void DiscSelectionDialog::okClicked() 0103 { 0104 openItem(m_listWidget->currentItem()); 0105 deleteLater(); 0106 } 0107 0108 void DiscSelectionDialog::openItem(QListWidgetItem *item) 0109 { 0110 if (item) { 0111 const SolidListItem *solidItem = static_cast<SolidListItem *>(item); 0112 Dragon::engine()->playDisc(solidItem->device()); 0113 } 0114 } 0115 0116 #include "moc_discSelectionDialog.cpp"