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 ()); } }
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 (); }
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 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; }
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 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 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 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 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 ()); }
void Core::SavePassword (QObject *accObj) { QVariantList keys; IAccount *account = qobject_cast<IAccount*> (accObj); keys << account->GetAccountID (); QVariantList passwordVar; passwordVar << account->GetPassword (); QVariantList values; values << QVariant (passwordVar); Entity e = Util::MakeEntity (keys, QString (), Internal, "x-leechcraft/data-persistent-save"); e.Additional_ ["Values"] = values; e.Additional_ ["Overwrite"] = true; emit gotEntity (e); }
void AccountsListDialog::on_Delete__released() { QModelIndex index = Ui_.Accounts_-> selectionModel ()->currentIndex (); if (!index.isValid ()) return; IAccount *acc = index .data (RAccObj).value<IAccount*> (); 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 AccountsSettings::addAccount (QObjectList accObjects) { IBookmarksService *ibs = qobject_cast<IBookmarksService*> (sender ()); if (!ibs) { qWarning () << Q_FUNC_INFO << sender () << "ins't IBookmarksService"; return; } QObjectList accounts; Q_FOREACH (QObject *accObj, accObjects) { IAccount *account = qobject_cast<IAccount*> (accObj); if (Id2Account_.contains (account->GetAccountID ())) continue; if (!account->GetPassword ().isEmpty ()) Core::Instance ().SavePassword (accObj); else account->SetPassword (Core::Instance ().GetPassword (accObj)); Id2Account_ [account->GetAccountID ()] = accObj; accounts << accObj; const QModelIndex& index = GetServiceIndex (ibs->GetObject ()); QStandardItem *parentItem = 0; if (!index.isValid ()) { parentItem = new QStandardItem (ibs->GetServiceIcon (), ibs->GetServiceName ()); parentItem->setEditable (false); Item2Service_ [parentItem] = ibs; AccountsModel_->appendRow (parentItem); } else parentItem = AccountsModel_->itemFromIndex (index); QList<QStandardItem*> record; QStandardItem *item = new QStandardItem (account->GetLogin ()); item->setEditable (false); item->setCheckable (true); item->setCheckState (account->IsSyncing () ? Qt::Checked : Qt::Unchecked); if (account->IsSyncing ()) { Core::Instance ().AddActiveAccount (accObj); IBookmarksService *ibs = qobject_cast<IBookmarksService*> (account->GetParentService ()); ibs->DownloadBookmarks (account->GetObject (), account->GetLastDownloadDateTime ()); ibs->UploadBookmarks (account->GetObject (), Core::Instance ().GetAllBookmarks ()); } Item2Account_ [item] = account; QStandardItem *uploaditem = new QStandardItem (account->GetLastUploadDateTime () .toString (Qt::DefaultLocaleShortDate)); uploaditem->setEditable (false); QStandardItem *downloaditem = new QStandardItem (account->GetLastDownloadDateTime () .toString (Qt::DefaultLocaleShortDate)); uploaditem->setEditable (false); record << item << uploaditem << downloaditem; parentItem->appendRow (record); if (account->IsSyncing ()) Core::Instance ().AddActiveAccount (accObj); Ui_.AccountsView_->expandAll (); Scheduled_ = false; ScheduleResize (); }