[Kde-imaging] extragear/libs

Gilles Caulier caulier.gilles at gmail.com
Thu Nov 22 09:53:25 CET 2007


SVN commit 739979 by cgilles:

kipi-plugins from trunk (KDE4) : No need to re-invent the wheel. KIPI::ImageDialog no use KDE4 default KFileDialog to handle url or list of urls.

But the improvment here is to add RAW file formats type mime support that KFileDialog do not support.
The ImageDialog implementation is more simplified and is a pure Qt4/KDE4 now.
Api still unchanged for plugins maintener. You can port plugins code as well.
Important change here : libkipi depend now of libkdcraw. Please packager take a care for the future...

Angelo, porting this code in KDE3 branch is trivial. I waiting your viewpoint to do it. Of course this will require a new libkipi release.

CCMAIL: kde-imaging at kde.org



 M  +4 -33     kipi-plugins/sendimages/imagespage.cpp  
 M  +2 -0      libkipi/CMakeLists.txt  
 M  +2 -0      libkipi/NEWS  
 M  +2 -0      libkipi/README  
 M  +7 -1      libkipi/libkipi/CMakeLists.txt  
 M  +64 -206   libkipi/libkipi/imagedialog.cpp  
 M  +4 -23     libkipi/libkipi/imagedialog.h  


--- trunk/extragear/libs/kipi-plugins/sendimages/imagespage.cpp #739978:739979
@@ -30,6 +30,7 @@
 #include <QPalette>
 #include <QDragEnterEvent>
 #include <QUrl>
+#include <QFileInfo>
 
 // KDE includes.
 
@@ -37,20 +38,14 @@
 #include <kdialog.h>
 #include <knuminput.h>
 #include <kiconloader.h>
-#include <kfiledialog.h>
-#include <kimageio.h>
 #include <kdebug.h>
 
 // LibKIPI includes.
 
 #include <libkipi/imagecollection.h>
 #include <libkipi/interface.h>
+#include <libkipi/imagedialog.h>
 
-// LibKDcraw includes.
-
-#include <libkdcraw/rawfiles.h>
-#include <libkdcraw/dcrawbinary.h>
-
 // Local includes.
 
 #include "imagespage.h"
@@ -305,32 +300,8 @@
 
 void ImagesPage::slotAddItems()
 {
-    QString fileformats;
-   
-    QStringList patternList = KImageIO::pattern(KImageIO::Reading).split('\n', QString::SkipEmptyParts);
-    
-    // All Images from list must been always the first entry given by KDE API
-    QString allPictures = patternList[0];
-    
-    // Add other files format witch are missing to All Images" type mime provided by KDE and remplace current.
-    if (KDcrawIface::DcrawBinary::instance()->versionIsRight())
-    {
-        allPictures.insert(allPictures.indexOf("|"), QString(raw_file_extentions) + QString(" *.JPE *.TIF"));
-        patternList.removeAll(patternList[0]);
-        patternList.prepend(allPictures);
-    }
-    
-    // Added RAW file formats supported by dcraw program like a type mime. 
-    // Nota: we cannot use here "image/x-raw" type mime from KDE because it uncomplete 
-    // or unavailable(see file #121242 in B.K.O).
-    if (KDcrawIface::DcrawBinary::instance()->versionIsRight())
-        patternList.append(i18n("\n%1|Camera RAW files",QString(raw_file_extentions)));
-    
-    fileformats = patternList.join("\n");
-    
-    KUrl::List urls = KFileDialog::getOpenUrls(d->iface->currentAlbum().path(), 
-                                               fileformats, this, i18n("Add Images"));
-
+    KIPI::ImageDialog dlg(this, d->iface, false);
+    KUrl::List urls = dlg.urls();
     if (!urls.isEmpty())
         slotAddImages(urls);
 }
--- trunk/extragear/libs/libkipi/CMakeLists.txt #739978:739979
@@ -43,6 +43,8 @@
 
 # =======================================================
 
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
+FIND_PACKAGE(Kdcraw REQUIRED)
 
 SUBDIRS(pics)
 SUBDIRS(libkipi)
--- trunk/extragear/libs/libkipi/NEWS #739978:739979
@@ -1,6 +1,8 @@
 0.2.0
 ------------------------------------------------------------------------
+
 Port to CMake/KDE4/QT4
+new depency to libKDcraw
 
 0.1.6-svn
 ------------------------------------------------------------------------
--- trunk/extragear/libs/libkipi/README #739978:739979
@@ -18,7 +18,9 @@
 CMake      >= 2.4.x                     http://www.cmake.org
 libqt      >= 4.2.x                     http://www.trolltech.com
 libkde     >= 4.0.x                     http://www.kde.org
+libkdcraw  >= 0.2                       http://www.kipi-plugins.org
 
