-
Notifications
You must be signed in to change notification settings - Fork 0
/
settingsdialog.cpp
139 lines (116 loc) · 4.53 KB
/
settingsdialog.cpp
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
#include "settingsdialog.h"
#include "ui_settings.h"
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Settings)
{
ui->setupUi(this);
QDir configLocation(QDir::homePath()+"/.config/glop_conf");
if(!configLocation.exists())
configLocation.mkpath(configLocation.path());
settings = GlopConfig::ParseFile( configLocation.filePath("simplifiedVideoLibraryRenamer.conf").toStdString() );
connect( ui->eSeasonLength,SIGNAL(valueChanged(int)), this,SLOT(updateExampleRename()) );
connect( ui->eEpisodeLength,SIGNAL(valueChanged(int)), this,SLOT(updateExampleRename()) );
connect( ui->bBrowseImport,SIGNAL(clicked()), this,SLOT(openFileDialog()) );
connect( ui->bBrowseLibrary,SIGNAL(clicked()), this,SLOT(openFileDialog()) );
connect( ui->bConfirm,SIGNAL(clicked()), this,SLOT(accept()) );
connect( ui->bCancel,SIGNAL(clicked()), this,SLOT(reject()) );
connect( ui->bAutoDeleteAddNew,SIGNAL(clicked()), this,SLOT(modifyAutoDeleteFilenames()) );
connect( ui->bAutoDeleteRemoveSelection,SIGNAL(clicked()), this,SLOT(modifyAutoDeleteFilenames()) );
}
QString SettingsDialog::operator[](QString key)
{
return QString::fromStdString(
settings.values[key.toStdString()]
);
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
void SettingsDialog::open()
{
QDialog::open();
ui->eSeasonLength->setValue(
QString::fromStdString(settings.values["season number length"]).toInt()
);
ui->eEpisodeLength->setValue(
QString::fromStdString(settings.values["episode number length"]).toInt()
);
ui->eImportLocation->setText(
QString::fromStdString(settings.values["import location"])
);
ui->eLibraryLocation->setText(
QString::fromStdString(settings.values["library location"])
);
updateExampleRename();
if( settings.values["auto delete enable"] == "true" )
ui->cAutoDeleteEnable->setChecked(true);
else
ui->cAutoDeleteEnable->setChecked(false);
if(settings.values.find("auto delete filenames") == settings.values.end())
settings.values["auto delete filenames"] = DEFAULT_DELETE_FILENAMES;
QStringList filenames = QString::fromStdString(settings.values["auto delete filenames"]).split(";",Qt::SkipEmptyParts);
ui->listAutoDeleteFiles->clear();
for(auto name : filenames)
ui->listAutoDeleteFiles->addItem(name);
}
void SettingsDialog::accept()
{
// lets save the settings to the config file
settings.values["season number length"] =
ui->eSeasonLength->text().toStdString();
settings.values["episode number length"] =
ui->eEpisodeLength->text().toStdString();
settings.values["import location"] =
ui->eImportLocation->text().toStdString();
settings.values["library location"] =
ui->eLibraryLocation->text().toStdString();
settings.values["auto delete enable"] =
ui->cAutoDeleteEnable->isChecked() ? "true" : "false";
QString filenames;
for( int row=0; row<ui->listAutoDeleteFiles->count(); row++)
filenames += ui->listAutoDeleteFiles->item(row)->text()+";";
settings.values["auto delete filenames"] = filenames.toStdString();
QDir configLocation(QDir::homePath()+"/.config/glop_conf/simplifiedVideoLibraryRenamer.conf");
GlopConfig::SaveToFile(configLocation.path().toStdString(),settings);
QDialog::accept();
}
void SettingsDialog::updateExampleRename()
{
QString season = QString::number(3).rightJustified(ui->eSeasonLength->value(),'0');
QString episode = QString::number(5).rightJustified(ui->eEpisodeLength->value(),'0');
// Example Show Title.s03e005.mkv
QString text("Example Show Title.s#e%.mkv");
text.replace('#',season);
text.replace('%',episode);
ui->lExampleRename->setText(text);
}
void SettingsDialog::openFileDialog(){
QObject *sender = QObject::sender();
if(sender == ui->bBrowseImport){
QString temp = QFileDialog::getExistingDirectory(this,"Select Location",ui->eImportLocation->text());
if(temp.length()>0) // handle if user hits cancel
ui->eImportLocation->setText(temp);
}
if(sender == ui->bBrowseLibrary){
QString temp = QFileDialog::getExistingDirectory(this,"Select Location",ui->eLibraryLocation->text());
if(temp.length()>0) // handle if user hits cancel
ui->eLibraryLocation->setText(temp);
}
}
void SettingsDialog::modifyAutoDeleteFilenames()
{
QObject *sender = QObject::sender();
if(sender == ui->bAutoDeleteRemoveSelection){
delete
ui->listAutoDeleteFiles->takeItem(
ui->listAutoDeleteFiles->currentRow()
);
}else if(sender == ui->bAutoDeleteAddNew){
QString newFilename = ui->eAutoDeleteNewFilename->text();
if(newFilename == "") return;
ui->listAutoDeleteFiles->addItem(newFilename);
ui->listAutoDeleteFiles->sortItems();
}
}