QtPass  1.2.0
Multi-platform GUI for pass, the standard unix password manager.
main.cpp
Go to the documentation of this file.
1 #include "mainwindow.h"
2 #include <QApplication>
3 #include <QTranslator>
4 
37 int main(int argc, char *argv[]) {
38  qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
39  QString text = "";
40  for (int i = 1; i < argc; ++i) {
41  if (i > 1)
42  text += " ";
43  text += argv[i];
44  }
45 
46  if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) {
47  text.clear();
48  }
49 
50 #if SINGLE_APP
51  QString name = qgetenv("USER");
52  if (name.isEmpty())
53  name = qgetenv("USERNAME");
54  SingleApplication app(argc, argv, name + "QtPass");
55  if (app.isRunning()) {
56  if (text.length() > 0)
57  app.sendMessage(text);
58  return 0;
59  }
60 #else
61  QApplication app(argc, argv);
62 #endif
63 
64  QCoreApplication::setOrganizationName("IJHack");
65  QCoreApplication::setOrganizationDomain("ijhack.org");
66  QCoreApplication::setApplicationName("QtPass");
67  QCoreApplication::setApplicationVersion(VERSION);
68 
69  // Setup and load translator for localization
70  QTranslator translator;
71  QString locale = QLocale::system().name();
72  // locale = "nl_NL";
73  // locale = "he_IL";
74  // locale = "ar_MA";
75  translator.load(QString(":localization/localization_") + locale +
76  QString(".qm"));
77  app.installTranslator(&translator);
78  app.setLayoutDirection(QObject::tr("LTR") == "RTL" ? Qt::RightToLeft
79  : Qt::LeftToRight);
80  MainWindow w;
81 
82  QObject::connect(&app, SIGNAL(aboutToQuit()), &w, SLOT(clearClipboard()));
83 
84  app.setActiveWindow(&w);
85  app.setWindowIcon(QIcon(":artwork/icon.png"));
86  w.setApp(&app);
87  w.setText(text);
88  w.show();
89 
90  return app.exec();
91 }
void setText(QString)
MainWindow::setText do a search from an external source (eg: commandline)
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 setApp(SingleApplication *app)
MainWindow::setApp make sure we know what/who/where we are.
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:42
int main(int argc, char *argv[])
main
Definition: main.cpp:37