summaryrefslogtreecommitdiff
path: root/OptionDialog.cpp
blob: fcfbf06cf6a15815739eea6fbc4db618f66cd7e4 (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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
/** \file OptionDialog.cpp
\brief To have an interface to control the options
\author alpha_one_x86
\version 0.3
\date 2010
\licence GPL3, see the file COPYING */

#include "OptionDialog.h"
#include "ui_OptionDialog.h"

#include <QDomElement>
#include <QFileDialog>

OptionDialog::OptionDialog() :
	ui(new Ui::OptionDialog)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	ignoreCopyEngineListEdition=false;
	allPluginsIsLoaded=false;
	ui->setupUi(this);
	ui->treeWidget->topLevelItem(0)->setSelected(true);
	ui->treeWidget->topLevelItem(3)->setTextColor(0,QColor(150, 150, 150, 255));
	ui->treeWidget->topLevelItem(4)->setTextColor(0,QColor(150, 150, 150, 255));
	ui->treeWidget->topLevelItem(5)->setTextColor(0,QColor(150, 150, 150, 255));
	ui->treeWidget->expandAll();
	ui->pluginList->expandAll();
	on_treeWidget_itemSelectionChanged();

	//load the plugins
	plugins->lockPluginListEdition();
	QList<PluginsAvailable> list=plugins->getPlugins();
	qRegisterMetaType<PluginsAvailable>("PluginsAvailable");
	connect(this,SIGNAL(previouslyPluginAdded(PluginsAvailable)),		this,SLOT(onePluginAdded(PluginsAvailable)),Qt::QueuedConnection);
	connect(plugins,	SIGNAL(onePluginAdded(PluginsAvailable)),		this,	SLOT(onePluginAdded(PluginsAvailable)));
	connect(plugins,	SIGNAL(onePluginWillBeRemoved(PluginsAvailable)),	this,	SLOT(onePluginWillBeRemoved(PluginsAvailable)),Qt::DirectConnection);
	connect(plugins,	SIGNAL(pluginListingIsfinish()),			this,	SLOT(loadOption()),Qt::QueuedConnection);
	connect(options,	SIGNAL(newOptionValue(QString,QString,QVariant)),	this,	SLOT(newOptionValue(QString,QString,QVariant)));
	foreach(PluginsAvailable currentPlugin,list)
		emit previouslyPluginAdded(currentPlugin);
	plugins->unlockPluginListEdition();
	defaultImportBackend=PluginsManager::ImportBackend_File;
	#ifndef ULTRACOPIER_PLUGIN_SUPPORT
	ui->pluginAdd->show();
	ui->pluginRemove->show();
	#endif
}

OptionDialog::~OptionDialog()
{
	delete ui;
}

//plugin management
void OptionDialog::onePluginAdded(PluginsAvailable plugin)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: "+plugin.name+" ("+QString::number(plugin.category)+")");
	pluginStore newItem;
	newItem.path=plugin.path;
	newItem.item=new QTreeWidgetItem(QStringList() << plugin.name << plugin.version);
	newItem.isWritable=plugin.isWritable;
	pluginLink<<newItem;
	switch(plugin.category)
	{
		case PluginType_CopyEngine:
			ui->pluginList->topLevelItem(0)->addChild(newItem.item);
		break;
		case PluginType_Languages:
			ui->pluginList->topLevelItem(1)->addChild(newItem.item);
			addLanguage(plugin);
		break;
		case PluginType_Listener:
			ui->pluginList->topLevelItem(2)->addChild(newItem.item);
		break;
		case PluginType_PluginLoader:
			ui->pluginList->topLevelItem(3)->addChild(newItem.item);
		break;
		case PluginType_SessionLoader:
			ui->pluginList->topLevelItem(4)->addChild(newItem.item);
		break;
		case PluginType_Themes:
			ui->pluginList->topLevelItem(5)->addChild(newItem.item);
			addTheme(plugin);
		break;
		default:
			ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"category not found for: "+plugin.path);
	}
}

