kmail

foldershortcutdialog.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 **
00003 ** Filename   : foldershortcutdialog.cpp
00004 ** Created on : 09 October, 2004
00005 ** Copyright  : (c) 2004 Till Adam
00006 ** Email      : adam@kde.org
00007 **
00008 *******************************************************************************/
00009 
00010 /*******************************************************************************
00011 **
00012 **   This program is free software; you can redistribute it and/or modify
00013 **   it under the terms of the GNU General Public License as published by
00014 **   the Free Software Foundation; either version 2 of the License, or
00015 **   (at your option) any later version.
00016 **
00017 **   This program is distributed in the hope that it will be useful,
00018 **   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 **   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 **   GNU General Public License for more details.
00021 **
00022 **   You should have received a copy of the GNU General Public License
00023 **   along with this program; if not, write to the Free Software
00024 **   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00025 **
00026 **   In addition, as a special exception, the copyright holders give
00027 **   permission to link the code of this program with any edition of
00028 **   the Qt library by Trolltech AS, Norway (or with modified versions
00029 **   of Qt that use the same license as Qt), and distribute linked
00030 **   combinations including the two.  You must obey the GNU General
00031 **   Public License in all respects for all of the code used other than
00032 **   Qt.  If you modify this file, you may extend this exception to
00033 **   your version of the file, but you are not obligated to do so.  If
00034 **   you do not wish to do so, delete this exception statement from
00035 **   your version.
00036 **
00037 *******************************************************************************/
00038 
00039 #include <qlabel.h>
00040 #include <qvbox.h>
00041 #include <qvgroupbox.h>
00042 #include <qwhatsthis.h>
00043 
00044 #include <kkeybutton.h>
00045 #include <klocale.h>
00046 #include <kmessagebox.h>
00047 
00048 #include "kmmainwidget.h"
00049 #include "foldershortcutdialog.h"
00050 #include "kmfolder.h"
00051 
00052 using namespace KMail;
00053 
00054 FolderShortcutDialog::FolderShortcutDialog( KMFolder *folder,
00055                                             KMMainWidget *mainwidget,
00056                                             QWidget *parent,
00057                                             const char *name )
00058 :  KDialogBase( parent, name, true,
00059                i18n( "Shortcut for Folder %1" ).arg( folder->label() ),
00060                KDialogBase::Ok | KDialogBase::Cancel ),
00061    mFolder( folder ), mMainWidget( mainwidget )
00062 {
00063   QVBox *box = makeVBoxMainWidget();
00064   QVGroupBox *gb = new QVGroupBox( i18n("Select Shortcut for Folder"), box );
00065   QWhatsThis::add( gb, i18n( "<qt>To choose a key or a combination "
00066                              "of keys which select the current folder, "
00067                              "click the button below and then press the key(s) "
00068                              "you wish to associate with this folder.</qt>" ) );
00069   QHBox *hb = new QHBox( gb );
00070   new QWidget(hb);
00071   mKeyButton = new KKeyButton( hb, "FolderShortcutSelector" );
00072   new QWidget(hb);
00073 
00074   connect( mKeyButton, SIGNAL( capturedShortcut( const KShortcut& ) ),
00075            this, SLOT( slotCapturedShortcut( const KShortcut& ) ) );
00076   mKeyButton->setShortcut( folder->shortcut(), false );
00077 }
00078 
00079 FolderShortcutDialog::~FolderShortcutDialog()
00080 {
00081 }
00082 
00083 void FolderShortcutDialog::slotCapturedShortcut( const KShortcut& sc )
00084 {
00085   if ( sc == mKeyButton->shortcut() ) return;
00086   if ( sc.toString().isNull() ) {
00087     // null is fine, that's reset, but sc.Ń–sNull() will be false :/
00088     mKeyButton->setShortcut( KShortcut::null(), false );
00089   } else {
00090     if( !mMainWidget->shortcutIsValid( sc ) ) {
00091       QString msg( i18n( "The selected shortcut is already used, "
00092             "please select a different one." ) );
00093       KMessageBox::sorry( mMainWidget, msg );
00094     } else {
00095       mKeyButton->setShortcut( sc, false );
00096     }
00097   }
00098 }
00099 
00100 void FolderShortcutDialog::slotOk()
00101 {
00102   mFolder->setShortcut( mKeyButton->shortcut() );
00103   KDialogBase::slotOk();
00104 }
00105 
00106 #include "foldershortcutdialog.moc"
00107 
00108