Ejemplo n.º 1
0
bool ClusterDialog::validateAndApply() {
  QVariant var = typeConnection_->currentData();
  core::connectionTypes currentType =
      static_cast<core::connectionTypes>(qvariant_cast<unsigned char>(var));

  std::string conName = common::ConvertToString(connectionName_->text());
  std::string conFolder = common::ConvertToString(connectionFolder_->text());
  if (conFolder.empty()) {
    conFolder = defaultNameConnectionFolder;
  }
  core::connection_path_t path(common::file_system::stable_dir_path(conFolder) + conName);
  core::IClusterSettingsBase* newConnection =
      core::ClusterConnectionSettingsFactory::instance().CreateFromType(currentType, path);
  if (newConnection) {
    cluster_connection_.reset(newConnection);
    if (logging_->isChecked()) {
      cluster_connection_->SetLoggingMsTimeInterval(loggingMsec_->value());
    }
    for (int i = 0; i < listWidget_->topLevelItemCount(); ++i) {
      ConnectionListWidgetItem* item =
          dynamic_cast<ConnectionListWidgetItem*>(listWidget_->topLevelItem(i));  // +
      if (item) {
        core::IConnectionSettingsBaseSPtr con = item->connection();
        cluster_connection_->AddNode(con);
      }
    }
  }
  return true;
}
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    /**
     * @brief Handles ListWidget layoutChanged() signal
     */
    void ConnectionsDialog::listWidget_layoutChanged()
    {
        int count = _listWidget->topLevelItemCount();

        // Make childrens toplevel again. This is a bad, but quickiest item reordering
        // implementation.
        for(int i = 0; i < count; i++)
        {
            ConnectionListWidgetItem * item = (ConnectionListWidgetItem *) _listWidget->topLevelItem(i);
            if (item->childCount() > 0) {
                ConnectionListWidgetItem *childItem = (ConnectionListWidgetItem *) item->child(0);
                item->removeChild(childItem);
                _listWidget->insertTopLevelItem(++i, childItem);
                _listWidget->setCurrentItem(childItem);
                break;
            }
        }

        count = _listWidget->topLevelItemCount();
        SettingsManager::ConnectionSettingsContainerType items;
        for(int i = 0; i < count; i++)
        {
            ConnectionListWidgetItem * item = (ConnectionListWidgetItem *) _listWidget->topLevelItem(i);
            items.push_back(item->connection());
        }

        _settingsManager->reorderConnections(items);
    }
Ejemplo n.º 4
0
    /**
     * @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();
    }
Ejemplo n.º 5
0
    /**
     * @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;
            }
        }        
    }
Ejemplo n.º 6
0
void ClusterDialog::setStartNode() {
  ConnectionListWidgetItem* currentItem = dynamic_cast<ConnectionListWidgetItem*>(list_widget_->currentItem());  // +

  // Do nothing if no item selected
  if (!currentItem) {
    return;
  }

  ConnectionListWidgetItem* top = dynamic_cast<ConnectionListWidgetItem*>(list_widget_->topLevelItem(0));  // +
  if (top == currentItem) {
    return;
  }

  proxy::IConnectionSettingsBaseSPtr tc = top->connection();
  proxy::IConnectionSettingsBaseSPtr cc = currentItem->connection();
  currentItem->setConnection(tc);
  top->setConnection(cc);
}
Ejemplo n.º 7
0
    IConnectionSettingsBaseSPtr ConnectionsDialog::selectedConnection() const
    {
        ConnectionListWidgetItem *currentItem = dynamic_cast<ConnectionListWidgetItem *>(listWidget_->currentItem());
        if (currentItem){
            return currentItem->connection();
        }

        return IConnectionSettingsBaseSPtr();
    }
Ejemplo n.º 8
0
void ClusterDialog::testConnection() {
  ConnectionListWidgetItem* currentItem = dynamic_cast<ConnectionListWidgetItem*>(list_widget_->currentItem());  // +

  // Do nothing if no item selected
  if (!currentItem) {
    return;
  }

  ConnectionDiagnosticDialog diag(this, currentItem->connection());
  diag.exec();
}
Ejemplo n.º 9
0
    /**
     * @brief This function is called when user clicks on "Connect" button.
     */
    void ConnectionsDialog::accept()
    {
        ConnectionListWidgetItem *currentItem = (ConnectionListWidgetItem *) _listWidget->currentItem();

        // Do nothing if no item selected
        if (currentItem == 0)
            return;

        _selectedConnection = currentItem->connection();

        close();
        QDialog::accept();
    }
