///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2010 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
// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// (at your option) any later version, but always including the *additional*
+// restrictions defined in the "License.txt" file.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#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;
- QStringList 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(!value.isEmpty())
+ {
+ const QFileInfo file = QFileInfo(value);
+ if(file.exists() && file.isFile())
+ {
+ if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, QStringList() << file.canonicalFilePath()))
+ {
+ qWarning("Failed to send IPC message!");
+ }
+ }
+ bSentFiles = true;
+ }
+ }
+ foreach(const QString &value, arguments.values("add-folder"))
{
- if(!arguments[i].compare("--add", Qt::CaseInsensitive))
+ if(!value.isEmpty())
{
- lamexp_ipc_send(1, QFileInfo(arguments[++i]).canonicalFilePath().toUtf8().constData());
+ const QDir dir = QDir(value);
+ if(dir.exists())
+ {
+ if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, QStringList() << dir.canonicalPath()))
+ {
+ qWarning("Failed to send IPC message!");
+ }
+ }
+ bSentFiles = true;
+ }
+ }
+ foreach(const QString &value, arguments.values("add-recursive"))
+ {
+ if(!value.isEmpty())
+ {
+ const QDir dir = QDir(value);
+ if(dir.exists())
+ {
+ 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!");
+ }
}
}