Ejemplo n.º 1
0
Settings::Settings(QWidget *parent) : Dialog(parent),
_passcodeSwitch(""),
_passCodePage(parent),
_changePassCodePage(parent),
_langPage(parent)
{
	_mainLayout.setContentsMargins(24, 24, 24, 24);
	setLayout(&_mainLayout);
	initGeneral();
	initSecurity();
	initDataBase();

	_mainLayout.insertSpacing(2, 24);
	_mainLayout.insertSpacing(5, 24);
	_mainLayout.insertSpacing(8, 24);
	setMinimumWidth(400);
	_passCodePage.hide();
	_changePassCodePage.hide();
	_langPage.hide();
	QSettings setting("MyOrg", "MyApp");
	_passcodeSwitch.setChecked(setting.value("authentication/hasPasscode").toBool());
	_langLabel.setText(Tr(setting.value("Language").toString()));
	QObject::connect(&_passcodeSwitch, SIGNAL(toggled(bool)), this, SLOT(onSwitch(bool)));
	QObject::connect(&_passCodePage, SIGNAL(cancel()), this, SLOT(onPassCodeCancel()));
	QObject::connect(&_changePassCodePage, SIGNAL(cancel()), this, SLOT(onPassCodeCancel()));
	QObject::connect(&_passCodePage, SIGNAL(save(QByteArray)), this, SLOT(onPassCodeSave(QByteArray)));
	QObject::connect(&_changePassCodePage, SIGNAL(save(QByteArray)), this, SLOT(onPassCodeSave(QByteArray)));
	QObject::connect(&_langItem, SIGNAL(clicked()), this, SLOT(onLanguage()));
	QObject::connect(&_langPage, SIGNAL(ok()), this, SLOT(onLanguageOk()));
	QObject::connect(&_langPage, SIGNAL(restart(QString)), this, SLOT(onLanguageRestart(QString)));
	QObject::connect(&_passCodeItem, SIGNAL(clicked()), this, SLOT(onChangePassCode()));
}
Ejemplo n.º 2
0
Archivo: cpm.c Proyecto: atluxity/cpm
/* if don't have any envorin variable at all */
int main(int argc, char **argv, char **envp)
#endif
#endif
  {
    rlim_t              memlock_limit = -2;
    int                 error = 0,
                        max_mem_lock = 0,
                        memory_safe = 0,
                        ptrace_safe = 0;
#ifdef TEST_OPTION
    int                 testrun = 0;
#endif
    char*               binaryname;

    savetermios();
    TRACE(99, "main()", NULL);

#ifndef HAVE_EXTERN_ENVIRON
#ifndef MANUAL_EXTERN_ENVIRON
    /* since in solaris environ does not exist, we manually pass it along */
    environ = envp;
#endif
#endif

    if (initSecurity(&max_mem_lock, &memory_safe, &ptrace_safe, &memlock_limit))
      { exit(1); }

    /* we initialize gettext */
    setlocale(LC_ALL, "");
#ifdef TEST_OPTION
    bindtextdomain(PACKAGE_NAME, "./po/");
#else
    bindtextdomain(PACKAGE_NAME, LOCALEDIR);
#endif
    textdomain(PACKAGE_NAME);

#ifndef LIBXML_TREE_ENABLED
    fprintf(stderr, _("Tree support not compiled in to libxml2 %s\n"),
        LIBXML_DOTTED_VERSION);
    exit(1);
#endif

    /*
     * This function installs "sighandler" to handle the SIGINT and returns a
     * pointer to the previously installed handler for this signal (which is
     * the default handler SIG_DFL initially). If we try to install another
     * handler to handle SIGINT at some other time... Then the new handler
     * replaces this current one and returns a pointer to this handler.
     */
    signal(SIGINT, sighandler);
    signal(SIGTERM, sighandler);
    /* the SIGWINCH handler is set in userInterface() */

    initConfiguration();

    runtime -> memlock_limit  = memlock_limit;
    runtime -> max_mem_lock   = max_mem_lock;
    runtime -> memory_safe    = memory_safe;
    runtime -> ptrace_safe    = ptrace_safe;

    initKeys();
    initPatternparser();
    initXML();
    initXMLInterface();

    if (getOptions(argc, argv))
      {
        fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]);
        error = 1;
      }
    if (!error && config -> help)
      { showHelp(); }
    else if (!error && config -> version)
      { showVersion(); }
    else if (!error)
      {
        getDefaultOptions();
        if (readResources())
            return 1;

        if (config -> dbfilecmd)
          {   /* the --file option must overwrite the resource file */
            runtime -> dbfile = resolveFilelink(config -> dbfilecmd);
          }
        else
          {   /* we use the resource file configuration or the compiletime
               * default
               */
            runtime -> dbfile = resolveFilelink(config -> dbfilerc);
          }
      }

    /* we switch to read-only mode on request */
    if (config -> readonly)
      { runtime -> readonly = 1; }

    /* in case our basename is cpmv, we switch to read-only mode */
    binaryname = basename(argv[0]);
    if (!strcmp(binaryname, "cpmv"))
      { runtime -> readonly = 1; }

    initGPG();

    if (!error && config -> security)
      { checkSecurity(0); }

#ifdef TEST_OPTION
    if (!error &&
        config -> testrun &&
        !strncmp(config -> testrun, "compress", 8))
      {
        testCompress();
        testrun = 1;
      }
    if (!error &&
        config -> testrun &&
        !strcmp(config -> testrun, "environment"))
      {
        testEnvironment();
        testrun = 1;
      }
    if (!error &&
        config -> testrun && (
        !strcmp(config -> testrun, "backup") ||
        !strcmp(config -> testrun, "garbage") ||
        !strcmp(config -> testrun, "searchpattern")))
      { testrun = 1; }
#endif

    if (config -> configtest &&
        !error)
      { fprintf(stderr, _("configuration ok.\n")); }

    if (config -> environtmentlist &&
        !error)
      { listEnvironment(); }

    if (!error &&
        !config -> configtest &&
        !config -> environtmentlist &&
        !config -> help &&
        !config -> security &&
        !config -> version)
      {
#ifdef TEST_OPTION
        if (checkSecurity(1) != MAX_SECURITY_LEVEL &&
            !config -> testrun)
#else
        if (checkSecurity(1) != MAX_SECURITY_LEVEL)
#endif
          {
            checkSecurity(0);
            printf("\n%s %s\n%s\n",
                _("Maximum security level not reached."),
                _("Your database will be less protected while CPM is running."),
                _("Are you sure you want to continue?"),
                _("Press CTRL+C to stop now or ENTER to continue."));

            fgetc(stdin);
          }
        if (runtime -> guimode)
          {   /* we run in interactive mode */
            userInterface();
          }
        else
          {   /* we run in CLI mode */
            error = cliInterface();
#ifdef TEST_OPTION
            if (error == 2)
              {   /* for testruns, we must modify the stuff a little */
                error = 0;
                testrun = 1;
              }
#endif
          }
      }

    freeGPG();
    freeXMLInterface();
    freeUTF8Interface();
    freeXML();
    freePatternparser();
    freeKeys();
    freeConfiguration();

    if (memCheck())
      {   /* we validate our memory consumption */
        fprintf(stderr, _("error: memory leak detected.\n"));
        if (memCheck() > 0)
          {
            fprintf(stderr, _("%ld byte of memory were not freed.\n"),
                memCheck());
          }
        else
          {
            fprintf(stderr,
                _("%ld byte of memory were freed without being allocated.\n"),
                memCheck());
          }

        fprintf(stderr, _("Please send a report about this problem to Harry Brueckner <*****@*****.**>.\n"));

        error = 1;
      }

#ifdef TEST_OPTION
    if (testrun)
      { return 0; }
    else
      { return error; }
#else
    return error;
#endif
  }
Ejemplo n.º 3
0
/**
 * @brief appInit
 *  应用初始化例程
 * @return(要对出错代码按不同的模块或例程进行规划,预留一定区间的代码给指定例程或模块)
 *  0:正常退出
 *  1:升级配置模块时出错
 *  2:用户取消了配置模块的升级 *
 *  3:基础库连接错误
 *  4:
 *  5:
 *  6:安全模块初始化错误
 *  7:全局变量初始化错误
 *  8:读取凭证类型出错
 */
int appInit()
{
    //初始化路径信息
    DatabasePath = QDir::toNativeSeparators(QDir::currentPath().append("/datas/databases/"));
    BaseDataPath = QDir::toNativeSeparators(QDir::currentPath().append("/datas/basicdatas/"));
    BackupPath = QDir::toNativeSeparators(QDir::currentPath().append("/datas/backups/"));
    VersionManager vm(VersionManager::MT_CONF);
    VersionUpgradeInspectResult result = vm.isMustUpgrade();
    bool exec = false;
    switch(result){
    case VUIR_CANT:
        return 1;
    case VUIR_DONT:
        exec = false;
        break;
    case VUIR_LOW:
        return 1;
    case VUIR_MUST:
        exec = true;
        break;
    }
    if(exec){
        if(vm.exec() == QDialog::Rejected){
            return 2;
        }
        else if(!vm.getUpgradeResult())
            return 1;
    }

    AppConfig* appCfg = AppConfig::getInstance();
    if(!appCfg)
        return 3;

    //设置应用程序的版本号
    int master = 0;
    int second = 98;
    aboutStr = qApp->tr("凭证助手,版权属于小灵猫工作室所有。\n版本号:%1.%2").arg(master).arg(second);



    //获取可用屏幕尺寸
    QDesktopWidget desktop;
    screenWidth = desktop.availableGeometry().width();
    screenHeight = desktop.availableGeometry().height();

    bdb = appCfg->getBaseDbConnect();
    initSecurity();    
    appCfg->initGlobalVar();

    appCfg->readPzSetStates(pzsStates,pzsStateDescs);
    appCfg->readPingzhenClass(pzClasses);
    appCfg->readPzStates(pzStates);

    //初始化凭证状态名表
    QSqlQuery q(bdb);
    bool r;

    pzClsImps.insert(Pzc_GdzcZj);
    pzClsImps.insert(Pzc_DtfyTx);

    pzClsJzhds.insert(Pzc_Jzhd_Bank);
    pzClsJzhds.insert(Pzc_Jzhd_Ys);
    pzClsJzhds.insert(Pzc_Jzhd_Yf);
    pzClsJzhds.insert(Pzc_Jzhd_Yuf );
    pzClsJzhds.insert(Pzc_Jzhd_Yus);
    pzClsJzhds.insert(Pzc_Jzhd);

    pzClsJzsys.insert(Pzc_JzsyIn);
    pzClsJzsys.insert(Pzc_JzsyFei);

    //初始化币种表
    r = q.exec("select code,name from MoneyTypes");
    while(q.next())
        MTS[q.value(0).toInt()] = q.value(1).toString();

    //初始化固定资产产品类别表
    r = q.exec("select code,name,zjMonths from gdzc_classes");
    while(q.next()){
        int code = q.value(0).toInt();
        int zjMonths = q.value(2).toInt();
        QString name = q.value(1).toString();
        allGdzcProductCls[code] = new GdzcType(code,name,zjMonths);
    }
    return 0;
}