summaryrefslogtreecommitdiffstats
path: root/quanta/dialogs/tagdialogs/tagattr.cpp
blob: f093ba712332657c5265f59e1d443aeb1c74b675 (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
/***************************************************************************
                          tagxml.cpp  -  description
                             -------------------
    begin                : ����25 14:34:07 EEST 2000
    copyright            : (C) 2000 by Dmitry Poplavsky & Alexander Yakovlev <pdima@users.sourceforge.net,yshurik@linuxfan.com>
                           (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
#include <dcopref.h>
#include <tdeapplication.h>
#include <kdebug.h>
#include <klineedit.h>

//qt includes
#include <tqdom.h>
#include <tqtextstream.h>

//app includes
#include "tagattr.h"
#include "node.h"
#include "colorcombo.h"
#include "qtag.h"
#include "quantacommon.h"

TQString Attr::attrName() const
{
  return name;
}


Attr_list::Attr_list( TQDomElement const& el, TQWidget *w, TQTag *dtdTag )
  : Attr(el, w, dtdTag)
{
   combo = (TQComboBox *)w;

   TQString source = el.attribute("source");
   if (source == "dcop") //fill the list with a result of a DCOP call
   {
     TQString method = el.attribute("method");
     TQString interface = el.attribute("interface", "QuantaIf");
     TQString arguments = el.attribute("arguments");
     arguments.replace("%tagname%", m_dtdTag->name());
     DCOPReply reply = QuantaCommon::callDCOPMethod(interface, method, arguments);
     if (reply.isValid())
     {
        TQStringList list = reply;
        combo->insertStringList(list);
     }
   }

   for ( TQDomElement n = el.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
      if ( n.tagName() == "items" ) {
         TQDomElement item = n.firstChild().toElement();
         while ( !item.isNull() ) {
             combo->insertItem( item.text() );
             item = item.nextSibling().toElement();
         }
      }
   }

   setValue("");
}

void Attr_list::setValue(const TQString &value)
{

  for ( int i=0; i<combo->count(); i++ )
    if ( value == combo->text(i) ) {
      combo->setCurrentItem(i);
      return;
    }

  combo->insertItem(value);
  combo->setCurrentItem( combo->count() - 1 );

}


TQDomNode findChild( TQDomNode &parent, const TQString &name )
{
  for ( TQDomNode n = parent.firstChild(); !n.isNull(); n = n.nextSibling() )
    if ( n.nodeName() == name )
         return n;
  return TQDomNode();
}