1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 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 QStringList &arguments = MUtils::OS::arguments();
63 for(int i = 0; i < arguments.count(); i++)
65 if(!arguments[i].compare("--kill", Qt::CaseInsensitive))
67 if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_NONE, NULL))
69 qWarning("Failed to send IPC message!");
73 if(!arguments[i].compare("--force-kill", Qt::CaseInsensitive))
75 if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_FORCE, NULL))
77 qWarning("Failed to send IPC message!");
83 for(int i = 0; i < arguments.count() - 1; i++)
85 if(!arguments[i].compare("--add", Qt::CaseInsensitive))
87 QFileInfo file = QFileInfo(arguments[++i]);
88 if(file.exists() && file.isFile())
90 if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, MUTILS_UTF8(file.canonicalFilePath())))
92 qWarning("Failed to send IPC message!");
97 if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
99 QDir dir = QDir(arguments[++i]);
102 if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, MUTILS_UTF8(dir.canonicalPath())))
104 qWarning("Failed to send IPC message!");
109 if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
111 QDir dir = QDir(arguments[++i]);
114 if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, MUTILS_UTF8(dir.canonicalPath())))
116 qWarning("Failed to send IPC message!");
125 if(!m_ipcChannel->send(IPC_CMD_PING, IPC_FLAG_NONE, "Use running instance!"))
127 qWarning("Failed to send IPC message!");
132 ////////////////////////////////////////////////////////////
134 ////////////////////////////////////////////////////////////