Commit b8659725 authored by Lukas Appelhans's avatar Lukas Appelhans

Here we go with our hook class

parent 5bab6ee1
......@@ -13,6 +13,7 @@ akabeierror.cpp
akabeigroup.cpp
akabeihelpers.c
akabeihelpers.cpp
akabeihook.cpp
akabeioperation.cpp
akabeioperationrunner.cpp
akabeipackage.cpp
......@@ -21,7 +22,7 @@ akabeivalidatorrunnable_p.cpp
md5.c
)
set(AKABEI_OPERATION_SRCS
set(AKABEI_OPERATION_SRCS
operations/akabeiplainhookoperation.cpp
operations/akabeiplainreinstalloperation.cpp
operations/akabeiplaininstalloperation.cpp
......@@ -38,6 +39,7 @@ akabeidatabase.h
akabeierror.h
akabeigroup.h
akabeihelpers.h
akabeihook.h
akabeioperation.h
akabeioperationrunner.h
akabeipackage.h
......
/* 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.
*/
#include "akabeihook.h"
#include "akabeihook_p.h"
#include <QTemporaryFile>
#include <qtextstream.h>
Akabei::Hook::Hook(const QString& name, const QString &content, Akabei::Database* db)
: d_ptr(new HookPrivate(name, content, db))
{
}
Akabei::Hook::~Hook()
{
}
QString Akabei::Hook::name() const
{
Q_D(const Hook);
return d->name;
}
Akabei::Database* Akabei::Hook::database() const
{
Q_D(const Hook);
return d->database;
}
QString Akabei::Hook::path()
{
Q_D(Hook);
if (d->file)
return d->file->fileName();
d->file = new QTemporaryFile();
QTextStream out(d->file);
out << d->content;
out.flush();
return d->file->fileName();
}
/* 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
#include <QtCore/QObject>
namespace Akabei {
/**
* A Hook is basically a scriplet, but on a global scale.
* Even though multiple packages can request a hook to be executed,
* it will only be done once at the end of the transaction.
*/
class HookPrivate;
class Database;
class Hook
{
Q_DISABLE_COPY(Hook)
Q_DECLARE_PRIVATE(Hook)
public:
virtual ~Hook();
QString name() const;
Akabei::Database * database() const;
/**
* A temporary script file gets created.
*/
QString path();
private:
Hook(const QString &name, const QString &content, Akabei::Database *db);
HookPrivate * const d_ptr;
friend class Backend;
friend class Database;
friend class DatabasePrivate;
};
}
#endif // AKABEIHOOK_H
/*
This file is part of the Chakra project
Copyright (C) 2011 Lukas Appelhans <boom1992@chakra-project.org>
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 AKABEI_AKABEIHOOK_P_H
#define AKABEI_AKABEIHOOK_P_H
#include "akabeihook.h"
class QTemporaryFile;
namespace Akabei {
class HookPrivate {
public:
HookPrivate(const QString &n, const QString &c, Akabei::Database * db)
: name(n)
, content(c)
, database(db)
, file(0)
{}
~HookPrivate() {}
QString name;
QString content;
Akabei::Database * database;
QTemporaryFile * file;
};
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment