2016-11-11 19:51:59 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-11-11 19:51:59 +00:00
|
|
|
*/
|
|
|
|
#include "window/window_main_menu.h"
|
|
|
|
|
|
|
|
#include "styles/style_window.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "profile/profile_userpic_button.h"
|
2017-04-05 09:21:38 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
#include "ui/widgets/menu.h"
|
|
|
|
#include "mainwindow.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/contacts_box.h"
|
|
|
|
#include "boxes/about_box.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
#include "lang.h"
|
|
|
|
#include "core/click_handler_types.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "auth_session.h"
|
2017-04-11 20:03:34 +00:00
|
|
|
#include "mainwidget.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
|
|
|
|
MainMenu::MainMenu(QWidget *parent) : TWidget(parent)
|
2016-11-16 10:44:06 +00:00
|
|
|
, _menu(this, st::mainMenu)
|
2016-12-23 13:21:01 +00:00
|
|
|
, _telegram(this, st::mainMenuTelegramLabel)
|
|
|
|
, _version(this, st::mainMenuVersionLabel) {
|
2016-11-11 19:51:59 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
2016-11-16 10:44:06 +00:00
|
|
|
|
|
|
|
subscribe(Global::RefSelfChanged(), [this] {
|
|
|
|
checkSelf();
|
|
|
|
});
|
|
|
|
checkSelf();
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
resize(st::mainMenuWidth, parentWidget()->height());
|
|
|
|
_menu->setTriggeredCallback([](QAction *action, int actionTop, Ui::Menu::TriggeredSource source) {
|
|
|
|
emit action->triggered();
|
|
|
|
});
|
|
|
|
_menu->addAction(lang(lng_create_group_title), [] {
|
|
|
|
App::wnd()->onShowNewGroup();
|
2016-11-16 10:44:06 +00:00
|
|
|
}, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver);
|
2016-11-11 19:51:59 +00:00
|
|
|
_menu->addAction(lang(lng_create_channel_title), [] {
|
|
|
|
App::wnd()->onShowNewChannel();
|
2016-11-16 10:44:06 +00:00
|
|
|
}, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver);
|
2016-11-11 19:51:59 +00:00
|
|
|
_menu->addAction(lang(lng_menu_contacts), [] {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<ContactsBox>());
|
2016-11-16 10:44:06 +00:00
|
|
|
}, &st::mainMenuContacts, &st::mainMenuContactsOver);
|
2016-11-11 19:51:59 +00:00
|
|
|
_menu->addAction(lang(lng_menu_settings), [] {
|
|
|
|
App::wnd()->showSettings();
|
2016-11-16 10:44:06 +00:00
|
|
|
}, &st::mainMenuSettings, &st::mainMenuSettingsOver);
|
2016-11-11 19:51:59 +00:00
|
|
|
_menu->addAction(lang(lng_settings_faq), [] {
|
|
|
|
QDesktopServices::openUrl(telegramFaqLink());
|
2016-11-16 10:44:06 +00:00
|
|
|
}, &st::mainMenuHelp, &st::mainMenuHelpOver);
|
2016-11-11 19:51:59 +00:00
|
|
|
|
|
|
|
_telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop")));
|
2016-11-16 10:44:06 +00:00
|
|
|
_telegram->setLink(1, MakeShared<UrlClickHandler>(qsl("https://desktop.telegram.org")));
|
|
|
|
_version->setRichText(textcmdLink(1, lng_settings_current_version(lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, lang(lng_menu_about)));
|
2017-01-11 18:31:31 +00:00
|
|
|
_version->setLink(1, MakeShared<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog")));
|
2016-12-13 17:07:56 +00:00
|
|
|
_version->setLink(2, MakeShared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
|
2016-11-16 10:44:06 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); });
|
2016-12-03 12:10:35 +00:00
|
|
|
subscribe(Global::RefConnectionTypeChanged(), [this] { updateConnectionState(); });
|
|
|
|
updateConnectionState();
|
2016-11-16 10:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::checkSelf() {
|
|
|
|
if (auto self = App::self()) {
|
2017-04-05 09:21:38 +00:00
|
|
|
auto showSelfChat = [] {
|
2016-12-31 13:34:41 +00:00
|
|
|
if (auto self = App::self()) {
|
2017-04-11 20:03:34 +00:00
|
|
|
App::main()->choosePeer(self->id, ShowAtUnreadMsgId);
|
2016-12-31 13:34:41 +00:00
|
|
|
}
|
2017-04-05 09:21:38 +00:00
|
|
|
};
|
|
|
|
_userpicButton.create(this, self, st::mainMenuUserpicSize);
|
|
|
|
_userpicButton->setClickedCallback(showSelfChat);
|
2016-11-16 16:04:25 +00:00
|
|
|
_userpicButton->show();
|
2017-04-05 09:21:38 +00:00
|
|
|
_cloudButton.create(this, st::mainMenuCloudButton);
|
|
|
|
_cloudButton->setClickedCallback(showSelfChat);
|
|
|
|
_cloudButton->show();
|
|
|
|
update();
|
2016-11-16 10:44:06 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
if (_showFinished) {
|
|
|
|
_userpicButton->showFinished();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_userpicButton.destroy();
|
2017-04-05 09:21:38 +00:00
|
|
|
_cloudButton.destroy();
|
2016-11-16 10:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::showFinished() {
|
|
|
|
_showFinished = true;
|
|
|
|
if (_userpicButton) {
|
|
|
|
_userpicButton->showFinished();
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::resizeEvent(QResizeEvent *e) {
|
2016-11-16 10:44:06 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::updateControlsGeometry() {
|
|
|
|
if (_userpicButton) {
|
|
|
|
_userpicButton->moveToLeft(st::mainMenuUserpicLeft, st::mainMenuUserpicTop);
|
|
|
|
}
|
2017-04-05 09:21:38 +00:00
|
|
|
if (_cloudButton) {
|
|
|
|
_cloudButton->moveToRight(0, st::mainMenuCoverHeight - _cloudButton->height());
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
_menu->setGeometry(0, st::mainMenuCoverHeight + st::mainMenuSkip, width(), _menu->height());
|
|
|
|
_telegram->moveToLeft(st::mainMenuFooterLeft, height() - st::mainMenuTelegramBottom - _telegram->height());
|
|
|
|
_version->moveToLeft(st::mainMenuFooterLeft, height() - st::mainMenuVersionBottom - _version->height());
|
|
|
|
}
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
void MainMenu::updateConnectionState() {
|
|
|
|
auto state = MTP::dcstate();
|
|
|
|
if (state == MTP::ConnectingState || state == MTP::DisconnectedState || state < 0) {
|
|
|
|
_connectionText = lang(lng_status_connecting);
|
|
|
|
} else {
|
|
|
|
_connectionText = lang(lng_status_online);
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
void MainMenu::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2016-11-17 11:03:49 +00:00
|
|
|
auto clip = e->rect();
|
|
|
|
auto cover = QRect(0, 0, width(), st::mainMenuCoverHeight).intersected(clip);
|
2016-11-11 19:51:59 +00:00
|
|
|
if (!cover.isEmpty()) {
|
|
|
|
p.fillRect(cover, st::mainMenuCoverBg);
|
|
|
|
p.setPen(st::mainMenuCoverFg);
|
|
|
|
p.setFont(st::semiboldFont);
|
|
|
|
if (auto self = App::self()) {
|
|
|
|
self->nameText.drawLeftElided(p, st::mainMenuCoverTextLeft, st::mainMenuCoverNameTop, width() - 2 * st::mainMenuCoverTextLeft, width());
|
|
|
|
p.setFont(st::normalFont);
|
2016-12-03 12:10:35 +00:00
|
|
|
p.drawTextLeft(st::mainMenuCoverTextLeft, st::mainMenuCoverStatusTop, width(), _connectionText);
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
2017-04-05 09:21:38 +00:00
|
|
|
if (_cloudButton) {
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::mainMenuCloudBg);
|
|
|
|
auto cloudBg = QRect(_cloudButton->x() + (_cloudButton->width() - st::mainMenuCloudSize) / 2,
|
|
|
|
_cloudButton->y() + (_cloudButton->height() - st::mainMenuCloudSize) / 2,
|
|
|
|
st::mainMenuCloudSize, st::mainMenuCloudSize);
|
|
|
|
p.drawEllipse(cloudBg);
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
2016-11-17 11:03:49 +00:00
|
|
|
auto other = QRect(0, st::mainMenuCoverHeight, width(), height() - st::mainMenuCoverHeight).intersected(clip);
|
2016-11-11 19:51:59 +00:00
|
|
|
if (!other.isEmpty()) {
|
|
|
|
p.fillRect(other, st::mainMenuBg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Window
|