QtPass  1.3.3
Multi-platform GUI for pass, the standard unix password manager.
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 
43 int main(int argc, char *argv[]) {
44 #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) && 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(QString(":localization/localization_%1.qm").arg(locale))) {
88  SingleApplication::installTranslator(&translator);
89  SingleApplication::setLayoutDirection(
90  QObject::tr("LTR") == "RTL" ? Qt::RightToLeft : Qt::LeftToRight);
91  }
92 
93  MainWindow w(text);
94 
95  SingleApplication::setActiveWindow(&w);
96  SingleApplication::setWindowIcon(QIcon(":artwork/icon.png"));
97 
98 #if SINGLE_APP
99  QObject::connect(&app, &SingleApplication::messageAvailable, &w,
101 #endif
102 
103 #if (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0))
104  QGuiApplication::setDesktopFileName("qtpass.desktop");
105 #endif
106 
107  //Center the MainWindow on the screen the mouse pointer is currently on
108 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
109  static int cursorScreen = app.desktop()->screenNumber(app.desktop()->cursor().pos());
110  QPoint cursorScreenCenter = app.desktop()->screenGeometry(cursorScreen).center();
111 #else
112  QScreen *screen = QGuiApplication::screenAt(QCursor::pos());
113  QPoint cursorScreenCenter = screen->geometry().center();
114 #endif
115  QRect windowFrameGeo = w.frameGeometry();
116  windowFrameGeo.moveCenter(cursorScreenCenter);
117  w.move(windowFrameGeo.topLeft());
118 
119  w.show();
120 
121  return SingleApplication::exec();
122 }
SingleApplication
The SingleApplication class is used for commandline intergration.
Definition: singleapplication.h:14
SingleApplication::sendMessage
bool sendMessage(const QString &message)
SingleApplication::sendMessage send a message (from commandline) to an already running QtPass instanc...
Definition: singleapplication.cpp:72
SingleApplication::messageAvailable
void messageAvailable(QString message)
messageAvailable notification from commandline
SingleApplication::isRunning
bool isRunning()
SingleApplication::isRunning is there already a QtPass instance running, to check wether to be server...
Definition: singleapplication.cpp:64
MainWindow::messageAvailable
void messageAvailable(QString message)
MainWindow::messageAvailable we have some text/message/search to do.
Definition: mainwindow.cpp:714
singleapplication.h
MainWindow
The MainWindow class does way too much, not only is it a switchboard, configuration handler and more,...
Definition: mainwindow.h:39
mainwindow.h
main
int main(int argc, char *argv[])
main
Definition: main.cpp:43