Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation browser, improved error messages #123

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ feather_autogen/
feather.cbp
src/config-feather.h
src/assets_tor.qrc
src/assets_docs.qrc
feather.AppDir/*
src/assets/tor/*
src/assets/docs/*
!src/assets/tor/.gitkeep
!src/assets/docs/.gitkeep
contrib/installers/windows/setup.nsi
githash.txt
guix/guix-build-*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "src/third-party/polyseed"]
path = src/third-party/polyseed
url = https://github.com/tevador/polyseed.git
[submodule "external/feather-docs"]
path = external/feather-docs
url = https://github.com/feather-wallet/feather-docs.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ if(UNIX AND NOT APPLE)
endif()
endif()

include(GenerateDocs)
include(TorQrcGenerator)

# To build Feather with embedded (and static) Tor, pass CMake -DTOR_DIR=/path/to/tor/
Expand Down
20 changes: 20 additions & 0 deletions cmake/GenerateDocs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
message(STATUS "Generating docs")

find_package(Python3 COMPONENTS Interpreter)

if(Python3_Interpreter_FOUND)
execute_process(COMMAND python3 contrib/docs/generate.py
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

FILE(GLOB DOCS LIST_DIRECTORIES false "src/assets/docs/*")

foreach(FILE ${DOCS})
cmake_path(GET FILE FILENAME FILE_REL)
list(APPEND QRC_LIST " <file alias=\"${FILE_REL}\">${FILE}</file>")
endforeach()

list(JOIN QRC_LIST "\n" QRC_DATA)
configure_file("cmake/assets_docs.qrc" "${CMAKE_CURRENT_SOURCE_DIR}/src/assets_docs.qrc")
else()
message(WARNING "No Python3 interpreter, skipping docs.")
endif()
5 changes: 5 additions & 0 deletions cmake/assets_docs.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/docs">
@QRC_DATA@
</qresource>
</RCC>
63 changes: 63 additions & 0 deletions contrib/docs/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
import glob

DOCS_DIR = "external/feather-docs/content/_guides"
OUT_DIR = "src/assets/docs"

CATEGORY_MAP = {
"getting-started": "1. Getting started",
"howto": "2. How to",
"faq": "3. Faq",
"advanced": "4. Advanced",
"troubleshooting": "5. Troubleshooting",
"help": "6. Help",
}

if not os.path.isdir(DOCS_DIR):
print("feather-docs submodule not found. Run `git submodule update --init --recursive`")
exit(1)

outfiles = glob.glob(f"{OUT_DIR}/*.md")
for file in outfiles:
os.remove(file)

files = glob.glob(f"{DOCS_DIR}/*.md")

for file in files:
with open(file) as f:
doc = f.read()

if not doc:
continue

# yaml frontmatter missing
if doc.count("---") < 2:
continue

_, front, body = doc.split("---", 2)
front = {x: y.strip(" \"") for (x, y) in [x.split(':', 1) for x in front.splitlines()[1:]]}

if not all((x in front) for x in ['category', 'nav_title']):
continue

if front['category'] not in CATEGORY_MAP:
continue

title = front['nav_title'].replace("(", "\\(").replace(")", "\\)")

# We use this format to insert metadata while preventing it from showing up in QTextBrowser
# This is easier than adding item tags to .qrc files and parsing the XML
# We need to be able to setSource on a resource directly, otherwise history doesn't work
docString = f"""
[nav_title]: # ({title})
[category]: # ({CATEGORY_MAP[front['category']]})

## {front['title']}
{body}
"""

_, filename = file.rsplit('/', 1)

with open(f"{OUT_DIR}/{filename}", 'w') as f:
print(filename)
f.write(docString)
1 change: 1 addition & 0 deletions external/feather-docs
Submodule feather-docs added at 02da18
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (CHECK_UPDATES)
add_subdirectory(openpgp)
endif()

qt_add_resources(RESOURCES assets.qrc assets_tor.qrc)
qt_add_resources(RESOURCES assets.qrc assets_tor.qrc assets_docs.qrc)

# Compile source files (.h/.cpp)
file(GLOB SOURCE_FILES
Expand Down
8 changes: 4 additions & 4 deletions src/CalcWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ void CalcWidget::initComboBox() {
QList<QString> cryptoKeys = appData()->prices.markets.keys();
QList<QString> fiatKeys = appData()->prices.rates.keys();

QStringList enabledCrypto = config()->get(Config::cryptoSymbols).toStringList();
QStringList enabledCrypto = conf()->get(Config::cryptoSymbols).toStringList();
QStringList filteredCryptoKeys;
for (const auto& symbol : cryptoKeys) {
if (enabledCrypto.contains(symbol)) {
filteredCryptoKeys.append(symbol);
}
}

QStringList enabledFiat = config()->get(Config::fiatSymbols).toStringList();
auto preferredFiat = config()->get(Config::preferredFiatCurrency).toString();
QStringList enabledFiat = conf()->get(Config::fiatSymbols).toStringList();
auto preferredFiat = conf()->get(Config::preferredFiatCurrency).toString();
if (!enabledFiat.contains(preferredFiat) && fiatKeys.contains(preferredFiat)) {
enabledFiat.append(preferredFiat);
config()->set(Config::fiatSymbols, enabledFiat);
conf()->set(Config::fiatSymbols, enabledFiat);
}
QStringList filteredFiatKeys;
for (const auto &symbol : fiatKeys) {
Expand Down
7 changes: 0 additions & 7 deletions src/CalcWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand Down
10 changes: 4 additions & 6 deletions src/CoinsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,24 +211,22 @@ void CoinsWidget::onSweepOutputs() {

QString keyImage = coin->keyImage();
if (!coin->keyImageKnown()) {
QMessageBox::warning(this, "Unable to sweep outputs", "Unable to create transaction: selected output has unknown key image");
Utils::showError(this, "Unable to sweep outputs", "Selected output has unknown key image");
return;
}

if (coin->spent()) {
QMessageBox::warning(this, "Unable to sweep outputs", "Unable to create transaction: selected output was already spent");
Utils::showError(this, "Unable to sweep outputs", "Selected output was already spent");
return;
}

if (coin->frozen()) {
QMessageBox::warning(this, "Unable to sweep outputs", "Unable to create transaction: selected output is frozen.\n\n"
"Thaw the selected output(s) before spending.");
Utils::showError(this, "Unable to sweep outputs", "Selected output is frozen", {"Thaw the selected output(s) before spending"}, "freeze_thaw_outputs");
return;
}

if (!coin->unlocked()) {
QMessageBox::warning(this, "Unable to sweep outputs", "Unable to create transaction: selected output is locked.\n\n"
"Wait until the output has reached the required number of confirmation before spending.");
Utils::showError(this, "Unable to sweep outputs", "Selected output is locked", {"Wait until the output has reached the required number of confirmation before spending."});
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/ContactsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void ContactsWidget::newContact(QString address, QString name)

bool addressValid = WalletManager::addressValid(address, m_wallet->nettype());
if (!addressValid) {
QMessageBox::warning(this, "Invalid address", "Invalid address");
Utils::showError(this, "Unable to add contact", "Invalid address", {"Use 'Tools -> Address checker' to check if the address is valid."}, "add_contact");
return;
}

Expand All @@ -141,12 +141,12 @@ void ContactsWidget::newContact(QString address, QString name)
});

if (address == address_entry) {
QMessageBox::warning(this, "Unable to add contact", "Duplicate address");
Utils::showError(this, "Unable to add contact", "Address already exists in contacts", {}, "add_contact");
ui->contacts->setCurrentIndex(m_model->index(i,0)); // Highlight duplicate address
return;
}
if (name == name_entry) {
QMessageBox::warning(this, "Unable to add contact", "Duplicate label");
Utils::showError(this, "Unable to add contact", "Label already exists in contacts", {}, "add_contact");
this->newContact(address, name);
return;
}
Expand Down
14 changes: 7 additions & 7 deletions src/HistoryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ HistoryWidget::HistoryWidget(Wallet *wallet, QWidget *parent)

connect(ui->btn_moreInfo, &QPushButton::clicked, this, &HistoryWidget::showSyncNoticeMsg);
connect(ui->btn_close, &QPushButton::clicked, [this]{
config()->set(Config::showHistorySyncNotice, false);
conf()->set(Config::showHistorySyncNotice, false);
ui->syncNotice->hide();
});

connect(m_wallet, &Wallet::walletRefreshed, this, &HistoryWidget::onWalletRefreshed);

ui->syncNotice->setVisible(config()->get(Config::showHistorySyncNotice).toBool());
ui->syncNotice->setVisible(conf()->get(Config::showHistorySyncNotice).toBool());
ui->history->setHistoryModel(m_model);

// Load view state
QByteArray historyViewState = QByteArray::fromBase64(config()->get(Config::GUI_HistoryViewState).toByteArray());
QByteArray historyViewState = QByteArray::fromBase64(conf()->get(Config::GUI_HistoryViewState).toByteArray());
if (!historyViewState.isEmpty()) {
ui->history->setViewState(historyViewState);
}
Expand Down Expand Up @@ -109,8 +109,8 @@ void HistoryWidget::onResendTransaction() {
void HistoryWidget::resetModel()
{
// Save view state
config()->set(Config::GUI_HistoryViewState, ui->history->viewState().toBase64());
config()->sync();
conf()->set(Config::GUI_HistoryViewState, ui->history->viewState().toBase64());
conf()->sync();

ui->history->setModel(nullptr);
}
Expand Down Expand Up @@ -164,8 +164,8 @@ void HistoryWidget::copy(copyField field) {
case copyField::Description:
return tx->description();
case copyField::Date:
return tx->timestamp().toString(QString("%1 %2").arg(config()->get(Config::dateFormat).toString(),
config()->get(Config::timeFormat).toString()));
return tx->timestamp().toString(QString("%1 %2").arg(conf()->get(Config::dateFormat).toString(),
conf()->get(Config::timeFormat).toString()));
case copyField::Amount:
return WalletManager::displayAmount(tx->balanceDelta());
default:
Expand Down
Loading