AlbumShaper 1.0a3
statusWidget.cpp
Go to the documentation of this file.
1//==============================================
2// copyright : (C) 2003-2005 by Will Stokes
3//==============================================
4// This program is free software; you can redistribute it
5// and/or modify it under the terms of the GNU General
6// Public License as published by the Free Software
7// Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//==============================================
10
11//Systemwide includes
12#include <qlayout.h>
13#include <qlabel.h>
14#include <qfont.h>
15#include <q3frame.h>
16#include <q3progressbar.h>
17#include <qfile.h>
18#include <qdom.h>
19#include <qstringlist.h>
20#include <qtooltip.h>
21#include <qpixmap.h>
22#include <qdir.h>
23#include <qmovie.h>
24#include <qtimer.h>
25#include <qsizegrip.h>
26//Added by qt3to4:
27#include <Q3GridLayout>
28#include <Q3TextStream>
29
30//Projectwide includes
31#include "clickableLabel.h"
32#include "statusWidget.h"
33#include "titleWidget.h"
34#include "window.h"
35#include "../config.h"
37
38//==============================================
40 const char* name ) : QWidget(parent,name)
41{
42 //create status message
43 message = new QLabel( this );
44 message->setText( "" );
45
46 //create timer object and setup signals
47 timer = new QTimer();
48 connect(timer, SIGNAL(timeout()), this, SLOT(removeStatus()) );
49
50 //create progress message and bar
51 progressBar = new Q3ProgressBar( this );
52 progressBar->setCenterIndicator(true);
53 progressBar->hide();
54 curStep = 0;
55
56 //-----------------------------------------------------------------
57 //setup http object to check for updates, only check for updates if they are enabled
58 updateAvailable = NULL;
59 http.setHost( "albumshaper.sourceforge.net" );
60 connect( &http, SIGNAL(done(bool)), this, SLOT(fileFetched(bool)) );
61 if(((Window*)parentWidget())->getConfig()->getBool( "alerts", "showSoftwareUpdateAlerts"))
62 {
64 }
65 //-----------------------------------------------------------------
66 //place progress frame and status message in main grid
67 grid = new Q3GridLayout( this, 1, 6, 0 );
68 grid->setSpacing(WIDGET_SPACING);
69 grid->setColSpacing( 0, WIDGET_SPACING );
70 grid->addWidget( message, 0, 1, Qt::AlignVCenter );
71 grid->addWidget( progressBar, 0, 2, Qt::AlignVCenter );
72 grid->setColStretch( 3, 1 );
73
74 //PLATFORM_SPECIFIC_CODE
75 //mac os x puts in a size grip that can interfere with the updates icon, in order
76 //to avoid this we manually place the size grip ourselves
77 //windows users expect a grip too, but qt doesn't put one in by default. we'll add
78 //it for them too. :-)
79 #if defined(Q_OS_MACX) || defined(Q_OS_WIN)
80 QSizeGrip* sizeGrip = new QSizeGrip( this );
81 grid->addWidget( sizeGrip, 0, 5, Qt::AlignBottom );
82 #endif
83
84}
85//==============================================
87{
88 delete timer;
89 timer = NULL;
90}
91//==============================================
92void StatusWidget::showProgressBar(QString message, int numSteps)
93{
94 //make sure timer is stopped so progress mess is never hidden
95 //this can occur if a new event is begun before the previous events message is removed after default delay
96 timer->stop();
97
98 //setup progress bar and show it
99 this->message->setText( message );
100 progressBar->setProgress( 0, numSteps );
101 progressBar->show();
102 curStep = 0;
103}
104//==============================================
105void StatusWidget::updateProgress(int progress, QString newMessage)
106{
107 curStep = progress;
108 progressBar->setProgress( progress );
109
110 //update message if provided
111 if(newMessage != QString::null)
112 {
113 this->message->setText( newMessage );
114 }
115}
116//==============================================
118{
119 return curStep;
120}
121//==============================================
123{
124 curStep++;
125 progressBar->setProgress( curStep );
126}
127//==============================================
128void StatusWidget::setStatus( QString message )
129{
130 timer->stop();
131
132 //hide progress bar
133 progressBar->hide();
134
135 //update status message
136 this->message->setText( message );
137
138 timer->start( 2000, TRUE );
139}
140//==============================================
142{
143 //set status message to empty string
144 message->setText( "" );
145}
146//==============================================
148{
149 //------------------------------------------------------------
150 //if unable to get file bail
151 if(error)
152 {
153 return;
154 }
155 //------------------------------------------------------------
156 //write releases to temp file
157 QFile fetchedDoc( TEMP_DIR + QString("/releases.xml") );
158 if(fetchedDoc.open(QIODevice::WriteOnly))
159 {
160 //----------------------------
161 //write to file
162 Q3TextStream stream( &fetchedDoc );
163 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
164 stream << QString( http.readAll() );
165 fetchedDoc.close();
166 //----------------------------
167 //parse xml file, construct string list of releases
168 //open file, bail if unable to
169 if( !fetchedDoc.open( QIODevice::ReadOnly ) )
170 {
171 return;
172 }
173
174 //parse dom
175 QDomDocument xmlDom;
176 if( !xmlDom.setContent( &fetchedDoc ) )
177 {
178 fetchedDoc.close();
179 return;
180 }
181
182 //close file
183 fetchedDoc.close();
184
185 //construct stringlist of releases
186 //actually, only get the first release since we don't need the others to determine if we
187 //are out of date
188
189 QStringList releases;
190 QDomElement root = xmlDom.documentElement();
191 QDomNode node = root.firstChild();
192 QDomText val;
193 bool thisVersionFound = false;
194 while( !node.isNull() )
195 {
196 if( node.isElement() && node.nodeName() == "release" )
197 {
198 val = node.firstChild().toText();
199 if(!val.isNull())
200 {
201 //append release #
202 releases.append( QString(val.nodeValue()) );
203
204 //is release this version?
205 if( QString(val.nodeValue()).compare( QString(ALBUMSHAPER_VERSION) ) == 0 )
206 thisVersionFound = true;
207 }
208 }
209 node = node.nextSibling();
210 }
211
212 //compare first release to this release, if strings not equal then we're outdated,
213 //update album shaper icon and start grabbing changelogs
214 if(thisVersionFound && releases.first().compare( QString(ALBUMSHAPER_VERSION) ) != 0)
215 {
216 ClickableLabel* uA = new ClickableLabel( this );
217 QMovie *m = new QMovie( QString(IMAGE_PATH)+"miscImages/updateAvailable.mng");
218 uA->setMovie(m);
219 QToolTip::add( uA, tr("Your copy of Album Shaper is not up to date! Click here for details") );
220 grid->addWidget( uA, 0, 4, Qt::AlignVCenter );
221 connect( uA, SIGNAL(clicked()),
222 ((Window*)parentWidget())->getTitle(), SLOT(aboutProgram()) );
223 uA->show();\
224 updateAvailable = uA;
225 }
226 }
227 //------------------------------------------------------------
228}
229//==============================================
231{
232 if(updateAvailable != NULL)
233 return;
234
235 //attempt to get releases list from website. this lets us find out if this
236 //copy of Album Shaper is outdated
237 http.get( "/webService/releases.xml");
238}
239//==============================================
241{
242 delete updateAvailable;
243 updateAvailable = NULL;
244}
245//==============================================
247{
248 grabKeyboard();
249 grabMouse();
250}
251//==============================================
253{
254 releaseKeyboard();
255 releaseMouse();
256}
257//==============================================
A clickable label.
void checkForUpdates()
Check for updates.
void setStatus(QString message)
Update message.
~StatusWidget()
Deletes all objects.
QLabel * message
ClickableLabel * updateAvailable
Update available label.
Q3GridLayout * grid
Layout widgets placed in.
void showProgressBar(QString message, int numSteps)
Initializes the progress bar.
Q3ProgressBar * progressBar
void fileFetched(bool error)
called once a file is fetched from the network
void removeUpdatesIcon()
Remove program updates icon.
QTimer * timer
void updateProgress(int progress, QString newMessage=QString::null)
Updates the progress bar.
int currentProgress()
Returns current progress in steps.
StatusWidget(QWidget *parent=0, const char *name=0)
Creates layout.
Q3Http http
http object for fetching releases file, used to check to see if installed copy is up to date
void removeStatus()
Unset message.
void incrementProgress()
Updates the progress bar by one step.
Top level widget, encapsulates the title widget, the layout widget, and the toolbar widget.
Definition window.h:40
QString IMAGE_PATH
Definition config.cpp:18
QString TEMP_DIR
Definition config.cpp:23
#define WIDGET_SPACING
Definition config.h:31
#define ALBUMSHAPER_VERSION
Definition config.h:21