Skip to content

Commit b5a9061

Browse files
committed
import src/qml from gui-qml rebased on bitcoin/bitcoin
Specifically commit f5be211f59 from pinheadmz/gui-qml#rebase-qml-cmake aka bitcoin-core/gui-qml#472
1 parent b69a592 commit b5a9061

File tree

231 files changed

+13505
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+13505
-0
lines changed

qml/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/moc_*.cpp

qml/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Bitcoin Core QML GUI
2+
3+
**WARNING: THIS IS EXPERIMENTAL, DO NOT USE BUILDS FROM THIS REPO FOR REAL TRANSACTIONS!**
4+
5+
This directory contains the source code for an experimental Bitcoin Core graphical user interface (GUI) built using the [Qt Quick](https://doc.qt.io/qt-5/qtquick-index.html) framework.
6+
7+
Unsecure CI artifacts are available for local testing of the master branch, avoiding the need to build. These can be found under the [Actions](https://github.com/bitcoin-core/gui-qml/actions?query=branch%3Amain) tab. It is required to have and be logged into a github account in order to download these.
8+
9+
Note: For macOS, the CI artifact binary must be made executable and code-signed before it can
10+
be ran. To make executable and apply a signature, run the following on the unzipped CI artifact:
11+
12+
```
13+
chmod +x ./Downloads/bitcoin-qt && codesign -s - ./Downloads/bitcoin-qt
14+
```
15+
16+
## Goals and Limitations
17+
18+
The current Bitcoin Core GUI has gathered enough technical debt and hacked on features; it is time to begin anew.
19+
This project will start from a clean slate to produce a feature-rich GUI with intuitive user flows and first-class design.
20+
21+
The primary goals of the project can be summed up as follows:
22+
23+
- Implement UX/UI best-practices as documented in the [Bitcoin Design Guide](https://bitcoin.design/guide/)
24+
- Engage with the Bitcoin Design community to implement well-designed features
25+
- Work alongside the Bitcoin Design community to develop an aesthetic GUI
26+
- Develop a mobile-optimized GUI
27+
28+
We must avoid conflicts with the Bitcoin Core repo.
29+
As such, this project will aim to make very few changes outside of the qml directory.
30+
Pull requests must be focused on developing the GUI itself, adding build support,
31+
or improving relevant documentation.
32+
33+
This project will **not** accept pull requests making any significant changes unrelated to the GUI.
34+
35+
## Development Process
36+
37+
This repo is synced with the [Bitcoin Core repo](https://github.com/bitcoin/bitcoin) on a weekly basis, or as needed to resolve conflicts.
38+
39+
Contributions are welcome from all, developers and designers. If you are a new contributor, please read [CONTRIBUTING.md](../../CONTRIBUTING.md).
40+
41+
### Minimum Required Qt Version
42+
43+
All development must adhere to the current upstream Qt Version to minimize our divergence from upstream and avoid costly changes. Review of open PR's must ensure that changes are compatible with this Qt version. Currently, the required version is [Qt 5.15.2](https://github.com/bitcoin-core/gui-qml/blob/main/depends/packages/qt.mk#L2).
44+
45+
As the Qt Version changes upstream, refactoring is allowed to use the now available features.
46+
47+
### Policies
48+
49+
This project has custom policies for development, see:
50+
- [Icon Policy](./doc/icon-policy.md)
51+
- [Translator Comments Policy](./doc/translator-comments.md)
52+
53+
## Compile and Run
54+
55+
The master branch is only guaranteed to work and build on Debian-based systems, Fedora, and macOS.
56+
Support for more systems will be confirmed and documented as the project matures.
57+
58+
### Dependencies
59+
No additional dependencies, besides those in [build-osx.md](../../doc/build-osx.md), are needed for macOS.
60+
61+
Aside from the dependencies listed in [build-unix.md](../../doc/build-unix.md), the following additional dependencies are required to compile:
62+
63+
#### Debian-based systems:
64+
65+
```
66+
sudo apt install qtdeclarative5-dev qtquickcontrols2-5-dev
67+
```
68+
69+
The following runtime dependencies are also required for dynamic builds;
70+
they are not needed for static builds:
71+
72+
```
73+
sudo apt install qml-module-qtquick2 qml-module-qtquick-controls qml-module-qtquick-controls2 qml-module-qtquick-dialogs qml-module-qtquick-layouts qml-module-qtquick-window2 qml-module-qt-labs-settings
74+
```
75+
##### Important:
76+
77+
If you're unable to install the dependencies through your system's package manager, you can instead perform a [depends build](../../depends/README.md).
78+
79+
#### Fedora:
80+
81+
```
82+
sudo dnf install qt5-qtdeclarative-devel qt5-qtquickcontrols qt5-qtquickcontrols2-devel
83+
```
84+
85+
### Build
86+
87+
For instructions on how to build and compile Bitcoin Core, refer to your respective system's build doc.
88+
89+
As long as the required dependencies are installed, the qml GUI will be built.
90+
To ensure that you are in fact building the qml GUI, you can configure with the following option:
91+
92+
```
93+
./configure --with-qml
94+
```
95+
96+
### Run
97+
98+
To run the qml GUI:
99+
```
100+
./src/qt/bitcoin-qt
101+
```

qml/androidnotifier.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <qml/androidnotifier.h>
6+
7+
#include <jni.h>
8+
9+
extern "C" {
10+
JNIEXPORT jboolean JNICALL Java_org_bitcoincore_qt_BitcoinQtService_register(JNIEnv *env, jobject obj);
11+
}
12+
13+
static JavaVM * g_vm = nullptr;
14+
static jobject g_obj;
15+
16+
JNIEXPORT jboolean JNICALL Java_org_bitcoincore_qt_BitcoinQtService_register(JNIEnv * env, jobject obj)
17+
{
18+
env->GetJavaVM(&g_vm);
19+
g_obj = env->NewGlobalRef(obj);
20+
21+
return (jboolean) true;
22+
}
23+
24+
namespace {
25+
26+
JNIEnv* getJNIEnv(JavaVM* javaVM) {
27+
JNIEnv* env;
28+
jint result = javaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
29+
30+
if (result == JNI_EDETACHED) {
31+
javaVM->AttachCurrentThread(&env, nullptr);
32+
} else if (result != JNI_OK) {
33+
// Error handling
34+
return nullptr;
35+
}
36+
37+
return env;
38+
}
39+
40+
}
41+
42+
AndroidNotifier::AndroidNotifier(const NodeModel & node_model,
43+
QObject * parent)
44+
: QObject(parent)
45+
, m_node_model(node_model)
46+
{
47+
QObject::connect(&node_model, &NodeModel::blockTipHeightChanged,
48+
this, &AndroidNotifier::onBlockTipHeightChanged);
49+
QObject::connect(&node_model, &NodeModel::numOutboundPeersChanged,
50+
this, &AndroidNotifier::onNumOutboundPeersChanged);
51+
QObject::connect(&node_model, &NodeModel::pauseChanged,
52+
this, &AndroidNotifier::onPausedChanged);
53+
QObject::connect(&node_model, &NodeModel::verificationProgressChanged,
54+
this, &AndroidNotifier::onVerificationProgressChanged);
55+
}
56+
57+
void AndroidNotifier::onBlockTipHeightChanged()
58+
{
59+
if (g_vm != nullptr) {
60+
JNIEnv * env = getJNIEnv(g_vm);
61+
if (env == nullptr) {
62+
return;
63+
}
64+
jclass clazz = env->GetObjectClass(g_obj);
65+
jmethodID mid = env->GetMethodID(clazz, "updateBlockTipHeight", "(I)V");
66+
env->CallVoidMethod(g_obj, mid, m_node_model.blockTipHeight());
67+
}
68+
}
69+
70+
void AndroidNotifier::onNumOutboundPeersChanged()
71+
{
72+
if (g_vm != nullptr) {
73+
JNIEnv * env = getJNIEnv(g_vm);
74+
if (env == nullptr) {
75+
return;
76+
}
77+
jclass clazz = env->GetObjectClass(g_obj);
78+
jmethodID mid = env->GetMethodID(clazz, "updateNumberOfPeers", "(I)V");
79+
env->CallVoidMethod(g_obj, mid, m_node_model.numOutboundPeers());
80+
}
81+
}
82+
83+
void AndroidNotifier::onVerificationProgressChanged()
84+
{
85+
if (g_vm != nullptr) {
86+
JNIEnv * env = getJNIEnv(g_vm);
87+
if (env == nullptr) {
88+
return;
89+
}
90+
jclass clazz = env->GetObjectClass(g_obj);
91+
jmethodID mid = env->GetMethodID(clazz, "updateVerificationProgress", "(D)V");
92+
env->CallVoidMethod(g_obj, mid, static_cast<jdouble>(m_node_model.verificationProgress()));
93+
}
94+
}
95+
96+
void AndroidNotifier::onPausedChanged()
97+
{
98+
if (g_vm != nullptr) {
99+
JNIEnv * env = getJNIEnv(g_vm);
100+
if (env == nullptr) {
101+
return;
102+
}
103+
jclass clazz = env->GetObjectClass(g_obj);
104+
jmethodID mid = env->GetMethodID(clazz, "updatePaused", "(Z)V");
105+
env->CallVoidMethod(g_obj, mid, static_cast<jboolean>(m_node_model.pause()));
106+
}
107+
}
108+

qml/androidnotifier.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef BITCOIN_QML_ANDROIDNOTIFIER_H
2+
#define BITCOIN_QML_ANDROIDNOTIFIER_H
3+
4+
#include <qml/models/nodemodel.h>
5+
6+
#include <QObject>
7+
#include <jni.h>
8+
9+
class AndroidNotifier : public QObject
10+
{
11+
Q_OBJECT
12+
13+
public:
14+
explicit AndroidNotifier(const NodeModel & node_model, QObject * parent = nullptr);
15+
16+
public Q_SLOTS:
17+
void onBlockTipHeightChanged();
18+
void onNumOutboundPeersChanged();
19+
void onVerificationProgressChanged();
20+
void onPausedChanged();
21+
22+
private:
23+
const NodeModel & m_node_model;
24+
};
25+
26+
#endif // BITCOIN_QML_ANDROIDNOTIFIER_H

qml/appmode.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2022 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_QML_APPMODE_H
6+
#define BITCOIN_QML_APPMODE_H
7+
8+
#include <QObject>
9+
10+
class AppMode : public QObject
11+
{
12+
Q_OBJECT
13+
Q_PROPERTY(bool isDesktop READ isDesktop NOTIFY modeChanged)
14+
Q_PROPERTY(bool isMobile READ isMobile NOTIFY modeChanged)
15+
Q_PROPERTY(bool walletEnabled READ walletEnabled NOTIFY walletEnabledChanged)
16+
Q_PROPERTY(QString state READ state NOTIFY modeChanged)
17+
18+
public:
19+
enum Mode {
20+
DESKTOP,
21+
MOBILE
22+
};
23+
24+
explicit AppMode(Mode mode, bool wallet_enabled)
25+
: m_mode(mode)
26+
, m_wallet_enabled(wallet_enabled)
27+
{
28+
}
29+
30+
bool isMobile() { return m_mode == MOBILE; }
31+
bool isDesktop() { return m_mode == DESKTOP; }
32+
bool walletEnabled() { return m_wallet_enabled; }
33+
QString state()
34+
{
35+
switch (m_mode) {
36+
case MOBILE:
37+
return "MOBILE";
38+
case DESKTOP:
39+
return "DESKTOP";
40+
default:
41+
return "DESKTOP";
42+
}
43+
}
44+
Mode mode() const { return m_mode; }
45+
46+
Q_SIGNALS:
47+
void modeChanged();
48+
void walletEnabledChanged();
49+
50+
private:
51+
const Mode m_mode;
52+
const bool m_wallet_enabled;
53+
};
54+
55+
#endif // BITCOIN_QML_APPMODE_H

0 commit comments

Comments
 (0)