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