/** * @brief Initiate 'edit' action, usually when user clicked on Edit button */ void ConnectionsDialog::edit() { ConnectionListWidgetItem *currentItem = (ConnectionListWidgetItem *) _listWidget->currentItem(); // Do nothing if no item selected if (currentItem == 0) return; ConnectionSettings *connection = currentItem->connection(); boost::scoped_ptr<ConnectionSettings> clonedConnection(connection->clone()); ConnectionDialog editDialog(clonedConnection.get()); // Do nothing if not accepted if (editDialog.exec() != QDialog::Accepted) { // on linux focus is lost - we need to activate connections dialog activateWindow(); return; } connection->apply(editDialog.connection()); _settingsManager->updateConnection(connection); // on linux focus is lost - we need to activate connections dialog activateWindow(); }
void MainWindow::updateConnectionsMenu() { _connectionsMenu->clear(); int number = 1; // Populate list with connections SettingsManager::ConnectionSettingsContainerType connections = AppRegistry::instance().settingsManager()->connections(); for(SettingsManager::ConnectionSettingsContainerType::const_iterator it = connections.begin(); it!= connections.end(); ++it) { ConnectionSettings *connection = *it; QAction *action = new QAction(QtUtils::toQString(connection->getReadableName()), this); action->setData(QVariant::fromValue(connection)); if (number <= 9 && !AppRegistry::instance().settingsManager()->disableConnectionShortcuts()) { action->setShortcut(QKeySequence(QString("Alt+").append(QString::number(number)))); } _connectionsMenu->addAction(action); ++number; } if (AppRegistry::instance().settingsManager()->connections().size() > 0) _connectionsMenu->addSeparator(); // Connect action QAction *connectAction = new QAction("&Manage Connections...", this); connectAction->setIcon(GuiRegistry::instance().connectIcon()); connectAction->setToolTip("Connect to MongoDB"); VERIFY(connect(connectAction, SIGNAL(triggered()), this, SLOT(manageConnections()))); _connectionsMenu->addAction(connectAction); }
/** * @brief Initiate 'edit' action, usually when user clicked on Edit button */ void ConnectionsDialog::edit() { ConnectionListWidgetItem *currentItem = (ConnectionListWidgetItem *) _listWidget->currentItem(); // Do nothing if no item selected if (currentItem == 0) return; ConnectionSettings *connection = currentItem->connection(); boost::scoped_ptr<ConnectionSettings> clonedConnection(connection->clone()); ConnectionDialog editDialog(clonedConnection.get()); // Do nothing if not accepted if (editDialog.exec() != QDialog::Accepted) { // on linux focus is lost - we need to activate connections dialog activateWindow(); return; } connection->apply(editDialog.connection()); // on linux focus is lost - we need to activate connections dialog activateWindow(); int size = _connectionItems.size(); for (int i=0; i<size; ++i) { ConnectionListWidgetItem *item = _connectionItems[i]; if (_connectionItems[i]->connection() == connection) { item->setConnection(connection); break; } } }
MongoShell *App::openShell(MongoCollection *collection,const QString &filePathToSave) { ConnectionSettings *connection = collection->database()->server()->connectionRecord(); connection->setDefaultDatabase(collection->database()->name()); QString script = detail::buildCollectionQuery(collection->name(), "find({})"); return openShell(connection, ScriptInfo(script, true, CursorPosition(0, -2), QtUtils::toQString(collection->database()->name()),filePathToSave)); }
void PppDownScriptWriter::fill() { dictionary()->SetValue(OBJECTNAME, QCoreApplication::instance()->objectName().toAscii().constData()); dictionary()->SetValue(GETIPSECINFOLIB, ConfWriter::fileName(ConfWriter::GETIPSECINFO).toAscii().constData()); const ConnectionSettings settings; const int iConnections = settings.connections(); for (int i = 0; i < iConnections; i++) { const QString strName(settings.connection(i)); if (!strName.isEmpty()) { const PppIpSettings ipSetting(settings.pppSettings(strName).ipSettings()); ctemplate::TemplateDictionary* const pConnection = dictionary()->AddSectionDictionary(CONN_SECTION); pConnection->SetValue(IPPARAM, (QCoreApplication::instance()->objectName() + "-" + strName).toAscii().constData()); pConnection->SetValue(GATEWAY, settings.ipsecSettings(strName).gateway().toAscii().constData()); if (ipSetting.useDefaultGateway()) pConnection->AddSectionDictionary(DEFAULT_GATEWAY_SECTION); } else addErrorMsg(QObject::tr("No such connection: '%1'.").arg(strName)); } }
void ExplorerTreeWidget::ui_renameCollection() { ExplorerCollectionTreeItem *collectionItem = selectedCollectionItem(); if (!collectionItem) return; MongoCollection *collection = collectionItem->collection(); MongoDatabase *database = collection->database(); MongoServer *server = database->server(); ConnectionSettings *settings = server->connectionRecord(); CreateDatabaseDialog dlg(settings->getFullAddress(), database->name(), collection->name()); dlg.setWindowTitle("Rename Collection"); dlg.setOkButtonText("&Rename"); dlg.setInputLabelText("New Collection Name:"); dlg.setInputText(collection->name()); int result = dlg.exec(); if (result == QDialog::Accepted) { database->renameCollection(collection->name(), dlg.databaseName()); // refresh list of collections database->loadCollections(); } }
void ExplorerTreeWidget::ui_addDocument() { ExplorerCollectionTreeItem *collectionItem = selectedCollectionItem(); if (!collectionItem) return; MongoCollection *collection = collectionItem->collection(); MongoDatabase *database = collection->database(); MongoServer *server = database->server(); ConnectionSettings *settings = server->connectionRecord(); DocumentTextEditor editor(settings->getFullAddress(), database->name(), collection->name(), "{\n \n}"); editor.setCursorPosition(1, 4); editor.setWindowTitle("Insert Document"); int result = editor.exec(); activateWindow(); if (result == QDialog::Accepted) { mongo::BSONObj obj = editor.bsonObj(); server->insertDocument(obj, database->name(), collection->name()); } /* openCurrentCollectionShell( "db.%1.insert({\n" " '' : '',\n" "})" , false, CursorPosition(1, 5)); */ }
void ConnectionsDialog::clone() { ConnectionListWidgetItem *currentItem = (ConnectionListWidgetItem *) _listWidget->currentItem(); // Do nothing if no item selected if (currentItem == 0) return; // Clone connection ConnectionSettings *connection = currentItem->connection()->clone(); std::string newConnectionName="Copy of "+connection->connectionName(); connection->setConnectionName(newConnectionName); ConnectionDialog editDialog(connection); // Cleanup newly created connection and return, if not accepted. if (editDialog.exec() != QDialog::Accepted) { delete connection; return; } // Now connection will be owned by SettingsManager _settingsManager->addConnection(connection); add(connection); }
void PasswordDialog::setupGenericUi(const ConnectionSettings &connectionSettings) { Setting::Ptr setting = connectionSettings.setting(m_settingName); ui = new Ui::PasswordDialog; ui->setupUi(this); // TODO fix this for high DPI ui->labelIcon->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-password")).pixmap(KIconLoader::SizeMedium)); m_neededSecrets = setting->needSecrets(m_flags & SecretAgent::RequestNew); if (m_neededSecrets.isEmpty()) { qCWarning(PLASMA_NM) << "list of secrets is empty!!!"; m_hasError = true; m_error = SecretAgent::InternalError; m_errorMessage = QLatin1String("No secrets were requested"); return; } WirelessSetting::Ptr wifi = connectionSettings.setting(Setting::Wireless).dynamicCast<WirelessSetting>(); Setting::SettingType connectionType = setting->type(); if (wifi && (connectionType == Setting::WirelessSecurity || connectionType == Setting::Security8021x)) { const QString ssid = QString::fromUtf8(wifi->ssid()); ui->labelText->setText(i18n("For accessing the wireless network '%1' you need to provide a password below", ssid)); } else { ui->labelText->setText(i18n("Please provide the password for activating connection '%1'", connectionSettings.id())); } ui->password->setFocus(); connect(ui->showPassword, &QCheckBox::toggled, this, &PasswordDialog::showPassword); connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &PasswordDialog::accept); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &PasswordDialog::reject); }
/** * * Gets a setting identified by key. If it doesn't exist, we'll recursively try * each parent until we hit the top level. If this happens we'll return null. * * @param key The (std::string) key to lookup * @param bubble true to bubble up to parents if we don't have the given setting * @return The result, or nullptr if there was none */ Variant ConnectionSettings::get(std::string key, bool bubble) { ConnectionSettings *parent; // We've got this key, send it back! if (contains(key)) { return settings[key]; } // uuid and name are handled specially. UUID needs to be generated if it // is missing and name mustn't bubble. if (key == "uuid") { // Generate UUID settings["uuid"] = UUID::makeUUID(); return settings["uuid"]; } else if (key == "name" or key == "parent") { // Name and parent should not climb the tree bubble = false; } // If bubble is true, we need to look for the first parent that has this // setting set. if (bubble && (parent = (ConnectionSettings*) this->getParent()) != nullptr) { return parent->get(key, true); } // Couldn't find it :( return Variant(); }
MongoShell *App::openShell(MongoDatabase *database, const QString &script, bool execute, const QString &shellName, const CursorPosition &cursorPosition,const QString &filePathToSave) { ConnectionSettings *connection = database->server()->connectionRecord(); connection->setDefaultDatabase(database->name()); return openShell(connection, ScriptInfo(script, execute, cursorPosition, shellName,filePathToSave)); }
MongoShell *App::openShell(MongoServer *server,const QString &script, const std::string &dbName, bool execute, const QString &shellName, const CursorPosition &cursorPosition,const QString &filePathToSave) { ConnectionSettings *connection = server->connectionRecord(); if (!dbName.empty()) connection->setDefaultDatabase(dbName); return openShell(connection, ScriptInfo(script, execute, cursorPosition, shellName,filePathToSave)); }
void ExplorerCollectionTreeItem::ui_copyToCollectionToDiffrentServer() { MongoDatabase *databaseFrom = _collection->database(); MongoServer *server = databaseFrom->server(); ConnectionSettings *settings = server->connectionRecord(); CopyCollection dlg(QtUtils::toQString(settings->getFullAddress()), QtUtils::toQString(databaseFrom->name()), QtUtils::toQString(_collection->name()) ); int result = dlg.exec(); if (result == QDialog::Accepted) { MongoDatabase *databaseTo = dlg.selectedDatabase(); databaseTo->copyCollection(server, databaseFrom->name(), _collection->name()); databaseTo->loadCollections(); } }
void ExplorerCollectionTreeItem::ui_addDocument() { MongoDatabase *database = _collection->database(); MongoServer *server = database->server(); ConnectionSettings *settings = server->connectionRecord(); DocumentTextEditor editor(CollectionInfo(settings->getFullAddress(), database->name(), _collection->name()), "{\n \n}"); editor.setCursorPosition(1, 4); editor.setWindowTitle("Insert Document"); int result = editor.exec(); treeWidget()->activateWindow(); if (result == QDialog::Accepted) { server->insertDocuments(editor.bsonObj(), MongoNamespace(database->name(), _collection->name()) ); } }
void ConnectionManager::connectTo(Konversation::ConnectionFlag flag, int serverGroupId) { ConnectionSettings settings; Konversation::ServerGroupSettingsPtr serverGroup; serverGroup = Preferences::serverGroupById(serverGroupId); if (serverGroup) { settings.setServerGroup(serverGroup); if (serverGroup->serverList().size() > 0) settings.setServer(serverGroup->serverList()[0]); } connectTo(flag, settings); }
MongoServer* App::continueOpenServer(ConnectionSettings *connection, bool visible, int localport) { ConnectionSettings* settings = connection->clone(); // Modify connection settings when SSH tunnel is used if (visible && settings->sshSettings()->enabled()) { settings->setServerHost("127.0.0.1"); settings->setServerPort(localport); } MongoServer *server = new MongoServer(settings, visible); _servers.push_back(server); server->runWorkerThread(); LOG_MSG(QString("Connecting to %1...").arg(QtUtils::toQString(server->connectionRecord()->getFullAddress())), mongo::logger::LogSeverity::Info()); server->tryConnect(); return server; }
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()); }
void ExplorerCollectionTreeItem::ui_renameCollection() { MongoDatabase *database = _collection->database(); MongoServer *server = database->server(); ConnectionSettings *connSettings = server->connectionRecord(); CreateDatabaseDialog dlg(QtUtils::toQString(connSettings->getFullAddress()), QtUtils::toQString(database->name()), QtUtils::toQString(_collection->name()), treeWidget()); dlg.setWindowTitle("Rename Collection"); dlg.setOkButtonText("&Rename"); dlg.setInputLabelText("New Collection Name:"); dlg.setInputText(QtUtils::toQString(_collection->name())); int result = dlg.exec(); if (result == QDialog::Accepted) { database->renameCollection(_collection->name(), QtUtils::toStdString(dlg.databaseName())); } }
void ConnectDbDialogWidget::loadSettings() { ConnectionSettings settings; ui->edEventName->setText(settings.eventName()); ui->tabWidget->setCurrentIndex(static_cast<int>(settings.connectionType())); ui->edServerHost->setText(settings.serverHost()); int port = settings.serverPort(); if(port > 0) ui->edServerPort->setValue(port); ui->edServerUser->setText(settings.serverUser()); ui->edServerPassword->setText(settings.serverPassword()); ui->edSingleWorkingDir->setText(settings.singleWorkingDir()); }
void PppUpScriptWriter::fill() { dictionary()->SetValue(OBJECTNAME, QCoreApplication::instance()->objectName().toAscii().constData()); dictionary()->SetValue(GETIPSECINFOLIB, ConfWriter::fileName(ConfWriter::GETIPSECINFO).toAscii().constData()); const ConnectionSettings settings; const int iConnections = settings.connections(); for (int i = 0; i < iConnections; i++) { ctemplate::TemplateDictionary* const pConnection = dictionary()->AddSectionDictionary(CONN_SECTION); const QString strName(settings.connection(i)); if (!strName.isEmpty()) { pConnection->SetValue(IPPARAM, (QCoreApplication::instance()->objectName() + "-" + strName).toAscii().constData()); pConnection->SetValue(GATEWAY, settings.ipsecSettings(strName).gateway().toAscii().constData()); const PppIpSettings ipSetting(settings.pppSettings(strName).ipSettings()); if (!ipSetting.useDefaultGateway()) { ctemplate::TemplateDictionary* const pDefaultRoute = pConnection->AddSectionDictionary(ROUTE_SECTION); pDefaultRoute->SetValue(IPADDRESS, "`echo \"${PPP_LOCAL}\" | cut -d'.' -f1`.0.0.0"); pDefaultRoute->SetValue(IPNETMASK, "255.0.0.0"); const int iRoutes = ipSetting.routes(); for (int j = 0; j < iRoutes; j++) { ctemplate::TemplateDictionary* const pRoute = pConnection->AddSectionDictionary(ROUTE_SECTION); pRoute->SetValue(IPADDRESS, ipSetting.routeAddress(j).toAscii().constData()); pRoute->SetValue(IPNETMASK, ipSetting.routeNetmask(j).toAscii().constData()); } } else pConnection->AddSectionDictionary(DEFAULT_GATEWAY_SECTION); } else addErrorMsg(QObject::tr("No such connection: '%1'.").arg(strName)); } }
void MainWindow::connectToServer(QAction *connectionAction) { QVariant data = connectionAction->data(); ConnectionSettings *ptr = data.value<ConnectionSettings *>(); try { _app->openServer(ptr, true); } catch(const std::exception &) { QString message = QString("Cannot connect to MongoDB (%1)").arg(QtUtils::toQString(ptr->getFullAddress())); QMessageBox::information(this, "Error", message); } }
/** * @brief Initiate 'remove' action, usually when user clicked on Remove button */ void ConnectionsDialog::remove() { ConnectionListWidgetItem *currentItem = (ConnectionListWidgetItem *)_listWidget->currentItem(); // Do nothing if no item selected if (currentItem == 0) return; ConnectionSettings *connectionModel = currentItem->connection(); // Ask user int answer = QMessageBox::question(this, "Connections", QString("Really delete \"%1\" connection?").arg(QtUtils::toQString(connectionModel->getReadableName())), QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton); if (answer != QMessageBox::Yes) return; _settingsManager->removeConnection(connectionModel); }
void ConnectionManager::connectTo(Konversation::ConnectionFlag flag, ConnectionSettings settings) { if (!settings.isValid()) return; emit closeServerList(); if (flag != Konversation::CreateNewConnection && reuseExistingConnection(settings, (flag == Konversation::PromptToReuseConnection))) { return; } IdentityPtr identity = settings.identity(); if (!identity || !validateIdentity(identity)) return; Application* konvApp = static_cast<Application *>(kapp); MainWindow* mainWindow = konvApp->getMainWindow(); Server* server = new Server(this, settings); enlistConnection(server->connectionId(), server); connect(server, SIGNAL(destroyed(int)), this, SLOT(delistConnection(int))); connect(server, SIGNAL(connectionStateChanged(Server*,Konversation::ConnectionState)), this, SLOT(handleConnectionStateChange(Server*,Konversation::ConnectionState))); connect(server, SIGNAL(awayState(bool)), this, SIGNAL(connectionChangedAwayState(bool))); connect(server, SIGNAL(nicksNowOnline(Server*,QStringList,bool)), mainWindow, SLOT(setOnlineList(Server*,QStringList,bool))); connect(server, SIGNAL(awayInsertRememberLine(Server*)), mainWindow, SIGNAL(triggerRememberLines(Server*))); connect(server, SIGNAL(multiServerCommand(QString,QString)), konvApp, SLOT(sendMultiServerCommand(QString,QString))); }
void ServerListDialog::slotOk() { QPtrList<QListViewItem> selected = m_serverList->selectedItems(); ServerListItem * item = static_cast<ServerListItem*>(selected.first()); while (item) { if (item->isServer()) { ConnectionSettings settings; settings.setServerGroup(Preferences::serverGroupById(item->serverGroupId())); settings.setServer(item->server()); emit connectTo(Konversation::PromptToReuseConnection, settings); } else emit connectTo(Konversation::PromptToReuseConnection, item->serverGroupId()); item = static_cast<ServerListItem*>(selected.next()); } }
void ConnectionManager::connectTo(Konversation::ConnectionFlag flag, const QString& target, const QString& port, const QString& password, const QString& nick, const QString& channel, bool useSSL) { ConnectionSettings settings; if (target.startsWith(QLatin1String("irc://")) || target.startsWith(QLatin1String("ircs://"))) decodeIrcUrl(target, settings); else { decodeAddress(target, settings); Konversation::ServerSettings server = settings.server(); if (!port.isEmpty()) server.setPort(port.toInt()); if (!password.isEmpty()) server.setPassword(password); if (useSSL) server.setSSLEnabled(true); settings.setServer(server); if (!nick.isEmpty()) settings.setInitialNick(nick); if (!channel.isEmpty()) { Konversation::ChannelSettings channelSettings(channel); Konversation::ChannelList cl; cl << channelSettings; settings.setOneShotChannelList(cl); } } connectTo(flag, settings); }
void PasswordDialog::setupVpnUi(const ConnectionSettings &connectionSettings) { NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings.setting(Setting::Vpn).dynamicCast<VpnSetting>(); if (!vpnSetting) { qCWarning(PLASMA_NM) << "Missing VPN setting!"; m_hasError = true; m_error = SecretAgent::InternalError; m_errorMessage = QLatin1String("VPN settings are missing"); } else { VpnUiPlugin *vpnUiPlugin; QString error; const QString serviceType = vpnSetting->serviceType(); // qCDebug(PLASMA_NM) << "Agent loading VPN plugin" << serviceType << "from DBUS" << calledFromDBus(); // vpnSetting->printSetting(); vpnUiPlugin = KServiceTypeTrader::createInstanceFromQuery<VpnUiPlugin>(QLatin1String("PlasmaNetworkManagement/VpnUiPlugin"), QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(serviceType), this, QVariantList(), &error); if (vpnUiPlugin && error.isEmpty()) { const QString shortName = serviceType.section('.', -1); setWindowTitle(i18n("VPN secrets (%1)", shortName)); vpnWidget = vpnUiPlugin->askUser(vpnSetting, this); QDialogButtonBox * box; if (shortName != QLatin1String("openconnect")) { box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); connect(box, &QDialogButtonBox::accepted, this, &PasswordDialog::accept); } else { box = new QDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, this); } connect(box, &QDialogButtonBox::rejected, this, &PasswordDialog::reject); QVBoxLayout * layout = new QVBoxLayout(this); layout->addWidget(vpnWidget); layout->addWidget(box); setLayout(layout); } else { qCWarning(PLASMA_NM) << error << ", serviceType == " << serviceType; m_hasError = true; m_error = SecretAgent::InternalError; m_errorMessage = error; } } }
void MainWindow::manageConnections() { ConnectionsDialog dialog(AppRegistry::instance().settingsManager(), this); int result = dialog.exec(); // save settings and update connection menu AppRegistry::instance().settingsManager()->save(); updateConnectionsMenu(); if (result == QDialog::Accepted) { ConnectionSettings *selected = dialog.selectedConnection(); try { _app->openServer(selected, true); } catch(const std::exception &) { QString message = QString("Cannot connect to MongoDB (%1)").arg(QtUtils::toQString(selected->getFullAddress())); QMessageBox::information(this, "Error", message); } } // on linux focus is lost - we need to activate main window back activateWindow(); }
/** * Load settings from the map. Existings settings will be overwritten. */ void SettingsManager::loadFromMap(QVariantMap &map) { // 1. Load version _version = map.value("version").toString(); // 2. Load UUID encoding int encoding = map.value("uuidEncoding").toInt(); if (encoding > 3 || encoding < 0) encoding = 0; _uuidEncoding = (UUIDEncoding) encoding; // 3. Load view mode if (map.contains("viewMode")) { int viewMode = map.value("viewMode").toInt(); if (viewMode > 2 || viewMode < 0) viewMode = Custom; // Default View Mode _viewMode = (ViewMode) viewMode; } else { _viewMode = Custom; // Default View Mode } _autoExpand = map.contains("autoExpand") ? map.value("autoExpand").toBool() : true; _autoExec = map.contains("autoExec") ? map.value("autoExec").toBool() : true; _lineNumbers = map.contains("lineNumbers") ? map.value("lineNumbers").toBool() : false; // 4. Load TimeZone int timeZone = map.value("timeZone").toInt(); if (timeZone > 1 || timeZone < 0) timeZone = 0; _timeZone = (SupportedTimes) timeZone; _loadMongoRcJs = map.value("loadMongoRcJs").toBool(); _disableConnectionShortcuts = map.value("disableConnectionShortcuts").toBool(); // Load AutocompletionMode if (map.contains("autocompletionMode")) { int autocompletionMode = map.value("autocompletionMode").toInt(); if (autocompletionMode < 0 || autocompletionMode > 2) autocompletionMode = AutocompleteAll; // Default Mode _autocompletionMode = (AutocompletionMode) autocompletionMode; } else { _autocompletionMode = AutocompleteAll; // Default Mode } // Load Batch Size _batchSize = map.value("batchSize").toInt(); if (_batchSize == 0) _batchSize = 50; _currentStyle = map.value("style").toString(); if (_currentStyle.isEmpty()) { _currentStyle = AppStyle::StyleName; } // Load font information _textFontFamily = map.value("textFontFamily").toString(); _textFontPointSize = map.value("textFontPointSize").toInt(); if (map.contains("mongoTimeoutSec")) { _mongoTimeoutSec = map.value("mongoTimeoutSec").toInt(); } if (map.contains("shellTimeoutSec")) { _shellTimeoutSec = map.value("shellTimeoutSec").toInt(); } // 5. Load connections _connections.clear(); QVariantList list = map.value("connections").toList(); for (QVariantList::iterator it = list.begin(); it != list.end(); ++it) { ConnectionSettings *record = new ConnectionSettings(); record->fromVariant((*it).toMap()); _connections.push_back(record); } _toolbars = map.value("toolbars").toMap(); ToolbarSettingsContainerType::const_iterator it = _toolbars.find("connect"); if (_toolbars.end() == it) _toolbars["connect"] = true; it = _toolbars.find("open_save"); if (_toolbars.end() == it) _toolbars["open_save"] = true; it = _toolbars.find("exec"); if (_toolbars.end() == it) _toolbars["exec"] = true; it = _toolbars.find("explorer"); if (_toolbars.end() == it) _toolbars["explorer"] = true; it = _toolbars.find("logs"); if (_toolbars.end() == it) _toolbars["logs"] = false; }
void ConnectionManager::connectTo(Konversation::ConnectionFlag flag, const QList<KUrl>& list) { QMap<QString,Konversation::ChannelList> serverChannels; QMap<QString,ConnectionSettings> serverConnections; QList<KUrl>::ConstIterator it = list.constBegin(); QList<KUrl>::ConstIterator end = list.constEnd(); for (; it != end; ++it) { ConnectionSettings settings; decodeIrcUrl(it->url(), settings); kDebug() << settings.name() << " - " << settings.server().host() << settings.server().port() << settings.server().password() << " - " << (settings.serverGroup()?settings.serverGroup()->name():""); QString sname = (settings.serverGroup() ? settings.serverGroup()->name() : (QString(settings.server().host()) + QString(':') + QString(settings.server().port()))); if (!serverChannels.contains(sname)) serverConnections[sname] = settings; serverChannels[sname] += settings.oneShotChannelList(); } // Perform the connection. QMap<QString,Konversation::ChannelList>::ConstIterator s_i = serverChannels.constBegin(); for (; s_i != serverChannels.constEnd(); ++s_i) { serverConnections[s_i.key()].setOneShotChannelList(s_i.value()); connectTo(flag, serverConnections[s_i.key()]); } }
bool ConnectionManager::reuseExistingConnection(ConnectionSettings& settings, bool interactive) { Server* dupe = 0; ConnectionDupe dupeType; bool doReuse = true; Application* konvApp = static_cast<Application *>(kapp); MainWindow* mainWindow = konvApp->getMainWindow(); QMap<int, Server*>::ConstIterator it; for (it = m_connectionList.constBegin(); it != m_connectionList.constEnd(); ++it) { if (it.value()->getServerGroup() && settings.serverGroup() && it.value()->getServerGroup() == settings.serverGroup()) { dupe = it.value(); dupeType = SameServerGroup; break; } } if (!dupe) { for (it = m_connectionList.constBegin(); it != m_connectionList.constEnd(); ++it) { if (it.value()->getConnectionSettings().server() == settings.server()) { dupe = it.value(); dupeType = SameServer; break; } } } if (dupe && interactive) { int result = KMessageBox::warningContinueCancel( mainWindow, i18n("You are already connected to %1. Do you want to open another connection?", dupe->getDisplayName()), i18n("Already connected to %1", dupe->getDisplayName()), KGuiItem(i18n("Create connection")), KStandardGuiItem::cancel(), QString("ReuseExistingConnection")); if (result == KMessageBox::Continue) doReuse = false; } if (dupe && doReuse) { if (interactive && dupeType == SameServerGroup && !(dupe->getConnectionSettings().server() == settings.server())) { int result = KMessageBox::warningContinueCancel( mainWindow, i18n("You are presently connected to %1 via '%2' (port <numid>%3</numid>). Do you want to switch to '%4' (port <numid>%5</numid>) instead?", dupe->getDisplayName(), dupe->getServerName(), dupe->getPort(), settings.server().host(), settings.server().port()), i18n("Already connected to %1", dupe->getDisplayName()), KGuiItem(i18n("Switch Server")), KStandardGuiItem::cancel(), "ReconnectWithDifferentServer"); if (result == KMessageBox::Continue) { dupe->disconnectServer(); dupe->setConnectionSettings(settings); } } if (!dupe->isConnected()) { if (!settings.oneShotChannelList().isEmpty()) dupe->updateAutoJoin(settings.oneShotChannelList()); if (!dupe->isConnecting()) dupe->reconnectServer(); } else { if (!settings.oneShotChannelList().isEmpty()) { Konversation::ChannelList::ConstIterator it = settings.oneShotChannelList().constBegin(); Konversation::ChannelList::ConstIterator itend = settings.oneShotChannelList().constEnd(); for ( ; it != itend; ++it ) { dupe->sendJoinCommand((*it).name(), (*it).password()); } settings.clearOneShotChannelList(); } } } return (dupe && doReuse); }