kitchensync

profilewizard.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
00005     Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "profilewizard.h"
00024 
00025 #include "profilecheckitem.h"
00026 
00027 #include <klineedit.h>
00028 #include <klocale.h>
00029 #include <klistview.h>
00030 #include <kmessagebox.h>
00031 #include <kinputdialog.h>
00032 
00033 #include <qlayout.h>
00034 #include <qlabel.h>
00035 #include <qpushbutton.h>
00036 
00037 using namespace KSync;
00038 
00039 ProfileWizard::ProfileWizard( const Profile &profile,
00040                               const ActionPartService::List &parts )
00041   : KDialogBase( Plain, i18n("Configure Profile"), Ok | Cancel, Ok, 0, "wiz" ),
00042     mProfile( profile ), mAvailableParts( parts )
00043 {
00044   initUI();
00045   initProfile();
00046 }
00047 
00048 ProfileWizard::ProfileWizard( const ActionPartService::List &parts )
00049   : KDialogBase( Plain, i18n("Configure Profile"), Ok | Cancel, Ok, 0, "wiz" ),
00050     mAvailableParts( parts )
00051 {
00052   initUI();
00053 }
00054 
00055 ProfileWizard::~ProfileWizard()
00056 {
00057 }
00058 
00059 void ProfileWizard::initUI()
00060 {
00061   QWidget *topWidget = plainPage();
00062 
00063   QBoxLayout *topLayout = new QVBoxLayout( topWidget );
00064   topLayout->setSpacing( spacingHint() );
00065 
00066   QBoxLayout *nameLayout = new QHBoxLayout( topLayout );
00067 
00068   QLabel *label = new QLabel( i18n("Profile name:"), topWidget );
00069   nameLayout->addWidget( label );
00070 
00071   mNameEdit = new KLineEdit( topWidget );
00072   nameLayout->addWidget( mNameEdit );
00073 
00074   label = new QLabel( "<qt><b>" + i18n("Which parts to load?") + "</b></qt>", topWidget );
00075   topLayout->addWidget( label );
00076   
00077   label = new QLabel( i18n("KitchenSync supports a variety of plugins. Below\n"
00078                            "you've the possibility to choose which plugins\n"
00079                            "should be loaded when this Profile is the active\n"
00080                            "one."), topWidget );
00081   topLayout->addWidget( label );
00082 
00083   mPartListView = new KListView( topWidget );
00084   mPartListView->addColumn( i18n( "Name" ) );
00085   mPartListView->addColumn( i18n( "Comment" ) );
00086   mPartListView->setSortColumn( -1 ); // Disable sorting by the user
00087   mPartListView->setAllColumnsShowFocus( true );
00088   mPartListView->setFullWidth( true );
00089   topLayout->addWidget( mPartListView );
00090 
00091   QBoxLayout *buttonLayout = new QHBoxLayout( topLayout );
00092 
00093   QPushButton *button = new QPushButton( i18n("Add..."), topWidget );
00094   buttonLayout->addWidget( button );
00095   connect( button, SIGNAL( clicked() ), SLOT( addPart() ) );
00096 
00097   button = new QPushButton( i18n("Remove"), topWidget );
00098   buttonLayout->addWidget( button );
00099   connect( button, SIGNAL( clicked() ), SLOT( removePart() ) );
00100 
00101   button = new QPushButton( i18n("Up"), topWidget );
00102   buttonLayout->addWidget( button );
00103   connect( button, SIGNAL( clicked() ), SLOT( raisePart() ) );
00104 
00105   button = new QPushButton( i18n("Down"), topWidget );
00106   buttonLayout->addWidget( button );
00107   connect( button, SIGNAL( clicked() ), SLOT( lowerPart() ) );
00108 }
00109 
00110 void ProfileWizard::initProfile()
00111 {
00112   mNameEdit->setText( mProfile.name() );
00113 
00114   ActionPartService::List selectedParts = mProfile.actionParts();
00115   
00116   ActionPartService::List::ConstIterator itPart;
00117   for ( itPart = selectedParts.begin(); itPart != selectedParts.end();
00118         ++itPart ) {
00119     new ProfileCheckItem( mPartListView, *itPart );
00120   }
00121 }
00122 
00123 Profile ProfileWizard::profile()
00124 {
00125   mProfile.setName( mNameEdit->text() );
00126   mProfile.setActionParts( selectedActionParts() );
00127   return mProfile;
00128 }
00129 
00130 ActionPartService::List ProfileWizard::selectedActionParts()
00131 {
00132   ActionPartService::List actionParts;
00133   QListViewItemIterator it( mPartListView );
00134   for ( ; it.current(); ++it ) {
00135     ProfileCheckItem *item = static_cast<ProfileCheckItem *>( it.current() );
00136     actionParts.append( item->actionPart() );
00137   }
00138   return actionParts;
00139 }
00140 
00141 void ProfileWizard::slotOk()
00142 {
00143   if ( mNameEdit->text().isEmpty() ) {
00144     KMessageBox::sorry( this, i18n("Profile name can not be empty.") );
00145   } else {
00146     accept();
00147   }
00148 }
00149 
00150 ProfileCheckItem *ProfileWizard::selectedItem()
00151 {
00152   return static_cast<ProfileCheckItem *>( mPartListView->selectedItem() );
00153 }
00154 
00155 void ProfileWizard::addPart()
00156 {
00157   QStringList partNames;
00158 
00159   ActionPartService::List::ConstIterator it;
00160   for( it = mAvailableParts.begin(); it != mAvailableParts.end(); ++it ) {
00161     partNames.append( (*it).name() );
00162   }
00163 
00164   QString partName = KInputDialog::getItem( i18n("Select Action Part"),
00165                         i18n("Selection the action part you want to add:"),
00166                         partNames, 0, false, 0, this );
00167 
00168   for( it = mAvailableParts.begin(); it != mAvailableParts.end(); ++it ) {
00169     if ( (*it).name() == partName ) {
00170       ProfileCheckItem *item = selectedItem();
00171       if ( item ) {
00172         new ProfileCheckItem( mPartListView, item, *it );
00173       } else {
00174         new ProfileCheckItem( mPartListView, *it );
00175       }
00176     }
00177   }
00178 }
00179 
00180 void ProfileWizard::removePart()
00181 {
00182   ProfileCheckItem *item = selectedItem();
00183   if ( item ) delete item;
00184 }
00185 
00186 void ProfileWizard::raisePart()
00187 {
00188   ProfileCheckItem *item = selectedItem();
00189 
00190   if ( !item )
00191     return;
00192 
00193   ProfileCheckItem *above;
00194   above = static_cast<ProfileCheckItem *>( item->itemAbove() );
00195 
00196   if ( above )
00197     above = static_cast<ProfileCheckItem *>( above->itemAbove() );
00198 
00199   item->moveItem( above );
00200 }
00201 
00202 void ProfileWizard::lowerPart()
00203 {
00204   ProfileCheckItem *item = selectedItem();
00205 
00206   if ( !item )
00207     return;
00208 
00209   ProfileCheckItem *below;
00210   below = static_cast<ProfileCheckItem *>( item->nextSibling() );
00211 
00212   if ( below )
00213     item->moveItem( below );
00214 }
00215 
00216 #include "profilewizard.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys