• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kedittoolbar.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Kurt Granroth <granroth@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 #include <kedittoolbar.h>
19 
20 #include <tqdom.h>
21 #include <tqlayout.h>
22 #include <tqdir.h>
23 #include <tqfile.h>
24 #include <tqheader.h>
25 #include <tqcombobox.h>
26 #include <tqdragobject.h>
27 #include <tqtoolbutton.h>
28 #include <tqlabel.h>
29 #include <tqvaluelist.h>
30 #include <tqapplication.h>
31 #include <tqtextstream.h>
32 
33 #include <tdeaction.h>
34 #include <kstandarddirs.h>
35 #include <tdelocale.h>
36 #include <kicontheme.h>
37 #include <kiconloader.h>
38 #include <kinstance.h>
39 #include <tdemessagebox.h>
40 #include <kxmlguifactory.h>
41 #include <kseparator.h>
42 #include <tdeconfig.h>
43 #include <tdelistview.h>
44 #include <kdebug.h>
45 #include <kpushbutton.h>
46 #include <kprocio.h>
47 
48 static const char * const lineseparatorstring = I18N_NOOP("--- line separator ---");
49 static const char * const separatorstring = I18N_NOOP("--- separator ---");
50 
51 #define LINESEPARATORSTRING i18n(lineseparatorstring)
52 #define SEPARATORSTRING i18n(separatorstring)
53 
54 static void dump_xml(const TQDomDocument& doc)
55 {
56  TQString str;
57  TQTextStream ts(&str, IO_WriteOnly);
58  ts << doc;
59  kdDebug() << str << endl;
60 }
61 
62 typedef TQValueList<TQDomElement> ToolbarList;
63 
64 namespace KEditToolbarInternal
65 {
66 class XmlData
67 {
68 public:
69  enum XmlType { Shell = 0, Part, Local, Merged };
70  XmlData()
71  {
72  m_isModified = false;
73  m_actionCollection = 0;
74  }
75 
76  TQString m_xmlFile;
77  TQDomDocument m_document;
78  XmlType m_type;
79  bool m_isModified;
80  TDEActionCollection* m_actionCollection;
81 
82  ToolbarList m_barList;
83 };
84 
85 typedef TQValueList<XmlData> XmlDataList;
86 
87 class ToolbarItem : public TQListViewItem
88 {
89 public:
90  ToolbarItem(TDEListView *parent, const TQString& tag = TQString::null, const TQString& name = TQString::null, const TQString& statusText = TQString::null)
91  : TQListViewItem(parent),
92  m_tag(tag),
93  m_name(name),
94  m_statusText(statusText)
95  {
96  }
97 
98  ToolbarItem(TDEListView *parent, TQListViewItem *item, const TQString &tag = TQString::null, const TQString& name = TQString::null, const TQString& statusText = TQString::null)
99  : TQListViewItem(parent, item),
100  m_tag(tag),
101  m_name(name),
102  m_statusText(statusText)
103  {
104  }
105 
106  virtual TQString key(int column, bool) const
107  {
108  TQString s = text( column );
109  if ( s == LINESEPARATORSTRING )
110  return "0";
111  if ( s == SEPARATORSTRING )
112  return "1";
113  return "2" + s;
114  }
115 
116  void setInternalTag(const TQString &tag) { m_tag = tag; }
117  void setInternalName(const TQString &name) { m_name = name; }
118  void setStatusText(const TQString &text) { m_statusText = text; }
119  TQString internalTag() const { return m_tag; }
120  TQString internalName() const { return m_name; }
121  TQString statusText() const { return m_statusText; }
122 private:
123  TQString m_tag;
124  TQString m_name;
125  TQString m_statusText;
126 };
127 
128 #define TOOLBARITEMMIMETYPE "data/x-kde.toolbar.item"
129 class ToolbarItemDrag : public TQStoredDrag
130 {
131 public:
132  ToolbarItemDrag(ToolbarItem *toolbarItem,
133  TQWidget *dragSource = 0, const char *name = 0)
134  : TQStoredDrag( TOOLBARITEMMIMETYPE, dragSource, name )
135  {
136  if (toolbarItem) {
137  TQByteArray data;
138  TQDataStream out(data, IO_WriteOnly);
139  out << toolbarItem->internalTag();
140  out << toolbarItem->internalName();
141  out << toolbarItem->statusText();
142  out << toolbarItem->text(1); // separators need this.
143  setEncodedData(data);
144  }
145  }
146 
147  static bool canDecode(TQMimeSource* e)
148  {
149  return e->provides(TOOLBARITEMMIMETYPE);
150  }
151 
152  static bool decode( const TQMimeSource* e, KEditToolbarInternal::ToolbarItem& item )
153  {
154  if (!e)
155  return false;
156 
157  TQByteArray data = e->encodedData(TOOLBARITEMMIMETYPE);
158  if ( data.isEmpty() )
159  return false;
160 
161  TQString internalTag, internalName, statusText, text;
162  TQDataStream in(data, IO_ReadOnly);
163  in >> internalTag;
164  in >> internalName;
165  in >> statusText;
166  in >> text;
167 
168  item.setInternalTag( internalTag );
169  item.setInternalName( internalName );
170  item.setStatusText( statusText );
171  item.setText(1, text);
172 
173  return true;
174  }
175 };
176 
177 class ToolbarListView : public TDEListView
178 {
179 public:
180  ToolbarListView(TQWidget *parent=0, const char *name=0)
181  : TDEListView(parent, name)
182  {
183  }
184 protected:
185  virtual TQDragObject *dragObject()
186  {
187  KEditToolbarInternal::ToolbarItem *item = dynamic_cast<KEditToolbarInternal::ToolbarItem*>(selectedItem());
188  if ( item ) {
189  KEditToolbarInternal::ToolbarItemDrag *obj = new KEditToolbarInternal::ToolbarItemDrag(item,
190  this, "ToolbarAction drag item");
191  const TQPixmap *pm = item->pixmap(0);
192  if( pm )
193  obj->setPixmap( *pm );
194  return obj;
195  }
196  return 0;
197  }
198 
199  virtual bool acceptDrag(TQDropEvent *event) const
200  {
201  return KEditToolbarInternal::ToolbarItemDrag::canDecode( event );
202  }
203 };
204 } // namespace
205 
206 class KEditToolbarWidgetPrivate
207 {
208 public:
216  KEditToolbarWidgetPrivate(TDEInstance *instance, TDEActionCollection* collection)
217  : m_collection( collection )
218  {
219  m_instance = instance;
220  m_isPart = false;
221  m_helpArea = 0L;
222  m_kdialogProcess = 0;
223  }
224  ~KEditToolbarWidgetPrivate()
225  {
226  }
227 
228  TQString xmlFile(const TQString& xml_file)
229  {
230  return xml_file.isNull() ? TQString(m_instance->instanceName()) + "ui.rc" :
231  xml_file;
232  }
233 
237  TQString loadXMLFile(const TQString& _xml_file)
238  {
239  TQString raw_xml;
240  TQString xml_file = xmlFile(_xml_file);
241  //kdDebug() << "loadXMLFile xml_file=" << xml_file << endl;
242 
243  if ( !TQDir::isRelativePath(xml_file) )
244  raw_xml = KXMLGUIFactory::readConfigFile(xml_file);
245  else
246  raw_xml = KXMLGUIFactory::readConfigFile(xml_file, m_instance);
247 
248  return raw_xml;
249  }
250 
254  ToolbarList findToolbars(TQDomNode n)
255  {
256  static const TQString &tagToolbar = TDEGlobal::staticQString( "ToolBar" );
257  static const TQString &attrNoEdit = TDEGlobal::staticQString( "noEdit" );
258  ToolbarList list;
259 
260  for( ; !n.isNull(); n = n.nextSibling() )
261  {
262  TQDomElement elem = n.toElement();
263  if (elem.isNull())
264  continue;
265 
266  if (elem.tagName() == tagToolbar && elem.attribute( attrNoEdit ) != "true" )
267  list.append(elem);
268 
269  list += findToolbars(elem.firstChild());
270  }
271 
272  return list;
273  }
274 
278  TQString toolbarName( const KEditToolbarInternal::XmlData& xmlData, const TQDomElement& it ) const
279  {
280  static const TQString &tagText = TDEGlobal::staticQString( "text" );
281  static const TQString &tagText2 = TDEGlobal::staticQString( "Text" );
282  static const TQString &attrName = TDEGlobal::staticQString( "name" );
283 
284  TQString name;
285  TQCString txt( it.namedItem( tagText ).toElement().text().utf8() );
286  if ( txt.isEmpty() )
287  txt = it.namedItem( tagText2 ).toElement().text().utf8();
288  if ( txt.isEmpty() )
289  name = it.attribute( attrName );
290  else
291  name = i18n( txt );
292 
293  // the name of the toolbar might depend on whether or not
294  // it is in tdeparts
295  if ( ( xmlData.m_type == KEditToolbarInternal::XmlData::Shell ) ||
296  ( xmlData.m_type == KEditToolbarInternal::XmlData::Part ) )
297  {
298  TQString doc_name(xmlData.m_document.documentElement().attribute( attrName ));
299  name += " <" + doc_name + ">";
300  }
301  return name;
302  }
306  TQDomElement findElementForToolbarItem( const KEditToolbarInternal::ToolbarItem* item ) const
307  {
308  static const TQString &attrName = TDEGlobal::staticQString( "name" );
309  for(TQDomNode n = m_currentToolbarElem.firstChild(); !n.isNull(); n = n.nextSibling())
310  {
311  TQDomElement elem = n.toElement();
312  if ((elem.attribute(attrName) == item->internalName()) &&
313  (elem.tagName() == item->internalTag()))
314  return elem;
315  }
316  return TQDomElement();
317  }
318 
319 #ifndef NDEBUG
320  void dump()
321  {
322  static const char* s_XmlTypeToString[] = { "Shell", "Part", "Local", "Merged" };
323  KEditToolbarInternal::XmlDataList::Iterator xit = m_xmlFiles.begin();
324  for ( ; xit != m_xmlFiles.end(); ++xit )
325  {
326  kdDebug(240) << "KEditToolbarInternal::XmlData type " << s_XmlTypeToString[(*xit).m_type] << " xmlFile: " << (*xit).m_xmlFile << endl;
327  for( TQValueList<TQDomElement>::Iterator it = (*xit).m_barList.begin();
328  it != (*xit).m_barList.end(); ++it ) {
329  kdDebug(240) << " Toolbar: " << toolbarName( *xit, *it ) << endl;
330  }
331  if ( (*xit).m_actionCollection )
332  kdDebug(240) << " " << (*xit).m_actionCollection->count() << " actions in the collection." << endl;
333  else
334  kdDebug(240) << " no action collection." << endl;
335  }
336  }
337 #endif
338 
339  //TQValueList<TDEAction*> m_actionList;
340  TDEActionCollection* m_collection;
341  TDEInstance *m_instance;
342 
343  KEditToolbarInternal::XmlData* m_currentXmlData;
344  TQDomElement m_currentToolbarElem;
345 
346  TQString m_xmlFile;
347  TQString m_globalFile;
348  TQString m_rcFile;
349  TQDomDocument m_localDoc;
350  bool m_isPart;
351 
352  ToolbarList m_barList;
353 
354  KEditToolbarInternal::XmlDataList m_xmlFiles;
355 
356  TQLabel *m_comboLabel;
357  KSeparator *m_comboSeparator;
358  TQLabel * m_helpArea;
359  KPushButton* m_changeIcon;
360  KProcIO* m_kdialogProcess;
361  bool m_hasKDialog;
362 };
363 
364 class KEditToolbarPrivate {
365 public:
366  bool m_accept;
367 
368  // Save parameters for recreating widget after resetting toolbar
369  bool m_global;
370  TDEActionCollection* m_collection;
371  TQString m_file;
372  KXMLGUIFactory* m_factory;
373 };
374 
375 const char *KEditToolbar::s_defaultToolbar = 0L;
376 
377 KEditToolbar::KEditToolbar(TDEActionCollection *collection, const TQString& file,
378  bool global, TQWidget* parent, const char* name)
379  : KDialogBase(Swallow, i18n("Configure Toolbars"), Default|Ok|Apply|Cancel, Ok, parent, name),
380  m_widget(new KEditToolbarWidget(TQString::fromLatin1(s_defaultToolbar), collection, file, global, this))
381 {
382  init();
383  d->m_global = global;
384  d->m_collection = collection;
385  d->m_file = file;
386 }
387 
388 KEditToolbar::KEditToolbar(const TQString& defaultToolbar, TDEActionCollection *collection,
389  const TQString& file, bool global,
390  TQWidget* parent, const char* name)
391  : KDialogBase(Swallow, i18n("Configure Toolbars"), Default|Ok|Apply|Cancel, Ok, parent, name),
392  m_widget(new KEditToolbarWidget(defaultToolbar, collection, file, global, this))
393 {
394  init();
395  d->m_global = global;
396  d->m_collection = collection;
397  d->m_file = file;
398 }
399 
400 KEditToolbar::KEditToolbar(KXMLGUIFactory* factory, TQWidget* parent, const char* name)
401  : KDialogBase(Swallow, i18n("Configure Toolbars"), Default|Ok|Apply|Cancel, Ok, parent, name),
402  m_widget(new KEditToolbarWidget(TQString::fromLatin1(s_defaultToolbar), factory, this))
403 {
404  init();
405  d->m_factory = factory;
406 }
407 
408 KEditToolbar::KEditToolbar(const TQString& defaultToolbar,KXMLGUIFactory* factory,
409  TQWidget* parent, const char* name)
410  : KDialogBase(Swallow, i18n("Configure Toolbars"), Default|Ok|Apply|Cancel, Ok, parent, name),
411  m_widget(new KEditToolbarWidget(defaultToolbar, factory, this))
412 {
413  init();
414  d->m_factory = factory;
415 }
416 
417 void KEditToolbar::init()
418 {
419  d = new KEditToolbarPrivate();
420  d->m_accept = false;
421  d->m_factory = 0;
422 
423  setMainWidget(m_widget);
424 
425  connect(m_widget, TQT_SIGNAL(enableOk(bool)), TQT_SLOT(acceptOK(bool)));
426  connect(m_widget, TQT_SIGNAL(enableOk(bool)), TQT_SLOT(enableButtonApply(bool)));
427  enableButtonApply(false);
428 
429  setMinimumSize(sizeHint());
430  s_defaultToolbar = 0L;
431 }
432 
433 KEditToolbar::~KEditToolbar()
434 {
435  delete d;
436 }
437 
438 void KEditToolbar::acceptOK(bool b)
439 {
440  enableButtonOK(b);
441  d->m_accept = b;
442 }
443 
444 void KEditToolbar::slotDefault()
445 {
446  if ( KMessageBox::warningContinueCancel(this, i18n("Do you really want to reset all toolbars of this application to their default? The changes will be applied immediately."), i18n("Reset Toolbars"),i18n("Reset"))!=KMessageBox::Continue )
447  return;
448 
449  delete m_widget;
450  d->m_accept = false;
451 
452  if ( d->m_factory )
453  {
454  const TQString localPrefix = locateLocal("data", "");
455  TQPtrList<KXMLGUIClient> clients(d->m_factory->clients());
456  TQPtrListIterator<KXMLGUIClient> it( clients );
457 
458  for( ; it.current(); ++it)
459  {
460  KXMLGUIClient *client = it.current();
461  TQString file = client->xmlFile();
462 
463  if (file.isNull())
464  continue;
465 
466  if (TQDir::isRelativePath(file))
467  {
468  const TDEInstance *instance = client->instance() ? client->instance() : TDEGlobal::instance();
469  file = locateLocal("data", TQString::fromLatin1( instance->instanceName() + '/' ) + file);
470  }
471  else
472  {
473  if (!file.startsWith(localPrefix))
474  continue;
475  }
476 
477  if ( TQFile::exists( file ) )
478  if ( !TQFile::remove( file ) )
479  kdWarning() << "Could not delete " << file << endl;
480  }
481 
482  m_widget = new KEditToolbarWidget(TQString::null, d->m_factory, this);
483  m_widget->rebuildKXMLGUIClients();
484  }
485  else
486  {
487  int slash = d->m_file.findRev('/')+1;
488  if (slash)
489  d->m_file = d->m_file.mid(slash);
490  TQString xml_file = locateLocal("data", TQString::fromLatin1( TDEGlobal::instance()->instanceName() + '/' ) + d->m_file);
491 
492  if ( TQFile::exists( xml_file ) )
493  if ( !TQFile::remove( xml_file ) )
494  kdWarning() << "Could not delete " << xml_file << endl;
495 
496  m_widget = new KEditToolbarWidget(TQString::null, d->m_collection, d->m_file, d->m_global, this);
497  }
498 
499  setMainWidget(m_widget);
500  m_widget->show();
501 
502  connect(m_widget, TQT_SIGNAL(enableOk(bool)), TQT_SLOT(acceptOK(bool)));
503  connect(m_widget, TQT_SIGNAL(enableOk(bool)), TQT_SLOT(enableButtonApply(bool)));
504 
505  enableButtonApply(false);
506  emit newToolbarConfig();
507 }
508 
509 void KEditToolbar::slotOk()
510 {
511  if (!d->m_accept) {
512  reject();
513  return;
514  }
515 
516  if (!m_widget->save())
517  {
518  // some error box here is needed
519  }
520  else
521  {
522  emit newToolbarConfig();
523  accept();
524  }
525 }
526 
527 void KEditToolbar::slotApply()
528 {
529  (void)m_widget->save();
530  enableButtonApply(false);
531  emit newToolbarConfig();
532 }
533 
534 void KEditToolbar::setDefaultToolbar(const char *toolbarName)
535 {
536  s_defaultToolbar = toolbarName;
537 }
538 
539 KEditToolbarWidget::KEditToolbarWidget(TDEActionCollection *collection,
540  const TQString& file,
541  bool global, TQWidget *parent)
542  : TQWidget(parent),
543  d(new KEditToolbarWidgetPrivate(instance(), collection))
544 {
545  initNonKPart(collection, file, global);
546  // now load in our toolbar combo box
547  loadToolbarCombo();
548  adjustSize();
549  setMinimumSize(sizeHint());
550 }
551 
552 KEditToolbarWidget::KEditToolbarWidget(const TQString& defaultToolbar,
553  TDEActionCollection *collection,
554  const TQString& file, bool global,
555  TQWidget *parent)
556  : TQWidget(parent),
557  d(new KEditToolbarWidgetPrivate(instance(), collection))
558 {
559  initNonKPart(collection, file, global);
560  // now load in our toolbar combo box
561  loadToolbarCombo(defaultToolbar);
562  adjustSize();
563  setMinimumSize(sizeHint());
564 }
565 
566 KEditToolbarWidget::KEditToolbarWidget( KXMLGUIFactory* factory,
567  TQWidget *parent)
568  : TQWidget(parent),
569  d(new KEditToolbarWidgetPrivate(instance(), KXMLGUIClient::actionCollection() /*create new one*/))
570 {
571  initKPart(factory);
572  // now load in our toolbar combo box
573  loadToolbarCombo();
574  adjustSize();
575  setMinimumSize(sizeHint());
576 }
577 
578 KEditToolbarWidget::KEditToolbarWidget( const TQString& defaultToolbar,
579  KXMLGUIFactory* factory,
580  TQWidget *parent)
581  : TQWidget(parent),
582  d(new KEditToolbarWidgetPrivate(instance(), KXMLGUIClient::actionCollection() /*create new one*/))
583 {
584  initKPart(factory);
585  // now load in our toolbar combo box
586  loadToolbarCombo(defaultToolbar);
587  adjustSize();
588  setMinimumSize(sizeHint());
589 }
590 
591 KEditToolbarWidget::~KEditToolbarWidget()
592 {
593  delete d;
594 }
595 
596 void KEditToolbarWidget::initNonKPart(TDEActionCollection *collection,
597  const TQString& file, bool global)
598 {
599  //d->m_actionList = collection->actions();
600 
601  // handle the merging
602  if (global)
603  setXMLFile(locate("config", "ui/ui_standards.rc"));
604  TQString localXML = d->loadXMLFile(file);
605  setXML(localXML, true);
606 
607  // reusable vars
608  TQDomElement elem;
609 
610  // first, get all of the necessary info for our local xml
611  KEditToolbarInternal::XmlData local;
612  local.m_xmlFile = d->xmlFile(file);
613  local.m_type = KEditToolbarInternal::XmlData::Local;
614  local.m_document.setContent(localXML);
615  elem = local.m_document.documentElement().toElement();
616  local.m_barList = d->findToolbars(elem);
617  local.m_actionCollection = collection;
618  d->m_xmlFiles.append(local);
619 
620  // then, the merged one (ui_standards + local xml)
621  KEditToolbarInternal::XmlData merge;
622  merge.m_xmlFile = TQString::null;
623  merge.m_type = KEditToolbarInternal::XmlData::Merged;
624  merge.m_document = domDocument();
625  elem = merge.m_document.documentElement().toElement();
626  merge.m_barList = d->findToolbars(elem);
627  merge.m_actionCollection = collection;
628  d->m_xmlFiles.append(merge);
629 
630 #ifndef NDEBUG
631  //d->dump();
632 #endif
633 
634  // okay, that done, we concern ourselves with the GUI aspects
635  setupLayout();
636 }
637 
638 void KEditToolbarWidget::initKPart(KXMLGUIFactory* factory)
639 {
640  // reusable vars
641  TQDomElement elem;
642 
643  setFactory( factory );
644  actionCollection()->setWidget( this );
645 
646  // add all of the client data
647  TQPtrList<KXMLGUIClient> clients(factory->clients());
648  TQPtrListIterator<KXMLGUIClient> it( clients );
649  for( ; it.current(); ++it)
650  {
651  KXMLGUIClient *client = it.current();
652 
653  if (client->xmlFile().isNull())
654  continue;
655 
656  KEditToolbarInternal::XmlData data;
657  data.m_xmlFile = client->localXMLFile();
658  if ( it.atFirst() )
659  data.m_type = KEditToolbarInternal::XmlData::Shell;
660  else
661  data.m_type = KEditToolbarInternal::XmlData::Part;
662  data.m_document.setContent( KXMLGUIFactory::readConfigFile( client->xmlFile(), client->instance() ) );
663  elem = data.m_document.documentElement().toElement();
664  data.m_barList = d->findToolbars(elem);
665  data.m_actionCollection = client->actionCollection();
666  d->m_xmlFiles.append(data);
667 
668  //d->m_actionList += client->actionCollection()->actions();
669  }
670 
671 #ifndef NDEBUG
672  //d->dump();
673 #endif
674 
675  // okay, that done, we concern ourselves with the GUI aspects
676  setupLayout();
677 }
678 
679 bool KEditToolbarWidget::save()
680 {
681  //kdDebug(240) << "KEditToolbarWidget::save" << endl;
682  KEditToolbarInternal::XmlDataList::Iterator it = d->m_xmlFiles.begin();
683  for ( ; it != d->m_xmlFiles.end(); ++it)
684  {
685  // let's not save non-modified files
686  if ( !((*it).m_isModified) )
687  continue;
688 
689  // let's also skip (non-existent) merged files
690  if ( (*it).m_type == KEditToolbarInternal::XmlData::Merged )
691  continue;
692 
693  dump_xml((*it).m_document);
694 
695  kdDebug(240) << "Saving " << (*it).m_xmlFile << endl;
696  // if we got this far, we might as well just save it
697  KXMLGUIFactory::saveConfigFile((*it).m_document, (*it).m_xmlFile);
698  }
699 
700  if ( !factory() )
701  return true;
702 
703  rebuildKXMLGUIClients();
704 
705  return true;
706 }
707 
708 void KEditToolbarWidget::rebuildKXMLGUIClients()
709 {
710  if ( !factory() )
711  return;
712 
713  TQPtrList<KXMLGUIClient> clients(factory()->clients());
714  //kdDebug(240) << "factory: " << clients.count() << " clients" << endl;
715 
716  // remove the elements starting from the last going to the first
717  KXMLGUIClient *client = clients.last();
718  while ( client )
719  {
720  //kdDebug(240) << "factory->removeClient " << client << endl;
721  factory()->removeClient( client );
722  client = clients.prev();
723  }
724 
725  KXMLGUIClient *firstClient = clients.first();
726 
727  // now, rebuild the gui from the first to the last
728  //kdDebug(240) << "rebuilding the gui" << endl;
729  TQPtrListIterator<KXMLGUIClient> cit( clients );
730  for( ; cit.current(); ++cit)
731  {
732  KXMLGUIClient* client = cit.current();
733  //kdDebug(240) << "updating client " << client << " " << client->instance()->instanceName() << " xmlFile=" << client->xmlFile() << endl;
734  TQString file( client->xmlFile() ); // before setting ui_standards!
735  if ( !file.isEmpty() )
736  {
737  // passing an empty stream forces the clients to reread the XML
738  client->setXMLGUIBuildDocument( TQDomDocument() );
739 
740  // for the shell, merge in ui_standards.rc
741  if ( client == firstClient ) // same assumption as in the ctor: first==shell
742  client->setXMLFile(locate("config", "ui/ui_standards.rc"));
743 
744  // and this forces it to use the *new* XML file
745  client->setXMLFile( file, client == firstClient /* merge if shell */ );
746  }
747  }
748 
749  // Now we can add the clients to the factory
750  // We don't do it in the loop above because adding a part automatically
751  // adds its plugins, so we must make sure the plugins were updated first.
752  cit.toFirst();
753  for( ; cit.current(); ++cit)
754  factory()->addClient( cit.current() );
755 }
756 
757 void KEditToolbarWidget::setupLayout()
758 {
759  // the toolbar name combo
760  d->m_comboLabel = new TQLabel(i18n("&Toolbar:"), this);
761  m_toolbarCombo = new TQComboBox(this);
762  m_toolbarCombo->setEnabled(false);
763  d->m_comboLabel->setBuddy(m_toolbarCombo);
764  d->m_comboSeparator = new KSeparator(this);
765  connect(m_toolbarCombo, TQT_SIGNAL(activated(const TQString&)),
766  this, TQT_SLOT(slotToolbarSelected(const TQString&)));
767 
768 // TQPushButton *new_toolbar = new TQPushButton(i18n("&New"), this);
769 // new_toolbar->setPixmap(BarIcon("document-new", TDEIcon::SizeSmall));
770 // new_toolbar->setEnabled(false); // disabled until implemented
771 // TQPushButton *del_toolbar = new TQPushButton(i18n("&Delete"), this);
772 // del_toolbar->setPixmap(BarIcon("edit-delete", TDEIcon::SizeSmall));
773 // del_toolbar->setEnabled(false); // disabled until implemented
774 
775  // our list of inactive actions
776  TQLabel *inactive_label = new TQLabel(i18n("A&vailable actions:"), this);
777  m_inactiveList = new KEditToolbarInternal::ToolbarListView(this);
778  m_inactiveList->setDragEnabled(true);
779  m_inactiveList->setAcceptDrops(true);
780  m_inactiveList->setDropVisualizer(false);
781  m_inactiveList->setAllColumnsShowFocus(true);
782  m_inactiveList->setMinimumSize(180, 250);
783  m_inactiveList->header()->hide();
784  m_inactiveList->addColumn(""); // icon
785  int column2 = m_inactiveList->addColumn(""); // text
786  m_inactiveList->setSorting( column2 );
787  inactive_label->setBuddy(m_inactiveList);
788  connect(m_inactiveList, TQT_SIGNAL(selectionChanged(TQListViewItem *)),
789  this, TQT_SLOT(slotInactiveSelected(TQListViewItem *)));
790  connect(m_inactiveList, TQT_SIGNAL( doubleClicked( TQListViewItem *, const TQPoint &, int )),
791  this, TQT_SLOT(slotInsertButton()));
792 
793  // our list of active actions
794  TQLabel *active_label = new TQLabel(i18n("Curr&ent actions:"), this);
795  m_activeList = new KEditToolbarInternal::ToolbarListView(this);
796  m_activeList->setDragEnabled(true);
797  m_activeList->setAcceptDrops(true);
798  m_activeList->setDropVisualizer(true);
799  m_activeList->setAllColumnsShowFocus(true);
800  m_activeList->setMinimumWidth(m_inactiveList->minimumWidth());
801  m_activeList->header()->hide();
802  m_activeList->addColumn(""); // icon
803  m_activeList->addColumn(""); // text
804  m_activeList->setSorting(-1);
805  active_label->setBuddy(m_activeList);
806 
807  connect(m_inactiveList, TQT_SIGNAL(dropped(TDEListView*,TQDropEvent*,TQListViewItem*)),
808  this, TQT_SLOT(slotDropped(TDEListView*,TQDropEvent*,TQListViewItem*)));
809  connect(m_activeList, TQT_SIGNAL(dropped(TDEListView*,TQDropEvent*,TQListViewItem*)),
810  this, TQT_SLOT(slotDropped(TDEListView*,TQDropEvent*,TQListViewItem*)));
811  connect(m_activeList, TQT_SIGNAL(selectionChanged(TQListViewItem *)),
812  this, TQT_SLOT(slotActiveSelected(TQListViewItem *)));
813  connect(m_activeList, TQT_SIGNAL( doubleClicked( TQListViewItem *, const TQPoint &, int )),
814  this, TQT_SLOT(slotRemoveButton()));
815 
816  // "change icon" button
817  d->m_changeIcon = new KPushButton( i18n( "Change &Icon..." ), this );
818  TQString kdialogExe = TDEStandardDirs::findExe(TQString::fromLatin1("kdialog"));
819  d->m_hasKDialog = !kdialogExe.isEmpty();
820  d->m_changeIcon->setEnabled( d->m_hasKDialog );
821 
822  connect( d->m_changeIcon, TQT_SIGNAL( clicked() ),
823  this, TQT_SLOT( slotChangeIcon() ) );
824 
825  // The buttons in the middle
826  TQIconSet iconSet;
827 
828  m_upAction = new TQToolButton(this);
829  iconSet = SmallIconSet( "go-up" );
830  m_upAction->setIconSet( iconSet );
831  m_upAction->setEnabled(false);
832  m_upAction->setAutoRepeat(true);
833  connect(m_upAction, TQT_SIGNAL(clicked()), TQT_SLOT(slotUpButton()));
834 
835  m_insertAction = new TQToolButton(this);
836  iconSet = TQApplication::reverseLayout() ? SmallIconSet( "back" ) : SmallIconSet( "forward" );
837  m_insertAction->setIconSet( iconSet );
838  m_insertAction->setEnabled(false);
839  connect(m_insertAction, TQT_SIGNAL(clicked()), TQT_SLOT(slotInsertButton()));
840 
841  m_removeAction = new TQToolButton(this);
842  iconSet = TQApplication::reverseLayout() ? SmallIconSet( "forward" ) : SmallIconSet( "back" );
843  m_removeAction->setIconSet( iconSet );
844  m_removeAction->setEnabled(false);
845  connect(m_removeAction, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveButton()));
846 
847  m_downAction = new TQToolButton(this);
848  iconSet = SmallIconSet( "go-down" );
849  m_downAction->setIconSet( iconSet );
850  m_downAction->setEnabled(false);
851  m_downAction->setAutoRepeat(true);
852  connect(m_downAction, TQT_SIGNAL(clicked()), TQT_SLOT(slotDownButton()));
853 
854  d->m_helpArea = new TQLabel(this);
855  d->m_helpArea->setAlignment( TQt::WordBreak );
856 
857  // now start with our layouts
858  TQVBoxLayout *top_layout = new TQVBoxLayout(this, 0, KDialog::spacingHint());
859 
860  TQVBoxLayout *name_layout = new TQVBoxLayout(KDialog::spacingHint());
861  TQHBoxLayout *list_layout = new TQHBoxLayout(KDialog::spacingHint());
862 
863  TQVBoxLayout *inactive_layout = new TQVBoxLayout(KDialog::spacingHint());
864  TQVBoxLayout *active_layout = new TQVBoxLayout(KDialog::spacingHint());
865  TQHBoxLayout *changeIcon_layout = new TQHBoxLayout(KDialog::spacingHint());
866 
867  TQGridLayout *button_layout = new TQGridLayout(5, 3, 0);
868 
869  name_layout->addWidget(d->m_comboLabel);
870  name_layout->addWidget(m_toolbarCombo);
871 // name_layout->addWidget(new_toolbar);
872 // name_layout->addWidget(del_toolbar);
873 
874  button_layout->setRowStretch( 0, 10 );
875  button_layout->addWidget(m_upAction, 1, 1);
876  button_layout->addWidget(m_removeAction, 2, 0);
877  button_layout->addWidget(m_insertAction, 2, 2);
878  button_layout->addWidget(m_downAction, 3, 1);
879  button_layout->setRowStretch( 4, 10 );
880 
881  inactive_layout->addWidget(inactive_label);
882  inactive_layout->addWidget(m_inactiveList, 1);
883 
884  active_layout->addWidget(active_label);
885  active_layout->addWidget(m_activeList, 1);
886  active_layout->addLayout(changeIcon_layout);
887 
888  changeIcon_layout->addStretch( 1 );
889  changeIcon_layout->addWidget( d->m_changeIcon );
890  changeIcon_layout->addStretch( 1 );
891 
892  list_layout->addLayout(inactive_layout);
893  list_layout->addLayout(TQT_TQLAYOUT(button_layout));
894  list_layout->addLayout(active_layout);
895 
896  top_layout->addLayout(name_layout);
897  top_layout->addWidget(d->m_comboSeparator);
898  top_layout->addLayout(list_layout,10);
899  top_layout->addWidget(d->m_helpArea);
900  top_layout->addWidget(new KSeparator(this));
901 }
902 
903 void KEditToolbarWidget::loadToolbarCombo(const TQString& defaultToolbar)
904 {
905  static const TQString &attrName = TDEGlobal::staticQString( "name" );
906  // just in case, we clear our combo
907  m_toolbarCombo->clear();
908 
909  int defaultToolbarId = -1;
910  int count = 0;
911  // load in all of the toolbar names into this combo box
912  KEditToolbarInternal::XmlDataList::Iterator xit = d->m_xmlFiles.begin();
913  for ( ; xit != d->m_xmlFiles.end(); ++xit)
914  {
915  // skip the local one in favor of the merged
916  if ( (*xit).m_type == KEditToolbarInternal::XmlData::Local )
917  continue;
918 
919  // each xml file may have any number of toolbars
920  ToolbarList::Iterator it = (*xit).m_barList.begin();
921  for ( ; it != (*xit).m_barList.end(); ++it)
922  {
923  TQString name = d->toolbarName( *xit, *it );
924  m_toolbarCombo->setEnabled( true );
925  m_toolbarCombo->insertItem( name );
926  if (defaultToolbarId == -1 && (name == defaultToolbar || defaultToolbar == (*it).attribute( attrName )))
927  defaultToolbarId = count;
928  count++;
929  }
930  }
931  bool showCombo = (count > 1);
932  d->m_comboLabel->setShown(showCombo);
933  d->m_comboSeparator->setShown(showCombo);
934  m_toolbarCombo->setShown(showCombo);
935  if (defaultToolbarId == -1)
936  defaultToolbarId = 0;
937  // we want to the specified item selected and its actions loaded
938  m_toolbarCombo->setCurrentItem(defaultToolbarId);
939  slotToolbarSelected(m_toolbarCombo->currentText());
940 }
941 
942 void KEditToolbarWidget::loadActionList(TQDomElement& elem)
943 {
944  static const TQString &tagSeparator = TDEGlobal::staticQString( "Separator" );
945  static const TQString &tagMerge = TDEGlobal::staticQString( "Merge" );
946  static const TQString &tagActionList= TDEGlobal::staticQString( "ActionList" );
947  static const TQString &attrName = TDEGlobal::staticQString( "name" );
948  static const TQString &attrLineSeparator = TDEGlobal::staticQString( "lineSeparator" );
949 
950  int sep_num = 0;
951  TQString sep_name("separator_%1");
952 
953  // clear our lists
954  m_inactiveList->clear();
955  m_activeList->clear();
956  m_insertAction->setEnabled(false);
957  m_removeAction->setEnabled(false);
958  m_upAction->setEnabled(false);
959  m_downAction->setEnabled(false);
960 
961  // We'll use this action collection
962  TDEActionCollection* actionCollection = d->m_currentXmlData->m_actionCollection;
963 
964  // store the names of our active actions
965  TQMap<TQString, bool> active_list;
966 
967  // see if our current action is in this toolbar
968  TDEIconLoader *loader = TDEGlobal::instance()->iconLoader();
969  TQDomNode n = elem.lastChild();
970  for( ; !n.isNull(); n = n.previousSibling() )
971  {
972  TQDomElement it = n.toElement();
973  if (it.isNull()) continue;
974  if (it.tagName() == tagSeparator)
975  {
976  KEditToolbarInternal::ToolbarItem *act = new KEditToolbarInternal::ToolbarItem(m_activeList, tagSeparator, sep_name.arg(sep_num++), TQString::null);
977  bool isLineSep = ( it.attribute(attrLineSeparator, "true").lower() == TQString::fromLatin1("true") );
978  if(isLineSep)
979  act->setText(1, LINESEPARATORSTRING);
980  else
981  act->setText(1, SEPARATORSTRING);
982  it.setAttribute( attrName, act->internalName() );
983  continue;
984  }
985 
986  if (it.tagName() == tagMerge)
987  {
988  // Merge can be named or not - use the name if there is one
989  TQString name = it.attribute( attrName );
990  KEditToolbarInternal::ToolbarItem *act = new KEditToolbarInternal::ToolbarItem(m_activeList, tagMerge, name, i18n("This element will be replaced with all the elements of an embedded component."));
991  if ( name.isEmpty() )
992  act->setText(1, i18n("<Merge>"));
993  else
994  act->setText(1, i18n("<Merge %1>").arg(name));
995  continue;
996  }
997 
998  if (it.tagName() == tagActionList)
999  {
1000  KEditToolbarInternal::ToolbarItem *act = new KEditToolbarInternal::ToolbarItem(m_activeList, tagActionList, it.attribute(attrName), i18n("This is a dynamic list of actions. You can move it, but if you remove it you won't be able to re-add it.") );
1001  act->setText(1, i18n("ActionList: %1").arg(it.attribute(attrName)));
1002  continue;
1003  }
1004 
1005  // iterate through this client's actions
1006  // This used to iterate through _all_ actions, but we don't support
1007  // putting any action into any client...
1008  for (unsigned int i = 0; i < actionCollection->count(); i++)
1009  {
1010  TDEAction *action = actionCollection->action( i );
1011 
1012  // do we have a match?
1013  if (it.attribute( attrName ) == action->name())
1014  {
1015  // we have a match!
1016  KEditToolbarInternal::ToolbarItem *act = new KEditToolbarInternal::ToolbarItem(m_activeList, it.tagName(), action->name(), action->toolTip());
1017  act->setText(1, action->plainText());
1018  if (action->hasIcon()) {
1019  if (!action->icon().isEmpty()) {
1020  act->setPixmap(0, loader->loadIcon(action->icon(), TDEIcon::Toolbar, 16, TDEIcon::DefaultState, 0, true) );
1021  }
1022  else { // Has iconset
1023  act->setPixmap(0, action->iconSet(TDEIcon::Toolbar).pixmap());
1024  }
1025  }
1026 
1027  active_list.insert(action->name(), true);
1028  break;
1029  }
1030  }
1031  }
1032 
1033  // go through the rest of the collection
1034  for (int i = actionCollection->count() - 1; i > -1; --i)
1035  {
1036  TDEAction *action = actionCollection->action( i );
1037 
1038  // skip our active ones
1039  if (active_list.contains(action->name())) {
1040  continue;
1041  }
1042 
1043  KEditToolbarInternal::ToolbarItem *act = new KEditToolbarInternal::ToolbarItem(m_inactiveList, tagActionList, action->name(), action->toolTip());
1044  act->setText(1, action->plainText());
1045  if (action->hasIcon()) {
1046  if (!action->icon().isEmpty()) {
1047  act->setPixmap(0, loader->loadIcon(action->icon(), TDEIcon::Toolbar, 16, TDEIcon::DefaultState, 0, true) );
1048  }
1049  else { // Has iconset
1050  act->setPixmap(0, action->iconSet(TDEIcon::Toolbar).pixmap());
1051  }
1052  }
1053  }
1054 
1055  // finally, add default separators to the inactive list
1056  KEditToolbarInternal::ToolbarItem *act = new KEditToolbarInternal::ToolbarItem(m_inactiveList, tagSeparator, sep_name.arg(sep_num++), TQString::null);
1057  act->setText(1, LINESEPARATORSTRING);
1058  act = new KEditToolbarInternal::ToolbarItem(m_inactiveList, tagSeparator, sep_name.arg(sep_num++), TQString::null);
1059  act->setText(1, SEPARATORSTRING);
1060 }
1061 
1062 TDEActionCollection *KEditToolbarWidget::actionCollection() const
1063 {
1064  return d->m_collection;
1065 }
1066 
1067 void KEditToolbarWidget::slotToolbarSelected(const TQString& _text)
1068 {
1069  // iterate through everything
1070  KEditToolbarInternal::XmlDataList::Iterator xit = d->m_xmlFiles.begin();
1071  for ( ; xit != d->m_xmlFiles.end(); ++xit)
1072  {
1073  // each xml file may have any number of toolbars
1074  ToolbarList::Iterator it = (*xit).m_barList.begin();
1075  for ( ; it != (*xit).m_barList.end(); ++it)
1076  {
1077  TQString name = d->toolbarName( *xit, *it );
1078  // is this our toolbar?
1079  if ( name == _text )
1080  {
1081  // save our current settings
1082  d->m_currentXmlData = & (*xit);
1083  d->m_currentToolbarElem = (*it);
1084 
1085  // load in our values
1086  loadActionList(d->m_currentToolbarElem);
1087 
1088  if ((*xit).m_type == KEditToolbarInternal::XmlData::Part || (*xit).m_type == KEditToolbarInternal::XmlData::Shell)
1089  setDOMDocument( (*xit).m_document );
1090  return;
1091  }
1092  }
1093  }
1094 }
1095 
1096 void KEditToolbarWidget::slotInactiveSelected(TQListViewItem *item)
1097 {
1098  KEditToolbarInternal::ToolbarItem* toolitem = static_cast<KEditToolbarInternal::ToolbarItem *>(item);
1099  if (item)
1100  {
1101  m_insertAction->setEnabled(true);
1102  TQString statusText = toolitem->statusText();
1103  d->m_helpArea->setText( statusText );
1104  }
1105  else
1106  {
1107  m_insertAction->setEnabled(false);
1108  d->m_helpArea->setText( TQString::null );
1109  }
1110 }
1111 
1112 void KEditToolbarWidget::slotActiveSelected(TQListViewItem *item)
1113 {
1114  KEditToolbarInternal::ToolbarItem* toolitem = static_cast<KEditToolbarInternal::ToolbarItem *>(item);
1115  m_removeAction->setEnabled( item );
1116 
1117  static const TQString &tagAction = TDEGlobal::staticQString( "Action" );
1118  d->m_changeIcon->setEnabled( item &&
1119  d->m_hasKDialog &&
1120  toolitem->internalTag() == tagAction );
1121 
1122  if (item)
1123  {
1124  if (item->itemAbove())
1125  m_upAction->setEnabled(true);
1126  else
1127  m_upAction->setEnabled(false);
1128 
1129  if (item->itemBelow())
1130  m_downAction->setEnabled(true);
1131  else
1132  m_downAction->setEnabled(false);
1133  TQString statusText = toolitem->statusText();
1134  d->m_helpArea->setText( statusText );
1135  }
1136  else
1137  {
1138  m_upAction->setEnabled(false);
1139  m_downAction->setEnabled(false);
1140  d->m_helpArea->setText( TQString::null );
1141  }
1142 }
1143 
1144 void KEditToolbarWidget::slotDropped(TDEListView *list, TQDropEvent *e, TQListViewItem *after)
1145 {
1146  KEditToolbarInternal::ToolbarItem *item = new KEditToolbarInternal::ToolbarItem(m_inactiveList); // needs parent, use inactiveList temporarily
1147  if(!KEditToolbarInternal::ToolbarItemDrag::decode(e, *item)) {
1148  delete item;
1149  return;
1150  }
1151 
1152  if (list == m_activeList) {
1153  if (e->source() == m_activeList) {
1154  // has been dragged within the active list (moved).
1155  moveActive(item, after);
1156  }
1157  else
1158  insertActive(item, after, true);
1159  } else if (list == m_inactiveList) {
1160  // has been dragged to the inactive list -> remove from the active list.
1161  removeActive(item);
1162  }
1163 
1164  delete item; item = 0; // not neded anymore
1165 
1166  // we're modified, so let this change
1167  emit enableOk(true);
1168 
1169  slotToolbarSelected( m_toolbarCombo->currentText() );
1170 }
1171 
1172 void KEditToolbarWidget::slotInsertButton()
1173 {
1174  KEditToolbarInternal::ToolbarItem *item = (KEditToolbarInternal::ToolbarItem*)m_inactiveList->currentItem();
1175  insertActive(item, m_activeList->currentItem(), false);
1176 
1177  // we're modified, so let this change
1178  emit enableOk(true);
1179 
1180  // TODO: #### this causes #97572.
1181  // It would be better to just "delete item; loadActions( ... , ActiveListOnly );" or something.
1182  slotToolbarSelected( m_toolbarCombo->currentText() );
1183 }
1184 
1185 void KEditToolbarWidget::slotRemoveButton()
1186 {
1187  removeActive( dynamic_cast<KEditToolbarInternal::ToolbarItem*>(m_activeList->currentItem()) );
1188 
1189  // we're modified, so let this change
1190  emit enableOk(true);
1191 
1192  slotToolbarSelected( m_toolbarCombo->currentText() );
1193 }
1194 
1195 void KEditToolbarWidget::insertActive(KEditToolbarInternal::ToolbarItem *item, TQListViewItem *before, bool prepend)
1196 {
1197  if (!item)
1198  return;
1199 
1200  static const TQString &tagAction = TDEGlobal::staticQString( "Action" );
1201  static const TQString &tagSeparator = TDEGlobal::staticQString( "Separator" );
1202  static const TQString &attrName = TDEGlobal::staticQString( "name" );
1203  static const TQString &attrLineSeparator = TDEGlobal::staticQString( "lineSeparator" );
1204  static const TQString &attrNoMerge = TDEGlobal::staticQString( "noMerge" );
1205 
1206  TQDomElement new_item;
1207  // let's handle the separator specially
1208  if (item->text(1) == LINESEPARATORSTRING) {
1209  new_item = domDocument().createElement(tagSeparator);
1210  } else if (item->text(1) == SEPARATORSTRING) {
1211  new_item = domDocument().createElement(tagSeparator);
1212  new_item.setAttribute(attrLineSeparator, "false");
1213  } else
1214  new_item = domDocument().createElement(tagAction);
1215  new_item.setAttribute(attrName, item->internalName());
1216 
1217  if (before)
1218  {
1219  // we have the item in the active list which is before the new
1220  // item.. so let's try our best to add our new item right after it
1221  KEditToolbarInternal::ToolbarItem *act_item = (KEditToolbarInternal::ToolbarItem*)before;
1222  TQDomElement elem = d->findElementForToolbarItem( act_item );
1223  Q_ASSERT( !elem.isNull() );
1224  d->m_currentToolbarElem.insertAfter(new_item, elem);
1225  }
1226  else
1227  {
1228  // simply put it at the beginning or the end of the list.
1229  if (prepend)
1230  d->m_currentToolbarElem.insertBefore(new_item, d->m_currentToolbarElem.firstChild());
1231  else
1232  d->m_currentToolbarElem.appendChild(new_item);
1233  }
1234 
1235  // and set this container as a noMerge
1236  d->m_currentToolbarElem.setAttribute( attrNoMerge, "1");
1237 
1238  // update the local doc
1239  updateLocal(d->m_currentToolbarElem);
1240 }
1241 
1242 void KEditToolbarWidget::removeActive(KEditToolbarInternal::ToolbarItem *item)
1243 {
1244  if (!item)
1245  return;
1246 
1247  static const TQString &attrNoMerge = TDEGlobal::staticQString( "noMerge" );
1248 
1249  // we're modified, so let this change
1250  emit enableOk(true);
1251 
1252  // now iterate through to find the child to nuke
1253  TQDomElement elem = d->findElementForToolbarItem( item );
1254  if ( !elem.isNull() )
1255  {
1256  // nuke myself!
1257  d->m_currentToolbarElem.removeChild(elem);
1258 
1259  // and set this container as a noMerge
1260  d->m_currentToolbarElem.setAttribute( attrNoMerge, "1");
1261 
1262  // update the local doc
1263  updateLocal(d->m_currentToolbarElem);
1264  }
1265 }
1266 
1267 void KEditToolbarWidget::slotUpButton()
1268 {
1269  KEditToolbarInternal::ToolbarItem *item = (KEditToolbarInternal::ToolbarItem*)m_activeList->currentItem();
1270 
1271  // make sure we're not the top item already
1272  if (!item->itemAbove())
1273  return;
1274 
1275  // we're modified, so let this change
1276  emit enableOk(true);
1277 
1278  moveActive( item, item->itemAbove()->itemAbove() );
1279  delete item;
1280 }
1281 
1282 void KEditToolbarWidget::moveActive( KEditToolbarInternal::ToolbarItem* item, TQListViewItem* before )
1283 {
1284  TQDomElement e = d->findElementForToolbarItem( item );
1285 
1286  if ( e.isNull() )
1287  return;
1288 
1289  // cool, i found me. now clone myself
1290  KEditToolbarInternal::ToolbarItem *clone = new KEditToolbarInternal::ToolbarItem(m_activeList,
1291  before,
1292  item->internalTag(),
1293  item->internalName(),
1294  item->statusText());
1295 
1296  clone->setText(1, item->text(1));
1297 
1298  // only set new pixmap if exists
1299  if( item->pixmap(0) )
1300  clone->setPixmap(0, *item->pixmap(0));
1301 
1302  // select my clone
1303  m_activeList->setSelected(clone, true);
1304 
1305  // make clone visible
1306  m_activeList->ensureItemVisible(clone);
1307 
1308  // and do the real move in the DOM
1309  if ( !before )
1310  d->m_currentToolbarElem.insertBefore(e, d->m_currentToolbarElem.firstChild() );
1311  else
1312  d->m_currentToolbarElem.insertAfter(e, d->findElementForToolbarItem( (KEditToolbarInternal::ToolbarItem*)before ));
1313 
1314  // and set this container as a noMerge
1315  static const TQString &attrNoMerge = TDEGlobal::staticQString( "noMerge" );
1316  d->m_currentToolbarElem.setAttribute( attrNoMerge, "1");
1317 
1318  // update the local doc
1319  updateLocal(d->m_currentToolbarElem);
1320 }
1321 
1322 void KEditToolbarWidget::slotDownButton()
1323 {
1324  KEditToolbarInternal::ToolbarItem *item = (KEditToolbarInternal::ToolbarItem*)m_activeList->currentItem();
1325 
1326  // make sure we're not the bottom item already
1327  if (!item->itemBelow())
1328  return;
1329 
1330  // we're modified, so let this change
1331  emit enableOk(true);
1332 
1333  moveActive( item, item->itemBelow() );
1334  delete item;
1335 }
1336 
1337 void KEditToolbarWidget::updateLocal(TQDomElement& elem)
1338 {
1339  static const TQString &attrName = TDEGlobal::staticQString( "name" );
1340 
1341  KEditToolbarInternal::XmlDataList::Iterator xit = d->m_xmlFiles.begin();
1342  for ( ; xit != d->m_xmlFiles.end(); ++xit)
1343  {
1344  if ( (*xit).m_type == KEditToolbarInternal::XmlData::Merged )
1345  continue;
1346 
1347  if ( (*xit).m_type == KEditToolbarInternal::XmlData::Shell ||
1348  (*xit).m_type == KEditToolbarInternal::XmlData::Part )
1349  {
1350  if ( d->m_currentXmlData->m_xmlFile == (*xit).m_xmlFile )
1351  {
1352  (*xit).m_isModified = true;
1353  return;
1354  }
1355 
1356  continue;
1357  }
1358 
1359  (*xit).m_isModified = true;
1360 
1361  ToolbarList::Iterator it = (*xit).m_barList.begin();
1362  for ( ; it != (*xit).m_barList.end(); ++it)
1363  {
1364  TQString name( (*it).attribute( attrName ) );
1365  TQString tag( (*it).tagName() );
1366  if ( (tag != elem.tagName()) || (name != elem.attribute(attrName)) )
1367  continue;
1368 
1369  TQDomElement toolbar = (*xit).m_document.documentElement().toElement();
1370  toolbar.replaceChild(elem, (*it));
1371  return;
1372  }
1373 
1374  // just append it
1375  TQDomElement toolbar = (*xit).m_document.documentElement().toElement();
1376  toolbar.appendChild(elem);
1377  }
1378 }
1379 
1380 void KEditToolbarWidget::slotChangeIcon()
1381 {
1382  // We can't use TDEIconChooser here, since it's in libtdeio
1383  // ##### KDE4: reconsider this, e.g. move KEditToolbar to libtdeio
1384 
1385  //if the process is already running (e.g. when somebody clicked the change button twice (see #127149)) - do nothing...
1386  //otherwise m_kdialogProcess will be overwritten and set to zero in slotProcessExited()...crash!
1387  if ( d->m_kdialogProcess && d->m_kdialogProcess->isRunning() )
1388  return;
1389 
1390  d->m_kdialogProcess = new KProcIO;
1391  TQString kdialogExe = TDEStandardDirs::findExe(TQString::fromLatin1("kdialog"));
1392  (*d->m_kdialogProcess) << kdialogExe;
1393  (*d->m_kdialogProcess) << "--embed";
1394  (*d->m_kdialogProcess) << TQString::number( (ulong)topLevelWidget()->winId() );
1395  (*d->m_kdialogProcess) << "--geticon";
1396  (*d->m_kdialogProcess) << "Toolbar";
1397  (*d->m_kdialogProcess) << "Actions";
1398  if ( !d->m_kdialogProcess->start( TDEProcess::NotifyOnExit ) ) {
1399  kdError(240) << "Can't run " << kdialogExe << endl;
1400  delete d->m_kdialogProcess;
1401  d->m_kdialogProcess = 0;
1402  return;
1403  }
1404 
1405  m_activeList->setEnabled( false ); // don't change the current item
1406  m_toolbarCombo->setEnabled( false ); // don't change the current toolbar
1407 
1408  connect( d->m_kdialogProcess, TQT_SIGNAL( processExited( TDEProcess* ) ),
1409  this, TQT_SLOT( slotProcessExited( TDEProcess* ) ) );
1410 }
1411 
1412 void KEditToolbarWidget::slotProcessExited( TDEProcess* )
1413 {
1414  m_activeList->setEnabled( true );
1415  m_toolbarCombo->setEnabled( true );
1416 
1417  TQString icon;
1418 
1419  if (!d->m_kdialogProcess) {
1420  kdError(240) << "Something is wrong here! m_kdialogProcess is zero!" << endl;
1421  return;
1422  }
1423 
1424  if ( !d->m_kdialogProcess->normalExit() ||
1425  d->m_kdialogProcess->exitStatus() ||
1426  d->m_kdialogProcess->readln(icon, true) <= 0 ) {
1427  delete d->m_kdialogProcess;
1428  d->m_kdialogProcess = 0;
1429  return;
1430  }
1431 
1432  KEditToolbarInternal::ToolbarItem *item = (KEditToolbarInternal::ToolbarItem*)m_activeList->currentItem();
1433  if(item){
1434  item->setPixmap(0, BarIcon(icon, 16));
1435 
1436  Q_ASSERT( d->m_currentXmlData->m_type != KEditToolbarInternal::XmlData::Merged );
1437 
1438  d->m_currentXmlData->m_isModified = true;
1439 
1440  // Get hold of ActionProperties tag
1441  TQDomElement elem = KXMLGUIFactory::actionPropertiesElement( d->m_currentXmlData->m_document );
1442  // Find or create an element for this action
1443  TQDomElement act_elem = KXMLGUIFactory::findActionByName( elem, item->internalName(), true /*create*/ );
1444  Q_ASSERT( !act_elem.isNull() );
1445  act_elem.setAttribute( "icon", icon );
1446 
1447  // we're modified, so let this change
1448  emit enableOk(true);
1449  }
1450 
1451  delete d->m_kdialogProcess;
1452  d->m_kdialogProcess = 0;
1453 }
1454 
1455 void KEditToolbar::virtual_hook( int id, void* data )
1456 { KDialogBase::virtual_hook( id, data ); }
1457 
1458 void KEditToolbarWidget::virtual_hook( int id, void* data )
1459 { KXMLGUIClient::virtual_hook( id, data ); }
1460 
1461 #include "kedittoolbar.moc"
KEditToolbar::acceptOK
void acceptOK(bool b)
should OK really save?
Definition: kedittoolbar.cpp:438
KPushButton
This is nothing but a TQPushButton with drag-support and KGuiItem support.
Definition: kpushbutton.h:37
KEditToolbar::setDefaultToolbar
static void setDefaultToolbar(const char *toolbarName)
Sets the default toolbar, which will be auto-selected when the constructor without the defaultToolbar...
Definition: kedittoolbar.cpp:534
KXMLGUIClient::setXML
virtual void setXML(const TQString &document, bool merge=false)
Sets the XML for the part.
Definition: kxmlguiclient.cpp:217
KXMLGUIClient::setXMLFile
virtual void setXMLFile(const TQString &file, bool merge=false, bool setXMLDoc=true)
Sets the name of the rc file containing the XML for the part.
Definition: kxmlguiclient.cpp:165
TDEIcon::DefaultState
KEditToolbar::~KEditToolbar
~KEditToolbar()
destructor
Definition: kedittoolbar.cpp:433
KXMLGUIClient
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
Definition: kxmlguiclient.h:43
locateLocal
TQString locateLocal(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
KXMLGUIClient::setXMLGUIBuildDocument
void setXMLGUIBuildDocument(const TQDomDocument &doc)
Definition: kxmlguiclient.cpp:540
KXMLGUIFactory::removeClient
void removeClient(KXMLGUIClient *client)
Removes the GUI described by the client, by unplugging all provided actions and removing all owned co...
Definition: kxmlguifactory.cpp:321
KEditToolbar::slotDefault
void slotDefault()
Set toolbars to default value.
Definition: kedittoolbar.cpp:444
KEditToolbar::slotApply
virtual void slotApply()
idem
Definition: kedittoolbar.cpp:527
TDEStdAccel::key
int key(StdAccel) KDE_DEPRECATED
KDialogBase::enableButtonOK
void enableButtonOK(bool state)
Enable or disable (gray out) the OK button.
Definition: kdialogbase.cpp:848
KXMLGUIFactory::addClient
void addClient(KXMLGUIClient *client)
Creates the GUI described by the TQDomDocument of the client, using the client's actions, and merges it with the previously created GUI.
Definition: kxmlguifactory.cpp:224
kdError
kdbgstream kdError(int area=0)
KXMLGUIClient::setDOMDocument
virtual void setDOMDocument(const TQDomDocument &document, bool merge=false)
Sets the Document for the part, describing the layout of the GUI.
Definition: kxmlguiclient.cpp:224
KEditToolbar::newToolbarConfig
void newToolbarConfig()
Signal emitted when 'apply' or 'ok' is clicked or toolbars were resetted.
KXMLGUIFactory::clients
TQPtrList< KXMLGUIClient > clients() const
Returns a list of all clients currently added to this factory.
Definition: kxmlguifactory.cpp:379
KEditToolbarWidget::actionCollection
virtual TDEActionCollection * actionCollection() const
Definition: kedittoolbar.cpp:1062
KXMLGUIClient::factory
KXMLGUIFactory * factory() const
Retrieves a pointer to the KXMLGUIFactory this client is associated with (will return 0L if the clien...
Definition: kxmlguiclient.cpp:555
TDEActionCollection::action
virtual TDEAction * action(int index) const
Return the TDEAction* at position "index" in the action collection.
Definition: tdeactioncollection.cpp:400
kdDebug
kdbgstream kdDebug(int area=0)
TDEActionCollection::setWidget
virtual void setWidget(TQWidget *widget)
This sets the widget to which the keyboard shortcuts should be attached.
Definition: tdeactioncollection.cpp:152
KEditToolbar::KEditToolbar
KEditToolbar(TDEActionCollection *collection, const TQString &xmlfile=TQString::null, bool global=true, TQWidget *parent=0, const char *name=0)
Constructor for apps that do not use components.
Definition: kedittoolbar.cpp:377
TDEActionCollection
A managed set of TDEAction objects.
Definition: tdeactioncollection.h:78
TDEAction
Class to encapsulate user-driven action or event.
Definition: tdeaction.h:202
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:191
I18N_NOOP
#define I18N_NOOP(x)
KXMLGUIClient::action
TDEAction * action(const char *name) const
Retrieves an action of the client by name.
Definition: kxmlguiclient.cpp:93
KXMLGUIClient::setFactory
void setFactory(KXMLGUIFactory *factory)
This method is called by the KXMLGUIFactory as soon as the client is added to the KXMLGUIFactory's GU...
Definition: kxmlguiclient.cpp:550
KSeparator
Standard horizontal or vertical separator.
Definition: kseparator.h:33
KXMLGUIFactory::findActionByName
static TQDomElement findActionByName(TQDomElement &elem, const TQString &sName, bool create)
Definition: kxmlguifactory.cpp:589
tdelocale.h
KXMLGUIClient::actionCollection
virtual TDEActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
Definition: kxmlguiclient.cpp:107
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:110
TDEGlobal::instance
static TDEInstance * instance()
KEditToolbarWidget::save
bool save()
Save any changes the user made.
Definition: kedittoolbar.cpp:679
kdWarning
kdbgstream kdWarning(int area=0)
KDialogBase::setMainWidget
void setMainWidget(TQWidget *widget)
Sets the main user definable widget.
Definition: kdialogbase.cpp:1431
KEditToolbarWidget::KEditToolbarWidget
KEditToolbarWidget(TDEActionCollection *collection, const TQString &xmlfile=TQString::null, bool global=true, TQWidget *parent=0L)
Constructor.
Definition: kedittoolbar.cpp:539
TDEStandardDirs::findExe
static TQString findExe(const TQString &appname, const TQString &pathstr=TQString::null, bool ignoreExecBit=false)
KXMLGUIFactory::actionPropertiesElement
static TQDomElement actionPropertiesElement(TQDomDocument &doc)
Definition: kxmlguifactory.cpp:567
TDEAction::setText
virtual void setText(const TQString &text)
Sets the text associated with this action.
Definition: tdeaction.cpp:879
TDEIconLoader::loadIcon
TQPixmap loadIcon(const TQString &name, TDEIcon::Group group, int size=0, int state=TDEIcon::DefaultState, TQString *path_store=0L, bool canReturnNull=false) const
TDEListView
This Widget extends the functionality of TQListView to honor the system wide settings for Single Clic...
Definition: tdelistview.h:84
KMessageBox::warningContinueCancel
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
Display a "warning" dialog.
Definition: tdemessagebox.cpp:585
TDEGlobal::staticQString
static const TQString & staticQString(const char *str)
KXMLGUIFactory
KXMLGUIFactory, together with KXMLGUIClient objects, can be used to create a GUI of container widgets...
Definition: kxmlguifactory.h:61
TDEIconLoader
KEditToolbarWidget::rebuildKXMLGUIClients
void rebuildKXMLGUIClients()
Remove and readd all KMXLGUIClients to update the GUI.
Definition: kedittoolbar.cpp:708
KDialogBase::enableButtonApply
void enableButtonApply(bool state)
Enable or disable (gray out) the Apply button.
Definition: kdialogbase.cpp:854
TDEAction::toolTip
virtual TQString toolTip() const
Get the tooltip text for the action.
Definition: tdeaction.cpp:623
KEditToolbarInternal
Definition: kedittoolbar.cpp:64
KXMLGUIClient::domDocument
virtual TQDomDocument domDocument() const
Definition: kxmlguiclient.cpp:128
TDEIcon::Toolbar
KEditToolbarWidget
A widget used to customize or configure toolbars.
Definition: kedittoolbar.h:269
KXMLGUIClient::instance
virtual TDEInstance * instance() const
Definition: kxmlguiclient.cpp:123
KEditToolbarWidget::enableOk
void enableOk(bool)
Emitted whenever any modifications are made by the user.
TDEProcess
endl
kndbgstream & endl(kndbgstream &s)
locate
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
KProcIO
KEditToolbarWidget::~KEditToolbarWidget
virtual ~KEditToolbarWidget()
Destructor.
Definition: kedittoolbar.cpp:591
TDEStdAccel::name
TQString name(StdAccel id)
TDEActionCollection::count
virtual uint count() const
Returns the TDEAccel object associated with widget #.
Definition: tdeactioncollection.cpp:418
TDEInstance
KXMLGUIClient::xmlFile
virtual TQString xmlFile() const
This will return the name of the XML file as set by setXMLFile().
Definition: kxmlguiclient.cpp:133
TDEAction::iconSet
virtual TQIconSet iconSet(TDEIcon::Group group, int size=0) const
Get the TQIconSet from which the icons used to display this action will be chosen.
Definition: tdeaction.cpp:1001
KEditToolbar::slotOk
virtual void slotOk()
Overridden in order to save any changes made to the toolbars.
Definition: kedittoolbar.cpp:509

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.