kpilot Library API Documentation

MultiDB-setup.cc

00001 /* MultiDB-setup.cc                        KPilot
00002 **
00003 ** Copyright (C) 2001 by Dan Pilone
00004 ** Copyright (C) 2002 by Reinhold Kainhofer
00005 **
00006 ** This file defines the factory for the MultiDB-conduit plugin.
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 ** MA 02111-1307, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 #include "options.h"
00031 
00032 #include <qpushbutton.h>
00033 #include <qtabwidget.h>
00034 #include <qlineedit.h>
00035 #include <qradiobutton.h>
00036 #include <qbuttongroup.h>
00037 
00038 #include <kconfig.h>
00039 #include <kinstance.h>
00040 #include <kaboutdata.h>
00041 #include <kfiledialog.h>
00042 #include <klistview.h>
00043 
00044 /*#include "MultiDB-conduitDialog.h"
00045 #include "MultiDB-factory.h"*/
00046 #include "MultiDB-conduit.h"
00047 #include "MultiDB-setup.moc"
00048 #include "DatabaseAction.h"
00049 //#include "DatabaseActiondlgPrivate.h"
00050 
00051 
00052 MultiDBWidgetSetup::MultiDBWidgetSetup(QWidget *w, const char *n,
00053         const QStringList & a, SyncTypeList_t *lst=0L, KAboutData *abt) : ConduitConfig(w,n,a) {
00054         FUNCTIONSETUP;
00055 
00056         fConfigWidget = new MultiDBWidgetPrivate(widget());
00057         setTabWidget(fConfigWidget->tabWidget);
00058         addAboutPage(false, abt);
00059         synctypes=lst;
00060         
00061         SyncTypeIterator_t it(*synctypes);
00062         KPilotSyncType *st;
00063         while ( (st = it.current()) != 0 ) {
00064                 ++it;
00065                 QRadioButton*btn=fConfigWidget->InsertRadioButton(st->LongName, st->ShortName.latin1());
00066 /*              if (st->getFlag(SYNC_NEEDSFILE)) {
00067                         QObject::connect(btn, SIGNAL(toggled(bool)), fConfigWidget->TextFileName, SLOT(setEnabled(bool)));
00068                 } else {
00069                         QObject::connect(btn, SIGNAL(toggled(bool)), fConfigWidget->TextFileName, SLOT(setDisabled(bool)));
00070                 }*/
00071         }
00072         
00073         QObject::connect(fConfigWidget->ListDatabases, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(edit(QListViewItem*)));
00074         QObject::connect(fConfigWidget->PushNew,SIGNAL(clicked()), this, SLOT(insert_db()));
00075         QObject::connect(fConfigWidget->PushEdit,SIGNAL(clicked()), this, SLOT(edit_db()));
00076         QObject::connect(fConfigWidget->PushDelete,SIGNAL(clicked()), this, SLOT(delete_db()));
00077         
00078         // Make the 1st and 3rd columns of the database list editable inline
00079         fConfigWidget->ListDatabases->setRenameable(0, true);
00080         fConfigWidget->ListDatabases->setRenameable(2, true);
00081 
00082 }
00083 
00084 MultiDBWidgetSetup::~MultiDBWidgetSetup() {
00085         FUNCTIONSETUP;
00086 }
00087 
00088 void MultiDBWidgetSetup::slotOk() {
00089         commitChanges();
00090         ConduitConfig::slotOk();
00091 }
00092 
00093 void MultiDBWidgetSetup::slotApply() {
00094         commitChanges();
00095         ConduitConfig::slotApply();
00096 }
00097 
00098 
00099 /* virtual */ void MultiDBWidgetSetup::commitChanges() {
00100         FUNCTIONSETUP;
00101 
00102         if (!fConfig) return;
00103         KConfigGroupSaver s(fConfig, getSettingsGroup());
00104         
00105         // walk through all items in the database list and commit the settings
00106         QListViewItem*item=fConfigWidget->ListDatabases->firstChild();
00107         QStringList strl;
00108         while (item) {
00109                 strl << item->text(0);
00110                 fConfig->writeEntry(item->text(0)+"_"+getSyncTypeEntry(), item->text(3));
00111                 fConfig->writeEntry(item->text(0)+"_"+getSyncFileEntry(), item->text(2));
00112                 item=item->nextSibling();
00113         }
00114         
00115         // now write out the default settings
00116         fConfig->writeEntry(settingsFileList(), strl);
00117         // TODO: This only works when the numbering starts from 0 and goes straight up to n.
00118         // This should do some translation from the id to the actual synctype!!!
00119         fConfig->writeEntry(getSettingsDefaultAct(),
00120                 fConfigWidget->DefaultSyncTypeGroup->id(
00121                         fConfigWidget->DefaultSyncTypeGroup->selected())
00122         );
00123 }
00124 
00125 /* virtual */ void MultiDBWidgetSetup::readSettings() {
00126         FUNCTIONSETUP;
00127 
00128         if (!fConfig) {
00129                 DEBUGCONDUIT << fname << ": !fConfig..." << endl;
00130                 return;
00131         }
00132 
00133         KConfigGroupSaver s(fConfig, getSettingsGroup());
00134         QStringList strl=fConfig->readListEntry(settingsFileList());
00135         
00136         for (QStringList::Iterator it = strl.begin(); it != strl.end(); ++it ) {
00137                 int synctypeentry=fConfig->readNumEntry((*it)+"_"+getSyncTypeEntry());
00138                 (void) new KListViewItem(fConfigWidget->ListDatabases, (*it),
00139                                         ActIdToName(synctypeentry),
00140                                         fConfig->readEntry((*it)+"_"+getSyncFileEntry()),
00141                                         fConfig->readEntry((*it)+"_"+getSyncTypeEntry()) );
00142         }
00143 
00144         // TODO: This only works when the numbering starts from 0 and goes straight up to n.
00145         // This should do some translation from the synctype to the actual id!!!
00146         fConfigWidget->DefaultSyncTypeGroup->setButton(fConfig->readNumEntry(getSettingsDefaultAct()));
00147 }
00148 
00149 void MultiDBWidgetSetup::insert_db() {
00150         FUNCTIONSETUP;
00151 
00152         KListViewItem*newitem=new KListViewItem(fConfigWidget->ListDatabases, i18n("New Item"), "ASK", "");
00153         fConfigWidget->ListDatabases->setSelected(newitem, true);
00154         edit(newitem);
00155 }
00156 
00157 void MultiDBWidgetSetup::edit(QListViewItem*listitem){
00158         FUNCTIONSETUP;
00159         if (listitem) {
00160                 DBSyncInfo item(listitem);
00161                 DBSettings*actiondlg=new DBSettings(this, "dbsettings", &item, synctypes);
00162                 if (actiondlg->exec()==QDialog::Accepted ) {
00163                         listitem->setText(0, item.dbname);
00164                         QString act;
00165                         listitem->setText(1, ActIdToName(item.syncaction));
00166                         listitem->setText(2, item.filename);
00167                         listitem->setText(3, act.arg(item.syncaction));
00168                 }
00169                 delete actiondlg;
00170         }
00171 }
00172 
00173 void MultiDBWidgetSetup::edit_db() {
00174         FUNCTIONSETUP;
00175 
00176         QListViewItem*listitem=fConfigWidget->ListDatabases->selectedItem();
00177         edit(listitem);
00178 }
00179 
00180 QString MultiDBWidgetSetup::ActIdToName(int act) {
00181         SyncTypeIterator_t it( *synctypes );
00182         KPilotSyncType *st;
00183         while ( (st = it.current()) != 0 ) {
00184                 ++it;
00185                 if (st->id==act) return st->ShortName;
00186         }
00187         return "";
00188 }
00189 int MultiDBWidgetSetup::ActNameToId(QString act) {
00190         SyncTypeIterator_t it( *synctypes );
00191         KPilotSyncType *st;
00192         while ( (st = it.current()) != 0 ) {
00193                 ++it;
00194                 if (st->ShortName==act) return st->id;
00195         }
00196         return st_ask;
00197 }
00198 
00199 void MultiDBWidgetSetup::delete_db() {
00200         FUNCTIONSETUP;
00201 
00202         QListViewItem*listitem=fConfigWidget->ListDatabases->selectedItem();
00203         fConfigWidget->ListDatabases->takeItem(listitem);
00204         delete listitem;
00205 }
00206 
00207 // $Log: MultiDB-setup.cc,v $
00208 // Revision 1.1.4.1  2003/03/12 23:31:10  adridg
00209 // CVS_SILENT: FSF address change
00210 //
00211 // Revision 1.1  2002/04/07 12:09:43  kainhofe
00212 // Initial checkin of the conduit. The gui works mostly, but syncing crashes KPilot...
00213 //
00214 // Revision 1.1  2002/04/07 01:03:52  reinhold
00215 // the list of possible actions is now created dynamically
00216 //
00217 // Revision 1.9  2002/04/05 21:17:00  reinhold
00218 // *** empty log message ***
00219 //
00220 // Revision 1.8  2002/04/01 14:36:49  reinhold
00221 // edit KListViewItems for DB setup inline
00222 // use QStringList instead of QStrList
00223 //
00224 // Revision 1.7  2002/03/28 13:47:53  reinhold
00225 // Added the list of synctypes, aboutbox is now directly passed on to the setup dlg (instead of being a static var)
00226 //
00227 // Revision 1.5  2002/03/15 20:43:17  reinhold
00228 // Fixed the crash on loading (member function not defined)...
00229 //
00230 // Revision 1.4  2002/03/13 22:14:40  reinhold
00231 // GUI should work now...
00232 //
00233 // Revision 1.3  2002/03/10 23:58:32  reinhold
00234 // Made the conduit compile...
00235 //
00236 // Revision 1.2  2002/03/10 16:06:43  reinhold
00237 // Cleaned up the class hierarchy, implemented some more features (should be quite finished now...)
00238 //
00239 // Revision 1.1.1.1  2002/03/09 15:38:45  reinhold
00240 // Initial checin of the  project manager / List manager conduit.
00241 //
00242 //
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:44 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001