QString Core::GetPassword (QObject *accObj) { QVariantList keys; IAccount *account = qobject_cast<IAccount*> (accObj); keys << account->GetAccountID (); const QVariantList& result = Util::GetPersistentData (keys, this); if (result.size () != 1) { qWarning () << Q_FUNC_INFO << "incorrect result size" << result; return QString (); } const QVariantList& strVarList = result.at (0).toList (); if (strVarList.isEmpty () || !strVarList.at (0).canConvert<QString> ()) { qWarning () << Q_FUNC_INFO << "invalid string variant list" << strVarList; return QString (); } return strVarList.at (0).toString (); }
int wmain() { // CoInitialize(NULL); CoInitializeEx(NULL, COINIT_MULTITHREADED); IInventory* pInv = NULL; HRESULT hr = CoCreateInstance(CLSID_Trader, NULL, CLSCTX_INPROC_SERVER, IID_IInventory, reinterpret_cast<LPVOID*>(&pInv)); if(SUCCEEDED(hr)) { int qty; double bal; wcout << L"Number of items to purchase : "; wcin >> qty; hr = pInv->Buy(qty, 100); if(FAILED(hr)) wcout << L"Buy operation failed with error code of " << hex << hr << endl; else { IAccount* pAcc = NULL; pInv->QueryInterface(IID_IAccount, reinterpret_cast<LPVOID*>(&pAcc)); pInv->GetStock(&qty); pAcc->GetBalance(&bal); wcout << L"Current stock : " << qty << endl; wcout << L"Current balance : " << bal << endl; pAcc->Release(); } pInv->Release(); } else
void AccountActionsManager::joinAccountConfFromBM () { IAccount *account = GetAccountFromSender (sender (), Q_FUNC_INFO); if (!account) return; const QVariant& bmData = sender ()->property ("Azoth/BMData"); if (bmData.isNull ()) return; const auto proto = qobject_cast<IMUCProtocol*> (account->GetParentProtocol ()); if (!proto) { qWarning () << Q_FUNC_INFO << account->GetAccountName () << "parent protocol does not implement IMUCProtocol"; return; } auto jWidget = proto->GetMUCJoinWidget (); IMUCJoinWidget *imjw = qobject_cast<IMUCJoinWidget*> (jWidget); imjw->SetIdentifyingData (bmData.toMap ()); imjw->Join (account->GetQObject ()); jWidget->deleteLater (); }
void CTradeLockDlg::OnShow(BOOL bShow) { if (bShow) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); m_edPsw.SetWindowText(""); m_cbFundAccount.ResetContent(); IAccount* pCurrAccount = m_pAccountMng->GetCurrentAccount(atTrade); int nCurrIndex = 0; for (int i = 0; i < m_pAccountMng->GetCount(atTrade); i++) { IAccount* pAccount = m_pAccountMng->GetAccount(i, atTrade); CString sTmp = ""; sTmp.Format(_T("股票%s(%s)"), pAccount->GetAccountName(), pAccount->GetUserName()); int nIndex = m_cbFundAccount.AddString(sTmp); m_cbFundAccount.SetItemDataPtr(nIndex, pAccount); if (pAccount == pCurrAccount) { nCurrIndex = nIndex; } } if (m_cbFundAccount.GetCount() > 0) { m_cbFundAccount.SetCurSel(nCurrIndex); } if (pCurrAccount->GetConnectHandle() == 0) { m_stErrorHint.SetWindowText("由于未知的原因连接被断开,请检查网络后重新连接!"); } else { m_stErrorHint.SetWindowText(""); } } }
IAccount* ImportManager::GetAccountID (Entity e) { const QString& accName = e.Additional_ ["AccountName"].toString (); auto accs = Core::Instance ().GetAccounts ([] (IProtocol *proto) { return qobject_cast<ISupportImport*> (proto->GetQObject ()); }); IAccount *acc = 0; Q_FOREACH (acc, accs) if (acc->GetAccountName () == accName) return acc; const QString& impId = e.Additional_ ["AccountID"].toString (); EntityQueues_ [impId] << e; if (EntityQueues_ [impId].size () > 1) return 0; if (AccID2OurID_.contains (impId)) return AccID2OurID_ [impId]; AccountHandlerChooserDialog dia (accs, tr ("Select account to import history from %1 into:").arg (accName)); if (dia.exec () != QDialog::Accepted) return 0; acc = dia.GetSelectedAccount (); AccID2OurID_ [impId] = acc; return acc; }
void Plugin::RequestLastMessages (QObject *entryObj, int num) { ICLEntry *entry = qobject_cast<ICLEntry*> (entryObj); if (!entry) { qWarning () << Q_FUNC_INFO << entryObj << "doesn't implement ICLEntry"; return; } if (entry->GetEntryType () != ICLEntry::ETChat) return; IAccount *account = qobject_cast<IAccount*> (entry->GetParentAccount ()); if (!account) { qWarning () << Q_FUNC_INFO << entry->GetParentAccount () << "doesn't implement IAccount"; return; } const QString& accId = account->GetAccountID (); const QString& entryId = entry->GetEntryID (); Core::Instance ()->GetChatLogs (accId, entryId, 0, num); RequestedLogs_ [accId] [entryId] = entryObj; }
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; }
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 ()); }
void AccountsListWidget::on_Delete__released() { QModelIndex index = Ui_.Accounts_-> selectionModel ()->currentIndex (); if (!index.isValid ()) return; IAccount *acc = index .data (RAccObj).value<IAccount*> (); if (QMessageBox::question (this, "LeechCraft", tr ("Are you sure you want to remove the account %1?") .arg (acc->GetAccountName ()), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return; QObject *protoObj = acc->GetParentProtocol (); IProtocol *proto = qobject_cast<IProtocol*> (protoObj); if (!proto) { qWarning () << Q_FUNC_INFO << "parent protocol for" << acc->GetAccountID () << "doesn't implement IProtocol"; return; } proto->RemoveAccount (acc->GetObject ()); }
void AccountsListWidget::on_PGP__released () { #ifdef ENABLE_CRYPT QModelIndex index = Ui_.Accounts_-> selectionModel ()->currentIndex (); if (!index.isValid ()) return; IAccount *acc = index .data (RAccObj).value<IAccount*> (); ISupportPGP *pgpAcc = qobject_cast<ISupportPGP*> (acc->GetObject ()); if (!pgpAcc) { QMessageBox::warning (this, "LeechCraft", tr ("The account %1 doesn't support encryption.") .arg (acc->GetAccountName ())); return; } const QString& str = tr ("Please select new PGP key for the account %1.") .arg (acc->GetAccountName ()); PGPKeySelectionDialog dia (str, PGPKeySelectionDialog::TPrivate, pgpAcc->GetPrivateKey (), this); if (dia.exec () != QDialog::Accepted) return; pgpAcc->SetPrivateKey (dia.GetSelectedKey ()); Core::Instance ().AssociatePrivateKey (acc, dia.GetSelectedKey ()); #endif }
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::handleAccountValidated (QObject *accObj, bool validated) { IAccount *acc = qobject_cast<IAccount*> (accObj); if (!acc) { qWarning () << Q_FUNC_INFO << accObj << "is not an IAccount"; return; } if (!Account2Item_.contains (acc)) { qWarning () << Q_FUNC_INFO << "account" << acc->GetAccountName () << acc->GetObject () << "from" << sender () << "not found here"; return; } QStandardItem *item = Account2Item_ [acc]; AccountsModel_->item (item->row (), Columns::IsValidated)->setText (validated ? tr ("Validated") : tr ("Not validated")); Ui_.Accounts_->header ()->setResizeMode (QHeaderView::ResizeToContents); }
void ContactListDelegate::DrawAccount (QPainter *painter, QStyleOptionViewItemV4 o, const QModelIndex& index) const { QStyle *style = o.widget ? o.widget->style () : QApplication::style (); painter->save (); painter->setRenderHints (QPainter::HighQualityAntialiasing | QPainter::Antialiasing); style->drawPrimitive (QStyle::PE_PanelButtonCommand, &o, painter, o.widget); painter->restore (); o.font.setBold (true); QStyledItemDelegate::paint (painter, o, index); QObject *accObj = index.data (Core::CLRAccountObject).value<QObject*> (); IAccount *acc = qobject_cast<IAccount*> (accObj); IExtSelfInfoAccount *extAcc = qobject_cast<IExtSelfInfoAccount*> (accObj); QIcon accIcon = extAcc ? extAcc->GetAccountIcon () : QIcon (); if (accIcon.isNull ()) accIcon = qobject_cast<IProtocol*> (acc->GetParentProtocol ())->GetProtocolIcon (); const QRect& r = o.rect; const int iconSize = r.height () - 2 * CPadding; QImage avatarImg; if (extAcc) avatarImg = extAcc->GetSelfAvatar (); if (avatarImg.isNull ()) avatarImg = Core::Instance ().GetDefaultAvatar (iconSize); else avatarImg = avatarImg.scaled (iconSize, iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); QPoint pxDraw = o.rect.topRight () - QPoint (CPadding, 0); if (!avatarImg.isNull ()) { pxDraw.rx () -= avatarImg.width (); const QPoint& delta = QPoint (0, (iconSize - avatarImg.height ()) / 2); painter->drawPixmap (pxDraw + delta, QPixmap::fromImage (avatarImg)); pxDraw.rx () -= CPadding; } if (!accIcon.isNull ()) { const int size = std::min (16, iconSize); const QPixmap& px = accIcon.pixmap (size, size); pxDraw.rx () -= px.width (); const QPoint& delta = QPoint (0, (iconSize - px.height ()) / 2); painter->drawPixmap (pxDraw + delta, px); } }
void AccountsListWidget::on_Modify__released () { QModelIndex index = Ui_.Accounts_->selectionModel ()->currentIndex (); if (!index.isValid ()) return; IAccount *acc = index.data (RAccObj).value<IAccount*> (); acc->OpenConfigurationDialog (); }
void AccountActionsManager::handleAccountSD () { IAccount *account = GetAccountFromSender (sender (), Q_FUNC_INFO); if (!account) return; auto w = new ServiceDiscoveryWidget (); w->SetAccount (account->GetQObject ()); emit gotSDWidget (w); }
void Core::DeletePassword (QObject *accObj) { IAccount *account = qobject_cast<IAccount*> (accObj); QVariantList keys; keys << account->GetAccountID (); Entity e = Util::MakeEntity (keys, QString (), Internal, "x-leechcraft/data-persistent-clear"); emit gotEntity (e); }
void AccountsListWidget::handleItemChanged (QStandardItem *item) { const auto type = item->data (Roles::RItemType).toInt (); if (type != ItemTypes::ShowInRoster) return; IAccount *acc = item->data (Roles::RAccObj).value<IAccount*> (); acc->SetShownInRoster (item->checkState () == Qt::Checked); if (!acc->IsShownInRoster () && acc->GetState ().State_ != SOffline) acc->ChangeState (EntryStatus (SOffline, QString ())); emit accountVisibilityChanged (acc); }
bool CLModel::TryDropFile (const QMimeData* mime, const QModelIndex& parent) { if (parent.data (Core::CLREntryType).value<Core::CLEntryType> () != Core::CLETContact) return false; QObject *entryObj = parent.data (Core::CLREntryObject).value<QObject*> (); ICLEntry *entry = qobject_cast<ICLEntry*> (entryObj); if (entry->Variants ().isEmpty ()) return false; IAccount *acc = qobject_cast<IAccount*> (entry->GetParentAccount ()); ITransferManager *mgr = qobject_cast<ITransferManager*> (acc->GetTransferManager ()); if (!mgr) return false; const QList<QUrl>& urls = mime->urls (); if (urls.isEmpty ()) return false; QString text; if (urls.size () > 2) text = tr ("Are you sure you want to send %n files to %1?", 0, urls.size ()) .arg (entry->GetEntryName ()); else { QStringList list; Q_FOREACH (const QUrl& url, urls) list << QFileInfo (url.path ()).fileName (); text = tr ("Are you sure you want to send %1 to %2?") .arg ("<em>" + list.join (", ") + "</em>") .arg (entry->GetEntryName ()); } if (QMessageBox::question (0, "LeechCraft", text, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return false; Q_FOREACH (const QUrl& url, urls) { const QString& path = url.toLocalFile (); if (!QFileInfo (path).exists ()) continue; QObject *job = mgr->SendFile (entry->GetEntryID (), entry->Variants ().first (), path); Core::Instance ().GetTransferJobManager()->HandleJob (job); } return true; }
void ProfileWidget::RereadProfileData () { //TODO const LJProfileData& data = Profile_->GetProfileData (); Ui_.JournalName_->setText (data.FullName_); IAccount *acc = qobject_cast<IAccount*> (Profile_->GetParentAccount ()); const QString& path = Util::CreateIfNotExists ("blogique/metida/avatars") .absoluteFilePath (acc->GetAccountID ().toBase64 ().replace ('/', '_')); Ui_.JournalPic_->setPixmap (QPixmap (path)); ReFillModels (); }
void LocalBloggingPlatform::handleAccountValidated (bool valid) { IAccount *acc = qobject_cast<IAccount*> (sender ()); if (!acc) { qWarning () << Q_FUNC_INFO << sender () << "is not an IAccount";; return; } emit accountValidated (acc->GetQObject (), valid); }
void Plugin::handleIdle (int seconds) { IdleSeconds_ = seconds; if (seconds && seconds % 60) return; if (!XmlSettingsManager::Instance ().property ("EnableAutoidler").toBool ()) return; const int mins = seconds / 60; if (!mins && !OldStatuses_.isEmpty ()) { for (QObject *accObj : AzothProxy_->GetAllAccounts ()) { if (!OldStatuses_.contains (accObj)) continue; IAccount *acc = qobject_cast<IAccount*> (accObj); acc->ChangeState (OldStatuses_ [accObj]); } OldStatuses_.clear (); } if (!mins) return; EntryStatus status; if (mins == XmlSettingsManager::Instance ().property ("AwayTimeout").toInt ()) status = EntryStatus (SAway, XmlSettingsManager::Instance ().property ("AwayText").toString ()); else if (mins == XmlSettingsManager::Instance ().property ("NATimeout").toInt ()) status = EntryStatus (SXA, XmlSettingsManager::Instance ().property ("NAText").toString ()); else return; for (QObject *accObj : AzothProxy_->GetAllAccounts ()) { auto acc = qobject_cast<IAccount*> (accObj); const auto& accState = acc->GetState (); if (accState.State_ == State::SOffline) continue; if (!OldStatuses_.contains (accObj)) OldStatuses_ [accObj] = accState; acc->ChangeState (status); } }
QList<QPair<QIcon, QString>> LJProfile::GetPostingTargets () const { QList<QPair<QIcon, QString>> targets; const QIcon& icon = Core::Instance ().GetCoreProxy ()->GetIcon ("system-users"); IAccount *acc = qobject_cast<IAccount*> (ParentAccount_); if (!acc) return targets; targets.append ({ Core::Instance ().GetCoreProxy ()->GetIcon ("im-user"), acc->GetOurLogin () }); for (const auto& community : ProfileData_.Communities_) targets.append ({ icon, community }); return targets; }
void AccountActionsManager::handleAccountConsole () { IAccount *account = GetAccountFromSender (sender (), Q_FUNC_INFO); if (!account) return; if (!Account2CW_.contains (account)) { ConsoleWidget *cw = new ConsoleWidget (account->GetQObject ()); Account2CW_ [account] = cw; connect (cw, SIGNAL (removeTab (QWidget*)), this, SLOT (consoleRemoved (QWidget*))); }
void Core::Process (QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetMessageType () != IMessage::MTChatMessage && msg->GetMessageType () != IMessage::MTMUCMessage) return; if (msg->GetBody ().isEmpty ()) return; if (msg->GetDirection () == IMessage::DOut && msg->GetMessageType () == IMessage::MTMUCMessage) return; ICLEntry *entry = qobject_cast<ICLEntry*> (msg->ParentCLEntry ()); if (!entry) { qWarning () << Q_FUNC_INFO << "message's other part doesn't implement ICLEntry" << msg->GetObject () << msg->OtherPart (); return; } if (DisabledIDs_.contains (entry->GetEntryID ())) return; IAccount *acc = qobject_cast<IAccount*> (entry->GetParentAccount ()); if (!acc) { qWarning () << Q_FUNC_INFO << "message's account doesn't implement IAccount" << entry->GetParentAccount (); return; } QVariantMap data; data ["EntryID"] = entry->GetEntryID (); data ["VisibleName"] = entry->GetEntryName (); data ["AccountID"] = acc->GetAccountID (); data ["DateTime"] = msg->GetDateTime (); data ["Direction"] = msg->GetDirection () == IMessage::DIn ? "IN" : "OUT"; data ["Body"] = msg->GetBody (); data ["OtherVariant"] = msg->GetOtherVariant (); data ["MessageType"] = static_cast<int> (msg->GetMessageType ()); QMetaObject::invokeMethod (StorageThread_->GetStorage (), "addMessage", Qt::QueuedConnection, Q_ARG (QVariantMap, data)); }
void LJBloggingPlatform::handleAccountValidated (bool validated) { IAccount *acc = qobject_cast<IAccount*> (sender ()); if (!acc) { qWarning () << Q_FUNC_INFO << sender () << "is not an IAccount";; return; } emit accountValidated (acc->GetQObject (), validated); if (validated && XmlSettingsManager::Instance ().Property ("CheckingInboxEnabled", true).toBool ()) checkForMessages ();; }
void DenyAuthForEntry (ICLEntry *entry) { IAccount *account = qobject_cast<IAccount*> (entry->GetParentAccount ()); if (!account) { qWarning () << Q_FUNC_INFO << "parent account doesn't implement IAccount:" << entry->GetParentAccount (); return; } account->DenyAuth (entry->GetQObject ()); const auto& e = Util::MakeANCancel ("org.LeechCraft.Azoth", "org.LC.Plugins.Azoth.AuthRequestFrom/" + entry->GetEntryID ()); Core::Instance ().SendEntity (e); }
void AuthorizeEntry (ICLEntry *entry) { IAccount *account = qobject_cast<IAccount*> (entry->GetParentAccount ()); if (!account) { qWarning () << Q_FUNC_INFO << "parent account doesn't implement IAccount:" << entry->GetParentAccount (); return; } const QString& id = entry->GetHumanReadableID (); account->Authorize (entry->GetQObject ()); account->RequestAuth (id); const auto& e = Util::MakeANCancel ("org.LeechCraft.Azoth", "org.LC.Plugins.Azoth.AuthRequestFrom/" + entry->GetEntryID ()); Core::Instance ().SendEntity (e); }
void LJProfile::handleAvatarDownloadFinished () { QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ()); if (!reply) return; reply->deleteLater (); IAccount *acc = qobject_cast<IAccount*> (ParentAccount_); if (!acc) return; const QByteArray filename = acc->GetAccountID ().toBase64 ().replace ('/', '_'); const QDir& avatarDir = Util::CreateIfNotExists ("blogique/metida/avatars"); const QString& path = avatarDir.absoluteFilePath (filename); QFile file (path); if (file.open (QIODevice::WriteOnly)) file.write (reply->readAll ()); }
QString ProxyObject::GetAccountPassword (QObject *accObj, bool useStored) { if (useStored) { const QString& result = GetPassword (accObj); if (!result.isNull ()) return result; } IAccount *acc = qobject_cast<IAccount*> (accObj); QString result = QInputDialog::getText (0, "LeechCraft", tr ("Enter password for %1:").arg (acc->GetAccountName ()), QLineEdit::Password); if (!result.isNull ()) SetPassword (result, accObj); return result; }
IXmppFeature *Registration::newXmppFeature(const QString &AFeatureNS, IXmppStream *AXmppStream) { // *** <<< eyeCU <<< *** if (AFeatureNS==NS_FEATURE_REGISTER) { IAccount *account = FAccountManager!=NULL ? FAccountManager->findAccountByStream(AXmppStream->streamJid()) : NULL; if (account && account->optionsNode().value("register-on-server").toBool() && !FStreamRegisterId.contains(AXmppStream)) { LOG_INFO(QString("XMPP account automatic registration started, server=%1").arg(AXmppStream->streamJid().pDomain())); FAutoRegisterStreams.insert(AXmppStream); QString id = QUuid::createUuid().toString(); FStreamRegisterId.insert(AXmppStream,id); connect(AXmppStream->instance(),SIGNAL(opened()),SLOT(onXmppStreamOpened())); connect(AXmppStream->instance(),SIGNAL(closed()),SLOT(onXmppStreamClosed())); connect(AXmppStream->instance(),SIGNAL(error(const XmppError &)),SLOT(onXmppStreamError(const XmppError &))); account->optionsNode().setValue(false,"register-on-server"); }