Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

statusWidget.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 <qprogressbar.h>
00017 #include <qfile.h>
00018 #include <qdom.h>
00019 #include <qstringlist.h>
00020 #include <qtooltip.h>
00021 #include <qpixmap.h>
00022 #include <qdir.h>
00023 #include <qmovie.h>
00024 #include <qtimer.h>
00025 #include <qsizegrip.h>
00026 
00027 //Projectwide includes
00028 #include "clickableLabel.h"
00029 #include "statusWidget.h"
00030 #include "titleWidget.h"
00031 #include "window.h"
00032 #include "../config.h"
00033 #include "../configuration/configuration.h"
00034 
00035 //==============================================
00036 StatusWidget::StatusWidget(QWidget *parent,
00037                          const char* name ) : QWidget(parent,name)
00038 {
00039  //create status message
00040   message = new QLabel( this );
00041   message->setText( "" );
00042   message->setFont( QFont( "Times", 12, QFont::Bold ) );
00043 
00044   //create timer object and setup signals
00045   timer = new QTimer();
00046   connect(timer, SIGNAL(timeout()), this, SLOT(removeStatus()) );
00047 
00048   //create progress message and bar
00049   progressBar = new QProgressBar( this );
00050   progressBar->setCenterIndicator(true);
00051   progressBar->hide();
00052   curStep = 0;
00053 
00054   //-----------------------------------------------------------------
00055   //setup http object to check for updates, only check for updates if they are enabled
00056   updateAvailable = NULL;
00057   http.setHost( "albumshaper.sourceforge.net" );
00058   connect( &http, SIGNAL(done(bool)), this, SLOT(fileFetched(bool)) );
00059   if(((Window*)parentWidget())->getConfig()->getBool( "alerts", "showSoftwareUpdateAlerts"))
00060   {
00061     checkForUpdates();
00062   }
00063   //-----------------------------------------------------------------
00064   //place progress frame and status message in main grid
00065   grid = new QGridLayout( this, 1, 6, 0 );
00066   grid->setSpacing(WIDGET_SPACING);
00067   grid->setColSpacing( 0, WIDGET_SPACING );
00068   grid->addWidget( message, 0, 1, Qt::AlignVCenter );
00069   grid->addWidget( progressBar, 0, 2, Qt::AlignVCenter );
00070   grid->setColStretch( 3, 1 );
00071 
00072   //PLATFORM_SPECIFIC_CODE
00073   //mac os x puts in a size grip that can interfere with the updates icon, in order
00074   //to avoid this we manually place the size grip ourselves
00075   //windows users expect a grip too, but qt doesn't put one in by default. we'll add
00076   //it for them too. :-)
00077   #if defined(Q_OS_MACX) || defined(Q_OS_WIN)
00078   QSizeGrip* sizeGrip = new QSizeGrip( this );
00079   grid->addWidget( sizeGrip, 0, 5, Qt::AlignBottom );
00080   #endif
00081 
00082 }
00083 //==============================================
00084 StatusWidget::~StatusWidget()
00085 {
00086   delete timer;
00087   timer = NULL;
00088 }
00089 //==============================================
00090 void StatusWidget::showProgressBar(QString message, int numSteps)
00091 {
00092   //make sure timer is stopped so progress mess is never hidden
00093   //this can occur if a new event is begun before the previous events message is removed after default delay
00094   timer->stop();
00095   
00096   //setup progress bar and show it
00097   this->message->setText( message );
00098   progressBar->setProgress( 0, numSteps );
00099   progressBar->show();
00100   curStep = 0;
00101 }
00102 //==============================================
00103 void StatusWidget::updateProgress(int progress, QString newMessage)
00104 {
00105   curStep = progress;
00106   progressBar->setProgress( progress );
00107 
00108   //update message if provided
00109   if(newMessage != QString::null)
00110   {
00111     this->message->setText( newMessage );
00112   }
00113 }
00114 //==============================================
00115 int StatusWidget::currentProgress()
00116 {
00117   return curStep;
00118 }
00119 //==============================================
00120 void StatusWidget::incrementProgress()
00121 {
00122   curStep++;
00123   progressBar->setProgress( curStep );
00124 }
00125 //==============================================
00126 void StatusWidget::setStatus( QString message )
00127 {
00128   timer->stop();
00129 
00130   //hide progress bar
00131   progressBar->hide();
00132 
00133   //update status message
00134   this->message->setText( message );
00135 
00136   timer->start( 2000, TRUE );
00137 }
00138 //==============================================
00139 void StatusWidget::removeStatus()
00140 {
00141   //set status message to empty string
00142   message->setText( "" );
00143 }
00144 //==============================================
00145 void StatusWidget::fileFetched(bool error)
00146 {
00147   //------------------------------------------------------------
00148   //if unable to get file bail
00149   if(error)
00150   {
00151     return;
00152   }
00153   //------------------------------------------------------------
00154   //write releases to temp file
00155   QFile fetchedDoc( TEMP_DIR + QString("/releases.xml") );
00156   if(fetchedDoc.open(IO_WriteOnly))
00157   {
00158     //----------------------------
00159     //write to file
00160     QTextStream stream( &fetchedDoc );
00161     stream.setEncoding( QTextStream::UnicodeUTF8 );
00162     stream << QString( http.readAll() );
00163     fetchedDoc.close();
00164     //----------------------------
00165     //parse xml file, construct string list of releases
00166     //open file, bail if unable to
00167     if( !fetchedDoc.open( IO_ReadOnly ) )
00168     {
00169       return;
00170     }
00171 
00172     //parse dom
00173     QDomDocument xmlDom;
00174     if( !xmlDom.setContent( &fetchedDoc ) )
00175     {
00176       fetchedDoc.close();
00177       return;
00178     }
00179 
00180     //close file
00181     fetchedDoc.close();
00182 
00183     //construct stringlist of releases
00184     //actually, only get the first release since we don't need the others to determine if we
00185     //are out of date
00186 
00187     QStringList releases;
00188     QDomElement root = xmlDom.documentElement();
00189     QDomNode node = root.firstChild();
00190     QDomText val;
00191     bool thisVersionFound = false;
00192     while( !node.isNull() )
00193     {
00194       if( node.isElement() && node.nodeName() == "release" )
00195       {
00196         val = node.firstChild().toText();
00197         if(!val.isNull())
00198         {
00199           //append release #
00200           releases.append( QString(val.nodeValue()) );
00201 
00202           //is release this version?
00203           if( QString(val.nodeValue()).compare( QString(ALBUMSHAPER_VERSION) ) == 0 )
00204             thisVersionFound = true;
00205         }
00206       }
00207       node = node.nextSibling();
00208     }
00209 
00210     //compare first release to this release, if strings not equal then we're outdated,
00211     //update album shaper icon and start grabbing changelogs
00212     if(thisVersionFound && releases.first().compare( QString(ALBUMSHAPER_VERSION) ) != 0)
00213     {
00214       ClickableLabel* uA = new ClickableLabel( this );
00215       uA->setMovie( QMovie( QString(IMAGE_PATH)+"miscImages/updateAvailable.mng") );
00216       QToolTip::add( uA, tr("Your copy of Album Shaper is not up to date! Click here for details") );
00217       grid->addWidget( uA, 0, 4, Qt::AlignVCenter );
00218       connect( uA, SIGNAL(clicked()),
00219                     ((Window*)parentWidget())->getTitle(), SLOT(aboutProgram()) );
00220       uA->show();\
00221       updateAvailable = uA;
00222     }
00223   }
00224   //------------------------------------------------------------
00225 }
00226 //==============================================
00227 void StatusWidget::checkForUpdates()
00228 {
00229   if(updateAvailable != NULL)
00230     return;
00231 
00232   //attempt to get releases list from website. this lets us find out if this
00233   //copy of Album Shaper is outdated
00234   http.get( "/webService/releases.xml");
00235 }
00236 //==============================================
00237 void StatusWidget::removeUpdatesIcon()
00238 {
00239   delete updateAvailable;
00240   updateAvailable = NULL;
00241 }
00242 //==============================================
00243 void StatusWidget::grabInput()
00244 {
00245   grabKeyboard();
00246   grabMouse(); 
00247 }
00248 //==============================================
00249 void StatusWidget::releaseInput()
00250 {
00251   releaseKeyboard();
00252   releaseMouse();
00253 }
00254 //==============================================

Generated on Sat Apr 2 05:44:04 2005 for AlbumShaper by  doxygen 1.3.9.1