AlbumShaper  1.0a3
Public Member Functions | Private Slots | Private Attributes
StatusWidget Class Reference

#include <statusWidget.h>

Inheritance diagram for StatusWidget:
Inheritance graph
[legend]
Collaboration diagram for StatusWidget:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 StatusWidget (QWidget *parent=0, const char *name=0)
 Creates layout.
 ~StatusWidget ()
 Deletes all objects.
void showProgressBar (QString message, int numSteps)
 Initializes the progress bar.
void updateProgress (int progress, QString newMessage=QString::null)
 Updates the progress bar.
int currentProgress ()
 Returns current progress in steps.
void incrementProgress ()
 Updates the progress bar by one step.
void setStatus (QString message)
 Update message.
void checkForUpdates ()
 Check for updates.
void removeUpdatesIcon ()
 Remove program updates icon.
void grabInput ()
void releaseInput ()

Private Slots

void fileFetched (bool error)
 called once a file is fetched from the network
void removeStatus ()
 Unset message.

Private Attributes

QGridLayout * grid
 Layout widgets placed in.
QLabelmessage
QProgressBar * progressBar
int curStep
QTimer * timer
QHttp http
 http object for fetching releases file, used to check to see if installed copy is up to date
ClickableLabelupdateAvailable
 Update available label.

Detailed Description

Definition at line 28 of file statusWidget.h.


Constructor & Destructor Documentation

StatusWidget::StatusWidget ( QWidget parent = 0,
const char *  name = 0 
)

Creates layout.

Definition at line 36 of file statusWidget.cpp.

References checkForUpdates(), curStep, fileFetched(), grid, http, message, progressBar, removeStatus(), timer, updateAvailable, and WIDGET_SPACING.

                                            : QWidget(parent,name)
{
 //create status message
  message = new QLabel( this );
  message->setText( "" );
  
  //create timer object and setup signals
  timer = new QTimer();
  connect(timer, SIGNAL(timeout()), this, SLOT(removeStatus()) );

  //create progress message and bar
  progressBar = new QProgressBar( this );
  progressBar->setCenterIndicator(true);
  progressBar->hide();
  curStep = 0;

  //-----------------------------------------------------------------
  //setup http object to check for updates, only check for updates if they are enabled
  updateAvailable = NULL;
  http.setHost( "albumshaper.sourceforge.net" );
  connect( &http, SIGNAL(done(bool)), this, SLOT(fileFetched(bool)) );
  if(((Window*)parentWidget())->getConfig()->getBool( "alerts", "showSoftwareUpdateAlerts"))
  {
    checkForUpdates();
  }
  //-----------------------------------------------------------------
  //place progress frame and status message in main grid
  grid = new QGridLayout( this, 1, 6, 0 );
  grid->setSpacing(WIDGET_SPACING);
  grid->setColSpacing( 0, WIDGET_SPACING );
  grid->addWidget( message, 0, 1, Qt::AlignVCenter );
  grid->addWidget( progressBar, 0, 2, Qt::AlignVCenter );
  grid->setColStretch( 3, 1 );

  //PLATFORM_SPECIFIC_CODE
  //mac os x puts in a size grip that can interfere with the updates icon, in order
  //to avoid this we manually place the size grip ourselves
  //windows users expect a grip too, but qt doesn't put one in by default. we'll add
  //it for them too. :-)
  #if defined(Q_OS_MACX) || defined(Q_OS_WIN)
  QSizeGrip* sizeGrip = new QSizeGrip( this );
  grid->addWidget( sizeGrip, 0, 5, Qt::AlignBottom );
  #endif

}
StatusWidget::~StatusWidget ( )

Deletes all objects.

Definition at line 83 of file statusWidget.cpp.

References timer.

{
  delete timer;
  timer = NULL;
}

Member Function Documentation

void StatusWidget::checkForUpdates ( )

Check for updates.

Definition at line 226 of file statusWidget.cpp.

References http, and updateAvailable.

Referenced by StatusWidget().

{
  if(updateAvailable != NULL)
    return;

  //attempt to get releases list from website. this lets us find out if this
  //copy of Album Shaper is outdated
  http.get( "/webService/releases.xml");
}
int StatusWidget::currentProgress ( )

Returns current progress in steps.

Definition at line 114 of file statusWidget.cpp.

References curStep.

{
  return curStep;
}
void StatusWidget::fileFetched ( bool  error) [private, slot]

called once a file is fetched from the network

Definition at line 144 of file statusWidget.cpp.

References ALBUMSHAPER_VERSION, grid, http, IMAGE_PATH, and TEMP_DIR.

Referenced by StatusWidget().

