This repository has been archived by the owner on May 30, 2023. It is now read-only.
/
settingsdialog.cpp
160 lines (144 loc) · 4.89 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include "skypetab.h"
#include <QCheckBox>
#include <QMessageBox>
#include <QFile>
#include <stdio.h>
namespace skypetab
{
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsDialog)
{
ui->setupUi(this);
QWidget*group=findChild<QWidget*>("tabClasses");
QBoxLayout*layout=new QBoxLayout(QBoxLayout::TopToBottom);
group->setLayout(layout);
//I know that copy/paste is a bad practice, but I'm too lazy to extract a function
bool isDefault=true;
for(int c=0; SkypeTab::tabClassesList[c][0]!=0; c++)
{
const char *name=SkypeTab::tabClassesList[c][0];
if(name[0]==0)
isDefault=false;
else
{
QString keyName("tabClasses/");
keyName=keyName.append(name);
addSettingsCheckbox(layout,QString::fromAscii(SkypeTab::tabClassesList[c][1]),keyName, isDefault);
/*
bool isChecked=(
((!SkypeTab::settings.contains(keyName))&&isDefault) //If no setting for this entry, use default flag
||
(SkypeTab::settings.value(keyName).toInt()==1)
);
QCheckBox* cb=new QCheckBox(QString::fromAscii(SkypeTab::tabClassesList[c][1]));
cb->setChecked(isChecked);
cb->setObjectName(keyName);
layout->addWidget(cb);
connect(cb, SIGNAL(stateChanged(int)), this, SLOT(namedCheckboxChanged(int)));
cb->show();
*/
}
}
group=findChild<QWidget*>("miscOptions");
layout=new QBoxLayout(QBoxLayout::TopToBottom);
group->setLayout(layout);
addSettingsCheckbox(layout, "Don't close tabs with the window", "tabs/noClose", false);
addSettingsCheckbox(layout, "Don't activate on file transfers", "tabs/disableTransferActivation", false);
addSettingsCheckbox(layout, "Always show additional event counter", "tabCounter/alwaysShow", false);
addSettingsCheckbox(layout, "Swallow X11 errors", "x11/swallowErrors", true);
if(SkypeTab::winManager==Unity)
{
addSettingsCheckbox(layout, "Do not wiggle constantly in Unity launcher", "unity/noConstantUrgency", false);
addSettingsCheckbox(layout, "Minimize on close", "unity/noClose", true, "tabCounter/alwaysShow");
}
group=findChild<QWidget*>("startOptions");
layout=new QBoxLayout(QBoxLayout::TopToBottom);
group->setLayout(layout);
addSettingsCheckbox(layout, "Don't show window at start", "startup/hidden", false);
autostartPath=QString(getenv("HOME"));
autostartPath=autostartPath.append("/.config/autostart/skypetab.desktop");
QCheckBox*cb=new QCheckBox("Start automatically");
cb->setChecked(QFile::exists(autostartPath));
cb->setObjectName("autostart");
layout->addWidget(cb);
this->resize(width(), minimumHeight());
foreach(cb, this->findChildren<QCheckBox*>())
{
checkBoxChanged(cb, cb->isChecked()?1:0);
}
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
void SettingsDialog::addSettingsCheckbox(QBoxLayout *layout, QString title, QString keyName, bool isDefault, QList<QString> &disables)
{
bool isChecked=(
((!SkypeTab::settings.contains(keyName))&&isDefault) //If no setting for this entry, use default flag
||
(SkypeTab::settings.value(keyName).toInt()==1)
);
QCheckBox* cb=new QCheckBox(title);
cb->setChecked(isChecked);
cb->setObjectName(keyName);
QList<QVariant> vlist;
QString dstr;
foreach (dstr, disables)
{
vlist.append(QVariant::fromValue(dstr));
}
cb->setProperty("disables", QVariant::fromValue(vlist));
layout->addWidget(cb);
connect(cb, SIGNAL(stateChanged(int)), this, SLOT(namedCheckboxChanged(int)));
cb->show();
}
void SettingsDialog::addSettingsCheckbox(QBoxLayout *layout, QString title, QString keyName, bool isDefault)
{
QList<QString> list;
addSettingsCheckbox(layout, title, keyName, isDefault, list);
}
void SettingsDialog::addSettingsCheckbox(QBoxLayout *layout, QString title, QString keyName, bool isDefault, QString disables)
{
QList<QString> list;
list.append(disables);
addSettingsCheckbox(layout, title, keyName, isDefault, list);
}
void SettingsDialog::execIt()
{
QDialog::exec();
QCheckBox*cb=findChild<QCheckBox*>("autostart");
if(cb->isChecked())
{
FILE*file=fopen(autostartPath.toLocal8Bit().data(), "w");
fprintf(file,"[Desktop Entry]\nEncoding=UTF-8\nName=SkypeTab\nComment=A program that adds tabs to Skype\nIcon=skype\nType=Application\nExec=skypetab-ng\nStartupNotify=False\nTerminal=false");
fclose(file);
}
else
{
QFile::remove(autostartPath);
}
QMessageBox msgbox("SkypeTab", "Some changes will take effect after the next start of Skype™",
QMessageBox::Information,0,0,0);
msgbox.exec();
}
void SettingsDialog::namedCheckboxChanged(int value)
{
checkBoxChanged((QCheckBox*)sender(), value);
}
void SettingsDialog::checkBoxChanged(QCheckBox *ccb, int value)
{
if(value>=1)
value=1;
QList<QVariant> vdisables=ccb->property ("disables").value<QList<QVariant>>();
QVariant vdis;
foreach(vdis, vdisables)
{
QCheckBox* cb=findChild<QCheckBox*>(vdis.toString());
cb->setEnabled(value==0);
}
SkypeTab::settings.setValue(ccb->objectName(), QVariant::fromValue(value));
}
}