AlbumShaper 1.0a3
about.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 <qicon.h>
16#include <qpixmap.h>
17#include <qtabwidget.h>
18#include <q3textbrowser.h>
19#include <qpushbutton.h>
20#include <qstringlist.h>
21#include <qdatetime.h>
22#include <qfile.h>
23#include <qdir.h>
24#include <qdom.h>
25#include <qstringlist.h>
26#include <qmovie.h>
27#include <qapplication.h>
28#include <q3frame.h>
29//Added by qt3to4:
30#include <Q3TextStream>
31#include <QCloseEvent>
32#include <Q3GridLayout>
33
34//Projectwide includes
35#include "about.h"
36#include "../titleWidget.h"
37#include "../window.h"
38#include "../../config.h"
40
41#define DEFAULT_WIDTH 600
42#define DEFAULT_HEIGHT 500
43
44#define UNSET 0
45#define GET_RELEASES 1
46#define GET_NEW_IMPROVEMENTS 2
47#define GET_UPCOMING_FEATURES 3
48
49//==============================================
50About::About( int mode, QWidget* parent, const char* name ) : QDialog(parent,name)
51{
52 displayMode = mode;
53 //--------------------------------------------------------------
54 QColor white(255, 255, 255);
55 QColor darkBlue(35, 75, 139);
56 QColor black(0, 0, 0);
57 //--------------------------------------------------------------
58 //by default not getting anything
59 getMode = UNSET;
60 //--
61 //set window title
62 setCaption( tr("About Album Shaper"));
63 //--
64 //application logo
65 Q3Frame* logoFrame = new Q3Frame( this );
66 logoFrame->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
67 albumShaperLogo = new QLabel( logoFrame );
68 albumShaperLogo->setPixmap( QPixmap( QString(IMAGE_PATH)+"miscImages/albumShaper.png" ) );
69 //--
70 //if user chooses to get product updates information
71 releases = NULL;
72 if(((Window*)(qApp->mainWidget()))->getConfig()->getBool( "alerts", "showSoftwareUpdateAlerts"))
73 {
74 //set http host
75 http.setHost( "albumshaper.sourceforge.net" );
76 connect( &http, SIGNAL(done(bool)), this, SLOT(fileFetched(bool)) );
77 //--
78 //attempt to get releases list from website. this lets us find out if this
79 //copy of Album Shaper is outdated, and also allows us to know what
80 //changelogs to get.
82 http.get( "/webService/releases.xml");
83 }
84 //--
85 //text labels
86 QDate currentDate = QDate::currentDate();
87 int copyYearFirst = QMIN( currentDate.year(), 2003 );
88 int copyYearLast = QMAX( currentDate.year(), 2004 );
89
90
91 progDesc = new QLabel( QString("Album Shaper " +
92 QString(ALBUMSHAPER_VERSION) +
93 ", © %1-%2 Will Stokes").arg(copyYearFirst).arg(copyYearLast),
94 logoFrame );
95
96 progURL = new QLabel( "http://albumshaper.sourceforge.net", logoFrame );
97
98
99 QFont textFont = progDesc->font();
100 textFont.setWeight(QFont::Bold);
101 progDesc->setFont( textFont );
102 progURL->setFont( textFont );
103 //--
104 //tab widget which contains credits, changelog, etc
105 tabWidget = new QTabWidget( this );
106 //--
107 //create credits tab
108 credits = new Q3TextBrowser( this );
109 credits->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
110 credits->mimeSourceFactory()->setFilePath( QStringList(TEXT_PATH) );
111 credits->setSource( "about.html");
112 tabWidget->addTab(credits,
113 QIcon( QPixmap(QString(IMAGE_PATH)+"tabIcons/credits.png") ),
114 tr("Credits") );
115 //--
116 //create history tab
117 history = new Q3TextBrowser(this);
118 history->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
119 history->mimeSourceFactory()->setFilePath( QStringList(TEXT_PATH) );
120 history->setSource( "history.html");
121 tabWidget->addTab(history,
122 QIcon( QPixmap(QString(IMAGE_PATH)+"tabIcons/history.png") ),
123 tr("History") );
124 //--
125 //create close button
126 closeButton = new QPushButton(
127 //PLATFORM_SPECIFIC_CODE
128 #ifndef Q_OS_MACX
129 QPixmap(QString(IMAGE_PATH)+"buttonIcons/button_ok.png"),
130 #endif
131 tr("Close"),
132 this );
133 closeButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
134 closeButton->setDefault(true);
135 connect( closeButton, SIGNAL(clicked()), SLOT(close()) );
136 //--
137 logoFrame->setPaletteBackgroundColor( darkBlue );
138 progDesc->setPaletteForegroundColor( white );
139 progDesc->setPaletteBackgroundColor( darkBlue );
140 progURL->setPaletteForegroundColor( white );
141 progURL->setPaletteBackgroundColor( darkBlue );
142 tabWidget->setPaletteForegroundColor( black );
143 //--
144 Q3GridLayout* logoGrid = new Q3GridLayout( logoFrame, 4, 3, 0);
145 logoGrid->setSpacing(WIDGET_SPACING);
146 logoGrid->addWidget( albumShaperLogo, 0, 1, Qt::AlignCenter );
147 logoGrid->addWidget( progDesc, 2, 1, Qt::AlignCenter );
148 logoGrid->addWidget( progURL, 3, 1, Qt::AlignCenter );
149
150 grid = new Q3GridLayout( this, 3, 1, 0);
151 grid->setSpacing(WIDGET_SPACING);
152 grid->addWidget( logoFrame, 0, 0 );
153 grid->addWidget( tabWidget, 1, 0 );
154 grid->addWidget( closeButton, 2, 0, Qt::AlignCenter );
155 resize( DEFAULT_WIDTH, DEFAULT_HEIGHT );
156 //--
157 //show secret images around Album Shaper's birthday (first release date - 4/3/2003)
158 if( currentDate.year() > 2003 && currentDate.month() == 4 && currentDate.day() <= 3)
159 {
160 QLabel* cakeLogo = new QLabel(logoFrame);
161 cakeLogo->setPixmap( QPixmap( QString(IMAGE_PATH)+"miscImages/birthdayL.png" ) );
162 QLabel* cakeLogo2 = new QLabel(logoFrame);
163 cakeLogo2->setPixmap( QPixmap( QString(IMAGE_PATH)+"miscImages/birthdayR.png" ) );
164 QLabel* cakeMessage = new QLabel( QString( tr("Happy Birthday Album Shaper!") +
165 QString(" %1 ").arg(currentDate.year() - 2003) +
166 ( currentDate.year()-2003 == 1 ? tr("Year Old!") : tr("Years Old!")) ), logoFrame );
167 cakeMessage->setFont(textFont);
168 cakeMessage->setPaletteForegroundColor( white );
169 //--
170 logoGrid->addWidget( cakeLogo, 0, 0, Qt::AlignCenter );
171 logoGrid->addWidget( cakeLogo2, 0, 2, Qt::AlignCenter );
172 logoGrid->addMultiCellWidget( cakeMessage, 1, 1, 0, 2, Qt::AlignCenter );
173 }
174 //-------------------------------
175 //set window to not be resizeable
176 this->show();
177 setFixedSize(size());
178 //-------------------------------
179}
180//==============================================
182{
183 delete releases;
184 releases = NULL;
185}
186//==============================================
187void About::fileFetched(bool error)
188{
189 //------------------------------------------------------------
190 //if unable to get file bail
191 if(error)
192 {
193 getMode = UNSET;
194 return;
195 }
196 //------------------------------------------------------------
197 //getting releases?
198 if(getMode == GET_RELEASES)
199 {
200 //write releases to temp file
201 QFile fetchedDoc( TEMP_DIR + QString("/releases.xml") );
202 if(fetchedDoc.open(QIODevice::WriteOnly))
203 {
204 //----------------------------
205 //write to file
206 Q3TextStream stream( &fetchedDoc );
207 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
208 stream << QString( http.readAll() );
209 fetchedDoc.close();
210 //----------------------------
211 //parse xml file, construct string list of releases
212 //open file, bail if unable to
213 if( !fetchedDoc.open( QIODevice::ReadOnly ) )
214 {
215 getMode = UNSET;
216 return;
217 }
218
219 //parse dom
220 QDomDocument xmlDom;
221 if( !xmlDom.setContent( &fetchedDoc ) )
222 {
223 fetchedDoc.close();
224 getMode = UNSET;
225 return;
226 }
227
228 //close file
229 fetchedDoc.close();
230
231 //construct stringlist of releases
232 releases = new QStringList();
233 QDomElement root = xmlDom.documentElement();
234 QDomNode node = root.firstChild();
235 QDomText val;
236 bool thisVersionFound = false;
237 while( !node.isNull() )
238 {
239 if( node.isElement() && node.nodeName() == "release" )
240 {
241 val = node.firstChild().toText();
242 if(!val.isNull())
243 {
244 //append release #
245 releases->append( QString(val.nodeValue()) );
246
247 //is release this version?
248 if( QString(val.nodeValue()).compare( QString(ALBUMSHAPER_VERSION) ) == 0 )
249 thisVersionFound = true;
250
251 }
252 }
253 node = node.nextSibling();
254 }
255
256 //else if this version is not first on list but it was found in list then newer releases exist
257 if(thisVersionFound && releases->first().compare( QString(ALBUMSHAPER_VERSION) ) != 0 )
258 {
259 //create new improvements file with beginning html and body tags
260 QFile fetchedDoc( TEMP_DIR + QString("/newImprovements.html") );
261 if(fetchedDoc.open(QIODevice::WriteOnly))
262 {
263 Q3TextStream stream( &fetchedDoc ); stream.setEncoding( Q3TextStream::UnicodeUTF8 );
264 stream << "<html><body bgcolor=\"white\" text=\"black\">\n";
265 stream << "<b><font size=\"+1\">" << tr("New improvements to Album Shaper are available in a new release!") << "<br><hr></font></b>";
266 fetchedDoc.close();
267 }
268
270 http.get( "/webService/" + releases->first() + "_changelog.html");
271 }
272 //else we're up to date! move on to checking for new features in cvs!
273 else
274 {
275 newImprovements = new Q3TextBrowser( this );
276 newImprovements->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
277 newImprovements->mimeSourceFactory()->setFilePath( QStringList(TEXT_PATH) );
278
279 //bleeding edge message
280 if(!thisVersionFound)
281 {
282 newImprovements->setSource( "bleedingEdge.html");
283 }
284 else
285 {
286 newImprovements->setSource( "noUpdates.html");
287 }
288
289 tabWidget->addTab(newImprovements,
290 QIcon( QPixmap(QString(IMAGE_PATH)+"tabIcons/newImprovements.png") ),
291 tr("Software Updates") );
292
293 if(displayMode == UPDATES)
294 tabWidget->setCurrentPage( tabWidget->indexOf( newImprovements ) );
295
297 http.get( "/webService/upcomingFeatures.html");
298 }
299 //----------------------------
300 //delete file
301 QDir rootDir( TEMP_DIR );
302 rootDir.remove("releases.xml");
303 //----------------------------
304 }
305 else
306 {
307 getMode = UNSET;
308 }
309 }
310 //------------------------------------------------------------
311 else if(getMode == GET_NEW_IMPROVEMENTS)
312 {
313 //write additional changelog information to disk
314 QFile fetchedDoc( TEMP_DIR + QString("/newImprovements.html") );
315 if(fetchedDoc.open(QIODevice::WriteOnly | QIODevice::Append))
316 {
317 //write to file
318 Q3TextStream stream( &fetchedDoc );
319 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
320 stream << QString( http.readAll() );
321 fetchedDoc.close();
322
323 //pop of release from stack
324 releases->pop_front();
325
326 //if stack empty then or we've goten up to this version add new tab with changes
327 if(releases->isEmpty() ||
328 releases->first().compare( QString(ALBUMSHAPER_VERSION) ) == 0 )
329 {
330 //tack on the end body and html tags
331 if(fetchedDoc.open(QIODevice::WriteOnly | QIODevice::Append))
332 {
333 //write to file
334 Q3TextStream stream( &fetchedDoc );
335 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
336 stream << "</body></html>";
337 fetchedDoc.close();
338
339 newImprovements = new Q3TextBrowser(this);
340 newImprovements->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
341 newImprovements->mimeSourceFactory()->setFilePath( TEMP_DIR );
342 newImprovements->setSource( "newImprovements.html" );
343 tabWidget->addTab(newImprovements,
344 QIcon( QPixmap(QString(IMAGE_PATH)+"tabIcons/newImprovements.png") ),
345 tr("Software Updates") );
346 tabWidget->setCurrentPage( tabWidget->indexOf( newImprovements ) );;
347
348 //move on to checking for upcoming features
350 http.get( "/webService/upcomingFeatures.html");
351 }
352 else
353 {
354 getMode = UNSET;
355 }
356 }
357 //if not empty then get even more new features!
358 else
359 {
360 http.get( "/webService/" + releases->first() + "_changelog.html");
361 }
362 }
363 else
364 {
365 getMode = UNSET;
366 }
367 }
368 //------------------------------------------------------------
369 //getting upcoming features?
371 {
372 //write upcoming features to temp file
373 QFile fetchedDoc( TEMP_DIR + QString("/upcomingFeatures.html") );
374 if(fetchedDoc.open(QIODevice::WriteOnly))
375 {
376 //write to file
377 Q3TextStream stream( &fetchedDoc );
378 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
379 stream << QString( http.readAll() );
380 fetchedDoc.close();
381
382 //add tab
384 upcomingFeatures->setFrameStyle( Q3Frame::Panel | Q3Frame::Sunken );
385 upcomingFeatures->mimeSourceFactory()->setFilePath( TEMP_DIR );
386 upcomingFeatures->setSource( "upcomingFeatures.html" );
388 QIcon( QPixmap(QString(IMAGE_PATH)+"tabIcons/upcomingFeatures.png") ),
389 tr("Upcoming Features") );
390
391 if(displayMode == UPCOMING)
392 tabWidget->setCurrentPage( tabWidget->indexOf( upcomingFeatures ) );
393
394 //delete file
395 QDir rootDir( TEMP_DIR );
396 rootDir.remove("upcomingFeatures.html");
397 }
398
399 getMode = UNSET;
400 }
401 //------------------------------------------------------------
402}
403//==============================================
404void About::closeEvent( QCloseEvent* e)
405{
406 QWidget::closeEvent( e );
407 emit closed();
408}
409//==============================================
411{
412 QDialog::reject();
413 emit closed();
414}
415//==============================================
#define DEFAULT_HEIGHT
Definition about.cpp:42
#define GET_RELEASES
Definition about.cpp:45
#define GET_UPCOMING_FEATURES
Definition about.cpp:47
#define DEFAULT_WIDTH
Definition about.cpp:41
#define UNSET
Definition about.cpp:44
#define GET_NEW_IMPROVEMENTS
Definition about.cpp:46
QLabel * albumShaperLogo
Definition about.h:59
Q3TextBrowser * credits
Definition about.h:66
QPushButton * closeButton
Close button.
Definition about.h:72
void closed()
QTabWidget * tabWidget
Definition about.h:64
Q3TextBrowser * history
Definition about.h:67
void reject()
Definition about.cpp:410
QLabel * progURL
Definition about.h:62
int getMode
Definition about.h:80
int displayMode
Definition about.h:83
Q3TextBrowser * newImprovements
Definition about.h:68
void closeEvent(QCloseEvent *e)
Definition about.cpp:404
QStringList * releases
Definition about.h:74
void fileFetched(bool error)
Definition about.cpp:187
About(int mode, QWidget *parent=0, const char *name=0)
Definition about.cpp:50
~About()
Definition about.cpp:181
Q3GridLayout * grid
Definition about.h:56
QLabel * progDesc
Definition about.h:61
Q3Http http
Definition about.h:77
Q3TextBrowser * upcomingFeatures
Definition about.h:69
Top level widget, encapsulates the title widget, the layout widget, and the toolbar widget.
Definition window.h:40
QString TEXT_PATH
Definition config.cpp:20
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
#define UPDATES
Definition titleWidget.h:45
#define UPCOMING
Definition titleWidget.h:46