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>
|
|
|
|
|
2013-11-20 16:35:41 +04:00
|
|
|
#include <signal.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"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "utility.h"
|
|
|
|
#include "cocoainitializer.h"
|
2014-01-29 13:38:12 +04:00
|
|
|
|
|
|
|
#include "updater/updater.h"
|
2013-07-08 04:58:26 +04:00
|
|
|
|
2014-08-30 12:46:09 +04:00
|
|
|
|
|
|
|
#include "config.h"
|
2014-08-26 20:07:42 +04:00
|
|
|
#ifdef WITH_CRASHREPORTER
|
2014-12-08 19:54:32 +03:00
|
|
|
#include "configfile.h"
|
2014-08-28 13:11:42 +04:00
|
|
|
#include <libcrashreporter-handler/Handler.h>
|
2014-08-26 20:07:42 +04:00
|
|
|
#endif
|
|
|
|
|
2013-09-10 13:35:30 +04:00
|
|
|
#include <QTimer>
|
2014-01-15 14:08:42 +04:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
using namespace OCC;
|
2013-09-10 13:35:30 +04:00
|
|
|
|
|
|
|
void warnSystray()
|
|
|
|
{
|
|
|
|
QMessageBox::critical(0, qApp->translate("main.cpp", "System Tray not available"),
|
|
|
|
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>. "
|
|
|
|
"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)
|
|
|
|
{
|
2014-12-08 20:00:29 +03:00
|
|
|
Q_INIT_RESOURCE(client);
|
2012-03-31 13:31:28 +04:00
|
|
|
|
2014-01-15 14:08:42 +04:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
Mac::CocoaInitializer cocoaInit; // RIIA
|
|
|
|
#endif
|
2014-11-10 00:34:07 +03:00
|
|
|
OCC::Application app(argc, argv);
|
2014-08-26 20:07:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_CRASHREPORTER
|
2014-08-30 12:46:09 +04:00
|
|
|
CrashReporter::Handler* handler = new CrashReporter::Handler( QDir::tempPath(), true, CRASHREPORTER_EXECUTABLE );
|
2014-11-12 02:07:59 +03:00
|
|
|
ConfigFile cfgFile;
|
2014-08-28 18:23:14 +04:00
|
|
|
handler->setActive(cfgFile.crashReporter());
|
2014-08-26 20:07:42 +04:00
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-15 13:01:21 +04:00
|
|
|
// check a environment variable for core dumps
|
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
if( !qgetenv("OWNCLOUD_CORE_DUMP").isEmpty() ) {
|
|
|
|
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 {
|
|
|
|
qDebug() << "Core dumps enabled";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-01-28 12:59:59 +04:00
|
|
|
// if handleStartup returns true, main()
|
|
|
|
// needs to terminate here, e.g. because
|
|
|
|
// the updater is triggered
|
|
|
|
if (Updater::instance()->handleStartup()) {
|
2014-01-15 14:08:42 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:10:48 +04:00
|
|
|
// if the application is already running, notify it.
|
|
|
|
if( app.isRunning() ) {
|
2014-10-16 17:25:33 +04:00
|
|
|
qDebug() << Q_FUNC_INFO << "Already running, exiting...";
|
2012-10-16 21:05:28 +04:00
|
|
|
QStringList args = app.arguments();
|
|
|
|
if ( args.size() > 1 && ! app.giveHelp() ) {
|
|
|
|
QString msg = args.join( QLatin1String("|") );
|
|
|
|
if( ! app.sendMessage( msg ) )
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2013-07-08 04:58:26 +04:00
|
|
|
} else {
|
2015-01-26 15:00:45 +03:00
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
|
|
|
Utility::sleep(1);
|
|
|
|
auto desktopSession = qgetenv("XDG_CURRENT_DESKTOP").toLower();
|
|
|
|
if (desktopSession.isEmpty()) {
|
|
|
|
desktopSession = qgetenv("DESKTOP_SESSION").toLower();
|
|
|
|
}
|
|
|
|
if (desktopSession == "xfce") {
|
|
|
|
int attempts = 0;
|
|
|
|
forever {
|
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
|
|
|
Utility::sleep(1);
|
|
|
|
attempts++;
|
|
|
|
if (attempts < 30) continue;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
warnSystray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable() && desktopSession != "ubuntu") {
|
|
|
|
app.showSettingsDialog();
|
2013-09-10 13:35:30 +04:00
|
|
|
}
|
2013-07-08 04:58:26 +04:00
|
|
|
}
|
2012-07-30 18:10:48 +04:00
|
|
|
}
|
2013-08-15 14:15:39 +04:00
|
|
|
return app.exec();
|
2011-02-17 02:21:45 +03:00
|
|
|
}
|
|
|
|
|