sandbox_p.h 1.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/**
 * @file sandbox_p.h
 * @copyright 2013 Jolla Ltd.
 * @author Martin Kampas <martin.kampas@tieto.com>
 * @date 2013
 */

#ifndef _SANDBOX_P_H
#define _SANDBOX_P_H

11
#include <QtCore/QDir>
12
#include <QtCore/QSet>
13 14 15 16 17 18 19 20 21
#include <QtCore/QString>

class Sandbox {
  public:
    enum Usage {
      UseDirectly,
      UseAsSkeleton,
    };

22 23 24 25 26 27
    enum Scope {
      ThisProcess    = 0x01,
      ChildProcesses = 0x02,
    };
    Q_DECLARE_FLAGS(Scopes, Scope)

28 29
  public:
    Sandbox();
30
    Sandbox(const QString &sandboxPath, Usage usage, Scopes scopes);
31 32
    ~Sandbox();

33
    bool activate();
34
    void deactivate();
35 36
    bool isActive() const;

37 38 39
    static QDir effectiveRootDir();
    static QString map(const QString &fileName);

40
    bool addWorldFiles(const QString &directory, QDir::Filters filters = QDir::NoFilter,
41
        const QStringList &filterNames = QStringList(), bool recurse = true);
42
    bool addWorldFile(const QString &file);
43 44

  private:
45
    bool prepare();
46
    static QString createTmpDir(const QString &nameTemplate);
47
    static bool copyDir(const QString &directory, const QString &newName);
48

49
  private:
50 51 52 53 54 55
    static Sandbox *s_activeInstance;
    const bool m_defaultConstructed;
    const Usage m_usage;
    const Scopes m_scopes;
    const QString m_sandboxPath;
    bool m_prepared;
56
    QString m_tempDir;
57
    QDir m_workingSandboxDir;
58 59
};

60 61
Q_DECLARE_OPERATORS_FOR_FLAGS(Sandbox::Scopes)

62
#endif