///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include "Thread_MessageProducer.h"
+//Internal
#include "Global.h"
+#include "IPCCommands.h"
+//MUtils
+#include <MUtils/Global.h>
+#include <MUtils/IPCChannel.h>
+#include <MUtils/OSSupport.h>
+
+//Qt
#include <QStringList>
#include <QApplication>
#include <QFileInfo>
#include <QDir>
+//CRT
#include <limits.h>
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
-MessageProducerThread::MessageProducerThread(void)
+MessageProducerThread::MessageProducerThread(MUtils::IPCChannel *const ipcChannel)
+:
+ m_ipcChannel(ipcChannel)
{
}
{
setTerminationEnabled(true);
bool bSentFiles = false;
- const QStringList &arguments = lamexp_arguments(); //QApplication::arguments();
+ const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments();
- for(int i = 0; i < arguments.count(); i++)
+ //Kill application?
+ if(arguments.contains("kill"))
{
- if(!arguments[i].compare("--kill", Qt::CaseInsensitive))
+ if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_NONE))
{
- lamexp_ipc_send(666, NULL);
- return;
+ qWarning("Failed to send IPC message!");
}
- if(!arguments[i].compare("--force-kill", Qt::CaseInsensitive))
+ return;
+ }
+ if(arguments.contains("force-kill"))
+ {
+ if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_FORCE))
{
- lamexp_ipc_send(666, "Force!");
- return;
+ qWarning("Failed to send IPC message!");
}
+ return;
}
- for(int i = 0; i < arguments.count() - 1; i++)
+ //Send file to "matser" instance
+ foreach(const QString &value, arguments.values("add"))
{
- if(!arguments[i].compare("--add", Qt::CaseInsensitive))
+ if(!value.isEmpty())
{
- QFileInfo file = QFileInfo(arguments[++i]);
+ const QFileInfo file = QFileInfo(value);
if(file.exists() && file.isFile())
{
- lamexp_ipc_send(1, QUTF8(file.canonicalFilePath()));
+ if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, QStringList() << file.canonicalFilePath()))
+ {
+ qWarning("Failed to send IPC message!");
+ }
}
bSentFiles = true;
}
- if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
+ }
+ foreach(const QString &value, arguments.values("add-folder"))
+ {
+ if(!value.isEmpty())
{
- QDir dir = QDir(arguments[++i]);
+ const QDir dir = QDir(value);
if(dir.exists())
{
- lamexp_ipc_send(2, QUTF8(dir.canonicalPath()));
+ if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, QStringList() << dir.canonicalPath()))
+ {
+ qWarning("Failed to send IPC message!");
+ }
}
bSentFiles = true;
}
- if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
+ }
+ foreach(const QString &value, arguments.values("add-recursive"))
+ {
+ if(!value.isEmpty())
{
- QDir dir = QDir(arguments[++i]);
+ const QDir dir = QDir(value);
if(dir.exists())
{
- lamexp_ipc_send(3, QUTF8(dir.canonicalPath()));
+ if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, QStringList() << dir.canonicalPath()))
+ {
+ qWarning("Failed to send IPC message!");
+ }
}
bSentFiles = true;
}
if(!bSentFiles)
{
- lamexp_ipc_send(UINT_MAX, "Use running instance!");
+ if(!m_ipcChannel->send(IPC_CMD_PING, IPC_FLAG_NONE, QStringList() << QLatin1String("Use running instance!")))
+ {
+ qWarning("Failed to send IPC message!");
+ }
}
}