From df12de3f5afa3eaec1332f8180509fa325cd1709 Mon Sep 17 00:00:00 2001 From: Alexandr Akulich Date: Tue, 1 Nov 2016 14:15:21 +0500 Subject: [PATCH] Removed Qt4 support --- CMakeLists.txt | 22 ++++++---------------- TelegramQt/CMakeLists.txt | 30 ++++++++---------------------- TelegramQt/CTelegramDispatcher.cpp | 28 ++-------------------------- TelegramQt/Utils.cpp | 6 ------ telegram-qt.pro | 9 +++++---- testApp/CMessageModel.cpp | 4 ---- testApp/MainWindow.cpp | 8 -------- testApp/testApp.pro | 4 +--- 8 files changed, 22 insertions(+), 89 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 920c744a5..0c4a9a956 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,22 +18,12 @@ 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) @@ -41,7 +31,7 @@ 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) diff --git a/TelegramQt/CMakeLists.txt b/TelegramQt/CMakeLists.txt index 7d4e5b90b..e3a493b93 100644 --- a/TelegramQt/CMakeLists.txt +++ b/TelegramQt/CMakeLists.txt @@ -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}) @@ -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} diff --git a/TelegramQt/CTelegramDispatcher.cpp b/TelegramQt/CTelegramDispatcher.cpp index a6c357b34..311c963ea 100644 --- a/TelegramQt/CTelegramDispatcher.cpp +++ b/TelegramQt/CTelegramDispatcher.cpp @@ -30,9 +30,7 @@ using namespace TelegramUtils; #include #include -#if QT_VERSION < 0x048000 #include -#endif #ifdef DEVELOPER_BUILD #include "TLTypesDebug.hpp" @@ -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, @@ -1290,7 +1280,7 @@ void CTelegramDispatcher::whenContactListChanged(const QVector &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); @@ -1313,12 +1303,7 @@ void CTelegramDispatcher::whenContactListChanged(const QVector &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(); @@ -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) { @@ -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 } } @@ -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(); } diff --git a/TelegramQt/Utils.cpp b/TelegramQt/Utils.cpp index 939bde19c..9341132b3 100644 --- a/TelegramQt/Utils.cpp +++ b/TelegramQt/Utils.cpp @@ -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(data.constData()), static_cast(data.size()), reinterpret_cast(pwdHash.data())); - return pwdHash; -#else return QCryptographicHash::hash(data, QCryptographicHash::Sha256); -#endif } QByteArray bnToBinArray(const BIGNUM *n) diff --git a/telegram-qt.pro b/telegram-qt.pro index f6461bc4a..4f15dfcb1 100644 --- a/telegram-qt.pro +++ b/telegram-qt.pro @@ -1,6 +1,9 @@ - include(options.pri) +!greaterThan(QT_MAJOR_VERSION, 4) { + error(This project requires Qt5) +} + TEMPLATE = subdirs SUBDIRS = TelegramQt SUBDIRS += testApp @@ -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 diff --git a/testApp/CMessageModel.cpp b/testApp/CMessageModel.cpp index ca03887a9..901e21c18 100644 --- a/testApp/CMessageModel.cpp +++ b/testApp/CMessageModel.cpp @@ -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() << Qt::DecorationRole); -#endif return i; } diff --git a/testApp/MainWindow.cpp b/testApp/MainWindow.cpp index f40257106..4b5dfa8a7 100644 --- a/testApp/MainWindow.cpp +++ b/testApp/MainWindow.cpp @@ -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(); } @@ -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)); @@ -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)); } diff --git a/testApp/testApp.pro b/testApp/testApp.pro index dfca1d3dd..def051f6a 100644 --- a/testApp/testApp.pro +++ b/testApp/testApp.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui widgets network CONFIG += c++11 TEMPLATE = app @@ -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