Update CMakeLists.txt - play with openssl
[novacoin.git] / src / qt / guiutil.h
1 #ifndef GUIUTIL_H
2 #define GUIUTIL_H
3
4 #include <QString>
5 #include <QObject>
6 #include <QMessageBox>
7 #include <QWidget>
8 #include <QEvent>
9 #include <QTextEdit>
10
11 #include <boost/filesystem.hpp>
12
13 QT_BEGIN_NAMESPACE
14 class QFont;
15 class QLineEdit;
16 class QWidget;
17 class QDateTime;
18 class QUrl;
19 class QAbstractItemView;
20 QT_END_NAMESPACE
21 class SendCoinsRecipient;
22
23 /** Utility functions used by the Bitcoin Qt UI.
24  */
25 namespace GUIUtil
26 {
27      /* Convert QString to OS specific boost path through UTF-8 */
28     boost::filesystem::path qstringToBoostPath(const QString &path);
29      /* Convert OS specific boost path to QString through UTF-8 */
30     QString boostPathToQString(const boost::filesystem::path &path);
31
32     // Create human-readable string from date
33     QString dateTimeStr(const QDateTime &datetime);
34     QString dateTimeStr(qint64 nTime);
35
36     // Render Bitcoin addresses in monospace font
37     QFont bitcoinAddressFont();
38
39     // Set up widgets for address and amounts
40     void setupAddressWidget(QLineEdit *widget, QWidget *parent);
41     void setupAmountWidget(QLineEdit *widget, QWidget *parent);
42
43     // Parse "novacoin:" URI into recipient object, return true on successful parsing
44     // See Bitcoin URI definition discussion here: https://bitcointalk.org/index.php?topic=33490.0
45     bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);
46     bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);
47
48     // HTML escaping for rich text controls
49     QString HtmlEscape(const QString& str, bool fMultiLine=false);
50     QString HtmlEscape(const std::string& str, bool fMultiLine=false);
51
52     /** Copy a field of the currently selected entry of a view to the clipboard. Does nothing if nothing
53         is selected.
54        @param[in] column  Data column to extract from the model
55        @param[in] role    Data role to extract from the model
56        @see  TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
57      */
58     void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
59
60     /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
61         when no suffix is provided by the user.
62
63       @param[in] parent  Parent window (or 0)
64       @param[in] caption Window caption (or empty, for default)
65       @param[in] dir     Starting directory (or empty, to default to documents directory)
66       @param[in] filter  Filter specification such as "Comma Separated Files (*.csv)"
67       @param[out] selectedSuffixOut  Pointer to return the suffix (file type) that was selected (or 0).
68                   Can be useful when choosing the save file format based on suffix.
69      */
70     QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(),
71                                    const QString &dir=QString(), const QString &filter=QString(),
72                                    QString *selectedSuffixOut=0);
73
74     /** Get connection type to call object slot in GUI thread with invokeMethod. The call will be blocking.
75
76        @returns If called from the GUI thread, return a Qt::DirectConnection.
77                 If called from another thread, return a Qt::BlockingQueuedConnection.
78     */
79     Qt::ConnectionType blockingGUIThreadConnection();
80
81     // Determine whether a widget is hidden behind other windows
82     bool isObscured(QWidget *w);
83
84     // Open debug.log
85     void openDebugLogfile();
86     // Open novacoin.conf
87     void openConfigfile();
88     /** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
89       representation if needed. This assures that Qt can word-wrap long tooltip messages.
90       Tooltips longer than the provided size threshold (in characters) are wrapped.
91      */
92     class ToolTipToRichTextFilter : public QObject
93     {
94         Q_OBJECT
95
96     public:
97         explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = 0);
98
99     protected:
100         bool eventFilter(QObject *obj, QEvent *evt);
101
102     private:
103         int size_threshold;
104     };
105
106     bool GetStartOnSystemStartup();
107     bool SetStartOnSystemStartup(bool fAutoStart);
108
109     /** Help message for Bitcoin-Qt, shown with --help. */
110     class HelpMessageBox : public QMessageBox
111     {
112         Q_OBJECT
113
114     public:
115         HelpMessageBox(QWidget *parent = 0);
116
117         /** Show message box or print help message to standard output, based on operating system. */
118         void showOrPrint();
119
120         /** Print help message to console */
121         void printToConsole();
122
123     private:
124         QString header;
125         QString coreOptions;
126         QString uiOptions;
127
128         virtual bool event(QEvent *e)
129         {
130             bool res = QMessageBox::event(e);
131             if (e->type() == QEvent::MouseMove || e->type() == QEvent::MouseButtonPress)
132             {
133                 setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
134                 if (QWidget *textEdit = findChild<QTextEdit *>())
135                 {
136                     textEdit->setMaximumHeight(QWIDGETSIZE_MAX);
137                 }
138             }
139
140             return res;
141         }
142     };
143     /* Convert seconds into a QString with days, hours, mins, secs */
144     QString formatDurationStr(int secs);
145
146 } // namespace GUIUtil
147
148 #endif // GUIUTIL_H