kpilot
config_dialog_dbselection.cc
Go 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 #include "config_dialog_dbselection.h"
00031
00032 #include <kmessagebox.h>
00033
00034 #include "options.h"
00035
00036 static inline void appendStringList(QStringList &items, const QStringList &add)
00037 {
00038 QStringList::ConstIterator e = add.end();
00039 for ( QStringList::ConstIterator it = add.begin(); it != e; ++it )
00040 {
00041 if (items.contains(*it)==0)
00042 {
00043 items << (*it);
00044 }
00045 }
00046 }
00047
00048 KPilotDBSelectionDialog::KPilotDBSelectionDialog(const QStringList &selectedDBs,
00049 const QStringList &deviceDBs, const QStringList &addedDBs, QWidget *w, const char *n) :
00050 KDialog(w),
00051 fSelectedDBs(selectedDBs),
00052 fAddedDBs(addedDBs),
00053 fDeviceDBs(deviceDBs)
00054 {
00055 FUNCTIONSETUP;
00056
00057 if (n)
00058 {
00059 setObjectName(n);
00060 }
00061 setButtons(Ok|Cancel);
00062 setDefaultButton(Ok);
00063 setModal(false);
00064
00065 if( !w )
00066 {
00067 w = new QWidget( this );
00068 }
00069
00070 fSelectionWidget.setupUi( w );
00071 setMainWidget( w );
00072
00073
00074 QStringList items(deviceDBs);
00075 appendStringList(items, fAddedDBs);
00076 appendStringList(items, fSelectedDBs);
00077 items.sort();
00078
00079 for ( QStringList::Iterator it = items.begin(); it != items.end(); ++it )
00080 {
00081 QListWidgetItem *checkitem = new QListWidgetItem(*it
00082 , fSelectionWidget.fDatabaseList);
00083 checkitem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled
00084 | Qt::ItemIsUserCheckable);
00085 checkitem->setCheckState(fSelectedDBs.contains(*it) ? Qt::Checked
00086 : Qt::Unchecked);
00087 }
00088
00089 fSelectionWidget.fAddButton->setEnabled(false);
00090 fSelectionWidget.fRemoveButton->setEnabled(false);
00091
00092 connect(fSelectionWidget.fNameEdit, SIGNAL(textChanged( const QString & )),
00093 this, SLOT(textChanged( const QString &)));
00094 connect(fSelectionWidget.fAddButton, SIGNAL(clicked()),
00095 this, SLOT(addDB()));
00096 connect(fSelectionWidget.fRemoveButton, SIGNAL(clicked()),
00097 this, SLOT(removeDB()));
00098 connect(fSelectionWidget.fDatabaseList, SIGNAL(currentRowChanged(int)),
00099 this, SLOT(dbSelectionChanged(int)) );
00100 }
00101
00102 KPilotDBSelectionDialog::~KPilotDBSelectionDialog()
00103 {
00104 FUNCTIONSETUP;
00105 }
00106
00107 void KPilotDBSelectionDialog::addDB()
00108 {
00109 FUNCTIONSETUP;
00110 QString dbname(fSelectionWidget.fNameEdit->text());
00111 if (!dbname.isEmpty())
00112 {
00113 fSelectionWidget.fNameEdit->clear();
00114 QListWidgetItem *checkitem = new QListWidgetItem(dbname
00115 , fSelectionWidget.fDatabaseList);
00116 checkitem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled
00117 | Qt::ItemIsUserCheckable);
00118 checkitem->setCheckState(Qt::Unchecked);
00119 fAddedDBs << dbname;
00120 }
00121 }
00122
00123 void KPilotDBSelectionDialog::removeDB()
00124 {
00125 FUNCTIONSETUP;
00126 QListWidgetItem *item(fSelectionWidget.fDatabaseList->currentItem());
00127 if (item)
00128 {
00129 QString dbname=item->text();
00130 if (fDeviceDBs.contains(dbname))
00131 {
00132 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"));
00133 }
00134 else
00135 {
00136 fSelectedDBs.removeAll(dbname);
00137 fAddedDBs.removeAll(dbname);
00138 KPILOT_DELETE(item);
00139 }
00140 }
00141 else
00142 {
00143 KMessageBox::information(this, i18n("You need to select a database to delete in the list."),i18n("No Database Selected"), CSL1("NoDBSelected"));
00144 }
00145 }
00146
00147 QStringList KPilotDBSelectionDialog::getSelectedDBs()
00148 {
00149 fSelectedDBs.clear();
00150
00151
00152 int c = fSelectionWidget.fDatabaseList->count();
00153 for (int i = 0; i<c; ++i)
00154 {
00155 QListWidgetItem *item = fSelectionWidget.fDatabaseList->item(i);
00156
00157 if ( item && item->checkState() )
00158 {
00159 fSelectedDBs << item->text();
00160 }
00161 }
00162
00163 return fSelectedDBs;
00164 }
00165
00166 void KPilotDBSelectionDialog::textChanged( const QString& dbname)
00167 {
00168 FUNCTIONSETUP;
00169 fSelectionWidget.fAddButton->setDisabled(dbname.isEmpty());
00170 }
00171
00172 void KPilotDBSelectionDialog::dbSelectionChanged( int row )
00173 {
00174 FUNCTIONSETUP;
00175 fSelectionWidget.fRemoveButton->setEnabled( row >= 0 );
00176 }
00177
00178