Subject: [PATCH v3 2/2] gnu: Add sqlitebrowser.

From: Foo Chuan Wei <[email-masked]>
Date: Sat, 15 Jan 2022 04:24:59 +0000

* gnu/packages/databases.scm (sqlitebrowser): New variable.
---
Changes relative to PATCH v2:
* Replace old-style inputs with new-style inputs.
* Update copyright year.

 gnu/packages/databases.scm | 92 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 91 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/databases.scm b/gnu/packages/databases.scm
index 4d7b090d03..b089af5e8b 100644
--- a/gnu/packages/databases.scm
+++ b/gnu/packages/databases.scm
@@ -54,7 +54,7 @@
 ;;; Copyright © 2021 Alexandre Hannud Abdo <[email-masked]>
 ;;; Copyright © 2021 Simon Tournier <[email-masked]>
 ;;; Copyright © 2021 jgart <[email-masked]>
-;;; Copyright © 2021 Foo Chuan Wei <[email-masked]>
+;;; Copyright © 2021, 2022 Foo Chuan Wei <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -131,6 +131,7 @@
   #:use-module (gnu packages python-science)
   #:use-module (gnu packages python-web)
   #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages qt)
   #:use-module (gnu packages rdf)
   #:use-module (gnu packages readline)
   #:use-module (gnu packages regex)
@@ -4156,6 +4157,95 @@ with no external dependencies.  The targets are small apps that would
 be blown away by a SQL-DB or an external database server.")
     (license license:expat)))
 
+(define-public sqlitebrowser
+  (package
+    (name "sqlitebrowser")
+    (version "3.12.2")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/sqlitebrowser/sqlitebrowser")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1ljqzcx388mmni8lv9jz5r58alhsjrrqi4nzjnbfki94rn4ray6z"))
+       ;; Remove bundled libraries.
+       (modules '((guix build utils)))
+       (snippet '(delete-file-recursively "libs"))))
+    (build-system cmake-build-system)
+    (arguments
+     `(#:configure-flags '("-DENABLE_TESTING=ON"
+                           ;; Force the use of non-bundled libraries.
+                           "-DFORCE_INTERNAL_QSCINTILLA=OFF"
+                           "-DFORCE_INTERNAL_QHEXEDIT=OFF"
+                           "-DFORCE_INTERNAL_QCUSTOMPLOT=OFF")
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'fix-build
+           (lambda* (#:key inputs #:allow-other-keys)
+             (substitute* "CMakeLists.txt"
+               (("^    find_package\\(QScintilla 2.8.10 QUIET\\)" all)
+                (string-append
+                  all "\n"
+                  "    set(QSCINTILLA_FOUND TRUE)\n"
+                  "    set(QSCINTILLA_INCLUDE_DIR "
+                  (assoc-ref inputs "qscintilla") "/include)"))
+               (("^    find_package\\(QHexEdit\\)" all)
+                (string-append
+                  all "\n"
+                  "    set(QHexEdit_FOUND TRUE)\n"
+                  "    set(QHexEdit_INCLUDE_DIR "
+                  (assoc-ref inputs "qhexedit") "/include)"))
+               (("^set\\(JSON_DIR libs/json\\)")
+                (string-append "set(JSON_DIR "
+                               (assoc-ref inputs "json-modern-cxx") "/include)"))
+               (("^add_subdirectory\\(\\$\\{JSON_DIR\\}\\)")  ; No need to build.
+                ""))
+
+             (substitute* '("src/EditDialog.cpp"
+                            "src/ExportDataDialog.cpp"
+                            "src/RemoteCommitsModel.h"
+                            "src/RemoteDock.cpp"
+                            "src/RemoteLocalFilesModel.h"
+                            "src/RemoteModel.h"
+                            "src/RemoteNetwork.cpp"
+                            "src/RemotePushDialog.cpp"
+                            "src/sqlitedb.cpp"
+                            "src/sqlitetablemodel.cpp")
+               (("^#include <json.hpp>")
+                "#include <nlohmann/json.hpp>"))
+
+             ;; Fix compilation error:
+             ;; "no matching function for call to ‘input_adapter(const QByteArray&)’"
+             (substitute* "src/EditDialog.cpp"
+               (("json::parse\\(cellData, nullptr, false\\)")
+                "json::parse(cellData.toStdString(), nullptr, false)"))
+             (substitute* '("src/RemoteDock.cpp"
+                            "src/RemotePushDialog.cpp")
+               (("json::parse\\(reply, nullptr, false\\)")
+                "json::parse(reply.toStdString(), nullptr, false)"))
+             (substitute* "src/RemoteNetwork.cpp"
+               (("json::parse\\(reply->readAll\\(\\), nullptr, false\\)")
+                "json::parse((reply->readAll()).toStdString(), nullptr, false)")))))))
+    (inputs
+     (list json-modern-cxx
+           qcustomplot
+           qhexedit
+           qscintilla
+           qtbase-5
+           sqlite))
+    (native-inputs (list qttools))
+    (home-page "https://sqlitebrowser.org")
+    (synopsis "GUI editor for SQLite databases")
+    (description
+     "DB Browser for SQLite (DB4S) is a visual tool to create, design, and edit
+database files compatible with SQLite.  DB4S is for users and developers who
+want to create, search, and edit databases using a familiar spreadsheet-like
+interface, without needing to learn complicated SQL commands.")
+    ;; Dual licensing.
+    (license (list license:gpl3+ license:mpl2.0))))
+
 (define-public sequeler
   (package
     (name "sequeler")
-- 
2.25.1