-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from oblivioncth/feature/fp_protocol
Add support for 'flashpoint://' protocol
- Loading branch information
Showing
21 changed files
with
477 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Unit Include | ||
#include "c-share.h" | ||
|
||
// Qx Includes | ||
#include <qx/core/qx-system.h> | ||
|
||
// Project Includes | ||
#include "task/t-message.h" | ||
#include "utility.h" | ||
|
||
//=============================================================================================================== | ||
// CShareError | ||
//=============================================================================================================== | ||
|
||
//-Constructor------------------------------------------------------------- | ||
//Private: | ||
CShareError::CShareError(Type t, const QString& s) : | ||
mType(t), | ||
mSpecific(s) | ||
{} | ||
|
||
//-Instance Functions------------------------------------------------------------- | ||
//Public: | ||
bool CShareError::isValid() const { return mType != NoError; } | ||
QString CShareError::specific() const { return mSpecific; } | ||
CShareError::Type CShareError::type() const { return mType; } | ||
|
||
//Private: | ||
Qx::Severity CShareError::deriveSeverity() const { return Qx::Critical; } | ||
quint32 CShareError::deriveValue() const { return mType; } | ||
QString CShareError::derivePrimary() const { return ERR_STRINGS.value(mType); } | ||
QString CShareError::deriveSecondary() const { return mSpecific; } | ||
|
||
//=============================================================================================================== | ||
// CShare | ||
//=============================================================================================================== | ||
|
||
//-Constructor------------------------------------------------------------- | ||
//Public: | ||
CShare::CShare(Core& coreRef) : TitleCommand(coreRef) {} | ||
|
||
//-Instance Functions------------------------------------------------------------- | ||
//Protected: | ||
QList<const QCommandLineOption*> CShare::options() { return CL_OPTIONS_SPECIFIC + TitleCommand::options(); } | ||
QString CShare::name() { return NAME; } | ||
|
||
Qx::Error CShare::perform() | ||
{ | ||
// Prioritize scheme (un)registration | ||
if(mParser.isSet(CL_OPTION_CONFIGURE)) | ||
{ | ||
mCore.logEvent(NAME, LOG_EVENT_REGISTRATION); | ||
|
||
if(!Qx::setDefaultProtocolHandler(SCHEME, SCHEME_NAME, CLIFP_PATH, {u"play"_s, u"-u"_s})) | ||
{ | ||
CShareError err(CShareError::RegistrationFailed); | ||
mCore.postError(NAME, err); | ||
return err; | ||
} | ||
|
||
// Enqueue success message task | ||
TMessage* successMsg = new TMessage(&mCore); | ||
successMsg->setStage(Task::Stage::Primary); | ||
successMsg->setText(MSG_REGISTRATION_COMPLETE); | ||
mCore.enqueueSingleTask(successMsg); | ||
|
||
return CShareError(); | ||
} | ||
else if(mParser.isSet(CL_OPTION_UNCONFIGURE)) | ||
{ | ||
mCore.logEvent(NAME, LOG_EVENT_UNREGISTRATION); | ||
|
||
#ifdef __linux__ // Function is too jank on linux right now, so always fail/no-op there | ||
if(true) | ||
#else | ||
if(!Qx::removeDefaultProtocolHandler(SCHEME, CLIFP_PATH)) | ||
#endif | ||
{ | ||
CShareError err(CShareError::UnregistrationFailed); | ||
mCore.postError(NAME, err); | ||
return err; | ||
} | ||
|
||
// Enqueue success message task | ||
TMessage* successMsg = new TMessage(&mCore); | ||
successMsg->setStage(Task::Stage::Primary); | ||
successMsg->setText(MSG_UNREGISTRATION_COMPLETE); | ||
mCore.enqueueSingleTask(successMsg); | ||
|
||
return CShareError(); | ||
} | ||
|
||
// Get ID of title to share | ||
QUuid shareId; | ||
if(Qx::Error ide = getTitleId(shareId); ide.isValid()) | ||
return ide; | ||
|
||
mCore.setStatus(STATUS_SHARE, shareId.toString(QUuid::WithoutBraces)); | ||
|
||
// Generate URL | ||
QString idStr = shareId.toString(QUuid::WithoutBraces); | ||
QString shareUrl = mParser.isSet(CL_OPTION_UNIVERSAL) ? SCHEME_TEMPLATE_UNI.arg(idStr) : SCHEME_TEMPLATE_STD.arg(idStr); | ||
mCore.logEvent(NAME, LOG_EVENT_URL.arg(shareUrl)); | ||
|
||
// Add URL to clipboard | ||
mCore.requestClipboardUpdate(shareUrl); | ||
|
||
// Enqueue message task | ||
TMessage* urlMsg = new TMessage(&mCore); | ||
urlMsg->setStage(Task::Stage::Primary); | ||
urlMsg->setText(MSG_GENERATED_URL.arg(shareUrl)); | ||
urlMsg->setSelectable(true); | ||
mCore.enqueueSingleTask(urlMsg); | ||
|
||
// Return success | ||
return Qx::Error(); | ||
} |
Oops, something went wrong.