summaryrefslogtreecommitdiffstats
path: root/kommander/widgets/dialog.cpp
blob: 3c6ed20f197ff6a2efd9b6edf1b5fdb332415395 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/***************************************************************************
                         dialog.cpp - Main dialog widget 
                             -------------------
    copyright            : (C) 2002 by Marc Britton
    email                : consume@optusnet.com.au
 ***************************************************************************/

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

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifndef KMDR_EXECUTOR_PATH
#define KMDR_EXECUTOR_PATH "/usr/bin/kmdr-executor"
#endif

/* KDE INCLUDES */
#include <tdelocale.h>

/* QT INCLUDES */
#include <tqstring.h>
#include <tqwidget.h>
#include <tqstringlist.h>
#include <tqevent.h>
#include <tqdialog.h>
#include <tqpoint.h>
#include <tqcursor.h>
#include <tqapplication.h>

/* OTHER INCLUDES */
#include <specials.h>
#include "dialog.h"
#include <myprocess.h>
#include "kommanderplugin.h"

enum Functions {
  FirstFunction = 185,
  D_focusWidget,
  D_waitCursor,
  D_restoreCursor,
  LastFunction
};

Dialog::Dialog(TQWidget *a_parent, const char *a_name, bool a_modal, int a_flags)
  : TQDialog(a_parent, a_name, a_modal, a_flags), KommanderWindow(this)
{
  TQStringList states;
  states << "default";
  states << "initialization";
  states << "destroy";
  setStates(states);
  setDisplayStates(states);
  m_useShebang = false;
  m_shebang = "#!" KMDR_EXECUTOR_PATH;
  m_firstShow = true;
  KommanderPlugin::setDefaultGroup(Group::DCOP);
  KommanderPlugin::registerFunction(D_focusWidget, "focusWidget(TQString widget)",  i18n("The name of the widget having focus"), 1);
  KommanderPlugin::registerFunction(D_waitCursor, "waitCursor(TQString widget)",  i18n("Set a wait cursor. CAUTION: if set more than once an equal number of calls to restore must be made to clear it."), 1);
  KommanderPlugin::registerFunction(D_restoreCursor, "restoreCursor(TQString widget)",  i18n("Restore normal curser. NOTE: must be called as many times as wait was."), 1);
}

Dialog::~Dialog()
{
  if (!inEditor)
    destroy();
}

TQString Dialog::currentState() const
{
  return TQString("default");
}

bool Dialog::isKommanderWidget() const
{
  return true;
}

bool Dialog::useInternalParser() const
{
  return m_useInternalParser; 
}

void Dialog::setUseInternalParser(bool b) 
{
  KommanderWidget::useInternalParser = b; 
  m_useInternalParser = b;
}


TQStringList Dialog::associatedText() const
{
  return KommanderWidget::associatedText();
}

void Dialog::setAssociatedText(const TQStringList& a_at)
{
  KommanderWidget::setAssociatedText(a_at);
}

void Dialog::setPopulationText(const TQString& a_text)
{
  KommanderWidget::setPopulationText( a_text );
}

TQString Dialog::populationText() const
{
  return KommanderWidget::populationText();
}

void Dialog::populate()
{
  setWidgetText(KommanderWidget::evalAssociatedText(populationText()));
}

void Dialog::initialize()
{    
  const TQStringList assoc = associatedText();
  if (assoc.count() > 1 && !assoc[1].isEmpty()) 
  {
    MyProcess proc(this);
    proc.run( KommanderWidget::evalAssociatedText(assoc[1]) );
  }
}

void Dialog::destroy()
{    
  const TQStringList assoc = associatedText();
  if (assoc.count() > 2 && !assoc[2].isEmpty()) 
  {
    MyProcess proc(this);
    proc.run( KommanderWidget::evalAssociatedText(assoc[2]) );
  }
}


void Dialog::setWidgetText(const TQString& a_text)
{
  setCaption(a_text);
  emit widgetTextChanged(a_text);
}

void Dialog::exec()
{
  TQDialog::exec();
  emit finished();
}

void Dialog::show()
{
//if the dialog is embedded in a KPart, the show can be called many times.
//to avoid re-init and sending signals we don't want, in that case call only the
//TQWidget's show method to show the widgets, but don't do any TQDialog specific 
//task
  if (!m_firstShow) 
  {
    TQWidget::show();
  } else
  {
    TQDialog::show();
    if (!inEditor)
      initialize();
    m_firstShow = false;
  }
}

void Dialog::done(int r)
{
/*  if (!inEditor)
    destroy();*/
  TQDialog::done(r);  
}

void Dialog::showEvent(TQShowEvent *e)
{
  TQDialog::showEvent( e );
  emit widgetOpened();
}

void Dialog::keyPressEvent( TQKeyEvent *e )
{
  if ( e->state() == 0 && e->key() == Key_Escape)
	return;
  else
   TQDialog::keyPressEvent(e);
  
}

void Dialog::contextMenuEvent( TQContextMenuEvent * e )
{
  TQDialog::contextMenuEvent( e );
  TQPoint p = e->globalPos();
  emit contextMenuRequested(p.x(), p.y());
}

bool Dialog::isFunctionSupported(int f)
{
  return f == DCOP::text || f == DCOP::setText || f == DCOP::geometry || (f > FirstFunction && f < LastFunction);
}

TQString Dialog::handleDCOP(int function, const TQStringList& args)
{
  switch (function) {
    case DCOP::text:
      return caption();
    case DCOP::setText:
      setWidgetText(args[0]);
      break;
    case DCOP::geometry:
      return TQString::number(this->x())+" "+TQString::number(this->y())+" "+TQString::number(this->width())+" "+TQString::number(this->height());
      break;
    case D_focusWidget:
      return focusWidget()->name();
      break;
    case D_waitCursor:
      TQApplication::setOverrideCursor(TQCursor(TQt::WaitCursor));
      break;
    case D_restoreCursor:
      TQApplication::restoreOverrideCursor();
      break;
    default:
      return KommanderWidget::handleDCOP(function, args);
  }
  return TQString();
}


#include "dialog.moc"