File indexing completed on 2024-05-19 05:55:46
0001 /* 0002 SPDX-FileCopyrightText: 2013 Valentin Rusu <kde@rusu.info> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "authorizedapplicationstable.h" 0008 #include "authorizedappmodel.h" 0009 #include "revokeauthbutton.h" 0010 0011 AuthorizedApplicationsTable::AuthorizedApplicationsTable(QWidget *parent) : 0012 QTableView(parent) 0013 { 0014 } 0015 0016 void AuthorizedApplicationsTable::setWallet(KWallet::Wallet *wallet) 0017 { 0018 _wallet = wallet; 0019 } 0020 0021 void AuthorizedApplicationsTable::setModel(QAbstractItemModel *model) 0022 { 0023 Q_ASSERT(_wallet != nullptr); 0024 0025 auto appModel = qobject_cast<AuthorizedAppModel *>(model); 0026 Q_ASSERT(appModel != nullptr); 0027 0028 QTableView::setModel(model); 0029 const int numberRow(model->rowCount()); 0030 for (int row = 0; row < numberRow; row++) { 0031 auto btn = new RevokeAuthButton(model->index(row, 0).data().toString(), _wallet); 0032 btn->setFixedHeight(btn->sizeHint().height()); 0033 setRowHeight(row, btn->height()); 0034 setIndexWidget(model->index(row, 1), btn); 0035 connect(btn, &RevokeAuthButton::appRevoked, appModel, &AuthorizedAppModel::removeApp); 0036 } 0037 } 0038 0039 void AuthorizedApplicationsTable::resizeEvent(QResizeEvent *resizeEvent) 0040 { 0041 // this will keep disconnect buttons column at it's minimum size and 0042 // make the application names take the reminder of the horizontal space 0043 resizeColumnsToContents(); 0044 const int appColumnSize = contentsRect().width() - columnWidth(1) - 50; 0045 setColumnWidth(0, appColumnSize); 0046 QAbstractItemView::resizeEvent(resizeEvent); 0047 } 0048 0049 #include "moc_authorizedapplicationstable.cpp"