From dc951ebf7e4ab6fce39f16687be1e93f8140b71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 9 Oct 2010 18:32:50 +0200 Subject: Moved Application from Swiften into SwifTools. diff --git a/Slimber/CLI/SConscript b/Slimber/CLI/SConscript index b939326..50aafc5 100644 --- a/Slimber/CLI/SConscript +++ b/Slimber/CLI/SConscript @@ -2,6 +2,7 @@ Import("env") myenv = env.Clone() myenv.MergeFlags(env["SLIMBER_FLAGS"]) +myenv.MergeFlags(env["SWIFTOOLS_FLAGS"]) myenv.MergeFlags(env["SWIFTEN_FLAGS"]) myenv.MergeFlags(env["LIBIDN_FLAGS"]) myenv.MergeFlags(env["BOOST_FLAGS"]) diff --git a/Slimber/Cocoa/SConscript b/Slimber/Cocoa/SConscript index 6594b9f..f11b276 100644 --- a/Slimber/Cocoa/SConscript +++ b/Slimber/Cocoa/SConscript @@ -2,6 +2,7 @@ Import("env") myenv = env.Clone() myenv.MergeFlags(env["SLIMBER_FLAGS"]) +myenv.MergeFlags(env["SWIFTOOLS_FLAGS"]) myenv.MergeFlags(env["SWIFTEN_FLAGS"]) myenv.MergeFlags(env["LIBIDN_FLAGS"]) myenv.MergeFlags(env["BOOST_FLAGS"]) diff --git a/Slimber/MainController.cpp b/Slimber/MainController.cpp index a557a07..38c1a7c 100644 --- a/Slimber/MainController.cpp +++ b/Slimber/MainController.cpp @@ -11,7 +11,7 @@ #include #include "Swiften/Base/foreach.h" -#include "Swiften/Application/PlatformApplicationPathProvider.h" +#include "SwifTools/Application/PlatformApplicationPathProvider.h" #include "Swiften/LinkLocal/LinkLocalService.h" #include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" #include "Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h" diff --git a/Slimber/Qt/SConscript b/Slimber/Qt/SConscript index 2148f02..53d8138 100644 --- a/Slimber/Qt/SConscript +++ b/Slimber/Qt/SConscript @@ -5,6 +5,7 @@ Import("env") myenv = env.Clone() myenv["CXXFLAGS"] = filter(lambda x : x != "-Wfloat-equal", myenv["CXXFLAGS"]) myenv.MergeFlags(env["SLIMBER_FLAGS"]) +myenv.MergeFlags(env["SWIFTOOLS_FLAGS"]) myenv.MergeFlags(env["SWIFTEN_FLAGS"]) myenv.MergeFlags(env["LIBIDN_FLAGS"]) myenv.MergeFlags(env["BOOST_FLAGS"]) diff --git a/SwifTools/Application/ApplicationPathProvider.cpp b/SwifTools/Application/ApplicationPathProvider.cpp new file mode 100644 index 0000000..bf0a19e --- /dev/null +++ b/SwifTools/Application/ApplicationPathProvider.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include +#include + +#include "SwifTools/Application/ApplicationPathProvider.h" +#include "Swiften/Base/foreach.h" + +namespace Swift { + +ApplicationPathProvider::ApplicationPathProvider(const String& applicationName) : applicationName(applicationName) { +} + +ApplicationPathProvider::~ApplicationPathProvider() { +} + +boost::filesystem::path ApplicationPathProvider::getAvatarDir() const { + return getDataDir() / "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; +} + +boost::filesystem::path ApplicationPathProvider::getResourcePath(const String& resource) const { + std::vector resourcePaths = getResourceDirs(); + foreach(const boost::filesystem::path& resourcePath, resourcePaths) { + boost::filesystem::path r(resourcePath / resource.getUTF8String()); + if (boost::filesystem::exists(r)) { + return r; + } + } + return boost::filesystem::path(); +} + +} diff --git a/SwifTools/Application/ApplicationPathProvider.h b/SwifTools/Application/ApplicationPathProvider.h new file mode 100644 index 0000000..7bd2630 --- /dev/null +++ b/SwifTools/Application/ApplicationPathProvider.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 +#include + +#include "Swiften/Base/String.h" + +namespace Swift { + class ApplicationPathProvider { + public: + ApplicationPathProvider(const String& applicationName); + virtual ~ApplicationPathProvider(); + + boost::filesystem::path getAvatarDir() const; + virtual boost::filesystem::path getHomeDir() const = 0; + virtual boost::filesystem::path getDataDir() const = 0; + virtual boost::filesystem::path getExecutableDir() const = 0; + boost::filesystem::path getProfileDir(const String& profile) const; + boost::filesystem::path getResourcePath(const String& resource) const; + + protected: + virtual std::vector getResourceDirs() const = 0; + const String& getApplicationName() const { + return applicationName; + } + + private: + String applicationName; + }; +} diff --git a/SwifTools/Application/CocoaApplication.h b/SwifTools/Application/CocoaApplication.h new file mode 100644 index 0000000..3b19d28 --- /dev/null +++ b/SwifTools/Application/CocoaApplication.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 + +namespace Swift { + class CocoaApplication { + public: + CocoaApplication(); + ~CocoaApplication(); + + private: + class Private; + Private* d; + }; +} diff --git a/SwifTools/Application/CocoaApplication.mm b/SwifTools/Application/CocoaApplication.mm new file mode 100644 index 0000000..edfdc25 --- /dev/null +++ b/SwifTools/Application/CocoaApplication.mm @@ -0,0 +1,24 @@ +#include "SwifTools/Application/CocoaApplication.h" + +#include +#include + +namespace Swift { + +class CocoaApplication::Private { + public: + NSAutoreleasePool* autoReleasePool_; +}; + +CocoaApplication::CocoaApplication() { + d = new CocoaApplication::Private(); + NSApplicationLoad(); + d->autoReleasePool_ = [[NSAutoreleasePool alloc] init]; +} + +CocoaApplication::~CocoaApplication() { + [d->autoReleasePool_ release]; + delete d; +} + +} diff --git a/SwifTools/Application/MacOSXApplicationPathProvider.cpp b/SwifTools/Application/MacOSXApplicationPathProvider.cpp new file mode 100644 index 0000000..eb6c63f --- /dev/null +++ b/SwifTools/Application/MacOSXApplicationPathProvider.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "SwifTools/Application/MacOSXApplicationPathProvider.h" + +#include +#include + +#include "Swiften/Base/ByteArray.h" + +namespace Swift { + +MacOSXApplicationPathProvider::MacOSXApplicationPathProvider(const String& name) : ApplicationPathProvider(name) { + resourceDirs.push_back(getExecutableDir() / "../Resources"); + resourceDirs.push_back(getExecutableDir() / "../resources"); // Development +} + +boost::filesystem::path MacOSXApplicationPathProvider::getDataDir() const { + boost::filesystem::path result(getHomeDir() / "Library/Application Support" / getApplicationName().getUTF8String()); + try { + boost::filesystem::create_directory(result); + } + catch (const boost::filesystem::filesystem_error& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + } + return result; +} + +boost::filesystem::path MacOSXApplicationPathProvider::getHomeDir() const { + return boost::filesystem::path(getenv("HOME")); +} + + +boost::filesystem::path MacOSXApplicationPathProvider::getExecutableDir() const { + ByteArray path; + uint32_t size = 4096; + path.resize(size); + if (_NSGetExecutablePath(path.getData(), &size) == 0) { + return boost::filesystem::path(path.toString().getUTF8Data()).parent_path(); + } + else { + return boost::filesystem::path(); + } +} + +} diff --git a/SwifTools/Application/MacOSXApplicationPathProvider.h b/SwifTools/Application/MacOSXApplicationPathProvider.h new file mode 100644 index 0000000..a914ded --- /dev/null +++ b/SwifTools/Application/MacOSXApplicationPathProvider.h @@ -0,0 +1,27 @@ +/* + * 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 "SwifTools/Application/ApplicationPathProvider.h" + +namespace Swift { + class MacOSXApplicationPathProvider : public ApplicationPathProvider { + public: + MacOSXApplicationPathProvider(const String& name); + + virtual boost::filesystem::path getHomeDir() const; + boost::filesystem::path getDataDir() const; + virtual boost::filesystem::path getExecutableDir() const; + + virtual std::vector getResourceDirs() const { + return resourceDirs; + } + + private: + std::vector resourceDirs; + }; +} diff --git a/SwifTools/Application/PlatformApplicationPathProvider.h b/SwifTools/Application/PlatformApplicationPathProvider.h new file mode 100644 index 0000000..bb9bfa9 --- /dev/null +++ b/SwifTools/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 "SwifTools/Application/MacOSXApplicationPathProvider.h" +namespace Swift { + typedef MacOSXApplicationPathProvider PlatformApplicationPathProvider; +} +#elif defined(SWIFTEN_PLATFORM_WIN32) +#include "SwifTools/Application/WindowsApplicationPathProvider.h" +namespace Swift { + typedef WindowsApplicationPathProvider PlatformApplicationPathProvider; +} +#else +#include "SwifTools/Application/UnixApplicationPathProvider.h" +namespace Swift { + typedef UnixApplicationPathProvider PlatformApplicationPathProvider; +} +#endif diff --git a/SwifTools/Application/SConscript b/SwifTools/Application/SConscript new file mode 100644 index 0000000..0097bca --- /dev/null +++ b/SwifTools/Application/SConscript @@ -0,0 +1,26 @@ +Import("swiftools_env", "env") + +sources = [ + "ApplicationPathProvider.cpp", + ] + +if swiftools_env["PLATFORM"] == "darwin" and swiftools_env["target"] == "native" : + sources += [ + "CocoaApplication.mm", + "MacOSXApplicationPathProvider.cpp", + ] +elif swiftools_env["PLATFORM"] == "win32" : + sources += [ + "WindowsApplicationPathProvider.cpp" + ] +else : + sources += [ + "UnixApplicationPathProvider.cpp" + ] + +objects = swiftools_env.StaticObject(sources) +swiftools_env.Append(SWIFTOOLS_OBJECTS = [objects]) + +env.Append(UNITTEST_SOURCES = [ + File("UnitTest/ApplicationPathProviderTest.cpp") + ]) diff --git a/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp b/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp new file mode 100644 index 0000000..cd171cb --- /dev/null +++ b/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include +#include + +#include "SwifTools/Application/PlatformApplicationPathProvider.h" +#include "Swiften/Base/String.h" + +using namespace Swift; + +class ApplicationPathProviderTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ApplicationPathProviderTest); + CPPUNIT_TEST(testGetDataDir); + CPPUNIT_TEST(testGetExecutableDir); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + testling_ = new PlatformApplicationPathProvider("SwiftTest"); + } + + void tearDown() { + delete testling_; + } + + void testGetDataDir() { + boost::filesystem::path dir = testling_->getDataDir(); + + CPPUNIT_ASSERT(boost::filesystem::exists(dir)); + CPPUNIT_ASSERT(boost::filesystem::is_directory(dir)); + + boost::filesystem::remove(dir); + } + + void testGetExecutableDir() { + boost::filesystem::path dir = testling_->getExecutableDir(); + CPPUNIT_ASSERT(boost::filesystem::is_directory(dir)); + CPPUNIT_ASSERT(String(dir.string()).endsWith("UnitTest")); + } + + private: + ApplicationPathProvider* testling_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ApplicationPathProviderTest); diff --git a/SwifTools/Application/UnixApplicationPathProvider.cpp b/SwifTools/Application/UnixApplicationPathProvider.cpp new file mode 100644 index 0000000..67252ec --- /dev/null +++ b/SwifTools/Application/UnixApplicationPathProvider.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "SwifTools/Application/UnixApplicationPathProvider.h" + +#include + +namespace Swift { + +UnixApplicationPathProvider::UnixApplicationPathProvider(const String& name) : ApplicationPathProvider(name) { + resourceDirs.push_back(getExecutableDir() / "../resources"); // Development + char* xdgDataDirs = getenv("XDG_DATA_DIRS"); + if (xdgDataDirs) { + std::vector dataDirs = String(xdgDataDirs).split(':'); + if (!dataDirs.empty()) { + foreach(const String& dir, dataDirs) { + resourceDirs.push_back(boost::filesystem::path(dir.getUTF8String()) / "swift"); + } + return; + } + } + resourceDirs.push_back("/usr/local/share/swift"); + resourceDirs.push_back("/usr/share/swift"); +} + +boost::filesystem::path UnixApplicationPathProvider::getHomeDir() const { + return boost::filesystem::path(getenv("HOME")); +} + +boost::filesystem::path UnixApplicationPathProvider::getDataDir() const { + char* xdgDataHome = getenv("XDG_DATA_HOME"); + String dataDir; + if (xdgDataHome) { + dataDir = String(xdgDataHome); + } + + boost::filesystem::path dataPath = (dataDir.isEmpty() ? + getHomeDir() / ".local" / "share" + : boost::filesystem::path(dataDir.getUTF8String())) / getApplicationName().getLowerCase().getUTF8String(); + + try { + boost::filesystem::create_directories(dataPath); + } + catch (const boost::filesystem::filesystem_error& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + } + return dataPath; +} + +boost::filesystem::path UnixApplicationPathProvider::getExecutableDir() const { + ByteArray path; + path.resize(4096); + size_t size = readlink("/proc/self/exe", path.getData(), path.getSize()); + if (size > 0) { + path.resize(size); + return boost::filesystem::path(path.toString().getUTF8Data()).parent_path(); + } + else { + return boost::filesystem::path(); + } +} + +} diff --git a/SwifTools/Application/UnixApplicationPathProvider.h b/SwifTools/Application/UnixApplicationPathProvider.h new file mode 100644 index 0000000..2ef04ea --- /dev/null +++ b/SwifTools/Application/UnixApplicationPathProvider.h @@ -0,0 +1,34 @@ +/* + * 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 "SwifTools/Application/ApplicationPathProvider.h" + +#include +#include + +#include "Swiften/Base/ByteArray.h" +#include "Swiften/Base/foreach.h" + +namespace Swift { + class UnixApplicationPathProvider : public ApplicationPathProvider { + public: + UnixApplicationPathProvider(const String& name); + + virtual boost::filesystem::path getHomeDir() const; + boost::filesystem::path getDataDir() const; + virtual boost::filesystem::path getExecutableDir() const; + + virtual std::vector getResourceDirs() const { + return resourceDirs; + } + + private: + std::vector resourceDirs; + }; +} + diff --git a/SwifTools/Application/WindowsApplicationPathProvider.cpp b/SwifTools/Application/WindowsApplicationPathProvider.cpp new file mode 100644 index 0000000..ed692d7 --- /dev/null +++ b/SwifTools/Application/WindowsApplicationPathProvider.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "SwifTools/Application/WindowsApplicationPathProvider.h" + +#include + +#include "Swiften/Base/ByteArray.h" + +namespace Swift { + +WindowsApplicationPathProvider::WindowsApplicationPathProvider(const String& name) : ApplicationPathProvider(name) { + resourceDirs.push_back(getExecutableDir()); + resourceDirs.push_back(getExecutableDir() / "../resources"); // Development +} + +boost::filesystem::path WindowsApplicationPathProvider::getExecutableDir() const { + ByteArray data; + data.resize(2048); + GetModuleFileName(NULL, data.getData(), data.getSize()); + return boost::filesystem::path(data.toString().getUTF8Data()).parent_path(); +} + +} diff --git a/SwifTools/Application/WindowsApplicationPathProvider.h b/SwifTools/Application/WindowsApplicationPathProvider.h new file mode 100644 index 0000000..b3341e3 --- /dev/null +++ b/SwifTools/Application/WindowsApplicationPathProvider.h @@ -0,0 +1,38 @@ +/* + * 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 "SwifTools/Application/ApplicationPathProvider.h" + +namespace Swift { + class WindowsApplicationPathProvider : public ApplicationPathProvider { + public: + WindowsApplicationPathProvider(const String& name); + + boost::filesystem::path getDataDir() 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); + } + + virtual boost::filesystem::path getExecutableDir() const; + virtual std::vector getResourceDirs() const { + return resourceDirs; + } + + private: + std::vector resourceDirs; + }; +} diff --git a/SwifTools/SConscript b/SwifTools/SConscript index 6b9b727..d4747db 100644 --- a/SwifTools/SConscript +++ b/SwifTools/SConscript @@ -47,6 +47,7 @@ if env["SCONS_STAGE"] == "build" : Export("swiftools_env") SConscript(dirs = [ + "Application", "Dock", "Notifier", "Idle/IdleQuerierTest", @@ -55,4 +56,3 @@ if env["SCONS_STAGE"] == "build" : ]) swiftools_env.StaticLibrary("SwifTools", sources + swiftools_env["SWIFTOOLS_OBJECTS"]) - \ No newline at end of file diff --git a/Swift/QtUI/ApplicationTest/main.cpp b/Swift/QtUI/ApplicationTest/main.cpp index 5df7601..4e93452 100644 --- a/Swift/QtUI/ApplicationTest/main.cpp +++ b/Swift/QtUI/ApplicationTest/main.cpp @@ -10,7 +10,7 @@ #include #include "../QtSwiftUtil.h" #include "Swiften/Base/String.h" -#include "Swiften/Application/Platform/PlatformApplication.h" +#include "SwifTools/Application/Platform/PlatformApplication.h" using namespace Swift; diff --git a/Swift/QtUI/QtSoundPlayer.cpp b/Swift/QtUI/QtSoundPlayer.cpp index 7fd6564..b967cef 100644 --- a/Swift/QtUI/QtSoundPlayer.cpp +++ b/Swift/QtUI/QtSoundPlayer.cpp @@ -9,7 +9,7 @@ #include #include -#include "Swiften/Application/ApplicationPathProvider.h" +#include "SwifTools/Application/ApplicationPathProvider.h" namespace Swift { diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index 26d1664..d9879a2 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -23,7 +23,7 @@ #include #include -#include "Swiften/Application/PlatformApplicationPathProvider.h" +#include "SwifTools/Application/PlatformApplicationPathProvider.h" #include "Swiften/Avatars/AvatarFileStorage.h" #include "Swiften/Disco/CapsFileStorage.h" #include "Swiften/VCards/VCardFileStorageFactory.h" diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index 092c45e..d72faaa 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -18,7 +18,7 @@ #include "QtChatWindowFactory.h" #include "QtSettingsProvider.h" #if defined(SWIFTEN_PLATFORM_MACOSX) -#include "Swiften/Application/CocoaApplication.h" +#include "SwifTools/Application/CocoaApplication.h" #endif #if defined(HAVE_SNARL) #include "SwifTools/Notifier/Win32NotifierWindow.h" diff --git a/Swiften/Application/ApplicationPathProvider.cpp b/Swiften/Application/ApplicationPathProvider.cpp deleted file mode 100644 index 634f183..0000000 --- a/Swiften/Application/ApplicationPathProvider.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include -#include - -#include "Swiften/Application/ApplicationPathProvider.h" -#include "Swiften/Base/foreach.h" - -namespace Swift { - -ApplicationPathProvider::ApplicationPathProvider(const String& applicationName) : applicationName(applicationName) { -} - -ApplicationPathProvider::~ApplicationPathProvider() { -} - -boost::filesystem::path ApplicationPathProvider::getAvatarDir() const { - return getDataDir() / "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; -} - -boost::filesystem::path ApplicationPathProvider::getResourcePath(const String& resource) const { - std::vector resourcePaths = getResourceDirs(); - foreach(const boost::filesystem::path& resourcePath, resourcePaths) { - boost::filesystem::path r(resourcePath / resource.getUTF8String()); - if (boost::filesystem::exists(r)) { - return r; - } - } - return boost::filesystem::path(); -} - -} diff --git a/Swiften/Application/ApplicationPathProvider.h b/Swiften/Application/ApplicationPathProvider.h deleted file mode 100644 index 7bd2630..0000000 --- a/Swiften/Application/ApplicationPathProvider.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 -#include - -#include "Swiften/Base/String.h" - -namespace Swift { - class ApplicationPathProvider { - public: - ApplicationPathProvider(const String& applicationName); - virtual ~ApplicationPathProvider(); - - boost::filesystem::path getAvatarDir() const; - virtual boost::filesystem::path getHomeDir() const = 0; - virtual boost::filesystem::path getDataDir() const = 0; - virtual boost::filesystem::path getExecutableDir() const = 0; - boost::filesystem::path getProfileDir(const String& profile) const; - boost::filesystem::path getResourcePath(const String& resource) const; - - protected: - virtual std::vector getResourceDirs() const = 0; - const String& getApplicationName() const { - return applicationName; - } - - private: - String applicationName; - }; -} diff --git a/Swiften/Application/CocoaApplication.h b/Swiften/Application/CocoaApplication.h deleted file mode 100644 index 3b19d28..0000000 --- a/Swiften/Application/CocoaApplication.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -namespace Swift { - class CocoaApplication { - public: - CocoaApplication(); - ~CocoaApplication(); - - private: - class Private; - Private* d; - }; -} diff --git a/Swiften/Application/CocoaApplication.mm b/Swiften/Application/CocoaApplication.mm deleted file mode 100644 index c5b3335..0000000 --- a/Swiften/Application/CocoaApplication.mm +++ /dev/null @@ -1,24 +0,0 @@ -#include "Swiften/Application/CocoaApplication.h" - -#include -#include - -namespace Swift { - -class CocoaApplication::Private { - public: - NSAutoreleasePool* autoReleasePool_; -}; - -CocoaApplication::CocoaApplication() { - d = new CocoaApplication::Private(); - NSApplicationLoad(); - d->autoReleasePool_ = [[NSAutoreleasePool alloc] init]; -} - -CocoaApplication::~CocoaApplication() { - [d->autoReleasePool_ release]; - delete d; -} - -} diff --git a/Swiften/Application/MacOSXApplicationPathProvider.cpp b/Swiften/Application/MacOSXApplicationPathProvider.cpp deleted file mode 100644 index 8ff4cb3..0000000 --- a/Swiften/Application/MacOSXApplicationPathProvider.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 -#include - -#include "Swiften/Base/ByteArray.h" - -namespace Swift { - -MacOSXApplicationPathProvider::MacOSXApplicationPathProvider(const String& name) : ApplicationPathProvider(name) { - resourceDirs.push_back(getExecutableDir() / "../Resources"); - resourceDirs.push_back(getExecutableDir() / "../resources"); // Development -} - -boost::filesystem::path MacOSXApplicationPathProvider::getDataDir() const { - boost::filesystem::path result(getHomeDir() / "Library/Application Support" / getApplicationName().getUTF8String()); - try { - boost::filesystem::create_directory(result); - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } - return result; -} - -boost::filesystem::path MacOSXApplicationPathProvider::getHomeDir() const { - return boost::filesystem::path(getenv("HOME")); -} - - -boost::filesystem::path MacOSXApplicationPathProvider::getExecutableDir() const { - ByteArray path; - uint32_t size = 4096; - path.resize(size); - if (_NSGetExecutablePath(path.getData(), &size) == 0) { - return boost::filesystem::path(path.toString().getUTF8Data()).parent_path(); - } - else { - return boost::filesystem::path(); - } -} - -} diff --git a/Swiften/Application/MacOSXApplicationPathProvider.h b/Swiften/Application/MacOSXApplicationPathProvider.h deleted file mode 100644 index 85cca0a..0000000 --- a/Swiften/Application/MacOSXApplicationPathProvider.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 getDataDir() const; - virtual boost::filesystem::path getExecutableDir() const; - - virtual std::vector getResourceDirs() const { - return resourceDirs; - } - - private: - std::vector resourceDirs; - }; -} diff --git a/Swiften/Application/PlatformApplicationPathProvider.h b/Swiften/Application/PlatformApplicationPathProvider.h deleted file mode 100644 index e59bb9a..0000000 --- a/Swiften/Application/PlatformApplicationPathProvider.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 deleted file mode 100644 index d3a2383..0000000 --- a/Swiften/Application/SConscript +++ /dev/null @@ -1,22 +0,0 @@ -Import("swiften_env") - -sources = [ - "ApplicationPathProvider.cpp", - ] - -if swiften_env["PLATFORM"] == "darwin" and swiften_env["target"] == "native" : - sources += [ - "CocoaApplication.mm", - "MacOSXApplicationPathProvider.cpp", - ] -elif swiften_env["PLATFORM"] == "win32" : - sources += [ - "WindowsApplicationPathProvider.cpp" - ] -else : - sources += [ - "UnixApplicationPathProvider.cpp" - ] - -objects = swiften_env.StaticObject(sources) -swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp b/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp deleted file mode 100644 index 3b46e6e..0000000 --- a/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include -#include - -#include "Swiften/Application/PlatformApplicationPathProvider.h" -#include "Swiften/Base/String.h" - -using namespace Swift; - -class ApplicationPathProviderTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ApplicationPathProviderTest); - CPPUNIT_TEST(testGetDataDir); - CPPUNIT_TEST(testGetExecutableDir); - CPPUNIT_TEST_SUITE_END(); - - public: - void setUp() { - testling_ = new PlatformApplicationPathProvider("SwiftTest"); - } - - void tearDown() { - delete testling_; - } - - void testGetDataDir() { - boost::filesystem::path dir = testling_->getDataDir(); - - CPPUNIT_ASSERT(boost::filesystem::exists(dir)); - CPPUNIT_ASSERT(boost::filesystem::is_directory(dir)); - - boost::filesystem::remove(dir); - } - - void testGetExecutableDir() { - boost::filesystem::path dir = testling_->getExecutableDir(); - CPPUNIT_ASSERT(boost::filesystem::is_directory(dir)); - CPPUNIT_ASSERT(String(dir.string()).endsWith("UnitTest")); - } - - private: - ApplicationPathProvider* testling_; -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ApplicationPathProviderTest); diff --git a/Swiften/Application/UnixApplicationPathProvider.cpp b/Swiften/Application/UnixApplicationPathProvider.cpp deleted file mode 100644 index b474ecf..0000000 --- a/Swiften/Application/UnixApplicationPathProvider.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/UnixApplicationPathProvider.h" - -#include - -namespace Swift { - -UnixApplicationPathProvider::UnixApplicationPathProvider(const String& name) : ApplicationPathProvider(name) { - resourceDirs.push_back(getExecutableDir() / "../resources"); // Development - char* xdgDataDirs = getenv("XDG_DATA_DIRS"); - if (xdgDataDirs) { - std::vector dataDirs = String(xdgDataDirs).split(':'); - if (!dataDirs.empty()) { - foreach(const String& dir, dataDirs) { - resourceDirs.push_back(boost::filesystem::path(dir.getUTF8String()) / "swift"); - } - return; - } - } - resourceDirs.push_back("/usr/local/share/swift"); - resourceDirs.push_back("/usr/share/swift"); -} - -boost::filesystem::path UnixApplicationPathProvider::getHomeDir() const { - return boost::filesystem::path(getenv("HOME")); -} - -boost::filesystem::path UnixApplicationPathProvider::getDataDir() const { - char* xdgDataHome = getenv("XDG_DATA_HOME"); - String dataDir; - if (xdgDataHome) { - dataDir = String(xdgDataHome); - } - - boost::filesystem::path dataPath = (dataDir.isEmpty() ? - getHomeDir() / ".local" / "share" - : boost::filesystem::path(dataDir.getUTF8String())) / getApplicationName().getLowerCase().getUTF8String(); - - try { - boost::filesystem::create_directories(dataPath); - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } - return dataPath; -} - -boost::filesystem::path UnixApplicationPathProvider::getExecutableDir() const { - ByteArray path; - path.resize(4096); - size_t size = readlink("/proc/self/exe", path.getData(), path.getSize()); - if (size > 0) { - path.resize(size); - return boost::filesystem::path(path.toString().getUTF8Data()).parent_path(); - } - else { - return boost::filesystem::path(); - } -} - -} diff --git a/Swiften/Application/UnixApplicationPathProvider.h b/Swiften/Application/UnixApplicationPathProvider.h deleted file mode 100644 index c1bfd95..0000000 --- a/Swiften/Application/UnixApplicationPathProvider.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 -#include - -#include "Swiften/Base/ByteArray.h" -#include "Swiften/Base/foreach.h" - -namespace Swift { - class UnixApplicationPathProvider : public ApplicationPathProvider { - public: - UnixApplicationPathProvider(const String& name); - - virtual boost::filesystem::path getHomeDir() const; - boost::filesystem::path getDataDir() const; - virtual boost::filesystem::path getExecutableDir() const; - - virtual std::vector getResourceDirs() const { - return resourceDirs; - } - - private: - std::vector resourceDirs; - }; -} - diff --git a/Swiften/Application/WindowsApplicationPathProvider.cpp b/Swiften/Application/WindowsApplicationPathProvider.cpp deleted file mode 100644 index e02da1e..0000000 --- a/Swiften/Application/WindowsApplicationPathProvider.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/WindowsApplicationPathProvider.h" - -#include - -#include "Swiften/Base/ByteArray.h" - -namespace Swift { - -WindowsApplicationPathProvider::WindowsApplicationPathProvider(const String& name) : ApplicationPathProvider(name) { - resourceDirs.push_back(getExecutableDir()); - resourceDirs.push_back(getExecutableDir() / "../resources"); // Development -} - -boost::filesystem::path WindowsApplicationPathProvider::getExecutableDir() const { - ByteArray data; - data.resize(2048); - GetModuleFileName(NULL, data.getData(), data.getSize()); - return boost::filesystem::path(data.toString().getUTF8Data()).parent_path(); -} - -} diff --git a/Swiften/Application/WindowsApplicationPathProvider.h b/Swiften/Application/WindowsApplicationPathProvider.h deleted file mode 100644 index a026dba..0000000 --- a/Swiften/Application/WindowsApplicationPathProvider.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 getDataDir() 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); - } - - virtual boost::filesystem::path getExecutableDir() const; - virtual std::vector getResourceDirs() const { - return resourceDirs; - } - - private: - std::vector resourceDirs; - }; -} diff --git a/Swiften/SConscript b/Swiften/SConscript index 7665fb0..ace9ab7 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -120,7 +120,6 @@ if env["SCONS_STAGE"] == "build" : "Base", "StringPrep", "SASL", - "Application", "EventLoop", "Parser", "JID", @@ -142,7 +141,6 @@ if env["SCONS_STAGE"] == "build" : myenv.StaticLibrary("Swiften", sources + swiften_env["SWIFTEN_OBJECTS"]) env.Append(UNITTEST_SOURCES = [ - File("Application/UnitTest/ApplicationPathProviderTest.cpp"), File("Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp"), File("Avatars/UnitTest/VCardAvatarManagerTest.cpp"), File("Avatars/UnitTest/CombinedAvatarProviderTest.cpp"), @@ -261,4 +259,4 @@ if env["SCONS_STAGE"] == "build" : swiften_header += "#include \"" + os.path.relpath(os.path.join(root, file), top_path) + "\"\n" for file in ["EventLoop/SimpleEventLoop.h"] : swiften_header += "#include \"Swiften/" + file + "\"\n" - swiften_env.WriteVal("Swiften.h", swiften_env.Value(swiften_header)) \ No newline at end of file + swiften_env.WriteVal("Swiften.h", swiften_env.Value(swiften_header)) -- cgit v0.10.2-6-g49f6