From e49bc0460be4b94904b6e965845fb8f228672379 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sat, 4 Jul 2009 16:40:41 +0200
Subject: Moved platform-specific stuff out of Application.


diff --git a/Swiften/Application/Application.cpp b/Swiften/Application/Application.cpp
index e5c925a..be77e95 100644
--- a/Swiften/Application/Application.cpp
+++ b/Swiften/Application/Application.cpp
@@ -21,20 +21,6 @@ boost::filesystem::path Application::getAvatarDir() const {
 	return getSettingsDir() / "avatars";
 }
 
-boost::filesystem::path Application::getHomeDir() const {
-	// FIXME: Does this work on windows?
-	// No it doesn't, putting alternative paths in for the moment.
-	char* homeDirRaw = getenv("HOME");
-	if (!homeDirRaw) {
-		homeDirRaw = getenv("APPDATA");
-	}
-	if (!homeDirRaw) {
-		homeDirRaw = getenv("USERPROFILE");
-	}
-	boost::filesystem::path homeDir(homeDirRaw);
-	return homeDir;
-}
-
 boost::filesystem::path Application::getProfileDir(const String& profile) const {
 	boost::filesystem::path result(getHomeDir() / profile.getUTF8String());
 	boost::filesystem::create_directory(result);
diff --git a/Swiften/Application/Application.h b/Swiften/Application/Application.h
index a65b1de..20d686c 100644
--- a/Swiften/Application/Application.h
+++ b/Swiften/Application/Application.h
@@ -15,7 +15,7 @@ namespace Swift {
 
 			boost::filesystem::path getSettingsFileName() const;
 			boost::filesystem::path getAvatarDir() const;
-			boost::filesystem::path getHomeDir() const;
+			virtual boost::filesystem::path getHomeDir() const = 0;
 			virtual boost::filesystem::path getSettingsDir() const = 0;
 			boost::filesystem::path getProfileDir(const String& profile) const;
 
diff --git a/Swiften/Application/MacOSX/MacOSXApplication.cpp b/Swiften/Application/MacOSX/MacOSXApplication.cpp
index 1df2bfa..79d7586 100644
--- a/Swiften/Application/MacOSX/MacOSXApplication.cpp
+++ b/Swiften/Application/MacOSX/MacOSXApplication.cpp
@@ -15,4 +15,8 @@ boost::filesystem::path MacOSXApplication::getSettingsDir() const {
 	return result;
 }
 
+boost::filesystem::path MacOSXApplication::getHomeDir() const {
+	return boost::filesystem::path(getenv("HOME"));
+}
+
 }
diff --git a/Swiften/Application/MacOSX/MacOSXApplication.h b/Swiften/Application/MacOSX/MacOSXApplication.h
index 9e77c54..e408ffd 100644
--- a/Swiften/Application/MacOSX/MacOSXApplication.h
+++ b/Swiften/Application/MacOSX/MacOSXApplication.h
@@ -11,6 +11,7 @@ namespace Swift {
 		public:
 			MacOSXApplication(const String& name);
 
+			virtual boost::filesystem::path getHomeDir() const;
 			virtual ApplicationMessageDisplay* getApplicationMessageDisplay();
 			boost::filesystem::path getSettingsDir() const;
 
diff --git a/Swiften/Application/Unix/UnixApplication.h b/Swiften/Application/Unix/UnixApplication.h
index 0b7bf67..d087bd8 100644
--- a/Swiften/Application/Unix/UnixApplication.h
+++ b/Swiften/Application/Unix/UnixApplication.h
@@ -15,6 +15,10 @@ namespace Swift {
 				return  &messageDisplay_;
 			}
 
+			virtual boost::filesystem::path getHomeDir() const {
+				return boost::filesystem::path(getenv("HOME"));
+			}
+
 			boost::filesystem::path getSettingsDir() const {
 				boost::filesystem::path result(getHomeDir() / ("." + getName().getLowerCase().getUTF8String()));
 				boost::filesystem::create_directory(result);
diff --git a/Swiften/Application/Windows/WindowsApplication.h b/Swiften/Application/Windows/WindowsApplication.h
index 9f1abb4..7b9ee74 100644
--- a/Swiften/Application/Windows/WindowsApplication.h
+++ b/Swiften/Application/Windows/WindowsApplication.h
@@ -22,6 +22,14 @@ namespace Swift {
 				return result;
 			}
 
+			boost::filesystem::path Application::getHomeDir() const {
+				char* homeDirRaw = getenv("APPDATA");
+				if (!homeDirRaw) {
+					homeDirRaw = getenv("USERPROFILE");
+				}
+				return boost::filesystem::path(homeDirRaw);
+			}
+
 		private:
 			NullApplicationMessageDisplay messageDisplay_;
 	};
-- 
cgit v0.10.2-6-g49f6