QtPass  1.2.1
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  qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
43  QString text = "";
44  for (int i = 1; i < argc; ++i) {
45  if (i > 1)
46  text += " ";
47  text += argv[i];
48  }
49 
50  if ((text.indexOf("-psn_") == 0) || (text.indexOf("-session") == 0)) {
51  text.clear();
52  }
53 
54 #if SINGLE_APP
55  QString name = qgetenv("USER");
56  if (name.isEmpty())
57  name = qgetenv("USERNAME");
58  SingleApplication app(argc, argv, name + "QtPass");
59  if (app.isRunning()) {
60  if (text.length() > 0)
61  app.sendMessage(text);
62  return 0;
63  }
64 #else
65  QApplication app(argc, argv);
66 #endif
67 
68  QCoreApplication::setOrganizationName("IJHack");
69  QCoreApplication::setOrganizationDomain("ijhack.org");
70  QCoreApplication::setApplicationName("QtPass");
71  QCoreApplication::setApplicationVersion(VERSION);
72 
73  // Setup and load translator for localization
74  QTranslator translator;
75  QString locale = QLocale::system().name();
76  // locale = "nl_NL";
77  // locale = "he_IL";
78  // locale = "ar_MA";
79  translator.load(QString(":localization/localization_%1.qm").arg(locale));
80  app.installTranslator(&translator);
81  app.setLayoutDirection(QObject::tr("LTR") == "RTL" ? Qt::RightToLeft
82  : Qt::LeftToRight);
83  MainWindow w;
84 
85  QObject::connect(&app, SIGNAL(aboutToQuit()), &w, SLOT(clearClipboard()));
86 
87  app.setActiveWindow(&w);
88  app.setWindowIcon(QIcon(":artwork/icon.png"));
89  w.setApp(&app);
90  w.setText(text);
91  w.show();
92 
93  return app.exec();
94 }
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:38
int main(int argc, char *argv[])
main
Definition: main.cpp:41