Changeset View
Changeset View
Standalone View
Standalone View
src/qt/guiutil.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
#include <QMouseEvent> | #include <QMouseEvent> | ||||
#include <QProgressDialog> | #include <QProgressDialog> | ||||
#include <QSettings> | #include <QSettings> | ||||
#include <QTextDocument> // for Qt::mightBeRichText | #include <QTextDocument> // for Qt::mightBeRichText | ||||
#include <QThread> | #include <QThread> | ||||
#include <QUrlQuery> | #include <QUrlQuery> | ||||
#if defined(Q_OS_MAC) | #if defined(Q_OS_MAC) | ||||
#pragma GCC diagnostic push | |||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |||||
#include <CoreServices/CoreServices.h> | |||||
void ForceActivation(); | void ForceActivation(); | ||||
#endif | #endif | ||||
namespace GUIUtil { | namespace GUIUtil { | ||||
QString dateTimeStr(const QDateTime &date) { | QString dateTimeStr(const QDateTime &date) { | ||||
return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + | return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + | ||||
▲ Show 20 Lines • Show All 633 Lines • ▼ Show 20 Lines | if (!fAutoStart) { | ||||
<< strprintf(" -min -chain=%s\n", chain); | << strprintf(" -min -chain=%s\n", chain); | ||||
optionFile << "Terminal=false\n"; | optionFile << "Terminal=false\n"; | ||||
optionFile << "Hidden=false\n"; | optionFile << "Hidden=false\n"; | ||||
optionFile.close(); | optionFile.close(); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
#elif defined(Q_OS_MAC) | |||||
// based on: | |||||
// https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m | |||||
// NB: caller must release returned ref if it's not NULL | |||||
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, | |||||
CFURLRef findUrl); | |||||
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, | |||||
CFURLRef findUrl) { | |||||
LSSharedFileListItemRef foundItem = nullptr; | |||||
// loop through the list of startup items and try to find the bitcoin app | |||||
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, nullptr); | |||||
for (int i = 0; !foundItem && i < CFArrayGetCount(listSnapshot); ++i) { | |||||
LSSharedFileListItemRef item = | |||||
(LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i); | |||||
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | | |||||
kLSSharedFileListDoNotMountVolumes; | |||||
CFURLRef currentItemURL = nullptr; | |||||
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && \ | |||||
MAC_OS_X_VERSION_MAX_ALLOWED >= 10100 | |||||
if (&LSSharedFileListItemCopyResolvedURL) { | |||||
currentItemURL = LSSharedFileListItemCopyResolvedURL( | |||||
item, resolutionFlags, nullptr); | |||||
} | |||||
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \ | |||||
MAC_OS_X_VERSION_MIN_REQUIRED < 10100 | |||||
else { | |||||
LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, | |||||
nullptr); | |||||
} | |||||
#endif | |||||
#else | |||||
LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, | |||||
nullptr); | |||||
#endif | |||||
if (currentItemURL && CFEqual(currentItemURL, findUrl)) { | |||||
// found | |||||
CFRetain(foundItem = item); | |||||
} | |||||
if (currentItemURL) { | |||||
CFRelease(currentItemURL); | |||||
} | |||||
} | |||||
CFRelease(listSnapshot); | |||||
return foundItem; | |||||
} | |||||
bool GetStartOnSystemStartup() { | |||||
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | |||||
LSSharedFileListRef loginItems = LSSharedFileListCreate( | |||||
nullptr, kLSSharedFileListSessionLoginItems, nullptr); | |||||
LSSharedFileListItemRef foundItem = | |||||
findStartupItemInList(loginItems, bitcoinAppUrl); | |||||
// findStartupItemInList retains the item it returned, need to release | |||||
if (foundItem) { | |||||
CFRelease(foundItem); | |||||
} | |||||
CFRelease(loginItems); | |||||
CFRelease(bitcoinAppUrl); | |||||
return foundItem; | |||||
} | |||||
bool SetStartOnSystemStartup(bool fAutoStart) { | |||||
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | |||||
LSSharedFileListRef loginItems = LSSharedFileListCreate( | |||||
nullptr, kLSSharedFileListSessionLoginItems, nullptr); | |||||
LSSharedFileListItemRef foundItem = | |||||
findStartupItemInList(loginItems, bitcoinAppUrl); | |||||
if (fAutoStart && !foundItem) { | |||||
// add bitcoin app to startup item list | |||||
LSSharedFileListInsertItemURL(loginItems, | |||||
kLSSharedFileListItemBeforeFirst, nullptr, | |||||
nullptr, bitcoinAppUrl, nullptr, nullptr); | |||||
} else if (!fAutoStart && foundItem) { | |||||
// remove item | |||||
LSSharedFileListItemRemove(loginItems, foundItem); | |||||
} | |||||
// findStartupItemInList retains the item it returned, need to release | |||||
if (foundItem) { | |||||
CFRelease(foundItem); | |||||
} | |||||
CFRelease(loginItems); | |||||
CFRelease(bitcoinAppUrl); | |||||
return true; | |||||
} | |||||
#pragma GCC diagnostic pop | |||||
#else | #else | ||||
bool GetStartOnSystemStartup() { | bool GetStartOnSystemStartup() { | ||||
return false; | return false; | ||||
} | } | ||||
bool SetStartOnSystemStartup(bool fAutoStart) { | bool SetStartOnSystemStartup(bool fAutoStart) { | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines |