int main( int argc, char * argv[]){ // to init resources, we'd use the following ( -> we need an 'application.qrc' file for that (..) ) //Q_INIT_RESOURCES( application ); QApplication app(argc, argv); // basic parameters of the status bar (..) app.setOrganizationName("Seeds Design"); app.setApplicationName("Digital Neurophone v0.1a"); // simplest setup ever -> we create a basic QWindow widget (..) //QMainWindow mainWin; // basic test with Qt original class for main windows objects (..) ConfigWindow mainWin; #if defined( Q_OS_SYMBIAN ) mainWin.showMaximized(); #else mainWin.show(); #endif // as usual, end the loop returning 'app.exec()' return app.exec(); }
void PDocument::ShowSettings(void) { bool locked = Lock(); ConfigWindow *configWin = documentManager->GetConfigWindow(); configWin->SetConfigMessage(documentSetting); configWin->Show(); if (locked) Unlock(); }
ConfigWindow* ConfigWindow::createConfigWindow(screen_context_t context, screen_window_t parent) { const int zOrder = 10; ConfigWindow *window = new ConfigWindow(context, parent); if (!window->m_valid) { delete window; return 0; } if (!window->setZOrder(zOrder) || !window->setTouchSensitivity(true)) { delete window; return 0; } return window; }
int main(int argc, char *argv[]) { CSVParser::AddParseTypes("Behavior", Behavior::OptionTypes); CSVParser::AddParseTypes("Effect", Effect::OptionTypes); CSVParser::AddParseTypes("Speak", Speak::OptionTypes); QApplication app(argc, argv); QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath()); QCoreApplication::setOrganizationName("qt-ponies"); QCoreApplication::setApplicationName("qt-ponies"); QString locale = QLocale::system().name().left(2).toLatin1(); QString trans_dir = QCoreApplication::applicationDirPath() + "/translations"; QTranslator translator; translator.load(QString("qt-ponies_%1").arg(locale), trans_dir); app.installTranslator(&translator); app.setQuitOnLastWindowClosed(false); QSettings::setDefaultFormat(QSettings::IniFormat); QFile qss(":/styles/res/style.qss"); qss.open(QFile::ReadOnly); app.setStyleSheet( QString::fromUtf8(qss.readAll()) ); qss.close(); ConfigWindow config; qDebug() << "Locale:" << locale; if(config.ponies.size() == 0) { config.show(); } return app.exec(); }
status_t PrintServerApp::async_thread(void* data) { AsyncThreadParams* p = (AsyncThreadParams*)data; Printer* printer = p->printer; BMessage* msg = p->AcquireMessage(); { AutoReply sender(msg, 'stop'); switch (msg->what) { // Handle showing the config dialog case PSRV_SHOW_PAGE_SETUP: { case PSRV_SHOW_PRINT_SETUP: if (printer) { if (p->app->fUseConfigWindow) { config_setup_kind kind = kJobSetup; if (msg->what == PSRV_SHOW_PAGE_SETUP) kind = kPageSetup; ConfigWindow* w = new ConfigWindow(kind, printer, msg, &sender); w->Go(); } else { BMessage reply(*msg); status_t status = B_ERROR; if (msg->what == PSRV_SHOW_PAGE_SETUP) status = printer->ConfigurePage(reply); else status = printer->ConfigureJob(reply); if (status == B_OK) sender.SetReply(&reply); } } else { // If no default printer is set, give user // choice of aborting or setting up a printer int32 count = Printer::CountPrinters(); BString alertText( B_TRANSLATE("There are no printers set up.")); if (count > 0) alertText.SetTo(B_TRANSLATE( "There is no default printer set up.")); alertText.Append(" "); alertText.Append( B_TRANSLATE("Would you like to set one up now?")); BAlert* alert = new BAlert("Info", alertText.String(), B_TRANSLATE("No"), B_TRANSLATE("Yes")); alert->SetShortcut(0, B_ESCAPE); if (alert->Go() == 1) { if (count == 0) run_add_printer_panel(); else run_select_printer_panel(); } } } break; // Retrieve default configuration message from printer add-on case PSRV_GET_DEFAULT_SETTINGS: { if (printer) { BMessage reply; if (printer->GetDefaultSettings(reply) == B_OK) { sender.SetReply(&reply); break; } } } break; // Create a new printer case PSRV_MAKE_PRINTER: { BString driverName; BString printerName; BString transportName; BString transportPath; if (msg->FindString("driver", &driverName) == B_OK && msg->FindString("transport", &transportName) == B_OK && msg->FindString("transport path", &transportPath) == B_OK && msg->FindString("printer name", &printerName) == B_OK) { BString connection; if (msg->FindString("connection", &connection) != B_OK) connection = "Local"; // then create the actual printer if (p->app->CreatePrinter(printerName.String(), driverName.String(), connection.String(), transportName.String(), transportPath.String()) == B_OK) { // If printer was created ok, // ask if it needs to be the default BString text(B_TRANSLATE("Would you like to make @ " "the default printer?")); text.ReplaceFirst("@", printerName.String()); BAlert* alert = new BAlert("", text.String(), B_TRANSLATE("No"), B_TRANSLATE("Yes")); alert->SetShortcut(0, B_ESCAPE); if (alert->Go() == 1) p->app->SelectPrinter(printerName.String()); } } } break; } } delete p; return B_OK; }
void MainWindow::on_configAction_triggered() { ConfigWindow *cfg = new ConfigWindow(config_, this); cfg->show(); }
int main(int argc, char * argv[]) { /* * Before starting main application, need to set 'QT_X11_NO_MITSHM=1' * to make the runtime work with IBM PPC machine. */ #if defined (Q_OS_LINUX) QByteArray val("1"); qputenv("QT_X11_NO_MITSHM", val); #endif // Create the QT application QApplication app(argc, argv); app.setQuitOnLastWindowClosed(false); // Setup the settings management QCoreApplication::setOrganizationName("pgadmin"); QCoreApplication::setOrganizationDomain("pgadmin.org"); QCoreApplication::setApplicationName(PGA_APP_NAME.toLower().replace(" ", "")); #if QT_VERSION >= 0x050000 // Set high DPI pixmap to display icons clear on Qt widget. QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif // Create a hash of the executable path so we can run copies side-by-side QString homeDir = QDir::homePath(); unsigned long exeHash = sdbm((unsigned char *)argv[0]); // Create the address file, that will be used to store the appserver URL for this instance addrFileName = homeDir + (QString("/.%1.%2.addr").arg(PGA_APP_NAME).arg(exeHash)).remove(" "); QFile addrFile(addrFileName); // Create a system-wide semaphore keyed by app name, exe hash and the username // to ensure instances are unique to the user and path QString userName = qgetenv("USER"); // *nix if (userName.isEmpty()) userName = qgetenv("USERNAME"); // Windows QString semaName = QString("%1-%2-%3-sema").arg(PGA_APP_NAME).arg(userName).arg(exeHash); QString shmemName = QString("%1-%2-%3-shmem").arg(PGA_APP_NAME).arg(userName).arg(exeHash); QSystemSemaphore sema(semaName, 1); sema.acquire(); #ifndef Q_OS_WIN32 // We may need to clean up stale shmem segments on *nix. Attaching and detaching // should remove the segment if it is orphaned. QSharedMemory stale_shmem(shmemName); if (stale_shmem.attach()) stale_shmem.detach(); #endif QSharedMemory shmem(shmemName); bool is_running; if (shmem.attach()) { is_running = true; } else { shmem.create(1); is_running = false; } sema.release(); QSettings settings; if (is_running){ addrFile.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream in(&addrFile); QString addr = in.readLine(); QString cmd = settings.value("BrowserCommand").toString(); if (!cmd.isEmpty()) { cmd.replace("%URL%", addr); QProcess::startDetached(cmd); } else { if (!QDesktopServices::openUrl(addr)) { QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?.")); QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); exit(1); } } return 0; } atexit(cleanup); // In windows and linux, it is required to set application level proxy // because socket bind logic to find free port gives socket creation error // when system proxy is configured. We are also setting // "setUseSystemConfiguration"=true to use the system proxy which will // override this application level proxy. As this bug is fixed in Qt 5.9 so // need to set application proxy for Qt version < 5.9. // #if defined (Q_OS_WIN) && QT_VERSION <= 0x050800 // Give dummy URL required to find proxy server configured in windows. QNetworkProxyQuery proxyQuery(QUrl("https://www.pgadmin.org")); QNetworkProxy l_proxy; QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(proxyQuery); if (listOfProxies.size()) { l_proxy = listOfProxies[0]; // If host name is not empty means proxy server is configured. if (!l_proxy.hostName().isEmpty()) { QNetworkProxy::setApplicationProxy(QNetworkProxy()); } } #endif #if defined (Q_OS_LINUX) && QT_VERSION <= 0x050800 QByteArray proxy_env; proxy_env = qgetenv("http_proxy"); // If http_proxy environment is defined in linux then proxy server is configured. if (!proxy_env.isEmpty()) { QNetworkProxy::setApplicationProxy(QNetworkProxy()); } #endif // Display the spash screen QSplashScreen *splash = new QSplashScreen(); splash->setPixmap(QPixmap(":/splash.png")); splash->show(); app.processEvents(QEventLoop::AllEvents); quint16 port = 0L; // Find an unused port number. Essentially, we're just reserving one // here that Flask will use when we start up the server. // In order to use the socket, we need to free this socket ASAP. // Hence - putting this code in a code block so the scope of the socket // variable vanishes to make that socket available. { #if QT_VERSION >= 0x050000 QTcpSocket socket; #if QT_VERSION >= 0x050900 socket.setProxy(QNetworkProxy::NoProxy); #endif socket.bind(0, QTcpSocket::ShareAddress); #else QUdpSocket socket; socket.bind(0, QUdpSocket::ShareAddress); #endif port = socket.localPort(); } // Generate a random key to authenticate the client to the server QString key = QUuid::createUuid().toString(); key = key.mid(1, key.length() - 2); // Generate the filename for the log logFileName = homeDir + (QString("/.%1.%2.log").arg(PGA_APP_NAME).arg(exeHash)).remove(" "); // Start the tray service TrayIcon *trayicon = new TrayIcon(logFileName); if (!trayicon->Init()) { QString error = QString(QWidget::tr("An error occurred initialising the tray icon")); QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); exit(1); } // Fire up the webserver Server *server; bool done = false; while (done != true) { server = new Server(port, key, logFileName); if (!server->Init()) { splash->finish(NULL); qDebug() << server->getError(); QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError()); QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); exit(1); } server->start(); // This is a hack to give the server a chance to start and potentially fail. As // the Python interpreter is a synchronous call, we can't check for proper startup // easily in a more robust way - we have to rely on a clean startup not returning. // It should always fail pretty quickly, and take longer to start if it succeeds, so // we don't really get a visible delay here. delay(1000); // Any errors? if (server->isFinished() || server->getError().length() > 0) { splash->finish(NULL); qDebug() << server->getError(); QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError()); QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); // Allow the user to tweak the Python Path if needed bool ok; ConfigWindow *dlg = new ConfigWindow(); dlg->setWindowTitle(QWidget::tr("Configuration")); dlg->setBrowserCommand(settings.value("BrowserCommand").toString()); dlg->setPythonPath(settings.value("PythonPath").toString()); dlg->setApplicationPath(settings.value("ApplicationPath").toString()); dlg->setModal(true); ok = dlg->exec(); QString browsercommand = dlg->getBrowserCommand(); QString pythonpath = dlg->getPythonPath(); QString applicationpath = dlg->getApplicationPath(); if (ok) { settings.setValue("BrowserCommand", browsercommand); settings.setValue("PythonPath", pythonpath); settings.setValue("ApplicationPath", applicationpath); settings.sync(); } else { exit(1); } delete server; } else done = true; } // Ensure the server gets cleaned up later QObject::connect(server, SIGNAL(finished()), server, SLOT(deleteLater())); // Generate the app server URL QString appServerUrl = QString("http://127.0.0.1:%1/?key=%2").arg(port).arg(key); // Read the server connection timeout from the registry or set the default timeout. int timeout = settings.value("ConnectionTimeout", 30).toInt(); // Now the server should be up, we'll attempt to connect and get a response. // We'll retry in a loop a few time before aborting if necessary. QTime endTime = QTime::currentTime().addSecs(timeout); bool alive = false; while(QTime::currentTime() <= endTime) { alive = PingServer(QUrl(appServerUrl)); if (alive) { break; } delay(200); } // Attempt to connect one more time in case of a long network timeout while looping if (!alive && !PingServer(QUrl(appServerUrl))) { splash->finish(NULL); QString error(QWidget::tr("The application server could not be contacted.")); QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); exit(1); } // Stash the URL for any duplicate processes to open if (addrFile.open(QIODevice::WriteOnly)) { addrFile.setPermissions(QFile::ReadOwner|QFile::WriteOwner); QTextStream out(&addrFile); out << appServerUrl << endl; } // Go! trayicon->setAppServerUrl(appServerUrl); // Enable the shutdown server menu as server started successfully. trayicon->enableShutdownMenu(); QString cmd = settings.value("BrowserCommand").toString(); if (!cmd.isEmpty()) { cmd.replace("%URL%", appServerUrl); QProcess::startDetached(cmd); } else { if (!QDesktopServices::openUrl(appServerUrl)) { QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?.")); QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); exit(1); } } QObject::connect(trayicon, SIGNAL(shutdownSignal(QUrl)), server, SLOT(shutdown(QUrl))); splash->finish(NULL); return app.exec(); }