QtPass 1.5.1
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#include "mainwindow.h"
5#if SINGLE_APP
6#include "singleapplication.h"
7#endif
8
9#include <QApplication>
10#include <QDir>
11#include <QTranslator>
12#include <QtWidgets>
13
46auto main(int argc, char *argv[]) -> int {
47#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
48 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
49 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
50#endif
51
52 QString text;
53#if SINGLE_APP
54 QString name = qgetenv("USER");
55 if (name.isEmpty())
56 name = qgetenv("USERNAME");
57 SingleApplication app(argc, argv, name + "QtPass");
58#else
59 QApplication app(argc, argv);
60#endif
61
62 const QStringList args = app.arguments();
63 bool consumeNextArg = false;
64 for (int i = 1; i < args.count(); ++i) {
65 const auto &arg = args.at(i);
66
67 if (arg == "--") {
68 consumeNextArg = false;
69 for (int j = i + 1; j < args.count(); ++j) {
70 if (!text.isEmpty())
71 text += " ";
72 text += args.at(j);
73 }
74 break;
75 }
76
77 if (consumeNextArg) {
78 consumeNextArg = false;
79 continue;
80 }
81
82 if (arg.startsWith('-')) {
83 if (!arg.contains('=') && i + 1 < args.count())
84 consumeNextArg = true;
85 continue;
86 }
87
88 if (!text.isEmpty())
89 text += " ";
90 text += arg;
91 }
92
93 if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) {
94 text.clear();
95 }
96
97#if SINGLE_APP
98 if (app.isRunning()) {
99 app.sendMessage(text);
100 return 0;
101 }
102#endif
103
104 Q_INIT_RESOURCE(resources);
105 Q_INIT_RESOURCE(qmake_qmake_qm_files); // qmake names the file
106
107 QCoreApplication::setOrganizationName("IJHack");
108 QCoreApplication::setOrganizationDomain("ijhack.org");
109 QCoreApplication::setApplicationName("QtPass");
110 QCoreApplication::setApplicationVersion(VERSION);
111
112 // Setup and load translator for localization
113 QTranslator translator;
114 QString locale = QLocale::system().name();
115 // locale = "nl_NL";
116 // locale = "he_IL";
117 // locale = "ar_MA";
118 if (translator.load(
119 QString(":localization/localization_%1.qm").arg(locale))) {
120 SingleApplication::installTranslator(&translator);
121 SingleApplication::setLayoutDirection(
122 QObject::tr("LTR") == "RTL" ? Qt::RightToLeft : Qt::LeftToRight);
123 }
124
125 MainWindow w(text);
126
127 w.activateWindow();
128
129 QApplication::setWindowIcon(QIcon(":artwork/icon.png"));
130#ifndef Q_OS_OSX
131 SingleApplication::setWindowIcon(QIcon(":artwork/icon.png"));
132#endif
133
134#if SINGLE_APP
135 QObject::connect(&app, &SingleApplication::messageAvailable, &w,
137#endif
138
139 QGuiApplication::setDesktopFileName("qtpass.desktop");
140
141 // Center the MainWindow on the screen the mouse pointer is currently on
142#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
143 static int cursorScreen =
144 app.desktop()->screenNumber(app.desktop()->cursor().pos());
145 QPoint cursorScreenCenter =
146 app.desktop()->screenGeometry(cursorScreen).center();
147#else
148 QScreen *screen = QGuiApplication::screenAt(QCursor::pos());
149 if (!screen)
150 screen = QGuiApplication::primaryScreen();
151 QPoint cursorScreenCenter;
152 if (screen)
153 cursorScreenCenter = screen->geometry().center();
154#endif
155 QRect windowFrameGeo = w.frameGeometry();
156 windowFrameGeo.moveCenter(cursorScreenCenter);
157 w.move(windowFrameGeo.topLeft());
158
159 w.show();
160
161 return SingleApplication::exec();
162}
The MainWindow class does way too much, not only is it a switchboard, configuration handler and more,...
Definition mainwindow.h:39
void messageAvailable(const QString &message)
MainWindow::messageAvailable we have some text/message/search to do.
The SingleApplication class is used for commandline intergration.
auto isRunning() -> bool
SingleApplication::isRunning is there already a QtPass instance running, to check wether to be server...
auto sendMessage(const QString &message) -> bool
SingleApplication::sendMessage send a message (from commandline) to an already running QtPass instanc...
auto main(int argc, char *argv[]) -> int
main
Definition main.cpp:46