From: APTX Date: Wed, 23 Sep 2009 23:29:00 +0000 (+0200) Subject: - AniPlayer now works as a single instance. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=8e1d942a01d616c968b333bfc774062bfb3f9bf1;p=aniplayer-old.git - AniPlayer now works as a single instance. --- diff --git a/src/aniplayer.cpp b/src/aniplayer.cpp index c462239..65635de 100644 --- a/src/aniplayer.cpp +++ b/src/aniplayer.cpp @@ -2,15 +2,39 @@ #include -AniPlayer::AniPlayer(int &argc, char *argv[]) : QApplication(argc, argv) +#include +#include "videowindow.h" + +#include + +AniPlayer::AniPlayer(int &argc, char *argv[]) : QtSingleApplication(argc, argv) { m_instance = this; QSettings::setDefaultFormat(QSettings::IniFormat); + setQuitOnLastWindowClosed(true); + + connect(this, SIGNAL(messageReceived(QString)), this, SLOT(handleMessage(QString))); } AniPlayer::~AniPlayer() { m_instance = 0; + AniDBUdpClient::Client::destroy(); +} + + +void AniPlayer::handleMessage(const QString &message) +{ +qDebug() << "handleMessage" << message; + if (message.left(4) != "open") + return; + + VideoWindow *w = new VideoWindow; + w->show(); + + int pos = -1; + if ((pos = message.indexOf(' ')) != -1) + w->play(message.mid(pos)); } AniPlayer *AniPlayer::m_instance = 0; diff --git a/src/aniplayer.h b/src/aniplayer.h index 1d4e607..74eaa81 100644 --- a/src/aniplayer.h +++ b/src/aniplayer.h @@ -1,14 +1,16 @@ #ifndef ANIPLAYER_H #define ANIPLAYER_H -#include +#include #ifdef qApp # undef qApp #endif #define qApp (AniPlayer::instance()) -class AniPlayer : public QApplication +class VideoWindow; + +class AniPlayer : public QtSingleApplication { Q_OBJECT @@ -17,6 +19,10 @@ public: virtual ~AniPlayer(); inline static const AniPlayer *instance() { return m_instance;} + +protected slots: + void handleMessage(const QString &message); + private: static AniPlayer *m_instance; }; diff --git a/src/main.cpp b/src/main.cpp index da1ef45..a2fc07c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,12 +25,21 @@ int main(int argc, char *argv[]) AniPlayer a(argc, argv); - VideoWindow w; - w.show(); + if (a.isRunning()) + { + if (a.argc() >= 2) + a.sendMessage("open " + QDir::fromNativeSeparators(a.arguments()[1])); + else + a.sendMessage("open"); + return 0; + } + + VideoWindow *w = new VideoWindow; + w->show(); if (a.argc() >= 2) { - w.play(QDir::fromNativeSeparators(a.arguments()[1]), true); + w->play(QDir::fromNativeSeparators(a.arguments()[1]), true); } return a.exec(); diff --git a/src/videowindow.cpp b/src/videowindow.cpp index 463d5f1..d64e7ab 100644 --- a/src/videowindow.cpp +++ b/src/videowindow.cpp @@ -40,6 +40,7 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent) # endif #endif { + setAttribute(Qt::WA_DeleteOnClose, true); #ifdef Q_WS_X11 setFocusPolicy(Qt::StrongFocus); @@ -187,7 +188,6 @@ VideoWindow::~VideoWindow() hide(); menu->hide(); - anidb->destroy(); anidb = 0; }