diff --git a/Telegram/Resources/lang.strings b/Telegram/Resources/lang.strings index b454398c0..073b5b7e2 100644 --- a/Telegram/Resources/lang.strings +++ b/Telegram/Resources/lang.strings @@ -28,6 +28,8 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org "lng_menu_restart" = "Restart"; "lng_menu_back" = "Back"; +"lng_disable_notifications_from_tray" = "Disable notifications"; +"lng_enable_notifications_from_tray" = "Enable notifications"; "lng_open_from_tray" = "Open Telegram"; "lng_minimize_to_tray" = "Minimize to tray"; "lng_quit_from_tray" = "Quit Telegram"; diff --git a/Telegram/SourceFiles/_other/updater.cpp b/Telegram/SourceFiles/_other/updater.cpp index d78f215bf..484026f26 100644 --- a/Telegram/SourceFiles/_other/updater.cpp +++ b/Telegram/SourceFiles/_other/updater.cpp @@ -30,8 +30,8 @@ bool equal(const wstring &a, const wstring &b) { void updateError(const WCHAR *msg, DWORD errorCode) { WCHAR errMsg[2048]; - LPTSTR errorText = NULL, errorTextDefault = L"(Unknown error)"; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, 0, 0); + LPWSTR errorText = NULL, errorTextDefault = L"(Unknown error)"; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&errorText, 0, 0); if (!errorText) { errorText = errorTextDefault; } @@ -146,11 +146,11 @@ bool update() { HANDLE versionFile = CreateFile((tdataDir + L"\\version").c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (versionFile != INVALID_HANDLE_VALUE) { - if (ReadFile(versionFile, &versionNum, sizeof(DWORD), &readLen, NULL) != TRUE || readLen != sizeof(DWORD)) { + if (!ReadFile(versionFile, &versionNum, sizeof(DWORD), &readLen, NULL) || readLen != sizeof(DWORD)) { versionNum = 0; - } else if (ReadFile(versionFile, &versionLen, sizeof(DWORD), &readLen, NULL) != TRUE || readLen != sizeof(DWORD) || versionLen > 63) { + } else if (!ReadFile(versionFile, &versionLen, sizeof(DWORD), &readLen, NULL) || readLen != sizeof(DWORD) || versionLen > 63) { versionNum = 0; - } else if (ReadFile(versionFile, versionStr, versionLen, &readLen, NULL) != TRUE || readLen != versionLen) { + } else if (!ReadFile(versionFile, versionStr, versionLen, &readLen, NULL) || readLen != versionLen) { versionNum = 0; } CloseHandle(versionFile); @@ -245,14 +245,14 @@ bool update() { int copyTries = 0; do { copyResult = CopyFile(fname.c_str(), tofname.c_str(), FALSE); - if (copyResult == FALSE) { + if (!copyResult) { ++copyTries; Sleep(100); } else { break; } } while (copyTries < 30); - if (copyResult == FALSE) { + if (!copyResult) { writeLog(L"Error: failed to copy, asking to retry.."); WCHAR errMsg[2048]; wsprintf(errMsg, L"Failed to update Telegram :(\n%s is not accessible.", tofname.c_str()); @@ -261,7 +261,7 @@ bool update() { return false; } } - } while (copyResult == FALSE); + } while (!copyResult); } writeLog(L"Update succeed! Clearing folder.."); @@ -292,7 +292,7 @@ void updateRegistry() { } } if (locationType == REG_EXPAND_SZ || locationType == REG_SZ) { - if (PathCanonicalize(exp, locationStr) == TRUE) { + if (PathCanonicalize(exp, locationStr)) { memcpy(locationStr, exp, bufSize * sizeof(WCHAR)); if (GetFullPathName(L".", bufSize, exp, 0) < bufSize) { wstring installpath = locationStr, mypath = exp; @@ -326,7 +326,7 @@ void updateRegistry() { #include -int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParamarg, int cmdShow) { +int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdParamarg, int cmdShow) { openLog(); #ifdef _NEED_WIN_GENERATE_DUMP diff --git a/Telegram/SourceFiles/pspecific_linux.cpp b/Telegram/SourceFiles/pspecific_linux.cpp index adec4309a..c9213d98f 100644 --- a/Telegram/SourceFiles/pspecific_linux.cpp +++ b/Telegram/SourceFiles/pspecific_linux.cpp @@ -1165,6 +1165,7 @@ namespace { } void psRegisterCustomScheme() { + #ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME QString home(_psHomeDir()); if (home.isEmpty()) return; @@ -1249,6 +1250,7 @@ void psRegisterCustomScheme() { LOG(("App Error: Could not open '%1' for write").arg(file)); } } + #endif } void psNewVersion() { diff --git a/Telegram/SourceFiles/pspecific_mac_p.mm b/Telegram/SourceFiles/pspecific_mac_p.mm index 623cdd05b..d02aede57 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.mm +++ b/Telegram/SourceFiles/pspecific_mac_p.mm @@ -936,8 +936,10 @@ void objc_finish() { } void objc_registerCustomScheme() { + #ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME OSStatus result = LSSetDefaultHandlerForURLScheme(CFSTR("tg"), (CFStringRef)[[NSBundle mainBundle] bundleIdentifier]); DEBUG_LOG(("App Info: set default handler for 'tg' scheme result: %1").arg(result)); + #endif } BOOL _execUpdater(BOOL update = YES) { diff --git a/Telegram/SourceFiles/pspecific_wnd.cpp b/Telegram/SourceFiles/pspecific_wnd.cpp index 544ecb171..07f58b9b4 100644 --- a/Telegram/SourceFiles/pspecific_wnd.cpp +++ b/Telegram/SourceFiles/pspecific_wnd.cpp @@ -2216,6 +2216,7 @@ namespace { } void RegisterCustomScheme() { + #ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME DEBUG_LOG(("App Info: Checking custom scheme 'tg'..")); HKEY rkey; @@ -2232,6 +2233,7 @@ void RegisterCustomScheme() { if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open", &rkey)) return; if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open\\command", &rkey)) return; if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\" -- \"%1\""))) return; + #endif } void psNewVersion() { diff --git a/Telegram/SourceFiles/settingswidget.cpp b/Telegram/SourceFiles/settingswidget.cpp index 0106d151b..7881a47e4 100644 --- a/Telegram/SourceFiles/settingswidget.cpp +++ b/Telegram/SourceFiles/settingswidget.cpp @@ -860,6 +860,7 @@ void SettingsInner::updateSize(int32 newWidth) { } } + void SettingsInner::updateOnlineDisplay() { } @@ -1474,6 +1475,11 @@ void SettingsInner::onDesktopNotify() { } } +void SettingsInner::enableDisplayNotify(bool enable) +{ + _desktopNotify.setChecked(enable); +} + void SettingsInner::onSenderName() { _messagePreview.setDisabled(!_senderName.checked()); if (!_senderName.checked() && _messagePreview.checked()) { @@ -1858,6 +1864,11 @@ void SettingsWidget::updateWideMode() { } } +void SettingsWidget::updateDisplayNotify() +{ + _inner.enableDisplayNotify(cDesktopNotify()); +} + void SettingsWidget::updateOnlineDisplay() { _inner.updateOnlineDisplay(); } diff --git a/Telegram/SourceFiles/settingswidget.h b/Telegram/SourceFiles/settingswidget.h index a65125083..e0fc5dbb9 100644 --- a/Telegram/SourceFiles/settingswidget.h +++ b/Telegram/SourceFiles/settingswidget.h @@ -85,6 +85,7 @@ public: void updateChatBackground(); void needBackgroundUpdate(bool tile); + void enableDisplayNotify(bool enable); public slots: @@ -318,6 +319,8 @@ public: void updateOnlineDisplay(); void updateConnectionType(); + void updateDisplayNotify(); + void rpcInvalidate(); void usernameChanged(); diff --git a/Telegram/SourceFiles/window.cpp b/Telegram/SourceFiles/window.cpp index ea5770345..3e3d1c01b 100644 --- a/Telegram/SourceFiles/window.cpp +++ b/Telegram/SourceFiles/window.cpp @@ -449,10 +449,15 @@ void Window::firstShow() { trayIconMenu = new QMenu(this); trayIconMenu->setFont(QFont("Tahoma")); #endif + QString notificationItem = lang(cDesktopNotify() + ? lng_disable_notifications_from_tray : lng_enable_notifications_from_tray); + if (cPlatform() == dbipWindows || cPlatform() == dbipMac) { + trayIconMenu->addAction(notificationItem, this, SLOT(toggleDisplayNotifyFromTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()))->setEnabled(true); } else { + trayIconMenu->addAction(notificationItem, this, SLOT(toggleDisplayNotifyFromTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_open_from_tray), this, SLOT(showFromTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()))->setEnabled(true); trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()))->setEnabled(true); @@ -1025,13 +1030,19 @@ void Window::updateTrayMenu(bool force) { bool active = isActive(false); if (cPlatform() == dbipWindows || cPlatform() == dbipMac) { + QString notificationItem = lang(cDesktopNotify() + ? lng_disable_notifications_from_tray : lng_enable_notifications_from_tray); + QAction *first = trayIconMenu->actions().at(0); - first->setText(lang(active ? lng_minimize_to_tray : lng_open_from_tray)); - disconnect(first, SIGNAL(triggered(bool)), 0, 0); - connect(first, SIGNAL(triggered(bool)), this, active ? SLOT(minimizeToTray()) : SLOT(showFromTray())); - } else { + first->setText(notificationItem); + QAction *second = trayIconMenu->actions().at(1); - second->setDisabled(!isVisible()); + second->setText(lang(active ? lng_minimize_to_tray : lng_open_from_tray)); + disconnect(second, SIGNAL(triggered(bool)), 0, 0); + connect(second, SIGNAL(triggered(bool)), this, active ? SLOT(minimizeToTray()) : SLOT(showFromTray())); + } else { + QAction *third = trayIconMenu->actions().at(2); + third->setDisabled(!isVisible()); } #ifndef Q_OS_WIN if (trayIcon) { @@ -1156,6 +1167,13 @@ void Window::toggleTray(QSystemTrayIcon::ActivationReason reason) { } } +void Window::toggleDisplayNotifyFromTray() { + cSetDesktopNotify(!cDesktopNotify()); + if (settings) { + settings->updateDisplayNotify(); + } +} + void Window::closeEvent(QCloseEvent *e) { if (MTP::authedId() && !App::app()->isSavingSession() && minimizeToTray()) { e->ignore(); diff --git a/Telegram/SourceFiles/window.h b/Telegram/SourceFiles/window.h index aa6a9380c..5db77d111 100644 --- a/Telegram/SourceFiles/window.h +++ b/Telegram/SourceFiles/window.h @@ -261,6 +261,7 @@ public slots: void showFromTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown); bool minimizeToTray(); void toggleTray(QSystemTrayIcon::ActivationReason reason = QSystemTrayIcon::Unknown); + void toggleDisplayNotifyFromTray(); void onInactiveTimer(); diff --git a/Telegram/Updater.rc b/Telegram/Updater.rc index 0a3c12aa2..5df23e756 100644 Binary files a/Telegram/Updater.rc and b/Telegram/Updater.rc differ