main.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /****************************************************************************
  2. ** Artriculate: Art comes tumbling down
  3. ** Copyright (C) 2016 Chaos Reins
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ****************************************************************************/
  18. #include "picturemodel.h"
  19. #include <QGuiApplication>
  20. #include <QQmlApplicationEngine>
  21. #include <QQmlContext>
  22. #include <QSettings>
  23. #include <QSurfaceFormat>
  24. #include <QTimer>
  25. #include <QQuickWindow>
  26. #include <QDir>
  27. #include <QFileInfo>
  28. #include <QTextStream>
  29. #include <QDebug>
  30. #include <QScreen>
  31. #include <QDBusInterface>
  32. #include <QDBusConnection>
  33. #include <QFileSystemWatcher>
  34. #include <QtPlugin>
  35. class NativeUtil : public QObject {
  36. Q_OBJECT
  37. Q_PROPERTY(bool rebootRequired MEMBER rebootRequired NOTIFY rebootRequiredChanged)
  38. public:
  39. NativeUtil();
  40. signals:
  41. void rebootRequiredChanged();
  42. public slots:
  43. void monitorRunPath(const QString &path);
  44. private:
  45. QString watchFile;
  46. QFileSystemWatcher runDirWatcher;
  47. bool rebootRequired;
  48. };
  49. NativeUtil::NativeUtil()
  50. : QObject(),
  51. watchFile("/run/reboot-required"),
  52. rebootRequired(false)
  53. {
  54. runDirWatcher.addPath(QFileInfo(watchFile).absolutePath());
  55. connect(&runDirWatcher, &QFileSystemWatcher::directoryChanged, this, &NativeUtil::monitorRunPath);
  56. monitorRunPath("");
  57. }
  58. void NativeUtil::monitorRunPath(const QString &path)
  59. {
  60. Q_UNUSED(path);
  61. rebootRequired = QFileInfo::exists(watchFile);
  62. emit rebootRequiredChanged();
  63. }
  64. int main(int argc, char *argv[])
  65. {
  66. #ifdef STATIC_BUILD
  67. Q_IMPORT_PLUGIN(QmlSettingsPlugin)
  68. Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
  69. Q_IMPORT_PLUGIN(QtQuick2Plugin)
  70. #endif
  71. qsrand(time(NULL));
  72. QGuiApplication app(argc, argv);
  73. app.setOrganizationName("Chaos Reins");
  74. app.setApplicationName("artriculate");
  75. QSettings settings;
  76. if (settings.value("raster", false).toBool()) {
  77. #if QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
  78. qDebug() << "Trying to use the SG software backend prior to Qt 5.8";
  79. #else
  80. QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
  81. #endif
  82. } else {
  83. if (settings.value("force32bpp", true).toBool()) {
  84. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  85. format.setAlphaBufferSize(0);
  86. format.setRedBufferSize(8);
  87. format.setGreenBufferSize(8);
  88. format.setBlueBufferSize(8);
  89. QSurfaceFormat::setDefaultFormat(format);
  90. }
  91. if (settings.value("forceSingleBuffer", false).toBool()) {
  92. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  93. format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
  94. QSurfaceFormat::setDefaultFormat(format);
  95. } else if (settings.value("forceDoubleBuffer", false).toBool()) {
  96. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  97. format.setSwapBehavior(QSurfaceFormat::TripleBuffer);
  98. QSurfaceFormat::setDefaultFormat(format);
  99. }
  100. }
  101. // qdbus org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver Inhibit "artriculate" "media playback"
  102. if (settings.value("suppressScreensaver", false).toBool()) {
  103. QDBusInterface screenSaver("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver");
  104. uint id = screenSaver.call("Inhibit", app.applicationName(), "Media playback").arguments().at(0).toInt();
  105. QObject::connect(&app, &QCoreApplication::aboutToQuit, [id]() {
  106. QDBusInterface screenSaver("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver");
  107. screenSaver.call("UnInhibit", id);
  108. });
  109. }
  110. NativeUtil nativeUtils;
  111. QQmlApplicationEngine engine;
  112. qmlRegisterType<PictureModel>("PictureModel", 1, 0, "PictureModel");
  113. QString qmlPath;
  114. #ifdef COMPILED_RESOURCES
  115. qmlPath = "qrc:/qml";
  116. #else
  117. qmlPath = QCoreApplication::applicationDirPath() % "/qml";
  118. if (!QDir(qmlPath).exists()) {
  119. qmlPath = "/usr/share/" % app.applicationName() % "/qml";
  120. }
  121. #endif
  122. engine.addImportPath(qmlPath);
  123. engine.rootContext()->setContextProperty("nativeUtils", &nativeUtils);
  124. engine.load(QUrl(qmlPath + "/main.qml"));
  125. return app.exec();
  126. }
  127. #include "main.moc"