main.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "filereader.h"
  20. #include "helperfunctions.h"
  21. #include <QGuiApplication>
  22. #include <QQmlApplicationEngine>
  23. #include <QQmlContext>
  24. #include <QSettings>
  25. #include <QSurfaceFormat>
  26. #include <QTimer>
  27. #include <QQuickWindow>
  28. #include <QDir>
  29. #include <QFileInfo>
  30. #include <QTextStream>
  31. #include <QDebug>
  32. #include <QScreen>
  33. #include <QDBusInterface>
  34. #include <QDBusConnection>
  35. int main(int argc, char *argv[])
  36. {
  37. qsrand(time(NULL));
  38. QGuiApplication app(argc, argv);
  39. app.setOrganizationName("Chaos Reins");
  40. app.setApplicationName("Articulate");
  41. QSettings settings;
  42. if (settings.value("raster", false).toBool()) {
  43. #if QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
  44. qDebug() << "Trying to use the SG software backend prior to Qt 5.8";
  45. #else
  46. QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
  47. #endif
  48. } else {
  49. if (settings.value("force32bpp", true).toBool()) {
  50. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  51. format.setAlphaBufferSize(0);
  52. format.setRedBufferSize(8);
  53. format.setGreenBufferSize(8);
  54. format.setBlueBufferSize(8);
  55. QSurfaceFormat::setDefaultFormat(format);
  56. }
  57. if (settings.value("forceSingleBuffer", false).toBool()) {
  58. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  59. format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
  60. QSurfaceFormat::setDefaultFormat(format);
  61. } else if (settings.value("forceDoubleBuffer", false).toBool()) {
  62. QSurfaceFormat format = QSurfaceFormat::defaultFormat();
  63. format.setSwapBehavior(QSurfaceFormat::TripleBuffer);
  64. QSurfaceFormat::setDefaultFormat(format);
  65. }
  66. }
  67. // qdbus org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver Inhibit "artriculate" "media playback"
  68. if (settings.value("suppressScreensaver", false).toBool()) {
  69. QDBusInterface screenSaver("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver");
  70. uint id = screenSaver.call("Inhibit", app.applicationName(), "Media playback").arguments().at(0).toInt();
  71. QObject::connect(&app, &QCoreApplication::aboutToQuit, [id]() {
  72. QDBusInterface screenSaver("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver");
  73. screenSaver.call("UnInhibit", id);
  74. });
  75. }
  76. QQmlApplicationEngine engine;
  77. qmlRegisterType<PictureModel>("PictureModel", 1, 0, "PictureModel");
  78. engine.rootContext()->setContextProperty("screenSize", app.screens().at(0)->availableSize());
  79. engine.rootContext()->setContextProperty("fileReader", new FileReader(&app));
  80. engine.rootContext()->setContextProperty("nativeHelper", new HelperFunctions(&app));
  81. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  82. return app.exec();
  83. }