int main(int argc, char *argv[]) { // NB: you don't really have to do this if your library links ok // but I tested it and it works and gives a nice message, rw. // //QLibrary otapi("libotapi.so"); // <===== FIRST constructor called. //if (!otapi.load()) // qDebug() << otapi.errorString(); //if (otapi.load()) // qDebug() << "otapi loaded"; // ---------------------------------------- // AppInit() is called here by this object's constructor. (And // AppCleanup() will be called automatically when we exit main(), // by this same object's destructor.) // __OTclient_RAII the_client_cleanup; // <===== SECOND constructor is called here. // ---------------------------------------- if (NULL == OTAPI_Wrap::It()) { OTLog::vError(0, "Error, exiting: OTAPI_Wrap::AppInit() call must have failed.\n"); return -1; } // ---------------------------------------- //Init qApp MTApplicationMC theApplication(argc, argv); // <====== THIRD constructor (they are destroyed in reverse order.) theApplication.setQuitOnLastWindowClosed(false); //Set language Translation appTranslation; QTranslator translator; appTranslation.updateLanguage(theApplication, translator); QTimer::singleShot(0, &theApplication, SLOT(appStarting())); // ---------------------------------------------------------------- int nExec = theApplication.exec(); // <=== Here's where we run the QApplication... // ---------------------------------------------------------------- OTLog::vOutput(0, "Finished executing the QApplication!\n(AppCleanup should occur " "immediately after this point.)\nReturning: %d\n", nExec); // ---------------------------------------------------------------- return nExec; }
int main(int argc, char *argv[]) { // NB: you don't really have to do this if your library links ok // but I tested it and it works and gives a nice message, rw. // //QLibrary otapi("libotapi.so"); // <===== FIRST constructor called. //if (!otapi.load()) // qDebug() << otapi.errorString(); //if (otapi.load()) // qDebug() << "otapi loaded"; // ---------------------------------------- // AppInit() is called here by this object's constructor. (And // AppCleanup() will be called automatically when we exit main(), // by this same object's destructor.) // __OTclient_RAII the_client_cleanup; // <===== SECOND constructor is called here. // ---------------------------------------- if (NULL == opentxs::OTAPI_Wrap::It()) { opentxs::Log::vError(0, "Error, exiting: opentxs::OTAPI_Wrap::AppInit() call must have failed.\n"); return -1; } // ---------------------------------------- //Init qApp MTApplicationMC theApplication(argc, argv); // <====== THIRD constructor (they are destroyed in reverse order.) theApplication.setQuitOnLastWindowClosed(false); { Modules modules; } // run constructor once, initialize static pointers BtcModulesPtr btcModules = BtcModulesPtr(new BtcModules()); //Set language Translation appTranslation; QTranslator translator; appTranslation.updateLanguage(theApplication, translator); QTimer::singleShot(0, &theApplication, SLOT(appStarting())); // ---------------------------------------------------------------- // ---------------------------------------------------------------- // NOTE: What's this about? // // For the Mac version only (and ONLY for actual release dmg's) we // want the scripts folder to be found inside the application directory, // near the binary itself. // // This is because we get problems with the MacOS .dmg where especially on // Mavericks, the sandbox prevents us from opening the scripts (ot_commands.ot, etc) // which on UNIX systems, are normally found in /usr/local/lib/opentxs // // There are several solutions at play. First, we are eliminating the scripts entirely, // by converting them to C++. But in the meantime, until that's done, we have to live with // the scripts, so we are putting them in a place where the application CAN open them: // the application folder itself. That is, the "AppBinaryFolder". // // Here we use QCoreApplication::applicationDirPath() to get the application folder path, // and we tell OT to use that as the "AppBinaryFolder". OT doesn't use that variable except // in one place: when setting the Scripts directory -- and ONLY if the variable is set (and // we ARE setting it here below.) // // If the variable is set (and in this case, it is) then OT will use the AppBinaryFolder instead // of the PrefixPath, to prepend to the Scripts path. This will cause OT to look for the scripts // in the ApplicationDirPath/lib/opentxs folder instead of /usr/local/lib/opentxs // // Notice also we are checking the path to see if it contains "clang" and "build", and we only // set the AppBinaryFolder in the case where those substrings are both NOT found. That way this // fix will not impact developer builds, but only actual release DMGs. // // This fix assumes that the DMG contains, in the MacOS folder, next to moneychanger-qt and mc_db, // a folder "lib", which contains a folder "opentxs", which contains the scripts. If those files // are not placed there in the DMG, then this code would obviously cause OT to fail trying to load // its scripts. // #ifdef Q_OS_MAC QString qstrAppDirPath = QCoreApplication::applicationDirPath(); if (!qstrAppDirPath.isEmpty()) { int nIndexClang = qstrAppDirPath.indexOf("clang", 0); int nIndexBuild = qstrAppDirPath.indexOf("build", 0); if ((-1 == nIndexClang) && (-1 == nIndexBuild)) opentxs::OTPaths::SetAppBinaryFolder(qstrAppDirPath.toStdString().c_str()); } // QMessageBox::information(NULL, "", QString::fromStdString(std::string(opentxs::OTPaths::ScriptsFolder().Get()))); #endif // ---------------------------------------------------------------- int nExec = theApplication.exec(); // <=== Here's where we run the QApplication... // ---------------------------------------------------------------- Moneychanger::It(NULL, true); // bShuttingDown=true. // ---------------------------------------------------------------- opentxs::Log::vOutput(0, "Finished executing the QApplication!\n(AppCleanup should occur " "immediately after this point.)\nReturning: %d\n", nExec); // ---------------------------------------------------------------- return nExec; }
/* ======= WinMain ======= */ int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow ) { HWND hwnd; MSG msg; /* Initialise and create window */ hwnd = CreateOurWindow( "Mirrors and Shadows", S_WIDTH, S_HEIGHT, 0, false, hInstance ); if( hwnd == NULL ) return true; /* Initialise OpenGL and other settings */ Init( hwnd ); /* Create the OpenGLApplication */ OpenGLApplication theApplication( mInput, mCamera ); theApplication.Init(); /* Main Loop */ while( true ) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if( msg.message == WM_QUIT ) { break; } TranslateMessage( &msg ); DispatchMessage( &msg ); /* Render Scene */ } else { /* Update Input and Camera */ mInput.Update(); mCamera.Update(); /* Switch to WireFrame */ if( mInput.mKeys[ VK_SPACE ] ) { glPolygonMode( GL_FRONT, GL_LINE ); } else { glPolygonMode( GL_FRONT, GL_FILL ); } /* Display Controls */ if( mInput.mKeys[ VK_CONTROL ] ) { theApplication.mDisplayControls = true; } else { theApplication.mDisplayControls = false; } /* Start OpenGl - clear buffers & load identity matrix */ glClearStencil( 0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glLoadIdentity(); /* Set our viewpoint - the camera */ gluLookAt( mCamera.mPosition.x, mCamera.mPosition.y, mCamera.mPosition.z, // where we are mCamera.mPointOfInterest.x, mCamera.mPointOfInterest.y, mCamera.mPointOfInterest.z, // what we look at mCamera.mUp.x, mCamera.mUp.y, mCamera.mUp.z ); // which way is up /* Render the Application */ theApplication.Render(); /* End OpenGL - swap the frame buffers */ SwapBuffers( ghdc ); } } return msg.wParam ; }