diff --git a/sources/gui/src/main.cpp b/sources/gui/src/main.cpp index 126f3c3..b0fb5c4 100644 --- a/sources/gui/src/main.cpp +++ b/sources/gui/src/main.cpp @@ -157,9 +157,6 @@ int main(int argc, char *argv[]) daemon(0, 0); QApplication a(argc, argv); QApplication::setQuitOnLastWindowClosed(false); - // check if exists - if (restoreExistSession()) - return 0; // reread translations according to flags QString language = Language::defineLanguage(args[QString("config")].toString(), args[QString("options")].toString()); @@ -186,6 +183,10 @@ int main(int argc, char *argv[]) cout << versionMessage().toUtf8().data(); return 0; } + + // check if exists + if (restoreExistSession()) + return 0; MainWindow w(0, args, &translator); return a.exec(); } diff --git a/sources/helper/CMakeLists.txt b/sources/helper/CMakeLists.txt index f948989..1478a45 100644 --- a/sources/helper/CMakeLists.txt +++ b/sources/helper/CMakeLists.txt @@ -3,7 +3,12 @@ set (SUBPROJECT netctlgui-helper) message (STATUS "Subproject ${SUBPROJECT}") # set directories +set (SUBPROJECT_BINARY_DIR bin) set (SUBPROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) +set (SUBPROJECT_RESOURCE_DIR ${PROJECT_RESOURCE_DIR}) +set (SUBPROJECT_TRANSLATION_DIR ${SUBPROJECT_RESOURCE_DIR}/translations-helper) +# executable path +set (EXECUTABLE_OUTPUT_PATH ${SUBPROJECT_BINARY_DIR}) # additional targets set (TARGETS "") diff --git a/sources/helper/src/CMakeLists.txt b/sources/helper/src/CMakeLists.txt index 13497b5..3f22a58 100644 --- a/sources/helper/src/CMakeLists.txt +++ b/sources/helper/src/CMakeLists.txt @@ -2,6 +2,9 @@ file (GLOB SOURCES *.cpp) file (GLOB HEADERS *.h) +file (GLOB LANGUAGES ${SUBPROJECT_TRANSLATION_DIR}/*.ts) +set (RESOURCES ${SUBPROJECT_RESOURCE_DIR}/resources-helper.qrc) + # include_path include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/include/ ${CMAKE_CURRENT_BINARY_DIR}/../ @@ -13,19 +16,43 @@ link_directories (${PROJECT_LIBRARY}/src/lib) if (USE_QT5) find_package(Qt5Core REQUIRED) find_package(Qt5DBus REQUIRED) + find_package(Qt5LinguistTools REQUIRED) add_definitions(${Qt5Core_DEFINITIONS}) add_definitions(${Qt5DBus_DEFINITIONS}) + add_definitions(${Qt5LinguistTools_DEFINITIONS}) include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES}) qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) + qt5_add_resources (QRC_SOURCES ${RESOURCES}) + + foreach (LANGUAGE ${LANGUAGES}) + set (TS ${LANGUAGE}) + string (REPLACE ".ts" ".qm" QM ${TS}) + set (TRANSLATIONS ${TRANSLATIONS} ${TS}) + set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM}) + add_custom_command (OUTPUT ${QM} COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS}) + endforeach () + add_custom_target (translations-helper COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} -ts ${TRANSLATIONS}) + add_custom_command (TARGET translations-helper COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TRANSLATIONS}) else () find_package (Qt4 COMPONENTS QtCore QtDBus REQUIRED) include (${QT_USE_FILE}) set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY}) qt4_wrap_cpp (MOC_SOURCES ${HEADERS}) + qt4_add_resources (QRC_SOURCES ${RESOURCES}) + + foreach (LANGUAGE ${LANGUAGES}) + set (TS ${LANGUAGE}) + string (REPLACE ".ts" ".qm" QM ${TS}) + set (TRANSLATIONS ${TRANSLATIONS} ${TS}) + set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM}) + add_custom_command (OUTPUT ${QM} COMMAND ${QT_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS}) + endforeach () + add_custom_target (translations-header COMMAND ${QT_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} -ts ${TRANSLATIONS}) + add_custom_command (TARGET translations-header COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS}) endif() -add_executable (${SUBPROJECT} ${SOURCES} ${HEADERS} ${MOC_SOURCES}) +add_executable (${SUBPROJECT} ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS}) target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS}) # install properties install (TARGETS ${SUBPROJECT} DESTINATION bin diff --git a/sources/helper/src/language.cpp b/sources/helper/src/language.cpp new file mode 120000 index 0000000..b49a613 --- /dev/null +++ b/sources/helper/src/language.cpp @@ -0,0 +1 @@ +../../gui/src/language.cpp \ No newline at end of file diff --git a/sources/helper/src/language.h b/sources/helper/src/language.h new file mode 120000 index 0000000..6feee84 --- /dev/null +++ b/sources/helper/src/language.h @@ -0,0 +1 @@ +../../gui/src/language.h \ No newline at end of file diff --git a/sources/helper/src/main.cpp b/sources/helper/src/main.cpp index 5a8d744..2a4da5a 100644 --- a/sources/helper/src/main.cpp +++ b/sources/helper/src/main.cpp @@ -21,9 +21,11 @@ #include #include #include +#include #include #include +#include "language.h" #include "messages.h" #include "netctlhelper.h" #include "version.h" @@ -80,9 +82,27 @@ int main(int argc, char *argv[]) args[QString("error")] = true; } } - if (args[QString("debug")].toBool()) + if ((args[QString("debug")].toBool()) || + (args[QString("help")].toBool()) || + (args[QString("info")].toBool()) || + (args[QString("version")].toBool()) || + (args[QString("error")].toBool())) args[QString("nodaemon")] = true; + // detach from console + if (!args[QString("nodaemon")].toBool()) + daemon(0, 0); +#if QT_VERSION >= 0x050000 + QCoreApplication::setSetuidAllowed(true); +#endif + QCoreApplication a(argc, argv); + // reread translations according to flags + QString language = Language::defineLanguage(args[QString("config")].toString(), + args[QString("options")].toString()); + QTranslator translator; + translator.load(QString(":/translations-helper/") + language); + a.installTranslator(&translator); + // running if (args[QString("error")].toBool()) { cout << errorMessage().toUtf8().data() << endl; @@ -103,17 +123,9 @@ int main(int argc, char *argv[]) return 0; } - // detach from console - if (!args[QString("nodaemon")].toBool()) - daemon(0, 0); -#if QT_VERSION >= 0x050000 - QCoreApplication::setSetuidAllowed(true); -#endif - QCoreApplication a(argc, argv); // check if exists if (checkExistSession()) return 0; - NetctlHelper w(0, args); return a.exec(); } diff --git a/sources/resources/resources-helper.qrc b/sources/resources/resources-helper.qrc new file mode 100644 index 0000000..2e908f9 --- /dev/null +++ b/sources/resources/resources-helper.qrc @@ -0,0 +1,7 @@ + + + + translations-helper/en.qm + translations-helper/ru.qm + + diff --git a/sources/resources/translations-helper/en.ts b/sources/resources/translations-helper/en.ts new file mode 100644 index 0000000..30bc79b --- /dev/null +++ b/sources/resources/translations-helper/en.ts @@ -0,0 +1,94 @@ + + + + + NetctlHelper + + + Unknown flag + + Unknown flag + + + + + Usage: + Usage: + + + + Options: + Options: + + + + read configuration from this file + read configuration from this file + + + + print debug information + print debug information + + + + do not start as daemon + do not start as daemon + + + + Show messages: + Show messages: + + + + show version and exit + show version and exit + + + + show build information and exit + show build information and exit + + + + show this help and exit + show this help and exit + + + + Build date: %1 + Build date: %1 + + + + cmake flags + cmake flags + + + + DBus configuration + DBus configuration + + + + Documentation + Documentation + + + + Version + Version + + + + Author + Author + + + + License + License + + + diff --git a/sources/resources/translations-helper/netctlgui-helper.ts b/sources/resources/translations-helper/netctlgui-helper.ts new file mode 100644 index 0000000..9cc59e3 --- /dev/null +++ b/sources/resources/translations-helper/netctlgui-helper.ts @@ -0,0 +1,93 @@ + + + + + NetctlHelper + + + Unknown flag + + + + + + Usage: + + + + + Options: + + + + + read configuration from this file + + + + + print debug information + + + + + do not start as daemon + + + + + Show messages: + + + + + show version and exit + + + + + show build information and exit + + + + + show this help and exit + + + + + Build date: %1 + + + + + cmake flags + + + + + DBus configuration + + + + + Documentation + + + + + Version + + + + + Author + + + + + License + + + + diff --git a/sources/resources/translations-helper/ru.ts b/sources/resources/translations-helper/ru.ts new file mode 100644 index 0000000..0478233 --- /dev/null +++ b/sources/resources/translations-helper/ru.ts @@ -0,0 +1,94 @@ + + + + + NetctlHelper + + + Unknown flag + + Неизвестный флаг + + + + + Usage: + Использование: + + + + Options: + Опции: + + + + read configuration from this file + прочитать настройки из данного файла + + + + print debug information + показать отладочную информацию + + + + do not start as daemon + не запускать как демон + + + + Show messages: + Показать сообщения: + + + + show version and exit + показать версию и выход + + + + show build information and exit + показать информацию о сборке и выход + + + + show this help and exit + показать справку и выход + + + + Build date: %1 + Дата сборки: %1 + + + + cmake flags + Флаги cmake + + + + DBus configuration + Настройка DBus + + + + Documentation + Документация + + + + Version + Версия + + + + Author + Автор + + + + License + Лицензия + + +