summaryrefslogtreecommitdiffstats
path: root/quanta/src/dcopquanta.cpp
blob: 8dde34bc76c069b4b968a68af04284bf75fa6483 (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
/***************************************************************************
                          dcopquanta.cpp  -  description
                             -------------------
    begin                : Thu Mar 4 2004
    copyright            : (C) 2004 Andras Mantia <amantia@kde.org>
 ***************************************************************************/

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

//kde includes

//qt includes
#include <tqregexp.h>

//app includes
#include "dcopquanta.h"
#include "node.h"

extern GroupElementMapList globalGroupMap;

DCOPQuanta::DCOPQuanta() : DCOPObject("QuantaIf")
{
}

TQStringList DCOPQuanta::selectors(const TQString& tag)
{
  const TQRegExp rx("\\.|\\#|\\:");
  TQStringList selectorList;
  GroupElementMapList::Iterator it;
  for ( it = globalGroupMap.begin(); it != globalGroupMap.end(); ++it )
  {
    TQString key = it.key();
    if (key.startsWith("Selectors|"))
    {
      TQString selectorName = key.mid(10);
      int index = selectorName.tqfind(':');
      if (index != -1)
        selectorName = selectorName.mid(0, index);
      TQString tmpStr;
      index = selectorName.tqfind(rx);
      if (index != -1)
      {
        tmpStr = selectorName.left(index).lower();
      } else
      {
        tmpStr = selectorName;
      }
      if (tmpStr.isEmpty() || tag.lower() == tmpStr || tmpStr == "*")
      {
        tmpStr = selectorName.mid(index + 1).tqreplace('.',' ');
        if (!tmpStr.isEmpty() && !selectorList.tqcontains(tmpStr))
          selectorList << tmpStr;
      }
     }
  }
  return selectorList;
}

TQStringList DCOPQuanta::idSelectors()
{
  TQStringList selectorList;
  GroupElementMapList::Iterator it;
  for ( it = globalGroupMap.begin(); it != globalGroupMap.end(); ++it )
  {
    TQString key = it.key();
    if (key.startsWith("Selectors|"))
    {
      TQString selectorName = key.mid(10);
      TQString tmpStr;
      if (selectorName.startsWith("#"))
      {
          selectorList << selectorName.mid(1);
      }
     }
  }
  return selectorList;
}

TQStringList DCOPQuanta::groupElements(const TQString& group)
{
  TQStringList elementList;
  GroupElementMapList::Iterator it;
  for ( it = globalGroupMap.begin(); it != globalGroupMap.end(); ++it )
  {
    TQString key = it.key();
    if (key.startsWith(group + "|"))
    {
      TQString name = key.mid(10);
      int index = name.tqfind(':');
      if (index != -1)
        name = name.mid(0, index);
      TQString tmpStr;
      index = name.tqfind("|");
      if (index != -1)
      {
        tmpStr = name.left(index).lower();
      } else
      {
        tmpStr = name;
      }
    
      elementList << tmpStr;
     }
  }
  return elementList;
}