Ejemplo n.º 1
0
    void ExplorerTreeModel::setDefaultDb(IServer* server, DataBaseInfoSPtr db)
    {
        ExplorerServerItem *parent = findServerItem(server);
        DCHECK(parent);
        if(!parent){
            return;
        }

        int child_count = parent->childrenCount();
        for(int i = 0; i < child_count ; ++i){
            ExplorerDatabaseItem *item = dynamic_cast<ExplorerDatabaseItem*>(parent->child(i));
            DCHECK(item);
            if(!item){
                continue;
            }

            DataBaseInfoSPtr info = item->info();
            if(info->isDefault()){
                if(info->name() != db->name()){
                    info->setIsDefault(false);
                    updateItem(createIndex(i,0,parent), createIndex(i,0,parent));
                }
            }
            else{
                if(info->name() == db->name()){
                    info->setIsDefault(true);
                    updateItem(createIndex(i,0,parent), createIndex(i,0,parent));
                }
            }
        }
    }
Ejemplo n.º 2
0
 void ExplorerKeyItem::loadValueFromDb()
 {
     ExplorerDatabaseItem* par = parent();
     if(par){
         par->loadValue(key_);
     }
 }
Ejemplo n.º 3
0
 void ExplorerKeyItem::removeFromDb()
 {
     ExplorerDatabaseItem* par = parent();
     if(par){
         par->removeKey(key_);
     }
 }
Ejemplo n.º 4
0
    IServerSPtr ExplorerKeyItem::server() const
    {
        ExplorerDatabaseItem* db = dynamic_cast<ExplorerDatabaseItem*>(parent_);
        if(!db){
            return IServerSPtr();
        }

        return db->server();
    }
Ejemplo n.º 5
0
    void ExplorerTreeView::setDefaultDb()
    {
        QModelIndex sel = selectedIndex();
        if(!sel.isValid()){
            return;
        }

        ExplorerDatabaseItem *node = common::utils_qt::item<ExplorerDatabaseItem*>(sel);
        if(node){
            node->setDefault();
        }
    }
Ejemplo n.º 6
0
    void ExplorerTreeView::viewKeys()
    {
        QModelIndex sel = selectedIndex();
        if(!sel.isValid()){
            return;
        }

        ExplorerDatabaseItem* node = common::utils_qt::item<ExplorerDatabaseItem*>(sel);
        if(node){
            ViewKeysDialog diag(QString("View key in %1 database").arg(node->name()), node->db(), this);
            diag.exec();
        }
    }
Ejemplo n.º 7
0
    void ExplorerTreeView::loadContentDb()
    {
        QModelIndex sel = selectedIndex();
        if(!sel.isValid()){
            return;
        }

        ExplorerDatabaseItem *node = common::utils_qt::item<ExplorerDatabaseItem*>(sel);
        if(node){
            LoadContentDbDialog loadDb(QString("Load %1 content").arg(node->name()), node->server()->type(), this);
            int result = loadDb.exec();
            if(result == QDialog::Accepted){
                node->loadContent(common::convertToString(loadDb.pattern()), loadDb.count());
            }
        }
    }
Ejemplo n.º 8
0
    ExplorerDatabaseItem *ExplorerTreeModel::findDatabaseItem(ExplorerServerItem* server, DataBaseInfoSPtr db) const
    {
        if(server){
            for(int i = 0; i < server->childrenCount() ; ++i){
                ExplorerDatabaseItem *item = dynamic_cast<ExplorerDatabaseItem*>(server->child(i));
                DCHECK(item);
                if(!item){
                    continue;
                }

                IDatabaseSPtr inf = item->db();
                if(inf && inf->name() == db->name()){
                    return item;
                }
            }
        }
        return NULL;
    }
Ejemplo n.º 9
0
    void ExplorerTreeView::createKey()
    {
        QModelIndex sel = selectedIndex();
        if(!sel.isValid()){
            return;
        }

        ExplorerDatabaseItem *node = common::utils_qt::item<ExplorerDatabaseItem*>(sel);
        if(node){
            CreateDbKeyDialog loadDb(QString("Create key for %1 database").arg(node->name()), node->server()->type(), this);
            int result = loadDb.exec();
            if(result == QDialog::Accepted){
                FastoObjectIPtr val = loadDb.value();
                NKey key = loadDb.key();
                node->createKey(key, val);
            }
        }
    }
Ejemplo n.º 10
0
    QVariant ExplorerTreeModel::data(const QModelIndex& index, int role) const
    {
        if (!index.isValid()){
            return QVariant();
        }

        IExplorerTreeItem* node = common::utils_qt::item<IExplorerTreeItem*>(index);

        if (!node){
            return QVariant();
        }

        int col = index.column();

        IExplorerTreeItem::eType t = node->type();

        if(role == Qt::ToolTipRole){
            IServerSPtr serv = node->server();
            if(t == IExplorerTreeItem::eServer && serv){
                ServerDiscoveryInfoSPtr disc = serv->discoveryInfo();
                if(disc){
                    QString dname = common::convertFromString<QString>(disc->name());
                    QString dtype = common::convertFromString<QString>(common::convertToString(disc->type()));
                    QString dhost = common::convertFromString<QString>(common::convertToString(disc->host()));
                    return QString("<b>Name:</b> %1<br/>"
                                   "<b>Type:</b> %2<br/>"
                                   "<b>Host:</b> %3<br/>").arg(dname).arg(dtype).arg(dhost);
                }
            }
            else if(t == IExplorerTreeItem::eDatabase){
                ExplorerDatabaseItem* db = dynamic_cast<ExplorerDatabaseItem*>(node);
                if(db && db->isDefault()){
                    return QString("<b>Db size:</b> %1 keys<br/>").arg(db->size());
                }
            }
        }

        if(role == Qt::DecorationRole && col == ExplorerServerItem::eName ){
            if(t == IExplorerTreeItem::eCluster){
                return GuiFactory::instance().clusterIcon();
            }
            else if(t == IExplorerTreeItem::eServer){
                return GuiFactory::instance().icon(node->server()->type());
            }
            else if(t == IExplorerTreeItem::eKey){
                return GuiFactory::instance().keyIcon();
            }
            else if(t == IExplorerTreeItem::eDatabase){
                return GuiFactory::instance().databaseIcon();
            }
            else{
                NOTREACHED();
            }
        }

        if (role == Qt::DisplayRole) {
            if (col == IExplorerTreeItem::eName) {
                if(t == IExplorerTreeItem::eKey){
                    return node->name();
                }
                else{
                    return QString("%1 (%2)").arg(node->name()).arg(node->childrenCount());
                }
            }
        }

        if(role == Qt::ForegroundRole){
            if(t == IExplorerTreeItem::eDatabase){
                ExplorerDatabaseItem* db = dynamic_cast<ExplorerDatabaseItem*>(node);
                if(db && db->isDefault()){
                    return QVariant( QColor( Qt::red ) );
                }
            }
        }

        return QVariant();
    }
Ejemplo n.º 11
0
    void ExplorerTreeView::showContextMenu(const QPoint& point)
    {
        QPoint menuPoint = mapToGlobal(point);
        menuPoint.setY(menuPoint.y() + header()->height());

        QModelIndex sel = selectedIndex();
        if(sel.isValid()){            
            IExplorerTreeItem *node = common::utils_qt::item<IExplorerTreeItem*>(sel);
            DCHECK(node);
            if(!node){
                return;
            }

            if(node->type() == IExplorerTreeItem::eCluster){
                QMenu menu(this);
                closeClusterAction_->setEnabled(true);
                menu.addAction(closeClusterAction_);
                menu.exec(menuPoint);
            }
            else if(node->type() == IExplorerTreeItem::eServer){
                QMenu menu(this);                
                menu.addAction(connectAction_);
                menu.addAction(openConsoleAction_);

                IServerSPtr server = node->server();
                bool isCon = server->isConnected();
                bool isAuth = server->isAuthenticated();

                bool isClusterMember = dynamic_cast<ExplorerClusterItem*>(node->parent()) != NULL;

                loadDatabaseAction_->setEnabled(isAuth);
                menu.addAction(loadDatabaseAction_);
                infoServerAction_->setEnabled(isAuth);
                menu.addAction(infoServerAction_);
                propertyServerAction_->setEnabled(isAuth);
                menu.addAction(propertyServerAction_);

                setServerPassword_->setEnabled(isAuth);
                menu.addAction(setServerPassword_);

                setMaxClientConnection_->setEnabled(isAuth);
                menu.addAction(setMaxClientConnection_);

                menu.addAction(historyServerAction_);
                closeServerAction_->setEnabled(!isClusterMember);
                menu.addAction(closeServerAction_);

                bool isLocal = server->isLocalHost();

                importAction_->setEnabled(!isCon && isLocal);
                menu.addAction(importAction_);                
                backupAction_->setEnabled(isCon && isLocal);
                menu.addAction(backupAction_);
                shutdownAction_->setEnabled(isAuth);
                menu.addAction(shutdownAction_);

                menu.exec(menuPoint);
            }
            else if(node->type() == IExplorerTreeItem::eDatabase){
                ExplorerDatabaseItem *db = dynamic_cast<ExplorerDatabaseItem*>(node);
                QMenu menu(this);
                menu.addAction(loadContentAction_);
                bool isDefault = db && db->isDefault();
                loadContentAction_->setEnabled(isDefault);

                menu.addAction(createKeyAction_);
                createKeyAction_->setEnabled(isDefault);

                if(isDefault){
                    menu.addAction(viewKeysAction_);
                }

                menu.addAction(setDefaultDbAction_);
                setDefaultDbAction_->setEnabled(!isDefault);
                menu.exec(menuPoint);
            }
            else if(node->type() == IExplorerTreeItem::eKey){
                QMenu menu(this);
                menu.addAction(getValueAction_);
                menu.addAction(deleteKeyAction_);
                menu.exec(menuPoint);
            }
        }
    }