+
 -- INSTALL ------------------------------------------------------------
 
 In order to compile, especially when QT3/Qt4 are installed at the same time, 
--- trunk/extragear/libs/libkipi/libkipi/CMakeLists.txt #739978:739979
@@ -9,7 +9,13 @@
 
 KDE4_ADD_LIBRARY(kipi SHARED ${kipi_LIB_SRCS})
 
-TARGET_LINK_LIBRARIES(kipi ${KDE4_KPARTS_LIBS} ${KDE4_KFILE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QT3SUPPORT_LIBRARY})
+TARGET_LINK_LIBRARIES(kipi 
+                      ${KDCRAW_LIBRARIES} 
+                      ${KDE4_KPARTS_LIBS} 
+                      ${KDE4_KFILE_LIBS} 
+                      ${QT_QTGUI_LIBRARY} 
+                      ${QT_QT3SUPPORT_LIBRARY}
+                     )
 
 SET_TARGET_PROPERTIES(kipi PROPERTIES VERSION ${KIPI_LIB_SO_VERSION_STRING} SOVERSION ${KIPI_LIB_SO_CUR_VERSION})
 
--- trunk/extragear/libs/libkipi/libkipi/imagedialog.cpp #739978:739979
@@ -7,9 +7,6 @@
  * Description : an image files selector dialog.
  *
  * Copyright (C) 2004-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
- * Copyright (C) 2004-2005 by Renchi Raju <renchi.raju at kdemail.net>
- * Copyright (C) 2004-2005 by Jesper K. Pedersen <blackie at kde.org>
- * Copyright (C) 2004-2005 by Aurelien Gateau <aurelien dot gateau at free.fr>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -23,126 +20,86 @@
  * 
  * ============================================================ */
 
-// Qt includes.
- 
-#include <QPointer>
-#include <QLabel>
-#include <QSplitter>
-#include <QLayout>
-#include <QFrame>
-#include <QPushButton>
-#include <QTimer>
-
 // KDE includes.
 
-#include <kvbox.h>
 #include <kdebug.h>
-#include <k3listview.h>
 #include <klocale.h>
 #include <kstandarddirs.h>
-#include <kio/previewjob.h>
-#include <kiconloader.h>
+#include <kfiledialog.h>
+#include <kimageio.h>
 
+// LibKDcraw includes.
+
+#include <libkdcraw/rawfiles.h>
+#include <libkdcraw/dcrawbinary.h>
+
 // Local includes.
 
 #include "version.h"
+#include "interface.h"
+#include "imagecollection.h"
 #include "imagedialog.h"
-#include "imagedialog.moc"
 
