• 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
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, 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  ToolbarItem *item = dynamic_cast<ToolbarItem*>(selectedItem());
189  if ( item ) {
190  ToolbarItemDrag *obj = new 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 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 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 == XmlData::Shell ) ||
297  ( xmlData.m_type == 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 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  XmlDataList::Iterator xit = m_xmlFiles.begin();
325  for ( ; xit != m_xmlFiles.end(); ++xit )
326  {
327  kdDebug(240) << "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  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  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  XmlData local;
613  local.m_xmlFile = d->xmlFile(file);
614  local.m_type = 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  XmlData merge;
623  merge.m_xmlFile = TQString::null;
624  merge.m_type = 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  XmlData data;
658  data.m_xmlFile = client->localXMLFile();
659  if ( it.atFirst() )
660  data.m_type = XmlData::Shell;
661  else
662  data.m_type = 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  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 == 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 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 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  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 == 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  ToolbarItem *act = new 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  ToolbarItem *act = new 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  ToolbarItem *act = new 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  ToolbarItem *act = new 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  else // Has iconset
1023  act->setPixmap(0, action->iconSet(KIcon::Toolbar).pixmap());
1024 
1025  active_list.insert(action->name(), true);
1026  break;
1027  }
1028  }
1029  }
1030 
1031  // go through the rest of the collection
1032  for (int i = actionCollection->count() - 1; i > -1; --i)
1033  {
1034  KAction *action = actionCollection->action( i );
1035 
1036  // skip our active ones
1037  if (active_list.contains(action->name()))
1038  continue;
1039 
1040  ToolbarItem *act = new ToolbarItem(m_inactiveList, tagActionList, action->name(), action->toolTip());
1041  act->setText(1, action->plainText());
1042  if (action->hasIcon())
1043  if (!action->icon().isEmpty())
1044  act->setPixmap(0, loader->loadIcon(action->icon(), KIcon::Toolbar, 16, KIcon::DefaultState, 0, true) );
1045  else // Has iconset
1046  act->setPixmap(0, action->iconSet(KIcon::Toolbar).pixmap());
1047  }
1048 
1049  // finally, add default separators to the inactive list
1050  ToolbarItem *act = new ToolbarItem(m_inactiveList, tagSeparator, sep_name.arg(sep_num++), TQString::null);
1051  act->setText(1, LINESEPARATORSTRING);
1052  act = new ToolbarItem(m_inactiveList, tagSeparator, sep_name.arg(sep_num++), TQString::null);
1053  act->setText(1, SEPARATORSTRING);
1054 }
1055 
1056 KActionCollection *KEditToolbarWidget::actionCollection() const
1057 {
1058  return d->m_collection;
1059 }
1060 
1061 void KEditToolbarWidget::slotToolbarSelected(const TQString& _text)
1062 {
1063  // iterate through everything
1064  XmlDataList::Iterator xit = d->m_xmlFiles.begin();
1065  for ( ; xit != d->m_xmlFiles.end(); ++xit)
1066  {
1067  // each xml file may have any number of toolbars
1068  ToolbarList::Iterator it = (*xit).m_barList.begin();
1069  for ( ; it != (*xit).m_barList.end(); ++it)
1070  {
1071  TQString name = d->toolbarName( *xit, *it );
1072  // is this our toolbar?
1073  if ( name == _text )
1074  {
1075  // save our current settings
1076  d->m_currentXmlData = & (*xit);
1077  d->m_currentToolbarElem = (*it);
1078 
1079  // load in our values
1080  loadActionList(d->m_currentToolbarElem);
1081 
1082  if ((*xit).m_type == XmlData::Part || (*xit).m_type == XmlData::Shell)
1083  setDOMDocument( (*xit).m_document );
1084  return;
1085  }
1086  }
1087  }
1088 }
1089 
1090 void KEditToolbarWidget::slotInactiveSelected(TQListViewItem *item)
1091 {
1092  ToolbarItem* toolitem = static_cast<ToolbarItem *>(item);
1093  if (item)
1094  {
1095  m_insertAction->setEnabled(true);
1096  TQString statusText = toolitem->statusText();
1097  d->m_helpArea->setText( statusText );
1098  }
1099  else
1100  {
1101  m_insertAction->setEnabled(false);
1102  d->m_helpArea->setText( TQString::null );
1103  }
1104 }
1105 
1106 void KEditToolbarWidget::slotActiveSelected(TQListViewItem *item)
1107 {
1108  ToolbarItem* toolitem = static_cast<ToolbarItem *>(item);
1109  m_removeAction->setEnabled( item );
1110 
1111  static const TQString &tagAction = KGlobal::staticQString( "Action" );
1112  d->m_changeIcon->setEnabled( item &&
1113  d->m_hasKDialog &&
1114  toolitem->internalTag() == tagAction );
1115 
1116  if (item)
1117  {
1118  if (item->itemAbove())
1119  m_upAction->setEnabled(true);
1120  else
1121  m_upAction->setEnabled(false);
1122 
1123  if (item->itemBelow())
1124  m_downAction->setEnabled(true);
1125  else
1126  m_downAction->setEnabled(false);
1127  TQString statusText = toolitem->statusText();
1128  d->m_helpArea->setText( statusText );
1129  }
1130  else
1131  {
1132  m_upAction->setEnabled(false);
1133  m_downAction->setEnabled(false);
1134  d->m_helpArea->setText( TQString::null );
1135  }
1136 }
1137 
1138 void KEditToolbarWidget::slotDropped(KListView *list, TQDropEvent *e, TQListViewItem *after)
1139 {
1140  ToolbarItem *item = new ToolbarItem(m_inactiveList); // needs parent, use inactiveList temporarily
1141  if(!ToolbarItemDrag::decode(e, *item)) {
1142  delete item;
1143  return;
1144  }
1145 
1146  if (list == m_activeList) {
1147  if (e->source() == m_activeList) {
1148  // has been dragged within the active list (moved).
1149  moveActive(item, after);
1150  }
1151  else
1152  insertActive(item, after, true);
1153  } else if (list == m_inactiveList) {
1154  // has been dragged to the inactive list -> remove from the active list.
1155  removeActive(item);
1156  }
1157 
1158  delete item; item = 0; // not neded anymore
1159 
1160  // we're modified, so let this change
1161  emit enableOk(true);
1162 
1163  slotToolbarSelected( m_toolbarCombo->currentText() );
1164 }
1165 
1166 void KEditToolbarWidget::slotInsertButton()
1167 {
1168  ToolbarItem *item = (ToolbarItem*)m_inactiveList->currentItem();
1169  insertActive(item, m_activeList->currentItem(), false);
1170 
1171  // we're modified, so let this change
1172  emit enableOk(true);
1173 
1174  // TODO: #### this causes #97572.
1175  // It would be better to just "delete item; loadActions( ... , ActiveListOnly );" or something.
1176  slotToolbarSelected( m_toolbarCombo->currentText() );
1177 }
1178 
1179 void KEditToolbarWidget::slotRemoveButton()
1180 {
1181  removeActive( dynamic_cast<ToolbarItem*>(m_activeList->currentItem()) );
1182 
1183  // we're modified, so let this change
1184  emit enableOk(true);
1185 
1186  slotToolbarSelected( m_toolbarCombo->currentText() );
1187 }
1188 
1189 void KEditToolbarWidget::insertActive(ToolbarItem *item, TQListViewItem *before, bool prepend)
1190 {
1191  if (!item)
1192  return;
1193 
1194  static const TQString &tagAction = KGlobal::staticQString( "Action" );
1195  static const TQString &tagSeparator = KGlobal::staticQString( "Separator" );
1196  static const TQString &attrName = KGlobal::staticQString( "name" );
1197  static const TQString &attrLineSeparator = KGlobal::staticQString( "lineSeparator" );
1198  static const TQString &attrNoMerge = KGlobal::staticQString( "noMerge" );
1199 
1200  TQDomElement new_item;
1201  // let's handle the separator specially
1202  if (item->text(1) == LINESEPARATORSTRING) {
1203  new_item = domDocument().createElement(tagSeparator);
1204  } else if (item->text(1) == SEPARATORSTRING) {
1205  new_item = domDocument().createElement(tagSeparator);
1206  new_item.setAttribute(attrLineSeparator, "false");
1207  } else
1208  new_item = domDocument().createElement(tagAction);
1209  new_item.setAttribute(attrName, item->internalName());
1210 
1211  if (before)
1212  {
1213  // we have the item in the active list which is before the new
1214  // item.. so let's try our best to add our new item right after it
1215  ToolbarItem *act_item = (ToolbarItem*)before;
1216  TQDomElement elem = d->findElementForToolbarItem( act_item );
1217  Q_ASSERT( !elem.isNull() );
1218  d->m_currentToolbarElem.insertAfter(new_item, elem);
1219  }
1220  else
1221  {
1222  // simply put it at the beginning or the end of the list.
1223  if (prepend)
1224  d->m_currentToolbarElem.insertBefore(new_item, d->m_currentToolbarElem.firstChild());
1225  else
1226  d->m_currentToolbarElem.appendChild(new_item);
1227  }
1228 
1229  // and set this container as a noMerge
1230  d->m_currentToolbarElem.setAttribute( attrNoMerge, "1");
1231 
1232  // update the local doc
1233  updateLocal(d->m_currentToolbarElem);
1234 }
1235 
1236 void KEditToolbarWidget::removeActive(ToolbarItem *item)
1237 {
1238  if (!item)
1239  return;
1240 
1241  static const TQString &attrNoMerge = KGlobal::staticQString( "noMerge" );
1242 
1243  // we're modified, so let this change
1244  emit enableOk(true);
1245 
1246  // now iterate through to find the child to nuke
1247  TQDomElement elem = d->findElementForToolbarItem( item );
1248  if ( !elem.isNull() )
1249  {
1250  // nuke myself!
1251  d->m_currentToolbarElem.removeChild(elem);
1252 
1253  // and set this container as a noMerge
1254  d->m_currentToolbarElem.setAttribute( attrNoMerge, "1");
1255 
1256  // update the local doc
1257  updateLocal(d->m_currentToolbarElem);
1258  }
1259 }
1260 
1261 void KEditToolbarWidget::slotUpButton()
1262 {
1263  ToolbarItem *item = (ToolbarItem*)m_activeList->currentItem();
1264 
1265  // make sure we're not the top item already
1266  if (!item->itemAbove())
1267  return;
1268 
1269  // we're modified, so let this change
1270  emit enableOk(true);
1271 
1272  moveActive( item, item->itemAbove()->itemAbove() );
1273  delete item;
1274 }
1275 
1276 void KEditToolbarWidget::moveActive( ToolbarItem* item, TQListViewItem* before )
1277 {
1278  TQDomElement e = d->findElementForToolbarItem( item );
1279 
1280  if ( e.isNull() )
1281  return;
1282 
1283  // cool, i found me. now clone myself
1284  ToolbarItem *clone = new ToolbarItem(m_activeList,
1285  before,
1286  item->internalTag(),
1287  item->internalName(),
1288  item->statusText());
1289 
1290  clone->setText(1, item->text(1));
1291 
1292  // only set new pixmap if exists
1293  if( item->pixmap(0) )
1294  clone->setPixmap(0, *item->pixmap(0));
1295 
1296  // select my clone
1297  m_activeList->setSelected(clone, true);
1298 
1299  // make clone visible
1300  m_activeList->ensureItemVisible(clone);
1301 
1302  // and do the real move in the DOM
1303  if ( !before )
1304  d->m_currentToolbarElem.insertBefore(e, d->m_currentToolbarElem.firstChild() );
1305  else
1306  d->m_currentToolbarElem.insertAfter(e, d->findElementForToolbarItem( (ToolbarItem*)before ));
1307 
1308  // and set this container as a noMerge
1309  static const TQString &attrNoMerge = KGlobal::staticQString( "noMerge" );
1310  d->m_currentToolbarElem.setAttribute( attrNoMerge, "1");
1311 
1312  // update the local doc
1313  updateLocal(d->m_currentToolbarElem);
1314 }
1315 
1316 void KEditToolbarWidget::slotDownButton()
1317 {
1318  ToolbarItem *item = (ToolbarItem*)m_activeList->currentItem();
1319 
1320  // make sure we're not the bottom item already
1321  if (!item->itemBelow())
1322  return;
1323 
1324  // we're modified, so let this change
1325  emit enableOk(true);
1326 
1327  moveActive( item, item->itemBelow() );
1328  delete item;
1329 }
1330 
1331 void KEditToolbarWidget::updateLocal(TQDomElement& elem)
1332 {
1333  static const TQString &attrName = KGlobal::staticQString( "name" );
1334 
1335  XmlDataList::Iterator xit = d->m_xmlFiles.begin();
1336  for ( ; xit != d->m_xmlFiles.end(); ++xit)
1337  {
1338  if ( (*xit).m_type == XmlData::Merged )
1339  continue;
1340 
1341  if ( (*xit).m_type == XmlData::Shell ||
1342  (*xit).m_type == XmlData::Part )
1343  {
1344  if ( d->m_currentXmlData->m_xmlFile == (*xit).m_xmlFile )
1345  {
1346  (*xit).m_isModified = true;
1347  return;
1348  }
1349 
1350  continue;
1351  }
1352 
1353  (*xit).m_isModified = true;
1354 
1355  ToolbarList::Iterator it = (*xit).m_barList.begin();
1356  for ( ; it != (*xit).m_barList.end(); ++it)
1357  {
1358  TQString name( (*it).attribute( attrName ) );
1359  TQString tag( (*it).tagName() );
1360  if ( (tag != elem.tagName()) || (name != elem.attribute(attrName)) )
1361  continue;
1362 
1363  TQDomElement toolbar = (*xit).m_document.documentElement().toElement();
1364  toolbar.replaceChild(elem, (*it));
1365  return;
1366  }
1367 
1368  // just append it
1369  TQDomElement toolbar = (*xit).m_document.documentElement().toElement();
1370  toolbar.appendChild(elem);
1371  }
1372 }
1373 
1374 void KEditToolbarWidget::slotChangeIcon()
1375 {
1376  // We can't use KIconChooser here, since it's in libkio
1377  // ##### KDE4: reconsider this, e.g. move KEditToolbar to libkio
1378 
1379  //if the process is already running (e.g. when somebody clicked the change button twice (see #127149)) - do nothing...
1380  //otherwise m_kdialogProcess will be overwritten and set to zero in slotProcessExited()...crash!
1381  if ( d->m_kdialogProcess && d->m_kdialogProcess->isRunning() )
1382  return;
1383 
1384  d->m_kdialogProcess = new KProcIO;
1385  TQString kdialogExe = KStandardDirs::findExe(TQString::fromLatin1("kdialog"));
1386  (*d->m_kdialogProcess) << kdialogExe;
1387  (*d->m_kdialogProcess) << "--embed";
1388  (*d->m_kdialogProcess) << TQString::number( (ulong)topLevelWidget()->winId() );
1389  (*d->m_kdialogProcess) << "--geticon";
1390  (*d->m_kdialogProcess) << "Toolbar";
1391  (*d->m_kdialogProcess) << "Actions";
1392  if ( !d->m_kdialogProcess->start( KProcess::NotifyOnExit ) ) {
1393  kdError(240) << "Can't run " << kdialogExe << endl;
1394  delete d->m_kdialogProcess;
1395  d->m_kdialogProcess = 0;
1396  return;
1397  }
1398 
1399  m_activeList->setEnabled( false ); // don't change the current item
1400  m_toolbarCombo->setEnabled( false ); // don't change the current toolbar
1401 
1402  connect( d->m_kdialogProcess, TQT_SIGNAL( processExited( KProcess* ) ),
1403  this, TQT_SLOT( slotProcessExited( KProcess* ) ) );
1404 }
1405 
1406 void KEditToolbarWidget::slotProcessExited( KProcess* )
1407 {
1408  m_activeList->setEnabled( true );
1409  m_toolbarCombo->setEnabled( true );
1410 
1411  TQString icon;
1412 
1413  if (!d->m_kdialogProcess) {
1414  kdError(240) << "Something is wrong here! m_kdialogProcess is zero!" << endl;
1415  return;
1416  }
1417 
1418  if ( !d->m_kdialogProcess->normalExit() ||
1419  d->m_kdialogProcess->exitStatus() ||
1420  d->m_kdialogProcess->readln(icon, true) <= 0 ) {
1421  delete d->m_kdialogProcess;
1422  d->m_kdialogProcess = 0;
1423  return;
1424  }
1425 
1426  ToolbarItem *item = (ToolbarItem*)m_activeList->currentItem();
1427  if(item){
1428  item->setPixmap(0, BarIcon(icon, 16));
1429 
1430  Q_ASSERT( d->m_currentXmlData->m_type != XmlData::Merged );
1431 
1432  d->m_currentXmlData->m_isModified = true;
1433 
1434  // Get hold of ActionProperties tag
1435  TQDomElement elem = KXMLGUIFactory::actionPropertiesElement( d->m_currentXmlData->m_document );
1436  // Find or create an element for this action
1437  TQDomElement act_elem = KXMLGUIFactory::findActionByName( elem, item->internalName(), true /*create*/ );
1438  Q_ASSERT( !act_elem.isNull() );
1439  act_elem.setAttribute( "icon", icon );
1440 
1441  // we're modified, so let this change
1442  emit enableOk(true);
1443  }
1444 
1445  delete d->m_kdialogProcess;
1446  d->m_kdialogProcess = 0;
1447 }
1448 
1449 void KEditToolbar::virtual_hook( int id, void* data )
1450 { KDialogBase::virtual_hook( id, data ); }
1451 
1452 void KEditToolbarWidget::virtual_hook( int id, void* data )
1453 { KXMLGUIClient::virtual_hook( id, data ); }
1454 
1455 #include "kedittoolbar.moc"

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.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |