Bump version + updated changelog.
[simple-x264-launcher.git] / src / thread_ipc_send.cpp
blob0dacc573d8406128a37e23b580a2b9142717a4d9
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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_ipc_send.h"
25 //Internal
26 #include "Global.h"
27 #include "cli.h"
28 #include "ipc.h"
30 //MUtils
31 #include <MUtils/Global.h>
32 #include <MUtils/IPCChannel.h>
33 #include <MUtils/OSSupport.h>
35 //Qt
36 #include <QStringList>
37 #include <QApplication>
38 #include <QFileInfo>
39 #include <QDir>
41 //CRT
42 #include <limits.h>
44 ////////////////////////////////////////////////////////////
45 // Constructor
46 ////////////////////////////////////////////////////////////
48 IPCThread_Send::IPCThread_Send(MUtils::IPCChannel *const ipcChannel)
50 m_ipcChannel(ipcChannel)
54 IPCThread_Send::~IPCThread_Send(void)
58 void IPCThread_Send::run()
60 setTerminationEnabled(true);
61 bool bSentFiles = false;
62 const MUtils::OS::ArgumentMap &args = MUtils::OS::arguments();
64 quint32 flags = 0;
65 bool commandSent = false;
67 //Handle flags
68 if(args.contains(CLI_PARAM_FORCE_START))
70 flags = ((flags | IPC_FLAG_FORCE_START) & (~IPC_FLAG_FORCE_ENQUEUE));
72 if(args.contains(CLI_PARAM_FORCE_ENQUEUE))
74 flags = ((flags | IPC_FLAG_FORCE_ENQUEUE) & (~IPC_FLAG_FORCE_START));
77 //Process all command-line arguments
78 if(args.contains(CLI_PARAM_ADD_FILE))
80 foreach(const QString &fileName, args.values(CLI_PARAM_ADD_FILE))
82 if(!m_ipcChannel->send(IPC_OPCODE_ADD_FILE, flags, QStringList() << fileName))
84 qWarning("Failed to send IPC message!");
86 commandSent = true;
89 if(args.contains(CLI_PARAM_ADD_JOB))
91 foreach(const QString &options, args.values(CLI_PARAM_ADD_JOB))
93 const QStringList optionValues = options.split('|', QString::SkipEmptyParts);
94 if(optionValues.count() == 3)
96 if(!m_ipcChannel->send(IPC_OPCODE_ADD_JOB, flags, optionValues))
98 qWarning("Failed to send IPC message!");
101 else
103 qWarning("Invalid number of arguments for parameter \"--%s\" detected!", CLI_PARAM_ADD_JOB);
105 commandSent = true;
109 //If no argument has been sent yet, send a ping!
110 if(!commandSent)
112 if(!m_ipcChannel->send(IPC_OPCODE_PING, 0, QStringList()))
114 qWarning("Failed to send IPC message!");
119 ////////////////////////////////////////////////////////////
120 // EVENTS
121 ////////////////////////////////////////////////////////////
123 /*NONE*/