Пример #1
0
QString clientHandler::getTmpRandomFileName()
{
    //get new primary is pseudo generate algo for creating DB primary
    //key based DDMMYYHHMMSS. This is to replace DB default auto increment
    //that will lead inconsistantcy during data update, append, migration
    //and rollback
    QDateTime now;
    QString utc;
    quint64 primaryKey = 0;

    utc = now.currentDateTimeUtc().toString();
    utc.remove(QRegExp("[^0-9]"));
    primaryKey = utc.toLongLong() + now.currentMSecsSinceEpoch();

    return QString::number(primaryKey);
}
Пример #2
0
bool SortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
    if (filterRole() == "fromNow" && sourceModel()->roleNames().values().contains("start")) {
        QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
        QDateTime date = sourceModel()->data(index, sourceModel()->roleNames().key("start")).toDateTime();
        QDateTime currentDateTime = QDateTime::currentDateTime();
        int localTimeZoneOffset = currentDateTime.offsetFromUtc();
        currentDateTime.setMSecsSinceEpoch(currentDateTime.currentMSecsSinceEpoch() + localTimeZoneOffset*1000);
        return date >= currentDateTime;
    } else {
        if (m_hide && sourceModel()->roleNames().values().contains("hideInSchedule")) {
            QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
            bool willBeHidden = sourceModel()->data(index, sourceModel()->roleNames().key("hideInSchedule")).toBool();
            if (willBeHidden)
                return false;
        }
        return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
    }
}
Пример #3
0
int main (int argc, char* argv[])
{
    // Q_INIT_RESOURCE(stylesheet);

    csApplet = new CryptostickApplet;

    int i;

    char* p;

    StartUpParameter_tst StartupInfo_st;

    QApplication a (argc, argv);

    // initialize i18n
    QTranslator qtTranslator;
#if defined(Q_WS_WIN)
    qtTranslator.load("qt_" + QLocale::system().name());                                                                                                                                                                                                               
#else
    qtTranslator.load("qt_" + QLocale::system().name(),
                      QLibraryInfo::location(QLibraryInfo::TranslationsPath));                                                                                                                                                                                         
#endif
    a.installTranslator(&qtTranslator);                                                                                                                                                                                                                              

    QTranslator myappTranslator;
#if QT_VERSION >= 0x040800 && !defined(Q_WS_MAC) 
    QLocale loc = QLocale::system();
    QString lang = QLocale::languageToString(loc.language());                                                                                                                                                                                                          

    if (lang != "en") {
        bool success;
        success = myappTranslator.load(QLocale::system(), // locale   
                                       "",                // file name
                                       "nitrokey_",        // prefix   
                                       ":/i18n/",         // folder   
                                       ".qm");            // suffix                                                                                                                                                                                                    

        if (!success) {
            myappTranslator.load(QString(":/i18n/nitrokey_%1.qm").arg(QLocale::system().name()));                                                                                                                                                                       
        }
    }
#else
    myappTranslator.load(QString(":/i18n/nitrokey_%1.qm").arg(QLocale::system().name()));                                                                                                                                                                               
#endif

    a.installTranslator(&myappTranslator);     

    // Check for multiple instances
    // GUID from http://www.guidgenerator.com/online-guid-generator.aspx
    /*
       QSharedMemory shared("6b50960df-f5f3-4562-bbdc-84c3bc004ef4");

       if( !shared.create( 512, QSharedMemory::ReadWrite) ) { // An instance is already running. Quit the current instance QMessageBox msgBox;
       msgBox.setText( QObject::tr("Can't start more than one instance of the application.") ); msgBox.setIcon( QMessageBox::Critical );
       msgBox.exec(); exit(0); } else { */
    qDebug () << "Application started successfully.";
    // }

    /*
       SplashScreen *splash = 0; splash = new SplashScreen; splash->show();

       QFile qss( ":/qss/default.qss" ); if( ! qss.open( QIODevice::ReadOnly ) ) { qss.setFileName( ":/qss/default.qss" ); qss.open(
       QIODevice::ReadOnly ); }

       if( qss.isOpen() ) { a.setStyleSheet( qss.readAll() ); }

       QTimer::singleShot(3000,splash,SLOT(deleteLater())); */

    StartupInfo_st.ExtendedConfigActive = FALSE;
    StartupInfo_st.FlagDebug = DEBUG_STATUS_NO_DEBUGGING;
    StartupInfo_st.PasswordMatrix = FALSE;
    StartupInfo_st.LockHardware = FALSE;
    StartupInfo_st.Cmd = FALSE;

    HID_Stick20Init ();

    // Check for commandline parameter
    for (i = 2; i <= argc; i++)
    {
        p = argv[i - 1];
        if ((0 == strcmp (p, "--help")) || (0 == strcmp (p, "-h")))
        {
            HelpInfos ();
            exit (0);
        }

        if ((0 == strcmp (p, "--debug")) || (0 == strcmp (p, "-d")))
        {
            StartupInfo_st.FlagDebug = DEBUG_STATUS_LOCAL_DEBUG;
        }
        if (0 == strcmp (p, "--debugAll"))
        {
            StartupInfo_st.FlagDebug = DEBUG_STATUS_DEBUG_ALL;
        }
        if ((0 == strcmp (p, "--admin")) || (0 == strcmp (p, "-a")))
        {
            StartupInfo_st.ExtendedConfigActive = TRUE;
        }
        /* Disable password matrix if (0 == strcmp (p,"--PWM")) { StartupInfo_st.PasswordMatrix = TRUE; } */
        if (0 == strcmp (p, "--lock-hardware"))
            StartupInfo_st.LockHardware = TRUE;

        if (0 == strcmp (p, "--cmd"))
        {
            StartupInfo_st.Cmd = TRUE;
            i++;
            if (i > argc)
            {
                fprintf (stderr, "ERROR: Can't get command\n");
                fflush (stderr);
                exit (1);
            }
            else
            {
                p = argv[i - 1];
                StartupInfo_st.CmdLine = p;
            }
        }
    }

    MainWindow w (&StartupInfo_st);

    QDateTime local (QDateTime::currentDateTime ());

    qsrand (local.currentMSecsSinceEpoch () % 2000000000);

    a.setQuitOnLastWindowClosed (false);
    return a.exec ();
}