mirror of https://github.com/procxx/kepka.git
Allow open folders by 'folders' code.
This commit is contained in:
parent
bf5356fd91
commit
0c2d8f1b6e
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
#include "boxes/confirm_box.h"
|
#include "boxes/confirm_box.h"
|
||||||
|
@ -22,14 +23,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/update_checker.h"
|
#include "core/update_checker.h"
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
#include "window/themes/window_theme_editor.h"
|
#include "window/themes/window_theme_editor.h"
|
||||||
|
#include "window/window_session_controller.h"
|
||||||
#include "media/audio/media_audio_track.h"
|
#include "media/audio/media_audio_track.h"
|
||||||
|
#include "settings/settings_common.h"
|
||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using SessionController = Window::SessionController;
|
||||||
|
|
||||||
auto GenerateCodes() {
|
auto GenerateCodes() {
|
||||||
auto codes = std::map<QString, Fn<void(::Main::Session*)>>();
|
auto codes = std::map<QString, Fn<void(SessionController*)>>();
|
||||||
codes.emplace(qsl("debugmode"), [](::Main::Session *session) {
|
codes.emplace(qsl("debugmode"), [](SessionController *window) {
|
||||||
QString text = Logs::DebugEnabled()
|
QString text = Logs::DebugEnabled()
|
||||||
? qsl("Do you want to disable DEBUG logs?")
|
? qsl("Do you want to disable DEBUG logs?")
|
||||||
: qsl("Do you want to enable DEBUG logs?\n\n"
|
: qsl("Do you want to enable DEBUG logs?\n\n"
|
||||||
|
@ -38,24 +44,24 @@ auto GenerateCodes() {
|
||||||
Core::App().switchDebugMode();
|
Core::App().switchDebugMode();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("viewlogs"), [](::Main::Session *session) {
|
codes.emplace(qsl("viewlogs"), [](SessionController *window) {
|
||||||
File::ShowInFolder(cWorkingDir() + "log.txt");
|
File::ShowInFolder(cWorkingDir() + "log.txt");
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("testmode"), [](::Main::Session *session) {
|
codes.emplace(qsl("testmode"), [](SessionController *window) {
|
||||||
auto text = cTestMode() ? qsl("Do you want to disable TEST mode?") : qsl("Do you want to enable TEST mode?\n\nYou will be switched to test cloud.");
|
auto text = cTestMode() ? qsl("Do you want to disable TEST mode?") : qsl("Do you want to enable TEST mode?\n\nYou will be switched to test cloud.");
|
||||||
Ui::show(Box<ConfirmBox>(text, [] {
|
Ui::show(Box<ConfirmBox>(text, [] {
|
||||||
Core::App().switchTestMode();
|
Core::App().switchTestMode();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
if (!Core::UpdaterDisabled()) {
|
if (!Core::UpdaterDisabled()) {
|
||||||
codes.emplace(qsl("testupdate"), [](::Main::Session *session) {
|
codes.emplace(qsl("testupdate"), [](SessionController *window) {
|
||||||
Core::UpdateChecker().test();
|
Core::UpdateChecker().test();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
codes.emplace(qsl("loadlang"), [](::Main::Session *session) {
|
codes.emplace(qsl("loadlang"), [](SessionController *window) {
|
||||||
Lang::CurrentCloudManager().switchToLanguage({ qsl("#custom") });
|
Lang::CurrentCloudManager().switchToLanguage({ qsl("#custom") });
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("debugfiles"), [](::Main::Session *session) {
|
codes.emplace(qsl("debugfiles"), [](SessionController *window) {
|
||||||
if (!Logs::DebugEnabled()) {
|
if (!Logs::DebugEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -66,10 +72,10 @@ auto GenerateCodes() {
|
||||||
}
|
}
|
||||||
Ui::show(Box<InformBox>(DebugLogging::FileLoader() ? qsl("Enabled file download logging") : qsl("Disabled file download logging")));
|
Ui::show(Box<InformBox>(DebugLogging::FileLoader() ? qsl("Enabled file download logging") : qsl("Disabled file download logging")));
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("crashplease"), [](::Main::Session *session) {
|
codes.emplace(qsl("crashplease"), [](SessionController *window) {
|
||||||
Unexpected("Crashed in Settings!");
|
Unexpected("Crashed in Settings!");
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("moderate"), [](::Main::Session *session) {
|
codes.emplace(qsl("moderate"), [](SessionController *window) {
|
||||||
auto text = Global::ModerateModeEnabled() ? qsl("Disable moderate mode?") : qsl("Enable moderate mode?");
|
auto text = Global::ModerateModeEnabled() ? qsl("Disable moderate mode?") : qsl("Enable moderate mode?");
|
||||||
Ui::show(Box<ConfirmBox>(text, [] {
|
Ui::show(Box<ConfirmBox>(text, [] {
|
||||||
Global::SetModerateModeEnabled(!Global::ModerateModeEnabled());
|
Global::SetModerateModeEnabled(!Global::ModerateModeEnabled());
|
||||||
|
@ -77,19 +83,19 @@ auto GenerateCodes() {
|
||||||
Ui::hideLayer();
|
Ui::hideLayer();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("getdifference"), [](::Main::Session *session) {
|
codes.emplace(qsl("getdifference"), [](SessionController *window) {
|
||||||
if (auto main = App::main()) {
|
if (auto main = App::main()) {
|
||||||
main->getDifference();
|
main->getDifference();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("loadcolors"), [](::Main::Session *session) {
|
codes.emplace(qsl("loadcolors"), [](SessionController *window) {
|
||||||
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open palette file", "Palette (*.tdesktop-palette)", [](const FileDialog::OpenResult &result) {
|
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open palette file", "Palette (*.tdesktop-palette)", [](const FileDialog::OpenResult &result) {
|
||||||
if (!result.paths.isEmpty()) {
|
if (!result.paths.isEmpty()) {
|
||||||
Window::Theme::Apply(result.paths.front());
|
Window::Theme::Apply(result.paths.front());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("videoplayer"), [](::Main::Session *session) {
|
codes.emplace(qsl("videoplayer"), [](SessionController *window) {
|
||||||
auto text = cUseExternalVideoPlayer() ? qsl("Use internal video player?") : qsl("Use external video player?");
|
auto text = cUseExternalVideoPlayer() ? qsl("Use internal video player?") : qsl("Use external video player?");
|
||||||
Ui::show(Box<ConfirmBox>(text, [] {
|
Ui::show(Box<ConfirmBox>(text, [] {
|
||||||
cSetUseExternalVideoPlayer(!cUseExternalVideoPlayer());
|
cSetUseExternalVideoPlayer(!cUseExternalVideoPlayer());
|
||||||
|
@ -97,7 +103,7 @@ auto GenerateCodes() {
|
||||||
Ui::hideLayer();
|
Ui::hideLayer();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
codes.emplace(qsl("endpoints"), [](::Main::Session *session) {
|
codes.emplace(qsl("endpoints"), [](SessionController *window) {
|
||||||
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open DC endpoints", "DC Endpoints (*.tdesktop-endpoints)", [](const FileDialog::OpenResult &result) {
|
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open DC endpoints", "DC Endpoints (*.tdesktop-endpoints)", [](const FileDialog::OpenResult &result) {
|
||||||
if (!result.paths.isEmpty()) {
|
if (!result.paths.isEmpty()) {
|
||||||
if (!Core::App().dcOptions()->loadFromFile(result.paths.front())) {
|
if (!Core::App().dcOptions()->loadFromFile(result.paths.front())) {
|
||||||
|
@ -106,14 +112,19 @@ auto GenerateCodes() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
codes.emplace(qsl("folders"), [](SessionController *window) {
|
||||||
|
if (window) {
|
||||||
|
window->showSettings(Settings::Type::Folders);
|
||||||
|
}
|
||||||
|
});
|
||||||
#ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
#ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
||||||
codes.emplace(qsl("registertg"), [](::Main::Session *session) {
|
codes.emplace(qsl("registertg"), [](SessionController *window) {
|
||||||
Platform::RegisterCustomScheme(true);
|
Platform::RegisterCustomScheme(true);
|
||||||
Ui::Toast::Show("Forced custom scheme register.");
|
Ui::Toast::Show("Forced custom scheme register.");
|
||||||
});
|
});
|
||||||
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
||||||
codes.emplace(qsl("export"), [](::Main::Session *session) {
|
codes.emplace(qsl("export"), [](SessionController *window) {
|
||||||
session->data().startExport();
|
window->session().data().startExport();
|
||||||
});
|
});
|
||||||
|
|
||||||
auto audioFilters = qsl("Audio files (*.wav *.mp3);;") + FileDialog::AllFilesFilter();
|
auto audioFilters = qsl("Audio files (*.wav *.mp3);;") + FileDialog::AllFilesFilter();
|
||||||
|
@ -126,28 +137,31 @@ auto GenerateCodes() {
|
||||||
qsl("call_end"),
|
qsl("call_end"),
|
||||||
};
|
};
|
||||||
for (auto &key : audioKeys) {
|
for (auto &key : audioKeys) {
|
||||||
codes.emplace(key, [=](::Main::Session *session) {
|
codes.emplace(key, [=](SessionController *window) {
|
||||||
if (!session) {
|
if (!window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open audio file", audioFilters, crl::guard(session, [=](const FileDialog::OpenResult &result) {
|
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open audio file", audioFilters, crl::guard(&window->session(), [=](const FileDialog::OpenResult &result) {
|
||||||
if (Main::Session::Exists() && !result.paths.isEmpty()) {
|
if (Main::Session::Exists() && !result.paths.isEmpty()) {
|
||||||
auto track = Media::Audio::Current().createTrack();
|
auto track = Media::Audio::Current().createTrack();
|
||||||
track->fillFromFile(result.paths.front());
|
track->fillFromFile(result.paths.front());
|
||||||
if (track->failed()) {
|
if (track->failed()) {
|
||||||
Ui::show(Box<InformBox>("Could not audio :( Errors in 'log.txt'."));
|
Ui::show(Box<InformBox>(
|
||||||
|
"Could not audio :( Errors in 'log.txt'."));
|
||||||
} else {
|
} else {
|
||||||
session->settings().setSoundOverride(key, result.paths.front());
|
window->session().settings().setSoundOverride(
|
||||||
|
key,
|
||||||
|
result.paths.front());
|
||||||
Local::writeUserSettings();
|
Local::writeUserSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
codes.emplace(qsl("sounds_reset"), [](::Main::Session *session) {
|
codes.emplace(qsl("sounds_reset"), [](SessionController *window) {
|
||||||
if (session) {
|
if (window) {
|
||||||
session->settings().clearSoundOverrides();
|
window->session().settings().clearSoundOverrides();
|
||||||
Local::writeUserSettings();
|
Local::writeUserSettings();
|
||||||
Ui::show(Box<InformBox>("All sound overrides were reset."));
|
Ui::show(Box<InformBox>("All sound overrides were reset."));
|
||||||
}
|
}
|
||||||
|
@ -156,7 +170,9 @@ auto GenerateCodes() {
|
||||||
return codes;
|
return codes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodesFeedString(::Main::Session *session, const QString &text) {
|
} // namespace
|
||||||
|
|
||||||
|
void CodesFeedString(SessionController *window, const QString &text) {
|
||||||
static const auto codes = GenerateCodes();
|
static const auto codes = GenerateCodes();
|
||||||
static auto secret = QString();
|
static auto secret = QString();
|
||||||
|
|
||||||
|
@ -167,7 +183,7 @@ void CodesFeedString(::Main::Session *session, const QString &text) {
|
||||||
auto found = false;
|
auto found = false;
|
||||||
for (const auto &[key, method] : codes) {
|
for (const auto &[key, method] : codes) {
|
||||||
if (piece == key) {
|
if (piece == key) {
|
||||||
method(session);
|
method(window);
|
||||||
from = size;
|
from = size;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,12 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace Main {
|
namespace Window {
|
||||||
class Session;
|
class SessionController;
|
||||||
} // namespace Main
|
} // namespace Main
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
void CodesFeedString(::Main::Session *session, const QString &text);
|
void CodesFeedString(Window::SessionController *window, const QString &text);
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
|
@ -342,7 +342,9 @@ Main::Main(
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::keyPressEvent(QKeyEvent *e) {
|
void Main::keyPressEvent(QKeyEvent *e) {
|
||||||
CodesFeedString(&_controller->session(), e->text());
|
crl::on_main(this, [=, text = e->text()]{
|
||||||
|
CodesFeedString(_controller, text);
|
||||||
|
});
|
||||||
return Section::keyPressEvent(e);
|
return Section::keyPressEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue