kpilot

dbSelectionDialog.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 2003 Reinhold Kainhofer <reinhold@kainhofer.com>
00004 **
00005 ** This file defines a dialog box that lets the
00006 ** user select a set of databases (e.g. which databases
00007 ** should be ignored  when doing a backup)
00008 */
00009 
00010 /*
00011 ** This program is free software; you can redistribute it and/or modify
00012 ** it under the terms of the GNU General Public License as published by
00013 ** the Free Software Foundation; either version 2 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 ** GNU General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU General Public License
00022 ** along with this program in a file called COPYING; if not, write to
00023 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 ** MA 02110-1301, USA.
00025 */
00026 
00027 /*
00028 ** Bug reports and questions can be sent to kde-pim@kde.org
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     // Fill the encodings list
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     //  update the list of selected databases
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 }