File indexing completed on 2024-04-28 04:48:38
0001 /* 0002 SPDX-FileCopyrightText: 2004 Max Howell <max.howell@methylblue.com> 0003 SPDX-FileCopyrightText: 2007 Ian Monroe <ian@monroe.nu> 0004 SPDX-FileCopyrightText: 2008 David Edmundson <kde@davidedmundson.co.uk> 0005 0006 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 */ 0008 0009 #include "mainWindow.h" 0010 0011 #include <KSharedConfig> 0012 #include <KToolBar> 0013 #include <QDebug> 0014 0015 #include "actions.h" 0016 #include "audioView2.h" 0017 #include "theStream.h" 0018 #include "videoWindow.h" 0019 0020 #define QT_FATAL_ASSERT 0021 0022 namespace Dragon 0023 { 0024 0025 void MainWindow::engineStateChanged(Phonon::State state) 0026 { 0027 bool const isFullScreen = toggleAction("fullscreen")->isChecked(); 0028 bool const hasMedia = TheStream::hasMedia(); 0029 0030 switch (state) { 0031 case Phonon::LoadingState: 0032 qDebug() << "Loading state"; 0033 break; 0034 case Phonon::StoppedState: 0035 qDebug() << "Stopped state"; 0036 break; 0037 case Phonon::PlayingState: 0038 qDebug() << "Playing state"; 0039 break; 0040 case Phonon::BufferingState: 0041 qDebug() << "Buffering state"; 0042 break; 0043 case Phonon::PausedState: 0044 qDebug() << "Paused state"; 0045 break; 0046 case Phonon::ErrorState: 0047 qDebug() << "Error state"; 0048 break; 0049 } 0050 0051 bool enable = engine()->isActiveState(state); 0052 action(QStringLiteral("stop"))->setEnabled(enable); 0053 action(QStringLiteral("video_settings"))->setEnabled(enable && TheStream::hasVideo()); 0054 action(QStringLiteral("volume"))->setEnabled(enable); 0055 if (m_volumeSlider) 0056 m_volumeSlider->setEnabled(enable); 0057 action(QStringLiteral("fullscreen"))->setEnabled(enable || isFullScreen); 0058 action(QStringLiteral("reset_zoom"))->setEnabled(hasMedia && !isFullScreen); 0059 action(QStringLiteral("prev_chapter"))->setEnabled(engine()->canGoPrev()); 0060 action(QStringLiteral("next_chapter"))->setEnabled(engine()->canGoNext()); 0061 0062 m_timeLabel->setVisible(enable); 0063 m_audioView->enableDemo(!enable); 0064 0065 if (!enable) { 0066 // Force out of full screen. 0067 if (isFullScreen) { 0068 setFullScreen(false); 0069 } 0070 } 0071 0072 if (!m_currentWidget && state == Phonon::PlayingState) { 0073 if (TheStream::hasVideo()) { 0074 m_currentWidget = engine(); 0075 } else { 0076 m_currentWidget = m_audioView; 0077 } 0078 toggleLoadView(); 0079 } 0080 0081 qDebug() << "updated actions"; 0082 0083 /// update menus 0084 { 0085 // the toolbar play button is always enabled, but the menu item 0086 // is disabled if we are empty, this looks more sensible 0087 PlayAction *playAction = static_cast<PlayAction *>(actionCollection()->action(QLatin1String("play"))); 0088 playAction->setEnabled(hasMedia); 0089 playAction->setPlaying(state == Phonon::PlayingState || state == Phonon::BufferingState); 0090 actionCollection()->action(QLatin1String("aspect_ratio_menu"))->setEnabled((enable) && TheStream::hasVideo()); 0091 0092 // set correct aspect ratio 0093 if (state != Phonon::LoadingState) 0094 TheStream::aspectRatioAction()->setChecked(true); 0095 } 0096 qDebug() << "updated menus"; 0097 0098 /// turn off screensaver 0099 if (state == Phonon::PlayingState) 0100 inhibitPowerSave(); 0101 else if (state == Phonon::StoppedState || !TheStream::hasMedia()) 0102 releasePowerSave(); 0103 0104 updateTitleBarText(); 0105 0106 // enable/disable DVD specific buttons 0107 QWidget *dvd_button = toolBar()->findChild<QWidget *>(QLatin1String("toolbutton_toggle_dvd_menu")); 0108 if (videoWindow()->isDVD()) { 0109 if (dvd_button) { 0110 dvd_button->setVisible(true); 0111 } 0112 action(QStringLiteral("toggle_dvd_menu"))->setEnabled(true); 0113 } else { 0114 if (dvd_button) { 0115 dvd_button->setVisible(false); 0116 } 0117 action(QStringLiteral("toggle_dvd_menu"))->setEnabled(false); 0118 } 0119 } // engineStateChanged 0120 0121 void MainWindow::engineMediaChanged(Phonon::MediaSource /*newSource*/) 0122 { 0123 m_audioView->update(); 0124 0125 // update recently played list 0126 qDebug() << " update recent files list "; 0127 0128 Q_EMIT fileChanged(engine()->urlOrDisc()); 0129 // TODO fetch this from the Media source 0130 QUrl const &url = TheStream::url(); 0131 const QString url_string = url.url(); 0132 0133 #ifndef NO_SKIP_PR0N 0134 // ;-) 0135 if (!(url_string.contains(QLatin1String("porn"), Qt::CaseInsensitive) || url_string.contains(QLatin1String("pr0n"), Qt::CaseInsensitive))) { 0136 #endif 0137 if (url.scheme() != QLatin1String("dvd") && url.scheme() != QLatin1String("vcd") && !url.toDisplayString().isEmpty()) { 0138 qobject_cast<KRecentFilesAction *>(action(QStringLiteral("file_open_recent")))->addUrl(url); 0139 } 0140 #ifndef NO_SKIP_PR0N 0141 } 0142 #endif 0143 0144 } // engineMediaChanged 0145 0146 void MainWindow::engineSeekableChanged(bool canSeek) 0147 { 0148 qDebug() << "seekable changed to " << canSeek; 0149 m_positionSlider->setEnabled(canSeek); 0150 action(QStringLiteral("ten_percent_back"))->setEnabled(canSeek); 0151 action(QStringLiteral("ten_percent_forward"))->setEnabled(canSeek); 0152 action(QStringLiteral("ten_seconds_back"))->setEnabled(canSeek); 0153 action(QStringLiteral("ten_seconds_forward"))->setEnabled(canSeek); 0154 // TODO connect/disconnect the jump forward/back here. 0155 } // engineSeekableChanged 0156 0157 void MainWindow::engineMetaDataChanged() 0158 { 0159 qDebug() << "metaDataChanged"; // FIXME Phonon emits metadataChanged() too often :/ 0160 qDebug() << "Disc ID:" << TheStream::discId(); 0161 updateTitleBarText(); 0162 if (!TheStream::hasVideo()) 0163 m_audioView->update(); 0164 } 0165 0166 void MainWindow::engineHasVideoChanged(bool hasVideo) 0167 { 0168 Q_UNUSED(hasVideo); 0169 0170 qDebug() << "hasVideo changed" << hasVideo; 0171 if (TheStream::hasVideo()) { 0172 if (m_mainView->indexOf(engine()) == -1) 0173 m_mainView->addWidget(engine()); 0174 m_mainView->setCurrentWidget(engine()); 0175 m_currentWidget = engine(); 0176 0177 // Fake change of state to trigger a re-evaluation of enabled actions. 0178 // The video state might have changed *after* a state change (e.g. in Phonon-VLC) 0179 // in which case the video related menu actions will not be enabled until 0180 // a new state change occurs. By forcing a fake state change we can work around this. 0181 engineStateChanged(videoWindow()->state()); 0182 } else if (engine()->isActiveState()) { 0183 m_audioView->setupAnalyzer(); 0184 m_mainView->setCurrentWidget(m_audioView); 0185 m_currentWidget = m_audioView; 0186 } 0187 0188 if (TheStream::hasVideo()) { 0189 inhibitPowerSave(); 0190 // Assumption: since we have no playlist the only way to release suppression 0191 // is through going into stopped state. This also means that should there 0192 // ever be a playlist playing video and then audio will possibly not 0193 // release video specific inhibitions. 0194 } 0195 } 0196 0197 } // namespace