21 #include <QMessageBox>
26 bool firstFormatted =
false;
28 for (
int i = 0;
i < text.length(); ++
i) {
29 if(text.mid(
i, 1) ==
" " and !firstFormatted) {
30 setFormat(0,
i, QColor(2,71,105));
31 setFormat(
i, text.length() - 1, Qt::gray);
32 firstFormatted =
true;
33 }
else if (text.mid(
i, 1) ==
"#") {
34 setFormat(
i, text.length() -
i, QColor(112,144,128));
55 connect(
ui.buttonBox, SIGNAL(accepted()),
this, SLOT(
saveTorrc()));
72 if(!errmsg) errmsg =
new QString(
"");
74 *errmsg = tr(
"Error connecting to Tor");
79 QStringList parts, lines;
81 if(
ui.rdoAll->isChecked())
82 lines =
ui.teditTorrc->toPlainText().split(
'\n', QString::SkipEmptyParts);
84 QString tmp =
ui.teditTorrc->toPlainText();
85 QTextCursor tcursor =
ui.teditTorrc->textCursor();
86 int start = tcursor.selectionStart();
87 int end = tcursor.selectionEnd();
88 tmp = tmp.mid(start, end - start).trimmed();
90 *errmsg = tr(
"Selection is empty. Please select some text, or check \"Apply all\"");
94 lines = tmp.split(
'\n', QString::SkipEmptyParts);
98 foreach(QString line, lines) {
100 int commentIndex = line.indexOf(
"#");
101 if(commentIndex != -1)
102 line = line.remove(commentIndex, line.length() - commentIndex);
104 line = line.trimmed();
105 if(line.startsWith(
"#"))
continue;
106 parts = line.split(
" ", QString::SkipEmptyParts);
107 if(parts.count() < 2) {
108 *errmsg = tr(
"Error at line %1: \"%2\"").arg(i).arg(line);
113 QHash<QString,QString> settings;
114 foreach(QString line, lines) {
115 line = line.trimmed();
116 parts = line.split(
" ", QString::SkipEmptyParts);
119 val = parts.join(
" ");
120 settings.insert(key, val);
123 if(!
tc->
setConf(settings, errmsg))
return false;
135 QFile file(
tc->
getInfo(
"config-file").toString());
136 if(file.open(QFile::ReadOnly)) {
137 QTextStream in(&file);
140 line = in.readLine();
142 }
while(!line.isNull());
143 ui.teditTorrc->setText(text);
145 QMessageBox::critical(
this, tr(
"Error"), tr(
"An error ocurred while opening torrc file"));
158 QMessageBox::critical(
this, tr(
"Error"), errmsg);
161 if(
ui.chkSave->isChecked()) {
163 QMessageBox::critical(
this, tr(
"Error"), errmsg);