[KPhotoAlbum] [PATCH 8/8] Cleanup: SettingsData.{h, cpp} are much more organized and consistent

Michael Witten mfwitten at MIT.EDU
Sun Sep 21 08:46:44 BST 2008


Mainly, I moved definitions around and grouped
them under common header comments.

I also named renamed some variables and KConfig
options.

Signed-off-by: Michael Witten <mfwitten at mit.edu>
---
 MainWindow/Window.cpp     |    2 +-
 Settings/SettingsData.cpp |  370 ++++++++++++++++++++++----------------------
 Settings/SettingsData.h   |   21 ++--
 3 files changed, 197 insertions(+), 196 deletions(-)

diff --git a/MainWindow/Window.cpp b/MainWindow/Window.cpp
index be4bb69..bdb3fe5 100644
--- a/MainWindow/Window.cpp
+++ b/MainWindow/Window.cpp
@@ -1694,7 +1694,7 @@ void MainWindow::Window::setupStatusBar()
     _dirtyIndicator = new DirtyIndicator( indicators );
 
     _lockedIndicator = new QLabel( indicators );
-    setLocked( Settings::SettingsData::instance()->isLocked(), true );
+    setLocked( Settings::SettingsData::instance()->locked(), true );
 
     statusBar()->addPermanentWidget( indicators, 0 );
 
diff --git a/Settings/SettingsData.cpp b/Settings/SettingsData.cpp
index 8d9227c..e6af3f0 100644
--- a/Settings/SettingsData.cpp
+++ b/Settings/SettingsData.cpp
@@ -123,6 +123,16 @@ SettingsData* SettingsData::instance()
     return _instance;
 }
 
