summaryrefslogtreecommitdiff
path: root/CliParser.cpp
blob: ffd511d8883e770e1dee5cb63aab805c19ab1b80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/** \file CliParser.cpp
\brief To group into one class, the CLI parsing
\author alpha_one_x86
\version 0.3
\date 2010
\licence GPL3, see the file COPYING */

#include "CliParser.h"

CliParser::CliParser(QObject *parent) :
    QObject(parent)
{
}

void CliParser::cli(const QStringList &ultracopierArguments,const bool &external)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"ultracopierArguments: "+ultracopierArguments.join(";"));
	if(ultracopierArguments.size()==1)
	{
		if(external)
			QMessageBox::warning(NULL,tr("Warning"),tr("Ultracopier is already running, right click on its system tray icon (near the clock) to use it"));
		// else do nothing, is normal starting without arguements
		return;
	}
	if(ultracopierArguments.size()==2 && ultracopierArguments.last()=="quit" && external)
	{
		QCoreApplication::exit();
		return;
	}
	if(ultracopierArguments.size()>3)
	{
		if(ultracopierArguments[1]=="Copy" || ultracopierArguments[1]=="cp")
		{
			QStringList transferList=ultracopierArguments;
			transferList.removeFirst();
			transferList.removeFirst();
			if(transferList.last()=="?")
			{
				transferList.removeLast();
				emit newCopy(transferList);
			}
			else
			{
				QString destination=transferList.last();
				transferList.removeLast();
				emit newCopy(transferList,destination);
			}
			return;
		}
		if(ultracopierArguments[1]=="Move" || ultracopierArguments[1]=="mv")
		{
			QStringList transferList=ultracopierArguments;
			transferList.removeFirst();
			transferList.removeFirst();
			if(transferList.last()=="?")
			{
				transferList.removeLast();
				emit newMove(transferList);
			}
			else
			{
				QString destination=transferList.last();
				transferList.removeLast();
				emit newMove(transferList,destination);
			}
			return;
		}
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Command line not understand");
		QMessageBox::warning(NULL,tr("Warning"),tr("Command line not understand"));
	}
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Command line not understand");
	QMessageBox::warning(NULL,tr("Warning"),tr("Command line not understand"));
}