2011-04-06 13:48:02 +04:00
|
|
|
/*
|
2014-05-15 13:01:21 +04:00
|
|
|
*
|
2011-04-06 13:48:02 +04:00
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
2014-05-15 13:01:21 +04:00
|
|
|
#include <QtGlobal>
|
|
|
|
|
2020-09-11 03:36:28 +03:00
|
|
|
#include <cmath>
|
2020-08-13 14:00:56 +03:00
|
|
|
#include <csignal>
|
2021-09-09 12:18:22 +03:00
|
|
|
#include <qqml.h>
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2014-05-15 13:01:21 +04:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "application.h"
|
2021-08-20 16:17:06 +03:00
|
|
|
#include "fileactivitylistmodel.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "theme.h"
|
2017-08-16 09:36:52 +03:00
|
|
|
#include "common/utility.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "cocoainitializer.h"
|
2021-09-09 12:18:22 +03:00
|
|
|
#include "userstatusselectormodel.h"
|
|
|
|
#include "emojimodel.h"
|
2021-09-14 14:17:03 +03:00
|
|
|
#include "tray/syncstatussummary.h"
|
2021-09-09 14:33:57 +03:00
|
|
|
#include "tray/unifiedsearchresultslistmodel.h"
|
2014-01-29 13:38:12 +04:00
|
|
|
|
2020-03-09 03:48:07 +03:00
|
|
|
#if defined(BUILD_UPDATER)
|
2014-01-29 13:38:12 +04:00
|
|
|
#include "updater/updater.h"
|
2020-03-09 03:48:07 +03:00
|
|
|
#endif
|
2013-07-08 04:58:26 +04:00
|
|
|
|
2013-09-10 13:35:30 +04:00
|
|
|
#include <QTimer>
|
2014-01-15 14:08:42 +04:00
|
|
|
#include <QMessageBox>
|
2017-09-15 18:59:14 +03:00
|
|
|
#include <QDebug>
|
2020-05-06 21:04:58 +03:00
|
|
|
#include <QQuickStyle>
|
2020-09-11 03:36:28 +03:00
|
|
|
#include <QQuickWindow>
|
2021-09-17 10:54:25 +03:00
|
|
|
#include <QSurfaceFormat>
|
2014-01-15 14:08:42 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
using namespace OCC;
|
2013-09-10 13:35:30 +04:00
|
|
|
|
|
|
|
void warnSystray()
|
|
|
|
{
|
2018-11-11 12:56:22 +03:00
|
|
|
QMessageBox::critical(nullptr, qApp->translate("main.cpp", "System Tray not available"),
|
2013-09-10 13:35:30 +04:00
|
|
|
qApp->translate("main.cpp", "%1 requires on a working system tray. "
|
|
|
|
"If you are running XFCE, please follow "
|
|
|
|
"<a href=\"http://docs.xfce.org/xfce/xfce4-panel/systray\">these instructions</a>. "
|
2021-05-06 16:38:22 +03:00
|
|
|
"Otherwise, please install a system tray application such as \"trayer\" and try again.")
|
2014-01-15 14:08:42 +04:00
|
|
|
.arg(Theme::instance()->appNameGUI()));
|
2013-09-10 13:35:30 +04:00
|
|
|
}
|
2011-02-17 02:21:45 +03:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2022-08-26 15:51:53 +03:00
|
|
|
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-gpu --no-sandbox");
|
2022-09-01 14:53:27 +03:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
|
2022-08-26 15:51:53 +03:00
|
|
|
|
2021-10-18 15:30:44 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
SetDllDirectory(L"");
|
|
|
|
#endif
|
2020-01-18 19:47:17 +03:00
|
|
|
Q_INIT_RESOURCE(resources);
|
2021-02-02 19:02:02 +03:00
|
|
|
Q_INIT_RESOURCE(theme);
|
2012-03-31 13:31:28 +04:00
|
|
|
|
2021-09-14 14:17:03 +03:00
|
|
|
qmlRegisterType<SyncStatusSummary>("com.nextcloud.desktopclient", 1, 0, "SyncStatusSummary");
|
2021-09-09 12:18:22 +03:00
|
|
|
qmlRegisterType<EmojiModel>("com.nextcloud.desktopclient", 1, 0, "EmojiModel");
|
2021-08-20 16:17:06 +03:00
|
|
|
qmlRegisterType<UserStatusSelectorModel>("com.nextcloud.desktopclient", 1, 0, "UserStatusSelectorModel");
|
|
|
|
qmlRegisterType<OCC::ActivityListModel>("com.nextcloud.desktopclient", 1, 0, "ActivityListModel");
|
|
|
|
qmlRegisterType<OCC::FileActivityListModel>("com.nextcloud.desktopclient", 1, 0, "FileActivityListModel");
|
2022-01-28 19:03:39 +03:00
|
|
|
qmlRegisterType<Theme>("com.nextcloud.desktopclient", 1, 0, "Theme");
|
2021-09-09 14:33:57 +03:00
|
|
|
qmlRegisterUncreatableType<OCC::UnifiedSearchResultsListModel>(
|
|
|
|
"com.nextcloud.desktopclient", 1, 0, "UnifiedSearchResultsListModel", "UnifiedSearchResultsListModel");
|
|
|
|
qRegisterMetaType<UnifiedSearchResultsListModel *>("UnifiedSearchResultsListModel*");
|
2021-08-20 16:17:06 +03:00
|
|
|
|
|
|
|
qmlRegisterUncreatableType<OCC::UserStatus>("com.nextcloud.desktopclient", 1, 0, "UserStatus", "Access to Status enum");
|
|
|
|
|
2021-09-09 12:18:22 +03:00
|
|
|
qRegisterMetaTypeStreamOperators<Emoji>();
|
|
|
|
qRegisterMetaType<OCC::UserStatus>("UserStatus");
|
|
|
|
|
|
|
|
|
2020-05-06 21:04:58 +03:00
|
|
|
// Work around a bug in KDE's qqc2-desktop-style which breaks
|
|
|
|
// buttons with icons not based on a name, by forcing a style name
|
|
|
|
// the platformtheme plugin won't try to force qqc2-desktops-style
|
|
|
|
// anymore.
|
|
|
|
// Can be removed once the bug in qqc2-desktop-style is gone.
|
|
|
|
QQuickStyle::setStyle("Default");
|
|
|
|
|
2018-11-08 11:24:39 +03:00
|
|
|
// OpenSSL 1.1.0: No explicit initialisation or de-initialisation is necessary.
|
2017-09-14 18:37:43 +03:00
|
|
|
|
2019-11-05 19:02:01 +03:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
2014-01-15 14:08:42 +04:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
Mac::CocoaInitializer cocoaInit; // RIIA
|
|
|
|
#endif
|
2022-03-09 13:44:51 +03:00
|
|
|
|
|
|
|
auto surfaceFormat = QSurfaceFormat::defaultFormat();
|
|
|
|
surfaceFormat.setOption(QSurfaceFormat::ResetNotification);
|
|
|
|
QSurfaceFormat::setDefaultFormat(surfaceFormat);
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
OCC::Application app(argc, argv);
|
2014-08-26 20:07:42 +04:00
|
|
|
|
2016-01-11 17:27:13 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// The Windows style still has pixelated elements with Qt 5.6,
|
|
|
|
// it's recommended to use the Fusion style in this case, even
|
|
|
|
// though it looks slightly less native. Check here after the
|
|
|
|
// QApplication was constructed, but before any QWidget is
|
|
|
|
// constructed.
|
|
|
|
if (app.devicePixelRatio() > 1)
|
|
|
|
QApplication::setStyle(QStringLiteral("fusion"));
|
|
|
|
#endif // Q_OS_WIN
|
|
|
|
|
2013-12-03 19:24:17 +04:00
|
|
|
#ifndef Q_OS_WIN
|
2013-11-20 16:35:41 +04:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2013-11-20 17:59:58 +04:00
|
|
|
#endif
|
2013-08-15 14:15:39 +04:00
|
|
|
if (app.giveHelp()) {
|
|
|
|
app.showHelp();
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-16 19:12:45 +03:00
|
|
|
if (app.versionOnly()) {
|
|
|
|
app.showVersion();
|
|
|
|
return 0;
|
|
|
|
}
|
2013-08-15 14:15:39 +04:00
|
|
|
|
2020-09-11 03:36:28 +03:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
|
|
|
|
#else
|
|
|
|
// See https://bugreports.qt.io/browse/QTBUG-70481
|
|
|
|
if (std::fmod(app.devicePixelRatio(), 1) == 0) {
|
|
|
|
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-15 13:01:21 +04:00
|
|
|
// check a environment variable for core dumps
|
|
|
|
#ifdef Q_OS_UNIX
|
2017-09-29 11:31:41 +03:00
|
|
|
if (!qEnvironmentVariableIsEmpty("OWNCLOUD_CORE_DUMP")) {
|
2014-05-15 13:01:21 +04:00
|
|
|
struct rlimit core_limit;
|
|
|
|
core_limit.rlim_cur = RLIM_INFINITY;
|
|
|
|
core_limit.rlim_max = RLIM_INFINITY;
|
|
|
|
|
|
|
|
if (setrlimit(RLIMIT_CORE, &core_limit) < 0) {
|
|
|
|
fprintf(stderr, "Unable to set core dump limit\n");
|
|
|
|
} else {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcApplication) << "Core dumps enabled";
|
2014-05-15 13:01:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2020-03-09 03:48:07 +03:00
|
|
|
|
|
|
|
#if defined(BUILD_UPDATER)
|
2014-01-28 12:59:59 +04:00
|
|
|
// if handleStartup returns true, main()
|
|
|
|
// needs to terminate here, e.g. because
|
|
|
|
// the updater is triggered
|
2017-01-13 18:08:16 +03:00
|
|
|
Updater *updater = Updater::instance();
|
|
|
|
if (updater && updater->handleStartup()) {
|
2017-07-04 11:55:41 +03:00
|
|
|
return 1;
|
2014-01-15 14:08:42 +04:00
|
|
|
}
|
2020-03-09 03:48:07 +03:00
|
|
|
#endif
|
2014-01-15 14:08:42 +04:00
|
|
|
|
2012-07-30 18:10:48 +04:00
|
|
|
// if the application is already running, notify it.
|
2015-02-19 18:54:34 +03:00
|
|
|
if (app.isRunning()) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcApplication) << "Already running, exiting...";
|
2015-08-03 18:32:41 +03:00
|
|
|
if (app.isSessionRestored()) {
|
2015-09-28 23:51:16 +03:00
|
|
|
// This call is mirrored with the one in Application::slotParseMessage
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcApplication) << "Session was restored, don't notify app!";
|
2015-08-03 18:32:41 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-16 21:05:28 +04:00
|
|
|
QStringList args = app.arguments();
|
2015-02-19 18:54:34 +03:00
|
|
|
if (args.size() > 1) {
|
|
|
|
QString msg = args.join(QLatin1String("|"));
|
|
|
|
if (!app.sendMessage(QLatin1String("MSG_PARSEOPTIONS:") + msg))
|
2012-10-16 21:05:28 +04:00
|
|
|
return -1;
|
2018-11-29 15:55:27 +03:00
|
|
|
} else if (!app.backgroundMode() && !app.sendMessage(QLatin1String("MSG_SHOWMAINDIALOG"))) {
|
2015-02-19 18:54:34 +03:00
|
|
|
return -1;
|
2015-09-28 23:51:16 +03:00
|
|
|
}
|
2012-10-16 21:05:28 +04:00
|
|
|
return 0;
|
2016-04-27 12:21:13 +03:00
|
|
|
}
|
2019-03-06 12:55:45 +03:00
|
|
|
|
2017-09-13 07:26:56 +03:00
|
|
|
// We can't call isSystemTrayAvailable with appmenu-qt5 begause it hides the systemtray
|
|
|
|
// (issue #4693)
|
2016-04-27 12:21:13 +03:00
|
|
|
if (qgetenv("QT_QPA_PLATFORMTHEME") != "appmenu-qt5")
|
|
|
|
{
|
2015-01-26 15:00:45 +03:00
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
2016-04-27 12:21:13 +03:00
|
|
|
// If the systemtray is not there, we will wait one second for it to maybe start
|
|
|
|
// (eg boot time) then we show the settings dialog if there is still no systemtray.
|
|
|
|
// On XFCE however, we show a message box with explainaition how to install a systemtray.
|
2019-03-06 12:55:45 +03:00
|
|
|
qCInfo(lcApplication) << "System tray is not available, waiting...";
|
2015-01-26 15:00:45 +03:00
|
|
|
Utility::sleep(1);
|
2019-03-06 12:55:45 +03:00
|
|
|
|
2015-01-26 15:00:45 +03:00
|
|
|
auto desktopSession = qgetenv("XDG_CURRENT_DESKTOP").toLower();
|
|
|
|
if (desktopSession.isEmpty()) {
|
|
|
|
desktopSession = qgetenv("DESKTOP_SESSION").toLower();
|
|
|
|
}
|
|
|
|
if (desktopSession == "xfce") {
|
|
|
|
int attempts = 0;
|
2019-03-06 12:55:45 +03:00
|
|
|
while (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
|
|
|
attempts++;
|
|
|
|
if (attempts >= 30) {
|
|
|
|
qCWarning(lcApplication) << "System tray unavailable (xfce)";
|
|
|
|
warnSystray();
|
2015-01-26 15:00:45 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-03-06 12:55:45 +03:00
|
|
|
Utility::sleep(1);
|
2015-01-26 15:00:45 +03:00
|
|
|
}
|
|
|
|
}
|
2019-03-06 12:55:45 +03:00
|
|
|
|
|
|
|
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
|
|
|
app.tryTrayAgain();
|
2021-06-21 14:33:22 +03:00
|
|
|
} else if (!app.backgroundMode() && !AccountManager::instance()->accounts().isEmpty()) {
|
2019-03-06 12:55:45 +03:00
|
|
|
if (desktopSession != "ubuntu") {
|
|
|
|
qCInfo(lcApplication) << "System tray still not available, showing window and trying again later";
|
|
|
|
app.showMainDialog();
|
|
|
|
QTimer::singleShot(10000, &app, &Application::tryTrayAgain);
|
|
|
|
} else {
|
|
|
|
qCInfo(lcApplication) << "System tray still not available, but assuming it's fine on 'ubuntu' desktop";
|
|
|
|
}
|
2013-09-10 13:35:30 +04:00
|
|
|
}
|
2013-07-08 04:58:26 +04:00
|
|
|
}
|
2012-07-30 18:10:48 +04:00
|
|
|
}
|
2016-04-27 12:21:13 +03:00
|
|
|
|
2013-08-15 14:15:39 +04:00
|
|
|
return app.exec();
|
2011-02-17 02:21:45 +03:00
|
|
|
}
|