denisq

Untitled

Aug 1st, 2014
223
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * abstractmediawidget.cpp
  3.  *
  4.  * Copyright (C) 2010-2012 Christoph Pfister <christophpfister@gmail.com>
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License along
  17.  * with this program; if not, write to the Free Software Foundation, Inc.,
  18.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19.  */
  20.  
  21. #include "abstractmediawidget.h"
  22.  
  23. #include <QCoreApplication>
  24.  
  25. AbstractMediaWidget::AbstractMediaWidget(QWidget *parent) : QWidget(parent), mediaWidget(NULL)
  26. {
  27.     playbackStatus = MediaWidget::Idle;
  28.     currentTime = 0;
  29.     totalTime = 0;
  30.     seekable = false;
  31.     currentAudioStream = -1;
  32.     currentSubtitle = -1;
  33.     titleCount = 0;
  34.     currentTitle = -1;
  35.     chapterCount = 0;
  36.     currentChapter = -1;
  37.     angleCount = 0;
  38.     currentAngle = -1;
  39.     dvdMenu = false;
  40. }
  41.  
  42. AbstractMediaWidget::~AbstractMediaWidget()
  43. {
  44. }
  45.  
  46. void AbstractMediaWidget::connectToMediaWidget(MediaWidget *mediaWidget_)
  47. {
  48.     mediaWidget = mediaWidget_;
  49.     addPendingUpdates(PlaybackStatus | CurrentTotalTime | Seekable | Metadata | AudioStreams |
  50.         Subtitles | Titles | Chapters | Angles | DvdMenu | VideoSize);
  51. }
  52.  
  53. void AbstractMediaWidget::addPendingUpdates(PendingUpdates pendingUpdatesToBeAdded)
  54. {
  55.     while (true) {
  56.         int oldValue = pendingUpdates;
  57.         int newValue = (oldValue | pendingUpdatesToBeAdded);
  58.  
  59.         if (!pendingUpdates.testAndSetRelaxed(oldValue, newValue)) {
  60.             continue;
  61.         }
  62.  
  63.         if (oldValue == 0) {
  64.             QCoreApplication::postEvent(this, new QEvent(QEvent::User));
  65.         }
  66.  
  67.         break;
  68.     }
  69. }
  70.  
  71. void AbstractMediaWidget::customEvent(QEvent *event)
  72. {
  73.     Q_UNUSED(event)
  74.  
  75.     while (true) {
  76.         int oldValue = pendingUpdates;
  77.         int lowestPendingUpdate = (oldValue & (~(oldValue - 1)));
  78.         int newValue = (oldValue & (~lowestPendingUpdate));
  79.  
  80.         if (!pendingUpdates.testAndSetRelaxed(oldValue, newValue)) {
  81.             continue;
  82.         }
  83.  
  84.         switch (static_cast<PendingUpdate>(lowestPendingUpdate)) {
  85.         case PlaybackFinished:
  86.             mediaWidget->playbackFinished();
  87.             break;
  88.         case PlaybackStatus:
  89.             updatePlaybackStatus();
  90.             mediaWidget->playbackStatusChanged();
  91.             break;
  92.         case CurrentTotalTime:
  93.             updateCurrentTotalTime();
  94.             mediaWidget->currentTotalTimeChanged();
  95.             break;
  96.         case Seekable:
  97.             updateSeekable();
  98.             mediaWidget->seekableChanged();
  99.             break;
  100.         case Metadata:
  101.             updateMetadata();
  102.             mediaWidget->metadataChanged();
  103.             break;
  104.         case AudioStreams:
  105.             updateAudioStreams();
  106.             mediaWidget->audioStreamsChanged();
  107.             break;
  108.         case Subtitles:
  109.             updateSubtitles();
  110.             mediaWidget->subtitlesChanged();
  111.             break;
  112.         case Titles:
  113.             updateTitles();
  114.             mediaWidget->titlesChanged();
  115.             break;
  116.         case Chapters:
  117.             updateChapters();
  118.             mediaWidget->chaptersChanged();
  119.             break;
  120.         case Angles:
  121.             updateAngles();
  122.             mediaWidget->anglesChanged();
  123.             break;
  124.         case DvdMenu:
  125.             updateDvdMenu();
  126.             mediaWidget->dvdMenuChanged();
  127.             break;
  128.         case VideoSize:
  129.             updateVideoSize();
  130.             mediaWidget->videoSizeChanged();
  131.             break;
  132.         }
  133.  
  134.         if (newValue == 0) {
  135.             break;
  136.         }
  137.     }
  138. }
  139.  
  140. DummyMediaWidget::DummyMediaWidget(QWidget *parent) : AbstractMediaWidget(parent)
  141. {
  142. }
  143.  
  144. DummyMediaWidget::~DummyMediaWidget()
  145. {
  146. }
  147.  
  148. void DummyMediaWidget::setMuted(bool muted)
  149. {
  150.     Q_UNUSED(muted)
  151. }
  152.  
  153. void DummyMediaWidget::setVolume(int volume)
  154. {
  155.     Q_UNUSED(volume)
  156. }
  157.  
  158. void DummyMediaWidget::setAspectRatio(MediaWidget::AspectRatio aspectRatio)
  159. {
  160.     Q_UNUSED(aspectRatio)
  161. }
  162.  
  163. void DummyMediaWidget::setDeinterlacing(bool deinterlacing)
  164. {
  165.     Q_UNUSED(deinterlacing)
  166. }
  167.  
  168. void DummyMediaWidget::play(const MediaSource &source)
  169. {
  170.     Q_UNUSED(source)
  171. }
  172.  
  173. void DummyMediaWidget::stop()
  174. {
  175. }
  176.  
  177. void DummyMediaWidget::setPaused(bool paused)
  178. {
  179.     Q_UNUSED(paused)
  180. }
  181.  
  182. void DummyMediaWidget::seek(int time)
  183. {
  184.     Q_UNUSED(time)
  185. }
  186.  
  187. void DummyMediaWidget::setCurrentAudioStream(int currentAudioStream)
  188. {
  189.     Q_UNUSED(currentAudioStream)
  190. }
  191.  
  192. void DummyMediaWidget::setCurrentSubtitle(int currentSubtitle)
  193. {
  194.     Q_UNUSED(currentSubtitle)
  195. }
  196.  
  197. void DummyMediaWidget::setExternalSubtitle(const KUrl &subtitleUrl)
  198. {
  199.     Q_UNUSED(subtitleUrl)
  200. }
  201.  
  202. void DummyMediaWidget::setCurrentTitle(int currentTitle)
  203. {
  204.     Q_UNUSED(currentTitle)
  205. }
  206.  
  207. void DummyMediaWidget::setCurrentChapter(int currentChapter)
  208. {
  209.     Q_UNUSED(currentChapter)
  210. }
  211.  
  212. void DummyMediaWidget::setCurrentAngle(int currentAngle)
  213. {
  214.     Q_UNUSED(currentAngle)
  215. }
  216.  
  217. bool DummyMediaWidget::jumpToPreviousChapter()
  218. {
  219.     return false;
  220. }
  221.  
  222. bool DummyMediaWidget::jumpToNextChapter()
  223. {
  224.     return false;
  225. }
  226.  
  227. void DummyMediaWidget::showDvdMenu()
  228. {
  229. }
  230.  
  231. void DummyMediaWidget::updatePlaybackStatus()
  232. {
  233. }
  234.  
  235. void DummyMediaWidget::updateCurrentTotalTime()
  236. {
  237. }
  238.  
  239. void DummyMediaWidget::updateSeekable()
  240. {
  241. }
  242.  
  243. void DummyMediaWidget::updateMetadata()
  244. {
  245. }
  246.  
  247. void DummyMediaWidget::updateAudioStreams()
  248. {
  249. }
  250.  
  251. void DummyMediaWidget::updateSubtitles()
  252. {
  253. }
  254.  
  255. void DummyMediaWidget::updateTitles()
  256. {
  257. }
  258.  
  259. void DummyMediaWidget::updateChapters()
  260. {
  261. }
  262.  
  263. void DummyMediaWidget::updateAngles()
  264. {
  265. }
  266.  
  267. void DummyMediaWidget::updateDvdMenu()
  268. {
  269. }
  270.  
  271. void DummyMediaWidget::updateVideoSize()
  272. {
  273. }
RAW Paste Data