diff options
Diffstat (limited to 'SwifTools')
70 files changed, 863 insertions, 88 deletions
diff --git a/SwifTools/Application/ApplicationPathProvider.cpp b/SwifTools/Application/ApplicationPathProvider.cpp index e683563..aa7e609 100644 --- a/SwifTools/Application/ApplicationPathProvider.cpp +++ b/SwifTools/Application/ApplicationPathProvider.cpp @@ -7,9 +7,9 @@ #include <boost/filesystem.hpp> #include <iostream> -#include "SwifTools/Application/ApplicationPathProvider.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Base/Paths.h" +#include <SwifTools/Application/ApplicationPathProvider.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Base/Paths.h> namespace Swift { diff --git a/SwifTools/Application/CocoaApplication.mm b/SwifTools/Application/CocoaApplication.mm index edfdc25..cbb5f2e 100644 --- a/SwifTools/Application/CocoaApplication.mm +++ b/SwifTools/Application/CocoaApplication.mm @@ -1,4 +1,4 @@ -#include "SwifTools/Application/CocoaApplication.h" +#include <SwifTools/Application/CocoaApplication.h> #include <AppKit/AppKit.h> #include <Cocoa/Cocoa.h> diff --git a/SwifTools/Application/MacOSXApplicationPathProvider.cpp b/SwifTools/Application/MacOSXApplicationPathProvider.cpp index 085eb33..41b0e4c 100644 --- a/SwifTools/Application/MacOSXApplicationPathProvider.cpp +++ b/SwifTools/Application/MacOSXApplicationPathProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Application/MacOSXApplicationPathProvider.h" +#include <SwifTools/Application/MacOSXApplicationPathProvider.h> #include <iostream> #include <mach-o/dyld.h> diff --git a/SwifTools/Application/MacOSXApplicationPathProvider.h b/SwifTools/Application/MacOSXApplicationPathProvider.h index fec1944..760ea9b 100644 --- a/SwifTools/Application/MacOSXApplicationPathProvider.h +++ b/SwifTools/Application/MacOSXApplicationPathProvider.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Application/ApplicationPathProvider.h" +#include <SwifTools/Application/ApplicationPathProvider.h> namespace Swift { class MacOSXApplicationPathProvider : public ApplicationPathProvider { diff --git a/SwifTools/Application/PlatformApplicationPathProvider.h b/SwifTools/Application/PlatformApplicationPathProvider.h index bb9bfa9..7ea4b35 100644 --- a/SwifTools/Application/PlatformApplicationPathProvider.h +++ b/SwifTools/Application/PlatformApplicationPathProvider.h @@ -6,20 +6,20 @@ #pragma once -#include "Swiften/Base/Platform.h" +#include <Swiften/Base/Platform.h> #if defined(SWIFTEN_PLATFORM_MACOSX) -#include "SwifTools/Application/MacOSXApplicationPathProvider.h" +#include <SwifTools/Application/MacOSXApplicationPathProvider.h> namespace Swift { typedef MacOSXApplicationPathProvider PlatformApplicationPathProvider; } #elif defined(SWIFTEN_PLATFORM_WIN32) -#include "SwifTools/Application/WindowsApplicationPathProvider.h" +#include <SwifTools/Application/WindowsApplicationPathProvider.h> namespace Swift { typedef WindowsApplicationPathProvider PlatformApplicationPathProvider; } #else -#include "SwifTools/Application/UnixApplicationPathProvider.h" +#include <SwifTools/Application/UnixApplicationPathProvider.h> namespace Swift { typedef UnixApplicationPathProvider PlatformApplicationPathProvider; } diff --git a/SwifTools/Application/SConscript b/SwifTools/Application/SConscript index 0097bca..32924fc 100644 --- a/SwifTools/Application/SConscript +++ b/SwifTools/Application/SConscript @@ -21,6 +21,7 @@ else : objects = swiftools_env.StaticObject(sources) swiftools_env.Append(SWIFTOOLS_OBJECTS = [objects]) -env.Append(UNITTEST_SOURCES = [ - File("UnitTest/ApplicationPathProviderTest.cpp") - ]) +if swiftools_env["PLATFORM"] != "darwin" or swiftools_env["target"] == "native" : + env.Append(UNITTEST_SOURCES = [ + File("UnitTest/ApplicationPathProviderTest.cpp") + ]) diff --git a/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp b/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp index a418bc2..5eb0e16 100644 --- a/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp +++ b/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp @@ -9,7 +9,7 @@ #include <string> #include <boost/algorithm/string.hpp> -#include "SwifTools/Application/PlatformApplicationPathProvider.h" +#include <SwifTools/Application/PlatformApplicationPathProvider.h> using namespace Swift; diff --git a/SwifTools/Application/UnixApplicationPathProvider.cpp b/SwifTools/Application/UnixApplicationPathProvider.cpp index d5a2f58..784256f 100644 --- a/SwifTools/Application/UnixApplicationPathProvider.cpp +++ b/SwifTools/Application/UnixApplicationPathProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Application/UnixApplicationPathProvider.h" +#include <SwifTools/Application/UnixApplicationPathProvider.h> #include <unistd.h> #include <boost/algorithm/string.hpp> diff --git a/SwifTools/Application/UnixApplicationPathProvider.h b/SwifTools/Application/UnixApplicationPathProvider.h index 7ca64c3..198e4ee 100644 --- a/SwifTools/Application/UnixApplicationPathProvider.h +++ b/SwifTools/Application/UnixApplicationPathProvider.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Application/ApplicationPathProvider.h" +#include <SwifTools/Application/ApplicationPathProvider.h> namespace Swift { class UnixApplicationPathProvider : public ApplicationPathProvider { diff --git a/SwifTools/Application/WindowsApplicationPathProvider.cpp b/SwifTools/Application/WindowsApplicationPathProvider.cpp index afcdea2..8514fa7 100644 --- a/SwifTools/Application/WindowsApplicationPathProvider.cpp +++ b/SwifTools/Application/WindowsApplicationPathProvider.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Application/WindowsApplicationPathProvider.h" +#include <SwifTools/Application/WindowsApplicationPathProvider.h> #include <windows.h> diff --git a/SwifTools/Application/WindowsApplicationPathProvider.h b/SwifTools/Application/WindowsApplicationPathProvider.h index 9428908..f288326 100644 --- a/SwifTools/Application/WindowsApplicationPathProvider.h +++ b/SwifTools/Application/WindowsApplicationPathProvider.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Application/ApplicationPathProvider.h" +#include <SwifTools/Application/ApplicationPathProvider.h> namespace Swift { class WindowsApplicationPathProvider : public ApplicationPathProvider { diff --git a/SwifTools/AutoUpdater/AutoUpdater.cpp b/SwifTools/AutoUpdater/AutoUpdater.cpp index f4e462b..e424f3b 100644 --- a/SwifTools/AutoUpdater/AutoUpdater.cpp +++ b/SwifTools/AutoUpdater/AutoUpdater.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/AutoUpdater/AutoUpdater.h" +#include <SwifTools/AutoUpdater/AutoUpdater.h> namespace Swift { diff --git a/SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.cpp b/SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.cpp index 4dd06c7..d2e89ac 100644 --- a/SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.cpp +++ b/SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.h" +#include <SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.h> #include <cassert> #ifdef HAVE_SPARKLE -#include "SwifTools/AutoUpdater/SparkleAutoUpdater.h" +#include <SwifTools/AutoUpdater/SparkleAutoUpdater.h> #endif namespace Swift { diff --git a/SwifTools/AutoUpdater/SparkleAutoUpdater.h b/SwifTools/AutoUpdater/SparkleAutoUpdater.h index fc08975..f367945 100644 --- a/SwifTools/AutoUpdater/SparkleAutoUpdater.h +++ b/SwifTools/AutoUpdater/SparkleAutoUpdater.h @@ -7,7 +7,7 @@ #pragma once #include <string> -#include "SwifTools/AutoUpdater/AutoUpdater.h" +#include <SwifTools/AutoUpdater/AutoUpdater.h> namespace Swift { class SparkleAutoUpdater : public AutoUpdater { diff --git a/SwifTools/AutoUpdater/SparkleAutoUpdater.mm b/SwifTools/AutoUpdater/SparkleAutoUpdater.mm index 440e178..c35abc8 100644 --- a/SwifTools/AutoUpdater/SparkleAutoUpdater.mm +++ b/SwifTools/AutoUpdater/SparkleAutoUpdater.mm @@ -1,4 +1,4 @@ -#include "SwifTools/AutoUpdater/SparkleAutoUpdater.h" +#include <SwifTools/AutoUpdater/SparkleAutoUpdater.h> #include <Cocoa/Cocoa.h> #include <Sparkle/Sparkle.h> diff --git a/SwifTools/Cocoa/CocoaAction.h b/SwifTools/Cocoa/CocoaAction.h new file mode 100644 index 0000000..a46ef7c --- /dev/null +++ b/SwifTools/Cocoa/CocoaAction.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 <Cocoa/Cocoa.h> +#include <boost/function.hpp> + +@interface CocoaAction : NSObject { + boost::function<void ()>* function; +} + +/** + * Acquires ownership of 'f'. + */ +- (id) initWithFunction: (boost::function<void()>*) f; + +/** + * Calls the functor passed as a parameter to the contsructor. + */ +- (void) doAction: (id) sender; + +@end diff --git a/SwifTools/Cocoa/CocoaAction.mm b/SwifTools/Cocoa/CocoaAction.mm new file mode 100644 index 0000000..d560787 --- /dev/null +++ b/SwifTools/Cocoa/CocoaAction.mm @@ -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. + */ + +#include <SwifTools/Cocoa/CocoaAction.h> + +@implementation CocoaAction + +- (id) initWithFunction: (boost::function<void()>*) f { + if ([super init]) { + function = f; + } + return self; +} + +- (void) dealloc { + delete function; + [super dealloc]; +} + +- (void) doAction: (id) sender { + (void) sender; + (*function)(); +} + +@end diff --git a/SwifTools/Cocoa/SConscript b/SwifTools/Cocoa/SConscript new file mode 100644 index 0000000..4ae4a07 --- /dev/null +++ b/SwifTools/Cocoa/SConscript @@ -0,0 +1,8 @@ +Import("swiftools_env", "env") + +sources = [] +if swiftools_env["PLATFORM"] == "darwin" and swiftools_env["target"] == "native" : + sources += ["CocoaAction.mm"] + +objects = swiftools_env.StaticObject(sources) +swiftools_env.Append(SWIFTOOLS_OBJECTS = [objects]) diff --git a/SwifTools/Dock/Dock.cpp b/SwifTools/Dock/Dock.cpp index 77bcd84..e159b8d 100644 --- a/SwifTools/Dock/Dock.cpp +++ b/SwifTools/Dock/Dock.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Dock/Dock.h" +#include <SwifTools/Dock/Dock.h> namespace Swift { diff --git a/SwifTools/Dock/MacOSXDock.h b/SwifTools/Dock/MacOSXDock.h index 64cc737..df2686f 100644 --- a/SwifTools/Dock/MacOSXDock.h +++ b/SwifTools/Dock/MacOSXDock.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Dock/Dock.h" +#include <SwifTools/Dock/Dock.h> namespace Swift { diff --git a/SwifTools/Dock/MacOSXDock.mm b/SwifTools/Dock/MacOSXDock.mm index a7a3d55..b8374fa 100644 --- a/SwifTools/Dock/MacOSXDock.mm +++ b/SwifTools/Dock/MacOSXDock.mm @@ -1,10 +1,10 @@ -#include "SwifTools/Dock/MacOSXDock.h" +#include <SwifTools/Dock/MacOSXDock.h> #include <AppKit/AppKit.h> #include <Cocoa/Cocoa.h> #include <boost/lexical_cast.hpp> -#include "Swiften/Base/String.h" +#include <Swiften/Base/String.h> namespace Swift { diff --git a/SwifTools/Dock/NullDock.h b/SwifTools/Dock/NullDock.h index a1655a4..b015770 100644 --- a/SwifTools/Dock/NullDock.h +++ b/SwifTools/Dock/NullDock.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Dock/Dock.h" +#include <SwifTools/Dock/Dock.h> namespace Swift { class NullDock : public Dock { diff --git a/SwifTools/Dock/WindowsDock.h b/SwifTools/Dock/WindowsDock.h index dc298da..0254617 100644 --- a/SwifTools/Dock/WindowsDock.h +++ b/SwifTools/Dock/WindowsDock.h @@ -9,8 +9,8 @@ #include <QSystemTrayIcon> #include <boost/lexical_cast.hpp> -#include "SwifTools/Dock/Dock.h" -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Dock/Dock.h> +#include <SwifTools/Notifier/Notifier.h> namespace Swift { class WindowsDock : public Dock { diff --git a/SwifTools/Idle/ActualIdleDetector.cpp b/SwifTools/Idle/ActualIdleDetector.cpp index 59df632..2a99e1a 100644 --- a/SwifTools/Idle/ActualIdleDetector.cpp +++ b/SwifTools/Idle/ActualIdleDetector.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/ActualIdleDetector.h" +#include <SwifTools/Idle/ActualIdleDetector.h> #include <boost/bind.hpp> #include <iostream> -#include "SwifTools/Idle/IdleQuerier.h" -#include "Swiften/Network/Timer.h" -#include "Swiften/Network/TimerFactory.h" +#include <SwifTools/Idle/IdleQuerier.h> +#include <Swiften/Network/Timer.h> +#include <Swiften/Network/TimerFactory.h> namespace Swift { diff --git a/SwifTools/Idle/ActualIdleDetector.h b/SwifTools/Idle/ActualIdleDetector.h index 3a355cc..7845398 100644 --- a/SwifTools/Idle/ActualIdleDetector.h +++ b/SwifTools/Idle/ActualIdleDetector.h @@ -8,7 +8,7 @@ #include <boost/shared_ptr.hpp> -#include "SwifTools/Idle/IdleDetector.h" +#include <SwifTools/Idle/IdleDetector.h> namespace Swift { class IdleQuerier; diff --git a/SwifTools/Idle/DummyIdleQuerier.h b/SwifTools/Idle/DummyIdleQuerier.h index 0c40643..162d8f6 100644 --- a/SwifTools/Idle/DummyIdleQuerier.h +++ b/SwifTools/Idle/DummyIdleQuerier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class DummyIdleQuerier : public IdleQuerier { diff --git a/SwifTools/Idle/IdleDetector.cpp b/SwifTools/Idle/IdleDetector.cpp index f29be01..66ec4a5 100644 --- a/SwifTools/Idle/IdleDetector.cpp +++ b/SwifTools/Idle/IdleDetector.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/IdleDetector.h" +#include <SwifTools/Idle/IdleDetector.h> namespace Swift { diff --git a/SwifTools/Idle/IdleDetector.h b/SwifTools/Idle/IdleDetector.h index 746e281..4b54801 100644 --- a/SwifTools/Idle/IdleDetector.h +++ b/SwifTools/Idle/IdleDetector.h @@ -6,7 +6,7 @@ #pragma once -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> namespace Swift { diff --git a/SwifTools/Idle/IdleQuerier.cpp b/SwifTools/Idle/IdleQuerier.cpp index d8c01ca..f553252 100644 --- a/SwifTools/Idle/IdleQuerier.cpp +++ b/SwifTools/Idle/IdleQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { diff --git a/SwifTools/Idle/IdleQuerierTest/IdleQuerierTest.cpp b/SwifTools/Idle/IdleQuerierTest/IdleQuerierTest.cpp index 5ae4a4d..df233a2 100644 --- a/SwifTools/Idle/IdleQuerierTest/IdleQuerierTest.cpp +++ b/SwifTools/Idle/IdleQuerierTest/IdleQuerierTest.cpp @@ -6,8 +6,8 @@ #include <iostream> -#include "SwifTools/Idle/PlatformIdleQuerier.h" -#include "Swiften/Base/sleep.h" +#include <SwifTools/Idle/PlatformIdleQuerier.h> +#include <Swiften/Base/sleep.h> using namespace Swift; diff --git a/SwifTools/Idle/MacOSXIdleQuerier.cpp b/SwifTools/Idle/MacOSXIdleQuerier.cpp index 4760285..64e010b 100644 --- a/SwifTools/Idle/MacOSXIdleQuerier.cpp +++ b/SwifTools/Idle/MacOSXIdleQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/MacOSXIdleQuerier.h" +#include <SwifTools/Idle/MacOSXIdleQuerier.h> #pragma GCC diagnostic ignored "-Wold-style-cast" diff --git a/SwifTools/Idle/MacOSXIdleQuerier.h b/SwifTools/Idle/MacOSXIdleQuerier.h index ebd4656..fbbd448 100644 --- a/SwifTools/Idle/MacOSXIdleQuerier.h +++ b/SwifTools/Idle/MacOSXIdleQuerier.h @@ -8,7 +8,7 @@ #include <IOKit/IOKitLib.h> -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class MacOSXIdleQuerier : public IdleQuerier { diff --git a/SwifTools/Idle/PlatformIdleQuerier.cpp b/SwifTools/Idle/PlatformIdleQuerier.cpp index a28e701..34bcedd 100644 --- a/SwifTools/Idle/PlatformIdleQuerier.cpp +++ b/SwifTools/Idle/PlatformIdleQuerier.cpp @@ -4,17 +4,17 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/PlatformIdleQuerier.h" -#include "Swiften/Base/Platform.h" +#include <SwifTools/Idle/PlatformIdleQuerier.h> +#include <Swiften/Base/Platform.h> -#if defined(SWIFTEN_PLATFORM_MACOSX) && defined(HAVE_IOKIT) -#include "SwifTools/Idle/MacOSXIdleQuerier.h" +#if defined(SWIFTEN_PLATFORM_MACOSX) && defined(HAVE_IOKIT) && !defined(SWIFTEN_PLATFORM_IPHONE) +#include <SwifTools/Idle/MacOSXIdleQuerier.h> #elif defined(SWIFTEN_PLATFORM_WINDOWS) -#include "SwifTools/Idle/WindowsIdleQuerier.h" +#include <SwifTools/Idle/WindowsIdleQuerier.h> #elif defined(HAVE_XSS) -#include "SwifTools/Idle/XSSIdleQuerier.h" +#include <SwifTools/Idle/XSSIdleQuerier.h> #endif -#include "SwifTools/Idle/DummyIdleQuerier.h" +#include <SwifTools/Idle/DummyIdleQuerier.h> #include <cassert> #include <iostream> @@ -23,7 +23,7 @@ namespace Swift { PlatformIdleQuerier::PlatformIdleQuerier() : querier(NULL) { #if defined(SWIFTEN_PLATFORM_MACOSX) -#if defined(HAVE_IOKIT) +#if defined(HAVE_IOKIT) && !defined(SWIFTEN_PLATFORM_IPHONE) querier = new MacOSXIdleQuerier(); #else querier = new DummyIdleQuerier(); diff --git a/SwifTools/Idle/PlatformIdleQuerier.h b/SwifTools/Idle/PlatformIdleQuerier.h index 30c4bb7..2679e39 100644 --- a/SwifTools/Idle/PlatformIdleQuerier.h +++ b/SwifTools/Idle/PlatformIdleQuerier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class PlatformIdleQuerier : public IdleQuerier { diff --git a/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp b/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp index 3fa7136..686b7a0 100644 --- a/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp +++ b/SwifTools/Idle/UnitTest/ActualIdleDetectorTest.cpp @@ -8,11 +8,11 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <boost/bind.hpp> -#include "SwifTools/Idle/ActualIdleDetector.h" -#include "SwifTools/Idle/IdleQuerier.h" -#include "Swiften/Base/foreach.h" -#include "Swiften/Network/TimerFactory.h" -#include "Swiften/Network/Timer.h" +#include <SwifTools/Idle/ActualIdleDetector.h> +#include <SwifTools/Idle/IdleQuerier.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/Timer.h> using namespace Swift; diff --git a/SwifTools/Idle/WindowsIdleQuerier.cpp b/SwifTools/Idle/WindowsIdleQuerier.cpp index 904fd6d..4b9a5a1 100644 --- a/SwifTools/Idle/WindowsIdleQuerier.cpp +++ b/SwifTools/Idle/WindowsIdleQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/WindowsIdleQuerier.h" +#include <SwifTools/Idle/WindowsIdleQuerier.h> #include <windows.h> diff --git a/SwifTools/Idle/WindowsIdleQuerier.h b/SwifTools/Idle/WindowsIdleQuerier.h index 8297c77..4a219e5 100644 --- a/SwifTools/Idle/WindowsIdleQuerier.h +++ b/SwifTools/Idle/WindowsIdleQuerier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class WindowsIdleQuerier : public IdleQuerier { diff --git a/SwifTools/Idle/XSSIdleQuerier.cpp b/SwifTools/Idle/XSSIdleQuerier.cpp index 39a3cef..74e1eda 100644 --- a/SwifTools/Idle/XSSIdleQuerier.cpp +++ b/SwifTools/Idle/XSSIdleQuerier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Idle/XSSIdleQuerier.h" +#include <SwifTools/Idle/XSSIdleQuerier.h> #include <cassert> #include <iostream> diff --git a/SwifTools/Idle/XSSIdleQuerier.h b/SwifTools/Idle/XSSIdleQuerier.h index b00c702..29569a3 100644 --- a/SwifTools/Idle/XSSIdleQuerier.h +++ b/SwifTools/Idle/XSSIdleQuerier.h @@ -9,7 +9,7 @@ #include <X11/Xlib.h> #include <X11/extensions/scrnsaver.h> -#include "SwifTools/Idle/IdleQuerier.h" +#include <SwifTools/Idle/IdleQuerier.h> namespace Swift { class XSSIdleQuerier : public IdleQuerier { diff --git a/SwifTools/LastLineTracker.cpp b/SwifTools/LastLineTracker.cpp new file mode 100644 index 0000000..a7360a8 --- /dev/null +++ b/SwifTools/LastLineTracker.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "LastLineTracker.h" + +using namespace Swift; + +LastLineTracker::LastLineTracker() { + lastFocus = true; + shouldMove = false; +} + +void LastLineTracker::setHasFocus(bool focus) { + if (!focus && lastFocus) { + shouldMove = true; + lastFocus = focus; + return; + } + shouldMove = false; + lastFocus = focus; +} + +bool LastLineTracker::getShouldMoveLastLine() { + bool ret = shouldMove; + shouldMove = false; + return ret; +} diff --git a/SwifTools/LastLineTracker.h b/SwifTools/LastLineTracker.h new file mode 100644 index 0000000..b7c9a3b --- /dev/null +++ b/SwifTools/LastLineTracker.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +namespace Swift { + class LastLineTracker { + public: + LastLineTracker(); + void setHasFocus(bool focus); + bool getShouldMoveLastLine(); + private: + bool lastFocus; + bool shouldMove; + }; +} diff --git a/SwifTools/Linkify.cpp b/SwifTools/Linkify.cpp index 91c713f..15fd9a5 100644 --- a/SwifTools/Linkify.cpp +++ b/SwifTools/Linkify.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Linkify.h" +#include <SwifTools/Linkify.h> #include <boost/regex.hpp> #include <sstream> @@ -12,7 +12,7 @@ namespace Swift { -static boost::regex linkifyRegexp("^https?://.*"); +static boost::regex linkifyRegexp("^(https?://|xmpp:).*"); std::string Linkify::linkify(const std::string& input) { std::ostringstream result; diff --git a/SwifTools/Notifier/GNTPNotifier.cpp b/SwifTools/Notifier/GNTPNotifier.cpp index 9a20c33..9bc05bd 100644 --- a/SwifTools/Notifier/GNTPNotifier.cpp +++ b/SwifTools/Notifier/GNTPNotifier.cpp @@ -6,15 +6,15 @@ // FIXME: This notifier needs finishing (handling callbacks etc.) -#include "SwifTools/Notifier/GNTPNotifier.h" +#include <SwifTools/Notifier/GNTPNotifier.h> #include <cassert> #include <iostream> #include <boost/bind.hpp> #include <sstream> -#include "Swiften/Base/foreach.h" -#include "Swiften/Network/ConnectionFactory.h" +#include <Swiften/Base/foreach.h> +#include <Swiften/Network/ConnectionFactory.h> namespace Swift { diff --git a/SwifTools/Notifier/GNTPNotifier.h b/SwifTools/Notifier/GNTPNotifier.h index a740c27..2cba044 100644 --- a/SwifTools/Notifier/GNTPNotifier.h +++ b/SwifTools/Notifier/GNTPNotifier.h @@ -8,8 +8,8 @@ #include <boost/filesystem.hpp> -#include "SwifTools/Notifier/Notifier.h" -#include "Swiften/Network/Connection.h" +#include <SwifTools/Notifier/Notifier.h> +#include <Swiften/Network/Connection.h> namespace Swift { class ConnectionFactory; diff --git a/SwifTools/Notifier/GrowlNotifier.cpp b/SwifTools/Notifier/GrowlNotifier.cpp index e289313..46355e9 100644 --- a/SwifTools/Notifier/GrowlNotifier.cpp +++ b/SwifTools/Notifier/GrowlNotifier.cpp @@ -8,10 +8,10 @@ #include <cassert> -#include "Swiften/Base/String.h" -#include "Swiften/Base/ByteArray.h" -#include "SwifTools/Notifier/GrowlNotifier.h" -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/String.h> +#include <Swiften/Base/ByteArray.h> +#include <SwifTools/Notifier/GrowlNotifier.h> +#include <Swiften/Base/foreach.h> #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/SwifTools/Notifier/GrowlNotifier.h b/SwifTools/Notifier/GrowlNotifier.h index d4a6178..e2686e8 100644 --- a/SwifTools/Notifier/GrowlNotifier.h +++ b/SwifTools/Notifier/GrowlNotifier.h @@ -10,7 +10,7 @@ #include <Growl/Growl.h> #include <boost/filesystem/fstream.hpp> -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> namespace Swift { /** diff --git a/SwifTools/Notifier/LoggingNotifier.h b/SwifTools/Notifier/LoggingNotifier.h index 18ae0e2..32e0610 100644 --- a/SwifTools/Notifier/LoggingNotifier.h +++ b/SwifTools/Notifier/LoggingNotifier.h @@ -6,8 +6,8 @@ #pragma once -#include "SwifTools/Notifier/Notifier.h" -#include "Swiften/Base/ByteArray.h" +#include <SwifTools/Notifier/Notifier.h> +#include <Swiften/Base/ByteArray.h> namespace Swift { class LoggingNotifier : public Notifier { diff --git a/SwifTools/Notifier/Notifier.cpp b/SwifTools/Notifier/Notifier.cpp index 1673400..5cd9c50 100644 --- a/SwifTools/Notifier/Notifier.cpp +++ b/SwifTools/Notifier/Notifier.cpp @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> namespace Swift { diff --git a/SwifTools/Notifier/NullNotifier.h b/SwifTools/Notifier/NullNotifier.h index 24b4476..2fa9c11 100644 --- a/SwifTools/Notifier/NullNotifier.h +++ b/SwifTools/Notifier/NullNotifier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> namespace Swift { class NullNotifier : public Notifier { diff --git a/SwifTools/Notifier/SnarlNotifier.cpp b/SwifTools/Notifier/SnarlNotifier.cpp index d891e7d..19d3622 100644 --- a/SwifTools/Notifier/SnarlNotifier.cpp +++ b/SwifTools/Notifier/SnarlNotifier.cpp @@ -4,14 +4,14 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/Notifier/SnarlNotifier.h" +#include <SwifTools/Notifier/SnarlNotifier.h> #include <cassert> #include <iostream> #include <boost/bind.hpp> -#include "Swiften/Base/foreach.h" -#include "SwifTools/Notifier/Win32NotifierWindow.h" +#include <Swiften/Base/foreach.h> +#include <SwifTools/Notifier/Win32NotifierWindow.h> #define SWIFT_SNARLNOTIFIER_MESSAGE_ID 0x4567 // Sounds sick to pick a number, but this is windows diff --git a/SwifTools/Notifier/SnarlNotifier.h b/SwifTools/Notifier/SnarlNotifier.h index 9e2cddf..065c9ec 100644 --- a/SwifTools/Notifier/SnarlNotifier.h +++ b/SwifTools/Notifier/SnarlNotifier.h @@ -8,7 +8,7 @@ #include <map> -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> #include "SnarlInterface.h" namespace Swift { diff --git a/SwifTools/Notifier/TogglableNotifier.h b/SwifTools/Notifier/TogglableNotifier.h index 415caf6..e8de5de 100644 --- a/SwifTools/Notifier/TogglableNotifier.h +++ b/SwifTools/Notifier/TogglableNotifier.h @@ -6,7 +6,7 @@ #pragma once -#include "SwifTools/Notifier/Notifier.h" +#include <SwifTools/Notifier/Notifier.h> namespace Swift { class TogglableNotifier : public Notifier { diff --git a/SwifTools/Notifier/Win32NotifierWindow.h b/SwifTools/Notifier/Win32NotifierWindow.h index 7ac149b..2279b0b 100644 --- a/SwifTools/Notifier/Win32NotifierWindow.h +++ b/SwifTools/Notifier/Win32NotifierWindow.h @@ -8,7 +8,7 @@ //#include <windows.h> -#include "Swiften/Base/boost_bsignals.h" +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class Win32NotifierWindow { diff --git a/SwifTools/SConscript b/SwifTools/SConscript index d4747db..e5085cc 100644 --- a/SwifTools/SConscript +++ b/SwifTools/SConscript @@ -27,6 +27,7 @@ if env["SCONS_STAGE"] == "build" : "AutoUpdater/PlatformAutoUpdaterFactory.cpp", "Linkify.cpp", "TabComplete.cpp", + "LastLineTracker.cpp", ] if swiftools_env.get("HAVE_SPARKLE", 0) : @@ -50,8 +51,10 @@ if env["SCONS_STAGE"] == "build" : "Application", "Dock", "Notifier", + "URIHandler", "Idle/IdleQuerierTest", "Idle/UnitTest", + "Cocoa", "UnitTest" ]) diff --git a/SwifTools/TabComplete.cpp b/SwifTools/TabComplete.cpp index b123360..4c295ab 100644 --- a/SwifTools/TabComplete.cpp +++ b/SwifTools/TabComplete.cpp @@ -4,12 +4,12 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "SwifTools/TabComplete.h" +#include <SwifTools/TabComplete.h> #include <algorithm> #include <boost/algorithm/string.hpp> -#include "Swiften/Base/foreach.h" +#include <Swiften/Base/foreach.h> namespace Swift { diff --git a/SwifTools/URIHandler/MacOSXURIHandler.h b/SwifTools/URIHandler/MacOSXURIHandler.h new file mode 100644 index 0000000..f803420 --- /dev/null +++ b/SwifTools/URIHandler/MacOSXURIHandler.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <SwifTools/URIHandler/URIHandler.h> + +namespace Swift { + class MacOSXURIHandler : public URIHandler { + public: + MacOSXURIHandler(); + virtual ~MacOSXURIHandler(); + + virtual void start(); + virtual void stop(); + + private: + class Private; + Private* p; + }; +} diff --git a/SwifTools/URIHandler/MacOSXURIHandler.mm b/SwifTools/URIHandler/MacOSXURIHandler.mm new file mode 100644 index 0000000..3542e2f --- /dev/null +++ b/SwifTools/URIHandler/MacOSXURIHandler.mm @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/URIHandler/MacOSXURIHandler.h> + +#include <Cocoa/Cocoa.h> +#include <iostream> + +using namespace Swift; + +@interface MacOSXURIEventHandler : NSObject { + URIHandler* handler; +} +- (id) initWithHandler: (URIHandler*) handler; +- (void) getUrl: (NSAppleEventDescriptor*) event withReplyEvent: (NSAppleEventDescriptor*) replyEvent; + +@end +@implementation MacOSXURIEventHandler + - (id) initWithHandler: (URIHandler*) h { + if ([super init]) { + handler = h; + } + return self; + } + + - (void) getUrl: (NSAppleEventDescriptor*) event withReplyEvent: (NSAppleEventDescriptor*) replyEvent { + (void) replyEvent; + NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; + handler->onURI(std::string([url UTF8String])); + } +@end + +class MacOSXURIHandler::Private { + public: + MacOSXURIEventHandler* eventHandler; +}; + +MacOSXURIHandler::MacOSXURIHandler() { + p = new Private(); + p->eventHandler = [[MacOSXURIEventHandler alloc] initWithHandler: this]; +} + +MacOSXURIHandler::~MacOSXURIHandler() { + [p->eventHandler release]; + delete p; +} + +void MacOSXURIHandler::start() { + [[NSAppleEventManager sharedAppleEventManager] setEventHandler:p->eventHandler andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; + NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier]; + LSSetDefaultHandlerForURLScheme((CFStringRef)@"xmpp", (CFStringRef)bundleID); +} + +void MacOSXURIHandler::stop() { + [[NSAppleEventManager sharedAppleEventManager] removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; +} diff --git a/SwifTools/URIHandler/MacOSXURIHandlerHelpers.h b/SwifTools/URIHandler/MacOSXURIHandlerHelpers.h new file mode 100644 index 0000000..5a2db7a --- /dev/null +++ b/SwifTools/URIHandler/MacOSXURIHandlerHelpers.h @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +namespace Swift { + void registerAppAsDefaultXMPPURIHandler(); +} diff --git a/SwifTools/URIHandler/MacOSXURIHandlerHelpers.mm b/SwifTools/URIHandler/MacOSXURIHandlerHelpers.mm new file mode 100644 index 0000000..dca91b8 --- /dev/null +++ b/SwifTools/URIHandler/MacOSXURIHandlerHelpers.mm @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/URIHandler/MacOSXURIHandlerHelpers.h> + +#include <Cocoa/Cocoa.h> + +namespace Swift { + void registerAppAsDefaultXMPPURIHandler() { + NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier]; + LSSetDefaultHandlerForURLScheme((CFStringRef)@"xmpp", (CFStringRef)bundleID); + } +} diff --git a/SwifTools/URIHandler/NullURIHandler.h b/SwifTools/URIHandler/NullURIHandler.h new file mode 100644 index 0000000..28c35bb --- /dev/null +++ b/SwifTools/URIHandler/NullURIHandler.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <SwifTools/URIHandler/URIHandler.h> + +namespace Swift { + class NullURIHandler : public URIHandler { + public: + virtual void start() { + } + + virtual void stop() { + } + }; +} diff --git a/SwifTools/URIHandler/SConscript b/SwifTools/URIHandler/SConscript new file mode 100644 index 0000000..42c6ca8 --- /dev/null +++ b/SwifTools/URIHandler/SConscript @@ -0,0 +1,23 @@ +Import("swiftools_env", "env") + +sources = [ + "XMPPURI.cpp", + "URIHandler.cpp", + ] + +if swiftools_env["PLATFORM"] == "darwin" and swiftools_env["target"] == "native" : + sources += [ + "MacOSXURIHandler.mm", + "MacOSXURIHandlerHelpers.mm", + ] +elif swiftools_env["PLATFORM"] == "win32" : + sources += [] +else : + sources += [] + +objects = swiftools_env.StaticObject(sources) +swiftools_env.Append(SWIFTOOLS_OBJECTS = [objects]) + +env.Append(UNITTEST_SOURCES = [ + File("UnitTest/XMPPURITest.cpp"), + ]) diff --git a/SwifTools/URIHandler/URIHandler.cpp b/SwifTools/URIHandler/URIHandler.cpp new file mode 100644 index 0000000..91e54e5 --- /dev/null +++ b/SwifTools/URIHandler/URIHandler.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/URIHandler/URIHandler.h> + +using namespace Swift; + +URIHandler::URIHandler() { +} + +URIHandler::~URIHandler() { +} diff --git a/SwifTools/URIHandler/URIHandler.h b/SwifTools/URIHandler/URIHandler.h new file mode 100644 index 0000000..9dd13a8 --- /dev/null +++ b/SwifTools/URIHandler/URIHandler.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <Swiften/Base/boost_bsignals.h> + +namespace Swift { + class URIHandler { + public: + URIHandler(); + virtual ~URIHandler(); + + boost::signal<void (const std::string&)> onURI; + }; +} diff --git a/SwifTools/URIHandler/UnitTest/XMPPURITest.cpp b/SwifTools/URIHandler/UnitTest/XMPPURITest.cpp new file mode 100644 index 0000000..8d03b60 --- /dev/null +++ b/SwifTools/URIHandler/UnitTest/XMPPURITest.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <SwifTools/URIHandler/XMPPURI.h> + +using namespace Swift; + +class XMPPURITest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(XMPPURITest); + CPPUNIT_TEST(testFromString_Authority); + CPPUNIT_TEST(testFromString_AuthorityWithPath); + CPPUNIT_TEST(testFromString_AuthorityWithFragment); + CPPUNIT_TEST(testFromString_AuthorityWithPathAndFragment); + CPPUNIT_TEST(testFromString_AuthorityWithIntlChars); + CPPUNIT_TEST(testFromString_AuthorityWithQueryWithoutParameters); + CPPUNIT_TEST(testFromString_AuthorityWithQueryWithParameters); + CPPUNIT_TEST(testFromString_AuthorityWithQueryWithoutParametersWithFragment); + CPPUNIT_TEST(testFromString_AuthorityWithQueryWithParametersWithFragment); + CPPUNIT_TEST(testFromString_Path); + CPPUNIT_TEST(testFromString_PathWithFragment); + CPPUNIT_TEST(testFromString_PathWithIntlChars); + CPPUNIT_TEST(testFromString_PathWithInvalidEscapedChar); + CPPUNIT_TEST(testFromString_PathWithIncompleteEscapedChar); + CPPUNIT_TEST(testFromString_PathWithIncompleteEscapedChar2); + CPPUNIT_TEST(testFromString_PathWithQueryWithoutParameters); + CPPUNIT_TEST(testFromString_PathWithQueryWithParameters); + CPPUNIT_TEST(testFromString_PathWithQueryWithoutParametersWithFragment); + CPPUNIT_TEST(testFromString_PathWithQueryWithParametersWithFragment); + CPPUNIT_TEST(testFromString_NoPrefix); + CPPUNIT_TEST_SUITE_END(); + + public: + void testFromString_Authority() { + XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com"); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority()); + } + + void testFromString_AuthorityWithPath() { + XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com/baz@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath()); + } + + void testFromString_AuthorityWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_AuthorityWithPathAndFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com/baz@example.com#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_AuthorityWithIntlChars() { + XMPPURI testling = XMPPURI::fromString("xmpp://nasty!%23$%25()*+,-.;=\%3F\%5B\%5C\%5D\%5E_\%60\%7B\%7C\%7D~node@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID("nasty!#$\%()*+,-.;=?[\\]^_`{|}~node@example.com"), testling.getAuthority()); + } + + void testFromString_AuthorityWithQueryWithoutParameters() { + XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + } + + void testFromString_AuthorityWithQueryWithParameters() { + XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject")); + CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body")); + } + + void testFromString_AuthorityWithQueryWithoutParametersWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_AuthorityWithQueryWithParametersWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject")); + CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body")); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_Path() { + XMPPURI testling = XMPPURI::fromString("xmpp:baz@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath()); + } + + void testFromString_PathWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp:baz@example.com#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_PathWithIntlChars() { + XMPPURI testling = XMPPURI::fromString("xmpp:nasty!%23$%25()*+,-.;=\%3F\%5B\%5C\%5D\%5E_\%60\%7B\%7C\%7D~node@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID("nasty!#$\%()*+,-.;=?[\\]^_`{|}~node@example.com"), testling.getPath()); + } + + void testFromString_PathWithInvalidEscapedChar() { + XMPPURI testling = XMPPURI::fromString("xmpp:test%%@example.com"); + + CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath()); + } + + void testFromString_PathWithIncompleteEscapedChar() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com%"); + + CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath()); + } + + void testFromString_PathWithIncompleteEscapedChar2() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com%1"); + + CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath()); + } + + void testFromString_PathWithQueryWithoutParameters() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + } + + void testFromString_PathWithQueryWithParameters() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject")); + CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body")); + } + + void testFromString_PathWithQueryWithoutParametersWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_PathWithQueryWithParametersWithFragment() { + XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message#myfragment"); + + CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath()); + CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType()); + CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject")); + CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body")); + CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment()); + } + + void testFromString_NoPrefix() { + XMPPURI testling = XMPPURI::fromString("baz@example.com"); + + CPPUNIT_ASSERT(testling.isNull()); + } + + private: + std::string get(const std::map<std::string, std::string>& m, const std::string& k) { + std::map<std::string, std::string>::const_iterator i = m.find(k); + return i == m.end() ? "" : i->second; + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(XMPPURITest); diff --git a/SwifTools/URIHandler/XMPPURI.cpp b/SwifTools/URIHandler/XMPPURI.cpp new file mode 100644 index 0000000..de83ac2 --- /dev/null +++ b/SwifTools/URIHandler/XMPPURI.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/URIHandler/XMPPURI.h> + +#include <boost/algorithm/string/predicate.hpp> +#include <boost/algorithm/string/find_format.hpp> +#include <boost/algorithm/string/formatter.hpp> +#include <boost/algorithm/string/find_iterator.hpp> +#include <boost/algorithm/string/split.hpp> +#include <boost/algorithm/string/classification.hpp> +#include <sstream> +#include <stdexcept> +#include <vector> + +using namespace Swift; + +// Should be in anonymous namespace, but older GCCs complain if we do that +struct PercentEncodedCharacterFinder { + template<typename Iterator> + boost::iterator_range<Iterator> operator()(Iterator begin, Iterator end) { + boost::iterator_range<Iterator> r = boost::first_finder("%")(begin, end); + if (r.end() == end) { + return r; + } + else { + if (r.end() + 1 == end || r.end() + 2 == end) { + throw std::runtime_error("Incomplete escape character"); + } + else { + r.advance_end(2); + return r; + } + } + } +}; + +struct PercentUnencodeFormatter { + template<typename FindResult> + std::string operator()(const FindResult& match) const { + std::stringstream s; + s << std::hex << std::string(match.begin() + 1, match.end()); + unsigned int value; + s >> value; + if (s.fail() || s.bad()) { + throw std::runtime_error("Invalid escape character"); + } + unsigned char charValue = static_cast<unsigned char>(value); + return std::string(reinterpret_cast<const char*>(&charValue), 1); + } +}; + +namespace { + std::string unescape(const std::string& s) { + try { + return boost::find_format_all_copy(s, PercentEncodedCharacterFinder(), PercentUnencodeFormatter()); + } + catch (const std::exception&) { + return ""; + } + } +} + +XMPPURI::XMPPURI() { +} + +XMPPURI XMPPURI::fromString(const std::string& s) { + XMPPURI result; + if (boost::starts_with(s, "xmpp:")) { + std::string uri = s.substr(5, s.npos); + bool parsePath = true; + bool parseQuery = true; + bool parseFragment = true; + + // Parse authority + if (boost::starts_with(uri, "//")) { + size_t i = uri.find_first_of("/#?", 2); + result.setAuthority(JID(unescape(uri.substr(2, i - 2)))); + if (i == uri.npos) { + uri = ""; + parsePath = parseQuery = parseFragment = false; + } + else { + if (uri[i] == '?') { + parsePath = false; + } + else if (uri[i] == '#') { + parseQuery = parsePath = false; + } + uri = uri.substr(i + 1, uri.npos); + } + } + + // Parse path + if (parsePath) { + size_t i = uri.find_first_of("#?"); + result.setPath(JID(unescape(uri.substr(0, i)))); + if (i == uri.npos) { + uri = ""; + parseQuery = parseFragment = false; + } + else { + if (uri[i] == '#') { + parseQuery = false; + } + uri = uri.substr(i + 1, uri.npos); + } + } + + // Parse query + if (parseQuery) { + size_t end = uri.find_first_of("#"); + std::string query = uri.substr(0, end); + bool haveType = false; + typedef boost::split_iterator<std::string::iterator> split_iterator; + for (split_iterator it = boost::make_split_iterator(query, boost::first_finder(";")); it != split_iterator(); ++it) { + if (haveType) { + std::vector<std::string> keyValue; + boost::split(keyValue, *it, boost::is_any_of("=")); + if (keyValue.size() == 1) { + result.addQueryParameter(unescape(keyValue[0]), ""); + } + else if (keyValue.size() >= 2) { + result.addQueryParameter(unescape(keyValue[0]), unescape(keyValue[1])); + } + } + else { + result.setQueryType(unescape(boost::copy_range<std::string>(*it))); + haveType = true; + } + } + uri = (end == uri.npos ? "" : uri.substr(end + 1, uri.npos)); + } + + // Parse fragment + if (parseFragment) { + result.setFragment(unescape(uri)); + } + } + return result; +} diff --git a/SwifTools/URIHandler/XMPPURI.h b/SwifTools/URIHandler/XMPPURI.h new file mode 100644 index 0000000..266b79b --- /dev/null +++ b/SwifTools/URIHandler/XMPPURI.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <map> + +#include <Swiften/JID/JID.h> + +namespace Swift { + class XMPPURI { + public: + XMPPURI(); + + const JID& getAuthority() const { + return authority; + } + + void setAuthority(const JID& j) { + authority = j; + } + + const JID& getPath() const { + return path; + } + + void setPath(const JID& j) { + path = j; + } + + const std::string& getQueryType() const { + return queryType; + } + + void setQueryType(const std::string& q) { + queryType = q; + } + + const std::map<std::string, std::string>& getQueryParameters() const { + return queryParameters; + } + + void addQueryParameter(const std::string& key, const std::string& path) { + queryParameters[key] = path; + } + + const std::string& getFragment() const { + return fragment; + } + + void setFragment(const std::string& f) { + fragment = f; + } + + bool isNull() const { + return !authority.isValid() && !path.isValid(); + } + + static XMPPURI fromString(const std::string&); + + private: + JID authority; + JID path; + std::string fragment; + std::string queryType; + std::map<std::string, std::string> queryParameters; + }; +} diff --git a/SwifTools/UnitTest/LastLineTrackerTest.cpp b/SwifTools/UnitTest/LastLineTrackerTest.cpp new file mode 100644 index 0000000..a7046ed --- /dev/null +++ b/SwifTools/UnitTest/LastLineTrackerTest.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <SwifTools/LastLineTracker.h> + +using namespace Swift; + +class LastLineTrackerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(LastLineTrackerTest); + CPPUNIT_TEST(testFocusNormal); + CPPUNIT_TEST(testFocusOut); + CPPUNIT_TEST(testFocusOtherTab); + CPPUNIT_TEST(testRepeatedFocusOut); + CPPUNIT_TEST(testRepeatedFocusIn); + CPPUNIT_TEST_SUITE_END(); + public: + LastLineTrackerTest () { + }; + void testFocusNormal() { + LastLineTracker testling; + testling.setHasFocus(true); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + } + void testFocusOut() { + LastLineTracker testling; + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + } + void testFocusOtherTab() { + LastLineTracker testling; + testling.setHasFocus(true); + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + } + + void testRepeatedFocusOut() { + LastLineTracker testling; + testling.setHasFocus(true); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(false, testling.getShouldMoveLastLine()); + } + void testRepeatedFocusIn() { + LastLineTracker testling; + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + testling.setHasFocus(true); + testling.setHasFocus(false); + CPPUNIT_ASSERT_EQUAL(true, testling.getShouldMoveLastLine()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(LastLineTrackerTest); diff --git a/SwifTools/UnitTest/LinkifyTest.cpp b/SwifTools/UnitTest/LinkifyTest.cpp index f7e2a37..3d0ce00 100644 --- a/SwifTools/UnitTest/LinkifyTest.cpp +++ b/SwifTools/UnitTest/LinkifyTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "SwifTools/Linkify.h" +#include <SwifTools/Linkify.h> using namespace Swift; diff --git a/SwifTools/UnitTest/SConscript b/SwifTools/UnitTest/SConscript index 8034905..e469deb 100644 --- a/SwifTools/UnitTest/SConscript +++ b/SwifTools/UnitTest/SConscript @@ -2,5 +2,6 @@ Import("env") env.Append(UNITTEST_SOURCES = [ File("LinkifyTest.cpp"), - File("TabCompleteTest.cpp") + File("TabCompleteTest.cpp"), + File("LastLineTrackerTest.cpp"), ]) diff --git a/SwifTools/UnitTest/TabCompleteTest.cpp b/SwifTools/UnitTest/TabCompleteTest.cpp index 2224839..0466484 100644 --- a/SwifTools/UnitTest/TabCompleteTest.cpp +++ b/SwifTools/UnitTest/TabCompleteTest.cpp @@ -7,7 +7,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "SwifTools/TabComplete.h" +#include <SwifTools/TabComplete.h> using namespace Swift; |