summaryrefslogtreecommitdiffstats
path: root/kio/tests/kdcopcheck.cpp
blob: b61dfd03dc738011cce23eb7d1fccd5d59fe18f4 (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
#include <kuserprofile.h>
#include <ktrader.h>
#include <kservice.h>
#include <kmimetype.h>
#include <assert.h>
#include <kstandarddirs.h>
#include <kservicegroup.h>
#include <kimageio.h>
#include <kprotocolinfo.h>
#include <kprocess.h>
#include <tqtimer.h>

#include "kdcopcheck.h"
#include <dcopclient.h>

#include <kapplication.h>

#include <stdio.h>
#include <stdlib.h>

void debug(TQString txt)
{
 fprintf(stderr, "%s\n", txt.ascii());
}

void debug(const char *txt)
{
 fprintf(stderr, "%s\n", txt);
}
void debug(const char *format, const char *txt)
{
 fprintf(stderr, format, txt);
 fprintf(stderr, "\n");
}

TestService::TestService(const TQString &exec)
{
   m_exec = exec;
   proc << exec;

   proc.start();

   connect(kapp->dcopClient(), TQT_SIGNAL( applicationRegistered(const TQCString&)),
           this, TQT_SLOT(newApp(const TQCString&)));
   connect(kapp->dcopClient(), TQT_SIGNAL( applicationRemoved(const TQCString&)),
           this, TQT_SLOT(endApp(const TQCString&)));
   connect(&proc, TQT_SIGNAL(processExited(KProcess *)),
           this, TQT_SLOT(appExit()));

   TQTimer::singleShot(20*1000, this, TQT_SLOT(stop()));
   result = KService::DCOP_None;
}

void TestService::newApp(const TQCString &appId)
{
   TQString id = appId;
   if (id == m_exec)
   {
      result = KService::DCOP_Unique;
      stop();
   }
   else if (id.startsWith(m_exec))
   {
      result = KService::DCOP_Multi;
      stop();
   }
   qWarning("Register %s", appId.data());
}

void TestService::endApp(const TQCString &appId)
{
   qWarning("Unegister %s", appId.data());
}

void TestService::appExit()
{
   qWarning("Exit");
}

void TestService::stop()
{
   kapp->exit_loop();
}

int TestService::exec()
{
   kapp->enter_loop();
   return result;
}

int main(int argc, char *argv[])
{
   putenv("IGNORE_SYCOCA_VERSION=true");
   KApplication k(argc,argv,"whatever",false/*noGUI*/); // KMessageBox needs KApp for makeStdCaption

   k.dcopClient()->setNotifications(true);

   KService::List list = KService::allServices();

   qWarning("I found %d services.", list.count());
   int i = 0;
   for(KService::List::ConstIterator it = list.begin(); it != list.end(); ++it)
   {
      if (((*it)->DCOPServiceType() == KService::DCOP_None) &&
          !(*it)->desktopEntryPath().startsWith("SuSE") &&
           (*it)->hasServiceType("Application"))
      {
         if ((*it)->exec().startsWith((*it)->desktopEntryName()))
         {
            i++;

            TestService *test = new TestService((*it)->desktopEntryName());
            int n = test->exec();
            delete test;

            TQString result;
            if (n == KService::DCOP_None)
               result = "None";
            else if (n == KService::DCOP_Unique)
               result = "Unique";
            else if (n == KService::DCOP_Multi)
               result = "Multi";
           
            qWarning("%s %s", (*it)->desktopEntryPath().latin1(),
                              result.latin1());
         }
      }
   }
   qWarning("%d left after filtering.", i);
}

#include "kdcopcheck.moc"