• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kpilot

config_dialog_dbselection.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 #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     // Fill the encodings list
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     //  update the list of selected databases
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 

kpilot

Skip menu "kpilot"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal