int main(int argc, char **argv) { if (argc < 3) { usage(); exit(EXIT_FAILURE); } options_t *options = parse_options(argc, argv); // opcoes const char *path = argv[argc-1]; pe_ctx_t ctx; pe_err_e err = pe_load_file(&ctx, path); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } err = pe_parse(&ctx); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } if (!pe_is_pe(&ctx)) EXIT_ERROR("not a valid PE file"); NODE_PERES *node = discoveryNodesPeres(&ctx); if (node == NULL) { fprintf(stderr, "this file has no resources\n"); return EXIT_SUCCESS; } if (options->all) { showInformations(node); showStatistics(node); extractResources(&ctx, node); } else { if (options->extract) extractResources(&ctx, node); if (options->info) showInformations(node); if (options->statistics) showStatistics(node); } freeNodes(node); // libera a memoria free_options(options); // free err = pe_unload(&ctx); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int consumeStream(Actuator ac) { char buf[MYBUFSIZ + 1]; /* use equal to Linux internal buffer size */ lng clk; char *endptr; lng l = 0; ssize_t m = 0; #ifdef _DEBUG_ACTUATOR_ mnstr_printf(ACout, "Consume stream\n"); #endif buf[0] = 0; while (tuples != events && (m = mnstr_readline(ac->fromServer, buf, MYBUFSIZ)) > 0) { buf[m] = 0; characters += m; received++; tuples++; if (trace) mnstr_printf(ACout, "%s%s", buf, (buf[m - 1] == '\n' ? "" : "\n")); /*mnstr_printf(ACout, "Received tuple[%d]:%s\n",received,buf);*/ endptr = 0; clk = strtoll(buf + 1, &endptr, 0); if (sendFirst == 0) sendFirst = clk; receivedLast = GDKusec(); if (receivedFirst == 0) receivedFirst = receivedLast; if (timestamp) { l = receivedLast - clk; #ifdef _DEBUG_ACTUATOR_ if (trace) mnstr_printf(ACout, "B#%d: " LLFMT " " LLFMT "\n", received, clk, l); #endif totallatency += l; } m = 0; if (statistics && (received % statistics) == 0) { showStatistics(); } } if (errno == EPIPE || errno == ECONNRESET) { mnstr_printf(ACout, "errno:%s\n", strerror(errno)); close_stream(ac->fromServer); } if (statistics) showStatistics(); #ifdef _DEBUG_ACTUATOR_ mnstr_printf(ACout, "tuples %d events %d \n", tuples, events); #endif if (tuples >= events) terminate(ac); return 0; }
bool showMenu() { cout << "Welcome to Student Performance Management System (SPMS)." << "\n"; cout << "\n"; cout << "1 - Add" << "\n"; cout << "2 - Remove" << "\n"; cout << "3 - Query" << "\n"; cout << "4 - Show ranking" << "\n"; cout << "5 - Show Statistics" << "\n"; cout << "0 - Exit" << "\n"; cout << "\n"; int n; cin >> n; switch ( n ) { case 1: while ( addStudents() ); break; case 2: while ( deleteStudents() ); break; case 3: while ( queryStudents() ); break; case 4: cout << "Showing the ranklist hurts students' self-esteem. Don't do that." << "\n"; break; case 5: showStatistics(); break; case 0: return false; } return true; }
static void stopListening(int i) { (void) i; signal(i, SIG_IGN); if (statistics) showStatistics(); exit(0); }
void HashTableManager::dialog() { cout << "Hash have been chosen automatically: SumHash." << endl; char keyPressed = 'x'; while (keyPressed != '0') { menu(); cin >> keyPressed; string str; switch (keyPressed) { case '1': { cout << "Enter the word you want to add: "; cin >> str; cout << endl; table->add(str, 1); break; } case '2': cout << "Enter the value you want to search: "; cin >> str; cout << endl; if (table->isExist(str)) { cout << "Word is exist." << endl; } else cout << "No such word." << endl; break; case '3': cout << "Enter the word you want to remove: "; cin >> str; cout << endl; try { table->remove(str); } catch (string exc) { cout << exc << endl; } break; case '4': cout << endl; showStatistics(); cout << endl; break; case '5': changeHash(); cout << "Hash Function has successfully changed." << endl; break; } } }
void MainWindow::on_btnRead_clicked() { btnBrowse->setEnabled(false); this->setCursor(Qt::WaitCursor); qApp->processEvents(); myStatusBar->showMessage(tr("Reading record file..")); clsRecFile recFile(this->strRecFile); int totleCompent = recFile.getRecordCout(); myStatusBar->showMessage(tr("Reading data file..")); clsDataFile dataFile(this->strDataFile,totleCompent); QList<DATA_FILE> dataRes = dataFile.getRes(); clsDbOp::getInst()->emptyMainSheet(); clsDbOp::getInst()->fillMainSheet(dataRes); myStatusBar->showMessage(tr("Reading step file..")); clsStepFile stepFile(this->strStepFile); stepFile.setTotleComp(dataRes.length()); QList<STEP_FILE>stepRes = stepFile.getStepData(); clsDbOp::getInst()->emptyDetailSheet(); clsDbOp::getInst()->fillDetailSheet(stepRes); double x =(1.0*clsDbOp::getInst()->getComponent().length()/1000.0); if(ceil(x)!=x) x++; txtPage->setMaximum((int)x); txtPage->setValue(1); showStatistics(clsDbOp::getInst()->getComponent(All).length(), clsDbOp::getInst()->getComponent(Pass).length(), clsDbOp::getInst()->getComponent(Fail).length()); mainSelectMode = All; stepSelectMode = All; rbMainAll->setChecked(true); rbStepAll->setChecked(true); myStatusBar->showMessage(tr("Creating MainSheet data sheet ..")); fillMainSheet(1); myStatusBar->showMessage(tr("Creating DetailSheet data sheet ..")); fillStepSheet(); myStatusBar->showMessage(tr("Done")); btnBrowse->setEnabled(true); this->setCursor(Qt::ArrowCursor); qApp->processEvents(); }
void ConnectWindow::onDisconnected() { QSettings settings; if (mode_ == MODE_OPEN_VPN) { ui.btnConnect->setStyleSheet("QPushButton {" "border-image :url(:/MainWindow/Images/btnOff.png);}"); ui.btnConnect->setEnabled(true); if ((settings.value("vpnKill").toString() == "true") && !killSwitch_->isActive() && (state_ == STATE_CONNECTED)) { killSwitch_->killInternet(); createButtonRestoreGw(); } if (settings.value("dnsLeakProtect", false).toBool()) { dnsLeaks_.enable(false); } state_ = STATE_DISCONNECTED; setBarInConnectstatus(false); showStatistics(false); ui.cbServer->setEnabled( true ); ui.cbEnableSmartDNS->setEnabled( true ); ui.lbStatusCon->setText(QString("<b>Status: </b><font color=\"red\">Disconnected</font>")); updateIP(); ui.tab->setEnabled(true); ui.tab_2->setEnabled(true); mainWindow_->setTrayStatusDisconnected(); } else { if (settings.value("dnsLeakProtect", false).toBool()) { dnsLeaks_.enable(false); } state_ = STATE_DISCONNECTED; setBarInConnectstatus(false); setSwitchOnSmartDNS(false); ui.pbSmartDns->setEnabled(true); ui.tab->setEnabled(true); ui.tab_2->setEnabled(true); mainWindow_->setTrayStatusDisconnected(); } }
void ConnectWindow::onConnected() { prevBytesIn = 0; prevBytesOut = 0; bFirstBytes = true; state_ = STATE_CONNECTED; mainWindow_->setTrayStatusConnected(); setBarInConnectstatus(false); if (mode_ == MODE_OPEN_VPN) { ui.btnConnect->setStyleSheet("QPushButton {border-image :url(:/MainWindow/Images/btnOn.png);}"); showStatistics(true); ui.cbServer->setEnabled( false ); ui.lbStatusCon->setText(QString("<b>Status: </b><font color=\"green\">Connected</font>")); updateIP(); QSettings settings; if (settings.value("dnsLeakProtect", false).toBool()) { dnsLeaks_.enable(true); } } else { QSettings settings; if (settings.value("dnsLeakProtect", false).toBool()) { dnsLeaks_.enable(true); } setSwitchOnSmartDNS( true ); } /*#if defined Q_OS_WIN timerVpnFeatures_ = startTimer(1500); #elif defined Q_OS_MAC timerVpnFeatures_ = startTimer(1); #endif*/ emit connected(); }
void ConnectWindow::onConnectionError(OPENVPN_ERROR err) { if (err == AUTH_ERROR) { QMessageBox::information((QWidget *)parent(), "VPNht", "Authorization failed"); } else if (err == PROXY_AUTH_ERROR) { QMessageBox::information((QWidget *)parent(), "VPNht", "Proxy authorization failed"); } else if (err == CANNOT_ALLOCATE_TUN_TAP) { QMessageBox::information((QWidget *)parent(), "VPNht", "There are no TAP-Windows adapters on this system. Please install."); } else { QMessageBox::information((QWidget *)parent(), "VPNht", "Error during connection number: " + QString::number(err)); } ui.btnConnect->setStyleSheet("QPushButton {" "border-image :url(:/MainWindow/Images/btnOff.png);}"); state_ = STATE_DISCONNECTED; setBarInConnectstatus(false); showStatistics(false); ui.cbServer->setEnabled( true ); ui.cbEnableSmartDNS->setEnabled( true ); ui.lbStatusCon->setText(QString("<b>Status: </b><font color=\"red\">Disconnected</font>")); ui.tab->setEnabled(true); ui.tab_2->setEnabled(true); ui.pbSmartDns->setEnabled(true); ui.btnConnect->setEnabled(true); mainWindow_->setTrayStatusDisconnected(false); }
ConnectWindow::ConnectWindow(QMenu *settingsMenu, QWidget *parent) : QWidget(parent), state_(STATE_DISCONNECTED), pbCancelCon(0), pbRestoreGateway(0), killSwitch_(NULL), getMyVpnIp_(NULL), mode_(MODE_OPEN_VPN), logDialog_(NULL) { ui.setupUi(this); #if defined Q_OS_WIN QString strUpdatedStyleSheet; QString strStyleSheet = ui.tabWidget->styleSheet(); QString matchStr = "QTabWidget:tab-bar{}"; int ind = strStyleSheet.indexOf(matchStr); Q_ASSERT(ind != -1); strUpdatedStyleSheet = strStyleSheet.left(ind); strUpdatedStyleSheet += "QTabWidget:tab-bar{left: 100px; top: 10px;}"; strUpdatedStyleSheet += strStyleSheet.right(strStyleSheet.length() - (ind + matchStr.length())); ui.tabWidget->setStyleSheet(strUpdatedStyleSheet); #endif ui.btnSettings->setMenu( settingsMenu ); showStatistics( false ); mainWindow_ = (MainWindow *)parent; killSwitch_ = new KillSwitch(this); QSettings settings; ui.cbEnableSmartDNS->setChecked(settings.value("openVpnDNSEnabled", true).toBool()); /*if (!connection_.initialize()) { QMessageBox::information(this, QApplication::applicationName(), tr("OpenVPN initialize error")); QTimer::singleShot(1, parent, SLOT(close())); return; } if (!connection_.tapInstalled()) { QMessageBox::question(this, QApplication::applicationName(), tr("TAP drivers not installed.")); QTimer::singleShot(1, this, SLOT(close())); return; } */ ui.cbServer->installEventFilter(this); logDialog_ = new ShowLog(this); connect(g_openVPNConnection, SIGNAL(log(QString)), logDialog_, SLOT(onUpdateLog(QString))); updateIP(); qRegisterMetaType<OPENVPN_ERROR>("OPENVPN_ERROR"); connect(ui.btnConnect, SIGNAL(clicked()), SLOT(onClickConnect())); connect(ui.cbEnableSmartDNS, SIGNAL(stateChanged(int)), SLOT(onDNSEnabledStateChanged(int))); connect(ui.pbSmartDnsHelp, SIGNAL(clicked()), SLOT(onSmartDnsHelp())); connect(ui.pbSmartDns, SIGNAL(clicked()), SLOT(onClickSmartDns())); connect(g_openVPNConnection, SIGNAL(connected()), SLOT(onConnected())); connect(g_openVPNConnection, SIGNAL(disconnected()), SLOT(onDisconnected())); connect(g_openVPNConnection, SIGNAL(error(OPENVPN_ERROR)), SLOT(onConnectionError(OPENVPN_ERROR))); connect(g_openVPNConnection, SIGNAL(disconnected()), SLOT(onDisconnected())); connect(g_openVPNConnection, SIGNAL(statisticsUpdated(long, long)), SLOT(onStatisticsChanged(long, long))); }
int runApp( options::variables_map const& opts ) { // Create renderer std::string cullingEngine = opts["cullingengine"].as<std::string>(); dp::culling::Mode cullingMode = dp::culling::Mode::AUTO; if ( cullingEngine == "cpu" ) { cullingMode = dp::culling::Mode::CPU; } else if ( cullingEngine == "gl_compute" ) { cullingMode = dp::culling::Mode::OPENGL_COMPUTE; } else if ( cullingEngine == "cuda" ) { cullingMode = dp::culling::Mode::CUDA; } else if ( cullingEngine != "auto" ) { std::cerr << "unknown culling engine, abort" << std::endl; return -1; } CFRPipelineSharedPtr renderer = CFRPipeline::create ( opts["renderengine"].as<std::string>().c_str() , getShaderManager( opts["shadermanager"].as<std::string>() ) , cullingMode ); //renderer->setCullingEnabled( opts["culling"].as<bool>() ); dp::sg::ui::ViewStateSharedPtr viewStateHandle = loadScene( opts["filename"].as<std::string>() ); g_viewState = viewStateHandle; if ( opts.count("replace") ) { // process replacements std::vector< std::string> replacementStrings = opts["replace"].as< std::vector<std::string > >(); dp::sg::algorithm::ReplacementMapNames replacements; for ( std::vector<std::string>::iterator it = replacementStrings.begin(); it != replacementStrings.end(); ++it ) { size_t equalChar = it->find_first_of(':'); if ( equalChar != std::string::npos && equalChar < it->size() - 1) { std::string str1 = it->substr( 0, equalChar ); std::string str2 = it->substr( equalChar + 1, it->size() - equalChar - 1); replacements[str1] = str2; } else { std::cerr << "invalid replacement token: " << *it << std::endl; } } dp::sg::algorithm::replacePipelineData( viewStateHandle->getScene(), replacements ); } if ( !opts["statistics"].empty() ) { showStatistics( viewStateHandle ); } dp::sg::ui::setupDefaultViewState( viewStateHandle ); if ( !opts["combineVertexAttributes"].empty() ) { combineVertexAttributes( viewStateHandle ); } { // Replace MatrixCamera by PerspectiveCamera to get all manipulator features if ( viewStateHandle->getCamera()->getObjectCode() == dp::sg::core::ObjectCode::MATRIX_CAMERA ) { dp::sg::core::PerspectiveCameraSharedPtr perspectiveCamera = dp::sg::core::PerspectiveCamera::create(); perspectiveCamera->setOrientation(viewStateHandle->getCamera()->getOrientation()); perspectiveCamera->setDirection((viewStateHandle->getCamera()->getDirection())); perspectiveCamera->setPosition(viewStateHandle->getCamera()->getPosition()); viewStateHandle->setAutoClipPlanes(true); viewStateHandle->setCamera(perspectiveCamera); } } if ( !opts["headlight"].empty() ) { // TODO is this still a bug? // Bug 914976 containsLight() doesn't find lights in the scene. Force adding the headlight anyway when the user specified it. if ( viewStateHandle /* && viewStateHandle->getScene() && !SceneLock( viewStateHandle->getScene() )->containsLight() */ && viewStateHandle->getCamera() && ( viewStateHandle->getCamera()->getNumberOfHeadLights() == 0 ) ) { // Use the defaults! Note that LightSource ambientColor is black. viewStateHandle->getCamera()->addHeadLight( dp::sg::core::createStandardPointLight() ); } } // Setup default OpenGL format descriptor // We need to create a default format first to be able to check if a stereo pixelformat is available later. // (An unfortunate RenderContextFormat.isAvailable() interface due to Linux.) dp::gl::RenderContextFormat format; // create a widget which shows the scene //dp::sg::ui::glut::SceneRendererWidget w( format ); GLUTMinimalCFR w; // TODO format is not yet supported #if 0 if (stereo) { format.setStereo( stereo ); if ( !w.setFormat( format ) ) // This automatically checks if the format is available. { std::cout << "Warning: No stereo pixelformat available." << std::endl; } } #endif viewStateHandle->setAutoClipPlanes( opts["autoclipplanes"].as<bool>() ); w.setViewState( viewStateHandle ); w.setSceneRenderer( renderer ); //always on if ( !opts["continuous"].empty() ) { w.setContinuousUpdate( true ); w.setShowFrameRate( true ); } if( opts["frames"].as<int>() != -1 ) { w.setNumberOfFrames( opts["frames"].as<int>() ); } w.setDuration( opts["duration"].as<double>() ); w.setWindowSize( 1280, 720 ); //w.show(); // Keep only once reference to the renderer in the widget. This is necessary since the OpenGL resources // used by the renderer must be deleted before the window gets destroyed. renderer.reset(); g_viewState->getCamera()->setPosition(dp::math::Vec3f(0.0f, 0.0f, 5.0f)); setLights(); glutMainLoop(); return w.getExitCode(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), gamewidget(new GameWidget(this)) { setWindowTitle("Blubbels"); // gamewidget->enableAnimations(settings.value("use_animation", USE_ANIMATIONS).toBool()); // gamewidget->enableSound(settings.value("use_sound", USE_SOUND).toBool()); gamewidget->enableAnimations(true); gamewidget->enableSound(false); setCentralWidget(gamewidget); setWindowIcon(QIcon("qrc:/blubbels.png")); //construct actions QAction *new_game = new QAction(QIcon(":/icons/new.png"), tr("&New Game"), this); new_game->setShortcut(tr("Ctrl+N")); QAction *undo = new QAction(QIcon(":/icons/undo.png"), tr("&Undo"), this); undo->setShortcut(tr("Ctrl+Z")); undo->setEnabled(false); use_sound = new QAction(tr("&Use Sound"), this); use_sound->setCheckable(true); // use_sound->setChecked(settings.value("use_sound", USE_SOUND).toBool()); use_animation = new QAction(tr("&Animate Bubbles"), this); use_animation->setCheckable(true); use_animation->setChecked(settings.value("use_animation", USE_ANIMATIONS).toBool()); /* #ifndef Q_WS_MAEMO_5 //create toolbar toolbar = new QToolBar(tr("Show Toolbar"), this); toolbar->setObjectName("toolBar"); //used by saveState() toolbar->addAction(new_game); toolbar->addSeparator(); toolbar->addAction(undo); //create menu QMenu *game_menu = menuBar()->addMenu(tr("&Game")); game_menu->addAction(new_game); game_menu->addSeparator(); game_menu->addAction(tr("&Statistics"), this, SLOT(showStatistics()), tr("Ctrl+S")); game_menu->addSeparator(); game_menu->addAction(tr("&Quit"), this, SLOT(close()), tr("Ctrl+Q")); QMenu *edit_menu = menuBar()->addMenu(tr("&Edit")); edit_menu->addAction(undo); QMenu *settings_menu = menuBar()->addMenu(tr("&Settings")); settings_menu->addAction(use_sound); settings_menu->addAction(use_animation); settings_menu->addSeparator(); settings_menu->addAction(toolbar->toggleViewAction()); QMenu *help_menu = menuBar()->addMenu(tr("&Help")); help_menu->addAction(tr("&How to Play"), this, SLOT(help()), tr("F1")); help_menu->addSeparator(); help_menu->addAction(tr("&About"), this, SLOT(about())); help_menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); #else*/ //maemo only supports a limited number of menu items menuBar()->addAction(tr("&Statistics"), this, SLOT(showStatistics())); menuBar()->addAction(tr("&About"), this, SLOT(about())); menuBar()->addAction(new_game); menuBar()->addAction(undo); //not visible when disabled, so we'll move it to the end to avoid confusion //set up portrait mode support /*orientation = new MaemoOrientation(this); connect(orientation, SIGNAL(orientationChanged(bool)), this, SLOT(rotate(bool)));*/ //#endif connect(new_game, SIGNAL(triggered()), gamewidget, SLOT(restart())); connect(undo, SIGNAL(triggered()), gamewidget, SLOT(undo())); connect(use_animation, SIGNAL(toggled(bool)), gamewidget, SLOT(enableAnimations(bool))); connect(use_sound, SIGNAL(toggled(bool)), gamewidget, SLOT(enableSound(bool))); connect(gamewidget, SIGNAL(enableUndo(bool)), undo, SLOT(setEnabled(bool))); //restoreState(settings.value("window_state", saveState()).toByteArray()); //resize(settings.value("window_size", size()).toSize()); //move(settings.value("window_pos", pos()).toPoint()); //setGeometry(40,0,1200,720); //resize(1200,720); //move(0,0); //QTimer::singleShot(6000, this, SLOT(setTheSizeCorrect())); }
bool ViewData::_handleEvent( const eq::Event& event ) { switch( event.type ) { case eq::Event::CHANNEL_POINTER_BUTTON_RELEASE: { const eq::PointerEvent& releaseEvent = event.pointerButtonRelease; if( releaseEvent.buttons == eq::PTR_BUTTON_NONE ) { if( releaseEvent.button == eq::PTR_BUTTON1 ) { _spinX = releaseEvent.dy; _spinY = releaseEvent.dx; return true; } if( releaseEvent.button == eq::PTR_BUTTON2 ) { _advance = -releaseEvent.dy; return true; } } return false; } case eq::Event::CHANNEL_POINTER_MOTION: switch( event.pointerMotion.buttons ) { case eq::PTR_BUTTON1: _spinX = 0; _spinY = 0; spinModel( -0.005f * event.pointerMotion.dy, -0.005f * event.pointerMotion.dx, 0.f ); return true; case eq::PTR_BUTTON2: _advance = -event.pointerMotion.dy; moveModel( 0.f, 0.f, .005f * _advance ); return true; case eq::PTR_BUTTON3: moveModel( .0005f * event.pointerMotion.dx, -.0005f * event.pointerMotion.dy, 0.f ); return true; default: return false; } case eq::Event::CHANNEL_POINTER_WHEEL: moveModel( -0.05f * event.pointerWheel.xAxis, 0.f, 0.05f * event.pointerWheel.yAxis ); return true; case eq::Event::MAGELLAN_AXIS: _spinX = 0; _spinY = 0; _advance = 0; spinModel( 0.0001f * event.magellan.zRotation, -0.0001f * event.magellan.xRotation, -0.0001f * event.magellan.yRotation ); moveModel( 0.0001f * event.magellan.xAxis, -0.0001f * event.magellan.zAxis, 0.0001f * event.magellan.yAxis ); return true; case eq::Event::KEY_PRESS: switch( event.keyPress.key ) { case 's': showStatistics( !getStatistics( )); return true; case 'o': setOrtho( !useOrtho( )); return true; } return false; default: return false; } }
PlaylistWindow::PlaylistWindow() : QWidget( 0, "PlaylistWindow", Qt::WGroupLeader ) , KXMLGUIClient() , m_lastBrowser( 0 ) { s_instance = this; // Sets caption and icon correctly (needed e.g. for GNOME) kapp->setTopWidget( this ); KActionCollection* const ac = actionCollection(); const EngineController* const ec = EngineController::instance(); ac->setAutoConnectShortcuts( false ); ac->setWidget( this ); new K3bExporter(); KStdAction::configureToolbars( kapp, SLOT( slotConfigToolBars() ), ac ); KStdAction::keyBindings( kapp, SLOT( slotConfigShortcuts() ), ac ); KStdAction::keyBindings( kapp, SLOT( slotConfigGlobalShortcuts() ), ac, "options_configure_globals" ); KStdAction::preferences( kapp, SLOT( slotConfigAmarok() ), ac ); KStdAction::quit( kapp, SLOT( quit() ), ac ); KStdAction::open( this, SLOT(slotAddLocation()), ac, "playlist_add" )->setText( i18n("&Add Media...") ); KStdAction::save( this, SLOT(savePlaylist()), ac, "playlist_save" )->setText( i18n("&Save Playlist As...") ); KStdAction::showMenubar( this, SLOT(slotToggleMenu()), ac ); new KAction( i18n("Play Media..."), "fileopen", 0, this, SLOT(slotPlayMedia()), ac, "playlist_playmedia" ); new KAction( i18n("Play Audio CD"), "cdaudio_unmount", 0, this, SLOT(playAudioCD()), ac, "play_audiocd" ); new KAction( i18n("Script Manager"), "pencil", 0, this, SLOT(showScriptSelector()), ac, "script_manager" ); new KAction( i18n("Queue Manager"), "goto", 0, this, SLOT(showQueueManager()), ac, "queue_manager" ); new KAction( i18n("Statistics"), amaroK::icon( "info" ), 0, this, SLOT(showStatistics()), ac, "statistics" ); ac->action( "options_configure_globals" )->setText( i18n( "Configure &Global Shortcuts..." ) ); new KAction( i18n( "Previous Track" ), amaroK::icon( "back" ), 0, ec, SLOT( previous() ), ac, "prev" ); new KAction( i18n( "Play" ), amaroK::icon( "play" ), 0, ec, SLOT( play() ), ac, "play" ); new KAction( i18n( "Pause" ), amaroK::icon( "pause" ), 0, ec, SLOT( pause() ), ac, "pause" ); new KAction( i18n( "Next Track" ), amaroK::icon( "next" ), 0, ec, SLOT( next() ), ac, "next" ); { KAction *gah = new KAction( i18n( "Toggle Focus" ), "reload", CTRL+Key_Tab, this, SLOT( slotToggleFocus() ), ac, "toggle_focus" ); KPopupMenu asdf; gah->plug( &asdf ); gah->unplug( &asdf ); } new amaroK::MenuAction( ac ); new amaroK::StopAction( ac ); new amaroK::PlayPauseAction( ac ); new amaroK::AnalyzerAction( ac ); new amaroK::RepeatAction( ac ); new amaroK::RandomAction( ac ); new amaroK::FavorAction( ac ); new amaroK::VolumeAction( ac ); if( K3bExporter::isAvailable() ) new amaroK::BurnMenuAction( ac ); if( AmarokConfig::playlistWindowSize().isValid() ) { // if first ever run, use sizeHint(), and let // KWin place us otherwise use the stored values resize( AmarokConfig::playlistWindowSize() ); move( AmarokConfig::playlistWindowPos() ); } }
int runApp( options::variables_map const& opts ) { // Create renderer std::string cullingEngine = opts["cullingengine"].as<std::string>(); dp::culling::Mode cullingMode = dp::culling::MODE_AUTO; if ( cullingEngine == "cpu" ) { cullingMode = dp::culling::MODE_CPU; } else if ( cullingEngine == "gl_compute" ) { cullingMode = dp::culling::MODE_OPENGL_COMPUTE; } else if ( cullingEngine == "cuda" ) { cullingMode = dp::culling::MODE_CUDA; } else if ( cullingEngine != "auto" ) { std::cerr << "unknown culling engine, abort" << std::endl; return -1; } dp::sg::renderer::rix::gl::SceneRendererSharedPtr renderer = dp::sg::renderer::rix::gl::SceneRenderer::create ( opts["renderengine"].as<std::string>().c_str() , getShaderManager( opts["shadermanager"].as<std::string>() ) , cullingMode //, dp::sg::renderer::rix::gl::TM_NONE ); renderer->setCullingEnabled( opts["culling"].as<bool>() ); if ( !opts["effectlibrary"].empty() ) { dp::fx::EffectLibrary::instance()->loadEffects( opts["effectlibrary"].as<std::string>() ); } dp::sg::ui::ViewStateSharedPtr viewState = loadScene( opts["filename"].as<std::string>() ); if ( opts.count("replace") ) { // process replacements std::vector< std::string> replacementStrings = opts["replace"].as< std::vector<std::string > >(); dp::sg::algorithm::ReplacementMapNames replacements; for ( std::vector<std::string>::iterator it = replacementStrings.begin(); it != replacementStrings.end(); ++it ) { size_t equalChar = it->find_first_of(':'); if ( equalChar != std::string::npos && equalChar < it->size() - 1) { std::string str1 = it->substr( 0, equalChar ); std::string str2 = it->substr( equalChar + 1, it->size() - equalChar - 1); replacements[str1] = str2; } else { std::cerr << "invalid replacement token: " << *it << std::endl; } } dp::sg::algorithm::replaceEffectDatas( viewState->getScene(), replacements ); } else if ( !opts["replaceAll"].empty() ) { dp::sg::core::EffectDataSharedPtr replacement = dp::sg::core::EffectData::create( dp::fx::EffectLibrary::instance()->getEffectData( opts["replaceAll"].as<std::string>() ) ); DP_ASSERT( replacement ); dp::sg::algorithm::SearchTraverser searchTraverser; searchTraverser.setClassName( "class dp::sg::core::GeoNode" ); searchTraverser.setBaseClassSearch( true ); searchTraverser.apply( viewState->getScene() ); const std::vector<dp::sg::core::ObjectSharedPtr> &vp = searchTraverser.getResults(); for ( size_t i=0 ; i<vp.size() ; i++ ) { vp[i].inplaceCast<dp::sg::core::GeoNode>()->setMaterialEffect( replacement ); } } if ( opts.count("gridSize") ) { DP_ASSERT( viewState && viewState->getScene() && viewState->getScene()->getRootNode() ); std::vector<unsigned int> gridSizes = opts["gridSize"].as<std::vector<unsigned int> >(); dp::math::Vec3ui gridSize; int i; for ( i=0 ; i<3 && i<gridSizes.size() ; i++ ) { gridSize[i] = gridSizes[i]; } for ( ; i<3 ; i++ ) { gridSize[i] = 1; } dp::math::Vec3f gridSpacing = dp::math::Vec3f( 1.0f, 1.0f, 1.0f ); if ( opts.count("gridSpacing") ) { std::vector<float> gridSpacings = opts["gridSpacing"].as<std::vector<float> >(); for ( int i=0 ; i<3 && i<gridSpacings.size() ; i++ ) { gridSpacing[i] = gridSpacings[i]; } } viewState->getScene()->setRootNode( dp::sg::generator::replicate( viewState->getScene()->getRootNode(), gridSize, gridSpacing, opts["gridClone"].as<bool>() ) ); } if ( !opts["statistics"].empty() ) { showStatistics( viewState ); } dp::sg::ui::setupDefaultViewState( viewState ); if ( !opts["combineVertexAttributes"].empty() ) { combineVertexAttributes( viewState ); } { // Replace MatrixCamera by PerspectiveCamera to get all manipulator features if ( viewState->getCamera()->getObjectCode() == dp::sg::core::OC_MATRIXCAMERA ) { dp::sg::core::PerspectiveCameraSharedPtr perspectiveCamera = dp::sg::core::PerspectiveCamera::create(); perspectiveCamera->setOrientation(viewState->getCamera()->getOrientation()); perspectiveCamera->setDirection((viewState->getCamera()->getDirection())); perspectiveCamera->setPosition(viewState->getCamera()->getPosition()); viewState->setAutoClipPlanes(true); viewState->setCamera(perspectiveCamera); } } if ( !opts["headlight"].empty() ) { if ( viewState && viewState->getScene() && !dp::sg::algorithm::containsLight( viewState->getScene() ) && viewState->getCamera() && ( viewState->getCamera()->getNumberOfHeadLights() == 0 ) ) { // Use the defaults! Note that LightSource ambientColor is black. viewState->getCamera()->addHeadLight( dp::sg::core::createStandardPointLight() ); } } if ( !opts["environment"].empty() ) { dp::sg::core::TextureSharedPtr texture = dp::sg::core::TextureFile::create( opts["environment"].as<std::string>() ); dp::sg::core::SamplerSharedPtr sampler = dp::sg::core::Sampler::create( texture ); renderer->setEnvironmentSampler( sampler ); } // Setup default OpenGL format descriptor // We need to create a default format first to be able to check if a stereo pixelformat is available later. // (An unfortunate RenderContextFormat.isAvailable() interface due to Linux.) dp::gl::RenderContextFormat format; // create a widget which shows the scene //dp::sg::ui::glut::SceneRendererWidget w( format ); GLUTMinimal w; // TODO format is not yet supported #if 0 if (stereo) { format.setStereo( stereo ); if ( !w.setFormat( format ) ) // This automatically checks if the format is available. { std::cout << "Warning: No stereo pixelformat available." << std::endl; } } #endif viewState->setAutoClipPlanes( opts["autoclipplanes"].as<bool>() ); //w.setNumberOfFrames( frames ); w.setViewState( viewState ); w.setSceneRenderer( renderer ); if ( !opts["continuous"].empty() ) { w.setContinuousUpdate( true ); w.setShowFrameRate( true ); } if( opts["frames"].as<int>() != -1 ) { w.setNumberOfFrames( opts["frames"].as<int>() ); } w.setDuration( opts["duration"].as<double>() ); if ( opts["fullscreen"].empty() ) { size_t width = 640; size_t height = 480; if ( opts.count("windowSize") ) { std::vector<size_t> sizes = opts["windowSize"].as<std::vector<size_t> >(); if ( 1 <= sizes.size() ) { width = sizes[0]; if ( 2 <= sizes.size() ) { height = sizes[1]; } } } w.setWindowSize( width, height ); } else { w.setWindowFullScreen(); } //w.show(); // Keep only once reference to the renderer in the widget. This is necessary since the OpenGL resources // used by the renderer must be deleted before the window gets destroyed. renderer.reset(); glutMainLoop(); return w.getExitCode(); }
int runApp( int argc, char *argv[], options::variables_map const& opts ) { QApplication app( argc, argv ); // Create rendering engine dp::sg::renderer::rix::gl::SceneRendererSharedPtr renderer = dp::sg::renderer::rix::gl::SceneRenderer::create ( opts["renderengine"].as<std::string>().c_str() , getShaderManager( opts["shadermanager"].as<std::string>() ) , getCullingMode( opts["cullingengine"].as<std::string>() ) , getTransparencyMode( opts["transparency"].as<std::string>() ) ); renderer->setCullingEnabled( opts["culling"].as<bool>() ); renderer->setDepthPass( opts["depthPass"].as<bool>() ); if ( !opts["effectlibrary"].empty() ) { dp::fx::EffectLibrary::instance()->loadEffects( opts["effectlibrary"].as<std::string>() ); } if ( !opts["environment"].empty() ) { dp::sg::core::TextureSharedPtr texture = dp::sg::core::TextureFile::create( opts["environment"].as<std::string>() ); dp::sg::core::SamplerSharedPtr sampler = dp::sg::core::Sampler::create( texture ); renderer->setEnvironmentSampler( sampler ); } dp::sg::ui::ViewStateSharedPtr viewState = loadScene( opts["filename"].as<std::string>() ); if ( opts.count("replace") ) { // process replacements std::vector< std::string> replacementStrings = opts["replace"].as< std::vector<std::string > >(); dp::sg::algorithm::ReplacementMapNames replacements; for ( std::vector<std::string>::iterator it = replacementStrings.begin(); it != replacementStrings.end(); ++it ) { size_t equalChar = it->find_first_of(':'); if ( equalChar != std::string::npos && equalChar < it->size() - 1) { std::string str1 = it->substr( 0, equalChar ); std::string str2 = it->substr( equalChar + 1, it->size() - equalChar - 1); replacements[str1] = str2; } else { std::cerr << "invalid replacement token: " << *it << std::endl; } } dp::sg::algorithm::replaceEffectDatas( viewState->getScene(), replacements ); } else if ( !opts["replaceAll"].empty() ) { dp::sg::core::EffectDataSharedPtr replacement = dp::sg::core::EffectData::create( dp::fx::EffectLibrary::instance()->getEffectData( opts["replaceAll"].as<std::string>() ) ); DP_ASSERT( replacement ); DP_ASSERT( viewState && viewState->getScene() && viewState->getScene()->getRootNode() ); const std::vector<dp::sg::core::ObjectSharedPtr> vp = dp::sg::algorithm::searchClass( viewState->getScene()->getRootNode(), "class dp::sg::core::GeoNode", true ); for ( size_t i=0 ; i<vp.size() ; i++ ) { vp[i].inplaceCast<dp::sg::core::GeoNode>()->setMaterialEffect( replacement ); } } if ( !opts["generateTexCoords"].empty() ) { dp::sg::core::TextureCoordType tct = getTextureCoordType( opts["generateTexCoords"].as<std::string>() ); DP_ASSERT( viewState && viewState->getScene() && viewState->getScene()->getRootNode() ); const std::vector<dp::sg::core::ObjectSharedPtr> vp = dp::sg::algorithm::searchClass( viewState->getScene()->getRootNode(), "class dp::sg::core::Primitive", true ); for ( size_t i=0 ; i<vp.size() ; i++ ) { vp[i].inplaceCast<dp::sg::core::Primitive>()->generateTexCoords( tct, dp::sg::core::VertexAttributeSet::DP_SG_TEXCOORD0, false ); // don't overwrite if there already are some texture coordinate ^^^^^ } } if ( !opts["generateTangentSpace"].empty() ) { DP_ASSERT( viewState && viewState->getScene() && viewState->getScene()->getRootNode() ); const std::vector<dp::sg::core::ObjectSharedPtr> vp = dp::sg::algorithm::searchClass( viewState->getScene()->getRootNode(), "class dp::sg::core::Primitive", true ); for ( size_t i=0 ; i<vp.size() ; i++ ) { vp[i].inplaceCast<dp::sg::core::Primitive>()->generateTangentSpace( dp::sg::core::VertexAttributeSet::DP_SG_TEXCOORD0 , dp::sg::core::VertexAttributeSet::DP_SG_TANGENT , dp::sg::core::VertexAttributeSet::DP_SG_BINORMAL , false ); // don't overwrite if there already are some texture coordinate ^^^^^ } } if ( opts.count("gridSize") ) { DP_ASSERT( viewState && viewState->getScene() && viewState->getScene()->getRootNode() ); std::vector<unsigned int> gridSizes = opts["gridSize"].as<std::vector<unsigned int> >(); dp::math::Vec3ui gridSize; int i; for ( i=0 ; i<3 && i<gridSizes.size() ; i++ ) { gridSize[i] = gridSizes[i]; } for ( ; i<3 ; i++ ) { gridSize[i] = 1; } dp::math::Vec3f gridSpacing = dp::math::Vec3f( 1.0f, 1.0f, 1.0f ); if ( opts.count("gridSpacing") ) { std::vector<float> gridSpacings = opts["gridSpacing"].as<std::vector<float> >(); for ( int i=0 ; i<3 && i<gridSpacings.size() ; i++ ) { gridSpacing[i] = gridSpacings[i]; } } viewState->getScene()->setRootNode( dp::sg::generator::replicate( viewState->getScene()->getRootNode(), gridSize, gridSpacing, opts["gridClone"].as<bool>() ) ); } if ( !opts["statistics"].empty() ) { showStatistics( viewState ); } dp::sg::ui::setupDefaultViewState( viewState ); if ( !opts["combineVertexAttributes"].empty() ) { combineVertexAttributes( viewState ); } { // Replace MatrixCamera by PerspectiveCamera to get all manipulator features if ( viewState->getCamera()->getObjectCode() == dp::sg::core::OC_MATRIXCAMERA ) { dp::sg::core::PerspectiveCameraSharedPtr perspectiveCamera = dp::sg::core::PerspectiveCamera::create(); perspectiveCamera->setOrientation(viewState->getCamera()->getOrientation()); perspectiveCamera->setDirection((viewState->getCamera()->getDirection())); perspectiveCamera->setPosition(viewState->getCamera()->getPosition()); viewState->setAutoClipPlanes(true); viewState->setCamera(perspectiveCamera); } } viewState->setAutoClipPlanes( opts["autoclipplanes"].as<bool>() ); if ( !opts["zoom"].empty() ) { DP_ASSERT( viewState && viewState->getCamera() ); viewState->getCamera()->zoom( opts["zoom"].as<float>() ); } if ( !opts["headlight"].empty() ) { if ( viewState && viewState->getScene() && !dp::sg::algorithm::containsLight( viewState->getScene() ) && viewState->getCamera() && ( viewState->getCamera()->getNumberOfHeadLights() == 0 ) ) { // Use the defaults! Note that LightSource ambientColor is black. viewState->getCamera()->addHeadLight( dp::sg::core::createStandardPointLight() ); } } // Setup default OpenGL format descriptor // We need to create a default format first to be able to check if a stereo pixelformat is available later. // (An unfortunate RenderContextFormat.isAvailable() interface due to Linux.) dp::gl::RenderContextFormat format; // create a widget which shows the scene QtMinimalWidget w( format ); w.setSceneName( opts["filename"].as<std::string>() ); w.setViewState( viewState ); w.setSceneRenderer( renderer ); if ( opts["multiSample"].as<unsigned int>() != 0 ) { unsigned int samples = opts["multiSample"].as<unsigned int>(); unsigned int coverage = std::max( samples, opts["multiSampleCoverage"].as<unsigned int>() ); format.setMultisampleCoverage( samples, coverage ); if ( !w.setFormat( format ) ) { std::cout << "Warning: No Coverage Sampling Antialiasing ( " << samples << "/" << coverage << " ) pixelformat available." << std::endl; if ( samples != coverage ) { format.setMultisample( samples ); if ( !w.setFormat( format ) ) { std::cout << "Warning: No Multisample Antialiasing ( " << samples << " ) pixelformat available." << std::endl; } } } } if ( !opts["stereo"].empty() ) { format.setStereo( true ); if ( !w.setFormat( format ) ) // This automatically checks if the format is available. { std::cout << "Warning: No stereo pixelformat available." << std::endl; } } if( opts["frames"].as<unsigned int>() != ~0 ) { w.setNumberOfFrames( opts["frames"].as<unsigned int>() ); } w.setDuration( opts["duration"].as<double>() ); if ( !opts["continuous"].empty() ) { w.setContinuousUpdate( true ); w.setShowFrameRate( true ); } if ( !opts["orbit"].empty() ) { w.setOrbit( opts["orbit"].as<float>() ); } if ( !opts["fullscreen"].empty() ) { w.showFullScreen(); } else if ( !opts["maximized"].empty() ) { w.showMaximized(); } else { int width = 640; int height = 480; if ( opts.count("windowSize") ) { std::vector<unsigned int> sizes = opts["windowSize"].as<std::vector<unsigned int> >(); if ( 1 <= sizes.size() ) { width = sizes[0]; if ( 2 <= sizes.size() ) { height = sizes[1]; } } } w.resize( width, height ); } w.show(); // Keep only once reference to the renderer in the widget. This is necessary since the OpenGL resources // used by the renderer must be deleted before the window gets destroyed. renderer.reset(); int result = app.exec(); return result; }