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

List:       kfm-devel
Subject:    PATCH: Open With...
From:       "Dawit A." <adawit () kde ! org>
Date:       2002-07-14 18:27:01
[Download RAW message or body]

Hello,

Here is a patch that changes/fixes a couple of things in the Open With... 
dialog box:

- Follow the "Open With->" format even if only one application is associated 
with a given mime-type.  I guess this is a matter of preference, but it would 
make the behavior consistent plus reduce the real-state the popup menu 
occupies.

- Make sure that separators are added properly.  Currently there were 
cuircumstances where a double/triple separators were being drawn. The
way to make sure this does not happen is to only add separators "before"
adding new menu items, never "after".  The culprit for the above problem were 
the plugins, specifically the kuick plugin.  As such, with the patch attached 
below, a plugin no longer needs to add any separator unless it specifically 
needs to separate its own items...

Regards,
Dawit A.

["konq_popupmenu.diff" (text/x-diff)]

Index: konq_popupmenu.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_popupmenu.cc,v
retrieving revision 1.120
diff -u -p -b -B -w -r1.120 konq_popupmenu.cc
--- konq_popupmenu.cc	2002/06/17 10:52:42	1.120
+++ konq_popupmenu.cc	2002/07/14 18:06:28
@@ -105,11 +105,10 @@ bool KonqPopupMenu::ProtocolInfo::trashI
 }
 
 KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
-                              KURL viewURL,
-                              KActionCollection & actions,
-                              KNewMenu * newMenu,
-                  bool showPropertiesAndFileType )
-  : QPopupMenu( 0L, "konq_popupmenu" ), m_actions( actions ), m_ownActions( \
static_cast<QObject *>( 0 ), "KonqPopupMenu::m_ownActions" ), +                       \
KURL viewURL, KActionCollection & actions, +                              KNewMenu * \
newMenu, bool showPropertiesAndFileType ) +              :QPopupMenu( 0L, \
"konq_popupmenu" ), m_actions( actions ),  +               m_ownActions( \
                static_cast<QObject *>( 0 ), "KonqPopupMenu::m_ownActions" ),
     m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
 {
   d = new KonqPopupMenuPrivate;
@@ -128,8 +127,10 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
   bool bCanChangeSharing = false;
   m_lstPopupURLs.clear();
   int id = 0;
+  
   if( m_sMimeType=="inode/directory" && m_lstItems.first()->isLocalFile())
     bCanChangeSharing=true;
+  
   setFont(KGlobalSettings::menuFont());
   m_pluginList.setAutoDelete( true );
   m_ownActions.setHighlightingEnabled( true );
@@ -142,6 +143,7 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
 
   KURL url;
   KFileItemListIterator it ( m_lstItems );
+  
   // Check whether all URLs are correct
   for ( ; it.current(); ++it )
   {
@@ -175,12 +177,14 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
     if ( sMoving )
       sMoving = KProtocolInfo::supportsMoving( url );
   }
+  
   // Be on the safe side when including the trash
   if ( bTrashIncluded )
   {
       sMoving = false;
       sDeleting = false;
   }
+  
   //check if current url is trash
   url = m_sViewURL;
   url.cleanPath();
@@ -371,7 +377,7 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
 
       QDomElement menu = m_menuElement;
 
-      if ( offers.count() > 1 ) // submenu 'open with'
+      if ( offers.count() > 0 ) // submenu 'open with'
       {
         menu = m_doc.createElement( "menu" );
         m_menuElement.appendChild( menu );
@@ -380,12 +386,6 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
         text.appendChild( m_doc.createTextNode( i18n("Open With") ) );
       }
 
-      if ( menu == m_menuElement ) // no submenu -> open with... above the single \
                offer
-      {
-        KAction *openWithAct = new KAction( i18n( "Open With..." ), 0, this, SLOT( \
                slotPopupOpenWith() ), &m_ownActions, "openwith" );
-        addAction( openWithAct, menu );
-      }
-
       KTrader::OfferList::ConstIterator it = offers.begin();
       for( ; it != offers.end(); it++ )
       {
@@ -403,7 +403,9 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
       if ( menu != m_menuElement ) // submenu
       {
         addSeparator( menu );
-        KAction *openWithAct = new KAction( i18n( "Other..." ), 0, this, SLOT( \
slotPopupOpenWith() ), &m_ownActions, "openwith" ); +        KAction *openWithAct = \
new KAction( i18n( "Other..." ), 0, this,  +                                          \
SLOT( slotPopupOpenWith() ),  +                                            \
&m_ownActions, "openwith" );  addAction( openWithAct, menu ); // Other...
       }
   }
@@ -416,8 +418,6 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
 
   addGroup( "preview" );
 
-  addSeparator();
-
   // Second block, builtin + user
   if ( !user.isEmpty() || !builtin.isEmpty() )
   {
@@ -464,25 +464,29 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
         m_mapPopupServices[ id++ ] = *it2;
         insertedOffer = true;
       }
-
-      if ( insertedOffer )
-        addSeparator();
   }
+  
   addPlugins( ); // now it's time to add plugins
 
-  if ( !m_sMimeType.isEmpty() && showPropertiesAndFileType )
+  if ( showPropertiesAndFileType )
   {
+    if ( !m_sMimeType.isEmpty() || KPropertiesDialog::canDisplay( m_lstItems ) )
+      addSeparator ();
+      
+    if ( !m_sMimeType.isEmpty() )
+    {
       act = new KAction( i18n( "Edit File Type..." ), 0, this, SLOT( \
slotPopupMimeType() ),  &m_ownActions, "editfiletype" );
       addAction( act );
   }
 
-  if ( KPropertiesDialog::canDisplay( m_lstItems ) && showPropertiesAndFileType )
+    if ( KPropertiesDialog::canDisplay( m_lstItems ) )
   {
       act = new KAction( i18n( "Properties..." ), 0, this, SLOT( \
slotPopupProperties() ),  &m_ownActions, "properties" );
       addAction( act );
   }
+  }
 
   while ( !m_menuElement.lastChild().isNull() &&
             m_menuElement.lastChild().toElement().tagName().lower() == "separator" )
@@ -493,9 +497,7 @@ KonqPopupMenu::KonqPopupMenu( KBookmarkM
    if(KFileShare::authorization()==KFileShare::Authorized)
    {
        addSeparator();
-       QString label;
-       label=i18n("Share");
-
+      QString label = i18n("Share");
        act = new KAction( label, 0, this, SLOT( slotOpenShareFileDialog() ),
                   &m_ownActions, "sharefile" );
        addAction( act );
@@ -666,10 +667,11 @@ KActionCollection *KonqPopupMenu::action
 QString KonqPopupMenu::mimeType( ) const {
     return m_sMimeType;
 }
-KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo() const
-{
+
+KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo() const {
   return m_info;
 }
+
 void KonqPopupMenu::addPlugins( ){
 	// search for Konq_PopupMenuPlugins inspired by simons kpropsdlg
 	//search for a plugin with the right protocol
@@ -673,25 +675,28 @@ KonqPopupMenu::ProtocolInfo KonqPopupMen
 void KonqPopupMenu::addPlugins( ){
 	// search for Konq_PopupMenuPlugins inspired by simons kpropsdlg
 	//search for a plugin with the right protocol
-	KTrader::OfferList plugin_offers;
         unsigned int pluginCount = 0;
-	plugin_offers = KTrader::self()->query( m_sMimeType.isNull() ? QString::fromLatin1( \
"all/all" ) : m_sMimeType , "'KonqPopupMenu/Plugin' in ServiceTypes"); +  
+  QString type = m_sMimeType.isNull() ? QString::fromLatin1( "all/all" ) : \
m_sMimeType; +  KTrader::OfferList plugin_offers = KTrader::self()->query( type , \
"'KonqPopupMenu/Plugin' in ServiceTypes"); +  
         if ( plugin_offers.isEmpty() )
 	  return; // no plugins installed do not bother about it
 
+  addSeparator ();
+  
 	KTrader::OfferList::ConstIterator iterator = plugin_offers.begin( );
 	KTrader::OfferList::ConstIterator end = plugin_offers.end( );
 
 	addGroup( "plugins" );
+  
 	// travers the offerlist
-	for(; iterator != end; ++iterator, ++pluginCount ){
-		KonqPopupMenuPlugin *plugin =
-			KParts::ComponentFactory::
-			createInstanceFromLibrary<KonqPopupMenuPlugin>( \
                (*iterator)->library().local8Bit(),
-									this,
-									(*iterator)->name().latin1() );
+  for(; iterator != end; ++iterator, ++pluginCount )
+  {
+    KonqPopupMenuPlugin *plugin = \
KParts::ComponentFactory::createInstanceFromLibrary<KonqPopupMenuPlugin>( \
(*iterator)->library().local8Bit(), this, (*iterator)->name().latin1() );  if ( \
!plugin )  continue;
+
                 QString pluginClientName = QString::fromLatin1( "Plugin%1" ).arg( \
pluginCount );  addMerge( pluginClientName );
                 plugin->domDocument().documentElement().setAttribute( "name", \
pluginClientName ); @@ -700,8 +705,8 @@ void KonqPopupMenu::addPlugins( ){
 	}
 
 	addMerge( "plugins" );
-	addSeparator();
 }
+
 KURL KonqPopupMenu::url( ) const {
   return m_sViewURL;
 }
@@ -718,7 +725,7 @@ KURL::List KonqPopupMenu::popupURLList( 
 KonqPopupMenuPlugin::KonqPopupMenuPlugin( KonqPopupMenu *parent, const char *name )
     : QObject( parent, name ) {
 }
-KonqPopupMenuPlugin::~KonqPopupMenuPlugin( ){
 
+KonqPopupMenuPlugin::~KonqPopupMenuPlugin( ){
 }
 #include "konq_popupmenu.moc"


["kuick.diff" (text/x-diff)]

Index: kmetamenu.cpp
===================================================================
RCS file: /home/kde/kdeaddons/konq-plugins/kuick/kmetamenu.cpp,v
retrieving revision 1.14
diff -u -p -b -B -w -r1.14 kmetamenu.cpp
--- kmetamenu.cpp	2002/06/16 20:07:31	1.14
+++ kmetamenu.cpp	2002/07/14 18:20:29
@@ -80,7 +80,7 @@ KMetaMenu::KMetaMenu( QWidget *parent, c
      connect(m_home, SIGNAL(fileChosen(const QString &)), 
              SLOT(slotFileChosen(const QString &) ) ); 
 
-     m_browse = new KAction(i18n("&Browse"), 0, this, SLOT(slotBrowse()), this );
+     m_browse = new KAction(i18n("&Browse..."), 0, this, SLOT(slotBrowse()), this );
      m_browse->plug(this);
      // read the last chosen dirs 
      // first set the group according to our parameter
Index: kuick_plugin.cpp
===================================================================
RCS file: /home/kde/kdeaddons/konq-plugins/kuick/kuick_plugin.cpp,v
retrieving revision 1.24
diff -u -p -b -B -w -r1.24 kuick_plugin.cpp
--- kuick_plugin.cpp	2002/06/16 18:20:35	1.24
+++ kuick_plugin.cpp	2002/07/14 18:20:29
@@ -43,7 +43,7 @@ KTestMenu::KTestMenu( KonqPopupMenu *pop
     meta_move_mmu = 0L;
     my_action = new KAction( "kuick_plugin", 0, this, SLOT( slotPopupMaeh( ) ), \
actionCollection( ), "Do some funky stuff"  );  addAction( my_action );
-    addSeparator();
+    //addSeparator();
     //popupmenu->addMerge();
     connect( popup, SIGNAL(aboutToShow() ), this, SLOT(slotPrepareMenu( ) ) );
 



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

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