link clicks and popup menu items activated async, some crashes fixed

This commit is contained in:
John Preston 2016-02-16 14:21:39 +03:00
parent ebd77ba71d
commit a5b466ec05
11 changed files with 41 additions and 18 deletions

View File

@ -1410,7 +1410,7 @@ namespace App {
QString uname(username.trimmed());
for (PeersData::const_iterator i = peersData.cbegin(), e = peersData.cend(); i != e; ++i) {
if (!i.value()->userName().compare(uname, Qt::CaseInsensitive)) {
return i.value()->asUser();
return i.value();
}
}
return 0;

View File

@ -63,11 +63,26 @@ namespace App {
}
void removeDialog(History *history) {
if (MainWidget *m = main()) m->removeDialog(history);
if (MainWidget *m = main()) {
m->removeDialog(history);
}
}
void showSettings() {
if (Window *win = wnd()) win->showSettings();
if (Window *w = wnd()) {
w->showSettings();
}
}
Q_DECLARE_METATYPE(TextLinkPtr);
Q_DECLARE_METATYPE(Qt::MouseButton);
void activateTextLink(TextLinkPtr link, Qt::MouseButton button) {
if (Window *w = wnd()) {
qRegisterMetaType<TextLinkPtr>();
qRegisterMetaType<Qt::MouseButton>();
QMetaObject::invokeMethod(w, "app_activateTextLink", Qt::QueuedConnection, Q_ARG(TextLinkPtr, link), Q_ARG(Qt::MouseButton, button));
}
}
}

View File

@ -35,6 +35,8 @@ namespace App {
void removeDialog(History *history);
void showSettings();
void activateTextLink(TextLinkPtr link, Qt::MouseButton button);
};
namespace Ui {

View File

@ -81,7 +81,7 @@ void PopupMenu::init() {
QAction *PopupMenu::addAction(const QString &text, const QObject *receiver, const char* member) {
QAction *a = new QAction(text, this);
connect(a, SIGNAL(triggered(bool)), receiver, member);
connect(a, SIGNAL(triggered(bool)), receiver, member, Qt::QueuedConnection);
return addAction(a);
}

View File

@ -681,8 +681,9 @@ HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) {
int32 addToH = 0, skip = 0;
if (!blocks.isEmpty()) { // remove date block
if (width) addToH = -blocks.front()->height;
delete blocks.front();
HistoryBlock *dateblock = blocks.front();
blocks.pop_front();
delete dateblock;
}
HistoryItem *till = blocks.isEmpty() ? 0 : blocks.front()->items.front();

View File

@ -684,11 +684,12 @@ void HistoryInner::itemRemoved(HistoryItem *item) {
dragActionCancel();
}
if (_dragSelFrom == item || _dragSelTo == item) {
_dragSelFrom = 0;
_dragSelTo = 0;
update();
}
onUpdateSelected();
if (_dragSelFrom == item) _dragSelFrom = 0;
if (_dragSelTo == item) _dragSelTo = 0;
updateDragSelection(_dragSelFrom, _dragSelTo, _dragSelecting, true);
}
void HistoryInner::dragActionFinish(const QPoint &screenPos, Qt::MouseButton button) {
@ -730,10 +731,9 @@ void HistoryInner::dragActionFinish(const QPoint &screenPos, Qt::MouseButton but
_wasSelectedText = false;
if (needClick) {
DEBUG_LOG(("Clicked link: %1 (%2) %3").arg(needClick->text()).arg(needClick->readable()).arg(needClick->encoded()));
DEBUG_LOG(("Will click link: %1 (%2) %3").arg(needClick->text()).arg(needClick->readable()).arg(needClick->encoded()));
dragActionCancel();
needClick->onClick(button); // this possibly can delete this object
App::activateTextLink(needClick, button);
return;
}
if (_dragAction == PrepareSelect && !_dragWasInactive && !_selected.isEmpty() && _selected.cbegin().value() == FullSelection) {

View File

@ -606,7 +606,7 @@ void MTPabstractTcpConnection::socketRead() {
longBuffer.clear();
} else if (!readingToShort && packetRead < MTPShortBufferSize * sizeof(mtpPrime)) {
memcpy(shortBuffer, currentPos - packetRead, packetRead);
currentPos = (char*)shortBuffer;
currentPos = (char*)shortBuffer + packetRead;
readingToShort = true;
longBuffer.clear();
}

View File

@ -199,15 +199,15 @@ void PeerData::fillNames() {
names.clear();
chars.clear();
QString toIndex = textAccentFold(name);
if (cRussianLetters().match(toIndex).hasMatch()) {
toIndex += ' ' + translitRusEng(toIndex);
}
if (isUser()) {
if (!asUser()->nameOrPhone.isEmpty() && asUser()->nameOrPhone != name) toIndex += ' ' + textAccentFold(asUser()->nameOrPhone);
if (!asUser()->username.isEmpty()) toIndex += ' ' + textAccentFold(asUser()->username);
} else if (isChannel()) {
if (!asChannel()->username.isEmpty()) toIndex += ' ' + textAccentFold(asChannel()->username);
}
if (cRussianLetters().match(toIndex).hasMatch()) {
toIndex += ' ' + translitRusEng(toIndex);
}
toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
QStringList namesList = toIndex.toLower().split(cWordSplit(), QString::SkipEmptyParts);

View File

@ -811,8 +811,7 @@ QString translitRusEng(const QString &rus) {
result.reserve(rus.size() * 2);
int32 toSkip = 0;
for (QString::const_iterator i = rus.cbegin(), e = rus.cend(); i != e;) {
i += toSkip;
for (QString::const_iterator i = rus.cbegin(), e = rus.cend(); i != e; i += toSkip) {
result += translitLetterRusEng(*i, (i + 1 == e) ? ' ' : *(i + 1), toSkip);
}
return result;

View File

@ -1651,6 +1651,10 @@ void Window::notifyUpdateAllPhotos() {
if (_mediaView && !_mediaView->isHidden()) _mediaView->updateControls();
}
void Window::app_activateTextLink(TextLinkPtr link, Qt::MouseButton button) {
link->onClick(button);
}
void Window::notifyUpdateAll() {
if (cCustomNotifies()) {
for (NotifyWindows::const_iterator i = notifyWindows.cbegin(), e = notifyWindows.cend(); i != e; ++i) {

View File

@ -281,6 +281,8 @@ public slots:
void notifyUpdateAllPhotos();
void app_activateTextLink(TextLinkPtr link, Qt::MouseButton button);
signals:
void resized(const QSize &size);