You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utilitydialog.cpp 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Copyright (c) 2011-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #if defined(HAVE_CONFIG_H)
  5. #include "config/starwels-config.h"
  6. #endif
  7. #include "utilitydialog.h"
  8. #include "ui_helpmessagedialog.h"
  9. #include "starwelsgui.h"
  10. #include "clientmodel.h"
  11. #include "guiconstants.h"
  12. #include "intro.h"
  13. #include "paymentrequestplus.h"
  14. #include "guiutil.h"
  15. #include "clientversion.h"
  16. #include "init.h"
  17. #include "util.h"
  18. #include <stdio.h>
  19. #include <QCloseEvent>
  20. #include <QLabel>
  21. #include <QRegExp>
  22. #include <QTextTable>
  23. #include <QTextCursor>
  24. #include <QVBoxLayout>
  25. /** "Help message" or "About" dialog box */
  26. HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
  27. QDialog(parent),
  28. ui(new Ui::HelpMessageDialog)
  29. {
  30. ui->setupUi(this);
  31. QString version = tr(PACKAGE_NAME) + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
  32. /* On x86 add a bit specifier to the version so that users can distinguish between
  33. * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambiguous.
  34. */
  35. #if defined(__x86_64__)
  36. version += " " + tr("(%1-bit)").arg(64);
  37. #elif defined(__i386__ )
  38. version += " " + tr("(%1-bit)").arg(32);
  39. #endif
  40. if (about)
  41. {
  42. setWindowTitle(tr("About %1").arg(tr(PACKAGE_NAME)));
  43. /// HTML-format the license message from the core
  44. QString licenseInfo = QString::fromStdString(LicenseInfo());
  45. QString licenseInfoHTML = licenseInfo;
  46. // Make URLs clickable
  47. QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
  48. uri.setMinimal(true); // use non-greedy matching
  49. licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
  50. // Replace newlines with HTML breaks
  51. licenseInfoHTML.replace("\n", "<br>");
  52. ui->aboutMessage->setTextFormat(Qt::RichText);
  53. ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  54. text = version + "\n" + licenseInfo;
  55. ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
  56. ui->aboutMessage->setWordWrap(true);
  57. ui->helpMessage->setVisible(false);
  58. } else {
  59. setWindowTitle(tr("Command-line options"));
  60. QString header = tr("Usage:") + "\n" +
  61. " starwels-qt [" + tr("command-line options") + "] " + "\n";
  62. QTextCursor cursor(ui->helpMessage->document());
  63. cursor.insertText(version);
  64. cursor.insertBlock();
  65. cursor.insertText(header);
  66. cursor.insertBlock();
  67. std::string strUsage = HelpMessage(HMM_STARWELS_QT);
  68. const bool showDebug = gArgs.GetBoolArg("-help-debug", false);
  69. strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
  70. if (showDebug) {
  71. strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS));
  72. }
  73. strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR));
  74. strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString());
  75. strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString());
  76. strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString());
  77. strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN));
  78. strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString());
  79. if (showDebug) {
  80. strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", StarwelsGUI::DEFAULT_UIPLATFORM));
  81. }
  82. QString coreOptions = QString::fromStdString(strUsage);
  83. text = version + "\n" + header + "\n" + coreOptions;
  84. QTextTableFormat tf;
  85. tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
  86. tf.setCellPadding(2);
  87. QVector<QTextLength> widths;
  88. widths << QTextLength(QTextLength::PercentageLength, 35);
  89. widths << QTextLength(QTextLength::PercentageLength, 65);
  90. tf.setColumnWidthConstraints(widths);
  91. QTextCharFormat bold;
  92. bold.setFontWeight(QFont::Bold);
  93. for (const QString &line : coreOptions.split("\n")) {
  94. if (line.startsWith(" -"))
  95. {
  96. cursor.currentTable()->appendRows(1);
  97. cursor.movePosition(QTextCursor::PreviousCell);
  98. cursor.movePosition(QTextCursor::NextRow);
  99. cursor.insertText(line.trimmed());
  100. cursor.movePosition(QTextCursor::NextCell);
  101. } else if (line.startsWith(" ")) {
  102. cursor.insertText(line.trimmed()+' ');
  103. } else if (line.size() > 0) {
  104. //Title of a group
  105. if (cursor.currentTable())
  106. cursor.currentTable()->appendRows(1);
  107. cursor.movePosition(QTextCursor::Down);
  108. cursor.insertText(line.trimmed(), bold);
  109. cursor.insertTable(1, 2, tf);
  110. }
  111. }
  112. ui->helpMessage->moveCursor(QTextCursor::Start);
  113. ui->scrollArea->setVisible(false);
  114. ui->aboutLogo->setVisible(false);
  115. }
  116. }
  117. HelpMessageDialog::~HelpMessageDialog()
  118. {
  119. delete ui;
  120. }
  121. void HelpMessageDialog::printToConsole()
  122. {
  123. // On other operating systems, the expected action is to print the message to the console.
  124. fprintf(stdout, "%s\n", qPrintable(text));
  125. }
  126. void HelpMessageDialog::showOrPrint()
  127. {
  128. #if defined(WIN32)
  129. // On Windows, show a message box, as there is no stderr/stdout in windowed applications
  130. exec();
  131. #else
  132. // On other operating systems, print help text to console
  133. printToConsole();
  134. #endif
  135. }
  136. void HelpMessageDialog::on_okButton_accepted()
  137. {
  138. close();
  139. }
  140. /** "Shutdown" window */
  141. ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
  142. QWidget(parent, f)
  143. {
  144. QVBoxLayout *layout = new QVBoxLayout();
  145. layout->addWidget(new QLabel(
  146. tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "<br /><br />" +
  147. tr("Do not shut down the computer until this window disappears.")));
  148. setLayout(layout);
  149. }
  150. QWidget *ShutdownWindow::showShutdownWindow(StarwelsGUI *window)
  151. {
  152. if (!window)
  153. return nullptr;
  154. // Show a simple window indicating shutdown status
  155. QWidget *shutdownWindow = new ShutdownWindow();
  156. shutdownWindow->setWindowTitle(window->windowTitle());
  157. // Center shutdown window at where main window was
  158. const QPoint global = window->mapToGlobal(window->rect().center());
  159. shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
  160. shutdownWindow->show();
  161. return shutdownWindow;
  162. }
  163. void ShutdownWindow::closeEvent(QCloseEvent *event)
  164. {
  165. event->ignore();
  166. }