2014-11-14 21:03:46 +01:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2014 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
# include "musescore.h"
# include "libmscore/score.h"
2014-11-24 17:25:32 +01:00
# include "libmscore/undo.h"
2014-11-14 21:03:46 +01:00
# include "uploadscoredialog.h"
namespace Ms {
//---------------------------------------------------------
// showUploadScore
//---------------------------------------------------------
void MuseScore : : showUploadScoreDialog ( )
{
2015-04-10 17:29:43 +02:00
if ( ! currentScore ( ) )
return ;
if ( ! currentScore ( ) - > sanityCheck ( ) ) {
QMessageBox msgBox ;
2015-04-28 13:45:52 +02:00
msgBox . setWindowTitle ( QObject : : tr ( " MuseScore: Upload Error " ) ) ;
msgBox . setText ( tr ( " This score cannot be saved online. Please fix the corrupted measures and try again. " ) ) ;
2015-04-10 17:29:43 +02:00
msgBox . setDetailedText ( MScore : : lastError ) ;
msgBox . setTextFormat ( Qt : : RichText ) ;
msgBox . setIcon ( QMessageBox : : Warning ) ;
msgBox . setStandardButtons ( QMessageBox : : Ok ) ;
msgBox . exec ( ) ;
return ;
}
2014-11-14 21:03:46 +01:00
if ( uploadScoreDialog = = nullptr ) {
uploadScoreDialog = new UploadScoreDialog ( _loginManager ) ;
}
2015-02-03 13:42:37 +01:00
2015-04-10 17:29:43 +02:00
uploadScoreDialog - > setTitle ( currentScore ( ) - > title ( ) ) ;
_loginManager - > tryLogin ( ) ;
2014-11-14 21:03:46 +01:00
}
//---------------------------------------------------------
// UploadScoreDialog
//---------------------------------------------------------
UploadScoreDialog : : UploadScoreDialog ( LoginManager * loginManager )
: QDialog ( 0 )
{
setupUi ( this ) ;
setWindowFlags ( this - > windowFlags ( ) & ~ Qt : : WindowContextHelpButtonHint ) ;
license - > addItem ( tr ( " All Rights reserved " ) , " all-rights-reserved " ) ;
license - > addItem ( tr ( " Creative Commons Attribution " ) , " cc-by " ) ;
license - > addItem ( tr ( " Creative Commons Attribution Share Alike " ) , " cc-by-sa " ) ;
license - > addItem ( tr ( " Creative Commons Attribution No Derivative Works " ) , " cc-by-nd " ) ;
license - > addItem ( tr ( " Creative Commons Attribution Noncommercial " ) , " cc-by-nc " ) ;
license - > addItem ( tr ( " Creative Commons Attribution Noncommercial Share Alike " ) , " cc-by-nc-sa " ) ;
license - > addItem ( tr ( " Creative Commons Attribution Noncommercial Non Derivate Works " ) , " cc-by-nc-nd " ) ;
license - > addItem ( tr ( " Public Domain " ) , " publicdomain " ) ;
license - > addItem ( tr ( " Creative Commons Zero " ) , " cc-zero " ) ;
2015-02-26 18:11:39 +01:00
licenseHelp - > setText ( tr ( " <a href= \" %1 \" >What does this mean?</a> " ) . arg ( " http://musescore.com/help/license " ) ) ;
QFont font = licenseHelp - > font ( ) ;
font . setPointSize ( 8 ) ;
licenseHelp - > setFont ( font ) ;
privateHelp - > setText ( tr ( " Respect the <a href= \" %1 \" >community guidelines</a>. Only make your scores accessible to anyone with permission from the right holders. " ) . arg ( " http://musescore.com/community-guidelines " ) ) ;
privateHelp - > setFont ( font ) ;
tagsHelp - > setText ( tr ( " Use a comma to separate the tags " ) ) ;
tagsHelp - > setFont ( font ) ;
2014-11-14 21:03:46 +01:00
connect ( buttonBox , SIGNAL ( clicked ( QAbstractButton * ) ) , SLOT ( buttonBoxClicked ( QAbstractButton * ) ) ) ;
chkSignoutOnExit - > setVisible ( false ) ;
_loginManager = loginManager ;
connect ( _loginManager , SIGNAL ( uploadSuccess ( QString ) ) , this , SLOT ( uploadSuccess ( QString ) ) ) ;
connect ( _loginManager , SIGNAL ( uploadError ( QString ) ) , this , SLOT ( uploadError ( QString ) ) ) ;
2015-02-26 18:11:39 +01:00
connect ( _loginManager , SIGNAL ( getScoreSuccess ( QString , QString , bool , QString , QString , QString ) ) , this , SLOT ( onGetScoreSuccess ( QString , QString , bool , QString , QString , QString ) ) ) ;
2014-11-20 18:02:05 +01:00
connect ( _loginManager , SIGNAL ( getScoreError ( QString ) ) , this , SLOT ( onGetScoreError ( QString ) ) ) ;
2014-11-14 21:03:46 +01:00
connect ( _loginManager , SIGNAL ( tryLoginSuccess ( ) ) , this , SLOT ( display ( ) ) ) ;
connect ( btnSignout , SIGNAL ( pressed ( ) ) , this , SLOT ( logout ( ) ) ) ;
}
2015-02-03 13:42:37 +01:00
2014-11-14 21:03:46 +01:00
//---------------------------------------------------------
// buttonBoxClicked
//---------------------------------------------------------
void UploadScoreDialog : : buttonBoxClicked ( QAbstractButton * button )
{
QDialogButtonBox : : StandardButton sb = buttonBox - > standardButton ( button ) ;
2014-11-20 18:02:05 +01:00
if ( sb = = QDialogButtonBox : : Save )
upload ( updateExistingCb - > isChecked ( ) ? _nid : - 1 ) ;
2014-11-14 21:03:46 +01:00
else
setVisible ( false ) ;
}
//---------------------------------------------------------
// upload
//---------------------------------------------------------
2014-11-20 18:02:05 +01:00
void UploadScoreDialog : : upload ( int nid )
2014-11-14 21:03:46 +01:00
{
if ( title - > text ( ) . trimmed ( ) . isEmpty ( ) ) {
QMessageBox : : critical ( this , tr ( " Missing title " ) , tr ( " Please provide a title " ) ) ;
return ;
}
2014-11-20 18:02:05 +01:00
Score * score = mscore - > currentScore ( ) - > rootScore ( ) ;
2014-11-14 21:03:46 +01:00
QString path = QDir : : tempPath ( ) + " /temp.mscz " ;
if ( mscore - > saveAs ( score , true , path , " mscz " ) ) {
QString licenseString = license - > currentData ( ) . toString ( ) ;
2015-02-26 18:11:39 +01:00
QString privateString = cbPrivate - > isChecked ( ) ? " 1 " : " 0 " ;
2014-11-20 18:02:05 +01:00
_loginManager - > upload ( path , nid , title - > text ( ) , description - > toPlainText ( ) , privateString , licenseString , tags - > text ( ) ) ;
2014-11-14 21:03:46 +01:00
}
}
//---------------------------------------------------------
// uploadSuccess
//---------------------------------------------------------
void UploadScoreDialog : : uploadSuccess ( const QString & url )
{
setVisible ( false ) ;
2014-11-24 17:25:32 +01:00
Score * score = mscore - > currentScore ( ) - > rootScore ( ) ;
QMap < QString , QString > metatags = score - > metaTags ( ) ;
metatags . insert ( " source " , url ) ;
score - > startCmd ( ) ;
score - > undo ( new ChangeMetaTags ( score , metatags ) ) ;
score - > endCmd ( ) ;
2014-11-14 21:03:46 +01:00
QMessageBox : : information ( this ,
tr ( " Success " ) ,
tr ( " Finished! <a href= \" %1 \" >Go to my score</a>. " ) . arg ( url ) ,
QMessageBox : : Ok , QMessageBox : : NoButton ) ;
2015-02-03 13:42:37 +01:00
2014-11-14 21:03:46 +01:00
}
//---------------------------------------------------------
// uploadError
//---------------------------------------------------------
void UploadScoreDialog : : uploadError ( const QString & error )
{
QMessageBox : : information ( this ,
tr ( " Error " ) ,
error ,
QMessageBox : : Ok , QMessageBox : : NoButton ) ;
}
//---------------------------------------------------------
// display
//---------------------------------------------------------
void UploadScoreDialog : : display ( )
{
lblUsername - > setText ( _loginManager - > userName ( ) ) ;
2014-11-20 18:02:05 +01:00
QString source = mscore - > currentScore ( ) - > rootScore ( ) - > metaTag ( " source " ) ;
if ( ! source . isEmpty ( ) ) {
QStringList sl = source . split ( " / " ) ;
if ( sl . length ( ) > 0 ) {
QString nidString = sl . last ( ) ;
bool ok ;
int nid = nidString . toInt ( & ok ) ;
if ( ok ) {
_nid = nid ;
_loginManager - > getScore ( nid ) ;
return ;
}
}
}
clear ( ) ;
setVisible ( true ) ;
}
//---------------------------------------------------------
// onGetScoreSuccess
//---------------------------------------------------------
2015-02-26 18:11:39 +01:00
void UploadScoreDialog : : onGetScoreSuccess ( const QString & t , const QString & desc , bool priv , const QString & lic , const QString & tag , const QString & url )
2014-11-20 18:02:05 +01:00
{
// file with score info
title - > setText ( t ) ;
description - > setPlainText ( desc ) ;
2015-02-26 18:11:39 +01:00
cbPrivate - > setChecked ( priv ) ;
2014-11-20 18:02:05 +01:00
int lIndex = license - > findData ( lic ) ;
if ( lIndex < 0 ) lIndex = 0 ;
license - > setCurrentIndex ( lIndex ) ;
tags - > setText ( tag ) ;
updateExistingCb - > setChecked ( true ) ;
updateExistingCb - > setVisible ( true ) ;
2015-02-26 18:11:39 +01:00
linkToScore - > setText ( tr ( " [<a href= \" %1 \" >link</a>] " ) . arg ( url ) ) ;
2014-11-20 18:02:05 +01:00
setVisible ( true ) ;
}
//---------------------------------------------------------
// onGetScoreError
//---------------------------------------------------------
2014-11-21 12:50:06 +01:00
void UploadScoreDialog : : onGetScoreError ( const QString & /*error*/ )
2014-11-20 18:02:05 +01:00
{
clear ( ) ;
setVisible ( true ) ;
}
//---------------------------------------------------------
// onGetScoreError
//---------------------------------------------------------
void UploadScoreDialog : : clear ( )
{
2014-11-14 21:03:46 +01:00
description - > clear ( ) ;
2015-02-26 18:11:39 +01:00
cbPrivate - > setChecked ( false ) ;
2014-11-14 21:03:46 +01:00
license - > setCurrentIndex ( 0 ) ;
tags - > clear ( ) ;
2014-11-20 18:02:05 +01:00
updateExistingCb - > setChecked ( false ) ;
updateExistingCb - > setVisible ( false ) ;
2015-02-26 18:11:39 +01:00
linkToScore - > setText ( " " ) ;
2014-11-20 18:02:05 +01:00
_nid = - 1 ;
2014-11-14 21:03:46 +01:00
}
//---------------------------------------------------------
// logout
//---------------------------------------------------------
void UploadScoreDialog : : logout ( )
{
_loginManager - > logout ( ) ;
setVisible ( false ) ;
}
}