loadingSavingWidget.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003-2005 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it
00005 //  and/or modify it under the terms of the GNU General
00006 //  Public License as published by the Free Software
00007 //  Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //==============================================
00010 
00011 //Systemwide includes
00012 #include <qlayout.h>
00013 #include <qlabel.h>
00014 #include <qfont.h>
00015 #include <qframe.h>
00016 #include <qcheckbox.h>
00017 #include <qvgroupbox.h>
00018 #include <qlineedit.h>
00019 #include <qpushbutton.h>
00020 #include <qtooltip.h>
00021 #include <qcombobox.h>
00022 #include <qstringlist.h>
00023 #include <qdir.h>
00024 #include <qfiledialog.h>
00025 #include <qslider.h>
00026 #include <qvalidator.h>
00027 
00028 //Projectwide includes
00029 #include "loadingSavingWidget.h"
00030 #include "configuration.h"
00031 #include "../config.h"
00032 
00033 //PLATFORM_SPECIFIC_CODE
00034 #if defined(Q_OS_WIN)
00035 #include <stdlib.h>
00036 #endif
00037 
00038 //==============================================
00039 LoadingSavingWidget::LoadingSavingWidget( Configuration* config,
00040                                           QWidget* parent,
00041                                           const char* name ) : QWidget( parent, name)
00042 {
00043   this->config = config;
00044 
00045   categoryLabel = new QLabel( tr("Loading + Saving:"), this);
00046   QFont labelFont = categoryLabel->font();
00047   labelFont.setWeight(QFont::Bold);
00048   categoryLabel->setFont( labelFont );
00049 
00050   horizontalLine = new QFrame(this);
00051   horizontalLine->setLineWidth(2);
00052   horizontalLine->setMidLineWidth(1);
00053   horizontalLine->setFrameStyle( QFrame::HLine | QFrame::Raised );
00054   //----------------
00055   //Default new album theme
00056   defaultToThisThemeFrame = new QFrame( this );
00057   defaultToThisThemeOnNew = new QLabel( tr("Default new album theme:"), defaultToThisThemeFrame);
00058   defaultToThisTheme = new QComboBox( defaultToThisThemeFrame );
00059   
00060   defaultToThisTheme->insertItem( tr("Last Used") );
00061   QDir localDir( THEMES_PATH );
00062   QStringList list = localDir.entryList( QDir::Dirs );
00063   QStringList::Iterator file;
00064   for ( file = list.begin(); file != list.end(); ++file )
00065   {
00066     if(localDir.exists( QString(*file) + "/theme.xsl" ))
00067       defaultToThisTheme->insertItem( *file );
00068   }
00069   
00070   defaultToThisThemeGrid = new QGridLayout(defaultToThisThemeFrame, 1, 4, 0);
00071   defaultToThisThemeGrid->addWidget(defaultToThisThemeOnNew, 0, 0);
00072   defaultToThisThemeGrid->setColSpacing(1, 8);
00073   defaultToThisThemeGrid->addWidget(defaultToThisTheme, 0, 2);
00074   defaultToThisThemeGrid->setColSpacing(3, 8);
00075   defaultToThisThemeGrid->setColStretch(3, 1);
00076   //----------------
00077   //Temp directory
00078   tempImageDirectoryFrame = new QFrame( this );
00079   tempImageDirectory = new QLabel( tr("Temporary image directory:"), tempImageDirectoryFrame);
00080   tempImageDirectoryVal = new QLineEdit( tempImageDirectoryFrame );
00081   tempImageDirectoryVal->setText( "/home" );
00082   browseButton = new QPushButton( tempImageDirectoryFrame );
00083   browseButton->setPixmap( QPixmap(QString(IMAGE_PATH)+"buttonIcons/browse.png") );
00084   browseButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
00085   QToolTip::add( browseButton, tr("Browse to temporary image directory") );
00086   connect( browseButton, SIGNAL(clicked()), SLOT(browse()) );
00087 
00088   tempImageDirectoryGrid = new QGridLayout(tempImageDirectoryFrame, 1, 5, 0);
00089   tempImageDirectoryGrid->addWidget(tempImageDirectory, 0, 0);
00090   tempImageDirectoryGrid->setColSpacing(1, 8);
00091   tempImageDirectoryGrid->addWidget(tempImageDirectoryVal, 0, 2);
00092   tempImageDirectoryGrid->setColStretch(2, 1);
00093   tempImageDirectoryGrid->setColSpacing(3, 8);
00094   tempImageDirectoryGrid->addWidget(browseButton, 0, 4);
00095   //----------------
00096   //Check photo mods since last load?
00097   checkPhotoMods = new QCheckBox( tr("Check for photo modifications"), this );
00098   //----------------
00099   //Setup larger boxes in overall grid
00100   mainGrid = new QGridLayout( this, 6, 1, 0);  
00101   mainGrid->setSpacing( WIDGET_SPACING );
00102     
00103   mainGrid->addWidget( categoryLabel, 0, 0, Qt::AlignLeft );
00104   mainGrid->addWidget( horizontalLine, 1, 0 );
00105   mainGrid->addWidget( defaultToThisThemeFrame,  2, 0 );
00106   mainGrid->addWidget( tempImageDirectoryFrame,  3, 0 );
00107   mainGrid->addWidget( checkPhotoMods,  4, 0 );
00108   mainGrid->setRowStretch( 5, 1 );
00109   //----------------
00110 }
00111 //==============================================
00112 void LoadingSavingWidget::browse()
00113 {
00114   QString dirName = QFileDialog::getExistingDirectory( tempImageDirectoryVal->text(),
00115                                                                           this, NULL, "Temporary Image Directory");
00116   if(!dirName.isNull())
00117     tempImageDirectoryVal->setText( dirName );
00118 }
00119 //==============================================
00120 void LoadingSavingWidget::setDefaults(Configuration* config)
00121 {
00122   config->setBool( "loadSave", "disableCheckPhotoMods", true );
00123   config->setString( "loadSave", "defaultTheme", "Last Used" );
00124   config->setString( "loadSave", "lastUsedTheme", "Slick" );
00125   //-------
00126   //set default loading/saving albums, add photo, and temp image directories
00127   config->setString( "loadSave", "tempImageDirectory", TEMP_DIR );
00128 
00129   //PLATFORM_SPECIFIC_CODE
00130 
00131   //Mac OS X
00132   #if defined(Q_OS_MACX)
00133   config->setString( "loadSave", "loadSaveDir",  QDir::homeDirPath() + QString("/Pictures") );
00134 
00135   //Windows
00136   #elif defined(Q_OS_WIN)
00137   config->setString( "loadSave", "loadSaveDir",
00138                            QDir::convertSeparators( getenv("USERPROFILE") +
00139                                                     QString("/My Documents/My Pictures") ));
00140 
00141   //Unix/Linux/BSD
00142   #else
00143   config->setString( "loadSave", "loadSaveDir", QDir::homeDirPath() );
00144   #endif
00145 
00146   config->setString( "loadSave", "addPhotoDir", config->getString( "loadSave", "loadSaveDir") );
00147   //-------
00148   config->setBool( "loadSave", "useDefaultImageSizes", true );
00149   config->setInt( "loadSave", "thumbWidth", 200 );
00150   config->setInt( "loadSave", "thumbHeight", 150 );
00151   config->setInt( "loadSave", "slideshowWidth", 600 );
00152   config->setInt( "loadSave", "slideshowHeight", 400 );
00153   config->setInt( "loadSave", "albumWidth", 500 );
00154   config->setInt( "loadSave", "albumHeight", 320 );
00155   config->setInt( "loadSave", "subalbumWidth", 200 );
00156   config->setInt( "loadSave", "subalbumHeight", 150 );
00157 }
00158 //==============================================
00159 void LoadingSavingWidget::loadSettings()
00160 {
00161   checkPhotoMods->setChecked( ! config->getBool( "loadSave", "disableCheckPhotoMods" ));
00162   tempImageDirectoryVal->setText( config->getString( "loadSave", "tempImageDirectory" ) );
00163   tempImageDirectoryVal->setCursorPosition(0);
00164 
00165   int i;
00166   bool defaultTFound = false;
00167   QString defaultT = config->getString( "loadSave", "defaultTheme" );
00168   for(i=1; i<defaultToThisTheme->count(); i++)
00169   {
00170     defaultToThisTheme->setCurrentItem(i);
00171     if(defaultToThisTheme->currentText().compare( defaultT ) == 0)
00172     {
00173       defaultTFound = true;
00174       break;
00175     }
00176   }
00177 
00178   if(!defaultTFound)
00179     defaultToThisTheme->setCurrentItem(0);
00180 }
00181 //==============================================
00182 void LoadingSavingWidget::saveSettings()
00183 {
00184   config->setBool( "loadSave", "disableCheckPhotoMods", !checkPhotoMods->isChecked() );
00185   config->setString( "loadSave", "tempImageDirectory",
00186   QDir::convertSeparators( QDir::cleanDirPath( tempImageDirectoryVal->text() ) ) );
00187   config->setString( "loadSave", "defaultTheme", defaultToThisTheme->currentText() );
00188 }
00189 //==============================================

Generated on Wed Nov 8 16:37:13 2006 for AlbumShaper by  doxygen 1.4.7