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 
42 int main(int argc, char *argv[]) {
43 #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
44  QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
45 #endif
46  QString text = "";
47  for (int i = 1; i < argc; ++i) {
48  if (i > 1)
49  text += " ";
50  text += argv[i];
51  }
52 
53  if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) {
54  text.clear();
55  }
56 
57 #if SINGLE_APP
58  QString name = qgetenv("USER");
59  if (name.isEmpty())
60  name = qgetenv("USERNAME");
61  SingleApplication app(argc, argv, name + "QtPass");
62  if (app.isRunning()) {
63  if (text.length() > 0)
64  app.sendMessage(text);
65  return 0;
66  }
67 #else
68  QApplication app(argc, argv);
69 #endif
70 
71  Q_INIT_RESOURCE(resources);
72  Q_INIT_RESOURCE(qmake_qmake_qm_files); // qmake names the file
73 
74  QCoreApplication::setOrganizationName("IJHack");
75  QCoreApplication::setOrganizationDomain("ijhack.org");
76  QCoreApplication::setApplicationName("QtPass");
77  QCoreApplication::setApplicationVersion(VERSION);
78 
79  // Setup and load translator for localization
80  QTranslator translator;
81  QString locale = QLocale::system().name();
82  // locale = "nl_NL";
83  // locale = "he_IL";
84  // locale = "ar_MA";
85  translator.load(QString(":localization/localization_%1.qm").arg(locale));
86  SingleApplication::installTranslator(&translator);
87  SingleApplication::setLayoutDirection(
88  QObject::tr("LTR") == "RTL" ? Qt::RightToLeft : Qt::LeftToRight);
89  MainWindow w(text);
90 
91  SingleApplication::setActiveWindow(&w);
92  SingleApplication::setWindowIcon(QIcon(":artwork/icon.png"));
93 
94 #if SINGLE_APP
95  QObject::connect(&app, &SingleApplication::messageAvailable, &w,
97 #endif
98 
99 #if (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0))
100  QGuiApplication::setDesktopFileName("qtpass.desktop");
101 #endif
102 
103  w.show();
104 
105  return SingleApplication::exec();
106 }
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:713
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:42