+bool SettingsData::ready()
+{
+    return _instance != 0;
+}
+
+void SettingsData::setup( const QString& imageDirectory )
+{
+    _instance = new SettingsData( imageDirectory );
+}
+
 SettingsData::SettingsData( const QString& imageDirectory )
 {
     _hasAskedAboutTimeStamps = false;
@@ -150,6 +160,54 @@ property_copy( autoSave                              , setAutoSave
 property_copy( backupCount                           , setBackupCount                           ,  int            , General , 5                          );
 property_enum( tTimeStamps                           , setTTimeStamps                           ,  TimeStampTrust , General , Always                     );
 
+getValueFunc( QSize,histogramSize,  General,QSize(15,30) );
+getValueFunc( ViewSortType,viewSortType,  General,(int)SortLastUse );
+
+void SettingsData::setHistogramSize( const QSize& size )
+{
+    if ( size == histogramSize() )
+        return;
+
+    setValue( "General", "histogramSize", size );
+    emit histogramSizeChanged( size );
+}
+
+void SettingsData::setViewSortType( const ViewSortType tp )
+{
+    if ( tp == viewSortType() )
+        return;
+
+    setValue( "General", "viewSortType", (int)tp );
+    emit viewSortTypeChanged( tp );
+}
+
+bool SettingsData::trustTimeStamps()
+{
+    if ( tTimeStamps() == Always )
+        return true;
+    else if ( tTimeStamps() == Never )
+        return false;
+    else {
+        if (!_hasAskedAboutTimeStamps ) {
+            QApplication::setOverrideCursor( Qt::ArrowCursor );
+            QString txt = i18n("When reading time information of images, their EXIF info is used. "
+                               "Exif info may, however, not be supported by your KPhotoAlbum installation, "
+                               "or no valid information may be in the file. "
+                               "As a backup, KPhotoAlbum may use the timestamp of the image - this may, "
+                               "however, not be valid in case the image is scanned in. "
+                               "So the question is, should KPhotoAlbum trust the time stamp on your images?" );
+            int answer = KMessageBox::questionYesNo( 0, txt, i18n("Trust Time Stamps?") );
+            QApplication::restoreOverrideCursor();
+            if ( answer == KMessageBox::Yes )
+                _trustTimeStamps = true;
+            else
+                _trustTimeStamps = false;
+            _hasAskedAboutTimeStamps = true;
+        }
+        return _trustTimeStamps;
+    }
+}
+
 ////////////////////
 //// Thumbnails ////
 ////////////////////
@@ -164,6 +222,34 @@ property_copy( previewSize              , setPreviewSize             ,  int
 property_copy( thumbnailSpace           , setThumbnailSpace          ,  int                   , Thumbnails , 1          );
 property_enum( thumbnailAspectRatio     , setThumbnailAspectRatio    ,  ThumbnailAspectRatio  , Thumbnails , Aspect_4_3 );
 
+getValueFunc( int,thumbSize,  Thumbnails,128);
+
+getValueFunc( int,thumbnailCacheScreens,  Thumbnails,3); // Three pages sounds good; one before, one after the current screen
+
+void SettingsData::setThumbnailCacheScreens( int screens )
+{
+    setValue( "Thumbnails", "thumbnailCacheScreens", screens );
+    QPixmapCache::setCacheLimit( thumbnailCacheBytes() / 1024);
+    QPixmapCache::clear();
+}
+
+void SettingsData::setThumbSize( int value )
+{
+    QPixmapCache::clear();
+    setValue( "Thumbnails", "thumbSize", value );
+}
+
+size_t SettingsData::thumbnailBytesForScreens(int screens) {
+    const QRect screen = QApplication::desktop()->screenGeometry();
+    const size_t kBytesPerPixel = 4;
+    return kBytesPerPixel * screen.width() * screen.height() * screens;
+}
+
+size_t SettingsData::thumbnailCacheBytes() const
+{
+    return thumbnailBytesForScreens(thumbnailCacheScreens());
+}
+
 ////////////////
 //// Viewer ////
 ////////////////
@@ -187,22 +273,6 @@ property_copy( infoBoxHeight             , setInfoBoxHeight             ,  int
 property_enum( infoBoxPosition           , setInfoBoxPosition           ,  Position         , Viewer , Bottom         );
 property_enum( viewerStandardSize        , setViewerStandardSize        ,  StandardViewSize , Viewer , FullSize       );
 
-///////////////////////
-//// Miscellaneous ////
-///////////////////////
-
-property_copy( delayLoadingPlugins, setDelayLoadingPlugins,  bool, Plug-ins, true  );
-
-//////////////
-//// EXIF ////
-//////////////
-
-#ifdef HAVE_EXIV2
-    property_sset( exifForViewer , setExifForViewer ,           EXIF , StringSet()                            );
-    property_sset( exifForDialog , setExifForDialog ,           EXIF , Exif::Info::instance()->standardKeys() );
-    property_ref ( iptcCharset   , setIptcCharset   , QString , EXIF , (QString)QString::null                 );
-#endif
-
 bool SettingsData::smoothScale() const
 {
     return _smoothScale;
@@ -214,74 +284,23 @@ void SettingsData::setSmoothScale( bool b )
     setValue( "Viewer", "smoothScale", b );
 }
 
-bool SettingsData::trustTimeStamps()
-{
-    if ( tTimeStamps() == Always )
-        return true;
-    else if ( tTimeStamps() == Never )
-        return false;
-    else {
-        if (!_hasAskedAboutTimeStamps ) {
-            QApplication::setOverrideCursor( Qt::ArrowCursor );
-            QString txt = i18n("When reading time information of images, their EXIF info is used. "
-                               "Exif info may, however, not be supported by your KPhotoAlbum installation, "
-                               "or no valid information may be in the file. "
-                               "As a backup, KPhotoAlbum may use the timestamp of the image - this may, "
-                               "however, not be valid in case the image is scanned in. "
-                               "So the question is, should KPhotoAlbum trust the time stamp on your images?" );
-            int answer = KMessageBox::questionYesNo( 0, txt, i18n("Trust Time Stamps?") );
-            QApplication::restoreOverrideCursor();
-            if ( answer == KMessageBox::Yes )
-                _trustTimeStamps = true;
-            else
-                _trustTimeStamps = false;
-            _hasAskedAboutTimeStamps = true;
-        }
-        return _trustTimeStamps;
-    }
-}
-
-QString SettingsData::imageDirectory() const
-{
-    return _imageDirectory;
-}
-
-property_ref_( HTMLBaseDir, setHTMLBaseDir, QString, groupForDatabase( "HTML Settings" ), QString::fromLocal8Bit(getenv( "HOME" )) + STR( "/public_html" ) );
-property_ref_( HTMLBaseURL, setHTMLBaseURL, QString, groupForDatabase( "HTML Settings" ), STR( "file://" ) + HTMLBaseDir()                                 );
-property_ref_( HTMLDestURL, setHTMLDestURL, QString, groupForDatabase( "HTML Settings" ), STR( "file://" ) + HTMLBaseDir()                                 );
-
-property_ref_( password, setPassword, QString, groupForDatabase( "Privacy Settings" ), STR("") + HTMLBaseDir() );
-
-void SettingsData::setup( const QString& imageDirectory )
-{
-    _instance = new SettingsData( imageDirectory );
-}
-
-void SettingsData::setCurrentLock( const DB::ImageSearchInfo& info, bool exclude )
-{
-    info.saveLock();
-    setValue( groupForDatabase( "Privacy Settings" ), "exclude", exclude );
-}
-
-DB::ImageSearchInfo SettingsData::currentLock() const
-{
-    return DB::ImageSearchInfo::loadLock();
-}
+////////////////////
+//// Categories ////
+////////////////////
 
-getValueFunc_( bool,isLocked,  groupForDatabase("Privacy Settings"),"locked",false );
+setValueFunc( setAlbumCategory,QString&,  General,albumCategory );
 
-void SettingsData::setLocked( bool lock, bool force )
+QString SettingsData::albumCategory() const
 {
-    if ( lock == isLocked() && !force )
-        return;
+    QString category = value( "General", "albumCategory", STR("") );
 
-    setValue( groupForDatabase( "Privacy Settings" ), "locked", lock );
-    emit locked( lock, lockExcludes() );
-}
+    if ( !DB::ImageDB::instance()->categoryCollection()->categoryNames().contains( category ) )
+    {
+        category = DB::ImageDB::instance()->categoryCollection()->categoryNames()[0];
+        const_cast<SettingsData*>(this)->setAlbumCategory( category );
+    }
 
-bool SettingsData::lockExcludes() const
-{
-    return value( groupForDatabase( "Privacy Settings" ), "exclude", false );
+    return category;
 }
 
 // PENDING(blackie) move this function to Category
@@ -294,6 +313,29 @@ QString SettingsData::fileForCategoryImage( const QString& category, QString mem
     return fileName;
 }
 
+// PENDING(blackie) moved this function to Category
+QPixmap SettingsData::categoryImage( const QString& category, QString member, int size ) const
+{
+    QString fileName = fileForCategoryImage( category, member );
+    QString key = STR( "%1-%2" ).arg(size).arg(fileName);
+    QPixmap res;
+    if ( QPixmapCache::find( key, res ) )
+        return res;
+
+    QImage img;
+    bool ok = img.load( fileName, "JPEG" );
+    if ( ! ok ) {
+        if ( DB::ImageDB::instance()->memberMap().isGroup( category, member ) )
+            img = KIconLoader::global()->loadIcon( STR( "kuser" ), KIconLoader::Desktop, size ).toImage();
+        else
+            img = DB::ImageDB::instance()->categoryCollection()->categoryForName( category )->icon().toImage();
+    }
+    res = QPixmap::fromImage( Utilities::scaleImage(img, size, size, Qt::KeepAspectRatio) );
+
+    QPixmapCache::insert( key, res );
+    return res;
+}
+
 // PENDING(blackie) move this function to Category
 void SettingsData::setCategoryImage( const QString& category, QString member, const QImage& image )
 {
@@ -322,109 +364,78 @@ void SettingsData::setCategoryImage( const QString& category, QString member, co
     QPixmapCache::remove( key );
 }
 
-// PENDING(blackie) moved this function to Category
-QPixmap SettingsData::categoryImage( const QString& category, QString member, int size ) const
-{
-    QString fileName = fileForCategoryImage( category, member );
-    QString key = STR( "%1-%2" ).arg(size).arg(fileName);
-    QPixmap res;
-    if ( QPixmapCache::find( key, res ) )
-        return res;
-
-    QImage img;
-    bool ok = img.load( fileName, "JPEG" );
-    if ( ! ok ) {
-        if ( DB::ImageDB::instance()->memberMap().isGroup( category, member ) )
-            img = KIconLoader::global()->loadIcon( STR( "kuser" ), KIconLoader::Desktop, size ).toImage();
-        else
-            img = DB::ImageDB::instance()->categoryCollection()->categoryForName( category )->icon().toImage();
-    }
-    res = QPixmap::fromImage( Utilities::scaleImage(img, size, size, Qt::KeepAspectRatio) );
+//////////////
+//// Exif ////
+//////////////
 
-    QPixmapCache::insert( key, res );
-    return res;
-}
+#ifdef HAVE_EXIV2
+    property_sset( exifForViewer , setExifForViewer ,           Exif , StringSet()                            );
+    property_sset( exifForDialog , setExifForDialog ,           Exif , Exif::Info::instance()->standardKeys() );
+    property_ref ( iptcCharset   , setIptcCharset   , QString , Exif , (QString)QString::null                 );
+#endif
 
-getValueFunc( ViewSortType,viewSortType,  General,(int)SortLastUse );
+///////////////
+//// SQLDB ////
+///////////////
 
-void SettingsData::setViewSortType( const ViewSortType tp )
+#ifdef SQLDB_SUPPORT
+SQLDB::DatabaseAddress SettingsData::SQLParameters() const
 {
-    if ( tp == viewSortType() )
-        return;
-
-    setValue( "General", "viewSortType", (int)tp );
-    emit viewSortTypeChanged( tp );
+    KConfigGroup config = KGlobal::config()->group(QString::fromLatin1("SQLDB"));
+    try {
+        return SQLDB::readConnectionParameters(config);
+    }
+    catch (SQLDB::DriverNotFoundError&) {}
+    return SQLDB::DatabaseAddress();
 }
 
-void SettingsData::setFromDate( const QDate& date)
+void SettingsData::setSQLParameters(const SQLDB::DatabaseAddress& address)
 {
-    if (date.isValid())
-        setValue( "Miscellaneous", "fromDate", date.toString( Qt::ISODate ) );
+    KConfigGroup config = KGlobal::config()->group(QString::fromLatin1("SQLDB"));
+    SQLDB::writeConnectionParameters(address, config);
+    config.sync();
 }
+#endif /* SQLDB_SUPPORT */
+
+///////////////////////
+//// Miscellaneous ////
+///////////////////////
+
+property_copy( delayLoadingPlugins, setDelayLoadingPlugins,  bool, Plug-ins, true  );
+
+property_ref_( HTMLBaseDir, setHTMLBaseDir, QString, groupForDatabase( "HTML Settings" ), QString::fromLocal8Bit(getenv( "HOME" )) + STR( "/public_html" ) );
+property_ref_( HTMLBaseURL, setHTMLBaseURL, QString, groupForDatabase( "HTML Settings" ), STR( "file://" ) + HTMLBaseDir()                                 );
+property_ref_( HTMLDestURL, setHTMLDestURL, QString, groupForDatabase( "HTML Settings" ), STR( "file://" ) + HTMLBaseDir()                                 );
+
+property_ref_( password, setPassword, QString, groupForDatabase( "Privacy Settings" ), STR("") + HTMLBaseDir() );
 
 QDate SettingsData::fromDate() const
 {
     QString date = value( "Miscellaneous", "fromDate", STR("") );
-    if ( date.isEmpty() )
-        return QDate( QDate::currentDate().year(), 1, 1 );
-    else
-        return QDate::fromString( date, Qt::ISODate );
+    return date.isEmpty() ? QDate( QDate::currentDate().year(), 1, 1 ) : QDate::fromString( date, Qt::ISODate );
 }
 
-void  SettingsData::setToDate( const QDate& date)
+void SettingsData::setFromDate( const QDate& date)
 {
     if (date.isValid())
-        setValue( "Miscellaneous", "toDate", date.toString( Qt::ISODate ) );
+        setValue( "Miscellaneous", "fromDate", date.toString( Qt::ISODate ) );
 }
 
 QDate SettingsData::toDate() const
 {
     QString date = value( "Miscellaneous", "toDate", STR("") );
-    if ( date.isEmpty() )
-        return QDate( QDate::currentDate().year()+1, 1, 1 );
-    else
-        return QDate::fromString( date, Qt::ISODate );
+    return date.isEmpty() ? QDate( QDate::currentDate().year()+1, 1, 1 ) : QDate::fromString( date, Qt::ISODate );
 }
 
-QString SettingsData::albumCategory() const
-{
-    QString category = value( "General", "albumCategory", STR("") );
-
-    if ( !DB::ImageDB::instance()->categoryCollection()->categoryNames().contains( category ) )
-    {
-        category = DB::ImageDB::instance()->categoryCollection()->categoryNames()[0];
-        const_cast<SettingsData*>(this)->setAlbumCategory( category );
-    }
-
-    return category;
-}
-
-setValueFunc( setAlbumCategory,QString&,  General,albumCategory );
-
-void SettingsData::setWindowGeometry( WindowType win, const QRect& geometry )
-{
-    setValue( "Window Geometry", win, geometry );
-}
-
-QRect SettingsData::windowGeometry( WindowType win ) const
-{
-    return value( "Window Geometry", win, QRect(0,0,800,600) );
-}
-
-bool SettingsData::ready()
+void  SettingsData::setToDate( const QDate& date)
 {
-    return _instance != 0;
+    if (date.isValid())
+        setValue( "Miscellaneous", "toDate", date.toString( Qt::ISODate ) );
 }
 
-getValueFunc( QSize,histogramSize,  General,QSize(15,30) );
-
-void SettingsData::setHistogramSize( const QSize& size )
+QString SettingsData::imageDirectory() const
 {
-    if ( size == histogramSize() )
-        return;
-
-    setValue( "General", "histogramSize", size );
-    emit histogramSizeChanged( size );
+    return _imageDirectory;
 }
 
 QString SettingsData::groupForDatabase( const char* setting ) const
@@ -432,50 +443,39 @@ QString SettingsData::groupForDatabase( const char* setting ) const
     return STR("%1 - %2").arg( setting ).arg( imageDirectory() );
 }
 
-size_t SettingsData::thumbnailBytesForScreens(int screens) {
-    const QRect screen = QApplication::desktop()->screenGeometry();
-    const size_t kBytesPerPixel = 4;
-    return kBytesPerPixel * screen.width() * screen.height() * screens;
+DB::ImageSearchInfo SettingsData::currentLock() const
+{
+    return DB::ImageSearchInfo::loadLock();
 }
 
-// Three pages sounds good; one before, one after the current screen
-getValueFunc( int,thumbnailCacheScreens,  Thumbnails,3);
-
-void SettingsData::setThumbnailCacheScreens( int screens )
+void SettingsData::setCurrentLock( const DB::ImageSearchInfo& info, bool exclude )
 {
-    setValue( "Thumbnails", "thumbnailCacheScreens", screens );
-    QPixmapCache::setCacheLimit( thumbnailCacheBytes() / 1024);
-    QPixmapCache::clear();
+    info.saveLock();
+    setValue( groupForDatabase( "Privacy Settings" ), "exclude", exclude );
 }
 
-size_t SettingsData::thumbnailCacheBytes() const
+bool SettingsData::lockExcludes() const
 {
-    return thumbnailBytesForScreens(thumbnailCacheScreens());
+    return value( groupForDatabase( "Privacy Settings" ), "exclude", false );
 }
 
-getValueFunc( int,thumbSize,  Thumbnails,128);
+getValueFunc_( bool,locked,  groupForDatabase("Privacy Settings"),"locked",false );
 
-void SettingsData::setThumbSize( int value )
+void SettingsData::setLocked( bool lock, bool force )
 {
-    QPixmapCache::clear();
-    setValue( "Thumbnails", "thumbSize", value );
+    if ( lock == locked() && !force )
+        return;
+
+    setValue( groupForDatabase( "Privacy Settings" ), "locked", lock );
+    emit locked( lock, lockExcludes() );
 }
 
-#ifdef SQLDB_SUPPORT
-void SettingsData::setSQLParameters(const SQLDB::DatabaseAddress& address)
+void SettingsData::setWindowGeometry( WindowType win, const QRect& geometry )
 {
-    KConfigGroup config = KGlobal::config()->group(QString::fromLatin1("SQLDB"));
-    SQLDB::writeConnectionParameters(address, config);
-    config.sync();
+    setValue( "Window Geometry", win, geometry );
 }
 
-SQLDB::DatabaseAddress SettingsData::SQLParameters() const
+QRect SettingsData::windowGeometry( WindowType win ) const
 {
-    KConfigGroup config = KGlobal::config()->group(QString::fromLatin1("SQLDB"));
-    try {
-        return SQLDB::readConnectionParameters(config);
-    }
-    catch (SQLDB::DriverNotFoundError&) {}
-    return SQLDB::DatabaseAddress();
+    return value( "Window Geometry", win, QRect(0,0,800,600) );
 }
-#endif /* SQLDB_SUPPORT */
diff --git a/Settings/SettingsData.h b/Settings/SettingsData.h
index 857ec50..396b06e 100644
--- a/Settings/SettingsData.h
+++ b/Settings/SettingsData.h
@@ -105,14 +105,14 @@ public:
     property_copy( thumbSize                , setThumbSize               , int                  );
     property_copy( thumbnailAspectRatio     , setThumbnailAspectRatio    , ThumbnailAspectRatio );
 
-    size_t thumbnailCacheBytes() const;   // convenience method
-
     /**
      * Return an approximate figure of megabytes to cache to be able to
      * cache the amount of "screens" of caches.
      */
     static size_t thumbnailBytesForScreens(int screen);
 
+    size_t thumbnailCacheBytes() const;   // convenience method
+
     ////////////////
     //// Viewer ////
     ////////////////
@@ -144,11 +144,12 @@ public:
     property_ref( albumCategory, setAlbumCategory , QString);
 
     QString fileForCategoryImage ( const QString& category, QString member ) const;
-    void    setCategoryImage     ( const QString& category, QString, const QImage& image );
+
     QPixmap categoryImage        ( const QString& category,  QString, int size ) const;
+    void    setCategoryImage     ( const QString& category, QString, const QImage& image );
 
     //////////////
-    //// EXIF ////
+    //// Exif ////
     //////////////
 
 #ifdef HAVE_EXIV2
@@ -171,25 +172,25 @@ public:
 
     property_copy( delayLoadingPlugins, setDelayLoadingPlugins , bool);
 
-    property_ref( fromDate , setFromDate , QDate );
-    property_ref( toDate   , setToDate   , QDate );
+    property_ref( password, setPassword , QString);
 
     property_ref( HTMLBaseDir, setHTMLBaseDir , QString);
     property_ref( HTMLBaseURL, setHTMLBaseURL , QString);
     property_ref( HTMLDestURL, setHTMLDestURL , QString);
 
-    property_ref( password, setPassword , QString);
+    property_ref( fromDate , setFromDate , QDate );
+    property_ref( toDate   , setToDate   , QDate );
 
     QString imageDirectory() const;
 
     QString groupForDatabase( const char* setting ) const;
 
-    void setCurrentLock( const DB::ImageSearchInfo&, bool exclude );
     DB::ImageSearchInfo currentLock() const;
+    void setCurrentLock( const DB::ImageSearchInfo&, bool exclude );
+    bool lockExcludes() const;
 
+    bool locked() const;
     void setLocked( bool locked, bool force );
-    bool isLocked() const;
-    bool lockExcludes() const;
 
     void  setWindowGeometry( WindowType, const QRect& geometry );
     QRect windowGeometry( WindowType ) const;
-- 
1.6.0.2.296.gfe33b




More information about the Kphotoalbum mailing list