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

List:       kfm-devel
Subject:    more servicemenus improvements
From:       "Aaron J. Seigo" <aseigo () olympusproject ! org>
Date:       2003-07-23 23:26:04
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi...

it was too hot to sleep last night, so instead i mucked around on the computer 
and ended up knocked off a few items from my servicemenus TODO list for 
3.2... attached are the patches for review... two things are added: 

first: support for separators using a _SEPARATOR_ keyword in the actions list, 
such as:

	Actions=setAsBackground;_SEPARATOR_;tileAsBackground

duplicate and "first item" separators are caught... it involves a bit of a 
hack though, namely: inserting an empty service.

second: allowing servicemenus in .directory files. this allows per-directory 
actions for special directories. i may want to extend this later to allow 
referencing external servicemenus (not sure at this point)

both of these were feature requests from users. comments and critique welcome, 
as always. 

also, just as an FYI i have two more items on my servicemenus TODO list at 
this point:

 o defining runtime checks for actions. this will allow things such as DCOP 
calls to be made to determine whether or not show the action (if it matches 
the mimetype first, of course)

 o GUI interface for managing servicemenus, including turning individual 
entries on/off and editting/creating servicemenus.

if you have thoughts regarding either of the above, please share them with me 
sooner rather than later in case it can save me some effort =)

- -- 
Aaron J. Seigo
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iD8DBQE/HxmO1rcusafx20MRAvWRAJ4vrODZnxtHcbO/xRd5qJCPFv3kRwCeJO8/
PliiPILfc7RzTaeNZ9UEqnc=
=Mj9D
-----END PGP SIGNATURE-----

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

Index: kmimetype.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kmimetype.cpp,v
retrieving revision 1.171
diff -u -3 -d -p -r1.171 kmimetype.cpp
--- kmimetype.cpp	2 Jul 2003 16:45:47 -0000	1.171
+++ kmimetype.cpp	23 Jul 2003 22:53:50 -0000
@@ -902,6 +902,14 @@ QValueList<KDEDesktopMimeType::Service> 
     //kdDebug(7009) << "CURRENT KEY = " << (*it) << endl;
 
     QString group = *it;
+
+    if (group == "_SEPARATOR_")
+    {
+        Service s;
+        result.append(s);
+        continue;
+    }
+
     group.prepend( "Desktop Action " );
 
     bool bInvalidMenu = false;
Index: kmimetype.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kmimetype.h,v
retrieving revision 1.76
diff -u -3 -d -p -r1.76 kmimetype.h
--- kmimetype.h	27 Jun 2003 21:03:17 -0000	1.76
+++ kmimetype.h	23 Jul 2003 22:53:54 -0000
@@ -497,6 +497,7 @@ public:
   struct Service
   {
     Service() { m_display = true; }
+    bool isEmpty() const { return m_strName.isEmpty(); }
     QString m_strName;
     QString m_strIcon;
     QString m_strExec;
@@ -529,7 +530,9 @@ public:
   static QValueList<Service> builtinServices( const KURL& _url );
   /**
    * Returns a list of services defined by the user as possible actions
-   * on the given .desktop file.
+   * on the given .desktop file. May include empty actions which represent where
+   * visual separators should appear in user-visible representations of those actions,
+   * such as separators in a menu.
    * @param path the path to the desktop file describing the services
    * @param bLocalFiles true if those services are to be applied to local files only
    * (if false, services that don't have %u or %U in the Exec line won't be taken into account).

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

Index: konq_popupmenu.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_popupmenu.cc,v
retrieving revision 1.156
diff -u -3 -d -p -r1.156 konq_popupmenu.cc
--- konq_popupmenu.cc	23 Jul 2003 14:13:40 -0000	1.156
+++ konq_popupmenu.cc	23 Jul 2003 23:26:17 -0000
@@ -165,6 +165,17 @@ void KonqPopupMenu::insertServices(const
     ServiceList::const_iterator it = list.begin();
     for( ; it != list.end(); ++it )
     {
+        if ((*it).isEmpty())
+        {
+            if (!menu.firstChild().isNull() &&
+                menu.lastChild().toElement().tagName().lower() != "separator")
+            {
+                QDomElement separator = m_doc.createElement( "separator" );
+                menu.appendChild(separator);
+            }
+            continue;
+        }
+
         if (isBuiltin || (*it).m_display == true)
         {
             QCString name;
@@ -187,6 +198,31 @@ void KonqPopupMenu::insertServices(const
     }
 }
 
+bool KonqPopupMenu::KIOSKAuthorizedAction(KConfig& cfg)
+{
+    if ( !cfg.hasKey( "X-KDE-AuthorizeAction") )
+    {
+        return true;
+    }
+
+    QStringList list = cfg.readListEntry("X-KDE-AuthorizeAction");
+    if (kapp && !list.isEmpty())
+    {
+        for(QStringList::ConstIterator it = list.begin();
+            it != list.end();
+            ++it)
+        {
+            if (!kapp->authorize((*it).stripWhiteSpace()))
+            {
+                return false;
+            }
+        }
+    }
+
+    return true;
+}
+
+
 void KonqPopupMenu::setup(bool showPropertiesAndFileType)
 {
   assert( m_lstItems.count() >= 1 );
@@ -200,11 +236,12 @@ void KonqPopupMenu::setup(bool showPrope
   bool sMoving        = true;
   m_sMimeType         = m_lstItems.first()->mimetype();
   mode_t mode         = m_lstItems.first()->mode();
+  bool isDirectory    = m_sMimeType == "inode/directory";
   bool bTrashIncluded = false;
   bool bCanChangeSharing = false;
   m_lstPopupURLs.clear();
   int id = 0;
-  if( m_sMimeType=="inode/directory" && m_lstItems.first()->isLocalFile())
+  if( isDirectory && m_lstItems.first()->isLocalFile())
     bCanChangeSharing=true;
   setFont(KGlobalSettings::menuFont());
   m_pluginList.setAutoDelete( true );
@@ -356,12 +393,12 @@ void KonqPopupMenu::setup(bool showPrope
 
     if ( currentDir || httpPage ) // rmb on background or html frame
     {
-      addAction( "up" );
+      if (currentDir)
+          addAction( "up" ); // don't show when viewing html
       addAction( "back" );
       addAction( "forward" );
-      if ( currentDir ) // khtml adds a different "reload frame" for frames
-        addAction( "reload" );
-      addGroup( "reload" );
+      if (httpPage)
+          addGroup( "reload" ); // only show when viewing html
       addSeparator();
     }
 
@@ -418,8 +455,9 @@ void KonqPopupMenu::setup(bool showPrope
   ServiceList user;
   QMap<QString, ServiceList> userSubmenus;
 
+  bool isSingleLocal = (m_lstItems.count() == 1 && \
m_lstItems.first()->url().isLocalFile());  // 1 - Look for builtin and user-defined \
                services
-  if ( m_sMimeType == "application/x-desktop" && m_lstItems.count() == 1 && \
m_lstItems.first()->url().isLocalFile() ) // .desktop file +  if ( m_sMimeType == \
"application/x-desktop" && isSingleLocal ) // .desktop file  {
       // get builtin services, like mount/unmount
       builtin = KDEDesktopMimeType::builtinServices( m_lstItems.first()->url() );
@@ -430,6 +468,28 @@ void KonqPopupMenu::setup(bool showPrope
   {
 
   // 2 - Look for "servicesmenus" bindings (konqueror-specific user-defined \
services) +
+  // first check the .directory if this is a directory
+  if (isDirectory && isSingleLocal)
+  {
+    QString dotDirectoryFile = \
m_lstItems.first()->url().path(1).append(".directory"); +    KSimpleConfig cfg( \
dotDirectoryFile, true ); +    cfg.setDesktopGroup();
+
+    if (KIOSKAuthorizedAction(cfg))
+    {
+        QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
+        if (submenuName.isEmpty())
+        {
+            user += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, true \
); +        }
+        else
+        {
+            userSubmenus[submenuName] += KDEDesktopMimeType::userDefinedServices( \
dotDirectoryFile, true ); +        }
+    }
+  }
+
   QStringList dirs = KGlobal::dirs()->findDirs( "data", "konqueror/servicemenus/" );
   QStringList::ConstIterator dIt = dirs.begin();
   QStringList::ConstIterator dEnd = dirs.end();
@@ -445,28 +505,11 @@ void KonqPopupMenu::setup(bool showPrope
       for (; eIt != eEnd; ++eIt )
       {
           KSimpleConfig cfg( *dIt + *eIt, true );
-
           cfg.setDesktopGroup();
 
-          if ( cfg.hasKey( "X-KDE-AuthorizeAction") )
+          if (!KIOSKAuthorizedAction(cfg))
           {
-              bool ok = true;
-              QStringList list = cfg.readListEntry("X-KDE-AuthorizeAction");
-              if (kapp && !list.isEmpty())
-              {
-                  for(QStringList::ConstIterator it = list.begin();
-                      it != list.end();
-                      ++it)
-                  {
-                      if (!kapp->authorize((*it).stripWhiteSpace()))
-                      {
-                          ok = false;
-                          break;
-                      }
-                  }
-              }
-              if (!ok)
-                continue;
+              continue;
           }
 
           if ( cfg.hasKey( "Actions" ) && cfg.hasKey( "ServiceTypes" ) )
@@ -492,7 +535,7 @@ void KonqPopupMenu::setup(bool showPrope
 
                   // next, do we match all files?
                   if (*it == "all/allfiles" &&
-                      m_sMimeType != "inode/directory") // ## or inherits from it
+                      !isDirectory) // ## or inherits from it
                   {
                       ok = true;
                       break;
Index: konq_popupmenu.h
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_popupmenu.h,v
retrieving revision 1.44
diff -u -3 -d -p -r1.44 konq_popupmenu.h
--- konq_popupmenu.h	23 Jul 2003 14:13:40 -0000	1.44
+++ konq_popupmenu.h	23 Jul 2003 23:26:17 -0000
@@ -87,7 +87,7 @@ public:
                  QWidget * parentWidget,
                  bool showPropertiesAndFileType = true,
                  bool isHierView = false );
-  
+
   /**
    * Don't forget to destroy the object
    */
@@ -147,6 +147,8 @@ private:
   void setup(bool showPropertiesAndFileType);
   void addPlugins( );
   void insertServices(const ServiceList& list, QDomElement& menu, bool isBuiltin);
+  bool KonqPopupMenu::KIOSKAuthorizedAction(KConfig& cfg);
+
   class KonqPopupMenuPrivate;
   KonqPopupMenuPrivate *d;
   KNewMenu *m_pMenuNew;



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

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