kitchensync

actionmanager.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <klocale.h>
00023 #include <kstatusbar.h>
00024 #include <kdebug.h>
00025 #include <kglobal.h>
00026 #include <kconfig.h>
00027 
00028 #include "prefs.h"
00029 
00030 #include "actionmanager.h"
00031 
00032 using namespace KSync;
00033 
00034 ActionManager::ActionManager( KActionCollection *actionCollection )
00035   : mActionCollection( actionCollection ), mView( 0 )
00036 {
00037 }
00038 
00039 ActionManager::~ActionManager()
00040 {
00041   writeConfig();
00042 }
00043 
00044 void ActionManager::setView( KitchenSync *view )
00045 {
00046   mView = view;
00047 }
00048 
00049 void ActionManager::initActions()
00050 {
00051   if ( !mView ) {
00052     kdError() << "Call KSync::ActionManager::setView() before "
00053               << "KSync::ActionManager::initActions()." << endl;
00054     return;
00055   }
00056 
00057   new KAction( i18n("Synchronize" ), "reload", 0, mView, SLOT( slotSync() ),
00058                mActionCollection, "sync" );
00059 
00060   new KAction( i18n("Configure Profiles..."), "configure", 0,
00061                mView, SLOT( configureProfiles() ),
00062                mActionCollection, "config_profile" );
00063 
00064   new KAction( i18n("Configure Current Profile..."), "configure", 0,
00065                mView, SLOT( configureCurrentProfile() ),
00066                mActionCollection, "config_current" );
00067 
00068   m_profAct = new KSelectAction( i18n("Profile"), KShortcut(), mView,
00069                                  SLOT( activateProfile() ),
00070                                  mActionCollection, "select_prof");
00071 
00072   KStdAction::preferences( mView, SLOT( slotPreferences() ),
00073                            mActionCollection );
00074 }
00075 
00076 int ActionManager::currentProfile()
00077 {
00078   return m_profAct->currentItem();
00079 }
00080 
00081 void ActionManager::setProfiles( const QStringList &profiles )
00082 {
00083   m_profAct->setItems( profiles );
00084 }
00085 
00086 void ActionManager::readConfig()
00087 {
00088   m_profAct->setCurrentItem( Prefs::instance()->currentProfile() );
00089 }
00090 
00091 void ActionManager::writeConfig()
00092 {
00093   Prefs::instance()->setCurrentProfile( m_profAct->currentItem() );
00094   Prefs::instance()->writeConfig();
00095 }
KDE Home | KDE Accessibility Home | Description of Access Keys