QWidget *MainWindow::createRecentEvents() { m_eventsView = new EventsView; m_eventsView->setContextMenuPolicy(Qt::CustomContextMenu); m_eventsView->setFrameStyle(QFrame::NoFrame); m_eventsView->setAttribute(Qt::WA_MacShowFocusRect, false); m_eventsView->setIncompletePlace(EventsProxyModel::IncompleteLast); m_eventsModel = new EventsModel(m_serverRepository, m_eventsView); EventsUpdater *updater = new EventsUpdater(m_serverRepository, m_eventsModel); connect(updater, SIGNAL(serverEventsAvailable(DVRServer*,QList<QSharedPointer<EventData>>)), m_eventsModel, SLOT(setServerEvents(DVRServer*,QList<QSharedPointer<EventData>>))); m_eventsView->setModel(m_eventsModel, updater->isUpdating()); connect(updater, SIGNAL(loadingStarted()), m_eventsView, SLOT(loadingStarted())); connect(updater, SIGNAL(loadingFinished()), m_eventsView, SLOT(loadingFinished())); QSettings settings; updater->setUpdateInterval(settings.value(QLatin1String("ui/main/eventRefreshInterval"), 10000).toInt()); updater->setLimit(50); m_eventsView->header()->restoreState(settings.value(QLatin1String("ui/main/eventsView")).toByteArray()); connect(m_eventsView, SIGNAL(doubleClicked(QModelIndex)), m_eventsView, SLOT(openEvent(QModelIndex))); connect(m_eventsView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(eventsContextMenu(QPoint))); return m_eventsView; }
void SyntaxHighlightDlg::OnImportEclipseTheme(wxAuiToolBarEvent& event) { #if 0 EclipseThemeImporterManager importer; importer.ImportCxxToAll(); ColoursAndFontsManager::Get().Reload(); EndModal(wxID_OK); wxCommandEvent openEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("syntax_highlight")); clMainFrame::Get()->GetEventHandler()->AddPendingEvent(openEvent); #else wxString eclipseThemeXml = ::wxFileSelector(_("Select eclipse XML theme file"), "", "", "", "Eclipse Theme Files (*.xml)|*.xml"); if(ColoursAndFontsManager::Get().ImportEclipseTheme(eclipseThemeXml)) { ::wxMessageBox(_("File imported successfully!")); // Dismiss the dialog EndModal(wxID_OK); // and reload it wxCommandEvent openEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("syntax_highlight")); clMainFrame::Get()->GetEventHandler()->AddPendingEvent(openEvent); } #endif }
void WorkspaceTab::OpenProjectSettings(const wxString& project) { if(m_dlg) { m_dlg->Raise(); return; } wxString projectName = project.IsEmpty() ? ManagerST::Get()->GetActiveProjectName() : project; wxString title(projectName); title << _(" Project Settings"); // Allow plugins to process this event first clCommandEvent openEvent(wxEVT_CMD_OPEN_PROJ_SETTINGS); openEvent.SetString(project); if(EventNotifier::Get()->ProcessEvent(openEvent)) { return; } // open the project properties dialog BuildMatrixPtr matrix = ManagerST::Get()->GetWorkspaceBuildMatrix(); #ifdef __WXMAC__ // On OSX we use a modal version of the project settings // since otherwise we get some weird focus issues when the project // settings dialog popups helper dialogs ProjectSettingsDlg dlg(clMainFrame::Get(), this, matrix->GetProjectSelectedConf(matrix->GetSelectedConfigurationName(), projectName), projectName, title); dlg.ShowModal(); #else // Find the project configuration name that matches the workspace selected configuration m_dlg = new ProjectSettingsDlg(clMainFrame::Get(), this, matrix->GetProjectSelectedConf(matrix->GetSelectedConfigurationName(), projectName), projectName, title); m_dlg->Show(); #endif // Mark this project as modified ProjectPtr proj = ManagerST::Get()->GetProject(projectName); if(proj) { proj->SetModified(true); } }
void HistoryDlg::actionOpenEvent(QTreeWidgetItem *item, int column) { Message m; QString sTime; sTime = ((DateItem*)DateTree->currentItem())->date().toString(Qt::ISODate) + "T" + item->text(1); m.setTimeStamp(QDateTime::fromString(sTime, Qt::ISODate)); m.setFrom(jid_); m.setType(item->text(0)); m.setBody(item->text(3)); m.setSpooled(true); MessageEvent *me = new MessageEvent(m, 0); me->setOriginLocal((item->text(2) == "to") ? true : false); openEvent(me); }
void SyntaxHighlightDlg::OnRestoreDefaults(wxCommandEvent& event) { // Ask for confirmation if(::wxMessageBox(_("Are you sure you want to restore colours to factory defaults?\nBy choosing 'Yes', you will " "lose all your local modifications"), _("Confirm"), wxICON_WARNING | wxYES_NO | wxCANCEL | wxNO_DEFAULT | wxCENTER, this) == wxYES) { // Restore defaults ColoursAndFontsManager::Get().RestoreDefaults(); // Dismiss the dialog EndModal(wxID_OK); // and reload it wxCommandEvent openEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("syntax_highlight")); clMainFrame::Get()->GetEventHandler()->AddPendingEvent(openEvent); } }
void SyntaxHighlightDlg::OnImport(wxCommandEvent& event) { wxString path = ::wxFileSelector(_("Select file"), "", "", "", "Zip Files (*.zip)|*.zip", wxFD_OPEN); if(path.IsEmpty()) return; wxFileName fn(path); clZipReader zr(fn); zr.Extract("*", clStandardPaths::Get().GetUserLexersDir()); // reload the settings ColoursAndFontsManager::Get().Reload(); EndModal(wxID_OK); // relaunch the dialog wxCommandEvent openEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("syntax_highlight")); clMainFrame::Get()->GetEventHandler()->AddPendingEvent(openEvent); }
void BundlePane::OnTreeItemActivated(wxTreeEvent& WXUNUSED(event)) { // Activate event restores focus to treeCtrl so we want to open item // in a subsequent event (otherwise it will steal focus from editorCtrl) wxCommandEvent openEvent(wxEVT_COMMAND_MENU_SELECTED, MENU_OPEN_ITEM); AddPendingEvent(openEvent); }
void EventPlugin::importEvent_qbe() { qfLogFuncFrame(); qff::MainWindow *fwk = qff::MainWindow::frameWork(); /* if(connectionType() != ConnectionType::SqlServer) { qfd::MessageBox::showError(fwk, tr("Data file can be imported to SQL server only!")); return; } */ QString ext = ".qbe"; QString fn = qf::qmlwidgets::dialogs::FileDialog::getOpenFileName (fwk, tr("Import as Quick Event"), QString(), "Quick Event files *.qbe (*.qbe)"); if(fn.isEmpty()) return; QString event_name = QInputDialog::getText(fwk, tr("Query"), tr("Event will be imported as ID:")).trimmed(); if(event_name.isEmpty()) return; QStringList existing_events = (connectionType() == ConnectionType::SingleFile)? existingFileEventNames(): existingSqlEventNames(); if(existing_events.contains(event_name)) { qfd::MessageBox::showError(fwk, tr("Event ID '%1' exists already!").arg(event_name)); return; } QString err_str; QString import_connection_name = QStringLiteral("qe_import_connection"); QString export_connection_name = QStringLiteral("qe_export_connection"); do { qfs::Connection current_conn = qfs::Connection::forName(); qfs::Connection imp_conn(QSqlDatabase::addDatabase("QSQLITE", import_connection_name)); imp_conn.setDatabaseName(fn); qfInfo() << "Opening import database file" << fn; if(!imp_conn.open()) { qfd::MessageBox::showError(fwk, tr("Open Database Error: %1").arg(imp_conn.errorString())); return; } qfs::Connection exp_conn(QSqlDatabase::addDatabase(current_conn.driverName(), export_connection_name)); if(connectionType() == ConnectionType::SingleFile) { exp_conn.setDatabaseName(eventNameToFileName(event_name)); } else { exp_conn.setHostName(current_conn.hostName()); exp_conn.setPort(current_conn.port()); exp_conn.setUserName(current_conn.userName()); exp_conn.setPassword(current_conn.password()); exp_conn.setDatabaseName(current_conn.databaseName()); } qfInfo() << "Opening export database:" << exp_conn.databaseName(); if(!exp_conn.open()) { qfd::MessageBox::showError(fwk, tr("Open Database Error: %1").arg(exp_conn.errorString())); return; } qfs::Transaction transaction(exp_conn); DbSchema db_schema = dbSchema(); auto tables = db_schema.tables(); int step_cnt = tables.count() + 1; int step_no = 0; fwk->showProgress(tr("Creating database"), ++step_no, step_cnt); { DbSchema::CreateDbSqlScriptOptions create_options; create_options.setDriverName(exp_conn.driverName()); create_options.setSchemaName(event_name); QStringList create_script = db_schema.createDbSqlScript(create_options); qfs::Query ex_q(exp_conn); if(!run_sql_script(ex_q, create_script)) { err_str = tr("Create Database Error: %1").arg(ex_q.lastError().text()); break; } } exp_conn.setCurrentSchema(event_name); for(QObject *table : tables) { QString table_name = table->property("name").toString(); qfDebug() << "Copying table" << table_name; fwk->showProgress(tr("Copying table %1").arg(table_name), ++step_no, step_cnt); QSqlRecord rec = db_schema.sqlRecord(table, true); err_str = copy_sql_table(table_name, rec, imp_conn, exp_conn); if(!err_str.isEmpty()) break; } if(!err_str.isEmpty()) break; transaction.commit(); } while(false); QSqlDatabase::removeDatabase(import_connection_name); QSqlDatabase::removeDatabase(export_connection_name); fwk->hideProgress(); if(!err_str.isEmpty()) { qfd::MessageBox::showError(fwk, err_str); return; } if(qfd::MessageBox::askYesNo(fwk, tr("Open imported event '%1'?").arg(event_name))) { openEvent(event_name); } }
bool EventPlugin::createEvent(const QString &event_name, const QVariantMap &event_params) { qfLogFuncFrame(); closeEvent(); qff::MainWindow *fwk = qff::MainWindow::frameWork(); EventPlugin::ConnectionType connection_type = connectionType(); QStringList existing_event_ids; if(connection_type == ConnectionType::SingleFile) existing_event_ids = existingFileEventNames(); else existing_event_ids = existingSqlEventNames(); QString event_id = event_name; QVariantMap new_params = event_params; do { qfd::Dialog dlg(fwk); dlg.setButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); EventDialogWidget *event_w = new EventDialogWidget(); event_w->setEventId(event_id); event_w->loadParams(new_params); dlg.setCentralWidget(event_w); if(!dlg.exec()) return false; event_id = event_w->eventId(); new_params = event_w->saveParams(); if(event_id.isEmpty()) { qf::qmlwidgets::dialogs::MessageBox::showError(fwk, tr("Event ID cannot be empty.")); continue; } if(existing_event_ids.contains(event_id)) { qf::qmlwidgets::dialogs::MessageBox::showError(fwk, tr("Event ID %1 exists already.").arg(event_id)); continue; } break; } while(true); bool ok = false; Event::EventConfig event_config; //ConnectionSettings connection_settings; event_config.setValue("event", new_params); int stage_count = event_params.value("stageCount").toInt(); if(stage_count == 0) stage_count = event_config.stageCount(); qfInfo() << "createEvent, stage_count:" << stage_count; QF_ASSERT(stage_count > 0, "Stage count have to be greater than 0", return false); qfInfo() << "will create:" << event_id; qfs::Connection conn = qfs::Connection::forName(); //QF_ASSERT(conn.isOpen(), "Connection is not open", return false); if(connection_type == ConnectionType::SingleFile) { QString event_fn = eventNameToFileName(event_id); conn.close(); conn.setDatabaseName(event_fn); conn.open(); } if(conn.isOpen()) { QVariantMap create_options; create_options["schemaName"] = event_id; create_options["driverName"] = conn.driverName(); QVariant ret_val; QMetaObject::invokeMethod(this, "createDbSqlScript", Qt::DirectConnection, Q_RETURN_ARG(QVariant, ret_val), Q_ARG(QVariant, create_options)); QStringList create_script = ret_val.toStringList(); qfInfo().nospace() << create_script.join(";\n") << ';'; qfs::Query q(conn); do { qfs::Transaction transaction(conn); ok = run_sql_script(q, create_script); if(!ok) break; qfDebug() << "creating stages:" << stage_count; QString stage_table_name = "stages"; if(connection_type == ConnectionType::SqlServer) stage_table_name = event_id + '.' + stage_table_name; q.prepare("INSERT INTO " + stage_table_name + " (id) VALUES (:id)"); for(int i=0; i<stage_count; i++) { q.bindValue(":id", i+1); ok = q.exec(); if(!ok) { break; } } if(!ok) break; conn.setCurrentSchema(event_id); event_config.save(); transaction.commit(); } while(false); if(!ok) { qfd::MessageBox::showError(fwk, tr("Create Database Error: %1").arg(q.lastError().text())); } } else { qfd::MessageBox::showError(fwk, tr("Cannot create event, database is not open: %1").arg(conn.lastError().text())); } if(ok) { ok = openEvent(event_id); } return ok; }
void EventPlugin::connectToSqlServer() { qfLogFuncFrame(); qff::MainWindow *fwk = qff::MainWindow::frameWork(); bool connect_ok = false; ConnectionType connection_type = ConnectionType::SingleFile; qfd::Dialog dlg(fwk); dlg.setButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); dlg.setSavePersistentPosition(false); ConnectDbDialogWidget *conn_w = new ConnectDbDialogWidget(); dlg.setCentralWidget(conn_w); while(!connect_ok) { conn_w->loadSettings(); if(!dlg.exec()) break; conn_w->saveSettings(); connection_type = conn_w->connectionType(); qfDebug() << "connection_type:" << (int)connection_type; if(connection_type == ConnectionType::SqlServer) { QString driver_name = "QPSQL"; QSqlDatabase::removeDatabase(QSqlDatabase::defaultConnection); QSqlDatabase db = QSqlDatabase::addDatabase(driver_name); connect_ok = db.isValid(); qfInfo() << "Adding database driver:" << driver_name << "OK:" << connect_ok; if(connect_ok) { //Log.info(db, db.connectionName, db.driverName); db.setHostName(conn_w->serverHost()); db.setPort(conn_w->serverPort()); db.setUserName(conn_w->serverUser()); //qfInfo() << conn_w->serverPassword(); db.setPassword(conn_w->serverPassword()); db.setDatabaseName("quickevent"); qfInfo().nospace() << "connecting to: " << db.userName() << "@" << db.hostName() << ":" << db.port(); connect_ok = db.open(); if(connect_ok) { bool ok = connect(db.driver(), SIGNAL(notification(QString,QSqlDriver::NotificationSource,QVariant)), this, SLOT(onDbEvent(QString,QSqlDriver::NotificationSource,QVariant))); if(ok) ok = db.driver()->subscribeToNotification(DBEVENT_NOTIFY_NAME); if(!ok) qfError() << "Failed to subscribe db notification:" << DBEVENT_NOTIFY_NAME; else { qfInfo() << "Successfully subscribe db notification:" << DBEVENT_NOTIFY_NAME; qfInfo() << db.driver() << "subscribedToNotifications:" << db.driver()->subscribedToNotifications().join(", "); } } } if(!connect_ok) { qff::MainWindow *fwk = qff::MainWindow::frameWork(); qfd::MessageBox::showError(fwk, tr("Connect Database Error: %1").arg(db.lastError().text())); } } else { connect_ok = true; } } setDbOpen(connect_ok); m_actCreateEvent->setEnabled(connect_ok); m_actOpenEvent->setEnabled(connect_ok); m_actEditEvent->setEnabled(connect_ok); m_actExportEvent->setEnabled(connect_ok); m_actImportEvent->setEnabled(connect_ok); if(connect_ok) { openEvent(conn_w->eventName()); } }
void EventPlugin::onInstalled() { qff::MainWindow *fwk = qff::MainWindow::frameWork(); m_actConnectDb = new qfw::Action(tr("&Connect to database")); //a->setShortcut("ctrl+L"); connect(m_actConnectDb, SIGNAL(triggered()), this, SLOT(connectToSqlServer())); m_actOpenEvent = new qfw::Action(tr("&Open event")); //m_actOpenEvent->setShortcut("Ctrl+O"); m_actOpenEvent->setEnabled(false); connect(m_actOpenEvent, SIGNAL(triggered()), this, SLOT(openEvent())); m_actCreateEvent = new qfw::Action(tr("Create eve&nt")); //m_actCreateEvent->setShortcut("Ctrl+N"); m_actCreateEvent->setEnabled(false); connect(m_actCreateEvent, SIGNAL(triggered()), this, SLOT(createEvent())); m_actEditEvent = new qfw::Action(tr("E&dit event")); m_actEditEvent->setEnabled(false); connect(m_actEditEvent, SIGNAL(triggered()), this, SLOT(editEvent())); connect(this, &EventPlugin::eventNameChanged, [this](const QString &event_name) { this->m_actEditEvent->setEnabled(!event_name.isEmpty()); }); m_actExportEvent = new qfw::Action(tr("E&xport event")); m_actExportEvent->setEnabled(false); connect(m_actExportEvent, &QAction::triggered, this, &EventPlugin::exportEvent); m_actImportEvent = new qfw::Action(tr("I&mport event")); m_actImportEvent->setEnabled(false); connect(m_actImportEvent, &QAction::triggered, this, &EventPlugin::importEvent_qbe); connect(this, SIGNAL(eventNameChanged(QString)), fwk->statusBar(), SLOT(setEventName(QString))); connect(this, SIGNAL(currentStageIdChanged(int)), fwk->statusBar(), SLOT(setStageNo(int))); connect(fwk, &qff::MainWindow::pluginsLoaded, this, &EventPlugin::connectToSqlServer); connect(this, &EventPlugin::eventOpened, this, &EventPlugin::onEventOpened); qfw::Action *a_quit = fwk->menuBar()->actionForPath("file/import", false); a_quit->addActionBefore(m_actConnectDb); a_quit->addSeparatorBefore(); m_actEvent = m_actConnectDb->addMenuAfter("file.event", tr("&Event")); m_actEvent->addActionInto(m_actCreateEvent); m_actEvent->addActionInto(m_actOpenEvent); m_actEvent->addActionInto(m_actEditEvent); m_actEvent->addActionInto(m_actExportEvent); m_actEvent->addActionInto(m_actImportEvent); qfw::ToolBar *tb = fwk->toolBar("Event", true); tb->setObjectName("EventToolbar"); { QToolButton *bt_stage = new QToolButton(); //bt_stage->setFlat(true); bt_stage->setAutoRaise(true); bt_stage->setCheckable(true); tb->addWidget(bt_stage); m_cbxStage = new QComboBox(); connect(m_cbxStage, SIGNAL(activated(int)), this, SLOT(onCbxStageActivated(int))); connect(this, &EventPlugin::currentStageIdChanged, [bt_stage](int stage_id) { bt_stage->setText(tr("Current stage E%1").arg(stage_id)); }); QAction *act_stage = tb->addWidget(m_cbxStage); act_stage->setVisible(false); auto *style = qf::qmlwidgets::Style::instance(); QIcon ico(style->icon("settings")); m_actEditStage = new qfw::Action(ico, "Stage settings"); m_actEditStage->setVisible(false); connect(m_actEditStage, SIGNAL(triggered()), this, SLOT(editStage())); tb->addAction(m_actEditStage); connect(bt_stage, &QPushButton::clicked, [this, act_stage](bool checked) { act_stage->setVisible(checked); m_actEditStage->setVisible(checked); }); } }
void HistoryDlg::actionOpenEvent(PsiEvent *e) { openEvent(e); }