From 8c71f0b34166fa9efa287e343a21999a1616c0c1 Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Fri, 16 Nov 2018 09:16:04 +0000 Subject: [PATCH] [Style+Launcher] Removed clang-format temporarily and improved update checker. --- .clang-format | 118 -------------------------------------------------- src/main.cpp | 93 +++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 159 deletions(-) delete mode 100644 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 65fe744..0000000 --- a/.clang-format +++ /dev/null @@ -1,118 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: Mozilla -AccessModifierOffset: -2 -AlignAfterOpenBracket: DontAlign -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlines: Right -AlignOperands: true -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Inline -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: Yes -BinPackArguments: false -BinPackParameters: false -BraceWrapping: - AfterClass: true - AfterControlStatement: false - AfterEnum: true - AfterFunction: true - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: true - AfterUnion: true - AfterExternBlock: true - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: false - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Mozilla -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeComma -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeComma -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 2 -ContinuationIndentWidth: 1 -Cpp11BracedListStyle: false -DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: false -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 -IncludeIsMainRegex: '(Test)?$' -IndentCaseLabels: true -IndentPPDirectives: None -IndentWidth: 2 -IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCSpaceAfterProperty: true -ObjCSpaceBeforeProtocolList: false -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Left -ReflowComments: true -SortIncludes: true -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 8 -UseTab: Never -... - diff --git a/src/main.cpp b/src/main.cpp index 6d4bdc8..affee7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,9 +17,9 @@ #endif #ifdef GIT_COMMIT_HASH -#include -#include #include +#include +#include #endif @@ -27,53 +27,58 @@ #include #include #include -void catchUnixSignals(std::initializer_list quitSignals) { - auto handler = [](int sig) -> void { - QCoreApplication::quit(); - }; - - sigset_t blocking_mask; - sigemptyset(&blocking_mask); - for (auto sig : quitSignals) - sigaddset(&blocking_mask, sig); - - struct sigaction sa; - sa.sa_handler = handler; - sa.sa_mask = blocking_mask; - sa.sa_flags = 0; - - for (auto sig : quitSignals) - sigaction(sig, &sa, nullptr); +void +catchUnixSignals(std::initializer_list quitSignals) +{ + auto handler = [](int sig) -> void { QCoreApplication::quit(); }; + + sigset_t blocking_mask; + sigemptyset(&blocking_mask); + for (auto sig : quitSignals) + sigaddset(&blocking_mask, sig); + + struct sigaction sa; + sa.sa_handler = handler; + sa.sa_mask = blocking_mask; + sa.sa_flags = 0; + + for (auto sig : quitSignals) + sigaction(sig, &sa, nullptr); } #endif - -int main(int argc, char* argv[]) +int +main(int argc, char* argv[]) { setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1); QApplication app(argc, argv); #ifdef __linux__ - catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP}); + catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP }); #endif #ifdef GIT_COMMIT_HASH -QString current_version = QString(GIT_COMMIT_HASH); -qDebug() << "Current Version: " << current_version; + QString current_version = QString(GIT_COMMIT_HASH); + qDebug() << "Current Version: " << current_version; -QNetworkRequest request(QUrl("https://api.github.com/repos/NamedKitten/KittehPlayer/releases/tags/continuous")); -QNetworkAccessManager nam; -QNetworkReply *reply = nam.get(request); + QNetworkRequest request(QUrl("https://api.github.com/repos/NamedKitten/" + "KittehPlayer/releases/tags/continuous")); + QNetworkAccessManager nam; + QNetworkReply* reply = nam.get(request); -while(!reply->isFinished()) { -qApp->processEvents(); -} -QByteArray response_data = reply->readAll(); -QJsonDocument json = QJsonDocument::fromJson(response_data); -QJsonArray jsonArray = json["assets"].toArray(); -qDebug() << "Latest Version: " << json["target_commitish"].toString(); -if (json["target_commitish"].toString().endsWith(current_version) == 0) { - qDebug() << "Update Available. Please update ASAP."; -} + while (!reply->isFinished()) { + qApp->processEvents(); + } + QByteArray response_data = reply->readAll(); + QJsonDocument json = QJsonDocument::fromJson(response_data); + + if (json["target_commitish"].toString().length() != 0) { + if (json["target_commitish"].toString().endsWith(current_version) == 0) { + qDebug() << "Latest Version: " << json["target_commitish"].toString(); + qDebug() << "Update Available. Please update ASAP."; + } + } else { + qDebug() << "Couldn't check for new version."; + } #endif app.setOrganizationName("KittehPlayer"); @@ -81,10 +86,15 @@ if (json["target_commitish"].toString().endsWith(current_version) == 0) { app.setApplicationName("KittehPlayer"); for (int i = 1; i < argc; ++i) { if (!qstrcmp(argv[i], "--update")) { - QString program = QProcessEnvironment::systemEnvironment().value("APPDIR", "") + "/usr/bin/appimageupdatetool"; + QString program = + QProcessEnvironment::systemEnvironment().value("APPDIR", "") + + "/usr/bin/appimageupdatetool"; QProcess updater; updater.setProcessChannelMode(QProcess::ForwardedChannels); - updater.start(program, QStringList() << QProcessEnvironment::systemEnvironment().value("APPIMAGE", "")); + updater.start(program, + QStringList() + << QProcessEnvironment::systemEnvironment().value( + "APPIMAGE", "")); updater.waitForFinished(); exit(0); } @@ -92,8 +102,9 @@ if (json["target_commitish"].toString().endsWith(current_version) == 0) { SetDPMS(false); - QString newpath = QProcessEnvironment::systemEnvironment().value("APPDIR", "") + - "/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", ""); + QString newpath = + QProcessEnvironment::systemEnvironment().value("APPDIR", "") + + "/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", ""); setenv("PATH", newpath.toUtf8().constData(), 1); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);