TDE core libraries
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.

kmcop.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. Copyright (c) 2001 Nikolas Zimmermann <wildfox@kde.org>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. */
  15. #include <kdebug.h>
  16. #include <kuniqueapplication.h>
  17. #include <tdeaboutdata.h>
  18. #include <tdecmdlineargs.h>
  19. #include <tdelocale.h>
  20. #include <dcopclient.h>
  21. #include <tqvaluelist.h>
  22. #include <tqcstring.h>
  23. #include <kartsdispatcher.h>
  24. #include <soundserver.h>
  25. #include <dispatcher.h>
  26. #include <object.h>
  27. #include <core.h>
  28. #include "mcopdcopobject.h"
  29. #include "kmcop.moc"
  30. using namespace Arts;
  31. using namespace std;
  32. class KMCOPPrivate
  33. {
  34. public:
  35. MCOPInfo mcopInfo;
  36. TQPtrList<MCOPDCOPObject> list;
  37. };
  38. int main(int argc, char **argv)
  39. {
  40. TDEAboutData aboutdata("kmcop", I18N_NOOP("KMCOP"),
  41. "0.1", I18N_NOOP("TDE MCOP-DCOP Bridge"),
  42. TDEAboutData::License_GPL, "(C) 2001, Nikolas Zimmermann");
  43. aboutdata.addAuthor("Nikolas Zimmermann", I18N_NOOP("Author"), "wildfox@kde.org");
  44. TDECmdLineArgs::init(argc, argv, &aboutdata);
  45. KUniqueApplication::addCmdLineOptions();
  46. if(!KUniqueApplication::start())
  47. {
  48. kdDebug() << "Running kmcop found" << endl;
  49. return 0;
  50. }
  51. KUniqueApplication app;
  52. app.disableSessionManagement();
  53. KArtsDispatcher dispatcher;
  54. KMCOP notify;
  55. app.dcopClient()->setDefaultObject("arts");
  56. app.dcopClient()->setDaemonMode(true);
  57. return app.exec();
  58. }
  59. KMCOP::KMCOP() : TQObject(), DCOPObject("arts")
  60. {
  61. d = new KMCOPPrivate();
  62. d->mcopInfo = Reference("global:Arts_MCOPInfo");
  63. d->list.setAutoDelete(true);
  64. }
  65. KMCOP::~KMCOP()
  66. {
  67. delete d;
  68. }
  69. int KMCOP::objectCount()
  70. {
  71. return d->mcopInfo.objectCount();
  72. }
  73. TQCString KMCOP::correctType(const TQCString &str)
  74. {
  75. if(str == "string")
  76. return "TQCString";
  77. return str;
  78. }
  79. void KMCOP::addInterfacesHackHackHack()
  80. {
  81. for(int i = 0; i <= objectCount(); i++)
  82. {
  83. Arts::Object obj = d->mcopInfo.objectForNumber(i);
  84. if(!obj.isNull())
  85. {
  86. TQCString interfaceName = obj._interfaceName().c_str();
  87. if(interfaceName != "Arts::TraderOffer")
  88. {
  89. Arts::InterfaceRepo ifaceRepo = Dispatcher::the()->interfaceRepo();
  90. MCOPDCOPObject *interface = new MCOPDCOPObject(interfaceName);
  91. d->list.append(interface);
  92. InterfaceDef ifaceDef = ifaceRepo.queryInterface(string(interfaceName));
  93. vector<MethodDef> ifaceMethods = ifaceDef.methods;
  94. vector<MethodDef>::iterator ifaceMethodsIterator;
  95. for(ifaceMethodsIterator = ifaceMethods.begin(); ifaceMethodsIterator != ifaceMethods.end(); ifaceMethodsIterator++)
  96. {
  97. TQCString function, signature;
  98. MCOPEntryInfo *entry = new MCOPEntryInfo();
  99. MethodDef currentMethod = *ifaceMethodsIterator;
  100. vector<ParamDef> currentParameters = currentMethod.signature;
  101. TQCString newType = correctType(TQCString(currentMethod.type.c_str()));
  102. entry->setFunctionType(newType);
  103. entry->setFunctionName(TQCString(currentMethod.name.c_str()));
  104. function = entry->functionType() + TQCString(" ") + entry->functionName() + TQCString("(");
  105. signature = TQCString("(");
  106. QCStringList signatureList;
  107. vector<ParamDef>::iterator methodParametersIterator;
  108. for(methodParametersIterator = currentParameters.begin(); methodParametersIterator != currentParameters.end(); methodParametersIterator++)
  109. {
  110. ParamDef parameter = *methodParametersIterator;
  111. if(methodParametersIterator != currentParameters.begin())
  112. {
  113. function += TQCString(", ");
  114. signature += TQCString(",");
  115. }
  116. TQCString correctParameter = correctType(TQCString(parameter.type.c_str()));
  117. function += correctParameter;
  118. signature += correctParameter;
  119. signatureList.append(TQCString(parameter.type.c_str()));
  120. }
  121. function += TQCString(")");
  122. signature += TQCString(")");
  123. entry->setSignature(signature);
  124. entry->setSignatureList(signatureList);
  125. interface->addDynamicFunction(function, entry);
  126. }
  127. }
  128. }
  129. }
  130. }