summaryrefslogtreecommitdiffstats
path: root/quanta/utility/qpevents.h
blob: 4c65c359e5fae803da9316650dbe14856757d325 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***************************************************************************
                          qpevents.h  -  description
                             -------------------
    begin                : Sun Jul 11 2004
    copyright          : (C) 2004 Andras Mantia <amantia@kde.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 TQPEVENTS_H
#define TQPEVENTS_H

#include <tqobject.h>

/**
@author Andras Mantia
*/

/** Describes an event action. */
struct EventAction {
 /** Possible event types */
  enum Types {
     Internal = 0,
     External = 1
  };
  /** The type of the event. See @ref Types */
  uint type;
  /** the name of the action to be executed. In case of external events
     this is the name of the script, in case of internal events it can be one of the
     following: "email"
  */
  TQString action;
  /** The arguments for the event action. It is different for each action.
  */
  TQStringList arguments;
};

/** The configured events. The key is the event name, the data is the event description.
For example: events["before_save"] points to the event data that needs to be used
before a file is saved. Possible key names are: before_save, after_save, after_open,
after_project_open, after_project_save, before_upload, after_upload, after_project_add,
after_project_remove, after_commit
*/
typedef  TQMap<TQString, TQValueList<EventAction> > EventActions;

class QPEvents : public TQObject
{
TQ_OBJECT
  
public:
    static QPEvents* const ref(TQObject *parent = 0L)
    {
      static QPEvents *m_ref;
      if (!m_ref) m_ref = new QPEvents(parent);
      return m_ref;
    }
    ~QPEvents();
    TQString fullEventName(const TQString &name);
    TQString fullActionName(const TQString &name);
    TQString eventName(const TQString &fullName);
    TQString actionName(const TQString &fullName);
    TQStringList eventNames();
    TQStringList actionNames();

public slots:
 /** Called when an event has happened */
   void slotEventHappened(const TQString& name, const TQString& argument1, const TQString& argument2);

private:
    QPEvents(TQObject *parent = 0, const char *name = 0);
  /** Calls the action associated with an event. Returns true if the call succeeded, false
  otherwise. The call might fail if:
    - the action type is unknown
    - the script cannot be found
    - the user canceled the execution
 */
    bool handleEvent(const EventAction& ev);

    TQMap<TQString, TQString> m_eventNames;
    TQMap<TQString, TQString> m_actionNames;
    TQString m_eventName;
};

#endif