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 "options.h"
00029 
00030 #include <pi-dlp.h>
00031 
00032 #include <qlineedit.h>
00033 #include <qcheckbox.h>
00034 #include <qtextcodec.h>
00035 #include <kdatewidget.h>
00036 #include <ktimewidget.h>
00037 #include <kmessagebox.h>
00038 
00039 #include "pilotAppCategory.h"
00040 #include "dbFlagsEditor.h"
00041 #include "dbFlagsEditor_base.h"
00042 
00043 
00044 DBFlagsEditor::DBFlagsEditor(DBInfo*dbinfo, QWidget *parent) :
00045     KDialogBase(parent, "FlagsEditor",false,
00046         i18n("Edit Database Flags"), Ok|Cancel), 
00047     dbi(dbinfo)
00048 {
00049     widget=new DBFlagsEditorWidget(this);
00050     setMainWidget(widget);
00051     fillWidgets();
00052 }
00053 
00054 
00055 DBFlagsEditor::~DBFlagsEditor()
00056 {
00057 }
00058 
00059 void DBFlagsEditor::slotOk()
00060 {
00061     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)
00062     {
00063         strlcpy(dbi->name, PilotAppCategory::codec()->fromUnicode(widget->fDBName->text()), 33);
00064 
00065         char buff[5];
00066         strlcpy(buff, widget->fType->text().latin1(), 5);
00067         dbi->type=get_long(buff);
00068 
00069         strlcpy(buff, widget->fCreator->text().latin1(), 5);
00070         dbi->creator=get_long(buff);
00071 
00072 
00073 #define setflag(ctrl, flag) if (widget->ctrl->isChecked()) dbi->flags |=flag;\
00074     else dbi->flags &= ~flag;
00075 
00076         setflag(fRessourceDB, dlpDBFlagResource);
00077         setflag(fReadOnly, dlpDBFlagReadOnly);
00078         setflag(fBackupDB, dlpDBFlagBackup);
00079         setflag(fCopyProtect, dlpDBFlagCopyPrevention);
00080         setflag(fReset, dlpDBFlagReset);
00081 #undef setflag
00082 
00083         if (widget->fExcludeDB->isChecked())
00084             dbi->miscFlags |= dlpDBMiscFlagExcludeFromSync;
00085         else    dbi->miscFlags &= ~dlpDBMiscFlagExcludeFromSync;
00086 
00087         QDateTime ttime;
00088         ttime.setDate(widget->fCreationDate->date());
00089 #if KDE_IS_VERSION(3,1,9)
00090         ttime.setTime(widget->fCreationTime->time());
00091 #endif
00092         dbi->createDate=ttime.toTime_t();
00093 
00094         ttime.setDate(widget->fModificationDate->date());
00095 #if KDE_IS_VERSION(3,1,9)
00096         ttime.setTime(widget->fModificationTime->time());
00097 #endif
00098         dbi->modifyDate=ttime.toTime_t();
00099 
00100         ttime.setDate(widget->fBackupDate->date());
00101 #if KDE_IS_VERSION(3,1,9)
00102         ttime.setTime(widget->fBackupTime->time());
00103 #endif
00104         dbi->backupDate=ttime.toTime_t();
00105 
00106         KDialogBase::slotOk();
00107     }
00108 }
00109 
00110 void DBFlagsEditor::slotCancel()
00111 {
00112     KDialogBase::slotCancel();
00113 }
00114 
00115 void DBFlagsEditor::fillWidgets()
00116 {
00117     // FUNCTIONSETUP
00118 
00119     widget->fDBName->setText(QString::fromLatin1(dbi->name));
00120 
00121     char buff[5];
00122     set_long(buff, dbi->type);
00123     buff[4]='\0';
00124     widget->fType->setText(QString::fromLatin1(buff));
00125     set_long(buff, dbi->creator);
00126     buff[4]='\0';
00127     widget->fCreator->setText(QString::fromLatin1(buff));
00128 
00129     widget->fRessourceDB->setChecked(dbi->flags & dlpDBFlagResource);
00130     widget->fReadOnly->setChecked(dbi->flags & dlpDBFlagReadOnly);
00131     widget->fBackupDB->setChecked(dbi->flags & dlpDBFlagBackup);
00132     widget->fCopyProtect->setChecked(dbi->flags & dlpDBFlagCopyPrevention);
00133 
00134     widget->fReset->setChecked(dbi->flags & dlpDBFlagReset);
00135     widget->fExcludeDB->setChecked(dbi->miscFlags & dlpDBMiscFlagExcludeFromSync);
00136 
00137     QDateTime ttime;
00138     ttime.setTime_t(dbi->createDate);
00139     widget->fCreationDate->setDate(ttime.date());
00140 #if KDE_IS_VERSION(3,1,9)
00141     widget->fCreationTime->setTime(ttime.time());
00142 #endif
00143 
00144     ttime.setTime_t(dbi->modifyDate);
00145     widget->fModificationDate->setDate(ttime.date());
00146 #if KDE_IS_VERSION(3,1,9)
00147     widget->fModificationTime->setTime(ttime.time());
00148 #endif
00149 
00150     ttime.setTime_t(dbi->backupDate);
00151     widget->fBackupDate->setDate(ttime.date());
00152 #if KDE_IS_VERSION(3,1,9)
00153     widget->fBackupTime->setTime(ttime.time());
00154 #endif
00155 }
00156 
00157 
00158 #include "dbFlagsEditor.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys