Telegram: improve Tracker integration

* Use 'Open With' Tracker dialog
* 'Show In Folder' select file in Tracker
* Idle time
* Cleanup code
This commit is contained in:
Gerasim Troeglazov
2021-03-24 19:33:20 +10:00
parent 672eff0e1c
commit 593bbc52ee
4 changed files with 245 additions and 152 deletions

View File

@@ -1,6 +1,6 @@
From fc3cc9c17c70402f8498db2921d2b18f650fea4a Mon Sep 17 00:00:00 2001
From 0cfe0abc83aa2204164fe5ced7fe69a0cd5cb8cf Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 21 Mar 2021 13:08:14 +1000
Date: Tue, 23 Mar 2021 19:00:30 +1000
Subject: Workaround build issues on GCC8

View File

@@ -1,6 +1,6 @@
From 2127b20c02768156a93701f9f8b4f63bc9970a26 Mon Sep 17 00:00:00 2001
From 9f1cf171999d1ee80137f3d8f11d3607db562f70 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 21 Mar 2021 11:45:25 +1000
Date: Tue, 23 Mar 2021 18:57:50 +1000
Subject: Add Haiku support
@@ -883,7 +883,7 @@ index 0bc42eb..c87cde9 100644
typedef pid_t PlatformThreadId;
typedef pthread_t PlatformThreadRef;
diff --git a/Telegram/cmake/lib_tgvoip.cmake b/Telegram/cmake/lib_tgvoip.cmake
index 7616728..f120a69 100644
index 7616728..51566ba 100644
--- a/Telegram/cmake/lib_tgvoip.cmake
+++ b/Telegram/cmake/lib_tgvoip.cmake
@@ -123,6 +123,14 @@ if (NOT TGVOIP_FOUND)
@@ -901,7 +901,7 @@ index 7616728..f120a69 100644
# POSIX
os/posix/NetworkSocketPosix.cpp
os/posix/NetworkSocketPosix.h
@@ -160,6 +168,37 @@ if (NOT TGVOIP_FOUND)
@@ -160,6 +168,25 @@ if (NOT TGVOIP_FOUND)
TGVOIP_NO_OSX_PRIVATE_API
)
endif()
@@ -924,18 +924,6 @@ index 7616728..f120a69 100644
+ network
+ media
+ )
+ remove_target_sources(lib_tgvoip_bundled ${tgvoip_loc}
+ os/linux/AudioInputALSA.cpp
+ os/linux/AudioInputALSA.h
+ os/linux/AudioOutputALSA.cpp
+ os/linux/AudioOutputALSA.h
+ os/linux/AudioOutputPulse.cpp
+ os/linux/AudioOutputPulse.h
+ os/linux/AudioInputPulse.cpp
+ os/linux/AudioInputPulse.h
+ os/linux/AudioPulse.cpp
+ os/linux/AudioPulse.h
+ )
else()
target_compile_options(lib_tgvoip_bundled
PRIVATE

View File

@@ -1,6 +1,6 @@
From 266ede233d6089b71460a589144d31ed3098e1c9 Mon Sep 17 00:00:00 2001
From fea67a51ebf1df0671fcf631b13b579b6c9cc0f5 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 21 Mar 2021 11:46:03 +1000
Date: Wed, 24 Mar 2021 19:03:17 +1000
Subject: Add Haiku support
@@ -62,6 +62,50 @@ index 732f75b..138608f 100644
rpl::variable<std::optional<bool>> _systemDarkMode = std::nullopt;
rpl::variable<bool> _systemDarkModeEnabled = false;
WindowPosition _windowPosition; // per-window
diff --git a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp
index 0489ece..29bdd29 100644
--- a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp
+++ b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp
@@ -15,6 +15,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/linux/linux_xdp_open_with_dialog.h"
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
+#ifdef Q_OS_HAIKU
+#include <base/haiku_types.h>
+#include <InterfaceKit.h>
+#include <StorageKit.h>
+#include <SupportKit.h>
+#include <MimeType.h>
+#include <Roster.h>
+#endif
+
#include <QtCore/QProcess>
#include <QtGui/QDesktopServices>
@@ -47,6 +56,23 @@ void UnsafeOpenEmailLink(const QString &email) {
}
bool UnsafeShowOpenWith(const QString &filepath) {
+#ifdef Q_OS_HAIKU
+ BMessenger trackerMessenger("application/x-vnd.Be-TRAK");
+ if (trackerMessenger.IsValid()) {
+ update_mime_info(filepath.toUtf8().data(), false, true, false);
+
+ BEntry fileEntry(filepath.toUtf8().data());
+ entry_ref fileRef;
+ if (fileEntry.GetRef(&fileRef) == B_OK) {
+ BMessage openCommand(B_REFS_RECEIVED);
+ openCommand.AddRef("refs", &fileRef);
+ openCommand.AddInt32("launchUsingSelector", 0);
+ if (trackerMessenger.SendMessage(&openCommand) == B_OK)
+ return true;
+ }
+ }
+#endif
+
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
if (internal::ShowXDPOpenWithDialog(filepath)) {
return true;
diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp
index 139667e..81361ef 100644
--- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp
@@ -108,10 +152,10 @@ index 139667e..81361ef 100644
#ifdef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_haiku.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_haiku.cpp
new file mode 100644
index 0000000..3926290
index 0000000..76f43f2
--- /dev/null
+++ b/Telegram/SourceFiles/platform/linux/notifications_manager_haiku.cpp
@@ -0,0 +1,254 @@
@@ -0,0 +1,252 @@
+/*
+This file is part of Telegram Desktop for Haiku,
+
@@ -127,22 +171,6 @@ index 0000000..3926290
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#ifdef __x86_64__
+#define int64 __haiku_int64
+#define uint64 __haiku_uint64
+#else
+#define int32 __haiku_int32
+#define uint32 __haiku_uint32
+#endif
+
+#include <SupportDefs.h>
+#include <Notification.h>
+#include <Message.h>
+#include <Bitmap.h>
+#include <TranslationUtils.h>
+#include <Entry.h>
+#include <OS.h>
+
+#include "platform/linux/notifications_manager_linux.h"
+
+#include "window/notifications_utilities.h"
@@ -152,12 +180,26 @@ index 0000000..3926290
+#include "core/core_settings.h"
+#include "main/main_session.h"
+
+#include "base/haiku_types.h"
+
+#ifdef __x86_64__
+#define uint64 __haiku_uint64
+#else
+#define uint32 __haiku_uint32
+#endif
+
+#include <AppKit.h>
+#include <SupportKit.h>
+#include <Notification.h>
+#include <InterfaceKit.h>
+#include <TranslationUtils.h>
+#include <OS.h>
+
+#define NOTIFY_MESSAGE_DEEP 16
+#define NOTIFY_PORT_NAME "tg_notify"
+#define NOTIFY_GATE_NAME "/bin/qnotify"
+#define NOTIFY_MESSAGE 'QNTF'
+
+#include <QProcess>
+#include <QObject>
+#include <QString>
+#include <QStringList>
@@ -367,23 +409,21 @@ index 0000000..3926290
+} // namespace Notifications
+} // namespace Platform
diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp
index f6b53fa..e92f64a 100644
index f6b53fa..cb43253 100644
--- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp
+++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp
@@ -7,6 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "platform/linux/specific_linux.h"
@@ -35,6 +35,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/linux/base_linux_xcb_utilities.h"
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
+#ifdef __HAIKU__
+#define _SUPPORT_DEFS_H
+typedef int32 status_t;
+typedef uint32 type_code;
+#ifdef Q_OS_HAIKU
+#include <base/haiku_types.h>
+#endif
+
#include "base/openssl_help.h"
#include "base/platform/base_platform_info.h"
#include "base/platform/linux/base_linux_glibmm_helper.h"
@@ -595,7 +601,7 @@ QString GetHomeDir() {
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
#include <QtCore/QStandardPaths>
@@ -595,7 +599,7 @@ QString GetHomeDir() {
return home;
}
@@ -392,7 +432,7 @@ index f6b53fa..e92f64a 100644
void HaikuAutostart(bool start) {
const auto home = GetHomeDir();
if (home.isEmpty()) {
@@ -620,7 +626,7 @@ void HaikuAutostart(bool start) {
@@ -620,7 +624,7 @@ void HaikuAutostart(bool start) {
file.remove();
}
}
@@ -401,7 +441,7 @@ index f6b53fa..e92f64a 100644
} // namespace
@@ -637,8 +643,11 @@ QString psAppDataPath() {
@@ -637,8 +641,11 @@ QString psAppDataPath() {
return oldPath;
}
}
@@ -414,7 +454,21 @@ index f6b53fa..e92f64a 100644
}
void psDoCleanup() {
@@ -857,7 +866,7 @@ bool OpenSystemSettings(SystemSettingsType type) {
@@ -754,11 +761,12 @@ void InstallLauncher(bool force) {
void RegisterCustomScheme(bool force) {
try {
+#ifndef Q_OS_HAIKU
if (InSnap()) {
SnapDefaultHandler(qsl("tg"));
return;
}
-
+#endif
if (cExeName().isEmpty()) {
return;
}
@@ -857,7 +865,7 @@ bool OpenSystemSettings(SystemSettingsType type) {
} else if (DesktopEnvironment::IsMATE()) {
add("mate-volume-control");
}
@@ -423,7 +477,7 @@ index f6b53fa..e92f64a 100644
add("Media");
#endif // __ HAIKU__
add("pavucontrol-qt");
@@ -906,17 +915,17 @@ void finish() {
@@ -906,17 +914,17 @@ void finish() {
} // namespace Platform
void psNewVersion() {
@@ -445,6 +499,145 @@ index f6b53fa..e92f64a 100644
if (InFlatpak()) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
diff --git a/Telegram/lib_base/base/haiku_types.h b/Telegram/lib_base/base/haiku_types.h
new file mode 100644
index 0000000..1aec6c5
--- /dev/null
+++ b/Telegram/lib_base/base/haiku_types.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#ifdef Q_OS_HAIKU
+
+#define _SUPPORT_DEFS_H
+
+#define int64 __haiku_int64
+#define int32 __haiku_int32
+
+typedef int32 status_t;
+typedef uint32 type_code;
+typedef uint32 perform_code;
+
+typedef int64 bigtime_t;
+typedef int64 nanotime_t;
+
+#endif
diff --git a/Telegram/lib_base/base/platform/linux/base_file_utilities_linux.cpp b/Telegram/lib_base/base/platform/linux/base_file_utilities_linux.cpp
index 4c6d431..801df3f 100644
--- a/Telegram/lib_base/base/platform/linux/base_file_utilities_linux.cpp
+++ b/Telegram/lib_base/base/platform/linux/base_file_utilities_linux.cpp
@@ -26,8 +26,58 @@
#include <stdio.h>
#include <fcntl.h>
+#ifdef Q_OS_HAIKU
+#include <base/haiku_types.h>
+#include <AppKit.h>
+#include <StorageKit.h>
+#endif
+
namespace base::Platform {
namespace {
+
+#ifdef Q_OS_HAIKU
+bool HaikuShowInFolder(const QString &filepath) {
+ try {
+ BMessenger trackerMessenger("application/x-vnd.Be-TRAK");
+ if (!trackerMessenger.IsValid())
+ return false;
+
+ BEntry fileEntry(filepath.toUtf8().data());
+ entry_ref fileRef;
+ if (fileEntry.GetRef(&fileRef) != B_OK)
+ return false;
+
+ if (!fileEntry.Exists())
+ return false;
+
+ BEntry folderEntry;
+ if (fileEntry.GetParent(&folderEntry) != B_OK)
+ return false;
+
+ entry_ref folderRef;
+ if (folderEntry.GetRef(&folderRef) != B_OK)
+ return false;
+
+ BMessage openCommand(B_REFS_RECEIVED);
+ openCommand.AddRef("refs", &folderRef);
+ node_ref fileNodeRef;
+ if (fileEntry.GetNodeRef(&fileNodeRef) == B_OK) {
+ openCommand.AddData("nodeRefToSelect", B_RAW_TYPE,
+ static_cast<void*>(&fileNodeRef), sizeof(node_ref));
+ }
+ if (trackerMessenger.SendMessage(&openCommand) == B_OK) {
+ snooze(300000);
+ BMessage selectCommand('Tsel');
+ selectCommand.AddRef("refs", &fileRef);
+ trackerMessenger.SendMessage(&selectCommand);
+ return true;
+ }
+ } catch (...) {
+ }
+
+ return false;
+}
+#endif
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
bool PortalShowInFolder(const QString &filepath) {
@@ -149,6 +199,12 @@ bool ShowInFolder(const QString &filepath) {
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
+#ifdef Q_OS_HAIKU
+ if (HaikuShowInFolder(filepath)) {
+ return true;
+ }
+#endif
+
if (ProcessShowInFolder(filepath)) {
return true;
}
diff --git a/Telegram/lib_base/base/platform/linux/base_last_input_linux.cpp b/Telegram/lib_base/base/platform/linux/base_last_input_linux.cpp
index c51d890..d411082 100644
--- a/Telegram/lib_base/base/platform/linux/base_last_input_linux.cpp
+++ b/Telegram/lib_base/base/platform/linux/base_last_input_linux.cpp
@@ -24,6 +24,11 @@
#include <xcb/screensaver.h>
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
+#ifdef Q_OS_HAIKU
+#include <base/haiku_types.h>
+#include <InterfaceDefs.h>
+#endif
+
namespace base::Platform {
namespace {
@@ -170,9 +175,23 @@ std::optional<crl::time> MutterDBusLastUserInputTime() {
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
+#ifdef Q_OS_HAIKU
+std::optional<crl::time> HaikuLastUserInputTime() {
+ const auto idle = idle_time() / 1000;
+ return (crl::now() - static_cast<crl::time>(idle));
+}
+#endif
+
} // namespace
std::optional<crl::time> LastUserInputTime() {
+#ifdef Q_OS_HAIKU
+ const auto haikuResult = HaikuLastUserInputTime();
+ if (haikuResult.has_value()) {
+ return haikuResult;
+ }
+#endif
+
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
if (::Platform::IsX11()) {
const auto xcbResult = XCBLastUserInputTime();
diff --git a/Telegram/lib_ui/ui/platform/linux/ui_utility_linux.cpp b/Telegram/lib_ui/ui/platform/linux/ui_utility_linux.cpp
index bfcc482..f451bbf 100644
--- a/Telegram/lib_ui/ui/platform/linux/ui_utility_linux.cpp
@@ -477,125 +670,37 @@ index bfcc482..f451bbf 100644
} // namespace Platform
diff --git a/Telegram/lib_webrtc/webrtc/details/webrtc_openal_adm.cpp b/Telegram/lib_webrtc/webrtc/details/webrtc_openal_adm.cpp
index b8929a5..cd1c61c 100644
index b8929a5..a6496ac 100644
--- a/Telegram/lib_webrtc/webrtc/details/webrtc_openal_adm.cpp
+++ b/Telegram/lib_webrtc/webrtc/details/webrtc_openal_adm.cpp
@@ -4,6 +4,13 @@
@@ -4,6 +4,11 @@
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
+
+#ifdef __HAIKU__
+#define _SUPPORT_DEFS_H
+typedef int32 status_t;
+typedef uint32 type_code;
+#ifdef Q_OS_HAIKU
+#include <base/haiku_types.h>
+#endif
+
#include "webrtc/details/webrtc_openal_adm.h"
#include "base/timer.h"
diff --git a/Telegram/lib_webrtc/webrtc/webrtc_audio_input_tester.cpp b/Telegram/lib_webrtc/webrtc/webrtc_audio_input_tester.cpp
index 092b667..e594a22 100644
index 092b667..204e259 100644
--- a/Telegram/lib_webrtc/webrtc/webrtc_audio_input_tester.cpp
+++ b/Telegram/lib_webrtc/webrtc/webrtc_audio_input_tester.cpp
@@ -4,6 +4,13 @@
@@ -4,6 +4,11 @@
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
+
+#ifdef __HAIKU__
+#define _SUPPORT_DEFS_H
+typedef int32 status_t;
+typedef uint32 type_code;
+#ifdef Q_OS_HAIKU
+#include <base/haiku_types.h>
+#endif
+
#include "webrtc/webrtc_audio_input_tester.h"
#include "webrtc/webrtc_create_adm.h"
diff --git a/cmake/nice_target_sources.cmake b/cmake/nice_target_sources.cmake
index 81f9a7b..38d81f9 100644
--- a/cmake/nice_target_sources.cmake
+++ b/cmake/nice_target_sources.cmake
@@ -15,6 +15,7 @@ function(nice_target_sources target_name src_loc)
set(not_win_sources "")
set(not_mac_sources "")
set(not_linux_sources "")
+ set(not_haiku_sources "")
foreach (entry ${list})
if (${entry} STREQUAL "PRIVATE" OR ${entry} STREQUAL "PUBLIC" OR ${entry} STREQUAL "INTERFACE")
set(writing_now ${entry})
@@ -23,12 +24,18 @@ function(nice_target_sources target_name src_loc)
if (${entry} MATCHES "(^|/)win/" OR ${entry} MATCHES "(^|/)winrc/" OR ${entry} MATCHES "(^|/)windows/" OR ${entry} MATCHES "[_\\/]win\\.")
list(APPEND not_mac_sources ${full_name})
list(APPEND not_linux_sources ${full_name})
+ list(APPEND not_haiku_sources ${full_name})
elseif (${entry} MATCHES "(^|/)mac/" OR ${entry} MATCHES "(^|/)darwin/" OR ${entry} MATCHES "(^|/)osx/" OR ${entry} MATCHES "[_\\/]mac\\." OR ${entry} MATCHES "[_\\/]darwin\\." OR ${entry} MATCHES "[_\\/]osx\\.")
list(APPEND not_win_sources ${full_name})
list(APPEND not_linux_sources ${full_name})
+ list(APPEND not_haiku_sources ${full_name})
elseif (${entry} MATCHES "(^|/)linux/" OR ${entry} MATCHES "[_\\/]linux\\.")
list(APPEND not_win_sources ${full_name})
list(APPEND not_mac_sources ${full_name})
+ elseif (${entry} MATCHES "(^|/)haiku/" OR ${entry} MATCHES "[_\\/]haiku\\.")
+ list(APPEND not_win_sources ${full_name})
+ list(APPEND not_mac_sources ${full_name})
+ list(APPEND not_linux_sources ${full_name})
elseif (${entry} MATCHES "(^|/)posix/" OR ${entry} MATCHES "[_\\/]posix\\.")
list(APPEND not_win_sources ${full_name})
endif()
@@ -64,6 +71,9 @@ function(nice_target_sources target_name src_loc)
elseif (APPLE)
set_source_files_properties(${not_mac_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${not_mac_sources} PROPERTIES SKIP_AUTOGEN TRUE)
+ elseif (HAIKU)
+ set_source_files_properties(${not_haiku_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
+ set_source_files_properties(${not_haiku_sources} PROPERTIES SKIP_AUTOGEN TRUE)
elseif (LINUX)
set_source_files_properties(${not_linux_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${not_linux_sources} PROPERTIES SKIP_AUTOGEN TRUE)
--
2.30.2
From 8b713808ca7d568b7a69adacec7b62a76b03813f Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 21 Mar 2021 13:06:10 +1000
Subject: Remove snap for Haiku
diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp
index e92f64a..e74e05d 100644
--- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp
+++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp
@@ -207,6 +207,7 @@ PortalAutostart::PortalAutostart(bool start, bool silent) {
}
}
+#ifndef Q_OS_HAIKU
class SnapDefaultHandler : public QWindow {
public:
SnapDefaultHandler(const QString &protocol);
@@ -268,6 +269,7 @@ SnapDefaultHandler::SnapDefaultHandler(const QString &protocol) {
QString::fromStdString(e.what())));
}
}
+#endif
bool IsIBusPortalPresent() {
static const auto Result = [&] {
@@ -763,11 +765,12 @@ void InstallLauncher(bool force) {
void RegisterCustomScheme(bool force) {
try {
+#ifndef Q_OS_HAIKU
if (InSnap()) {
SnapDefaultHandler(qsl("tg"));
return;
}
-
+#endif
if (cExeName().isEmpty()) {
return;
}
--
2.30.2

View File

@@ -3,7 +3,7 @@ DESCRIPTION="Unofficial build of the original Telegram client for Haiku."
HOMEPAGE="https://www.telegram.org/"
COPYRIGHT="2013-2021 Telegram"
LICENSE="GNU GPL v3"
REVISION="1"
REVISION="2"
SOURCE_URI="https://github.com/telegramdesktop/tdesktop/releases/download/v$portVersion/tdesktop-$portVersion-full.tar.gz"
CHECKSUM_SHA256="41bfbe1ee63da9a6af7cf7d11b1cdd13a6754b51b294ac5a9d56f5f11dfbdd05"
SOURCE_FILENAME="tdesktop-$portVersion-full.tar.gz"