17
17
#endif // WIN32
18
18
19
19
#ifdef Q_OS_LINUX
20
+ #include < cassert>
20
21
#include < stdlib.h>
21
22
#include < unistd.h>
22
23
#endif // Q_OS_LINUX
25
26
#include < QDir>
26
27
#include < QFileDialog>
27
28
#include < QFileInfo>
29
+ #include < QPixmap>
28
30
#include < QRegExp>
29
31
#include < QStandardPaths>
30
32
#include < QString>
@@ -44,11 +46,88 @@ std::string GetExecutablePathAsString()
44
46
exe_path[r] = ' \0 ' ;
45
47
return exe_path;
46
48
}
49
+
50
+ fs::path GetUserApplicationsDir ()
51
+ {
52
+ const char * home_dir = getenv (" HOME" );
53
+ if (!home_dir) return fs::path ();
54
+ return fs::path (home_dir) / " .local" / " share" / " applications" ;
55
+ }
56
+
57
+ fs::path GetDesktopFilePath (std::string chain)
58
+ {
59
+ const auto app_dir = GetUserApplicationsDir ();
60
+ if (app_dir.empty ()) return fs::path ();
61
+ if (!chain.empty ()) {
62
+ chain = " _" + chain;
63
+ }
64
+ return app_dir / strprintf (" org.bitcoincore.BitcoinQt%s.desktop" , chain);
65
+ }
66
+
67
+ fs::path GetUserIconsDir ()
68
+ {
69
+ const char * home_dir = getenv (" HOME" );
70
+ if (!home_dir) return fs::path ();
71
+ return fs::path (home_dir) / " .local" / " share" / " icons" ;
72
+ }
73
+
74
+ fs::path GetIconPath (std::string chain)
75
+ {
76
+ const auto icons_dir = GetUserIconsDir ();
77
+ if (icons_dir.empty ()) return fs::path ();
78
+ if (!chain.empty ()) {
79
+ chain = " -" + chain;
80
+ }
81
+ return icons_dir / strprintf (" bitcoin%s.png" , chain);
82
+ }
47
83
#endif // Q_OS_LINUX
48
84
} // namespace
49
85
50
86
namespace GUIUtil {
51
87
88
+ #ifdef Q_OS_LINUX
89
+ bool IntegrateWithDesktopEnvironment (QIcon icon)
90
+ {
91
+ std::string chain = gArgs .GetChainName ();
92
+ assert (chain == CBaseChainParams::MAIN || chain == CBaseChainParams::TESTNET);
93
+ if (chain == CBaseChainParams::MAIN) {
94
+ chain.clear ();
95
+ }
96
+
97
+ const auto icon_path = GetIconPath (chain);
98
+ if (icon_path.empty () || !icon.pixmap (256 ).save (boostPathToQString (icon_path))) return false ;
99
+ const auto exe_path = GetExecutablePathAsString ();
100
+ if (exe_path.empty ()) return false ;
101
+ const auto desktop_file_path = GetDesktopFilePath (chain);
102
+ if (desktop_file_path.empty ()) return false ;
103
+ fsbridge::ofstream desktop_file (desktop_file_path, std::ios_base::out | std::ios_base::trunc );
104
+ if (!desktop_file.good ()) return false ;
105
+
106
+ desktop_file << " [Desktop Entry]\n " ;
107
+ desktop_file << " Type=Application\n " ;
108
+ desktop_file << " Version=1.1\n " ;
109
+ desktop_file << " GenericName=Bitcoin client\n " ;
110
+ desktop_file << " Comment=Bitcoin full node and wallet\n " ;
111
+ desktop_file << strprintf (" Icon=%s\n " , icon_path.stem ().string ());
112
+ desktop_file << strprintf (" TryExec=%s\n " , exe_path);
113
+ desktop_file << " Categories=Network;Office;Finance;\n " ;
114
+ if (chain.empty ()) {
115
+ desktop_file << " Name=" PACKAGE_NAME " \n " ;
116
+ desktop_file << strprintf (" Exec=%s %%u\n " , exe_path);
117
+ desktop_file << " Actions=Testnet;\n " ;
118
+ desktop_file << " [Desktop Action Testnet]\n " ;
119
+ desktop_file << strprintf (" Exec=%s -testnet\n " , exe_path);
120
+ desktop_file << " Name=Testnet mode\n " ;
121
+ } else {
122
+ desktop_file << " Name=" PACKAGE_NAME " - Testnet\n " ;
123
+ desktop_file << strprintf (" Exec=%s -testnet %%u\n " , exe_path);
124
+ }
125
+
126
+ desktop_file.close ();
127
+ return true ;
128
+ }
129
+ #endif // Q_OS_LINUX
130
+
52
131
QString getDefaultDataDirectory ()
53
132
{
54
133
return boostPathToQString (GetDefaultDataDir ());
0 commit comments