bool SessionManager::open(const QString& name_){ if(_docMgr.closeAllIfPossible()){ _currentSession = name_; SessionSettings s; QList<QStringList> views; s.load(_currentSession, views); if(views.size() == 1){ //open in the active view //to be sure another won't be activated for nothing _docMgr.blockSignals(true); _docMgr.open(views[0]); _docMgr.blockSignals(false); }else{ for(int i = 0; i < views.size(); i++){ _docMgr.blockSignals(true); _docMgr.open(views[i], i); _docMgr.blockSignals(false); } } //update main window emit activeDocumentChanged(_docMgr.getActiveDocument()); return true; }else{ error(); return false; } }
void SessionManager::saveStartSession(){ SessionSettings s; QString tmp = _currentSession; _currentSession = startSessionId; save(); _currentSession = tmp; s.saveStartSessionName(startSessionId, _currentSession); if(!_currentSession.isEmpty()) save(); }
void SessionManager::openStartSession(){ SessionSettings s; _currentSession = s.loadStartSessionName(startSessionId); if(_currentSession.isEmpty()){ open(startSessionId); _currentSession = ""; }else{ open(_currentSession); } }
void ThreadedSocketAcceptor::onInitialize( const SessionSettings& s ) throw ( RuntimeError ) { short port = 0; std::set<int> ports; std::set<SessionID> sessions = s.getSessions(); std::set<SessionID>::iterator i = sessions.begin(); for( ; i != sessions.end(); ++i ) { const Dictionary& settings = s.get( *i ); port = (short)settings.getInt( SOCKET_ACCEPT_PORT ); m_portToSessions[port].insert( *i ); if( ports.find(port) != ports.end() ) continue; ports.insert( port ); const bool reuseAddress = settings.has( SOCKET_REUSE_ADDRESS ) ? settings.getBool( SOCKET_REUSE_ADDRESS ) : true; const bool noDelay = settings.has( SOCKET_NODELAY ) ? settings.getBool( SOCKET_NODELAY ) : false; const int sendBufSize = settings.has( SOCKET_SEND_BUFFER_SIZE ) ? settings.getInt( SOCKET_SEND_BUFFER_SIZE ) : 0; const int rcvBufSize = settings.has( SOCKET_RECEIVE_BUFFER_SIZE ) ? settings.getInt( SOCKET_RECEIVE_BUFFER_SIZE ) : 0; int socket = socket_createAcceptor( port, reuseAddress ); if( socket < 0 ) { SocketException e; socket_close( socket ); throw RuntimeError( "Unable to create, bind, or listen to port " + IntConvertor::convert( (unsigned short)port ) + " (" + e.what() + ")" ); } if( noDelay ) socket_setsockopt( socket, TCP_NODELAY ); if( sendBufSize ) socket_setsockopt( socket, SO_SNDBUF, sendBufSize ); if( rcvBufSize ) socket_setsockopt( socket, SO_RCVBUF, rcvBufSize ); m_socketToPort[socket] = port; m_sockets.insert( socket ); } }
void SessionManager::save(){ SessionSettings s; QList<QStringList> views; if(_docMgr.getViewNumber() == 1){ //get list in the active view views << _docMgr.getDocumentsNameList(); }else{ for(int i = 0; i < _docMgr.getViewNumber(); i++){ views << _docMgr.getDocumentsNameList(i); } } s.save(_currentSession, views); }
void ThreadedSocketAcceptor::onConfigure( const SessionSettings& s ) throw ( ConfigError ) { std::set<SessionID> sessions = s.getSessions(); std::set<SessionID>::iterator i; for( i = sessions.begin(); i != sessions.end(); ++i ) { const Dictionary& settings = s.get( *i ); settings.getInt( SOCKET_ACCEPT_PORT ); if( settings.has(SOCKET_REUSE_ADDRESS) ) settings.getBool( SOCKET_REUSE_ADDRESS ); if( settings.has(SOCKET_NODELAY) ) settings.getBool( SOCKET_NODELAY ); } }
void ThreadedSSLSocketInitiator::onConfigure(const SessionSettings &s) throw( ConfigError) { const Dictionary &dict = s.get(); if (dict.has(RECONNECT_INTERVAL)) m_reconnectInterval = dict.getInt(RECONNECT_INTERVAL); if (dict.has(SOCKET_NODELAY)) m_noDelay = dict.getBool(SOCKET_NODELAY); if (dict.has(SOCKET_SEND_BUFFER_SIZE)) m_sendBufSize = dict.getInt(SOCKET_SEND_BUFFER_SIZE); if (dict.has(SOCKET_RECEIVE_BUFFER_SIZE)) m_rcvBufSize = dict.getInt(SOCKET_RECEIVE_BUFFER_SIZE); }
/** * We are overidding start to prevent Adapter processing of session life cycle */ void QuickFIXAdapter::start() { //std::cout << "QuickFIXAdapter: start()" << std::endl; // Perform all QuickFIX initialisation std::string settingsFileName = "QuickFIXAdapter.cfg"; SessionSettings *settings = new SessionSettings( settingsFileName); std::cout << "QuickFIXAdapter: settings loaded from " << settingsFileName << std::endl; MyApplication *application = new MyApplication( this); FileStoreFactory *storeFactory = new FileStoreFactory(*settings); FileLogFactory *logFactory = new FileLogFactory(*settings); this->initiator = new SocketInitiator( *application, *storeFactory, *settings, *logFactory /*optional*/); //std::cout << "QuickFIXAdapter: starting initiator" << std::endl; this->initiator->start(); // memorize session std::set<SessionID> sessions = settings->getSessions(); std::cout << "QuickFIXAdapter: adapter started with " << sessions.size() << " session(s)" << std::endl; if( sessions.size() > 0) { this->session = FIX::Session::lookupSession( *sessions.begin()); } }
void HttpServer::startGlobal( const SessionSettings& s ) throw ( ConfigError, RuntimeError ) { Locker l( s_mutex ); if( !s.get().has(HTTP_ACCEPT_PORT) ) return; s_count += 1; if( !s_pServer ) { s_pServer = new HttpServer( s ); s_pServer->start(); } }
int guiMain(const po::variables_map& options) { { // by default on Windows the selection is hard to see in the main window, because it's some gray; QPalette pal (QApplication::palette()); pal.setColor(QPalette::Highlight, pal.color(QPalette::Active, QPalette::Highlight)); pal.setColor(QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::HighlightedText)); QApplication::setPalette(pal); } getDefaultFont(); // !!! to initialize the static var string strStartSession; string strLastSession; int nSessCnt; bool bOpenLast; string strTempSessTempl; string strDirSessTempl; //bool bIsTempSess (false); string strTempSession (getSepTerminatedDir(convStr(QDir::tempPath())) + TEMP_SESS + SessionEditorDlgImpl::SESS_EXT); string strFolderSess; bool bHideFolderSess (true); if (options.count(s_hiddenFolderSessOpt.m_szLongOpt) > 0) { strFolderSess = options[s_hiddenFolderSessOpt.m_szLongOpt].as<string>(); } else if (options.count(s_loadedFolderSessOpt.m_szLongOpt) > 0) { strFolderSess = options[s_loadedFolderSessOpt.m_szLongOpt].as<string>(); bHideFolderSess = false; } SessEraser sessEraser; strLastSession = getActiveSession(options, nSessCnt, bOpenLast, strTempSessTempl, strDirSessTempl); if (options.count(s_tempSessOpt.m_szLongOpt) > 0) { SessEraser::eraseTempSess(); strStartSession = strTempSession; if (strTempSessTempl.empty()) { strTempSessTempl = strLastSession; } if (!strTempSessTempl.empty()) { try { copyFile2(strTempSessTempl, strStartSession); } catch (...) { // nothing //ttt2 do more } } string strProcDir (options[s_tempSessOpt.m_szLongOpt].as<string>()); strProcDir = getNonSepTerminatedDir(convStr(QDir(fromNativeSeparators(convStr(strProcDir))).absolutePath())); setFolder(strStartSession, strProcDir); bOpenLast = true; } else if (!strFolderSess.empty()) { string strProcDir = getNonSepTerminatedDir(convStr(QDir(fromNativeSeparators(convStr(strFolderSess))).absolutePath())); //ttt2 test on root if (!dirExists(strProcDir)) { showMessage(0, QMessageBox::Critical, 0, 0, MainFormDlgImpl::tr("Error"), MainFormDlgImpl::tr("Folder \"%1\" doesn't exist. The program will exit ...").arg(convStr(strProcDir)), MainFormDlgImpl::tr("O&K")); return 1; } string strDirName (convStr(QFileInfo(convStr(strProcDir)).fileName())); if (strDirName.empty()) // it's a whole disk drive on Windows, e.g. D:\\ ; { strDirName += strProcDir[0]; strDirName += "-MP3Diags"; } strStartSession = getSepTerminatedDir(strProcDir) + strDirName + SessionEditorDlgImpl::SESS_EXT; if (bHideFolderSess) { sessEraser.m_strSessionToHide = strStartSession; } if (!fileExists(strStartSession)) { if (strDirSessTempl.empty()) { strDirSessTempl = strLastSession; } if (!strDirSessTempl.empty()) { try { copyFile2(strDirSessTempl, strStartSession); setFolder(strStartSession, strProcDir); } catch (...) { // nothing //ttt2 do more } } } ofstream out (strStartSession.c_str(), ios_base::app); if (!out) { showMessage(0, QMessageBox::Critical, 0, 0, MainFormDlgImpl::tr("Error"), MainFormDlgImpl::tr("Cannot write to file \"%1\". The program will exit ...").arg(convStr(strStartSession)), MainFormDlgImpl::tr("O&K")); return 1; } bOpenLast = true; } else if (0 == nSessCnt) { // first run; create a new session and run it SessionEditorDlgImpl dlg (0, "", SessionEditorDlgImpl::FIRST_TIME, ""); // ttt0 detect system locale dlg.setWindowIcon(QIcon(":/images/logo.svg")); strStartSession = dlg.run(); if (strStartSession.empty()) { return 0; } if ("*" == strStartSession) { strStartSession.clear(); } else { vector<string> vstrSess; //vstrSess.push_back(strStartSession); GlobalSettings st; st.saveSessions(vstrSess, strStartSession, dlg.shouldOpenLastSession(), "", "", dlg.getTranslation(), GlobalSettings::LOAD_EXTERNAL_CHANGES); } bOpenLast = true; } else { strStartSession = strLastSession; } bool bOpenSelDlg (strStartSession.empty() || !bOpenLast); try { for (;;) { { QFont fnt; string strNewFont (convStr(fnt.family())); int nNewSize (fnt.pointSize()); fixAppFont(fnt, strNewFont, nNewSize); } if (bOpenSelDlg) { SessionsDlgImpl dlg (0); dlg.setWindowIcon(QIcon(":/images/logo.svg")); strStartSession = dlg.run(); if (strStartSession.empty()) { return 0; } } bOpenSelDlg = true; CB_ASSERT (!strStartSession.empty()); bool bDefaultForVisibleSessBtn (true); //if (strStartSession != strTempSession) { vector<string> vstrSess; bool bOpenLast; string s, s1, s2, s3; GlobalSettings st; st.loadSessions(vstrSess, s, bOpenLast, s1, s2, s3); st.saveSessions(vstrSess, strStartSession, bOpenLast, s1, s2, s3, GlobalSettings::LOAD_EXTERNAL_CHANGES); bDefaultForVisibleSessBtn = (cSize(vstrSess) != 1 || !strFolderSess.empty() || vstrSess.end() != find(vstrSess.begin(), vstrSess.end(), strTempSession)); } { //ttt2 overkill - create a "CommonData" just to read the language setting SessionSettings settings (strStartSession); CommonData commonData(settings, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); settings.loadMiscConfigSettings(&commonData, SessionSettings::DONT_INIT_GUI); TranslatorHandler::getGlobalTranslator().setTranslation(commonData.m_strTranslation); // !!! must be done here, before the MainFormDlgImpl constructor } MainFormDlgImpl mainDlg (strStartSession, bDefaultForVisibleSessBtn); mainDlg.setWindowIcon(QIcon(":/images/logo.svg")); if (bDefaultForVisibleSessBtn) { mainDlg.setWindowTitle(QString(getAppName()) + " - " + convStr(SessionEditorDlgImpl::getTitleName(strStartSession))); } else { mainDlg.setWindowTitle(QString(getAppName())); } if (MainFormDlgImpl::OPEN_SESS_DLG != mainDlg.run()) { return 0; } } } catch (const exception& ex) { CB_ASSERT1 (false, ex.what()); } catch (...) // ttt2 for now it doesn't catch many exceptions; it seems that nothing can be done if an exception leaves a slot / event handler, but maybe there are ways around { /*QMessageBox dlg (QMessageBox::Critical, "Error", "Caught generic exception. Exiting ...", QMessageBox::Close, 0, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); dlg.exec(); qDebug("out - err");*/ CB_ASSERT (false); } /*mainDlg.show(); return app.exec();*/ }
void HttpServer::onConfigure( const SessionSettings& s ) throw ( ConfigError ) { m_port = s.get().getLong( HTTP_ACCEPT_PORT ); }