add language files manager to download translations from the web
This commit is contained in:
parent
04f6cea64a
commit
b14f79dbd6
8 changed files with 453 additions and 11 deletions
|
@ -46,7 +46,7 @@ QT4_WRAP_UI (ui_headers
|
|||
fretdprops.ui stafftype.ui sectionbreak.ui bend.ui tremolobar.ui textproperties.ui
|
||||
editpitch.ui editstringdata.ui editraster.ui mediadialog.ui textstyle.ui album.ui layer.ui
|
||||
omrpanel.ui startdialog.ui masterpalette.ui pluginManager.ui harmonyedit.ui pathlistdialog.ui
|
||||
note_groups.ui importmidi_panel.ui
|
||||
note_groups.ui importmidi_panel.ui resourceManager.ui
|
||||
|
||||
debugger/barline.ui
|
||||
debugger/harmony.ui
|
||||
|
@ -155,6 +155,7 @@ QT4_WRAP_CPP (mocs
|
|||
importmidi_inner.h importmidi_data.h importmidi_swing.h
|
||||
debugger/debugger.h importmidi_fraction.h importmidi_drum.h
|
||||
importmidi_lrhand.h importmidi_lyrics.h importmidi_trview.h
|
||||
resourceManager.h downloadUtils.h
|
||||
${OMR_MOCS}
|
||||
${SCRIPT_MOCS}
|
||||
)
|
||||
|
@ -270,6 +271,7 @@ add_executable ( ${ExecutableName}
|
|||
importmidi_data.cpp importmidi_swing.cpp importmidi_fraction.cpp importmidi_drum.cpp
|
||||
importmidi_clef.cpp importmidi_lrhand.cpp importmidi_lyrics.cpp importmidi_trview.cpp
|
||||
importmidi_inner.cpp
|
||||
resourceManager.cpp downloadUtils.cpp
|
||||
|
||||
${OMR_FILES}
|
||||
${AUDIO}
|
||||
|
|
|
@ -2029,6 +2029,13 @@ Shortcut Shortcut::sc[] = {
|
|||
QT_TRANSLATE_NOOP("action","Inspector"),
|
||||
QT_TRANSLATE_NOOP("action","Show inspector")
|
||||
),
|
||||
Shortcut(
|
||||
STATE_ALL,
|
||||
0,
|
||||
"resource-manager",
|
||||
Qt::ApplicationShortcut,
|
||||
QT_TRANSLATE_NOOP("action", "Resource Manager")
|
||||
),
|
||||
Shortcut(
|
||||
STATE_NORMAL | STATE_NOTE_ENTRY | STATE_PLAY | STATE_EDIT | STATE_LYRICS_EDIT,
|
||||
0,
|
||||
|
|
63
mscore/downloadUtils.cpp
Normal file
63
mscore/downloadUtils.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2002-2013 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 "downloadUtils.h"
|
||||
|
||||
namespace Ms {
|
||||
|
||||
DownloadUtils::DownloadUtils(QWidget *parent) :QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool DownloadUtils::saveFile()
|
||||
{
|
||||
QFile localFile(_localFile);
|
||||
if (!localFile.open(QIODevice::WriteOnly))
|
||||
{
|
||||
qDebug() << "can't access";
|
||||
return false;
|
||||
}
|
||||
qDebug() << "here writing to file "<< sdata << " at " << _localFile;
|
||||
localFile.write(sdata);
|
||||
localFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void DownloadUtils::downloadFinished(QNetworkReply *data)
|
||||
{
|
||||
sdata = data->readAll();
|
||||
emit done();
|
||||
}
|
||||
|
||||
QByteArray DownloadUtils::returnData()
|
||||
{
|
||||
return sdata;
|
||||
}
|
||||
|
||||
void DownloadUtils::download()
|
||||
{
|
||||
QUrl url = QUrl::fromEncoded(_target.toLocal8Bit());
|
||||
QNetworkRequest request(url);
|
||||
QEventLoop loop;
|
||||
QObject::connect(manager.get(request), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
|
||||
QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
|
||||
QObject::connect(manager.get(request), SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
void DownloadUtils::downloadProgress(qint64 received, qint64 total)
|
||||
{
|
||||
qDebug() << (double(received)/total)*100 << "%";
|
||||
}
|
||||
|
||||
}
|
41
mscore/downloadUtils.h
Normal file
41
mscore/downloadUtils.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2002-2013 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
|
||||
//=============================================================================
|
||||
|
||||
namespace Ms {
|
||||
|
||||
class DownloadUtils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QByteArray sdata;
|
||||
QNetworkAccessManager manager;
|
||||
QString _target;
|
||||
QString _localFile;
|
||||
|
||||
public:
|
||||
explicit DownloadUtils(QWidget *parent=0);
|
||||
|
||||
void setTarget(const QString& t) { _target = t; }
|
||||
void setLocalFile(const QString& t) { _localFile = t; }
|
||||
bool saveFile();
|
||||
QByteArray returnData();
|
||||
|
||||
signals:
|
||||
void done();
|
||||
|
||||
public slots:
|
||||
void download();
|
||||
void downloadFinished(QNetworkReply* data);
|
||||
void downloadProgress(qint64 recieved, qint64 total);
|
||||
};
|
||||
}
|
|
@ -76,6 +76,8 @@
|
|||
#include "drumtools.h"
|
||||
#include "editstafftype.h"
|
||||
#include "texttools.h"
|
||||
#include "textpalette.h"
|
||||
#include "resourceManager.h"
|
||||
|
||||
#include "libmscore/mscore.h"
|
||||
#include "libmscore/system.h"
|
||||
|
@ -83,7 +85,7 @@
|
|||
#include "libmscore/chordlist.h"
|
||||
#include "libmscore/volta.h"
|
||||
#include "libmscore/lasso.h"
|
||||
#include "textpalette.h"
|
||||
|
||||
#include "driver.h"
|
||||
|
||||
// #include "effects/freeverb/freeverb.h"
|
||||
|
@ -1038,6 +1040,7 @@ MuseScore::MuseScore()
|
|||
|
||||
menuPlugins->addSeparator();
|
||||
|
||||
|
||||
//---------------------
|
||||
// Menu Help
|
||||
//---------------------
|
||||
|
@ -1075,6 +1078,9 @@ MuseScore::MuseScore()
|
|||
menuHelp->addAction(tr("Report a bug"), this, SLOT(reportBug()));
|
||||
#endif
|
||||
|
||||
menuHelp->addSeparator();
|
||||
menuHelp->addAction(getAction("resource-manager"));
|
||||
|
||||
setCentralWidget(envelope);
|
||||
|
||||
// load cascading instrument templates
|
||||
|
@ -1308,7 +1314,7 @@ int MuseScore::appendScore(Score* score)
|
|||
{
|
||||
int index = scoreList.size();
|
||||
for (int i = 0; i < scoreList.size(); ++i) {
|
||||
if (scoreList[i]->filePath() == score->filePath()) {
|
||||
if (scoreList[i]->filePath() == score->filePath() && score->fileInfo()->exists()) {
|
||||
removeTab(i);
|
||||
index = i;
|
||||
break;
|
||||
|
@ -1997,16 +2003,23 @@ void setMscoreLocale(QString localeName)
|
|||
}
|
||||
|
||||
QTranslator* translator = new QTranslator;
|
||||
QString lp = mscoreGlobalShare + "locale/" + QString("mscore_") + localeName;
|
||||
if (MScore::debugMode)
|
||||
qDebug("load translator <%s>", qPrintable(lp));
|
||||
|
||||
if (!translator->load(lp) && MScore::debugMode)
|
||||
qDebug("load translator <%s> failed", qPrintable(lp));
|
||||
else {
|
||||
qApp->installTranslator(translator);
|
||||
translatorList.append(translator);
|
||||
// load translator from userspace
|
||||
QString lp = dataPath + "/locale/" + QString("mscore_") + localeName;
|
||||
if (MScore::debugMode) qDebug("load translator <%s>", qPrintable(lp));
|
||||
bool success = translator->load(lp);
|
||||
if (!success) {
|
||||
if (MScore::debugMode) qDebug("load translator <%s> failed", qPrintable(lp));
|
||||
// fallback to default translation
|
||||
lp = mscoreGlobalShare + "locale/" + QString("mscore_") + localeName;
|
||||
if (MScore::debugMode) qDebug("load translator <%s>", qPrintable(lp));
|
||||
success = translator->load(lp);
|
||||
if (!success && MScore::debugMode) qDebug("load translator <%s> failed", qPrintable(lp));
|
||||
}
|
||||
if(success) {
|
||||
qApp->installTranslator(translator);
|
||||
translatorList.append(translator);
|
||||
}
|
||||
|
||||
QString resourceDir;
|
||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||
|
@ -4081,6 +4094,10 @@ void MuseScore::cmd(QAction* a, const QString& cmd)
|
|||
PluginManager pm(0);
|
||||
pm.exec();
|
||||
}
|
||||
else if(cmd == "resource-manager"){
|
||||
ResourceManager r(0);
|
||||
r.exec();
|
||||
}
|
||||
else if (cmd == "media")
|
||||
showMediaDialog();
|
||||
else if (cmd == "page-settings")
|
||||
|
|
149
mscore/resourceManager.cpp
Normal file
149
mscore/resourceManager.cpp
Normal file
|
@ -0,0 +1,149 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2002-2013 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 "resourceManager.h"
|
||||
#include "ui_resourceManager.h"
|
||||
|
||||
namespace Ms {
|
||||
|
||||
extern QString dataPath;
|
||||
extern QString mscoreGlobalShare;
|
||||
|
||||
ResourceManager::ResourceManager(QWidget *parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
QDir dir;
|
||||
dir.mkpath(dataPath + "/locale");
|
||||
baseAddr = "http://extensions.musescore.org/";
|
||||
displayPlugins();
|
||||
displayLanguages();
|
||||
languagesTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
|
||||
languagesTable->verticalHeader()->hide();
|
||||
tabs->removeTab(1);
|
||||
tabs->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void ResourceManager::displayPlugins()
|
||||
{
|
||||
tabs->setTabText(1, "Plugins");
|
||||
textBrowser->setText("hello");
|
||||
}
|
||||
|
||||
void ResourceManager::displayLanguages()
|
||||
{
|
||||
tabs->setTabText(0,tr("Languages"));
|
||||
DownloadUtils *js = new DownloadUtils(this);
|
||||
js->setTarget(baseAddr + "languages/details.json");
|
||||
js->download();
|
||||
QByteArray json = js->returnData();
|
||||
|
||||
QJsonParseError err;
|
||||
QJsonDocument result = QJsonDocument::fromJson(json, &err);
|
||||
|
||||
if (err.error != QJsonParseError::NoError || !result.isObject()) {
|
||||
qFatal("An error occured during parsing");
|
||||
return;
|
||||
}
|
||||
int rowCount = result.object().keys().size();
|
||||
rowCount -= 2; //version and type
|
||||
qDebug() << result.object().keys().size();
|
||||
qDebug() << result.toJson();
|
||||
languagesTable->setRowCount(rowCount);
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
QPushButton* updateButtons[rowCount];
|
||||
QPushButton* temp;
|
||||
languagesTable->verticalHeader()->show();
|
||||
|
||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||
|
||||
for (QString key : result.object().keys()) {
|
||||
if (!result.object().value(key).isObject())
|
||||
continue;
|
||||
QJsonObject value = result.object().value(key).toObject();
|
||||
col = 0;
|
||||
QString test = value.value("file_name").toString();
|
||||
if(test.length() == 0)
|
||||
continue;
|
||||
|
||||
QString filename = value.value("file_name").toString();
|
||||
QString name = value.value("name").toString();
|
||||
QString fileSize = value.value("file_size").toString();
|
||||
QString hashValue = value.value("hash").toString();
|
||||
|
||||
languagesTable->setItem(row,col++,new QTableWidgetItem (name));
|
||||
languagesTable->setItem(row,col++,new QTableWidgetItem (filename));
|
||||
languagesTable->setItem(row,col++,new QTableWidgetItem (tr("%1 KB").arg(fileSize)));
|
||||
updateButtons[row] = new QPushButton(tr("Update"));
|
||||
|
||||
temp = updateButtons[row];
|
||||
buttonMap[temp] = "languages/" + filename;
|
||||
buttonHashMap[temp] = hashValue;
|
||||
languagesTable->setIndexWidget(languagesTable->model()->index(row,col++), temp);
|
||||
QString local = dataPath + "/locale/" + filename;
|
||||
|
||||
QFileInfo fileLocal(local);
|
||||
if(!fileLocal.exists())
|
||||
local = mscoreGlobalShare + "locale/" + filename;;
|
||||
|
||||
if(verifyFile(local, hashValue)) {
|
||||
temp->setText(tr("No update"));
|
||||
temp->setDisabled(1);
|
||||
}
|
||||
else {
|
||||
connect(temp, SIGNAL(clicked()), this, SLOT(download()));
|
||||
}
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::download()
|
||||
{
|
||||
QPushButton *button = dynamic_cast<QPushButton*>( sender() );
|
||||
QString data = buttonMap[button];
|
||||
QString hash = buttonHashMap[button];
|
||||
button->setText(tr("Updating"));
|
||||
button->setDisabled(1);
|
||||
QString baseAddress = baseAddr + data;
|
||||
DownloadUtils *dl = new DownloadUtils(this);
|
||||
dl->setTarget(baseAddress);
|
||||
qDebug() << baseAddress;
|
||||
QString localPath = dataPath + "/locale/" + data.split('/')[1];
|
||||
dl->setLocalFile(localPath);
|
||||
dl->download();
|
||||
if( !dl->saveFile() || !verifyFile(localPath, hash)) {
|
||||
button->setText(tr("Failed, try again"));
|
||||
button->setEnabled(1);
|
||||
}
|
||||
else {
|
||||
button->setText(tr("Updated"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ResourceManager::verifyFile(QString path, QString hash)
|
||||
{
|
||||
QFile file(path);
|
||||
QCryptographicHash localHash(QCryptographicHash::Sha1);
|
||||
if(file.open(QIODevice::ReadOnly)) {
|
||||
localHash.reset();
|
||||
localHash.addData(file.readAll());
|
||||
QString hashValue2 = QString(localHash.result().toHex());
|
||||
if(hash == hashValue2)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
42
mscore/resourceManager.h
Normal file
42
mscore/resourceManager.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2002-2013 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
|
||||
//=============================================================================
|
||||
|
||||
#ifndef RESOURCE_H
|
||||
#define RESOURCE_H
|
||||
|
||||
#include "ui_resourceManager.h"
|
||||
#include "downloadUtils.h"
|
||||
|
||||
namespace Ms {
|
||||
|
||||
class ResourceManager : public QDialog, public Ui::Resource
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ResourceManager(QWidget *parent = 0);
|
||||
QByteArray txt;
|
||||
void displayLanguages();
|
||||
void displayPlugins();
|
||||
bool verifyFile(QString path, QString hash);
|
||||
|
||||
private:
|
||||
QMap <QPushButton *, QString> buttonMap;
|
||||
QMap <QPushButton *, QString> buttonHashMap;
|
||||
QString baseAddr;
|
||||
|
||||
public slots:
|
||||
void download();
|
||||
};
|
||||
|
||||
}
|
||||
#endif // RESOURCE_H
|
121
mscore/resourceManager.ui
Normal file
121
mscore/resourceManager.ui
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Resource</class>
|
||||
<widget class="QDialog" name="Resource">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>595</width>
|
||||
<height>480</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MuseScore Resources</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabs">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="languages">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>545</width>
|
||||
<height>407</height>
|
||||
</size>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="languagesTable">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="rowCount">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Language</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Filename</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>File Size</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Install/Update</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
<widget class="QTextBrowser" name="textBrowser">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>251</width>
|
||||
<height>341</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in a new issue