Skip to content

Commit

Permalink
make qrcodegen optional wow!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
ouwou committed Jul 10, 2023
1 parent b5d85f4 commit 2295559
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ option(USE_LIBHANDY "Enable features that require libhandy (default)" ON)
option(ENABLE_VOICE "Enable voice suppport" ON)
option(USE_KEYCHAIN "Store the token in the keychain (default)" ON)
option(ENABLE_NOTIFICATION_SOUNDS "Enable notification sounds (default)" ON)
option(ENABLE_QRCODE_LOGIN "Enable QR code login (default)" ON)

find_package(nlohmann_json REQUIRED)
find_package(CURL)
Expand Down Expand Up @@ -61,11 +62,14 @@ target_include_directories(abaddon PUBLIC ${ZLIB_INCLUDE_DIRS})
target_include_directories(abaddon PUBLIC ${SQLite3_INCLUDE_DIRS})
target_include_directories(abaddon PUBLIC ${NLOHMANN_JSON_INCLUDE_DIRS})

add_library(qrcodegen subprojects/qrcodegen/cpp/qrcodegen.hpp subprojects/qrcodegen/cpp/qrcodegen.cpp)
target_include_directories(qrcodegen PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/subprojects/qrcodegen/cpp")
target_link_libraries(abaddon qrcodegen)
if (ENABLE_QRCODE_LOGIN)
add_library(qrcodegen subprojects/qrcodegen/cpp/qrcodegen.hpp subprojects/qrcodegen/cpp/qrcodegen.cpp)
target_include_directories(qrcodegen PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/subprojects/qrcodegen/cpp")
target_link_libraries(abaddon qrcodegen)

target_include_directories(abaddon PUBLIC "subprojects/qrcodegen/cpp")
target_include_directories(abaddon PUBLIC "subprojects/qrcodegen/cpp")
target_compile_definitions(abaddon PRIVATE WITH_QRLOGIN)
endif ()

target_precompile_headers(abaddon PRIVATE <gtkmm.h> src/abaddon.hpp src/util.hpp)

Expand Down
2 changes: 2 additions & 0 deletions src/abaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ void Abaddon::ActionSetToken() {
}

void Abaddon::ActionLoginQR() {
#ifdef WITH_QRLOGIN
RemoteAuthDialog dlg(*m_main_window);
auto response = dlg.run();
if (response == Gtk::RESPONSE_OK) {
Expand All @@ -847,6 +848,7 @@ void Abaddon::ActionLoginQR() {
ActionConnect();
}
m_main_window->UpdateMenus();
#endif
}

void Abaddon::ActionChannelOpened(Snowflake id, bool expand_to) {
Expand Down
8 changes: 8 additions & 0 deletions src/remoteauth/remoteauthclient.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#ifdef WITH_QRLOGIN

// clang-format off

#include "remoteauthclient.hpp"
#include "http.hpp"
#include <nlohmann/json.hpp>
#include <spdlog/fmt/bin_to_hex.h>

// clang-format on

RemoteAuthClient::RemoteAuthClient()
: m_ws("remote-auth-ws")
, m_log(spdlog::get("remote-auth")) {
Expand Down Expand Up @@ -341,3 +347,5 @@ RemoteAuthClient::type_signal_token RemoteAuthClient::signal_token() {
RemoteAuthClient::type_signal_error RemoteAuthClient::signal_error() {
return m_signal_error;
}

#endif
9 changes: 9 additions & 0 deletions src/remoteauth/remoteauthclient.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#pragma once

#ifdef WITH_QRLOGIN

// clang-format off

#include <string>
#include <queue>
#include <spdlog/logger.h>
#include "ssl.hpp"
#include "discord/waiter.hpp"
#include "discord/websocket.hpp"

// clang-format on

class RemoteAuthClient {
public:
RemoteAuthClient();
Expand Down Expand Up @@ -84,3 +91,5 @@ class RemoteAuthClient {
type_signal_token m_signal_token;
type_signal_error m_signal_error;
};

#endif
8 changes: 8 additions & 0 deletions src/remoteauth/remoteauthdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifdef WITH_QRLOGIN

// clang-format off

#include "remoteauthdialog.hpp"
#include <qrcodegen.hpp>

// clang-format on

RemoteAuthDialog::RemoteAuthDialog(Gtk::Window &parent)
: Gtk::Dialog("Login with QR Code", parent, true)
, m_layout(Gtk::ORIENTATION_VERTICAL)
Expand Down Expand Up @@ -122,3 +128,5 @@ void RemoteAuthDialog::OnError(const std::string &error) {
Abaddon::Get().ShowConfirm(error, dynamic_cast<Gtk::Window *>(get_toplevel()));
response(Gtk::RESPONSE_CANCEL);
}

#endif
9 changes: 9 additions & 0 deletions src/remoteauth/remoteauthdialog.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#pragma once

#ifdef WITH_QRLOGIN

// clang-format off

#include <gtkmm/dialog.h>
#include "remoteauthclient.hpp"

// clang-format on

class RemoteAuthDialog : public Gtk::Dialog {
public:
RemoteAuthDialog(Gtk::Window &parent);
Expand All @@ -27,3 +34,5 @@ class RemoteAuthDialog : public Gtk::Dialog {

std::string m_token;
};

#endif
6 changes: 6 additions & 0 deletions src/windows/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ void MainWindow::OnDiscordSubmenuPopup() {
m_menu_discord_connect.set_sensitive(!token.empty() && !discord_active);
m_menu_discord_disconnect.set_sensitive(discord_active);
m_menu_discord_set_token.set_sensitive(!discord_active);
#ifdef WITH_QRLOGIN
m_menu_discord_login_qr.set_sensitive(!discord_active);
#endif
m_menu_discord_set_status.set_sensitive(discord_active);
}

Expand Down Expand Up @@ -249,6 +251,10 @@ void MainWindow::SetupMenu() {
m_menu_discord_disconnect.set_sensitive(false);
m_menu_discord_set_token.set_label("Set Token");
m_menu_discord_login_qr.set_label("Login with QR Code");
#ifndef WITH_QRLOGIN
m_menu_discord_login_qr.set_sensitive(false);
m_menu_discord_login_qr.set_tooltip_text("Not compiled with support");
#endif
m_menu_discord_set_status.set_label("Set Status");
m_menu_discord_set_status.set_sensitive(false);
m_menu_discord_add_recipient.set_label("Add user to DM");
Expand Down

0 comments on commit 2295559

Please sign in to comment.