Skip to content

Commit

Permalink
Make GUI and CLI independent from each other
Browse files Browse the repository at this point in the history
  • Loading branch information
paolostivanin committed Mar 8, 2024
1 parent 94736e3 commit c5d8ada
Show file tree
Hide file tree
Showing 48 changed files with 996 additions and 1,009 deletions.
55 changes: 27 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(OTPClient VERSION "3.5.3" LANGUAGES "C")
project(OTPClient VERSION "3.6.0" LANGUAGES "C")
include(GNUInstallDirs)

configure_file("src/common/version.h.in" "version.h")
Expand All @@ -11,6 +11,7 @@ include_directories(${PROJECT_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

option(IS_FLATPAK "Use flatpak app's config folder to store the database" OFF)
option(BUILD_GUI "Build the GTK UI" ON)
option(BUILD_CLI "Build the CLI" ON)

set(CMAKE_C_STANDARD 11)
Expand Down Expand Up @@ -52,7 +53,6 @@ pkg_check_modules(LIBSECRET REQUIRED libsecret-1>=0.20.0)
pkg_check_modules(LIBQRENCODE REQUIRED libqrencode>=4.0.2)

set(COMMON_INCDIRS
${GTK3_INCLUDE_DIRS}
${GCRYPT_INCLUDE_DIRS}
${COTP_INCLUDE_DIRS}
${JANSSON_INCLUDE_DIRS}
Expand All @@ -63,7 +63,6 @@ set(COMMON_INCDIRS
)

set(COMMON_LIBS
${GTK3_LIBRARIES}
${GCRYPT_LIBRARIES}
${COTP_LIBRARIES}
${JANSSON_LIBRARIES}
Expand All @@ -73,34 +72,35 @@ set(COMMON_LIBS
${LIBQRENCODE_LIBRARIES}
)

## GUI START
add_subdirectory(src/gui)
target_link_libraries(${PROJECT_NAME}
${PNG_LIBRARIES}
${ZBAR_LIBRARIES}
${COMMON_LIBS}
)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "otpclient")
if(BUILD_GUI)
add_subdirectory(src/gui)
target_link_libraries(${PROJECT_NAME}
${GTK3_LIBRARIES}
${PNG_LIBRARIES}
${ZBAR_LIBRARIES}
${COMMON_LIBS}
)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "otpclient")

install(TARGETS ${PROJECT_NAME} DESTINATION bin)

install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES data/com.github.paolostivanin.OTPClient.desktop DESTINATION share/applications)

install(FILES data/com.github.paolostivanin.OTPClient.desktop DESTINATION share/applications)
install(FILES
src/gui/ui/otpclient.ui
src/gui/ui/add_popover.ui
src/gui/ui/settings_popover.ui
src/gui/ui/shortcuts.ui
DESTINATION share/otpclient)

install(FILES
src/gui/ui/otpclient.ui
src/gui/ui/add_popover.ui
src/gui/ui/settings_popover.ui
src/gui/ui/shortcuts.ui
DESTINATION share/otpclient)
install(FILES man/otpclient.1.gz DESTINATION share/man/man1)

install(FILES man/otpclient.1.gz DESTINATION share/man/man1)
install(FILES
data/icons/com.github.paolostivanin.OTPClient.svg
data/icons/com.github.paolostivanin.OTPClient-symbolic.svg
DESTINATION share/icons/hicolor/scalable/apps)
endif ()

install(FILES
data/icons/com.github.paolostivanin.OTPClient.svg
data/icons/com.github.paolostivanin.OTPClient-symbolic.svg
DESTINATION share/icons/hicolor/scalable/apps)
## GUI END
## CLI START
if(BUILD_CLI)
add_subdirectory(src/cli)
target_link_libraries(${PROJECT_NAME}-cli
Expand All @@ -112,6 +112,5 @@ if(BUILD_CLI)

install(FILES man/otpclient-cli.1.gz DESTINATION share/man/man1)
endif()
## CLI END

install(FILES data/com.github.paolostivanin.OTPClient.appdata.xml DESTINATION share/metainfo)
install(FILES data/com.github.paolostivanin.OTPClient.appdata.xml DESTINATION share/metainfo)
50 changes: 6 additions & 44 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
set(CLI_HEADER_FILES
main.h
get-data.h
../gui/db-misc.h
../gui/gquarks.h
../gui/file-size.h
../gui/parse-uri.h
../gui/google-migration.pb-c.h
../gui/secret-schema.h
../gui/treeview.h
../gui/liststore-misc.h
../gui/gui-common.h
../gui/add-common.h
../gui/imports.h
../gui/password-cb.h
../gui/get-builder.h
../gui/message-dialogs.h
../common/exports.h
../common/common.h
../common/get-providers-data.h
file(GLOB CLI_HEADER_FILES
*.h
../common/*.h
)

set(CLI_SOURCE_FILES
main.c
get-data.c
exec-action.c
../gui/db-misc.c
../gui/gquarks.c
../gui/file-size.c
../gui/parse-uri.c
../gui/secret-schema.c
../gui/google-migration.pb-c.c
../gui/treeview.c
../gui/liststore-misc.c
../gui/gui-common.c
../gui/add-common.c
../gui/imports.c
../gui/password-cb.c
../gui/get-builder.c
../gui/message-dialogs.c
../common/common.c
../common/andotp.c
../common/aegis.c
../common/freeotp.c
../common/twofas.c
../common/authpro.c
file(GLOB CLI_SOURCE_FILES
*.c
../common/*.c
)

include_directories(
Expand Down
5 changes: 2 additions & 3 deletions src/cli/exec-action.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
#include <termios.h>
#include <libsecret/secret.h>
#include "main.h"
#include "../gui/secret-schema.h"
#include "../common/common.h"
#include "../gui/db-misc.h"
#include "get-data.h"
#include "../common/exports.h"
#include "../common/secret-schema.h"
#include "../common/db-common.h"

#ifndef IS_FLATPAK
static gchar *get_db_path (void);
Expand Down
10 changes: 7 additions & 3 deletions src/cli/get-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include <jansson.h>
#include <cotp.h>
#include <glib/gi18n.h>
#include "../gui/db-misc.h"
#include "../common/common.h"
#include "../common/db-common.h"

static gint compare_strings (const gchar *s1,
const gchar *s2,
Expand Down Expand Up @@ -132,9 +131,14 @@ get_token (json_t *obj,
// counter must be updated every time it is accessed
json_object_set (obj, "counter", json_integer (counter + 1));
GError *err = NULL;
update_and_reload_db (NULL, db_data, FALSE, &err);
update_db (db_data, &err);
if (err != NULL) {
g_printerr ("[ERROR] %s\n", err->message);
} else {
reload_db (db_data, &err);
if (err != NULL) {
g_printerr ("[ERROR] %s\n", err->message);
}
}
}
}
2 changes: 1 addition & 1 deletion src/cli/main.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <glib.h>
#include <gio/gio.h>
#include <gcrypt.h>
#include "version.h"
#include "main.h"
#include "../common/common.h"

static gint handle_local_options (GApplication *application,
GVariantDict *options,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/main.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <glib.h>
#include "../gui/data.h"
#include "../common/db-common.h"

G_BEGIN_DECLS

Expand Down
4 changes: 2 additions & 2 deletions src/common/aegis.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <glib.h>
#include <gio/gio.h>
#include <gcrypt.h>
#include <jansson.h>
#include <time.h>
#include <uuid/uuid.h>
#include "../gui/imports.h"
#include "../gui/gquarks.h"
#include "gquarks.h"
#include "common.h"


Expand Down
4 changes: 1 addition & 3 deletions src/common/andotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#include <jansson.h>
#include <time.h>
#include <glib/gi18n.h>
#include "../gui/file-size.h"
#include "../gui/imports.h"
#include "../gui/gquarks.h"
#include "gquarks.h"
#include "common.h"

// salt and iv are both 12 bytes
Expand Down
3 changes: 1 addition & 2 deletions src/common/authpro.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <glib.h>
#include <gio/gio.h>
#include <gcrypt.h>
#include "gquarks.h"
#include "common.h"
#include "../gui/gquarks.h"
#include "../gui/imports.h"

static GSList *get_otps_from_encrypted_backup (const gchar *path,
const gchar *password,
Expand Down
Loading

0 comments on commit c5d8ada

Please sign in to comment.