Skip to content

Commit

Permalink
plugin manager: show plugin description and allow voting without webkit
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 24, 2016
1 parent c1d0fab commit 4b16c64
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 50 deletions.
106 changes: 82 additions & 24 deletions src/app/pluginmanager/qgspluginmanager.cpp
Expand Up @@ -114,6 +114,12 @@ QgsPluginManager::QgsPluginManager( QWidget * parent, bool pluginsAreEnabled, Qt
buttonUninstall->hide();
frameSettings->setHidden( true );

voteRating->hide();
voteLabel->hide();
voteSlider->hide();
voteSubmit->hide();
connect( voteSubmit, SIGNAL( clicked() ), this, SLOT( submitVote() ) );

// Init the message bar instance
msgBar = new QgsMessageBar( this );
msgBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
Expand Down Expand Up @@ -343,7 +349,7 @@ void QgsPluginManager::getCppPluginsMetadata()
}
else
{
QgsDebugMsg( "dlopen suceeded for " + lib );
QgsDebugMsg( "dlopen succeeded for " + lib );
dlclose( handle );
}
#endif //#ifndef Q_OS_WIN && Q_OS_MACX
Expand Down Expand Up @@ -598,7 +604,10 @@ void QgsPluginManager::showPluginDetails( QStandardItem * item )
{
const QMap<QString, QString> * metadata = pluginMetadata( item->data( PLUGIN_BASE_NAME_ROLE ).toString() );

if ( ! metadata ) return;
if ( !metadata )
{
return;
}

QString html = "";
html += "<style>"
Expand All @@ -615,8 +624,9 @@ void QgsPluginManager::showPluginDetails( QStandardItem * item )
" }"
"</style>";

if ( ! metadata->value( "plugin_id" ).isEmpty() )
if ( !metadata->value( "plugin_id" ).isEmpty() )
{
#ifdef WITH_QTWEBKIT
html += QString(
"<style>"
" div#stars_bg {"
Expand Down Expand Up @@ -671,9 +681,31 @@ void QgsPluginManager::showPluginDetails( QStandardItem * item )
" document.getElementById('send_vote_trigger').dispatchEvent(ev);"
" }"
"</script>" ).arg( metadata->value( "plugin_id" ) );
#else
voteRating->show();
voteLabel->show();
voteSlider->show();
voteSubmit->show();
QgsDebugMsg( QString( "vote slider:%1" ).arg( qRound( metadata->value( "average_vote" ).toFloat() ) ) );
voteSlider->setValue( qRound( metadata->value( "average_vote" ).toFloat() ) );
mCurrentPluginId = metadata->value( "plugin_id" ).toInt();
}
else
{
voteRating->hide();
voteLabel->hide();
voteSlider->hide();
voteSubmit->hide();
mCurrentPluginId = -1;
#endif
}

#ifdef WITH_QTWEBKIT
html += "<body onload='ready()'>";
#else
html += "<body>";
#endif


// First prepare message box(es)
if ( ! metadata->value( "error" ).isEmpty() )
Expand All @@ -695,24 +727,28 @@ void QgsPluginManager::showPluginDetails( QStandardItem * item )
" <tr><td width=\"100%\" style=\"color:#CC0000\">%1</td></tr>"
"</table>" ).arg( errorMsg );
}

if ( metadata->value( "status" ) == "upgradeable" )
{
html += QString( "<table bgcolor=\"#FFFFAA\" cellspacing=\"2\" cellpadding=\"6\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#880000\"><b>%1</b></td></tr>"
"</table>" ).arg( tr( "There is a new version available" ) );
}

if ( metadata->value( "status" ) == "new" )
{
html += QString( "<table bgcolor=\"#CCFFCC\" cellspacing=\"2\" cellpadding=\"6\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#008800\"><b>%1</b></td></tr>"
"</table>" ).arg( tr( "This is a new plugin" ) );
}

if ( metadata->value( "status" ) == "newer" )
{
html += QString( "<table bgcolor=\"#FFFFCC\" cellspacing=\"2\" cellpadding=\"6\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#550000\"><b>%1</b></td></tr>"
"</table>" ).arg( tr( "Installed version of this plugin is higher than any version found in repository" ) );
}

if ( metadata->value( "experimental" ) == "true" )
{
html += QString( "<table bgcolor=\"#EEEEBB\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\">"
Expand All @@ -721,6 +757,7 @@ void QgsPluginManager::showPluginDetails( QStandardItem * item )
" </td></tr>"
"</table>" ).arg( tr( "This plugin is experimental" ) );
}

