1 #include <QApplication>
13 #include <QDoubleValidator>
16 #if QT_VERSION >= 0x050000
21 #include <QTextDocument>
22 #include <QAbstractItemView>
24 #include <QFileDialog>
25 #include <QDesktopServices>
28 #include <boost/filesystem.hpp>
29 #include <boost/filesystem/fstream.hpp>
35 #define _WIN32_WINNT 0x0501
39 #define _WIN32_IE 0x0501
40 #define WIN32_LEAN_AND_MEAN 1
53 return date.date().toString(Qt::SystemLocaleShortDate) + QString(
" ") + date.toString(
"hh:mm");
58 return dateTimeStr(QDateTime::fromTime_t((qint32)nTime));
63 QFont font(
"Monospace");
64 font.setStyleHint(QFont::TypeWriter);
77 QDoubleValidator *amountValidator =
new QDoubleValidator(parent);
78 amountValidator->setDecimals(8);
79 amountValidator->setBottom(0.0);
80 widget->setValidator(amountValidator);
81 widget->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
87 if(!uri.isValid() || uri.scheme() != QString(
"feathercoin"))
94 #if QT_VERSION < 0x050000
95 QList<QPair<QString, QString> > items = uri.queryItems();
97 QUrlQuery uriQuery(uri);
98 QList<QPair<QString, QString> > items = uriQuery.queryItems();
100 for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++)
102 bool fShouldReturnFalse =
false;
103 if (i->first.startsWith(
"req-"))
105 i->first.remove(0, 4);
106 fShouldReturnFalse =
true;
109 if (i->first ==
"label")
111 rv.
label = i->second;
112 fShouldReturnFalse =
false;
114 else if (i->first ==
"amount")
116 if(!i->second.isEmpty())
123 fShouldReturnFalse =
false;
126 if (fShouldReturnFalse)
142 if(uri.startsWith(
"feathercoin://"))
144 uri.replace(0, 14,
"feathercoin:");
146 QUrl uriInstance(uri);
152 #if QT_VERSION < 0x050000
153 QString escaped = Qt::escape(str);
155 QString escaped = str.toHtmlEscaped();
159 escaped = escaped.replace(
"\n",
"<br>\n");
166 return HtmlEscape(QString::fromStdString(str), fMultiLine);
171 if(!view || !view->selectionModel())
173 QModelIndexList selection = view->selectionModel()->selectedRows(column);
175 if(!selection.isEmpty())
178 QApplication::clipboard()->setText(selection.at(0).data(role).toString(), QClipboard::Clipboard);
180 QApplication::clipboard()->setText(selection.at(0).data(role).toString(), QClipboard::Selection);
186 QApplication::clipboard()->setText(str, QClipboard::Clipboard);
187 QApplication::clipboard()->setText(str, QClipboard::Selection);
192 const QString &filter,
193 QString *selectedSuffixOut)
195 QString selectedFilter;
199 #if QT_VERSION < 0x050000
200 myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
202 myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
212 QRegExp filter_re(
".* \\(\\*\\.(.*)[ \\)]");
213 QString selectedSuffix;
214 if(filter_re.exactMatch(selectedFilter))
216 selectedSuffix = filter_re.cap(1);
220 QFileInfo info(result);
221 if(!result.isEmpty())
223 if(info.suffix().isEmpty() && !selectedSuffix.isEmpty())
226 if(!result.endsWith(
"."))
228 result.append(selectedSuffix);
233 if(selectedSuffixOut)
235 *selectedSuffixOut = selectedSuffix;
242 if(QThread::currentThread() != qApp->thread())
244 return Qt::BlockingQueuedConnection;
248 return Qt::DirectConnection;
254 QWidget *atW = QApplication::widgetAt(w->mapToGlobal(p));
255 if (!atW)
return false;
256 return atW->topLevelWidget() == w;
264 &&
checkPoint(QPoint(w->width() - 1, w->height() - 1), w)
265 &&
checkPoint(QPoint(w->width() / 2, w->height() / 2), w));
270 boost::filesystem::path pathDebug =
GetDataDir() /
"debug.log";
273 if (boost::filesystem::exists(pathDebug))
274 QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(pathDebug.string())));
278 QObject(parent), size_threshold(size_threshold)
285 if(evt->type() == QEvent::ToolTipChange)
287 QWidget *widget =
static_cast<QWidget*
>(obj);
288 QString tooltip = widget->toolTip();
289 if(tooltip.size() >
size_threshold && !tooltip.startsWith(
"<qt/>") && !Qt::mightBeRichText(tooltip))
293 tooltip =
"<qt/>" +
HtmlEscape(tooltip,
true);
294 widget->setToolTip(tooltip);
298 return QObject::eventFilter(obj, evt);
302 boost::filesystem::path
static StartupShortcutPath()
304 return GetSpecialFolderPath(CSIDL_STARTUP) /
"Feathercoin.lnk";
310 return boost::filesystem::exists(StartupShortcutPath());
316 boost::filesystem::remove(StartupShortcutPath());
323 IShellLink* psl = NULL;
324 HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,
325 CLSCTX_INPROC_SERVER, IID_IShellLink,
326 reinterpret_cast<void**>(&psl));
332 GetModuleFileName(NULL, pszExePath,
sizeof(pszExePath));
334 TCHAR pszArgs[5] = TEXT(
"-min");
337 psl->SetPath(pszExePath);
338 PathRemoveFileSpec(pszExePath);
339 psl->SetWorkingDirectory(pszExePath);
340 psl->SetShowCmd(SW_SHOWMINNOACTIVE);
341 psl->SetArguments(pszArgs);
345 IPersistFile* ppf = NULL;
346 hres = psl->QueryInterface(IID_IPersistFile,
347 reinterpret_cast<void**>(&ppf));
352 MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().
string().c_str(), -1, pwsz,
MAX_PATH);
354 hres = ppf->Save(pwsz, TRUE);
373 boost::filesystem::path
static GetAutostartDir()
375 namespace fs = boost::filesystem;
377 char* pszConfigHome = getenv(
"XDG_CONFIG_HOME");
378 if (pszConfigHome)
return fs::path(pszConfigHome) /
"autostart";
379 char* pszHome = getenv(
"HOME");
380 if (pszHome)
return fs::path(pszHome) /
".config" /
"autostart";
384 boost::filesystem::path
static GetAutostartFilePath()
386 return GetAutostartDir() /
"feathercoin.desktop";
391 boost::filesystem::ifstream optionFile(GetAutostartFilePath());
392 if (!optionFile.good())
396 while (!optionFile.eof())
398 getline(optionFile, line);
399 if (line.find(
"Hidden") != std::string::npos &&
400 line.find(
"true") != std::string::npos)
411 boost::filesystem::remove(GetAutostartFilePath());
415 memset(pszExePath, 0,
sizeof(pszExePath));
416 if (readlink(
"/proc/self/exe", pszExePath,
sizeof(pszExePath)-1) == -1)
419 boost::filesystem::create_directories(GetAutostartDir());
421 boost::filesystem::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
422 if (!optionFile.good())
425 optionFile <<
"[Desktop Entry]\n";
426 optionFile <<
"Type=Application\n";
427 optionFile <<
"Name=Feathercoin\n";
428 optionFile <<
"Exec=" << pszExePath <<
" -min\n";
429 optionFile <<
"Terminal=false\n";
430 optionFile <<
"Hidden=false\n";
436 #elif defined(Q_OS_MAC)
439 #include <CoreFoundation/CoreFoundation.h>
440 #include <CoreServices/CoreServices.h>
442 LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
443 LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
446 CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, NULL);
447 for(
int i = 0; i < CFArrayGetCount(listSnapshot); i++) {
448 LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i);
449 UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
450 CFURLRef currentItemURL = NULL;
451 LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, NULL);
452 if(currentItemURL && CFEqual(currentItemURL, findUrl)) {
454 CFRelease(currentItemURL);
458 CFRelease(currentItemURL);
466 CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
467 LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
468 LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
474 CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
475 LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
476 LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
478 if(fAutoStart && !foundItem) {
480 LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, NULL, NULL, bitcoinAppUrl, NULL, NULL);
482 else if(!fAutoStart && foundItem) {
484 LSSharedFileListItemRemove(loginItems, foundItem);
498 header = tr(
"Feathercoin-Qt") +
" " + tr(
"version") +
" " +
500 tr(
"Usage:") +
"\n" +
501 " feathercoin-qt [" + tr(
"command-line options") +
"] " +
"\n";
506 " -lang=<lang> " + tr(
"Set language, for example \"de_DE\" (default: system locale)") +
"\n" +
507 " -min " + tr(
"Start minimized") +
"\n" +
508 " -splash " + tr(
"Show splash screen on startup (default: 1)") +
"\n";
510 setWindowTitle(tr(
"Feathercoin-Qt"));
511 setTextFormat(Qt::PlainText);
513 setText(
header + QString(QChar(0x2003)).repeated(50));
521 fprintf(stdout,
"%s", strUsage.toStdString().c_str());
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
static const int MaxAddressLength
Utility functions used by the Bitcoin Qt UI.
void setupAmountWidget(QLineEdit *widget, QWidget *parent)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
HelpMessageBox(QWidget *parent=0)
QString dateTimeStr(const QDateTime &date)
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
bool GetStartOnSystemStartup()
ToolTipToRichTextFilter(int size_threshold, QObject *parent=0)
QString HtmlEscape(const QString &str, bool fMultiLine)
void setupAddressWidget(QLineEdit *widget, QWidget *parent)
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
Base58 entry widget validator.
bool isObscured(QWidget *w)
bool eventFilter(QObject *obj, QEvent *evt)
void setClipboard(const QString &str)
void printToConsole()
Print help message to console.
void showOrPrint()
Show message box or print help message to standard output, based on operating system.
string FormatFullVersion()
static bool parse(int unit, const QString &value, qint64 *val_out)
Parse string to coin amount.
bool checkPoint(const QPoint &p, const QWidget *w)
bool SetStartOnSystemStartup(bool fAutoStart)
std::string HelpMessage()
void copyEntryData(QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
QFont bitcoinAddressFont()