kpilot Library API Documentation

dbSelectionDialog.cc

00001 /* dbSelectionDialog.cc KPilot 00002 ** 00003 ** Copyright (C) 2003 by Dan Pilone 00004 ** Created 2003 by Reinhold Kainhofer 00005 ** 00006 ** This file defines a dialog box that lets the 00007 ** user select a set of databases (e.g. which databases 00008 ** should be ignored when doing a backup) 00009 */ 00010 00011 /* 00012 ** This program is free software; you can redistribute it and/or modify 00013 ** it under the terms of the GNU General Public License as published by 00014 ** the Free Software Foundation; either version 2 of the License, or 00015 ** (at your option) any later version. 00016 ** 00017 ** This program is distributed in the hope that it will be useful, 00018 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 ** GNU General Public License for more details. 00021 ** 00022 ** You should have received a copy of the GNU General Public License 00023 ** along with this program in a file called COPYING; if not, write to 00024 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00025 ** MA 02111-1307, USA. 00026 */ 00027 00028 /* 00029 ** Bug reports and questions can be sent to kde-pim@kde.org 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 // Fill the encodings list 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 // update the list of selected databases 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 }
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:48 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003