kpilot
dbSelectionDialog.ccGo to the documentation of this file.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 #include "options.h"
00032
00033 #include <qlistview.h>
00034 #include <qpushbutton.h>
00035 #include <klistview.h>
00036 #include <kmessagebox.h>
00037 #include <kpushbutton.h>
00038 #include <klineedit.h>
00039
00040 #include "dbSelection_base.h"
00041 #include "dbSelectionDialog.moc"
00042
00043
00044 KPilotDBSelectionDialog::KPilotDBSelectionDialog(QStringList &selectedDBs, QStringList &deviceDBs,
00045 QStringList &addedDBs, QWidget *w, const char *n) :
00046 KDialogBase(w, n, true, QString::null, KDialogBase::Ok | KDialogBase::Cancel,
00047 KDialogBase::Ok, false),
00048 fSelectedDBs(selectedDBs),
00049 fAddedDBs(addedDBs),
00050 fDeviceDBs(deviceDBs)
00051 {
00052 FUNCTIONSETUP;
00053
00054 fSelectionWidget = new KPilotDBSelectionWidget(this);
00055 setMainWidget(fSelectionWidget);
00056
00057
00058 QStringList items(deviceDBs);
00059 for ( QStringList::Iterator it = fAddedDBs.begin(); it != fAddedDBs.end(); ++it ) {
00060 if (items.contains(*it)==0) items << (*it);
00061 }
00062 for ( QStringList::Iterator it = fSelectedDBs.begin(); it != fSelectedDBs.end(); ++it ) {
00063 if (items.contains(*it)==0) items << (*it);
00064 }
00065 items.sort();
00066
00067 for ( QStringList::Iterator it = items.begin(); it != items.end(); ++it ) {
00068 QCheckListItem*checkitem=new QCheckListItem(fSelectionWidget->fDatabaseList,
00069 *it, QCheckListItem::CheckBox);
00070 if (fSelectedDBs.contains(*it)) checkitem->setOn(true);
00071 }
00072
00073 connect(fSelectionWidget->fNameEdit, SIGNAL(textChanged( const QString & )),
00074 this, SLOT(slotTextChanged( const QString &)));
00075 connect(fSelectionWidget->fAddButton, SIGNAL(clicked()),
00076 this, SLOT(addDB()));
00077 connect(fSelectionWidget->fRemoveButton, SIGNAL(clicked()),
00078 this, SLOT(removeDB()));
00079 }
00080
00081 KPilotDBSelectionDialog::~KPilotDBSelectionDialog()
00082 {
00083 FUNCTIONSETUP;
00084 }
00085
00086 void KPilotDBSelectionDialog::addDB()
00087 {
00088 FUNCTIONSETUP;
00089 QString dbname(fSelectionWidget->fNameEdit->text());
00090 if (!dbname.isEmpty())
00091 {
00092 fSelectionWidget->fNameEdit->clear();
00093 new QCheckListItem(fSelectionWidget->fDatabaseList, dbname,
00094 QCheckListItem::CheckBox);
00095 fAddedDBs << dbname;
00096 }
00097 }
00098
00099 void KPilotDBSelectionDialog::removeDB()
00100 {
00101 FUNCTIONSETUP;
00102 QListViewItem*item(fSelectionWidget->fDatabaseList->selectedItem());
00103 if (item)
00104 {
00105 QString dbname=item->text(0);
00106 if (fDeviceDBs.contains(dbname))
00107 {
00108 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"));
00109 }
00110 else
00111 {
00112 fSelectedDBs.remove(dbname);
00113 fAddedDBs.remove(dbname);
00114 KPILOT_DELETE(item);
00115 }
00116 }
00117 else
00118 {
00119 KMessageBox::information(this, i18n("You need to select a database to delete in the list."),i18n("No Database Selected"), CSL1("NoDBSelected"));
00120 }
00121 }
00122
00123 QStringList KPilotDBSelectionDialog::getSelectedDBs()
00124 {
00125 fSelectedDBs.clear();
00126
00127
00128 QListViewItemIterator it( fSelectionWidget->fDatabaseList );
00129 while ( it.current() ) {
00130 QCheckListItem *item = dynamic_cast<QCheckListItem*>(it.current());
00131 ++it;
00132
00133 if ( item && item->isOn() )
00134 fSelectedDBs << item->text();
00135 }
00136
00137 return fSelectedDBs;
00138 }
00139
00140 void KPilotDBSelectionDialog::slotTextChanged( const QString& dbname)
00141 {
00142 FUNCTIONSETUP;
00143 fSelectionWidget->fAddButton->setDisabled(dbname.isEmpty());
00144 }
|