void OptionDialog::onePluginWillBeRemoved(PluginsAvailable plugin)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	//remove if have options
	index=0;
	loop_size=pluginOptionsWidgetList.size();
	if(plugin.category==PluginType_CopyEngine || plugin.category==PluginType_Listener || plugin.category==PluginType_PluginLoader || plugin.category==PluginType_SessionLoader)
	{
		while(index<loop_size)
		{
			if(plugin.category==pluginOptionsWidgetList.at(index).category && plugin.name==pluginOptionsWidgetList.at(index).name)
			{
				if(pluginOptionsWidgetList.at(index).item->isSelected())
				{
					pluginOptionsWidgetList.at(index).item->setSelected(false);
					ui->treeWidget->topLevelItem(0)->setSelected(true);
				}
				delete pluginOptionsWidgetList.at(index).item;
				break;
			}
			index++;
		}
	}
	//remove from general list
	index=0;
	loop_size=pluginLink.size();
	while(index<loop_size)
	{
		if(pluginLink.at(index).path==plugin.path)
		{
			delete pluginLink.at(index).item;
			if(plugin.category==PluginType_Languages)
				removeLanguage(plugin);
			else if(plugin.category==PluginType_Themes)
				removeTheme(plugin);
			pluginLink.removeAt(index);
			return;
		}
		index++;
	}
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"not found!");
}

void OptionDialog::addLanguage(PluginsAvailable plugin)
{
	QList<QPair<QString,QString> > listChildAttribute;
	QPair<QString,QString> temp;
	temp.first = "mainCode";
	temp.second = "true";
	listChildAttribute << temp;
	ui->Language->addItem(QIcon(plugin.path+"flag.png"),plugins->getDomSpecific(plugin.categorySpecific,"fullName"),plugins->getDomSpecific(plugin.categorySpecific,"shortName",listChildAttribute));
}

void OptionDialog::removeLanguage(PluginsAvailable plugin)
{
	QList<QPair<QString,QString> > listChildAttribute;
	QPair<QString,QString> temp;
	temp.first = "mainCode";
	temp.second = "true";
	listChildAttribute << temp;
	int index=ui->Language->findData(plugins->getDomSpecific(plugin.categorySpecific,"shortName",listChildAttribute));
	if(index!=-1)
		ui->Language->removeItem(index);
}

void OptionDialog::addTheme(PluginsAvailable plugin)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"plugin.name: "+plugin.name);
	ui->Ultracopier_current_theme->addItem(plugin.name,plugin.name);
}

void OptionDialog::removeTheme(PluginsAvailable plugin)
{
	int index=ui->Ultracopier_current_theme->findData(plugin.name);
	if(index!=-1)
		ui->Ultracopier_current_theme->removeItem(index);
}

void OptionDialog::changeEvent(QEvent *e)
{
	QDialog::changeEvent(e);
	switch (e->type()) {
	case QEvent::LanguageChange:
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"retranslate the ui");
		ui->retranslateUi(this);
		//old code to reload the widget because it dropped by the translation
		/*
		index=0;
		loop_size=pluginOptionsWidgetList.size();
		while(index<loop_size)
		{
			if(pluginOptionsWidgetList.at(index).options!=NULL)
				ui->treeWidget->topLevelItem(2)->addChild(pluginOptionsWidgetList.at(index).item);
			else
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("the copy engine %1 have not the options").arg(index));
			index++;
		}*/
		ui->treeWidget->topLevelItem(2)->setText(0,tr("Copy engine"));
		ui->treeWidget->topLevelItem(3)->setText(0,tr("Listener"));
		ui->treeWidget->topLevelItem(4)->setText(0,tr("Plugin loader"));
		ui->treeWidget->topLevelItem(5)->setText(0,tr("Session loader"));
		ui->labelLoadAtSession->setToolTip(tr("Disabled because you have any SessionLoader plugin"));
		ui->LoadAtSessionStarting->setToolTip(tr("Disabled because you have any SessionLoader plugin"));
		ui->ActionOnManualOpen->setItemText(0,tr("Do nothing"));
		ui->ActionOnManualOpen->setItemText(1,tr("Ask source as folder"));
		ui->ActionOnManualOpen->setItemText(2,tr("Ask sources as files"));
		ui->GroupWindowWhen->setItemText(0,tr("Never"));
		ui->GroupWindowWhen->setItemText(1,tr("When source is same"));
		ui->GroupWindowWhen->setItemText(2,tr("When destination is same"));
		ui->GroupWindowWhen->setItemText(3,tr("When source and destination are same"));
		ui->GroupWindowWhen->setItemText(4,tr("When source or destination are same"));
		ui->GroupWindowWhen->setItemText(5,tr("Always"));
		break;
	default:
		break;
	}
}

