Implemented basics of the "Save to Cloud…" action
This commit is contained in:
parent
c31a7d43dc
commit
861943b4cc
7 changed files with 87 additions and 46 deletions
|
@ -171,7 +171,7 @@ MenuItem* AppMenuModel::makeFileMenu()
|
|||
makeMenuItem("file-save-as"),
|
||||
makeMenuItem("file-save-a-copy"),
|
||||
makeMenuItem("file-save-selection"),
|
||||
makeMenuItem("file-save-online"), // need implement
|
||||
makeMenuItem("file-save-to-cloud"),
|
||||
makeSeparator(),
|
||||
makeMenuItem("file-import-pdf"),
|
||||
makeMenuItem("file-export"),
|
||||
|
|
|
@ -38,7 +38,6 @@ void PublishToolBarModel::load()
|
|||
|
||||
MenuItemList items {
|
||||
makeMenuItem("print"),
|
||||
makeMenuItem("file-save-online"),
|
||||
makeMenuItem("file-export")
|
||||
};
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ void ProjectActionsController::init()
|
|||
dispatcher()->reg(this, "file-save-as", this, &ProjectActionsController::saveProjectAs);
|
||||
dispatcher()->reg(this, "file-save-a-copy", this, &ProjectActionsController::saveProjectCopy);
|
||||
dispatcher()->reg(this, "file-save-selection", this, &ProjectActionsController::saveSelection);
|
||||
dispatcher()->reg(this, "file-save-online", this, &ProjectActionsController::saveOnline);
|
||||
dispatcher()->reg(this, "file-save-to-cloud", this, &ProjectActionsController::saveToCloud);
|
||||
|
||||
dispatcher()->reg(this, "file-export", this, &ProjectActionsController::exportScore);
|
||||
dispatcher()->reg(this, "file-import-pdf", this, &ProjectActionsController::importPdf);
|
||||
|
@ -337,11 +337,11 @@ bool ProjectActionsController::saveProject(const io::path& path)
|
|||
}
|
||||
|
||||
if (!project->isNewlyCreated()) {
|
||||
return doSaveScore();
|
||||
return saveProjectLocally();
|
||||
}
|
||||
|
||||
if (!path.empty()) {
|
||||
return doSaveScore(path);
|
||||
return saveProjectLocally(path);
|
||||
}
|
||||
|
||||
RetVal<SaveLocation> location = saveProjectScenario()->askSaveLocation(project, SaveMode::Save);
|
||||
|
@ -391,11 +391,52 @@ void ProjectActionsController::saveSelection()
|
|||
}
|
||||
}
|
||||
|
||||
void ProjectActionsController::saveOnline()
|
||||
void ProjectActionsController::saveToCloud()
|
||||
{
|
||||
INotationProjectPtr project = currentNotationProject();
|
||||
RetVal<SaveLocation> response = saveProjectScenario()->askSaveLocation(project, SaveMode::SaveAs, SaveLocationType::Cloud);
|
||||
if (!response.ret) {
|
||||
return;
|
||||
}
|
||||
|
||||
SaveLocation saveLocation = response.val;
|
||||
saveProjectAt(saveLocation, SaveMode::SaveAs);
|
||||
}
|
||||
|
||||
bool ProjectActionsController::saveProjectAt(const SaveLocation& location, SaveMode saveMode)
|
||||
{
|
||||
if (location.isLocal()) {
|
||||
return saveProjectLocally(location.localInfo().path, saveMode);
|
||||
}
|
||||
|
||||
if (location.isCloud()) {
|
||||
NOT_IMPLEMENTED;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProjectActionsController::saveProjectLocally(const io::path& filePath, project::SaveMode saveMode)
|
||||
{
|
||||
Ret ret = currentNotationProject()->save(filePath, saveMode);
|
||||
if (!ret) {
|
||||
LOGE() << ret.toString();
|
||||
return false;
|
||||
}
|
||||
|
||||
prependToRecentScoreList(filePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectActionsController::saveProjectToCloud(const SaveLocation::CloudInfo& info, SaveMode saveMode)
|
||||
{
|
||||
UNUSED(info)
|
||||
UNUSED(saveMode)
|
||||
|
||||
INotationProjectPtr project = globalContext()->currentProject();
|
||||
if (!project) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
QBuffer* projectData = new QBuffer();
|
||||
|
@ -405,7 +446,7 @@ void ProjectActionsController::saveOnline()
|
|||
if (!ret) {
|
||||
LOGE() << ret.toString();
|
||||
delete projectData;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
projectData->close();
|
||||
|
@ -439,6 +480,9 @@ void ProjectActionsController::saveOnline()
|
|||
|
||||
ProjectMeta meta = project->metaInfo();
|
||||
uploadingService()->uploadScore(*projectData, meta.title, meta.source);
|
||||
|
||||
// TODO(save-to-cloud): check whether upload was successful?
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectActionsController::checkCanIgnoreError(const Ret& ret, const io::path& filePath)
|
||||
|
@ -538,32 +582,6 @@ io::path ProjectActionsController::selectScoreOpeningFile()
|
|||
return interactive()->selectOpeningFile(qtrc("project", "Score"), configuration()->userProjectsPath(), filter.join(";;"));
|
||||
}
|
||||
|
||||
bool ProjectActionsController::saveProjectAt(const SaveLocation& location, SaveMode saveMode)
|
||||
{
|
||||
if (location.isLocal()) {
|
||||
return doSaveScore(location.localInfo().path, saveMode);
|
||||
}
|
||||
|
||||
if (location.isCloud()) {
|
||||
NOT_IMPLEMENTED;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProjectActionsController::doSaveScore(const io::path& filePath, project::SaveMode saveMode)
|
||||
{
|
||||
Ret ret = currentNotationProject()->save(filePath, saveMode);
|
||||
if (!ret) {
|
||||
LOGE() << ret.toString();
|
||||
return false;
|
||||
}
|
||||
|
||||
prependToRecentScoreList(filePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProjectActionsController::prependToRecentScoreList(const io::path& filePath)
|
||||
{
|
||||
if (filePath.empty()) {
|
||||
|
|
|
@ -91,7 +91,11 @@ private:
|
|||
void saveProjectAs();
|
||||
void saveProjectCopy();
|
||||
void saveSelection();
|
||||
void saveOnline();
|
||||
void saveToCloud();
|
||||
|
||||
bool saveProjectAt(const SaveLocation& saveLocation, SaveMode saveMode = SaveMode::Save);
|
||||
bool saveProjectLocally(const io::path& path = io::path(), SaveMode saveMode = SaveMode::Save);
|
||||
bool saveProjectToCloud(const SaveLocation::CloudInfo& info, SaveMode saveMode = SaveMode::Save);
|
||||
|
||||
void importPdf();
|
||||
|
||||
|
@ -104,9 +108,6 @@ private:
|
|||
|
||||
Ret doOpenProject(const io::path& filePath);
|
||||
|
||||
bool saveProjectAt(const SaveLocation& location, SaveMode saveMode);
|
||||
bool doSaveScore(const io::path& filePath = io::path(), project::SaveMode saveMode = project::SaveMode::Save);
|
||||
|
||||
Ret openPageIfNeed(Uri pageUri);
|
||||
|
||||
void exportScore();
|
||||
|
|
|
@ -48,12 +48,6 @@ const UiActionList ProjectUiActions::m_actions = {
|
|||
QT_TRANSLATE_NOOP("action", "Save score to file"),
|
||||
IconCode::Code::SAVE
|
||||
),
|
||||
UiAction("file-save-online",
|
||||
mu::context::UiCtxNotationOpened,
|
||||
QT_TRANSLATE_NOOP("action", "Upload to MuseScore.com"),
|
||||
QT_TRANSLATE_NOOP("action", "Save score on MuseScore.com"),
|
||||
IconCode::Code::CLOUD_FILE
|
||||
),
|
||||
UiAction("file-save-as",
|
||||
mu::context::UiCtxNotationOpened,
|
||||
QT_TRANSLATE_NOOP("action", "Save as…"),
|
||||
|
@ -69,6 +63,11 @@ const UiActionList ProjectUiActions::m_actions = {
|
|||
QT_TRANSLATE_NOOP("action", "Save selection…"),
|
||||
QT_TRANSLATE_NOOP("action", "Save current selection as new score")
|
||||
),
|
||||
UiAction("file-save-to-cloud",
|
||||
mu::context::UiCtxNotationOpened,
|
||||
QT_TRANSLATE_NOOP("action", "Save to cloud…"),
|
||||
IconCode::Code::CLOUD_FILE
|
||||
),
|
||||
UiAction("file-export",
|
||||
mu::context::UiCtxNotationOpened,
|
||||
QT_TRANSLATE_NOOP("action", "Export…"),
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
using namespace mu;
|
||||
using namespace mu::project;
|
||||
|
||||
constexpr int RET_CODE_CHANGE_SAVE_LOCATION_TYPE = 1234;
|
||||
|
||||
RetVal<SaveLocation> SaveProjectScenario::askSaveLocation(INotationProjectPtr project, SaveMode mode,
|
||||
SaveLocationType preselectedType) const
|
||||
{
|
||||
|
@ -39,6 +41,10 @@ RetVal<SaveLocation> SaveProjectScenario::askSaveLocation(INotationProjectPtr pr
|
|||
type = askedType.val;
|
||||
}
|
||||
|
||||
IF_ASSERT_FAILED(type != SaveLocationType::Undefined) {
|
||||
return make_ret(Ret::Code::UnknownError);
|
||||
}
|
||||
|
||||
// The user may switch between Local and Cloud as often as they want
|
||||
for (;;) {
|
||||
configuration()->setLastUsedSaveLocationType(type);
|
||||
|
@ -54,14 +60,25 @@ RetVal<SaveLocation> SaveProjectScenario::askSaveLocation(INotationProjectPtr pr
|
|||
SaveLocation::LocalInfo localInfo { path.val };
|
||||
return RetVal<SaveLocation>::make_ok(SaveLocation(localInfo));
|
||||
}
|
||||
// TODO: Add a case that changes the `type` and lets the loop rerun
|
||||
case RET_CODE_CHANGE_SAVE_LOCATION_TYPE:
|
||||
type = SaveLocationType::Cloud;
|
||||
continue;
|
||||
default:
|
||||
return path.ret;
|
||||
}
|
||||
}
|
||||
|
||||
case SaveLocationType::Cloud: {
|
||||
return make_ret(Ret::Code::NotImplemented);
|
||||
RetVal<SaveLocation::CloudInfo> info = askCloudLocation(project);
|
||||
switch (info.ret.code()) {
|
||||
case int(Ret::Code::Ok):
|
||||
return RetVal<SaveLocation>::make_ok(SaveLocation(info.val));
|
||||
case RET_CODE_CHANGE_SAVE_LOCATION_TYPE:
|
||||
type = SaveLocationType::Local;
|
||||
continue;
|
||||
default:
|
||||
return info.ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,3 +142,8 @@ RetVal<SaveLocationType> SaveProjectScenario::askSaveLocationType() const
|
|||
SaveLocationType type = static_cast<SaveLocationType>(vals["saveLocationType"].toInt());
|
||||
return RetVal<SaveLocationType>::make_ok(type);
|
||||
}
|
||||
|
||||
RetVal<SaveLocation::CloudInfo> SaveProjectScenario::askCloudLocation(INotationProjectPtr project) const
|
||||
{
|
||||
return make_ret(Ret::Code::NotImplemented);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ public:
|
|||
private:
|
||||
RetVal<SaveLocationType> saveLocationType() const;
|
||||
RetVal<SaveLocationType> askSaveLocationType() const;
|
||||
|
||||
RetVal<SaveLocation::CloudInfo> askCloudLocation(INotationProjectPtr project) const;
|
||||
};
|
||||
|
||||
class QMLSaveLocationType
|
||||
|
|
Loading…
Reference in a new issue