diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2014-10-08 15:41:08 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2014-10-08 15:41:08 -0500 |
commit | 1c137dacd1195df2bba9c110e7b7b325b56dee56 (patch) | |
tree | b4bbf858a16afad9312eef9dac59a3dcc4d5f627 /src/newstuff | |
parent | e4b4d01f652d8ae191a7ce029f8bb37f67f77fdb (diff) | |
download | tellico-1c137dacd1195df2bba9c110e7b7b325b56dee56.tar.gz tellico-1c137dacd1195df2bba9c110e7b7b325b56dee56.zip |
Fix TDEHotNewStuff interface with OCS providers
This relates to Bug 2127
Diffstat (limited to 'src/newstuff')
-rw-r--r-- | src/newstuff/Makefile.am | 2 | ||||
-rw-r--r-- | src/newstuff/dialog.cpp | 101 | ||||
-rw-r--r-- | src/newstuff/dialog.h | 19 | ||||
-rw-r--r-- | src/newstuff/manager.cpp | 7 | ||||
-rw-r--r-- | src/newstuff/providerloader.cpp | 102 | ||||
-rw-r--r-- | src/newstuff/providerloader.h | 85 |
6 files changed, 112 insertions, 204 deletions
diff --git a/src/newstuff/Makefile.am b/src/newstuff/Makefile.am index 9054dcb..1c962bc 100644 --- a/src/newstuff/Makefile.am +++ b/src/newstuff/Makefile.am @@ -2,7 +2,7 @@ noinst_LIBRARIES = libnewstuff.a libnewstuff_a_METASOURCES = AUTO -libnewstuff_a_SOURCES = manager.cpp dialog.cpp newscript.cpp providerloader.cpp +libnewstuff_a_SOURCES = manager.cpp dialog.cpp newscript.cpp CLEANFILES = *~ 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) { diff --git a/src/newstuff/dialog.h b/src/newstuff/dialog.h index 082fbd8..468b6c4 100644 --- a/src/newstuff/dialog.h +++ b/src/newstuff/dialog.h @@ -1,6 +1,8 @@ /*************************************************************************** copyright : (C) 2006 by Robby Stephenson email : robby@periapsis.org + + Copyright (c) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net> ***************************************************************************/ /*************************************************************************** @@ -17,16 +19,13 @@ #include "manager.h" #include <kdialogbase.h> +#include <tdenewstuff/provider.h> class KPushButton; class KStatusBar; namespace TDEIO { class Job; } -namespace KNS { - class Entry; - class Provider; -} class TQProgressBar; class TQSplitter; @@ -39,7 +38,9 @@ namespace Tellico { class CursorSaver; } - namespace NewStuff { +using namespace KNS; + +namespace NewStuff { class Dialog : public KDialogBase { Q_OBJECT @@ -52,15 +53,18 @@ public: TQPtrList<DataSourceInfo> dataSourceInfo() const { return m_manager->dataSourceInfo(); } private slots: - void slotProviders(TQPtrList<KNS::Provider>* list); + void slotProviders(Provider::List* list); void slotData(TDEIO::Job* job, const TQByteArray& data); void slotResult(TDEIO::Job* job); + void slotJobData( TDEIO::Job *, const TQByteArray & ); + void slotJobResult( TDEIO::Job * ); void slotPreviewResult(TDEIO::Job* job); void slotShowPercent(TDEIO::Job* job, unsigned long percent); void slotSelected(TQListViewItem* item); void slotInstall(); + void slotInstallPhase2(); void slotDoneInstall(KNS::Entry* entry); void slotProviderError(); @@ -95,6 +99,9 @@ private: TQMap<TQListViewItem*, KNS::Entry*> m_entryMap; TQListViewItem* m_lastPreviewItem; + + KNS::Entry* mJobEntry; + TQString mJobData; }; } diff --git a/src/newstuff/manager.cpp b/src/newstuff/manager.cpp index 304a110..9fed36e 100644 --- a/src/newstuff/manager.cpp +++ b/src/newstuff/manager.cpp @@ -367,7 +367,12 @@ void Manager::slotDownloadJobResult(TDEIO::Job* job_) { bool deleteTempFile = true; if(type == EntryTemplate) { - installTemplate(job->destURL(), entry->name()); + if (installTemplate(job->destURL(), entry->name())) { + emit signalInstalled(entry); + } + else { + emit signalInstalled(0); + } } else { #if KDE_IS_VERSION(3,3,90) // needed so the GPG signature can be checked diff --git a/src/newstuff/providerloader.cpp b/src/newstuff/providerloader.cpp deleted file mode 100644 index 625156c..0000000 --- a/src/newstuff/providerloader.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************** - copyright : (C) 2006 by Robby Stephenson - email : robby@periapsis.org - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of version 2 of the GNU General Public License as * - * published by the Free Software Foundation; * - * * - ***************************************************************************/ - -// this class is largely copied from tdelibs/tdenewstuff/provider.cpp -// which is Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> -// and licensed under GPL v2, just like Tellico - -#include "providerloader.h" -#include "../tellico_debug.h" -#include "../latin1literal.h" - -#include <tdeio/job.h> -#include <tdenewstuff/provider.h> -#include <tdeglobal.h> -#include <tdeconfig.h> -#include <tdemessagebox.h> -#include <tdelocale.h> - -#include <tqdom.h> - -using Tellico::NewStuff::ProviderLoader; - -ProviderLoader::ProviderLoader( TQWidget *parentWidget ) : - mParentWidget( parentWidget ), mTryAlt(true) -{ - mProviders.setAutoDelete( true ); -} - -void ProviderLoader::load( const TQString &type, const TQString &providersList ) -{ - mProviders.clear(); - mJobData.truncate(0); - -// myLog() << "ProviderLoader::load(): providersList: " << providersList << endl; - - TDEIO::TransferJob *job = TDEIO::get( KURL( providersList ), 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 & ) ) ); - connect( job, TQT_SIGNAL( percent (TDEIO::Job *, unsigned long) ), - TQT_SIGNAL( percent (TDEIO::Job *, unsigned long) ) ); - -// job->dumpObjectInfo(); -} - -void ProviderLoader::slotJobData( TDEIO::Job *, const TQByteArray &data ) -{ - if ( data.size() == 0 ) return; - TQCString str( data, data.size() + 1 ); - mJobData.append( TQString::fromUtf8( str ) ); -} - -void ProviderLoader::slotJobResult( TDEIO::Job *job ) -{ - if ( job->error() ) { - job->showErrorDialog( mParentWidget ); - if(mTryAlt && !mAltProvider.isEmpty()) { - mTryAlt = false; - load(TQString(), mAltProvider); - } else { - emit error(); - } - return; - } - - TQDomDocument doc; - if ( !doc.setContent( mJobData ) ) { - myDebug() << "ProviderLoader::slotJobResult() - error parsing providers list." << endl; - if(mTryAlt && !mAltProvider.isEmpty()) { - mTryAlt = false; - load(TQString(), mAltProvider); - } else { - emit error(); - } - return; - } - - TQDomElement providers = doc.documentElement(); - TQDomNode n; - for ( n = providers.firstChild(); !n.isNull(); n = n.nextSibling() ) { - TQDomElement p = n.toElement(); - - if ( p.tagName() == Latin1Literal("provider") ) { - mProviders.append( new KNS::Provider( p ) ); - } - } - - emit providersLoaded( &mProviders ); -} - -#include "providerloader.moc" diff --git a/src/newstuff/providerloader.h b/src/newstuff/providerloader.h deleted file mode 100644 index 91fedc9..0000000 --- a/src/newstuff/providerloader.h +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - copyright : (C) 2006 by Robby Stephenson - email : robby@periapsis.org - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of version 2 of the GNU General Public License as * - * published by the Free Software Foundation; * - * * - ***************************************************************************/ - -// this class is largely copied from tdelibs/tdenewstuff/provider.h -// which is Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> -// and licensed under GPL v2, just like Tellico -// -// I want progress info for the download, and this was the -// easiest way to get it - -#ifndef TELLICO_NEWSTUFF_PROVIDERLOADER_H -#define TELLICO_NEWSTUFF_PROVIDERLOADER_H - -#include <tqobject.h> -#include <tqptrlist.h> - -namespace TDEIO { - class Job; -} -namespace KNS { - class Provider; -} - -namespace Tellico { - namespace NewStuff { - -class ProviderLoader : public TQObject { -Q_OBJECT - -public: - /** - * Constructor. - * - * @param parentWidget the parent widget - */ - ProviderLoader( TQWidget *parentWidget ); - - /** - * Starts asynchronously loading the list of providers of the - * specified type. - * - * @param type data type such as 'kdesktop/wallpaper'. - * @param providerList the URl to the list of providers; if empty - * we first try the ProvidersUrl from TDEGlobal::config, then we - * fall back to a hardcoded value. - */ - void load( const TQString &type, const TQString &providerList = TQString() ); - - void setAlternativeProvider(const TQString& alt) { mAltProvider = alt; } - - signals: - /** - * Indicates that the list of providers has been successfully loaded. - */ - void providersLoaded( TQPtrList<KNS::Provider>* ); - void percent(TDEIO::Job *job, unsigned long percent); - void error(); - - protected slots: - void slotJobData( TDEIO::Job *, const TQByteArray & ); - void slotJobResult( TDEIO::Job * ); - - private: - TQWidget *mParentWidget; - - TQString mJobData; - - TQPtrList<KNS::Provider> mProviders; - TQString mAltProvider; - bool mTryAlt; -}; - - } -} -#endif |