From 6e4b357141a6d09632f1e96d0eaf54f79daf52c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Wed, 7 Apr 2010 21:57:03 +0200 Subject: Added VCardStorage. diff --git a/.cproject b/.cproject index 0e7336d..5473cea 100644 --- a/.cproject +++ b/.cproject @@ -39,6 +39,10 @@ + + + + @@ -121,6 +125,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -205,10 +292,6 @@ - - - - @@ -246,6 +329,10 @@ + + + + @@ -328,6 +415,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -412,10 +582,6 @@ - - - - @@ -453,6 +619,10 @@ + + + + @@ -535,7 +705,7 @@ - + @@ -618,11 +788,380 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project index fcdfcdc..06cc260 100644 --- a/.project +++ b/.project @@ -18,7 +18,7 @@ org.eclipse.cdt.make.core.autoBuildTarget - + dist=1 org.eclipse.cdt.make.core.buildArguments @@ -29,6 +29,10 @@ python + org.eclipse.cdt.make.core.buildLocation + + + org.eclipse.cdt.make.core.cleanBuildTarget -c @@ -50,7 +54,7 @@ org.eclipse.cdt.make.core.fullBuildTarget - + dist=1 org.eclipse.cdt.make.core.stopOnError diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index b267dd2..6eb3a2c 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -19,6 +19,7 @@ #include "Swiften/Network/MainBoostIOServiceThread.h" #include "Swift/Controllers/BuildVersion.h" #include "Swift/Controllers/Chat/ChatController.h" +#include "Swiften/VCards/VCardStorageFactory.h" #include "Swift/Controllers/Chat/MUCSearchController.h" #include "Swift/Controllers/Chat/ChatsManager.h" #include "Swift/Controllers/EventController.h" @@ -63,8 +64,30 @@ 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, 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) { +MainController::MainController( + ChatWindowFactory* chatWindowFactory, + MainWindowFactory *mainWindowFactory, + LoginWindowFactory *loginWindowFactory, + EventWindowFactory* eventWindowFactory, + SettingsProvider *settings, + SystemTray* systemTray, + SoundPlayer* soundPlayer, + XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, + ChatListWindowFactory* chatListWindowFactory, + MUCSearchWindowFactory* mucSearchWindowFactory, + AvatarStorage* avatarStorage, + VCardStorageFactory* vcardStorageFactory, + ApplicationMessageDisplay* applicationMessageDisplay, + bool useDelayForLatency) : + timerFactory_(&boostIOServiceThread_.getIOService()), + idleDetector_(&idleQuerier_, &timerFactory_, 100), + chatWindowFactory_(chatWindowFactory), + mainWindowFactory_(mainWindowFactory), + loginWindowFactory_(loginWindowFactory), + settings_(settings), + loginWindow_(NULL), + vcardStorageFactory_(vcardStorageFactory), + useDelayForLatency_(useDelayForLatency) { presenceOracle_ = NULL; avatarManager_ = NULL; chatsManager_ = NULL; diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index e220211..a612175 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -63,10 +63,25 @@ namespace Swift { class MUCSearchController; class MUCSearchWindowFactory; class StatusTracker; + class VCardStorageFactory; class MainController { public: - MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, EventWindowFactory* eventWindowFactory, SettingsProvider *settings, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, ChatListWindowFactory* chatListWindowFactory_, MUCSearchWindowFactory* mucSearchWindowFactory, AvatarStorage* avatarStorage, ApplicationMessageDisplay* applicationMessageDisplay, bool useDelayForLatency); + MainController( + ChatWindowFactory* chatWindowFactory, + MainWindowFactory *mainWindowFactory, + LoginWindowFactory *loginWindowFactory, + EventWindowFactory* eventWindowFactory, + SettingsProvider *settings, + SystemTray* systemTray, + SoundPlayer* soundPlayer, + XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, + ChatListWindowFactory* chatListWindowFactory_, + MUCSearchWindowFactory* mucSearchWindowFactory, + AvatarStorage* avatarStorage, + VCardStorageFactory* vcardStorageFactory, + ApplicationMessageDisplay* applicationMessageDisplay, + bool useDelayForLatency); ~MainController(); @@ -105,6 +120,7 @@ namespace Swift { SettingsProvider *settings_; ProfileSettingsProvider* profileSettings_; AvatarStorage* avatarStorage_; + VCardStorageFactory* vcardStorageFactory_; ApplicationMessageDisplay* applicationMessageDisplay_; ChatController* chatController_; XMPPRosterController* xmppRosterController_; diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index 55bc112..0405681 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -24,6 +24,7 @@ #include "Swiften/Application/PlatformApplication.h" #include "Swiften/Application/PlatformApplicationPathProvider.h" #include "Swiften/Avatars/AvatarFileStorage.h" +#include "Swiften/VCards/VCardFileStorageFactory.h" #include "Swiften/Base/String.h" #include "Swiften/Base/Platform.h" #include "Swiften/Elements/Presence.h" @@ -79,6 +80,7 @@ QtSwift::QtSwift(po::variables_map options) : autoUpdater_(NULL) { application_ = new PlatformApplication(SWIFT_APPLICATION_NAME); applicationPathProvider_ = new PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME); avatarStorage_ = new AvatarFileStorage(applicationPathProvider_->getAvatarDir()); + vcardStorageFactory_ = new VCardFileStorageFactory(applicationPathProvider_->getDataDir()); chatWindowFactory_ = new QtChatWindowFactory(splitter_, settings_, tabs_); soundPlayer_ = new QtSoundPlayer(applicationPathProvider_); if (splitter_) { @@ -100,7 +102,21 @@ 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_, systemTray, soundPlayer_, xmlConsoleWidgetFactory, chatListWindowFactory, mucSearchWindowFactory, avatarStorage_, application_->getApplicationMessageDisplay(), options.count("latency-debug") > 0); + MainController* mainController = new MainController( + chatWindowFactory_, + rosterWindowFactory, + loginWindowFactory, + eventWindowFactory, + settings_, + systemTray, + soundPlayer_, + xmlConsoleWidgetFactory, + chatListWindowFactory, + mucSearchWindowFactory, + avatarStorage_, + vcardStorageFactory_, + application_->getApplicationMessageDisplay(), + options.count("latency-debug") > 0); mainControllers_.push_back(mainController); } @@ -144,6 +160,8 @@ QtSwift::~QtSwift() { foreach (QtChatListWindowFactory* factory, chatListWindowFactories_) { delete factory; } + delete avatarStorage_; + delete vcardStorageFactory_; } } diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index d205f9f..a0ea069 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -22,6 +22,7 @@ namespace po = boost::program_options; class QSplitter; namespace Swift { + class VCardStorageFactory; class AutoUpdater; class Application; class ApplicationPathProvider; @@ -61,6 +62,7 @@ namespace Swift { Application* application_; ApplicationPathProvider* applicationPathProvider_; AvatarStorage* avatarStorage_; + VCardStorageFactory* vcardStorageFactory_; AutoUpdater* autoUpdater_; }; diff --git a/Swiften/Elements/VCard.h b/Swiften/Elements/VCard.h index 2b2e99f..60f94b1 100644 --- a/Swiften/Elements/VCard.h +++ b/Swiften/Elements/VCard.h @@ -7,11 +7,12 @@ #pragma once #include "Swiften/Base/String.h" +#include "Swiften/Base/Shared.h" #include "Swiften/Base/ByteArray.h" #include "Swiften/Elements/Payload.h" namespace Swift { - class VCard : public Payload { + class VCard : public Payload, public Shared { public: VCard() {} diff --git a/Swiften/QA/SConscript b/Swiften/QA/SConscript index 4cc56c9..e9c1546 100644 --- a/Swiften/QA/SConscript +++ b/Swiften/QA/SConscript @@ -3,4 +3,5 @@ SConscript(dirs = [ "ReconnectTest", "ClientTest", "DNSSDTest", + "StorageTest", ]) diff --git a/Swiften/QA/StorageTest/.gitignore b/Swiften/QA/StorageTest/.gitignore new file mode 100644 index 0000000..10d2e31 --- /dev/null +++ b/Swiften/QA/StorageTest/.gitignore @@ -0,0 +1 @@ +StorageTest diff --git a/Swiften/QA/StorageTest/SConscript b/Swiften/QA/StorageTest/SConscript new file mode 100644 index 0000000..c7401e0 --- /dev/null +++ b/Swiften/QA/StorageTest/SConscript @@ -0,0 +1,17 @@ +import os + +Import("env") + +if env["TEST"] : + myenv = env.Clone() + myenv.MergeFlags(myenv["CHECKER_FLAGS"]) + myenv.MergeFlags(myenv["SWIFTEN_FLAGS"]) + myenv.MergeFlags(myenv["CPPUNIT_FLAGS"]) + myenv.MergeFlags(myenv["BOOST_FLAGS"]) + myenv.MergeFlags(myenv["LIBIDN_FLAGS"]) + myenv.MergeFlags(myenv.get("EXPAT_FLAGS", {})) + + tester = myenv.Program("StorageTest", [ + "VCardFileStorageTest.cpp", + ]) + myenv.Test(tester, "system") diff --git a/Swiften/QA/StorageTest/VCardFileStorageTest.cpp b/Swiften/QA/StorageTest/VCardFileStorageTest.cpp new file mode 100644 index 0000000..9704409 --- /dev/null +++ b/Swiften/QA/StorageTest/VCardFileStorageTest.cpp @@ -0,0 +1,78 @@ +/* + * 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/VCards/VCardFileStorage.h" +#include "Swiften/JID/JID.h" +#include "Swiften/Application/PlatformApplicationPathProvider.h" +#include "Swiften/Elements/VCard.h" + +using namespace Swift; + +class VCardFileStorageTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(VCardFileStorageTest); + CPPUNIT_TEST(testSetVCard); + CPPUNIT_TEST(testGetVCard); + CPPUNIT_TEST(testGetVCard_FileDoesNotExist); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + pathProvider = new PlatformApplicationPathProvider("VCardStorageTest"); + vcardsPath = pathProvider->getExecutableDir() / "vcards"; + boost::filesystem::remove_all(vcardsPath); + } + + void tearDown() { + delete pathProvider; + boost::filesystem::remove_all(vcardsPath); + } + + void testSetVCard() { + std::auto_ptr testling(createTestling()); + VCard::ref vcard(new VCard()); + vcard->setFullName("Alice In Wonderland"); + vcard->setEMail("alice@wonderland.lit"); + + testling->setVCard(JID("alice@wonderland.lit"), vcard); + + boost::filesystem::path vcardFile(vcardsPath / "alice@wonderland.lit.xml"); + CPPUNIT_ASSERT(boost::filesystem::exists(vcardFile)); + ByteArray data; + data.readFromFile(vcardFile.string()); + CPPUNIT_ASSERT(data.toString().beginsWith("")); + } + + void testGetVCard() { + std::auto_ptr testling(createTestling()); + VCard::ref vcard(new VCard()); + vcard->setFullName("Alice In Wonderland"); + vcard->setEMail("alice@wonderland.lit"); + testling->setVCard(JID("alice@wonderland.lit"), vcard); + + VCard::ref result = testling->getVCard(JID("alice@wonderland.lit")); + CPPUNIT_ASSERT_EQUAL(String("Alice In Wonderland"), result->getFullName()); + CPPUNIT_ASSERT_EQUAL(String("alice@wonderland.lit"), result->getEMail()); + } + + void testGetVCard_FileDoesNotExist() { + std::auto_ptr testling(createTestling()); + VCard::ref result = testling->getVCard(JID("alice@wonderland.lit")); + CPPUNIT_ASSERT(!result); + } + + private: + VCardFileStorage* createTestling() { + return new VCardFileStorage(vcardsPath); + } + + PlatformApplicationPathProvider* pathProvider; + boost::filesystem::path vcardsPath; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(VCardFileStorageTest); diff --git a/Swiften/SConscript b/Swiften/SConscript index 3d4d5f6..f206dd0 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -123,6 +123,7 @@ if env["SCONS_STAGE"] == "build" : "EventLoop", "Parser", "JID", + "VCards", "Network", "History", "StreamStack", diff --git a/Swiften/VCards/SConscript b/Swiften/VCards/SConscript new file mode 100644 index 0000000..538eb4a --- /dev/null +++ b/Swiften/VCards/SConscript @@ -0,0 +1,8 @@ +Import("swiften_env") + +objects = swiften_env.StaticObject([ + "VCardStorage.cpp", + "VCardFileStorage.cpp", + "VCardStorageFactory.cpp", + ]) +swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/VCards/VCardFileStorage.cpp b/Swiften/VCards/VCardFileStorage.cpp new file mode 100644 index 0000000..d3163fb --- /dev/null +++ b/Swiften/VCards/VCardFileStorage.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/VCards/VCardFileStorage.h" + +#include + +#include "Swiften/JID/JID.h" +#include "Swiften/Base/ByteArray.h" +#include "Swiften/Elements/VCard.h" +#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/VCardParser.h" + +namespace Swift { + +VCardFileStorage::VCardFileStorage(boost::filesystem::path dir) : vcardsPath(dir) { +} + +boost::shared_ptr VCardFileStorage::getVCard(const JID& jid) const { + boost::filesystem::path vcardPath(getVCardPath(jid)); + if (boost::filesystem::exists(vcardPath)) { + ByteArray data; + data.readFromFile(vcardPath.string()); + + VCardParser parser; + PayloadParserTester tester(&parser); + tester.parse(String(data.getData(), data.getSize())); + return boost::dynamic_pointer_cast(parser.getPayload()); + } + else { + return boost::shared_ptr(); + } +} + +void VCardFileStorage::setVCard(const JID& jid, boost::shared_ptr v) { + boost::filesystem::path vcardPath(getVCardPath(jid)); + if (!boost::filesystem::exists(vcardPath.parent_path())) { + boost::filesystem::create_directories(vcardPath.parent_path()); + } + boost::filesystem::ofstream file(getVCardPath(jid)); + file << VCardSerializer().serializePayload(v); + file.close(); +} + +boost::filesystem::path VCardFileStorage::getVCardPath(const JID& jid) const { + return boost::filesystem::path(vcardsPath / (jid.toBare().toString().getUTF8String() + ".xml")); +} + +} diff --git a/Swiften/VCards/VCardFileStorage.h b/Swiften/VCards/VCardFileStorage.h new file mode 100644 index 0000000..d75ac92 --- /dev/null +++ b/Swiften/VCards/VCardFileStorage.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. + */ + +#pragma once + +#include +#include + +#include "Swiften/VCards/VCardStorage.h" + +namespace Swift { + class VCardFileStorage : public VCardStorage { + public: + VCardFileStorage(boost::filesystem::path dir); + + virtual boost::shared_ptr getVCard(const JID& jid) const; + virtual void setVCard(const JID& jid, boost::shared_ptr v); + + private: + boost::filesystem::path getVCardPath(const JID&) const; + + private: + boost::filesystem::path vcardsPath; + }; +} diff --git a/Swiften/VCards/VCardFileStorageFactory.h b/Swiften/VCards/VCardFileStorageFactory.h new file mode 100644 index 0000000..136c6a7 --- /dev/null +++ b/Swiften/VCards/VCardFileStorageFactory.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 + +#include "Swiften/VCards/VCardStorageFactory.h" +#include "Swiften/VCards/VCardFileStorage.h" + +namespace Swift { + class VCardFileStorageFactory : public VCardStorageFactory { + public: + VCardFileStorageFactory(boost::filesystem::path base) : base(base) { + } + + virtual VCardStorage* createVCardStorage(const String& profile) { + return new VCardFileStorage(base / profile.getUTF8String()); + } + + private: + boost::filesystem::path base; + }; +} diff --git a/Swiften/VCards/VCardStorage.cpp b/Swiften/VCards/VCardStorage.cpp new file mode 100644 index 0000000..cacd083 --- /dev/null +++ b/Swiften/VCards/VCardStorage.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/VCards/VCardStorage.h" + +namespace Swift { + +VCardStorage::~VCardStorage() { +} + +} diff --git a/Swiften/VCards/VCardStorage.h b/Swiften/VCards/VCardStorage.h new file mode 100644 index 0000000..2a9044c --- /dev/null +++ b/Swiften/VCards/VCardStorage.h @@ -0,0 +1,23 @@ +/* + * 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/Elements/VCard.h" + +namespace Swift { + class JID; + + class VCardStorage { + public: + virtual ~VCardStorage(); + + virtual boost::shared_ptr getVCard(const JID& jid) const = 0; + virtual void setVCard(const JID&, boost::shared_ptr) = 0; + }; +} diff --git a/Swiften/VCards/VCardStorageFactory.cpp b/Swiften/VCards/VCardStorageFactory.cpp new file mode 100644 index 0000000..64a3e88 --- /dev/null +++ b/Swiften/VCards/VCardStorageFactory.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/VCards/VCardStorageFactory.h" + +namespace Swift { + +VCardStorageFactory::~VCardStorageFactory() { +} + +} diff --git a/Swiften/VCards/VCardStorageFactory.h b/Swiften/VCards/VCardStorageFactory.h new file mode 100644 index 0000000..7bef87b --- /dev/null +++ b/Swiften/VCards/VCardStorageFactory.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 VCardStorage; + class String; + + class VCardStorageFactory { + public: + virtual ~VCardStorageFactory(); + + virtual VCardStorage* createVCardStorage(const String& profile) = 0; + }; +} -- cgit v0.10.2-6-g49f6