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

kdeui

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

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |