#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;
#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
virtual ~AniPlayer();
inline static const AniPlayer *instance() { return m_instance;}
+
+protected slots:
+ void handleMessage(const QString &message);
+
private:
static AniPlayer *m_instance;
};
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();