1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Thread_MessageProducer.h"
27 #include "IPCCommands.h"
30 #include <MUtils/Global.h>
31 #include <MUtils/IPCChannel.h>
32 #include <MUtils/OSSupport.h>
35 #include <QStringList>
36 #include <QApplication>
43 ////////////////////////////////////////////////////////////
45 ////////////////////////////////////////////////////////////
47 MessageProducerThread::MessageProducerThread(MUtils::IPCChannel
*const ipcChannel
)
49 m_ipcChannel(ipcChannel
)
53 MessageProducerThread::~MessageProducerThread(void)
57 void MessageProducerThread::run()
59 setTerminationEnabled(true);
60 bool bSentFiles
= false;
61 const MUtils::OS::ArgumentMap
&arguments
= MUtils::OS::arguments();
64 if(arguments
.contains("kill"))
66 if(!m_ipcChannel
->send(IPC_CMD_TERMINATE
, IPC_FLAG_NONE
))
68 qWarning("Failed to send IPC message!");
72 if(arguments
.contains("force-kill"))
74 if(!m_ipcChannel
->send(IPC_CMD_TERMINATE
, IPC_FLAG_FORCE
))
76 qWarning("Failed to send IPC message!");
81 //Send file to "matser" instance
82 foreach(const QString
&value
, arguments
.values("add"))
86 const QFileInfo file
= QFileInfo(value
);
87 if(file
.exists() && file
.isFile())
89 if(!m_ipcChannel
->send(IPC_CMD_ADD_FILE
, IPC_FLAG_NONE
, QStringList() << file
.canonicalFilePath()))
91 qWarning("Failed to send IPC message!");
97 foreach(const QString
&value
, arguments
.values("add-folder"))
101 const QDir dir
= QDir(value
);
104 if(!m_ipcChannel
->send(IPC_CMD_ADD_FOLDER
, IPC_FLAG_NONE
, QStringList() << dir
.canonicalPath()))
106 qWarning("Failed to send IPC message!");
112 foreach(const QString
&value
, arguments
.values("add-recursive"))
116 const QDir dir
= QDir(value
);
119 if(!m_ipcChannel
->send(IPC_CMD_ADD_FOLDER
, IPC_FLAG_ADD_RECURSIVE
, QStringList() << dir
.canonicalPath()))
121 qWarning("Failed to send IPC message!");
130 if(!m_ipcChannel
->send(IPC_CMD_PING
, IPC_FLAG_NONE
, QStringList() << QLatin1String("Use running instance!")))
132 qWarning("Failed to send IPC message!");
137 ////////////////////////////////////////////////////////////
139 ////////////////////////////////////////////////////////////