if ( metadata->value( "deprecated" ) == "true" )
{
html += QString( "<table bgcolor=\"#EEBBCC\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\">"
Expand Down Expand Up @@ -768,23 +805,33 @@ void QgsPluginManager::showPluginDetails( QStandardItem * item )
}

html += "<br/><br/>";
html += "<div id='stars_bg'/><div id='stars'/>";
html += "<div id='votes'>";

QString votes;
#ifndef WITH_QTWEBKIT
votes += tr( "Average rating %1" ).arg( metadata->value( "average_vote" ).toFloat(), 0, 'f', 1 );
#endif
if ( ! metadata->value( "rating_votes" ).isEmpty() )
{
html += tr( "%1 rating vote(s)" ).arg( metadata->value( "rating_votes" ) );
}
if ( !( metadata->value( "rating_votes" ).isEmpty() || metadata->value( "downloads" ).isEmpty() ) )
{
html += ", ";
if ( !votes.isEmpty() )
votes += ", ";
votes += tr( "%1 rating vote(s)" ).arg( metadata->value( "rating_votes" ) );
}
if ( ! metadata->value( "downloads" ).isEmpty() )
{
html += tr( "%1 downloads" ).arg( metadata->value( "downloads" ) );
if ( !votes.isEmpty() )
votes += ", ";
votes += tr( "%1 downloads" ).arg( metadata->value( "downloads" ) );
}

#ifdef WITH_QTWEBKIT
html += "<div id='stars_bg'/><div id='stars'/>";
html += "<div id='votes'>";
html += votes;
html += "</div>";
html += "<div><a id='send_vote_trigger'/></div>";

#else
voteRating->setText( votes );
#endif
html += "</td></tr><tr><td>";
html += "<br/>";

Expand Down Expand Up @@ -1159,7 +1206,29 @@ void QgsPluginManager::on_vwPlugins_doubleClicked( const QModelIndex & theIndex
}
}

#ifndef WITH_QTWEBKIT
void QgsPluginManager::submitVote()
{
if ( mCurrentPluginId < 0 )
return;

sendVote( mCurrentPluginId, voteSlider->value() );
}
#endif

void QgsPluginManager::sendVote( int pluginId, int vote )
{
QString response;
QgsPythonRunner::eval( QString( "pyplugin_installer.instance().sendVote('%1', '%2')" ).arg( pluginId ).arg( vote ), response );
if ( response == "True" )
{
pushMessage( tr( "Vote sent successfully" ), QgsMessageBar::INFO );
}
else
{
pushMessage( tr( "Sending vote to the plugin repository failed." ), QgsMessageBar::WARNING );
}
}

void QgsPluginManager::on_wvDetails_linkClicked( const QUrl & url )
{
Expand All @@ -1169,17 +1238,7 @@ void QgsPluginManager::on_wvDetails_linkClicked( const QUrl & url )
{
QString params = url.path();
QString response;
QgsPythonRunner::eval( QString( "pyplugin_installer.instance().sendVote('%1', '%2')" )
.arg( params.split( '/' )[1],
params.split( '/' )[2] ), response );
if ( response == "True" )
{
pushMessage( tr( "Vote sent successfully" ), QgsMessageBar::INFO );
}
else
{
pushMessage( tr( "Sending vote to the plugin repository failed." ), QgsMessageBar::WARNING );
}
sendVote( params.split( '/' )[1].toInt(), params.split( '/' )[2].toInt() );
}
}
else
Expand All @@ -1189,7 +1248,6 @@ void QgsPluginManager::on_wvDetails_linkClicked( const QUrl & url )
}



void QgsPluginManager::on_leFilter_textChanged( QString theText )
{
if ( theText.startsWith( "tag:", Qt::CaseInsensitive ) )
Expand Down
12 changes: 12 additions & 0 deletions src/app/pluginmanager/qgspluginmanager.h
Expand Up @@ -170,6 +170,11 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
//! show the given message in the Plugin Manager internal message bar
void pushMessage( const QString &text, QgsMessageBar::MessageLevel level, int duration = -1 );

#ifndef WITH_QTWEBKIT
//! vote button was clicked
void submitVote();
#endif

protected:
//! Reimplement QgsOptionsDialogBase method as we have a custom window title what would be overwritten by this method
void showEvent( QShowEvent* e ) override;
Expand Down Expand Up @@ -199,6 +204,9 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
//! Return true if there are invalid plugins in the metadata registry
bool hasInvalidPlugins();

//! send vote
void sendVote( int pluginId, int vote );

QStandardItemModel *mModelPlugins;

QgsPluginSortFilterProxyModel * mModelProxy;
Expand All @@ -217,6 +225,10 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
QList<int> mCheckingOnStartIntervals;

QgsMessageBar *msgBar;

#ifndef WITH_QTWEBKIT
int mCurrentPluginId;
#endif
};

