OSDN Git Service

Improved Russian & Spanish translations for the installer
[lamexp/LameXP.git] / src / Thread_MessageProducer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 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.
10 //
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.
15 //
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.
19 //
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "Thread_MessageProducer.h"
24
25 //Internal
26 #include "Global.h"
27 #include "IPCCommands.h"
28
29 //MUtils
30 #include <MUtils/Global.h>
31 #include <MUtils/IPCChannel.h>
32 #include <MUtils/OSSupport.h>
33
34 //Qt
35 #include <QStringList>
36 #include <QApplication>
37 #include <QFileInfo>
38 #include <QDir>
39
40 //CRT
41 #include <limits.h>
42
43 ////////////////////////////////////////////////////////////
44 // Constructor
45 ////////////////////////////////////////////////////////////
46
47 MessageProducerThread::MessageProducerThread(MUtils::IPCChannel *const ipcChannel)
48 :
49         m_ipcChannel(ipcChannel)
50 {
51 }
52
53 MessageProducerThread::~MessageProducerThread(void)
54 {
55 }
56
57 void MessageProducerThread::run()
58 {
59         setTerminationEnabled(true);
60         bool bSentFiles = false;
61         const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments();
62
63         //Kill application?
64         if(arguments.contains("kill"))
65         {
66                 if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_NONE))
67                 {
68                         qWarning("Failed to send IPC message!");
69                 }
70                 return;
71         }
72         if(arguments.contains("force-kill"))
73         {
74                 if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_FORCE))
75                 {
76                         qWarning("Failed to send IPC message!");
77                 }
78                 return;
79         }
80
81         //Send file to "matser" instance
82         foreach(const QString &value, arguments.values("add"))
83         {
84                 if(!value.isEmpty())
85                 {
86                         const QFileInfo file = QFileInfo(value);
87                         if(file.exists() && file.isFile())
88                         {
89                                 if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, QStringList() << file.canonicalFilePath()))
90                                 {
91                                         qWarning("Failed to send IPC message!");
92                                 }
93                         }
94                         bSentFiles = true;
95                 }
96         }
97         foreach(const QString &value, arguments.values("add-folder"))
98         {
99                 if(!value.isEmpty())
100                 {
101                         const QDir dir = QDir(value);
102                         if(dir.exists())
103                         {
104                                 if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, QStringList() << dir.canonicalPath()))
105                                 {
106                                         qWarning("Failed to send IPC message!");
107                                 }
108                         }
109                         bSentFiles = true;
110                 }
111         }
112         foreach(const QString &value, arguments.values("add-recursive"))
113         {
114                 if(!value.isEmpty())
115                 {
116                         const QDir dir = QDir(value);
117                         if(dir.exists())
118                         {
119                                 if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, QStringList() << dir.canonicalPath()))
120                                 {
121                                         qWarning("Failed to send IPC message!");
122                                 }
123                         }
124                         bSentFiles = true;
125                 }
126         }
127
128         if(!bSentFiles)
129         {
130                 if(!m_ipcChannel->send(IPC_CMD_PING, IPC_FLAG_NONE, QStringList() << QLatin1String("Use running instance!")))
131                 {
132                         qWarning("Failed to send IPC message!");
133                 }
134         }
135 }
136
137 ////////////////////////////////////////////////////////////
138 // EVENTS
139 ////////////////////////////////////////////////////////////
140
141 /*NONE*/