]> Some of my projects - aniplayer-old.git/commitdiff
- AniPlayer now works as a single instance.
authorAPTX <APTX@.(none)>
Wed, 23 Sep 2009 23:29:00 +0000 (01:29 +0200)
committerAPTX <APTX@.(none)>
Wed, 23 Sep 2009 23:29:00 +0000 (01:29 +0200)
src/aniplayer.cpp
src/aniplayer.h
src/main.cpp
src/videowindow.cpp

index c462239662950fec39a770c7dc6c5754adf2a874..65635de3c76545c74c2b0262a779fdd40decc518 100644 (file)
@@ -2,15 +2,39 @@
 
 #include <QSettings>
 
-AniPlayer::AniPlayer(int &argc, char *argv[]) : QApplication(argc, argv)
+#include <AniDBUdpClient/Client>
+#include "videowindow.h"
+
+#include <QDebug>
+
+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;
index 1d4e6078f347c7475832c3da4ab6d3d14d5061d2..74eaa81d284f7d80ba2c85a859ae2f8901a48ca3 100644 (file)
@@ -1,14 +1,16 @@
 #ifndef ANIPLAYER_H
 #define ANIPLAYER_H
 
-#include <QApplication>
+#include <QtSingleApplication>
 
 #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;
 };
index da1ef453fb2ad1dd7e053e967f0ea999e6654608..a2fc07c2a18e1cb0f12ae21f6446a740c4d66faf 100644 (file)
@@ -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();
index 463d5f1a3f5ad451c66c1d8219aab1676c764056..d64e7ab15fe6ce09d5c7a8f492480eb92f97fdf3 100644 (file)
@@ -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;
 }