diff options
Diffstat (limited to 'src/newstuff/dialog.cpp')
-rw-r--r-- | src/newstuff/dialog.cpp | 101 |
1 files changed, 92 insertions, 9 deletions
diff --git a/src/newstuff/dialog.cpp b/src/newstuff/dialog.cpp index 786eb98..15c5b70 100644 --- a/src/newstuff/dialog.cpp +++ b/src/newstuff/dialog.cpp @@ -1,6 +1,9 @@ /*************************************************************************** copyright : (C) 2006 by Robby Stephenson email : robby@periapsis.org + + Copyright (c) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net> + ***************************************************************************/ /*************************************************************************** @@ -12,7 +15,6 @@ ***************************************************************************/ #include "dialog.h" -#include "providerloader.h" #include "../gui/listview.h" #include "../latin1literal.h" #include "../tellico_utils.h" @@ -50,6 +52,9 @@ #define ENTRYEMAIL(e) TQString() #endif +#define OPENDESKTOP_REDIRECT_URL "opendesktop.org/content/download.php?content=" +#define OPENDESKTOP_REDIRECT_TEXT "If the download does not start in 3 seconds:</span><span class=\"defaulttext\"> <a href=\"" + namespace { static const int NEW_STUFF_MIN_WIDTH = 600; static const int NEW_STUFF_MIN_HEIGHT = 400; @@ -223,10 +228,10 @@ Dialog::Dialog(NewStuff::DataType type_, TQWidget* parent_) setStatus(i18n("Downloading information...")); - ProviderLoader* loader = new Tellico::NewStuff::ProviderLoader(this); - connect(loader, TQT_SIGNAL(providersLoaded(TQPtrList<KNS::Provider>*)), TQT_SLOT(slotProviders(TQPtrList<KNS::Provider>*))); - connect(loader, TQT_SIGNAL(percent(TDEIO::Job*, unsigned long)), TQT_SLOT(slotShowPercent(TDEIO::Job*, unsigned long))); - connect(loader, TQT_SIGNAL(error()), TQT_SLOT(slotProviderError())); + KNS::ProviderLoader* loader = new KNS::ProviderLoader(this); + connect(loader, TQT_SIGNAL(providersLoaded(Provider::List*)), this, TQT_SLOT(slotProviders(Provider::List*))); + connect(loader, TQT_SIGNAL(percent(TDEIO::Job*, unsigned long)), this, TQT_SLOT(slotShowPercent(TDEIO::Job*, unsigned long))); + connect(loader, TQT_SIGNAL(error()), this, TQT_SLOT(slotProviderError())); TDEConfigGroup config(TDEGlobal::config(), "TDENewStuff"); TQString prov = config.readEntry("ProvidersUrl"); @@ -262,7 +267,7 @@ void Dialog::slotProviderError() { } } -void Dialog::slotProviders(TQPtrList<KNS::Provider>* list_) { +void Dialog::slotProviders(Provider::List* list_) { for(KNS::Provider* prov = list_->first(); prov; prov = list_->next()) { TDEIO::TransferJob* job = TDEIO::get(prov->downloadUrl()); m_jobs[job] = prov; @@ -296,14 +301,25 @@ void Dialog::slotResult(TDEIO::Job* job_) { } TQDomElement tdenewstuff = dom.documentElement(); + TQDomElement content; + + for(TQDomNode pn = tdenewstuff.firstChild(); !pn.isNull(); pn = pn.nextSibling()) + { + TQDomElement stuff = pn.toElement(); + + if(stuff.tagName() == "data") + { + content = pn.toElement(); + } + } - for(TQDomNode pn = tdenewstuff.firstChild(); !pn.isNull(); pn = pn.nextSibling()) { + for(TQDomNode pn = content.firstChild(); !pn.isNull(); pn = pn.nextSibling()) { TQDomElement stuff = pn.toElement(); if(stuff.isNull()) { continue; } - if(stuff.tagName() == Latin1Literal("stuff")) { + if(stuff.tagName() == Latin1Literal("content")) { KNS::Entry* entry = new KNS::Entry(stuff); if(!entry->type().isEmpty() && entry->type() != m_typeName) { myLog() << "NewStuff::Dialog::slotResult() - type mismatch, skipping " << ENTRYNAME(entry) << endl; @@ -408,11 +424,78 @@ void Dialog::slotInstall() { m_progress->show(); m_timer->start(100); connect(m_manager, TQT_SIGNAL(signalInstalled(KNS::Entry*)), TQT_SLOT(slotDoneInstall(KNS::Entry*))); - m_manager->install(m_type, entry); + mJobEntry = entry; + + // OpenDesktop.org broke the basic functionality of TDEHNS by forcing + // downloads though an advertising display page. This in turn forces + // the user to download and manually install the wallpaper, which + // is relatively complex and negates much of the benefit of TDEHNS. + // Therefore, if the download URL contains OPENDESKTOP_REDIRECT_URL + // then download the raw HTML page and extract the real download URL for use below. + // In the future we may want to figure out how to display unobtrusive ads + // during the download process, but OpenDesktop.org would need to add back + // in the direct download ability for this to even be considered. + if (entry->payload().url().contains(OPENDESKTOP_REDIRECT_URL)) { + TDEIO::TransferJob *job = TDEIO::get( KURL( entry->payload() ), false, false ); + connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotJobResult( TDEIO::Job * ) ) ); + connect( job, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), + TQT_SLOT( slotJobData( TDEIO::Job *, const TQByteArray & ) ) ); + } + else { + slotInstallPhase2(); + } +} + +void Dialog::slotInstallPhase2() { + m_manager->install(m_type, mJobEntry); delete m_cursorSaver; m_cursorSaver = 0; } +void Dialog::slotJobData( TDEIO::Job *, const TQByteArray &data ) +{ + kdDebug() << "DownloadDialog::slotJobData()" << endl; + + if ( data.size() == 0 ) return; + + TQCString str( data, data.size() + 1 ); + + mJobData.append( TQString::fromUtf8( str ) ); +} + +void Dialog::slotJobResult( TDEIO::Job *job ) +{ + if ( job->error() ) { + job->showErrorDialog( this ); + slotInstallPhase2(); + return; + } + + // See previous note regarding OpenDesktop.org + if (mJobEntry->payload().url().contains(OPENDESKTOP_REDIRECT_URL)) { + int pos = mJobData.find("<a href=\"/CONTENT/content-files/"); + if (pos >= 0) { + TQString realURL = mJobData.mid(pos); + realURL = realURL.mid(0, realURL.find("\">")); + realURL = realURL.mid(strlen("<a href=\"")); + realURL = mJobEntry->payload().protocol() + "://opendesktop.org" + realURL; + mJobEntry->setPayload(realURL); + } + else if ((pos = mJobData.find(OPENDESKTOP_REDIRECT_TEXT)) > 0) { + pos = pos + strlen(OPENDESKTOP_REDIRECT_TEXT); + TQString realURL = mJobData.mid(pos); + realURL = realURL.mid(0, realURL.find("\">")); + mJobEntry->setPayload(realURL); + } + } + + // Reset for next load + mJobData = TQString::null; + + slotInstallPhase2(); +} + void Dialog::slotDoneInstall(KNS::Entry* entry_) { TQMap<TQListViewItem*, KNS::Entry*>::Iterator it; for(it = m_entryMap.begin(); entry_ && it != m_entryMap.end(); ++it) { |