From kde-pim Tue May 31 22:01:57 2005 From: Scott Beck Date: Tue, 31 May 2005 22:01:57 +0000 To: kde-pim Subject: [Kde-pim] select folder tree shortcuts Message-Id: <200505311501.57237.sbeck () gossamer-threads ! com> X-MARC-Message: https://marc.info/?l=kde-pim&m=111757698201537 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_V7NnCP4kW/n40Gs" --Boundary-00=_V7NnCP4kW/n40Gs Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --Boundary-00=_V7NnCP4kW/n40Gs Content-Type: text/x-diff; charset="us-ascii"; name="kmail-simplefoldertree-shortcuts.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kmail-simplefoldertree-shortcuts.patch" Index: kmfolderseldlg.h =================================================================== --- kmfolderseldlg.h (revision 419304) +++ kmfolderseldlg.h (working copy) @@ -8,10 +8,12 @@ #include #include +#include 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, --Boundary-00=_V7NnCP4kW/n40Gs Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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/ --Boundary-00=_V7NnCP4kW/n40Gs--