Commit 07aaa19b authored by Aleksei Kanash's avatar Aleksei Kanash

Merge branch 'master' of github.com:Sankore/Sankore-3.1

Conflicts:
	src/board/UBBoardController.cpp
parents 47cdb048 28bb7a67
...@@ -1234,7 +1234,6 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, ...@@ -1234,7 +1234,6 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
if(documentChange) if(documentChange)
{ {
emit activeDocumentChanged(); emit activeDocumentChanged();
// Notify the navigator palette that the document has changed
emit setDocOnPageNavigator(pDocumentProxy); emit setDocOnPageNavigator(pDocumentProxy);
UBGraphicsTextItem::lastUsedTextColor = QColor(); UBGraphicsTextItem::lastUsedTextColor = QColor();
} }
......
...@@ -135,27 +135,13 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing ...@@ -135,27 +135,13 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing
UBResources::resources(); UBResources::resources();
if (!undoStack) if (!undoStack)
{
undoStack = new QUndoStack(staticMemoryCleaner); undoStack = new QUndoStack(staticMemoryCleaner);
}
mApplicationTranslator = new QTranslator(this);
mApplicationTranslator->load(UBPlatformUtils::preferredTranslation(QString("sankore_")));
installTranslator(mApplicationTranslator);
QString localString; QString forcedLanguage("");
if (!mApplicationTranslator->isEmpty()) if(args.contains("-lang"))
localString = UBPlatformUtils::preferredLanguage(); forcedLanguage=args.at(args.indexOf("-lang") + 1);
else
localString = "en_US";
mQtGuiTranslator = new QTranslator(this);
mQtGuiTranslator->load(UBPlatformUtils::preferredTranslation(QString("qt_")));
installTranslator(mQtGuiTranslator);
setupTranslator(forcedLanguage);
QLocale::setDefault(QLocale(localString));
qDebug() << "Running application in:" << localString;
UBSettings *settings = UBSettings::settings(); UBSettings *settings = UBSettings::settings();
...@@ -217,6 +203,51 @@ UBApplication::~UBApplication() ...@@ -217,6 +203,51 @@ UBApplication::~UBApplication()
staticMemoryCleaner = 0; 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) int UBApplication::exec(const QString& pFileToImport)
{ {
QPixmapCache::setCacheLimit(1024 * 100); QPixmapCache::setCacheLimit(1024 * 100);
......
...@@ -121,6 +121,7 @@ class UBApplication : public QtSingleApplication ...@@ -121,6 +121,7 @@ class UBApplication : public QtSingleApplication
private: private:
void updateProtoActionsState(); void updateProtoActionsState();
void setupTranslator(QString forcedLanguage);
QList<QMenu*> mProtoMenus; QList<QMenu*> mProtoMenus;
bool mIsVerbose; bool mIsVerbose;
......
...@@ -177,7 +177,7 @@ void UBFileSystemUtils::cleanupGhostTempFolders(const QString& templateString) ...@@ -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; QStringList result;
if (pDirPath == "" || pDirPath == "." || pDirPath == "..") if (pDirPath == "" || pDirPath == "." || pDirPath == "..")
...@@ -187,7 +187,7 @@ QStringList UBFileSystemUtils::allFiles(const QString& pDirPath) ...@@ -187,7 +187,7 @@ QStringList UBFileSystemUtils::allFiles(const QString& pDirPath)
foreach(QFileInfo dirContent, dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot , QDir::Name)) foreach(QFileInfo dirContent, dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot , QDir::Name))
{ {
if (dirContent.isDir()) if (isRecursive && dirContent.isDir())
{ {
result << allFiles(dirContent.absoluteFilePath()); result << allFiles(dirContent.absoluteFilePath());
} }
......
...@@ -37,7 +37,7 @@ class UBFileSystemUtils ...@@ -37,7 +37,7 @@ class UBFileSystemUtils
static QFileInfoList allElementsInDirectory(const QString& pDirPath); 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); static bool deleteDir(const QString& pDirPath);
......
...@@ -103,8 +103,8 @@ class UBPlatformUtils ...@@ -103,8 +103,8 @@ class UBPlatformUtils
static void setFileType(const QString &filePath, unsigned long fileType); static void setFileType(const QString &filePath, unsigned long fileType);
static void fadeDisplayOut(); static void fadeDisplayOut();
static void fadeDisplayIn(); static void fadeDisplayIn();
static QString preferredTranslation(QString pFilePrefix); static QString translationPath(QString pFilePrefix, QString pLanguage);
static QString preferredLanguage(); static QString systemLanguage();
static bool hasVirtualKeyboard(); static bool hasVirtualKeyboard();
//static void showVirtualKeyboard(); //static void showVirtualKeyboard();
static void runInstaller(const QString &installerFilePath); static void runInstaller(const QString &installerFilePath);
...@@ -115,6 +115,7 @@ class UBPlatformUtils ...@@ -115,6 +115,7 @@ class UBPlatformUtils
static QString computerName(); static QString computerName();
static UBKeyboardLocale** getKeyboardLayouts(int& nCount); static UBKeyboardLocale** getKeyboardLayouts(int& nCount);
static QString urlFromClipboard(); static QString urlFromClipboard();
static QStringList availableTranslations();
}; };
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include "frameworks/UBFileSystemUtils.h"
void UBPlatformUtils::init() void UBPlatformUtils::init()
{ {
...@@ -55,13 +57,22 @@ void UBPlatformUtils::fadeDisplayIn() ...@@ -55,13 +57,22 @@ void UBPlatformUtils::fadeDisplayIn()
// NOOP // 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; return qmPath;
} }
QString UBPlatformUtils::preferredLanguage() QString UBPlatformUtils::systemLanguage()
{ {
return QLocale::system().name(); return QLocale::system().name();
} }
......
...@@ -184,31 +184,64 @@ void UBPlatformUtils::fadeDisplayIn() ...@@ -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]; 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]; QString UBPlatformUtils::translationPath(QString pFilePrefix, QString pLanguage)
if (lprojPath) {
{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *lang = [[lprojPath lastPathComponent] stringByDeletingPathExtension]; NSString *lprojPath = [[NSBundle mainBundle] resourcePath];
NSString *translationFilePath = [lprojPath stringByAppendingPathComponent:[[filePrefix stringByAppendingString:lang] stringByAppendingPathExtension:@"qm"]]; QString translationsPath = QString::fromUtf8([lprojPath UTF8String], strlen([lprojPath UTF8String]));
qmPath = QString::fromUtf8([translationFilePath UTF8String], strlen([translationFilePath UTF8String]));
}
[pool drain]; [pool drain];
return qmPath; return translationsPath + "/" + pLanguage + ".lproj/" + pFilePrefix + pLanguage + ".qm";
} }
QString UBPlatformUtils::preferredLanguage() QString UBPlatformUtils::systemLanguage()
{ {
QFileInfo qmFileInfo = QFileInfo(preferredTranslation("sankore_")); NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
QDir lprojPath = qmFileInfo.dir(); NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
QFileInfo lprojFileInfo = QFileInfo(lprojPath.absolutePath()); NSArray* languages = [defs objectForKey:@"AppleLanguages"];
return lprojFileInfo.baseName(); NSString* preferredLang = [languages objectAtIndex:0];
QString result = QString::fromUtf8([preferredLang UTF8String], strlen([preferredLang UTF8String]));
[pool drain];
return result;
} }
void UBPlatformUtils::runInstaller(const QString &installerFilePath) void UBPlatformUtils::runInstaller(const QString &installerFilePath)
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <windows.h> #include <windows.h>
#include <shellapi.h> #include <shellapi.h>
#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h" #include "core/memcheck.h"
void UBPlatformUtils::init() void UBPlatformUtils::init()
...@@ -59,14 +60,22 @@ void UBPlatformUtils::fadeDisplayIn() ...@@ -59,14 +60,22 @@ void UBPlatformUtils::fadeDisplayIn()
// NOOP // NOOP
} }
QString UBPlatformUtils::preferredTranslation(QString pFilePrefix) QStringList UBPlatformUtils::availableTranslations()
{ {
QString localPreferredLanguage = preferredLanguage(); QString translationsPath = applicationResourcesDirectory() + "/" + "i18n" + "/";
QString qmPath = applicationResourcesDirectory() + "/" + "i18n" + "/" + pFilePrefix + localPreferredLanguage + ".qm"; 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; return qmPath;
} }
QString UBPlatformUtils::preferredLanguage() QString UBPlatformUtils::systemLanguage()
{ {
return QLocale::system().name(); return QLocale::system().name();
} }
......
...@@ -263,14 +263,6 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event) ...@@ -263,14 +263,6 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
// Update the thumbnails width // Update the thumbnails width
mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth; 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 // Refresh the scene
refreshScene(); refreshScene();
} }
......
...@@ -45,7 +45,7 @@ UBLeftPalette::~UBLeftPalette() ...@@ -45,7 +45,7 @@ UBLeftPalette::~UBLeftPalette()
*/ */
void UBLeftPalette::updateMaxWidth() void UBLeftPalette::updateMaxWidth()
{ {
setMaximumWidth(270); setMaximumWidth((int)(parentWidget()->width() * 0.45));
} }
/** /**
......
...@@ -69,7 +69,7 @@ void UBRightPalette::resizeEvent(QResizeEvent *event) ...@@ -69,7 +69,7 @@ void UBRightPalette::resizeEvent(QResizeEvent *event)
*/ */
void UBRightPalette::updateMaxWidth() void UBRightPalette::updateMaxWidth()
{ {
setMaximumWidth((int)((parentWidget()->width() * 2)/3)); setMaximumWidth((int)(parentWidget()->width() * 0.45));
setMaximumHeight(parentWidget()->height()); setMaximumHeight(parentWidget()->height());
setMinimumHeight(parentWidget()->height()); setMinimumHeight(parentWidget()->height());
} }
...@@ -887,11 +887,6 @@ void UBImgTextThumbnailElement::Place(int row, int col, qreal width, qreal heigh ...@@ -887,11 +887,6 @@ void UBImgTextThumbnailElement::Place(int row, int col, qreal width, qreal heigh
qreal scaleFactor = qMin(scaleWidth, scaleHeight); qreal scaleFactor = qMin(scaleWidth, scaleHeight);
UBThumbnail* pix = dynamic_cast<UBThumbnail*>(this->thumbnail); UBThumbnail* pix = dynamic_cast<UBThumbnail*>(this->thumbnail);
if(pix)
{
scaleFactor = qMin(scaleFactor, 1.0);
}
QTransform transform; QTransform transform;
transform.scale(scaleFactor, scaleFactor); transform.scale(scaleFactor, scaleFactor);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment