]> Some of my projects - aniplayer-old.git/commitdiff
- Add option to build without anidbudpclient
authorAPTX <APTX@.(none)>
Mon, 27 Apr 2009 12:55:54 +0000 (14:55 +0200)
committerAPTX <APTX@.(none)>
Mon, 27 Apr 2009 12:55:54 +0000 (14:55 +0200)
- Basic custom SeekSlider

aniplayer.pro
lib/anidbudpclient/anidbudpclient.h
lib/anidbudpclient/anidbudpclient_global.h
src/menu.cpp
src/menu.h
src/seekslider.cpp [new file with mode: 0644]
src/seekslider.h [new file with mode: 0644]
src/src.pro
src/videowindow.cpp
src/videowindow.h

index 6e173eb66d7f2fd1318fd1fabc3cfaca393fc50e..be5b0e652909633559b268512841a0b99d261a5c 100644 (file)
@@ -4,5 +4,7 @@ TEMPLATE = subdirs
 #CONFIG += browserplugin
 #CONFIG += static
 
+
+
 SUBDIRS +=  lib \
             src
index 28c681a9cd69cdf33e3bf50c6967e039856b2e0b..7a7da46dab7aa8a4478649006b256519d0796fdb 100644 (file)
@@ -17,11 +17,6 @@ class QTimer;
 class AbstractCommand;
 class AuthCommand;
 
