[Merge] lp:~renatofilho/buteo-syncfw-qml/release into lp:buteo-syncfw-qml
Michael Sheldon
michael.sheldon at canonical.com
Tue Sep 29 11:10:21 UTC 2015
Review: Needs Information
Added a comment and a question to the diff, other than that this looks good.
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
> @@ -25,31 +26,33 @@
> #define BUTEO_DBUS_OBJECT_PATH "/synchronizer"
> #define BUTEO_DBUS_INTERFACE "com.meego.msyncd"
>
> +typedef QPair<QString, bool> ProfileData;
> +
> ButeoSyncFW::ButeoSyncFW(QObject *parent)
> - : QObject(parent)
> + : QObject(parent),
> + m_waitSyncStart(false)
> {
> + connect(this, SIGNAL(syncStatus(QString,int,QString,int)), SIGNAL(syncStatusChanged()));
> + connect(this, SIGNAL(profileChanged(QString,int,QString)), SIGNAL(profilesChanged()));
> }
>
> bool ButeoSyncFW::syncing() const
> {
> - return !(getRunningSyncList().isEmpty());
> + return (m_waitSyncStart || !getRunningSyncList().isEmpty());
> }
>
> QStringList ButeoSyncFW::visibleSyncProfiles() const
> {
> - if (m_iface) {
> - QDBusReply<QStringList> result = m_iface->call("allVisibleSyncProfiles");
> - return result.value();
> - }
> - return QStringList();
> + return profiles();
> +}
> +
> +int ButeoSyncFW::profilesCount() const
> +{
> + return visibleSyncProfiles().count();
Since visibleSyncProfiles() just calls profiles() I think this would be clearer if it was just "return profiles().count();"
> }
>
> void ButeoSyncFW::classBegin()
> {
> -}
> -
> -void ButeoSyncFW::componentComplete()
> -{
> m_serviceWatcher.reset(new QDBusServiceWatcher(BUTEO_DBUS_SERVICE_NAME,
> QDBusConnection::sessionBus(),
> QDBusServiceWatcher::WatchForOwnerChange,
> @@ -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
I'm not clear on the naming/purpose of the onlyEnabled parameter, could you give a brief description of its purpose? (I'm wondering if it should be true for visibleSyncProfiles)
> +{
> + 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