Пример #1
0
int main(int argc, char * argv[])
{
	qInstallMessageHandler(MessageOutput);

    QApplication app(argc, argv);
	QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));

	QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
	//db.setDatabaseName(":memory:");
	db.setDatabaseName("calllog.db");
	db.open();

	QSqlQuery query;
	query.exec("create table CallLog(callnumber varchar(32), calltype varchar(16), starttime int, duration int, calllocation varchar(128), otherCallLocation varchar(32), callInLac varchar(32), callInCellid varchar(32))");

	WindowMain viewer;
	viewer.show();

	ObjectRegister::instance()->init();

    return app.exec();
}
Пример #2
0
int main(int argc, char *argv[])
{
  int retCode = -1;
  bool guiNeverShown = true;
  QString vboxDefaultMachineFolder;

  // Hide the console on windows if no args specified
  #ifdef PM_WINDOWS
    if (argc == 1)
      FreeConsole();
  #endif

  #ifndef PM_WINDOWS
    // On Linux, this is needed for console output and for reading INI-Files
    // TODO:check that!! QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  #endif

  // Initialize random seed (based on current time)
  pm_srand(0);

  QApplication app(argc, argv);
  app.setOrganizationName("PrivacyMachine");
  app.setApplicationName("PrivacyMachine");
  app.setApplicationVersion(constPrivacyMachineVersion);
  app.setOrganizationDomain("https://www.privacymachine.eu");
  // Get the path to the current running executable
  // (only works before we change the current path inside this application)
  QString pmInstallDirPath = app.applicationDirPath();

  // set InstallDirPath to be static inside the function getInstallDir
  // IMPORTANT: be shure this is the first call of getInstallDir
  getInstallDir(pmInstallDirPath);

  // Be save to run only one instance
  RunGuard guard( "PrivacyMachine is running   uniqe-key = 90hQlQsd1Gp+sPeD+ANdUGymXxUtdLwgoxsdjDqK7Q1zZ2hYQBnQBw" );
  if ( !guard.tryToRun() )
  {
    qDebug() <<  "An other instance of the PrivacyMachine is already running";
    QMessageBox abortMsg(QMessageBox::Information, QApplication::applicationName()+" "+QApplication::applicationVersion(),
                         "The PrivacyMachine is already running!");
    abortMsg.setWindowIcon(QIcon(":/resources/privacymachine.svg"));
    return abortMsg.exec();
  }

  if (!rotateLogfiles())
    return false; // error message already logged to the console


  // Enable Warning messages triggered by qDebug(), qWarning(), qCritical(), qFatal()
  qInstallMessageHandler(logMessages);


  // We want the same look&feel on all Platforms
  //app.setStyle(QStyleFactory::create("windows"));


  QString startTime = currentTimeStampAsISO();
  ILOG("Starting up at " + startTime + " Version:" + constPrivacyMachineVersion);

#ifdef WIN32
    WSADATA wsaData;
    int err;
    err = WSAStartup(0x101, &wsaData);
    if (err != 0)
    {
        IERR("WSAStartup failed with error: " + QString::number(err));
        return -1;
    }
#endif

  try // catching exceptions
  {  
    // init the translation of qt internal messages
    QTranslator qtTranslator;
    qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);

    // init the translation of PrivacyMachine messages
    QTranslator pmTranslator;
    // TODO: read from PrivacyMachine.ini
    QString currentLanguage = "lang_" + QLocale::system().name();
    // TODO: Bernhard: hardcode to english because german tranlation is incomplete
    currentLanguage = "lang_de_DE";
    pmTranslator.load(currentLanguage);
    app.installTranslator(&pmTranslator);

    QCoreApplication::setApplicationName(QCoreApplication::translate("mainfunc", "PrivacyMachine"));
    QCoreApplication::setApplicationVersion(constPrivacyMachineVersion);

    QCommandLineParser parser;
    parser.setApplicationDescription(QCoreApplication::translate("mainfunc", "This executeable launches the PrivacyMachine, a browser who protects your Privacy"));
    parser.addHelpOption();
    parser.addVersionOption();
    parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);

    QCommandLineOption optionLogSensitiveData("logsensitive", QCoreApplication::translate("mainfunc", "Enable logging of sensible data, i.e. passwords"));
    parser.addOption(optionLogSensitiveData);
    parser.process(app);

    // set the global variable to enable logging of sensitive data via ILOG_SENSITIVE
    globalSensitiveLoggingEnabed = parser.isSet(optionLogSensitiveData);

    // Check if all is installed what will be needed to run the PrivacyMachine
    if (!checkSystemInstallation(vboxDefaultMachineFolder))
    {
      guiNeverShown = false;
      return -1; // error messages to User are already presented
    }

    WindowMain mainWindow;
    if (mainWindow.init(pmInstallDirPath, vboxDefaultMachineFolder))
    {
      mainWindow.show();
      guiNeverShown = false;
      retCode = app.exec();
    }
    else
    {
      retCode = -1;
    }
  }
  catch (std::exception& e)
  {
    IERR("exception occoured: " + QString::fromStdString(e.what()));
    retCode = -1;
  }

  if (guiNeverShown && retCode != 0)
  {
    QString message = QCoreApplication::translate("mainfunc", "Some errors occoured: Please check the logfile for Details.");
    QMessageBox::warning(Q_NULLPTR, "PrivacyMachine", message);
  }

  QString stopTime = currentTimeStampAsISO();
  ILOG("shutting down at " + stopTime);
  return retCode;
}