Beispiel #1
0
int main( int argc, char *argv[] )
{
    QApplication app(argc, argv);

    QStringList arguments (QApplication::arguments());
    arguments.pop_front(); // application path

    // Pass files to existing instance and quit

    SingleInstanceGuard guard;
    if (guard.tryConnect(arguments))
        return 0;

    // Set up translations

    QTranslator qtTranslator;
    qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);

    QTranslator scideTranslator;
    scideTranslator.load("scide_" + QLocale::system().name());
    app.installTranslator(&scideTranslator);

    // Set up style

    app.setStyle( new ScIDE::Style(app.style()) );

    // Go...

    Main * main = Main::instance();

    MainWindow *win = new MainWindow(main);

    // NOTE: load session after GUI is created, so that GUI can respond
    Settings::Manager *settings = main->settings();
    SessionManager *sessions = main->sessionManager();

    QString startSessionName = settings->value("IDE/startWithSession").toString();
    if (startSessionName == "last") {
        QString lastSession = sessions->lastSession();
        if (!lastSession.isEmpty()) {
            sessions->openSession(lastSession);
        }
    }
    else if (!startSessionName.isEmpty()) {
        sessions->openSession(startSessionName);
    }

    if (!sessions->currentSession()) {
        win->restoreWindowState();
        sessions->newSession();
    }

    win->show();

    foreach (QString argument, arguments) {
        main->documentManager()->open(argument);
    }
Beispiel #2
0
int main( int argc, char *argv[] )
{
    QApplication app(argc, argv);

    QStringList arguments (QApplication::arguments());
    arguments.pop_front(); // application path

    // Pass files to existing instance and quit

    SingleInstanceGuard guard;
    if (guard.tryConnect(arguments))
        return 0;

    // Set up translations

    QTranslator qtTranslator;
    qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);

    char resourcePath[PATH_MAX];
    sc_GetResourceDirectory(resourcePath, PATH_MAX);
    QString ideTranslationPath = QString(resourcePath) + "/translations";

    bool translationLoaded;

    // Load fallback translator that only handles plural forms in English
    QTranslator fallbackTranslator;
    translationLoaded = fallbackTranslator.load( "scide", ideTranslationPath );
    app.installTranslator(&fallbackTranslator);
    if (!translationLoaded)
        qWarning("scide warning: Failed to load fallback translation file.");

    // Load translator for locale
    QString ideTranslationFile = "scide_" + QLocale::system().name();
    QTranslator scideTranslator;
    scideTranslator.load( ideTranslationFile, ideTranslationPath );
    app.installTranslator(&scideTranslator);

    // Set up style

    app.setStyle( new ScIDE::Style(app.style()) );

    // Go...

    Main * main = Main::instance();

    MainWindow *win = new MainWindow(main);

    // NOTE: load session after GUI is created, so that GUI can respond
    Settings::Manager *settings = main->settings();
    SessionManager *sessions = main->sessionManager();

    // NOTE: window has to be shown before restoring its geometry,
    // or else restoring maximized state will fail, if it has ever before
    // been saved un-maximized.
    win->show();

    QString startSessionName = settings->value("IDE/startWithSession").toString();
    if (startSessionName == "last") {
        QString lastSession = sessions->lastSession();
        if (!lastSession.isEmpty()) {
            sessions->openSession(lastSession);
        }
    }
    else if (!startSessionName.isEmpty()) {
        sessions->openSession(startSessionName);
    }

    if (!sessions->currentSession()) {
        win->restoreWindowState();
        sessions->newSession();
    }

    foreach (QString argument, arguments) {
        main->documentManager()->open(argument);
    }
void SessionManagerTests::testOpenClose()
{
	// Create an empty object store
#ifndef _WIN32
	ObjectStore store("./testdir");
#else
	ObjectStore store(".\\testdir");
#endif

	// Create the managers
	SlotManager slotManager(&store);
	SessionManager sessionManager;

	// Get a slot
	CK_SLOT_ID slotID = 0;
	Slot* slot = slotManager.getSlot(slotID);

	// Use some bad data
	CK_SESSION_HANDLE hSession;
	CK_RV rv = sessionManager.openSession(NULL, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_SLOT_ID_INVALID);
	rv = sessionManager.openSession(slot, 0, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_SESSION_PARALLEL_NOT_SUPPORTED);
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, NULL_PTR);
	CPPUNIT_ASSERT(rv == CKR_ARGUMENTS_BAD);

	// Try open a slot with an uninitialized token
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_TOKEN_NOT_RECOGNIZED);

	// Initialize the token
	ByteString soPIN((unsigned char*)"1234", 4);
	CK_UTF8CHAR label[33] = "My test token                   ";
	CPPUNIT_ASSERT(slot->initToken(soPIN, label) == CKR_OK);

	// Open a session
	bool haveSession = sessionManager.haveSession(slotID);
	CPPUNIT_ASSERT(haveSession == false);
	bool haveROSession = sessionManager.haveROSession(slotID);
	CPPUNIT_ASSERT(haveROSession == false);
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
	haveSession = sessionManager.haveSession(slotID);
	CPPUNIT_ASSERT(haveSession == true);
	haveROSession = sessionManager.haveROSession(slotID);
	CPPUNIT_ASSERT(haveROSession == true);

	// Close session
	rv = sessionManager.closeSession(CK_INVALID_HANDLE);
	CPPUNIT_ASSERT(rv == CKR_SESSION_HANDLE_INVALID);
	rv = sessionManager.closeSession(hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.closeSession(hSession);
	CPPUNIT_ASSERT(rv == CKR_SESSION_HANDLE_INVALID);
	haveSession = sessionManager.haveSession(slotID);
	CPPUNIT_ASSERT(haveSession == false);
	haveROSession = sessionManager.haveROSession(slotID);
	CPPUNIT_ASSERT(haveROSession == false);

	// Try open a Read-Only session when in SO mode
	rv = slot->getToken()->loginSO(soPIN);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_SESSION_READ_WRITE_SO_EXISTS);
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
	haveSession = sessionManager.haveSession(slotID);
	CPPUNIT_ASSERT(haveSession == true);
	haveROSession = sessionManager.haveROSession(slotID);
	CPPUNIT_ASSERT(haveROSession == false);

	// Close session and check that we are logged out
	bool isLoggedIn = slot->getToken()->isSOLoggedIn();
	CPPUNIT_ASSERT(isLoggedIn == true);
	rv = sessionManager.closeSession(hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
	isLoggedIn = slot->getToken()->isSOLoggedIn();
	CPPUNIT_ASSERT(isLoggedIn == false);
	haveSession = sessionManager.haveSession(slotID);
	CPPUNIT_ASSERT(haveSession == false);
	haveROSession = sessionManager.haveROSession(slotID);
	CPPUNIT_ASSERT(haveROSession == false);

	// Open a new logged in session
	rv = slot->getToken()->loginSO(soPIN);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);

	// Close all sessions and check that we are logged out
	isLoggedIn = slot->getToken()->isSOLoggedIn();
	CPPUNIT_ASSERT(isLoggedIn == true);
	rv = sessionManager.closeAllSessions(NULL);
	CPPUNIT_ASSERT(rv == CKR_SLOT_ID_INVALID);
	rv = sessionManager.closeAllSessions(slot);
	CPPUNIT_ASSERT(rv == CKR_OK);
	isLoggedIn = slot->getToken()->isSOLoggedIn();
	CPPUNIT_ASSERT(isLoggedIn == false);
}
void SessionManagerTests::testSessionInfo()
{
	// Create an empty object store
#ifndef _WIN32
	ObjectStore store("./testdir");
#else
	ObjectStore store(".\\testdir");
#endif

	// Create the managers
	SlotManager slotManager(&store);
	SessionManager sessionManager;

	// Get a slot
	CK_SLOT_ID slotID = 0;
	Slot* slot = slotManager.getSlot(slotID);

	// Initialize the token
	ByteString soPIN((unsigned char*)"1234", 4);
	ByteString userPIN((unsigned char*)"1234", 4);
	CK_UTF8CHAR label[33] = "My test token                   ";
	CPPUNIT_ASSERT(slot->initToken(soPIN, label) == CKR_OK);
	CPPUNIT_ASSERT(slot->getToken()->loginSO(soPIN) == CKR_OK);
	CPPUNIT_ASSERT(slot->getToken()->initUserPIN(userPIN) == CKR_OK);
	slot->getToken()->logout();

	// Get a session
	CK_SESSION_HANDLE hSession;
	CK_RV rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);

	// Get session info
	CK_SESSION_INFO info;
	rv = sessionManager.getSessionInfo(CK_INVALID_HANDLE, &info);
	CPPUNIT_ASSERT(rv == CKR_SESSION_HANDLE_INVALID);
	rv = sessionManager.getSessionInfo(hSession, NULL_PTR);
	CPPUNIT_ASSERT(rv == CKR_ARGUMENTS_BAD);
	rv = sessionManager.getSessionInfo(hSession, &info);
	CPPUNIT_ASSERT(rv == CKR_OK);

	// Public RO session info
	CPPUNIT_ASSERT(info.slotID == slotID);
	CPPUNIT_ASSERT(info.state == CKS_RO_PUBLIC_SESSION);
	CPPUNIT_ASSERT(info.flags == CKF_SERIAL_SESSION);

	rv = sessionManager.closeSession(hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);

	// Public RW session info
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
	Session* session = sessionManager.getSession(CK_INVALID_HANDLE);
	CPPUNIT_ASSERT(session == NULL);
	session = sessionManager.getSession(hSession);
	CPPUNIT_ASSERT(session != NULL);
	rv = session->getInfo(&info);
	CPPUNIT_ASSERT(rv == CKR_OK);
	CPPUNIT_ASSERT(info.state == CKS_RW_PUBLIC_SESSION);
	CPPUNIT_ASSERT(info.flags == (CKF_SERIAL_SESSION | CKF_RW_SESSION));

	rv = sessionManager.closeSession(hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);

	// User RO session info
	rv = slot->getToken()->loginUser(userPIN);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.getSessionInfo(hSession, &info);
	CPPUNIT_ASSERT(rv == CKR_OK);
	CPPUNIT_ASSERT(info.state == CKS_RO_USER_FUNCTIONS);
	CPPUNIT_ASSERT(info.flags == CKF_SERIAL_SESSION);

	rv = sessionManager.closeSession(hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);

	// User RW session info
	rv = slot->getToken()->loginUser(userPIN);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.getSessionInfo(hSession, &info);
	CPPUNIT_ASSERT(rv == CKR_OK);
	CPPUNIT_ASSERT(info.state == CKS_RW_USER_FUNCTIONS);
	CPPUNIT_ASSERT(info.flags == (CKF_SERIAL_SESSION | CKF_RW_SESSION));

	rv = sessionManager.closeSession(hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);

	// SO RW session info
	rv = slot->getToken()->loginSO(soPIN);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.openSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL_PTR, NULL_PTR, &hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
	rv = sessionManager.getSessionInfo(hSession, &info);
	CPPUNIT_ASSERT(rv == CKR_OK);
	CPPUNIT_ASSERT(info.state == CKS_RW_SO_FUNCTIONS);
	CPPUNIT_ASSERT(info.flags == (CKF_SERIAL_SESSION | CKF_RW_SESSION));

	rv = sessionManager.closeSession(hSession);
	CPPUNIT_ASSERT(rv == CKR_OK);
}