From: APTX Date: Mon, 27 Apr 2009 12:55:54 +0000 (+0200) Subject: - Add option to build without anidbudpclient X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=20a8d01af9ed18053d2326494124e6b2bfd6b48d;p=aniplayer-old.git - Add option to build without anidbudpclient - Basic custom SeekSlider --- diff --git a/aniplayer.pro b/aniplayer.pro index 6e173eb..be5b0e6 100644 --- a/aniplayer.pro +++ b/aniplayer.pro @@ -4,5 +4,7 @@ TEMPLATE = subdirs #CONFIG += browserplugin #CONFIG += static + + SUBDIRS += lib \ src diff --git a/lib/anidbudpclient/anidbudpclient.h b/lib/anidbudpclient/anidbudpclient.h index 28c681a..7a7da46 100644 --- a/lib/anidbudpclient/anidbudpclient.h +++ b/lib/anidbudpclient/anidbudpclient.h @@ -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 diff --git a/lib/anidbudpclient/anidbudpclient_global.h b/lib/anidbudpclient/anidbudpclient_global.h index 2b578d2..a0a429a 100644 --- a/lib/anidbudpclient/anidbudpclient_global.h +++ b/lib/anidbudpclient/anidbudpclient_global.h @@ -3,6 +3,10 @@ #include +#define CLIENT_NAME "anidbudpclient" +#define CLIENT_VERSION 0x000001 +#define PROTOCOL_VERSION 3 + #if defined(ANIDBUDPCLIENT_LIBRARY) # define ANIDBUDPCLIENTSHARED_EXPORT Q_DECL_EXPORT #else diff --git a/src/menu.cpp b/src/menu.cpp index 4337680..e47c05a 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -5,7 +5,7 @@ # include # include #else -# include +# include #endif #include @@ -13,6 +13,8 @@ #include #include +#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 actions) ui->mainToolBar->addActions(actions); } -Phonon::SeekSlider *Menu::seekSlider() const +SeekSlider *Menu::seekSlider() const { return m_seekSlider; } diff --git a/src/menu.h b/src/menu.h index c22ef97..9b2a2ff 100644 --- a/src/menu.h +++ b/src/menu.h @@ -17,6 +17,7 @@ namespace Phonon class QMouseEvent; class QLabel; +class SeekSlider; class Menu : public QMainWindow { @@ -28,7 +29,7 @@ public: void addActions(QList 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 index 0000000..313952f --- /dev/null +++ b/src/seekslider.cpp @@ -0,0 +1,148 @@ +#include "seekslider.h" + +#include +#include +#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 index 0000000..0077502 --- /dev/null +++ b/src/seekslider.h @@ -0,0 +1,70 @@ +#ifndef SEEKSLIDER_H +#define SEEKSLIDER_H + +#include +#include +#include + +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 m_media; + bool ticking; + + bool m_tracking; + int m_pageStep; + int m_singleStep; + Qt::Orientation m_orientation; +}; + +#endif // SEEKSLIDER_H diff --git a/src/src.pro b/src/src.pro index a576240..a4b9517 100644 --- a/src/src.pro +++ b/src/src.pro @@ -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 +} diff --git a/src/videowindow.cpp b/src/videowindow.cpp index 1478e50..5d8d2d0 100644 --- a/src/videowindow.cpp +++ b/src/videowindow.cpp @@ -18,31 +18,39 @@ #include "directoryplaylist.h" #include "anidbconfigdialog.h" #include "versiondialog.h" +#include "seekslider.h" -#include -#include -#include +#ifndef NO_ANIDBUDPCLIENT +# include +# include +# include +#endif #include 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 } diff --git a/src/videowindow.h b/src/videowindow.h index 3966cd1..6258fc4 100644 --- a/src/videowindow.h +++ b/src/videowindow.h @@ -9,7 +9,7 @@ # include # include #else -# include +# include #endif #ifdef GRAPHICS_VIEW_VIDEO @@ -34,8 +34,11 @@ 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);