void ServerListQuerier::get_finished() { QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); if (reply->error()) { emit error(reply->errorString()); } else { int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if(status == 200) { #ifdef XML_SERVER_LIST // Parse the XML file QDomDocument doc; if (!doc.setContent(reply->readAll())) { emit error(tr("Unable to parse server list")); return; } // Fill the list QStringList servers; QDomNodeList items = doc.elementsByTagName("item"); for (int i = 0; i < items.count(); i++) { QString jid = items.item(i).toElement().attribute("jid"); if (!jid.isEmpty()) { servers.push_back(jid); } } #else QStringList servers; QString contents = QString::fromUtf8(reply->readAll()); int index = 0; QRegExp re("data-original-title=\"([^\"]+)\""); while ((index = contents.indexOf(re, index + 1)) != -1) { servers.append(re.cap(1)); } #endif emit listReceived(servers); } else if(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) { if (redirectCount_ >= SERVERLIST_MAX_REDIRECT) { emit error(tr("Maximum redirect count reached")); return; } url_ = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).value<QUrl>().resolved(url_); if (url_.isValid()) { QNetworkReply *newReply = http_->get(QNetworkRequest(url_)); connect(newReply, SIGNAL(finished()),SLOT(get_finished())); ++redirectCount_; } else { emit error(tr("Invalid redirect URL %1").arg(url_.toString())); return; } } else { emit error(tr("Unexpected HTTP status code: %1").arg(status)); } } reply->deleteLater(); }
void ServerListQuerier::get_finished(int, bool err) { if (err) { emit error(http_->errorString()); } else { // Parse the XML file QDomDocument doc; if (!doc.setContent(http_->readAll())) { emit error(tr("Unable to parse server list")); return; } // Fill the list QStringList servers; QDomNodeList items = doc.elementsByTagName("item"); for (int i = 0; i < items.count(); i++) { QString jid = items.item(i).toElement().attribute("jid"); if (!jid.isEmpty()) { servers.push_back(jid); } } emit listReceived(servers); } }
PrivacyDlg::PrivacyDlg(JabberAccount* acc, QWidget* parent) : KDialog(parent), acc_(acc) { QWidget * w = new QWidget (this); ui_.setupUi(w); setMainWidget (w); setAttribute(Qt::WA_DeleteOnClose); setCaption(i18n("%1: Privacy Lists", (acc->myself()->nickName() ) ) ); setButtons (KDialog::Close); ui_.lv_rules->setFocus (Qt::PopupFocusReason); PrivacyManager* manager = acc->client()->privacyManager(); connect(manager,SIGNAL(listsReceived(QString,QString,QStringList)),SLOT(updateLists(QString,QString,QStringList))); connect(manager,SIGNAL(listReceived(PrivacyList)),SLOT(refreshList(PrivacyList))); connect(manager,SIGNAL(listError()),SLOT(list_failed())); //connect(manager,SIGNAL(listNamesError()),SLOT(listNamesError())); //connect(manager,SIGNAL(listReceiveError()),SLOT(listReceiveError())); connect(ui_.cb_active,SIGNAL(activated(int)),SLOT(active_selected(int))); connect(ui_.cb_default,SIGNAL(activated(int)),SLOT(default_selected(int))); connect(ui_.cb_lists,SIGNAL(activated(int)),SLOT(list_selected(int))); connect(ui_.cb_lists,SIGNAL(currentIndexChanged(int)),SLOT(list_changed(int))); connect(manager,SIGNAL(changeActiveList_success()),SLOT(change_succeeded())); connect(manager,SIGNAL(changeActiveList_error()),SLOT(change_failed())); connect(manager,SIGNAL(changeDefaultList_success()),SLOT(change_succeeded())); connect(manager,SIGNAL(changeDefaultList_error()),SLOT(change_failed())); connect(manager,SIGNAL(changeList_success()),SLOT(changeList_succeeded())); connect(manager,SIGNAL(changeList_error()),SLOT(changeList_failed())); connect(ui_.pb_newList,SIGNAL(clicked()),SLOT(newList())); connect(ui_.pb_deleteList,SIGNAL(clicked()),SLOT(removeList())); connect(ui_.pb_add,SIGNAL(clicked()),SLOT(addRule())); connect(ui_.pb_edit,SIGNAL(clicked()),SLOT(editCurrentRule())); connect(ui_.pb_remove,SIGNAL(clicked()),SLOT(removeCurrentRule())); connect(ui_.pb_up,SIGNAL(clicked()),SLOT(moveCurrentRuleUp())); connect(ui_.pb_down,SIGNAL(clicked()),SLOT(moveCurrentRuleDown())); connect(ui_.pb_apply,SIGNAL(clicked()),SLOT(applyList())); ui_.pb_newList->setIcon(KIcon("list-add")); ui_.pb_deleteList->setIcon(KIcon("list-remove")); ui_.pb_add->setIcon(KIcon("list-add")); ui_.pb_remove->setIcon(KIcon("list-remove")); ui_.pb_up->setIcon(KIcon("arrow-up")); ui_.pb_down->setIcon(KIcon("arrow-down")); ui_.pb_edit->setIcon(KIcon("edit-rename")); ui_.pb_apply->setIcon(KIcon("dialog-ok-apply")); setWidgetsEnabled(false); // Disable all buttons ui_.pb_deleteList->setEnabled(false); setEditRuleEnabled(false); ui_.pb_add->setEnabled(false); ui_.pb_apply->setEnabled(false); // FIXME: Temporarily disabling auto-activate ui_.ck_autoActivate->hide(); manager->requestListNames(); }
void MockPrivacyManager::requestList(const QString& name) { qDebug() << "requestList(" << name << ")"; QList<PrivacyListItem> items; if (name == "a") { items += createItem(PrivacyListItem::JidType, "*****@*****.**", PrivacyListItem::Deny, true, true, false, false); items += createItem(PrivacyListItem::FallthroughType, "", PrivacyListItem::Allow, true, true, true, true); } else if (name == "b") { items += createItem(PrivacyListItem::GroupType, "mygroup", PrivacyListItem::Deny, false, false, true, true); } else if (name == "c") { items += createItem(PrivacyListItem::SubscriptionType, "to", PrivacyListItem::Allow, false, false, false, false); items += createItem(PrivacyListItem::FallthroughType, "", PrivacyListItem::Deny, true, true, true, true); } PrivacyList list(name, items); emit listReceived(list); }