summaryrefslogtreecommitdiff
path: root/plugins-alternative/Themes/Teracopy/interface.cpp
blob: be5407590e672c4efaffb47c2bcd518bc4153753 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
/** \file interface.cpp
\brief Define the interface core
\author alpha_one_x86
\version 0.3
\date 2010 */

#include <QtCore>
#include <QMessageBox>

#include "interface.h"
#include "ui_interface.h"

InterfacePlugin::InterfacePlugin(FacilityInterface * facilityEngine) :
	ui(new Ui::interfaceCopy())
{
	this->facilityEngine=facilityEngine;
	ui->setupUi(this);
	currentFile		= 0;
	totalFile		= 0;
	currentSize		= 0;
	totalSize		= 0;
	this->show();
	storeIsInPause		= false;
	isInPause(false);
	modeIsForced		= false;
	haveStarted		= false;
	speedString		= facilityEngine->speedToString(0);
	ui->toolButtonMenu->setMenu(&menu);
	
	connect(ui->actionAddFile,SIGNAL(triggered()),this,SLOT(forcedModeAddFile()));
	connect(ui->actionAddFileToCopy,SIGNAL(triggered()),this,SLOT(forcedModeAddFileToCopy()));
	connect(ui->actionAddFileToMove,SIGNAL(triggered()),this,SLOT(forcedModeAddFileToMove()));
	connect(ui->actionAddFolderToCopy,SIGNAL(triggered()),this,SLOT(forcedModeAddFolderToCopy()));
	connect(ui->actionAddFolderToMove,SIGNAL(triggered()),this,SLOT(forcedModeAddFolderToMove()));
	connect(ui->actionAddFolder,SIGNAL(triggered()),this,SLOT(forcedModeAddFolder()));

	iconStart=QIcon(":/resources/player_play.png");
	iconPause=QIcon(":/resources/player_pause.png");
	iconStop=QIcon(":/resources/checkbox.png");
}

InterfacePlugin::~InterfacePlugin()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
}

QWidget * InterfacePlugin::getOptionsEngineWidget()
{
	return &optionEngineWidget;
}

void InterfacePlugin::getOptionsEngineEnabled(bool isEnabled)
{
	Q_UNUSED(isEnabled);
}

/// \brief set if transfer list is exportable/importable
void InterfacePlugin::setTransferListOperation(TransferListOperation transferListOperation)
{
	Q_UNUSED(transferListOperation);
}

void InterfacePlugin::closeEvent(QCloseEvent *event)
{
	event->ignore();
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	this->hide();
	emit cancel();
}

void InterfacePlugin::updateOverallInformation()
{
	ui->overall->setText(tr("Total: %3 of %4").arg(facilityEngine->sizeToString(currentSize)).arg(facilityEngine->sizeToString(totalSize)));
	ui->labelNumberFile->setText(tr("%1 of %2").arg(currentFile).arg(totalFile));
}

void InterfacePlugin::actionInProgess(EngineActionInProgress action)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,"start: "+QString::number(action));
	this->action=action;
	ui->pauseButton->setEnabled(action!=Idle);
	switch(action)
	{
		case Copying:
		case CopyingAndListing:
			ui->progressBar_all->setMaximum(65535);
			ui->progressBar_all->setMinimum(0);
		break;
		case Listing:
			ui->progressBar_all->setMaximum(0);
			ui->progressBar_all->setMinimum(0);
		break;
		case Idle:
			if(haveStarted)
				emit cancel();
		break;
		default:
			ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"Very wrong switch case!");
		break;
	}
	switch(action)
	{
		case Copying:
		case CopyingAndListing:
			haveStarted=true;
		break;
		case Idle:
			ui->cancelButton->setText(tr("Quit"));
		break;
		default:
		break;
	}
}

void InterfacePlugin::newFolderListing(const QString &path)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	if(action==Listing)
		ui->from->setText(path);
}

void InterfacePlugin::detectedSpeed(const quint64 &speed)//in byte per seconds
{
	speedString=facilityEngine->speedToString(speed);
}

void InterfacePlugin::remainingTime(const int &remainingSeconds)
{
	if(remainingSeconds==-1)
		ui->labelTimeRemaining->setText("<html><body>&#8734;</body></html>");
	else
	{
		TimeDecomposition time=facilityEngine->secondsToTimeDecomposition(remainingSeconds);
		ui->labelTimeRemaining->setText(QString::number(time.hour)+":"+QString::number(time.minute)+":"+QString::number(time.second));
	}
}

void InterfacePlugin::newCollisionAction(const QString &action)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	Q_UNUSED(action);
}

void InterfacePlugin::newErrorAction(const QString &action)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	Q_UNUSED(action);
}

void InterfacePlugin::errorDetected()
{
}

//speed limitation
bool InterfacePlugin::setSpeedLimitation(const qint64 &speedLimitation)
{
	if(speedLimitation>0)
		emit newSpeedLimitation(0);
	return true;
}

//get information about the copy
void InterfacePlugin::setGeneralProgression(const quint64 &current,const quint64 &total)
{
	currentSize=current;
	totalSize=total;
	if(total>0)
	{
		int newIndicator=((double)current/total)*65535;
		ui->progressBar_all->setValue(newIndicator);
	}
	else
		ui->progressBar_all->setValue(0);
}

void InterfacePlugin::setCollisionAction(const QList<QPair<QString,QString> > &list)
{
	Q_UNUSED(list);
}

void InterfacePlugin::setErrorAction(const QList<QPair<QString,QString> > &list)
{
	Q_UNUSED(list);
}

void InterfacePlugin::setCopyType(CopyType type)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	this->type=type;
	updateModeAndType();
}

void InterfacePlugin::forceCopyMode(CopyMode mode)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	modeIsForced=true;
	this->mode=mode;
	if(mode==Copy)
		this->setWindowTitle("Ultracopier - "+tr("Copy"));
	else
		this->setWindowTitle("Ultracopier - "+tr("Move"));
	updateModeAndType();
}

void InterfacePlugin::updateTitle()
{
	QString startString;
	if(action==Copying || action==CopyingAndListing)
		startString=tr("%1% done").arg(((double)currentSize/totalSize)*100);
	else
		startString="Ultracopier";
	startString+=" - ";
	if(mode==Copy)
		this->setWindowTitle(startString+facilityEngine->translateText("Copy")+" ("+speedString+")");
	else
		this->setWindowTitle(startString+facilityEngine->translateText("Move")+" ("+speedString+")");
}

void InterfacePlugin::haveExternalOrder()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
//	ui->moreButton->toggle();
}

void InterfacePlugin::isInPause(bool isInPause)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"isInPause: "+QString::number(isInPause));
	//resume in auto the pause
	storeIsInPause=isInPause;
	if(isInPause)
		ui->pauseButton->setText(facilityEngine->translateText("Resume"));
	else
		ui->pauseButton->setText(facilityEngine->translateText("Pause"));
}

void InterfacePlugin::updateCurrentFileInformation()
{
	if(currentProgressList.size()>0)
	{
		ui->from->setText(currentProgressList.first().generalData.sourceFullPath);
		if(currentProgressList.first().generalData.size>0)
			ui->progressBar_file->setValue(((double)currentProgressList.first().currentProgression/currentProgressList.first().generalData.size)*65535);
		else
			ui->progressBar_file->setValue(0);
	}
	else
	{
		ui->from->setText("-");
		ui->progressBar_file->setValue(65535);
	}
}


void InterfacePlugin::on_cancelButton_clicked()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	this->hide();
	emit cancel();
}


void InterfacePlugin::on_pauseButton_clicked()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	if(storeIsInPause)
		emit resume();
	else
		emit pause();
}

void InterfacePlugin::on_skipButton_clicked()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	if(currentProgressList.size()>0)
		emit skip(currentProgressList.first().generalData.id);
	else
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"unable to skip the transfer, because no transfer running");
}

void InterfacePlugin::updateModeAndType()
{
	menu.clear();
	if(modeIsForced)
	{
		menu.addAction(ui->actionAddFile);
		if(type==FileAndFolder)
			menu.addAction(ui->actionAddFolder);
	}
	else
	{
		menu.addAction(ui->actionAddFileToCopy);
		menu.addAction(ui->actionAddFileToMove);
		if(type==FileAndFolder)
		{
			menu.addAction(ui->actionAddFolderToCopy);
			menu.addAction(ui->actionAddFolderToMove);
		}
	}
}

void InterfacePlugin::forcedModeAddFile()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	emit userAddFile(mode);
}

void InterfacePlugin::forcedModeAddFolder()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	emit userAddFolder(mode);
}

void InterfacePlugin::forcedModeAddFileToCopy()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	emit userAddFile(Copy);
}

void InterfacePlugin::forcedModeAddFolderToCopy()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	emit userAddFolder(Copy);
}

void InterfacePlugin::forcedModeAddFileToMove()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	emit userAddFile(Move);
}

void InterfacePlugin::forcedModeAddFolderToMove()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	emit userAddFolder(Move);
}

//set the translate
void InterfacePlugin::newLanguageLoaded()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	if(modeIsForced)
		forceCopyMode(mode);
	ui->retranslateUi(this);
	if(haveStarted)
		updateCurrentFileInformation();
	updateOverallInformation();
}

/*
  Return[0]: totalFile
  Return[1]: totalSize
  Return[2]: currentFile
  */
void InterfacePlugin::getActionOnList(const QList<returnActionOnCopyList>& returnActions)
{
	loop_size=returnActions.size();
	index_for_loop=0;
	while(index_for_loop<loop_size)
	{
		const returnActionOnCopyList& action=returnActions.at(index_for_loop);
		switch(action.type)
		{
			case AddingItem:
			{
				InternalRunningOperationGraphic.insert(action.addAction.id,new QTreeWidgetItem(QStringList() << action.addAction.sourceFullPath << facilityEngine->sizeToString(action.addAction.size) << action.addAction.destinationFullPath));
				ui->CopyList->addTopLevelItem(InternalRunningOperationGraphic[action.addAction.id]);
				totalFile++;
				totalSize+=action.addAction.size;
			}
			break;
			case MoveItem:
				ui->CopyList->move(action.userAction.position,action.userAction.moveAt);
			break;
			case RemoveItem:
			{
				InternalRunningOperationGraphic[action.addAction.id]->setIcon(0,iconStop);
				InternalRunningOperationGraphic.remove(action.addAction.id);
				//delete ui->CopyList->topLevelItem(action.userAction.position);
				currentFile++;
				startId.removeOne(action.addAction.id);
				stopId.removeOne(action.addAction.id);
			}
			break;
			case PreOperation:
			{
				ItemOfCopyListWithMoreInformations tempItem;
				tempItem.currentProgression=0;
				tempItem.generalData=action.addAction;
				InternalRunningOperation << tempItem;
			}
			break;
			case Transfer:
			{
				if(!startId.contains(action.addAction.id))
					startId << action.addAction.id;
				stopId.removeOne(action.addAction.id);
				sub_index_for_loop=0;
				sub_loop_size=InternalRunningOperation.size();
				while(sub_index_for_loop<sub_loop_size)
				{
					if(InternalRunningOperation.at(sub_index_for_loop).generalData.id==action.addAction.id)
					{
						InternalRunningOperation[sub_index_for_loop].actionType=action.type;
						break;
					}
					sub_index_for_loop++;
				}
				InternalRunningOperationGraphic[action.addAction.id]->setIcon(0,iconStart);
			}
			break;
			case PostOperation:
			{
				if(!stopId.contains(action.addAction.id))
					stopId << action.addAction.id;
				startId.removeOne(action.addAction.id);
				sub_index_for_loop=0;
				sub_loop_size=InternalRunningOperation.size();
				while(sub_index_for_loop<sub_loop_size)
				{
					if(InternalRunningOperation.at(sub_index_for_loop).generalData.id==action.addAction.id)
					{
						InternalRunningOperation.removeAt(sub_index_for_loop);
						break;
					}
					sub_index_for_loop++;
				}
				InternalRunningOperationGraphic[action.addAction.id]->setIcon(0,iconPause);
			}
			break;
			case CustomOperation:
			{
				bool custom_with_progression=(action.addAction.size==1);
				//without progression
				if(custom_with_progression)
				{
					if(startId.removeOne(action.addAction.id))
						if(!stopId.contains(action.addAction.id))
							stopId << action.addAction.id;
				}
				//with progression
				else
				{
					stopId.removeOne(action.addAction.id);
					if(!startId.contains(action.addAction.id))
						startId << action.addAction.id;
				}
				sub_index_for_loop=0;
				sub_loop_size=InternalRunningOperation.size();
				while(sub_index_for_loop<sub_loop_size)
				{
					if(InternalRunningOperation.at(sub_index_for_loop).generalData.id==action.addAction.id)
					{
						InternalRunningOperation[sub_index_for_loop].actionType=action.type;
						InternalRunningOperation[sub_index_for_loop].custom_with_progression=custom_with_progression;
						InternalRunningOperation[sub_index_for_loop].currentProgression=0;
						break;
					}
					sub_index_for_loop++;
				}
			}
			break;
			default:
				//unknow code, ignore it
			break;
		}
		index_for_loop++;
	}
}

