diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-08-19 16:22:31 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-08-19 16:36:51 (GMT) |
commit | f416fe2749a959ad26544ead709683d3800059e4 (patch) | |
tree | 2813851a656f98300cba2dd7e1cf47597b19d891 /Swiften | |
parent | b44ed4b36505ece31f29cdd0803af9949463f94b (diff) | |
download | swift-f416fe2749a959ad26544ead709683d3800059e4.zip swift-f416fe2749a959ad26544ead709683d3800059e4.tar.bz2 |
Extract dir providing functionality from application class.
Diffstat (limited to 'Swiften')
15 files changed, 234 insertions, 64 deletions
diff --git a/Swiften/Application/Application.cpp b/Swiften/Application/Application.cpp index d9f4a86..c9706aa 100644 --- a/Swiften/Application/Application.cpp +++ b/Swiften/Application/Application.cpp @@ -7,7 +7,6 @@ #include "Swiften/Application/Application.h" #include <iostream> -#include <boost/filesystem.hpp> #include <stdlib.h> #include "Swiften/Application/ApplicationMessageDisplay.h" @@ -20,23 +19,4 @@ Application::Application(const String& name) : name_(name) { Application::~Application() { } -boost::filesystem::path Application::getSettingsFileName() const { - return getSettingsDir() / "settings"; -} - -boost::filesystem::path Application::getAvatarDir() const { - return getSettingsDir() / "avatars"; -} - -boost::filesystem::path Application::getProfileDir(const String& profile) const { - boost::filesystem::path result(getHomeDir() / profile.getUTF8String()); - try { - boost::filesystem::create_directory(result); - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } - return result; -} - } diff --git a/Swiften/Application/Application.h b/Swiften/Application/Application.h index e6205f1..98e2881 100644 --- a/Swiften/Application/Application.h +++ b/Swiften/Application/Application.h @@ -4,10 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_Application_H -#define SWIFTEN_Application_H - -#include <boost/filesystem.hpp> +#pragma once #include "Swiften/Base/String.h" @@ -19,12 +16,6 @@ namespace Swift { Application(const String& name); virtual ~Application(); - boost::filesystem::path getSettingsFileName() const; - boost::filesystem::path getAvatarDir() const; - virtual boost::filesystem::path getHomeDir() const = 0; - virtual boost::filesystem::path getSettingsDir() const = 0; - boost::filesystem::path getProfileDir(const String& profile) const; - const String& getName() const { return name_; } @@ -35,5 +26,3 @@ namespace Swift { String name_; }; } - -#endif diff --git a/Swiften/Application/ApplicationPathProvider.cpp b/Swiften/Application/ApplicationPathProvider.cpp new file mode 100644 index 0000000..ec19160 --- /dev/null +++ b/Swiften/Application/ApplicationPathProvider.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Application/Application.h" + +#include <boost/filesystem.hpp> +#include <iostream> + +#include "Swiften/Application/ApplicationPathProvider.h" + +namespace Swift { + +ApplicationPathProvider::ApplicationPathProvider(const String& applicationName) : applicationName(applicationName) { +} + +ApplicationPathProvider::~ApplicationPathProvider() { +} + +boost::filesystem::path ApplicationPathProvider::getSettingsFileName() const { + return getSettingsDir() / "settings"; +} + +boost::filesystem::path ApplicationPathProvider::getAvatarDir() const { + return getSettingsDir() / "avatars"; +} + +boost::filesystem::path ApplicationPathProvider::getProfileDir(const String& profile) const { + boost::filesystem::path result(getHomeDir() / profile.getUTF8String()); + try { + boost::filesystem::create_directory(result); + } + catch (const boost::filesystem::filesystem_error& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + } + return result; +} + +} diff --git a/Swiften/Application/ApplicationPathProvider.h b/Swiften/Application/ApplicationPathProvider.h new file mode 100644 index 0000000..ba671ee --- /dev/null +++ b/Swiften/Application/ApplicationPathProvider.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/filesystem.hpp> + +#include "Swiften/Base/String.h" + +namespace Swift { + class ApplicationPathProvider { + public: + ApplicationPathProvider(const String& applicationName); + virtual ~ApplicationPathProvider(); + + boost::filesystem::path getSettingsFileName() const; + boost::filesystem::path getAvatarDir() const; + virtual boost::filesystem::path getHomeDir() const = 0; + virtual boost::filesystem::path getSettingsDir() const = 0; + boost::filesystem::path getProfileDir(const String& profile) const; + + protected: + const String& getApplicationName() const { + return applicationName; + } + + private: + String applicationName; + }; +} diff --git a/Swiften/Application/MacOSXApplicationPathProvider.cpp b/Swiften/Application/MacOSXApplicationPathProvider.cpp new file mode 100644 index 0000000..e679517 --- /dev/null +++ b/Swiften/Application/MacOSXApplicationPathProvider.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Application/MacOSXApplicationPathProvider.h" + +#include <iostream> + +namespace Swift { + +MacOSXApplicationPathProvider::MacOSXApplicationPathProvider(const String& name) : ApplicationPathProvider(name) { +} + +boost::filesystem::path MacOSXApplicationPathProvider::getSettingsDir() const { + try { + boost::filesystem::path result(getHomeDir() / "Library/Application Support" / getApplicationName().getUTF8String()); + } + catch (const boost::filesystem::filesystem_error& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + } + boost::filesystem::create_directory(result); + return result; +} + +boost::filesystem::path MacOSXApplicationPathProvider::getHomeDir() const { + return boost::filesystem::path(getenv("HOME")); +} + +} diff --git a/Swiften/Application/MacOSXApplicationPathProvider.h b/Swiften/Application/MacOSXApplicationPathProvider.h new file mode 100644 index 0000000..c1d86d0 --- /dev/null +++ b/Swiften/Application/MacOSXApplicationPathProvider.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Application/ApplicationPathProvider.h" + +namespace Swift { + class MacOSXApplicationPathProvider : public ApplicationPathProvider { + public: + MacOSXApplicationPathProvider(const String& name); + + virtual boost::filesystem::path getHomeDir() const; + boost::filesystem::path getSettingsDir() const; + }; +} diff --git a/Swiften/Application/Platform/PlatformApplication.h b/Swiften/Application/PlatformApplication.h index 2508fb3..7facbe5 100644 --- a/Swiften/Application/Platform/PlatformApplication.h +++ b/Swiften/Application/PlatformApplication.h @@ -4,8 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_PlatformApplication_H -#define SWIFTEN_PlatformApplication_H +#pragma once #include "Swiften/Base/Platform.h" @@ -16,15 +15,13 @@ namespace Swift { typedef MacOSXApplication PlatformApplication; } #elif defined(SWIFTEN_PLATFORM_WIN32) -#include "Swiften/Application/Windows/WindowsApplication.h" +#include "Swiften/Application/WindowsApplication.h" namespace Swift { typedef WindowsApplication PlatformApplication; } #else -#include "Swiften/Application/Unix/UnixApplication.h" +#include "Swiften/Application/UnixApplication.h" namespace Swift { typedef UnixApplication PlatformApplication; } #endif - -#endif diff --git a/Swiften/Application/PlatformApplicationPathProvider.h b/Swiften/Application/PlatformApplicationPathProvider.h new file mode 100644 index 0000000..e59bb9a --- /dev/null +++ b/Swiften/Application/PlatformApplicationPathProvider.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Base/Platform.h" + +#if defined(SWIFTEN_PLATFORM_MACOSX) +#include "Swiften/Application/MacOSXApplicationPathProvider.h" +namespace Swift { + typedef MacOSXApplicationPathProvider PlatformApplicationPathProvider; +} +#elif defined(SWIFTEN_PLATFORM_WIN32) +#include "Swiften/Application/WindowsApplicationPathProvider.h" +namespace Swift { + typedef WindowsApplicationPathProvider PlatformApplicationPathProvider; +} +#else +#include "Swiften/Application/UnixApplicationPathProvider.h" +namespace Swift { + typedef UnixApplicationPathProvider PlatformApplicationPathProvider; +} +#endif diff --git a/Swiften/Application/SConscript b/Swiften/Application/SConscript index 78b3a34..69e755a 100644 --- a/Swiften/Application/SConscript +++ b/Swiften/Application/SConscript @@ -3,6 +3,7 @@ Import("swiften_env") sources = [ "Application.cpp", "ApplicationMessageDisplay.cpp", + "ApplicationPathProvider.cpp", ] if swiften_env["PLATFORM"] == "darwin" and swiften_env["target"] == "native" : @@ -10,6 +11,11 @@ if swiften_env["PLATFORM"] == "darwin" and swiften_env["target"] == "native" : "MacOSX/MacOSXApplication.cpp", "MacOSX/MacOSXApplicationMessageDisplay.mm", "MacOSX/MacOSXApplicationInitializer.mm", + "MacOSX/MacOSXApplicationPathProvider.cpp", + ] +elif swiften_env["PLATFORM"] == "win32" : + sources += [ + "WindowsApplicationPathProvider.cpp" ] objects = swiften_env.StaticObject(sources) diff --git a/Swiften/Application/UnitTest/ApplicationTest.cpp b/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp index 8be3d4d..7cb277a 100644 --- a/Swiften/Application/UnitTest/ApplicationTest.cpp +++ b/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp @@ -7,22 +7,18 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Swiften/Application/Application.h" -#include "Swiften/Application/Platform/PlatformApplication.h" +#include "Swiften/Application/PlatformApplicationPathProvider.h" using namespace Swift; -class ApplicationTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(ApplicationTest); +class ApplicationPathProviderTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ApplicationPathProviderTest); CPPUNIT_TEST(testGetSettingsDir); CPPUNIT_TEST_SUITE_END(); public: - ApplicationTest() {} - void setUp() { - testling_ = new PlatformApplication("SwiftTest"); + testling_ = new PlatformApplicationPathProvider("SwiftTest"); } void tearDown() { @@ -39,7 +35,7 @@ class ApplicationTest : public CppUnit::TestFixture } private: - Application* testling_; + ApplicationPathProvider* testling_; }; -CPPUNIT_TEST_SUITE_REGISTRATION(ApplicationTest); +CPPUNIT_TEST_SUITE_REGISTRATION(ApplicationPathProviderTest); diff --git a/Swiften/Application/Unix/UnixApplication.h b/Swiften/Application/UnixApplication.h index 56ee0ed..9ec9300 100644 --- a/Swiften/Application/Unix/UnixApplication.h +++ b/Swiften/Application/UnixApplication.h @@ -27,7 +27,7 @@ namespace Swift { } boost::filesystem::path getSettingsDir() const { - boost::filesystem::path result(getHomeDir() / ("." + getName().getLowerCase().getUTF8String())); + boost::filesystem::path result(getHomeDir() / ("." + getApplicationName().getLowerCase().getUTF8String())); try { boost::filesystem::create_directory(result); } diff --git a/Swiften/Application/UnixApplicationPathProvider.h b/Swiften/Application/UnixApplicationPathProvider.h new file mode 100644 index 0000000..04387f7 --- /dev/null +++ b/Swiften/Application/UnixApplicationPathProvider.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Application/ApplicationPathProvider.h" + +#include <iostream> + +namespace Swift { + class UnixApplicationPathProvider : public ApplicationPathProvider { + public: + UnixApplicationPathProvider(const String& name) : ApplicationPathProvider(name) { + } + + 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())); + try { + boost::filesystem::create_directory(result); + } + catch (const boost::filesystem::filesystem_error& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + } + return result; + } + }; +} + +#endif diff --git a/Swiften/Application/Windows/WindowsApplication.h b/Swiften/Application/WindowsApplication.h index fb0f5f1..eda066d 100644 --- a/Swiften/Application/Windows/WindowsApplication.h +++ b/Swiften/Application/WindowsApplication.h @@ -20,20 +20,6 @@ namespace Swift { return &messageDisplay_; } - boost::filesystem::path getSettingsDir() const { - char* appDirRaw = getenv("APPDATA"); - boost::filesystem::path result(boost::filesystem::path(appDirRaw) / getName().getUTF8String()); - boost::filesystem::create_directory(result); - return result; - } - - boost::filesystem::path getHomeDir() const { - //FIXME: This should be My Documents - - char* homeDirRaw = getenv("USERPROFILE"); - return boost::filesystem::path(homeDirRaw); - } - private: NullApplicationMessageDisplay messageDisplay_; }; diff --git a/Swiften/Application/WindowsApplicationPathProvider.h b/Swiften/Application/WindowsApplicationPathProvider.h new file mode 100644 index 0000000..0d6862e --- /dev/null +++ b/Swiften/Application/WindowsApplicationPathProvider.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Application/ApplicationPathProvider.h" + +namespace Swift { + class WindowsApplicationPathProvider : public ApplicationPathProvider { + public: + WindowsApplicationPathProvider(const String& name); + + boost::filesystem::path getSettingsDir() const { + char* appDirRaw = getenv("APPDATA"); + boost::filesystem::path result(boost::filesystem::path(appDirRaw) / getApplicationName().getUTF8String()); + boost::filesystem::create_directory(result); + return result; + } + + boost::filesystem::path getHomeDir() const { + //FIXME: This should be My Documents + + char* homeDirRaw = getenv("USERPROFILE"); + return boost::filesystem::path(homeDirRaw); + } + }; +} diff --git a/Swiften/SConscript b/Swiften/SConscript index 866baa9..3d4d5f6 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -138,7 +138,7 @@ if env["SCONS_STAGE"] == "build" : myenv.StaticLibrary("Swiften", sources + swiften_env["SWIFTEN_OBJECTS"]) env.Append(UNITTEST_SOURCES = [ - File("Application/UnitTest/ApplicationTest.cpp"), + File("Application/UnitTest/ApplicationPathProviderTest.cpp"), File("Avatars/UnitTest/MockAvatarManager.cpp"), File("Avatars/UnitTest/AvatarManagerTest.cpp"), File("Base/UnitTest/IDGeneratorTest.cpp"), |