Skip to content

Commit

Permalink
Removed Qt4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaffeine committed Nov 7, 2016
1 parent 743add8 commit df12de3
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 89 deletions.
22 changes: 6 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,20 @@ option(STATIC_BUILD "Compile static library instead of shared" FALSE)
# Add an option for dev build
option(DEVELOPER_BUILD "Enable extra debug codepaths, like asserts and extra output" FALSE)

if (USE_QT4)
set(QT_VERSION_MAJOR "4")

if(ENABLE_TESTAPP)
find_package(Qt4 4.8.0 REQUIRED QtCore QtNetwork QtGui)
else()
find_package(Qt4 4.8.0 REQUIRED QtCore QtNetwork)
endif()
else()
set(QT_VERSION_MAJOR "5")
set(QT_VERSION_MAJOR "5")

if(ENABLE_TESTAPP)
find_package(Qt5 REQUIRED COMPONENTS Core Network Gui Widgets)
else()
find_package(Qt5 REQUIRED COMPONENTS Core Network)
endif()
if(ENABLE_TESTAPP)
find_package(Qt5 REQUIRED COMPONENTS Core Network Gui Widgets)
else()
find_package(Qt5 REQUIRED COMPONENTS Core Network)
endif()

find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)

include(GNUInstallDirs)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")

# Add the source subdirectories
add_subdirectory(TelegramQt)
Expand Down
30 changes: 8 additions & 22 deletions TelegramQt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ endif()

add_definitions(-DTELEGRAMQT_LIBRARY)

if (USE_QT4)
QT4_WRAP_CPP(telegram_qt_MOC_SOURECES ${telegram_qt_META_HEADERS})
else()
QT5_WRAP_CPP(telegram_qt_MOC_SOURECES ${telegram_qt_META_HEADERS})
endif()
QT5_WRAP_CPP(telegram_qt_MOC_SOURECES ${telegram_qt_META_HEADERS})

if (STATIC_BUILD)
add_library(telegram-qt${QT_VERSION_MAJOR} STATIC ${telegram_qt_SOURCES} ${telegram_qt_MOC_SOURECES})
Expand All @@ -79,23 +75,13 @@ endif()

