main.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * wpa_gui - Application startup
  3. * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
  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 version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #ifdef CONFIG_NATIVE_WINDOWS
  15. #include <winsock.h>
  16. #endif /* CONFIG_NATIVE_WINDOWS */
  17. #include <QApplication>
  18. #include <QtCore/QLibraryInfo>
  19. #include <QtCore/QTranslator>
  20. #include "wpagui.h"
  21. class WpaGuiApp : public QApplication
  22. {
  23. public:
  24. WpaGuiApp(int &argc, char **argv);
  25. #ifndef QT_NO_SESSIONMANAGER
  26. virtual void saveState(QSessionManager &manager);
  27. #endif
  28. WpaGui *w;
  29. };
  30. WpaGuiApp::WpaGuiApp(int &argc, char **argv) : QApplication(argc, argv)
  31. {
  32. }
  33. #ifndef QT_NO_SESSIONMANAGER
  34. void WpaGuiApp::saveState(QSessionManager &manager)
  35. {
  36. QApplication::saveState(manager);
  37. w->saveState();
  38. }
  39. #endif
  40. int main(int argc, char *argv[])
  41. {
  42. WpaGuiApp app(argc, argv);
  43. QTranslator translator;
  44. QString locale;
  45. QString resourceDir;
  46. int ret;
  47. locale = QLocale::system().name();
  48. resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
  49. if (!translator.load("wpa_gui_" + locale, resourceDir))
  50. translator.load("wpa_gui_" + locale, "lang");
  51. app.installTranslator(&translator);
  52. WpaGui w(&app);
  53. #ifdef CONFIG_NATIVE_WINDOWS
  54. WSADATA wsaData;
  55. if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
  56. /* printf("Could not find a usable WinSock.dll\n"); */
  57. return -1;
  58. }
  59. #endif /* CONFIG_NATIVE_WINDOWS */
  60. app.w = &w;
  61. ret = app.exec();
  62. #ifdef CONFIG_NATIVE_WINDOWS
  63. WSACleanup();
  64. #endif /* CONFIG_NATIVE_WINDOWS */
  65. return ret;
  66. }