kpilot/kpilot

dbFlagsEditor.cc

00001 /* KPilot
00002 **
00003 ** Copyright (C) 2003 Reinhold Kainhofer <reinhold@kainhofer.com>
00004 **
00005 **/
00006 
00007 /*
00008 ** This program is free software; you can redistribute it and/or modify
00009 ** it under the terms of the GNU General Public License as published by
00010 ** the Free Software Foundation; either version 2 of the License, or
00011 ** (at your option) any later version.
00012 **
00013 ** This program is distributed in the hope that it will be useful,
00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016 ** GNU General Public License for more details.
00017 **
00018 ** You should have received a copy of the GNU General Public License
00019 ** along with this program in a file called COPYING; if not, write to
00020 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00021 ** MA 02110-1301, USA.
00022 */
00023 
00024 /*
00025 ** Bug reports and questions can be sent to kde-pim@kde.org
00026 */
00027 
00028 #include <config.h>
00029 #include "options.h"
00030 #include "fakes.h"
00031 
00032 #include <pi-dlp.h>
00033 
00034 #include <qlineedit.h>
00035 #include <qcheckbox.h>
00036 #include <kdatewidget.h>
00037 #include <ktimewidget.h>
00038 #include <kmessagebox.h>
00039 
00040 #include "pilotRecord.h"
00041 #include "dbFlagsEditor.h"
00042 #include "dbFlagsEditor_base.h"
00043 
00044 
00045 DBFlagsEditor::DBFlagsEditor(DBInfo*dbinfo, QWidget *parent) :
00046     KDialogBase(parent, "FlagsEditor",false,
00047         i18n("Edit Database Flags"), Ok|Cancel),
00048     dbi(dbinfo)
00049 {
00050     widget=new DBFlagsEditorWidget(this);
00051     setMainWidget(widget);
00052     fillWidgets();
00053 }
00054 
00055 
00056 DBFlagsEditor::~DBFlagsEditor()
00057 {
00058 }
00059 
00060 void DBFlagsEditor::slotOk()
00061 {
00062     if (KMessageBox::questionYesNo(this, i18n("Changing the database flags might corrupt the whole database, or make the data unusable. Do not change the values unless you are absolutely sure you know what you are doing.\n\nReally assign these new flags?"), i18n("Changing Database Flags"),i18n("Assign"),KStdGuiItem::cancel())==KMessageBox::Yes)
00063     {
00064         Pilot::toPilot(widget->fDBName->text(),dbi->name,33);
00065 
00066         char buff[5];
00067         strlcpy(buff, widget->fType->text().latin1(), 5);
00068         dbi->type=get_long(buff);
00069 
00070         strlcpy(buff, widget->fCreator->text().latin1(), 5);
00071         dbi->creator=get_long(buff);
00072 
00073 
00074 #define setflag(ctrl, flag) if (widget->ctrl->isChecked()) dbi->flags |=flag;\
00075     else dbi->flags &= ~flag;
00076 
00077         setflag(fRessourceDB, dlpDBFlagResource);
00078         setflag(fReadOnly, dlpDBFlagReadOnly);
00079         setflag(fBackupDB, dlpDBFlagBackup);
00080         setflag(fCopyProtect, dlpDBFlagCopyPrevention);
00081         setflag(fReset, dlpDBFlagReset);
00082 #undef setflag
00083 
00084         if (widget->fExcludeDB->isChecked())
00085             dbi->miscFlags |= dlpDBMiscFlagExcludeFromSync;
00086         else    dbi->miscFlags &= ~dlpDBMiscFlagExcludeFromSync;
00087 
00088         QDateTime ttime;
00089         ttime.setDate(widget->fCreationDate->date());
00090 #if KDE_IS_VERSION(3,1,9)
00091         ttime.setTime(widget->fCreationTime->time());
00092 #endif
00093         dbi->createDate=ttime.toTime_t();
00094 
00095         ttime.setDate(widget->fModificationDate->date());
00096 #if KDE_IS_VERSION(3,1,9)
00097         ttime.setTime(widget->fModificationTime->time());
00098 #endif
00099         dbi->modifyDate=ttime.toTime_t();
00100 
00101         ttime.setDate(widget->fBackupDate->date());
00102 #if KDE_IS_VERSION(3,1,9)
00103         ttime.setTime(widget->fBackupTime->time());
00104 #endif
00105         dbi->backupDate=ttime.toTime_t();
00106 
00107         KDialogBase::slotOk();
00108     }
00109 }
00110 
00111 void DBFlagsEditor::slotCancel()
00112 {
00113     KDialogBase::slotCancel();
00114 }
00115 
00116 void DBFlagsEditor::fillWidgets()
00117 {
00118     // FUNCTIONSETUP
00119 
00120     widget->fDBName->setText(QString::fromLatin1(dbi->name));
00121 
00122     char buff[5];
00123     set_long(buff, dbi->type);
00124     buff[4]='\0';
00125     widget->fType->setText(QString::fromLatin1(buff));
00126     set_long(buff, dbi->creator);
00127     buff[4]='\0';
00128     widget->fCreator->setText(QString::fromLatin1(buff));
00129 
00130     widget->fRessourceDB->setChecked(dbi->flags & dlpDBFlagResource);
00131     widget->fReadOnly->setChecked(dbi->flags & dlpDBFlagReadOnly);
00132     widget->fBackupDB->setChecked(dbi->flags & dlpDBFlagBackup);
00133     widget->fCopyProtect->setChecked(dbi->flags & dlpDBFlagCopyPrevention);
00134 
00135     widget->fReset->setChecked(dbi->flags & dlpDBFlagReset);
00136     widget->fExcludeDB->setChecked(dbi->miscFlags & dlpDBMiscFlagExcludeFromSync);
00137 
00138     QDateTime ttime;
00139     ttime.setTime_t(dbi->createDate);
00140     widget->fCreationDate->setDate(ttime.date());
00141 #if KDE_IS_VERSION(3,1,9)
00142     widget->fCreationTime->setTime(ttime.time());
00143 #endif
00144 
00145     ttime.setTime_t(dbi->modifyDate);
00146     widget->fModificationDate->setDate(ttime.date());
00147 #if KDE_IS_VERSION(3,1,9)
00148     widget->fModificationTime->setTime(ttime.time());
00149 #endif
00150 
00151     ttime.setTime_t(dbi->backupDate);
00152     widget->fBackupDate->setDate(ttime.date());
00153 #if KDE_IS_VERSION(3,1,9)
00154     widget->fBackupTime->setTime(ttime.time());
00155 #endif
00156 }
00157 
00158 
00159 #include "dbFlagsEditor.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys