dbSelectionDialog.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "options.h"
00033
00034 #include <qlistview.h>
00035 #include <qpushbutton.h>
00036 #include <klistview.h>
00037 #include <kmessagebox.h>
00038 #include <kpushbutton.h>
00039 #include <klineedit.h>
00040
00041 #include "dbSelection_base.h"
00042 #include "dbSelectionDialog.moc"
00043
00044
00045 KPilotDBSelectionDialog::KPilotDBSelectionDialog(QStringList &selectedDBs, QStringList &deviceDBs,
00046 QStringList &addedDBs, QWidget *w, const char *n) :
00047 KDialogBase(w, n, true, QString::null, KDialogBase::Ok | KDialogBase::Cancel,
00048 KDialogBase::Ok, false),
00049 fSelectedDBs(selectedDBs),
00050 fAddedDBs(addedDBs),
00051 fDeviceDBs(deviceDBs)
00052 {
00053 FUNCTIONSETUP;
00054
00055 fSelectionWidget = new KPilotDBSelectionWidget(this);
00056 setMainWidget(fSelectionWidget);
00057
00058
00059 QStringList items(deviceDBs);
00060 for ( QStringList::Iterator it = fAddedDBs.begin(); it != fAddedDBs.end(); ++it ) {
00061 if (items.contains(*it)==0) items << (*it);
00062 }
00063 for ( QStringList::Iterator it = fSelectedDBs.begin(); it != fSelectedDBs.end(); ++it ) {
00064 if (items.contains(*it)==0) items << (*it);
00065 }
00066 items.sort();
00067
00068 for ( QStringList::Iterator it = items.begin(); it != items.end(); ++it ) {
00069 QCheckListItem*checkitem=new QCheckListItem(fSelectionWidget->fDatabaseList,
00070 *it, QCheckListItem::CheckBox);
00071 if (fSelectedDBs.contains(*it)) checkitem->setOn(true);
00072 }
00073
00074 connect(fSelectionWidget->fNameEdit, SIGNAL(textChanged( const QString & )),
00075 this, SLOT(slotTextChanged( const QString &)));
00076 connect(fSelectionWidget->fAddButton, SIGNAL(clicked()),
00077 this, SLOT(addDB()));
00078 connect(fSelectionWidget->fRemoveButton, SIGNAL(clicked()),
00079 this, SLOT(removeDB()));
00080 }
00081
00082 KPilotDBSelectionDialog::~KPilotDBSelectionDialog()
00083 {
00084 FUNCTIONSETUP;
00085 }
00086
00087 void KPilotDBSelectionDialog::addDB()
00088 {
00089 FUNCTIONSETUP;
00090 QString dbname(fSelectionWidget->fNameEdit->text());
00091 if (!dbname.isEmpty())
00092 {
00093 fSelectionWidget->fNameEdit->clear();
00094 new QCheckListItem(fSelectionWidget->fDatabaseList, dbname,
00095 QCheckListItem::CheckBox);
00096 fAddedDBs << dbname;
00097 }
00098 }
00099
00100 void KPilotDBSelectionDialog::removeDB()
00101 {
00102 FUNCTIONSETUP;
00103 QListViewItem*item(fSelectionWidget->fDatabaseList->selectedItem());
00104 if (item)
00105 {
00106 QString dbname=item->text(0);
00107 if (fDeviceDBs.contains(dbname))
00108 {
00109 KMessageBox::error(this, i18n("This is a database that exists on the device. It was not added manually, so it can not removed from the list."), i18n("Database on Device"));
00110 }
00111 else
00112 {
00113 fSelectedDBs.remove(dbname);
00114 fAddedDBs.remove(dbname);
00115 KPILOT_DELETE(item);
00116 }
00117 }
00118 else
00119 {
00120 KMessageBox::information(this, i18n("You need to select a database to delete in the list."),i18n("No Database Selected"), "NoDBSelected");
00121 }
00122 }
00123
00124 QStringList KPilotDBSelectionDialog::getSelectedDBs()
00125 {
00126 fSelectedDBs.clear();
00127
00128
00129 QListViewItemIterator it( fSelectionWidget->fDatabaseList );
00130 while ( it.current() ) {
00131 QCheckListItem *item = dynamic_cast<QCheckListItem*>(it.current());
00132 ++it;
00133
00134 if ( item && item->isOn() )
00135 fSelectedDBs << item->text();
00136 }
00137
00138 return fSelectedDBs;
00139 }
00140
00141 void KPilotDBSelectionDialog::slotTextChanged( const QString& dbname)
00142 {
00143 FUNCTIONSETUP;
00144 fSelectionWidget->fAddButton->setDisabled(dbname.isEmpty());
00145 }
This file is part of the documentation for kpilot Library Version 3.2.2.