[Merge] lp:~renatofilho/buteo-syncfw-qml/release into lp:buteo-syncfw-qml
Renato Araujo Oliveira Filho
renato.filho at canonical.com
Tue Sep 29 13:01:22 UTC 2015
Fixed
Diff comments:
> === modified file 'Buteo/buteo-sync-qml.cpp'
> --- Buteo/buteo-sync-qml.cpp 2015-07-08 18:09:47 +0000
> +++ Buteo/buteo-sync-qml.cpp 2015-09-01 15:05:12 +0000
> @@ -197,8 +184,118 @@
>
> void ButeoSyncFW::deinitialize()
> {
> + m_waitSyncStart = false;
> + m_profilesByCategory.clear();
> + m_reloadProfilesWatcher.reset();
> m_iface.reset();
> +
> // notify changes on properties
> - emit syncStatus("", 0, "", 0);
> - emit profileChanged("", 0, "");
> + emit profilesChanged();
> + emit syncStatusChanged();
> +}
> +
> +QStringList ButeoSyncFW::profiles(const QString &category, bool onlyEnabled) const
Some profiles are hide = true, this property is common used for template profiles (profiles used as template to create new ones). Ex, google-contacts has a template profile and all google accounts created on the system will use this profile to create individual profiles.
If the account is disabled the profile will be marked as disabled.
> +{
> + QStringList result;
> + QList<ProfileData> filter = category.isEmpty() ?
> + m_profilesByCategory.values() : m_profilesByCategory.values(category);
> +
> + foreach(const ProfileData &p, filter) {
> + if (!onlyEnabled || p.second) {
> + result << p.first;
> + }
> + }
> + return result;
> +}
> +
> +
> +QMultiMap<QString, QPair<QString, bool> > ButeoSyncFW::paserProfiles(const QStringList &profiles) const
> +{
> + // extract category/ids
> + QMultiMap<QString, ProfileData> profilesByCategory;
> +
> + foreach(const QString &profile, profiles) {
> + QDomDocument doc;
> + QString errorMsg;
> + int errorLine;
> + int errorColumn;
> + if (doc.setContent(profile, &errorMsg, &errorLine, &errorColumn)) {
> + QDomNodeList profileElements = doc.elementsByTagName("profile");
> + if (!profileElements.isEmpty()) {
> + //check if is enabled
> + QDomElement e = profileElements.item(0).toElement();
> + QDomNodeList values = e.elementsByTagName("key");
> + bool enabled = true;
> + QString profileCategory;
> + for(int i = 0; i < values.count(); i++) {
> + QDomElement v = values.at(i).toElement();
> + if ((v.attribute("name") == "enabled") &&
> + (v.attribute("value") == "false")) {
> + enabled = false;
> + }
> + if (v.attribute("name") == "category") {
> + profileCategory = v.attribute("value");
> + }
> + }
> +
> + QString profileName = e.attribute("name", "");
> + if (profileName.isEmpty() || profileCategory.isEmpty()) {
> + qWarning() << "Fail to retrieve profile name and category";
> + } else {
> + profilesByCategory.insertMulti(profileCategory, qMakePair(profileName, enabled));
> + }
> + } else {
> + qWarning() << "Profile not found in:" << profile;
> + }
> + } else {
> + qWarning() << "Fail to parse profile:" << profile;
> + qWarning() << "Error:" << errorMsg << errorLine << errorColumn;
> + }
> + }
> + return profilesByCategory;
> +}
> +
> +void ButeoSyncFW::reloadProfiles()
> +{
> + if (m_reloadProfilesWatcher) {
> + m_reloadProfilesWatcher.reset();
> + }
> +
> + if (!m_iface) {
> + return;
> + }
> +
> + // we only care about profiles that uses online-accounts
> + QDBusPendingCall pcall = m_iface->asyncCall(QLatin1String("syncProfilesByKey"),
> + QLatin1String("use_accounts"),
> + QLatin1String("true"));
> + if (pcall.isError()) {
> + qWarning() << "Fail to call syncProfilesByKey:" << pcall.error().message();
> + } else {
> + m_reloadProfilesWatcher.reset(new QDBusPendingCallWatcher(pcall, this));
> + connect(m_reloadProfilesWatcher.data(), SIGNAL(finished(QDBusPendingCallWatcher*)),
> + SLOT(onAllVisibleSyncProfilesFinished(QDBusPendingCallWatcher*)), Qt::UniqueConnection);
> + }
> +}
> +
> +void ButeoSyncFW::onAllVisibleSyncProfilesFinished(QDBusPendingCallWatcher *watcher)
> +{
> + QStringList profiles;
> + QDBusPendingReply<QStringList> reply = *watcher;
> + if (reply.isError()) {
> + qWarning() << "Fail to call 'syncProfilesByKey'" << reply.error().message();
> + } else {
> + profiles = reply.value();
> + }
> +
> + m_profilesByCategory = paserProfiles(profiles);
> + m_reloadProfilesWatcher.take()->deleteLater();
> +
> + // notify property change
> + emit profilesChanged();
> +}
> +
> +void ButeoSyncFW::onSyncStatusChanged()
> +{
> + m_waitSyncStart = false;
> }
--
https://code.launchpad.net/~renatofilho/buteo-syncfw-qml/release/+merge/264336
Your team Ubuntu Phablet Team is subscribed to branch lp:buteo-syncfw-qml.
More information about the Ubuntu-reviews
mailing list