[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [conquirere] src/nbibio: fix some smaller bugs
From:       Jörg_Ehrichs <Joerg.Ehrichs () gmx ! de>
Date:       2013-01-31 21:04:16
Message-ID: 20130131210416.4B399A6091 () git ! kde ! org
[Download RAW message or body]

Git commit 0bf2df2f2978c6f74e24791206c7a79ca1253ce8 by Jörg Ehrichs.
Committed on 31/01/2013 at 21:09.
Pushed by jehrichs into branch 'master'.

fix some smaller bugs

M  +16   -5    src/nbibio/nepomuksyncclient.cpp
M  +3    -0    src/nbibio/nepomuksyncclient.h
M  +2    -2    src/nbibio/pipe/nepomuktovariantpipe.cpp
M  +0    -2    src/nbibio/provider/zotero/zoterosync.cpp
M  +62   -35   src/nbibio/ui/itemmergedialog.cpp
M  +5    -4    src/nbibio/ui/itemmergedialog.h

http://commits.kde.org/conquirere/0bf2df2f2978c6f74e24791206c7a79ca1253ce8

diff --git a/src/nbibio/nepomuksyncclient.cpp b/src/nbibio/nepomuksyncclient.cpp
index 91fa6de..4cec710 100644
--- a/src/nbibio/nepomuksyncclient.cpp
+++ b/src/nbibio/nepomuksyncclient.cpp
@@ -50,6 +50,9 @@ NepomukSyncClient::NepomukSyncClient(QObject *parent)
 {
     connect(this, SIGNAL(pushNextItem()), this, SLOT(pushNewItemCache()) );
     connect(this, SIGNAL(deleteNextItem()), this, SLOT(deleteItemsCache()) );
+
+    qRegisterMetaType<SyncMergeDetails>("SyncMergeDetails");
+    qRegisterMetaType<QList<SyncMergeDetails> >("QList<SyncMergeDetails>");
 }
 
 void NepomukSyncClient::setProviderSettings(const ProviderSyncDetails &psd)
@@ -391,6 +394,7 @@ void NepomukSyncClient::readDownloadSyncAfterDelete()
 
 void NepomukSyncClient::findDuplicates(QList<Nepomuk2::Resource> &existingItems)
 {
+    kDebug() << "check duplicates for" << m_cacheDownloaded.size();
     // for each downloaded item from zotero we try to find the item in the local \
storage  // we can identify this via the unique zotero Key
 
@@ -420,11 +424,12 @@ void \
NepomukSyncClient::findDuplicates(QList<Nepomuk2::Resource> &existingItems)  \
QList<Nepomuk2::Resource> queryResult;  while( it.next() ) {
             Soprano::BindingSet p = it.current();
-            queryResult << \
Nepomuk2::Resource(p.value(QLatin1String("?r")).toString()); +            queryResult \
<< Nepomuk2::Resource(p.value(QLatin1String("r")).toString());  }
 
         // nothing found, means we have a new entry
         if(queryResult.isEmpty()) {
+            kDebug() << "new entry found";
             m_newEntries.append(entry);
         }
         // we found something, means we need to check if it changed on the server
@@ -435,9 +440,11 @@ void NepomukSyncClient::findDuplicates(QList<Nepomuk2::Resource> \
&existingItems)  
             Nepomuk2::Resource syncResource = queryResult.first();
 
-            QString localEtag = syncResource.property( SYNC::etag()).toString();
+            QString localEtag = syncResource.property( SYNC::etag() ).toString();
             QString serverEtag = entry.value( QLatin1String("sync-etag") \
).toString();  
+            kDebug() << "existing entry found. Local etag" << localEtag << "| server \
etag" << serverEtag; +
             // Here we change some values depending if the syncdata represents a \
                BibResource, Note or Attachment.
             // Because when we check the isRelated  part we need to check different \
                resources in this case
             // also while for note/attachment the resource itself must be valid
@@ -451,7 +458,7 @@ void NepomukSyncClient::findDuplicates(QList<Nepomuk2::Resource> \
&existingItems)  if(resourceType == SYNC::BibResource()) {
                 Nepomuk2::Resource publication = syncResource.property( \
                SYNC::publication()).toResource();
                 Nepomuk2::Resource reference = syncResource.property( \
                SYNC::reference()).toResource();
-                if(reference.isValid() && publication.isValid()) {
+                if(reference.isValid()) {
                     addToExisting.append(publication);
                     addToExisting.append(reference);
                     validExistingData = true;
@@ -532,9 +539,10 @@ void NepomukSyncClient::fixMergingItems()
 //            foreach(const SyncMergeDetails &sd, m_tmpUserMergeRequest) {
 //                mergePipe.merge(sd.syncResource, sd.externalResource, \
m_psd.mergeMode);  //            }
-        }
 
-        m_tmpUserMergeRequest.clear();
+            m_mergeFinished = true;
+            m_tmpUserMergeRequest.clear();
+        }
     }
     else {
         m_mergeFinished = true;
@@ -612,6 +620,9 @@ void NepomukSyncClient::endSyncStep()
 
 void NepomukSyncClient::exportData()
 {
+    kDebug() << "##################### export disabled #############";
+    emit finished();
+    return;
     kDebug() << "##### START Upload ###### m_currentStep" << m_currentStep;
     clearInternalData();
 
diff --git a/src/nbibio/nepomuksyncclient.h b/src/nbibio/nepomuksyncclient.h
index 1bb1141..2611769 100644
--- a/src/nbibio/nepomuksyncclient.h
+++ b/src/nbibio/nepomuksyncclient.h
@@ -31,6 +31,9 @@ struct SyncMergeDetails {
     QVariantMap        externalResource;
 };
 
+Q_DECLARE_METATYPE(SyncMergeDetails)
+Q_DECLARE_METATYPE(QList<SyncMergeDetails>)
+
 class NepomukSyncClient : public QObject
 {
     Q_OBJECT
diff --git a/src/nbibio/pipe/nepomuktovariantpipe.cpp \
b/src/nbibio/pipe/nepomuktovariantpipe.cpp index 47f7a9f..4b19bbe 100644
--- a/src/nbibio/pipe/nepomuktovariantpipe.cpp
+++ b/src/nbibio/pipe/nepomuktovariantpipe.cpp
@@ -335,8 +335,8 @@ void NepomukToVariantPipe::collectContent(Nepomuk2::Resource \
                reference, Nepomuk2
     setValue(publication, NBIB::legalStatus(), QLatin1String("legalstatus"));
     setValue(publication, NBIB::filingDate(), QLatin1String("filingdate"));
     setValue(publication, NBIB::archive(), QLatin1String("archive"));
-    setValue(publication, NBIB::archiveLocation(), \
                QLatin1String("archiveLocation"));
-    setValue(publication, NBIB::libraryCatalog(), QLatin1String("libraryCatalog"));
+    setValue(publication, NBIB::archiveLocation(), \
QLatin1String("archivelocation")); +    setValue(publication, NBIB::libraryCatalog(), \
                QLatin1String("librarycatalog"));
     setValue(publication, NBIB::shortTitle(), QLatin1String("shorttitle"));
     setValue(publication, NBIB::numberOfPages(), QLatin1String("numpages"));
     setValue(publication, NBIB::numberOfVolumes(), \
                QLatin1String("numberofvolumes"));
diff --git a/src/nbibio/provider/zotero/zoterosync.cpp \
b/src/nbibio/provider/zotero/zoterosync.cpp index 6d9051e..cd65fb9 100644
--- a/src/nbibio/provider/zotero/zoterosync.cpp
+++ b/src/nbibio/provider/zotero/zoterosync.cpp
@@ -692,8 +692,6 @@ QByteArray ZoteroSync::writeJsonContent(const QVariantList \
&items, bool updateIt  json = serializer.serialize(jsonMap);
     }
 
-    kDebug() << json;
-
     return json;
 }
 
diff --git a/src/nbibio/ui/itemmergedialog.cpp b/src/nbibio/ui/itemmergedialog.cpp
index 5c02dae..926263e 100644
--- a/src/nbibio/ui/itemmergedialog.cpp
+++ b/src/nbibio/ui/itemmergedialog.cpp
@@ -19,13 +19,10 @@
 #include "ui_itemmergedialog.h"
 
 #include "globals.h"
-//#include "nbibio/pipe/bibtextonepomukpipe.h"
+
 #include "core/library.h"
 #include "core/projectsettings.h"
-
-#include <kbibtex/element.h>
-#include <kbibtex/entry.h>
-#include <kbibtex/value.h>
+#include "nbibio/pipe/nepomuktovariantpipe.h"
 
 #include "sync.h"
 #include "nbib.h"
@@ -37,6 +34,7 @@
 #include <KDE/KComboBox>
 #include <KDE/KDebug>
 
+#include <QtCore/QList>
 #include <QtGui/QScrollArea>
 #include <QtGui/QFormLayout>
 
@@ -146,30 +144,59 @@ ItemMergeDialog::~ItemMergeDialog()
 
 void ItemMergeDialog::setItemsToMerge(const QList<SyncMergeDetails> &items)
 {
+    NepomukToVariantPipe ntvp;
 
     foreach(const SyncMergeDetails &sd, items) {
-        Nepomuk2::Resource publication;
+        Nepomuk2::Resource resource;
 
         QUrl syncType = sd.syncResource.property(SYNC::syncDataType()).toUrl();
 
         if( syncType == SYNC::Note()) {
-            publication = sd.syncResource.property(SYNC::note()).toResource();
+            resource = sd.syncResource.property(SYNC::note()).toResource();
         }
         else if ( syncType == SYNC::Attachment()) {
-            publication = sd.syncResource.property(SYNC::attachment()).toResource();
+            resource = sd.syncResource.property(SYNC::attachment()).toResource();
         }
         else {
-            publication = sd.syncResource.property(SYNC::reference()).toResource();
+            resource = sd.syncResource.property(SYNC::reference()).toResource();
         }
-/*
- //FIXME: fix merge ite mdialog
+
+        ntvp.pipeExport(QList<Nepomuk2::Resource>() << resource);
+        QVariantList localExportedList = ntvp.variantList();
         MergedResults mr;
         mr.localSyncResource = sd.syncResource;
-        mr.originalServerEntry = sd.externalResource;
-        mr.serverChanges = BibTexToNepomukPipe::getDiff(publication, \
                sd.externalResource, false, mr.localEntry);
-        mr.mergedChanges = mr.serverChanges;
+        mr.localEntry = localExportedList.first().toMap();
+        mr.serverEntry = sd.externalResource;
+
+        // get each key that has a different content
+        //TODO: put this into NepomukToVariantPipe ?
+        QMapIterator<QString, QVariant> i(mr.serverEntry);
+         while (i.hasNext()) {
+             i.next();
+
+             QString keyToCheck = i.key().toLower();
+
+             // the server item has no content, and the key does not exist in the \
local storage +             if( i.value().toString().isEmpty() && \
!mr.localEntry.contains(keyToCheck) ) { +                 continue;
+             }
+
+             if( i.value() != mr.localEntry.value(keyToCheck) ) {
+                 QVariant localValue = mr.localEntry.value(keyToCheck);
+                 // exception for date handling
+                 if(keyToCheck == QLatin1String("accessdate")) {
+                     // ignore if server is 2012-01-12 and local is \
2012-01-13T00:00:00Z +                     \
if(localValue.toString().startsWith(i.value().toString())) +                         \
continue; +                 }
+
+                 //TODO: for names/tags check also different order of the entry
+                 // otherwise add the entry differeces
+                 mr.differendKeys << keyToCheck;
+             }
+         }
+
         m_mergeResults.append(mr);
-        */
     }
 
     ui->previousButton->setEnabled(false);
@@ -234,6 +261,7 @@ void ItemMergeDialog::showPrevious()
 
 void ItemMergeDialog::finish()
 {
+    kDebug() << "finish ... merge all differences";
     /*
     BibTexToNepomukPipe btnp;
     btnp.setSyncDetails(m_psd.url, m_psd.userName);
@@ -246,8 +274,9 @@ void ItemMergeDialog::finish()
         btnp.mergeManual(mr.localSyncResource, mr.mergedChanges);
     }
 
-    accept();
     */
+
+    accept();
 }
 
 void ItemMergeDialog::replaceSelection()
@@ -260,12 +289,13 @@ void ItemMergeDialog::replaceSelection()
     QString key = cb->itemData(index).toString();
 
     if(index == 0) { // stick to local
-        mr.mergedChanges->remove( key );
+        mr.mergedChanges.remove( key );
     }
     else { // select server changes
-        mr.mergedChanges->insert( key , mr.originalServerEntry->value(key)); // i \
                need to take the entry from originalServerEntry because the entry \
                from serverChanges
-                                                                             // got \
altered somehow and only has 1 of the several entries (so only 1 instead of 4 \
authors) +        mr.mergedChanges.insert( key , mr.serverEntry.value(key));
     }
+
+    m_mergeResults.replace(m_currentItem, mr);
 }
 
 void ItemMergeDialog::showItem(int index)
@@ -279,8 +309,9 @@ void ItemMergeDialog::showItem(int index)
 
     QUrl syncType = mr.localSyncResource.property(SYNC::syncDataType()).toUrl();
 
-    kDebug() << "sync type" << syncType << "entry item type" << \
mr.mergedChanges->type(); +    kDebug() << "sync type" << syncType << "entry item \
type" << mr.localEntry.value(QLatin1String("bibtexentrytype"));  
+    //TODO: put icon stuff in MergeResource creation
     if( syncType == SYNC::Note()) {
         publication = mr.localSyncResource.property(SYNC::note()).toResource();
         ui->itemIcon->setPixmap(KIcon("knotes").pixmap(22,22));
@@ -307,33 +338,29 @@ void ItemMergeDialog::showItem(int index)
     QFormLayout *localLayout = new QFormLayout();
     localData->setLayout(localLayout);
 
-    // now we fill the groupboxes with the different values
-    QMapIterator<QString, Value> i(*mr.serverChanges);
-    while (i.hasNext()) {
-        i.next();
-
-        if( i.key().startsWith(QLatin1String("zotero")))
+    foreach(const QString &key, mr.differendKeys) {
+        if(key.startsWith( QLatin1String("sync-") ))
             continue;
 
-        Value serverValue = i.value();
+        QString localValue = mr.localEntry.value(key).toString();
+        QString serverValue = mr.serverEntry.value(key).toString();
 
         // add server row
-        QLabel *valueLabel = new QLabel( PlainTextValue::text(serverValue) );
-        serverLayout->addRow(QLatin1String("<b>") + \
m_keyTranslate.value(i.key().toLower()) + QLatin1String(":</b>"), valueLabel); +      \
serverLayout->addRow(QLatin1String("<b>") + m_keyTranslate.value(key, key) + \
QLatin1String(":</b>"), new QLabel(serverValue)); +
 
         //add local row
         KComboBox *cb = new KComboBox;
-        Value localValue = mr.localEntry->value(i.key());
-        cb->addItem( PlainTextValue::text( localValue ), i.key() );
-        cb->addItem( PlainTextValue::text( serverValue ), i.key() );
-        localLayout->addRow(QLatin1String("<b>") + \
m_keyTranslate.value(i.key().toLower()) + QLatin1String(":</b>"), cb); +        \
cb->addItem( localValue, key ); +        cb->addItem( serverValue, key );
+        localLayout->addRow(QLatin1String("<b>") + m_keyTranslate.value(key, key) + \
QLatin1String(":</b>"), cb);  
         connect(cb, SIGNAL(currentIndexChanged(int)), this, \
SLOT(replaceSelection()));  
         // automatically select localvalue as default
-        mr.mergedChanges->insert( i.key() , localValue);
+        mr.mergedChanges.insert( key , localValue);
 
-        kDebug() << "insert key" << i.key() << "with" << \
PlainTextValue::text(i.value()); +        kDebug() << "insert key" << key << "with" \
<< localValue;  }
 
     // complete server groupbox
diff --git a/src/nbibio/ui/itemmergedialog.h b/src/nbibio/ui/itemmergedialog.h
index 36a8060..4a4240f 100644
--- a/src/nbibio/ui/itemmergedialog.h
+++ b/src/nbibio/ui/itemmergedialog.h
@@ -54,10 +54,11 @@ private slots:
 private:
     struct MergedResults {
         Nepomuk2::Resource localSyncResource;
-        QSharedPointer<Entry> localEntry;
-        Entry * originalServerEntry;
-        Entry * serverChanges;
-        Entry * mergedChanges;
+        QVariantMap localEntry;
+        QVariantMap serverEntry;
+        QStringList differendKeys;
+
+        QVariantMap mergedChanges;
     };
 
     void showItem(int index);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic