Skip to content

Commit

Permalink
some template send improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 17, 2014
1 parent 21a7e02 commit b35b3bc
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 35 deletions.
10 changes: 5 additions & 5 deletions Telegram/SourceFiles/boxes/photosendbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ a_opacity(0, 1) {

void PhotoSendBox::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
onSend();
onSend((e->modifiers().testFlag(Qt::ControlModifier) || e->modifiers().testFlag(Qt::MetaModifier)) && e->modifiers().testFlag(Qt::ShiftModifier));
} else if (e->key() == Qt::Key_Escape) {
onCancel();
}
Expand Down Expand Up @@ -200,18 +200,18 @@ void PhotoSendBox::animStep(float64 ms) {
update();
}

void PhotoSendBox::onSend() {
void PhotoSendBox::onSend(bool ctrlShiftEnter) {
if (!_img) {
if (App::main()) App::main()->confirmShareContact(_phone, _fname, _lname);
if (App::main()) App::main()->confirmShareContact(ctrlShiftEnter, _phone, _fname, _lname);
} else {
if (!_compressed.isHidden()) {
cSetCompressPastedImage(_compressed.checked());
App::writeUserConfig();
}
if (_compressed.isHidden() || _compressed.checked()) {
if (App::main()) App::main()->confirmSendImage(*_img);
if (App::main()) App::main()->confirmSendImage(ctrlShiftEnter, *_img);
} else {
if (App::main()) App::main()->confirmSendImageUncompressed();
if (App::main()) App::main()->confirmSendImageUncompressed(ctrlShiftEnter);
}
}
emit closed();
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/boxes/photosendbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PhotoSendBox : public LayeredWidget {

public slots:

void onSend();
void onSend(bool ctrlShiftEnter = false);
void onCancel();

private:
Expand Down
42 changes: 26 additions & 16 deletions Telegram/SourceFiles/historywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,25 +2282,28 @@ void HistoryWidget::onShareContact(const PeerId &peer, UserData *contact) {
App::main()->showPeer(peer, 0, false, true);
if (!hist) return;

shareContact(contact->phone, contact->firstName, contact->lastName, int32(contact->id & 0xFFFFFFFF));
shareContact(peer, contact->phone, contact->firstName, contact->lastName, int32(contact->id & 0xFFFFFFFF));
}

void HistoryWidget::shareContact(const QString &phone, const QString &fname, const QString &lname, int32 userId) {
App::main()->readServerHistory(hist, false);
void HistoryWidget::shareContact(const PeerId &peer, const QString &phone, const QString &fname, const QString &lname, int32 userId) {
History *h = App::history(peer);
App::main()->readServerHistory(h, false);

uint64 randomId = MTP::nonce<uint64>();
MsgId newId = clientMsgId();

hist->loadAround(0);
h->loadAround(0);

hist->addToBack(MTP_message(MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(histPeer->id), MTP_bool(true), MTP_bool(true), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname), MTP_int(userId))));
h->addToBack(MTP_message(MTP_int(newId), MTP_int(MTP::authedId()), App::peerToMTP(peer), MTP_bool(true), MTP_bool(true), MTP_int(unixtime()), MTP_string(""), MTP_messageMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname), MTP_int(userId))));

MTP::send(MTPmessages_SendMedia(histPeer->input, MTP_inputMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname)), MTP_long(randomId)), App::main()->rpcDone(&MainWidget::sentFullDataReceived, randomId));
MTP::send(MTPmessages_SendMedia(App::peer(peer)->input, MTP_inputMediaContact(MTP_string(phone), MTP_string(fname), MTP_string(lname)), MTP_long(randomId)), App::main()->rpcDone(&MainWidget::sentFullDataReceived, randomId));

App::historyRegRandom(randomId, newId);
App::main()->historyToDown(hist);
if (hist && histPeer && peer == histPeer->id) {
App::main()->historyToDown(hist);
}
App::main()->dialogsToUp();
peerMessagesUpdated();
peerMessagesUpdated(peer);
}

