Skip to content

Commit

Permalink
Merge pull request #952 from meganz/develop
Browse files Browse the repository at this point in the history
Update release branch with bindings for whyamiblocked (WP-UWP)
  • Loading branch information
sergiohs84 authored Feb 14, 2018
2 parents bc0e2af + e442406 commit 986431f
Show file tree
Hide file tree
Showing 17 changed files with 264 additions and 92 deletions.
8 changes: 8 additions & 0 deletions bindings/ios/MEGASdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -4582,6 +4582,14 @@ typedef NS_ENUM(NSUInteger, PasswordStrength) {

#endif

/**
* @brief Get the MIME type associated with the extension
*
* @param extension File extension (with or without a leading dot)
* @return MIME type associated with the extension
*/
+ (NSString *)mimeTypeByExtension:(NSString *)extension;

/**
* @brief Register a device token for iOS push notifications
*
Expand Down
10 changes: 10 additions & 0 deletions bindings/ios/MEGASdk.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,16 @@ - (NSInteger)httpServerGetMaxOutputSize {

#endif

+ (NSString *)mimeTypeByExtension:(NSString *)extension {
const char *val = MegaApi::getMimeType([extension UTF8String]);
if (!val) return nil;

NSString *ret = [[NSString alloc] initWithUTF8String:val];

delete [] val;
return ret;
}

- (void)registeriOSdeviceToken:(NSString *)deviceToken delegate:(id<MEGARequestDelegate>)delegate {
self.megaApi->registerPushNotifications(PushNotificationTokenTypeiOSStandard, deviceToken ? [deviceToken UTF8String] : NULL, [self createDelegateMEGARequestListener:delegate singleListener:YES]);
}
Expand Down
28 changes: 17 additions & 11 deletions bindings/wp8/DelegateMGlobalListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ using namespace Platform;

DelegateMGlobalListener::DelegateMGlobalListener(MegaSDK^ megaSDK, MGlobalListenerInterface^ listener)
{
this->megaSDK = megaSDK;
this->listener = listener;
this->megaSDK = megaSDK;
this->listener = listener;
}

MGlobalListenerInterface^ DelegateMGlobalListener::getUserListener()
{
return listener;
return listener;
}

void DelegateMGlobalListener::onUsersUpdate(MegaApi* api, MegaUserList *users)
{
if (listener != nullptr)
listener->onUsersUpdate(megaSDK, users ? ref new MUserList(users->copy(), true) : nullptr);
if (listener != nullptr)
listener->onUsersUpdate(megaSDK, users ? ref new MUserList(users->copy(), true) : nullptr);
}

void DelegateMGlobalListener::onNodesUpdate(MegaApi* api, MegaNodeList *nodes)
{
if (listener != nullptr)
listener->onNodesUpdate(megaSDK, nodes ? ref new MNodeList(nodes->copy(), true) : nullptr);
if (listener != nullptr)
listener->onNodesUpdate(megaSDK, nodes ? ref new MNodeList(nodes->copy(), true) : nullptr);
}

void DelegateMGlobalListener::onAccountUpdate(MegaApi* api)
{
if (listener != nullptr)
listener->onAccountUpdate(megaSDK);
if (listener != nullptr)
listener->onAccountUpdate(megaSDK);
}

void DelegateMGlobalListener::onContactRequestsUpdate(MegaApi* api, MegaContactRequestList* requests)
Expand All @@ -61,6 +61,12 @@ void DelegateMGlobalListener::onContactRequestsUpdate(MegaApi* api, MegaContactR

void DelegateMGlobalListener::onReloadNeeded(MegaApi* api)
{
if (listener != nullptr)
listener->onReloadNeeded(megaSDK);
if (listener != nullptr)
listener->onReloadNeeded(megaSDK);
}

void DelegateMGlobalListener::onEvent(MegaApi* api, MegaEvent* ev)
{
if (listener != nullptr)
listener->onEvent(megaSDK, ev ? ref new MEvent(ev->copy(), true) : nullptr);
}
37 changes: 19 additions & 18 deletions bindings/wp8/DelegateMGlobalListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,26 @@

namespace mega
{
ref class MegaSDK;
ref class MegaSDK;

using namespace Windows::Foundation;
using Platform::String;
using namespace Windows::Foundation;
using Platform::String;

private class DelegateMGlobalListener : public MegaGlobalListener
{
public:
DelegateMGlobalListener(MegaSDK^ megaSDK, MGlobalListenerInterface^ listener);
MGlobalListenerInterface^ getUserListener();
private class DelegateMGlobalListener : public MegaGlobalListener
{
public:
DelegateMGlobalListener(MegaSDK^ megaSDK, MGlobalListenerInterface^ listener);
MGlobalListenerInterface^ getUserListener();

void onUsersUpdate(MegaApi* api, MegaUserList *users);
void onNodesUpdate(MegaApi* api, MegaNodeList *nodes);
void onAccountUpdate(MegaApi* api);
void onUsersUpdate(MegaApi* api, MegaUserList *users);
void onNodesUpdate(MegaApi* api, MegaNodeList *nodes);
void onAccountUpdate(MegaApi* api);
void onContactRequestsUpdate(MegaApi* api, MegaContactRequestList* requests);
void onReloadNeeded(MegaApi* api);

private:
MegaSDK^ megaSDK;
MGlobalListenerInterface^ listener;
};
}
void onReloadNeeded(MegaApi* api);
void onEvent(MegaApi* api, MegaEvent* ev);

private:
MegaSDK^ megaSDK;
MGlobalListenerInterface^ listener;
};
}
6 changes: 6 additions & 0 deletions bindings/wp8/DelegateMListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ void DelegateMListener::onReloadNeeded(MegaApi* api)
if (listener != nullptr)
listener->onReloadNeeded(megaSDK);
}

void DelegateMListener::onEvent(MegaApi* api, MegaEvent* ev)
{
if (listener != nullptr)
listener->onEvent(megaSDK, ev ? ref new MEvent(ev->copy(), true) : nullptr);
}
51 changes: 26 additions & 25 deletions bindings/wp8/DelegateMListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,34 @@

namespace mega
{
ref class MegaSDK;
ref class MegaSDK;

using namespace Windows::Foundation;
using Platform::String;
using namespace Windows::Foundation;
using Platform::String;

private class DelegateMListener : public MegaListener
{
public:
DelegateMListener(MegaSDK^ megaSDK, MListenerInterface^ listener);
MListenerInterface^ getUserListener();
private class DelegateMListener : public MegaListener
{
public:
DelegateMListener(MegaSDK^ megaSDK, MListenerInterface^ listener);
MListenerInterface^ getUserListener();

void onRequestStart(MegaApi* api, MegaRequest* request);
void onRequestFinish(MegaApi* api, MegaRequest* request, MegaError* e);
void onRequestUpdate(MegaApi* api, MegaRequest* request);
void onRequestTemporaryError(MegaApi* api, MegaRequest* request, MegaError* e);
void onTransferStart(MegaApi* api, MegaTransfer* transfer);
void onTransferFinish(MegaApi* api, MegaTransfer* transfer, MegaError* e);
void onTransferUpdate(MegaApi* api, MegaTransfer* transfer);
void onTransferTemporaryError(MegaApi* api, MegaTransfer* transfer, MegaError* e);
void onUsersUpdate(MegaApi* api, MegaUserList *users);
void onNodesUpdate(MegaApi* api, MegaNodeList *nodes);
void onAccountUpdate(MegaApi* api);
void onRequestStart(MegaApi* api, MegaRequest* request);
void onRequestFinish(MegaApi* api, MegaRequest* request, MegaError* e);
void onRequestUpdate(MegaApi* api, MegaRequest* request);
void onRequestTemporaryError(MegaApi* api, MegaRequest* request, MegaError* e);
void onTransferStart(MegaApi* api, MegaTransfer* transfer);
void onTransferFinish(MegaApi* api, MegaTransfer* transfer, MegaError* e);
void onTransferUpdate(MegaApi* api, MegaTransfer* transfer);
void onTransferTemporaryError(MegaApi* api, MegaTransfer* transfer, MegaError* e);
void onUsersUpdate(MegaApi* api, MegaUserList *users);
void onNodesUpdate(MegaApi* api, MegaNodeList *nodes);
void onAccountUpdate(MegaApi* api);
void onContactRequestsUpdate(MegaApi* api, MegaContactRequestList* requests);
void onReloadNeeded(MegaApi* api);
void onReloadNeeded(MegaApi* api);
void onEvent(MegaApi* api, MegaEvent* ev);

private:
MegaSDK^ megaSDK;
MListenerInterface^ listener;
};
}
private:
MegaSDK^ megaSDK;
MListenerInterface^ listener;
};
}
67 changes: 67 additions & 0 deletions bindings/wp8/MEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @file MError.cpp
* @brief Provides information about an event.
*
* (c) 2013-2014 by Mega Limited, Auckland, New Zealand
*
* This file is part of the MEGA SDK - Client Access Engine.
*
* Applications using the MEGA API must present a valid application key
* and comply with the the rules set forth in the Terms of Service.
*
* The MEGA SDK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/

#include "MEvent.h"

using namespace mega;
using namespace Platform;

MEvent::MEvent(MegaEvent *megaEvent, bool cMemoryOwn)
{
this->megaEvent = megaEvent;
this->cMemoryOwn = cMemoryOwn;
}

MEvent::~MEvent()
{
if (cMemoryOwn)
delete megaEvent;
}

MegaEvent* MEvent::getCPtr()
{
return megaEvent;
}

MEvent^ MEvent::copy()
{
return megaEvent ? ref new MEvent(megaEvent->copy(), true) : nullptr;
}

MEventType MEvent::getType()
{
return (MEventType) (megaEvent ? megaEvent->getType() : -1);
}

String^ MEvent::getText()
{
std::string utf16text;
const char *utf8text = megaEvent->getText();

MegaApi::utf8ToUtf16(utf8text, &utf16text);

return ref new String((wchar_t *)utf16text.data());
}

int MEvent::getNumber()
{
return megaEvent ? megaEvent->getNumber() : 0;
}
59 changes: 59 additions & 0 deletions bindings/wp8/MEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @file MError.h
* @brief Provides information about an event.
*
* (c) 2013-2014 by Mega Limited, Auckland, New Zealand
*
* This file is part of the MEGA SDK - Client Access Engine.
*
* Applications using the MEGA API must present a valid application key
* and comply with the the rules set forth in the Terms of Service.
*
* The MEGA SDK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/

#pragma once

#include "megaapi.h"

namespace mega
{
using namespace Windows::Foundation;
using Platform::String;

public enum class MEventType
{
EVENT_COMMIT_DB = 0,
EVENT_ACCOUNT_CONFIRMATION = 1,
EVENT_CHANGE_TO_HTTPS = 2,
EVENT_DISCONNECT = 3,
EVENT_ACCOUNT_BLOCKED = 4
};

public ref class MEvent sealed
{
friend ref class MegaSDK;
friend class DelegateMListener;
friend class DelegateMGlobalListener;

public:
virtual ~MEvent();
MEvent^ copy();
MEventType getType();
String^ getText();
int getNumber();

private:
MEvent(MegaEvent *megaEvent, bool cMemoryOwn);
MegaEvent *megaEvent;
MegaEvent *getCPtr();
bool cMemoryOwn;
};
}
23 changes: 12 additions & 11 deletions bindings/wp8/MGlobalListenerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@

namespace mega
{
ref class MegaSDK;
ref class MegaSDK;

using namespace Windows::Foundation;
using Platform::String;
using namespace Windows::Foundation;
using Platform::String;

public interface class MGlobalListenerInterface
{
public:
void onUsersUpdate(MegaSDK^ api, MUserList ^users);
void onNodesUpdate(MegaSDK^ api, MNodeList^ nodes);
void onAccountUpdate(MegaSDK^ api);
public interface class MGlobalListenerInterface
{
public:
void onUsersUpdate(MegaSDK^ api, MUserList ^users);
void onNodesUpdate(MegaSDK^ api, MNodeList^ nodes);
void onAccountUpdate(MegaSDK^ api);
void onContactRequestsUpdate(MegaSDK^ api, MContactRequestList^ requests);
void onReloadNeeded(MegaSDK^ api);
};
void onReloadNeeded(MegaSDK^ api);
void onEvent(MegaSDK^ api, MEvent^ ev);
};
}
Loading

0 comments on commit 986431f

Please sign in to comment.