From e0a364dd0f8b51e034f4485059904162b41b4bb2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 20 Jun 2014 11:06:21 +0400 Subject: [PATCH] fixed online display, fixed reading messages on idle --- Telegram/SourceFiles/app.cpp | 2 ++ Telegram/SourceFiles/dialogswidget.cpp | 1 + Telegram/SourceFiles/gui/flatinput.cpp | 13 +++++++-- Telegram/SourceFiles/gui/flatinput.h | 4 +++ Telegram/SourceFiles/historywidget.cpp | 2 ++ Telegram/SourceFiles/main.cpp | 9 +++++-- Telegram/SourceFiles/mainwidget.cpp | 1 - Telegram/SourceFiles/pspecific_mac.cpp | 30 ++++++++++++--------- Telegram/SourceFiles/pspecific_mac.h | 4 ++- Telegram/SourceFiles/pspecific_wnd.cpp | 22 ++++++++++----- Telegram/SourceFiles/pspecific_wnd.h | 2 ++ Telegram/SourceFiles/window.cpp | 6 +++++ Telegram/Telegram.plist | 2 +- Telegram/Telegram.xcodeproj/project.pbxproj | 10 +++---- 14 files changed, 77 insertions(+), 31 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index e0e0c0bd78..7f0f2c03c2 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1225,7 +1225,9 @@ namespace App { textlnkDown(TextLinkPtr()); if (completely) { + LOG(("Deleting sound..")); delete newMsgSound; + LOG(("Sound deleted!")); newMsgSound = 0; delete ::sprite; diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index c7f605f8ca..f76fa94263 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -736,6 +736,7 @@ DialogsWidget::DialogsWidget(MainWidget *parent) : QWidget(parent) _filter.show(); _filter.move(st::dlgPaddingHor, st::dlgFilterPadding); _filter.setFocusPolicy(Qt::StrongFocus); + _filter.customUpDown(true); _addContact.hide(); _newGroup.show(); _newGroup.move(width() - _newGroup.width() - st::dlgPaddingHor, 0); diff --git a/Telegram/SourceFiles/gui/flatinput.cpp b/Telegram/SourceFiles/gui/flatinput.cpp index 74d734234f..f032001f42 100644 --- a/Telegram/SourceFiles/gui/flatinput.cpp +++ b/Telegram/SourceFiles/gui/flatinput.cpp @@ -41,7 +41,7 @@ namespace { FlatInputStyle _flatInputStyle; } -FlatInput::FlatInput(QWidget *parent, const style::flatInput &st, const QString &pholder, const QString &v) : QLineEdit(v, parent), _oldtext(v), _kev(0), _phVisible(!v.length()), +FlatInput::FlatInput(QWidget *parent, const style::flatInput &st, const QString &pholder, const QString &v) : QLineEdit(v, parent), _oldtext(v), _kev(0), _customUpDown(false), _phVisible(!v.length()), a_phLeft(_phVisible ? 0 : st.phShift), a_phAlpha(_phVisible ? 1 : 0), a_phColor(st.phColor->c), a_borderColor(st.borderColor->c), a_bgColor(st.bgColor->c), _notingBene(0), _st(st) { resize(_st.width, _st.height); @@ -67,6 +67,10 @@ FlatInput::FlatInput(QWidget *parent, const style::flatInput &st, const QString connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer())); } +void FlatInput::customUpDown(bool custom) { + _customUpDown = custom; +} + void FlatInput::onTouchTimer() { _touchRightButton = true; } @@ -231,7 +235,12 @@ void FlatInput::correctValue(QKeyEvent *e, const QString &was) { void FlatInput::keyPressEvent(QKeyEvent *e) { QString was(text()); _kev = e; - QLineEdit::keyPressEvent(e); + if (_customUpDown && (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down)) { + e->ignore(); + } else { + QLineEdit::keyPressEvent(e); + } + if (was == text()) { // call correct manually correctValue(_kev, was); _oldtext = text(); diff --git a/Telegram/SourceFiles/gui/flatinput.h b/Telegram/SourceFiles/gui/flatinput.h index b77d8a44e7..ea7012ef29 100644 --- a/Telegram/SourceFiles/gui/flatinput.h +++ b/Telegram/SourceFiles/gui/flatinput.h @@ -47,6 +47,8 @@ public: QSize sizeHint() const; QSize minimumSizeHint() const; + void customUpDown(bool isCustom); + public slots: void onTextChange(const QString &text); @@ -71,6 +73,8 @@ private: QString _ph, _oldtext; QKeyEvent *_kev; + bool _customUpDown; + bool _phVisible; anim::ivalue a_phLeft; anim::fvalue a_phAlpha; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 7e72ab93e0..843df46545 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -1979,6 +1979,8 @@ void HistoryWidget::onSend() { MTP::send(MTPmessages_SendMessage(histInputPeer, msgText, MTP_long(randomId)), App::main()->rpcDone(&MainWidget::sentDataReceived, randomId)); _field.setPlainText(""); + if (!_attachType.isHidden()) _attachType.hideStart(); + if (!_emojiPan.isHidden()) _emojiPan.hideStart(); } _field.setFocus(); } diff --git a/Telegram/SourceFiles/main.cpp b/Telegram/SourceFiles/main.cpp index 6c7cc3ebc7..f579b141c9 100644 --- a/Telegram/SourceFiles/main.cpp +++ b/Telegram/SourceFiles/main.cpp @@ -45,8 +45,13 @@ int main(int argc, char *argv[]) { DEBUG_LOG(("Application Info: ideal thread count: %1, using %2 connections per session").arg(QThread::idealThreadCount()).arg(cConnectionsInSession())); - Application app(argc, argv); - int result = App::quiting() ? 0 : app.exec(); + int result = 0; + { + Application app(argc, argv); + if (!App::quiting()) { + result = app.exec(); + } + } psFinish(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index efc3f94a4a..8be1ecf1f9 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -272,7 +272,6 @@ MainWidget::MainWidget(Window *window) : QWidget(window), failedObjId(0), _dialo connect(this, SIGNAL(peerPhotoChanged(PeerData *)), this, SIGNAL(dialogsUpdated())); connect(&noUpdatesTimer, SIGNAL(timeout()), this, SLOT(getDifference())); connect(&onlineTimer, SIGNAL(timeout()), this, SLOT(setOnline())); - connect(window->windowHandle(), SIGNAL(windowStateChanged(Qt::WindowState)), this, SLOT(mainStateChanged(Qt::WindowState))); connect(&onlineUpdater, SIGNAL(timeout()), this, SLOT(updateOnlineDisplay())); connect(this, SIGNAL(peerUpdated(PeerData*)), &history, SLOT(peerUpdated(PeerData*))); connect(&_topBar, SIGNAL(clicked()), this, SLOT(onTopBarClick())); diff --git a/Telegram/SourceFiles/pspecific_mac.cpp b/Telegram/SourceFiles/pspecific_mac.cpp index 072616a1b0..60f1082822 100644 --- a/Telegram/SourceFiles/pspecific_mac.cpp +++ b/Telegram/SourceFiles/pspecific_mac.cpp @@ -119,25 +119,30 @@ void MacPrivate::notifyReplied(unsigned long long peer, const char *str) { PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/iconround256.png")) { - - //tbCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated"); - icon16 = icon256.scaledToWidth(16, Qt::SmoothTransformation); - icon32 = icon256.scaledToWidth(32, Qt::SmoothTransformation); connect(&psIdleTimer, SIGNAL(timeout()), this, SLOT(psIdleTimeout())); psIdleTimer.setSingleShot(false); connect(¬ifyWaitTimer, SIGNAL(timeout()), this, SLOT(psNotifyFire())); notifyWaitTimer.setSingleShot(true); } +void PsMainWindow::psNotIdle() const { + psIdleTimer.stop(); + if (psIdle) { + psIdle = false; + if (App::main()) App::main()->setOnline(); + if (App::wnd()) App::wnd()->checkHistoryActivation(); + } +} + void PsMainWindow::psIdleTimeout() { int64 idleTime = objc_idleTime(); if (idleTime >= 0) { if (idleTime <= IdleMsecs) { - psIdle = false; - psIdleTimer.stop(); - if (App::main()) App::main()->setOnline(); + psNotIdle(); } - } + } else { // error + psNotIdle(); + } } bool PsMainWindow::psIsOnline(int state) const { @@ -157,16 +162,17 @@ bool PsMainWindow::psIsOnline(int state) const { } return false; } else { - psIdle = false; - psIdleTimer.stop(); + psNotIdle(); } - } + } else { // error + psNotIdle(); + } return true; } bool PsMainWindow::psIsActive(int state) const { if (state < 0) state = this->windowState(); - return isActiveWindow() && isVisible() && !(state & Qt::WindowMinimized); + return isActiveWindow() && isVisible() && !(state & Qt::WindowMinimized) && !psIdle; } void PsMainWindow::psRefreshTaskbarIcon() { diff --git a/Telegram/SourceFiles/pspecific_mac.h b/Telegram/SourceFiles/pspecific_mac.h index 2ff8966c54..ff26e49097 100644 --- a/Telegram/SourceFiles/pspecific_mac.h +++ b/Telegram/SourceFiles/pspecific_mac.h @@ -151,10 +151,12 @@ public slots: protected: + void psNotIdle() const; + bool posInited; QSystemTrayIcon *trayIcon; QMenu *trayIconMenu; - QImage icon16, icon32, icon256; + QImage icon256; virtual void setupTrayIcon() { } diff --git a/Telegram/SourceFiles/pspecific_wnd.cpp b/Telegram/SourceFiles/pspecific_wnd.cpp index 1f82295331..d0127d8a36 100644 --- a/Telegram/SourceFiles/pspecific_wnd.cpp +++ b/Telegram/SourceFiles/pspecific_wnd.cpp @@ -872,6 +872,15 @@ PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), ps_hWnd(0), p notifyWaitTimer.setSingleShot(true); } +void PsMainWindow::psNotIdle() const { + psIdleTimer.stop(); + if (psIdle) { + psIdle = false; + if (App::main()) App::main()->setOnline(); + if (App::wnd()) App::wnd()->checkHistoryActivation(); + } +} + void PsMainWindow::psIdleTimeout() { LASTINPUTINFO lii; lii.cbSize = sizeof(LASTINPUTINFO); @@ -879,15 +888,15 @@ void PsMainWindow::psIdleTimeout() { if (res) { uint64 ticks = GetTickCount(); if (lii.dwTime >= ticks - IdleMsecs) { - psIdle = false; - psIdleTimer.stop(); - if (App::main()) App::main()->setOnline(); + psNotIdle(); } + } else { // error { + psNotIdle(); } } bool PsMainWindow::psIsActive() const { - return isActiveWindow() && isVisible() && !(windowState() & Qt::WindowMinimized); + return isActiveWindow() && isVisible() && !(windowState() & Qt::WindowMinimized) && !psIdle; } bool PsMainWindow::psIsOnline(int windowState) const { @@ -909,9 +918,10 @@ bool PsMainWindow::psIsOnline(int windowState) const { } return false; } else { - psIdle = false; - psIdleTimer.stop(); + psNotIdle(); } + } else { // error + psNotIdle(); } return true; } diff --git a/Telegram/SourceFiles/pspecific_wnd.h b/Telegram/SourceFiles/pspecific_wnd.h index be6b205bb9..109316d88b 100644 --- a/Telegram/SourceFiles/pspecific_wnd.h +++ b/Telegram/SourceFiles/pspecific_wnd.h @@ -136,6 +136,8 @@ public slots: protected: + void psNotIdle() const; + bool posInited; QSystemTrayIcon *trayIcon; QMenu *trayIconMenu; diff --git a/Telegram/SourceFiles/window.cpp b/Telegram/SourceFiles/window.cpp index 8cf74c8bbb..3356d70037 100644 --- a/Telegram/SourceFiles/window.cpp +++ b/Telegram/SourceFiles/window.cpp @@ -444,6 +444,12 @@ QRect Window::iconRect() const { bool Window::eventFilter(QObject *obj, QEvent *evt) { if (obj == App::app() && (evt->type() == QEvent::ApplicationActivate)) { QTimer::singleShot(1, this, SLOT(checkHistoryActivation())); + } else if (obj == this && evt->type() == QEvent::WindowStateChange) { + Qt::WindowState state = (windowState() & Qt::WindowMinimized) ? Qt::WindowMinimized : ((windowState() & Qt::WindowMaximized) ? Qt::WindowMaximized : ((windowState() & Qt::WindowFullScreen) ? Qt::WindowFullScreen : Qt::WindowNoState)); + psStateChanged(state); + if (App::main()) { + App::main()->mainStateChanged(state); + } } return PsMainWindow::eventFilter(obj, evt); } diff --git a/Telegram/Telegram.plist b/Telegram/Telegram.plist index a290a92b6c..e6aa25d609 100644 --- a/Telegram/Telegram.plist +++ b/Telegram/Telegram.plist @@ -11,7 +11,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.5.2 + 0.5.4 CFBundleSignature ???? NOTE diff --git a/Telegram/Telegram.xcodeproj/project.pbxproj b/Telegram/Telegram.xcodeproj/project.pbxproj index 93f54a598c..aa926d49c0 100644 --- a/Telegram/Telegram.xcodeproj/project.pbxproj +++ b/Telegram/Telegram.xcodeproj/project.pbxproj @@ -1458,8 +1458,9 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; + CURRENT_PROJECT_VERSION = 0.5.4; DYLIB_COMPATIBILITY_VERSION = 0.5; - DYLIB_CURRENT_VERSION = 0.5.1; + DYLIB_CURRENT_VERSION = 0.5.4; FRAMEWORK_SEARCH_PATHS = ""; GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_OPTIMIZATION_LEVEL = fast; @@ -1576,9 +1577,10 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 0.5.4; DEBUG_INFORMATION_FORMAT = dwarf; DYLIB_COMPATIBILITY_VERSION = 0.5; - DYLIB_CURRENT_VERSION = 0.5.1; + DYLIB_CURRENT_VERSION = 0.5.4; FRAMEWORK_SEARCH_PATHS = ""; GCC_GENERATE_DEBUGGING_SYMBOLS = YES; GCC_OPTIMIZATION_LEVEL = 0; @@ -1693,8 +1695,6 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 0.5.2; - DYLIB_CURRENT_VERSION = 0.5.2; GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_LINK_WITH_DYNAMIC_LIBRARIES = NO; GCC_OPTIMIZATION_LEVEL = fast; @@ -1714,9 +1714,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 0.5.2; DEBUG_INFORMATION_FORMAT = dwarf; - DYLIB_CURRENT_VERSION = 0.5.2; GCC_GENERATE_DEBUGGING_SYMBOLS = YES; GCC_LINK_WITH_DYNAMIC_LIBRARIES = NO; GCC_OPTIMIZATION_LEVEL = 0;