X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fguiutil.cpp;h=24bb95d8a36344ea9f6540f12a241f69bae3863e;hb=d652709abaccff37c1e5ea36a8334ad643809d23;hp=29ef554ac3de7c5d12796b85c23beb092b01aa1b;hpb=cce89ead184c6b61a3361e598cc7553512730a72;p=novacoin.git diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 29ef554..24bb95d 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include QString GUIUtil::dateTimeStr(qint64 nTime) { @@ -49,15 +51,15 @@ void GUIUtil::setupAmountWidget(QLineEdit *widget, QWidget *parent) widget->setAlignment(Qt::AlignRight|Qt::AlignVCenter); } -bool GUIUtil::parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out) +bool GUIUtil::parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) { - if(url->scheme() != QString("bitcoin")) + if(uri.scheme() != QString("bitcoin")) return false; SendCoinsRecipient rv; - rv.address = url->path(); + rv.address = uri.path(); rv.amount = 0; - QList > items = url->queryItems(); + QList > items = uri.queryItems(); for (QList >::iterator i = items.begin(); i != items.end(); i++) { bool fShouldReturnFalse = false; @@ -94,6 +96,20 @@ bool GUIUtil::parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out) return true; } +bool GUIUtil::parseBitcoinURI(QString uri, SendCoinsRecipient *out) +{ + // Convert bitcoin:// to bitcoin: + // + // Cannot handle this later, because bitcoin:// will cause Qt to see the part after // as host, + // which will lowercase it (and thus invalidate the address). + if(uri.startsWith("bitcoin://")) + { + uri.replace(0, 10, "bitcoin:"); + } + QUrl uriInstance(uri); + return parseBitcoinURI(uriInstance, out); +} + QString GUIUtil::HtmlEscape(const QString& str, bool fMultiLine) { QString escaped = Qt::escape(str); @@ -121,3 +137,50 @@ void GUIUtil::copyEntryData(QAbstractItemView *view, int column, int role) QApplication::clipboard()->setText(selection.at(0).data(role).toString()); } } + +QString GUIUtil::getSaveFileName(QWidget *parent, const QString &caption, + const QString &dir, + const QString &filter, + QString *selectedSuffixOut) +{ + QString selectedFilter; + QString myDir; + if(dir.isEmpty()) // Default to user documents location + { + myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + } + else + { + myDir = dir; + } + QString result = QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter); + + /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ + QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); + QString selectedSuffix; + if(filter_re.exactMatch(selectedFilter)) + { + selectedSuffix = filter_re.cap(1); + } + + /* Add suffix if needed */ + QFileInfo info(result); + if(!result.isEmpty()) + { + if(info.suffix().isEmpty() && !selectedSuffix.isEmpty()) + { + /* No suffix specified, add selected suffix */ + if(!result.endsWith(".")) + result.append("."); + result.append(selectedSuffix); + } + } + + /* Return selected suffix if asked to */ + if(selectedSuffixOut) + { + *selectedSuffixOut = selectedSuffix; + } + return result; +} +