Changeset c59a740 in subsurface


Ignore:
Timestamp:
Jul 9, 2017, 5:40:29 PM (3 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
ff65939
Parents:
e8b4603
git-author:
Dirk Hohndel <dirk@…> (07/09/17 17:03:57)
git-committer:
Dirk Hohndel <dirk@…> (07/09/17 17:40:29)
Message:

Android: write appLog to file

The trick is to pick a path that is accessible from other applications.
In theory QStandardPaths::GenericDataLocation? should provide that.

Signed-off-by: Dirk Hohndel <dirk@…>

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mobile-widgets/qmlmanager.cpp

    r9111ce0 rc59a740  
    9191        m_lastDevicePixelRatio = qApp->devicePixelRatio();
    9292        connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged);
     93
     94#if defined(Q_OS_ANDROID)
     95        appLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/subsurface.log";
     96        appLogFile.setFileName(appLogFileName);
     97        if (!appLogFile.open(QIODevice::ReadWrite)) {
     98                appLogFileOpen = false;
     99                appendTextToLog("Failed to open logfile" + appLogFileName);
     100        } else {
     101                appLogFileOpen = true;
     102                appendTextToLog("Successfully opened logfile" + appLogFileName);
     103        }
     104#endif
    93105        appendTextToLog("Starting " + getUserAgent());
    94106        appendTextToLog(QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()));
     
    235247QMLManager::~QMLManager()
    236248{
     249#if defined(Q_OS_ANDROID)
     250        if (appLogFileOpen)
     251                appLogFile.close();
     252#endif
    237253        m_instance = NULL;
    238254}
     
    15311547#if defined (Q_OS_ANDROID)
    15321548
     1549void writeToAppLogFile(QString logText)
     1550{
     1551        // write to storage and flush so that the data doesn't get lost
     1552        logText.append("\n");
     1553        QMLManager *self = QMLManager::instance();
     1554        if (self) {
     1555                self->writeToAppLogFile(logText);
     1556        }
     1557}
     1558
     1559void QMLManager::writeToAppLogFile(QString logText)
     1560{
     1561        if (appLogFileOpen) {
     1562                appLogFile.write(logText.toUtf8().data());
     1563                appLogFile.flush();
     1564        }
     1565}
    15331566
    15341567//HACK to color the system bar on Android, use qtandroidextras and call the appropriate Java methods
  • mobile-widgets/qmlmanager.h

    rfd96dac rc59a740  
    126126        void setShowPin(bool enable);
    127127        Q_INVOKABLE void setStatusbarColor(QColor color);
     128#if defined(Q_OS_ANDROID)
     129        void writeToAppLogFile(QString logText);
     130#endif
    128131
    129132public slots:
     
    209212        DCDeviceData *m_device_data;
    210213        QString m_progressMessage;
     214#if defined(Q_OS_ANDROID)
     215        QString appLogFileName;
     216        QFile appLogFile;
     217        bool appLogFileOpen;
     218#endif
    211219
    212220signals:
  • qt-models/messagehandlermodel.cpp

    r5bc91f0 rc59a740  
    33
    44/* based on logging bits from libdivecomputer */
    5 #ifndef __ANDROID__
     5#if !defined(Q_OS_ANDROID)
    66#define INFO(fmt, ...)  fprintf(stderr, "INFO: " fmt "\n", ##__VA_ARGS__)
    77#else
     8extern void writeToAppLogFile(QString logText);
    89#include <android/log.h>
    9 #define INFO(fmt, ...)  __android_log_print(ANDROID_LOG_DEBUG, __FILE__, "INFO: " fmt "\n", ##__VA_ARGS__)
     10#define INFO(fmt, ...)  __android_log_print(ANDROID_LOG_DEBUG, __FILE__, "INFO: " fmt "\n", ##__VA_ARGS__);
    1011#endif
    1112
     
    4344        endInsertRows();
    4445        INFO("%s", message.toUtf8().constData());
     46#if defined (Q_OS_ANDROID)
     47        writeToAppLogFile(message);
     48#endif
    4549}
    4650
Note: See TracChangeset for help on using the changeset viewer.