Add Remove Only Selected in Network Keyring.

This commit is contained in:
Phenom 2020-11-24 15:48:56 +01:00
parent bcafd06748
commit 457206272c
3 changed files with 37 additions and 13 deletions

View File

@ -133,21 +133,22 @@ void NetworkDialog::connectTreeWidgetCostumPopupMenu( QPoint /*point*/ )
contextMnu->addAction(QIcon(IMAGE_PEERDETAILS), tr("Profile details..."), this, SLOT(peerdetails())); contextMnu->addAction(QIcon(IMAGE_PEERDETAILS), tr("Profile details..."), this, SLOT(peerdetails()));
contextMnu->addSeparator() ; contextMnu->addSeparator() ;
contextMnu->addAction(QIcon(), tr("Remove unused keys..."), this, SLOT(removeUnusedKeys())); contextMnu->addAction(QIcon(), tr("Remove unused keys..."), this, SLOT(removeUnusedKeys()));
contextMnu->addAction(QIcon(), tr("Remove this key"), this, SLOT(removeSelectedKeys()));
contextMnu->exec(QCursor::pos()); contextMnu->exec(QCursor::pos());
} }
void NetworkDialog::removeUnusedKeys() void NetworkDialog::removeUnusedKeys()
{ {
std::set<RsPgpId> pre_selected ; std::set<RsPgpId> pre_selected ;
std::list<RsPgpId> ids ; std::list<RsPgpId> ids ;
rsPeers->getGPGAllList(ids) ; rsPeers->getGPGAllList(ids) ;
RsPeerDetails details ; RsPeerDetails details ;
time_t now = time(NULL) ; time_t now = time(NULL) ;
time_t THREE_MONTHS = 3*31*24*60*60 ;//3*DayPerMonth*HoursPerDay*MinPerHour*SecPerMin time_t THREE_MONTHS = 3*31*24*60*60 ;//3*DayPerMonth*HoursPerDay*MinPerHour*SecPerMin
for(std::list<RsPgpId>::const_iterator it(ids.begin());it!=ids.end();++it) for(std::list<RsPgpId>::const_iterator it(ids.begin());it!=ids.end();++it)
{ {
rsPeers->getGPGDetails(*it,details) ; rsPeers->getGPGDetails(*it,details) ;
@ -159,17 +160,34 @@ void NetworkDialog::removeUnusedKeys()
if(now > (time_t) (THREE_MONTHS + details.lastUsed) && !details.accept_connection) if(now > (time_t) (THREE_MONTHS + details.lastUsed) && !details.accept_connection)
{ {
std::cerr << "Adding " << *it << " to pre-selection." << std::endl; std::cerr << "Adding " << *it << " to pre-selection." << std::endl;
pre_selected.insert(*it) ; pre_selected.insert(*it) ;
} }
} }
std::set<RsPgpId> selected = FriendSelectionDialog::selectFriends_PGP(NULL, std::set<RsPgpId> selected = FriendSelectionDialog::selectFriends_PGP(NULL,
tr("Clean keyring"), tr("Clean keyring"),
tr("The selected keys below haven't been used in the last 3 months. \nDo you want to delete them permanently ? \n\nNotes: Your old keyring will be backed up.\n The removal may fail when running multiple Retroshare instances on the same machine."),FriendSelectionWidget::MODUS_CHECK,FriendSelectionWidget::SHOW_GPG | FriendSelectionWidget::SHOW_NON_FRIEND_GPG, tr("The selected keys below haven't been used in the last 3 months. \nDo you want to delete them permanently ? \n\nNotes: Your old keyring will be backed up.\n The removal may fail when running multiple Retroshare instances on the same machine."),FriendSelectionWidget::MODUS_CHECK,FriendSelectionWidget::SHOW_GPG | FriendSelectionWidget::SHOW_NON_FRIEND_GPG,
pre_selected) ; pre_selected) ;
removeKeys(selected);
}
void NetworkDialog::removeSelectedKeys()
{
QModelIndexList l = ui.connectTreeWidget->selectionModel()->selection().indexes();
if(l.empty())
return;
std::set<RsPgpId> selected;
selected.insert(RsPgpId(ui.connectTreeWidget->model()->data(ui.connectTreeWidget->model()->index(l.begin()->row(), COLUMN_PEERID)).toString().toStdString()));
removeKeys(selected);
}
void NetworkDialog::removeKeys(std::set<RsPgpId> selected)
{
std::cerr << "Removing these keys from the keyring: " << std::endl; std::cerr << "Removing these keys from the keyring: " << std::endl;
for(std::set<RsPgpId>::const_iterator it(selected.begin());it!=selected.end();++it) for(std::set<RsPgpId>::const_iterator it(selected.begin());it!=selected.end();++it)
std::cerr << " " << *it << std::endl; std::cerr << " " << *it << std::endl;
std::string backup_file ; std::string backup_file ;
@ -200,7 +218,7 @@ void NetworkDialog::removeUnusedKeys()
} }
QMessageBox::warning(NULL,tr("Keyring info"),tr("Key removal has failed. Your keyring remains intact.\n\nReported error:")+" "+error_string ) ; QMessageBox::warning(NULL,tr("Keyring info"),tr("Key removal has failed. Your keyring remains intact.\n\nReported error:")+" "+error_string ) ;
} }
updateDisplay(); updateDisplay();
// insertConnect() ; // insertConnect() ;
} }

View File

@ -68,6 +68,7 @@ protected:
private slots: private slots:
void removeUnusedKeys() ; void removeUnusedKeys() ;
void removeSelectedKeys() ;
void makeFriend() ; void makeFriend() ;
void denyFriend() ; void denyFriend() ;
void peerdetails(); void peerdetails();
@ -86,6 +87,8 @@ private slots:
private: private:
void removeKeys(std::set<RsPgpId> selected) ;
/* Color definitions (for standard see qss.default) */ /* Color definitions (for standard see qss.default) */
QColor mBackgroundColorSelf; QColor mBackgroundColorSelf;
QColor mBackgroundColorOwnSign; QColor mBackgroundColorOwnSign;

View File

@ -185,7 +185,7 @@ int FriendSelectionWidget::addColumn(const QString &title)
return column; return column;
} }
void FriendSelectionWidget::showEvent(QShowEvent *e) void FriendSelectionWidget::showEvent(QShowEvent */*e*/)
{ {
if(gxsIds.empty()) if(gxsIds.empty())
loadIdentities(); loadIdentities();
@ -838,6 +838,9 @@ void FriendSelectionWidget::contextMenuRequested(const QPoint &/*pos*/)
contextMenu->addAction(QIcon(), tr("Mark all"), this, SLOT(selectAll())); contextMenu->addAction(QIcon(), tr("Mark all"), this, SLOT(selectAll()));
contextMenu->addAction(QIcon(), tr("Mark none"), this, SLOT(deselectAll())); contextMenu->addAction(QIcon(), tr("Mark none"), this, SLOT(deselectAll()));
} }
if (mListModus == MODUS_CHECK) {
contextMenu->addAction(QIcon(), tr("Mark none"), this, SLOT(deselectAll()));
}
if (!mContextMenuActions.isEmpty()) { if (!mContextMenuActions.isEmpty()) {
bool addSeparator = false; bool addSeparator = false;