mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Improve/simplify item import
Unify import functions for some (on_butImport_clicked) or all (on_butOk_clicked) items. They both call "importIndexes(const QModelIndexList &indexes)" containing some or all indexes to import. db_x509.cpp: Only need to search the treeItem (containing all items without issuer, not all in the rootItem (containing also certificates with known issuer) Re-use "remFromCont()" when stealing items from an other CA.
This commit is contained in:
parent
1176a35fa7
commit
061f676041
@ -300,15 +300,8 @@ void db_base::insertChild(pki_base *child, pki_base *parent)
|
||||
if (!parent || parent == child)
|
||||
parent = treeItem;
|
||||
|
||||
if (curr_parent) {
|
||||
/* Need to take it */
|
||||
if (curr_parent != treeItem && treeview)
|
||||
idx = index(curr_parent);
|
||||
int row = rownumber(child);
|
||||
beginRemoveRows(idx, row, row);
|
||||
curr_parent->takeChild(child);
|
||||
endRemoveRows();
|
||||
}
|
||||
if (curr_parent)
|
||||
remFromCont(index(child));
|
||||
|
||||
if (parent != treeItem && treeview)
|
||||
idx = index(parent);
|
||||
|
||||
@ -75,10 +75,10 @@ class db_base: public QAbstractItemModel
|
||||
|
||||
void dump(const QString &dirname) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent) const;
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex index(pki_base *pki) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int allItemsCount() const
|
||||
{
|
||||
return rootItem->childCount();
|
||||
|
||||
@ -192,7 +192,7 @@ void db_x509::inToCont(pki_base *pki)
|
||||
revList.merge(other->getRevList());
|
||||
}
|
||||
/* Search rootItem childs, whether they are ours */
|
||||
foreach(pki_base *b, rootItem->getChildItems()) {
|
||||
foreach(pki_base *b, treeItem->getChildItems()) {
|
||||
pki_x509 *child = dynamic_cast<pki_x509*>(b);
|
||||
if (!child || child == cert || child->getSigner() == child)
|
||||
continue;
|
||||
|
||||
@ -163,34 +163,32 @@ void ImportMulti::on_butRemove_clicked()
|
||||
|
||||
void ImportMulti::on_butOk_clicked()
|
||||
{
|
||||
if (!openDB())
|
||||
return;
|
||||
QModelIndexList indexes;
|
||||
|
||||
Transaction;
|
||||
if (!TransBegin())
|
||||
return;
|
||||
for (int i = 0; i < mcont->rowCount(); i++)
|
||||
indexes << mcont->index(i, 0, QModelIndex());
|
||||
|
||||
while (mcont->rowCount(QModelIndex()))
|
||||
import(mcont->index(0, 0, QModelIndex()));
|
||||
|
||||
TransCommit();
|
||||
importIndexes(indexes);
|
||||
accept();
|
||||
}
|
||||
|
||||
void ImportMulti::on_butImport_clicked()
|
||||
{
|
||||
QItemSelectionModel *selectionModel = listView->selectionModel();
|
||||
QModelIndexList indexes = selectionModel->selectedIndexes();
|
||||
|
||||
importIndexes(selectionModel->selectedIndexes());
|
||||
}
|
||||
|
||||
void ImportMulti::importIndexes(const QModelIndexList &indexes)
|
||||
{
|
||||
if (!openDB())
|
||||
return;
|
||||
|
||||
Transaction;
|
||||
if (!TransBegin())
|
||||
return;
|
||||
|
||||
foreach(QModelIndex index, indexes) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
import(index);
|
||||
}
|
||||
TransCommit();
|
||||
@ -237,6 +235,9 @@ pki_base *ImportMulti::import(const QModelIndex &idx)
|
||||
{
|
||||
pki_base *pki = mcont->fromIndex(idx);
|
||||
|
||||
if (idx.column() != 0)
|
||||
return NULL;
|
||||
|
||||
for (int i = 0; i < mcont->rowCount(idx); i++)
|
||||
import(mcont->index(i, 0, idx));
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ class ImportMulti: public QDialog, private Ui::ImportMulti
|
||||
void addItem(pki_base *pki);
|
||||
pki_base *getSelected();
|
||||
pki_base *import(const QModelIndex &idx);
|
||||
void importIndexes(const QModelIndexList &indexes);
|
||||
void execute(int force=0, QStringList failed = QStringList());
|
||||
int entries();
|
||||
void tokenInfo(const slotid &s);
|
||||
@ -45,7 +46,6 @@ class ImportMulti: public QDialog, private Ui::ImportMulti
|
||||
void on_butOk_clicked();
|
||||
void on_deleteToken_clicked();
|
||||
void on_renameToken_clicked();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user