2010-11-09 22:06:11 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2017-03-12 12:12:49 +01:00
|
|
|
// Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-09 22:06:11 +01:00
|
|
|
//
|
|
|
|
// 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
|
2013-10-23 20:56:57 +02:00
|
|
|
// (at your option) any later version, but always including the *additional*
|
|
|
|
// restrictions defined in the "License.txt" file.
|
2010-11-09 22:06:11 +01:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Thread_MessageProducer.h"
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//Internal
|
2010-11-09 22:06:11 +01:00
|
|
|
#include "Global.h"
|
2014-12-14 19:33:28 +01:00
|
|
|
#include "IPCCommands.h"
|
2010-11-09 22:06:11 +01:00
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/Global.h>
|
2014-12-13 23:27:47 +01:00
|
|
|
#include <MUtils/IPCChannel.h>
|
2014-11-25 22:34:20 +01:00
|
|
|
#include <MUtils/OSSupport.h>
|
2014-11-25 02:14:42 +01:00
|
|
|
|
|
|
|
//Qt
|
2010-11-09 22:06:11 +01:00
|
|
|
#include <QStringList>
|
|
|
|
#include <QApplication>
|
2010-11-13 02:11:15 +01:00
|
|
|
#include <QFileInfo>
|
2011-06-11 17:18:30 +02:00
|
|
|
#include <QDir>
|
2010-11-09 22:06:11 +01:00
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//CRT
|
2010-11-09 22:06:11 +01:00
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-13 23:27:47 +01:00
|
|
|
MessageProducerThread::MessageProducerThread(MUtils::IPCChannel *const ipcChannel)
|
|
|
|
:
|
|
|
|
m_ipcChannel(ipcChannel)
|
2010-11-09 22:06:11 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageProducerThread::~MessageProducerThread(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageProducerThread::run()
|
|
|
|
{
|
|
|
|
setTerminationEnabled(true);
|
|
|
|
bool bSentFiles = false;
|
2015-01-04 17:04:26 +01:00
|
|
|
const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments();
|
2010-11-09 22:06:11 +01:00
|
|
|
|
2015-01-04 17:04:26 +01:00
|
|
|
//Kill application?
|
|
|
|
if(arguments.contains("kill"))
|
2010-11-09 22:06:11 +01:00
|
|
|
{
|
2015-02-01 15:11:07 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_NONE))
|
2010-11-09 22:06:11 +01:00
|
|
|
{
|
2015-01-04 17:04:26 +01:00
|
|
|
qWarning("Failed to send IPC message!");
|
2010-11-09 22:06:11 +01:00
|
|
|
}
|
2015-01-04 17:04:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(arguments.contains("force-kill"))
|
|
|
|
{
|
2015-02-01 15:11:07 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_FORCE))
|
2010-11-09 22:06:11 +01:00
|
|
|
{
|
2015-01-04 17:04:26 +01:00
|
|
|
qWarning("Failed to send IPC message!");
|
2010-11-09 22:06:11 +01:00
|
|
|
}
|
2015-01-04 17:04:26 +01:00
|
|
|
return;
|
2010-11-09 22:06:11 +01:00
|
|
|
}
|
|
|
|
|
2015-01-04 17:04:26 +01:00
|
|
|
//Send file to "matser" instance
|
|
|
|
foreach(const QString &value, arguments.values("add"))
|
2010-11-09 22:06:11 +01:00
|
|
|
{
|
2015-01-04 17:04:26 +01:00
|
|
|
if(!value.isEmpty())
|
2010-11-09 22:06:11 +01:00
|
|
|
{
|
2015-01-04 17:04:26 +01:00
|
|
|
const QFileInfo file = QFileInfo(value);
|
2011-06-11 17:18:30 +02:00
|
|
|
if(file.exists() && file.isFile())
|
|
|
|
{
|
2015-02-01 15:11:07 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, QStringList() << file.canonicalFilePath()))
|
2014-12-14 19:33:28 +01:00
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2011-06-11 17:18:30 +02:00
|
|
|
}
|
|
|
|
bSentFiles = true;
|
|
|
|
}
|
2015-01-04 17:04:26 +01:00
|
|
|
}
|
|
|
|
foreach(const QString &value, arguments.values("add-folder"))
|
|
|
|
{
|
|
|
|
if(!value.isEmpty())
|
2011-06-11 17:18:30 +02:00
|
|
|
{
|
2015-01-04 17:04:26 +01:00
|
|
|
const QDir dir = QDir(value);
|
2011-06-11 17:18:30 +02:00
|
|
|
if(dir.exists())
|
|
|
|
{
|
2015-02-01 15:11:07 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, QStringList() << dir.canonicalPath()))
|
2014-12-14 19:33:28 +01:00
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2011-06-11 17:18:30 +02:00
|
|
|
}
|
|
|
|
bSentFiles = true;
|
|
|
|
}
|
2015-01-04 17:04:26 +01:00
|
|
|
}
|
|
|
|
foreach(const QString &value, arguments.values("add-recursive"))
|
|
|
|
{
|
|
|
|
if(!value.isEmpty())
|
2011-06-11 17:18:30 +02:00
|
|
|
{
|
2015-01-04 17:04:26 +01:00
|
|
|
const QDir dir = QDir(value);
|
2011-06-11 17:18:30 +02:00
|
|
|
if(dir.exists())
|
|
|
|
{
|
2015-02-01 15:11:07 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, QStringList() << dir.canonicalPath()))
|
2014-12-14 19:33:28 +01:00
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2011-06-11 17:18:30 +02:00
|
|
|
}
|
2010-11-09 22:06:11 +01:00
|
|
|
bSentFiles = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!bSentFiles)
|
|
|
|
{
|
2015-02-01 15:11:07 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_PING, IPC_FLAG_NONE, QStringList() << QLatin1String("Use running instance!")))
|
2014-12-14 19:33:28 +01:00
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2010-11-09 22:06:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// EVENTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*NONE*/
|