You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
363 lines
12 KiB
363 lines
12 KiB
15 years ago
|
//
|
||
|
//
|
||
|
// C++ Implementation: $MODULE$
|
||
|
//
|
||
|
// Description:
|
||
|
//
|
||
|
//
|
||
|
// Author: Gav Wood <gav@kde.org>, (C) 2003
|
||
|
//
|
||
|
// Copyright: See COPYING file that comes with this distribution
|
||
|
//
|
||
|
//
|
||
14 years ago
|
#include <tqregexp.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqradiobutton.h>
|
||
|
#include <tqcombobox.h>
|
||
|
#include <tqcheckbox.h>
|
||
|
#include <tqwidgetstack.h>
|
||
|
#include <tqbuttongroup.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
#include <klineedit.h>
|
||
12 years ago
|
#include <tdelistview.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <knuminput.h>
|
||
|
#include <keditlistbox.h>
|
||
|
|
||
|
#include <dcopclient.h>
|
||
|
#include <irkick_stub.h>
|
||
|
|
||
|
#include "prototype.h"
|
||
|
#include "profileserver.h"
|
||
|
#include "remoteserver.h"
|
||
|
#include "editaction.h"
|
||
|
#include "addaction.h"
|
||
|
|
||
13 years ago
|
EditAction::EditAction(IRAIt action, TQWidget *parent, const char *name) : EditActionBase(parent, name)
|
||
15 years ago
|
{
|
||
|
theAction = action;
|
||
|
|
||
|
updateApplications();
|
||
|
updateDCOPApplications();
|
||
|
}
|
||
|
|
||
|
EditAction::~EditAction()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void EditAction::readFrom()
|
||
|
{
|
||
|
theRepeat->setChecked((*theAction).repeat());
|
||
|
theAutoStart->setChecked((*theAction).autoStart());
|
||
|
theDoBefore->setChecked((*theAction).doBefore());
|
||
|
theDoAfter->setChecked((*theAction).doAfter());
|
||
|
theDontSend->setChecked((*theAction).ifMulti() == IM_DONTSEND);
|
||
|
theSendToTop->setChecked((*theAction).ifMulti() == IM_SENDTOTOP);
|
||
|
theSendToBottom->setChecked((*theAction).ifMulti() == IM_SENDTOBOTTOM);
|
||
|
theSendToAll->setChecked((*theAction).ifMulti() == IM_SENDTOALL);
|
||
|
|
||
|
if((*theAction).isModeChange())
|
||
|
{ // change mode
|
||
|
theChangeMode->setChecked(true);
|
||
|
if((*theAction).object().isEmpty())
|
||
|
theModes->setCurrentText(i18n("[Exit current mode]"));
|
||
|
else
|
||
|
theModes->setCurrentText((*theAction).object());
|
||
|
}
|
||
|
else if((*theAction).isJustStart())
|
||
|
{ // profile action
|
||
|
theUseProfile->setChecked(true);
|
||
|
const Profile *p = ProfileServer::profileServer()->profiles()[(*theAction).program()];
|
||
|
theApplications->setCurrentText(p->name());
|
||
|
updateFunctions();
|
||
|
updateArguments();
|
||
|
theJustStart->setChecked(true);
|
||
|
}
|
||
|
else if(ProfileServer::profileServer()->getAction((*theAction).program(), (*theAction).object(), (*theAction).method().prototype()))
|
||
|
{ // profile action
|
||
|
theUseProfile->setChecked(true);
|
||
|
const ProfileAction *a = ProfileServer::profileServer()->getAction((*theAction).program(), (*theAction).object(), (*theAction).method().prototype());
|
||
|
theApplications->setCurrentText(a->profile()->name());
|
||
|
updateFunctions();
|
||
|
theFunctions->setCurrentText(a->name());
|
||
|
arguments = (*theAction).arguments();
|
||
|
updateArguments();
|
||
|
theNotJustStart->setChecked(true);
|
||
|
}
|
||
|
else
|
||
|
{ // dcop action
|
||
|
theUseDCOP->setChecked(true);
|
||
|
theDCOPApplications->setCurrentText((*theAction).program());
|
||
|
updateDCOPObjects();
|
||
|
theDCOPObjects->setCurrentText((*theAction).object());
|
||
|
updateDCOPFunctions();
|
||
|
theDCOPFunctions->setCurrentText((*theAction).method().prototype());
|
||
|
arguments = (*theAction).arguments();
|
||
|
updateArguments();
|
||
|
}
|
||
|
updateOptions();
|
||
|
}
|
||
|
|
||
|
void EditAction::writeBack()
|
||
|
{
|
||
|
if(theChangeMode->isChecked())
|
||
|
{
|
||
|
(*theAction).setProgram("");
|
||
|
if(theModes->currentText() == i18n("[Exit current mode]"))
|
||
|
(*theAction).setObject("");
|
||
|
else
|
||
|
(*theAction).setObject(theModes->currentText());
|
||
|
(*theAction).setDoBefore(theDoBefore->isChecked());
|
||
|
(*theAction).setDoAfter(theDoAfter->isChecked());
|
||
|
}
|
||
|
else if(theUseProfile->isChecked() && (
|
||
|
ProfileServer::profileServer()->getAction(applicationMap[theApplications->currentText()], functionMap[theFunctions->currentText()])
|
||
|
||
|
||
|
theJustStart->isChecked() && ProfileServer::profileServer()->profiles()[theApplications->currentText()]
|
||
|
)
|
||
|
)
|
||
|
{ if(theJustStart->isChecked())
|
||
|
{ (*theAction).setProgram(ProfileServer::profileServer()->profiles()[applicationMap[theApplications->currentText()]]->id());
|
||
|
(*theAction).setObject("");
|
||
|
}
|
||
|
else
|
||
|
{ const ProfileAction *a = ProfileServer::profileServer()->getAction(applicationMap[theApplications->currentText()], functionMap[theFunctions->currentText()]);
|
||
|
(*theAction).setProgram(ProfileServer::profileServer()->profiles()[applicationMap[theApplications->currentText()]]->id());
|
||
|
(*theAction).setObject(a->objId());
|
||
|
(*theAction).setMethod(a->prototype());
|
||
|
(*theAction).setArguments(arguments);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
(*theAction).setProgram(program);//theDCOPApplications->currentText());
|
||
|
(*theAction).setObject(theDCOPObjects->currentText());
|
||
|
(*theAction).setMethod(theDCOPFunctions->currentText());
|
||
|
(*theAction).setArguments(arguments);
|
||
|
}
|
||
|
(*theAction).setRepeat(theRepeat->isChecked());
|
||
|
(*theAction).setAutoStart(theAutoStart->isChecked());
|
||
|
(*theAction).setUnique(isUnique);
|
||
|
(*theAction).setIfMulti(theDontSend->isChecked() ? IM_DONTSEND : theSendToTop->isChecked() ? IM_SENDTOTOP : theSendToBottom->isChecked() ? IM_SENDTOBOTTOM : IM_SENDTOALL);
|
||
|
}
|
||
|
|
||
|
void EditAction::updateArguments()
|
||
|
{
|
||
|
kdDebug() << k_funcinfo << endl;
|
||
|
if(theUseProfile->isChecked())
|
||
|
{
|
||
|
theArguments->clear();
|
||
|
const ProfileAction *a = ProfileServer::profileServer()->getAction(applicationMap[theApplications->currentText()], functionMap[theFunctions->currentText()]);
|
||
|
if(!a) { arguments.clear(); return; }
|
||
14 years ago
|
const TQValueList<ProfileActionArgument> &p = a->arguments();
|
||
15 years ago
|
if(p.count() != arguments.count())
|
||
|
{ arguments.clear();
|
||
|
for(unsigned i = 0; i < p.count(); i++)
|
||
14 years ago
|
arguments.append(TQVariant(""));
|
||
15 years ago
|
}
|
||
|
theArguments->setEnabled(p.count());
|
||
|
for(unsigned i = 0; i < p.count(); i++)
|
||
|
{ theArguments->insertItem(p[i].comment() + " (" + p[i].type() + ")");
|
||
14 years ago
|
arguments[i].cast(TQVariant::nameToType(p[i].type().utf8()));
|
||
15 years ago
|
}
|
||
|
if(p.count()) updateArgument(0); else updateArgument(-1);
|
||
|
}
|
||
|
else if(theUseDCOP->isChecked())
|
||
|
{
|
||
|
theArguments->clear();
|
||
|
Prototype p(theDCOPFunctions->currentText());
|
||
|
if(p.count() != arguments.count())
|
||
|
{ arguments.clear();
|
||
|
for(unsigned i = 0; i < p.count(); i++)
|
||
14 years ago
|
arguments.append(TQVariant(""));
|
||
15 years ago
|
}
|
||
|
theArguments->setEnabled(p.count());
|
||
|
for(unsigned i = 0; i < p.count(); i++)
|
||
14 years ago
|
{ theArguments->insertItem(TQString(TQString().setNum(i + 1) + ": " + (p.name(i).isEmpty() ? p.type(i) : p.name(i) + " (" + p.type(i) + ")")));
|
||
14 years ago
|
arguments[i].cast(TQVariant::nameToType(p.type(i).utf8()));
|
||
15 years ago
|
}
|
||
|
if(p.count()) updateArgument(0); else updateArgument(-1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void EditAction::updateOptions()
|
||
|
{
|
||
|
if (theUseProfile->isChecked())
|
||
|
{
|
||
|
ProfileServer *theServer = ProfileServer::profileServer();
|
||
|
if(!theApplications->currentItem()) return;
|
||
|
const Profile *p = theServer->profiles()[applicationMap[theApplications->currentText()]];
|
||
|
isUnique = p->unique();
|
||
|
}
|
||
|
else if (theUseDCOP->isChecked())
|
||
|
{
|
||
|
if(theDCOPApplications->currentText().isNull() || theDCOPApplications->currentText().isEmpty()) return;
|
||
|
program = theDCOPApplications->currentText();
|
||
|
isUnique = uniqueProgramMap[theDCOPApplications->currentText()];
|
||
|
}
|
||
|
else
|
||
|
isUnique = true;
|
||
|
|
||
|
theIMLabel->setEnabled(!isUnique);
|
||
|
theIMGroup->setEnabled(!isUnique);
|
||
|
theDontSend->setEnabled(!isUnique);
|
||
|
theSendToTop->setEnabled(!isUnique);
|
||
|
theSendToBottom->setEnabled(!isUnique);
|
||
|
theSendToAll->setEnabled(!isUnique);
|
||
|
}
|
||
|
|
||
|
// called when the textbox/checkbox/whatever changes value
|
||
|
void EditAction::slotParameterChanged()
|
||
|
{
|
||
|
kdDebug() << "in: " << arguments[theArguments->currentItem()].toString() << endl;
|
||
|
int type = arguments[theArguments->currentItem()].type();
|
||
|
kdDebug() << type << endl;
|
||
|
switch(type)
|
||
|
{
|
||
14 years ago
|
case TQVariant::Int: case TQVariant::UInt:
|
||
15 years ago
|
arguments[theArguments->currentItem()].asInt() = theValueIntNumInput->value();
|
||
|
break;
|
||
14 years ago
|
case TQVariant::Double:
|
||
15 years ago
|
arguments[theArguments->currentItem()].asDouble() = theValueDoubleNumInput->value();
|
||
|
break;
|
||
14 years ago
|
case TQVariant::Bool:
|
||
15 years ago
|
arguments[theArguments->currentItem()].asBool() = theValueCheckBox->isChecked();
|
||
|
break;
|
||
14 years ago
|
case TQVariant::StringList:
|
||
15 years ago
|
arguments[theArguments->currentItem()].asStringList() = theValueEditListBox->items();
|
||
|
break;
|
||
|
default:
|
||
|
arguments[theArguments->currentItem()].asString() = theValueLineEdit->text();
|
||
|
}
|
||
14 years ago
|
arguments[theArguments->currentItem()].cast(TQVariant::Type(type));
|
||
15 years ago
|
kdDebug() << "out: " << arguments[theArguments->currentItem()].toString() << endl;
|
||
|
|
||
|
}
|
||
|
|
||
|
void EditAction::updateArgument(int index)
|
||
|
{
|
||
|
kdDebug() << k_funcinfo << " i: " << index << endl;
|
||
|
if(index >= 0)
|
||
|
{ switch(arguments[index].type())
|
||
|
{
|
||
14 years ago
|
case TQVariant::Int: case TQVariant::UInt:
|
||
15 years ago
|
theValue->raiseWidget(2);
|
||
|
theValueIntNumInput->setValue(arguments[index].toInt());
|
||
|
break;
|
||
14 years ago
|
case TQVariant::Double:
|
||
15 years ago
|
theValue->raiseWidget(3);
|
||
|
theValueDoubleNumInput->setValue(arguments[index].toDouble());
|
||
|
break;
|
||
14 years ago
|
case TQVariant::Bool:
|
||
15 years ago
|
theValue->raiseWidget(1);
|
||
|
theValueCheckBox->setChecked(arguments[index].toBool());
|
||
|
break;
|
||
14 years ago
|
case TQVariant::StringList:
|
||
15 years ago
|
{ theValue->raiseWidget(4);
|
||
14 years ago
|
TQStringList backup = arguments[index].toStringList();
|
||
15 years ago
|
// backup needed because calling clear will kill what ever has been saved.
|
||
|
theValueEditListBox->clear();
|
||
|
theValueEditListBox->insertStringList(backup);
|
||
|
arguments[index].asStringList() = backup;
|
||
|
break;
|
||
|
}
|
||
|
default:
|
||
|
theValue->raiseWidget(0);
|
||
|
theValueLineEdit->setText(arguments[index].toString());
|
||
|
}
|
||
|
theValue->setEnabled(true);
|
||
|
}
|
||
|
else
|
||
|
{ theValueLineEdit->setText("");
|
||
|
theValueCheckBox->setChecked(false);
|
||
|
theValueIntNumInput->setValue(0);
|
||
|
theValueDoubleNumInput->setValue(0.0);
|
||
|
theValue->setEnabled(false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void EditAction::updateApplications()
|
||
|
{
|
||
|
ProfileServer *theServer = ProfileServer::profileServer();
|
||
|
theApplications->clear();
|
||
|
applicationMap.clear();
|
||
|
|
||
14 years ago
|
TQDict<Profile> dict = theServer->profiles();
|
||
|
TQDictIterator<Profile> i(dict);
|
||
15 years ago
|
for(; i.current(); ++i)
|
||
|
{ theApplications->insertItem(i.current()->name());
|
||
|
applicationMap[i.current()->name()] = i.currentKey();
|
||
|
}
|
||
|
updateFunctions();
|
||
|
}
|
||
|
|
||
|
void EditAction::updateFunctions()
|
||
|
{
|
||
|
ProfileServer *theServer = ProfileServer::profileServer();
|
||
|
theFunctions->clear();
|
||
|
functionMap.clear();
|
||
|
if(theApplications->currentText().isNull() || theApplications->currentText().isEmpty()) return;
|
||
|
|
||
|
const Profile *p = theServer->profiles()[applicationMap[theApplications->currentText()]];
|
||
|
|
||
14 years ago
|
TQDict<ProfileAction> dict = p->actions();
|
||
|
for(TQDictIterator<ProfileAction> i(dict); i.current(); ++i)
|
||
15 years ago
|
{ theFunctions->insertItem(i.current()->name());
|
||
|
functionMap[i.current()->name()] = i.currentKey();
|
||
|
}
|
||
|
updateArguments();
|
||
|
}
|
||
|
|
||
|
void EditAction::updateDCOPApplications()
|
||
|
{
|
||
14 years ago
|
TQStringList names;
|
||
15 years ago
|
|
||
|
theDCOPApplications->clear();
|
||
12 years ago
|
DCOPClient *theClient = TDEApplication::kApplication()->dcopClient();
|
||
15 years ago
|
QCStringList theApps = theClient->registeredApplications();
|
||
|
for(QCStringList::iterator i = theApps.begin(); i != theApps.end(); ++i)
|
||
|
{
|
||
13 years ago
|
if(!TQString(*i).find("anonymous")) continue;
|
||
14 years ago
|
TQRegExp r("(.*)-[0-9]+");
|
||
|
TQString name = r.exactMatch(TQString(*i)) ? r.cap(1) : *i;
|
||
13 years ago
|
if(names.contains(name)) continue;
|
||
15 years ago
|
names += name;
|
||
|
|
||
|
theDCOPApplications->insertItem(name);
|
||
14 years ago
|
uniqueProgramMap[name] = name == TQString(*i);
|
||
15 years ago
|
nameProgramMap[name] = *i;
|
||
|
|
||
|
|
||
|
}
|
||
|
updateDCOPObjects();
|
||
|
}
|
||
|
|
||
|
void EditAction::updateDCOPObjects()
|
||
|
{
|
||
|
theDCOPObjects->clear();
|
||
12 years ago
|
DCOPClient *theClient = TDEApplication::kApplication()->dcopClient();
|
||
15 years ago
|
if(theDCOPApplications->currentText().isNull() || theDCOPApplications->currentText().isEmpty()) return;
|
||
|
QCStringList theObjects = theClient->remoteObjects(nameProgramMap[theDCOPApplications->currentText()].utf8());
|
||
|
if(!theObjects.size() && theDCOPApplications->currentText() == (*theAction).program()) theDCOPObjects->insertItem((*theAction).object());
|
||
|
for(QCStringList::iterator j = theObjects.begin(); j != theObjects.end(); ++j)
|
||
12 years ago
|
if(*j != "tdesycoca" && *j != "qt" && AddAction::getFunctions(nameProgramMap[theDCOPApplications->currentText()], *j).count())
|
||
14 years ago
|
theDCOPObjects->insertItem(TQString::fromUtf8(*j));
|
||
15 years ago
|
updateDCOPFunctions();
|
||
|
}
|
||
|
|
||
|
void EditAction::updateDCOPFunctions()
|
||
|
{
|
||
|
theDCOPFunctions->clear();
|
||
|
if(theDCOPApplications->currentText().isNull() || theDCOPApplications->currentText().isEmpty()) return;
|
||
14 years ago
|
TQStringList functions = AddAction::getFunctions(nameProgramMap[theDCOPApplications->currentText()], theDCOPObjects->currentText());
|
||
15 years ago
|
if(!functions.size() && theDCOPApplications->currentText() == (*theAction).program()) theDCOPFunctions->insertItem((*theAction).method().prototype());
|
||
14 years ago
|
for(TQStringList::iterator i = functions.begin(); i != functions.end(); ++i)
|
||
15 years ago
|
theDCOPFunctions->insertItem(*i);
|
||
|
updateArguments();
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "editaction.moc"
|