summaryrefslogtreecommitdiffstats
path: root/ksirc/puke/pobject.h
blob: 8e5c7c5a3781f550f5379f6ce1a7b6d030084671 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef POBJECT_H
#define POBJECT_H

class PObject;
class PukeController;
class CreateArgs;

#include <qobject.h>
#include "pmessage.h"


class CreateArgs {
public:
  CreateArgs(PukeController *_pc, PukeMessage *_pm, widgetId *_pwI, PObject *_parent){
    pc = _pc;
    pwI = _pwI;
    parent = _parent;
    pm = _pm;
    fetchedObj = 0;
  }
  PukeController *pc;
  widgetId *pwI;
  PObject *parent;
  PukeMessage *pm;

  /**
   * name of the widget which was fetched from kSirc, this has to be set explicitly
   */
  QObject *fetchedObj;
};

class PObject : public QObject
{
  Q_OBJECT
 public:
  PObject(QObject *parent = 0, const char *name = 0);
  virtual ~PObject();

  /**
   * Creates a new QObject and returns a PObject
   */
  static PObject *createWidget(CreateArgs &ca);

  /**
   * Handles messages from dsirc
   * PObject can't get messages so return an error
   */
  virtual void messageHandler(int fd, PukeMessage *pm);

  /**
   * Sets the current opbect
   */
  virtual void setWidget(QObject *w);
  
  /**
   * Returns the current object
   */
  virtual QObject *widget();

  /**
   * Sets the window id
   */
  virtual void setWidgetId(widgetId *pwI);
  /**
   * Returns the current window identifier
   */
  virtual widgetId widgetIden();

  /**
   * Set's the puke controller for the widget
   */
  void setPukeController(PukeController *pc){
    pController = pc;
  }

  /**
   * If we cannot delete the widget, check this (ie fetched widgets)
   */
  bool isDeleteAble(){
      return deleteAble;
  }

  /**
   * Returns if an error was encountered.
   */
  bool hasError() { 
      return m_hasError;
  }

  /**
   * Returns error description
   */
  QString error() {
      m_hasError = false;
      return m_error;
  }

  /**
   * Set this for fetched widgets and such that cannot be deleted
   */
  void setDeleteAble(bool _d){
      deleteAble = _d;
  }
  /**
   * Before deleting the widget, call manTerm() to signal manual
   * termination of the widget
   */
  void manTerm();
   

 signals:
  void outputMessage(int fd, PukeMessage *pm);
  void widgetDestroyed(widgetId wI);

 protected slots:
   void swidgetDestroyed();

protected:
  PukeController *controller();
  void errorInvalidSet(QObject *_w);

private:
  QObject *obj;
  PukeController *pController;
  widgetId wI;

  bool manualTerm;
  bool deleteAble;
  QString m_error;
  bool m_hasError;
};

#include "controller.h"
#endif