00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include "profiledialog.h"
00025
00026
#include "profileitem.h"
00027
#include "profilewizard.h"
00028
00029
#include <klocale.h>
00030
#include <kpushbutton.h>
00031
#include <klistview.h>
00032
00033
#include <qlayout.h>
00034
#include <qlabel.h>
00035
#include <qpushbutton.h>
00036
00037
using namespace KSync;
00038
00039 ProfileDialog::ProfileDialog(
const Profile::List &profiles,
00040
const ActionPartService::List &parts )
00041 : KDialogBase( Plain, i18n(
"Configure Profiles"), Ok | Cancel, Ok, 0, 0, true,
00042 false ),
00043 mAvailableParts( parts )
00044 {
00045
QWidget *topWidget = plainPage();
00046
00047
QBoxLayout *topLayout =
new QVBoxLayout( topWidget );
00048 topLayout->
setSpacing( spacingHint() );
00049
00050
QLabel *label =
new QLabel(
"<qt><b>" + i18n(
"Setup Profiles") +
"</b></qt>", topWidget );
00051 topLayout->
addWidget( label );
00052
00053 label =
new QLabel(
00054 i18n(
"A Profile contains information about which Parts\n"
00055
"should get loaded and used for the synchronization\n"
00056
"process." ),
00057 topWidget );
00058 topLayout->
addWidget( label );
00059
00060
QBoxLayout *listLayout =
new QHBoxLayout( topLayout );
00061
00062 mProfileList =
new KListView( topWidget );
00063 mProfileList->addColumn( i18n(
"Name" ) );
00064 mProfileList->setAllColumnsShowFocus(
true );
00065 mProfileList->setFullWidth(
true );
00066 listLayout->
addWidget( mProfileList );
00067 connect( mProfileList, SIGNAL( selectionChanged(
QListViewItem* ) ),
00068 SLOT( slotSelectionChanged() ) );
00069
00070
QBoxLayout *buttonLayout =
new QVBoxLayout( listLayout );
00071
00072
QPushButton *button =
new QPushButton( i18n(
"Add..."), topWidget );
00073 buttonLayout->
addWidget( button );
00074 connect( button, SIGNAL( clicked() ), SLOT( slotAdd() ) );
00075
00076 mEditButton =
new QPushButton( i18n(
"Edit..."), topWidget );
00077 buttonLayout->
addWidget( mEditButton );
00078 connect( mEditButton, SIGNAL( clicked() ), SLOT( slotEdit() ) );
00079
00080 mRemoveButton =
new QPushButton( i18n(
"Remove"), topWidget );
00081 buttonLayout->
addWidget( mRemoveButton );
00082 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( slotRemove() ) );
00083
00084 buttonLayout->addStretch();
00085
00086 initListView( profiles );
00087
00088 slotSelectionChanged();
00089 }
00090
00091 ProfileDialog::~ProfileDialog()
00092 {
00093 }
00094
00095
void ProfileDialog::initListView(
const Profile::List& profiles )
00096 {
00097 Profile::List::ConstIterator it;
00098
for ( it = profiles.begin(); it != profiles.end(); ++it ) {
00099
new ProfileItem( mProfileList, (*it) );
00100 }
00101 }
00102
00103
Profile::List ProfileDialog::profiles()
const
00104
{
00105
Profile::List profiles;
00106
00107
QListViewItemIterator it( mProfileList );
00108
for ( ; it.current(); ++it ) {
00109 ProfileItem *item = static_cast<ProfileItem *>( it.current() );
00110 profiles.append( item->profile() );
00111 }
00112
00113
return profiles;
00114 }
00115
00116
void ProfileDialog::slotRemove()
00117 {
00118
delete mProfileList->selectedItem();
00119 }
00120
00121
void ProfileDialog::slotAdd()
00122 {
00123 ProfileWizard wiz( mAvailableParts );
00124
00125
if ( wiz.exec() ) {
00126
new ProfileItem( mProfileList, wiz.profile() );
00127 }
00128 }
00129
00130
void ProfileDialog::slotEdit()
00131 {
00132 ProfileItem *item =
00133 static_cast<ProfileItem *>( mProfileList->selectedItem() );
00134
if ( !item )
return;
00135
00136 ProfileWizard wiz( item->profile(), mAvailableParts );
00137
if ( wiz.exec() ) {
00138 item->setProfile( wiz.profile() );
00139 }
00140 }
00141
00142
void ProfileDialog::slotSelectionChanged()
00143 {
00144
bool state = (mProfileList->selectedItem() != 0);
00145
00146 mEditButton->setEnabled( state );
00147 mRemoveButton->setEnabled( state );
00148 }
00149
00150
#include "profiledialog.moc"