-const int PREVIEW_SIZE = 128;
-
 namespace KIPI
 {
 
-struct AlbumLVI : public K3ListViewItem 
+class ImageDialogPrivate 
 {
-    AlbumLVI(K3ListView* parent, const ImageCollection& album)
-        : K3ListViewItem(parent, album.name()), _album(album) {}
+public:
 
-    const ImageCollection& _album;
-};
+    ImageDialogPrivate()
+    {
+        singleSelect = false;
+        iface        = 0;
+    }
 
+    bool             singleSelect;
 
-struct ImageLVI : public K3ListViewItem 
-{
-    ImageLVI(K3ListView* parent, const KUrl& url)
-        : K3ListViewItem(parent, url.fileName()), _url(url) {}
+    QString          fileformats;
 
-    KUrl _url;
-};
+    KUrl             url;
+    KUrl::List       urls;
 
-struct ImageDialog::Private 
-{
-    KUrl                   _url;
-    KUrl::List             _urls;
-    KIPI::Interface*       _interface;
-    K3ListView*            _albumList;
-    K3ListView*            _imageList;
-    QLabel*                _preview;
-    QList<ImageCollection> _albums;
-    bool                   _singleSelection;
+    KIPI::Interface *iface;
 };
 
-ImageDialog::ImageDialog(QWidget* parent, KIPI::Interface* interface,
-                         bool singleSelection)
-           : KDialog(parent)
+ImageDialog::ImageDialog(QWidget* parent, KIPI::Interface* iface, bool singleSelect)
 {
-    d = new Private;
-    d->_interface       = interface;
-    d->_singleSelection = singleSelection;
-
-    setCaption(i18n("Select Image From Album"));
-    setButtons(KDialog::Help | KDialog::Ok | KDialog::Cancel);
-    setModal(true);
-    setDefaultButton(KDialog::Ok);
-
-    KVBox *box = new KVBox( this );
-    setMainWidget( box );
-    QVBoxLayout *dvlay = new QVBoxLayout( box );
-
-    //---------------------------------------------
-
-    QSplitter* splitter = new QSplitter(box);
-
-    d->_albumList = new K3ListView(splitter);
-    d->_albumList->addColumn(i18n("Album Name"));
-    d->_albumList->setMinimumWidth(200);
-    d->_albumList->setResizeMode(Q3ListView::LastColumn);
-
-    d->_imageList = new K3ListView(splitter);
-    d->_imageList->addColumn(i18n("Image Name"));
-    d->_imageList->setMinimumWidth(200);
-    d->_imageList->setSelectionMode(singleSelection ? Q3ListView::Single :
-                                    Q3ListView::Extended);
-    d->_imageList->setResizeMode(Q3ListView::LastColumn);
-
-    d->_preview = new QLabel(splitter);
-    d->_preview->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
-    d->_preview->setFixedWidth(PREVIEW_SIZE);
-    d->_preview->setText(i18n("No image selected"));
-
-    dvlay->addWidget( splitter );
-
-    d->_albums = d->_interface->allAlbums();
-    QList<ImageCollection>::ConstIterator it=d->_albums.begin();
-
-    for(; it!=d->_albums.end(); ++it) 
+    d = new ImageDialogPrivate;
+    d->iface        = iface;
+    d->singleSelect = singleSelect;
+ 
+    QStringList patternList = KImageIO::pattern(KImageIO::Reading).split('\n', QString::SkipEmptyParts);
+    
+    // All Images from list must been always the first entry given by KDE API
+    QString allPictures = patternList[0];
+    
+    // Add other files format witch are missing to All Images" type mime provided by KDE and remplace current.
+    if (KDcrawIface::DcrawBinary::instance()->versionIsRight())
     {
-        new AlbumLVI(d->_albumList, *it);
+        allPictures.insert(allPictures.indexOf("|"), QString(raw_file_extentions) + QString(" *.JPE *.TIF"));
+        patternList.removeAll(patternList[0]);
+        patternList.prepend(allPictures);
     }
-    QTimer::singleShot(0, this, SLOT(slotInitialShow()));
+    
+    // Added RAW file formats supported by dcraw program like a type mime. 
+    // Nota: we cannot use here "image/x-raw" type mime from KDE because it uncomplete 
+    // or unavailable(see file #121242 in B.K.O).
+    if (KDcrawIface::DcrawBinary::instance()->versionIsRight())
+        patternList.append(i18n("\n%1|Camera RAW files",QString(raw_file_extentions)));
+    
+    d->fileformats = patternList.join("\n");
 
-    connect(d->_albumList, SIGNAL(selectionChanged(QListViewItem*)),
-            this, SLOT(fillImageList(QListViewItem*)) );
-
-    if (singleSelection)
-        connect(d->_imageList, SIGNAL(selectionChanged(QListViewItem*)),
-                this, SLOT(slotImageSelected(QListViewItem*)) );
+    if (singleSelect)
+    {
+        d->url = KFileDialog::getOpenUrl(d->iface->currentAlbum().path(), 
+                                         d->fileformats, parent, i18n("Select an Image"));
+    }
     else
-        connect(d->_imageList, SIGNAL(selectionChanged()),
-                this, SLOT(slotImagesSelected()));
-
-    enableButtonOk(false);
+    {
+        d->urls = KFileDialog::getOpenUrls(d->iface->currentAlbum().path(), 
+                                           d->fileformats, parent, i18n("Select Images"));
+    }
 }
 
 ImageDialog::~ImageDialog() 
@@ -152,18 +109,19 @@
 
 KUrl ImageDialog::url() const 
 {
-    return d->_url;
+    return d->url;
 }
 
 KUrl::List ImageDialog::urls() const
 {
-    return d->_urls;
+    return d->urls;
 }
 
-KUrl ImageDialog::getImageURL(QWidget* parent, Interface* interface) 
+KUrl ImageDialog::getImageURL(QWidget* parent, Interface* iface) 
 {
-    ImageDialog dlg(parent, interface, true);
-    if (dlg.exec() == QDialog::Accepted) 
+    ImageDialog dlg(parent, iface, true);
+
+    if (dlg.url().isValid())
     {
         return dlg.url();
     }
@@ -173,117 +131,17 @@
     }
 }
 
