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

List:       kde-pim
Subject:    [Kde-pim] select folder tree shortcuts
From:       Scott Beck <sbeck () gossamer-threads ! com>
Date:       2005-05-31 22:01:57
Message-ID: 200505311501.57237.sbeck () gossamer-threads ! com
[Download RAW message or body]

Hi All,

This patch adds folder shortcut support to the select folder dialog. I'm not 
sure this is the best way to do this. Comments welcome.

Cheers,

Scott
-- 
-------------------- Gossamer Threads Inc. ----------------------
Scott Beck                      Email: scott@gossamer-threads.com
Lead Software Developer         Phone: (604) 687-5804
http://www.gossamer-threads.com Fax:   (604) 687-5806


["kmail-simplefoldertree-shortcuts.patch" (text/x-diff)]

Index: kmfolderseldlg.h
===================================================================
--- kmfolderseldlg.h	(revision 419304)
+++ kmfolderseldlg.h	(working copy)
@@ -8,10 +8,12 @@
 
 #include <kdialogbase.h>
 #include <klistview.h>
+#include <kaction.h>
 
 class KMFolder;
 class KMFolderTree;
 class KMMainWidget;
+class KActionCollection;
 
 namespace KMail {
 
@@ -22,6 +24,7 @@
     public:
       SimpleFolderTree( QWidget * parent, KMFolderTree * folderTree,
                         const QString & preSelection, bool mustBeReadWrite );
+      ~SimpleFolderTree();
 
       /** Reload the tree and select what folders to show and what not */
       void reload( bool mustBeReadWrite, bool showOutbox, bool showImapFolders,
@@ -46,8 +49,30 @@
       bool mLastMustBeReadWrite;
       bool mLastShowOutbox;
       bool mLastShowImapFolders;
+      KActionCollection *mActionCollection;
 };
+  class SimpleFolderShortcutCommand : public QObject
+  {
+    Q_OBJECT
 
+  public:
+    SimpleFolderShortcutCommand( SimpleFolderTree*, KMFolder* );
+    ~SimpleFolderShortcutCommand();
+
+  public slots:
+    void start();
+    /** Assign a KActio to the command which is used to trigger it. This
+     * action will be deleted along with the command, so you don't need to
+     * keep track of it separately. */
+    void setAction( KAction* );
+
+  private:
+    SimpleFolderTree *mMainWidget;
+    KMFolder *mFolder;
+    KAction *mAction;
+  };
+
+
   //-----------------------------------------------------------------------------
   class KMFolderSelDlg: public KDialogBase
   {
Index: kmfolderseldlg.cpp
===================================================================
--- kmfolderseldlg.cpp	(revision 419304)
+++ kmfolderseldlg.cpp	(working copy)
@@ -53,7 +53,29 @@
     mFolder( 0 )
 {}
 
+SimpleFolderShortcutCommand::SimpleFolderShortcutCommand( SimpleFolderTree *mainwidget,
+                                              KMFolder *folder )
+    : mMainWidget( mainwidget ), mFolder( folder ), mAction( 0 )
+{
+}
 
+SimpleFolderShortcutCommand::~SimpleFolderShortcutCommand()
+{
+  if ( mAction ) mAction->unplugAll();
+  delete mAction;
+}
+
+void SimpleFolderShortcutCommand::start()
+{
+  mMainWidget->setFolder( mFolder );
+}
+
+void SimpleFolderShortcutCommand::setAction( KAction* action )
+{
+  mAction = action;
+}
+
+
 //-----------------------------------------------------------------------------
 SimpleFolderTree::SimpleFolderTree( QWidget * parent,
                                     KMFolderTree * folderTree,
@@ -64,6 +86,8 @@
   mFolderColumn = addColumn( i18n( "Folder" ) );
   setRootIsDecorated( true );
   setSorting( -1 );
+  mActionCollection = new KActionCollection( this );
+  mActionCollection->setAutoConnectShortcuts( true );
 
   reload( mustBeReadWrite, true, true, preSelection );
 
@@ -153,6 +177,19 @@
     } else {
       if ( fti->folder() ) {
         item->setFolder( fti->folder() );
+        if ( !fti->folder()->shortcut().isNull() ) {
+            KMFolder *folder = fti->folder();
+            SimpleFolderShortcutCommand *c = new SimpleFolderShortcutCommand( this, folder );
+            QString actionlabel = QString( "FolderShortcut %1").arg( folder->prettyURL() );
+            QString actionname = QString( "FolderShortcut %1").arg( folder->idString() );
+            QString normalizedName = actionname.replace(" ", "_");
+            KAction* action =
+                new KAction(actionlabel, folder->shortcut(), c, SLOT(start()),
+                        mActionCollection, normalizedName.local8Bit());
+            action->setIcon( folder->unreadIconPath() );
+            c->setAction( action );
+        }
+
         if ( selected == item->folder()->idString() )
           selectedItem = item;
       }
@@ -235,6 +272,11 @@
   folderMenu = 0;
 }
 
+SimpleFolderTree::~SimpleFolderTree()
+{
+  if ( mActionCollection )
+      delete mActionCollection;
+}
 
 //-----------------------------------------------------------------------------
 KMFolderSelDlg::KMFolderSelDlg( KMMainWidget * parent, const QString& caption, 


_______________________________________________
kde-pim mailing list
kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

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

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