summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-03-28 15:46:49 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-03-28 15:46:49 (GMT)
commitf53a1ef582494458301b97bf6e546be52d7ff7e8 (patch)
tree7571b5cbcbd8a8f1dd1c966c9045b6cb69f0e295 /Swiften/Application
parent638345680d72ca6acaf123f2c8c1c391f696e371 (diff)
downloadswift-contrib-f53a1ef582494458301b97bf6e546be52d7ff7e8.zip
swift-contrib-f53a1ef582494458301b97bf6e546be52d7ff7e8.tar.bz2
Moving submodule contents back.
Diffstat (limited to 'Swiften/Application')
-rw-r--r--Swiften/Application/Application.cpp30
-rw-r--r--Swiften/Application/Application.h33
-rw-r--r--Swiften/Application/ApplicationMessageDisplay.cpp8
-rw-r--r--Swiften/Application/ApplicationMessageDisplay.h15
-rw-r--r--Swiften/Application/MacOSX/MacOSXApplication.cpp22
-rw-r--r--Swiften/Application/MacOSX/MacOSXApplication.h25
-rw-r--r--Swiften/Application/MacOSX/MacOSXApplicationInitializer.h16
-rw-r--r--Swiften/Application/MacOSX/MacOSXApplicationInitializer.mm24
-rw-r--r--Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.h17
-rw-r--r--Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.mm20
-rw-r--r--Swiften/Application/NullApplicationMessageDisplay.h16
-rw-r--r--Swiften/Application/Platform/PlatformApplication.h24
-rw-r--r--Swiften/Application/SConscript16
-rw-r--r--Swiften/Application/UnitTest/ApplicationTest.cpp39
-rw-r--r--Swiften/Application/Unix/UnixApplication.h32
-rw-r--r--Swiften/Application/Windows/WindowsApplication.h36
16 files changed, 373 insertions, 0 deletions
diff --git a/Swiften/Application/Application.cpp b/Swiften/Application/Application.cpp
new file mode 100644
index 0000000..be77e95
--- /dev/null
+++ b/Swiften/Application/Application.cpp
@@ -0,0 +1,30 @@
+#include "Swiften/Application/Application.h"
+
+#include <boost/filesystem.hpp>
+#include <stdlib.h>
+
+#include "Swiften/Application/ApplicationMessageDisplay.h"
+
+namespace Swift {
+
+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());
+ boost::filesystem::create_directory(result);
+ return result;
+}
+
+}
diff --git a/Swiften/Application/Application.h b/Swiften/Application/Application.h
new file mode 100644
index 0000000..20d686c
--- /dev/null
+++ b/Swiften/Application/Application.h
@@ -0,0 +1,33 @@
+#ifndef SWIFTEN_Application_H
+#define SWIFTEN_Application_H
+
+#include <boost/filesystem.hpp>
+
+#include "Swiften/Base/String.h"
+
+namespace Swift {
+ class ApplicationMessageDisplay;
+
+ class Application {
+ public:
+ 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_;
+ }
+
+ virtual ApplicationMessageDisplay* getApplicationMessageDisplay() = 0;
+
+ private:
+ String name_;
+ };
+}
+
+#endif
diff --git a/Swiften/Application/ApplicationMessageDisplay.cpp b/Swiften/Application/ApplicationMessageDisplay.cpp
new file mode 100644
index 0000000..48db37d
--- /dev/null
+++ b/Swiften/Application/ApplicationMessageDisplay.cpp
@@ -0,0 +1,8 @@
+#include "Swiften/Application/ApplicationMessageDisplay.h"
+
+namespace Swift {
+
+ApplicationMessageDisplay::~ApplicationMessageDisplay() {
+}
+
+}
diff --git a/Swiften/Application/ApplicationMessageDisplay.h b/Swiften/Application/ApplicationMessageDisplay.h
new file mode 100644
index 0000000..df7f0cb
--- /dev/null
+++ b/Swiften/Application/ApplicationMessageDisplay.h
@@ -0,0 +1,15 @@
+#ifndef SWIFTEN_ApplicationMessageDisplay_H
+#define SWIFTEN_ApplicationMessageDisplay_H
+
+namespace Swift {
+ class String;
+
+ class ApplicationMessageDisplay {
+ public:
+ virtual ~ApplicationMessageDisplay();
+
+ virtual void setMessage(const String& message) = 0;
+ };
+}
+
+#endif
diff --git a/Swiften/Application/MacOSX/MacOSXApplication.cpp b/Swiften/Application/MacOSX/MacOSXApplication.cpp
new file mode 100644
index 0000000..79d7586
--- /dev/null
+++ b/Swiften/Application/MacOSX/MacOSXApplication.cpp
@@ -0,0 +1,22 @@
+#include "Swiften/Application/MacOSX/MacOSXApplication.h"
+
+namespace Swift {
+
+MacOSXApplication::MacOSXApplication(const String& name) : Application(name) {
+}
+
+ApplicationMessageDisplay* MacOSXApplication::getApplicationMessageDisplay() {
+ return &messageDisplay_;
+}
+
+boost::filesystem::path MacOSXApplication::getSettingsDir() const {
+ boost::filesystem::path result(getHomeDir() / "Library/Application Support" / getName().getUTF8String());
+ boost::filesystem::create_directory(result);
+ return result;
+}
+
+boost::filesystem::path MacOSXApplication::getHomeDir() const {
+ return boost::filesystem::path(getenv("HOME"));
+}
+
+}
diff --git a/Swiften/Application/MacOSX/MacOSXApplication.h b/Swiften/Application/MacOSX/MacOSXApplication.h
new file mode 100644
index 0000000..cd5e69f
--- /dev/null
+++ b/Swiften/Application/MacOSX/MacOSXApplication.h
@@ -0,0 +1,25 @@
+#ifndef SWIFTEN_MacOSXApplication_H
+#define SWIFTEN_MacOSXApplication_H
+
+#include "Swiften/Application/Application.h"
+#include "Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.h"
+#include "Swiften/Application/MacOSX/MacOSXApplicationInitializer.h"
+
+namespace Swift {
+ class ApplicationMessageDisplay;
+
+ class MacOSXApplication : public Application {
+ public:
+ MacOSXApplication(const String& name);
+
+ virtual boost::filesystem::path getHomeDir() const;
+ virtual ApplicationMessageDisplay* getApplicationMessageDisplay();
+ boost::filesystem::path getSettingsDir() const;
+
+ private:
+ MacOSXApplicationInitializer initializer_;
+ MacOSXApplicationMessageDisplay messageDisplay_;
+ };
+}
+
+#endif
diff --git a/Swiften/Application/MacOSX/MacOSXApplicationInitializer.h b/Swiften/Application/MacOSX/MacOSXApplicationInitializer.h
new file mode 100644
index 0000000..db551eb
--- /dev/null
+++ b/Swiften/Application/MacOSX/MacOSXApplicationInitializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_MacOSXApplicationInitializer_H
+#define SWIFTEN_MacOSXApplicationInitializer_H
+
+namespace Swift {
+ class MacOSXApplicationInitializer {
+ public:
+ MacOSXApplicationInitializer();
+ ~MacOSXApplicationInitializer();
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif
diff --git a/Swiften/Application/MacOSX/MacOSXApplicationInitializer.mm b/Swiften/Application/MacOSX/MacOSXApplicationInitializer.mm
new file mode 100644
index 0000000..e401697
--- /dev/null
+++ b/Swiften/Application/MacOSX/MacOSXApplicationInitializer.mm
@@ -0,0 +1,24 @@
+#include "Swiften/Application/MacOSX/MacOSXApplicationInitializer.h"
+
+#include <AppKit/AppKit.h>
+#include <Cocoa/Cocoa.h>
+
+namespace Swift {
+
+class MacOSXApplicationInitializer::Private {
+ public:
+ NSAutoreleasePool* autoReleasePool_;
+};
+
+MacOSXApplicationInitializer::MacOSXApplicationInitializer() {
+ d = new MacOSXApplicationInitializer::Private();
+ NSApplicationLoad();
+ d->autoReleasePool_ = [[NSAutoreleasePool alloc] init];
+}
+
+MacOSXApplicationInitializer::~MacOSXApplicationInitializer() {
+ [d->autoReleasePool_ release];
+ delete d;
+}
+
+}
diff --git a/Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.h b/Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.h
new file mode 100644
index 0000000..98af1fa
--- /dev/null
+++ b/Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.h
@@ -0,0 +1,17 @@
+#ifndef SWIFTEN_MacOSXApplicationMessageDisplay_H
+#define SWIFTEN_MacOSXApplicationMessageDisplay_H
+
+#include "Swiften/Application/ApplicationMessageDisplay.h"
+
+namespace Swift {
+ class String;
+
+ class MacOSXApplicationMessageDisplay : public ApplicationMessageDisplay {
+ public:
+ MacOSXApplicationMessageDisplay();
+
+ void setMessage(const String& label);
+ };
+}
+
+#endif
diff --git a/Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.mm b/Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.mm
new file mode 100644
index 0000000..c10c707
--- /dev/null
+++ b/Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.mm
@@ -0,0 +1,20 @@
+#include "Swiften/Application/MacOSX/MacOSXApplicationMessageDisplay.h"
+
+#include <AppKit/AppKit.h>
+#include <Cocoa/Cocoa.h>
+
+#include "Swiften/Base/String.h"
+
+namespace Swift {
+
+MacOSXApplicationMessageDisplay::MacOSXApplicationMessageDisplay() {
+}
+
+void MacOSXApplicationMessageDisplay::setMessage(const String& label) {
+ NSString *labelString = [[NSString alloc] initWithUTF8String: label.getUTF8Data()];
+ [[NSApp dockTile] setBadgeLabel: labelString];
+ [labelString release];
+ [NSApp requestUserAttention: NSInformationalRequest];
+}
+
+}
diff --git a/Swiften/Application/NullApplicationMessageDisplay.h b/Swiften/Application/NullApplicationMessageDisplay.h
new file mode 100644
index 0000000..03e0b42
--- /dev/null
+++ b/Swiften/Application/NullApplicationMessageDisplay.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_NullApplicationMessageDisplay_H
+#define SWIFTEN_NullApplicationMessageDisplay_H
+
+#include "Swiften/Application/ApplicationMessageDisplay.h"
+
+namespace Swift {
+ class NullApplicationMessageDisplay : public ApplicationMessageDisplay {
+ public:
+ NullApplicationMessageDisplay() {}
+
+ virtual void setMessage(const String&) {
+ }
+ };
+}
+
+#endif
diff --git a/Swiften/Application/Platform/PlatformApplication.h b/Swiften/Application/Platform/PlatformApplication.h
new file mode 100644
index 0000000..749bce4
--- /dev/null
+++ b/Swiften/Application/Platform/PlatformApplication.h
@@ -0,0 +1,24 @@
+#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/SConscript b/Swiften/Application/SConscript
new file mode 100644
index 0000000..78b3a34
--- /dev/null
+++ b/Swiften/Application/SConscript
@@ -0,0 +1,16 @@
+Import("swiften_env")
+
+sources = [
+ "Application.cpp",
+ "ApplicationMessageDisplay.cpp",
+ ]
+
+if swiften_env["PLATFORM"] == "darwin" and swiften_env["target"] == "native" :
+ sources += [
+ "MacOSX/MacOSXApplication.cpp",
+ "MacOSX/MacOSXApplicationMessageDisplay.mm",
+ "MacOSX/MacOSXApplicationInitializer.mm",
+ ]
+
+objects = swiften_env.StaticObject(sources)
+swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/Application/UnitTest/ApplicationTest.cpp b/Swiften/Application/UnitTest/ApplicationTest.cpp
new file mode 100644
index 0000000..0196755
--- /dev/null
+++ b/Swiften/Application/UnitTest/ApplicationTest.cpp
@@ -0,0 +1,39 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#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
new file mode 100644
index 0000000..c2671d8
--- /dev/null
+++ b/Swiften/Application/Unix/UnixApplication.h
@@ -0,0 +1,32 @@
+#ifndef SWIFTEN_UnixApplication_H
+#define SWIFTEN_UnixApplication_H
+
+#include "Swiften/Application/Application.h"
+#include "Swiften/Application/NullApplicationMessageDisplay.h"
+
+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()));
+ boost::filesystem::create_directory(result);
+ return result;
+ }
+
+ private:
+ NullApplicationMessageDisplay messageDisplay_;
+ };
+}
+
+#endif
diff --git a/Swiften/Application/Windows/WindowsApplication.h b/Swiften/Application/Windows/WindowsApplication.h
new file mode 100644
index 0000000..365157b
--- /dev/null
+++ b/Swiften/Application/Windows/WindowsApplication.h
@@ -0,0 +1,36 @@
+#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