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
PreferencesDialog::PreferencesDialog(WindowRef	windowRef, WindowRef mainWindowRef) :
	preferencesWindow(windowRef),
	mainWindow(mainWindowRef),
	m_dataBase(NULL),
	m_dataBaseCopy(NULL),
	midiin(NULL)
{
    EventTypeSpec eventSpec[] = {{kEventClassCommand,kEventCommandProcess}, 
								 {kEventClassControl, kEventControlHit}, 
								 {kEventClassWindow, kEventWindowClose}};

	InstallWindowEventHandler(windowRef, 
							  NewEventHandlerUPP(WindowEventHandler),
							  sizeof(eventSpec)/sizeof(EventTypeSpec), 
							  (EventTypeSpec*)&eventSpec, 
							  (void*)this, 
							  NULL);

	// Create RtMidi instance for querying device information
	try 
	{
		midiin = new RtMidiIn();
	}
	catch (RtMidiError &error) 
	{
		error.printMessage();
		midiin = NULL;
	}	

	initDataBase();
}
Ejemplo n.º 3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    initDataBase();
    initWindowUI();

}
Ejemplo n.º 4
0
static KFileMetaInfo cachedMetaInfo(const KFileItem& file)
{
    QString dbName="metainfocache";
    if (!QSqlDatabase::contains(dbName))
    {
        QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE",dbName);
        db.setDatabaseName(KStandardDirs::locateLocal("appdata", dbName+".sqlite"));
        if (KDE_ISUNLIKELY( !db.open() ))
            return KFileMetaInfo(file.url());
        initDataBase(db);
    }
    QSqlDatabase db=QSqlDatabase::database(dbName);
    if (!db.isOpen())
        return KFileMetaInfo(file.url());

    static const QString fields[]={
        "translation.translated",
        "translation.untranslated",
        "translation.fuzzy",
        "translation.last_translator",
        "translation.source_date",
        "translation.translation_date",
        "translation.translated_reviewer",
        "translation.translated_approver",
        "translation.fuzzy_reviewer",
        "translation.fuzzy_approver"
    };
    static const int nFields = sizeof(fields) / sizeof(fields[0]);

    QByteArray result;

    QSqlQuery queryCache(db);
    queryCache.prepare("SELECT * from metainfo where filepath=?");
    queryCache.bindValue(0, qHash(file.localPath()));
    queryCache.exec();
    if (queryCache.next() && file.time(KFileItem::ModificationTime).dateTime()==queryCache.value(2).toDateTime())
    {
        result=queryCache.value(1).toByteArray();
        QDataStream stream(&result,QIODevice::ReadOnly);

        //unfortunately direct KFileMetaInfo << operator doesn't work
        KFileMetaInfo info;
        QVector<QVariant> keys;
        stream>>keys;
        for(int i=0;i<keys.count();i++)
            info.item(fields[i]).setValue(keys.at(i));
        return info;
    }
int check_for_db(sqlite3 ** db, const char * filename, int can_create, int readonly)
{
	struct stat dbfile;
	int rc;
	int accessflags = R_OK | W_OK;
	if (readonly)
		accessflags = R_OK;

	// Check if DB exist. If it does not, initialize it
	if (access(filename, accessflags)) {
		printf("Database <%s> does not already exist, ", filename);
		if (can_create)
		{
			printf("creating it...\n");

			rc = initDataBase(filename, db);

			if (rc)
			{
				printf("Error initializing database (return code: %d), exiting...\n", rc);
				return 1;
			}
		}
		else
		{
			printf("exiting ...\n");
			return 1;
		}
	}
	else
	{
		if (stat(filename, &dbfile))
		{
			perror("stat()");
			return 1;
		}
		if ((S_ISREG(dbfile.st_mode) && !S_ISDIR(dbfile.st_mode)) == 0)
		{
			printf("\"%s\" does not appear to be a file.\n", filename);
			return 1;
		}
	}

	rc = sqlite3_open(filename, &(*db));
	if(rc) {
		sql_error(*db);
		sqlite3_close(*db);
		return 1;
	}

	// TODO: Sanity check: Table definitions, index

	// register new functions to be used in SQL statements
	if (sqlite3_create_function(*db, "PMK", 2, SQLITE_ANY, 0, &sql_calcpmk,0,0) != SQLITE_OK) {
		printf("Failed creating PMK function.\n");
		sql_error(*db);
		sqlite3_close(*db);
		return 1;
	}
	if (sqlite3_create_function(*db, "VERIFY_ESSID", 1, SQLITE_ANY, 0, &sql_verify_essid,0,0) != SQLITE_OK) {
		printf("Failed creating VERIFY_ESSID function.\n");
		sql_error(*db);
		sqlite3_close(*db);
		return 1;
	}
	if (sqlite3_create_function(*db, "VERIFY_PASSWD", 1, SQLITE_ANY, 0, &sql_verify_passwd,0,0) != SQLITE_OK) {
		printf("Failed creating VERIFY_PASSWD function.\n");
		sql_error(*db);
		sqlite3_close(*db);
		return 1;
	}
#ifdef HAVE_REGEXP
	if (sqlite3_create_function(*db, "regexp", 2, SQLITE_ANY,0, &sqlite_regexp,0,0) != SQLITE_OK) {
		printf("Failed creating regexp() handler.\n");
		sql_error(*db);
		sqlite3_close(*db);
		return 1;
	}
#endif

	return 0;
}