diff --git a/lgpl.txt b/lgpl.txt index 65c5ca88..02bbb60b 100644 --- a/lgpl.txt +++ b/lgpl.txt @@ -162,4 +162,4 @@ General Public License ever published by the Free Software Foundation. whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the -Library. +Library. \ No newline at end of file diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index bcbab5a8..edfcd5c6 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1234,7 +1234,6 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, if(documentChange) { emit activeDocumentChanged(); - // Notify the navigator palette that the document has changed emit setDocOnPageNavigator(pDocumentProxy); UBGraphicsTextItem::lastUsedTextColor = QColor(); } diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index faab24bf..699f9a37 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -135,27 +135,13 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing UBResources::resources(); if (!undoStack) - { undoStack = new QUndoStack(staticMemoryCleaner); - } - - mApplicationTranslator = new QTranslator(this); - mApplicationTranslator->load(UBPlatformUtils::preferredTranslation(QString("sankore_"))); - installTranslator(mApplicationTranslator); - - QString localString; - if (!mApplicationTranslator->isEmpty()) - localString = UBPlatformUtils::preferredLanguage(); - else - localString = "en_US"; - mQtGuiTranslator = new QTranslator(this); - mQtGuiTranslator->load(UBPlatformUtils::preferredTranslation(QString("qt_"))); - installTranslator(mQtGuiTranslator); + QString forcedLanguage(""); + if(args.contains("-lang")) + forcedLanguage=args.at(args.indexOf("-lang") + 1); - - QLocale::setDefault(QLocale(localString)); - qDebug() << "Running application in:" << localString; + setupTranslator(forcedLanguage); UBSettings *settings = UBSettings::settings(); @@ -217,6 +203,51 @@ UBApplication::~UBApplication() staticMemoryCleaner = 0; } + +void UBApplication::setupTranslator(QString forcedLanguage) +{ + QStringList availablesTranslations = UBPlatformUtils::availableTranslations(); + QString language(""); + if(!forcedLanguage.isEmpty()){ + if(availablesTranslations.contains(forcedLanguage,Qt::CaseInsensitive)) + language = forcedLanguage; + else + qDebug() << "forced language " << forcedLanguage << " not available"; + } + else{ + QString systemLanguage = UBPlatformUtils::systemLanguage(); + if(availablesTranslations.contains(systemLanguage,Qt::CaseInsensitive)) + language = systemLanguage; + else + qDebug() << "translation for system language " << systemLanguage << " not found"; + } + + if(language.isEmpty()){ + language = "en_US"; + //fallback if no translation are available + } + else{ + mApplicationTranslator = new QTranslator(this); + mQtGuiTranslator = new QTranslator(this); + + mApplicationTranslator->load(UBPlatformUtils::translationPath(QString("sankore_"),language)); + installTranslator(mApplicationTranslator); + + + mQtGuiTranslator->load(UBPlatformUtils::translationPath(QString("qt_"),language)); + if(!mQtGuiTranslator->isEmpty()){ + // checked because this translation could be not available + installTranslator(mQtGuiTranslator); + } + else + qDebug() << "Qt gui translation in " << language << " are not available"; + } + + + QLocale::setDefault(QLocale(language)); + qDebug() << "Running application in:" << language; +} + int UBApplication::exec(const QString& pFileToImport) { QPixmapCache::setCacheLimit(1024 * 100); diff --git a/src/core/UBApplication.h b/src/core/UBApplication.h index 2950005f..efe2c0ec 100644 --- a/src/core/UBApplication.h +++ b/src/core/UBApplication.h @@ -121,6 +121,7 @@ class UBApplication : public QtSingleApplication private: void updateProtoActionsState(); + void setupTranslator(QString forcedLanguage); QList mProtoMenus; bool mIsVerbose; diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index 5d9e018c..658a4389 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -177,7 +177,7 @@ void UBFileSystemUtils::cleanupGhostTempFolders(const QString& templateString) } -QStringList UBFileSystemUtils::allFiles(const QString& pDirPath) +QStringList UBFileSystemUtils::allFiles(const QString& pDirPath, bool isRecursive) { QStringList result; if (pDirPath == "" || pDirPath == "." || pDirPath == "..") @@ -187,7 +187,7 @@ QStringList UBFileSystemUtils::allFiles(const QString& pDirPath) foreach(QFileInfo dirContent, dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot , QDir::Name)) { - if (dirContent.isDir()) + if (isRecursive && dirContent.isDir()) { result << allFiles(dirContent.absoluteFilePath()); } diff --git a/src/frameworks/UBFileSystemUtils.h b/src/frameworks/UBFileSystemUtils.h index bd20755b..26ec89d2 100644 --- a/src/frameworks/UBFileSystemUtils.h +++ b/src/frameworks/UBFileSystemUtils.h @@ -37,7 +37,7 @@ class UBFileSystemUtils static QFileInfoList allElementsInDirectory(const QString& pDirPath); - static QStringList allFiles(const QString& pDirPath); + static QStringList allFiles(const QString& pDirPath, const bool isRecurive=true); static bool deleteDir(const QString& pDirPath); diff --git a/src/frameworks/UBPlatformUtils.h b/src/frameworks/UBPlatformUtils.h index a4d6d886..0b99b370 100644 --- a/src/frameworks/UBPlatformUtils.h +++ b/src/frameworks/UBPlatformUtils.h @@ -103,8 +103,8 @@ class UBPlatformUtils static void setFileType(const QString &filePath, unsigned long fileType); static void fadeDisplayOut(); static void fadeDisplayIn(); - static QString preferredTranslation(QString pFilePrefix); - static QString preferredLanguage(); + static QString translationPath(QString pFilePrefix, QString pLanguage); + static QString systemLanguage(); static bool hasVirtualKeyboard(); //static void showVirtualKeyboard(); static void runInstaller(const QString &installerFilePath); @@ -115,6 +115,7 @@ class UBPlatformUtils static QString computerName(); static UBKeyboardLocale** getKeyboardLayouts(int& nCount); static QString urlFromClipboard(); + static QStringList availableTranslations(); }; diff --git a/src/frameworks/UBPlatformUtils_linux.cpp b/src/frameworks/UBPlatformUtils_linux.cpp index 174e3694..6be93d3f 100644 --- a/src/frameworks/UBPlatformUtils_linux.cpp +++ b/src/frameworks/UBPlatformUtils_linux.cpp @@ -20,6 +20,8 @@ #include #include +#include "frameworks/UBFileSystemUtils.h" + void UBPlatformUtils::init() { @@ -55,13 +57,22 @@ void UBPlatformUtils::fadeDisplayIn() // NOOP } -QString UBPlatformUtils::preferredTranslation(QString pFilePrefix) +QStringList UBPlatformUtils::availableTranslations() +{ + QString translationsPath = applicationResourcesDirectory() + "/" + "i18n" + "/"; + QStringList translationsList = UBFileSystemUtils::allFiles(translationsPath); + QRegExp sankoreTranslationFiles(".*sankore_.*.qm"); + translationsList=translationsList.filter(sankoreTranslationFiles); + return translationsList.replaceInStrings(QRegExp("(.*)sankore_(.*).qm"),"\\2"); +} + +QString UBPlatformUtils::translationPath(QString pFilePrefix,QString pLanguage) { - QString qmPath = applicationResourcesDirectory() + "/" + "i18n" + "/" + pFilePrefix + preferredLanguage() + ".qm"; + QString qmPath = applicationResourcesDirectory() + "/" + "i18n" + "/" + pFilePrefix + pLanguage + ".qm"; return qmPath; } -QString UBPlatformUtils::preferredLanguage() +QString UBPlatformUtils::systemLanguage() { return QLocale::system().name(); } diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index e94d254b..33d2bc25 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -184,31 +184,64 @@ void UBPlatformUtils::fadeDisplayIn() } } -QString UBPlatformUtils::preferredTranslation(QString pFilePrefix) -{ - QString qmPath; - NSString* filePrefix = [[NSString alloc] initWithUTF8String:(const char*)(pFilePrefix.toUtf8())]; +//QString UBPlatformUtils::preferredTranslation(QString pFilePrefix) +//{ +// QString qmPath; +// NSString* filePrefix = [[NSString alloc] initWithUTF8String:(const char*)(pFilePrefix.toUtf8())]; + +// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + +// NSString *lprojPath = [[[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"] stringByDeletingLastPathComponent]; +// if (lprojPath) +// { +// NSString *lang = [[lprojPath lastPathComponent] stringByDeletingPathExtension]; +// NSString *translationFilePath = [lprojPath stringByAppendingPathComponent:[[filePrefix stringByAppendingString:lang] stringByAppendingPathExtension:@"qm"]]; +// qmPath = QString::fromUtf8([translationFilePath UTF8String], strlen([translationFilePath UTF8String])); +// } + +// [pool drain]; +// return qmPath; +//} + +//QString UBPlatformUtils::preferredLanguage() +//{ +// QFileInfo qmFileInfo = QFileInfo(preferredTranslation("sankore_")); +// QDir lprojPath = qmFileInfo.dir(); +// QFileInfo lprojFileInfo = QFileInfo(lprojPath.absolutePath()); +// return lprojFileInfo.baseName(); +//} + +QStringList UBPlatformUtils::availableTranslations() +{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *lprojPath = [[NSBundle mainBundle] resourcePath]; + QString translationsPath = QString::fromUtf8([lprojPath UTF8String], strlen([lprojPath UTF8String])); + QStringList translationsList = UBFileSystemUtils::allFiles(translationsPath, false); + QRegExp sankoreTranslationFiles(".*lproj"); + translationsList=translationsList.filter(sankoreTranslationFiles); + [pool drain]; + return translationsList.replaceInStrings(QRegExp("(.*)/(.*).lproj"),"\\2"); +} - NSString *lprojPath = [[[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"] stringByDeletingLastPathComponent]; - if (lprojPath) - { - NSString *lang = [[lprojPath lastPathComponent] stringByDeletingPathExtension]; - NSString *translationFilePath = [lprojPath stringByAppendingPathComponent:[[filePrefix stringByAppendingString:lang] stringByAppendingPathExtension:@"qm"]]; - qmPath = QString::fromUtf8([translationFilePath UTF8String], strlen([translationFilePath UTF8String])); - } - +QString UBPlatformUtils::translationPath(QString pFilePrefix, QString pLanguage) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *lprojPath = [[NSBundle mainBundle] resourcePath]; + QString translationsPath = QString::fromUtf8([lprojPath UTF8String], strlen([lprojPath UTF8String])); [pool drain]; - return qmPath; + return translationsPath + "/" + pLanguage + ".lproj/" + pFilePrefix + pLanguage + ".qm"; } -QString UBPlatformUtils::preferredLanguage() +QString UBPlatformUtils::systemLanguage() { - QFileInfo qmFileInfo = QFileInfo(preferredTranslation("sankore_")); - QDir lprojPath = qmFileInfo.dir(); - QFileInfo lprojFileInfo = QFileInfo(lprojPath.absolutePath()); - return lprojFileInfo.baseName(); + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSUserDefaults* defs = [NSUserDefaults standardUserDefaults]; + NSArray* languages = [defs objectForKey:@"AppleLanguages"]; + NSString* preferredLang = [languages objectAtIndex:0]; + QString result = QString::fromUtf8([preferredLang UTF8String], strlen([preferredLang UTF8String])); + [pool drain]; + return result; } void UBPlatformUtils::runInstaller(const QString &installerFilePath) diff --git a/src/frameworks/UBPlatformUtils_win.cpp b/src/frameworks/UBPlatformUtils_win.cpp index 04f09420..4127e7f1 100644 --- a/src/frameworks/UBPlatformUtils_win.cpp +++ b/src/frameworks/UBPlatformUtils_win.cpp @@ -20,6 +20,7 @@ #include #include +#include "frameworks/UBFileSystemUtils.h" #include "core/memcheck.h" void UBPlatformUtils::init() @@ -59,14 +60,22 @@ void UBPlatformUtils::fadeDisplayIn() // NOOP } -QString UBPlatformUtils::preferredTranslation(QString pFilePrefix) +QStringList UBPlatformUtils::availableTranslations() { - QString localPreferredLanguage = preferredLanguage(); - QString qmPath = applicationResourcesDirectory() + "/" + "i18n" + "/" + pFilePrefix + localPreferredLanguage + ".qm"; + QString translationsPath = applicationResourcesDirectory() + "/" + "i18n" + "/"; + QStringList translationsList = UBFileSystemUtils::allFiles(translationsPath); + QRegExp sankoreTranslationFiles(".*sankore_.*.qm"); + translationsList=translationsList.filter(sankoreTranslationFiles); + return translationsList.replaceInStrings(QRegExp("(.*)sankore_(.*).qm"),"\\2"); +} + +QString UBPlatformUtils::translationPath(QString pFilePrefix,QString pLanguage) +{ + QString qmPath = applicationResourcesDirectory() + "/" + "i18n" + "/" + pFilePrefix + pLanguage + ".qm"; return qmPath; } -QString UBPlatformUtils::preferredLanguage() +QString UBPlatformUtils::systemLanguage() { return QLocale::system().name(); } diff --git a/src/gui/UBDocumentNavigator.cpp b/src/gui/UBDocumentNavigator.cpp index 37544b55..916cd6c8 100644 --- a/src/gui/UBDocumentNavigator.cpp +++ b/src/gui/UBDocumentNavigator.cpp @@ -263,14 +263,6 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event) // Update the thumbnails width mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth; - // Update the scene rect - // QRect sceneRect; - // sceneRect.setWidth(width() - 2*border()); - // sceneRect.setHeight(height() - 2*border()); - // sceneRect.moveLeft(border()); - // sceneRect.moveTop(border()); - // scene()->setSceneRect(sceneRect); - // Refresh the scene refreshScene(); } diff --git a/src/gui/UBLeftPalette.cpp b/src/gui/UBLeftPalette.cpp index 00e0a4d9..4ef5225e 100644 --- a/src/gui/UBLeftPalette.cpp +++ b/src/gui/UBLeftPalette.cpp @@ -45,7 +45,7 @@ UBLeftPalette::~UBLeftPalette() */ void UBLeftPalette::updateMaxWidth() { - setMaximumWidth(270); + setMaximumWidth((int)(parentWidget()->width() * 0.45)); } /** diff --git a/src/gui/UBRightPalette.cpp b/src/gui/UBRightPalette.cpp index 26923eac..f8190528 100644 --- a/src/gui/UBRightPalette.cpp +++ b/src/gui/UBRightPalette.cpp @@ -69,7 +69,7 @@ void UBRightPalette::resizeEvent(QResizeEvent *event) */ void UBRightPalette::updateMaxWidth() { - setMaximumWidth((int)((parentWidget()->width() * 2)/3)); + setMaximumWidth((int)(parentWidget()->width() * 0.45)); setMaximumHeight(parentWidget()->height()); setMinimumHeight(parentWidget()->height()); } diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index dc87f1b6..e42122bb 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -887,11 +887,6 @@ void UBImgTextThumbnailElement::Place(int row, int col, qreal width, qreal heigh qreal scaleFactor = qMin(scaleWidth, scaleHeight); UBThumbnail* pix = dynamic_cast(this->thumbnail); - if(pix) - { - scaleFactor = qMin(scaleFactor, 1.0); - } - QTransform transform; transform.scale(scaleFactor, scaleFactor);