Version 0.10.14 alpha: using $XDG_DATA_HOME in Linux.

If there is no app data in ~/.TelegramDesktop (like in
fresh installs) we use $XDG_DATA_HOME/TelegramDesktop.
This commit is contained in:
John Preston 2016-10-18 13:32:33 +03:00
parent fc7c5d0ab3
commit ba4dcc42dc
13 changed files with 382 additions and 364 deletions

View File

@ -1291,7 +1291,7 @@ textRectMargins: margins(-2px, -1px, -2px, -1px);
taMsgField: flatTextarea(taDefFlat) {
font: msgFont;
}
maxFieldHeight: 220px;
maxFieldHeight: 224px;
// historyMinHeight: 56px;
reportSpamHide: flatButton(btnDefFlat) {

View File

@ -34,8 +34,8 @@ IDI_ICON1 ICON "..\\art\\icon256.ico"
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,10,13,0
PRODUCTVERSION 0,10,13,0
FILEVERSION 0,10,14,0
PRODUCTVERSION 0,10,14,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -51,10 +51,10 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Telegram Messenger LLP"
VALUE "FileVersion", "0.10.13.0"
VALUE "FileVersion", "0.10.14.0"
VALUE "LegalCopyright", "Copyright (C) 2014-2016"
VALUE "ProductName", "Telegram Desktop"
VALUE "ProductVersion", "0.10.13.0"
VALUE "ProductVersion", "0.10.14.0"
END
END
BLOCK "VarFileInfo"

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,10,13,0
PRODUCTVERSION 0,10,13,0
FILEVERSION 0,10,14,0
PRODUCTVERSION 0,10,14,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -43,10 +43,10 @@ BEGIN
BEGIN
VALUE "CompanyName", "Telegram Messenger LLP"
VALUE "FileDescription", "Telegram Updater"
VALUE "FileVersion", "0.10.13.0"
VALUE "FileVersion", "0.10.14.0"
VALUE "LegalCopyright", "Copyright (C) 2014-2016"
VALUE "ProductName", "Telegram Desktop"
VALUE "ProductVersion", "0.10.13.0"
VALUE "ProductVersion", "0.10.14.0"
END
END
BLOCK "VarFileInfo"

View File

@ -1086,8 +1086,8 @@ void AppClass::checkMapVersion() {
if (Local::oldMapVersion() < AppVersion) {
if (Local::oldMapVersion()) {
QString versionFeatures;
if ((cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 10012) {
versionFeatures = QString::fromUtf8("Windows and Linux:\n\xe2\x80\x94 Quick reply from notifications\n\xe2\x80\x94 Hide all notifications button added\n\xe2\x80\x94 Change notifications location and maximum count\n\nLinux:\n\xe2\x80\x94 You can enable native notifications in Settings");
if ((cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 10014) {
versionFeatures = QString::fromUtf8("\xe2\x80\x94 New audio player design\n\xe2\x80\x94 Moved to Qt library version 5.6.2\n\nWindows 10:\n\xe2\x80\x94 Respecting quite hours for the notifications");
} else if (!(cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 10005) {
versionFeatures = langNewVersionText();
} else {

View File

@ -24,7 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#define BETA_VERSION_MACRO (0ULL)
constexpr int AppVersion = 10013;
constexpr str_const AppVersionStr = "0.10.13";
constexpr int AppVersion = 10014;
constexpr str_const AppVersionStr = "0.10.14";
constexpr bool AppAlphaVersion = true;
constexpr uint64 AppBetaVersion = BETA_VERSION_MACRO;

View File

@ -3275,8 +3275,7 @@ void HistoryWidget::onTextChange() {
}
if (updateCmdStartShown()) {
updateControlsVisibility();
resizeEvent(0);
update();
updateControlsGeometry();
}
_saveCloudDraftTimer.stop();
@ -3597,7 +3596,7 @@ void HistoryWidget::notify_userIsBotChanged(UserData *user) {
_list->notifyIsBotChanged();
_list->updateBotInfo();
updateControlsVisibility();
resizeEvent(0);
updateControlsGeometry();
}
}
@ -4117,8 +4116,7 @@ void HistoryWidget::applyCloudDraft(History *history) {
applyDraft();
updateControlsVisibility();
resizeEvent(nullptr);
update();
updateControlsGeometry();
}
}
@ -5313,7 +5311,7 @@ void HistoryWidget::onBotStart() {
}
}
updateControlsVisibility();
resizeEvent(0);
updateControlsGeometry();
}
void HistoryWidget::onJoinChannel() {
@ -6918,7 +6916,7 @@ void HistoryWidget::peerMessagesUpdated(PeerId peer) {
if (!upd && !unblock && !botStart && !joinChannel) upd = (_muteUnmute.isHidden() == muteUnmute);
if (upd) {
updateControlsVisibility();
resizeEvent(0);
updateControlsGeometry();
}
}
}
@ -7006,6 +7004,10 @@ void HistoryWidget::notify_handlePendingHistoryUpdate() {
}
void HistoryWidget::resizeEvent(QResizeEvent *e) {
updateControlsGeometry();
}
void HistoryWidget::updateControlsGeometry() {
_reportSpamPanel.resize(width(), _reportSpamPanel.height());
moveFieldControls();
@ -8041,8 +8043,7 @@ void HistoryWidget::cancelEdit() {
void HistoryWidget::cancelForwarding() {
updateControlsVisibility();
resizeEvent(0);
update();
updateControlsGeometry();
}
void HistoryWidget::onFieldBarCancel() {
@ -8243,11 +8244,10 @@ void HistoryWidget::onFullPeerUpdated(PeerData *data) {
}
if (updateCmdStartShown()) {
updateControlsVisibility();
resizeEvent(0);
update();
updateControlsGeometry();
} else if (!_scroll.isHidden() && _unblock.isHidden() == isBlocked()) {
updateControlsVisibility();
resizeEvent(0);
updateControlsGeometry();
}
}
@ -8293,8 +8293,7 @@ void HistoryWidget::peerUpdated(PeerData *data) {
}
updateControlsVisibility();
if (resize) {
resizeEvent(0);
update();
updateControlsGeometry();
}
}
App::main()->updateOnlineDisplay();
@ -8479,8 +8478,7 @@ void HistoryWidget::updateForwarding(bool force) {
if (readyToForward()) {
updateControlsVisibility();
} else {
resizeEvent(0);
update();
updateControlsGeometry();
}
}

View File

@ -55,17 +55,6 @@ public:
void messagesReceived(PeerData *peer, const QVector<MTPMessage> &messages);
void messagesReceivedDown(PeerData *peer, const QVector<MTPMessage> &messages);
bool event(QEvent *e) override; // calls touchEvent when necessary
void touchEvent(QTouchEvent *e);
void paintEvent(QPaintEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
void enterEvent(QEvent *e) override;
void leaveEvent(QEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void showContextMenu(QContextMenuEvent *e, bool showFromTouch = false);
TextWithEntities getSelectedText() const;
@ -122,6 +111,18 @@ public:
protected:
bool focusNextPrevChild(bool next) override;
bool event(QEvent *e) override; // calls touchEvent when necessary
void touchEvent(QTouchEvent *e);
void paintEvent(QPaintEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
void enterEvent(QEvent *e) override;
void leaveEvent(QEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
public slots:
void onUpdateSelected();
void onParentGeometryChanged();
@ -331,22 +332,20 @@ class ReportSpamPanel : public TWidget {
Q_OBJECT
public:
ReportSpamPanel(HistoryWidget *parent);
void resizeEvent(QResizeEvent *e);
void paintEvent(QPaintEvent *e);
void setReported(bool reported, PeerData *onPeer);
signals:
void hideClicked();
void reportClicked();
void clearClicked();
private:
protected:
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;
private:
FlatButton _report, _hide;
LinkButton _clear;
@ -358,13 +357,6 @@ class BotKeyboard : public TWidget, public AbstractTooltipShower, public ClickHa
public:
BotKeyboard();
void paintEvent(QPaintEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void enterEvent(QEvent *e) override;
void leaveEvent(QEvent *e) override;
bool moderateKeyActivate(int index);
// With force=true the markup is updated even if it is
@ -397,6 +389,13 @@ public:
protected:
int resizeGetHeight(int newWidth) override;
void paintEvent(QPaintEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void enterEvent(QEvent *e) override;
void leaveEvent(QEvent *e) override;
private:
void updateSelected();
@ -537,18 +536,10 @@ public:
void windowShown();
bool doWeReadServerHistory() const;
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void dragEnterEvent(QDragEnterEvent *e) override;
void dragLeaveEvent(QDragLeaveEvent *e) override;
void leaveEvent(QEvent *e) override;
void dropEvent(QDropEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void leaveToChildEvent(QEvent *e, QWidget *child) override;
void contextMenuEvent(QContextMenuEvent *e) override;
void dragEnterEvent(QDragEnterEvent *e) override;
void dragLeaveEvent(QDragLeaveEvent *e) override;
void dropEvent(QDropEvent *e) override;
void updateTopBarSelection();
@ -596,6 +587,7 @@ public:
void cancelShareContact();
void updateControlsVisibility();
void updateControlsGeometry();
void updateOnlineDisplay();
void updateOnlineDisplayTimer();
@ -694,7 +686,7 @@ public:
void grabStart() override {
_inGrab = true;
resizeEvent(0);
updateControlsGeometry();
}
void grapWithoutTopBarShadow();
void grabFinish() override;
@ -727,6 +719,16 @@ public:
~HistoryWidget();
protected:
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void leaveEvent(QEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
signals:
void cancelled();
void historyShown(History *history, MsgId atMsgId);

View File

@ -28,6 +28,7 @@ int main(int argc, char *argv[]) {
#ifndef Q_OS_MAC // Retina display support is working fine, others are not.
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
#endif // Q_OS_MAC
QCoreApplication::setApplicationName(qsl("TelegramDesktop"));
settingsParseArgs(argc, argv);
if (cLaunchMode() == LaunchModeFixPrevious) {

View File

@ -2724,7 +2724,7 @@ void MainWidget::showAll() {
_wideSection->show();
} else if (_history->peer()) {
_history->show();
_history->resizeEvent(0);
_history->updateControlsGeometry();
} else {
_dialogs->show();
_history->hide();
@ -2754,7 +2754,7 @@ void MainWidget::showAll() {
_wideSection->show();
} else {
_history->show();
_history->resizeEvent(0);
_history->updateControlsGeometry();
}
if (_wideSection) {
_topBar->hide();
@ -3551,7 +3551,7 @@ void MainWidget::openPeerByName(const QString &username, MsgId msgId, const QStr
peer->asUser()->botInfo->startToken = startToken;
if (peer == _history->peer()) {
_history->updateControlsVisibility();
_history->resizeEvent(0);
_history->updateControlsGeometry();
}
}
Ui::showPeerHistoryAsync(peer->id, msgId, Ui::ShowWay::Forward);
@ -3636,7 +3636,7 @@ void MainWidget::usernameResolveDone(QPair<MsgId, QString> msgIdAndStartToken, c
peer->asUser()->botInfo->startToken = startToken;
if (peer == _history->peer()) {
_history->updateControlsVisibility();
_history->resizeEvent(0);
_history->updateControlsGeometry();
}
}
Ui::showPeerHistory(peer->id, msgId, Ui::ShowWay::Forward);

View File

@ -37,68 +37,65 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
using namespace Platform;
namespace {
QByteArray escapeShell(const QByteArray &str) {
QByteArray result;
const char *b = str.constData(), *e = str.constEnd();
for (const char *ch = b; ch != e; ++ch) {
if (*ch == ' ' || *ch == '"' || *ch == '\'' || *ch == '\\') {
if (result.isEmpty()) {
result.reserve(str.size() * 2);
}
if (ch > b) {
result.append(b, ch - b);
}
result.append('\\');
b = ch;
}
}
if (result.isEmpty()) return str;
if (e > b) {
result.append(b, e - b);
}
return result;
}
class _PsEventFilter : public QAbstractNativeEventFilter {
public:
_PsEventFilter() {
QByteArray escapeShell(const QByteArray &str) {
QByteArray result;
const char *b = str.constData(), *e = str.constEnd();
for (const char *ch = b; ch != e; ++ch) {
if (*ch == ' ' || *ch == '"' || *ch == '\'' || *ch == '\\') {
if (result.isEmpty()) {
result.reserve(str.size() * 2);
}
if (ch > b) {
result.append(b, ch - b);
}
result.append('\\');
b = ch;
}
}
if (result.isEmpty()) return str;
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
auto wnd = App::wnd();
if (!wnd) return false;
return false;
}
};
_PsEventFilter *_psEventFilter = 0;
};
namespace {
QRect _monitorRect;
uint64 _monitorLastGot = 0;
if (e > b) {
result.append(b, e - b);
}
return result;
}
class _PsEventFilter : public QAbstractNativeEventFilter {
public:
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
//auto wnd = App::wnd();
//if (!wnd) return false;
return false;
}
};
_PsEventFilter *_psEventFilter = nullptr;
QRect _monitorRect;
uint64 _monitorLastGot = 0;
} // namespace
QRect psDesktopRect() {
uint64 tnow = getms();
if (tnow > _monitorLastGot + 1000 || tnow < _monitorLastGot) {
_monitorLastGot = tnow;
_monitorRect = QApplication::desktop()->availableGeometry(App::wnd());
}
return _monitorRect;
uint64 tnow = getms();
if (tnow > _monitorLastGot + 1000 || tnow < _monitorLastGot) {
_monitorLastGot = tnow;
_monitorRect = QApplication::desktop()->availableGeometry(App::wnd());
}
return _monitorRect;
}
void psShowOverAll(QWidget *w, bool canFocus) {
w->show();
w->show();
}
void psBringToBack(QWidget *w) {
w->hide();
w->hide();
}
QAbstractNativeEventFilter *psNativeEventFilter() {
delete _psEventFilter;
delete _psEventFilter;
_psEventFilter = new _PsEventFilter();
return _psEventFilter;
}
@ -107,7 +104,7 @@ void psWriteDump() {
}
QString demanglestr(const QString &mangled) {
if (mangled.isEmpty()) return mangled;
if (mangled.isEmpty()) return mangled;
QByteArray cmd = ("c++filt -n " + mangled).toUtf8();
FILE *f = popen(cmd.constData(), "r");
@ -151,12 +148,12 @@ QStringList addr2linestr(uint64 *addresses, int count) {
if (addresses[i]) {
if (j < addr2lineResult.size() && !addr2lineResult.at(j).isEmpty() && !addr2lineResult.at(j).startsWith(qstr("0x"))) {
QString res = addr2lineResult.at(j).trimmed();
if (int index = res.indexOf(qstr("/Telegram/"))) {
if (index > 0) {
res = res.mid(index + qstr("/Telegram/").size());
}
}
result.push_back(res);
if (int index = res.indexOf(qstr("/Telegram/"))) {
if (index > 0) {
res = res.mid(index + qstr("/Telegram/").size());
}
}
result.push_back(res);
} else {
result.push_back(QString());
}
@ -175,7 +172,7 @@ QString psPrepareCrashDump(const QByteArray &crashdump, QString dumpfile) {
int32 i = 0, l = lines.size();
while (i < l) {
uint64 addresses[1024] = { 0 };
uint64 addresses[1024] = { 0 };
for (; i < l; ++i) {
result.append(lines.at(i)).append('\n');
QString line = lines.at(i).trimmed();
@ -185,20 +182,20 @@ QString psPrepareCrashDump(const QByteArray &crashdump, QString dumpfile) {
}
}
int32 start = i;
int32 start = i;
for (; i < l; ++i) {
QString line = lines.at(i).trimmed();
QString line = lines.at(i).trimmed();
if (line.isEmpty()) break;
QRegularExpressionMatch m1 = QRegularExpression(qsl("^(.+)\\(([^+]+)\\+([^\\)]+)\\)\\[(.+)\\]$")).match(line);
QRegularExpressionMatch m2 = QRegularExpression(qsl("^(.+)\\[(.+)\\]$")).match(line);
QString addrstr = m1.hasMatch() ? m1.captured(4) : (m2.hasMatch() ? m2.captured(2) : QString());
if (!addrstr.isEmpty()) {
uint64 addr = addrstr.startsWith(qstr("0x")) ? addrstr.mid(2).toULongLong(0, 16) : addrstr.toULongLong();
if (addr > 1) {
addresses[i - start] = addr;
}
}
QRegularExpressionMatch m1 = QRegularExpression(qsl("^(.+)\\(([^+]+)\\+([^\\)]+)\\)\\[(.+)\\]$")).match(line);
QRegularExpressionMatch m2 = QRegularExpression(qsl("^(.+)\\[(.+)\\]$")).match(line);
QString addrstr = m1.hasMatch() ? m1.captured(4) : (m2.hasMatch() ? m2.captured(2) : QString());
if (!addrstr.isEmpty()) {
uint64 addr = addrstr.startsWith(qstr("0x")) ? addrstr.mid(2).toULongLong(0, 16) : addrstr.toULongLong();
if (addr > 1) {
addresses[i - start] = addr;
}
}
}
QStringList addr2line = addr2linestr(addresses, i - start);
@ -206,72 +203,72 @@ QString psPrepareCrashDump(const QByteArray &crashdump, QString dumpfile) {
QString line = lines.at(i).trimmed();
if (line.isEmpty()) break;
result.append(qsl("\n%1. ").arg(i - start));
if (line.startsWith(qstr("ERROR: "))) {
result.append(line).append('\n');
continue;
}
if (line == qstr("[0x1]")) {
result.append(qsl("(0x1 separator)\n"));
continue;
}
result.append(qsl("\n%1. ").arg(i - start));
if (line.startsWith(qstr("ERROR: "))) {
result.append(line).append('\n');
continue;
}
if (line == qstr("[0x1]")) {
result.append(qsl("(0x1 separator)\n"));
continue;
}
QRegularExpressionMatch m1 = QRegularExpression(qsl("^(.+)\\(([^+]*)\\+([^\\)]+)\\)(.+)$")).match(line);
QRegularExpressionMatch m2 = QRegularExpression(qsl("^(.+)\\[(.+)\\]$")).match(line);
if (!m1.hasMatch() && !m2.hasMatch()) {
result.append(qstr("BAD LINE: ")).append(line).append('\n');
continue;
}
QRegularExpressionMatch m1 = QRegularExpression(qsl("^(.+)\\(([^+]*)\\+([^\\)]+)\\)(.+)$")).match(line);
QRegularExpressionMatch m2 = QRegularExpression(qsl("^(.+)\\[(.+)\\]$")).match(line);
if (!m1.hasMatch() && !m2.hasMatch()) {
result.append(qstr("BAD LINE: ")).append(line).append('\n');
continue;
}
if (m1.hasMatch()) {
result.append(demanglestr(m1.captured(2))).append(qsl(" + ")).append(m1.captured(3)).append(qsl(" [")).append(m1.captured(1)).append(qsl("] "));
if (!addr2line.at(i - start).isEmpty() && addr2line.at(i - start) != qsl("??:0")) {
result.append(qsl(" (")).append(addr2line.at(i - start)).append(qsl(")\n"));
} else {
result.append(m1.captured(4)).append(qsl(" (demangled)")).append('\n');
}
} else {
result.append('[').append(m2.captured(1)).append(']');
if (!addr2line.at(i - start).isEmpty() && addr2line.at(i - start) != qsl("??:0")) {
result.append(qsl(" (")).append(addr2line.at(i - start)).append(qsl(")\n"));
} else {
result.append(' ').append(m2.captured(2)).append('\n');
}
}
if (m1.hasMatch()) {
result.append(demanglestr(m1.captured(2))).append(qsl(" + ")).append(m1.captured(3)).append(qsl(" [")).append(m1.captured(1)).append(qsl("] "));
if (!addr2line.at(i - start).isEmpty() && addr2line.at(i - start) != qsl("??:0")) {
result.append(qsl(" (")).append(addr2line.at(i - start)).append(qsl(")\n"));
} else {
result.append(m1.captured(4)).append(qsl(" (demangled)")).append('\n');
}
} else {
result.append('[').append(m2.captured(1)).append(']');
if (!addr2line.at(i - start).isEmpty() && addr2line.at(i - start) != qsl("??:0")) {
result.append(qsl(" (")).append(addr2line.at(i - start)).append(qsl(")\n"));
} else {
result.append(' ').append(m2.captured(2)).append('\n');
}
}
}
}
return result;
}
bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c
QByteArray pathRaw = QFile::encodeName(path);
DIR *d = opendir(pathRaw.constData());
if (!d) return false;
QByteArray pathRaw = QFile::encodeName(path);
DIR *d = opendir(pathRaw.constData());
if (!d) return false;
while (struct dirent *p = readdir(d)) {
/* Skip the names "." and ".." as we don't want to recurse on them. */
if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) continue;
while (struct dirent *p = readdir(d)) {
/* Skip the names "." and ".." as we don't want to recurse on them. */
if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) continue;
QString fname = path + '/' + p->d_name;
QByteArray fnameRaw = QFile::encodeName(fname);
struct stat statbuf;
if (!stat(fnameRaw.constData(), &statbuf)) {
if (S_ISDIR(statbuf.st_mode)) {
if (!_removeDirectory(fname)) {
closedir(d);
return false;
}
} else {
if (unlink(fnameRaw.constData())) {
closedir(d);
return false;
}
}
}
}
closedir(d);
QString fname = path + '/' + p->d_name;
QByteArray fnameRaw = QFile::encodeName(fname);
struct stat statbuf;
if (!stat(fnameRaw.constData(), &statbuf)) {
if (S_ISDIR(statbuf.st_mode)) {
if (!_removeDirectory(fname)) {
closedir(d);
return false;
}
} else {
if (unlink(fnameRaw.constData())) {
closedir(d);
return false;
}
}
}
}
closedir(d);
return !rmdir(pathRaw.constData());
return !rmdir(pathRaw.constData());
}
void psDeleteDir(const QString &dir) {
@ -279,8 +276,10 @@ void psDeleteDir(const QString &dir) {
}
namespace {
uint64 _lastUserAction = 0;
}
uint64 _lastUserAction = 0;
} // namespace
void psUserActionDone() {
_lastUserAction = getms(true);
@ -299,25 +298,37 @@ void psActivateProcess(uint64 pid) {
}
QString psCurrentCountry() {
QString country;// = objc_currentCountry();
QString country;// = objc_currentCountry();
return country.isEmpty() ? QString::fromLatin1(DefaultCountry) : country;
}
QString psCurrentLanguage() {
QString lng;// = objc_currentLang();
QString lng;// = objc_currentLang();
return lng.isEmpty() ? QString::fromLatin1(DefaultLanguage) : lng;
}
namespace {
QString _psHomeDir() {
struct passwd *pw = getpwuid(getuid());
return (pw && pw->pw_dir && strlen(pw->pw_dir)) ? (QFile::decodeName(pw->pw_dir) + '/') : QString();
}
QString getHomeDir() {
struct passwd *pw = getpwuid(getuid());
return (pw && pw->pw_dir && strlen(pw->pw_dir)) ? (QFile::decodeName(pw->pw_dir) + '/') : QString();
}
} // namespace
QString psAppDataPath() {
QString home(_psHomeDir());
return home.isEmpty() ? QString() : (home + qsl(".TelegramDesktop/"));
// Previously we used ~/.TelegramDesktop, so look there first.
// If we find data there, we should still use it.
auto home = getHomeDir();
if (!home.isEmpty()) {
auto oldPath = home + qsl(".TelegramDesktop/");
auto oldSettingsBase = oldPath + qsl("tdata/settings");
if (QFile(oldSettingsBase + '0').exists() || QFile(oldSettingsBase + '1').exists()) {
return oldPath;
}
}
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + '/';
}
QString psDownloadPath() {
@ -325,16 +336,16 @@ QString psDownloadPath() {
}
QString psCurrentExeDirectory(int argc, char *argv[]) {
QString first = argc ? QFile::decodeName(argv[0]) : QString();
if (!first.isEmpty()) {
QFileInfo info(first);
if (info.isSymLink()) {
info = info.symLinkTarget();
}
if (info.exists()) {
return QDir(info.absolutePath()).absolutePath() + '/';
}
}
QString first = argc ? QFile::decodeName(argv[0]) : QString();
if (!first.isEmpty()) {
QFileInfo info(first);
if (info.isSymLink()) {
info = info.symLinkTarget();
}
if (info.exists()) {
return QDir(info.absolutePath()).absolutePath() + '/';
}
}
return QString();
}
@ -342,10 +353,10 @@ QString psCurrentExeName(int argc, char *argv[]) {
QString first = argc ? QFile::decodeName(argv[0]) : QString();
if (!first.isEmpty()) {
QFileInfo info(first);
if (info.isSymLink()) {
info = info.symLinkTarget();
}
if (info.exists()) {
if (info.isSymLink()) {
info = info.symLinkTarget();
}
if (info.exists()) {
return info.fileName();
}
}
@ -377,12 +388,12 @@ void psPostprocessFile(const QString &name) {
}
void psOpenFile(const QString &name, bool openWith) {
QDesktopServices::openUrl(QUrl::fromLocalFile(name));
QDesktopServices::openUrl(QUrl::fromLocalFile(name));
}
void psShowInFolder(const QString &name) {
Ui::hideLayer(true);
system(("xdg-open " + escapeShell(QFile::encodeName(QFileInfo(name).absoluteDir().absolutePath()))).constData());
Ui::hideLayer(true);
system(("xdg-open " + escapeShell(QFile::encodeName(QFileInfo(name).absoluteDir().absolutePath()))).constData());
}
namespace Platform {
@ -410,108 +421,110 @@ void finish() {
} // namespace Platform
namespace {
bool _psRunCommand(const QByteArray &command) {
int result = system(command.constData());
if (result) {
DEBUG_LOG(("App Error: command failed, code: %1, command (in utf8): %2").arg(result).arg(command.constData()));
return false;
}
DEBUG_LOG(("App Info: command succeeded, command (in utf8): %1").arg(command.constData()));
return true;
}
bool _psRunCommand(const QByteArray &command) {
int result = system(command.constData());
if (result) {
DEBUG_LOG(("App Error: command failed, code: %1, command (in utf8): %2").arg(result).arg(command.constData()));
return false;
}
DEBUG_LOG(("App Info: command succeeded, command (in utf8): %1").arg(command.constData()));
return true;
}
} // namespace
void psRegisterCustomScheme() {
#ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
QString home(_psHomeDir());
if (home.isEmpty() || cBetaVersion()) return; // don't update desktop file for beta version
auto home = getHomeDir();
if (home.isEmpty() || cBetaVersion()) return; // don't update desktop file for beta version
#ifndef TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
DEBUG_LOG(("App Info: placing .desktop file"));
if (QDir(home + qsl(".local/")).exists()) {
QString apps = home + qsl(".local/share/applications/");
QString icons = home + qsl(".local/share/icons/");
if (!QDir(apps).exists()) QDir().mkpath(apps);
if (!QDir(icons).exists()) QDir().mkpath(icons);
DEBUG_LOG(("App Info: placing .desktop file"));
if (QDir(home + qsl(".local/")).exists()) {
QString apps = home + qsl(".local/share/applications/");
QString icons = home + qsl(".local/share/icons/");
if (!QDir(apps).exists()) QDir().mkpath(apps);
if (!QDir(icons).exists()) QDir().mkpath(icons);
QString path = cWorkingDir() + qsl("tdata/"), file = path + qsl("telegramdesktop.desktop");
QDir().mkpath(path);
QFile f(file);
if (f.open(QIODevice::WriteOnly)) {
QString icon = icons + qsl("telegram.png");
if (!QFile(icon).exists()) {
if (QFile(qsl(":/gui/art/icon256.png")).copy(icon)) {
DEBUG_LOG(("App Info: Icon copied to 'tdata'"));
}
QString path = cWorkingDir() + qsl("tdata/"), file = path + qsl("telegramdesktop.desktop");
QDir().mkpath(path);
QFile f(file);
if (f.open(QIODevice::WriteOnly)) {
QString icon = icons + qsl("telegram.png");
if (!QFile(icon).exists()) {
if (QFile(qsl(":/gui/art/icon256.png")).copy(icon)) {
DEBUG_LOG(("App Info: Icon copied to 'tdata'"));
}
}
}
QTextStream s(&f);
s.setCodec("UTF-8");
s << "[Desktop Entry]\n";
s << "Encoding=UTF-8\n";
s << "Version=1.0\n";
s << "Name=Telegram Desktop\n";
s << "Comment=Official desktop version of Telegram messaging app\n";
s << "Exec=" << escapeShell(QFile::encodeName(cExeDir() + cExeName())) << " -- %u\n";
s << "Icon=telegram\n";
s << "Terminal=false\n";
s << "StartupWMClass=Telegram\n";
s << "Type=Application\n";
s << "Categories=Network;\n";
s << "MimeType=x-scheme-handler/tg;\n";
f.close();
QTextStream s(&f);
s.setCodec("UTF-8");
s << "[Desktop Entry]\n";
s << "Encoding=UTF-8\n";
s << "Version=1.0\n";
s << "Name=Telegram Desktop\n";
s << "Comment=Official desktop version of Telegram messaging app\n";
s << "Exec=" << escapeShell(QFile::encodeName(cExeDir() + cExeName())) << " -- %u\n";
s << "Icon=telegram\n";
s << "Terminal=false\n";
s << "StartupWMClass=Telegram\n";
s << "Type=Application\n";
s << "Categories=Network;\n";
s << "MimeType=x-scheme-handler/tg;\n";
f.close();
if (_psRunCommand("desktop-file-install --dir=" + escapeShell(QFile::encodeName(home + qsl(".local/share/applications"))) + " --delete-original " + escapeShell(QFile::encodeName(file)))) {
DEBUG_LOG(("App Info: removing old .desktop file"));
QFile(qsl("%1.local/share/applications/telegram.desktop").arg(home)).remove();
if (_psRunCommand("desktop-file-install --dir=" + escapeShell(QFile::encodeName(home + qsl(".local/share/applications"))) + " --delete-original " + escapeShell(QFile::encodeName(file)))) {
DEBUG_LOG(("App Info: removing old .desktop file"));
QFile(qsl("%1.local/share/applications/telegram.desktop").arg(home)).remove();
_psRunCommand("update-desktop-database " + escapeShell(QFile::encodeName(home + qsl(".local/share/applications"))));
_psRunCommand("xdg-mime default telegramdesktop.desktop x-scheme-handler/tg");
}
} else {
LOG(("App Error: Could not open '%1' for write").arg(file));
}
}
_psRunCommand("update-desktop-database " + escapeShell(QFile::encodeName(home + qsl(".local/share/applications"))));
_psRunCommand("xdg-mime default telegramdesktop.desktop x-scheme-handler/tg");
}
} else {
LOG(("App Error: Could not open '%1' for write").arg(file));
}
}
#endif // !TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
DEBUG_LOG(("App Info: registerting for Gnome"));
if (_psRunCommand("gconftool-2 -t string -s /desktop/gnome/url-handlers/tg/command " + escapeShell(escapeShell(QFile::encodeName(cExeDir() + cExeName())) + " -- %s"))) {
_psRunCommand("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/needs_terminal false");
_psRunCommand("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/enabled true");
}
DEBUG_LOG(("App Info: registerting for Gnome"));
if (_psRunCommand("gconftool-2 -t string -s /desktop/gnome/url-handlers/tg/command " + escapeShell(escapeShell(QFile::encodeName(cExeDir() + cExeName())) + " -- %s"))) {
_psRunCommand("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/needs_terminal false");
_psRunCommand("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/enabled true");
}
DEBUG_LOG(("App Info: placing .protocol file"));
QString services;
if (QDir(home + qsl(".kde4/")).exists()) {
services = home + qsl(".kde4/share/kde4/services/");
} else if (QDir(home + qsl(".kde/")).exists()) {
services = home + qsl(".kde/share/kde4/services/");
}
if (!services.isEmpty()) {
if (!QDir(services).exists()) QDir().mkpath(services);
DEBUG_LOG(("App Info: placing .protocol file"));
QString services;
if (QDir(home + qsl(".kde4/")).exists()) {
services = home + qsl(".kde4/share/kde4/services/");
} else if (QDir(home + qsl(".kde/")).exists()) {
services = home + qsl(".kde/share/kde4/services/");
}
if (!services.isEmpty()) {
if (!QDir(services).exists()) QDir().mkpath(services);
QString path = services, file = path + qsl("tg.protocol");
QFile f(file);
if (f.open(QIODevice::WriteOnly)) {
QTextStream s(&f);
s.setCodec("UTF-8");
s << "[Protocol]\n";
s << "exec=" << QFile::decodeName(escapeShell(QFile::encodeName(cExeDir() + cExeName()))) << " -- %u\n";
s << "protocol=tg\n";
s << "input=none\n";
s << "output=none\n";
s << "helper=true\n";
s << "listing=false\n";
s << "reading=false\n";
s << "writing=false\n";
s << "makedir=false\n";
s << "deleting=false\n";
f.close();
} else {
LOG(("App Error: Could not open '%1' for write").arg(file));
}
}
QString path = services, file = path + qsl("tg.protocol");
QFile f(file);
if (f.open(QIODevice::WriteOnly)) {
QTextStream s(&f);
s.setCodec("UTF-8");
s << "[Protocol]\n";
s << "exec=" << QFile::decodeName(escapeShell(QFile::encodeName(cExeDir() + cExeName()))) << " -- %u\n";
s << "protocol=tg\n";
s << "input=none\n";
s << "output=none\n";
s << "helper=true\n";
s << "listing=false\n";
s << "reading=false\n";
s << "writing=false\n";
s << "makedir=false\n";
s << "deleting=false\n";
f.close();
} else {
LOG(("App Error: Could not open '%1' for write").arg(file));
}
}
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
}
@ -520,38 +533,38 @@ void psNewVersion() {
}
bool _execUpdater(bool update = true, const QString &crashreport = QString()) {
static const int MaxLen = 65536, MaxArgsCount = 128;
static const int MaxLen = 65536, MaxArgsCount = 128;
char path[MaxLen] = {0};
QByteArray data(QFile::encodeName(cExeDir() + "Updater"));
memcpy(path, data.constData(), data.size());
char path[MaxLen] = {0};
QByteArray data(QFile::encodeName(cExeDir() + "Updater"));
memcpy(path, data.constData(), data.size());
char *args[MaxArgsCount] = {0}, p_noupdate[] = "-noupdate", p_autostart[] = "-autostart", p_debug[] = "-debug", p_tosettings[] = "-tosettings", p_key[] = "-key", p_path[] = "-workpath", p_startintray[] = "-startintray", p_testmode[] = "-testmode", p_crashreport[] = "-crashreport";
char p_datafile[MaxLen] = {0}, p_pathbuf[MaxLen] = {0}, p_crashreportbuf[MaxLen] = {0};
int argIndex = 0;
args[argIndex++] = path;
if (!update) {
args[argIndex++] = p_noupdate;
args[argIndex++] = p_tosettings;
}
if (cLaunchMode() == LaunchModeAutoStart) args[argIndex++] = p_autostart;
if (cDebug()) args[argIndex++] = p_debug;
char *args[MaxArgsCount] = {0}, p_noupdate[] = "-noupdate", p_autostart[] = "-autostart", p_debug[] = "-debug", p_tosettings[] = "-tosettings", p_key[] = "-key", p_path[] = "-workpath", p_startintray[] = "-startintray", p_testmode[] = "-testmode", p_crashreport[] = "-crashreport";
char p_datafile[MaxLen] = {0}, p_pathbuf[MaxLen] = {0}, p_crashreportbuf[MaxLen] = {0};
int argIndex = 0;
args[argIndex++] = path;
if (!update) {
args[argIndex++] = p_noupdate;
args[argIndex++] = p_tosettings;
}
if (cLaunchMode() == LaunchModeAutoStart) args[argIndex++] = p_autostart;
if (cDebug()) args[argIndex++] = p_debug;
if (cStartInTray()) args[argIndex++] = p_startintray;
if (cTestMode()) args[argIndex++] = p_testmode;
if (cDataFile() != qsl("data")) {
QByteArray dataf = QFile::encodeName(cDataFile());
if (dataf.size() < MaxLen) {
memcpy(p_datafile, dataf.constData(), dataf.size());
args[argIndex++] = p_key;
args[argIndex++] = p_datafile;
}
}
QByteArray pathf = QFile::encodeName(cWorkingDir());
if (pathf.size() < MaxLen) {
memcpy(p_pathbuf, pathf.constData(), pathf.size());
args[argIndex++] = p_path;
args[argIndex++] = p_pathbuf;
}
if (cDataFile() != qsl("data")) {
QByteArray dataf = QFile::encodeName(cDataFile());
if (dataf.size() < MaxLen) {
memcpy(p_datafile, dataf.constData(), dataf.size());
args[argIndex++] = p_key;
args[argIndex++] = p_datafile;
}
}
QByteArray pathf = QFile::encodeName(cWorkingDir());
if (pathf.size() < MaxLen) {
memcpy(p_pathbuf, pathf.constData(), pathf.size());
args[argIndex++] = p_path;
args[argIndex++] = p_pathbuf;
}
if (!crashreport.isEmpty()) {
QByteArray crashreportf = QFile::encodeName(crashreport);
if (crashreportf.size() < MaxLen) {
@ -563,22 +576,22 @@ bool _execUpdater(bool update = true, const QString &crashreport = QString()) {
Logs::closeMain();
SignalHandlers::finish();
pid_t pid = fork();
switch (pid) {
case -1: return false;
case 0: execv(path, args); return false;
}
return true;
pid_t pid = fork();
switch (pid) {
case -1: return false;
case 0: execv(path, args); return false;
}
return true;
}
void psExecUpdater() {
if (!_execUpdater()) {
if (!_execUpdater()) {
psDeleteDir(cWorkingDir() + qsl("tupdates/temp"));
}
}
void psExecTelegram(const QString &crashreport) {
_execUpdater(false, crashreport);
_execUpdater(false, crashreport);
}
bool psShowOpenWithMenu(int x, int y, const QString &file) {

View File

@ -228,12 +228,18 @@ void FlatInput::focusOutEvent(QFocusEvent *e) {
}
void FlatInput::resizeEvent(QResizeEvent *e) {
updatePlaceholderText();
return QLineEdit::resizeEvent(e);
}
void FlatInput::updatePlaceholderText() {
int32 availw = width() - _st.textMrg.left() - _st.textMrg.right() - _st.phPos.x() - 1;
if (_st.font->width(_fullph) > availw) {
_ph = _st.font->elided(_fullph, availw);
} else {
_ph = _fullph;
}
update();
}
void FlatInput::contextMenuEvent(QContextMenuEvent *e) {
@ -279,8 +285,7 @@ void FlatInput::step_appearance(float64 ms, bool timer) {
void FlatInput::setPlaceholder(const QString &ph) {
_fullph = ph;
resizeEvent(0);
update();
updatePlaceholderText();
}
void FlatInput::setPlaceholderFast(bool fast) {
@ -2200,10 +2205,15 @@ void MaskedInputField::focusOutEvent(QFocusEvent *e) {
}
void MaskedInputField::resizeEvent(QResizeEvent *e) {
_placeholder = _st.font->elided(_placeholderFull, width() - _textMargins.left() - _textMargins.right() - _st.placeholderMargins.left() - _st.placeholderMargins.right() - 1);
updatePlaceholderText();
QLineEdit::resizeEvent(e);
}
void MaskedInputField::updatePlaceholderText() {
_placeholder = _st.font->elided(_placeholderFull, width() - _textMargins.left() - _textMargins.right() - _st.placeholderMargins.left() - _st.placeholderMargins.right() - 1);
update();
}
void MaskedInputField::contextMenuEvent(QContextMenuEvent *e) {
if (QMenu *menu = createStandardContextMenu()) {
(new PopupMenu(menu))->popup(e->globalPos());
@ -2267,8 +2277,7 @@ void MaskedInputField::step_border(float64 ms, bool timer) {
bool MaskedInputField::setPlaceholder(const QString &placeholder) {
if (_placeholderFull != placeholder) {
_placeholderFull = placeholder;
resizeEvent(0);
update();
updatePlaceholderText();
return true;
}
return false;

View File

@ -27,18 +27,8 @@ class FlatInput : public QLineEdit {
T_WIDGET
public:
FlatInput(QWidget *parent, const style::flatInput &st, const QString &ph = QString(), const QString &val = QString());
bool event(QEvent *e) override;
void touchEvent(QTouchEvent *e);
void paintEvent(QPaintEvent *e) override;
void focusInEvent(QFocusEvent *e) override;
void focusOutEvent(QFocusEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
void notaBene();
void setPlaceholder(const QString &ph);
@ -62,14 +52,12 @@ public:
void setTextMargins(const QMargins &mrg);
public slots:
void onTextChange(const QString &text);
void onTextEdited();
void onTouchTimer();
signals:
void changed();
void cancelled();
void submitted(bool ctrlShiftEnter);
@ -84,6 +72,15 @@ protected:
return QLineEdit::leaveEvent(e);
}
bool event(QEvent *e) override;
void touchEvent(QTouchEvent *e);
void paintEvent(QPaintEvent *e) override;
void focusInEvent(QFocusEvent *e) override;
void focusOutEvent(QFocusEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
virtual void correctValue(const QString &was, QString &now);
style::font phFont() {
@ -93,6 +90,7 @@ protected:
void phPrepare(Painter &p);
private:
void updatePlaceholderText();
QString _oldtext, _ph, _fullph;
bool _fastph;
@ -515,7 +513,6 @@ class MaskedInputField : public QLineEdit {
T_WIDGET
public:
MaskedInputField(QWidget *parent, const style::InputField &st, const QString &placeholder = QString(), const QString &val = QString());
bool event(QEvent *e) override;
@ -556,7 +553,6 @@ public:
}
public slots:
void onTextChange(const QString &text);
void onCursorPositionChanged(int oldPosition, int position);
@ -565,7 +561,6 @@ public slots:
void onTouchTimer();
signals:
void changed();
void cancelled();
void submitted(bool ctrlShiftEnter);
@ -595,8 +590,8 @@ protected:
const style::InputField &_st;
private:
void startBorderAnimation();
void updatePlaceholderText();
int32 _maxLength;

View File

@ -1,6 +1,6 @@
AppVersion 10013
AppVersion 10014
AppVersionStrMajor 0.10
AppVersionStrSmall 0.10.13
AppVersionStr 0.10.13
AppVersionStrSmall 0.10.14
AppVersionStr 0.10.14
AlphaChannel 1
BetaVersion 0