| 1 | // Copyright (C) 2014 Sacha Refshauge |
| 2 | |
| 3 | // This program is free software: you can redistribute it and/or modify |
| 4 | // it under the terms of the GNU General Public License as published by |
| 5 | // the Free Software Foundation, version 3.0. |
| 6 | |
| 7 | // This program is distributed in the hope that it will be useful, |
| 8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | // GNU General Public License 3.0 for more details. |
| 11 | |
| 12 | // A copy of the GPL 3.0 should have been included with the program. |
| 13 | // If not, see http://www.gnu.org/licenses/ |
| 14 | |
| 15 | // Official GIT repository and contact information can be found at |
| 16 | // http://github.com/xsacha/Sachesi |
| 17 | |
| 18 | #include <QApplication> |
| 19 | #include <QtQml> |
| 20 | #include <QQmlContext> |
| 21 | #include <QQmlEngine> |
| 22 | #include <QQuickWindow> |
| 23 | #include <QQmlApplicationEngine> |
| 24 | |
| 25 | #include "search/mainnet.h" |
| 26 | #include "search/scanner.h" |
| 27 | #ifndef BLACKBERRY |
| 28 | #include "installer.h" |
| 29 | #include "backupinfo.h" |
| 30 | #endif |
| 31 | #include "carrierinfo.h" |
| 32 | #include "translator.h" |
| 33 | #ifdef BOOTLOADER_ACCESS |
| 34 | #include "boot.h" |
| 35 | #endif |
| 36 | |
| 37 | // Known bugs |
| 38 | // Crash: If you are looking at a different tab when backup size results return. Unknown cause! |
| 39 | |
| 40 | // Feature and function TODO |
| 41 | // TODO: We can make blitz faster by checking OTAs. Do this in download stage and perhaps in live blitz |
| 42 | // TODO: Allow installing directly from zip (difficult due to pipelining and requirement of seek which QuaZip won't support) |
| 43 | // TODO: Make extraction handle decent % tracking for QNX FS. Perhaps a per-file extractor for progress circle. |
| 44 | // TODO: Completely redo how Splitter is accessed. Possibly make it a class with per-function jobs/threads |
| 45 | // Need help: Check and improve the USB Loader (Boot). |
| 46 | // TODO: Use CircleProgress in Extract section. Pass a class to QML that contains file count, current and total progress |
| 47 | |
| 48 | // Platform TODO |
| 49 | // TODO: Window {} not working on Android. Maybe special QML files required? |
| 50 | // TODO: Blackberry is having a lot of issues with Qt5. For now I have a custom Cascades version with reduced feature-set |
| 51 | |
| 52 | // Need testing of policies: |
| 53 | // Personal: policy_block_backup_and_restore, policy_backup_and_restore |
| 54 | // Enterprise: policy_disable_devmode, policy_log_submission, policy_block_computer_access_to_device |
| 55 | |
| 56 | Q_DECL_EXPORT int main(int argc, char *argv[]) |
| 57 | { |
| 58 | QApplication::setAttribute(Qt::AA_X11InitThreads, true); |
| 59 | |
| 60 | QApplication app(argc, argv); |
| 61 | app.setOrganizationName("Qtness"); |
| 62 | app.setOrganizationDomain("qtness.com"); |
| 63 | app.setApplicationName("Sachesi"); |
| 64 | app.setApplicationVersion("2.0.4"); |
| 65 | |
| 66 | // Use system proxy except where not possible |
| 67 | QNetworkProxyFactory::setUseSystemConfiguration(true); |
| 68 | |
| 69 | QQmlApplicationEngine engine; |
| 70 | QQmlContext *context = engine.rootContext(); |
| 71 | |
| 72 | // Do we have a suitable place to store files that the user will be able to find? |
| 73 | if (!checkCurPath()) { |
| 74 | QMessageBox::critical(NULL, "Error", "Could not find a suitable storage path.\nPlease report this."); |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | // *** Static QML Variables that describe the environment |
| 79 | // Useful as QML is unable to detect this natively |
| 80 | |
| 81 | // Send the version across. Preferably via the .pro |
| 82 | context->setContextProperty("version", QVariant::fromValue(QApplication::applicationVersion())); |
| 83 | // Check if we have at least Qt 5.3 available. If not, do some workarounds for bugs. |
| 84 | context->setContextProperty("qt_new", QVariant::fromValue(QT_VERSION > QT_VERSION_CHECK(5, 3, 0))); |
| 85 | // Check if this is a mobile device as they often do not have enough space. |
| 86 | context->setContextProperty("mobile", QVariant::fromValue( |
| 87 | #if defined(BLACKBERRY) || defined(ANDROID) |
| 88 | 1 |
| 89 | #else |
| 90 | 0 |
| 91 | #endif |
| 92 | )); |
| 93 | |
| 94 | // *** C++ Classes that are passed to the QML pages. |
| 95 | // Heavy lifting to be done by the compiled and feature-packed language. |
| 96 | InstallNet i; |
| 97 | context->setContextProperty("i", &i); |
| 98 | MainNet p(&i); |
| 99 | Scanner scanner; |
| 100 | Translator translator; |
| 101 | #ifdef BOOTLOADER_ACCESS |
| 102 | Boot b; |
| 103 | |
| 104 | QObject::connect(&b, SIGNAL(started()), &b, SLOT(search())); |
| 105 | QObject::connect(&b, SIGNAL(finished()), &b, SLOT(exit())); |
| 106 | QObject::connect(&i, SIGNAL(newPassword(QString)), &b, SLOT(newPassword(QString))); |
| 107 | b.start(); |
| 108 | context->setContextProperty("b", &b); // Boot |
| 109 | #endif |
| 110 | CarrierInfo info; |
| 111 | |
| 112 | // Set contexts for the classes |
| 113 | context->setContextProperty("p", &p); // MainNet |
| 114 | context->setContextProperty("scanner", &scanner); |
| 115 | context->setContextProperty("download", p.currentDownload); |
| 116 | context->setContextProperty("carrierinfo", &info); |
| 117 | context->setContextProperty("translator", &translator); |
| 118 | |
| 119 | // *** Register types for the QML language to understand types used by C++, when passed |
| 120 | #ifndef BLACKBERRY |
| 121 | qmlRegisterType<BackupInfo>("BackupTools", 1, 0, "BackupInfo"); |
| 122 | #endif |
| 123 | qmlRegisterType<Apps>(); |
| 124 | qmlRegisterType<DeviceInfo>(); |
| 125 | qmlRegisterType<DiscoveredRelease>(); |
| 126 | |
| 127 | #if defined(_WIN32) && defined(STATIC) |
| 128 | engine.addImportPath("qrc:/qml/"); |
| 129 | #endif |
| 130 | |
| 131 | // *** Now let's try to show the QML file and check for errors |
| 132 | QScopedPointer<QQmlComponent> comp(new QQmlComponent(&engine)); |
| 133 | comp->loadUrl(QUrl("qrc:/qml/generic/Title.qml")); |
| 134 | if (comp->status() == QQmlComponent::Error) { |
| 135 | QMessageBox::information(nullptr, "Error", qPrintable(comp->errorString()), QMessageBox::Ok); |
| 136 | return 0; |
| 137 | } |
| 138 | QQuickWindow *window = qobject_cast<QQuickWindow *>(comp->create()); |
| 139 | window->show(); |
| 140 | |
| 141 | int ret = app.exec(); |
| 142 | |
| 143 | #ifdef BOOTLOADER_ACCESS |
| 144 | b.quit(); |
| 145 | b.wait(1000); |
| 146 | #endif |
| 147 | delete window; |
| 148 | return ret; |
| 149 | } |