summaryrefslogtreecommitdiffstats
path: root/configurationdialog.cpp
blob: 0654ea704a173d40b3ef6123cc3baa2b66aa7a59 (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
/*
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version
  2 of the License, or (at your option) any later version.
*/

#include <QPushButton>
#include <QTabWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QFormLayout>
#include <QLineEdit>
#include <QLabel>
#include <QComboBox>
#include <QDirModel>
#include <QCompleter>
#include <QApplication>
#include <QSettings>
#include <QRegExp>
#include <QFileInfo>
#include <QGroupBox>
#include <QCheckBox>
#include <QSpinBox>
#include <QFileInfo>
#include <QMessageBox>
#include <QFile>
#include <QTextStream>
#include <QRegExpValidator>
#include <QSignalMapper>
#include <QColor>
#include <QColorDialog>
#include <QPalette>
#include <QImage>
#include <QPainter>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QDesktopWidget>
#include <QInputDialog>

#include "configurationdialog.h"
#include "programconfigurator.h"
#include "smglobals.h"
#include "helper.h"

ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : SmDialog(parent, f) {
	//setup
	mTab = new QTabWidget;
	QDirModel *model = new QDirModel(this);
	QCompleter *fsCompleter = new QCompleter(this);
	fsCompleter->setModel(model);
	fsCompleter->setCompletionMode(QCompleter::PopupCompletion);

	//directories tab
	//directories
	QWidget *pathWidget = new QWidget;
	QGroupBox *pathBox = new QGroupBox(tr("Paths"));
    QFormLayout *pathL = new QFormLayout;
	mArchiveDir = new QLineEdit;
	mArchiveDir->setCompleter(fsCompleter);
    pathL->addRow(tr("Archive directory"), mArchiveDir);
	mBurnDir = new QLineEdit;
	mBurnDir->setCompleter(fsCompleter);
    pathL->addRow(tr("Burn directory"), mBurnDir);
    mUSBDir = new QLineEdit;
    mUSBDir->setCompleter(fsCompleter);
    pathL->addRow(tr("USB directory"), mUSBDir);
	mFfProbePath = new QLineEdit;
	mFfProbePath->setCompleter(fsCompleter);
    pathL->addRow(tr("Path to ffprobe"), mFfProbePath);
	mFfMpegPath = new QLineEdit;
	mFfMpegPath->setCompleter(fsCompleter);
    pathL->addRow(tr("Path to ffmpeg"), mFfMpegPath);
	mDvdMountPath = new QLineEdit;
    pathL->addRow(tr("DVD mount directory"), mDvdMountPath);
	mCoverPath = new QLineEdit;
	mCoverPath->setCompleter(fsCompleter);
    pathL->addRow(tr("Cover directory"), mCoverPath);
    pathBox->setLayout(pathL);
	QVBoxLayout *pathLayout = new QVBoxLayout;
	pathLayout->addWidget(pathBox);
	pathWidget->setLayout(pathLayout);

	//copy path options
	QGroupBox *copyBox = new QGroupBox(tr("Copy path options"));
    QFormLayout *copyL = new QFormLayout;
	mWindowsDrive = new QLineEdit;
	QRegExp pathValid("[a-z]{1}:");
	pathValid.setCaseSensitivity(Qt::CaseInsensitive);
	QRegExpValidator *pathValidator = new QRegExpValidator(pathValid, this);
	mWindowsDrive->setValidator(pathValidator);
    copyL->addRow(tr("Windows drive"), mWindowsDrive);
	mStripPath = new QLineEdit;
    copyL->addRow(tr("Strip from path"), mStripPath);
    copyBox->setLayout(copyL);
	pathLayout->addWidget(copyBox);

    //expensive option
    QGroupBox *expensiveBox = new QGroupBox(tr("Expensive file operations"));
    QHBoxLayout *expensiveL = new QHBoxLayout;
    mExpensive = new QCheckBox(tr("Do expenive file operations"));
    expensiveL->addWidget(mExpensive);
    expensiveBox->setLayout(expensiveL);
    pathLayout->addWidget(expensiveBox);
    pathLayout->addStretch(Qt::Vertical);
    mTab->addTab(pathWidget, tr("Files"));

	//misc tab
	QWidget *miscWidget = new QWidget;
	QVBoxLayout *miscLayout = new QVBoxLayout;
	miscLayout->setAlignment(Qt::AlignTop);

	//misc - hover
	QGroupBox *hoverBox = new QGroupBox(tr("Hover options"));
	QVBoxLayout *hoverLayout = new QVBoxLayout;
	mHoverPics = new QCheckBox(tr("Show picture when hovering"));
	hoverLayout->addWidget(mHoverPics);
	mHoverOpacity = new QSpinBox;
	mHoverOpacity->setMinimum(1);
	mHoverOpacity->setMaximum(10);
	QGridLayout *miscInputGrid = new QGridLayout;
	QLabel *miscl6 = new QLabel(tr("Opacity of hover window"));
	miscInputGrid->addWidget(miscl6, 0, 0);
	miscInputGrid->addWidget(mHoverOpacity, 0, 1);
	QLabel *miscl8 = new QLabel(tr("Y cursor offset (hover)"));
	mCursorOffset = new QSpinBox;
	mCursorOffset->setMinimum(-100);
	mCursorOffset->setMaximum(100);
	miscInputGrid->addWidget(miscl8, 2, 0);
	miscInputGrid->addWidget(mCursorOffset, 2, 1);
	hoverLayout->addLayout(miscInputGrid);
	hoverBox->setLayout(hoverLayout);

	//misc - archiving movies
	QGroupBox *archiveBox = new QGroupBox(tr("Archiving options"));
	QVBoxLayout *archiveLayout = new QVBoxLayout;
	mAutoAddCovers = new QCheckBox(tr("Automatically add covers"));
	archiveLayout->addWidget(mAutoAddCovers);
	mIconizeCovers = new QCheckBox(tr("Iconize covers"));
	archiveLayout->addWidget(mIconizeCovers);
	archiveBox->setLayout(archiveLayout);

    //auto refresh
    QGroupBox *autoRefreshBox = new QGroupBox(tr("Auto Refresh"));
    QVBoxLayout *autoRefreshLayout = new QVBoxLayout;
    mAutoRefresh = new QCheckBox(tr("Automatically refresh directory"));
    autoRefreshLayout->addWidget(mAutoRefresh);
    QLabel *refreshL1 = new QLabel(tr("Refresh every (s)"));
    mAutoRefreshValue = new QSpinBox;
    mAutoRefreshValue->setMinimum(5);
    mAutoRefreshValue->setValue(5);
    QHBoxLayout *autoSpinLayout = new QHBoxLayout;
    autoSpinLayout->addWidget(refreshL1);
    autoSpinLayout->addWidget(mAutoRefreshValue);
    QVBoxLayout *autoRefreshBoxL = new QVBoxLayout;
    autoRefreshBoxL->addWidget(mAutoRefresh);
    autoRefreshBoxL->addLayout(autoSpinLayout);
    autoRefreshBox->setLayout(autoRefreshBoxL);

    //misc - clear wizard?
    QGroupBox *clearWizardBox = new QGroupBox(tr("New movie Wizard"));
    QVBoxLayout *clearWizardLayout = new QVBoxLayout;
    mClearNewMovieWizard = new QCheckBox(tr("Clear new movie Wizard"));
    mClearNewMovieWizard->setChecked(false);
    clearWizardLayout->addWidget(mClearNewMovieWizard);
    clearWizardBox->setLayout(clearWizardLayout);

    //misc - assemble
	miscLayout->addWidget(hoverBox);
	miscLayout->addWidget(archiveBox);
    miscLayout->addWidget(autoRefreshBox);
    miscLayout->addWidget(clearWizardBox);
	miscWidget->setLayout(miscLayout);
	mTab->addTab(miscWidget, tr("Misc. settings"));

    // icons
    mIconModel = new QStandardItemModel;
    const QHash<QString, QString> icons = SmGlobals::instance()->icons();
    for(QHash<QString, QString>::const_iterator it = icons.constBegin(); it != icons.constEnd(); ++it){
        QStandardItem *item = new QStandardItem(QIcon(it.value()), it.key());
        mIconModel->appendRow(item);
    }
    QGroupBox *folderIconBox = new QGroupBox(tr("Icon for folders"));
    QHBoxLayout *folderIconLayout = new QHBoxLayout;
    mIconForFolder = new QComboBox;
    mIconForFolder->setModel(mIconModel);
    folderIconLayout->addWidget(mIconForFolder);
    folderIconBox->setLayout(folderIconLayout);

    QGroupBox *fileIconBox = new QGroupBox(tr("Icon for files"));
    QHBoxLayout *fileIconLayout = new QHBoxLayout;
    mIconForFile = new QComboBox;
    mIconForFile->setModel(mIconModel);
    fileIconLayout->addWidget(mIconForFile);
    fileIconBox->setLayout(fileIconLayout);

    QGroupBox *seriesIconBox = new QGroupBox(tr("Icon for series"));
    QHBoxLayout *seriesIconLayout = new QHBoxLayout;
    mIconForSeries= new QComboBox;
    mIconForSeries->setModel(mIconModel);
    seriesIconLayout->addWidget(mIconForSeries);
    seriesIconBox->setLayout(seriesIconLayout);

    QGroupBox *actorIconBox = new QGroupBox(tr("Icon for actors"));
    QHBoxLayout *actorIconLayout = new QHBoxLayout;
    mIconForActor = new QComboBox;
    mIconForActor->setModel(mIconModel);
    actorIconLayout->addWidget(mIconForActor);
    actorIconBox->setLayout(actorIconLayout);

    QGroupBox *genreIconBox = new QGroupBox(tr("Icon for genres"));
    QHBoxLayout *genreIconLayout = new QHBoxLayout;
    mIconForGenre = new QComboBox;
    mIconForGenre->setModel(mIconModel);
    genreIconLayout->addWidget(mIconForGenre);
    genreIconBox->setLayout(genreIconLayout);

    QGroupBox *metaIconBox = new QGroupBox(tr("Icon for metadata"));
    QHBoxLayout *metaIconLayout = new QHBoxLayout;
    mIconForMeta = new QComboBox;
    mIconForMeta->setModel(mIconModel);
    metaIconLayout->addWidget(mIconForMeta);
    metaIconBox->setLayout(metaIconLayout);

    QVBoxLayout *iconWidgetLayout = new QVBoxLayout;
    iconWidgetLayout->addWidget(folderIconBox);
    iconWidgetLayout->addWidget(fileIconBox);
    iconWidgetLayout->addWidget(seriesIconBox);
    iconWidgetLayout->addWidget(actorIconBox);
    iconWidgetLayout->addWidget(genreIconBox);
    iconWidgetLayout->addWidget(metaIconBox);
    iconWidgetLayout->addStretch();
    QWidget *iconWidget = new QWidget;
    iconWidget->setLayout(iconWidgetLayout);
    mTab->addTab(iconWidget, tr("Icons"));

	// movie viewer
    QGroupBox *movieBox = new QGroupBox(tr("Movie viewer"));
    QHBoxLayout *movieBoxLayout = new QHBoxLayout;
	mMovieConfig = new ProgramConfigurator("movieviewer", "Movie viewer");
    movieBoxLayout->addWidget(mMovieConfig);
    movieBox->setLayout(movieBoxLayout);
    QWidget *movieWidget = new QWidget;
    QVBoxLayout *movieWidgetLayout = new QVBoxLayout;
    movieWidgetLayout->addWidget(movieBox);
    QGroupBox *reasonBox = new QGroupBox(tr("Reencode reasons"));
    QLabel *rbl1 = new QLabel(tr("Reasons"));
    mReasonsBox = new QComboBox;
    QStringList reasons = SmGlobals::instance()->reencReasons();
    mReasonsBox->addItems(reasons);
    QPushButton *editRBtn = new QPushButton(tr("Edit..."));
    connect(editRBtn, SIGNAL(clicked()), this, SLOT(editReason()));
    QPushButton *newRBtn = new QPushButton(tr("Add..."));
    connect(newRBtn, SIGNAL(clicked()), this, SLOT(addReason()));
    QPushButton *delRBtn = new QPushButton(tr("Delete..."));
    connect(delRBtn, SIGNAL(clicked()), this, SLOT(delReason()));
    QVBoxLayout *reasonL = new QVBoxLayout;
    QHBoxLayout *reasonCBL = new QHBoxLayout;
    reasonCBL->addWidget(rbl1);
    reasonCBL->addWidget(mReasonsBox);
    reasonCBL->setStretch(1, 3);
    QHBoxLayout *reasonBL = new QHBoxLayout;
    reasonBL->addStretch();
    reasonBL->addWidget(newRBtn);
    reasonBL->addWidget(editRBtn);
    reasonBL->addWidget(delRBtn);
    reasonL->addLayout(reasonCBL);
    reasonL->addLayout(reasonBL);
    reasonBox->setLayout(reasonL);
    movieWidgetLayout->addWidget(reasonBox);
    movieWidgetLayout->addStretch();
    movieWidget->setLayout(movieWidgetLayout);
    mTab->addTab(movieWidget, tr("Movies"));

    //picture viewer - information
    createPositionMap();
    QFormLayout *pvInfoL = new QFormLayout;
    QGroupBox *picInfoBox = new QGroupBox(tr("Show additional info"));
    mInfoBox = new QComboBox;
    fillPositions(mInfoBox);
    pvInfoL->addRow(tr("Picture information position"), mInfoBox);
    mMapBox = new QComboBox;
    fillPositions(mMapBox);
    pvInfoL->addRow(tr("Picture mapping information"), mMapBox);
    picInfoBox->setLayout(pvInfoL);

    //picture viewer - size
    QFormLayout *pvSizeWHL = new QFormLayout;
    QVBoxLayout *pvSizeL = new QVBoxLayout;
    pvSizeL->addLayout(pvSizeWHL);

    //picture viewer - layout
    QWidget *picWidget = new QWidget;
    QVBoxLayout *picLayout = new QVBoxLayout;
    picLayout->addWidget(picInfoBox);
    picLayout->addStretch();
    picWidget->setLayout(picLayout);

    mTab->addTab(picWidget, tr("Pictures"));

	//database tab
    QFormLayout *dbFormL = new QFormLayout;
	mDatabaseHost = new QLineEdit;
    dbFormL->addRow(tr("Database &host"), mDatabaseHost);
	mDatabaseName = new QLineEdit;
    dbFormL->addRow(tr("Database &name"), mDatabaseName);
	mDatabaseUsername = new QLineEdit;
    dbFormL->addRow(tr("Database &user"), mDatabaseUsername);
    mDatabasePassword = new QLineEdit;
	mDatabasePassword->setEchoMode(QLineEdit::Password);
    dbFormL->addRow(tr("Database &password"), mDatabasePassword);
    QGroupBox *dbBox = new QGroupBox(tr("Database connection"));
    dbBox->setLayout(dbFormL);
    QVBoxLayout *dbWidgetLayout = new QVBoxLayout;
    dbWidgetLayout->addWidget(dbBox);
    dbWidgetLayout->addStretch();
    QWidget *dbWidget = new QWidget;
    dbWidget->setLayout(dbWidgetLayout);
    mTab->addTab(dbWidget, tr("Database"));

	//colors tab
	QWidget *colorsWidget = new QWidget;
	QGridLayout *colorGrid = new QGridLayout;
	QSignalMapper *colorMapper = new QSignalMapper(this);
	QLabel *colorl2 = new QLabel(tr("Files in clipboard"));
	mClipboardColor = new QLabel;
	mClipboardColor->setFrameStyle(QFrame::Sunken | QFrame::Panel);
	mClipboardColor->setScaledContents(true);
	mClipboardButton = new QPushButton(tr("Choose..."));
	colorGrid->addWidget(colorl2, 1, 0);
	colorGrid->addWidget(mClipboardColor, 1, 1);
	colorGrid->addWidget(mClipboardButton, 1, 2);
	colorMapper->setMapping(mClipboardButton, mClipboardColor);
	connect(mClipboardButton, SIGNAL(clicked()), colorMapper, SLOT(map()));
	QLabel *colorl3 = new QLabel(tr("Base color for rows"));
	mBaseColor = new QLabel;
	mBaseColor->setFrameStyle(QFrame::Sunken | QFrame::Panel);
	mBaseColor->setScaledContents(true);
	mBaseButton = new QPushButton(tr("Choose..."));
	colorGrid->addWidget(colorl3, 2, 0);
	colorGrid->addWidget(mBaseColor, 2, 1);
	colorGrid->addWidget(mBaseButton, 2, 2);
	colorMapper->setMapping(mBaseButton, mBaseColor);
	connect(mBaseButton, SIGNAL(clicked()), colorMapper, SLOT(map()));
	QLabel *colorl4 = new QLabel(tr("Alternate base for rows"));
	mAlternateBaseColor = new QLabel;
	mAlternateBaseColor->setFrameStyle(QFrame::Sunken | QFrame::Panel);
	mAlternateBaseColor->setScaledContents(true);
	mAlternateBaseButton = new QPushButton(tr("Choose..."));
	colorGrid->addWidget(colorl4, 3, 0);
	colorGrid->addWidget(mAlternateBaseColor, 3, 1);
	colorGrid->addWidget(mAlternateBaseButton, 3, 2);
	colorMapper->setMapping(mAlternateBaseButton, mAlternateBaseColor);
	connect(mAlternateBaseButton, SIGNAL(clicked()), colorMapper, SLOT(map()));
	QLabel *colorl5 = new QLabel(tr("Font color"));
	mFontColor = new QLabel;
	mFontColor->setFrameStyle(QFrame::Sunken | QFrame::Panel);
	mFontColor->setScaledContents(true);
	mFontColorButton = new QPushButton(tr("Choose..."));
	colorGrid->addWidget(colorl5, 4, 0);
	colorGrid->addWidget(mFontColor, 4, 1);
	colorGrid->addWidget(mFontColorButton, 4, 2);
	colorMapper->setMapping(mFontColorButton, mFontColor);
	connect(mFontColorButton, SIGNAL(clicked()), colorMapper, SLOT(map()));
	QLabel *colorl6 = new QLabel(tr("Local files"));
	mLocalColor = new QLabel;
	mLocalColor->setFrameStyle(QFrame::Sunken | QFrame::Panel);
	mLocalColor->setScaledContents(true);
	mLocalColorButton = new QPushButton(tr("Choose..."));
	colorGrid->addWidget(colorl6, 5, 0);
	colorGrid->addWidget(mLocalColor, 5, 1);
	colorGrid->addWidget(mLocalColorButton, 5, 2);
	colorMapper->setMapping(mLocalColorButton, mLocalColor);
	connect(mLocalColorButton, SIGNAL(clicked()), colorMapper, SLOT(map()));
	QLabel *colorl7 = new QLabel(tr("Archived Files"));
	mArchivedColor = new QLabel;
	mArchivedColor->setFrameStyle(QFrame::Sunken | QFrame::Panel);
	mArchivedColor->setScaledContents(true);
	mArchivedColorButton = new QPushButton(tr("Choose..."));
	colorGrid->addWidget(colorl7, 6, 0);
	colorGrid->addWidget(mArchivedColor, 6, 1);
	colorGrid->addWidget(mArchivedColorButton, 6, 2);
	colorMapper->setMapping(mArchivedColorButton, mArchivedColor);
	connect(mArchivedColorButton, SIGNAL(clicked()), colorMapper, SLOT(map()));
	QLabel *colorl8 = new QLabel(tr("Favorites"));
	mFavoriteColor = new QLabel;
	mFavoriteColor->setFrameStyle(QFrame::Sunken | QFrame::Panel);
	mFavoriteColor->setScaledContents(true);
	mFavoriteColorButton = new QPushButton(tr("Choose..."));
	colorGrid->addWidget(colorl8, 7, 0);
	colorGrid->addWidget(mFavoriteColor, 7, 1);
	colorGrid->addWidget(mFavoriteColorButton, 7, 2);
	colorMapper->setMapping(mFavoriteColorButton, mFavoriteColor);
	connect(mFavoriteColorButton, SIGNAL(clicked()), colorMapper, SLOT(map()));
    mAlternateColors = new QCheckBox(tr("Use alternating row colors"));
	mAlternateColors->setTristate(false);
	connect(mAlternateColors, SIGNAL(stateChanged(int)), this, SLOT(alternateColorsChanged(int)));
	colorGrid->addWidget(mAlternateColors, 8, 1, 1, 2, Qt::AlignLeft);
    colorsWidget->setLayout(colorGrid);

    QLabel *color9 = new QLabel(tr("PicViewer Background"));
    mPVBgColor = new QLabel;
    mPVBgColor->setFrameStyle(QFrame::Sunken | QFrame::Panel);
    mPVBgColor->setScaledContents(true);
    mPVBgButton = new QPushButton(tr("Choose..."));
    QGridLayout *pvGrid = new QGridLayout;
    pvGrid->addWidget(color9, 0, 0);
    pvGrid->addWidget(mPVBgColor, 0, 1);
    pvGrid->addWidget(mPVBgButton, 0, 2);
    colorMapper->setMapping(mPVBgButton, mPVBgColor);
    connect(mPVBgButton, SIGNAL(clicked()), colorMapper, SLOT(map()));
    mPVGradient = new QCheckBox(tr("Use random gradient as background"));
    mPVGradient->setTristate(false);
    connect(mPVGradient, SIGNAL(stateChanged(int)), this, SLOT(randomGradientChanged(int)));
    pvGrid->addWidget(mPVGradient, 1, 1, 1, 2, Qt::AlignLeft);

    connect(colorMapper, SIGNAL(mapped(QWidget*)), this, SLOT(chooseColor(QWidget*)));
    QGroupBox *treeGB = new QGroupBox(tr("Treeview colors"));
    treeGB->setLayout(colorGrid);
    QGroupBox *pvGB = new QGroupBox(tr("PicViewer colors"));
    pvGB->setLayout(pvGrid);
    QVBoxLayout *colorLayout = new QVBoxLayout;
    colorLayout->addWidget(treeGB);
    colorLayout->addWidget(pvGB);
    colorsWidget->setLayout(colorLayout);
	mTab->addTab(colorsWidget, tr("Colors"));

	//main layout
	mOk = new QPushButton(tr("Ok"));
	connect(mOk, SIGNAL(clicked()), this, SLOT(accept()));
	mCancel = new QPushButton(tr("Cancel"));
	connect(mCancel, SIGNAL(clicked()), this, SLOT(reject()));
	QHBoxLayout *mainButtonLayout = new QHBoxLayout;
	mainButtonLayout->addStretch();
	mainButtonLayout->addWidget(mOk);
	mainButtonLayout->addWidget(mCancel);
	QVBoxLayout *mainLayout = new QVBoxLayout;
	mainLayout->addWidget(mTab);
	mainLayout->addLayout(mainButtonLayout);
	setLayout(mainLayout);
	QString winTitle = QString(tr("%1 - Configure")).arg(qApp->applicationName());
	setWindowTitle(winTitle);
	readSettings();
}

void ConfigurationDialog::accept(){
	writeSettings();
	QDialog::accept();
}

void ConfigurationDialog::readSettings(){
	QSettings s;

    //read icons
    QString iconText = s.value("ui/foldericon", "Dildo").toString();
    int pos = mIconForFolder->findText(iconText);
    pos = pos > -1 ? pos : 0;
    mIconForFolder->setCurrentIndex(pos);
    iconText = s.value("ui/fileicon", "Dildo").toString();
    pos = mIconForFile->findText(iconText);
    pos = pos > -1 ? pos : 0;
    mIconForFile->setCurrentIndex(pos);
    iconText = s.value("ui/seriesicon", "Dildo").toString();
    pos = mIconForSeries->findText(iconText);
    pos = pos > -1 ? pos : 0;
    mIconForSeries->setCurrentIndex(pos);
    iconText = s.value("ui/actoricon", "Dildo").toString();
    pos = mIconForActor->findText(iconText);
    pos = pos > -1 ? pos : 0;
    mIconForActor->setCurrentIndex(pos);
    iconText = s.value("ui/genreicon", "Dildo").toString();
    pos = mIconForGenre->findText(iconText);
    pos = pos > -1 ? pos : 0;
    mIconForGenre->setCurrentIndex(pos);
    iconText = s.value("ui/metaicon", "Dildo").toString();
    pos = mIconForMeta->findText(iconText);
    pos = pos > -1 ? pos : 0;
    mIconForMeta->setCurrentIndex(pos);

    // read misc
	mHoverPics->setChecked(s.value("ui/hoverpics", false).toBool());
	mHoverOpacity->setValue(s.value("ui/hoveropacity", 10).toInt());
	mAutoAddCovers->setChecked(s.value("ui/autoaddcovers", false).toBool());
	mIconizeCovers->setChecked(s.value("ui/iconizecovers", false).toBool());
	mCursorOffset->setValue(s.value("ui/cursoroffset", SmGlobals::instance()->cursorSize().height()).toInt());
    mAutoRefresh->setChecked(s.value("ui/autorefresh", false).toBool());
    mAutoRefreshValue->setValue(s.value("ui/autorefreshvalue", 5).toInt());
    mClearNewMovieWizard->setChecked(s.value("ui/clearnewmoviewizard", false).toBool());

	//read paths
	mArchiveDir->setText(s.value("paths/archivedir").toString());
	mBurnDir->setText(s.value("paths/burn").toString());
    mUSBDir->setText(s.value("paths/usb").toString());
	mFfProbePath->setText(s.value("paths/ffprobe").toString());
	mFfMpegPath->setText(s.value("paths/ffmpeg").toString());
	mDvdMountPath->setText(s.value("paths/dvdmount").toString());
	mCoverPath->setText(s.value("paths/coverpath").toString());
	mWindowsDrive->setText(s.value("paths/windowsdrive").toString());
	mStripPath->setText(s.value("paths/strippath").toString());
    mExpensive->setChecked(s.value("ui/expensiveops", true).toBool());

    //read pictures
    mInfoBox->setCurrentIndex(mInfoBox->findData(s.value("ui/infoposition", TopLeft).toInt()));
    mMapBox->setCurrentIndex(mMapBox->findData(s.value("ui/mappingposition", TopRight).toInt()));

	//read database
	mDatabaseHost->setText(s.value("database/hostname").toString());
	mDatabaseName->setText(s.value("database/dbname").toString());
	mDatabaseUsername->setText(s.value("database/dbuser").toString());
	mDatabasePassword->setText(s.value("database/dbpass").toString());

	//read colors
    QVariant clip = s.value("ui/clipcolor", QVariant(QColor(Qt::darkBlue)));
	mColors.insert(mClipboardColor, clip.value<QColor>());
	QVariant base = s.value("ui/basecolor", qApp->palette().base().color());
	mColors.insert(mBaseColor, base.value<QColor>());
	QVariant alternate = s.value("ui/alternatecolor", qApp->palette().alternateBase().color());
	mColors.insert(mAlternateBaseColor, alternate.value<QColor>());
	QVariant font = s.value("ui/fontcolor", qApp->palette().foreground().color());
	mColors.insert(mFontColor, font.value<QColor>());
    QVariant local = s.value("ui/localcolor", QVariant(QColor(Qt::darkBlue)));
	mColors.insert(mLocalColor, local.value<QColor>());
    QVariant archived = s.value("ui/archivedcolor", QVariant(QColor(Qt::black)));
	mColors.insert(mArchivedColor, archived.value<QColor>());
    QVariant favorite = s.value("ui/favoritecolor", QVariant(QColor(Qt::red)));
	mColors.insert(mFavoriteColor, favorite.value<QColor>());
    QVariant pvbackground = s.value("ui/pvbgcolor", QVariant(QColor(Qt::red)));
    mColors.insert(mPVBgColor, pvbackground.value<QColor>());
	QHash<QWidget*, QColor>::const_iterator it;
	for(it = mColors.constBegin(); it != mColors.constEnd(); ++it){
		setColor(it.key());
	}
	bool allowAlternate = s.value("ui/allowalternate", true).toBool();
	mAlternateColors->setChecked(allowAlternate);
	alternateColorsChanged(mAlternateColors->checkState());
    bool useGradient = s.value("ui/pvgradient", false).toBool();
    mPVGradient->setChecked(useGradient);
    randomGradientChanged(mPVGradient->checkState());
}

void ConfigurationDialog::writeSettings(){
	QSettings s;

	//write paths
	s.setValue("paths/archivedir", mArchiveDir->text());
	s.setValue("paths/burn", mBurnDir->text());
    s.setValue("paths/usb", mUSBDir->text());
	QString ffprobe = mFfProbePath->text();
	QFileInfo ffProbeInfo(ffprobe);
	if(ffProbeInfo.exists() && ffProbeInfo.isExecutable()){
		s.setValue("paths/ffprobe", ffprobe);
	}
	QString ffmpeg = mFfMpegPath->text();
	QFileInfo ffMpegInfo(ffmpeg);
	if(ffMpegInfo.exists() && ffMpegInfo.isExecutable()){
		s.setValue("paths/ffmpeg", ffmpeg);
	}
	if(checkDvdPath()){
		s.setValue("paths/dvdmount", mDvdMountPath->text());
	}
	s.setValue("paths/windowsdrive", mWindowsDrive->text());
	s.setValue("paths/strippath", mStripPath->text());
	s.setValue("paths/coverpath", mCoverPath->text());
    s.setValue("ui/expensiveops", (mExpensive->checkState() == Qt::Checked));

    //write icons
    s.setValue("ui/foldericon", mIconForFolder->currentText());
    s.setValue("ui/fileicon", mIconForFile->currentText());
    s.setValue("ui/seriesicon", mIconForSeries->currentText());
    s.setValue("ui/actoricon", mIconForActor->currentText());
    s.setValue("ui/genreicon", mIconForGenre->currentText());
    s.setValue("ui/metaicon", mIconForMeta->currentText());

    //write misc
	s.setValue("ui/hoverpics", (mHoverPics->checkState() == Qt::Checked));
	s.setValue("ui/hoveropacity", mHoverOpacity->value());
	s.setValue("ui/autoaddcovers", (mAutoAddCovers->checkState() == Qt::Checked));
	s.setValue("ui/iconizecovers", (mIconizeCovers->checkState() == Qt::Checked));
	s.setValue("ui/cursoroffset", mCursorOffset->value());
    s.setValue("ui/autorefresh", (mAutoRefresh->checkState() == Qt::Checked));
    s.setValue("ui/autorefreshvalue", mAutoRefreshValue->value());
    s.setValue("ui/clearnewmoviewizard", (mClearNewMovieWizard->checkState() == Qt::Checked));

    //write pictures
    QString curPos = mInfoBox->currentText();
    s.setValue("ui/infoposition", mPositionMap.value(curPos));
    curPos = mMapBox->currentText();
    s.setValue("ui/mappingposition", mPositionMap.value(curPos));

	//write database
	s.setValue("database/hostname", mDatabaseHost->text());
	s.setValue("database/dbname", mDatabaseName->text());
	s.setValue("database/dbuser", mDatabaseUsername->text());
	s.setValue("database/dbpass", mDatabasePassword->text());

	//write movies
	mMovieConfig->writeSettings();

	//write colors
	s.setValue("ui/clipcolor", mColors.value(mClipboardColor));
	s.setValue("ui/basecolor", mColors.value(mBaseColor));
	s.setValue("ui/alternatecolor", mColors.value(mAlternateBaseColor));
	s.setValue("ui/fontcolor", mColors.value(mFontColor));
	s.setValue("ui/localcolor", mColors.value(mLocalColor));
	s.setValue("ui/archivedcolor", mColors.value(mArchivedColor));
	s.setValue("ui/favoritecolor", mColors.value(mFavoriteColor));
    s.setValue("ui/pvbgcolor", mColors.value(mPVBgColor));
	s.setValue("ui/allowalternate", mAlternateColors->isChecked());
    s.setValue("ui/pvgradient", mPVGradient->isChecked());
}

bool ConfigurationDialog::checkDvdPath(){
	QString path = mDvdMountPath->text();
	if(path.isEmpty()){
		return true;
	}
	QFileInfo mountInfo(path);
	if(!mountInfo.exists() || !mountInfo.isDir()){
		QString message = QString(tr("%1 does not exist or is not a directory. Ignoring.")).arg(path);
		mountError(message);
		return false;
	}
	QFile fstab("/etc/fstab");
	if(!fstab.exists() || !fstab.open(QFile::ReadOnly)){
		mountError(QString());
		return true;
	}
	QTextStream fStream(&fstab);
	QString line;
	bool ok = false;
	do {
		line = fStream.readLine();
		if(line.contains(path)){
			QStringList fsParts = line.split(QRegExp("\\s+"));
			if(fsParts.isEmpty() || (fsParts.size() < 4)){
				continue;
			}
			QStringList options = fsParts.at(3).split(',');
			foreach(QString opt, options){
				if(opt.toLower().trimmed() == "user"){
					ok = true;
					break;
				}
			}
		}
	} while(!line.isNull());
	if(!ok){
		QString message = QString(tr("Didn't find %1 in fstab or it isn't user mountable. Ignoring.")).arg(path);
		mountError(message);
		return false;
	}
	return true;
}

void ConfigurationDialog::mountError(const QString &error){
	if(!error.isEmpty()){
		QMessageBox::critical(this, tr("Mount Path Error"), error);
	}
	QSettings s;
	s.setValue("paths/dvdmount", QString());
}

void ConfigurationDialog::chooseColor(QWidget *label){
	QColor newColor = QColorDialog::getColor(mColors.value(label), this);
	if(newColor.isValid()){
		mColors[label] = newColor;
		setColor(label);
	}
}

void ConfigurationDialog::alternateColorsChanged(int state){
	mBaseButton->setEnabled(state == Qt::Checked);
	mBaseColor->setEnabled(state == Qt::Checked);
	mAlternateBaseButton->setEnabled(state == Qt::Checked);
	mAlternateBaseColor->setEnabled(state == Qt::Checked);
}

void ConfigurationDialog::randomGradientChanged(int state){
    mPVBgButton->setEnabled(state == Qt::Unchecked);
    mPVBgColor->setEnabled(state == Qt::Unchecked);
}

void ConfigurationDialog::editReason(){
    QString curReason = mReasonsBox->currentText();
    if(curReason.isEmpty()){
        return;
    }
    QString newReason = QInputDialog::getText(this, tr("Edit reason..."), tr("Reason"), QLineEdit::Normal, curReason);
    if(!newReason.isEmpty()){
        QStringList r = SmGlobals::instance()->reencReasons();
        r.removeAll(curReason);
        r.append(newReason);
        SmGlobals::instance()->setReencReasons(r);
        r = SmGlobals::instance()->reencReasons();
        mReasonsBox->clear();
        mReasonsBox->addItems(r);
        mReasonsBox->setCurrentText(newReason);
    }
}

void ConfigurationDialog::addReason(){
    QString newReason = QInputDialog::getText(this, tr("Add reason..."), tr("Reason"));
    if(!newReason.isEmpty()){
        QStringList r = SmGlobals::instance()->reencReasons();
        if(r.contains(newReason)){
            mReasonsBox->setCurrentText(newReason);
            return;
        }
        r.append(newReason);
        SmGlobals::instance()->setReencReasons(r);
        mReasonsBox->clear();
        r = SmGlobals::instance()->reencReasons();
        mReasonsBox->addItems(r);
        mReasonsBox->setCurrentText(newReason);
    }
}

void ConfigurationDialog::delReason(){
    QString curReason = mReasonsBox->currentText();
    QStringList r = SmGlobals::instance()->reencReasons();
    r.removeAll(curReason);
    SmGlobals::instance()->setReencReasons(r);
    r = SmGlobals::instance()->reencReasons();
    mReasonsBox->clear();
    mReasonsBox->addItems(r);
    if(!r.isEmpty()){
        mReasonsBox->setCurrentIndex(0);
    }
}

void ConfigurationDialog::setColor(QWidget *label){
	QLabel *curLabel = qobject_cast<QLabel*>(label);
	if(!curLabel){
		return;
	}
	QColor curColor = mColors.value(label);
	QPixmap pm(curLabel->sizeHint());
	pm.fill(curColor);
	curLabel->setPixmap(pm);
}

void ConfigurationDialog::createPositionMap(){
    mPositionMap.insert(tr("Top left"), TopLeft);
    mPositionMap.insert(tr("Top right"), TopRight);
    mPositionMap.insert(tr("Bottom left"), BottomLeft);
    mPositionMap.insert(tr("Bottom right"), BottomRigth);
    mPositionMap.insert(tr("Freely moveable"), Moveable);
    mPositionMap.insert(tr("Do not show"), NoDisplay);
}

void ConfigurationDialog::fillPositions(QComboBox *cb){
    for(QMap<QString, int>::const_iterator it = mPositionMap.constBegin(); it != mPositionMap.constEnd(); ++it){
        cb->addItem(it.key(), it.value());
    }
}