#endif
2 changes: 1 addition & 1 deletion src/core/auth/qgsauthmethodregistry.cpp
Expand Up @@ -277,7 +277,7 @@ QgsAuthMethod *QgsAuthMethodRegistry::authMethod( const QString &authMethodKey )
}
else
{
QgsDebugMsg( "dlopen suceeded" );
QgsDebugMsg( "dlopen succeeded" );
dlclose( handle );
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsproviderregistry.cpp
Expand Up @@ -369,7 +369,7 @@ QgsDataProvider *QgsProviderRegistry::provider( QString const & providerKey, QSt
}
else
{
QgsDebugMsg( "dlopen suceeded" );
QgsDebugMsg( "dlopen succeeded" );
dlclose( handle );
}

Expand Down
15 changes: 10 additions & 5 deletions src/core/qgswebpage.h
Expand Up @@ -28,6 +28,7 @@
#include <QMenu>
#include <QNetworkAccessManager>
#include <QPalette>
#include <QTextBrowser>


/**
Expand Down Expand Up @@ -78,17 +79,14 @@ class CORE_EXPORT QWebSettings : public QObject
explicit QWebSettings( QObject* parent = 0 )
: QObject( parent )
{

}

void setUserStyleSheetUrl( const QUrl& )
{

}

void setAttribute( WebAttribute, bool on )
void setAttribute( WebAttribute, bool )
{
Q_UNUSED( on );
}
/// @endcond
};
Expand Down Expand Up @@ -147,7 +145,14 @@ class CORE_EXPORT QWebPage : public QObject

void setLinkDelegationPolicy( LinkDelegationPolicy linkDelegationPolicy )
{
Q_UNUSED( linkDelegationPolicy );
if ( !parent() )
return;

QTextBrowser *tb = qobject_cast<QTextBrowser *>( parent() );
if ( !tb )
return;

tb->setOpenExternalLinks( linkDelegationPolicy != DontDelegateLinks );
}

void setNetworkAccessManager( QNetworkAccessManager* networkAccessManager )
Expand Down
27 changes: 10 additions & 17 deletions src/core/qgswebview.h
Expand Up @@ -42,6 +42,7 @@ class CORE_EXPORT QgsWebView : public QWebView
};
#else
#include "qgswebpage.h"
#include <QTextBrowser>

/**
* @brief The QgsWebView class is a collection of stubs to mimic the API of QWebView on systems where the real
Expand All @@ -51,17 +52,18 @@ class CORE_EXPORT QgsWebView : public QWebView
* WITH_QTWEBKIT=OFF then this will be an empty QWidget. If you miss methods in here that you would like to use,
* please add additional stubs.
*/
class CORE_EXPORT QgsWebView : public QWidget
class CORE_EXPORT QgsWebView : public QTextBrowser
{

/// @cond NOT_STABLE_API
Q_OBJECT
public:
explicit QgsWebView( QWidget *parent = 0 )
: QWidget( parent )
: QTextBrowser( parent )
, mSettings( new QWebSettings() )
, mPage( new QWebPage() )
, mPage( new QWebPage( this ) )
{
connect( this, SIGNAL( anchorClicked( const QUrl & ) ), this, SIGNAL( linkClicked( const QUrl & ) ) );
}

~QgsWebView()
Expand All @@ -72,13 +74,12 @@ class CORE_EXPORT QgsWebView : public QWidget

void setUrl( const QUrl& url )
{
Q_UNUSED( url );

setSource( url );
}

void load( const QUrl& url )
{
Q_UNUSED( url );
setSource( url );
}

QWebPage* page() const
Expand All @@ -91,33 +92,25 @@ class CORE_EXPORT QgsWebView : public QWidget
return mSettings;
}

void setHtml( const QString& html )
{
Q_UNUSED( html );
}

virtual QgsWebView* createWindow( QWebPage::WebWindowType )
{
return new QgsWebView();
}

void setContent( const QByteArray&, const QString&, const QUrl& )
{

}

void print( QPrinter* )
{

}

signals:

public slots:
void linkClicked( const QUrl &link );

private:
QWebSettings* mSettings;
QWebPage* mPage;
QWebSettings *mSettings;
QWebPage *mPage;

/// @endcond
};
Expand Down

0 comments on commit 4b16c64

Please sign in to comment.