{
  //------------------------------------------------------------
  //if unable to get file bail
  if(error)
  {
    return;
  }
  //------------------------------------------------------------
  //write releases to temp file
  QFile fetchedDoc( TEMP_DIR + QString("/releases.xml") );
  if(fetchedDoc.open(IO_WriteOnly))
  {
    //----------------------------
    //write to file
    QTextStream stream( &fetchedDoc );
    stream.setEncoding( QTextStream::UnicodeUTF8 );
    stream << QString( http.readAll() );
    fetchedDoc.close();
    //----------------------------
    //parse xml file, construct string list of releases
    //open file, bail if unable to
    if( !fetchedDoc.open( IO_ReadOnly ) )
    {
      return;
    }

    //parse dom
    QDomDocument xmlDom;
    if( !xmlDom.setContent( &fetchedDoc ) )
    {
      fetchedDoc.close();
      return;
    }

    //close file
    fetchedDoc.close();

    //construct stringlist of releases
    //actually, only get the first release since we don't need the others to determine if we
    //are out of date

    QStringList releases;
    QDomElement root = xmlDom.documentElement();
    QDomNode node = root.firstChild();
    QDomText val;
    bool thisVersionFound = false;
    while( !node.isNull() )
    {
      if( node.isElement() && node.nodeName() == "release" )
      {
        val = node.firstChild().toText();
        if(!val.isNull())
        {
          //append release #
          releases.append( QString(val.nodeValue()) );

          //is release this version?
          if( QString(val.nodeValue()).compare( QString(ALBUMSHAPER_VERSION) ) == 0 )
            thisVersionFound = true;
        }
      }
      node = node.nextSibling();
    }

    //compare first release to this release, if strings not equal then we're outdated,
    //update album shaper icon and start grabbing changelogs
    if(thisVersionFound && releases.first().compare( QString(ALBUMSHAPER_VERSION) ) != 0)
    {
      ClickableLabel* uA = new ClickableLabel( this );
      uA->setMovie( QMovie( QString(IMAGE_PATH)+"miscImages/updateAvailable.mng") );
      QToolTip::add( uA, tr("Your copy of Album Shaper is not up to date! Click here for details") );
      grid->addWidget( uA, 0, 4, Qt::AlignVCenter );
      connect( uA, SIGNAL(clicked()),
                    ((Window*)parentWidget())->getTitle(), SLOT(aboutProgram()) );
      uA->show();\
      updateAvailable = uA;
    }
  }
  //------------------------------------------------------------
}
void StatusWidget::grabInput ( )
void StatusWidget::incrementProgress ( )
void StatusWidget::releaseInput ( )
void StatusWidget::removeStatus ( ) [private, slot]

Unset message.

Definition at line 138 of file statusWidget.cpp.

References message.

Referenced by StatusWidget().

{
  //set status message to empty string
  message->setText( "" );
}
void StatusWidget::removeUpdatesIcon ( )

Remove program updates icon.

Definition at line 236 of file statusWidget.cpp.

References updateAvailable.

{
  delete updateAvailable;
  updateAvailable = NULL;
}
void StatusWidget::setStatus ( QString  message)
void StatusWidget::showProgressBar ( QString  message,
int  numSteps 
)

Initializes the progress bar.

Definition at line 89 of file statusWidget.cpp.

References curStep, progressBar, and timer.

Referenced by SubalbumWidget::addImageAction(), EditingInterface::applyEffect(), blackWhiteEffect(), correctImageTilt(), embossEffect(), enhanceImageContrast(), TitleWidget::exportLargeImages(), TitleWidget::exportSmallWebGallery(), Album::exportToDisk(), Album::importFromDisk(), improveColorBalance(), mosaicEffect(), oilPaintingEffect(), removeRedeyeRegions(), SubalbumWidget::rotate270ImageAction(), SubalbumWidget::rotate90ImageAction(), and sepiaEffect().

{
  //make sure timer is stopped so progress mess is never hidden
  //this can occur if a new event is begun before the previous events message is removed after default delay
  timer->stop();
  
  //setup progress bar and show it
  this->message->setText( message );
  progressBar->setProgress( 0, numSteps );
  progressBar->show();
  curStep = 0;
}
void StatusWidget::updateProgress ( int  progress,
QString  newMessage = QString::null 
)

Updates the progress bar.

Definition at line 102 of file statusWidget.cpp.

References curStep, message, and progressBar.

Referenced by SubalbumWidget::addImageAction(), Album::exportCompressedWebAlbum(), Album::exportLargeImages(), SubalbumWidget::rotate270ImageAction(), and SubalbumWidget::rotate90ImageAction().

{
  curStep = progress;
  progressBar->setProgress( progress );

  //update message if provided
  if(newMessage != QString::null)
  {
    this->message->setText( newMessage );
  }
}

Member Data Documentation

int StatusWidget::curStep [private]
QGridLayout* StatusWidget::grid [private]

Layout widgets placed in.

Definition at line 76 of file statusWidget.h.

Referenced by fileFetched(), and StatusWidget().

QHttp StatusWidget::http [private]

http object for fetching releases file, used to check to see if installed copy is up to date

Definition at line 85 of file statusWidget.h.

Referenced by checkForUpdates(), fileFetched(), and StatusWidget().

Definition at line 78 of file statusWidget.h.

Referenced by removeStatus(), StatusWidget(), and updateProgress().

QProgressBar* StatusWidget::progressBar [private]
QTimer* StatusWidget::timer [private]

Definition at line 82 of file statusWidget.h.

Referenced by setStatus(), showProgressBar(), StatusWidget(), and ~StatusWidget().

Update available label.

Definition at line 88 of file statusWidget.h.

Referenced by checkForUpdates(), removeUpdatesIcon(), and StatusWidget().


The documentation for this class was generated from the following files: