From e8e8757b6bc2468d6bce581de4c5dfbdb1cfa46c Mon Sep 17 00:00:00 2001 From: tezeb Date: Tue, 24 Oct 2017 00:18:09 +0200 Subject: separate into main/static library --- main/main.cpp | 91 ++++++++++++++++++++++++++++++++ main/main.pro | 27 ++++++++++ qtpass.pri | 77 ++++++++++++++++++++++++++- qtpass.pro | 32 ++++++++++- src/main.cpp | 91 -------------------------------- src/src.pro | 135 +++-------------------------------------------- tests/auto/util/util.pro | 9 +--- tests/tests.pro | 1 + 8 files changed, 233 insertions(+), 230 deletions(-) create mode 100644 main/main.cpp create mode 100644 main/main.pro delete mode 100644 src/main.cpp diff --git a/main/main.cpp b/main/main.cpp new file mode 100644 index 00000000..8a18409c --- /dev/null +++ b/main/main.cpp @@ -0,0 +1,91 @@ +#include "mainwindow.h" +#include +#include + +/*! \mainpage QtPass + * + * \section intro_sec Introduction + * + * QtPass is a multi-platform GUI for pass, the standard unix password manager. + * + * https://qtpass.org/ + * + * \section install_sec Installation + * + * \subsection dependencies Dependencies + * + * - QtPass requires Qt 4.8 or later, preferably Qt5.5 or later. + * - The Linguist package is required to compile the translations. + * - For use of the fallback icons the SVG library is required. + * + * At runtime the only real dependency is gpg2 but to make the most of it, + * you'll need git and pass too. + * + * \subsection source From source + * + * On most *nix systems all you need is: + * + * `qmake && make && make install` + */ + +/** + * @brief main + * @param argc + * @param argv + * @return + */ +int main(int argc, char *argv[]) { + qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1"); + QString text = ""; + for (int i = 1; i < argc; ++i) { + if (i > 1) + text += " "; + text += argv[i]; + } + + if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) { + text.clear(); + } + +#if SINGLE_APP + QString name = qgetenv("USER"); + if (name.isEmpty()) + name = qgetenv("USERNAME"); + SingleApplication app(argc, argv, name + "QtPass"); + if (app.isRunning()) { + if (text.length() > 0) + app.sendMessage(text); + return 0; + } +#else + QApplication app(argc, argv); +#endif + + QCoreApplication::setOrganizationName("IJHack"); + QCoreApplication::setOrganizationDomain("ijhack.org"); + QCoreApplication::setApplicationName("QtPass"); + QCoreApplication::setApplicationVersion(VERSION); + + // Setup and load translator for localization + QTranslator translator; + QString locale = QLocale::system().name(); + // locale = "nl_NL"; + // locale = "he_IL"; + // locale = "ar_MA"; + translator.load(QString(":localization/localization_") + locale + + QString(".qm")); + app.installTranslator(&translator); + app.setLayoutDirection(QObject::tr("LTR") == "RTL" ? Qt::RightToLeft + : Qt::LeftToRight); + MainWindow w; + + QObject::connect(&app, SIGNAL(aboutToQuit()), &w, SLOT(clearClipboard())); + + app.setActiveWindow(&w); + app.setWindowIcon(QIcon(":artwork/icon.png")); + w.setApp(&app); + w.setText(text); + w.show(); + + return app.exec(); +} diff --git a/main/main.pro b/main/main.pro new file mode 100644 index 00000000..8344b0b7 --- /dev/null +++ b/main/main.pro @@ -0,0 +1,27 @@ +!include(../qtpass.pri) { error("Couldn't find the qtpass.pri file!") } + +TEMPLATE = app +QT += core gui + +CONFIG += c++11 +LIBS += -L../src/ -lqtpass +INCLUDEPATH += ../src + +macx { + TARGET = QtPass +} else { + TARGET = qtpass +} + +SOURCES += main.cpp + +isEmpty(PREFIX) { + PREFIX = $$(PREFIX) +} + +isEmpty(PREFIX) { + PREFIX = /usr/local +} +target.path = $$PREFIX/bin/ + +INSTALLS += target diff --git a/qtpass.pri b/qtpass.pri index 3e89fe87..b6568524 100644 --- a/qtpass.pri +++ b/qtpass.pri @@ -1,7 +1,80 @@ VERSION = 1.2.0-pre -TEMPLATE = subdirs - CONFIG(coverage) { QMAKE_LFLAGS += --coverage + QMAKE_CXXFLAGS += --coverage +} + +CONFIG(debug, debug|release) { + QMAKE_CXXFLAGS += -g -c -Wall -O0 + QMAKE_LFLAGS += -O0 +} + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +clang|gcc:QMAKE_CXXFLAGS_WARN_ON += -Wno-unknown-pragmas + +nosingleapp { + QMAKE_CXXFLAGS += -DSINGLE_APP=0 +} else { + QT += network + QMAKE_CXXFLAGS += -DSINGLE_APP=1 +} + +DEFINES += "VERSION=\"\\\"$$VERSION\\\"\"" + +CODECFORSRC = UTF-8 +CODECFORTR = UTF-8 + +macx { + QMAKE_MAC_SDK = macosx + QT += svg } + +isEmpty(QMAKE_LRELEASE) { + win32|os2:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\\lrelease.exe + else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease + unix { + !exists($$QMAKE_LRELEASE) { + greaterThan(QT_MAJOR_VERSION, 4) { + QMAKE_LRELEASE = lrelease-qt5 + } else { + QMAKE_LRELEASE = lrelease-qt4 + } + } + } else { + !exists($$QMAKE_LRELEASE) { QMAKE_LRELEASE = lrelease } + } +} + +isEmpty(QMAKE_LUPDATE) { + win32|os2:QMAKE_LUPDATE = $$[QT_INSTALL_BINS]\\lupdate.exe + else:QMAKE_LUPDATE = $$[QT_INSTALL_BINS]/lupdate + unix { + !exists($$QMAKE_LUPDATE) { + greaterThan(QT_MAJOR_VERSION, 4) { + QMAKE_LUPDATE = lupdate-qt5 + } else { + QMAKE_LUPDATE = lupdate-qt4 + } + } + } else { + !exists($$QMAKE_LUPDATE) { QMAKE_LUPDATE = lupdate } + } +} + +win32 { + RC_FILE = ../windows.rc + static { + QMAKE_LFLAGS += -static-libgcc -static-libstdc++ + } + gcc:QMAKE_LFLAGS += -Wl,--dynamicbase -Wl,--nxcompat + msvc:QMAKE_LFLAGS += /DYNAMICBASE /NXCOMPAT + LIBS += -lmpr -lbcrypt +} else:macx { + ICON = ../artwork/icon.icns + QMAKE_INFO_PLIST = ../qtpass.plist +} else:bsd { + LIBS += -L/usr/local/lib +} + diff --git a/qtpass.pro b/qtpass.pro index 4bec8406..c0026c08 100644 --- a/qtpass.pro +++ b/qtpass.pro @@ -1,7 +1,9 @@ !include(qtpass.pri) { error("Couldn't find the qtpass.pri file!") } -SUBDIRS += src tests +TEMPLATE = subdirs +SUBDIRS += src tests main tests.depends = src +main.depends = tests OTHER_FILES += LICENSE \ README.md \ @@ -55,3 +57,31 @@ CONFIG(coverage) { QMAKE_CLEAN += src/$$OBJECTS_DIR/*.gc?? src/*.gcov QMAKE_DISTCLEAN += -r src/$$OBJECTS_DIR/lcov/ } + +TRANSLATIONS += localization/localization_nl_NL.ts \ + localization/localization_de_DE.ts \ + localization/localization_es_ES.ts \ + localization/localization_gl_ES.ts \ + localization/localization_hu_HU.ts \ + localization/localization_sv_SE.ts \ + localization/localization_pl_PL.ts \ + localization/localization_ru_RU.ts \ + localization/localization_he_IL.ts \ + localization/localization_zh_CN.ts \ + localization/localization_ar_MA.ts \ + localization/localization_fr_FR.ts \ + localization/localization_fr_BE.ts \ + localization/localization_nl_BE.ts \ + localization/localization_fr_LU.ts \ + localization/localization_de_LU.ts \ + localization/localization_lb_LU.ts \ + localization/localization_en_GB.ts \ + localization/localization_en_US.ts \ + localization/localization_el_GR.ts \ + localization/localization_cs_CZ.ts \ + localization/localization_it_IT.ts \ + localization/localization_pt_PT.ts + +system($$QMAKE_LUPDATE $$_PRO_FILE_) +system($$QMAKE_LRELEASE $$_PRO_FILE_) + diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 8a18409c..00000000 --- a/src/main.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "mainwindow.h" -#include -#include - -/*! \mainpage QtPass - * - * \section intro_sec Introduction - * - * QtPass is a multi-platform GUI for pass, the standard unix password manager. - * - * https://qtpass.org/ - * - * \section install_sec Installation - * - * \subsection dependencies Dependencies - * - * - QtPass requires Qt 4.8 or later, preferably Qt5.5 or later. - * - The Linguist package is required to compile the translations. - * - For use of the fallback icons the SVG library is required. - * - * At runtime the only real dependency is gpg2 but to make the most of it, - * you'll need git and pass too. - * - * \subsection source From source - * - * On most *nix systems all you need is: - * - * `qmake && make && make install` - */ - -/** - * @brief main - * @param argc - * @param argv - * @return - */ -int main(int argc, char *argv[]) { - qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1"); - QString text = ""; - for (int i = 1; i < argc; ++i) { - if (i > 1) - text += " "; - text += argv[i]; - } - - if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) { - text.clear(); - } - -#if SINGLE_APP - QString name = qgetenv("USER"); - if (name.isEmpty()) - name = qgetenv("USERNAME"); - SingleApplication app(argc, argv, name + "QtPass"); - if (app.isRunning()) { - if (text.length() > 0) - app.sendMessage(text); - return 0; - } -#else - QApplication app(argc, argv); -#endif - - QCoreApplication::setOrganizationName("IJHack"); - QCoreApplication::setOrganizationDomain("ijhack.org"); - QCoreApplication::setApplicationName("QtPass"); - QCoreApplication::setApplicationVersion(VERSION); - - // Setup and load translator for localization - QTranslator translator; - QString locale = QLocale::system().name(); - // locale = "nl_NL"; - // locale = "he_IL"; - // locale = "ar_MA"; - translator.load(QString(":localization/localization_") + locale + - QString(".qm")); - app.installTranslator(&translator); - app.setLayoutDirection(QObject::tr("LTR") == "RTL" ? Qt::RightToLeft - : Qt::LeftToRight); - MainWindow w; - - QObject::connect(&app, SIGNAL(aboutToQuit()), &w, SLOT(clearClipboard())); - - app.setActiveWindow(&w); - app.setWindowIcon(QIcon(":artwork/icon.png")); - w.setApp(&app); - w.setText(text); - w.show(); - - return app.exec(); -} diff --git a/src/src.pro b/src/src.pro index 5cf24593..55a60b97 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,31 +1,12 @@ !include(../qtpass.pri) { error("Couldn't find the qtpass.pri file!") } -TEMPLATE = app +TEMPLATE = lib QT += core gui +TARGET = qtpass -CONFIG += c++11 +CONFIG += c++11 staticlib -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG(debug, debug|release) { - QMAKE_CXXFLAGS += -g -c -Wall -O0 - QMAKE_LFLAGS += -O0 -} - -CONFIG(coverage) { - QMAKE_CXXFLAGS += --coverage -} - -macx { - TARGET = QtPass - QMAKE_MAC_SDK = macosx - QT += svg -} else { - TARGET = qtpass -} - -SOURCES += main.cpp \ - mainwindow.cpp \ +SOURCES += mainwindow.cpp \ configdialog.cpp \ storemodel.cpp \ util.cpp \ @@ -71,79 +52,6 @@ FORMS += mainwindow.ui \ keygendialog.ui \ passworddialog.ui -clang|gcc:QMAKE_CXXFLAGS_WARN_ON += -Wno-unknown-pragmas - -nosingleapp { - QMAKE_CXXFLAGS += -DSINGLE_APP=0 -} else { - SOURCES += singleapplication.cpp - HEADERS += singleapplication.h - QT += network - QMAKE_CXXFLAGS += -DSINGLE_APP=1 -} - -DEFINES += "VERSION=\"\\\"$$VERSION\\\"\"" - - -TRANSLATIONS += ../localization/localization_nl_NL.ts \ - ../localization/localization_de_DE.ts \ - ../localization/localization_es_ES.ts \ - ../localization/localization_gl_ES.ts \ - ../localization/localization_hu_HU.ts \ - ../localization/localization_sv_SE.ts \ - ../localization/localization_pl_PL.ts \ - ../localization/localization_ru_RU.ts \ - ../localization/localization_he_IL.ts \ - ../localization/localization_zh_CN.ts \ - ../localization/localization_ar_MA.ts \ - ../localization/localization_fr_FR.ts \ - ../localization/localization_fr_BE.ts \ - ../localization/localization_nl_BE.ts \ - ../localization/localization_fr_LU.ts \ - ../localization/localization_de_LU.ts \ - ../localization/localization_lb_LU.ts \ - ../localization/localization_en_GB.ts \ - ../localization/localization_en_US.ts \ - ../localization/localization_el_GR.ts \ - ../localization/localization_cs_CZ.ts \ - ../localization/localization_it_IT.ts \ - ../localization/localization_pt_PT.ts - -CODECFORSRC = UTF-8 -CODECFORTR = UTF-8 - -isEmpty(QMAKE_LRELEASE) { - win32|os2:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\\lrelease.exe - else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease - unix { - !exists($$QMAKE_LRELEASE) { - greaterThan(QT_MAJOR_VERSION, 4) { - QMAKE_LRELEASE = lrelease-qt5 - } else { - QMAKE_LRELEASE = lrelease-qt4 - } - } - } else { - !exists($$QMAKE_LRELEASE) { QMAKE_LRELEASE = lrelease } - } -} - -isEmpty(QMAKE_LUPDATE) { - win32|os2:QMAKE_LUPDATE = $$[QT_INSTALL_BINS]\\lupdate.exe - else:QMAKE_LUPDATE = $$[QT_INSTALL_BINS]/lupdate - unix { - !exists($$QMAKE_LUPDATE) { - greaterThan(QT_MAJOR_VERSION, 4) { - QMAKE_LUPDATE = lupdate-qt5 - } else { - QMAKE_LUPDATE = lupdate-qt4 - } - } - } else { - !exists($$QMAKE_LUPDATE) { QMAKE_LUPDATE = lupdate } - } -} - updateqm.input = TRANSLATIONS updateqm.output = ../localization/${QMAKE_FILE_BASE}.qm updateqm.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} -qm ../localization/${QMAKE_FILE_BASE}.qm @@ -151,38 +59,9 @@ updateqm.CONFIG += no_link target_predeps QMAKE_EXTRA_COMPILERS += updateqm PRE_TARGETDEPS += compiler_updateqm_make_all -win32 { - system($$QMAKE_LUPDATE ../qtpass.pro) - system($$QMAKE_LRELEASE ../qtpass.pro) -} else { - system($$QMAKE_LUPDATE $$_PRO_FILE_) - system($$QMAKE_LRELEASE $$_PRO_FILE_) -} - RESOURCES += ../resources.qrc -win32 { - RC_FILE = ../windows.rc - static { - QMAKE_LFLAGS += -static-libgcc -static-libstdc++ - } - gcc:QMAKE_LFLAGS += -Wl,--dynamicbase -Wl,--nxcompat - msvc:QMAKE_LFLAGS += /DYNAMICBASE /NXCOMPAT - LIBS += -lmpr -lbcrypt -} else:macx { - ICON = ../artwork/icon.icns - QMAKE_INFO_PLIST = ../qtpass.plist -} else:bsd { - LIBS += -L/usr/local/lib -} - -isEmpty(PREFIX) { - PREFIX = $$(PREFIX) -} - -isEmpty(PREFIX) { - PREFIX = /usr/local +!nosingleapp { + SOURCES += singleapplication.cpp + HEADERS += singleapplication.h } -target.path = $$PREFIX/bin/ - -INSTALLS += target diff --git a/tests/auto/util/util.pro b/tests/auto/util/util.pro index 7e9c582a..150aa141 100644 --- a/tests/auto/util/util.pro +++ b/tests/auto/util/util.pro @@ -4,14 +4,7 @@ message($$QMAKE_LINK_OBJECT_MAX) SOURCES += tst_util.cpp \ -OBJECTS += ../../../src/$(OBJECTS_DIR)/util.o \ - ../../../src/$(OBJECTS_DIR)/qtpasssettings.o \ - ../../../src/$(OBJECTS_DIR)/settingsconstants.o \ - ../../../src/$(OBJECTS_DIR)/pass.o \ - ../../../src/$(OBJECTS_DIR)/realpass.o \ - ../../../src/$(OBJECTS_DIR)/imitatepass.o \ - ../../../src/$(OBJECTS_DIR)/executor.o \ - ../../../src/$(OBJECTS_DIR)/simpletransaction.o +LIBS += -L../../../src -lqtpass HEADERS += util.h \ qtpasssettings.h \ diff --git a/tests/tests.pro b/tests/tests.pro index da7ad3ec..e4a0b6aa 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,5 +1,6 @@ !include(tests.pri) { error("Couldn't find the tests.pri file!") } +TEMPLATE = subdirs CONFIG += no_docs_target SUBDIRS += auto exists(manual): SUBDIRS += manual -- cgit v1.2.3