[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: kdebase/libkonq
From:       "Sashmit B. Bhaduri" <gtg850g () mail ! gatech ! edu>
Date:       2003-06-16 20:23:40
[Download RAW message or body]

On Mon, 16 Jun 2003, David Faure wrote:

> I guess the main difference is that the new subdir would be visible in a tree view,
> and not visible in an iconview or flat listview. Maybe something like
> KonqPopupMenu::setDirectoryViewIsHierarchical(bool) (a separate method
> since we can't add a constructor argument in a BC way).
> If this is called with "true" (default would be false), by the sidebar and the treeview,
> then the code you removed and readded, can check for that bool.
> What do you think?


I like the idea, but I guess you would need to prepend the action (not a
problem on to itself), AFTER KonqPopupMenu's ctor's calls
KonqPopupMenu::setup which in turn calls KXMLGUIFactory::addClient on it's
factory object. If KXMLGUIFactory::addClient isn't called, the menu isn't
updated with the new action.. if it is called, you get the original menu,
with everything merged in, then the new action, and then the whole menu
again. If KXMLGUIFactory::removeClient is called, Konq segfaults. If
setup() is called, it also does.

I have a patch that implements all of the rest of the work, but I can't
get seemed to this properly. If there was way to state whether the menu
was hierarchical in the ctor, none of this would be a problem, of course.

Can you think of any way to solve this problem? Patch is attached.

thanks,
Sashmit


["kdelibs.patch" (TEXT/PLAIN)]

Index: kparts/browserview.desktop
===================================================================
RCS file: /home/kde/kdelibs/kparts/browserview.desktop,v
retrieving revision 1.147
diff -u -b -w -B -r1.147 browserview.desktop
--- kparts/browserview.desktop	20 Mar 2003 05:50:10 -0000	1.147
+++ kparts/browserview.desktop	16 Jun 2003 20:17:03 -0000
@@ -72,6 +72,9 @@
 [PropertyDef::X-KDE-BrowserView-LinkedView]
 Type=bool
 
+[PropertyDef::X-KDE-BrowserView-HierarchicalView]
+Type=bool
+
 [PropertyDef::X-KDE-BrowserView-PassiveMode]
 Type=bool
 

["kdebase.patch" (TEXT/PLAIN)]

Index: libkonq/konq_popupmenu.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_popupmenu.cc,v
retrieving revision 1.150
diff -u -b -w -B -r1.150 konq_popupmenu.cc
--- libkonq/konq_popupmenu.cc	15 Jun 2003 17:28:19 -0000	1.150
+++ libkonq/konq_popupmenu.cc	16 Jun 2003 20:16:21 -0000
@@ -73,9 +73,13 @@
 class KonqPopupMenu::KonqPopupMenuPrivate
 {
 public:
-  KonqPopupMenuPrivate() : m_parentWidget(0) {}
+  KonqPopupMenuPrivate() : m_parentWidget(0) 
+  {
+    m_hierarchicalDirectoryView=false;
+  }
   QString m_urlTitle;
   QWidget *m_parentWidget;
+  bool m_hierarchicalDirectoryView;
 };
 
 KonqPopupMenu::ProtocolInfo::ProtocolInfo( )
@@ -313,11 +317,14 @@
       }
       else
       {
+        if ( d->m_hierarchicalDirectoryView) // this most likely will never be true \
at this point +        {
         KAction *actNewDir = new KAction( i18n( "Create Director&y..." ), \
"folder_new", 0, this, SLOT( slotPopupNewDir() ), &m_ownActions, "newdir" );  \
addAction( actNewDir );  addSeparator();
       }
     }
+    }
 
     // hack for khtml pages/frames
     bool httpPage = (m_sViewURL.protocol().find("http", 0, false) == 0);
@@ -675,6 +682,35 @@
 void KonqPopupMenu::setURLTitle( const QString& urlTitle )
 {
     d->m_urlTitle = urlTitle;
+}
+
+void KonqPopupMenu::setDirectoryViewIsHierarchical( bool hierarchialView, bool \
addAct ) +{
+    kdDebug(1203) << "KonqPopupMenu setDirectoryViewIsHierarchical = " << \
hierarchialView << endl; +    d->m_hierarchicalDirectoryView=hierarchialView;
+    if (hierarchialView && addAct)
+    {
+        mode_t mode         = m_lstItems.first()->mode();
+        bool currentDir = false;
+        if ( m_lstItems.count() == 1 )
+        {
+            KURL firstPopupURL ( m_lstItems.first()->url() );
+            KURL url = m_sViewURL;
+	    url.cleanPath();
+	    firstPopupURL.cleanPath();
+            currentDir = firstPopupURL.cmp( url, true /* ignore_trailing */ );
+        }
+	if ( S_ISDIR(mode) && m_info.m_Writing && !currentDir)
+	{
+            kdDebug(1203) << "KonqPopupMenu adding hierarchical actions" << endl;
+	
+	    //m_factory->removeClient( this );
+	    KAction *actNewDir = new KAction( i18n( "Create Director&y..." ),
+               "folder_new", 0, this, SLOT( slotPopupNewDir() ), &m_ownActions, \
"newdir" ); +            prependAction(actNewDir);
+	    m_factory->addClient( this );
+	}
+    }
 }
 
 void KonqPopupMenu::slotPopupNewView()
Index: libkonq/konq_popupmenu.h
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_popupmenu.h,v
retrieving revision 1.42
diff -u -b -w -B -r1.42 konq_popupmenu.h
--- libkonq/konq_popupmenu.h	19 May 2003 17:24:46 -0000	1.42
+++ libkonq/konq_popupmenu.h	16 Jun 2003 20:16:21 -0000
@@ -90,6 +90,16 @@
    */
   void setURLTitle( const QString& urlTitle );
 
+
+  /**
+   * Set whether a given directory view is hierarchical.
+   * This is used to determine whether or not to add actions that are only
+   * applicable in hierarchical views and not in icon or flat listviews.
+   */
+  
+  void setDirectoryViewIsHierarchical(bool hierarchialView, bool addAct=false);
+
+  
   class ProtocolInfo {
    public:
     ProtocolInfo();
Index: libkonq/konq_xmlguiclient.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_xmlguiclient.cc,v
retrieving revision 1.5
diff -u -b -w -B -r1.5 konq_xmlguiclient.cc
--- libkonq/konq_xmlguiclient.cc	12 Jan 2003 16:21:39 -0000	1.5
+++ libkonq/konq_xmlguiclient.cc	16 Jun 2003 20:16:22 -0000
@@ -102,5 +102,28 @@
   group.setAttribute( "name", grp );
 }
 
+void KonqXMLGUIClient::prependAction( KAction *act, const QDomElement &menu )
+{
+  prependAction( act->name(), menu );
+}
+
+void KonqXMLGUIClient::prependAction( const char *name, const QDomElement &menu )
+{
+  static QString tagAction = QString::fromLatin1( "action" );
+
+  if (!kapp->authorizeKAction(name))
+     return;
+
+  QDomElement parent = menu;
+  if ( parent.isNull() )
+    parent = m_menuElement;
+
+  QDomElement e = m_doc.createElement( tagAction );
+  parent.insertBefore( e, parent.firstChild() );
+  e.setAttribute( attrName, name );
+}
+
+
+
 KonqXMLGUIClient::~KonqXMLGUIClient( ){
 }
Index: libkonq/konq_xmlguiclient.h
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_xmlguiclient.h,v
retrieving revision 1.2
diff -u -b -w -B -r1.2 konq_xmlguiclient.h
--- libkonq/konq_xmlguiclient.h	2 Dec 2001 19:10:42 -0000	1.2
+++ libkonq/konq_xmlguiclient.h	16 Jun 2003 20:16:22 -0000
@@ -47,6 +47,10 @@
   void addSeparator( const QDomElement &menu = QDomElement() );
   void addGroup( const QString &grp );
   void addMerge( const QString &name );
+
+  void prependAction( KAction *act, const QDomElement &menu = QDomElement() );
+  void prependAction( const char *name, const QDomElement &menu = QDomElement() );
+
 	void prepareXMLGUIStuff();
   QDomDocument m_doc;
   QDomElement m_menuElement;
Index: konqueror/konq_mainwindow.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.cc,v
retrieving revision 1.1185
diff -u -b -w -B -r1.1185 konq_mainwindow.cc
--- konqueror/konq_mainwindow.cc	10 Jun 2003 11:34:24 -0000	1.1185
+++ konqueror/konq_mainwindow.cc	16 Jun 2003 20:16:44 -0000
@@ -3801,6 +3801,9 @@
   if ( openedForViewURL && !viewURL.isLocalFile() )
       pPopupMenu.setURLTitle( m_currentView->caption() );
 