void OptionDialog::on_treeWidget_itemSelectionChanged()
{
	QList<QTreeWidgetItem *> listSelectedItem=ui->treeWidget->selectedItems();
	if(listSelectedItem.size()!=1)
		return;
	QTreeWidgetItem * selectedItem=listSelectedItem.first();
	//general
	if(selectedItem==ui->treeWidget->topLevelItem(0))
		ui->stackedWidget->setCurrentIndex(0);
	//plugins
	else if(selectedItem==ui->treeWidget->topLevelItem(1))
		ui->stackedWidget->setCurrentIndex(1);
	//Copy engine
	else if(selectedItem==ui->treeWidget->topLevelItem(2))
		ui->stackedWidget->setCurrentIndex(2);
	//Listener
		//do nothing
	//PluginLoader
		//do nothing
	//SessionLoader
		//do nothing
	//Themes
	else if(selectedItem==ui->treeWidget->topLevelItem(6))
		ui->stackedWidget->setCurrentIndex(7);
	//log
	else if(selectedItem==ui->treeWidget->topLevelItem(7))
		ui->stackedWidget->setCurrentIndex(8);
	else
	{
		int index;
		if(selectedItem->parent()==ui->treeWidget->topLevelItem(2))
		{
			ui->stackedWidget->setCurrentIndex(3);
			index=selectedItem->parent()->indexOfChild(selectedItem);
			if(index!=-1)
				ui->stackedOptionsCopyEngine->setCurrentIndex(index);
			else
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"selection into of sub item wrong???");
		}
		else if(selectedItem->parent()==ui->treeWidget->topLevelItem(3))
		{
			ui->stackedWidget->setCurrentIndex(4);
			index=selectedItem->parent()->indexOfChild(selectedItem);
			if(index!=-1)
				ui->stackedOptionsListener->setCurrentIndex(index);
			else
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"selection into of sub item wrong???");
		}
		else if(selectedItem->parent()==ui->treeWidget->topLevelItem(4))
		{
			ui->stackedWidget->setCurrentIndex(5);
			index=selectedItem->parent()->indexOfChild(selectedItem);
			if(index!=-1)
				ui->stackedOptionsPluginLoader->setCurrentIndex(index);
			else
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"selection into of sub item wrong???");
		}
		else if(selectedItem->parent()==ui->treeWidget->topLevelItem(5))
		{
			ui->stackedWidget->setCurrentIndex(6);
			index=selectedItem->parent()->indexOfChild(selectedItem);
			if(index!=-1)
				ui->stackedOptionsSessionLoader->setCurrentIndex(index);
			else
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"selection into of sub item wrong???");
		}
		else
			ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"selection into option list cat not found");
	}
}

void OptionDialog::on_buttonBox_clicked(QAbstractButton *button)
{
	if(ui->buttonBox->buttonRole(button)==QDialogButtonBox::ResetRole)
		options->queryResetOptions();
	else
		this->close();
}

