summaryrefslogtreecommitdiffstats
path: root/quanta/project/eventconfigurationdlg.cpp
blob: d50eb1e0d929de1381e1c509660b585a7fb0a9e9 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/***************************************************************************
                          eventconfigurationdlg.cpp  -  description
                             -------------------
    begin                : Mon Jul 12 2004
    copyright          : (C) 2004 Andras Mantia <[email protected]>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

 //qt includes
#include <tqdom.h>

//kde includes
#include <kcombobox.h>
#include <kdialogbase.h>
#include <klistview.h>
#include <klocale.h>
#include <kmessagebox.h>

//app includes
#include "eventconfigurationdlg.h"
#include "eventeditordlg.h"
#include "qpevents.h"

EventConfigurationDlg::EventConfigurationDlg(KActionCollection *actionCollection, TQWidget* tqparent, const char* name, WFlags fl)
: EventConfigurationDlgS(tqparent,name,fl)
{
  m_actionCollection = actionCollection;
}

EventConfigurationDlg::~EventConfigurationDlg()
{
}

void EventConfigurationDlg::initEvents(EventActions *events)
{
  TQListViewItem *item;
  for (EventActions::ConstIterator it = events->constBegin(); it != events->constEnd(); ++it)
  {
    TQValueList<EventAction> evList = it.data();
    for (TQValueList<EventAction>::ConstIterator it2 = evList.constBegin(); it2 != evList.constEnd(); ++it2)
    {
      EventAction ev = *it2;
      item = new TQListViewItem(eventsListView, QPEvents::ref()->fullEventName(it.key()), QPEvents::ref()->fullActionName(ev.action));
      int argcount = ev.arguments.count();
      if (argcount > 0)
          item->setText(2, ev.arguments[0]);
      if (argcount > 1)
          item->setText(3, ev.arguments[1]);
      if (argcount > 2)
          item->setText(4, ev.arguments[2]);
      if (argcount > 3)
          item->setText(5, ev.arguments[3]);
    }
  }
}

void EventConfigurationDlg::saveEvents(TQDomDocument dom)
{
    TQDomNode projectNode = dom.firstChild().firstChild();
    TQDomNode eventsNode = projectNode.namedItem("events");
    projectNode.removeChild(eventsNode);
    eventsNode = dom.createElement("events");
    projectNode.appendChild(eventsNode);
    TQDomElement node;
    TQListViewItemIterator it(eventsListView);
    TQListViewItem *item;
    while (it.current())
    {
       item = it.current();
       node = dom.createElement("event");
       eventsNode.appendChild(node);
       TQDomElement el = node.toElement();
       el.setAttribute("name", QPEvents::ref()->eventName(item->text(0)));
       el.setAttribute("action", QPEvents::ref()->actionName(item->text(1)));
       if (el.attribute("action") == "script" || el.attribute("action") == "action")
         el.setAttribute("type", "external");
       else
         el.setAttribute("type", "internal");
       for (uint  i = 2; i < 6; i++)
       {
          TQString s = item->text(i);
          if (s.isEmpty())
            s = "--not set--";
          TQDomNode argNode = dom.createElement("argument");
          node.appendChild(argNode);
          argNode.appendChild(dom.createTextNode(s));
        }
        ++it;
    }
}

void EventConfigurationDlg::slotAddEvent()
{
   KDialogBase editDlg(this, "add_event", true, i18n("New Event"), KDialogBase::Ok | KDialogBase::Cancel);
   EventEditorDlg eventDlg(m_actionCollection, &editDlg);
   editDlg.setMainWidget(&eventDlg);
   if (editDlg.exec())
   {
      TQListViewItem *item = new TQListViewItem(eventsListView);
      item->setText(0, eventDlg.eventCombo->currentText());
      item->setText(1, eventDlg.actionCombo->currentText());
      item->setText(2, eventDlg.argument1());
      item->setText(3, eventDlg.argument2());
      item->setText(4, eventDlg.argument3());
      item->setText(5, eventDlg.argument4());
   }
}

void EventConfigurationDlg::slotEditEvent()
{
   TQListViewItem *item = eventsListView->currentItem();
   if (!item) return;
   KDialogBase editDlg(this, "edit_event", true, i18n("Edit Event"), KDialogBase::Ok | KDialogBase::Cancel);
   EventEditorDlg eventDlg(m_actionCollection, &editDlg);
   editDlg.setMainWidget(&eventDlg);
   eventDlg.setEvent(item->text(0));
   eventDlg.setAction(item->text(1));
   TQStringList arguments;
   arguments << item->text(2) << item->text(3) << item->text(4) << item->text(5);
   eventDlg.setArguments(arguments);
   if (editDlg.exec())
   {
      item->setText(0, eventDlg.eventCombo->currentText());
      item->setText(1, eventDlg.actionCombo->currentText());
      item->setText(2, eventDlg.argument1());
      item->setText(3, eventDlg.argument2());
      item->setText(4, eventDlg.argument3());
      item->setText(5, eventDlg.argument4());
   }
}

void EventConfigurationDlg::slotDeleteEvent()
{
   TQListViewItem *item = eventsListView->currentItem();
   if (!item) return;
   if (KMessageBox::warningContinueCancel(this, i18n("<qt>Are you sure that you want to remove the configuration of the <b>%1</b> event?</qt>").tqarg(item->text(0)), i18n("Delete Event Configuration"),KStdGuiItem::del()) == KMessageBox::Continue)
   {
      delete item;
   }
}

#include "eventconfigurationdlg.moc"