main.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <QTranslator>
  2. #include <QLocale>
  3. #include <QtGui/QApplication>
  4. #include <QDeclarativeEngine>
  5. #include <QString>
  6. #include <QtDeclarative>
  7. #include <QFile>
  8. #include <stdlib.h>
  9. // Define the SQLite database file size.
  10. const int DBSize = 7235584;
  11. int main(int argc, char *argv[])
  12. {
  13. QApplication app(argc, argv);
  14. // Detect system locale and loads the Traditional Chinese / Simplified Chinese / English UIs accordingly
  15. QTranslator translator;
  16. QString locale = getenv("LANG");
  17. qDebug() << "Locale = " + locale;
  18. if (locale == "zh_HK" || locale == "zh_TW" || locale == "zh_MO") {
  19. // Loading localized translation files from Resources
  20. translator.load("zh_HK.qm", ":/qml/");
  21. app.installTranslator(&translator);
  22. }
  23. else if (locale == "zh_CN" || locale == "zh_SG") {
  24. // Loading localized translation files from Resources
  25. translator.load("zh_CN.qm", ":/qml/");
  26. app.installTranslator(&translator);
  27. }
  28. QDeclarativeView view;
  29. // Connect the quit signal of QML to Qt's quit signal so that Exit app feature works in QML.
  30. QObject::connect((QObject*)view.engine(), SIGNAL(quit()), &app, SLOT(quit()));
  31. // Copy SQLite database over to user's / developer's default local storage path if it does not exist currently.
  32. QFile UserINIFile("/home/user/.local/share/data/QML/OfflineStorage/Databases/7c78ebb4c223c96f8e6ccc29f73cc28e.ini");
  33. QFile UserDBFile("/home/user/.local/share/data/QML/OfflineStorage/Databases/7c78ebb4c223c96f8e6ccc29f73cc28e.sqlite");
  34. QFile DevINIFile("/home/developer/.local/share/data/QML/OfflineStorage/Databases/7c78ebb4c223c96f8e6ccc29f73cc28e.ini");
  35. QFile DevDBFile("/home/developer/.local/share/data/QML/OfflineStorage/Databases/7c78ebb4c223c96f8e6ccc29f73cc28e.sqlite");
  36. if ((!UserINIFile.exists() || !UserDBFile.exists() || UserDBFile.size()!=DBSize) && (strcmp(getenv("USER"),"user")==0)) {
  37. system("cp -f /opt/IMQuery/db/* /home/user/.local/share/data/QML/OfflineStorage/Databases/");
  38. }
  39. if ((!DevINIFile.exists() || !DevDBFile.exists() || UserDBFile.size()!=DBSize) && (strcmp(getenv("USER"),"developer")==0)) {
  40. system("cp -f /opt/IMQuery/db/* /home/developer/.local/share/data/QML/OfflineStorage/Databases/");
  41. }
  42. // Load the main QML file for main UI and logics
  43. view.setSource(QUrl("qrc:/qml/main.qml"));
  44. view.showFullScreen();
  45. return app.exec();
  46. }