RFC: KRecentFilesAction: hide urls

Johnathan Burchill jkerrb at rogers.com
Wed Apr 11 19:15:34 BST 2007


Hi,

The KRecentFilesAction shows the full url path in square brackets behind the 
short name? I'd like to hide that url and just show the short name. If the 
same shortname is associated with more than one url, the short name would be 
appended with a unique identifier, like (2), (3), etc.

The API doesn't appear to do this.  Please see the following patch. It 
defaults to the current behaviour. Comments?

Thanks,
JB

Index: krecentfilesaction.cpp
===================================================================
--- krecentfilesaction.cpp      (revision 652566)
+++ krecentfilesaction.cpp      (working copy)
@@ -46,10 +46,12 @@
   KRecentFilesActionPrivate()
   {
     m_maxItems = 10;
+    m_showUrls = true;
     m_noEntriesAction=0;
   }

   int m_maxItems;
+  bool m_showUrls;
   QMap<QAction*, QString> m_shortNames;
   QMap<QAction*, KUrl> m_urls;
   QPointer<QAction> m_noEntriesAction;
@@ -121,6 +123,17 @@
         delete removeAction(selectableActionGroup()->actions().last());
 }

+bool KRecentFilesAction::showUrls() const
+{
+    return d->m_showUrls;
+}
+
+void KRecentFilesAction::setShowUrls( bool show )
+{
+    // set new showUrls
+    d->m_showUrls = show;
+}
+
 void KRecentFilesAction::addUrl( const KUrl& _url, const QString& name )
 {
     /**
@@ -153,7 +166,18 @@

     if (d->m_noEntriesAction) 
removeAction(d->m_noEntriesAction)->deleteLater();
     // add file to list
-    const QString title = tmpName + " [" + file + ']';
+    QString title = tmpName;
+    QList<QString> shortNames = d->m_shortNames.values();
+    int numNames = shortNames.count(tmpName);
+    if (numNames)
+    {
+        title.append( " ("+QString::number(numNames+1)+")");
+    }
+    if ( d->m_showUrls )
+    {
+        // show full url path
+        title.append( " [" + file + "]" );
+    }
     QAction* action = new QAction(title, selectableActionGroup());
     // TODO: This action should be prepended like in KDE 3 - Clarence.
     addAction(action, url, tmpName);
@@ -232,7 +256,17 @@

         nameKey = QString( "Name%1" ).arg( i );
         nameValue = cg.readPathEntry( nameKey, url.fileName() );
-        title = nameValue + " [" + value + ']';
+        title = nameValue;
+        QList<QString> shortNames = d->m_shortNames.values();
+        int numNames = shortNames.count(nameValue);
+        if (numNames)
+        {
+            title.append( " ("+QString::number(numNames+1)+")");
+        }
+       if (d->m_showUrls)
+       {
+            title.append( " [" + value + "]" );
+       }
         if (!value.isNull())
         {
          thereAreEntries=true;
Index: krecentfilesaction.h
===================================================================
--- krecentfilesaction.h        (revision 652566)
+++ krecentfilesaction.h        (working copy)
@@ -46,6 +46,7 @@
 {
   Q_OBJECT
   Q_PROPERTY( int maxItems READ maxItems WRITE setMaxItems )
+  Q_PROPERTY( bool showUrls READ showUrls WRITE setShowUrls )

 public:
     /**
@@ -121,6 +122,16 @@
   void setMaxItems( int maxItems );

   /**
+   *  Returns whether the full Url paths should be shown with the name.
+   */
+  bool showUrls() const;
+
+  /**
+   *  Sets whether the full Url paths should be shown with the name.
+   */
+  void setShowUrls( bool show );
+
+  /**
    *  Loads the recent files entries from a given KConfigGroup object.
    *  You can provide the name of the group used to load the entries.
    *  If the groupname is empty, entries are load from a group 
called 'RecentFiles'




More information about the kde-core-devel mailing list