void OptionDialog::loadOption()
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
	newOptionValue("Themes",	"Ultracopier_current_theme",	options->getOptionValue("Themes","Ultracopier_current_theme"));
	newOptionValue("Ultracopier",	"ActionOnManualOpen",		options->getOptionValue("Ultracopier","ActionOnManualOpen"));
	newOptionValue("Ultracopier",	"GroupWindowWhen",		options->getOptionValue("Ultracopier","GroupWindowWhen"));
	newOptionValue("Language",	"Language",			options->getOptionValue("Language","Language"));
	newOptionValue("Language",	"Language_autodetect",		options->getOptionValue("Language","Language_autodetect"));
	newOptionValue("SessionLoader",	"LoadAtSessionStarting",	options->getOptionValue("SessionLoader","LoadAtSessionStarting"));
	newOptionValue("CopyListener",	"CatchCopyAsDefault",		options->getOptionValue("CopyListener","CatchCopyAsDefault"));
	newOptionValue("CopyEngine",	"List",				options->getOptionValue("CopyEngine","List"));
	if(resources->getWritablePath()=="")
		ui->checkBox_Log->setEnabled(false);
	else
	{
		newOptionValue("Write_log",	"enabled",			options->getOptionValue("Write_log","enabled"));
		newOptionValue("Write_log",	"file",				options->getOptionValue("Write_log","file"));
		newOptionValue("Write_log",	"transfer",			options->getOptionValue("Write_log","transfer"));
		newOptionValue("Write_log",	"error",			options->getOptionValue("Write_log","error"));
		newOptionValue("Write_log",	"folder",			options->getOptionValue("Write_log","folder"));
		newOptionValue("Write_log",	"transfer_format",		options->getOptionValue("Write_log","transfer_format"));
		newOptionValue("Write_log",	"error_format",			options->getOptionValue("Write_log","error_format"));
		newOptionValue("Write_log",	"folder_format",		options->getOptionValue("Write_log","folder_format"));
		newOptionValue("Write_log",	"sync",				options->getOptionValue("Write_log","sync"));
	}
	on_checkBox_Log_clicked();
	if(plugins->getPluginsByCategory(PluginType_SessionLoader).size()>0)
	{
		ui->labelLoadAtSession->setToolTip("");
		ui->LoadAtSessionStarting->setToolTip("");
		ui->labelLoadAtSession->setEnabled(true);
		ui->LoadAtSessionStarting->setEnabled(true);
	}
	else
	{
		ui->labelLoadAtSession->setToolTip(tr("Disabled because you have any SessionLoader plugin"));
		ui->LoadAtSessionStarting->setToolTip(tr("Disabled because you have any SessionLoader plugin"));
		ui->labelLoadAtSession->setEnabled(false);
		ui->LoadAtSessionStarting->setEnabled(false);
	}
	allPluginsIsLoaded=true;
	on_Ultracopier_current_theme_currentIndexChanged(ui->Ultracopier_current_theme->currentIndex());
}

void OptionDialog::newOptionValue(QString group,QString name,QVariant value)
{
	if(group=="Themes")
	{
		if(name=="Ultracopier_current_theme")
		{
			int index=ui->Ultracopier_current_theme->findData(value.toString());
			if(index!=-1)
			{
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"Themes located: "+value.toString());
				ui->Ultracopier_current_theme->setCurrentIndex(index);
			}
			else
			{
				if(ui->Ultracopier_current_theme->count()>0)
				{
					ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Default to the current value: "+ui->Ultracopier_current_theme->itemData(ui->Ultracopier_current_theme->currentIndex()).toString());
					options->setOptionValue("Themes","Ultracopier_current_theme",ui->Ultracopier_current_theme->itemData(ui->Ultracopier_current_theme->currentIndex()));
				}
				else
					ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"No themes: "+value.toString());
			}
		}
	}
	else if(group=="Language")
	{
		if(name=="Language")
		{
			int index=ui->Language->findData(value.toString());
			if(index!=-1)
				ui->Language->setCurrentIndex(index);
			else if(ui->Language->count()>0)
			{
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"Language in settings: "+value.toString());
				options->setOptionValue("Language","Language",ui->Language->itemData(ui->Language->currentIndex()));
			}
		}
		else if(name=="Language_autodetect")
		{
			ui->Language_autodetect->setChecked(value.toBool());
			ui->Language->setDisabled(value.toBool());
		}
	}
	else if(group=="SessionLoader")
	{
		if(name=="LoadAtSessionStarting")
		{
			ui->LoadAtSessionStarting->setChecked(value.toBool());
		}
	}
	else if(group=="CopyListener")
	{
		if(name=="CatchCopyAsDefault")
		{
			ui->CatchCopyAsDefault->setChecked(value.toBool());
		}
	}
	else if(group=="CopyEngine")
	{
		if(name=="List")
		{
			if(!ignoreCopyEngineListEdition)
			{
				QStringList copyEngine=value.toStringList();
				copyEngine.removeDuplicates();
				int index=0;
				int loop_size=ui->CopyEngineList->count();
				while(index<loop_size)
				{
					copyEngine.removeOne(ui->CopyEngineList->item(index)->text());
					index++;
				}
				ui->CopyEngineList->addItems(copyEngine);
			}
		}
	}
	else if(group=="Write_log")
	{
		if(name=="enabled")
		{
			ui->checkBox_Log->setChecked(value.toBool());
		}
		else if(name=="file")
		{
			ui->lineEditLog_File->setText(value.toString());
		}
		else if(name=="transfer")
		{
			ui->checkBoxLog_transfer->setChecked(value.toBool());
		}
		else if(name=="sync")
		{
			ui->checkBoxLog_sync->setChecked(value.toBool());
		}
		else if(name=="error")
		{
			ui->checkBoxLog_error->setChecked(value.toBool());
		}
		else if(name=="folder")
		{
			ui->checkBoxLog_folder->setChecked(value.toBool());
		}
		else if(name=="transfer_format")
		{
			ui->lineEditLog_transfer_format->setText(value.toString());
		}
		else if(name=="error_format")
		{
			ui->lineEditLog_error_format->setText(value.toString());
		}
		else if(name=="folder_format")
		{
			ui->lineEditLog_folder_format->setText(value.toString());
		}
	}
	else if(group=="Ultracopier")
	{
		if(name=="ActionOnManualOpen")
		{
			ui->ActionOnManualOpen->setCurrentIndex(value.toInt());
		}
		if(name=="GroupWindowWhen")
		{
			ui->GroupWindowWhen->setCurrentIndex(value.toInt());
		}
	}
}

