QtPass 1.4.0
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include "mainwindow.h"
2#if SINGLE_APP
3#include "singleapplication.h"
4#endif
5
6#include <QApplication>
7#include <QDir>
8#include <QTranslator>
9#include <QtWidgets>
10
43int main(int argc, char *argv[]) {
44#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
45 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
46 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
47#endif
48 QString text = "";
49 for (int i = 1; i < argc; ++i) {
50 if (i > 1)
51 text += " ";
52 text += argv[i];
53 }
54
55 if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) {
56 text.clear();
57 }
58
59#if SINGLE_APP
60 QString name = qgetenv("USER");
61 if (name.isEmpty())
62 name = qgetenv("USERNAME");
63 SingleApplication app(argc, argv, name + "QtPass");
64 if (app.isRunning()) {
65 if (text.length() > 0)
66 app.sendMessage(text);
67 return 0;
68 }
69#else
70 QApplication app(argc, argv);
71#endif
72
73 Q_INIT_RESOURCE(resources);
74 Q_INIT_RESOURCE(qmake_qmake_qm_files); // qmake names the file
75
76 QCoreApplication::setOrganizationName("IJHack");
77 QCoreApplication::setOrganizationDomain("ijhack.org");
78 QCoreApplication::setApplicationName("QtPass");
79 QCoreApplication::setApplicationVersion(VERSION);
80
81 // Setup and load translator for localization
82 QTranslator translator;
83 QString locale = QLocale::system().name();
84 // locale = "nl_NL";
85 // locale = "he_IL";
86 // locale = "ar_MA";
87 if (translator.load(
88 QString(":localization/localization_%1.qm").arg(locale))) {
89 SingleApplication::installTranslator(&translator);
90 SingleApplication::setLayoutDirection(
91 QObject::tr("LTR") == "RTL" ? Qt::RightToLeft : Qt::LeftToRight);
92 }
93
94 MainWindow w(text);
95
96 SingleApplication::setActiveWindow(&w);
97 SingleApplication::setWindowIcon(QIcon(":artwork/icon.png"));
98
99#if SINGLE_APP
100 QObject::connect(&app, &SingleApplication::messageAvailable, &w,
102#endif
103
104 QGuiApplication::setDesktopFileName("qtpass.desktop");
105
106 // Center the MainWindow on the screen the mouse pointer is currently on
107#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
108 static int cursorScreen =
109 app.desktop()->screenNumber(app.desktop()->cursor().pos());
110 QPoint cursorScreenCenter =
111 app.desktop()->screenGeometry(cursorScreen).center();
112#else
113 QScreen *screen = QGuiApplication::screenAt(QCursor::pos());
114 QPoint cursorScreenCenter = screen->geometry().center();
115#endif
116 QRect windowFrameGeo = w.frameGeometry();
117 windowFrameGeo.moveCenter(cursorScreenCenter);
118 w.move(windowFrameGeo.topLeft());
119
120 w.show();
121
122 return SingleApplication::exec();
123}
The MainWindow class does way too much, not only is it a switchboard, configuration handler and more,...
Definition: mainwindow.h:37
void messageAvailable(QString message)
MainWindow::messageAvailable we have some text/message/search to do.
Definition: mainwindow.cpp:736
The SingleApplication class is used for commandline intergration.
bool isRunning()
SingleApplication::isRunning is there already a QtPass instance running, to check wether to be server...
bool sendMessage(const QString &message)
SingleApplication::sendMessage send a message (from commandline) to an already running QtPass instanc...
void messageAvailable(QString message)
messageAvailable notification from commandline
int main(int argc, char *argv[])
main
Definition: main.cpp:43