Adapted for the latest MUtils library changes.
[LameXP.git] / src / Thread_MessageProducer.cpp
bloba764d526ce8f3bb901b52c576d20ff661a11676e
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2017 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_MessageProducer.h"
25 //Internal
26 #include "Global.h"
27 #include "IPCCommands.h"
29 //MUtils
30 #include <MUtils/Global.h>
31 #include <MUtils/IPCChannel.h>
32 #include <MUtils/OSSupport.h>
34 //Qt
35 #include <QStringList>
36 #include <QApplication>
37 #include <QFileInfo>
38 #include <QDir>
40 //CRT
41 #include <limits.h>
43 ////////////////////////////////////////////////////////////
44 // Constructor
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();
63 //Kill application?
64 if(arguments.contains("kill"))
66 if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_NONE))
68 qWarning("Failed to send IPC message!");
70 return;
72 if(arguments.contains("force-kill"))
74 if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_FORCE))
76 qWarning("Failed to send IPC message!");
78 return;
81 //Send file to "matser" instance
82 foreach(const QString &value, arguments.values("add"))
84 if(!value.isEmpty())
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!");
94 bSentFiles = true;
97 foreach(const QString &value, arguments.values("add-folder"))
99 if(!value.isEmpty())
101 const QDir dir = QDir(value);
102 if(dir.exists())
104 if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, QStringList() << dir.canonicalPath()))
106 qWarning("Failed to send IPC message!");
109 bSentFiles = true;
112 foreach(const QString &value, arguments.values("add-recursive"))
114 if(!value.isEmpty())
116 const QDir dir = QDir(value);
117 if(dir.exists())
119 if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, QStringList() << dir.canonicalPath()))
121 qWarning("Failed to send IPC message!");
124 bSentFiles = true;
128 if(!bSentFiles)
130 if(!m_ipcChannel->send(IPC_CMD_PING, IPC_FLAG_NONE, QStringList() << QLatin1String("Use running instance!")))
132 qWarning("Failed to send IPC message!");
137 ////////////////////////////////////////////////////////////
138 // EVENTS
139 ////////////////////////////////////////////////////////////
141 /*NONE*/