akabeihook.h 2.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/* This file is part of the Chakra project

   Copyright (C) 2011 Lukas Appelhans

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
*/

#ifndef AKABEIHOOK_H
#define AKABEIHOOK_H

14
#include <QObject>
15 16

namespace Akabei {
Lukas Appelhans's avatar
Docs  
Lukas Appelhans committed
17 18 19
class HookPrivate;
class Database;
class Package;
20
/**
Lukas Appelhans's avatar
Docs  
Lukas Appelhans committed
21 22 23
 * \class Hook  akabeihook.h "akabeihook.h"
 *
 * \brief This class describes a script which possibly gets executed once in a transaction.
24
 *
25
 * A Hook is basically a scriptlet, but on a global scale.
26 27
 * Even though multiple packages can request a hook to be executed,
 * it will only be done once at the end of the transaction.
28
 *
Lukas Appelhans's avatar
Docs  
Lukas Appelhans committed
29
 * For example, we have a bunch of packages wanting to run kbuildsycoca4 to update kde's plugin cache.
30
 * Since this command is quite expensive it took a lot of time in pacman days to install multiple of
Lukas Appelhans's avatar
Docs  
Lukas Appelhans committed
31 32 33
 * those packages as every package was executing the command on itself.
 * Now we just have a hook running kbuildsycoca4 inside the database and all those packages use it. It
 * then gets executed only once at the end of the transaction.
34 35
 *
 * This class is thread-safe.
36 37 38 39 40 41 42
 */
class Hook
{
    Q_DISABLE_COPY(Hook)
    Q_DECLARE_PRIVATE(Hook)
    public:
        virtual ~Hook();
43

Lukas Appelhans's avatar
Docs  
Lukas Appelhans committed
44 45 46
        /**
         * @returns the name of the hook
         */
47
        QString name() const;
48

Lukas Appelhans's avatar
Docs  
Lukas Appelhans committed
49 50 51
        /**
         * @returns the script which gets executed when running the hook
         */
52
        QString content() const;
53

Lukas Appelhans's avatar
Docs  
Lukas Appelhans committed
54 55 56
        /**
         * @returns a list of packages which request this hook on transaction
         */
Lukas Appelhans's avatar
Lukas Appelhans committed
57
        QList<Akabei::Package*> packages() const;
58

59
        /**
Lukas Appelhans's avatar
Docs  
Lukas Appelhans committed
60 61
         * @returns a path to a file containing the content()
         * A developer can now easily run the script with a \c QProcess object
62 63
         */
        QString path();
64

65
    private:
Lukas Appelhans's avatar
Lukas Appelhans committed
66
        Hook(const QString &name, const QString &content, QList<Akabei::Package*> pkgs);
67

68 69 70 71 72 73 74 75 76
        HookPrivate * const d_ptr;

        friend class Backend;
        friend class Database;
        friend class DatabasePrivate;
};
}

#endif // AKABEIHOOK_H