target_include_directories(telegram-qt${QT_VERSION_MAJOR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

if(USE_QT4)
target_link_libraries(telegram-qt${QT_VERSION_MAJOR}
${QT_QTCORE_LIBRARY}
${QT_QTNETWORK_LIBRARY}
)
target_include_directories(telegram-qt${QT_VERSION_MAJOR} PRIVATE
${QT_INCLUDES}
)
else()
target_link_libraries(telegram-qt${QT_VERSION_MAJOR}
Qt5::Core
Qt5::Network
)
target_include_directories(telegram-qt${QT_VERSION_MAJOR} PRIVATE
${QT5_INCLUDES}
)
endif()
target_link_libraries(telegram-qt${QT_VERSION_MAJOR}
Qt5::Core
Qt5::Network
)
target_include_directories(telegram-qt${QT_VERSION_MAJOR} PRIVATE
${QT5_INCLUDES}
)

target_link_libraries(telegram-qt${QT_VERSION_MAJOR}
${OPENSSL_LIBRARIES}
Expand Down
28 changes: 2 additions & 26 deletions TelegramQt/CTelegramDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ using namespace TelegramUtils;

#include <QCryptographicHash>
#include <QDebug>
#if QT_VERSION < 0x048000
#include <algorithm>
#endif

#ifdef DEVELOPER_BUILD
#include "TLTypesDebug.hpp"
Expand All @@ -58,14 +56,6 @@ static const int s_autoConnectionIndexInvalid = -1; // App logic rely on (s_auto
static const quint32 s_legacyDcInfoTlType = 0x2ec2a43cu; // Scheme23_DcOption
static const quint32 s_legacyVectorTlType = 0x1cb5c415u; // Scheme23_Vector;

#ifndef Q_NULLPTR
#define Q_NULLPTR NULL
#endif

#if QT_VERSION < 0x050000
const int s_timerMaxInterval = 500; // 0.5 sec. Needed to limit max possible typing time deviation in Qt4 by this value.
#endif

enum TelegramMessageFlags {
TelegramMessageFlagNone = 0,
TelegramMessageFlagUnread = 1 << 0,
Expand Down Expand Up @@ -1290,7 +1280,7 @@ void CTelegramDispatcher::whenContactListChanged(const QVector<quint32> &added,
foreach (const quint32 contact, removed) {
for (int i = 0; i < newContactList.count(); ++i) {
// We can use remove one, because we warranty that there is no duplication
#if QT_VERSION >= 0x050400
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
newContactList.removeOne(contact);
#else
int index = newContactList.indexOf(contact);
Expand All @@ -1313,12 +1303,7 @@ void CTelegramDispatcher::whenContactListChanged(const QVector<quint32> &added,

void CTelegramDispatcher::messageActionTimerTimeout()
{

#if QT_VERSION >= 0x050000
int minTime = s_userTypingActionPeriod;
#else
int minTime = s_timerMaxInterval;
#endif

for (int i = m_contactsMessageActions.count() - 1; i >= 0; --i) {
int remainingTime = m_contactsMessageActions.at(i).typingTime - m_typingUpdateTimer->interval();
Expand Down Expand Up @@ -1648,11 +1633,7 @@ void CTelegramDispatcher::processUpdate(const TLUpdate &update)
TelegramNamespace::MessageAction action = telegramMessageActionToPublicAction(update.action.tlType);

int remainingTime = s_userTypingActionPeriod;
#if QT_VERSION >= 0x050000
remainingTime += m_typingUpdateTimer->remainingTime();
#else
// Missed timer remaining time method can leads to typing time period deviation.
#endif

int index = -1;
if (update.tlType == TLValue::UpdateUserTyping) {
Expand Down Expand Up @@ -2585,12 +2566,7 @@ void CTelegramDispatcher::whenAuthExportedAuthorizationReceived(quint32 dc, quin
void CTelegramDispatcher::ensureTypingUpdateTimer(int interval)
{
if (!m_typingUpdateTimer->isActive()) {
#if QT_VERSION >= 0x050000
m_typingUpdateTimer->start(interval);
#else
Q_UNUSED(interval);
m_typingUpdateTimer->start(s_timerMaxInterval);
#endif
}
}

Expand Down Expand Up @@ -2818,7 +2794,7 @@ void CTelegramDispatcher::clearMainConnection()
void CTelegramDispatcher::clearExtraConnections()
{
foreach (CTelegramConnection *connection, m_extraConnections) {
disconnect(connection, Q_NULLPTR, this, Q_NULLPTR);
disconnect(connection, nullptr, this, nullptr);
connection->deleteLater();
}

Expand Down
6 changes: 0 additions & 6 deletions TelegramQt/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,7 @@ QByteArray Utils::sha1(const QByteArray &data)

QByteArray Utils::sha256(const QByteArray &data)
{
#if QT_VERSION < 0x050000
QByteArray pwdHash(32, Qt::Uninitialized);
SHA256(reinterpret_cast<const uchar*>(data.constData()), static_cast<size_t>(data.size()), reinterpret_cast<uchar*>(pwdHash.data()));
return pwdHash;
#else
return QCryptographicHash::hash(data, QCryptographicHash::Sha256);
#endif
}

QByteArray bnToBinArray(const BIGNUM *n)
Expand Down
9 changes: 5 additions & 4 deletions telegram-qt.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

include(options.pri)

!greaterThan(QT_MAJOR_VERSION, 4) {
error(This project requires Qt5)
}

TEMPLATE = subdirs
SUBDIRS = TelegramQt
SUBDIRS += testApp
Expand All @@ -9,9 +12,7 @@ CONFIG += ordered
contains(options, developer-build) {
SUBDIRS += TelegramQt/tests
SUBDIRS += TelegramQt/generator
greaterThan(QT_MAJOR_VERSION, 4) {
SUBDIRS += TelegramQt/generator-ng
}
SUBDIRS += TelegramQt/generator-ng
}

OTHER_FILES += CMakeLists.txt
4 changes: 0 additions & 4 deletions testApp/CMessageModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,7 @@ int CMessageModel::setMessageMediaData(quint64 messageId, const QVariant &data)
}

m_messages[i].mediaData = data;
#if QT_VERSION < 0x050000
emit dataChanged(index(i, Message), index(i, Message));
#else
emit dataChanged(index(i, Message), index(i, Message), QVector<int>() << Qt::DecorationRole);
#endif
return i;
}

Expand Down
8 changes: 0 additions & 8 deletions testApp/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ MainWindow::MainWindow(QWidget *parent) :

connect(ui->groupChatContactPhone, SIGNAL(textChanged(QString)), SLOT(updateGroupChatAddContactButtonText()));

#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
connect(ui->messagingView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(whenCustomMenuRequested(QPoint)));
connect(ui->contactSearchResult, SIGNAL(customContextMenuRequested(QPoint)), SLOT(onSearchCustomMenuRequested(QPoint)));
#endif

ui->groupChatAddContactForwardMessages->hide();
}
Expand Down Expand Up @@ -573,22 +571,18 @@ void MainWindow::whenCustomMenuRequested(const QPoint &pos)
const SContact *contact = m_contactsModel->contactAt(i);

QAction *a = resendMenu->addAction(CContactModel::getContactName(*contact));
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
connect(a, &QAction::triggered, [=]() {
TelegramNamespace::MessageMediaInfo info;
m_core->getMessageMediaInfo(&info, messageId);
m_core->sendMedia(contact->id(), info);
});
#endif
}
}

for (int i = 0; i < m_contactsModel->rowCount(); ++i) {
const SContact *contact = m_contactsModel->contactAt(i);
QAction *a = forwardMenu->addAction(CContactModel::getContactName(*contact));
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
connect(a, &QAction::triggered, [=]() { m_core->forwardMessage(contact->id(), messageId); });
#endif
}

menu->popup(ui->messagingView->mapToGlobal(pos));
Expand Down Expand Up @@ -616,12 +610,10 @@ void MainWindow::onSearchCustomMenuRequested(const QPoint &pos)
}

QAction *a = menu->addAction(tr("Send a message"));
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
connect(a, &QAction::triggered, [=]() {
setActiveContact(contact->id());
ui->tabWidget->setCurrentWidget(ui->tabMessaging);
});
#endif

menu->popup(ui->contactSearchResult->mapToGlobal(pos));
}
Expand Down
4 changes: 1 addition & 3 deletions testApp/testApp.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += core gui network
QT += core gui widgets network
CONFIG += c++11

TEMPLATE = app
Expand All @@ -9,8 +9,6 @@ LIBS += -lssl -lcrypto -lz
LIBS += -lTelegramQt
LIBS += -L$$OUT_PWD/../TelegramQt

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = testApp
TEMPLATE = app

Expand Down

3 comments on commit df12de3

@barracuda156
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kaffeine Could you say if Qt4-based version is still compatible with the current API?

@Kaffeine
Copy link
Owner Author

@Kaffeine Kaffeine commented on df12de3 Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barracuda156, I had to stop the development because since April 2021 Telegram bans custom clients, and I'd still develop it otherwise. I have no idea if Telegram servers still support scheme-45 but it worked the last time I checked in 2020.

IIUC Telegram bans virtually all users of custom credentials, so do not try this lib with its bundled credentials (appId/appHash) or you'd probably get banned (users had to ask support for unban). See e.g. procxx/kepka#254 (comment) (a fork of Telegram Desktop).

Telegram treats custom API credentials more strictly than official ones. This problem affects all Telegram clients and MTProto libraries: even official client, if you build it with custom API credentials.

Telegram does not ban the phone number associated with the credentials, thus I never got banned with my credentials, and you (probably) won't be banned if you try any client with your credential.

@barracuda156
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kaffeine Thank you for the explanation! It is sad that Telegram tries to prevent using other open source clients, since their own library is just broken for multiple platforms.

P. S. For the context, initially I was interested to get Signal working on older macOS, but Signal does not seem to have any C/C++ implementation at all, so that is off. Telegram was an obvious substitute, but turned out, tdlib is broken for years on all big-endian platforms. There is Tox which should work, I guess, but it is not exactly a replacement for Signal/Telegram.

Please sign in to comment.