OSDN Git Service

Moved all IPC functions into the MUtilities libraries.
[lamexp/LameXP.git] / src / Thread_MessageProducer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 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
28 //MUtils
29 #include <MUtils/Global.h>
30 #include <MUtils/IPCChannel.h>
31 #include <MUtils/OSSupport.h>
32
33 //Qt
34 #include <QStringList>
35 #include <QApplication>
36 #include <QFileInfo>
37 #include <QDir>
38
39 //CRT
40 #include <limits.h>
41
42 ////////////////////////////////////////////////////////////
43 // Constructor
44 ////////////////////////////////////////////////////////////
45
46 MessageProducerThread::MessageProducerThread(MUtils::IPCChannel *const ipcChannel)
47 :
48         m_ipcChannel(ipcChannel)
49 {
50 }
51
52 MessageProducerThread::~MessageProducerThread(void)
53 {
54 }
55
56 void MessageProducerThread::run()
57 {
58         setTerminationEnabled(true);
59         bool bSentFiles = false;
60         const QStringList &arguments = MUtils::OS::arguments();
61
62         for(int i = 0; i < arguments.count(); i++)
63         {
64                 if(!arguments[i].compare("--kill", Qt::CaseInsensitive))
65                 {
66                         m_ipcChannel->send(666, NULL);
67                         return;
68                 }
69                 if(!arguments[i].compare("--force-kill", Qt::CaseInsensitive))
70                 {
71                         m_ipcChannel->send(666, "Force!");
72                         return;
73                 }
74         }
75
76         for(int i = 0; i < arguments.count() - 1; i++)
77         {
78                 if(!arguments[i].compare("--add", Qt::CaseInsensitive))
79                 {
80                         QFileInfo file = QFileInfo(arguments[++i]);
81                         if(file.exists() && file.isFile())
82                         {
83                                 m_ipcChannel->send(1, MUTILS_UTF8(file.canonicalFilePath()));
84                         }
85                         bSentFiles = true;
86                 }
87                 if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
88                 {
89                         QDir dir = QDir(arguments[++i]);
90                         if(dir.exists())
91                         {
92                                 m_ipcChannel->send(2, MUTILS_UTF8(dir.canonicalPath()));
93                         }
94                         bSentFiles = true;
95                 }
96                 if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
97                 {
98                         QDir dir = QDir(arguments[++i]);
99                         if(dir.exists())
100                         {
101                                 m_ipcChannel->send(3, MUTILS_UTF8(dir.canonicalPath()));
102                         }
103                         bSentFiles = true;
104                 }
105         }
106
107         if(!bSentFiles)
108         {
109                 m_ipcChannel->send(UINT_MAX, "Use running instance!");
110         }
111 }
112
113 ////////////////////////////////////////////////////////////
114 // EVENTS
115 ////////////////////////////////////////////////////////////
116
117 /*NONE*/