Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes
UpgradeCheckerGUI Class Reference

#include <upgradechecker.h>

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

List of all members.

Public Slots

void fileStarted (bool error)
void fileFinished (bool error)
void reqStarted (int id)
void reqFinished (int id, bool error)

Public Member Functions

 UpgradeCheckerGUI (QWidget *widget=0)
 ~UpgradeCheckerGUI ()
bool fetch ()
bool process (QFile &dataFile)
void show (bool error)
QStringList upgradeData ()

Protected Member Functions

virtual void outputText (QString text)
void init ()

Protected Attributes

QWidget * outputWidget
bool writeToConsole
QString version
QString stability
uint major
uint minor
uint revision1
uint revision2
bool isCVS
QString platform
QStringList updates
QString tempFile
bool fin
QHttp * getter
int getterID
bool retrieveError
QString message

Detailed Description

Definition at line 58 of file upgradechecker.h.


Constructor & Destructor Documentation

UpgradeCheckerGUI::UpgradeCheckerGUI ( QWidget *  widget = 0)

Definition at line 263 of file upgradechecker.cpp.

 : UpgradeChecker(),
 outputWidget(widget)
{
       writeToConsole=false;
}

Definition at line 270 of file upgradechecker.cpp.

{
}

Member Function Documentation

bool UpgradeChecker::fetch ( ) [inherited]

Definition at line 66 of file upgradechecker.cpp.

{
       QString filename("scribusversions.xml");
       tempFile=ScPaths::getTempFileDir()+filename;

       fin=false;
       
       QFile file(tempFile);
       if (getter)
              delete getter;
       getter=new QHttp();
       connect (getter, SIGNAL(done(bool)), this, SLOT(fileFinished(bool)));
       connect (getter, SIGNAL(requestStarted(int)), this, SLOT(reqStarted(int)));
       connect (getter, SIGNAL(requestFinished(int, bool)), this, SLOT(reqFinished(int, bool)));
       retrieveError=false;
       getter->setHost("www.scribus.net");
       if (retrieveError)
              return true;
       outputText("<b>"+ tr("Attempting to get the Scribus version update file")+"</b>");
       outputText( tr("(No data on your computer will be sent to an external location)"));
       if(!file.open(IO_ReadWrite))
              return true;
       getterID=getter->get("/downloads/"+filename, &file);
       
       int waitCount=0;
       while (!fin && waitCount<10 && !retrieveError)
       {
              qApp->processEvents();
              sleep(1);
              ++waitCount;
              if (writeToConsole)
                     std::cout << ". " << std::flush;
       }
       if (writeToConsole)
              std::cout << std::endl;
       getter->closeConnection();
       bool errorOccurred=false;
       if (waitCount>=10)
       {
              outputText("<b>"+ tr("Timed out when attempting to get update file.")+"</b>");
              errorOccurred=true;
       }
       if (retrieveError || getter->error()!=QHttp::NoError)
       {
              outputText("<b>"+ tr("Error when attempting to get update file: %1").arg(getter->errorString())+"</b>");
              errorOccurred=true;
       }
       if (errorOccurred)
       {
              file.close();
              file.remove();
              return true;
       }

       file.reset();
       process(file);
       file.close();
       file.remove();
       return false;
}

Here is the call graph for this function:

void UpgradeChecker::fileFinished ( bool  error) [slot, inherited]

Definition at line 233 of file upgradechecker.cpp.

{
       fin=true;
}

Here is the caller graph for this function:

void UpgradeChecker::fileStarted ( bool  error) [slot, inherited]

Definition at line 238 of file upgradechecker.cpp.

{
}
void UpgradeChecker::init ( void  ) [protected, inherited]

Definition at line 41 of file upgradechecker.cpp.

{
       message="";
       getter=0;
       updates.clear();
       version=(VERSION);
       stability="unstable";
       QString versionStripped=version.lower();
       isCVS=versionStripped.contains("cvs");
       if (isCVS)
              versionStripped.remove("cvs");
       major=versionStripped.section('.',0,0).toInt();
       minor=versionStripped.section('.',1,1).toInt();
       revision1=versionStripped.section('.',2,2).toInt();
       revision2=versionStripped.section('.',3,4).toInt();
       #if defined(Q_OS_MAC)
       platform="MacOSX";
       #elif defined(Q_OS_WIN32)
       platform="Win32";
       #else
       platform="X11";
       #endif
}

Here is the caller graph for this function:

void UpgradeCheckerGUI::outputText ( QString  text) [protected, virtual]

Reimplemented from UpgradeChecker.

Definition at line 274 of file upgradechecker.cpp.

{
       TextBrowser* w=dynamic_cast<TextBrowser*>(outputWidget);
       if (w)
       {
              QString wText(w->text());
              wText.replace("\n","<br>");
              wText.remove("<qt>");
              wText.remove("</qt>");
              w->setText("<qt>"+wText+text+"<br>"+"</qt>");
       }      
}
bool UpgradeChecker::process ( QFile &  dataFile) [inherited]

Definition at line 127 of file upgradechecker.cpp.

