DumontEXE 0.0.1
cmcConversation.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 <QStringList>
00026 
00027 #include "cmcConversation.h"
00028 
00029 namespace cmcDatabaseApi {
00030 
00031 cmcConversation::cmcConversation( const cmcConversation & copy ): 
00032   cmcApi( copy )
00033 {
00034 }
00035 
00036 cmcConversation::cmcConversation
00037 (
00038   const QString & applicationName,
00039   const QString & topic,
00040   IDispatch * dispatch,
00041   cmcApplication * app,
00042   QObject * parent
00043 ): 
00044   cmcApi( "Conversation", dispatch, app, parent )
00045 {
00046   setObjectName("Conversation");
00047 
00048 //  TRACE_FUNCTION
00049 }
00050 
00051 cmcConversation::~cmcConversation()
00052 {
00053 //  TRACE_FUNCTION
00054 }
00055 
00056 QString cmcConversation::request( const QString & req )
00057 {
00058   QString retVal;
00059 
00060   /*
00061   ** Clear the last error
00062   **
00063   */
00064   err.clear();
00065 
00066 //  qDebug( "request(\"%s\")", qPrintable(req) );
00067 
00068   retVal = GetServerString( "Request", req, DISPATCH_METHOD );
00069 
00070   return( retVal );
00071 }
00072 
00073 bool cmcConversation::execute( const QString & cmd )
00074 {
00075 //  if( eventTrace() )
00076 //    qDebug( "CV::execute(%s)", qPrintable(cmd) );
00077 
00078   /*
00079   ** Clear the last error
00080   **
00081   */
00082   err.clear();
00083 
00084   VARIANTARG varg[1];
00085   ::VariantInit(&varg[0]);     // Initialize the VARIANT.
00086 
00087   BSTR bstrCmd = ::SysAllocString((OLECHAR*)cmd.utf16());
00088 
00089   // load the variant
00090   varg[0].vt = VT_BSTR; varg[0].bstrVal = bstrCmd;
00091 
00092   // Fill in the DISPPARAMS structure.
00093   DISPPARAMS param;
00094   param.cArgs             = 1;     // Number of arguments
00095   param.rgvarg            = varg;  // Arguments
00096   param.cNamedArgs        = 0;     // Number of named args
00097   param.rgdispidNamedArgs = NULL;  // Named arguments
00098 
00099   // Allocate a variant for the returned parameter.
00100   VARIANT varResult;
00101   ::VariantInit(&varResult);
00102 
00103   // Invoke the function.
00104   HRESULT hr = Invoke
00105   (
00106     "Execute",
00107     IID_NULL,
00108     GetUserDefaultLCID(),
00109     DISPATCH_METHOD,
00110     &param,
00111     &varResult,
00112     NULL,
00113     NULL
00114   );
00115 
00116   ::SysFreeString(bstrCmd);
00117 
00118   if( FAILED(hr) )
00119   {
00120     err.set( 1, QString("cmcConversation::execute('%1'):Failed").arg(cmd) );
00121     return false;
00122   }
00123 
00124   // Display the returned string.
00125   if( varResult.vt == VT_BOOL )
00126   {
00127     if( varResult.boolVal ) return true;
00128     else                    return false;
00129   }
00130 
00131   return( false );
00132 }
00133 
00134 bool cmcConversation::addItem
00135 (
00136   const QString & categoryName,
00137   const QString & itemName,
00138   const QString & itemClarify
00139 )
00140 {
00141   return( execute
00142   (
00143     "[AddItem( "                  +
00144     dq(categoryName)              + "," +
00145     dq(itemName)                  + "," +
00146     dq(itemClarify)               + ")]"
00147   ) );
00148 }
00149 
00150 bool cmcConversation::addSharedItem
00151 (
00152   const QString & categoryName,
00153   const QString & itemName
00154 )
00155 {
00156   return( execute
00157   (
00158     "[AddSharedItem("             +
00159     dq(categoryName)              + "," +
00160     dq(itemName)                  + ")]"
00161   ) );
00162 }
00163 
00164 bool cmcConversation::appendText
00165 (
00166   const QString & categoryName,
00167   const QString & itemName,
00168   const QString & fieldName,
00169   const QString & appendText
00170 )
00171 {
00172   return( execute
00173   (
00174     "[AppendText("                +
00175     dq(categoryName)              + "," +
00176     dq(itemName)                  + "," +
00177     dq(fieldName)                 + "," +
00178     dq(appendText)                + ")]"
00179   ) );
00180 }
00181 
00182 bool cmcConversation::assignConnection
00183 (
00184   const QString & fromCategory,
00185   const QString & fromItem,
00186   const QString & connectionName,
00187   const QString & toCategory,
00188   const QString & toItem
00189 )
00190 {
00191   return( execute
00192   (
00193     "[AssignConnection("          +
00194     dq(fromCategory)              + "," +
00195     dq(fromItem)                  + "," +
00196     dq(connectionName)            + "," +
00197     dq(toCategory)                + "," +
00198     dq(toItem)                    + ")]"
00199   ) );
00200 }
00201 
00202 bool cmcConversation::checkInFormScript
00203 (
00204   const QString & categoryName,
00205   const QString & formName,
00206   const QString & fileName
00207 )
00208 {
00209   return( execute
00210   (
00211     "[CheckInFormScript("         +
00212     dq(categoryName)              + "," +
00213     dq(formName)                  + "," +
00214     dq(fileName)                  + ")]"
00215   ) );
00216 }
00217 
00218 bool cmcConversation::checkOutFormScript
00219 (
00220   const QString & categoryName,
00221   const QString & formName,
00222   const QString & fileName
00223 )
00224 {
00225   return( execute
00226   (
00227     "[CheckOutFormScript("        +
00228     dq(categoryName)              + "," +
00229     dq(formName)                  + "," +
00230     dq(fileName)                  + ")]"
00231   ) );
00232 }
00233 
00234 void cmcConversation::clarifyItemNames
00235 (
00236   const bool status
00237 )
00238 {
00239   request
00240   ( 
00241     "[ClarifyItemNames(" + 
00242     QString(status? "True":"False") + ")]" 
00243   );
00244 }
00245 
00246 bool cmcConversation::clarifyItemNames()
00247 {
00248   return
00249   ( 
00250     request("[ClarifyItemNames()]").split("\r\n")[0] == "True"? true:false 
00251   );
00252 }
00253 
00254 QString cmcConversation::databases()
00255 {
00256   return( request("[Databases]") );
00257 }
00258 
00259 bool cmcConversation::deleteItem
00260 ( 
00261   const QString & categoryName, 
00262   const QString & itemName 
00263 )
00264 {
00265   return( execute
00266   ( 
00267     "[DeleteItem("   + 
00268     dq(categoryName) + "," + 
00269     dq(itemName)     + ")]" 
00270   ) );
00271 }
00272 
00273 bool cmcConversation::deleteView
00274 (
00275   const QString & viewName
00276 )
00277 {
00278   return( execute
00279   (
00280     "[DeleteView(" +
00281     dq(viewName)   + ")]"
00282   ) );
00283 }
00284 
00285 bool cmcConversation::editItem
00286 (
00287   const QString & categoryName,
00288   const QString & itemName,
00289   const QString & fieldName,
00290   const QString & fieldValue
00291 )
00292 {
00293   return( execute
00294   (
00295     "[EditItem("     +
00296     dq(categoryName) + "," +
00297     dq(itemName)     + "," +
00298     dq(fieldName)    + "," +
00299     dq(fieldValue)   + ")]"
00300   ) );
00301 }
00302 
00303 bool cmcConversation::fireTrigger
00304 (
00305   const QString & trigger,
00306   const QString & arg2,
00307   const QString & arg3,
00308   const QString & arg4,
00309   const QString & arg5,
00310   const QString & arg6,
00311   const QString & arg7,
00312   const QString & arg8,
00313   const QString & arg9
00314 )
00315 {
00316   QString req = "[FireTrigger(" + dq(trigger);
00317   if( arg2 != "" )   req += "," + dq(arg2);
00318   if( arg3 != "" )   req += "," + dq(arg3);
00319   if( arg4 != "" )   req += "," + dq(arg4);
00320   if( arg5 != "" )   req += "," + dq(arg5);
00321   if( arg6 != "" )   req += "," + dq(arg6);
00322   if( arg7 != "" )   req += "," + dq(arg7);
00323   if( arg8 != "" )   req += "," + dq(arg8);
00324   if( arg9 != "" )   req += "," + dq(arg9);
00325   req += ")]";
00326   return( execute(req) );
00327 }
00328 
00329 
00330 QString cmcConversation::formats()
00331 {
00332   return( request("Formats") );
00333 }
00334 
00335 QString cmcConversation::getActiveViewInfo( const QString & delimiter )
00336 {
00337   return( request
00338   (
00339     "[GetActiveViewInfo(" + 
00340     dq(delimiter)         + ")]"
00341   ) );
00342 }
00343 
00344 QString cmcConversation::getCallerID
00345 (
00346   const QString & categoryName,
00347   const QString & phoneNumber,
00348   const QString & delimiter 
00349 )
00350 {
00351   return( request
00352   (
00353     "[GetCallerID("               +
00354     dq(categoryName)              + "," +
00355     dq(phoneNumber)               + "," +
00356     dq(delimiter)                 + ")]"
00357   ) );
00358 }
00359 
00360 long cmcConversation::getCategoryCount()
00361 {
00362   return( request( "[GetCategoryCount()]" ).toLong() );
00363 }
00364 
00365 QString cmcConversation::getCategoryDefinition
00366 (
00367   const QString & categoryName,
00368   const QString & delimiter
00369 )
00370 {
00371   return( request
00372   (
00373     "[GetCategoryDefinition("     +
00374     dq(categoryName)              + "," +
00375     dq(delimiter)                 + ")]"
00376   ) );
00377 }
00378 
00379 QString cmcConversation::getCategoryNames
00380 (
00381   const QString & delimiter
00382 )
00383 {
00384   return( request("[GetCategoryNames(" + delimiter + ")]") );
00385 }
00386 
00387 long cmcConversation::getConnectedItemCount
00388 (
00389   const QString & fromCategory,
00390   const QString & fromItem,
00391   const QString & connectionName,
00392   const QString & toCategory,
00393   const QString & delimiter
00394 )
00395 {
00396   return( request
00397   (
00398     "[GetConnectedItemCount("     + 
00399     dq(fromCategory)              + "," +
00400     dq(fromItem)                  + "," +
00401     dq(connectionName)            + "," +
00402     dq(toCategory)                + "," +
00403     dq(delimiter)                 + ")]"
00404   ).toLong() );
00405 }
00406 
00407 
00408 QString cmcConversation::getConnectedItemField
00409 (
00410   const QString & fromCategory,
00411   const QString & fromItem,
00412   const QString & connectionName,
00413   const QString & toCategory,
00414   const QString & toFieldName,
00415   const QString & delimiter
00416 )
00417 {
00418   return( request
00419   (
00420     "[GetConnectedItemField("     +
00421     dq(fromCategory)              + "," +
00422     dq(fromItem)                  + "," +
00423     dq(connectionName)            + "," +
00424     dq(toCategory)                + "," +
00425     dq(toFieldName)               + "," +
00426     dq(delimiter)                 + ")]"
00427   ) );
00428 }
00429 
00430 QString cmcConversation::getConnectedItemNames
00431 (
00432   const QString & fromCategory,
00433   const QString & fromItem,
00434   const QString & connectionName,
00435   const QString & toCategory,
00436   const QString & delimiter
00437 )
00438 {
00439   return( request
00440   (
00441     "[GetConnectedItemNames("     +
00442     dq(fromCategory)              + "," +
00443     dq(fromItem)                  + "," +
00444     dq(connectionName)            + "," +
00445     dq(toCategory)                + "," +
00446     dq(delimiter)                 + ")]"
00447   ) );
00448 }
00449 
00450 QString cmcConversation::getConnectionNames
00451 (
00452   const QString & categoryName,
00453   const QString & delimiter,
00454   const QString & conCatDelimiter
00455 )
00456 {
00457   return( request
00458   (
00459     "[GetConnectionNames("        +
00460     dq(categoryName)              + "," +
00461     dq(delimiter)                 + "," +
00462     dq(conCatDelimiter)           + ")]"
00463   ) );
00464 }
00465 
00466 QString cmcConversation::getDatabase
00467 (
00468   const QString & delimiter
00469 )
00470 {
00471   return( request
00472   (
00473     "[GetDatabase(" +
00474     dq(delimiter)   + ")]"
00475   ) );
00476 }
00477 
00478 QString cmcConversation::getDatabaseDefinition
00479 (
00480   const QString & delimiter
00481 )
00482 {
00483   return( request
00484   (
00485     "[GetDatabaseDefinition(" + 
00486     dq(delimiter)             + ")]"
00487   ) );
00488 }
00489 
00490 long cmcConversation::getDesktopCount()
00491 {
00492   return( request("[GetDesktopCount()]").toLong() );
00493 }
00494 
00495 QString cmcConversation::getDesktopNames
00496 (
00497   const QString & delimiter
00498 )
00499 {
00500   return( request
00501   (
00502     "[GetDesktopNames(" +
00503     dq(delimiter)       + ")]"
00504   ) );
00505 }
00506 
00507 QString cmcConversation::getField
00508 (
00509   const QString & categoryName,
00510   const QString & itemName,
00511   const QString & fieldName
00512 )
00513 {
00514   return( request
00515   (
00516     "[GetField("                  + 
00517     dq(categoryName)              + "," + 
00518     dq(itemName)                  + "," +
00519     dq(fieldName)                 + ")]"
00520   ) );
00521 }
00522 
00523 long cmcConversation::getFieldCount
00524 (
00525   const QString & categoryName
00526 )
00527 {
00528   return( request("[GetFieldCount(" + dq(categoryName) + ")]").toLong() );
00529 }
00530 
00531 QString cmcConversation::getFieldDefinition
00532 (
00533   const QString & categoryName,
00534   const QString & fieldName
00535 )
00536 {
00537   return( request
00538   (
00539     "[GetFieldDefinition("        +
00540     dq(categoryName)              + "," +
00541     dq(fieldName)                 + ")]"
00542   ) );
00543 }
00544 
00545 QString cmcConversation::getFieldNames
00546 (
00547   const QString & categoryName 
00548 )
00549 {
00550   return( request
00551   (
00552     "[GetFieldNames("             +
00553     dq(categoryName)              + ")]"
00554   ) );
00555 }
00556 
00557 bool cmcConversation::getFieldToFile
00558 (
00559   const QString & categoryName,
00560   const QString & itemName,
00561   const QString & fieldName,
00562   const QString & fileName
00563 )
00564 {
00565   request( "[GetFieldToFile("     + 
00566   dq(categoryName)                + "," +
00567   dq(itemName)                    + "," +
00568   dq(fieldName)                   + "," +
00569   dq(fileName)                    + ")]"
00570   );
00571   return( true );
00572 }
00573 
00574 long cmcConversation::getFormCount
00575 (
00576   const QString & categoryName
00577 )
00578 {
00579   return( request
00580   (
00581     "[GetFormCount(" + 
00582     dq(categoryName) + ")]").toLong() 
00583   );
00584 }
00585 
00586 
00587 QString cmcConversation::getFormNames
00588 ( 
00589   const QString & categoryName 
00590 )
00591 {
00592   return( request
00593   (
00594     "[GetFormNames("              + 
00595     dq(categoryName)              + ")]"
00596   ) );
00597 }
00598 
00599 long cmcConversation::getItemCount
00600 (
00601   const QString & categoryName
00602 )
00603 {
00604   return( request
00605   (
00606     "[GetItemCount(" +
00607     dq(categoryName) + ")]"
00608   ).toLong() );
00609 }
00610 
00611 
00612 
00613 
00614 QString cmcConversation::getMeField
00615 (
00616   const QString & fieldName
00617 )
00618 {
00619   return( request
00620   (
00621     "[GetMeField("             + 
00622     dq(fieldName)              + ")]"
00623   ) );
00624 }
00625 
00626 QString cmcConversation::getPreference
00627 (
00628   const QString & setting 
00629 )
00630 {
00631   return( request
00632   (
00633     "[GetPreference("        + 
00634     dq(setting)              + ")]"
00635   ) );
00636 }
00637 
00638 QString cmcConversation::getViewNames
00639 (
00640   const QString & categoryName
00641 )
00642 {
00643   return( request
00644   (
00645     "[GetViewNames("              + 
00646     dq(categoryName)              + ")]"
00647   ) );
00648 }
00649 
00650 bool cmcConversation::showItem
00651 (
00652   const QString & categoryName,
00653   const QString & itemName,
00654   const QString & formName
00655 )
00656 {
00657   QString cmd =
00658     "[ShowItem("     +
00659     dq(categoryName) + "," + 
00660     dq(itemName);
00661 
00662   if( formName != "" )
00663     cmd += "," + dq(formName);
00664 
00665   cmd += ")]";
00666 
00667   return( execute(cmd) );
00668 }
00669 
00670 
00671 bool cmcConversation::showView
00672 (
00673   const QString & viewName,
00674   bool reopen
00675 
00676 )
00677 {
00678   return( execute
00679   (
00680     "[ShowView("         +
00681     dq(viewName)         + "," + QString(reopen? "1":"0") + ")]"
00682   ) );
00683 }
00684 
00685 
00686 
00687 bool cmcConversation::viewCategory
00688 (
00689   const QString & categoryName
00690 )
00691 {
00692   return( request
00693   (
00694     "[ViewCategory(" +
00695     dq(categoryName) + ")]"
00696 
00697   ) == "OK"? true:false );
00698 
00699 }
00700 
00701 bool cmcConversation::viewFilter
00702 (
00703   const QString & filter
00704 )
00705 {
00706   QString f = filter;
00707 
00708   if( !f.contains("[ViewFilter(") )
00709     f = "[ViewFilter(" + f + ")]";
00710 
00711   return( request(f)=="OK"? true:false );
00712 }
00713 
00714 
00715 long cmcConversation::viewItemCount()
00716 {
00717   return( request( "[ViewItemCount()]" ).toLong() ); // [ViewItemCount()]
00718 }
00719 
00720 
00721 bool cmcConversation::viewMarkItem
00722 (
00723   long index
00724 )
00725 {
00726   // [ViewMarkItem(Index)]
00727   return( request
00728   ( 
00729     "[ViewMarkItem(" + 
00730     QString::number(index) + ")]" 
00731 
00732   )=="OK"? true:false );
00733 }
00734 
00735 
00736 
00737 
00738 } // endnamespace cmcDatabaseApi
00739 
 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