void AccountsListWidget::handleAccountClicked (const QModelIndex& idx) { QModelIndex index = idx.sibling (idx.row (), Columns::Name); if (!index.isValid ()) return; QStandardItem *item = AccountsModel_->itemFromIndex (index); if (item && Item2Account_.contains (item)) { IAccount *acc = Item2Account_ [item]; auto ibp = qobject_cast<IBloggingPlatform*> (acc->GetParentBloggingPlatform ()); if (!ibp) { qWarning () << Q_FUNC_INFO << "account" << acc->GetAccountID () << "hasn't valid parent blogging platform" << acc->GetParentBloggingPlatform (); return; } Ui_.Profile_->setEnabled ((ibp->GetFeatures () & IBloggingPlatform::BPFSupportsProfiles) && acc->IsValidated ()); } }
void AccountsListWidget::on_Delete__released () { auto index = Ui_.Accounts_->selectionModel ()->currentIndex (); index = index.sibling (index.row (), Columns::Name); if (!index.isValid ()) return; QStandardItem *item = AccountsModel_->itemFromIndex (index); IAccount *acc = 0; if (item && Item2Account_.contains (item)) acc = Item2Account_ [item]; else return; if (QMessageBox::question (this, "LeechCraft", tr ("Are you sure you want to remove the account %1?") .arg ("<em>" + acc->GetAccountName () + "</em>"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return; QObject *bpObj = acc->GetParentBloggingPlatform (); IBloggingPlatform *ibp = qobject_cast<IBloggingPlatform*> (bpObj); if (!ibp) { qWarning () << Q_FUNC_INFO << "parent blogging platform for" << acc->GetAccountID () << "doesn't implement IBloggingPlatform"; return; } ibp->RemoveAccount (acc->GetObject ()); }
QWidget* SelectTargetDelegate::createEditor (QWidget *parent, const QStyleOptionViewItem&, const QModelIndex& index) const { QComboBox *box = new QComboBox (parent); IAccount *acc = Dlg_->GetAccountFromIndex (index.sibling (index.row (), SubmitToDialog::Account)); if (!acc) return box; auto ibp = qobject_cast<IBloggingPlatform*> (acc->GetParentBloggingPlatform ()); if (!ibp) return box; if (ibp->GetFeatures () & IBloggingPlatform::BPFSelectablePostDestination) { auto profile = qobject_cast<IProfile*> (acc->GetProfile ()); if (!profile) box->addItem (tr ("<Default>")); else for (const auto& pair : profile->GetPostingTargets ()) box->addItem (pair.first, pair.second); } else box->addItem (tr ("<Default>")); box->setCurrentIndex (0); Dlg_->GetModel ()->setData (index, box->currentText (), TargetRole); return box; }