{
       
       QTextStream ts(&dataFile);
       ts.setEncoding(QTextStream::UnicodeUTF8);
       QString errorMsg;
       int eline;
       int ecol;
       QDomDocument doc( "scribusversions" );
       QString data(ts.read());
       if ( !doc.setContent( data, &errorMsg, &eline, &ecol )) 
       {
              if (data.lower().contains("404 not found"))
                     outputText("<b>"+ tr("File not found on server")+"</b>");
              else
                     outputText("<b>"+ tr("Could not open version file: %1\nError:%2 at line: %3, row: %4").arg(dataFile.name()).arg(errorMsg).arg(eline).arg(ecol)+"</b>");
              return false;
       }
       
       QDomElement docElem = doc.documentElement();
       QDomNode n = docElem.firstChild();
       while( !n.isNull() ) {
              QDomElement e = n.toElement();
              if( !e.isNull() ) {
                     if (e.tagName()=="release")
                     {
                            if (e.hasAttribute("stability") && e.hasAttribute("platform") && e.hasAttribute("version"))
                            {
                                   if (e.attribute("platform")==platform)
                                   {
                                          bool newVersion = false;
                                          QString verA(e.attribute("version"));
                                          QString verAStripped=verA.lower();
                                          bool verIsCVS=verAStripped.contains("cvs");
                                          if (verIsCVS)
                                                 verAStripped.remove("cvs");
                                          uint verMajor=verAStripped.section('.',0,0).toInt();
                                          uint verMinor=verAStripped.section('.',1,1).toInt();
                                          uint verRevsion1=verAStripped.section('.',2,2).toInt();
                                          uint verRevsion2=verAStripped.section('.',3,3).toInt();
                                          //If we found a release whe a user is running an old CVS version
                                          if (verMajor==major && verMinor==minor && verRevsion1==revision1 && verRevsion2==revision2 && isCVS && !verIsCVS && !updates.contains(verA))
                                                 newVersion = true;
                                          else
                                          //If we found a version that is not the same as what we are running
                                          if (!(verMajor==major && verMinor==minor && verRevsion1==revision1 && verRevsion2==revision2))
                                          {
                                                 if (
                                                        ((verMajor>major) ||
                                                        (verMajor==major && verMinor>minor) ||
                                                        (verMajor==major && verMinor==minor && verRevsion1>revision1) ||
                                                        (verMajor==major && verMinor==minor && verRevsion1==revision1 && verRevsion2>revision2))
                                                        && !updates.contains(verA)
                                                        )
                                                        newVersion = true;
                                          }
                                          if (newVersion)
                                          {
                                                 QString ver = verA;
                                                 QString link = e.attribute("link", "");
                                                 if (!link.isEmpty())
                                                 {
                                                        QString linkStr = QString("<a href=\"%1\">%2</a>").arg(link).arg(link);
                                                        ver = QString("%1 : %2").arg(verA).arg(linkStr);
                                                 }
                                                 updates.append(ver);
                                          }
                                   }
                            }
                     }
                     else
                     if (e.tagName()=="message")
                     {
                            message+=e.text();
                     }
              }
              n = n.nextSibling();
       }
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void UpgradeChecker::reqFinished ( int  id,
bool  error 
) [slot, inherited]

Definition at line 246 of file upgradechecker.cpp.

{
       retrieveError=error;
}

Here is the caller graph for this function:

void UpgradeChecker::reqStarted ( int  id) [slot, inherited]

Definition at line 242 of file upgradechecker.cpp.

{
}

Here is the caller graph for this function:

void UpgradeChecker::show ( bool  error) [inherited]

Definition at line 213 of file upgradechecker.cpp.

{
       if (error)
       {
              outputText("<b>"+ tr("An error occurred while looking for updates for Scribus, please check your internet connection.")+"</b>");
              return;
       }
       if (updates.isEmpty())
              outputText("<b>"+ tr("No updates are available for your version of Scribus %1").arg(version)+"</b>");
       else
       {
              outputText("<b>"+ tr("One or more updates for your version of Scribus (%1) are available:").arg(version)+"</b>");
              outputText( tr("This list may contain development versions."));
              for ( QStringList::Iterator it = updates.begin(); it != updates.end(); ++it )
                     outputText(*it);
              outputText("<b>"+ tr("Please visit www.scribus.net for details.")+"</b>");
       }
       outputText(message);
}

Here is the call graph for this function:

QStringList UpgradeChecker::upgradeData ( ) [inherited]

Definition at line 208 of file upgradechecker.cpp.

{
       return updates;
}

Member Data Documentation

bool UpgradeChecker::fin [protected, inherited]

Definition at line 51 of file upgradechecker.h.

QHttp* UpgradeChecker::getter [protected, inherited]

Definition at line 52 of file upgradechecker.h.

int UpgradeChecker::getterID [protected, inherited]

Definition at line 53 of file upgradechecker.h.

bool UpgradeChecker::isCVS [protected, inherited]

Definition at line 47 of file upgradechecker.h.

uint UpgradeChecker::major [protected, inherited]

Definition at line 46 of file upgradechecker.h.

QString UpgradeChecker::message [protected, inherited]

Definition at line 55 of file upgradechecker.h.

uint UpgradeChecker::minor [protected, inherited]

Definition at line 46 of file upgradechecker.h.

QWidget* UpgradeCheckerGUI::outputWidget [protected]

Definition at line 68 of file upgradechecker.h.

QString UpgradeChecker::platform [protected, inherited]

Definition at line 48 of file upgradechecker.h.

bool UpgradeChecker::retrieveError [protected, inherited]

Definition at line 54 of file upgradechecker.h.

uint UpgradeChecker::revision1 [protected, inherited]

Definition at line 46 of file upgradechecker.h.

uint UpgradeChecker::revision2 [protected, inherited]

Definition at line 46 of file upgradechecker.h.

QString UpgradeChecker::stability [protected, inherited]

Definition at line 45 of file upgradechecker.h.

QString UpgradeChecker::tempFile [protected, inherited]

Definition at line 50 of file upgradechecker.h.

QStringList UpgradeChecker::updates [protected, inherited]

Definition at line 49 of file upgradechecker.h.

QString UpgradeChecker::version [protected, inherited]

Definition at line 44 of file upgradechecker.h.

bool UpgradeChecker::writeToConsole [protected, inherited]

Definition at line 43 of file upgradechecker.h.


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