void UnixSignals::handleSignal(int number) { qDebug() << "Got signal:" << number; switch (number) { #ifdef SIGBREAK case SIGBREAK: qDebug() << "Got SIGBREAK! emit event!"; emit sigBREAK(); break; #endif #ifdef SIGHUP case SIGHUP: qDebug() << "Got SIGHUP! emit event!"; emit sigHUP(); break; #endif #ifdef SIGINT case SIGINT: qDebug() << "Got SIGINT! emit event!"; emit sigINT(); break; #endif #ifdef SIGTERM case SIGTERM: qDebug() << "Got SIGTERM! emit event!"; emit sigTERM(); break; #endif #ifdef SIGUSR1 case SIGUSR1: qDebug() << "Got SIGUSR1! emit event!"; emit sigUSR1(); break; #endif #ifdef SIGUSR2 case SIGUSR2: qDebug() << "Got SIGUSR2! emit event!"; emit sigUSR2(); break; #endif default: qDebug() << "Got something? Dunno what to do..."; } }
void MainWindow::init(AnyOption *opts) { cmdopts = opts; if (cmdopts->getValue("config") || cmdopts->getValue('c')) { qDebug(">> Config option in command prompt..."); QString cfgPath = cmdopts->getValue('c'); if (cfgPath.isEmpty()) { cfgPath = cmdopts->getValue("config"); } loadSettings(cfgPath); } else { loadSettings(QString("")); } if (mainSettings->value("signals/enable").toBool()) { connect(handler, SIGNAL(sigUSR1()), SLOT(unixSignalUsr1())); connect(handler, SIGNAL(sigUSR2()), SLOT(unixSignalUsr2())); } handler->start(); setMinimumWidth(320); setMinimumHeight(200); quint16 minimalWidth = mainSettings->value("view/minimal-width").toUInt(); quint16 minimalHeight = mainSettings->value("view/minimal-height").toUInt(); if (minimalWidth) { setMinimumWidth(minimalWidth); } if (minimalHeight) { setMinimumHeight(minimalHeight); } hiddenCurdor = new QCursor(Qt::BlankCursor); qDebug() << "Application icon: " << mainSettings->value("application/icon").toString(); setWindowIcon(QIcon( mainSettings->value("application/icon").toString() )); if (cmdopts->getValue("uri") || cmdopts->getValue('u')) { qDebug(">> Uri option in command prompt..."); QString uri = cmdopts->getValue('u'); if (uri.isEmpty()) { uri = cmdopts->getValue("uri"); } mainSettings->setValue("browser/homepage", uri); } QCoreApplication::setOrganizationName( mainSettings->value("application/organization").toString() ); QCoreApplication::setOrganizationDomain( mainSettings->value("application/organization-domain").toString() ); QCoreApplication::setApplicationName( mainSettings->value("application/name").toString() ); QCoreApplication::setApplicationVersion( mainSettings->value("application/version").toString() ); // --- Network --- // if (mainSettings->value("proxy/enable").toBool()) { bool system = mainSettings->value("proxy/system").toBool(); if (system) { QNetworkProxyFactory::setUseSystemConfiguration(system); } else { QNetworkProxy proxy; proxy.setType(QNetworkProxy::HttpProxy); proxy.setHostName( mainSettings->value("proxy/host").toString() ); proxy.setPort(mainSettings->value("proxy/port").toUInt()); if (mainSettings->value("proxy/auth").toBool()) { proxy.setUser(mainSettings->value("proxy/username").toString()); proxy.setPassword(mainSettings->value("proxy/password").toString()); } QNetworkProxy::setApplicationProxy(proxy); } } // --- Web View --- // view = new WebView(this); if (mainSettings->value("view/show_load_progress").toBool()) { // --- Progress Bar --- // loadProgress = new QProgressBar(view); loadProgress->setContentsMargins(2, 2, 2, 2); loadProgress->setMinimumWidth(100); loadProgress->setMinimumHeight(16); loadProgress->setFixedHeight(16); loadProgress->setAutoFillBackground(true); QPalette palette = this->palette(); palette.setColor(QPalette::Window, QColor(255,255,255,63)); loadProgress->setPalette(palette); // Do not work... Need Layout... loadProgress->setAlignment(Qt::AlignTop); loadProgress->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); loadProgress->hide(); } setCentralWidget(view); view->setSettings(mainSettings); view->setPage(new QWebPage(view)); // --- Disk cache --- // if (mainSettings->value("cache/enable").toBool()) { diskCache = new QNetworkDiskCache(this); QString location = mainSettings->value("cache/location").toString(); if (!location.length()) { #ifdef QT5 location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); #else location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); #endif } diskCache->setCacheDirectory(location); diskCache->setMaximumCacheSize(mainSettings->value("cache/size").toUInt()); if (mainSettings->value("cache/clear-on-start").toBool()) { diskCache->clear(); } else if (cmdopts->getFlag('C') || cmdopts->getFlag("clear-cache")) { diskCache->clear(); } CachingNetworkManager *nm = new CachingNetworkManager(); nm->setCache(diskCache); view->page()->setNetworkAccessManager(nm); } if (mainSettings->value("browser/cookiejar").toBool()) { view->page()->networkAccessManager()->setCookieJar(new PersistentCookieJar()); } view->settings()->setAttribute(QWebSettings::JavascriptEnabled, mainSettings->value("browser/javascript").toBool() ); view->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, mainSettings->value("browser/javascript_can_open_windows").toBool() ); view->settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, mainSettings->value("browser/javascript_can_close_windows").toBool() ); view->settings()->setAttribute(QWebSettings::WebGLEnabled, mainSettings->value("browser/webgl").toBool() ); view->settings()->setAttribute(QWebSettings::JavaEnabled, mainSettings->value("browser/java").toBool() ); view->settings()->setAttribute(QWebSettings::PluginsEnabled, mainSettings->value("browser/plugins").toBool() ); if (mainSettings->value("inspector/enable").toBool()) { view->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); inspector = new QWebInspector(); inspector->setVisible(mainSettings->value("inspector/visible").toBool()); inspector->setMinimumSize(800, 600); inspector->setWindowTitle(mainSettings->value("application/name").toString() + " - WebInspector"); inspector->setWindowIcon(this->windowIcon()); inspector->setPage(view->page()); } connect(view, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); connect(view, SIGNAL(loadStarted()), SLOT(startLoading())); connect(view, SIGNAL(urlChanged(const QUrl &)), SLOT(urlChanged(const QUrl &))); connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool))); connect(view, SIGNAL(iconChanged()), SLOT(pageIconLoaded())); QDesktopWidget *desktop = QApplication::desktop(); connect(desktop, SIGNAL(resized(int)), SLOT(desktopResized(int))); // Window show, start events loop show(); view->page()->view()->setFocusPolicy(Qt::StrongFocus); view->setFocusPolicy(Qt::StrongFocus); if (mainSettings->value("view/hide_mouse_cursor").toBool()) { QApplication::setOverrideCursor(Qt::BlankCursor); view->setCursor(*hiddenCurdor); } int delay_resize = 0; if (mainSettings->value("view/startup_resize_delayed").toBool()) { delay_resize = mainSettings->value("view/startup_resize_delay").toInt(); } delayedResize->singleShot(delay_resize, this, SLOT(delayedWindowResize())); int delay_load = 0; if (mainSettings->value("browser/startup_load_delayed").toBool()) { delay_load = mainSettings->value("browser/startup_load_delay").toInt(); } delayedLoad->singleShot(delay_load, this, SLOT(delayedPageLoad())); }
void UnixSignals::start() { #ifdef SIGBREAK // Available on Windows if (receivers(SIGNAL(sigBREAK())) > 0) { if (signal(SIGBREAK, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on BREAK"); } } else { qDebug("No listeners for signal BREAK"); } #else qWarning("No signal BREAK defined"); #endif #ifdef SIGTERM if (receivers(SIGNAL(sigTERM())) > 0) { if (signal(SIGTERM, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on TERM"); } } else { qDebug("No listeners for signal TERM"); } #else qWarning("No signal TERM defined"); #endif #ifdef SIGINT if (receivers(SIGNAL(sigINT())) > 0) { if (signal(SIGINT, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on INT"); } } else { qDebug("No listeners for signal INT"); } #else qWarning("No signal INT defined"); #endif #ifdef SIGHUP // Unavailable on Windows if (receivers(SIGNAL(sigHUP())) > 0) { if (signal(SIGHUP, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on HUP"); } } else { qDebug("No listeners for signal HUP"); } #else qWarning("No signal HUP defined"); #endif #ifdef SIGUSR1 // Unavailable on Windows if (receivers(SIGNAL(sigUSR1())) > 0) { if (signal(SIGUSR1, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on USR1"); } } else { qDebug("No listeners for signal USR1"); } #else qWarning("No signal USR1 defined"); #endif #ifdef SIGUSR2 // Unavailable on Windows if (receivers(SIGNAL(sigUSR2())) > 0) { if (signal(SIGUSR2, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on USR2"); } } else { qDebug("No listeners for signal USR1"); } #else qWarning("No signal USR2 defined"); #endif }