MainWindow::MainWindow() : QMainWindow(NULL) { log_ = new LogWindow(this); setCentralWidget(log_); setWindowIcon(QIcon(":/oyun.png")); QLOG_INFO() << "Server log console initialized."; tcp_server_ = new QTcpServer(this); if (!tcp_server_->listen()) { QLOG_FATAL() << "Unable to start the server!"; QLOG_FATAL() << QString("Error message: %1").arg(tcp_server_->errorString()); QLOG_FATAL() << "Server will not accept any clients."; return; } connect(tcp_server_, SIGNAL(newConnection()), this, SLOT(clientConnected())); QLOG_INFO() << QString("Server started, running on port %1").arg(tcp_server_->serverPort()); bonjour_handler_ = new BonjourRegistrationHandler(this); bonjour_handler_->registerService(BonjourRecord(QString::fromUtf8("Oyun3D Server on %1").arg(QHostInfo::localHostName()), QLatin1String("_oyun3d._tcp"), QString()), tcp_server_->serverPort()); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // init the logging mechanism QsLogging::Logger& logger = QsLogging::Logger::instance(); logger.setLoggingLevel(QsLogging::TraceLevel); const QString sLogPath(QDir(a.applicationDirPath()).filePath("log.txt")); QsLogging::DestinationPtr fileDestination( QsLogging::DestinationFactory::MakeFileDestination(sLogPath) ); QsLogging::DestinationPtr debugDestination( QsLogging::DestinationFactory::MakeDebugOutputDestination() ); logger.addDestination(debugDestination.get()); logger.addDestination(fileDestination.get()); //logger.setLoggingLevel(QsLogging::InfoLevel); QLOG_INFO() << "Program started"; QLOG_INFO() << "Built with Qt" << QT_VERSION_STR << "running on" << qVersion(); QLOG_TRACE() << "Here's a" << QString("trace") << "message"; QLOG_DEBUG() << "Here's a" << static_cast<int>(QsLogging::DebugLevel) << "message"; QLOG_WARN() << "Uh-oh!"; qDebug() << "This message won't be picked up by the logger"; QLOG_ERROR() << "An error has occurred"; qWarning() << "Neither will this one"; QLOG_FATAL() << "Fatal error!"; const int ret = 0; std::cout << std::endl << "Press any key..."; std::cin.get(); QLOG_INFO() << "Program exited with return code" << ret; return ret; }
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) { (void)context; QDateTime now = QDateTime::currentDateTime(); QDate nowDate = now.date(); QTime nowTime = now.time(); QByteArray localMsg = msg.toLocal8Bit(); switch (type) { case QtDebugMsg: { QLOG_DEBUG() << localMsg.constData(); break; } case QtWarningMsg: { QLOG_WARN() << localMsg.constData(); break; } case QtCriticalMsg: { QLOG_ERROR() << localMsg.constData(); break; } case QtFatalMsg: { QLOG_FATAL() << localMsg.constData(); break; } } }
bool DatabaseManager::initDb(QFile* sqlFile) { QString sql; if (!sqlFile->open(QIODevice::ReadOnly | QIODevice::Text)) return false; QTextStream in(sqlFile); while (!in.atEnd()) { QString line = in.readLine(); if (!line.startsWith("--")) sql.append(line); } QStringList sqlList; QLOG_DEBUG() << sql; sqlList << sql; DBUpdater dbUpdater(QSqlDatabase::database(m_connName), sqlList); dbUpdater.start(); if (!dbUpdater.result().success) { QLOG_FATAL() << "could not init Database " << dbUpdater.result().sqlError.databaseText(); return false; } return true; }
bool OcDbManager::openDB() { db = QSqlDatabase::addDatabase("QSQLITE"); QString path(QDir::homePath()); path.append(BASE_PATH).append("/database.sqlite"); path = QDir::toNativeSeparators(path); QLOG_DEBUG() << "Database file path: " << path; // check if database file exists before database will be opened QFile dbfile(path); while(!dbfile.exists()) { QLOG_WARN() << "Database file does not exist. Waiting for it's creation by the engine..."; QEventLoop loop; QTimer::singleShot(1000, &loop, SLOT(quit())); loop.exec(); } db.setDatabaseName(path); db.setConnectOptions("QSQLITE_OPEN_READONLY"); bool dbOpen = db.open(); if (!dbOpen) { QLOG_FATAL() << "Can not open sqlite database"; } else { QLOG_INFO() << "Opened sqlite database"; } return dbOpen; }
QList<QbPersistable*> QbAdvancedQueryHelper::queryOneToMany(QString className, QString conditionClass, int id) { if(QbDatabase::getInstance()->checkDriver("QMYSQL")) { QbQuery* query = new QbMySQLQuery(className); query->appendWhere(conditionClass, QString::number(id), QbQuery::EQUALS); return QbDatabase::getInstance()->load(query); } else { QLOG_FATAL() << "Advanced queries are not implemented for " + QbDatabase::getInstance()->getDatabase()->driverName() + " driver"; return QList<QbPersistable*>(); } }
int main(int argc, char *argv[]) { qInstallMessageHandler(messageHandler); QCoreApplication app(argc, argv); QsLogging::Logger& logger = QsLogging::Logger::instance(); logger.setLoggingLevel(QsLogging::TraceLevel); logger.setTimestampFormat("yyyy-MM-dd hh:mm:ss"); // Find a free log file name. QString logFile(QDir(app.applicationDirPath()).filePath("phototweet")); int logNumber = 0; while (1) { QString name = logFile + QString::number(logNumber) + ".log"; if (!QFile::exists(name)) { logFile = name; break; } logNumber++; } QsLogging::DestinationPtr fileDestination(QsLogging::DestinationFactory::MakeFileDestination(logFile)); logger.addDestination(fileDestination.get()); QsLogging::DestinationPtr debugDestination(QsLogging::DestinationFactory::MakeDebugOutputDestination(true)); logger.addDestination(debugDestination.get()); if (!QFile::exists("phototweet.cfg")) { QLOG_FATAL() << "Couldn't find config file 'phototweet.cfg'!"; return 1; } Config config("phototweet.cfg"); QString loggingLevel = config.GetValue("logging_level"); logger.setLoggingLevel(loggingLevel); QLOG_INFO() << "Phototweet is starting.."; PhotoTweet pt(&config); QObject::connect(&pt, SIGNAL(quit()), &app, SLOT(quit())); QMetaObject::invokeMethod(&pt, "main", Qt::QueuedConnection); return app.exec(); }
QList<QbPersistable*> QbAdvancedQueryHelper::queryManyToMany(QString className, QString conditionClass, QString middleClass, int id) { if(QbDatabase::getInstance()->checkDriver("QMYSQL")) { QString tableIdentifier = QbProperties::getInstance()->getProperty("qubic.configuration.table.identifier").toUpper(); QString queryString = "SELECT * FROM " + className.toUpper() + " WHERE " ; queryString += className.toUpper() + "." + tableIdentifier + " IN (SELECT "; queryString += middleClass.toUpper() + "." + className.toUpper() + " FROM " + middleClass.toUpper(); queryString += " WHERE " + middleClass.toUpper() + "." + conditionClass.toUpper() + "='" + QString::number(id) + "')"; QbQuery* query = new QbMySQLQuery(className); query->setQuery(queryString); return QbDatabase::getInstance()->load(query); } else { QLOG_FATAL() << "Advanced queries are not implemented for " + QbDatabase::getInstance()->getDatabase()->driverName() + " driver"; return QList<QbPersistable*>(); } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); // Initialize the QS logger QsLogging::Logger& logger = QsLogging::Logger::instance(); logger.setLoggingLevel(QsLogging::TraceLevel); // Set up the logging file const QString logFilePath(QDir(a.applicationDirPath()).filePath("clientLog.txt")); QsLogging::DestinationPtr fileDestination(QsLogging::DestinationFactory::MakeFileDestination(logFilePath)); QsLogging::DestinationPtr debugDestination(QsLogging::DestinationFactory::MakeDebugOutputDestination()); logger.addDestination(fileDestination.get()); logger.addDestination(debugDestination.get()); QLOG_TRACE() << "Tracer Initialized"; QLOG_INFO() << "Program started"; QLOG_INFO() << "Built with QT " << QT_VERSION_STR << "running on " << qVersion(); // MainWindow w; ClientInterface w; QLOG_TRACE() << "Object of MainWindow called w created"; w.show(); QLOG_TRACE() << "Showing the client UI through MainWindow called w"; if (a.exec() == 0) { QLOG_TRACE() << "Program exit successful"; return 0; } else { QLOG_FATAL() << "Program exit successful"; return -1; } }
int main(int argc, char *argv[]) { try { QCommandLineParser parser; parser.setApplicationDescription("Plex Media Player"); parser.addHelpOption(); parser.addVersionOption(); parser.addOptions({{{"l", "licenses"}, "Show license information"}}); parser.addOptions({{{"a", "from-auto-update"}, "When invoked from auto-update"}}); char **newArgv = appendCommandLineArguments(argc, argv, g_qtFlags); argc += g_qtFlags.size(); // Suppress SSL related warnings on OSX // See https://bugreports.qt.io/browse/QTBUG-43173 for more info // #ifdef Q_OS_MAC qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false"); #endif // Qt calls setlocale(LC_ALL, "") in a bunch of places, which breaks // float/string processing in mpv and ffmpeg. #ifdef Q_OS_UNIX qputenv("LC_ALL", "C"); qputenv("LC_NUMERIC", "C"); #endif detectOpenGLEarly(); preinitQt(); QGuiApplication app(argc, newArgv); app.setWindowIcon(QIcon(":/images/icon.png")); // Get the arguments from the app, this is the parsed version of newArgc and newArgv QStringList args = app.arguments(); // Remove the qt flags above so that our command line parser doesn't get cranky. for (auto flag : g_qtFlags) args.removeAll(flag); // Now parse the command line. parser.process(args); if (parser.isSet("licenses")) { ShowLicenseInfo(); return EXIT_SUCCESS; } // init breakpad. setupCrashDumper(); UniqueApplication* uniqueApp = new UniqueApplication(); if (!uniqueApp->ensureUnique()) return EXIT_SUCCESS; #ifdef Q_OS_UNIX // install signals handlers for proper app closing. SignalManager signalManager(&app); Q_UNUSED(signalManager); #endif Log::Init(); // Quit app and apply update if we find one. if (UpdateManager::CheckForUpdates()) { app.quit(); return 0; } detectOpenGLLate(); #ifdef Q_OS_WIN32 initD3DDevice(); #endif Codecs::preinitCodecs(); // Initialize all the components. This needs to be done // early since most everything else relies on it // ComponentManager::Get().initialize(); // enable remote inspection if we have the correct setting for it. if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool()) qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992"); QtWebEngine::initialize(); // start our helper HelperLauncher::Get().connectToHelper(); // load QtWebChannel so that we can register our components with it. QQmlApplicationEngine *engine = Globals::Engine(); KonvergoWindow::RegisterClass(); Globals::SetContextProperty("components", &ComponentManager::Get().getQmlPropertyMap()); // the only way to detect if QML parsing fails is to hook to this signal and then see // if we get a valid object passed to it. Any error messages will be reported on stderr // but since no normal user should ever see this it should be fine // QObject::connect(engine, &QQmlApplicationEngine::objectCreated, [=](QObject* object, const QUrl& url) { Q_UNUSED(url); if (object == nullptr) throw FatalException(QObject::tr("Failed to parse application engine script.")); KonvergoWindow* window = Globals::MainWindow(); QObject* webChannel = qvariant_cast<QObject*>(window->property("webChannel")); Q_ASSERT(webChannel); ComponentManager::Get().setWebChannel(qobject_cast<QWebChannel*>(webChannel)); QObject::connect(uniqueApp, &UniqueApplication::otherApplicationStarted, window, &KonvergoWindow::otherAppFocus); }); engine->load(QUrl(QStringLiteral("qrc:/ui/webview.qml"))); Log::UpdateLogLevel(); // run our application int ret = app.exec(); delete uniqueApp; Globals::EngineDestroy(); Log::Uninit(); return ret; } catch (FatalException& e) { QLOG_FATAL() << "Unhandled FatalException:" << qPrintable(e.message()); QApplication errApp(argc, argv); auto msg = new ErrorMessage(e.message(), true); msg->show(); errApp.exec(); Log::Uninit(); return 1; } }
bool BrowserNode::tool_cmd(ToolCom * com, const char * args) { switch ((unsigned char) args[-1]) { case applyCmd: { QLOG_FATAL() << Q_FUNC_INFO << "If this got called then we have a logic flaw going on and BrowserNode needs to have Q_OBJECT in it to properly catch ToolCom::Run execution result"; Q_ASSERT_X(0, "applyCmd happened", "very bad"); int runResult = ToolCom::run(args, this, FALSE, FALSE); com->write_unsigned(runResult); break; } case createCmd: // invalid creation com->write_id(0); break; case parentCmd: if (this != BrowserView::get_project()) ((BrowserNode *) parent())->write_id(com); else com->write_id(0); break; case childrenCmd: { unsigned v = com->api_format(); unsigned n = 0; Q3ListViewItem * child; for (child = firstChild(); child != 0; child = child->nextSibling()) if (!((BrowserNode *) child)->deletedp() && ((BrowserNode *) child)->api_compatible(v)) n += 1; com->write_unsigned(n); for (child = firstChild(); child != 0; child = child->nextSibling()) if (!((BrowserNode *) child)->deletedp() && ((BrowserNode *) child)->api_compatible(v)) ((BrowserNode *) child)->write_id(com); } break; case getDefCmd: case getUmlDefCmd: case getCppDefCmd: case getJavaDefCmd: case getPhpDefCmd: case getPythonDefCmd: case getIdlDefCmd: get_data()->send_uml_def(com, this, comment); break; case isWritableCmd: com->write_bool(!is_read_only); break; case supportFileCmd: // goes up to the package return ((BrowserNode *) parent())->tool_cmd(com, args); case isOpenCmd: com->write_bool(isOpen()); break; case referencedByCmd: { BrowserNodeList targetof; referenced_by(targetof); // remove duplicats targetof.sort_it(); BrowserNode * bn; targetof.first(); while ((bn = targetof.current()) != 0) if (bn == targetof.next()) targetof.remove(); com->write_unsigned(targetof.count()); for (bn = targetof.first(); bn != 0; bn = targetof.next()) bn->write_id(com); } break; case setCoupleValueCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { set_value(args, args + strlen(args) + 1); package_modified(); get_data()->modified(); com->write_ack(TRUE); } break; case setDescriptionCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { set_comment(args); package_modified(); com->write_ack(TRUE); } break; case setNameCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { if (name != args) { if (((BrowserNode *) parent())->wrong_child_name(args, get_type(), allow_spaces(), allow_empty())) { com->write_ack(FALSE); return TRUE; } else { set_name(args); update_stereotype(); package_modified(); get_data()->modified(); } } com->write_ack(TRUE); } break; case setOpenCmd: BrowserView::select(this); setOpen(*args); com->write_ack(TRUE); break; case setMarkedCmd: if (*args) { if (this == BrowserView::get_project()) com->write_ack(FALSE); else { if (!is_marked) toggle_mark(); com->write_ack(TRUE); } } else { if (is_marked) toggle_mark(); com->write_ack(TRUE); } break; case moveAfterCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { BrowserNode * p = (BrowserNode *) parent(); BrowserNode * after = (BrowserNode *) com->get_id(args); if (after == 0) { if (p == 0) com->write_ack(FALSE); else { p->takeItem(this); p->insertItem(this); com->write_ack(TRUE); p->package_modified(); } } else if ((after->parent() != p) || (after == this)) { com->write_ack(FALSE); } else { moveItem(after); com->write_ack(TRUE); p->package_modified(); } } break; case moveInCmd: // plug-out upgrade, limited checks if (is_read_only && !root_permission()) com->write_ack(FALSE); else { BrowserNode * newparent = (BrowserNode *) com->get_id(args); BrowserNode * oldparent = (BrowserNode *) parent(); if ((newparent == oldparent) || (newparent == this)) { com->write_ack(FALSE); } else { oldparent->takeItem(this); newparent->insertItem(this); com->write_ack(TRUE); oldparent->package_modified(); newparent->package_modified(); } } break; case old_deleteCmd: case deleteCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { delete_it(); ((BrowserNode *) parent())->get_data()->modified(); package_modified(); com->write_ack(TRUE); } break; case applyStereotypeCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { ProfiledStereotypes::applyStereotype(this); // call package_modified() if needed com->write_ack(TRUE); } break; default: return FALSE; } return TRUE; }