[Kde-pim] KDE/kdepim

David Faure faure at kde.org
Fri Sep 25 10:47:54 BST 2009


SVN commit 1027982 by dfaure:

Better solution for hiding specific actions in kontact: tagging them in the xml
and removing them from the xml dynamically, so that they don't appear in "Configure Toolbars"
(but so that it's still possible to manually add them).
I still need to convert the other plugins to this system, but this solves 207296 at least.
CCMAIL: kde-pim at kde.org
BUG: 207296


 M  +2 -2      kaddressbook/kaddressbookui.rc  
 M  +5 -7      kontact/plugins/kaddressbook/kaddressbook_plugin.cpp  
 M  +1 -1      kontact/plugins/kaddressbook/kaddressbook_plugin.h  
 M  +47 -12    kontact/src/mainwindow.cpp  
 M  +1 -0      kontact/src/mainwindow.h  


--- trunk/KDE/kdepim/kaddressbook/kaddressbookui.rc #1027981:1027982
@@ -5,8 +5,8 @@
     <Menu name="file"><text>&File</text>
       <Menu name="file_new">
         <text>&New</text>
-        <Action name="akonadi_contact_create"/>
-        <Action name="akonadi_contact_group_create"/>
+        <Action name="akonadi_contact_create" remove_in_kontact="true"/>
+        <Action name="akonadi_contact_group_create" remove_in_kontact="true"/>
         <Separator/>
         <Action name="akonadi_addressbook_create"/>
       </Menu>
--- trunk/KDE/kdepim/kontact/plugins/kaddressbook/kaddressbook_plugin.cpp #1027981:1027982
@@ -129,14 +129,12 @@
   return mUniqueAppWatcher->isRunningStandalone();
 }
 
-QStringList KAddressBookPlugin::invisibleToolbarActions() const
-{
-  QStringList actions;
-  actions << "akonadi_contact_create" << "akonadi_contact_group_create";
+//QStringList KAddressBookPlugin::invisibleToolbarActions() const
+//{
+  //QStringList actions;
+  //return actions;
+//}
 
-  return actions;
-}
-
 void KAddressBookPlugin::slotSyncContacts()
 {
   QDBusMessage message =
--- trunk/KDE/kdepim/kontact/plugins/kaddressbook/kaddressbook_plugin.h #1027981:1027982
@@ -46,7 +46,7 @@
     virtual bool isRunningStandalone() const;
     int weight() const { return 300; }
 
-    virtual QStringList invisibleToolbarActions() const;
+    //virtual QStringList invisibleToolbarActions() const;
 
   protected:
     KParts::ReadOnlyPart *createPart();
--- trunk/KDE/kdepim/kontact/src/mainwindow.cpp #1027981:1027982
@@ -829,6 +829,8 @@
       syncAction = plugin->syncActions().first();
     }
 
+    removeInvisibleToolbarActions(plugin);
+
     createGUI( plugin->part() );
 
     setCaption( i18nc( "Plugin dependent window title", "%1 - Kontact", plugin->title() ) );
@@ -871,19 +873,7 @@
       }
     }
   }
-  const QStringList invisibleActions = plugin->invisibleToolbarActions();
 
-  QStringList::ConstIterator it;
-  for ( it = invisibleActions.constBegin(); it != invisibleActions.constEnd(); ++it ) {
-    QAction *action = part->actionCollection()->action( (*it) );
-    if ( action ) {
-      QList<KToolBar*> toolbars = toolBars();
-      for ( QList<KToolBar*>::Iterator it = toolbars.begin(); it != toolbars.end(); ++it ) {
-        ( *it )->removeAction( action );
-      }
-    }
-  }
-
   KToolBar *navigatorToolBar = findToolBar( "navigatorToolBar" );
   if ( navigatorToolBar && !navigatorToolBar->isHidden() &&
        ( toolBarArea( navigatorToolBar ) == Qt::TopToolBarArea ||
@@ -897,6 +887,50 @@
   QApplication::restoreOverrideCursor();
 }
 
+// Hack to access KXMLGUIClient::setDOMDocument which should be public...
+class ReadOnlyPartAccess : public KParts::ReadOnlyPart
+{
+  public:
+  using KParts::ReadOnlyPart::setDOMDocument;
+};
+
+void MainWindow::removeInvisibleToolbarActions(Plugin* plugin)
+{
+  // Hide unwanted toolbar action by modifying the XML before createGUI, rather than
+  // doing it by calling removeAction on the toolbar after createGUI. Both solutions
+  // work visually, but only modifying the XML ensures that the actions don't appear
+  // in "edit toolbars". #207296
+  KParts::Part *part = plugin->part();
+  const QStringList hideActions = plugin->invisibleToolbarActions();
+  //kDebug() << "Hiding actions" << hideActions;
+  QDomDocument doc = part->domDocument();
+  QDomElement docElem = doc.documentElement();
+  // 1. Iterate over containers
+  for (QDomElement containerElem = docElem.firstChildElement();
+       !containerElem.isNull(); containerElem = containerElem.nextSiblingElement()) {
+    if (QString::compare(containerElem.tagName(), "ToolBar", Qt::CaseInsensitive) == 0) {
+      // 2. Iterate over actions in toolbars
+      QDomElement actionElem = containerElem.firstChildElement();
+      while (!actionElem.isNull()) {
+        QDomElement nextActionElem = actionElem.nextSiblingElement();
+        if (actionElem.attribute("remove_in_kontact") == "true") {
+            containerElem.removeChild(actionElem);
+        }
+        if (QString::compare(actionElem.tagName(), "Action", Qt::CaseInsensitive) == 0) {
+          //kDebug() << "Looking at action" << actionElem.attribute("name");
+          if (hideActions.contains(actionElem.attribute("name"))) {
+            //kDebug() << "REMOVING";
+            containerElem.removeChild(actionElem);
+          }
+        }
+        actionElem = nextActionElem;
+      }
+    }
+  }
+  //kDebug() << doc.toString();
+  static_cast<ReadOnlyPartAccess *>(part)->setDOMDocument(doc);
+}
+
 void MainWindow::slotActionTriggered()
 {
   KAction *actionSender = static_cast<KAction*>( sender() );
@@ -1072,6 +1106,7 @@
 void MainWindow::slotNewToolbarConfig()
 {
   if ( mCurrentPlugin && mCurrentPlugin->part() ) {
+    removeInvisibleToolbarActions(mCurrentPlugin);
     createGUI( mCurrentPlugin->part() );
   }
   if ( mCurrentPlugin ) {
--- trunk/KDE/kdepim/kontact/src/mainwindow.h #1027981:1027982
@@ -98,6 +98,7 @@
     void initAboutScreen();
     void loadSettings();
     void saveSettings();
+    void removeInvisibleToolbarActions(Plugin* plugin);
 
     bool isPluginLoaded( const KPluginInfo & );
     KontactInterface::Plugin *pluginFromInfo( const KPluginInfo & );
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list