void ConnectDbDialogWidget::saveSettings()
{
    ConnectionSettings settings;
    settings.setEventName(ui->edEventName->text());
    settings.setConnectionType(static_cast<Event::EventPlugin::ConnectionType>(ui->tabWidget->currentIndex()));
    settings.setServerHost(ui->edServerHost->text());
    settings.setServerPort(ui->edServerPort->value());
    settings.setServerUser(ui->edServerUser->text());
    settings.setServerPassword(ui->edServerPassword->text());
    settings.setSingleWorkingDir(ui->edSingleWorkingDir->text());
}
Example #2
0
bool EventPlugin::openEvent(const QString &_event_name)
{
	closeEvent();
	//return true;
	qff::MainWindow *fwk = qff::MainWindow::frameWork();
	QString event_name = _event_name;
	ConnectionSettings connection_settings;
	ConnectionType connection_type = connection_settings.connectionType();
	//console.debug("openEvent()", "event_name:", event_name, "connection_type:", connection_type);
	bool ok = false;
	if(connection_type == ConnectionType::SqlServer) {
		//console.debug(db);
		QStringList event_names = existingSqlEventNames();
		if(!event_names.contains(event_name))
			event_name = QString();
		ok = !event_name.isEmpty();
		if(!ok) {
			event_name = QInputDialog::getItem(fwk, tr("Query"), tr("Open event"), event_names, 0, false, &ok);
		}
		//Log.info(event_name, typeof event_name, (event_name)? "T": "F");
		ok = ok && !event_name.isEmpty();
		if(ok) {
			qfs::Connection conn(QSqlDatabase::database());
			if(conn.setCurrentSchema(event_name)) {
				ConnectionSettings settings;
				settings.setEventName(event_name);
				ok = true;
			}
		}
	}
	else if(connection_type == ConnectionType::SingleFile) {
		QString event_fn;
		if(!event_name.isEmpty()) {
			event_fn = eventNameToFileName(event_name);
			if(!QFile::exists(event_fn)) {
				event_fn = event_name = QString();
			}
		}
		if(event_name.isEmpty()) {
			QStringList event_names = existingFileEventNames(connection_settings.singleWorkingDir());
			event_name = QInputDialog::getItem(fwk, tr("Query"), tr("Open event"), event_names, 0, false, &ok);
			//event_fn = qfd::FileDialog::getOpenFileName(fwk, tr("Select event"), connection_settings.singleWorkingDir(), tr("Quick Event files (*%1)").arg(qbe_ext));
			if(ok && !event_name.isEmpty()) {
				event_fn = eventNameToFileName(event_name);
			}
		}
		//Log.info(event_name, typeof event_name, (event_name)? "T": "F");
		{
			QString conn_name;
			{
				qfs::Connection conn(QSqlDatabase::database());
				conn_name = conn.connectionName();
				conn.close();
			}
			qfInfo() << "removing database:" << conn_name;
			QSqlDatabase::removeDatabase(conn_name);
			QSqlDatabase::addDatabase("QSQLITE");
		}
		if(event_fn.isEmpty()) {
			ok = false;
		}
		else {
			if(QFile::exists(event_fn)) {
				qfs::Connection conn(QSqlDatabase::database());
				conn.setDatabaseName(event_fn);
				qfInfo() << "Opening database file" << event_fn;
				if(conn.open()) {
					qfs::Query q(conn);
					ok = q.exec("PRAGMA foreign_keys=ON");
				}
				else {
					qfd::MessageBox::showError(fwk, tr("Open Database Error: %1").arg(conn.errorString()));
				}
			}
			else {
				qfd::MessageBox::showError(fwk, tr("Database file %1 doesn't exist.").arg(event_fn));
			}
		}
	}
	else {
		qfError() << "Invalid connection type:" << static_cast<int>(connection_type);
	}
	if(ok) {
		eventConfig(true);
		connection_settings.setEventName(event_name);
		setEventName(event_name);
		emit eventOpened(eventName());
		//emit reloadDataRequest();
	}
	return ok;
}