void HistoryWidget::onSendPaths(const PeerId &peer) {
Expand Down Expand Up @@ -2735,11 +2738,15 @@ void HistoryWidget::shareContactConfirmation(const QString &phone, const QString
App::wnd()->showLayer(new PhotoSendBox(phone, fname, lname));
}

void HistoryWidget::uploadConfirmImageUncompressed() {
void HistoryWidget::uploadConfirmImageUncompressed(bool ctrlShiftEnter) {
if (!hist || !confirmImageId || confirmImage.isNull()) return;

App::wnd()->activateWindow();
imageLoader.append(confirmImage, histPeer->id, ToPrepareDocument);
PeerId peerId = histPeer->id;
if (confirmWithText) {
onSend(ctrlShiftEnter);
}
imageLoader.append(confirmImage, peerId, ToPrepareDocument);
confirmImageId = 0;
confirmWithText = false;
confirmImage = QImage();
Expand Down Expand Up @@ -2767,7 +2774,7 @@ void HistoryWidget::onPhotoReady() {
if (i->id == confirmImageId) {
App::wnd()->showLayer(new PhotoSendBox(*i));
} else {
confirmSendImage(*i);
confirmSendImage(false, *i);
}
}
list.clear();
Expand All @@ -2776,22 +2783,25 @@ void HistoryWidget::onPhotoReady() {
void HistoryWidget::onPhotoFailed(quint64 id) {
}

void HistoryWidget::confirmShareContact(const QString &phone, const QString &fname, const QString &lname) {
void HistoryWidget::confirmShareContact(bool ctrlShiftEnter, const QString &phone, const QString &fname, const QString &lname) {
if (!histPeer) return;

PeerId peerId = histPeer->id;
if (0xFFFFFFFFFFFFFFFFL == confirmImageId) {
if (confirmWithText) {
onSend();
onSend(ctrlShiftEnter);
}
confirmImageId = 0;
confirmWithText = false;
confirmImage = QImage();
}
shareContact(phone, fname, lname);
shareContact(peerId, phone, fname, lname);
}

void HistoryWidget::confirmSendImage(const ReadyLocalMedia &img) {
void HistoryWidget::confirmSendImage(bool ctrlShiftEnter, const ReadyLocalMedia &img) {
if (img.id == confirmImageId) {
if (confirmWithText) {
onSend();
onSend(ctrlShiftEnter);
}
confirmImageId = 0;
confirmWithText = false;
Expand Down
8 changes: 4 additions & 4 deletions Telegram/SourceFiles/historywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ class HistoryWidget : public QWidget, public RPCSender, public Animated {
void uploadImage(const QImage &img, bool withText = false);
void uploadFile(const QString &file, bool withText = false); // with confirmation
void shareContactConfirmation(const QString &phone, const QString &fname, const QString &lname, bool withText = false);
void uploadConfirmImageUncompressed();
void uploadConfirmImageUncompressed(bool ctrlShiftEnter);
void uploadMedias(const QStringList &files, ToPrepareMediaType type);
void uploadMedia(const QByteArray &fileContent, ToPrepareMediaType type);
void confirmShareContact(const QString &phone, const QString &fname, const QString &lname);
void confirmSendImage(const ReadyLocalMedia &img);
void confirmShareContact(bool ctrlShiftEnter, const QString &phone, const QString &fname, const QString &lname);
void confirmSendImage(bool ctrlShiftEnter, const ReadyLocalMedia &img);
void cancelSendImage();

void checkUnreadLoaded(bool checkOnlyShow = false);
Expand All @@ -304,7 +304,7 @@ class HistoryWidget : public QWidget, public RPCSender, public Animated {
void onShareContact(const PeerId &peer, UserData *contact);
void onSendPaths(const PeerId &peer);

void shareContact(const QString &phone, const QString &fname, const QString &lname, int32 userId = 0);
void shareContact(const PeerId &peer, const QString &phone, const QString &fname, const QString &lname, int32 userId = 0);

PeerData *peer() const;
PeerData *activePeer() const;
Expand Down
12 changes: 6 additions & 6 deletions Telegram/SourceFiles/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,16 +981,16 @@ void MainWidget::updateOnlineDisplay() {
if (App::wnd()->settingsWidget()) App::wnd()->settingsWidget()->updateOnlineDisplay();
}

void MainWidget::confirmShareContact(const QString &phone, const QString &fname, const QString &lname) {
history.confirmShareContact(phone, fname, lname);
void MainWidget::confirmShareContact(bool ctrlShiftEnter, const QString &phone, const QString &fname, const QString &lname) {
history.confirmShareContact(ctrlShiftEnter, phone, fname, lname);
}

void MainWidget::confirmSendImage(const ReadyLocalMedia &img) {
history.confirmSendImage(img);
void MainWidget::confirmSendImage(bool ctrlShiftEnter, const ReadyLocalMedia &img) {
history.confirmSendImage(ctrlShiftEnter, img);
}

void MainWidget::confirmSendImageUncompressed() {
history.uploadConfirmImageUncompressed();
void MainWidget::confirmSendImageUncompressed(bool ctrlShiftEnter) {
history.uploadConfirmImageUncompressed(ctrlShiftEnter);
}

void MainWidget::cancelSendImage() {
Expand Down
6 changes: 3 additions & 3 deletions Telegram/SourceFiles/mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ class MainWidget : public QWidget, public Animated, public RPCSender {
void showBackFromStack();
QRect historyRect() const;

void confirmShareContact(const QString &phone, const QString &fname, const QString &lname);
void confirmSendImage(const ReadyLocalMedia &img);
void confirmSendImageUncompressed();
void confirmShareContact(bool ctrlShiftEnter, const QString &phone, const QString &fname, const QString &lname);
void confirmSendImage(bool ctrlShiftEnter, const ReadyLocalMedia &img);
void confirmSendImageUncompressed(bool ctrlShiftEnter);
void cancelSendImage();

void destroyData();
Expand Down

0 comments on commit b35b3bc

Please sign in to comment.