From 3f8d7944c1ffaee8816b40b3ee3c800792aa051f Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 2 Nov 2015 17:36:26 -0500 Subject: [PATCH 1/7] folders not allowed to be dropped / pasted --- Telegram/SourceFiles/config.h | 2 +- Telegram/SourceFiles/historywidget.cpp | 11 +++++++---- Telegram/SourceFiles/localimageloader.cpp | 9 +++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 58b7905d05..2a49ed1a9e 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -351,7 +351,7 @@ enum { }; inline const QRegularExpression &cWordSplit() { - static QRegularExpression regexp(qsl("[\\@\\s\\-\\+\\)\\(\\,\\.\\:\\!\\_\\;\\\"\\'\\x0]")); + static QRegularExpression regexp(qsl("[\\@\\s\\-\\+\\(\\)\\[\\]\\{\\}\\<\\>\\,\\.\\:\\!\\_\\;\\\"\\'\\x0]")); return regexp; } diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 21d7028e7e..4398f133a0 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -4378,7 +4378,10 @@ DragState HistoryWidget::getDragState(const QMimeData *d) { QString file(i->toLocalFile()); if (file.startsWith(qsl("/.file/id="))) file = psConvertFileUrl(file); - quint64 s = QFileInfo(file).size(); + QFileInfo info(file); + if (info.isDir()) return DragStateNone; + + quint64 s = info.size(); if (s >= MaxUploadDocumentSize) { return DragStateNone; } @@ -4527,10 +4530,10 @@ void HistoryWidget::onFilesDrop(const QMimeData *data) { return; } - if (files.size() == 1) { + if (files.size() == 1 && !QFileInfo(files.at(0)).isDir()) { uploadFile(files.at(0), PrepareAuto); } -// uploadFiles(files, PrepareAuto); // multiple confirm with "compressed" checkbox +// uploadFiles(files, PrepareAuto); // multiple confirm with "compressed" checkbox } void HistoryWidget::onKbToggle(bool manual) { @@ -4816,7 +4819,7 @@ void HistoryWidget::uploadFile(const QString &file, PrepareMediaType type, FileL void HistoryWidget::uploadFiles(const QStringList &files, PrepareMediaType type) { if (!_history || files.isEmpty()) return; - if (files.size() == 1) return uploadFile(files.at(0), type); + if (files.size() == 1 && !QFileInfo(files.at(0)).isDir()) return uploadFile(files.at(0), type); App::wnd()->activateWindow(); diff --git a/Telegram/SourceFiles/localimageloader.cpp b/Telegram/SourceFiles/localimageloader.cpp index ba9e7a0d04..1b71de0de9 100644 --- a/Telegram/SourceFiles/localimageloader.cpp +++ b/Telegram/SourceFiles/localimageloader.cpp @@ -216,6 +216,10 @@ void FileLoadTask::process() { if (!_filepath.isEmpty()) { QFileInfo info(_filepath); + if (info.isDir()) { + _result->filesize = -1; + return; + } filesize = info.size(); filemime = mimeTypeForFile(info).name(); filename = info.fileName(); @@ -399,6 +403,11 @@ void FileLoadTask::finish() { App::wnd()->replaceLayer(new InformBox(lang(lng_send_image_empty))); return; } + if (_result->filesize == -1) { // dir + App::main()->onSendFileCancel(_result); + App::wnd()->replaceLayer(new InformBox(lng_send_folder(lt_name, QFileInfo(_filepath).fileName()))); + return; + } if (_result->filesize > MaxUploadDocumentSize) { App::main()->onSendFileCancel(_result); App::wnd()->replaceLayer(new InformBox(lang(lng_send_image_too_large))); From 53728e1d13e9783117ed1f137d4608c1a5770ff7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 2 Nov 2015 17:39:40 -0500 Subject: [PATCH 2/7] version 0.9.9.dev before stable, testing custom context menu --- Telegram/SourceFiles/application.cpp | 4 ++-- Telegram/Telegram.plist | 2 +- Telegram/Telegram.rc | Bin 5532 -> 5532 bytes Telegram/Telegram.xcodeproj/project.pbxproj | 12 ++++++------ Telegram/Version | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index f403058110..4ecbe58456 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -696,8 +696,8 @@ void Application::checkMapVersion() { if (Local::oldMapVersion() < AppVersion) { if (Local::oldMapVersion()) { QString versionFeatures; - if (cDevVersion() && Local::oldMapVersion() < 9007) { - versionFeatures = QString::fromUtf8("\xe2\x80\x94 Tilde symbol fixed in message input field\n\xe2\x80\x94 Add a caption to any photo you send\n\xe2\x80\x94 Bad sound quality bug fixed\n\xe2\x80\x94 Some bugfixes and improvements");// .replace('@', qsl("@") + QChar(0x200D)); + if (cDevVersion() && Local::oldMapVersion() < 9009) { + versionFeatures = QString::fromUtf8("\xe2\x80\x94 New popup menus in text input fields\n\xe2\x80\x94 Error is displayed when trying to paste or drop a folder instead of a file\n\xe2\x80\x94 Some bugfixes and improvements");// .replace('@', qsl("@") + QChar(0x200D)); } else if (Local::oldMapVersion() < 9005) { versionFeatures = lang(lng_new_version_text).trimmed(); } else { diff --git a/Telegram/Telegram.plist b/Telegram/Telegram.plist index ce9f208f66..217a1bf819 100644 --- a/Telegram/Telegram.plist +++ b/Telegram/Telegram.plist @@ -11,7 +11,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.9.8 + 0.9.9 CFBundleSignature ???? CFBundleURLTypes diff --git a/Telegram/Telegram.rc b/Telegram/Telegram.rc index 7479f851ae23b07eafebd0b0f58d7bc558600bdd..d575f5cc74b66fbb371b2169c64a320d6bc64683 100644 GIT binary patch delta 50 zcmbQEJx6;(0WYKF Date: Mon, 2 Nov 2015 17:51:21 -0500 Subject: [PATCH 3/7] langs updated for 0.9.9.dev --- Telegram/Resources/lang.strings | 1 + 1 file changed, 1 insertion(+) diff --git a/Telegram/Resources/lang.strings b/Telegram/Resources/lang.strings index bfaa9b231a..c61644b99f 100644 --- a/Telegram/Resources/lang.strings +++ b/Telegram/Resources/lang.strings @@ -676,6 +676,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org "lng_send_image_compressed" = "Send compressed image"; "lng_send_image_empty" = "Could not send an empty file :("; "lng_send_image_too_large" = "Could not send a file, because it is larger than 1.5 GB :("; +"lng_send_folder" = "Could not send «{name}» because it is a directory :("; "lng_forward_choose" = "Choose recipient.."; "lng_forward_cant" = "Sorry, no way to forward here :("; From 9a83c26731355af14c13052b13995e68d46928b3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 2 Nov 2015 18:30:28 -0500 Subject: [PATCH 4/7] fixed OS X PopupMenu behaviour and directory name in error msg --- Telegram/SourceFiles/config.h | 4 ++-- Telegram/SourceFiles/gui/popupmenu.cpp | 17 +++++++++-------- Telegram/SourceFiles/gui/popupmenu.h | 1 + Telegram/SourceFiles/localimageloader.cpp | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 2a49ed1a9e..4cd25c8801 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -20,8 +20,8 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org */ #pragma once -static const int32 AppVersion = 9008; -static const wchar_t *AppVersionStr = L"0.9.8"; +static const int32 AppVersion = 9009; +static const wchar_t *AppVersionStr = L"0.9.9"; static const bool DevVersion = true; static const wchar_t *AppNameOld = L"Telegram Win (Unofficial)"; diff --git a/Telegram/SourceFiles/gui/popupmenu.cpp b/Telegram/SourceFiles/gui/popupmenu.cpp index 251a547c3d..ea68cff3d0 100644 --- a/Telegram/SourceFiles/gui/popupmenu.cpp +++ b/Telegram/SourceFiles/gui/popupmenu.cpp @@ -50,6 +50,7 @@ PopupMenu::PopupMenu(QMenu *menu, const style::PopupMenu &st) : TWidget(0) , _mouseSelection(false) , _shadow(_st.shadow) , _selected(-1) +, _childMenuIndex(-1) , a_opacity(1) , _a_hide(animFunc(this, &PopupMenu::animStep_hide)) , _deleteOnHide(true) { @@ -301,11 +302,7 @@ void PopupMenu::keyPressEvent(QKeyEvent *e) { void PopupMenu::enterEvent(QEvent *e) { QPoint mouse = QCursor::pos(); - if (_inner.marginsRemoved(QMargins(0, _st.skip, 0, _st.skip)).contains(mapFromGlobal(mouse))) { - _mouseSelection = true; - _mouse = mouse; - updateSelected(); - } else { + if (!_inner.marginsRemoved(QMargins(0, _st.skip, 0, _st.skip)).contains(mapFromGlobal(mouse))) { if (_mouseSelection && _childMenuIndex < 0) { _mouseSelection = false; setSelected(-1); @@ -385,6 +382,12 @@ void PopupMenu::focusOutEvent(QFocusEvent *e) { hideMenu(); } +void PopupMenu::hideEvent(QHideEvent *e) { + if (_deleteOnHide) { + deleteLater(); + } +} + void PopupMenu::hideMenu(bool fast) { if (isHidden()) return; if (_parent && !_a_hide.animating()) { @@ -419,9 +422,6 @@ void PopupMenu::childHiding(PopupMenu *child) { void PopupMenu::hideFinish() { hide(); - if (_deleteOnHide) { - deleteLater(); - } } bool PopupMenu::animStep_hide(float64 ms) { @@ -482,6 +482,7 @@ void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, PressSource source) } move(w); + _mouseSelection = (source == PressSourceMouse); setSelected((source == PressSourceMouse || _actions.isEmpty()) ? -1 : 0); psUpdateOverlayed(this); show(); diff --git a/Telegram/SourceFiles/gui/popupmenu.h b/Telegram/SourceFiles/gui/popupmenu.h index 8aa2a80858..bccb3483c9 100644 --- a/Telegram/SourceFiles/gui/popupmenu.h +++ b/Telegram/SourceFiles/gui/popupmenu.h @@ -47,6 +47,7 @@ protected: void leaveEvent(QEvent *e); void enterEvent(QEvent *e); void focusOutEvent(QFocusEvent *e); + void hideEvent(QHideEvent *e); public slots: diff --git a/Telegram/SourceFiles/localimageloader.cpp b/Telegram/SourceFiles/localimageloader.cpp index 1b71de0de9..f82fdb396f 100644 --- a/Telegram/SourceFiles/localimageloader.cpp +++ b/Telegram/SourceFiles/localimageloader.cpp @@ -405,7 +405,7 @@ void FileLoadTask::finish() { } if (_result->filesize == -1) { // dir App::main()->onSendFileCancel(_result); - App::wnd()->replaceLayer(new InformBox(lng_send_folder(lt_name, QFileInfo(_filepath).fileName()))); + App::wnd()->replaceLayer(new InformBox(lng_send_folder(lt_name, QFileInfo(_filepath).dir().dirName()))); return; } if (_result->filesize > MaxUploadDocumentSize) { From 5110ebb18e359736685915c8e22881c5a26a89c3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 3 Nov 2015 11:49:14 -0500 Subject: [PATCH 5/7] crash in PopupMenu fixed --- Telegram/SourceFiles/gui/popupmenu.cpp | 37 +++++++++++++++++++------- Telegram/SourceFiles/gui/popupmenu.h | 2 +- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/gui/popupmenu.cpp b/Telegram/SourceFiles/gui/popupmenu.cpp index ea68cff3d0..bfc890cb34 100644 --- a/Telegram/SourceFiles/gui/popupmenu.cpp +++ b/Telegram/SourceFiles/gui/popupmenu.cpp @@ -37,7 +37,9 @@ PopupMenu::PopupMenu(const style::PopupMenu &st) : TWidget(0) , _childMenuIndex(-1) , a_opacity(1) , _a_hide(animFunc(this, &PopupMenu::animStep_hide)) -, _deleteOnHide(true) { +, _deleteOnHide(true) +, _triggering(false) +, _deleteLater(false) { init(); } @@ -53,7 +55,9 @@ PopupMenu::PopupMenu(QMenu *menu, const style::PopupMenu &st) : TWidget(0) , _childMenuIndex(-1) , a_opacity(1) , _a_hide(animFunc(this, &PopupMenu::animStep_hide)) -, _deleteOnHide(true) { +, _deleteOnHide(true) +, _triggering(false) +, _deleteLater(false) { init(); QList actions(menu->actions()); for (int32 i = 0, l = actions.size(); i < l; ++i) { @@ -238,7 +242,13 @@ void PopupMenu::itemPressed(PressSource source) { } } else { hideMenu(); + _triggering = true; emit _actions[_selected]->trigger(); + _triggering = false; + if (_deleteLater) { + _deleteLater = false; + deleteLater(); + } } } } @@ -262,6 +272,7 @@ void PopupMenu::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { itemPressed(PressSourceKeyboard); + return; } else if (e->key() == Qt::Key_Escape) { hideMenu(_parent ? true : false); return; @@ -269,6 +280,7 @@ void PopupMenu::keyPressEvent(QKeyEvent *e) { if (e->key() == (rtl() ? Qt::Key_Left : Qt::Key_Right)) { if (_selected >= 0 && _menus.at(_selected)) { itemPressed(PressSourceKeyboard); + return; } else if (_selected < 0 && _parent && !_actions.isEmpty()) { _mouseSelection = false; setSelected(0); @@ -368,13 +380,14 @@ void PopupMenu::mouseMoveEvent(QMouseEvent *e) { void PopupMenu::mousePressEvent(QMouseEvent *e) { mouseMoveEvent(e); - itemPressed(PressSourceMouse); - if (!_inner.contains(mapFromGlobal(e->globalPos()))) { - if (_parent) { - _parent->mousePressEvent(e); - } else { - hideMenu(); - } + if (_inner.contains(mapFromGlobal(e->globalPos()))) { + itemPressed(PressSourceMouse); + return; + } + if (_parent) { + _parent->mousePressEvent(e); + } else { + hideMenu(); } } @@ -384,7 +397,11 @@ void PopupMenu::focusOutEvent(QFocusEvent *e) { void PopupMenu::hideEvent(QHideEvent *e) { if (_deleteOnHide) { - deleteLater(); + if (_triggering) { + _deleteLater = true; + } else { + deleteLater(); + } } } diff --git a/Telegram/SourceFiles/gui/popupmenu.h b/Telegram/SourceFiles/gui/popupmenu.h index bccb3483c9..887f15bd6c 100644 --- a/Telegram/SourceFiles/gui/popupmenu.h +++ b/Telegram/SourceFiles/gui/popupmenu.h @@ -102,6 +102,6 @@ private: anim::fvalue a_opacity; Animation _a_hide; - bool _deleteOnHide; + bool _deleteOnHide, _triggering, _deleteLater; }; From 6feef57b84d5876f2acc58c87d077f23697a7974 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 3 Nov 2015 11:50:40 -0500 Subject: [PATCH 6/7] fixed photo label for groups and channels --- Telegram/SourceFiles/mediaview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index dfcd6f29ae..3564a5907f 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1946,10 +1946,10 @@ void MediaView::updateHeader() { _headerText = _doc->name.isEmpty() ? lang(lng_mediaview_doc_image) : _doc->name; } else if (_user) { _headerText = lang(lng_mediaview_profile_photo); - } else if (_channel) { - _headerText = lang(lng_mediaview_group_photo); - } else if (_peer) { + } else if (_channel || (_peer && _peer->isChannel())) { _headerText = lang(lng_mediaview_channel_photo); + } else if (_peer) { + _headerText = lang(lng_mediaview_group_photo); } else { _headerText = lang(lng_mediaview_single_photo); } From 16afb72166f32077e314e0fd0675f86088b922c9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 3 Nov 2015 12:15:49 -0500 Subject: [PATCH 7/7] fixed emoji replaces in the beginning of the input fields --- Telegram/SourceFiles/gui/flatinput.cpp | 20 ++++++++++---------- Telegram/SourceFiles/gui/flattextarea.cpp | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/gui/flatinput.cpp b/Telegram/SourceFiles/gui/flatinput.cpp index 887ea25994..8d5e5731c4 100644 --- a/Telegram/SourceFiles/gui/flatinput.cpp +++ b/Telegram/SourceFiles/gui/flatinput.cpp @@ -917,7 +917,7 @@ QVariant InputArea::InputAreaInner::loadResource(int type, const QUrl &name) { } void InputArea::processDocumentContentsChange(int position, int charsAdded) { - int32 emojiPosition = 0, emojiLen = 0; + int32 emojiPosition = -1, emojiLen = 0; const EmojiData *emoji = 0; static QString regular = qsl("Open Sans"), semibold = qsl("Open Sans Semibold"); @@ -982,11 +982,11 @@ void InputArea::processDocumentContentsChange(int position, int charsAdded) { ++fp; } } - if (emojiPosition) break; + if (emojiPosition >= 0) break; } - if (emojiPosition) break; + if (emojiPosition >= 0) break; } - if (emojiPosition) { + if (emojiPosition >= 0) { if (emoji) { if (!_inner.document()->pageSize().isNull()) { _inner.document()->setPageSize(QSizeF(0, 0)); @@ -999,7 +999,7 @@ void InputArea::processDocumentContentsChange(int position, int charsAdded) { position = emojiPosition + 1; emoji = 0; - emojiPosition = 0; + emojiPosition = -1; } else { break; } @@ -1611,7 +1611,7 @@ QVariant InputField::InputFieldInner::loadResource(int type, const QUrl &name) { } void InputField::processDocumentContentsChange(int position, int charsAdded) { - int32 emojiPosition = 0, emojiLen = 0; + int32 emojiPosition = -1, emojiLen = 0; const EmojiData *emoji = 0; static QString regular = qsl("Open Sans"), semibold = qsl("Open Sans Semibold"), space(' '); @@ -1689,9 +1689,9 @@ void InputField::processDocumentContentsChange(int position, int charsAdded) { ++fp; } } - if (emojiPosition) break; + if (emojiPosition >= 0) break; } - if (emojiPosition) break; + if (emojiPosition >= 0) break; if (b.next() != doc->end()) { emojiPosition = b.next().position() - 1; @@ -1702,7 +1702,7 @@ void InputField::processDocumentContentsChange(int position, int charsAdded) { break; } } - if (emojiPosition) { + if (emojiPosition >= 0) { if (emoji) { if (!_inner.document()->pageSize().isNull()) { _inner.document()->setPageSize(QSizeF(0, 0)); @@ -1715,7 +1715,7 @@ void InputField::processDocumentContentsChange(int position, int charsAdded) { position = emojiPosition + 1; emoji = 0; - emojiPosition = 0; + emojiPosition = -1; } else { break; } diff --git a/Telegram/SourceFiles/gui/flattextarea.cpp b/Telegram/SourceFiles/gui/flattextarea.cpp index d49a219481..8cb8103b6d 100644 --- a/Telegram/SourceFiles/gui/flattextarea.cpp +++ b/Telegram/SourceFiles/gui/flattextarea.cpp @@ -619,7 +619,7 @@ void FlatTextarea::checkContentHeight() { } void FlatTextarea::processDocumentContentsChange(int position, int charsAdded) { - int32 emojiPosition = 0, emojiLen = 0; + int32 emojiPosition = -1, emojiLen = 0; const EmojiData *emoji = 0; static QString regular = qsl("Open Sans"), semibold = qsl("Open Sans Semibold"); @@ -681,11 +681,11 @@ void FlatTextarea::processDocumentContentsChange(int position, int charsAdded) { ++fp; } } - if (emojiPosition) break; + if (emojiPosition >= 0) break; } - if (emojiPosition) break; + if (emojiPosition >= 0) break; } - if (emojiPosition) { + if (emojiPosition >= 0) { if (emoji) { if (!document()->pageSize().isNull()) { document()->setPageSize(QSizeF(0, 0)); @@ -698,7 +698,7 @@ void FlatTextarea::processDocumentContentsChange(int position, int charsAdded) { position = emojiPosition + 1; emoji = 0; - emojiPosition = 0; + emojiPosition = -1; } else { break; }