-KUrl::List ImageDialog::getImageURLs(QWidget* parent, Interface* interface)
+KUrl::List ImageDialog::getImageURLs(QWidget* parent, Interface* iface)
 {
-    ImageDialog dlg(parent, interface, false);
-    if (dlg.exec() == QDialog::Accepted)
-        return dlg.urls();
-    else
+    ImageDialog dlg(parent, iface, false);
+    if (!dlg.urls().isEmpty())
     {
-        KUrl::List urls;
-        return urls;
+        return dlg.urls();
     }
-}
-
-void ImageDialog::fillImageList(Q3ListViewItem* item) 
-{
-    d->_imageList->clear();
-    if (!item) return;
-
-    const ImageCollection& album = static_cast<AlbumLVI*>(item)->_album;
-    KUrl::List images=album.images();
-
-    KUrl::List::ConstIterator it=images.begin();
-    for (;it!=images.end(); ++it) 
-    {
-        new ImageLVI(d->_imageList, *it);
-    }
-}
-
-void ImageDialog::slotImageSelected(Q3ListViewItem* item) 
-{
-    if (!item) 
-    {
-        enableButtonOk(false);
-        d->_preview->setText(i18n("No image selected"));
-        d->_url=KUrl();
-        return;
-    }
-    enableButtonOk(true);
-    d->_url = static_cast<ImageLVI*>(item)->_url;
-    d->_preview->clear();
-
-    KIO::PreviewJob* thumbJob = KIO::filePreview(d->_url, PREVIEW_SIZE);
-    connect( thumbJob, SIGNAL(gotPreview(const K3FileItem*, const QPixmap&)),
-             SLOT(slotGotPreview(const K3FileItem* , const QPixmap&)));
-}
-
-void ImageDialog::slotImagesSelected()
-{
-    d->_url = KUrl();
-    d->_urls.clear();
-    d->_preview->clear();
-
-    Q3ListViewItem* selectedItem = 0;
-    Q3ListViewItem* listItem = d->_imageList->firstChild();
-    while (listItem)
-    {
-        if (listItem->isSelected())
-        {
-            selectedItem = listItem;
-            d->_urls.append(static_cast<ImageLVI*>(listItem)->_url);
-        }
-        listItem = listItem->nextSibling();
-    }
-
-    if (!selectedItem)
-    {
-        enableButtonOk(false);
-        d->_preview->setText(i18n("No images selected"));
-        d->_url=KUrl();
-        d->_urls.clear();
-        return;
-    }
-
-    enableButtonOk(true);
-
-    if (d->_urls.count() == 1)
-    {
-        d->_url = d->_urls.first();
-
-        KIO::PreviewJob* thumbJob = KIO::filePreview(d->_url, PREVIEW_SIZE);
-        connect( thumbJob, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)),
-                 SLOT(slotGotPreview(const KFileItem* , const QPixmap&)));
-    }
     else
     {
-        d->_url = d->_urls.first();
-        d->_preview->setText(i18np("1 image selected", "%1 images selected", d->_urls.count()));
+        return KUrl::List();
     }
 }
 
-void ImageDialog::slotGotPreview(const K3FileItem*, const QPixmap& pix) 
-{
-    d->_preview->setPixmap(pix);
-}
-
-void ImageDialog::slotInitialShow()
-{
-    ImageCollection current = d->_interface->currentAlbum();
-
-    Q3ListViewItemIterator it( d->_albumList );
-    while ( it.current() )
-    {
-        AlbumLVI* lvi = static_cast<AlbumLVI*>( it.current() );
-        if ( lvi->_album == current )
-        {
-            d->_albumList->ensureItemVisible( lvi );
-            d->_albumList->setSelected( lvi, true );
-            break;
-        }
-        ++it;
-    }
-}
-
 } // namespace KIPI
-
--- trunk/extragear/libs/libkipi/libkipi/imagedialog.h #739978:739979
@@ -7,9 +7,6 @@
  * Description : an image files selector dialog.
  *
  * Copyright (C) 2004-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
- * Copyright (C) 2004-2005 by Renchi Raju <renchi.raju at kdemail.net>
- * Copyright (C) 2004-2005 by Jesper K. Pedersen <blackie at kde.org>
- * Copyright (C) 2004-2005 by Aurelien Gateau <aurelien dot gateau at free.fr>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -34,27 +31,19 @@
 // KDE includes.
 
 #include <kurl.h>
-#include <kdialog.h>
 
 // LibKipi includes.
 
-#include "interface.h"
-#include "imagecollection.h"
 #include "libkipi_export.h"
 
-class Q3ListViewItem;
-
-class K3FileItem;
-
 namespace KIPI
 {
 
-class LIBKIPI_EXPORT ImageDialog : public KDialog 
+class ImageDialogPrivate;
+
+class LIBKIPI_EXPORT ImageDialog
 {
-Q_OBJECT
 
-    class Private;
-
 public:
 
     ImageDialog(QWidget*, Interface*, bool singleSelection=false);
@@ -66,17 +55,9 @@
     static KUrl getImageURL(QWidget*, Interface*);
     static KUrl::List getImageURLs(QWidget*, Interface*);
 
-private Q_SLOTS:
-
-    void fillImageList(Q3ListViewItem*);
-    void slotImageSelected(Q3ListViewItem*);
-    void slotImagesSelected();
-    void slotGotPreview(const K3FileItem*, const QPixmap&);
-    void slotInitialShow();
-
 private:
 
-    Private* d;
+    ImageDialogPrivate* d;
 };
 
 } // namespace KIPI


More information about the Kde-imaging mailing list