void InterfacePlugin::setFileProgression(const QList<ProgressionItem> &progressionList)
{
	loop_size=InternalRunningOperation.size();
	sub_loop_size=progressionList.size();
	index_for_loop=0;
	while(index_for_loop<loop_size)
	{
		sub_index_for_loop=0;
		while(sub_index_for_loop<sub_loop_size)
		{
			if(progressionList.at(sub_index_for_loop).id==InternalRunningOperation.at(index_for_loop).generalData.id)
			{
				InternalRunningOperation[index_for_loop].generalData.size=progressionList.at(sub_index_for_loop).total;
				InternalRunningOperation[index_for_loop].currentProgression=progressionList.at(sub_index_for_loop).current;
				break;
			}
			sub_index_for_loop++;
		}
		index_for_loop++;
	}
}

InterfacePlugin::currentTransfertItem InterfacePlugin::getCurrentTransfertItem()
{
	currentTransfertItem returnItem;
	returnItem.haveItem=InternalRunningOperation.size()>0;
	if(returnItem.haveItem)
	{
		const ItemOfCopyListWithMoreInformations &itemTransfer=InternalRunningOperation.first();
		returnItem.from=itemTransfer.generalData.sourceFullPath;
		returnItem.to=itemTransfer.generalData.destinationFullPath;
		returnItem.current_file=itemTransfer.generalData.destinationFileName+", "+facilityEngine->sizeToString(itemTransfer.generalData.size);
		switch(itemTransfer.actionType)
		{
			case CustomOperation:
			if(!itemTransfer.custom_with_progression)
				returnItem.progressBar_file=0;
			else
			{
				if(itemTransfer.generalData.size>0)
					returnItem.progressBar_file=((double)itemTransfer.currentProgression/itemTransfer.generalData.size)*65535;
				else
					returnItem.progressBar_file=0;
			}
			break;
			case Transfer:
			if(itemTransfer.generalData.size>0)
				returnItem.progressBar_file=((double)itemTransfer.currentProgression/itemTransfer.generalData.size)*65535;
			else
				returnItem.progressBar_file=0;
			break;
			case PostOperation:
				returnItem.progressBar_file=65535;
			break;
			default:
				returnItem.progressBar_file=0;
		}
	}
	return returnItem;
}