[Digikam-devel] extragear/libs/kipi-plugins/gpssync

Gilles Caulier caulier.gilles at free.fr
Tue Oct 24 09:00:55 BST 2006


SVN commit 598625 by cgilles:

kipiplugins from trunk : GPSSync plugin: 

plugin now provides 3 sub-menu entries (instead just one) :

- Start GPS device correlator using current pictures selection.
- Start Geographical Coordinates editor to tag current pictures selection.
- Remove Geographical Coordinates from current pictures selection

CCBUGS: 135451
CCMAIL: kde-imaging at kde.org, digikam-devel at kde.org


 M  +6 -3      gpseditdialog.cpp  
 M  +140 -14   plugin_gpssync.cpp  
 M  +5 -3      plugin_gpssync.h  


--- trunk/extragear/libs/kipi-plugins/gpssync/gpseditdialog.cpp #598624:598625
@@ -196,21 +196,24 @@
     d->altitudeInput->text().toDouble(&ok);
     if (!ok)
     {
-        KMessageBox::error(this, i18n("Altitude value is not correct!"), i18n("GPS Sync"));    
+        KMessageBox::error(this, i18n("Altitude value is not correct!"), 
+                           i18n("Edit Geographical Coordinates"));    
         return;
     }        
 
     d->latitudeInput->text().toDouble(&ok);
     if (!ok)
     {
-        KMessageBox::error(this, i18n("Latitude value is not correct!"), i18n("GPS Sync"));    
+        KMessageBox::error(this, i18n("Latitude value is not correct!"), 
+                           i18n("Edit Geographical Coordinates"));    
         return;
     }        
 
     d->longitudeInput->text().toDouble(&ok);
     if (!ok)
     {
-        KMessageBox::error(this, i18n("Longitude value is not correct!"), i18n("GPS Sync"));    
+        KMessageBox::error(this, i18n("Longitude value is not correct!"), 
+                           i18n("Edit Geographical Coordinates"));    
         return;
     }        
 
--- trunk/extragear/libs/kipi-plugins/gpssync/plugin_gpssync.cpp #598624:598625
@@ -19,6 +19,10 @@
  *
  * ============================================================ */
 
+// Qt includes.
+
+#include <qfileinfo.h>
+
 // KDE includes.
 
 #include <klocale.h>
@@ -36,7 +40,10 @@
 
 // Local includes.
 
+#include "exiv2iface.h"
 #include "gpsbabelbinary.h"
+#include "gpsdatacontainer.h"
+#include "gpseditdialog.h"
 #include "gpssyncdialog.h"
 #include "plugin_gpssync.h"
 #include "plugin_gpssync.moc"
@@ -55,18 +62,37 @@
 {
     KIPI::Plugin::setup( widget );
 
-    // this is our action shown in the menubar/toolbar of the mainwindow
+    m_action_geolocalization = new KActionMenu(i18n("Geolocalization"),
+                               0,
+                               actionCollection(),
+                               "geolocalization");
 
-    m_actionGPSSync = new KAction (i18n("Geolocalization..."),
-                                   "gpsimagetag",
-                                   0,     
-                                   this,
-                                   SLOT(slotActivate()),
-                                   actionCollection(),
-                                   "gpssync");
+    m_action_geolocalization->insert(new KAction (i18n("Correlator..."),
+                                     "gpsimagetag",
+                                     0,     
+                                     this,
+                                     SLOT(slotGPSSync()),
+                                     actionCollection(),
+                                     "gpssync"));
 
-    addAction( m_actionGPSSync );
+    m_action_geolocalization->insert(new KAction (i18n("Edit coordinates..."),
+                                     0,
+                                     0,     
+                                     this,
+                                     SLOT(slotGPSEdit()),
+                                     actionCollection(),
+                                     "gpsedit"));
 
+    m_action_geolocalization->insert(new KAction (i18n("Remove coordinates..."),
+                                     0,
+                                     0,     
+                                     this,
+                                     SLOT(slotGPSRemove()),
+                                     actionCollection(),
+                                     "gpsremove"));
+
+    addAction( m_action_geolocalization );
+
     m_interface = dynamic_cast< KIPI::Interface* >( parent() );
 
     if ( !m_interface )
@@ -76,10 +102,10 @@
     }
 
     KIPI::ImageCollection selection = m_interface->currentSelection();
-    m_actionGPSSync->setEnabled( selection.isValid() && !selection.images().isEmpty() );
+    m_action_geolocalization->setEnabled( selection.isValid() && !selection.images().isEmpty() );
 
     connect( m_interface, SIGNAL(selectionChanged(bool)),
-             m_actionGPSSync, SLOT(setEnabled(bool)));
+             m_action_geolocalization, SLOT(setEnabled(bool)));
 }
 
 bool Plugin_GPSSync::checkBinaries(QString &gpsBabelVersion)
@@ -127,9 +153,8 @@
     return true;
 }
 
-void Plugin_GPSSync::slotActivate()
+void Plugin_GPSSync::slotGPSSync()
 {
-    // Get the current/selected album from host
     KIPI::ImageCollection images = m_interface->currentSelection();
 
     if ( !images.isValid() || images.images().isEmpty() )
@@ -147,9 +172,110 @@
     dialog->show();
 }
 
+void Plugin_GPSSync::slotGPSEdit()
+{
+    KIPI::ImageCollection images = m_interface->currentSelection();
+
+    if ( !images.isValid() || images.images().isEmpty() )
+        return;
+
+    KURL img = images.images().first();
+    KIPIPlugins::Exiv2Iface exiv2Iface;
+    exiv2Iface.load(img.path());
+    double alt, lat, lng;
+    bool hasGPSInfo = exiv2Iface.getGPSInfo(alt, lat, lng);
+    KIPIGPSSyncPlugin::GPSDataContainer gpsData(alt, lat, lng, false);
+
+    KIPIGPSSyncPlugin::GPSEditDialog dlg(kapp->activeWindow(), 
+                                         gpsData, img.fileName(), hasGPSInfo);
+
+    if (dlg.exec() == KDialogBase::Accepted)
+    {
+        gpsData = dlg.getGPSInfo();
+        KURL::List imageURLs = images.images();
+        KURL::List errorURLs;
+    
+        for( KURL::List::iterator it = imageURLs.begin() ; 
+            it != imageURLs.end(); ++it)
+        {
+            KURL url = *it;
+        
+            // We only add all JPEG files as R/W because Exiv2 can't yet 
+            // update metadata on others file formats.
+        
+            QFileInfo fi(url.path());
+            QString ext = fi.extension(false).upper();
+            if (ext == QString("JPG") || ext == QString("JPEG") || ext == QString("JPE"))
+            {
+                if (exiv2Iface.load(url.path()))
+                {
+                    bool ret = exiv2Iface.setGPSInfo(gpsData.altitude(), 
+                                                     gpsData.latitude(), 
+                                                     gpsData.longitude());
+                    ret &= exiv2Iface.save(url.path());
+                
+                    if (!ret)
+                        errorURLs.append(url);
+                }
+            }
+        }
+
+        if (!errorURLs.isEmpty())
+        {
+            KMessageBox::errorList(
+                        kapp->activeWindow(),
+                        i18n("Unable to save geographical coordinates to:"),
+                        errorURLs.toStringList(),
+                        i18n("Edit Geographical Coordinates"));  
+        }
+    }
+}
+
+void Plugin_GPSSync::slotGPSRemove()
+{
+    KIPI::ImageCollection images = m_interface->currentSelection();
+
+    if ( !images.isValid() || images.images().isEmpty() )
+        return;
+
+    KURL::List imageURLs = images.images();
+    KURL::List errorURLs;
+
+    for( KURL::List::iterator it = imageURLs.begin() ; 
+         it != imageURLs.end(); ++it)
+    {
+        KURL url = *it;
+    
+        // We only add all JPEG files as R/W because Exiv2 can't yet 
+        // update metadata on others file formats.
+    
+        QFileInfo fi(url.path());
+        QString ext = fi.extension(false).upper();
+        if (ext == QString("JPG") || ext == QString("JPEG") || ext == QString("JPE"))
+        {
+            KIPIPlugins::Exiv2Iface exiv2Iface;
+            exiv2Iface.load(url.path());
+            bool ret = exiv2Iface.removeGPSInfo();
+            ret &= exiv2Iface.save(url.path());
+        
+            if (!ret)
+                errorURLs.append(url);
+        }
+    }
+
+    if (!errorURLs.isEmpty())
+    {
+        KMessageBox::errorList(
+                    kapp->activeWindow(),
+                    i18n("Unable to remove geographical coordinates from:"),
+                    errorURLs.toStringList(),
+                    i18n("Remove Geographical Coordinates"));  
+    }
+}
+
 KIPI::Category Plugin_GPSSync::category( KAction* action ) const
 {
-    if ( action == m_actionGPSSync )
+    if ( action == m_action_geolocalization )
        return KIPI::IMAGESPLUGIN;
 
     kdWarning( 51000 ) << "Unrecognized action for plugin category identification" << endl;
--- trunk/extragear/libs/kipi-plugins/gpssync/plugin_gpssync.h #598624:598625
@@ -26,7 +26,7 @@
 
 #include <libkipi/plugin.h>
 
-class KAction;
+class KActionMenu;
 
 class Plugin_GPSSync : public KIPI::Plugin
 {
@@ -41,7 +41,9 @@
 
 protected slots:
 
-    void slotActivate();
+    void slotGPSSync();
+    void slotGPSEdit();
+    void slotGPSRemove();
 
 private:
 
@@ -49,7 +51,7 @@
 
 private:
 
-    KAction         *m_actionGPSSync;
+    KActionMenu     *m_action_geolocalization;
 
     KIPI::Interface *m_interface;
 };



More information about the Digikam-devel mailing list