void OptionDialog::on_Ultracopier_current_theme_currentIndexChanged(int index)
{
	if(index!=-1 && allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"data value: "+ui->Ultracopier_current_theme->itemData(index).toString()+", string value: "+ui->Ultracopier_current_theme->itemText(index)+", index: "+QString::number(index));
		options->setOptionValue("Themes","Ultracopier_current_theme",ui->Ultracopier_current_theme->itemData(index));
		int index_loop=0;
		loop_size=pluginOptionsWidgetList.size();
		while(index_loop<loop_size)
		{
			if(pluginOptionsWidgetList.at(index_loop).name==ui->Ultracopier_current_theme->itemData(index).toString())
			{
				if(pluginOptionsWidgetList.at(index_loop).options==NULL)
					ui->stackedWidgetThemes->setCurrentIndex(1);
				else
					ui->stackedWidgetThemes->setCurrentWidget(pluginOptionsWidgetList.at(index_loop).options);
				return;
			}
			index_loop++;
		}
		ui->stackedWidgetThemes->setCurrentIndex(0);
	}
}

void OptionDialog::on_Language_currentIndexChanged(int index)
{
	if(index!=-1 && allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"data value: "+ui->Language->itemData(index).toString()+", string value: "+ui->Language->itemText(index)+", index: "+QString::number(index));
		options->setOptionValue("Language","Language",ui->Language->itemData(index));
	}
}

void OptionDialog::on_Language_autodetect_toggled(bool checked)
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Language","Language_autodetect",checked);
	}
}

void OptionDialog::on_CatchCopyAsDefault_toggled(bool checked)
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("CopyListener","CatchCopyAsDefault",checked);
	}
}

void OptionDialog::on_LoadAtSessionStarting_toggled(bool checked)
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("SessionLoader","LoadAtSessionStarting",checked);
	}
}

void OptionDialog::on_CopyEngineList_itemSelectionChanged()
{
	if(ui->CopyEngineList->selectedItems().size()!=0 && ui->CopyEngineList->count()>1)
	{
		ui->toolButtonUp->setEnabled(true);
		ui->toolButtonDown->setEnabled(true);
	}
	else
	{
		ui->toolButtonUp->setEnabled(false);
		ui->toolButtonDown->setEnabled(false);
	}
}

void OptionDialog::on_toolButtonDown_clicked()
{
	QListWidgetItem *item=ui->CopyEngineList->selectedItems().first();
	int position=ui->CopyEngineList->row(item);
	if((position+1)<ui->CopyEngineList->count())
	{
		QString text=item->text();
		item->setSelected(false);
		delete item;
		ui->CopyEngineList->insertItem(position+1,text);
		ui->CopyEngineList->item(position+1)->setSelected(true);
		ignoreCopyEngineListEdition=true;
		options->setOptionValue("CopyEngine","List",copyEngineStringList());
		ignoreCopyEngineListEdition=false;
	}
}

void OptionDialog::on_toolButtonUp_clicked()
{
	QListWidgetItem *item=ui->CopyEngineList->selectedItems().first();
	int position=ui->CopyEngineList->row(item);
	if(position>0)
	{
		QString text=item->text();
		item->setSelected(false);
		delete item;
		ui->CopyEngineList->insertItem(position-1,text);
		ui->CopyEngineList->item(position-1)->setSelected(true);
		ignoreCopyEngineListEdition=true;
		options->setOptionValue("CopyEngine","List",copyEngineStringList());
		ignoreCopyEngineListEdition=false;
	}
}

QStringList OptionDialog::copyEngineStringList()
{
	QStringList newList;
	int index=0;
	while(index<ui->CopyEngineList->count())
	{
		newList << ui->CopyEngineList->item(index)->text();
		index++;
	}
	return newList;
}

void OptionDialog::newThemeOptions(QString name,QWidget* theNewOptionsWidget,bool isLoaded,bool havePlugin)
{
	Q_UNUSED(isLoaded);
	Q_UNUSED(havePlugin);
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("start: isLoaded: %1, havePlugin: %2, name: %3").arg(isLoaded).arg(havePlugin).arg(name));
	pluginOptionsWidget tempItem;
	tempItem.name=name;
	tempItem.item=NULL;
	tempItem.options=theNewOptionsWidget;
	tempItem.category=PluginType_Themes;
	pluginOptionsWidgetList << tempItem;
	if(theNewOptionsWidget!=NULL)
	{
		ui->stackedWidgetThemes->addWidget(theNewOptionsWidget);
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"set the last page");
	}
	on_Ultracopier_current_theme_currentIndexChanged(ui->Ultracopier_current_theme->currentIndex());
}

void OptionDialog::addPluginOptionWidget(PluginType category,QString name,QWidget * options)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("start: %1, category: %2").arg(name).arg(category));
	//prevent send the empty options
	if(options!=NULL)
	{
		index=0;
		loop_size=pluginOptionsWidgetList.size();
		while(index<loop_size)
		{
			if(pluginOptionsWidgetList.at(index).name==name)
			{
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"already found: "+name);
				return;
			}
			index++;
		}
		//add to real list
		pluginOptionsWidget temp;
		temp.name=name;
		temp.options=options;
		temp.item=new QTreeWidgetItem(QStringList() << name);
		temp.category=category;
		pluginOptionsWidgetList << temp;
		//add the specific options
		switch(category)
		{
		case PluginType_CopyEngine:
			ui->treeWidget->topLevelItem(2)->addChild(pluginOptionsWidgetList.at(index).item);
			ui->stackedOptionsCopyEngine->addWidget(options);
			break;
		case PluginType_Listener:
			ui->treeWidget->topLevelItem(3)->addChild(pluginOptionsWidgetList.at(index).item);
			ui->stackedOptionsListener->addWidget(options);
			break;
		case PluginType_PluginLoader:
			ui->treeWidget->topLevelItem(4)->addChild(pluginOptionsWidgetList.at(index).item);
			ui->stackedOptionsPluginLoader->addWidget(options);
			break;
		case PluginType_SessionLoader:
			ui->treeWidget->topLevelItem(5)->addChild(pluginOptionsWidgetList.at(index).item);
			ui->stackedOptionsSessionLoader->addWidget(options);
			break;
		default:
			ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"Unable to parse this unknow type of plugin: "+name);
			return;
		}
	}
	//only for copy engine
	if(category==PluginType_CopyEngine)
	{
		//but can loaded by the previous options
		index=0;
		loop_size=ui->CopyEngineList->count();
		while(index<loop_size)
		{
			if(ui->CopyEngineList->item(index)->text()==name)
				break;
			index++;
		}
		if(index==loop_size)
			ui->CopyEngineList->addItems(QStringList() << name);
	}
}

