2014-07-08 10:24:21 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2016-01-10 06:05:23 +00:00
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
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.
|
2016-01-10 06:05:23 +00:00
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
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.
|
2016-01-10 06:05:23 +00:00
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
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
|
2014-07-08 10:24:21 +00:00
|
|
|
*/
|
2017-03-05 22:43:35 +00:00
|
|
|
#include "platform/linux/specific_linux.h"
|
2014-07-08 10:24:21 +00:00
|
|
|
|
2016-06-16 17:20:58 +00:00
|
|
|
#include "platform/linux/linux_libs.h"
|
2014-07-08 10:24:21 +00:00
|
|
|
#include "lang.h"
|
|
|
|
#include "application.h"
|
|
|
|
#include "mainwidget.h"
|
2017-02-25 18:17:50 +00:00
|
|
|
#include "mainwindow.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "platform/linux/file_utilities_linux.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "platform/platform_notifications_manager.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2014-07-14 05:16:21 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
2014-07-24 16:00:35 +00:00
|
|
|
#include <pwd.h>
|
2014-07-14 05:16:21 +00:00
|
|
|
|
2015-01-15 14:22:15 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2016-11-11 07:51:53 +00:00
|
|
|
#include <qpa/qplatformnativeinterface.h>
|
|
|
|
|
2016-06-16 17:20:58 +00:00
|
|
|
using namespace Platform;
|
2017-02-28 14:05:30 +00:00
|
|
|
using Platform::File::internal::EscapeShell;
|
2015-01-15 14:22:15 +00:00
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
namespace {
|
2016-10-18 10:32:33 +00:00
|
|
|
|
|
|
|
class _PsEventFilter : public QAbstractNativeEventFilter {
|
|
|
|
public:
|
|
|
|
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
|
|
|
|
//auto wnd = App::wnd();
|
|
|
|
//if (!wnd) return false;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-08 10:24:21 +00:00
|
|
|
};
|
2016-10-18 10:32:33 +00:00
|
|
|
_PsEventFilter *_psEventFilter = nullptr;
|
2014-07-08 10:24:21 +00:00
|
|
|
|
2016-10-18 10:32:33 +00:00
|
|
|
QRect _monitorRect;
|
2016-12-01 19:20:33 +00:00
|
|
|
auto _monitorLastGot = 0LL;
|
2016-10-18 10:32:33 +00:00
|
|
|
|
|
|
|
} // namespace
|
2014-07-08 10:24:21 +00:00
|
|
|
|
2014-07-09 05:54:12 +00:00
|
|
|
QRect psDesktopRect() {
|
2016-12-01 19:20:33 +00:00
|
|
|
auto tnow = getms();
|
|
|
|
if (tnow > _monitorLastGot + 1000LL || tnow < _monitorLastGot) {
|
2016-10-18 10:32:33 +00:00
|
|
|
_monitorLastGot = tnow;
|
|
|
|
_monitorRect = QApplication::desktop()->availableGeometry(App::wnd());
|
|
|
|
}
|
|
|
|
return _monitorRect;
|
2014-07-08 10:24:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 12:57:14 +00:00
|
|
|
void psShowOverAll(QWidget *w, bool canFocus) {
|
2016-10-18 10:32:33 +00:00
|
|
|
w->show();
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void psBringToBack(QWidget *w) {
|
2016-10-18 10:32:33 +00:00
|
|
|
w->hide();
|
2014-10-17 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
QAbstractNativeEventFilter *psNativeEventFilter() {
|
2016-10-18 10:32:33 +00:00
|
|
|
delete _psEventFilter;
|
2014-07-08 10:24:21 +00:00
|
|
|
_psEventFilter = new _PsEventFilter();
|
2016-01-11 15:43:29 +00:00
|
|
|
return _psEventFilter;
|
2014-07-08 10:24:21 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 18:24:42 +00:00
|
|
|
void psWriteDump() {
|
|
|
|
}
|
|
|
|
|
|
|
|
QString demanglestr(const QString &mangled) {
|
2016-10-18 10:32:33 +00:00
|
|
|
if (mangled.isEmpty()) return mangled;
|
2016-01-31 16:13:51 +00:00
|
|
|
|
2016-01-30 18:24:42 +00:00
|
|
|
QByteArray cmd = ("c++filt -n " + mangled).toUtf8();
|
|
|
|
FILE *f = popen(cmd.constData(), "r");
|
|
|
|
if (!f) return "BAD_SYMBOL_" + mangled;
|
|
|
|
|
|
|
|
QString result;
|
|
|
|
char buffer[4096] = { 0 };
|
|
|
|
while (!feof(f)) {
|
|
|
|
if (fgets(buffer, 4096, f) != NULL) {
|
|
|
|
result += buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
return result.trimmed();
|
|
|
|
}
|
|
|
|
|
2016-01-31 16:13:51 +00:00
|
|
|
QStringList addr2linestr(uint64 *addresses, int count) {
|
|
|
|
QStringList result;
|
|
|
|
if (!count) return result;
|
|
|
|
|
|
|
|
result.reserve(count);
|
2017-02-28 14:05:30 +00:00
|
|
|
QByteArray cmd = "addr2line -e " + EscapeShell(QFile::encodeName(cExeDir() + cExeName()));
|
2016-01-31 16:13:51 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
if (addresses[i]) {
|
2016-02-09 14:42:36 +00:00
|
|
|
cmd += qsl(" 0x%1").arg(addresses[i], 0, 16).toUtf8();
|
2016-01-31 16:13:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FILE *f = popen(cmd.constData(), "r");
|
|
|
|
|
|
|
|
QStringList addr2lineResult;
|
|
|
|
if (f) {
|
|
|
|
char buffer[4096] = {0};
|
|
|
|
while (!feof(f)) {
|
|
|
|
if (fgets(buffer, 4096, f) != NULL) {
|
|
|
|
addr2lineResult.push_back(QString::fromUtf8(buffer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
for (int i = 0, j = 0; i < count; ++i) {
|
|
|
|
if (addresses[i]) {
|
|
|
|
if (j < addr2lineResult.size() && !addr2lineResult.at(j).isEmpty() && !addr2lineResult.at(j).startsWith(qstr("0x"))) {
|
|
|
|
QString res = addr2lineResult.at(j).trimmed();
|
2016-10-18 10:32:33 +00:00
|
|
|
if (int index = res.indexOf(qstr("/Telegram/"))) {
|
|
|
|
if (index > 0) {
|
|
|
|
res = res.mid(index + qstr("/Telegram/").size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.push_back(res);
|
2016-01-31 16:13:51 +00:00
|
|
|
} else {
|
|
|
|
result.push_back(QString());
|
|
|
|
}
|
|
|
|
++j;
|
|
|
|
} else {
|
|
|
|
result.push_back(QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-01-31 18:01:43 +00:00
|
|
|
QString psPrepareCrashDump(const QByteArray &crashdump, QString dumpfile) {
|
2016-01-30 18:24:42 +00:00
|
|
|
QString initial = QString::fromUtf8(crashdump), result;
|
|
|
|
QStringList lines = initial.split('\n');
|
|
|
|
result.reserve(initial.size());
|
|
|
|
int32 i = 0, l = lines.size();
|
|
|
|
|
|
|
|
while (i < l) {
|
2016-10-18 10:32:33 +00:00
|
|
|
uint64 addresses[1024] = { 0 };
|
2016-01-30 18:24:42 +00:00
|
|
|
for (; i < l; ++i) {
|
|
|
|
result.append(lines.at(i)).append('\n');
|
|
|
|
QString line = lines.at(i).trimmed();
|
|
|
|
if (line == qstr("Backtrace:")) {
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 10:32:33 +00:00
|
|
|
int32 start = i;
|
2016-01-31 16:13:51 +00:00
|
|
|
for (; i < l; ++i) {
|
2016-10-18 10:32:33 +00:00
|
|
|
QString line = lines.at(i).trimmed();
|
2016-01-31 16:13:51 +00:00
|
|
|
if (line.isEmpty()) break;
|
|
|
|
|
2016-10-18 10:32:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-01-31 16:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList addr2line = addr2linestr(addresses, i - start);
|
|
|
|
for (i = start; i < l; ++i) {
|
2016-01-30 18:24:42 +00:00
|
|
|
QString line = lines.at(i).trimmed();
|
|
|
|
if (line.isEmpty()) break;
|
|
|
|
|
2016-10-18 10:32:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
2016-01-30 18:24:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-14 05:16:21 +00:00
|
|
|
bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c
|
2016-10-18 10:32:33 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
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());
|
2014-07-14 05:16:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 18:13:01 +00:00
|
|
|
void psDeleteDir(const QString &dir) {
|
|
|
|
_removeDirectory(dir);
|
2014-07-08 10:24:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 13:04:41 +00:00
|
|
|
namespace {
|
2016-10-18 10:32:33 +00:00
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
auto _lastUserAction = 0LL;
|
2016-10-18 10:32:33 +00:00
|
|
|
|
|
|
|
} // namespace
|
2015-01-26 13:04:41 +00:00
|
|
|
|
|
|
|
void psUserActionDone() {
|
|
|
|
_lastUserAction = getms(true);
|
|
|
|
}
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
bool psIdleSupported() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
TimeMs psIdleTime() {
|
2015-01-26 13:04:41 +00:00
|
|
|
return getms(true) - _lastUserAction;
|
|
|
|
}
|
2015-01-16 16:46:01 +00:00
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
void psActivateProcess(uint64 pid) {
|
|
|
|
// objc_activateProgram();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString psCurrentCountry() {
|
2016-10-18 10:32:33 +00:00
|
|
|
QString country;// = objc_currentCountry();
|
2014-07-08 10:24:21 +00:00
|
|
|
return country.isEmpty() ? QString::fromLatin1(DefaultCountry) : country;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString psCurrentLanguage() {
|
2016-10-18 10:32:33 +00:00
|
|
|
QString lng;// = objc_currentLang();
|
2014-07-08 10:24:21 +00:00
|
|
|
return lng.isEmpty() ? QString::fromLatin1(DefaultLanguage) : lng;
|
|
|
|
}
|
|
|
|
|
2014-12-04 09:48:46 +00:00
|
|
|
namespace {
|
2016-10-18 10:32:33 +00:00
|
|
|
|
|
|
|
QString getHomeDir() {
|
|
|
|
struct passwd *pw = getpwuid(getuid());
|
|
|
|
return (pw && pw->pw_dir && strlen(pw->pw_dir)) ? (QFile::decodeName(pw->pw_dir) + '/') : QString();
|
2014-12-04 09:48:46 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 10:32:33 +00:00
|
|
|
} // namespace
|
|
|
|
|
2014-12-04 09:48:46 +00:00
|
|
|
QString psAppDataPath() {
|
2016-10-18 10:32:33 +00:00
|
|
|
// 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) + '/';
|
2014-07-08 10:24:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 14:11:09 +00:00
|
|
|
QString psDownloadPath() {
|
2016-05-04 10:41:41 +00:00
|
|
|
return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + '/' + str_const_toString(AppName) + '/';
|
2014-09-30 14:11:09 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
QString psCurrentExeDirectory(int argc, char *argv[]) {
|
2016-10-18 10:32:33 +00:00
|
|
|
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() + '/';
|
|
|
|
}
|
|
|
|
}
|
2014-07-08 10:24:21 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2014-11-27 18:20:48 +00:00
|
|
|
QString psCurrentExeName(int argc, char *argv[]) {
|
2016-02-09 14:42:36 +00:00
|
|
|
QString first = argc ? QFile::decodeName(argv[0]) : QString();
|
2014-11-27 18:20:48 +00:00
|
|
|
if (!first.isEmpty()) {
|
|
|
|
QFileInfo info(first);
|
2016-10-18 10:32:33 +00:00
|
|
|
if (info.isSymLink()) {
|
|
|
|
info = info.symLinkTarget();
|
|
|
|
}
|
|
|
|
if (info.exists()) {
|
2014-11-27 18:20:48 +00:00
|
|
|
return info.fileName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
void psDoCleanup() {
|
|
|
|
try {
|
|
|
|
psAutoStart(false, true);
|
2014-07-18 10:37:34 +00:00
|
|
|
psSendToMenu(false, true);
|
2014-07-08 10:24:21 +00:00
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int psCleanup() {
|
|
|
|
psDoCleanup();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void psDoFixPrevious() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int psFixPrevious() {
|
|
|
|
psDoFixPrevious();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
namespace Platform {
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
void start() {
|
|
|
|
}
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
void finish() {
|
2017-03-04 19:36:59 +00:00
|
|
|
Notifications::Finish();
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
delete _psEventFilter;
|
|
|
|
_psEventFilter = nullptr;
|
|
|
|
}
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2016-10-22 14:35:37 +00:00
|
|
|
void SetWatchingMediaKeys(bool watching) {
|
|
|
|
}
|
|
|
|
|
2016-11-11 07:51:53 +00:00
|
|
|
bool TransparentWindowsSupported(QPoint globalPosition) {
|
|
|
|
if (auto app = static_cast<QGuiApplication*>(QCoreApplication::instance())) {
|
|
|
|
if (auto native = app->platformNativeInterface()) {
|
|
|
|
if (auto desktop = QApplication::desktop()) {
|
|
|
|
auto index = desktop->screenNumber(globalPosition);
|
|
|
|
auto screens = QGuiApplication::screens();
|
|
|
|
if (auto screen = (index >= 0 && index < screens.size()) ? screens[index] : QGuiApplication::primaryScreen()) {
|
|
|
|
if (native->nativeResourceForScreen(QByteArray("compositingEnabled"), screen)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static OrderedSet<int> WarnedAbout;
|
|
|
|
if (!WarnedAbout.contains(index)) {
|
|
|
|
WarnedAbout.insert(index);
|
|
|
|
LOG(("WARNING: Compositing is disabled for screen index %1 (for position %2,%3)").arg(index).arg(globalPosition.x()).arg(globalPosition.y()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(("WARNING: Could not get screen for index %1 (for position %2,%3)").arg(index).arg(globalPosition.x()).arg(globalPosition.y()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-02 07:25:20 +00:00
|
|
|
void InitOnTopPanel(QWidget *panel) {
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
namespace ThirdParty {
|
2016-02-21 14:45:07 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
void start() {
|
2016-06-16 17:20:58 +00:00
|
|
|
Libs::start();
|
|
|
|
MainWindow::LibsLoaded();
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2016-02-21 14:45:07 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
void finish() {
|
2014-07-08 10:24:21 +00:00
|
|
|
}
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
} // namespace ThirdParty
|
|
|
|
|
|
|
|
} // namespace Platform
|
|
|
|
|
2014-12-04 09:48:46 +00:00
|
|
|
namespace {
|
2016-10-18 10:32:33 +00:00
|
|
|
|
|
|
|
bool _psRunCommand(const QByteArray &command) {
|
2017-03-22 15:38:40 +00:00
|
|
|
auto result = system(command.constData());
|
2016-10-18 10:32:33 +00:00
|
|
|
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;
|
2014-12-04 09:48:46 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 10:32:33 +00:00
|
|
|
} // namespace
|
|
|
|
|
2014-12-03 13:10:32 +00:00
|
|
|
void psRegisterCustomScheme() {
|
2016-10-18 07:56:38 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
2016-10-18 10:32:33 +00:00
|
|
|
auto home = getHomeDir();
|
|
|
|
if (home.isEmpty() || cBetaVersion()) return; // don't update desktop file for beta version
|
2014-12-04 09:48:46 +00:00
|
|
|
|
2016-10-18 07:56:38 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
|
2016-10-18 10:32:33 +00:00
|
|
|
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");
|
2016-12-20 13:03:51 +00:00
|
|
|
auto iconExists = QFile(icon).exists();
|
|
|
|
if (Local::oldSettingsVersion() < 10021 && iconExists) {
|
|
|
|
// Icon was changed.
|
|
|
|
if (QFile(icon).remove()) {
|
|
|
|
iconExists = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!iconExists) {
|
2016-10-18 10:32:33 +00:00
|
|
|
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 << "Version=1.0\n";
|
|
|
|
s << "Name=Telegram Desktop\n";
|
|
|
|
s << "Comment=Official desktop version of Telegram messaging app\n";
|
2017-03-23 15:00:21 +00:00
|
|
|
s << "TryExec=" << EscapeShell(QFile::encodeName(cExeDir() + cExeName())) << "\n";
|
2017-02-28 14:05:30 +00:00
|
|
|
s << "Exec=" << EscapeShell(QFile::encodeName(cExeDir() + cExeName())) << " -- %u\n";
|
2016-10-18 10:32:33 +00:00
|
|
|
s << "Icon=telegram\n";
|
|
|
|
s << "Terminal=false\n";
|
2017-03-23 15:00:21 +00:00
|
|
|
s << "StartupWMClass=TelegramDesktop\n";
|
2016-10-18 10:32:33 +00:00
|
|
|
s << "Type=Application\n";
|
2017-03-23 15:00:21 +00:00
|
|
|
s << "Categories=Network;InstantMessaging;Qt;\n";
|
2016-10-18 10:32:33 +00:00
|
|
|
s << "MimeType=x-scheme-handler/tg;\n";
|
|
|
|
f.close();
|
|
|
|
|
2017-02-28 14:05:30 +00:00
|
|
|
if (_psRunCommand("desktop-file-install --dir=" + EscapeShell(QFile::encodeName(home + qsl(".local/share/applications"))) + " --delete-original " + EscapeShell(QFile::encodeName(file)))) {
|
2016-10-18 10:32:33 +00:00
|
|
|
DEBUG_LOG(("App Info: removing old .desktop file"));
|
|
|
|
QFile(qsl("%1.local/share/applications/telegram.desktop").arg(home)).remove();
|
|
|
|
|
2017-02-28 14:05:30 +00:00
|
|
|
_psRunCommand("update-desktop-database " + EscapeShell(QFile::encodeName(home + qsl(".local/share/applications"))));
|
2016-10-18 10:32:33 +00:00
|
|
|
_psRunCommand("xdg-mime default telegramdesktop.desktop x-scheme-handler/tg");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(("App Error: Could not open '%1' for write").arg(file));
|
|
|
|
}
|
|
|
|
}
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
|
2014-12-04 09:48:46 +00:00
|
|
|
|
2016-10-18 10:32:33 +00:00
|
|
|
DEBUG_LOG(("App Info: registerting for Gnome"));
|
2017-02-28 14:05:30 +00:00
|
|
|
if (_psRunCommand("gconftool-2 -t string -s /desktop/gnome/url-handlers/tg/command " + EscapeShell(EscapeShell(QFile::encodeName(cExeDir() + cExeName())) + " -- %s"))) {
|
2016-10-18 10:32:33 +00:00
|
|
|
_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);
|
|
|
|
|
|
|
|
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";
|
2017-02-28 14:05:30 +00:00
|
|
|
s << "exec=" << QFile::decodeName(EscapeShell(QFile::encodeName(cExeDir() + cExeName()))) << " -- %u\n";
|
2016-10-18 10:32:33 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
2014-12-03 13:10:32 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 15:11:07 +00:00
|
|
|
void psNewVersion() {
|
|
|
|
psRegisterCustomScheme();
|
|
|
|
}
|
|
|
|
|
2016-01-30 18:24:42 +00:00
|
|
|
bool _execUpdater(bool update = true, const QString &crashreport = QString()) {
|
2016-10-18 10:32:33 +00:00
|
|
|
static const int MaxLen = 65536, MaxArgsCount = 128;
|
|
|
|
|
|
|
|
char path[MaxLen] = {0};
|
2017-03-23 15:00:21 +00:00
|
|
|
QByteArray data(QFile::encodeName(cExeDir() + (update ? "Updater" : gExeName)));
|
2016-10-18 10:32:33 +00:00
|
|
|
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;
|
2015-01-27 16:58:58 +00:00
|
|
|
if (cStartInTray()) args[argIndex++] = p_startintray;
|
2015-04-02 10:33:19 +00:00
|
|
|
if (cTestMode()) args[argIndex++] = p_testmode;
|
2016-10-18 10:32:33 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-01-30 18:24:42 +00:00
|
|
|
if (!crashreport.isEmpty()) {
|
2016-02-09 14:42:36 +00:00
|
|
|
QByteArray crashreportf = QFile::encodeName(crashreport);
|
2016-01-30 18:24:42 +00:00
|
|
|
if (crashreportf.size() < MaxLen) {
|
|
|
|
memcpy(p_crashreportbuf, crashreportf.constData(), crashreportf.size());
|
|
|
|
args[argIndex++] = p_crashreport;
|
|
|
|
args[argIndex++] = p_crashreportbuf;
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 08:53:23 +00:00
|
|
|
|
2016-02-08 10:50:56 +00:00
|
|
|
Logs::closeMain();
|
|
|
|
SignalHandlers::finish();
|
2016-10-18 10:32:33 +00:00
|
|
|
pid_t pid = fork();
|
|
|
|
switch (pid) {
|
|
|
|
case -1: return false;
|
|
|
|
case 0: execv(path, args); return false;
|
|
|
|
}
|
|
|
|
return true;
|
2014-07-10 08:53:23 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
void psExecUpdater() {
|
2016-10-18 10:32:33 +00:00
|
|
|
if (!_execUpdater()) {
|
2015-06-03 18:13:01 +00:00
|
|
|
psDeleteDir(cWorkingDir() + qsl("tupdates/temp"));
|
2014-07-08 10:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-30 18:24:42 +00:00
|
|
|
void psExecTelegram(const QString &crashreport) {
|
2016-10-18 10:32:33 +00:00
|
|
|
_execUpdater(false, crashreport);
|
2014-07-08 10:24:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-21 10:20:23 +00:00
|
|
|
bool psShowOpenWithMenu(int x, int y, const QString &file) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
void psAutoStart(bool start, bool silent) {
|
|
|
|
}
|
2014-07-18 10:37:34 +00:00
|
|
|
|
|
|
|
void psSendToMenu(bool send, bool silent) {
|
|
|
|
}
|
2014-09-29 02:47:30 +00:00
|
|
|
|
|
|
|
void psUpdateOverlayed(QWidget *widget) {
|
|
|
|
}
|
2015-06-03 18:13:01 +00:00
|
|
|
|
|
|
|
bool linuxMoveFile(const char *from, const char *to) {
|
|
|
|
FILE *ffrom = fopen(from, "rb"), *fto = fopen(to, "wb");
|
|
|
|
if (!ffrom) {
|
|
|
|
if (fto) fclose(fto);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!fto) {
|
|
|
|
fclose(ffrom);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static const int BufSize = 65536;
|
|
|
|
char buf[BufSize];
|
|
|
|
while (size_t size = fread(buf, 1, BufSize, ffrom)) {
|
|
|
|
fwrite(buf, 1, size, fto);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stat fst; // from http://stackoverflow.com/questions/5486774/keeping-fileowner-and-permissions-after-copying-file-in-c
|
|
|
|
//let's say this wont fail since you already worked OK on that fp
|
|
|
|
if (fstat(fileno(ffrom), &fst) != 0) {
|
|
|
|
fclose(ffrom);
|
|
|
|
fclose(fto);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//update to the same uid/gid
|
|
|
|
if (fchown(fileno(fto), fst.st_uid, fst.st_gid) != 0) {
|
|
|
|
fclose(ffrom);
|
|
|
|
fclose(fto);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//update the permissions
|
|
|
|
if (fchmod(fileno(fto), fst.st_mode) != 0) {
|
|
|
|
fclose(ffrom);
|
|
|
|
fclose(fto);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(ffrom);
|
|
|
|
fclose(fto);
|
|
|
|
|
|
|
|
if (unlink(from)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-17 16:37:21 +00:00
|
|
|
|
2016-02-28 13:54:04 +00:00
|
|
|
bool psLaunchMaps(const LocationCoords &coords) {
|
2016-02-17 16:37:21 +00:00
|
|
|
return false;
|
|
|
|
}
|