-
-#define CLIENT_NAME "anidbudpclient"
-#define CLIENT_VERSION 0x000001
-#define PROTOCOL_VERSION 3
-
 class ANIDBUDPCLIENTSHARED_EXPORT AniDBUdpClient : public QObject
 {
        Q_OBJECT
index 2b578d2209c7e911d9571f6abe9e67c758930ed4..a0a429ae539e47e888e9f8f6efd71e4d4b811a30 100644 (file)
@@ -3,6 +3,10 @@
 
 #include <QtCore/qglobal.h>
 
+#define CLIENT_NAME "anidbudpclient"
+#define CLIENT_VERSION 0x000001
+#define PROTOCOL_VERSION 3
+
 #if defined(ANIDBUDPCLIENT_LIBRARY)
 #  define ANIDBUDPCLIENTSHARED_EXPORT Q_DECL_EXPORT
 #else
index 4337680a0376c419d03b940cf92a82b0a57ee2d1..e47c05a308a9f588c5df7011da4fe784478965da 100644 (file)
@@ -5,7 +5,7 @@
 #      include <phonon/seekslider.h>
 #      include <phonon/volumeslider.h>
 #else
-#      include <Phonon>
+#      include <Phonon/phonon>
 #endif
 
 #include <QHBoxLayout>
@@ -13,6 +13,8 @@
 #include <QTime>
 #include <QLabel>
 
+#include "seekslider.h"
+
 Menu::Menu(QWidget *parent)
        : QMainWindow(parent), ui(new Ui::MenuClass), dragged(false)
 {
@@ -27,13 +29,14 @@ Menu::Menu(QWidget *parent)
 
        QWidget *playBarContents = new QWidget(ui->playBar);
 
-       m_seekSlider = new Phonon::SeekSlider(playBarContents);
+//     m_seekSlider = new Phonon::SeekSlider(playBarContents);
+       m_seekSlider = new SeekSlider(playBarContents);
        m_volumeSlider = new Phonon::VolumeSlider(playBarContents);
 
        m_seekSlider->setMinimumWidth(100);
        m_volumeSlider->setMinimumWidth(50);
 
-       timeLabel = new QLabel("0", this);
+       timeLabel = new QLabel("0:00:00 / 0:00:00", this);
 
        QHBoxLayout *layout = new QHBoxLayout(playBarContents);
        layout->addWidget(m_seekSlider, 5);
@@ -56,7 +59,7 @@ void Menu::addActions(QList<QAction *> actions)
        ui->mainToolBar->addActions(actions);
 }
 
-Phonon::SeekSlider *Menu::seekSlider() const
+SeekSlider *Menu::seekSlider() const
 {
        return m_seekSlider;
 }
index c22ef976dd71bea1ae1777a1eb653fbf8967cce5..9b2a2ffb60be5c672c0f9a5f0e2ce9a3e60f8699 100644 (file)
@@ -17,6 +17,7 @@ namespace Phonon
 
 class QMouseEvent;
 class QLabel;
+class SeekSlider;
 
 class Menu : public QMainWindow
 {
@@ -28,7 +29,7 @@ public:
 
        void addActions(QList<QAction *> actions);
 
-       Phonon::SeekSlider *seekSlider() const;
+       SeekSlider *seekSlider() const;
        Phonon::VolumeSlider *volumeSlider() const;
 
 public slots:
@@ -48,7 +49,8 @@ protected:
 
 private:
     Ui::MenuClass *ui;
-       Phonon::SeekSlider *m_seekSlider;
+//     Phonon::SeekSlider *m_seekSlider;
+       SeekSlider *m_seekSlider;
        Phonon::VolumeSlider *m_volumeSlider;
 
 
diff --git a/src/seekslider.cpp b/src/seekslider.cpp
new file mode 100644 (file)
index 0000000..313952f
--- /dev/null
@@ -0,0 +1,148 @@
+#include "seekslider.h"
+
+#include <QEvent>
+#include <QMouseEvent>
+#include "aniplayer.h"
+
+SeekSlider::SeekSlider(QWidget *parent) : QSlider(parent)
+{
+       ticking = false;
+       setOrientation(Qt::Horizontal);
+}
+
+SeekSlider::SeekSlider(Phonon::MediaObject *mo, QWidget *parent) : QSlider(parent)
+{
+       ticking = false;
+       setOrientation(Qt::Horizontal);
+       setMediaObject(mo);
+}
+
+SeekSlider::~SeekSlider()
+{
+
+}
+
+void SeekSlider::setMediaObject(Phonon::MediaObject *media)
+{
+       if (m_media)
+       {
+               disconnect(m_media, 0, this, 0);
+       }
+       m_media = media;
+
+       if (m_media)
+       {
+               connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(stateChanged(Phonon::State)));
+               connect(m_media, SIGNAL(totalTimeChanged(qint64)), SLOT(length(qint64)));
+               connect(m_media, SIGNAL(tick(qint64)), SLOT(tick(qint64)));
+               connect(m_media, SIGNAL(seekableChanged(bool)), SLOT(seekableChanged(bool)));
+               connect(m_media, SIGNAL(currentSourceChanged(const Phonon::MediaSource&)), SLOT(currentSourceChanged()));
+               connect(this, SIGNAL(valueChanged(int)), SLOT(seek(int)));
+               stateChanged(m_media->state());
+               seekableChanged(m_media->isSeekable());
+               length(m_media->totalTime());
+       }
+       else
+       {
+               stateChanged(Phonon::StoppedState);
+               seekableChanged(false);
+       }
+}
+
+Phonon::MediaObject *SeekSlider::mediaObject() const
+{
+       return m_media;
+}
+
+void SeekSlider::seek(int msec)
+{
+       if (!ticking && m_media)
+       {
+               m_media->seek(msec);
+       }
+}
+
+void SeekSlider::tick(qint64 msec)
+{
+       ticking = true;
+       setValue(msec);
+       ticking = false;
+}
+
+void SeekSlider::length(qint64 msec)
+{
+       ticking = true;
+       setRange(0, msec);
+       ticking = false;
+}
+
+void SeekSlider::seekableChanged(bool isSeekable)
+{
+       if (!isSeekable || !m_media)
+       {
+               setEnabled(false);
+       }
+       else
+       {
+               switch (m_media->state())
+               {
+               case Phonon::PlayingState:
+                       if (m_media->tickInterval() == 0)
+                       {
+                               // if the tick signal is not enabled the slider is useless
+                               // set the tickInterval to some common value
+                               m_media->setTickInterval(350);
+                       }
+               case Phonon::BufferingState:
+               case Phonon::PausedState:
+                       setEnabled(true);
+                       break;
+               case Phonon::StoppedState:
+               case Phonon::LoadingState:
+               case Phonon::ErrorState:
+                       setEnabled(false);
+                       ticking = true;
+                       setValue(0);
+                       ticking = false;
+                       break;
+               }
+       }
+}
+
+void SeekSlider::currentSourceChanged()
+{
+       //this releases the mouse and makes the seek slider stop seeking if the current source has changed
+       QMouseEvent event(QEvent::MouseButtonRelease, QPoint(), Qt::LeftButton, 0, 0);
+//     QApplication::sendEvent(this, &event);
+}
+
+void SeekSlider::stateChanged(Phonon::State newState)
+{
+       if (!m_media || !m_media->isSeekable())
+       {
+               setEnabled(false);
+               return;
+       }
+       switch (newState)
+       {
+       case Phonon::PlayingState:
+               if (m_media->tickInterval() == 0)
+               {
+                       // if the tick signal is not enabled the slider is useless
+                       // set the tickInterval to some common value
+                       m_media->setTickInterval(350);
+               }
+       case Phonon::BufferingState:
+       case Phonon::PausedState:
+               setEnabled(true);
+               break;
+       case Phonon::StoppedState:
+       case Phonon::LoadingState:
+       case Phonon::ErrorState:
+               setEnabled(false);
+               ticking = true;
+               setValue(0);
+               ticking = false;
+               break;
+       }
+}
diff --git a/src/seekslider.h b/src/seekslider.h
new file mode 100644 (file)
index 0000000..0077502
--- /dev/null
@@ -0,0 +1,70 @@
+#ifndef SEEKSLIDER_H
+#define SEEKSLIDER_H
+
+#include <QSlider>
+#include <QPointer>
+#include <Phonon/MediaObject>
+
+class SeekSlider : public QSlider
+{
+       Q_OBJECT
+
+       Q_DISABLE_COPY(SeekSlider);
+/*
+       Q_PROPERTY(bool tracking READ hasTracking WRITE setTracking)
+       Q_PROPERTY(int pageStep READ pageStep WRITE setPageStep)
+       Q_PROPERTY(int singleStep READ singleStep WRITE setSingleStep)
+       Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
+*/
+public:
+       explicit SeekSlider(QWidget *parent = 0);
+       explicit SeekSlider(Phonon::MediaObject *media, QWidget *parent = 0);
+       ~SeekSlider();
+
+/*     bool hasTracking() const;
+       void setTracking(bool tracking);
+       int pageStep() const;
+       void setPageStep(int milliseconds);
+       int singleStep() const;
+       void setSingleStep(int milliseconds);
+       Qt::Orientation orientation() const;
+*/
+       Phonon::MediaObject *mediaObject() const;
+
+
+/*     QSize sizeHint() const;
+       QSize minimumSizeHint() const;
+
+       bool event(QEvent *event);
+*/
+public slots:
+//     void setOrientation(Qt::Orientation o);
+
+       void setMediaObject(Phonon::MediaObject *m);
+/*
+protected:
+       void paintEvent(QPaintEvent *ev);
+       void mousePressEvent(QMouseEvent *ev);
+       void mouseReleaseEvent(QMouseEvent *ev);
+       void mouseMoveEvent(QMouseEvent *ev);
+       void initStyleOption(QStyleOptionSlider *option) const;
+*/
+private slots:
+       void stateChanged(Phonon::State newState);
+       void seek(int msec);
+       void tick(qint64 msec);
+       void length(qint64 msec);
+       void seekableChanged(bool isSeekable);
+       void currentSourceChanged();
+
+private:
+       QPointer<Phonon::MediaObject> m_media;
+       bool ticking;
+
+       bool m_tracking;
+       int m_pageStep;
+       int m_singleStep;
+       Qt::Orientation m_orientation;
+};
+
+#endif // SEEKSLIDER_H
index a5762408ea45ca30bbaf6dd29c28ef30ef8e3696..a4b95178d26a0fa3a4fe5bf981fae8c693144837 100644 (file)
@@ -1,6 +1,7 @@
 # -------------------------------------------------
 # Project created by QtCreator 2009-02-11T10:09:59
 # -------------------------------------------------
+CONFIG += use_anidbudpclient
 QT += phonon
 unix { 
     message(Using system (KDE?) Phonon)
@@ -21,7 +22,8 @@ SOURCES += main.cpp \
     directoryplaylist.cpp \
     anidbconfigdialog.cpp \
     episodevotedialog.cpp \
-    versiondialog.cpp
+    versiondialog.cpp \
+    seekslider.cpp
 HEADERS += menu.h \
     videowindow.h \
     videowidget.h \
@@ -31,14 +33,13 @@ HEADERS += menu.h \
     anidbconfigdialog.h \
     episodevotedialog.h \
     versiondialog.h \
-    constants.h
+    constants.h \
+    seekslider.h
 FORMS += menu.ui \
     anidbconfigdialog.ui \
     episodevotedialog.ui
 win32:RC_FILE += aniplayer.rc
 browserplugin { 
-    win32:
-    
     # CONFIG += qaxserver
     include(../lib/browserplugin-solution/src/qtbrowserplugin.pri)
     DESTDIR = ../browserplugin_build/
@@ -64,4 +65,11 @@ static {
 }
 REV = $$system(git show-ref -s HEAD)
 DEFINES += REVISION=\"$${REV}\"
-include(../lib/anidbudpclient/anidbudpclient.pri)
+use_anidbudpclient { 
+    message(Building with AniDBUdpClient!)
+    include(../lib/anidbudpclient/anidbudpclient.pri)
+}
+!use_anidbudpclient { 
+    message(Building without AniDBUdpClient!)
+    DEFINES += NO_ANIDBUDPCLIENT
+}
index 1478e509c7ca0722053cc94854b4adb74b8aefda..5d8d2d051e4a24d3746c913ac213e6064fcf90ae 100644 (file)
 #include "directoryplaylist.h"
 #include "anidbconfigdialog.h"
 #include "versiondialog.h"
+#include "seekslider.h"
 
-#include <anidbudpclient.h>
-#include <rawcommand.h>
-#include <mylistaddcommand.h>
+#ifndef NO_ANIDBUDPCLIENT
+#  include <anidbudpclient.h>
+#  include <rawcommand.h>
+#  include <mylistaddcommand.h>
+#endif
 
 #include <QDebug>
 
 VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent)
 #ifdef BROWSERPLUGIN_BUILD
        , QtNPBindable()
+#  ifdef QAXSERVER
+       , QAxBindable()
+#  endif
 #endif
 {
-       anidb = new AniDBUdpClient(this);
-
 
 #ifdef Q_WS_X11
        setFocusPolicy(Qt::StrongFocus);
 #endif
        resize(640, 480);
 
-       addCommand = 0;
        destroyed = menuMoving = windowMoving = m_closeOnStop = false;
+       m_currentFile = "";
+
+#ifndef NO_ANIDBUDPCLIENT
+       anidb = new AniDBUdpClient(this);
+       addCommand = 0;
        m_marked = true;
        m_automark = 0;
-       m_currentFile = "";
+#endif
 
 
        mediaObject = new Phonon::MediaObject(this);
@@ -94,8 +102,10 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent)
        m_actions["togglePinMenu"]->setChecked(true);
        m_actions["toggleStayOnTop"]->setChecked(false);
 #endif
+#ifndef NO_ANIDBUDPCLIENT
        addAction("markWatched", "Mark Watched", QKeySequence("CTRL+M"));
        addAction("settings", "Settings", QKeySequence("F7"));
+#endif
        addAction("about", "About", QKeySequence());
 
        menu = new Menu(this);
@@ -118,9 +128,10 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent)
 
        connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(handleStateChange(Phonon::State,Phonon::State)));
        connect(mediaController, SIGNAL(availableSubtitlesChanged()), this, SLOT(updateSubtitles()));