Ejemplo n.º 10
0
    void ConnectionsDialog::remove()
    {
        QTreeWidgetItem* qitem = listWidget_->currentItem();
        if(!qitem){
            return;
        }

        ConnectionListWidgetItem* currentItem = dynamic_cast<ConnectionListWidgetItem *>(qitem);
        if(currentItem){

            QTreeWidgetItem* qpitem = qitem->parent();
            if(!qpitem){
                // Ask user
                int answer = QMessageBox::question(this, "Connections", QString("Really delete \"%1\" connection?").arg(currentItem->text(0)),
                                                   QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton);

                if (answer != QMessageBox::Yes)
                    return;

                IConnectionSettingsBaseSPtr connection = currentItem->connection();
                delete currentItem;
                SettingsManager::instance().removeConnection(connection);
                return;
            }
            else{
                qitem = qpitem;
            }
        }

        ClusterConnectionListWidgetItem* clCurrentItem = dynamic_cast<ClusterConnectionListWidgetItem *>(qitem);
        if(clCurrentItem){

            // Ask user
            int answer = QMessageBox::question(this, "Connections", QString("Really delete \"%1\" cluster?").arg(clCurrentItem->text(0)),
                                               QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton);

            if (answer != QMessageBox::Yes)
                return;

            IClusterSettingsBaseSPtr connection = clCurrentItem->connection();
            delete clCurrentItem;
            SettingsManager::instance().removeCluster(connection);
        }
    }
Ejemplo n.º 11
0
void ClusterDialog::edit() {
  ConnectionListWidgetItem* currentItem = dynamic_cast<ConnectionListWidgetItem*>(list_widget_->currentItem());  // +

  // Do nothing if no item selected
  if (!currentItem) {
    return;
  }

#ifdef BUILD_WITH_REDIS
  proxy::IConnectionSettingsBaseSPtr oldConnection = currentItem->connection();
  ConnectionDialog dlg(oldConnection->Clone(), this);
  dlg.setFolderEnabled(false);
  int result = dlg.exec();
  proxy::IConnectionSettingsBaseSPtr newConnection = dlg.connection();
  if (result == QDialog::Accepted && newConnection) {
    currentItem->setConnection(newConnection);
  }
#endif
}
Ejemplo n.º 12
0
    void ConnectionsDialog::edit()
    {
        QTreeWidgetItem* qitem = listWidget_->currentItem();
        if(!qitem){
            return;
        }

        ConnectionListWidgetItem* currentItem = dynamic_cast<ConnectionListWidgetItem *>(qitem);
        if(currentItem){
            QTreeWidgetItem* qpitem = qitem->parent();
            if(!qpitem){
                IConnectionSettingsBaseSPtr con = currentItem->connection();
                ConnectionDialog dlg(this, dynamic_cast<IConnectionSettingsBase*>(con->clone()));
                int result = dlg.exec();
                IConnectionSettingsBaseSPtr newConnection = dlg.connection();
                if(result == QDialog::Accepted && newConnection){
                    currentItem->setConnection(newConnection);
                    SettingsManager::instance().removeConnection(con);
                    SettingsManager::instance().addConnection(newConnection);
                }
                return;
            }
            else{
                qitem = qpitem;
            }
        }


        ClusterConnectionListWidgetItem* clCurrentItem = dynamic_cast<ClusterConnectionListWidgetItem *>(qitem);
        if(clCurrentItem){
            IClusterSettingsBaseSPtr con = clCurrentItem->connection();
            ClusterDialog dlg(this, dynamic_cast<IClusterSettingsBase*>(con->clone()));
            int result = dlg.exec();
            IClusterSettingsBaseSPtr newConnection = dlg.connection();
            if(result == QDialog::Accepted && newConnection){
                clCurrentItem->setConnection(newConnection);
                SettingsManager::instance().removeCluster(con);
                SettingsManager::instance().addCluster(newConnection);
            }
        }
    }
Ejemplo n.º 13
0
    /**
     * @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);
    }
Ejemplo n.º 14
0
void ClusterDialog::discoveryCluster() {
  ConnectionListWidgetItem* currentItem = dynamic_cast<ConnectionListWidgetItem*>(list_widget_->currentItem());  // +

  // Do nothing if no item selected
  if (!currentItem) {
    return;
  }

  if (!validateAndApply()) {
    return;
  }

  DiscoveryClusterDiagnosticDialog diag(this, currentItem->connection(), cluster_connection_);
  int result = diag.exec();
  if (result == QDialog::Accepted) {
    std::vector<ConnectionListWidgetItemDiscovered*> conns = diag.selectedConnections();
    for (size_t i = 0; i < conns.size(); ++i) {
      proxy::IConnectionSettingsBaseSPtr it = conns[i]->connection();
      addConnection(it);
    }
  }
}