FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tdesktop/Telegram/SourceFiles/settings/settings_widget.cpp at master · JavaDevl/tdesktop · GitHub
JavaDevl
tdesktop
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
settings
/
settings_widget.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
267 lines (240 loc) · 8.58 KB
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
settings
/
settings_widget.cpp
Copy path
File metadata and controls
267 lines (240 loc) · 8.58 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
This file is part of Telegram Desktop,
the official desktop version of Telegram messaging app, see https://telegram.org
Telegram Desktop 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 3 of the License, or
(at your option) any later version.
It is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#
include
"
settings/settings_widget.h
"
#
include
"
settings/settings_inner_widget.h
"
#
include
"
settings/settings_fixed_bar.h
"
#
include
"
styles/style_settings.h
"
#
include
"
styles/style_window.h
"
#
include
"
styles/style_boxes.h
"
#
include
"
ui/effects/widget_fade_wrap.h
"
#
include
"
ui/widgets/scroll_area.h
"
#
include
"
ui/widgets/buttons.h
"
#
include
"
mainwindow.h
"
#
include
"
mainwidget.h
"
#
include
"
storage/localstorage.h
"
#
include
"
boxes/confirm_box.h
"
#
include
"
lang/lang_keys.h
"
#
include
"
lang/lang_cloud_manager.h
"
#
include
"
messenger.h
"
#
include
"
mtproto/mtp_instance.h
"
#
include
"
mtproto/dc_options.h
"
#
include
"
core/file_utilities.h
"
#
include
"
window/themes/window_theme.h
"
#
include
"
window/themes/window_theme_editor.h
"
#
include
"
media/media_audio_track.h
"
namespace
Settings
{
namespace
{
QString SecretText;
QMap<QString, base::lambda<
void
()>> Codes;
void
fillCodes
() {
Codes.
insert
(
qsl
(
"
debugmode
"
), [] {
QString text =
cDebug
() ?
qsl
(
"
Do you want to disable DEBUG logs?
"
) :
qsl
(
"
Do you want to enable DEBUG logs?
\n\n
All network events will be logged.
"
);
Ui::show
(Box<ConfirmBox>(text, [] {
Messenger::Instance
().
onSwitchDebugMode
();
}));
});
Codes.
insert
(
qsl
(
"
testmode
"
), [] {
auto
text =
cTestMode
() ?
qsl
(
"
Do you want to disable TEST mode?
"
) :
qsl
(
"
Do you want to enable TEST mode?
\n\n
You will be switched to test cloud.
"
);
Ui::show
(Box<ConfirmBox>(text, [] {
Messenger::Instance
().
onSwitchTestMode
();
}));
});
Codes.
insert
(
qsl
(
"
loadlang
"
), [] {
Lang::CurrentCloudManager
().
switchToLanguage
(
qsl
(
"
custom
"
));
});
Codes.
insert
(
qsl
(
"
debugfiles
"
), [] {
if
(!
cDebug
())
return
;
if
(
DebugLogging::FileLoader
()) {
Global::RefDebugLoggingFlags
() &= ~DebugLogging::FileLoaderFlag;
}
else
{
Global::RefDebugLoggingFlags
() |= DebugLogging::FileLoaderFlag;
}
Ui::show
(Box<InformBox>(
DebugLogging::FileLoader
() ?
qsl
(
"
Enabled file download logging
"
) :
qsl
(
"
Disabled file download logging
"
)));
});
Codes.
insert
(
qsl
(
"
crashplease
"
), [] {
Unexpected
(
"
Crashed in Settings!
"
);
});
Codes.
insert
(
qsl
(
"
workmode
"
), [] {
auto
text =
Global::DialogsModeEnabled
() ?
qsl
(
"
Disable work mode?
"
) :
qsl
(
"
Enable work mode?
"
);
Ui::show
(Box<ConfirmBox>(text, [] {
Messenger::Instance
().
onSwitchWorkMode
();
}));
});
Codes.
insert
(
qsl
(
"
moderate
"
), [] {
auto
text =
Global::ModerateModeEnabled
() ?
qsl
(
"
Disable moderate mode?
"
) :
qsl
(
"
Enable moderate mode?
"
);
Ui::show
(Box<ConfirmBox>(text, []() {
Global::SetModerateModeEnabled
(!
Global::ModerateModeEnabled
());
Local::writeUserSettings
();
Ui::hideLayer
();
}));
});
Codes.
insert
(
qsl
(
"
getdifference
"
), [] {
if
(
auto
main =
App::main
()) {
main->
getDifference
();
}
});
Codes.
insert
(
qsl
(
"
loadcolors
"
), [] {
FileDialog::GetOpenPath
(
"
Open palette file
"
,
"
Palette (*.tdesktop-palette)
"
, [](
const
FileDialog::OpenResult &result) {
if
(!result.
paths
.
isEmpty
()) {
Window::Theme::Apply
(result.
paths
.
front
());
}
});
});
Codes.
insert
(
qsl
(
"
edittheme
"
), [] {
Window::Theme::Editor::Start
();
});
Codes.
insert
(
qsl
(
"
videoplayer
"
), [] {
auto
text =
cUseExternalVideoPlayer
() ?
qsl
(
"
Use internal video player?
"
) :
qsl
(
"
Use external video player?
"
);
Ui::show
(Box<ConfirmBox>(text, [] {
cSetUseExternalVideoPlayer
(!
cUseExternalVideoPlayer
());
Local::writeUserSettings
();
Ui::hideLayer
();
}));
});
Codes.
insert
(
qsl
(
"
endpoints
"
), [] {
FileDialog::GetOpenPath
(
"
Open DC endpoints
"
,
"
DC Endpoints (*.tdesktop-endpoints)
"
, [](
const
FileDialog::OpenResult &result) {
if
(!result.
paths
.
isEmpty
()) {
if
(!
Messenger::Instance
().
mtp
()->
dcOptions
()->
loadFromFile
(result.
paths
.
front
())) {
Ui::show
(Box<InformBox>(
"
Could not load endpoints :( Errors in 'log.txt'.
"
));
}
}
});
});
auto
audioFilters =
qsl
(
"
Audio files (*.wav *.mp3);;
"
) +
FileDialog::AllFilesFilter
();
auto
audioKeys = {
qsl
(
"
msg_incoming
"
),
qsl
(
"
call_incoming
"
),
qsl
(
"
call_outgoing
"
),
qsl
(
"
call_busy
"
),
qsl
(
"
call_connect
"
),
qsl
(
"
call_end
"
),
};
for
(
auto
&key : audioKeys) {
Codes.
insert
(key, [audioFilters, key] {
if
(!
AuthSession::Exists
()) {
return
;
}
FileDialog::GetOpenPath
(
"
Open audio file
"
, audioFilters, [key](
const
FileDialog::OpenResult &result) {
if
(
AuthSession::Exists
() && !result.
paths
.
isEmpty
()) {
auto
track =
Media::Audio::Current
().
createTrack
();
track->
fillFromFile
(result.
paths
.
front
());
if
(track->
failed
()) {
Ui::show
(Box<InformBox>(
"
Could not audio :( Errors in 'log.txt'.
"
));
}
else
{
Auth
().
data
().
setSoundOverride
(key, result.
paths
.
front
());
Local::writeUserSettings
();
}
}
});
});
}
Codes.
insert
(
qsl
(
"
sounds_reset
"
), [] {
if
(
AuthSession::Exists
()) {
Auth
().
data
().
clearSoundOverrides
();
Local::writeUserSettings
();
Ui::show
(Box<InformBox>(
"
All sound overrides were reset.
"
));
}
});
}
void
codesFeedString
(
const
QString &text) {
if
(Codes.
isEmpty
())
fillCodes
();
SecretText += text.
toLower
();
int
size = SecretText.
size
(), from =
0
;
while
(size > from) {
auto
piece = SecretText.
midRef
(from);
auto
found =
false
;
for
(
auto
i = Codes.
cbegin
(), e = Codes.
cend
(); i != e; ++i) {
if
(piece == i.
key
()) {
(*i)();
from = size;
found =
true
;
break
;
}
}
if
(found)
break
;
for
(
auto
i = Codes.
cbegin
(), e = Codes.
cend
(); i != e; ++i) {
if
(i.
key
().
startsWith
(piece)) {
found =
true
;
break
;
}
}
if
(found)
break
;
++from;
}
SecretText = (size > from) ? SecretText.
mid
(from) :
QString
();
}
}
//
namespace
Widget::Widget
(QWidget *parent) {
refreshLang
();
subscribe
(
Lang::Current
().
updated
(), [
this
] {
refreshLang
(); });
_inner =
setInnerWidget
(object_ptr<InnerWidget>(
this
));
setCloseClickHandler
([]() {
Ui::hideSettingsAndLayer
();
});
}
void
Widget::refreshLang
() {
setTitle
(
lang
(lng_menu_settings));
update
();
}
void
Widget::showFinished
() {
_inner->
showFinished
();
}
void
Widget::keyPressEvent
(QKeyEvent *e) {
codesFeedString
(e->
text
());
return
LayerWidget::keyPressEvent
(e);
}
void
Widget::parentResized
() {
auto
parentSize =
parentWidget
()->
size
();
auto
windowWidth = parentSize.
width
();
auto
newWidth = st::settingsMaxWidth;
auto
newContentLeft = st::settingsMaxPadding;
if
(windowWidth <= st::settingsMaxWidth) {
newWidth = windowWidth;
newContentLeft = st::settingsMinPadding;
if
(windowWidth > st::windowMinWidth) {
//
Width changes from st::windowMinWidth to st::settingsMaxWidth.
//
Padding changes from st::settingsMinPadding to st::settingsMaxPadding.
newContentLeft += ((newWidth - st::windowMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::windowMinWidth);
}
}
else
if
(windowWidth < st::settingsMaxWidth +
2
* st::settingsMargin) {
newWidth = windowWidth -
2
* st::settingsMargin;
newContentLeft = st::settingsMinPadding;
if
(windowWidth > st::windowMinWidth) {
//
Width changes from st::windowMinWidth to st::settingsMaxWidth.
//
Padding changes from st::settingsMinPadding to st::settingsMaxPadding.
newContentLeft += ((newWidth - st::windowMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::windowMinWidth);
}
}
resizeToWidth
(newWidth, newContentLeft);
}
void
Widget::resizeUsingInnerHeight
(
int
newWidth,
int
innerHeight) {
if
(!
App::wnd
())
return
;
auto
parentSize =
parentWidget
()->
size
();
auto
windowWidth = parentSize.
width
();
auto
windowHeight = parentSize.
height
();
auto
maxHeight = st::settingsFixedBarHeight + innerHeight;
auto
newHeight = maxHeight + st::boxRadius;
if
(newHeight > windowHeight || newWidth >= windowWidth) {
newHeight = windowHeight;
}
auto
roundedCorners = newHeight < windowHeight;
setRoundedCorners
(roundedCorners);
setAttribute
(Qt::WA_OpaquePaintEvent, !roundedCorners);
setGeometry
((windowWidth - newWidth) /
2
, (windowHeight - newHeight) /
2
, newWidth, newHeight);
update
();
}
}
//
namespace Settings
Back
|
FazBrowse Home
|
New Git URL