-
+#ifndef NO_ANIDBUDPCLIENT
        connect(m_actions["markWatched"], SIGNAL(triggered()), this, SLOT(markWatched()));
        connect(m_actions["settings"], SIGNAL(triggered()), this, SLOT(anidbSettings()));
+#endif
        connect(m_actions["about"], SIGNAL(triggered()), this, SLOT(about()));
 
        connect(m_actions["open"], SIGNAL(triggered()), this, SLOT(open()));
@@ -165,9 +176,11 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent)
 
        loadSettings();
 
+#ifndef NO_ANIDBUDPCLIENT
        anidb->setCompression(true);
        anidb->setIdlePolicy(AniDBUdpClient::LogoutIdlePolicy);
-qDebug() << m_currentFile;
+#endif
+
        open(m_currentFile);
 }
 
@@ -231,7 +244,7 @@ void VideoWindow::open(const QString &file, bool closeOnStop)
 {
        if (file == "")
                return;
-qDebug() << "open => " << file;
+
        QFileInfo fileInfo(file);
        if (!fileInfo.exists())
        {
@@ -421,12 +434,14 @@ qDebug() << "Media changed state from" << oldstate << "to" << newstate;
                        if (!isFullScreen())
                                resizeToVideo();
 #endif
+#ifndef NO_ANIDBUDPCLIENT
                        if (!m_marked)
                                addCommand->deleteLater();
 
                        addCommand = new MylistAddCommand(m_currentFile, this);
                        m_marked = false;
-               break;
+#endif
+                       break;
                case Phonon::PlayingState:
                        if (newstate == Phonon::PausedState && mediaObject->remainingTime() == 0)
                        {
@@ -441,6 +456,7 @@ void VideoWindow::tick(qint64 time)
 {
        menu->tick(time);
 
+#ifndef NO_ANIDBUDPCLIENT
        if (!m_automark || m_marked)
                return;
 
@@ -450,6 +466,7 @@ void VideoWindow::tick(qint64 time)
 
        markWatched();
        m_marked = true;
+#endif
 }
 
 void VideoWindow::updateChapters()
@@ -588,6 +605,7 @@ void VideoWindow::moveWithMenu()
        menuMoving = false;
 }
 
+#ifndef NO_ANIDBUDPCLIENT
 void VideoWindow::markWatched()
 {
        if (!addCommand)
@@ -657,6 +675,7 @@ void VideoWindow::anidbSettings()
        anidb->setPass(dialog.pass());
        m_automark = dialog.automark();
 }
+#endif
 
 void VideoWindow::addAction(const QString &name, const QString &text, const QKeySequence &shortcut, bool checkable)
 {
@@ -703,7 +722,7 @@ void VideoWindow::saveSettings()
                settings.setValue("state", menu->saveState());
                settings.setValue("isVisible", menu->isVisible());
        settings.endGroup();
-
+#  ifdef ANIDBUDPCLIENT
        settings.beginGroup("anidbudpapiclient");
                settings.setValue("host", anidb->host());
                settings.setValue("hostPort", anidb->hostPort());
@@ -712,6 +731,7 @@ void VideoWindow::saveSettings()
                settings.setValue("pass", anidb->pass());
                settings.setValue("automark", m_automark);
        settings.endGroup();
+#  endif
 #endif
 }
 
@@ -733,7 +753,7 @@ void VideoWindow::loadSettings()
                menu->restoreState(settings.value("state", menu->saveState()).toByteArray());
                menu->setVisible(settings.value("isVisible", true).toBool());
        settings.endGroup();
-
+#  ifdef ANIDBUDPCLIENT
        settings.beginGroup("anidbudpapiclient");
                anidb->setHost(settings.value("host", "api.anidb.info").toString());
                anidb->setHostPort(settings.value("hostPort", 9000).toInt());
@@ -742,6 +762,7 @@ void VideoWindow::loadSettings()
                anidb->setPass(settings.value("pass").toString());
                m_automark = settings.value("automark", 0).toInt();
        settings.endGroup();
+#  endif
 #endif
 }
 
index 3966cd1c9d984ffa854dece965386be07575ba29..6258fc4f15adcb2a834dabbf720343aec3de1606 100644 (file)
@@ -9,7 +9,7 @@
 #      include <phonon/seekslider.h>
 #      include <phonon/volumeslider.h>
 #else
-#      include <Phonon>
+#      include <Phonon/phonon>
 #endif
 
 #ifdef GRAPHICS_VIEW_VIDEO
 class VideoWidget;
 class Menu;
 class DirectoryPlaylist;
+
+#ifndef NO_ANIDBUDPCLIENT
 class AniDBUdpClient;
 class MylistAddCommand;
+#endif
 
 class VideoWindow : public QMainWindow
 #ifdef BROWSERPLUGIN_BUILD
@@ -112,12 +115,13 @@ private slots:
        void updateChapters();
        void updateSubtitles();
 
+#ifndef NO_ANIDBUDPCLIENT
        void markWatched();
        void doMarkWatched();
        void showMarkResult(bool success);
 
        void anidbSettings();
-
+#endif
 private:
        void addAction(const QString &name, const QString &text, const QKeySequence &shortcut = QKeySequence(), bool checkable = false);
 
@@ -160,12 +164,15 @@ private:
 
        bool m_closeOnStop;
 
+#ifndef NO_ANIDBUDPCLIENT
        int m_automark;
        bool m_marked;
-
-       DirectoryPlaylist *playlist;
        AniDBUdpClient *anidb;
        MylistAddCommand *addCommand;
+#endif
+
+       DirectoryPlaylist *playlist;
+
 
 #ifdef BROWSERPLUGIN_BUILD
        virtual bool readData( QIODevice *source, const QString &format);