transferengine_p.h 4.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright (c) 2013 - 2019 Jolla Ltd.
 *
 * All rights reserved.
 *
 * This file is part of Sailfish Transfer Engine package.
 *
 * You may use this file under the terms of the GNU Lesser General
 * Public License version 2.1 as published by the Free Software Foundation
 * and appearing in the file license.lgpl included in the packaging
 * of this file.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * and appearing in the file license.lgpl included in the packaging
 * of this file.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 */
24 25 26 27 28 29

#ifndef TRANSFERENGINE_P_H
#define TRANSFERENGINE_P_H

#include <QObject>
#include <QMap>
Pekka Vuorela's avatar
Pekka Vuorela committed
30
#include <QVariantList>
31 32 33 34

#include "mediatransferinterface.h"
#include "transfermethodinfo.h"

35 36 37
namespace Accounts {
class Manager;
}
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

class QFileSystemWatcher;
class QTimer;
class QUrl;
class TransferEngine;
class TransferPluginInfo;

class TransferEngineSignalHandler: public QObject
{
    Q_OBJECT
public:
    static TransferEngineSignalHandler * instance();
    static void signalHandler(int signal);

Q_SIGNALS:
    void exitSafely();

private:
    TransferEngineSignalHandler();
};

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
class ClientActivityMonitor: public QObject
{
    Q_OBJECT
public:
    ClientActivityMonitor(QObject *parent = 0);
    ~ClientActivityMonitor();

    void newActivity(int transferId);
    void activityFinished(int transferId);

    bool activeTransfers() const;

public Q_SLOTS:
    void checkActivity();

Q_SIGNALS:
    void transfersExpired(QList<int> transferIds);

private:
    // Map for transferId, timestamps
    QMap<int, quint32> m_activityMap;
    QTimer *m_timer;
};

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
class TransferEnginePrivate: QObject
{
    Q_OBJECT
public:
    // CallbackElement enum is used as an accessor to DBus callback
    // information from a list. Enums are used as an indeces.
    enum CallbackElements {
        Service = 0,
        Path,
        Interface
    };

    // CallbackMethodType enum is used as an accessor to the list where
    // method names starts from the index 3.
    enum CallbackMethodType {
        CancelCallback  = 3,
        RestartCallback = 4
    };

    TransferEnginePrivate(TransferEngine *parent);
    void recoveryCheck();
    void sendNotification(TransferEngineData::TransferType type,
                          TransferEngineData::TransferStatus status,
106 107 108
                          qreal progress,
                          const QString &fileName,
                          int transferId);
109 110 111 112 113 114 115 116
    int uploadMediaItem(MediaItem *mediaItem,
                        MediaTransferInterface *muif,
                        const QVariantMap &userData);
    inline TransferEngineData::TransferType transferType(int transferId);
    void callbackCall(int transferId, CallbackMethodType method);

public Q_SLOTS:
    void exitSafely();
117
    void delayedExitSafely();
118
    void enabledPluginsCheck();
119
    void cleanupExpiredTransfers(const QList<int> &expiredIds);
120 121 122 123 124 125 126 127 128
    void pluginDirChanged();
    void uploadItemStatusChanged(MediaTransferInterface::TransferStatus status);
    void updateProgress(qreal progress);
    void pluginInfoReady();
    void pluginInfoError(const QString &msg);

public:
    QStringList pluginList() const;
    QList <TransferMethodInfo> enabledPlugins() const;
129
    QList<QVariantMap> pluginMetaData() const;
130
    MediaTransferInterface *loadPlugin(const QString &pluginId) const;
131
    QString mediaFileOrResourceName(MediaItem *mediaItem) const;
132

133
private:
134 135 136 137 138
    QMap <MediaTransferInterface*, int> m_plugins;
    QMap <int, TransferEngineData::TransferType> m_keyTypeCache;
    bool m_notificationsEnabled;
    QList <TransferPluginInfo*> m_infoObjects;
    QList <TransferMethodInfo> m_enabledPlugins;
139
    QList<QVariantMap> m_pluginMetaData;
140 141 142
    Accounts::Manager *m_accountManager;
    QFileSystemWatcher *m_fileWatcher;
    QTimer *m_fileWatcherTimer;
143
    QTimer *m_delayedExitTimer;
144
    ClientActivityMonitor *m_activityMonitor;
145
    TransferEngine *q_ptr;
Pekka Vuorela's avatar
Pekka Vuorela committed
146
    QVariantList m_defaultActions;
147 148 149 150 151
    Q_DECLARE_PUBLIC(TransferEngine)
};

#endif