Gavin Andresen: implementation of autostart on system startup option on Linux
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Fri, 9 Jul 2010 02:11:50 +0000 (02:11 +0000)
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Fri, 9 Jul 2010 02:11:50 +0000 (02:11 +0000)
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@101 1a98c847-1fd6-4fd8-948a-caf3550aa51b

headers.h
init.cpp
serialize.h
ui.cpp
util.cpp

index b53de82..91e9dbe 100644 (file)
--- a/headers.h
+++ b/headers.h
@@ -58,6 +58,7 @@
 #include <boost/bind.hpp>\r
 #include <boost/function.hpp>\r
 #include <boost/filesystem.hpp>\r
+#include <boost/filesystem/fstream.hpp>\r
 #include <boost/algorithm/string.hpp>\r
 #include <boost/interprocess/sync/interprocess_mutex.hpp>\r
 #include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>\r
index 4660ccd..77c1225 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -117,9 +117,86 @@ void SetStartOnSystemStartup(bool fAutoStart)
         CoUninitialize();\r
     }\r
 }\r
+\r
+#elif defined(__WXGTK__)\r
+\r
+//\r
+// Follow the Desktop Application Autostart Spec:\r
+//  http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html\r
+//\r
+\r
+boost::filesystem::path GetAutostartDir()\r
+{\r
+    namespace fs = boost::filesystem;\r
+\r
+    char* pszConfigHome = getenv("XDG_CONFIG_HOME");\r
+    if (pszConfigHome) return fs::path(pszConfigHome) / fs::path("autostart");\r
+    char* pszHome = getenv("HOME");\r
+    if (pszHome) return fs::path(pszHome) / fs::path(".config/autostart");\r
+    return fs::path();\r
+}\r
+\r
+boost::filesystem::path GetAutostartFilePath()\r
+{\r
+    return GetAutostartDir() / boost::filesystem::path("bitcoin.desktop");\r
+}\r
+\r
+bool GetStartOnSystemStartup()\r
+{\r
+    boost::filesystem::ifstream optionFile(GetAutostartFilePath());\r
+    if (!optionFile.good())\r
+        return false;\r
+    // Scan through file for "Hidden=true":\r
+    string line;\r
+    while (!optionFile.eof())\r
+    {\r
+        getline(optionFile, line);\r
+        if (line.find("Hidden") != string::npos &&\r
+            line.find("true") != string::npos)\r
+            return false;\r
+    }\r
+    optionFile.close();\r
+\r
+    return true;\r
+}\r
+\r
+void SetStartOnSystemStartup(bool fAutoStart)\r
+{\r
+    if (!fAutoStart)\r
+    {\r
+        unlink(GetAutostartFilePath().native_file_string().c_str());\r
+    }\r
+    else\r
+    {\r
+        boost::filesystem::create_directories(GetAutostartDir());\r
+\r
+        boost::filesystem::ofstream optionFile(GetAutostartFilePath(), ios_base::out|ios_base::trunc);\r
+        if (!optionFile.good())\r
+        {\r
+            wxMessageBox(_("Cannot write autostart/bitcoin.desktop file"), "Bitcoin");\r
+            return;\r
+        }\r
+        // Write a bitcoin.desktop file to the autostart directory:\r
+        char pszExePath[MAX_PATH+1];\r
+        memset(pszExePath, 0, sizeof(pszExePath));\r
+        readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1);\r
+        optionFile << "[Desktop Entry]\n";\r
+        optionFile << "Type=Application\n";\r
+        optionFile << "Name=Bitcoin\n";\r
+        optionFile << "Exec=" << pszExePath << "\n";\r
+        optionFile << "Terminal=false\n";\r
+        optionFile << "Hidden=false\n";\r
+        optionFile.close();\r
+    }\r
+}\r
 #else\r
+\r
+// TODO: OSX startup stuff; see:\r
+// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html\r
+\r
 bool GetStartOnSystemStartup() { return false; }\r
 void SetStartOnSystemStartup(bool fAutoStart) { }\r
+\r
 #endif\r
 \r
 \r
index 44eeb23..25a6532 100644 (file)
@@ -20,7 +20,7 @@ class CDataStream;
 class CAutoFile;\r
 \r
 static const int VERSION = 300;\r
-static const char* pszSubVer = ".1";\r
+static const char* pszSubVer = ".2";\r
 \r
 \r
 \r
diff --git a/ui.cpp b/ui.cpp
index d6c87f4..51d50e6 100644 (file)
--- a/ui.cpp
+++ b/ui.cpp
@@ -1444,8 +1444,10 @@ COptionsDialog::COptionsDialog(wxWindow* parent) : COptionsDialogBase(parent)
     //m_listBox->Append(_("Test 2"));\r
     m_listBox->SetSelection(0);\r
     SelectPage(0);\r
-#ifndef __WXMSW__\r
-    m_checkBoxMinimizeOnClose->SetLabel(_("&Minimize on close"));\r
+#ifdef __WXGTK__\r
+    m_checkBoxStartOnSystemStartup->SetLabel(_("&Start Bitcoin on window system startup"));\r
+#endif\r
+#ifdef __WXMAC_OSX__\r
     m_checkBoxStartOnSystemStartup->Enable(false); // not implemented yet\r
 #endif\r
 \r
index c09419f..250861f 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -559,9 +559,9 @@ string MyGetSpecialFolderPath(int nFolder, bool fCreate)
 \r
 string GetDefaultDataDir()\r
 {\r
-    // Windows: C:\Documents and Settings\username\Application Data\Appname\r
-    // Mac: ~/Library/Application Support/Appname\r
-    // Unix: ~/.appname\r
+    // Windows: C:\Documents and Settings\username\Application Data\Bitcoin\r
+    // Mac: ~/Library/Application Support/Bitcoin\r
+    // Unix: ~/.bitcoin\r
 #ifdef __WXMSW__\r
     // Windows\r
     return MyGetSpecialFolderPath(CSIDL_APPDATA, true) + "\\Bitcoin";\r