From f416fe2749a959ad26544ead709683d3800059e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Thu, 19 Aug 2010 18:22:31 +0200 Subject: Extract dir providing functionality from application class. diff --git a/.cdtproject b/.cdtproject deleted file mode 100644 index d815dfd..0000000 --- a/.cdtproject +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..842628d --- /dev/null +++ b/.cproject @@ -0,0 +1,422 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..31ac475 --- /dev/null +++ b/.project @@ -0,0 +1,143 @@ + + + Swift + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + + + + org.eclipse.cdt.make.core.buildArguments + ${ProjDirPath}/3rdParty/SCons/scons.py + + + org.eclipse.cdt.make.core.buildCommand + python + + + org.eclipse.cdt.make.core.cleanBuildTarget + -c + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + false + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + 1282232084903 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.obj + + + + 1282232084906 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.o + + + + 1282232084909 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.a + + + + 1282232084912 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.lib + + + + 1282232084914 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*~ + + + + 1282232084917 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-moc_* + + + + 1282231206287 + 3rdParty/Boost + 26 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-src + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..0c51e47 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Thu Aug 19 16:27:10 CEST 2010 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/BuildTools/Eclipse/Swift (Windows).launch b/BuildTools/Eclipse/Swift (Windows).launch new file mode 100644 index 0000000..bb27678 --- /dev/null +++ b/BuildTools/Eclipse/Swift (Windows).launch @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 22e78fe..f010c49 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -64,9 +64,8 @@ static const String CLIENT_VERSION = "1.0-devel"; static const String CLIENT_NODE = "http://swift.im"; -MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, EventWindowFactory* eventWindowFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, ChatListWindowFactory* chatListWindowFactory, MUCSearchWindowFactory* mucSearchWindowFactory, bool useDelayForLatency) +MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, EventWindowFactory* eventWindowFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, ChatListWindowFactory* chatListWindowFactory, MUCSearchWindowFactory* mucSearchWindowFactory, AvatarStorage* avatarStorage, ApplicationMessageDisplay* applicationMessageDisplay, bool useDelayForLatency) : timerFactory_(&boostIOServiceThread_.getIOService()), idleDetector_(&idleQuerier_, &timerFactory_, 100), chatWindowFactory_(chatWindowFactory), mainWindowFactory_(mainWindowFactory), loginWindowFactory_(loginWindowFactory), settings_(settings), loginWindow_(NULL), useDelayForLatency_(useDelayForLatency) { - application_ = application; presenceOracle_ = NULL; avatarManager_ = NULL; chatsManager_ = NULL; @@ -86,10 +85,11 @@ MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowF timeBeforeNextReconnect_ = -1; mucSearchWindowFactory_ = mucSearchWindowFactory; eventWindowFactory_ = eventWindowFactory; + applicationMessageDisplay_ = applicationMessageDisplay; chatListWindowFactory_ = chatListWindowFactory; uiEventStream_ = new UIEventStream(); - avatarStorage_ = new AvatarFileStorage(application_->getAvatarDir()); + avatarStorage_ = avatarStorage; eventController_ = new EventController(); eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1)); @@ -249,7 +249,7 @@ void MainController::handleConnected() { } void MainController::handleEventQueueLengthChange(int count) { - application_->getApplicationMessageDisplay()->setMessage(count == 0 ? "" : boost::lexical_cast(count).c_str()); + applicationMessageDisplay_->setMessage(count == 0 ? "" : boost::lexical_cast(count).c_str()); } void MainController::reconnectAfterError() { diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index f17bc9b..2bda61a 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -42,6 +42,7 @@ namespace Swift { class XMPPRosterController; class PresenceSender; class DiscoInfoResponder; + class ApplicationMessageDisplay; class AvatarManager; class LoginWindow; class EventLoop; @@ -64,7 +65,7 @@ namespace Swift { class MainController { public: - MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, EventWindowFactory* eventWindowFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, ChatListWindowFactory* chatListWindowFactory_, MUCSearchWindowFactory* mucSearchWindowFactory, bool useDelayForLatency); + MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, EventWindowFactory* eventWindowFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, ChatListWindowFactory* chatListWindowFactory_, MUCSearchWindowFactory* mucSearchWindowFactory, AvatarStorage* avatarStorage, ApplicationMessageDisplay* applicationMessageDisplay, bool useDelayForLatency); ~MainController(); @@ -101,8 +102,8 @@ namespace Swift { LoginWindowFactory* loginWindowFactory_; EventWindowFactory* eventWindowFactory_; SettingsProvider *settings_; - Application* application_; AvatarStorage* avatarStorage_; + ApplicationMessageDisplay* applicationMessageDisplay_; ChatController* chatController_; XMPPRosterController* xmppRosterController_; RosterController* rosterController_; diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index 57b4edf..84ae3a1 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -21,7 +21,9 @@ #include #include "Swiften/Application/Application.h" -#include "Swiften/Application/Platform/PlatformApplication.h" +#include "Swiften/Application/PlatformApplication.h" +#include "Swiften/Application/PlatformApplicationPathProvider.h" +#include "Swiften/Avatars/AvatarFileStorage.h" #include "Swiften/Base/String.h" #include "Swiften/Base/Platform.h" #include "Swiften/Elements/Presence.h" @@ -66,9 +68,11 @@ QtSwift::QtSwift(po::variables_map options) : autoUpdater_(NULL) { int numberOfAccounts = options["multi-account"].as(); - tabs_ = options.count("no-tabs") && !splitter_ > 0 ? NULL : new QtChatTabs(); + tabs_ = options.count("no-tabs") && !(splitter_ > 0) ? NULL : new QtChatTabs(); settings_ = new QtSettingsProvider(); application_ = new PlatformApplication(SWIFT_APPLICATION_NAME); + applicationPathProvider_ = new PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME); + avatarStorage_ = new AvatarFileStorage(applicationPathProvider_->getAvatarDir()); chatWindowFactory_ = new QtChatWindowFactory(splitter_, settings_, tabs_); soundPlayer_ = new QtSoundPlayer(); if (splitter_) { @@ -90,7 +94,7 @@ QtSwift::QtSwift(po::variables_map options) : autoUpdater_(NULL) { chatListWindowFactories_.push_back(chatListWindowFactory); QtMUCSearchWindowFactory* mucSearchWindowFactory = new QtMUCSearchWindowFactory(); mucSearchWindowFactories_.push_back(mucSearchWindowFactory); - MainController* mainController = new MainController(chatWindowFactory_, rosterWindowFactory, loginWindowFactory, eventWindowFactory, settings_, application_, systemTray, soundPlayer_, xmlConsoleWidgetFactory, chatListWindowFactory, mucSearchWindowFactory, options.count("latency-debug") > 0); + MainController* mainController = new MainController(chatWindowFactory_, rosterWindowFactory, loginWindowFactory, eventWindowFactory, settings_, application_, systemTray, soundPlayer_, xmlConsoleWidgetFactory, chatListWindowFactory, mucSearchWindowFactory, avatarStorage_, application_->getApplicationMessageDisplay(), options.count("latency-debug") > 0); mainControllers_.push_back(mainController); } diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index 567af32..d205f9f 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -24,6 +24,8 @@ class QSplitter; namespace Swift { class AutoUpdater; class Application; + class ApplicationPathProvider; + class AvatarStorage; class MainController; class QtChatWindowFactory; class QtMainWindowFactory; @@ -57,6 +59,8 @@ namespace Swift { QtSoundPlayer* soundPlayer_; QtChatTabs* tabs_; Application* application_; + ApplicationPathProvider* applicationPathProvider_; + AvatarStorage* avatarStorage_; AutoUpdater* autoUpdater_; }; 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 -#include #include #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 +#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 +#include + +#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 + +#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 + +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/Platform/PlatformApplication.h deleted file mode 100644 index 2508fb3..0000000 --- a/Swiften/Application/Platform/PlatformApplication.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#ifndef SWIFTEN_PlatformApplication_H -#define SWIFTEN_PlatformApplication_H - -#include "Swiften/Base/Platform.h" - - -#if defined(SWIFTEN_PLATFORM_MACOSX) -#include "Swiften/Application/MacOSX/MacOSXApplication.h" -namespace Swift { - typedef MacOSXApplication PlatformApplication; -} -#elif defined(SWIFTEN_PLATFORM_WIN32) -#include "Swiften/Application/Windows/WindowsApplication.h" -namespace Swift { - typedef WindowsApplication PlatformApplication; -} -#else -#include "Swiften/Application/Unix/UnixApplication.h" -namespace Swift { - typedef UnixApplication PlatformApplication; -} -#endif - -#endif diff --git a/Swiften/Application/PlatformApplication.h b/Swiften/Application/PlatformApplication.h new file mode 100644 index 0000000..7facbe5 --- /dev/null +++ b/Swiften/Application/PlatformApplication.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 "Swiften/Base/Platform.h" + + +#if defined(SWIFTEN_PLATFORM_MACOSX) +#include "Swiften/Application/MacOSX/MacOSXApplication.h" +namespace Swift { + typedef MacOSXApplication PlatformApplication; +} +#elif defined(SWIFTEN_PLATFORM_WIN32) +#include "Swiften/Application/WindowsApplication.h" +namespace Swift { + typedef WindowsApplication PlatformApplication; +} +#else +#include "Swiften/Application/UnixApplication.h" +namespace Swift { + typedef UnixApplication PlatformApplication; +} +#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/ApplicationPathProviderTest.cpp b/Swiften/Application/UnitTest/ApplicationPathProviderTest.cpp new file mode 100644 index 0000000..7cb277a --- /dev/null +++ b/Swiften/Application/UnitTest/ApplicationPathProviderTest.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 +#include + +#include "Swiften/Application/PlatformApplicationPathProvider.h" + +using namespace Swift; + +class ApplicationPathProviderTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ApplicationPathProviderTest); + CPPUNIT_TEST(testGetSettingsDir); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + testling_ = new PlatformApplicationPathProvider("SwiftTest"); + } + + void tearDown() { + delete testling_; + } + + void testGetSettingsDir() { + boost::filesystem::path dir = testling_->getSettingsDir(); + + CPPUNIT_ASSERT(boost::filesystem::exists(dir)); + CPPUNIT_ASSERT(boost::filesystem::is_directory(dir)); + + boost::filesystem::remove(dir); + } + + private: + ApplicationPathProvider* testling_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ApplicationPathProviderTest); diff --git a/Swiften/Application/UnitTest/ApplicationTest.cpp b/Swiften/Application/UnitTest/ApplicationTest.cpp deleted file mode 100644 index 8be3d4d..0000000 --- a/Swiften/Application/UnitTest/ApplicationTest.cpp +++ /dev/null @@ -1,45 +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/Application.h" -#include "Swiften/Application/Platform/PlatformApplication.h" - -using namespace Swift; - -class ApplicationTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(ApplicationTest); - CPPUNIT_TEST(testGetSettingsDir); - CPPUNIT_TEST_SUITE_END(); - - public: - ApplicationTest() {} - - void setUp() { - testling_ = new PlatformApplication("SwiftTest"); - } - - void tearDown() { - delete testling_; - } - - void testGetSettingsDir() { - boost::filesystem::path dir = testling_->getSettingsDir(); - - CPPUNIT_ASSERT(boost::filesystem::exists(dir)); - CPPUNIT_ASSERT(boost::filesystem::is_directory(dir)); - - boost::filesystem::remove(dir); - } - - private: - Application* testling_; -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ApplicationTest); diff --git a/Swiften/Application/Unix/UnixApplication.h b/Swiften/Application/Unix/UnixApplication.h deleted file mode 100644 index 56ee0ed..0000000 --- a/Swiften/Application/Unix/UnixApplication.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#ifndef SWIFTEN_UnixApplication_H -#define SWIFTEN_UnixApplication_H - -#include "Swiften/Application/Application.h" -#include "Swiften/Application/NullApplicationMessageDisplay.h" - -#include - -namespace Swift { - class UnixApplication : public Application { - public: - UnixApplication(const String& name) : Application(name) { - } - - virtual ApplicationMessageDisplay* getApplicationMessageDisplay() { - 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())); - try { - boost::filesystem::create_directory(result); - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } - return result; - } - - private: - NullApplicationMessageDisplay messageDisplay_; - }; -} - -#endif diff --git a/Swiften/Application/UnixApplication.h b/Swiften/Application/UnixApplication.h new file mode 100644 index 0000000..9ec9300 --- /dev/null +++ b/Swiften/Application/UnixApplication.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#ifndef SWIFTEN_UnixApplication_H +#define SWIFTEN_UnixApplication_H + +#include "Swiften/Application/Application.h" +#include "Swiften/Application/NullApplicationMessageDisplay.h" + +#include + +namespace Swift { + class UnixApplication : public Application { + public: + UnixApplication(const String& name) : Application(name) { + } + + virtual ApplicationMessageDisplay* getApplicationMessageDisplay() { + return &messageDisplay_; + } + + virtual boost::filesystem::path getHomeDir() const { + return boost::filesystem::path(getenv("HOME")); + } + + boost::filesystem::path getSettingsDir() const { + boost::filesystem::path result(getHomeDir() / ("." + getApplicationName().getLowerCase().getUTF8String())); + try { + boost::filesystem::create_directory(result); + } + catch (const boost::filesystem::filesystem_error& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + } + return result; + } + + private: + NullApplicationMessageDisplay messageDisplay_; + }; +} + +#endif 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 + +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/Windows/WindowsApplication.h deleted file mode 100644 index fb0f5f1..0000000 --- a/Swiften/Application/Windows/WindowsApplication.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#ifndef SWIFTEN_WindowsApplication_H -#define SWIFTEN_WindowsApplication_H - -#include "Swiften/Application/Application.h" -#include "Swiften/Application/NullApplicationMessageDisplay.h" - -namespace Swift { - class WindowsApplication : public Application { - public: - WindowsApplication(const String& name) : Application(name) { - } - - virtual ApplicationMessageDisplay* getApplicationMessageDisplay() { - 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_; - }; -} - -#endif diff --git a/Swiften/Application/WindowsApplication.h b/Swiften/Application/WindowsApplication.h new file mode 100644 index 0000000..eda066d --- /dev/null +++ b/Swiften/Application/WindowsApplication.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#ifndef SWIFTEN_WindowsApplication_H +#define SWIFTEN_WindowsApplication_H + +#include "Swiften/Application/Application.h" +#include "Swiften/Application/NullApplicationMessageDisplay.h" + +namespace Swift { + class WindowsApplication : public Application { + public: + WindowsApplication(const String& name) : Application(name) { + } + + virtual ApplicationMessageDisplay* getApplicationMessageDisplay() { + return &messageDisplay_; + } + + private: + NullApplicationMessageDisplay messageDisplay_; + }; +} + +#endif 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"), -- cgit v0.10.2-6-g49f6