void OptionDialog::on_pluginList_itemSelectionChanged()
{
	if(ui->pluginList->selectedItems().size()==0)
	{
		ui->pluginRemove->setEnabled(false);
		ui->pluginInformation->setEnabled(false);
	}
	else
	{
		treeWidgetItem=ui->pluginList->selectedItems().first();
		index=0;
		loop_size=pluginLink.size();
		while(index<loop_size)
		{
			if(pluginLink.at(index).item==treeWidgetItem)
			{
				ui->pluginRemove->setEnabled(pluginLink.at(index).isWritable);
				ui->pluginInformation->setEnabled(true);
				return;
			}
			index++;
		}
	}
}

void OptionDialog::on_pluginRemove_clicked()
{
	treeWidgetItem=ui->pluginList->selectedItems().first();
	index=0;
	loop_size=pluginLink.size();
	while(index<loop_size)
	{
		if(pluginLink.at(index).item==treeWidgetItem)
		{
			plugins->removeThePluginSelected(pluginLink.at(index).path);
			return;
		}
		index++;
	}
}

void OptionDialog::on_pluginInformation_clicked()
{
	treeWidgetItem=ui->pluginList->selectedItems().first();
	index=0;
	loop_size=pluginLink.size();
	while(index<loop_size)
	{
		if(pluginLink.at(index).item==treeWidgetItem)
		{
			plugins->showInformation(pluginLink.at(index).path);
			return;
		}
		index++;
	}
}

void OptionDialog::on_pluginAdd_clicked()
{
	plugins->addPlugin(defaultImportBackend);
}

void OptionDialog::on_checkBox_Log_clicked()
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Write_log","enabled",ui->checkBox_Log->isChecked());
	}
	ui->lineEditLog_transfer_format->setEnabled(ui->checkBoxLog_transfer->isChecked() && ui->checkBox_Log->isChecked());
	ui->lineEditLog_error_format->setEnabled(ui->checkBoxLog_error->isChecked() && ui->checkBox_Log->isChecked());
	ui->lineEditLog_folder_format->setEnabled(ui->checkBoxLog_folder->isChecked() && ui->checkBox_Log->isChecked());
}

void OptionDialog::on_lineEditLog_File_editingFinished()
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Write_log","file",ui->lineEditLog_File->text());
	}
}

void OptionDialog::on_lineEditLog_transfer_format_editingFinished()
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Write_log","transfer_format",ui->lineEditLog_transfer_format->text());
	}
}

void OptionDialog::on_lineEditLog_error_format_editingFinished()
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Write_log","error_format",ui->lineEditLog_error_format->text());
	}
}

void OptionDialog::on_checkBoxLog_transfer_clicked()
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Write_log","transfer",ui->checkBoxLog_transfer->isChecked());
	}
}

void OptionDialog::on_checkBoxLog_error_clicked()
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Write_log","error",ui->checkBoxLog_error->isChecked());
	}
}

void OptionDialog::on_checkBoxLog_folder_clicked()
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Write_log","folder",ui->checkBoxLog_folder->isChecked());
	}
}

void OptionDialog::on_pushButton_clicked()
{
	QString file=QFileDialog::getSaveFileName(this,tr("Save logs as: "),resources->getWritablePath());
	if(file!="")
	{
		ui->lineEditLog_File->setText(file);
		on_lineEditLog_File_editingFinished();
	}
}

void OptionDialog::on_checkBoxLog_sync_clicked()
{
	if(allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
		options->setOptionValue("Write_log","sync",ui->checkBoxLog_sync->isChecked());
	}
}

void OptionDialog::on_ActionOnManualOpen_currentIndexChanged(int index)
{
	if(index!=-1 && allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"data value: "+ui->ActionOnManualOpen->itemData(index).toString()+", string value: "+ui->ActionOnManualOpen->itemText(index)+", index: "+QString::number(index));
		options->setOptionValue("Ultracopier","ActionOnManualOpen",index);
	}
}

void OptionDialog::on_GroupWindowWhen_currentIndexChanged(int index)
{
	if(index!=-1 && allPluginsIsLoaded)
	{
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"data value: "+ui->GroupWindowWhen->itemData(index).toString()+", string value: "+ui->GroupWindowWhen->itemText(index)+", index: "+QString::number(index));
		options->setOptionValue("Ultracopier","GroupWindowWhen",index);
	}
}