void PasswordsManager::createInstance(QObject *parent) { if (!m_instance) { m_instance = new PasswordsManager(parent); m_backend = new FilePasswordsStorageBackend(m_instance); connect(m_backend, SIGNAL(passwordsModified()), m_instance, SIGNAL(passwordsModified())); } }
void PasswordsContentsWidget::populatePasswords() { m_model->clear(); m_model->setHorizontalHeaderLabels(QStringList({tr("Name"), tr("Value")})); const QStringList hosts(PasswordsManager::getHosts()); for (int i = 0; i < hosts.count(); ++i) { const QUrl url(QStringLiteral("http://%1/").arg(hosts.at(i))); const QList<PasswordsManager::PasswordInformation> passwords(PasswordsManager::getPasswords(url)); QStandardItem *hostItem(new QStandardItem(HistoryManager::getIcon(url), hosts.at(i))); hostItem->setData(hosts.at(i), HostRole); for (int j = 0; j < passwords.count(); ++j) { QStandardItem *setItem(new QStandardItem(tr("Set #%1").arg(j + 1))); setItem->setData(passwords.at(j).url, UrlRole); setItem->setData(((passwords.at(j).type == PasswordsManager::AuthPassword) ? QLatin1String("auth") : QLatin1String("form")), AuthTypeRole); for (int k = 0; k < passwords.at(j).fields.count(); ++k) { const bool isPassword(passwords.at(j).fields.at(k).type == PasswordsManager::PasswordField); QList<QStandardItem*> fieldItems({new QStandardItem(passwords.at(j).fields.at(k).name), new QStandardItem(isPassword ? QLatin1String("*****") : passwords.at(j).fields.at(k).value)}); fieldItems[0]->setData((isPassword ? QLatin1String("password") : QLatin1String("text")), FieldTypeRole); setItem->appendRow(fieldItems); } hostItem->appendRow(QList<QStandardItem*>({setItem, new QStandardItem()})); } hostItem->setText(QStringLiteral("%1 (%2)").arg(hosts.at(i)).arg(hostItem->rowCount())); m_model->appendRow(hostItem); } m_model->sort(0); if (m_isLoading) { m_isLoading = false; emit loadingStateChanged(WindowsManager::FinishedLoadingState); connect(PasswordsManager::getInstance(), SIGNAL(passwordsModified()), this, SLOT(populatePasswords())); } }