DumontEXE 0.0.1
cmcCda.cpp
00001 /* ***************************************************************************
00002 **
00003 ** Copyright (C) 2007 Lorimark Solutions, LLC. All rights reserved.
00004 **
00005 ** This file is part of the DumontEXE Scripting Extension Kit
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://dumont.showoff-db.org/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://dumont.showoff-db.org/licensing.html 
00017 ** or contact the sales department at sales@lorimarksolutions.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ** author: Mark Petryk ~ Lorimark Solutions, LLC
00023 ** **************************************************************************/
00024 
00025 #include <QSettings>
00026 #include <QDir>
00027 
00028 #include "cmcCda.h"
00029 
00030 #include "cmcApplication.h"
00031 #include "cmcCategoryDef.h"
00032 #include "cmcVersion.h"
00033 
00034 
00035 namespace cmcDatabaseApi {
00036 
00037 cmcCda::cmcCda( const cmcCda & copy )
00038 {
00039 //  TRACE_FUNCTION
00040   init();
00041 }
00042 
00043 cmcCda::cmcCda( QObject * parent )
00044 : cmcObject( parent )
00045 //: QAbstractItemModel( parent )
00046 {
00047 //  TRACE_FUNCTION
00048   init();
00049 }
00050 
00051 cmcCda::cmcCda( cmcApplication * app )
00052 : cmcObject( "cda", app, app )
00053 //: QAbstractItemModel( app )
00054 {
00055 //  TRACE_FUNCTION
00056   init();
00057 }
00058 
00059 cmcCda::~cmcCda()
00060 {
00061 //  TRACE_FUNCTION
00062 
00063   delete m_ini;
00064 
00065   delete m_rootItem;
00066 }
00067 
00068 void cmcCda::init()
00069 {
00070   m_cdaReadyChecked = false;
00071 
00072   rootItem();
00073 }
00074 
00075 cmcApplication * cmcCda::app()
00076 {
00077   return( qobject_cast<cmcApplication*>(parent()) );
00078 }
00079 
00080 
00081 bool cmcCda::ready()
00082 {
00083   if( !m_cdaReadyChecked )
00084   {
00085     /*
00086     ** If the database has changed from what we originally registered
00087     **  then there's nothing we can do.
00088     **
00089     */
00090 //    if( !sameDatabase() )
00091 //    {
00092 //      err.set( 2, QString("database has changed. cannot save!") );
00093 //      return( false );
00094 //    }
00095 
00096     /*
00097     ** We check the readyness of the cda only once and then cache the
00098     **  answer.  This allows this call to be made frequently in the system
00099     **  without compromising speed.
00100     **
00101     */
00102     m_cdaReadyChecked = true;
00103     m_cdaReady        = false;
00104 
00105     /*
00106     ** If a category exists for the cda, then we know we have a category
00107     **  dedicated to the cmcDatabaseApi.
00108     **
00109     */
00110     if( app()-> categoryDef( catName() ) )
00111     {
00112       /*
00113       ** If the CDA_CATNAME category contains a detail form called CDA_FRMNAME
00114       **  then we know we have a category dedicated to the Cmc Database Api
00115       **  that is also capable of storing the extended application definition
00116       **  attributes.
00117       **
00118       */
00119       if( app()-> categoryDef( catName() )-> formDef( frmName() ) ) 
00120       {
00121         /*
00122         ** Get a handle on the database directory.
00123         **
00124         */
00125         QDir dbDir( app()-> databaseDirectory() );
00126 
00127         /*
00128         ** Make a temp for the cda directory path.
00129         **
00130         */
00131         QString dbCda = dbDir.absolutePath() + dirName();
00132 
00133         /*
00134         ** Look for the cda directory.  If it doesn't exist then create it.
00135         **  This way, after checking the previous conditions for the cda
00136         **  readyness, then we insure that the cda directory is ready to
00137         **  go.
00138         **
00139         */
00140         if( !dbDir.exists( dbCda ) )
00141              dbDir.mkdir(  dbCda ) ;
00142 
00143         /*
00144         ** Make one final check of the cda directory.  If it doesn't exist
00145         **  then we were unable to create it.
00146         **
00147         */
00148         if( !dbDir.exists( dbCda ) )
00149         {
00150 //          err.set( 2, QString("unable to create cda directory: %1").arg(dbCda) );
00151           return( false );
00152         }
00153 
00154         m_cdaReady = true;
00155       }
00156       else
00157       {
00158 //        err.set( 2, QString("no CDA form: %1").arg(frmName()) );
00159       }
00160 
00161     }
00162     else
00163     {
00164 //      err.set( 3, QString("no CDA category: %1").arg(catName()) );
00165     }
00166   }
00167 
00168   return( m_cdaReady );
00169 
00170 } // endbool cmcApplication::cdaReady()
00171 
00172 QString cmcCda::version()
00173 {
00174   return( CDALIB_VERSION );
00175 }
00176 
00177 QString cmcCda::objName()
00178 {
00179   return( "cda" );
00180 }
00181 
00182 QString cmcCda::dirName()
00183 {
00184   return( "\\" + objName() );
00185 }
00186 
00187 QString cmcCda::datName()
00188 {
00189   return( dirName() + "\\data.bin" );
00190 }
00191 
00192 QString cmcCda::catName()
00193 {
00194   return( "~" + objName() );
00195 }
00196 
00197 QString cmcCda::frmName()
00198 {
00199   return( "~" + objName() );
00200 }
00201 
00202 QString cmcCda::iniName()
00203 {
00204   return( app()-> databaseDirectory() + "\\" + objName() + ".ini" );
00205 }
00206 
00207 QString cmcCda::datFile()
00208 {
00209   return( app()-> databaseDirectory() + datName() );
00210 }
00211 
00212 QSettings * cmcCda::settings()
00213 {
00214   if( !m_ini )
00215        m_ini = new QSettings( iniName(), QSettings::IniFormat );
00216 
00217   return( m_ini );
00218 }
00219 
00220 cmcCdaItem * cmcCda::rootItem()
00221 {
00222   if( !m_rootItem )
00223        m_rootItem = new cmcCdaItem( QString("root"), this );
00224 
00225   return( m_rootItem );
00226 }
00227 
00228 
00229 //QModelIndex cmcCda::index( int row, int column, const QModelIndex & parent ) const
00230 //{
00231 //  return( QModelIndex() );
00232 //}
00233 //
00234 //QModelIndex cmcCda::parent( const QModelIndex & ) const
00235 //{
00236 //}
00237 //
00238 //int cmcCda::rowCount( const QModelIndex & ) const
00239 //{
00240 //}
00241 //
00242 //int cmcCda::columnCount( const QModelIndex & ) const
00243 //{
00244 //}
00245 //
00246 //QVariant cmcCda::data( const QModelIndex &, int ) const
00247 //{
00248 //}
00249 
00250 
00251 } // endnamespace cmcDatabaseApi
00252 
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties




~ ~ ~ ~ ~ ~
Source Code without Comments is like a Cranberry Garland
without the berries. Comment your Code!
 
Commence Database User Support Group Forum
http://newsgroup.showoff-db.org/
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC
mark@lorimarksolutions.com