main.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #include <signal.h>
  15. #include "mirall/application.h"
  16. #include "mirall/theme.h"
  17. #include "mirall/utility.h"
  18. #include <QMessageBox>
  19. #include <QTimer>
  20. void warnSystray()
  21. {
  22. QMessageBox::critical(0, qApp->translate("main.cpp", "System Tray not available"),
  23. qApp->translate("main.cpp", "%1 requires on a working system tray. "
  24. "If you are running XFCE, please follow "
  25. "<a href=\"http://docs.xfce.org/xfce/xfce4-panel/systray\">these instructions</a>. "
  26. "Otherwise, please install a system tray application such as 'trayer' and try again.")
  27. .arg(Mirall::Theme::instance()->appNameGUI()));
  28. }
  29. int main(int argc, char **argv)
  30. {
  31. Q_INIT_RESOURCE(mirall);
  32. Mirall::Application app(argc, argv);
  33. app.initialize();
  34. #ifndef Q_OS_WIN32
  35. signal(SIGPIPE, SIG_IGN);
  36. #endif
  37. if( app.giveHelp() ) {
  38. app.showHelp();
  39. return 0;
  40. }
  41. // if the application is already running, notify it.
  42. if( app.isRunning() ) {
  43. QStringList args = app.arguments();
  44. if ( args.size() > 1 && ! app.giveHelp() ) {
  45. QString msg = args.join( QLatin1String("|") );
  46. if( ! app.sendMessage( msg ) )
  47. return -1;
  48. }
  49. return 0;
  50. } else {
  51. int attempts = 0;
  52. forever {
  53. if (!QSystemTrayIcon::isSystemTrayAvailable() && qgetenv("DESKTOP_SESSION") != "ubuntu") {
  54. Mirall::Utility::sleep(1);
  55. attempts++;
  56. if (attempts < 30) continue;
  57. } else {
  58. break;
  59. }
  60. warnSystray();
  61. break;
  62. }
  63. }
  64. return app.exec();
  65. }