+  
+  pPopupMenu.setDirectoryViewIsHierarchical( m_currentView->isHierarchicalView(), \
true ); +  
   // We will need these if we call the newTab slot
   popupItems = _items;
 
Index: konqueror/konq_view.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_view.cc,v
retrieving revision 1.332
diff -u -b -w -B -r1.332 konq_view.cc
--- konqueror/konq_view.cc	10 Jun 2003 11:34:24 -0000	1.332
+++ konqueror/konq_view.cc	16 Jun 2003 20:16:49 -0000
@@ -89,6 +89,7 @@
   m_bLinkedView = false;
   m_bAborted = false;
   m_bToggleView = false;
+  m_bHierarchicalView = false;
   m_bGotIconURL = false;
   m_bPopupMenuEnabled = true;
   m_browserIface = new KonqBrowserInterface( this, "browseriface" );
@@ -245,6 +246,17 @@
       setPassiveMode( true ); // set as passive
     }
 
+    prop = m_service->property( "X-KDE-BrowserView-HierarchicalView");
+    if ( prop.isValid() && prop.toBool() )
+    {
+      kdDebug() << "KonqView::switchView X-KDE-BrowserView-HierarchicalView -> \
setHierarchicalView" << endl;	     +      setHierarchicalView( true );
+    }
+    else
+    {
+	    setHierarchicalView( false );//TODO: check
+    }
+    
     // Honour "linked view"
     prop = m_service->property( "X-KDE-BrowserView-LinkedView");
     if ( prop.isValid() && prop.toBool() )
@@ -836,6 +848,13 @@
   // Update statusbar stuff
   m_pMainWindow->viewManager()->viewCountChanged();
 }
+
+void KonqView::setHierarchicalView( bool mode )
+{
+ m_bHierarchicalView=mode;
+}
+		
+
 
 void KonqView::setLinkedView( bool mode )
 {
Index: konqueror/konq_view.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_view.h,v
retrieving revision 1.160
diff -u -b -w -B -r1.160 konq_view.h
--- konqueror/konq_view.h	7 Mar 2003 22:05:52 -0000	1.160
+++ konqueror/konq_view.h	16 Jun 2003 20:16:51 -0000
@@ -229,6 +229,10 @@
   bool isPassiveMode() const { return m_bPassiveMode; }
   void setPassiveMode( bool mode );
 
+  // True if is hierarchical view
+  bool isHierarchicalView() const { return m_bHierarchicalView; }
+  void setHierarchicalView( bool mode );
+
   // True if 'link' symbol set
   bool isLinkedView() const { return m_bLinkedView; }
   void setLinkedView( bool mode );
@@ -412,6 +416,7 @@
   KonqViewIface * m_dcopObject;
   KonqBrowserInterface *m_browserIface;
   bool m_bBackRightClick;
+  bool m_bHierarchicalView;
   int m_randID;
 };
 
Index: konqueror/listview/konq_treeview.desktop
===================================================================
RCS file: /home/kde/kdebase/konqueror/listview/konq_treeview.desktop,v
retrieving revision 1.188
diff -u -b -w -B -r1.188 konq_treeview.desktop
--- konqueror/listview/konq_treeview.desktop	31 May 2003 05:22:42 -0000	1.188
+++ konqueror/listview/konq_treeview.desktop	16 Jun 2003 20:16:53 -0000
@@ -63,5 +63,6 @@
 X-KDE-Library=konq_listview
 X-KDE-BrowserView-Args=MixedTree
 X-KDE-BrowserView-HideFromMenus=true
+X-KDE-BrowserView-HierarchicalView=true
 Icon=view_tree
 InitialPreference=8
Index: konqueror/sidebar/konq_sidebartng.desktop
===================================================================
RCS file: /home/kde/kdebase/konqueror/sidebar/konq_sidebartng.desktop,v
retrieving revision 1.102
diff -u -b -w -B -r1.102 konq_sidebartng.desktop
--- konqueror/sidebar/konq_sidebartng.desktop	27 May 2003 07:39:30 -0000	1.102
+++ konqueror/sidebar/konq_sidebartng.desktop	16 Jun 2003 20:16:54 -0000
@@ -62,5 +62,6 @@
 X-KDE-BrowserView-Toggable=true
 X-KDE-BrowserView-ToggableView-Orientation=vertical
 X-KDE-BrowserView-ToggableView-NoHeader=true
+X-KDE-BrowserView-HierarchicalView=true
 X-KDE-BrowserView-FollowActive=true
 X-KDE-BrowserView-LinkedView=false



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic