QtPass  1.2.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 <QTranslator>
8 
41 int main(int argc, char *argv[]) {
42 #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
43  QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
44 #endif
45  QString text = "";
46  for (int i = 1; i < argc; ++i) {
47  if (i > 1)
48  text += " ";
49  text += argv[i];
50  }
51 
52  if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) {
53  text.clear();
54  }
55 
56 #if SINGLE_APP
57  QString name = qgetenv("USER");
58  if (name.isEmpty())
59  name = qgetenv("USERNAME");
60  SingleApplication app(argc, argv, name + "QtPass");
61  if (app.isRunning()) {
62  if (text.length() > 0)
63  app.sendMessage(text);
64  return 0;
65  }
66 #else
67  QApplication app(argc, argv);
68 #endif
69 
70  QCoreApplication::setOrganizationName("IJHack");
71  QCoreApplication::setOrganizationDomain("ijhack.org");
72  QCoreApplication::setApplicationName("QtPass");
73  QCoreApplication::setApplicationVersion(VERSION);
74 
75  // Setup and load translator for localization
76  QTranslator translator;
77  QString locale = QLocale::system().name();
78  // locale = "nl_NL";
79  // locale = "he_IL";
80  // locale = "ar_MA";
81  translator.load(QString(":localization/localization_%1.qm").arg(locale));
82  app.installTranslator(&translator);
83  app.setLayoutDirection(QObject::tr("LTR") == "RTL" ? Qt::RightToLeft
84  : Qt::LeftToRight);
85  MainWindow w(text);
86 
87  app.setActiveWindow(&w);
88  app.setWindowIcon(QIcon(":artwork/icon.png"));
89 
90 #if SINGLE_APP
91  QObject::connect(&app, &SingleApplication::messageAvailable, &w,
93 #endif
94 
95  w.show();
96 
97  return app.exec();
98 }
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
void messageAvailable(QString message)
MainWindow::messageAvailable we have some text/message/search to do.
Definition: mainwindow.cpp:709
The SingleApplication class is used for commandline intergration.
The MainWindow class does way too much, not only is it a switchboard, configuration handler and more...
Definition: mainwindow.h:39
int main(int argc, char *argv[])
main
Definition: main.cpp:41